applemedia: vtenc: Register a hardware-only vtenc_h264_hw element on OSX

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
This commit is contained in:
Heinrich Fink 2016-06-01 13:43:32 +02:00 committed by Sebastian Dröge
parent 3d8d60baa8
commit ab70d79c43
2 changed files with 15 additions and 2 deletions

View file

@ -47,6 +47,9 @@ GST_DEBUG_CATEGORY (gst_vtenc_debug);
const CFStringRef const CFStringRef
kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder = kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder =
CFSTR ("EnableHardwareAcceleratedVideoEncoder"); CFSTR ("EnableHardwareAcceleratedVideoEncoder");
const CFStringRef
kVTVideoEncoderSpecification_RequireHardwareAcceleratedVideoEncoder =
CFSTR ("RequireHardwareAcceleratedVideoEncoder");
const CFStringRef kVTCompressionPropertyKey_ProfileLevel = const CFStringRef kVTCompressionPropertyKey_ProfileLevel =
CFSTR ("ProfileLevel"); CFSTR ("ProfileLevel");
const CFStringRef kVTProfileLevel_H264_Baseline_AutoLevel = const CFStringRef kVTProfileLevel_H264_Baseline_AutoLevel =
@ -648,7 +651,7 @@ gst_vtenc_set_format (GstVideoEncoder * enc, GstVideoCodecState * state)
self->session = session; self->session = session;
GST_OBJECT_UNLOCK (self); GST_OBJECT_UNLOCK (self);
return TRUE; return session != NULL;
} }
static gboolean static gboolean
@ -786,6 +789,8 @@ gst_vtenc_create_session (GstVTEnc * self)
VTCompressionSessionRef session = NULL; VTCompressionSessionRef session = NULL;
CFMutableDictionaryRef encoder_spec = NULL, pb_attrs; CFMutableDictionaryRef encoder_spec = NULL, pb_attrs;
OSStatus status; OSStatus status;
const GstVTEncoderDetails *codec_details =
GST_VTENC_CLASS_GET_CODEC_DETAILS (G_OBJECT_GET_CLASS (self));
#if !HAVE_IOS #if !HAVE_IOS
encoder_spec = encoder_spec =
@ -793,6 +798,10 @@ gst_vtenc_create_session (GstVTEnc * self)
&kCFTypeDictionaryValueCallBacks); &kCFTypeDictionaryValueCallBacks);
gst_vtutil_dict_set_boolean (encoder_spec, gst_vtutil_dict_set_boolean (encoder_spec,
kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder, true); kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder, true);
if (codec_details->require_hardware)
gst_vtutil_dict_set_boolean (encoder_spec,
kVTVideoEncoderSpecification_RequireHardwareAcceleratedVideoEncoder,
TRUE);
#endif #endif
pb_attrs = CFDictionaryCreateMutable (NULL, 0, &kCFTypeDictionaryKeyCallBacks, pb_attrs = CFDictionaryCreateMutable (NULL, 0, &kCFTypeDictionaryKeyCallBacks,
@ -1398,7 +1407,10 @@ gst_vtenc_register (GstPlugin * plugin,
} }
static const GstVTEncoderDetails gst_vtenc_codecs[] = { 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 void

View file

@ -44,6 +44,7 @@ struct _GstVTEncoderDetails
const gchar * element_name; const gchar * element_name;
const gchar * mimetype; const gchar * mimetype;
CMVideoCodecType format_id; CMVideoCodecType format_id;
gboolean require_hardware;
}; };
struct _GstVTEncClass struct _GstVTEncClass