diff --git a/gst/rawparse/gstrawvideoparse.c b/gst/rawparse/gstrawvideoparse.c index 03baec2435..ab67921678 100644 --- a/gst/rawparse/gstrawvideoparse.c +++ b/gst/rawparse/gstrawvideoparse.c @@ -37,7 +37,7 @@ * * If the properties configuration is used, plane strides and offsets will be * computed by using gst_video_info_set_format(). This can be overridden by passing - * GValueArrays to the plane-offsets and plane-strides properties. When this is + * GstValueArrays to the plane-offsets and plane-strides properties. When this is * done, these custom offsets and strides are used later even if new width, * height, format etc. property values might be set. To switch back to computed * plane strides & offsets, pass NULL to one or both of the plane-offset and @@ -80,10 +80,6 @@ # include "config.h" #endif -/* FIXME: GValueArray is deprecated, but there is currently no viabla alternative - * See https://bugzilla.gnome.org/show_bug.cgi?id=667228 */ -#define GLIB_DISABLE_DEPRECATION_WARNINGS - #include #include "gstrawvideoparse.h" #include "unalignedvideo.h" @@ -292,26 +288,26 @@ gst_raw_video_parse_class_init (GstRawVideoParseClass * klass) ); g_object_class_install_property (object_class, PROP_PLANE_STRIDES, - g_param_spec_value_array ("plane-strides", + gst_param_spec_array ("plane-strides", "Plane strides", - "Strides of the planes in bytes", - g_param_spec_uint ("plane-stride", + "Strides of the planes in bytes (e.g. plane-strides=\"<320,320>\")", + g_param_spec_int ("plane-stride", "Plane stride", "Stride of the n-th plane in bytes (0 = stride equals width*bytes-per-pixel)", - 0, G_MAXUINT, + 0, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS), G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS) ); g_object_class_install_property (object_class, PROP_PLANE_OFFSETS, - g_param_spec_value_array ("plane-offsets", + gst_param_spec_array ("plane-offsets", "Plane offsets", - "Offsets of the planes in bytes", - g_param_spec_uint ("plane-offset", + "Offsets of the planes in bytes (e.g. plane-offset=\"<0,76800>\")", + g_param_spec_int ("plane-offset", "Plane offset", "Offset of the n-th plane in bytes", - 0, G_MAXUINT, + 0, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS), G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS) @@ -508,14 +504,13 @@ gst_raw_video_parse_set_property (GObject * object, guint prop_id, case PROP_PLANE_STRIDES: { - GValueArray *valarray = g_value_get_boxed (value); guint n_planes; guint i; - /* If no valarray is given, then disable custom + /* If no array is given, then disable custom * plane strides & offsets and stick to the * standard computed ones */ - if (valarray == NULL) { + if (gst_value_array_get_size (value) == 0) { GST_DEBUG_OBJECT (raw_video_parse, "custom plane strides & offsets disabled"); props_cfg->custom_plane_strides = FALSE; @@ -523,30 +518,24 @@ gst_raw_video_parse_set_property (GObject * object, guint prop_id, break; } - /* Sanity check - reject empty arrays */ - if ((valarray != NULL) && (valarray->n_values == 0)) { - GST_ELEMENT_ERROR (raw_video_parse, LIBRARY, SETTINGS, - ("plane strides property holds an empty array"), (NULL)); - break; - } - GST_RAW_BASE_PARSE_CONFIG_MUTEX_LOCK (object); n_planes = GST_VIDEO_INFO_N_PLANES (&(props_cfg->info)); - /* Check that the valarray holds the right number of values */ - if (valarray->n_values != n_planes) { + /* Check that the array holds the right number of values */ + if (gst_value_array_get_size (value) < n_planes) { GST_ELEMENT_ERROR (raw_video_parse, LIBRARY, SETTINGS, ("incorrect number of elements in plane strides property"), - ("expected: %u, got: %u", n_planes, valarray->n_values)); + ("expected: %u, got: %u", n_planes, + gst_value_array_get_size (value))); GST_RAW_BASE_PARSE_CONFIG_MUTEX_UNLOCK (object); break; } /* Copy the values to the stride array */ for (i = 0; i < n_planes; ++i) { - GValue *val = g_value_array_get_nth (valarray, i); - props_cfg->plane_strides[i] = g_value_get_uint (val); + const GValue *val = gst_value_array_get_value (value, i); + props_cfg->plane_strides[i] = g_value_get_int (val); GST_DEBUG_OBJECT (raw_video_parse, "plane #%u stride: %d", i, props_cfg->plane_strides[i]); } @@ -566,14 +555,13 @@ gst_raw_video_parse_set_property (GObject * object, guint prop_id, case PROP_PLANE_OFFSETS: { - GValueArray *valarray = g_value_get_boxed (value); guint n_planes; guint i; - /* If no valarray is given, then disable custom + /* If no array is given, then disable custom * plane strides & offsets and stick to the * standard computed ones */ - if (valarray == NULL) { + if (gst_value_array_get_size (value) == 0) { GST_DEBUG_OBJECT (raw_video_parse, "custom plane strides & offsets disabled"); props_cfg->custom_plane_strides = FALSE; @@ -581,30 +569,24 @@ gst_raw_video_parse_set_property (GObject * object, guint prop_id, break; } - /* Sanity check - reject empty arrays */ - if ((valarray != NULL) && (valarray->n_values == 0)) { - GST_ELEMENT_ERROR (raw_video_parse, LIBRARY, SETTINGS, - ("plane offsets property holds an empty array"), (NULL)); - break; - } - GST_RAW_BASE_PARSE_CONFIG_MUTEX_LOCK (object); n_planes = GST_VIDEO_INFO_N_PLANES (&(props_cfg->info)); - /* Check that the valarray holds the right number of values */ - if (valarray->n_values != n_planes) { + /* Check that the alarray holds the right number of values */ + if (gst_value_array_get_size (value) < n_planes) { GST_ELEMENT_ERROR (raw_video_parse, LIBRARY, SETTINGS, ("incorrect number of elements in plane offsets property"), - ("expected: %u, got: %u", n_planes, valarray->n_values)); + ("expected: %u, got: %u", n_planes, + gst_value_array_get_size (value))); GST_RAW_BASE_PARSE_CONFIG_MUTEX_UNLOCK (object); break; } /* Copy the values to the offset array */ for (i = 0; i < n_planes; ++i) { - GValue *val = g_value_array_get_nth (valarray, i); - props_cfg->plane_offsets[i] = g_value_get_uint (val); + const GValue *val = gst_value_array_get_value (value, i); + props_cfg->plane_offsets[i] = g_value_get_int (val); GST_DEBUG_OBJECT (raw_video_parse, "plane #%u offset: %" G_GSIZE_FORMAT, i, props_cfg->plane_offsets[i]); } @@ -702,26 +684,22 @@ gst_raw_video_parse_get_property (GObject * object, guint prop_id, { guint i, n_planes; GValue val = G_VALUE_INIT; - GValueArray *valarray; + + g_value_reset (value); GST_RAW_BASE_PARSE_CONFIG_MUTEX_LOCK (object); n_planes = GST_VIDEO_INFO_N_PLANES (&(props_cfg->info)); - valarray = g_value_array_new (n_planes); - g_value_init (&val, G_TYPE_UINT); + g_value_init (&val, G_TYPE_INT); for (i = 0; i < n_planes; ++i) { - g_value_set_uint (&val, props_cfg->plane_strides[i]); - g_value_array_insert (valarray, i, &val); + g_value_set_int (&val, props_cfg->plane_strides[i]); + gst_value_array_append_value (value, &val); } g_value_unset (&val); GST_RAW_BASE_PARSE_CONFIG_MUTEX_UNLOCK (object); - - /* Pass on ownership to the value array, - * since we don't need it anymore */ - g_value_take_boxed (value, valarray); break; } @@ -729,26 +707,22 @@ gst_raw_video_parse_get_property (GObject * object, guint prop_id, { guint i, n_planes; GValue val = G_VALUE_INIT; - GValueArray *valarray; + + g_value_reset (value); GST_RAW_BASE_PARSE_CONFIG_MUTEX_LOCK (object); n_planes = GST_VIDEO_INFO_N_PLANES (&(props_cfg->info)); - valarray = g_value_array_new (n_planes); - g_value_init (&val, G_TYPE_UINT); + g_value_init (&val, G_TYPE_INT); for (i = 0; i < n_planes; ++i) { - g_value_set_uint (&val, props_cfg->plane_offsets[i]); - g_value_array_insert (valarray, i, &val); + g_value_set_int (&val, props_cfg->plane_offsets[i]); + gst_value_array_append_value (value, &val); } g_value_unset (&val); GST_RAW_BASE_PARSE_CONFIG_MUTEX_UNLOCK (object); - - /* Pass on ownership to the value array, - * since we don't need it anymore */ - g_value_take_boxed (value, valarray); break; } diff --git a/tests/check/elements/rawvideoparse.c b/tests/check/elements/rawvideoparse.c index bca199921e..19aacd934b 100644 --- a/tests/check/elements/rawvideoparse.c +++ b/tests/check/elements/rawvideoparse.c @@ -20,10 +20,6 @@ * Boston, MA 02110-1301, USA. */ -/* FIXME: GValueArray is deprecated, but there is currently no viabla alternative - * See https://bugzilla.gnome.org/show_bug.cgi?id=667228 */ -#define GLIB_DISABLE_DEPRECATION_WARNINGS - #include #include @@ -177,42 +173,50 @@ setup_rawvideoparse (gboolean use_sink_caps, g_object_set (G_OBJECT (rawvideoparse), "use-sink-caps", use_sink_caps, NULL); if (set_properties) { - GValueArray *plane_offsets, *plane_strides; + GValue plane_offsets = G_VALUE_INIT; + GValue plane_strides = G_VALUE_INIT; GValue val = G_VALUE_INIT; - g_value_init (&val, G_TYPE_UINT); + g_value_init (&val, G_TYPE_INT); + g_value_init (&plane_offsets, GST_TYPE_ARRAY); + g_value_init (&plane_strides, GST_TYPE_ARRAY); - plane_offsets = g_value_array_new (NUM_TEST_PLANES); for (i = 0; i < NUM_TEST_PLANES; ++i) { - g_value_set_uint (&val, properties_ctx.plane_size * i); - g_value_array_insert (plane_offsets, i, &val); + g_value_set_int (&val, properties_ctx.plane_size * i); + gst_value_array_append_value (&plane_offsets, &val); } - plane_strides = g_value_array_new (NUM_TEST_PLANES); for (i = 0; i < NUM_TEST_PLANES; ++i) { - g_value_set_uint (&val, properties_ctx.plane_stride); - g_value_array_insert (plane_strides, i, &val); + g_value_set_int (&val, properties_ctx.plane_stride); + gst_value_array_append_value (&plane_strides, &val); } g_value_unset (&val); g_object_set (G_OBJECT (rawvideoparse), "width", TEST_WIDTH, "height", TEST_HEIGHT, "frame-stride", PROP_CTX_FRAME_STRIDE, "framerate", - TEST_FRAMERATE_N, TEST_FRAMERATE_D, "plane-offsets", plane_offsets, - "plane-strides", plane_strides, "format", TEST_FRAME_FORMAT, NULL); + TEST_FRAMERATE_N, TEST_FRAMERATE_D, "format", TEST_FRAME_FORMAT, NULL); + g_object_set_property (G_OBJECT (rawvideoparse), "plane-offsets", + &plane_offsets); + g_object_set_property (G_OBJECT (rawvideoparse), "plane-strides", + &plane_strides); - g_value_array_free (plane_offsets); - g_value_array_free (plane_strides); + g_value_unset (&plane_offsets); + g_value_unset (&plane_strides); } /* Check that the plane stride/offset values are correct */ { - GValueArray *plane_offsets_array; - GValueArray *plane_strides_array; + GValue plane_offsets_array = G_VALUE_INIT; + GValue plane_strides_array = G_VALUE_INIT; + /* By default, 320x240 i420 is used as format */ guint plane_offsets[3] = { 0, 76800, 96000 }; guint plane_strides[3] = { 320, 160, 160 }; + g_value_init (&plane_offsets_array, GST_TYPE_ARRAY); + g_value_init (&plane_strides_array, GST_TYPE_ARRAY); + if (set_properties) { /* When properties are explicitely set, we use Y444 as video format, * so in that case, plane stride values are all the same */ @@ -223,27 +227,28 @@ setup_rawvideoparse (gboolean use_sink_caps, properties_ctx.plane_stride; } - g_object_get (G_OBJECT (rawvideoparse), "plane-offsets", - &plane_offsets_array, "plane-strides", &plane_strides_array, NULL); - fail_unless (plane_offsets_array != NULL); - fail_unless (plane_strides_array != NULL); - fail_unless (plane_offsets_array->n_values == - plane_strides_array->n_values); + g_object_get_property (G_OBJECT (rawvideoparse), "plane-offsets", + &plane_offsets_array); + g_object_get_property (G_OBJECT (rawvideoparse), "plane-strides", + &plane_strides_array); - for (i = 0; i < plane_offsets_array->n_values; ++i) { - GValue *gvalue; + fail_unless (gst_value_array_get_size (&plane_offsets_array) == + gst_value_array_get_size (&plane_strides_array)); - gvalue = g_value_array_get_nth (plane_offsets_array, i); + for (i = 0; i < gst_value_array_get_size (&plane_offsets_array); ++i) { + const GValue *gvalue; + + gvalue = gst_value_array_get_value (&plane_offsets_array, i); fail_unless (gvalue != NULL); - fail_unless_equals_uint64 (plane_offsets[i], g_value_get_uint (gvalue)); + fail_unless_equals_uint64 (plane_offsets[i], g_value_get_int (gvalue)); - gvalue = g_value_array_get_nth (plane_strides_array, i); + gvalue = gst_value_array_get_value (&plane_strides_array, i); fail_unless (gvalue != NULL); - fail_unless_equals_uint64 (plane_strides[i], g_value_get_uint (gvalue)); + fail_unless_equals_uint64 (plane_strides[i], g_value_get_int (gvalue)); } - g_value_array_free (plane_offsets_array); - g_value_array_free (plane_strides_array); + g_value_unset (&plane_offsets_array); + g_value_unset (&plane_strides_array); } fail_unless (gst_element_set_state (rawvideoparse, @@ -459,13 +464,15 @@ GST_START_TEST (test_computed_plane_strides) /* Test how plane strides & offsets are (re)computed if custom offsets/strides * are disabled, and how they are preserved if they are enabled. */ - GValueArray *plane_offsets_array; - GValueArray *plane_strides_array; + GValue plane_offsets_array = G_VALUE_INIT; + GValue plane_strides_array = G_VALUE_INIT; guint i; guint const expected_comp_psize = TEST_WIDTH * TEST_HEIGHT; - setup_rawvideoparse (FALSE, TRUE, NULL, GST_FORMAT_BYTES); + g_value_init (&plane_offsets_array, GST_TYPE_ARRAY); + g_value_init (&plane_strides_array, GST_TYPE_ARRAY); + setup_rawvideoparse (FALSE, TRUE, NULL, GST_FORMAT_BYTES); /* The setup set a custom set of plane offsets and strides together with * width=TEST_WIDTH and height=TEST_HEIGHT. Check that the offsets & strides @@ -474,34 +481,36 @@ GST_START_TEST (test_computed_plane_strides) g_object_set (G_OBJECT (rawvideoparse), "width", TEST_WIDTH * 2, "height", TEST_HEIGHT * 2, NULL); - g_object_get (G_OBJECT (rawvideoparse), "plane-offsets", - &plane_offsets_array, "plane-strides", &plane_strides_array, NULL); + g_object_get_property (G_OBJECT (rawvideoparse), "plane-offsets", + &plane_offsets_array); + g_object_get_property (G_OBJECT (rawvideoparse), "plane-strides", + &plane_strides_array); - for (i = 0; i < plane_offsets_array->n_values; ++i) { - GValue *gvalue; + for (i = 0; i < gst_value_array_get_size (&plane_offsets_array); ++i) { + const GValue *gvalue; /* See setup_rawvideoparse() for how the offsets & strides are defined * there. Offsets are set to plane_size*plane_index, and strides are * set to the properties_ctx.plane_stride value. */ - gvalue = g_value_array_get_nth (plane_offsets_array, i); + gvalue = gst_value_array_get_value (&plane_offsets_array, i); fail_unless (gvalue != NULL); fail_unless_equals_uint64 (properties_ctx.plane_size * i, - g_value_get_uint (gvalue)); + g_value_get_int (gvalue)); - gvalue = g_value_array_get_nth (plane_strides_array, i); + gvalue = gst_value_array_get_value (&plane_strides_array, i); fail_unless (gvalue != NULL); fail_unless_equals_uint64 (properties_ctx.plane_stride, - g_value_get_uint (gvalue)); + g_value_get_int (gvalue)); } - g_value_array_free (plane_offsets_array); - g_value_array_free (plane_strides_array); - - /* Discard the custom planes&offsets, re-enabling computed values. */ - g_object_set (G_OBJECT (rawvideoparse), "plane-offsets", (GValueArray *) NULL, - "plane-strides", (GValueArray *) NULL, NULL); + g_value_reset (&plane_offsets_array); + g_value_reset (&plane_strides_array); + g_object_set_property (G_OBJECT (rawvideoparse), "plane-offsets", + &plane_offsets_array); + g_object_set_property (G_OBJECT (rawvideoparse), "plane-strides", + &plane_strides_array); /* The strides & offsets should have been recomputed by now. Since the Y444 @@ -510,24 +519,26 @@ GST_START_TEST (test_computed_plane_strides) * plane_size*plane_index, with plane_size set to (TEST_WIDTH*2 * TEST_HEIGHT*2), * or TEST_WIDTH*TEST_HEIGHT*4 (-> expected_comp_psize*4). */ - g_object_get (G_OBJECT (rawvideoparse), "plane-offsets", - &plane_offsets_array, "plane-strides", &plane_strides_array, NULL); + g_object_get_property (G_OBJECT (rawvideoparse), "plane-offsets", + &plane_offsets_array); + g_object_get_property (G_OBJECT (rawvideoparse), "plane-strides", + &plane_strides_array); - for (i = 0; i < plane_offsets_array->n_values; ++i) { - GValue *gvalue; + for (i = 0; i < gst_value_array_get_size (&plane_offsets_array); ++i) { + const GValue *gvalue; - gvalue = g_value_array_get_nth (plane_offsets_array, i); + gvalue = gst_value_array_get_value (&plane_offsets_array, i); fail_unless (gvalue != NULL); fail_unless_equals_uint64 (expected_comp_psize * 4 * i, - g_value_get_uint (gvalue)); + g_value_get_int (gvalue)); - gvalue = g_value_array_get_nth (plane_strides_array, i); + gvalue = gst_value_array_get_value (&plane_strides_array, i); fail_unless (gvalue != NULL); - fail_unless_equals_uint64 (TEST_WIDTH * 2, g_value_get_uint (gvalue)); + fail_unless_equals_uint64 (TEST_WIDTH * 2, g_value_get_int (gvalue)); } - g_value_array_free (plane_offsets_array); - g_value_array_free (plane_strides_array); + g_value_reset (&plane_offsets_array); + g_value_reset (&plane_strides_array); /* Again change the width & height values. width=TEST_WIDTH, height=TEST_HEIGHT. @@ -540,25 +551,26 @@ GST_START_TEST (test_computed_plane_strides) "height", TEST_HEIGHT, NULL); - g_object_get (G_OBJECT (rawvideoparse), "plane-offsets", - &plane_offsets_array, "plane-strides", &plane_strides_array, NULL); + g_object_get_property (G_OBJECT (rawvideoparse), "plane-offsets", + &plane_offsets_array); + g_object_get_property (G_OBJECT (rawvideoparse), "plane-strides", + &plane_strides_array); - for (i = 0; i < plane_offsets_array->n_values; ++i) { - GValue *gvalue; + for (i = 0; i < gst_value_array_get_size (&plane_offsets_array); ++i) { + const GValue *gvalue; - gvalue = g_value_array_get_nth (plane_offsets_array, i); + gvalue = gst_value_array_get_value (&plane_offsets_array, i); fail_unless (gvalue != NULL); fail_unless_equals_uint64 (expected_comp_psize * i, - g_value_get_uint (gvalue)); + g_value_get_int (gvalue)); - gvalue = g_value_array_get_nth (plane_strides_array, i); + gvalue = gst_value_array_get_value (&plane_strides_array, i); fail_unless (gvalue != NULL); - fail_unless_equals_uint64 (TEST_WIDTH, g_value_get_uint (gvalue)); + fail_unless_equals_uint64 (TEST_WIDTH, g_value_get_int (gvalue)); } - g_value_array_free (plane_offsets_array); - g_value_array_free (plane_strides_array); - + g_value_unset (&plane_offsets_array); + g_value_unset (&plane_strides_array); cleanup_rawvideoparse (); }