Browse Source

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 years ago
parent
commit
3838b088e3

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

@@ -894,6 +894,8 @@ void AutoConfigTestPage::TestStreamEncoderThread()
 			wiz->streamingEncoder = AutoConfig::Encoder::NVENC;
 			wiz->streamingEncoder = AutoConfig::Encoder::NVENC;
 		else if (wiz->qsvAvailable)
 		else if (wiz->qsvAvailable)
 			wiz->streamingEncoder = AutoConfig::Encoder::QSV;
 			wiz->streamingEncoder = AutoConfig::Encoder::QSV;
+		else if (wiz->appleAvailable)
+			wiz->streamingEncoder = AutoConfig::Encoder::Apple;
 		else
 		else
 			wiz->streamingEncoder = AutoConfig::Encoder::AMD;
 			wiz->streamingEncoder = AutoConfig::Encoder::AMD;
 	} else {
 	} else {
@@ -927,6 +929,8 @@ void AutoConfigTestPage::TestRecordingEncoderThread()
 			wiz->recordingEncoder = AutoConfig::Encoder::NVENC;
 			wiz->recordingEncoder = AutoConfig::Encoder::NVENC;
 		else if (wiz->qsvAvailable)
 		else if (wiz->qsvAvailable)
 			wiz->recordingEncoder = AutoConfig::Encoder::QSV;
 			wiz->recordingEncoder = AutoConfig::Encoder::QSV;
+		else if (wiz->appleAvailable)
+			wiz->recordingEncoder = AutoConfig::Encoder::Apple;
 		else
 		else
 			wiz->recordingEncoder = AutoConfig::Encoder::AMD;
 			wiz->recordingEncoder = AutoConfig::Encoder::AMD;
 	} else {
 	} else {
@@ -948,6 +952,7 @@ void AutoConfigTestPage::TestRecordingEncoderThread()
 #define ENCODER_NVENC ENCODER_TEXT("Hardware.NVENC.H264")
 #define ENCODER_NVENC ENCODER_TEXT("Hardware.NVENC.H264")
 #define ENCODER_QSV ENCODER_TEXT("Hardware.QSV.H264")
 #define ENCODER_QSV ENCODER_TEXT("Hardware.QSV.H264")
 #define ENCODER_AMD ENCODER_TEXT("Hardware.AMD.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_SAME "Basic.Settings.Output.Simple.RecordingQuality.Stream"
 #define QUALITY_HIGH "Basic.Settings.Output.Simple.RecordingQuality.Small"
 #define QUALITY_HIGH "Basic.Settings.Output.Simple.RecordingQuality.Small"
@@ -990,6 +995,8 @@ void AutoConfigTestPage::FinalizeResults()
 			return QTStr(ENCODER_QSV);
 			return QTStr(ENCODER_QSV);
 		case AutoConfig::Encoder::AMD:
 		case AutoConfig::Encoder::AMD:
 			return QTStr(ENCODER_AMD);
 			return QTStr(ENCODER_AMD);
+		case AutoConfig::Encoder::Apple:
+			return QTStr(ENCODER_APPLE);
 		case AutoConfig::Encoder::Stream:
 		case AutoConfig::Encoder::Stream:
 			return QTStr(QUALITY_SAME);
 			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
 		/* Newer generations of NVENC have a high enough quality to
 		 * bitrate ratio that if NVENC is available, it makes sense to
 		 * bitrate ratio that if NVENC is available, it makes sense to
 		 * just always prefer hardware encoding by default */
 		 * just always prefer hardware encoding by default */
-		bool preferHardware = nvencAvailable ||
+		bool preferHardware = nvencAvailable || appleAvailable ||
 				      os_get_physical_cores() <= 4;
 				      os_get_physical_cores() <= 4;
 		streamPage->ui->preferHardware->setChecked(preferHardware);
 		streamPage->ui->preferHardware->setChecked(preferHardware);
 	}
 	}
@@ -1000,6 +1000,18 @@ void AutoConfig::TestHardwareEncoding()
 			hardwareEncodingAvailable = qsvAvailable = true;
 			hardwareEncodingAvailable = qsvAvailable = true;
 		else if (strcmp(id, "h264_texture_amf") == 0)
 		else if (strcmp(id, "h264_texture_amf") == 0)
 			hardwareEncodingAvailable = vceAvailable = true;
 			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;
 		return SIMPLE_ENCODER_QSV;
 	case Encoder::AMD:
 	case Encoder::AMD:
 		return SIMPLE_ENCODER_AMD;
 		return SIMPLE_ENCODER_AMD;
+	case Encoder::Apple:
+		return SIMPLE_ENCODER_APPLE_H264;
 	default:
 	default:
 		return SIMPLE_ENCODER_X264;
 		return SIMPLE_ENCODER_X264;
 	}
 	}

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

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