1 /* GStreamer RTP payloader unit tests
2 * Copyright (C) 2009 Axis Communications <dev-gstreamer@axis.com>
3 * @author Ognyan Tonchev <ognyan@axis.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
20 #include <gst/check/gstcheck.h>
21 #include <gst/base/gstbasesink.h>
25 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
30 #define RTP_HEADER_SIZE 12
31 #define RTP_PAYLOAD_SIZE 1024
34 * Number of bytes received in the render function when using buffer lists
36 static guint render_list_bytes_received;
39 * Render function for testing udpsink with buffer lists
42 udpsink_render (GstBaseSink * sink, GstBufferList * list)
44 GstBufferListIterator *it;
49 * Count the size of the rtp header and the payload in the buffer list.
52 it = gst_buffer_list_iterate (list);
54 /* Loop through all groups */
55 while (gst_buffer_list_iterator_next_group (it)) {
57 /* Loop through all buffers in the current group */
58 while ((buf = gst_buffer_list_iterator_next (it))) {
61 size = GST_BUFFER_SIZE (buf);
62 GST_DEBUG ("rendered %u bytes", size);
64 render_list_bytes_received += size;
68 gst_buffer_list_iterator_free (it);
74 _set_render_function (GstElement * bsink)
76 GstBaseSinkClass *bsclass;
77 bsclass = GST_BASE_SINK_GET_CLASS ((GstBaseSink *) bsink);
78 /* Add callback function for the buffer list tests */
79 bsclass->render_list = udpsink_render;
82 static GstBufferList *
83 _create_buffer_list (guint * data_size)
86 GstBufferListIterator *it;
87 GstBuffer *rtp_buffer;
88 GstBuffer *data_buffer;
90 list = gst_buffer_list_new ();
91 it = gst_buffer_list_iterate (list);
93 /*** First group, i.e. first packet. **/
95 /* Create the RTP header buffer */
96 rtp_buffer = gst_buffer_new ();
97 GST_BUFFER_MALLOCDATA (rtp_buffer) = g_malloc (RTP_HEADER_SIZE);
98 GST_BUFFER_DATA (rtp_buffer) = GST_BUFFER_MALLOCDATA (rtp_buffer);
99 GST_BUFFER_SIZE (rtp_buffer) = RTP_HEADER_SIZE;
100 memset (GST_BUFFER_DATA (rtp_buffer), 0, RTP_HEADER_SIZE);
102 /* Create the buffer that holds the payload */
103 data_buffer = gst_buffer_new ();
104 GST_BUFFER_MALLOCDATA (data_buffer) = g_malloc (RTP_PAYLOAD_SIZE);
105 GST_BUFFER_DATA (data_buffer) = GST_BUFFER_MALLOCDATA (data_buffer);
106 GST_BUFFER_SIZE (data_buffer) = RTP_PAYLOAD_SIZE;
107 memset (GST_BUFFER_DATA (data_buffer), 0, RTP_PAYLOAD_SIZE);
109 /* Create a new group to hold the rtp header and the payload */
110 gst_buffer_list_iterator_add_group (it);
111 gst_buffer_list_iterator_add (it, rtp_buffer);
112 gst_buffer_list_iterator_add (it, data_buffer);
114 /*** Second group, i.e. second packet. ***/
116 /* Create the RTP header buffer */
117 rtp_buffer = gst_buffer_new ();
118 GST_BUFFER_MALLOCDATA (rtp_buffer) = g_malloc (RTP_HEADER_SIZE);
119 GST_BUFFER_DATA (rtp_buffer) = GST_BUFFER_MALLOCDATA (rtp_buffer);
120 GST_BUFFER_SIZE (rtp_buffer) = RTP_HEADER_SIZE;
121 memset (GST_BUFFER_DATA (rtp_buffer), 0, RTP_HEADER_SIZE);
123 /* Create the buffer that holds the payload */
124 data_buffer = gst_buffer_new ();
125 GST_BUFFER_MALLOCDATA (data_buffer) = g_malloc (RTP_PAYLOAD_SIZE);
126 GST_BUFFER_DATA (data_buffer) = GST_BUFFER_MALLOCDATA (data_buffer);
127 GST_BUFFER_SIZE (data_buffer) = RTP_PAYLOAD_SIZE;
128 memset (GST_BUFFER_DATA (data_buffer), 0, RTP_PAYLOAD_SIZE);
130 /* Create a new group to hold the rtp header and the payload */
131 gst_buffer_list_iterator_add_group (it);
132 gst_buffer_list_iterator_add (it, rtp_buffer);
133 gst_buffer_list_iterator_add (it, data_buffer);
135 /* Calculate the size of the data */
136 *data_size = 2 * RTP_HEADER_SIZE + 2 * RTP_PAYLOAD_SIZE;
138 gst_buffer_list_iterator_free (it);
144 udpsink_test (gboolean use_buffer_lists)
151 list = _create_buffer_list (&data_size);
153 udpsink = gst_check_setup_element ("udpsink");
154 if (use_buffer_lists)
155 _set_render_function (udpsink);
157 srcpad = gst_check_setup_src_pad_by_name (udpsink, &srctemplate, "sink");
159 gst_element_set_state (udpsink, GST_STATE_PLAYING);
161 gst_pad_push_event (srcpad, gst_event_new_new_segment_full (FALSE, 1.0, 1.0,
162 GST_FORMAT_TIME, 0, -1, 0));
164 gst_pad_push_list (srcpad, list);
166 gst_check_teardown_pad_by_name (udpsink, "sink");
167 gst_check_teardown_element (udpsink);
169 if (use_buffer_lists)
170 fail_unless_equals_int (data_size, render_list_bytes_received);
173 GST_START_TEST (test_udpsink)
175 udpsink_test (FALSE);
179 GST_START_TEST (test_udpsink_bufferlist)
187 * Creates the test suite.
189 * Returns: pointer to the test suite.
194 Suite *s = suite_create ("udpsink_test");
196 TCase *tc_chain = tcase_create ("linear");
198 /* Set timeout to 60 seconds. */
199 tcase_set_timeout (tc_chain, 60);
201 suite_add_tcase (s, tc_chain);
202 tcase_add_test (tc_chain, test_udpsink);
203 tcase_add_test (tc_chain, test_udpsink_bufferlist);
207 GST_CHECK_MAIN (udpsink)