From f63bdd04837139492cd2c5620f0870a9862b5dd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Mon, 12 May 2014 17:20:14 +0100 Subject: [PATCH] v4l2src: avoid lists with one single framerate in probed caps Simplify framerate field if possible, so we don't end up with e.g. framerate = (fraction) { 30/1 }. Maybe the helper function should be moved to core, but we can do this later. --- sys/v4l2/gstv4l2object.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/sys/v4l2/gstv4l2object.c b/sys/v4l2/gstv4l2object.c index 77f8aa4b04..920f2cca8c 100644 --- a/sys/v4l2/gstv4l2object.c +++ b/sys/v4l2/gstv4l2object.c @@ -1557,6 +1557,25 @@ cropcap_failed: goto done; } +/* returns TRUE if the value was changed in place, otherwise FALSE */ +static gboolean +gst_v4l2src_value_simplify (GValue * val) +{ + /* simplify list of one value to one value */ + if (GST_VALUE_HOLDS_LIST (val) && gst_value_list_get_size (val) == 1) { + const GValue *list_val; + GValue new_val = G_VALUE_INIT; + + list_val = gst_value_list_get_value (val, 0); + g_value_init (&new_val, G_VALUE_TYPE (list_val)); + g_value_copy (list_val, &new_val); + g_value_unset (val); + *val = new_val; + return TRUE; + } + + return FALSE; +} /* The frame interval enumeration code first appeared in Linux 2.6.19. */ static GstStructure * @@ -1745,6 +1764,7 @@ return_data: (interlaced ? "mixed" : "progressive"), NULL); if (G_IS_VALUE (&rates)) { + gst_v4l2src_value_simplify (&rates); /* only change the framerate on the template when we have a valid probed new * value */ gst_structure_set_value (s, "framerate", &rates);