From 49992be6437a29b65dec5a5200e1c8dedd4f9c42 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Thu, 27 May 2021 16:22:42 -0400 Subject: [PATCH] v4lcodecs: Validate src formats This add src format validation, this avoid registering element for drivers we don't support any of their src formats. This also special case the AlphaDecodeBin wrapper, as we know that alphacombine element only support I420 and NV12 for now. Part-of: --- sys/v4l2codecs/gstv4l2codech264dec.c | 18 +++++++++++++++++- sys/v4l2codecs/gstv4l2codech264dec.h | 1 + sys/v4l2codecs/gstv4l2codecvp8dec.c | 27 ++++++++++++++++++++++++--- sys/v4l2codecs/gstv4l2codecvp8dec.h | 5 +++-- sys/v4l2codecs/plugin.c | 6 ++++-- 5 files changed, 49 insertions(+), 8 deletions(-) diff --git a/sys/v4l2codecs/gstv4l2codech264dec.c b/sys/v4l2codecs/gstv4l2codech264dec.c index d76bea5715..7804b87881 100644 --- a/sys/v4l2codecs/gstv4l2codech264dec.c +++ b/sys/v4l2codecs/gstv4l2codech264dec.c @@ -1401,13 +1401,29 @@ gst_v4l2_codec_h264_dec_subclass_init (GstV4l2CodecH264DecClass * klass, } void -gst_v4l2_codec_h264_dec_register (GstPlugin * plugin, +gst_v4l2_codec_h264_dec_register (GstPlugin * plugin, GstV4l2Decoder * decoder, GstV4l2CodecDevice * device, guint rank) { + GstCaps *src_caps; + + if (!gst_v4l2_decoder_set_sink_fmt (decoder, V4L2_PIX_FMT_H264_SLICE, + 320, 240, 8)) + return; + src_caps = gst_v4l2_decoder_enum_src_formats (decoder); + + if (gst_caps_is_empty (src_caps)) { + GST_WARNING ("Not registering H264 decoder since it produces no " + "supported format"); + goto done; + } + gst_v4l2_decoder_register (plugin, GST_TYPE_V4L2_CODEC_H264_DEC, (GClassInitFunc) gst_v4l2_codec_h264_dec_subclass_init, gst_mini_object_ref (GST_MINI_OBJECT (device)), (GInstanceInitFunc) gst_v4l2_codec_h264_dec_subinit, "v4l2sl%sh264dec", device, rank, NULL); + +done: + gst_caps_unref (src_caps); } diff --git a/sys/v4l2codecs/gstv4l2codech264dec.h b/sys/v4l2codecs/gstv4l2codech264dec.h index ccce690e4d..f327311fcd 100644 --- a/sys/v4l2codecs/gstv4l2codech264dec.h +++ b/sys/v4l2codecs/gstv4l2codech264dec.h @@ -45,6 +45,7 @@ struct _GstV4l2CodecH264DecClass GType gst_v4l2_codec_h264_dec_get_type (void); void gst_v4l2_codec_h264_dec_register (GstPlugin * plugin, + GstV4l2Decoder * decoder, GstV4l2CodecDevice * device, guint rank); diff --git a/sys/v4l2codecs/gstv4l2codecvp8dec.c b/sys/v4l2codecs/gstv4l2codecvp8dec.c index 9acdbfdabc..4abcbfcae6 100644 --- a/sys/v4l2codecs/gstv4l2codecvp8dec.c +++ b/sys/v4l2codecs/gstv4l2codecvp8dec.c @@ -872,10 +872,22 @@ static void gst_v4l2_codec_vp8_alpha_decode_bin_subclass_init } void -gst_v4l2_codec_vp8_dec_register (GstPlugin * plugin, +gst_v4l2_codec_vp8_dec_register (GstPlugin * plugin, GstV4l2Decoder * decoder, GstV4l2CodecDevice * device, guint rank) { gchar *element_name; + GstCaps *src_caps, *alpha_caps; + + if (!gst_v4l2_decoder_set_sink_fmt (decoder, V4L2_PIX_FMT_VP8_FRAME, + 320, 240, 8)) + return; + src_caps = gst_v4l2_decoder_enum_src_formats (decoder); + + if (gst_caps_is_empty (src_caps)) { + GST_WARNING ("Not registering VP8 decoder since it produces no " + "supported format"); + goto done; + } gst_v4l2_decoder_register (plugin, GST_TYPE_V4L2_CODEC_VP8_DEC, (GClassInitFunc) gst_v4l2_codec_vp8_dec_subclass_init, @@ -883,9 +895,18 @@ gst_v4l2_codec_vp8_dec_register (GstPlugin * plugin, (GInstanceInitFunc) gst_v4l2_codec_vp8_dec_subinit, "v4l2sl%svp8dec", device, rank, &element_name); - if (element_name) { + if (!element_name) + goto done; + + alpha_caps = gst_caps_from_string ("video/x-raw,format={I420, NV12}"); + + if (gst_caps_can_intersect (src_caps, alpha_caps)) gst_v4l2_codec_alpha_decode_bin_register (plugin, (GClassInitFunc) gst_v4l2_codec_vp8_alpha_decode_bin_subclass_init, element_name, "v4l2slvp8%salphadecodebin", device, rank); - } + + gst_caps_unref (alpha_caps); + +done: + gst_caps_unref (src_caps); } diff --git a/sys/v4l2codecs/gstv4l2codecvp8dec.h b/sys/v4l2codecs/gstv4l2codecvp8dec.h index 8233686ffe..c74cc78182 100644 --- a/sys/v4l2codecs/gstv4l2codecvp8dec.h +++ b/sys/v4l2codecs/gstv4l2codecvp8dec.h @@ -45,8 +45,9 @@ struct _GstV4l2CodecVp8DecClass GType gst_v4l2_codec_vp8_dec_get_type (void); void gst_v4l2_codec_vp8_dec_register (GstPlugin * plugin, - GstV4l2CodecDevice * device, - guint rank); + GstV4l2Decoder * decoder, + GstV4l2CodecDevice * device, + guint rank); G_END_DECLS diff --git a/sys/v4l2codecs/plugin.c b/sys/v4l2codecs/plugin.c index 91334e7432..8d0c969a8f 100644 --- a/sys/v4l2codecs/plugin.c +++ b/sys/v4l2codecs/plugin.c @@ -50,12 +50,14 @@ register_video_decoder (GstPlugin * plugin, GstV4l2CodecDevice * device) case V4L2_PIX_FMT_H264_SLICE: GST_INFO_OBJECT (decoder, "Registering %s as H264 Decoder", device->name); - gst_v4l2_codec_h264_dec_register (plugin, device, GST_RANK_PRIMARY + 1); + gst_v4l2_codec_h264_dec_register (plugin, decoder, device, + GST_RANK_PRIMARY + 1); break; case V4L2_PIX_FMT_VP8_FRAME: GST_INFO_OBJECT (decoder, "Registering %s as VP8 Decoder", device->name); - gst_v4l2_codec_vp8_dec_register (plugin, device, GST_RANK_PRIMARY + 1); + gst_v4l2_codec_vp8_dec_register (plugin, decoder, + device, GST_RANK_PRIMARY + 1); break; default: GST_FIXME_OBJECT (decoder, "%" GST_FOURCC_FORMAT " is not supported.",