From c4216a693ca559c67250e617cb31047faa317829 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Fri, 10 Dec 2021 14:07:18 -0500 Subject: [PATCH] v4l2codecs: mpeg2: Check that the decoder output formats This is to avoid exposing a decoder for which we don't support any output format. This happens on platform using vendor formats or not yet supported tiles formats. Part-of: --- .../sys/v4l2codecs/gstv4l2codecmpeg2dec.c | 18 +++++++++++++++++- .../sys/v4l2codecs/gstv4l2codecmpeg2dec.h | 5 +++-- subprojects/gst-plugins-bad/sys/v4l2codecs/plugin.c | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/subprojects/gst-plugins-bad/sys/v4l2codecs/gstv4l2codecmpeg2dec.c b/subprojects/gst-plugins-bad/sys/v4l2codecs/gstv4l2codecmpeg2dec.c index a4aec05..e3bc78a 100644 --- a/subprojects/gst-plugins-bad/sys/v4l2codecs/gstv4l2codecmpeg2dec.c +++ b/subprojects/gst-plugins-bad/sys/v4l2codecs/gstv4l2codecmpeg2dec.c @@ -1048,12 +1048,28 @@ gst_v4l2_codec_mpeg2_dec_subclass_init (GstV4l2CodecMpeg2DecClass * klass, } void -gst_v4l2_codec_mpeg2_dec_register (GstPlugin * plugin, +gst_v4l2_codec_mpeg2_dec_register (GstPlugin * plugin, GstV4l2Decoder * decoder, GstV4l2CodecDevice * device, guint rank) { + GstCaps *src_caps; + + if (!gst_v4l2_decoder_set_sink_fmt (decoder, V4L2_PIX_FMT_MPEG2_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 MPEG2 decoder since it produces no " + "supported format"); + goto done; + } + gst_v4l2_decoder_register (plugin, GST_TYPE_V4L2_CODEC_MPEG2_DEC, (GClassInitFunc) gst_v4l2_codec_mpeg2_dec_subclass_init, gst_mini_object_ref (GST_MINI_OBJECT (device)), (GInstanceInitFunc) gst_v4l2_codec_mpeg2_dec_subinit, "v4l2sl%smpeg2dec", device, rank, NULL); + +done: + gst_caps_unref (src_caps); } diff --git a/subprojects/gst-plugins-bad/sys/v4l2codecs/gstv4l2codecmpeg2dec.h b/subprojects/gst-plugins-bad/sys/v4l2codecs/gstv4l2codecmpeg2dec.h index eb2f8df..3e9c3b5 100644 --- a/subprojects/gst-plugins-bad/sys/v4l2codecs/gstv4l2codecmpeg2dec.h +++ b/subprojects/gst-plugins-bad/sys/v4l2codecs/gstv4l2codecmpeg2dec.h @@ -45,8 +45,9 @@ struct _GstV4l2CodecMpeg2DecClass GType gst_v4l2_codec_mpeg2_dec_get_type (void); void gst_v4l2_codec_mpeg2_dec_register (GstPlugin * plugin, - GstV4l2CodecDevice * device, - guint rank); + GstV4l2Decoder * decoder, + GstV4l2CodecDevice * device, + guint rank); G_END_DECLS diff --git a/subprojects/gst-plugins-bad/sys/v4l2codecs/plugin.c b/subprojects/gst-plugins-bad/sys/v4l2codecs/plugin.c index fc6fe37..79250bb 100644 --- a/subprojects/gst-plugins-bad/sys/v4l2codecs/plugin.c +++ b/subprojects/gst-plugins-bad/sys/v4l2codecs/plugin.c @@ -63,7 +63,7 @@ register_video_decoder (GstPlugin * plugin, GstV4l2CodecDevice * device) case V4L2_PIX_FMT_MPEG2_SLICE: GST_INFO_OBJECT (decoder, "Registering %s as Mpeg2 Decoder", device->name); - gst_v4l2_codec_mpeg2_dec_register (plugin, device, + gst_v4l2_codec_mpeg2_dec_register (plugin, decoder, device, GST_RANK_PRIMARY + 1); break; case V4L2_PIX_FMT_VP9_FRAME: -- 2.7.4