3 * unit test for rtpmux elements
5 * Copyright 2009 Collabora Ltd.
6 * @author: Olivier Crete <olivier.crete@collabora.co.uk>
7 * Copyright 2009 Nokia Corp.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
25 #include <gst/check/gstcheck.h>
26 #include <gst/rtp/gstrtpbuffer.h>
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"));
39 typedef void (*check_cb) (GstPad * pad, int i);
42 query_func (GstPad * pad, GstObject * noparent, GstQuery * query)
44 switch (GST_QUERY_TYPE (query)) {
47 GstCaps **caps = g_object_get_data (G_OBJECT (pad), "caps");
49 fail_unless (caps != NULL && *caps != NULL);
50 gst_query_set_caps_result (query, *caps);
61 event_func (GstPad * pad, GstObject * noparent, GstEvent * event)
63 switch (GST_EVENT_TYPE (event)) {
67 GstCaps **caps2 = g_object_get_data (G_OBJECT (pad), "caps");
69 gst_event_parse_caps (event, &caps);
70 fail_unless (caps2 != NULL && *caps2 != NULL);
71 fail_unless (gst_caps_is_equal (caps, *caps2));
75 gst_event_unref (event);
83 test_basic (const gchar * elem_name, const gchar * sink2, int count,
86 GstElement *rtpmux = NULL;
87 GstPad *reqpad1 = NULL;
88 GstPad *reqpad2 = NULL;
92 GstBuffer *inbuf = NULL;
93 GstCaps *src1caps = NULL;
94 GstCaps *src2caps = NULL;
95 GstCaps *sinkcaps = NULL;
100 rtpmux = gst_check_setup_element (elem_name);
102 reqpad1 = gst_element_get_request_pad (rtpmux, "sink_1");
103 fail_unless (reqpad1 != NULL);
104 reqpad2 = gst_element_get_request_pad (rtpmux, sink2);
105 fail_unless (reqpad2 != NULL);
106 sink = gst_check_setup_sink_pad_by_name (rtpmux, &sinktemplate, "src");
108 src1 = gst_pad_new_from_static_template (&srctemplate, "src");
109 src2 = gst_pad_new_from_static_template (&srctemplate, "src");
110 fail_unless (gst_pad_link (src1, reqpad1) == GST_PAD_LINK_OK);
111 fail_unless (gst_pad_link (src2, reqpad2) == GST_PAD_LINK_OK);
112 gst_pad_set_query_function (src1, query_func);
113 gst_pad_set_query_function (src2, query_func);
114 gst_pad_set_query_function (sink, query_func);
115 gst_pad_set_event_function (sink, event_func);
116 g_object_set_data (G_OBJECT (src1), "caps", &src1caps);
117 g_object_set_data (G_OBJECT (src2), "caps", &src2caps);
118 g_object_set_data (G_OBJECT (sink), "caps", &sinkcaps);
120 src1caps = gst_caps_new_simple ("application/x-rtp",
121 "clock-rate", G_TYPE_INT, 1, "ssrc", G_TYPE_UINT, 11, NULL);
122 src2caps = gst_caps_new_simple ("application/x-rtp",
123 "clock-rate", G_TYPE_INT, 2, "ssrc", G_TYPE_UINT, 12, NULL);
124 sinkcaps = gst_caps_new_simple ("application/x-rtp",
125 "clock-rate", G_TYPE_INT, 3, "ssrc", G_TYPE_UINT, 13, NULL);
127 caps = gst_pad_peer_query_caps (src1, NULL);
128 fail_unless (gst_caps_is_empty (caps));
129 gst_caps_unref (caps);
131 gst_caps_set_simple (src2caps, "clock-rate", G_TYPE_INT, 3, NULL);
132 caps = gst_pad_peer_query_caps (src1, NULL);
133 fail_unless (gst_caps_is_equal (caps, sinkcaps));
134 gst_caps_unref (caps);
136 g_object_set (rtpmux, "seqnum-offset", 100, "timestamp-offset", 1000,
139 fail_unless (gst_element_set_state (rtpmux,
140 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS);
141 gst_pad_set_active (sink, TRUE);
142 gst_pad_set_active (src1, TRUE);
143 gst_pad_set_active (src2, TRUE);
145 gst_caps_set_simple (sinkcaps,
146 "payload", G_TYPE_INT, 98, "seqnum-base", G_TYPE_UINT, 100,
147 "clock-base", G_TYPE_UINT, 1000, "ssrc", G_TYPE_UINT, 66, NULL);
148 caps = gst_caps_new_simple ("application/x-rtp",
149 "payload", G_TYPE_INT, 98, "clock-rate", G_TYPE_INT, 3,
150 "seqnum-base", G_TYPE_UINT, 56, "clock-base", G_TYPE_UINT, 57,
151 "ssrc", G_TYPE_UINT, 66, NULL);
152 fail_unless (gst_pad_set_caps (src1, caps));
154 gst_segment_init (&segment, GST_FORMAT_TIME);
155 segment.start = 100000;
156 fail_unless (gst_pad_push_event (src1, gst_event_new_segment (&segment)));
158 fail_unless (gst_pad_push_event (src2, gst_event_new_segment (&segment)));
161 for (i = 0; i < count; i++) {
162 GstRTPBuffer rtpbuffer = GST_RTP_BUFFER_INIT;
164 inbuf = gst_rtp_buffer_new_allocate (10, 0, 0);
165 GST_BUFFER_PTS (inbuf) = i * 1000 + 100000;
166 GST_BUFFER_DURATION (inbuf) = 1000;
168 gst_rtp_buffer_map (inbuf, GST_MAP_WRITE, &rtpbuffer);
170 gst_rtp_buffer_set_version (&rtpbuffer, 2);
171 gst_rtp_buffer_set_payload_type (&rtpbuffer, 98);
172 gst_rtp_buffer_set_ssrc (&rtpbuffer, 44);
173 gst_rtp_buffer_set_timestamp (&rtpbuffer, 200 + i);
174 gst_rtp_buffer_set_seq (&rtpbuffer, 2000 + i);
175 gst_rtp_buffer_unmap (&rtpbuffer);
176 fail_unless (gst_pad_push (src1, inbuf) == GST_FLOW_OK);
179 fail_unless (GST_BUFFER_PTS (buffers->data) == i * 1000, "%lld",
180 GST_BUFFER_PTS (buffers->data));
184 g_list_foreach (buffers, (GFunc) gst_buffer_unref, NULL);
185 g_list_free (buffers);
190 gst_pad_set_active (sink, FALSE);
191 gst_pad_set_active (src1, FALSE);
192 gst_pad_set_active (src2, FALSE);
193 fail_unless (gst_element_set_state (rtpmux,
194 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS);
195 gst_check_teardown_pad_by_name (rtpmux, "src");
196 gst_object_unref (reqpad1);
197 gst_object_unref (reqpad2);
198 gst_check_teardown_pad_by_name (rtpmux, "sink_1");
199 gst_check_teardown_pad_by_name (rtpmux, sink2);
200 gst_element_release_request_pad (rtpmux, reqpad1);
201 gst_element_release_request_pad (rtpmux, reqpad2);
203 gst_caps_unref (caps);
204 gst_caps_replace (&src1caps, NULL);
205 gst_caps_replace (&src2caps, NULL);
206 gst_caps_replace (&sinkcaps, NULL);
208 gst_check_teardown_element (rtpmux);
212 basic_check_cb (GstPad * pad, int i)
214 GstRTPBuffer rtpbuffer = GST_RTP_BUFFER_INIT;
215 fail_unless (buffers && g_list_length (buffers) == 1);
217 gst_rtp_buffer_map (buffers->data, GST_MAP_READ, &rtpbuffer);
218 fail_unless (gst_rtp_buffer_get_ssrc (&rtpbuffer) == 55);
219 fail_unless (gst_rtp_buffer_get_timestamp (&rtpbuffer) ==
220 200 - 57 + 1000 + i);
221 fail_unless (gst_rtp_buffer_get_seq (&rtpbuffer) == 100 + 1 + i);
222 gst_rtp_buffer_unmap (&rtpbuffer);
226 GST_START_TEST (test_rtpmux_basic)
228 test_basic ("rtpmux", "sink_2", 10, basic_check_cb);
233 GST_START_TEST (test_rtpdtmfmux_basic)
235 test_basic ("rtpdtmfmux", "sink_2", 10, basic_check_cb);
241 lock_check_cb (GstPad * pad, int i)
246 fail_unless (buffers == NULL);
248 GstRTPBuffer rtpbuffer = GST_RTP_BUFFER_INIT;
250 fail_unless (buffers && g_list_length (buffers) == 1);
251 gst_rtp_buffer_map (buffers->data, GST_MAP_READ, &rtpbuffer);
252 fail_unless (gst_rtp_buffer_get_ssrc (&rtpbuffer) == 55);
253 fail_unless (gst_rtp_buffer_get_timestamp (&rtpbuffer) ==
254 200 - 57 + 1000 + i);
255 fail_unless (gst_rtp_buffer_get_seq (&rtpbuffer) == 100 + 1 + i);
256 gst_rtp_buffer_unmap (&rtpbuffer);
258 inbuf = gst_rtp_buffer_new_allocate (10, 0, 0);
259 GST_BUFFER_PTS (inbuf) = i * 1000 + 500;
260 GST_BUFFER_DURATION (inbuf) = 1000;
261 gst_rtp_buffer_map (inbuf, GST_MAP_WRITE, &rtpbuffer);
262 gst_rtp_buffer_set_version (&rtpbuffer, 2);
263 gst_rtp_buffer_set_payload_type (&rtpbuffer, 98);
264 gst_rtp_buffer_set_ssrc (&rtpbuffer, 44);
265 gst_rtp_buffer_set_timestamp (&rtpbuffer, 200 + i);
266 gst_rtp_buffer_set_seq (&rtpbuffer, 2000 + i);
267 gst_rtp_buffer_unmap (&rtpbuffer);
268 fail_unless (gst_pad_push (pad, inbuf) == GST_FLOW_OK);
271 g_list_foreach (buffers, (GFunc) gst_buffer_unref, NULL);
272 g_list_free (buffers);
277 GST_START_TEST (test_rtpdtmfmux_lock)
279 test_basic ("rtpdtmfmux", "priority_sink_2", 10, lock_check_cb);
287 Suite *s = suite_create ("rtpmux");
290 tc_chain = tcase_create ("rtpmux_basic");
291 tcase_add_test (tc_chain, test_rtpmux_basic);
292 suite_add_tcase (s, tc_chain);
294 tc_chain = tcase_create ("rtpdtmfmux_basic");
295 tcase_add_test (tc_chain, test_rtpdtmfmux_basic);
296 suite_add_tcase (s, tc_chain);
298 tc_chain = tcase_create ("rtpdtmfmux_lock");
299 tcase_add_test (tc_chain, test_rtpdtmfmux_lock);
300 suite_add_tcase (s, tc_chain);
305 GST_CHECK_MAIN (rtpmux)