浏览代码

UI: Add Apple Hardware Encoder to AutoConfig

Starting with macOS 13 the VT hardware encoder has all the capabilities
it needs for both streaming and recording, so we can start recommending
it in AutoConfig.
gxalpha 2 年之前
父节点
当前提交
3838b088e3
共有 3 个文件被更改,包括 24 次插入1 次删除
  1. 7 0
      UI/window-basic-auto-config-test.cpp
  2. 15 1
      UI/window-basic-auto-config.cpp
  3. 2 0
      UI/window-basic-auto-config.hpp

+ 7 - 0
UI/window-basic-auto-config-test.cpp

@@ -894,6 +894,8 @@ void AutoConfigTestPage::TestStreamEncoderThread()
 			wiz->streamingEncoder = AutoConfig::Encoder::NVENC;
 		else if (wiz->qsvAvailable)
 			wiz->streamingEncoder = AutoConfig::Encoder::QSV;
+		else if (wiz->appleAvailable)
+			wiz->streamingEncoder = AutoConfig::Encoder::Apple;
 		else
 			wiz->streamingEncoder = AutoConfig::Encoder::AMD;
 	} else {
@@ -927,6 +929,8 @@ void AutoConfigTestPage::TestRecordingEncoderThread()
 			wiz->recordingEncoder = AutoConfig::Encoder::NVENC;
 		else if (wiz->qsvAvailable)
 			wiz->recordingEncoder = AutoConfig::Encoder::QSV;
+		else if (wiz->appleAvailable)
+			wiz->recordingEncoder = AutoConfig::Encoder::Apple;
 		else
 			wiz->recordingEncoder = AutoConfig::Encoder::AMD;
 	} else {
@@ -948,6 +952,7 @@ void AutoConfigTestPage::TestRecordingEncoderThread()
 #define ENCODER_NVENC ENCODER_TEXT("Hardware.NVENC.H264")
 #define ENCODER_QSV ENCODER_TEXT("Hardware.QSV.H264")
 #define ENCODER_AMD ENCODER_TEXT("Hardware.AMD.H264")
+#define ENCODER_APPLE ENCODER_TEXT("Hardware.Apple.H264")
 
 #define QUALITY_SAME "Basic.Settings.Output.Simple.RecordingQuality.Stream"
 #define QUALITY_HIGH "Basic.Settings.Output.Simple.RecordingQuality.Small"
@@ -990,6 +995,8 @@ void AutoConfigTestPage::FinalizeResults()
 			return QTStr(ENCODER_QSV);
 		case AutoConfig::Encoder::AMD:
 			return QTStr(ENCODER_AMD);
+		case AutoConfig::Encoder::Apple:
+			return QTStr(ENCODER_APPLE);
 		case AutoConfig::Encoder::Stream:
 			return QTStr(QUALITY_SAME);
 		}

+ 15 - 1
UI/window-basic-auto-config.cpp

@@ -969,7 +969,7 @@ AutoConfig::AutoConfig(QWidget *parent) : QWizard(parent)
 		/* Newer generations of NVENC have a high enough quality to
 		 * bitrate ratio that if NVENC is available, it makes sense to
 		 * just always prefer hardware encoding by default */
-		bool preferHardware = nvencAvailable ||
+		bool preferHardware = nvencAvailable || appleAvailable ||
 				      os_get_physical_cores() <= 4;
 		streamPage->ui->preferHardware->setChecked(preferHardware);
 	}
@@ -1000,6 +1000,18 @@ void AutoConfig::TestHardwareEncoding()
 			hardwareEncodingAvailable = qsvAvailable = true;
 		else if (strcmp(id, "h264_texture_amf") == 0)
 			hardwareEncodingAvailable = vceAvailable = true;
+#ifdef __APPLE__
+		else if (strcmp(id,
+				"com.apple.videotoolbox.videoencoder.ave.avc") ==
+				 0
+#ifndef __aarch64__
+			 && os_get_emulation_status() == true
+#endif
+		)
+			if (__builtin_available(macOS 13.0, *))
+				hardwareEncodingAvailable = appleAvailable =
+					true;
+#endif
 	}
 }
 
@@ -1047,6 +1059,8 @@ inline const char *AutoConfig::GetEncoderId(Encoder enc)
 		return SIMPLE_ENCODER_QSV;
 	case Encoder::AMD:
 		return SIMPLE_ENCODER_AMD;
+	case Encoder::Apple:
+		return SIMPLE_ENCODER_APPLE_H264;
 	default:
 		return SIMPLE_ENCODER_X264;
 	}

+ 2 - 0
UI/window-basic-auto-config.hpp

@@ -47,6 +47,7 @@ class AutoConfig : public QWizard {
 		NVENC,
 		QSV,
 		AMD,
+		Apple,
 		Stream,
 	};
 
@@ -89,6 +90,7 @@ class AutoConfig : public QWizard {
 	bool nvencAvailable = false;
 	bool qsvAvailable = false;
 	bool vceAvailable = false;
+	bool appleAvailable = false;
 
 	int startingBitrate = 2500;
 	bool customServer = false;