4 * Copyright (C) 2014 Axis Communications AB
5 * Author: Guillaume Desmottes <guillaume.desmottes@collabora.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
21 #include <gst/check/gstcheck.h>
22 #include <gst/rtp/gstrtpbuffer.h>
24 /* For ease of programming we use globals to keep refs for our floating
25 * src and sink pads we create; otherwise we always have to do get_pad,
26 * get_peer, and then remove references in every test function */
27 static GstPad *mysrcpad, *mysinkpad;
29 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
32 GST_STATIC_CAPS ("application/x-rtp")
34 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
37 GST_STATIC_CAPS ("application/x-rtp")
40 #define NTP_OFFSET (guint64) 1245
44 setup_element (GstElement * element)
46 mysrcpad = gst_check_setup_src_pad (element, &srctemplate);
47 mysinkpad = gst_check_setup_sink_pad (element, &sinktemplate);
48 gst_pad_set_active (mysrcpad, TRUE);
49 gst_pad_set_active (mysinkpad, TRUE);
51 fail_unless (gst_element_set_state (element,
52 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
53 "could not set to playing");
57 cleanup_element (GstElement * element)
59 fail_unless (gst_element_set_state (element,
60 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
62 gst_pad_set_active (mysrcpad, FALSE);
64 gst_pad_set_active (mysinkpad, FALSE);
65 gst_check_teardown_src_pad (element);
66 gst_check_teardown_sink_pad (element);
67 gst_check_teardown_element (element);
73 convert_to_ntp (guint64 t)
77 /* convert to NTP time. upper 32 bits should contain the seconds
78 * and the lower 32 bits, the fractions of a second. */
79 ntptime = gst_util_uint64_scale (t, (G_GINT64_CONSTANT (1) << 32),
85 /* Create a copy of @buffer_in having the RTP extension */
87 create_extension_buffer (GstBuffer * buffer_in, gboolean clean_point,
88 gboolean end_contiguous, gboolean discont)
90 GstBuffer *buffer_out;
91 GstRTPBuffer rtpbuffer_out = GST_RTP_BUFFER_INIT;
95 buffer_out = gst_buffer_copy (buffer_in);
97 fail_unless (gst_rtp_buffer_map (buffer_out, GST_MAP_READWRITE,
101 gst_rtp_buffer_set_extension_data (&rtpbuffer_out, 0xABAC, 3);
102 fail_unless (gst_rtp_buffer_get_extension (&rtpbuffer_out));
103 gst_rtp_buffer_get_extension_data (&rtpbuffer_out, NULL, (gpointer) & data,
107 GST_WRITE_UINT64_BE (data, convert_to_ntp (buffer_in->pts + NTP_OFFSET));
117 GST_WRITE_UINT8 (data + 8, flags);
120 GST_WRITE_UINT8 (data + 9, 0x78);
122 memset (data + 10, 0, 4);
124 gst_rtp_buffer_unmap (&rtpbuffer_out);
130 setup_rtponvifparse (gboolean set_e_bit)
134 GST_DEBUG ("setup_rtponvifparse");
135 parse = gst_check_setup_element ("rtponvifparse");
137 setup_element (parse);
143 cleanup_rtponvifparse (GstElement * parse)
145 GST_DEBUG ("cleanup_rtponvifparse");
147 cleanup_element (parse);
151 test_parse (gboolean clean_point, gboolean discont)
154 GstBuffer *rtp, *buf;
157 parse = setup_rtponvifparse (FALSE);
159 rtp = gst_rtp_buffer_new_allocate (4, 0, 0);
160 buf = create_extension_buffer (rtp, clean_point, FALSE, discont);
161 gst_buffer_unref (rtp);
164 fail_unless (gst_pad_push_event (mysrcpad,
165 gst_event_new_stream_start ("test")));
168 gst_segment_init (&segment, GST_FORMAT_TIME);
169 fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_segment (&segment)));
172 fail_unless (gst_pad_push (mysrcpad, buf) == GST_FLOW_OK,
173 "failed pushing buffer");
175 g_assert_cmpuint (g_list_length (buffers), ==, 1);
179 g_assert (!GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT));
181 g_assert (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT));
184 g_assert (GST_BUFFER_IS_DISCONT (buf));
186 g_assert (!GST_BUFFER_IS_DISCONT (buf));
188 g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
189 g_list_free (buffers);
192 ASSERT_OBJECT_REFCOUNT (parse, "rtponvifparse", 1);
193 cleanup_rtponvifparse (parse);
196 GST_START_TEST (test_parse_no_flag)
198 test_parse (FALSE, FALSE);
203 GST_START_TEST (test_parse_clean_point)
205 test_parse (TRUE, FALSE);
210 GST_START_TEST (test_parse_discont)
212 test_parse (FALSE, TRUE);
218 onviftimestamp_suite (void)
220 Suite *s = suite_create ("onviftimestamp");
223 tc_chain = tcase_create ("parse");
224 suite_add_tcase (s, tc_chain);
225 tcase_add_test (tc_chain, test_parse_no_flag);
226 tcase_add_test (tc_chain, test_parse_clean_point);
227 tcase_add_test (tc_chain, test_parse_discont);
232 GST_CHECK_MAIN (onviftimestamp);