Browse Source

mac-vth264: Clean up encoder list

When enumerating the list of encoders offered by VideoToolbox,
there's no reason we can't use the returned ID, which allows us to
remove the hardware/software encoder specific functions. At the
same time, this does add a slight complexity when localizing the
encoder name, so we can fall back to the OS-provided encoder name
if there's not a match.
Doug Kelly 4 years ago
parent
commit
6a9f25c8ea
1 changed files with 15 additions and 37 deletions
  1. 15 37
      plugins/mac-vth264/encoder.c

+ 15 - 37
plugins/mac-vth264/encoder.c

@@ -23,9 +23,6 @@
 extern const double NSAppKitVersionNumber;
 #define NSAppKitVersionNumber10_8 1187
 
-#define APPLE_H264_ENC_ID_HW "com.apple.videotoolbox.videoencoder.h264.gva"
-#define APPLE_H264_ENC_ID_SW "com.apple.videotoolbox.videoencoder.h264"
-
 // Get around missing symbol on 10.8 during compilation
 enum { kCMFormatDescriptionBridgeError_InvalidParameter_ = -12712,
 };
@@ -490,15 +487,14 @@ static bool vt_h264_update(void *data, obs_data_t *settings)
 	return true;
 }
 
-static void *vt_h264_create(obs_data_t *settings, obs_encoder_t *encoder,
-			    const char *vt_encoder_id)
+static void *vt_h264_create(obs_data_t *settings, obs_encoder_t *encoder)
 {
 	struct vt_h264_encoder *enc = bzalloc(sizeof(struct vt_h264_encoder));
 
 	OSStatus code;
 
 	enc->encoder = encoder;
-	enc->vt_encoder_id = vt_encoder_id;
+	enc->vt_encoder_id = obs_encoder_get_id(encoder);
 
 	update_params(enc, settings);
 
@@ -516,16 +512,6 @@ fail:
 	return NULL;
 }
 
-static void *vt_h264_create_hw(obs_data_t *settings, obs_encoder_t *encoder)
-{
-	return vt_h264_create(settings, encoder, APPLE_H264_ENC_ID_HW);
-}
-
-static void *vt_h264_create_sw(obs_data_t *settings, obs_encoder_t *encoder)
-{
-	return vt_h264_create(settings, encoder, APPLE_H264_ENC_ID_SW);
-}
-
 static const uint8_t annexb_startcode[4] = {0, 0, 0, 1};
 
 static void packet_put(struct darray *packet, const uint8_t *buf, size_t size)
@@ -845,16 +831,16 @@ static bool vt_h264_extra_data(void *data, uint8_t **extra_data, size_t *size)
 	return true;
 }
 
-static const char *vt_h264_getname_hw(void *unused)
+static const char *vt_h264_getname(void *data)
 {
-	UNUSED_PARAMETER(unused);
-	return obs_module_text("VTH264EncHW");
-}
+	const char *disp_name = vt_encoders.array[(int)data].disp_name;
 
-static const char *vt_h264_getname_sw(void *unused)
-{
-	UNUSED_PARAMETER(unused);
-	return obs_module_text("VTH264EncSW");
+	if (strcmp("Apple H.264 (HW)", disp_name) == 0) {
+		return obs_module_text("VTH264EncHW");
+	} else if (strcmp("Apple H.264 (SW)", disp_name) == 0) {
+		return obs_module_text("VTH264EncSW");
+	}
+	return disp_name;
 }
 
 #define TEXT_VT_ENCODER obs_module_text("VTEncoder")
@@ -994,19 +980,11 @@ void register_encoders()
 	};
 
 	for (size_t i = 0; i < vt_encoders.num; i++) {
-		if (strcmp(vt_encoders.array[i].id, APPLE_H264_ENC_ID_HW) ==
-		    0) {
-			info.id = "vt_h264_hw";
-			info.get_name = vt_h264_getname_hw;
-			info.create = vt_h264_create_hw;
-			obs_register_encoder(&info);
-		} else if (strcmp(vt_encoders.array[i].id,
-				  APPLE_H264_ENC_ID_SW) == 0) {
-			info.id = "vt_h264_sw";
-			info.get_name = vt_h264_getname_sw;
-			info.create = vt_h264_create_sw;
-			obs_register_encoder(&info);
-		}
+		info.id = vt_encoders.array[i].id;
+		info.type_data = (void *)i;
+		info.get_name = vt_h264_getname;
+		info.create = vt_h264_create;
+		obs_register_encoder(&info);
 	}
 }