test: rtpbin_buffer_list: add a test for wrapping sequence numbers
[platform/upstream/gstreamer.git] / tests / check / elements / rtpbin_buffer_list.c
1 /* GStreamer
2  *
3  * Unit test for gstrtpbin sending rtp packets using GstBufferList.
4  * Copyright (C) 2009 Branko Subasic <branko dot subasic at axis dot com>
5  * Copyright 2019, Collabora Ltd.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
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  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 #include <gst/check/gstcheck.h>
24
25 #include <gst/rtp/gstrtpbuffer.h>
26
27 /* UDP/IP is assumed for bandwidth calculation */
28 #define UDP_IP_HEADER_OVERHEAD 28
29
30 /* This test makes sure that RTP packets sent as buffer lists are sent through
31  * the rtpbin as they are supposed to, and not corrupted in any way.
32  */
33
34
35 #define TEST_CAPS \
36   "application/x-rtp, "                \
37   "media=(string)video, "              \
38   "clock-rate=(int)90000, "            \
39   "encoding-name=(string)H264, "       \
40   "profile-level-id=(string)4d4015, "  \
41   "payload=(int)96, "                  \
42   "ssrc=(guint)2633237432, "           \
43   "clock-base=(guint)1868267015, "     \
44   "seqnum-base=(guint)54229"
45
46
47 /* RTP headers and the first 2 bytes of the payload (FU indicator and FU header)
48  */
49 static const guint8 rtp_header[2][14] = {
50   {0x80, 0x60, 0xbb, 0xb7, 0x5c, 0xe9, 0x09,
51       0x0d, 0xf5, 0x9c, 0x43, 0x55, 0x1c, 0x86},
52   {0x80, 0x60, 0xbb, 0xb8, 0x5c, 0xe9, 0x09,
53       0x0d, 0xf5, 0x9c, 0x43, 0x55, 0x1c, 0x46}
54 };
55
56 static const guint rtp_header_len[] = {
57   sizeof rtp_header[0],
58   sizeof rtp_header[1]
59 };
60
61 /* Some payload.
62  */
63 static const char *payload =
64     "0123456789ABSDEF0123456789ABSDEF0123456789ABSDEF0123456789ABSDEF0123456789ABSDEF"
65     "0123456789ABSDEF0123456789ABSDEF0123456789ABSDEF0123456789ABSDEF0123456789ABSDEF"
66     "0123456789ABSDEF0123456789ABSDEF0123456789ABSDEF0123456789ABSDEF0123456789ABSDEF"
67     "0123456789ABSDEF0123456789ABSDEF0123456789ABSDEF0123456789ABSDEF0123456789ABSDEF"
68     "0123456789ABSDEF0123456789ABSDEF0123456789ABSDEF0123456789ABSDEF0123456789ABSDEF"
69     "0123456789ABSDEF0123456789ABSDEF0123456789ABSDEF0123456789ABSDEF0123456789ABSDEF"
70     "0123456789ABSDEF0123456";
71
72 static const guint payload_offset[] = {
73   0, 498
74 };
75
76 static const guint payload_len[] = {
77   498, 5
78 };
79
80
81 static GstBuffer *original_buffer = NULL;
82
83 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
84     GST_PAD_SINK,
85     GST_PAD_ALWAYS,
86     GST_STATIC_CAPS ("application/x-rtp"));
87
88 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
89     GST_PAD_SRC,
90     GST_PAD_ALWAYS,
91     GST_STATIC_CAPS ("application/x-rtp"));
92
93
94 static GstBuffer *
95 create_original_buffer (void)
96 {
97   if (original_buffer != NULL)
98     return original_buffer;
99
100   original_buffer =
101       gst_buffer_new_wrapped ((guint8 *) payload, strlen (payload));
102   fail_unless (original_buffer != NULL);
103
104   GST_BUFFER_TIMESTAMP (original_buffer) =
105       gst_clock_get_internal_time (gst_system_clock_obtain ());
106
107   return original_buffer;
108 }
109
110 static GstBuffer *
111 create_rtp_packet_buffer (gconstpointer header, gint header_size,
112     GstBuffer * payload_buffer, gint payload_offset, gint payload_size)
113 {
114   GstBuffer *buffer;
115   GstBuffer *sub_buffer;
116
117   /* Create buffer with RTP header. */
118   buffer = gst_buffer_new_allocate (NULL, header_size, NULL);
119   gst_buffer_fill (buffer, 0, header, header_size);
120   gst_buffer_copy_into (buffer, payload_buffer, GST_BUFFER_COPY_METADATA, 0,
121       -1);
122
123   /* Create the payload buffer and add it to the current buffer. */
124   sub_buffer =
125       gst_buffer_copy_region (payload_buffer, GST_BUFFER_COPY_MEMORY,
126       payload_offset, payload_size);
127
128   buffer = gst_buffer_append (buffer, sub_buffer);
129   fail_if (buffer == NULL);
130
131   return buffer;
132 }
133
134 static GstBuffer *
135 create_rtp_buffer_fields (gconstpointer header, gint header_size,
136     GstBuffer * payload_buffer, gint payload_offset, gint payload_size,
137     guint16 seqnum, guint32 timestamp)
138 {
139   GstBuffer *buffer;
140   GstMemory *memory;
141   GstMapInfo info;
142   gboolean ret;
143   guint32 *tmp;
144
145   buffer =
146       create_rtp_packet_buffer (header, header_size, payload_buffer,
147       payload_offset, payload_size);
148   fail_if (buffer == NULL);
149
150   memory = gst_buffer_get_memory (buffer, 0);
151   ret = gst_memory_map (memory, &info, GST_MAP_READ);
152   fail_if (ret == FALSE);
153
154   info.data[2] = (seqnum >> 8) & 0xff;
155   info.data[3] = seqnum & 0xff;
156
157   tmp = (guint32 *) & (info.data[4]);
158   *tmp = g_htonl (timestamp);
159
160   gst_memory_unmap (memory, &info);
161   gst_memory_unref (memory);
162
163   return buffer;
164 }
165
166 static void
167 check_seqnum (GstBuffer * buffer, guint16 seqnum)
168 {
169   GstMemory *memory;
170   GstMapInfo info;
171   gboolean ret;
172   guint16 current_seqnum;
173
174   fail_if (buffer == NULL);
175
176   memory = gst_buffer_get_memory (buffer, 0);
177   ret = gst_memory_map (memory, &info, GST_MAP_READ);
178   fail_if (ret == FALSE);
179
180   current_seqnum = info.data[2] << 8 | info.data[3];
181   fail_unless (current_seqnum == seqnum);
182
183   gst_memory_unmap (memory, &info);
184   gst_memory_unref (memory);
185 }
186
187 static void
188 check_header (GstBuffer * buffer, guint index)
189 {
190   GstMemory *memory;
191   GstMapInfo info;
192   gboolean ret;
193
194   fail_if (buffer == NULL);
195   fail_unless (index < 2);
196
197   memory = gst_buffer_get_memory (buffer, 0);
198   ret = gst_memory_map (memory, &info, GST_MAP_READ);
199   fail_if (ret == FALSE);
200
201   fail_unless (info.size == rtp_header_len[index]);
202
203   /* Can't do a memcmp() on the whole header, cause the SSRC (bytes 8-11) will
204    * most likely be changed in gstrtpbin.
205    */
206   fail_unless (info.data != NULL);
207   fail_unless_equals_uint64 (*(guint64 *) info.data,
208       *(guint64 *) rtp_header[index]);
209   fail_unless (*(guint16 *) (info.data + 12) ==
210       *(guint16 *) (rtp_header[index] + 12));
211
212   gst_memory_unmap (memory, &info);
213   gst_memory_unref (memory);
214 }
215
216 static void
217 check_payload (GstBuffer * buffer, guint index)
218 {
219   GstMemory *memory;
220   GstMapInfo info;
221   gboolean ret;
222
223   fail_if (buffer == NULL);
224   fail_unless (index < 2);
225
226   memory = gst_buffer_get_memory (buffer, 1);
227   ret = gst_memory_map (memory, &info, GST_MAP_READ);
228   fail_if (ret == FALSE);
229
230   fail_unless (info.size == payload_len[index]);
231   fail_if (info.data != (gpointer) (payload + payload_offset[index]));
232   fail_if (memcmp (info.data, payload + payload_offset[index],
233           payload_len[index]));
234
235   gst_memory_unmap (memory, &info);
236   gst_memory_unref (memory);
237 }
238
239 static void
240 check_packet (GstBufferList * list, guint list_index, guint packet_index)
241 {
242   GstBuffer *buffer;
243
244   fail_unless (list != NULL);
245
246   fail_unless ((buffer = gst_buffer_list_get (list, list_index)) != NULL);
247   fail_unless (gst_buffer_n_memory (buffer) == 2);
248
249   fail_unless (GST_BUFFER_TIMESTAMP (buffer) ==
250       GST_BUFFER_TIMESTAMP (original_buffer));
251
252   check_header (buffer, packet_index);
253   check_payload (buffer, packet_index);
254 }
255
256 /*
257  * Used to verify that the chain_list function is actually implemented by the
258  * element and called when executing the pipeline. This is needed because pads
259  * always have a default chain_list handler which handle buffers in a buffer
260  * list individually, and pushing a list to a pad can succeed even if no
261  * chain_list handler has been set.
262  */
263 static gboolean chain_list_func_called;
264 static guint chain_list_bytes_received;
265
266 /* Create two packets with different payloads. */
267 static GstBufferList *
268 create_buffer_list (void)
269 {
270   GstBufferList *list;
271   GstBuffer *orig_buffer;
272   GstBuffer *buffer;
273
274   orig_buffer = create_original_buffer ();
275   fail_if (orig_buffer == NULL);
276
277   list = gst_buffer_list_new ();
278   fail_if (list == NULL);
279
280   /*** First packet. **/
281   buffer =
282       create_rtp_packet_buffer (&rtp_header[0], rtp_header_len[0], orig_buffer,
283       payload_offset[0], payload_len[0]);
284   gst_buffer_list_add (list, buffer);
285
286   /***  Second packet. ***/
287   buffer =
288       create_rtp_packet_buffer (&rtp_header[1], rtp_header_len[1], orig_buffer,
289       payload_offset[1], payload_len[1]);
290   gst_buffer_list_add (list, buffer);
291
292   return list;
293 }
294
295 /* Check that the correct packets have been pushed out of the element. */
296 static GstFlowReturn
297 sink_chain_list (GstPad * pad, GstObject * parent, GstBufferList * list)
298 {
299   GstCaps *current_caps;
300   GstCaps *caps;
301
302   chain_list_func_called = TRUE;
303
304   current_caps = gst_pad_get_current_caps (pad);
305   fail_unless (current_caps != NULL);
306
307   caps = gst_caps_from_string (TEST_CAPS);
308   fail_unless (caps != NULL);
309
310   fail_unless (gst_caps_is_equal (caps, current_caps));
311   gst_caps_unref (caps);
312   gst_caps_unref (current_caps);
313
314   fail_unless (GST_IS_BUFFER_LIST (list));
315   fail_unless (gst_buffer_list_length (list) == 2);
316
317   /* received bytes include lower level protocol overhead */
318   chain_list_bytes_received = gst_buffer_list_calculate_size (list) +
319       2 * UDP_IP_HEADER_OVERHEAD;
320
321   fail_unless (gst_buffer_list_get (list, 0));
322   check_packet (list, 0, 0);
323
324   fail_unless (gst_buffer_list_get (list, 1));
325   check_packet (list, 1, 1);
326
327   gst_buffer_list_unref (list);
328
329   return GST_FLOW_OK;
330 }
331
332
333 /* Non-consecutive seqnums makes probation fail. */
334 static GstBufferList *
335 create_buffer_list_fail_probation (void)
336 {
337   GstBufferList *list;
338   GstBuffer *orig_buffer;
339   GstBuffer *buffer;
340
341   guint16 seqnums[] = { 1, 3, 5 };
342   guint i;
343
344   orig_buffer = create_original_buffer ();
345   fail_if (orig_buffer == NULL);
346
347   list = gst_buffer_list_new ();
348   fail_if (list == NULL);
349
350   for (i = 0; i < sizeof (seqnums) / sizeof (seqnums[0]); i++) {
351     buffer =
352         create_rtp_buffer_fields (&rtp_header[0], rtp_header_len[0],
353         orig_buffer, payload_offset[0], payload_len[0], seqnums[i], 0);
354     gst_buffer_list_add (list, buffer);
355   }
356
357   return list;
358 }
359
360 /* When probation fails this function shouldn't be called. */
361 static GstFlowReturn
362 sink_chain_list_probation_failed (GstPad * pad, GstObject * parent,
363     GstBufferList * list)
364 {
365   chain_list_func_called = TRUE;
366   return GST_FLOW_OK;
367 }
368
369
370 /* After probation succeeds, a small gap in seqnums is allowed. */
371 static GstBufferList *
372 create_buffer_list_permissible_gap (void)
373 {
374   GstBufferList *list;
375   GstBuffer *orig_buffer;
376   GstBuffer *buffer;
377
378   /* probation succeeds, but then there is a permissible out of sequence */
379   guint16 seqnums[] = { 1, 2, 4, 5 };
380   guint i;
381
382   orig_buffer = create_original_buffer ();
383   fail_if (orig_buffer == NULL);
384
385   list = gst_buffer_list_new ();
386   fail_if (list == NULL);
387
388   for (i = 0; i < sizeof (seqnums) / sizeof (seqnums[0]); i++) {
389     buffer =
390         create_rtp_buffer_fields (&rtp_header[0], rtp_header_len[0],
391         orig_buffer, payload_offset[0], payload_len[0], seqnums[i], 0);
392     gst_buffer_list_add (list, buffer);
393   }
394
395   return list;
396 }
397
398 /* All buffers should have been pushed. */
399 static GstFlowReturn
400 sink_chain_list_permissible_gap (GstPad * pad, GstObject * parent,
401     GstBufferList * list)
402 {
403   GstBuffer *buffer;
404
405   chain_list_func_called = TRUE;
406
407   fail_unless (GST_IS_BUFFER_LIST (list));
408   fail_unless (gst_buffer_list_length (list) == 4);
409
410   /* Verify sequence numbers */
411   buffer = gst_buffer_list_get (list, 0);
412   check_seqnum (buffer, 1);
413
414   buffer = gst_buffer_list_get (list, 1);
415   check_seqnum (buffer, 2);
416
417   buffer = gst_buffer_list_get (list, 2);
418   check_seqnum (buffer, 4);
419
420   buffer = gst_buffer_list_get (list, 3);
421   check_seqnum (buffer, 5);
422
423   gst_buffer_list_unref (list);
424
425   return GST_FLOW_OK;
426 }
427
428
429 /* After probation succeeds, wrapping seqnum is allowed. */
430 static GstBufferList *
431 create_buffer_list_wrapping_seqnums (void)
432 {
433   GstBufferList *list;
434   GstBuffer *orig_buffer;
435   GstBuffer *buffer;
436
437   /* probation succeeds, but then seqnum wraps around */
438   guint16 seqnums[] = { 65533, 65534, 65535, 0 };
439   guint i;
440
441   orig_buffer = create_original_buffer ();
442   fail_if (orig_buffer == NULL);
443
444   list = gst_buffer_list_new ();
445   fail_if (list == NULL);
446
447   for (i = 0; i < sizeof (seqnums) / sizeof (seqnums[0]); i++) {
448     buffer =
449         create_rtp_buffer_fields (&rtp_header[0], rtp_header_len[0],
450         orig_buffer, payload_offset[0], payload_len[0], seqnums[i], 0);
451     gst_buffer_list_add (list, buffer);
452   }
453
454   return list;
455 }
456
457 /* All buffers should have been pushed. */
458 static GstFlowReturn
459 sink_chain_list_wrapping_seqnums (GstPad * pad, GstObject * parent,
460     GstBufferList * list)
461 {
462   GstBuffer *buffer;
463
464   chain_list_func_called = TRUE;
465
466   fail_unless (GST_IS_BUFFER_LIST (list));
467   fail_unless (gst_buffer_list_length (list) == 4);
468
469   /* Verify sequence numbers */
470   buffer = gst_buffer_list_get (list, 0);
471   check_seqnum (buffer, 65533);
472
473   buffer = gst_buffer_list_get (list, 1);
474   check_seqnum (buffer, 65534);
475
476   buffer = gst_buffer_list_get (list, 2);
477   check_seqnum (buffer, 65535);
478
479   buffer = gst_buffer_list_get (list, 3);
480   check_seqnum (buffer, 0);
481
482   gst_buffer_list_unref (list);
483
484   return GST_FLOW_OK;
485 }
486
487
488 /* Get the stats of the **first** source of the given type (get_sender) */
489 static void
490 get_source_stats (GstElement * rtpsession,
491     gboolean get_sender, GstStructure ** source_stats)
492 {
493   GstStructure *stats;
494   GValueArray *stats_arr;
495   guint i;
496
497   g_object_get (rtpsession, "stats", &stats, NULL);
498   stats_arr =
499       g_value_get_boxed (gst_structure_get_value (stats, "source-stats"));
500   g_assert (stats_arr != NULL);
501   fail_unless (stats_arr->n_values >= 1);
502
503   *source_stats = NULL;
504   for (i = 0; i < stats_arr->n_values; i++) {
505     GstStructure *tmp_source_stats;
506     gboolean is_sender;
507
508     tmp_source_stats = g_value_dup_boxed (&stats_arr->values[i]);
509     gst_structure_get (tmp_source_stats, "is-sender", G_TYPE_BOOLEAN,
510         &is_sender, NULL);
511
512     /* Return the stats of the **first** source of the given type. */
513     if (is_sender == get_sender) {
514       *source_stats = tmp_source_stats;
515       break;
516     }
517     gst_structure_free (tmp_source_stats);
518   }
519
520   gst_structure_free (stats);
521 }
522
523 /* Get the source stats given a session and a source type (get_sender) */
524 static void
525 get_session_source_stats (GstElement * rtpbin, guint session,
526     gboolean get_sender, GstStructure ** source_stats)
527 {
528   GstElement *rtpsession;
529
530   g_signal_emit_by_name (rtpbin, "get-session", session, &rtpsession);
531   fail_if (rtpsession == NULL);
532
533   get_source_stats (rtpsession, get_sender, source_stats);
534
535   gst_object_unref (rtpsession);
536 }
537
538 GST_START_TEST (test_bufferlist)
539 {
540   GstElement *rtpbin;
541   GstPad *srcpad;
542   GstPad *sinkpad;
543   GstCaps *caps;
544   GstBufferList *list;
545   GstStructure *stats;
546   guint64 packets_sent;
547   guint64 packets_received;
548
549   list = create_buffer_list ();
550   fail_unless (list != NULL);
551
552   rtpbin = gst_check_setup_element ("rtpbin");
553
554   srcpad =
555       gst_check_setup_src_pad_by_name (rtpbin, &srctemplate, "send_rtp_sink_0");
556   fail_if (srcpad == NULL);
557   sinkpad =
558       gst_check_setup_sink_pad_by_name (rtpbin, &sinktemplate,
559       "send_rtp_src_0");
560   fail_if (sinkpad == NULL);
561
562   gst_pad_set_chain_list_function (sinkpad,
563       GST_DEBUG_FUNCPTR (sink_chain_list));
564
565   gst_pad_set_active (srcpad, TRUE);
566   gst_pad_set_active (sinkpad, TRUE);
567
568   caps = gst_caps_from_string (TEST_CAPS);
569   gst_check_setup_events (srcpad, rtpbin, caps, GST_FORMAT_TIME);
570   gst_caps_unref (caps);
571
572   gst_element_set_state (rtpbin, GST_STATE_PLAYING);
573
574   chain_list_func_called = FALSE;
575   fail_unless (gst_pad_push_list (srcpad, list) == GST_FLOW_OK);
576   fail_if (chain_list_func_called == FALSE);
577
578   /* make sure that stats about the number of sent packets are OK too */
579   get_session_source_stats (rtpbin, 0, TRUE, &stats);
580   fail_if (stats == NULL);
581
582   gst_structure_get (stats,
583       "packets-sent", G_TYPE_UINT64, &packets_sent,
584       "packets-received", G_TYPE_UINT64, &packets_received, NULL);
585   fail_unless (packets_sent == 2);
586   fail_unless (packets_received == 2);
587   gst_structure_free (stats);
588
589   gst_pad_set_active (sinkpad, FALSE);
590   gst_pad_set_active (srcpad, FALSE);
591
592   gst_check_teardown_pad_by_name (rtpbin, "send_rtp_src_0");
593   gst_check_teardown_pad_by_name (rtpbin, "send_rtp_sink_0");
594   gst_check_teardown_element (rtpbin);
595 }
596
597 GST_END_TEST;
598
599
600 GST_START_TEST (test_bufferlist_recv)
601 {
602   GstElement *rtpbin;
603   GstPad *srcpad;
604   GstPad *sinkpad;
605   GstCaps *caps;
606   GstBufferList *list;
607   GstStructure *stats;
608   guint64 bytes_received;
609   guint64 packets_received;
610
611   list = create_buffer_list ();
612   fail_unless (list != NULL);
613
614   rtpbin = gst_check_setup_element ("rtpsession");
615
616   srcpad =
617       gst_check_setup_src_pad_by_name (rtpbin, &srctemplate, "recv_rtp_sink");
618   fail_if (srcpad == NULL);
619
620   sinkpad =
621       gst_check_setup_sink_pad_by_name (rtpbin, &sinktemplate, "recv_rtp_src");
622   fail_if (sinkpad == NULL);
623
624   gst_pad_set_chain_list_function (sinkpad,
625       GST_DEBUG_FUNCPTR (sink_chain_list));
626
627   gst_pad_set_active (srcpad, TRUE);
628   gst_pad_set_active (sinkpad, TRUE);
629
630   caps = gst_caps_from_string (TEST_CAPS);
631   gst_check_setup_events (srcpad, rtpbin, caps, GST_FORMAT_TIME);
632   gst_caps_unref (caps);
633
634   gst_element_set_state (rtpbin, GST_STATE_PLAYING);
635
636   chain_list_func_called = FALSE;
637   fail_unless (gst_pad_push_list (srcpad, list) == GST_FLOW_OK);
638   fail_if (chain_list_func_called == FALSE);
639
640   /* make sure that stats about the number of received packets are OK too */
641   /* The source becomes a sender after probation succeeds, pass TRUE here. */
642   get_source_stats (rtpbin, TRUE, &stats);
643   fail_if (stats == NULL);
644
645   gst_structure_get (stats,
646       "bytes-received", G_TYPE_UINT64, &bytes_received,
647       "packets-received", G_TYPE_UINT64, &packets_received, NULL);
648   fail_unless (packets_received == 2);
649   fail_unless (bytes_received == chain_list_bytes_received);
650   gst_structure_free (stats);
651
652
653   gst_pad_set_active (sinkpad, FALSE);
654   gst_pad_set_active (srcpad, FALSE);
655
656   gst_check_teardown_pad_by_name (rtpbin, "recv_rtp_src");
657   gst_check_teardown_pad_by_name (rtpbin, "recv_rtp_sink");
658   gst_check_teardown_element (rtpbin);
659 }
660
661 GST_END_TEST;
662
663
664 GST_START_TEST (test_bufferlist_recv_probation_failed)
665 {
666   GstElement *rtpbin;
667   GstPad *srcpad;
668   GstPad *sinkpad;
669   GstCaps *caps;
670   GstBufferList *list;
671
672   list = create_buffer_list_fail_probation ();
673   fail_unless (list != NULL);
674
675   rtpbin = gst_check_setup_element ("rtpsession");
676
677   srcpad =
678       gst_check_setup_src_pad_by_name (rtpbin, &srctemplate, "recv_rtp_sink");
679   fail_if (srcpad == NULL);
680
681   sinkpad =
682       gst_check_setup_sink_pad_by_name (rtpbin, &sinktemplate, "recv_rtp_src");
683   fail_if (sinkpad == NULL);
684
685   gst_pad_set_chain_list_function (sinkpad,
686       GST_DEBUG_FUNCPTR (sink_chain_list_probation_failed));
687
688   gst_pad_set_active (srcpad, TRUE);
689   gst_pad_set_active (sinkpad, TRUE);
690
691   caps = gst_caps_from_string (TEST_CAPS);
692   gst_check_setup_events (srcpad, rtpbin, caps, GST_FORMAT_TIME);
693   gst_caps_unref (caps);
694
695   gst_element_set_state (rtpbin, GST_STATE_PLAYING);
696
697   chain_list_func_called = FALSE;
698   fail_unless (gst_pad_push_list (srcpad, list) == GST_FLOW_OK);
699   /* when probation fails the list should not be pushed at all, and the
700    * chain_list functions should not be called, fail if it has been. */
701   fail_if (chain_list_func_called == TRUE);
702
703   gst_pad_set_active (sinkpad, FALSE);
704   gst_pad_set_active (srcpad, FALSE);
705
706   gst_check_teardown_pad_by_name (rtpbin, "recv_rtp_src");
707   gst_check_teardown_pad_by_name (rtpbin, "recv_rtp_sink");
708   gst_check_teardown_element (rtpbin);
709 }
710
711 GST_END_TEST;
712
713
714 GST_START_TEST (test_bufferlist_recv_permissible_gap)
715 {
716   GstElement *rtpbin;
717   GstPad *srcpad;
718   GstPad *sinkpad;
719   GstCaps *caps;
720   GstBufferList *list;
721
722   list = create_buffer_list_permissible_gap ();
723   fail_unless (list != NULL);
724
725   rtpbin = gst_check_setup_element ("rtpsession");
726
727   srcpad =
728       gst_check_setup_src_pad_by_name (rtpbin, &srctemplate, "recv_rtp_sink");
729   fail_if (srcpad == NULL);
730
731   sinkpad =
732       gst_check_setup_sink_pad_by_name (rtpbin, &sinktemplate, "recv_rtp_src");
733   fail_if (sinkpad == NULL);
734
735   gst_pad_set_chain_list_function (sinkpad,
736       GST_DEBUG_FUNCPTR (sink_chain_list_permissible_gap));
737
738   gst_pad_set_active (srcpad, TRUE);
739   gst_pad_set_active (sinkpad, TRUE);
740
741   caps = gst_caps_from_string (TEST_CAPS);
742   gst_check_setup_events (srcpad, rtpbin, caps, GST_FORMAT_TIME);
743   gst_caps_unref (caps);
744
745   gst_element_set_state (rtpbin, GST_STATE_PLAYING);
746
747   chain_list_func_called = FALSE;
748   fail_unless (gst_pad_push_list (srcpad, list) == GST_FLOW_OK);
749   fail_if (chain_list_func_called == FALSE);
750
751   gst_pad_set_active (sinkpad, FALSE);
752   gst_pad_set_active (srcpad, FALSE);
753
754   gst_check_teardown_pad_by_name (rtpbin, "recv_rtp_src");
755   gst_check_teardown_pad_by_name (rtpbin, "recv_rtp_sink");
756   gst_check_teardown_element (rtpbin);
757 }
758
759 GST_END_TEST;
760
761
762 GST_START_TEST (test_bufferlist_recv_wrapping_seqnums)
763 {
764   GstElement *rtpbin;
765   GstPad *srcpad;
766   GstPad *sinkpad;
767   GstCaps *caps;
768   GstBufferList *list;
769
770   list = create_buffer_list_wrapping_seqnums ();
771   fail_unless (list != NULL);
772
773   rtpbin = gst_check_setup_element ("rtpsession");
774
775   srcpad =
776       gst_check_setup_src_pad_by_name (rtpbin, &srctemplate, "recv_rtp_sink");
777   fail_if (srcpad == NULL);
778
779   sinkpad =
780       gst_check_setup_sink_pad_by_name (rtpbin, &sinktemplate, "recv_rtp_src");
781   fail_if (sinkpad == NULL);
782
783   gst_pad_set_chain_list_function (sinkpad,
784       GST_DEBUG_FUNCPTR (sink_chain_list_wrapping_seqnums));
785
786   gst_pad_set_active (srcpad, TRUE);
787   gst_pad_set_active (sinkpad, TRUE);
788
789   caps = gst_caps_from_string (TEST_CAPS);
790   gst_check_setup_events (srcpad, rtpbin, caps, GST_FORMAT_TIME);
791   gst_caps_unref (caps);
792
793   gst_element_set_state (rtpbin, GST_STATE_PLAYING);
794
795   chain_list_func_called = FALSE;
796   fail_unless (gst_pad_push_list (srcpad, list) == GST_FLOW_OK);
797   fail_if (chain_list_func_called == FALSE);
798
799   gst_pad_set_active (sinkpad, FALSE);
800   gst_pad_set_active (srcpad, FALSE);
801
802   gst_check_teardown_pad_by_name (rtpbin, "recv_rtp_src");
803   gst_check_teardown_pad_by_name (rtpbin, "recv_rtp_sink");
804   gst_check_teardown_element (rtpbin);
805 }
806
807 GST_END_TEST;
808
809
810 static Suite *
811 bufferlist_suite (void)
812 {
813   Suite *s = suite_create ("BufferList");
814
815   TCase *tc_chain = tcase_create ("general");
816
817   /* time out after 30s. */
818   tcase_set_timeout (tc_chain, 10);
819
820   suite_add_tcase (s, tc_chain);
821   tcase_add_test (tc_chain, test_bufferlist);
822   tcase_add_test (tc_chain, test_bufferlist_recv);
823   tcase_add_test (tc_chain, test_bufferlist_recv_probation_failed);
824   tcase_add_test (tc_chain, test_bufferlist_recv_permissible_gap);
825   tcase_add_test (tc_chain, test_bufferlist_recv_wrapping_seqnums);
826
827   return s;
828 }
829
830 GST_CHECK_MAIN (bufferlist);