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: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2272>
This commit is contained in:
Nicolas Dufresne 2021-05-27 16:22:42 -04:00
parent 9e86ac4a22
commit 49992be643
5 changed files with 49 additions and 8 deletions

View file

@ -1401,13 +1401,29 @@ gst_v4l2_codec_h264_dec_subclass_init (GstV4l2CodecH264DecClass * klass,
} }
void void
gst_v4l2_codec_h264_dec_register (GstPlugin * plugin, gst_v4l2_codec_h264_dec_register (GstPlugin * plugin, GstV4l2Decoder * decoder,
GstV4l2CodecDevice * device, guint rank) 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_v4l2_decoder_register (plugin,
GST_TYPE_V4L2_CODEC_H264_DEC, GST_TYPE_V4L2_CODEC_H264_DEC,
(GClassInitFunc) gst_v4l2_codec_h264_dec_subclass_init, (GClassInitFunc) gst_v4l2_codec_h264_dec_subclass_init,
gst_mini_object_ref (GST_MINI_OBJECT (device)), gst_mini_object_ref (GST_MINI_OBJECT (device)),
(GInstanceInitFunc) gst_v4l2_codec_h264_dec_subinit, (GInstanceInitFunc) gst_v4l2_codec_h264_dec_subinit,
"v4l2sl%sh264dec", device, rank, NULL); "v4l2sl%sh264dec", device, rank, NULL);
done:
gst_caps_unref (src_caps);
} }

View file

@ -45,6 +45,7 @@ struct _GstV4l2CodecH264DecClass
GType gst_v4l2_codec_h264_dec_get_type (void); GType gst_v4l2_codec_h264_dec_get_type (void);
void gst_v4l2_codec_h264_dec_register (GstPlugin * plugin, void gst_v4l2_codec_h264_dec_register (GstPlugin * plugin,
GstV4l2Decoder * decoder,
GstV4l2CodecDevice * device, GstV4l2CodecDevice * device,
guint rank); guint rank);

View file

@ -872,10 +872,22 @@ static void gst_v4l2_codec_vp8_alpha_decode_bin_subclass_init
} }
void void
gst_v4l2_codec_vp8_dec_register (GstPlugin * plugin, gst_v4l2_codec_vp8_dec_register (GstPlugin * plugin, GstV4l2Decoder * decoder,
GstV4l2CodecDevice * device, guint rank) GstV4l2CodecDevice * device, guint rank)
{ {
gchar *element_name; 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, gst_v4l2_decoder_register (plugin, GST_TYPE_V4L2_CODEC_VP8_DEC,
(GClassInitFunc) gst_v4l2_codec_vp8_dec_subclass_init, (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, (GInstanceInitFunc) gst_v4l2_codec_vp8_dec_subinit,
"v4l2sl%svp8dec", device, rank, &element_name); "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, gst_v4l2_codec_alpha_decode_bin_register (plugin,
(GClassInitFunc) gst_v4l2_codec_vp8_alpha_decode_bin_subclass_init, (GClassInitFunc) gst_v4l2_codec_vp8_alpha_decode_bin_subclass_init,
element_name, "v4l2slvp8%salphadecodebin", device, rank); element_name, "v4l2slvp8%salphadecodebin", device, rank);
}
gst_caps_unref (alpha_caps);
done:
gst_caps_unref (src_caps);
} }

View file

@ -45,6 +45,7 @@ struct _GstV4l2CodecVp8DecClass
GType gst_v4l2_codec_vp8_dec_get_type (void); GType gst_v4l2_codec_vp8_dec_get_type (void);
void gst_v4l2_codec_vp8_dec_register (GstPlugin * plugin, void gst_v4l2_codec_vp8_dec_register (GstPlugin * plugin,
GstV4l2Decoder * decoder,
GstV4l2CodecDevice * device, GstV4l2CodecDevice * device,
guint rank); guint rank);

View file

@ -50,12 +50,14 @@ register_video_decoder (GstPlugin * plugin, GstV4l2CodecDevice * device)
case V4L2_PIX_FMT_H264_SLICE: case V4L2_PIX_FMT_H264_SLICE:
GST_INFO_OBJECT (decoder, "Registering %s as H264 Decoder", GST_INFO_OBJECT (decoder, "Registering %s as H264 Decoder",
device->name); 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; break;
case V4L2_PIX_FMT_VP8_FRAME: case V4L2_PIX_FMT_VP8_FRAME:
GST_INFO_OBJECT (decoder, "Registering %s as VP8 Decoder", GST_INFO_OBJECT (decoder, "Registering %s as VP8 Decoder",
device->name); 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; break;
default: default:
GST_FIXME_OBJECT (decoder, "%" GST_FOURCC_FORMAT " is not supported.", GST_FIXME_OBJECT (decoder, "%" GST_FOURCC_FORMAT " is not supported.",