Commit 06424c43 authored by Nicolas Dufresne's avatar Nicolas Dufresne

v4l2: Don't probe for unneeded format

For v4l2videodec/enc, we generate elements per formats, and in
this case we can speed up the start up by only probing the format
we care about.
parent 724a3cee
......@@ -3918,24 +3918,39 @@ gst_v4l2_object_probe_caps (GstV4l2Object * v4l2object, GstCaps * filter)
for (walk = formats; walk; walk = walk->next) {
struct v4l2_fmtdesc *format;
GstStructure *template;
GstCaps *tmp;
format = (struct v4l2_fmtdesc *) walk->data;
template = gst_v4l2_object_v4l2fourcc_to_bare_struct (format->pixelformat);
if (template) {
GstCaps *tmp;
tmp = gst_v4l2_object_probe_caps_for_format (v4l2object,
format->pixelformat, template);
if (tmp)
gst_caps_append (ret, tmp);
gst_structure_free (template);
} else {
if (!template) {
GST_DEBUG_OBJECT (v4l2object->element, "unknown format %u",
format->pixelformat);
continue;
}
/* If we have a filter, check if we need to probe this format or not */
if (filter) {
GstCaps *format_caps = gst_caps_new_empty ();
gst_caps_append_structure (format_caps, gst_structure_copy (template));
if (!gst_caps_can_intersect (format_caps, filter)) {
gst_caps_unref (format_caps);
gst_structure_free (template);
continue;
}
gst_caps_unref (format_caps);
}
tmp = gst_v4l2_object_probe_caps_for_format (v4l2object,
format->pixelformat, template);
if (tmp)
gst_caps_append (ret, tmp);
gst_structure_free (template);
}
if (filter) {
......@@ -3946,6 +3961,8 @@ gst_v4l2_object_probe_caps (GstV4l2Object * v4l2object, GstCaps * filter)
gst_caps_unref (tmp);
}
GST_INFO_OBJECT (v4l2object->element, "probed caps: %" GST_PTR_FORMAT, ret);
return ret;
}
......@@ -3964,8 +3981,6 @@ gst_v4l2_object_get_caps (GstV4l2Object * v4l2object, GstCaps * filter)
ret = gst_caps_ref (v4l2object->probed_caps);
}
GST_INFO_OBJECT (v4l2object->element, "probed caps: %" GST_PTR_FORMAT, ret);
return ret;
}
......
......@@ -113,6 +113,7 @@ static gboolean
gst_v4l2_video_dec_open (GstVideoDecoder * decoder)
{
GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
GstCaps *codec_caps;
GST_DEBUG_OBJECT (self, "Opening");
......@@ -122,13 +123,15 @@ gst_v4l2_video_dec_open (GstVideoDecoder * decoder)
if (!gst_v4l2_object_open_shared (self->v4l2capture, self->v4l2output))
goto failure;
self->probed_sinkcaps = gst_v4l2_object_get_caps (self->v4l2output,
gst_v4l2_object_get_codec_caps ());
codec_caps = gst_pad_get_pad_template_caps (decoder->sinkpad);
self->probed_sinkcaps = gst_v4l2_object_probe_caps (self->v4l2output,
codec_caps);
gst_caps_unref (codec_caps);
if (gst_caps_is_empty (self->probed_sinkcaps))
goto no_encoded_format;
self->probed_srccaps = gst_v4l2_object_get_caps (self->v4l2capture,
self->probed_srccaps = gst_v4l2_object_probe_caps (self->v4l2capture,
gst_v4l2_object_get_raw_caps ());
if (gst_caps_is_empty (self->probed_srccaps))
......
......@@ -113,6 +113,7 @@ static gboolean
gst_v4l2_video_enc_open (GstVideoEncoder * encoder)
{
GstV4l2VideoEnc *self = GST_V4L2_VIDEO_ENC (encoder);
GstCaps *codec_caps;
GST_DEBUG_OBJECT (self, "Opening");
......@@ -122,14 +123,16 @@ gst_v4l2_video_enc_open (GstVideoEncoder * encoder)
if (!gst_v4l2_object_open_shared (self->v4l2capture, self->v4l2output))
goto failure;
self->probed_sinkcaps = gst_v4l2_object_get_caps (self->v4l2output,
self->probed_sinkcaps = gst_v4l2_object_probe_caps (self->v4l2output,
gst_v4l2_object_get_raw_caps ());
if (gst_caps_is_empty (self->probed_sinkcaps))
goto no_raw_format;
self->probed_srccaps = gst_v4l2_object_get_caps (self->v4l2capture,
gst_v4l2_object_get_codec_caps ());
codec_caps = gst_pad_get_pad_template_caps (encoder->srcpad);
self->probed_srccaps = gst_v4l2_object_probe_caps (self->v4l2capture,
codec_caps);
gst_caps_unref (codec_caps);
if (gst_caps_is_empty (self->probed_srccaps))
goto no_encoded_format;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment