diff options
author | Víctor Manuel Jáquez Leal <victorx.jaquez@intel.com> | 2017-04-06 16:28:12 +0200 |
---|---|---|
committer | Víctor Manuel Jáquez Leal <victorx.jaquez@intel.com> | 2017-04-06 22:00:05 +0200 |
commit | 5ccadd6e9cc76c30060878949eb4c4e2edfef45f (patch) | |
tree | df62576dacee3ac9e957d26e87cafaac9985298c | |
parent | 7153b4597d24af67508b0f20c20f34c8a56b1675 (diff) |
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
-rw-r--r-- | gst/vaapi/gstvaapiencode.c | 15 | ||||
-rw-r--r-- | gst/vaapi/gstvaapiencode.h | 1 | ||||
-rw-r--r-- | gst/vaapi/gstvaapiencode_h264.c | 20 | ||||
-rw-r--r-- | gst/vaapi/gstvaapiencode_h265.c | 20 |
4 files changed, 54 insertions, 2 deletions
diff --git a/gst/vaapi/gstvaapiencode.c b/gst/vaapi/gstvaapiencode.c index ff7154de..12d634de 100644 --- a/gst/vaapi/gstvaapiencode.c +++ b/gst/vaapi/gstvaapiencode.c @@ -349,9 +349,11 @@ gst_vaapiencode_buffer_loop (GstVaapiEncode * encode) static gboolean ensure_allowed_sinkpad_caps (GstVaapiEncode * encode) { + GstVaapiEncodeClass *klass = GST_VAAPIENCODE_GET_CLASS (encode); GstCaps *out_caps, *raw_caps = NULL; GArray *formats = NULL; gboolean ret = FALSE; + GstVaapiProfile profile = GST_VAAPI_PROFILE_UNKNOWN; if (encode->allowed_sinkpad_caps) return TRUE; @@ -362,8 +364,17 @@ ensure_allowed_sinkpad_caps (GstVaapiEncode * encode) if (!out_caps) goto failed_create_va_caps; - formats = gst_vaapi_encoder_get_surface_formats (encode->encoder, - GST_VAAPI_PROFILE_UNKNOWN); + if (klass->get_profile) { + 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) goto failed_get_formats; diff --git a/gst/vaapi/gstvaapiencode.h b/gst/vaapi/gstvaapiencode.h index 77a8a40b..72121f79 100644 --- a/gst/vaapi/gstvaapiencode.h +++ b/gst/vaapi/gstvaapiencode.h @@ -80,6 +80,7 @@ struct _GstVaapiEncodeClass GstFlowReturn (*alloc_buffer) (GstVaapiEncode * encode, GstVaapiCodedBuffer * coded_buf, GstBuffer ** outbuf_ptr); + GstVaapiProfile (*get_profile) (GstCaps * caps); }; GType diff --git a/gst/vaapi/gstvaapiencode_h264.c b/gst/vaapi/gstvaapiencode_h264.c index 35306ebd..07427452 100644 --- a/gst/vaapi/gstvaapiencode_h264.c +++ b/gst/vaapi/gstvaapiencode_h264.c @@ -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 { GstVaapiProfile best_profile; @@ -397,6 +416,7 @@ gst_vaapiencode_h264_class_init (GstVaapiEncodeH264Class * klass) object_class->get_property = gst_vaapiencode_h264_get_property; 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->get_caps = gst_vaapiencode_h264_get_caps; encode_class->alloc_encoder = gst_vaapiencode_h264_alloc_encoder; diff --git a/gst/vaapi/gstvaapiencode_h265.c b/gst/vaapi/gstvaapiencode_h265.c index 3915b2f1..c8490fb1 100644 --- a/gst/vaapi/gstvaapiencode_h265.c +++ b/gst/vaapi/gstvaapiencode_h265.c @@ -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 { GstVaapiProfile best_profile; @@ -396,6 +415,7 @@ gst_vaapiencode_h265_class_init (GstVaapiEncodeH265Class * klass) object_class->get_property = gst_vaapiencode_h265_get_property; 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->get_caps = gst_vaapiencode_h265_get_caps; encode_class->alloc_encoder = gst_vaapiencode_h265_alloc_encoder; |