From 674611c8512aec889fe87fa6c1b4d7d20678da19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Fri, 24 Sep 2021 13:02:13 -0400 Subject: [PATCH] rtphdrext test: Use helper function for caps Also, let the base class parse the direction for us. Part-of: --- .../tests/check/libs/rtpdummyhdrextimpl.c | 50 ++----------------- .../tests/check/libs/rtphdrext.c | 12 +++-- 2 files changed, 10 insertions(+), 52 deletions(-) diff --git a/subprojects/gst-plugins-base/tests/check/libs/rtpdummyhdrextimpl.c b/subprojects/gst-plugins-base/tests/check/libs/rtpdummyhdrextimpl.c index 3144a7c488..4e881acea4 100644 --- a/subprojects/gst-plugins-base/tests/check/libs/rtpdummyhdrextimpl.c +++ b/subprojects/gst-plugins-base/tests/check/libs/rtpdummyhdrextimpl.c @@ -56,7 +56,6 @@ struct _GstRTPDummyHdrExt guint set_attributes_count; guint caps_field_value; - gchar *direction; gchar *attributes; }; @@ -139,8 +138,6 @@ gst_rtp_dummy_hdr_ext_finalize (GObject * object) g_free (dummy->attributes); dummy->attributes = NULL; - g_free (dummy->direction); - dummy->direction = NULL; G_OBJECT_CLASS (gst_rtp_dummy_hdr_ext_parent_class)->finalize (object); } @@ -208,42 +205,9 @@ gst_rtp_dummy_hdr_ext_set_caps_from_attributes (GstRTPHeaderExtension * ext, GstCaps * caps) { GstRTPDummyHdrExt *dummy = GST_RTP_DUMMY_HDR_EXT (ext); - gchar *field_name = gst_rtp_header_extension_get_sdp_caps_field_name (ext); - GstStructure *s = gst_caps_get_structure (caps, 0); - if (!field_name) - return FALSE; - - if (dummy->attributes || dummy->direction) { - GValue arr = G_VALUE_INIT; - GValue val = G_VALUE_INIT; - - g_value_init (&arr, GST_TYPE_ARRAY); - g_value_init (&val, G_TYPE_STRING); - - /* direction */ - g_value_set_string (&val, dummy->direction); - gst_value_array_append_value (&arr, &val); - - /* uri */ - g_value_set_string (&val, gst_rtp_header_extension_get_uri (ext)); - gst_value_array_append_value (&arr, &val); - - /* attributes */ - g_value_set_string (&val, dummy->attributes); - gst_value_array_append_value (&arr, &val); - - gst_structure_set_value (s, field_name, &arr); - - g_value_unset (&val); - g_value_unset (&arr); - } else { - gst_structure_set (s, field_name, G_TYPE_STRING, - gst_rtp_header_extension_get_uri (ext), NULL); - } - - g_free (field_name); - return TRUE; + return gst_rtp_header_extension_set_caps_from_attributes_helper (ext, caps, + dummy->attributes); } static gboolean @@ -253,9 +217,9 @@ gst_rtp_dummy_hdr_ext_set_attributes_from_caps (GstRTPHeaderExtension * ext, GstRTPDummyHdrExt *dummy = GST_RTP_DUMMY_HDR_EXT (ext); gchar *field_name = gst_rtp_header_extension_get_sdp_caps_field_name (ext); GstStructure *s = gst_caps_get_structure (caps, 0); - gchar *new_attrs = NULL, *new_direction = NULL; const gchar *ext_uri; const GValue *arr; + gchar *new_attrs = NULL; dummy->set_attributes_count++; @@ -279,11 +243,6 @@ gst_rtp_dummy_hdr_ext_set_attributes_from_caps (GstRTPHeaderExtension * ext, gst_rtp_header_extension_get_uri (ext)) != 0) goto error; - val = gst_value_array_get_value (arr, 0); - if (!G_VALUE_HOLDS_STRING (val)) - goto error; - new_direction = g_value_dup_string (val); - val = gst_value_array_get_value (arr, 2); if (!G_VALUE_HOLDS_STRING (val)) goto error; @@ -295,15 +254,12 @@ gst_rtp_dummy_hdr_ext_set_attributes_from_caps (GstRTPHeaderExtension * ext, g_free (dummy->attributes); dummy->attributes = new_attrs; - g_free (dummy->direction); - dummy->direction = new_direction; g_free (field_name); return TRUE; error: g_free (field_name); - g_free (new_direction); g_free (new_attrs); return FALSE; } diff --git a/subprojects/gst-plugins-base/tests/check/libs/rtphdrext.c b/subprojects/gst-plugins-base/tests/check/libs/rtphdrext.c index 12464d222d..65d20d0b1a 100644 --- a/subprojects/gst-plugins-base/tests/check/libs/rtphdrext.c +++ b/subprojects/gst-plugins-base/tests/check/libs/rtphdrext.c @@ -95,7 +95,8 @@ GST_START_TEST (rtp_header_ext_caps_with_attributes) gst_rtp_header_extension_set_id (dummy, 1); - GST_RTP_DUMMY_HDR_EXT (dummy)->direction = g_strdup (direction); + gst_rtp_header_extension_set_direction (dummy, + GST_RTP_HEADER_EXTENSION_DIRECTION_RECVONLY); GST_RTP_DUMMY_HDR_EXT (dummy)->attributes = g_strdup (attributes); fail_unless (gst_rtp_header_extension_set_caps_from_attributes (dummy, caps)); @@ -111,8 +112,9 @@ GST_START_TEST (rtp_header_ext_caps_with_attributes) val = gst_value_array_get_value (arr, 2); fail_unless_equals_int (g_strcmp0 (g_value_get_string (val), attributes), 0); - g_free (GST_RTP_DUMMY_HDR_EXT (dummy)->direction); - GST_RTP_DUMMY_HDR_EXT (dummy)->direction = NULL; + gst_rtp_header_extension_set_direction (dummy, + GST_RTP_HEADER_EXTENSION_DIRECTION_SENDRECV | + GST_RTP_HEADER_EXTENSION_DIRECTION_INHERITED); g_free (GST_RTP_DUMMY_HDR_EXT (dummy)->attributes); GST_RTP_DUMMY_HDR_EXT (dummy)->attributes = NULL; @@ -120,8 +122,8 @@ GST_START_TEST (rtp_header_ext_caps_with_attributes) fail_unless_equals_int (g_strcmp0 (GST_RTP_DUMMY_HDR_EXT (dummy)->attributes, attributes), 0); - fail_unless_equals_int (g_strcmp0 (GST_RTP_DUMMY_HDR_EXT (dummy)->direction, - direction), 0); + fail_unless_equals_int (gst_rtp_header_extension_get_direction (dummy), + GST_RTP_HEADER_EXTENSION_DIRECTION_RECVONLY); gst_caps_unref (caps); gst_object_unref (dummy);