vaapiencode: add get_profile() vmethod

This new virtual method, get_profile(), if implemented by specific
encoders, will return the VA profile potentially determined by the
source caps.

Also it is implemented by h264 and h265 encoders, which are the main
users of this vmethod.

https://bugzilla.gnome.org/show_bug.cgi?id=771291
This commit is contained in:
Víctor Manuel Jáquez Leal 2017-04-06 16:28:12 +02:00
parent 7153b4597d
commit 5ccadd6e9c
4 changed files with 54 additions and 2 deletions

View file

@ -349,9 +349,11 @@ gst_vaapiencode_buffer_loop (GstVaapiEncode * encode)
static gboolean static gboolean
ensure_allowed_sinkpad_caps (GstVaapiEncode * encode) ensure_allowed_sinkpad_caps (GstVaapiEncode * encode)
{ {
GstVaapiEncodeClass *klass = GST_VAAPIENCODE_GET_CLASS (encode);
GstCaps *out_caps, *raw_caps = NULL; GstCaps *out_caps, *raw_caps = NULL;
GArray *formats = NULL; GArray *formats = NULL;
gboolean ret = FALSE; gboolean ret = FALSE;
GstVaapiProfile profile = GST_VAAPI_PROFILE_UNKNOWN;
if (encode->allowed_sinkpad_caps) if (encode->allowed_sinkpad_caps)
return TRUE; return TRUE;
@ -362,8 +364,17 @@ ensure_allowed_sinkpad_caps (GstVaapiEncode * encode)
if (!out_caps) if (!out_caps)
goto failed_create_va_caps; goto failed_create_va_caps;
formats = gst_vaapi_encoder_get_surface_formats (encode->encoder, if (klass->get_profile) {
GST_VAAPI_PROFILE_UNKNOWN); GstCaps *allowed =
gst_pad_get_allowed_caps (GST_VAAPI_PLUGIN_BASE_SRC_PAD (encode));
if (allowed) {
if (!gst_caps_is_empty (allowed) && !gst_caps_is_any (allowed))
profile = klass->get_profile (allowed);
gst_caps_unref (allowed);
}
}
formats = gst_vaapi_encoder_get_surface_formats (encode->encoder, profile);
if (!formats) if (!formats)
goto failed_get_formats; goto failed_get_formats;

View file

@ -80,6 +80,7 @@ struct _GstVaapiEncodeClass
GstFlowReturn (*alloc_buffer) (GstVaapiEncode * encode, GstFlowReturn (*alloc_buffer) (GstVaapiEncode * encode,
GstVaapiCodedBuffer * coded_buf, GstVaapiCodedBuffer * coded_buf,
GstBuffer ** outbuf_ptr); GstBuffer ** outbuf_ptr);
GstVaapiProfile (*get_profile) (GstCaps * caps);
}; };
GType GType

View file

@ -129,6 +129,25 @@ gst_vaapiencode_h264_get_property (GObject * object,
} }
} }
static GstVaapiProfile
gst_vaapiencode_h264_get_profile (GstCaps * caps)
{
guint i;
for (i = 0; i < gst_caps_get_size (caps); i++) {
GstStructure *const structure = gst_caps_get_structure (caps, i);
const GValue *const value = gst_structure_get_value (structure, "profile");
if (value && G_VALUE_HOLDS_STRING (value)) {
const gchar *str = g_value_get_string (value);
if (str)
return gst_vaapi_utils_h264_get_profile_from_string (str);
}
}
return GST_VAAPI_PROFILE_UNKNOWN;
}
typedef struct typedef struct
{ {
GstVaapiProfile best_profile; GstVaapiProfile best_profile;
@ -397,6 +416,7 @@ gst_vaapiencode_h264_class_init (GstVaapiEncodeH264Class * klass)
object_class->get_property = gst_vaapiencode_h264_get_property; object_class->get_property = gst_vaapiencode_h264_get_property;
encode_class->get_properties = gst_vaapi_encoder_h264_get_default_properties; encode_class->get_properties = gst_vaapi_encoder_h264_get_default_properties;
encode_class->get_profile = gst_vaapiencode_h264_get_profile;
encode_class->set_config = gst_vaapiencode_h264_set_config; encode_class->set_config = gst_vaapiencode_h264_set_config;
encode_class->get_caps = gst_vaapiencode_h264_get_caps; encode_class->get_caps = gst_vaapiencode_h264_get_caps;
encode_class->alloc_encoder = gst_vaapiencode_h264_alloc_encoder; encode_class->alloc_encoder = gst_vaapiencode_h264_alloc_encoder;

View file

@ -128,6 +128,25 @@ gst_vaapiencode_h265_get_property (GObject * object,
} }
} }
static GstVaapiProfile
gst_vaapiencode_h265_get_profile (GstCaps * caps)
{
guint i;
for (i = 0; i < gst_caps_get_size (caps); i++) {
GstStructure *const structure = gst_caps_get_structure (caps, i);
const GValue *const value = gst_structure_get_value (structure, "profile");
if (value && G_VALUE_HOLDS_STRING (value)) {
const gchar *str = g_value_get_string (value);
if (str)
return gst_vaapi_utils_h265_get_profile_from_string (str);
}
}
return GST_VAAPI_PROFILE_UNKNOWN;
}
typedef struct typedef struct
{ {
GstVaapiProfile best_profile; GstVaapiProfile best_profile;
@ -396,6 +415,7 @@ gst_vaapiencode_h265_class_init (GstVaapiEncodeH265Class * klass)
object_class->get_property = gst_vaapiencode_h265_get_property; object_class->get_property = gst_vaapiencode_h265_get_property;
encode_class->get_properties = gst_vaapi_encoder_h265_get_default_properties; encode_class->get_properties = gst_vaapi_encoder_h265_get_default_properties;
encode_class->get_profile = gst_vaapiencode_h265_get_profile;
encode_class->set_config = gst_vaapiencode_h265_set_config; encode_class->set_config = gst_vaapiencode_h265_set_config;
encode_class->get_caps = gst_vaapiencode_h265_get_caps; encode_class->get_caps = gst_vaapiencode_h265_get_caps;
encode_class->alloc_encoder = gst_vaapiencode_h265_alloc_encoder; encode_class->alloc_encoder = gst_vaapiencode_h265_alloc_encoder;