From f26034cd661ee2a9bc69ac4af8bf32d5042f640c Mon Sep 17 00:00:00 2001 From: Víctor Manuel Jáquez Leal Date: Tue, 19 Jul 2016 16:40:10 +0200 Subject: vaapidecode: generate source pad caps Just as vaapipostproc, VA decoder's context can be queried to get the possible raw formats, so, the src caps can negotiate the exact caps that the context supports. --- gst/vaapi/gstvaapidecode.c | 56 ++++++++++++++++++++++++++++++++++++++++++---- gst/vaapi/gstvaapidecode.h | 1 + 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/gst/vaapi/gstvaapidecode.c b/gst/vaapi/gstvaapidecode.c index 51001ef0..a1f9b2fe 100644 --- a/gst/vaapi/gstvaapidecode.c +++ b/gst/vaapi/gstvaapidecode.c @@ -200,12 +200,59 @@ gst_vaapidecode_update_sink_caps (GstVaapiDecode * decode, GstCaps * caps) return TRUE; } +static gboolean +gst_vaapidecode_ensure_allowed_srcpad_caps (GstVaapiDecode * decode) +{ + GstCaps *out_caps, *raw_caps; + + if (decode->allowed_srcpad_caps) + return TRUE; + + if (!GST_VAAPI_PLUGIN_BASE_DISPLAY (decode)) + return FALSE; + + /* Create VA caps */ + out_caps = gst_caps_from_string (GST_VAAPI_MAKE_SURFACE_CAPS ";" + GST_VAAPI_MAKE_GLTEXUPLOAD_CAPS); + if (!out_caps) { + GST_WARNING_OBJECT (decode, "failed to create VA/GL source caps"); + return FALSE; + } + + raw_caps = gst_vaapi_plugin_base_get_allowed_raw_caps + (GST_VAAPI_PLUGIN_BASE (decode)); + if (!raw_caps) { + gst_caps_unref (out_caps); + GST_WARNING_OBJECT (decode, "failed to create raw sink caps"); + return FALSE; + } + + out_caps = gst_caps_make_writable (out_caps); + gst_caps_append (out_caps, gst_caps_copy (raw_caps)); + decode->allowed_srcpad_caps = out_caps; + + GST_INFO_OBJECT (decode, "allowed srcpad caps: %" GST_PTR_FORMAT, + decode->allowed_srcpad_caps); + + return TRUE; +} + +static GstCaps * +gst_vaapidecode_get_allowed_srcpad_caps (GstVaapiDecode * decode) +{ + GstPad *const srcpad = GST_VIDEO_DECODER_SRC_PAD (decode); + + if (gst_vaapidecode_ensure_allowed_srcpad_caps (decode)) + return gst_caps_ref (decode->allowed_srcpad_caps); + return gst_pad_get_pad_template_caps (srcpad); +} + static gboolean gst_vaapidecode_update_src_caps (GstVaapiDecode * decode) { GstVideoDecoder *const vdec = GST_VIDEO_DECODER (decode); GstPad *const srcpad = GST_VIDEO_DECODER_SRC_PAD (vdec); - GstCaps *templ; + GstCaps *allowed; GstVideoCodecState *state, *ref_state; GstVaapiCapsFeature feature; GstCapsFeatures *features; @@ -223,9 +270,9 @@ gst_vaapidecode_update_src_caps (GstVaapiDecode * decode) ref_state = decode->input_state; format = GST_VIDEO_INFO_FORMAT (&decode->decoded_info); - templ = gst_pad_get_pad_template_caps (srcpad); - feature = gst_vaapi_find_preferred_caps_feature (srcpad, templ, &format); - gst_caps_unref (templ); + allowed = gst_vaapidecode_get_allowed_srcpad_caps (decode); + feature = gst_vaapi_find_preferred_caps_feature (srcpad, allowed, &format); + gst_caps_unref (allowed); if (feature == GST_VAAPI_CAPS_FEATURE_NOT_NEGOTIATED) return FALSE; @@ -934,6 +981,7 @@ gst_vaapidecode_close (GstVideoDecoder * vdec) GstVaapiDecode *const decode = GST_VAAPIDECODE (vdec); gst_vaapidecode_destroy (decode); + gst_caps_replace (&decode->allowed_srcpad_caps, NULL); gst_vaapi_plugin_base_close (GST_VAAPI_PLUGIN_BASE (decode)); return TRUE; } diff --git a/gst/vaapi/gstvaapidecode.h b/gst/vaapi/gstvaapidecode.h index 41d85640..cb2a2f1d 100644 --- a/gst/vaapi/gstvaapidecode.h +++ b/gst/vaapi/gstvaapidecode.h @@ -47,6 +47,7 @@ struct _GstVaapiDecode { GCond surface_ready; GstCaps *decoder_caps; GstCaps *allowed_sinkpad_caps; + GstCaps *allowed_srcpad_caps; guint current_frame_size; guint has_texture_upload_meta : 1; -- cgit v1.2.3