• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer RTP header extension unit tests
2  * Copyright (C) 2020 Matthew Waters <matthew@centricular.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General
15  * Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 #include "gst/gstcaps.h"
21 #include "gst/gstvalue.h"
22 #include "gst/rtp/gstrtphdrext.h"
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26 
27 #include <gst/gst.h>
28 #include <gst/check/check.h>
29 #include <gst/rtp/rtp.h>
30 
31 #include "rtpdummyhdrextimpl.c"
32 
GST_START_TEST(rtp_header_ext_write)33 GST_START_TEST (rtp_header_ext_write)
34 {
35   GstRTPHeaderExtension *dummy;
36   GstBuffer *buffer;
37   guint8 *data;
38   gsize size;
39   gssize written;
40 
41   dummy = rtp_dummy_hdr_ext_new ();
42   gst_rtp_header_extension_set_id (dummy, 1);
43 
44   buffer = gst_buffer_new ();
45   size = gst_rtp_header_extension_get_max_size (dummy, buffer);
46   fail_unless (size > 0);
47 
48   data = g_malloc0 (size);
49   fail_unless (data != NULL);
50 
51   written =
52       gst_rtp_header_extension_write (dummy, buffer, 0, buffer, data, size);
53   fail_unless (written > 0 && written <= size);
54   fail_unless_equals_int (GST_RTP_DUMMY_HDR_EXT (dummy)->write_count, 1);
55 
56   fail_unless (gst_rtp_header_extension_read (dummy, 0, data, size, buffer));
57   fail_unless_equals_int (GST_RTP_DUMMY_HDR_EXT (dummy)->read_count, 1);
58 
59   g_free (data);
60   gst_buffer_unref (buffer);
61   g_object_unref (dummy);
62 }
63 
64 GST_END_TEST;
65 
GST_START_TEST(rtp_header_ext_create_from_uri)66 GST_START_TEST (rtp_header_ext_create_from_uri)
67 {
68   GstElementFactory *factory;
69   GstRTPHeaderExtension *dummy;
70 
71   fail_unless (gst_element_register (NULL, "test-dummyrtphdrext",
72           GST_RANK_MARGINAL, GST_TYPE_RTP_DUMMY_HDR_EXT));
73 
74   dummy = gst_rtp_header_extension_create_from_uri (DUMMY_HDR_EXT_URI);
75   fail_unless (GST_IS_RTP_DUMMY_HDR_EXT (dummy));
76 
77   factory = gst_element_get_factory (GST_ELEMENT (dummy));
78   gst_registry_remove_feature (gst_registry_get (),
79       GST_PLUGIN_FEATURE (factory));
80   gst_object_unref (dummy);
81 }
82 
83 GST_END_TEST;
84 
GST_START_TEST(rtp_header_ext_caps_with_attributes)85 GST_START_TEST (rtp_header_ext_caps_with_attributes)
86 {
87   GstRTPHeaderExtension *dummy;
88   GstCaps *caps = gst_caps_new_empty_simple ("application/x-rtp");
89   GstStructure *s = gst_caps_get_structure (caps, 0);
90   const GValue *arr, *val;
91   const gchar *attributes = "attr0 attr1";
92   const gchar *direction = "recvonly";
93 
94   dummy = rtp_dummy_hdr_ext_new ();
95 
96   gst_rtp_header_extension_set_id (dummy, 1);
97 
98   gst_rtp_header_extension_set_direction (dummy,
99       GST_RTP_HEADER_EXTENSION_DIRECTION_RECVONLY);
100   GST_RTP_DUMMY_HDR_EXT (dummy)->attributes = g_strdup (attributes);
101 
102   fail_unless (gst_rtp_header_extension_set_caps_from_attributes (dummy, caps));
103   fail_unless (gst_structure_has_field_typed (s, "extmap-1", GST_TYPE_ARRAY));
104   arr = gst_structure_get_value (s, "extmap-1");
105   fail_unless (GST_VALUE_HOLDS_ARRAY (arr));
106   fail_unless_equals_int (gst_value_array_get_size (arr), 3);
107   val = gst_value_array_get_value (arr, 0);
108   fail_unless_equals_string (g_value_get_string (val), direction);
109   val = gst_value_array_get_value (arr, 1);
110   fail_unless_equals_string (g_value_get_string (val),
111       gst_rtp_header_extension_get_uri (dummy));
112   val = gst_value_array_get_value (arr, 2);
113   fail_unless_equals_string (g_value_get_string (val), attributes);
114 
115   gst_rtp_header_extension_set_direction (dummy,
116       GST_RTP_HEADER_EXTENSION_DIRECTION_SENDRECV |
117       GST_RTP_HEADER_EXTENSION_DIRECTION_INHERITED);
118   g_free (GST_RTP_DUMMY_HDR_EXT (dummy)->attributes);
119   GST_RTP_DUMMY_HDR_EXT (dummy)->attributes = NULL;
120 
121   fail_unless (gst_rtp_header_extension_set_attributes_from_caps (dummy, caps));
122 
123   fail_unless_equals_string (GST_RTP_DUMMY_HDR_EXT (dummy)->attributes,
124       attributes);
125   fail_unless_equals_int (gst_rtp_header_extension_get_direction (dummy),
126       GST_RTP_HEADER_EXTENSION_DIRECTION_RECVONLY);
127 
128   gst_caps_unref (caps);
129   gst_object_unref (dummy);
130 }
131 
132 GST_END_TEST;
133 
134 static Suite *
rtp_header_extension_suite(void)135 rtp_header_extension_suite (void)
136 {
137   Suite *s = suite_create ("rtp_header_extension_test");
138   TCase *tc_chain = tcase_create ("header extension test");
139 
140   suite_add_tcase (s, tc_chain);
141   tcase_add_test (tc_chain, rtp_header_ext_write);
142   tcase_add_test (tc_chain, rtp_header_ext_create_from_uri);
143   tcase_add_test (tc_chain, rtp_header_ext_caps_with_attributes);
144 
145   return s;
146 }
147 
148 GST_CHECK_MAIN (rtp_header_extension)
149