v4l2codecs: mpeg2: Check that the decoder output formats
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Fri, 10 Dec 2021 19:07:18 +0000 (14:07 -0500)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Fri, 10 Dec 2021 21:37:14 +0000 (21:37 +0000)
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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1439>

subprojects/gst-plugins-bad/sys/v4l2codecs/gstv4l2codecmpeg2dec.c
subprojects/gst-plugins-bad/sys/v4l2codecs/gstv4l2codecmpeg2dec.h
subprojects/gst-plugins-bad/sys/v4l2codecs/plugin.c

index a4aec05..e3bc78a 100644 (file)
@@ -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);
 }
index eb2f8df..3e9c3b5 100644 (file)
@@ -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
 
index fc6fe37..79250bb 100644 (file)
@@ -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: