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 getcaps_func (GstPad * pad)
44 GstCaps **caps = g_object_get_data (G_OBJECT (pad), "caps");
46 fail_unless (caps != NULL && *caps != NULL);
48 return gst_caps_ref (*caps);
52 setcaps_func (GstPad * pad, GstCaps * caps)
54 GstCaps **caps2 = g_object_get_data (G_OBJECT (pad), "caps");
56 fail_unless (caps2 != NULL && *caps2 != NULL);
58 fail_unless (gst_caps_is_equal (caps, *caps2));
64 event_func (GstPad * pad, GstEvent * event)
66 gst_event_unref (event);
72 test_basic (const gchar * elem_name, const gchar * sink2, int count,
75 GstElement *rtpmux = NULL;
76 GstPad *reqpad1 = NULL;
77 GstPad *reqpad2 = NULL;
81 GstBuffer *inbuf = NULL;
82 GstCaps *src1caps = NULL;
83 GstCaps *src2caps = NULL;
84 GstCaps *sinkcaps = NULL;
89 rtpmux = gst_check_setup_element (elem_name);
91 reqpad1 = gst_element_get_request_pad (rtpmux, "sink_1");
92 fail_unless (reqpad1 != NULL);
93 reqpad2 = gst_element_get_request_pad (rtpmux, sink2);
94 fail_unless (reqpad2 != NULL);
95 sink = gst_check_setup_sink_pad_by_name (rtpmux, &sinktemplate, "src");
97 src1 = gst_pad_new_from_static_template (&srctemplate, "src");
98 src2 = gst_pad_new_from_static_template (&srctemplate, "src");
99 fail_unless (gst_pad_link (src1, reqpad1) == GST_PAD_LINK_OK);
100 fail_unless (gst_pad_link (src2, reqpad2) == GST_PAD_LINK_OK);
101 gst_pad_set_getcaps_function (src1, getcaps_func);
102 gst_pad_set_getcaps_function (src2, getcaps_func);
103 gst_pad_set_getcaps_function (sink, getcaps_func);
104 gst_pad_set_setcaps_function (sink, setcaps_func);
105 gst_pad_set_event_function (sink, event_func);
106 g_object_set_data (G_OBJECT (src1), "caps", &src1caps);
107 g_object_set_data (G_OBJECT (src2), "caps", &src2caps);
108 g_object_set_data (G_OBJECT (sink), "caps", &sinkcaps);
110 src1caps = gst_caps_new_simple ("application/x-rtp",
111 "clock-rate", G_TYPE_INT, 1, "ssrc", G_TYPE_UINT, 11, NULL);
112 src2caps = gst_caps_new_simple ("application/x-rtp",
113 "clock-rate", G_TYPE_INT, 2, "ssrc", G_TYPE_UINT, 12, NULL);
114 sinkcaps = gst_caps_new_simple ("application/x-rtp",
115 "clock-rate", G_TYPE_INT, 3, "ssrc", G_TYPE_UINT, 13, NULL);
117 caps = gst_pad_peer_get_caps (src1);
118 fail_unless (gst_caps_is_empty (caps));
119 gst_caps_unref (caps);
121 gst_caps_set_simple (src2caps, "clock-rate", G_TYPE_INT, 3, NULL);
122 caps = gst_pad_peer_get_caps (src1);
123 fail_unless (gst_caps_is_equal (caps, sinkcaps));
124 gst_caps_unref (caps);
126 g_object_set (rtpmux, "seqnum-offset", 100, "timestamp-offset", 1000,
129 fail_unless (gst_element_set_state (rtpmux,
130 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS);
131 gst_pad_set_active (sink, TRUE);
132 gst_pad_set_active (src1, TRUE);
133 gst_pad_set_active (src2, TRUE);
135 gst_caps_set_simple (sinkcaps,
136 "payload", G_TYPE_INT, 98, "seqnum-base", G_TYPE_UINT, 100,
137 "clock-base", G_TYPE_UINT, 1000, "ssrc", G_TYPE_UINT, 66, NULL);
138 caps = gst_caps_new_simple ("application/x-rtp",
139 "payload", G_TYPE_INT, 98, "clock-rate", G_TYPE_INT, 3,
140 "seqnum-base", G_TYPE_UINT, 56, "clock-base", G_TYPE_UINT, 57,
141 "ssrc", G_TYPE_UINT, 66, NULL);
142 fail_unless (gst_pad_set_caps (src1, caps));
144 newsegment = gst_event_new_new_segment (FALSE, 1, GST_FORMAT_TIME, 100000,
146 fail_unless (gst_pad_push_event (src1, newsegment));
147 newsegment = gst_event_new_new_segment (FALSE, 1, GST_FORMAT_TIME, 0, -1, 0);
148 fail_unless (gst_pad_push_event (src2, newsegment));
150 for (i = 0; i < count; i++) {
151 inbuf = gst_rtp_buffer_new_allocate (10, 0, 0);
152 GST_BUFFER_TIMESTAMP (inbuf) = i * 1000 + 100000;
153 GST_BUFFER_DURATION (inbuf) = 1000;
154 gst_buffer_set_caps (inbuf, caps);
155 gst_rtp_buffer_set_version (inbuf, 2);
156 gst_rtp_buffer_set_payload_type (inbuf, 98);
157 gst_rtp_buffer_set_ssrc (inbuf, 44);
158 gst_rtp_buffer_set_timestamp (inbuf, 200 + i);
159 gst_rtp_buffer_set_seq (inbuf, 2000 + i);
160 fail_unless (gst_pad_push (src1, inbuf) == GST_FLOW_OK);
163 fail_unless (GST_BUFFER_TIMESTAMP (buffers->data) == i * 1000, "%lld",
164 GST_BUFFER_TIMESTAMP (buffers->data));
168 g_list_foreach (buffers, (GFunc) gst_buffer_unref, NULL);
169 g_list_free (buffers);
174 gst_pad_set_active (sink, FALSE);
175 gst_pad_set_active (src1, FALSE);
176 gst_pad_set_active (src2, FALSE);
177 fail_unless (gst_element_set_state (rtpmux,
178 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS);
179 gst_check_teardown_pad_by_name (rtpmux, "src");
180 gst_object_unref (reqpad1);
181 gst_object_unref (reqpad2);
182 gst_check_teardown_pad_by_name (rtpmux, "sink_1");
183 gst_check_teardown_pad_by_name (rtpmux, sink2);
184 gst_element_release_request_pad (rtpmux, reqpad1);
185 gst_element_release_request_pad (rtpmux, reqpad2);
187 gst_caps_unref (caps);
188 gst_caps_replace (&src1caps, NULL);
189 gst_caps_replace (&src2caps, NULL);
190 gst_caps_replace (&sinkcaps, NULL);
192 gst_check_teardown_element (rtpmux);
196 basic_check_cb (GstPad * pad, int i)
198 fail_unless (buffers && g_list_length (buffers) == 1);
199 fail_unless (gst_rtp_buffer_get_ssrc (buffers->data) == 55);
200 fail_unless (gst_rtp_buffer_get_timestamp (buffers->data) ==
201 200 - 57 + 1000 + i);
202 fail_unless (gst_rtp_buffer_get_seq (buffers->data) == 100 + 1 + i);
206 GST_START_TEST (test_rtpmux_basic)
208 test_basic ("rtpmux", "sink_2", 10, basic_check_cb);
213 GST_START_TEST (test_rtpdtmfmux_basic)
215 test_basic ("rtpdtmfmux", "sink_2", 10, basic_check_cb);
221 lock_check_cb (GstPad * pad, int i)
226 fail_unless (buffers == NULL);
228 fail_unless (buffers && g_list_length (buffers) == 1);
229 fail_unless (gst_rtp_buffer_get_ssrc (buffers->data) == 55);
230 fail_unless (gst_rtp_buffer_get_timestamp (buffers->data) ==
231 200 - 57 + 1000 + i);
232 fail_unless (gst_rtp_buffer_get_seq (buffers->data) == 100 + 1 + i);
234 inbuf = gst_rtp_buffer_new_allocate (10, 0, 0);
235 GST_BUFFER_TIMESTAMP (inbuf) = i * 1000 + 500;
236 GST_BUFFER_DURATION (inbuf) = 1000;
237 gst_rtp_buffer_set_version (inbuf, 2);
238 gst_rtp_buffer_set_payload_type (inbuf, 98);
239 gst_rtp_buffer_set_ssrc (inbuf, 44);
240 gst_rtp_buffer_set_timestamp (inbuf, 200 + i);
241 gst_rtp_buffer_set_seq (inbuf, 2000 + i);
242 fail_unless (gst_pad_push (pad, inbuf) == GST_FLOW_OK);
245 g_list_foreach (buffers, (GFunc) gst_buffer_unref, NULL);
246 g_list_free (buffers);
251 GST_START_TEST (test_rtpdtmfmux_lock)
253 test_basic ("rtpdtmfmux", "priority_sink_2", 10, lock_check_cb);
261 Suite *s = suite_create ("rtpmux");
264 tc_chain = tcase_create ("rtpmux_basic");
265 tcase_add_test (tc_chain, test_rtpmux_basic);
266 suite_add_tcase (s, tc_chain);
268 tc_chain = tcase_create ("rtpdtmfmux_basic");
269 tcase_add_test (tc_chain, test_rtpdtmfmux_basic);
270 suite_add_tcase (s, tc_chain);
272 tc_chain = tcase_create ("rtpdtmfmux_lock");
273 tcase_add_test (tc_chain, test_rtpdtmfmux_lock);
274 suite_add_tcase (s, tc_chain);
279 GST_CHECK_MAIN (rtpmux)