applemedia: vtenc: Register a hardware-only vtenc_h264_hw element on OSX
authorHeinrich Fink <hfink@toolsonair.com>
Wed, 1 Jun 2016 11:43:32 +0000 (13:43 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Thu, 2 Jun 2016 08:22:09 +0000 (11:22 +0300)
Similar to vtdec_hw, this commit adds a vtenc_h264_hw element that fails
caps negotiation unless a hardware encoder could actually be acquired.
This is useful in situations where a fallback to a software encoder
other than the vtenc_h264 software encoder is desired (e.g. to x264enc).

https://bugzilla.gnome.org/show_bug.cgi?id=767104

sys/applemedia/vtenc.c
sys/applemedia/vtenc.h

index 5c0c6ca62502c9565d9d86eb7d19dd9283cdbdbd..39b7813beac9a7c56f0a4ee134d2c5084f8dbf18 100644 (file)
@@ -47,6 +47,9 @@ GST_DEBUG_CATEGORY (gst_vtenc_debug);
 const CFStringRef
     kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder =
 CFSTR ("EnableHardwareAcceleratedVideoEncoder");
+const CFStringRef
+    kVTVideoEncoderSpecification_RequireHardwareAcceleratedVideoEncoder =
+CFSTR ("RequireHardwareAcceleratedVideoEncoder");
 const CFStringRef kVTCompressionPropertyKey_ProfileLevel =
 CFSTR ("ProfileLevel");
 const CFStringRef kVTProfileLevel_H264_Baseline_AutoLevel =
@@ -648,7 +651,7 @@ gst_vtenc_set_format (GstVideoEncoder * enc, GstVideoCodecState * state)
   self->session = session;
   GST_OBJECT_UNLOCK (self);
 
-  return TRUE;
+  return session != NULL;
 }
 
 static gboolean
@@ -786,6 +789,8 @@ gst_vtenc_create_session (GstVTEnc * self)
   VTCompressionSessionRef session = NULL;
   CFMutableDictionaryRef encoder_spec = NULL, pb_attrs;
   OSStatus status;
+  const GstVTEncoderDetails *codec_details =
+      GST_VTENC_CLASS_GET_CODEC_DETAILS (G_OBJECT_GET_CLASS (self));
 
 #if !HAVE_IOS
   encoder_spec =
@@ -793,6 +798,10 @@ gst_vtenc_create_session (GstVTEnc * self)
       &kCFTypeDictionaryValueCallBacks);
   gst_vtutil_dict_set_boolean (encoder_spec,
       kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder, true);
+  if (codec_details->require_hardware)
+    gst_vtutil_dict_set_boolean (encoder_spec,
+        kVTVideoEncoderSpecification_RequireHardwareAcceleratedVideoEncoder,
+        TRUE);
 #endif
 
   pb_attrs = CFDictionaryCreateMutable (NULL, 0, &kCFTypeDictionaryKeyCallBacks,
@@ -1398,7 +1407,10 @@ gst_vtenc_register (GstPlugin * plugin,
 }
 
 static const GstVTEncoderDetails gst_vtenc_codecs[] = {
-  {"H.264", "h264", "video/x-h264", kCMVideoCodecType_H264},
+  {"H.264", "h264", "video/x-h264", kCMVideoCodecType_H264, FALSE},
+#ifndef HAVE_IOS
+  {"H.264 (HW only)", "h264_hw", "video/x-h264", kCMVideoCodecType_H264, TRUE},
+#endif
 };
 
 void
index 3bbe3c69fe7377cf504bb07edc790995af626ec7..4c6100016f321b487c3c21209c50e385219609b1 100644 (file)
@@ -44,6 +44,7 @@ struct _GstVTEncoderDetails
   const gchar * element_name;
   const gchar * mimetype;
   CMVideoCodecType format_id;
+  gboolean require_hardware;
 };
 
 struct _GstVTEncClass