5 * Copyright (C) <2006> Stefan Kost <ensonic@users.sf.net>
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.
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.
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.
25 #include <gst/check/gstcheck.h>
27 #define UNDERRUN_LOCK() (g_mutex_lock (&underrun_mutex))
28 #define UNDERRUN_UNLOCK() (g_mutex_unlock (&underrun_mutex))
29 #define UNDERRUN_SIGNAL() (g_cond_signal (&underrun_cond))
30 #define UNDERRUN_WAIT() (g_cond_wait (&underrun_cond, &underrun_mutex))
32 static GstElement *queue;
34 /* For ease of programming we use globals to keep refs for our floating
35 * src and sink pads we create; otherwise we always have to do get_pad,
36 * get_peer, and then remove references in every test function */
37 static GstPad *mysrcpad;
38 static GstPad *mysinkpad;
39 static GstPad *qsrcpad;
40 static gulong probe_id;
42 static gint overrun_count;
44 static GMutex underrun_mutex;
45 static GCond underrun_cond;
46 static gint underrun_count;
50 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
54 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
60 queue_overrun (GstElement * queue, gpointer user_data)
63 GST_DEBUG ("queue overrun %d", overrun_count);
67 queue_underrun (GstElement * queue, gpointer user_data)
71 GST_DEBUG ("queue underrun %d", underrun_count);
77 event_func (GstPad * pad, GstObject * parent, GstEvent * event)
79 GST_DEBUG ("%s event", gst_event_type_get_name (GST_EVENT_TYPE (event)));
80 events = g_list_append (events, event);
88 while (events != NULL) {
89 gst_event_unref (GST_EVENT (events->data));
90 events = g_list_delete_link (events, events);
97 qsrcpad = gst_element_get_static_pad (queue, "src");
98 probe_id = gst_pad_add_probe (qsrcpad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM,
105 gst_pad_remove_probe (qsrcpad, probe_id);
106 gst_object_unref (qsrcpad);
112 GST_DEBUG ("setup_queue");
114 queue = gst_check_setup_element ("queue");
115 g_signal_connect (queue, "underrun", G_CALLBACK (queue_underrun), NULL);
117 mysrcpad = gst_check_setup_src_pad (queue, &srctemplate);
118 gst_pad_set_active (mysrcpad, TRUE);
132 GST_DEBUG ("cleanup_queue");
134 gst_check_drop_buffers ();
138 if (mysinkpad != NULL) {
139 gst_pad_set_active (mysinkpad, FALSE);
140 gst_check_teardown_sink_pad (queue);
143 gst_pad_set_active (mysrcpad, FALSE);
144 gst_check_teardown_src_pad (queue);
146 gst_check_teardown_element (queue);
150 /* setup the sinkpad on a playing queue element. gst_check_setup_sink_pad()
151 * does not work in this case since it does not activate the pad before linking
154 setup_sink_pad (GstElement * element, GstStaticPadTemplate * tmpl)
159 sinkpad = gst_pad_new_from_static_template (tmpl, "sink");
160 fail_if (sinkpad == NULL);
161 srcpad = gst_element_get_static_pad (element, "src");
162 fail_if (srcpad == NULL);
163 gst_pad_set_chain_function (sinkpad, gst_check_chain_func);
164 gst_pad_set_event_function (sinkpad, event_func);
165 gst_pad_set_active (sinkpad, TRUE);
166 fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK);
167 gst_object_unref (srcpad);
172 /* set queue size to 2 buffers
174 * check over/underuns
176 GST_START_TEST (test_non_leaky_underrun)
178 g_signal_connect (queue, "overrun", G_CALLBACK (queue_overrun), NULL);
179 g_object_set (G_OBJECT (queue), "max-size-buffers", 2, NULL);
180 mysinkpad = gst_check_setup_sink_pad (queue, &sinktemplate);
181 gst_pad_set_active (mysinkpad, TRUE);
183 GST_DEBUG ("starting");
186 fail_unless (gst_element_set_state (queue,
187 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
188 "could not set to playing");
192 fail_unless (overrun_count == 0);
193 fail_unless (underrun_count == 1);
195 GST_DEBUG ("stopping");
196 fail_unless (gst_element_set_state (queue,
197 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
203 queue_overrun_link_and_activate (GstElement * queue, gpointer user_data)
205 GST_DEBUG ("queue overrun");
208 /* link the src pad of the queue to make it dequeue buffers */
209 mysinkpad = setup_sink_pad (queue, &sinktemplate);
214 /* set queue size to 2 buffers
216 * check over/underuns
218 * check over/underuns again
220 GST_START_TEST (test_non_leaky_overrun)
227 g_signal_connect (queue, "overrun",
228 G_CALLBACK (queue_overrun_link_and_activate), NULL);
229 g_object_set (G_OBJECT (queue), "max-size-buffers", 2, NULL);
233 GST_DEBUG ("starting");
236 fail_unless (gst_element_set_state (queue,
237 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
238 "could not set to playing");
242 gst_pad_push_event (mysrcpad, gst_event_new_stream_start ("test"));
244 fail_unless (underrun_count == 1);
245 fail_unless (overrun_count == 0);
247 buffer1 = gst_buffer_new_and_alloc (4);
248 /* pushing gives away my reference */
249 gst_pad_push (mysrcpad, buffer1);
251 GST_DEBUG ("added 1st");
252 fail_unless (overrun_count == 0);
253 fail_unless (underrun_count == 1);
255 buffer2 = gst_buffer_new_and_alloc (4);
256 gst_pad_push (mysrcpad, buffer2);
258 GST_DEBUG ("added 2nd");
259 fail_unless (overrun_count == 0);
260 fail_unless (underrun_count == 1);
262 buffer3 = gst_buffer_new_and_alloc (4);
263 /* the next call to gst_pad_push will emit the overrun signal. The signal
264 * handler queue_overrun_link_and_activate() (above) increases overrun_count,
265 * activates and links mysinkpad. The queue task then dequeues a buffer and
266 * gst_pad_push() will return. */
267 gst_pad_push (mysrcpad, buffer3);
269 GST_DEBUG ("added 3rd");
270 fail_unless (overrun_count == 1);
272 /* lock the check_mutex to block the first buffer pushed to mysinkpad */
273 g_mutex_lock (&check_mutex);
274 /* now let the queue push all buffers */
275 while (g_list_length (buffers) < 3) {
276 g_cond_wait (&check_cond, &check_mutex);
278 g_mutex_unlock (&check_mutex);
280 fail_unless (overrun_count == 1);
281 /* make sure we get the underrun signal before we check underrun_count */
283 while (underrun_count < 2) {
286 /* we can't check the underrun_count here safely because when adding the 3rd
287 * buffer, the queue lock is released to emit the overrun signal and the
288 * downstream part can then push and empty the queue and signal an additional
290 /* fail_unless_equals_int (underrun_count, 2); */
293 buffer = g_list_nth (buffers, 0)->data;
294 fail_unless (buffer == buffer1);
296 buffer = g_list_nth (buffers, 1)->data;
297 fail_unless (buffer == buffer2);
299 GST_DEBUG ("stopping");
300 fail_unless (gst_element_set_state (queue,
301 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
306 /* set queue size to 2 buffers
308 * check over/underuns
310 * check over/underuns again
311 * check which buffer was leaked
313 GST_START_TEST (test_leaky_upstream)
320 g_signal_connect (queue, "overrun", G_CALLBACK (queue_overrun), NULL);
321 g_object_set (G_OBJECT (queue), "max-size-buffers", 2, "leaky", 1, NULL);
323 GST_DEBUG ("starting");
328 fail_unless (gst_element_set_state (queue,
329 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
330 "could not set to playing");
334 gst_pad_push_event (mysrcpad, gst_event_new_stream_start ("test"));
336 fail_unless (overrun_count == 0);
337 fail_unless (underrun_count == 1);
339 buffer1 = gst_buffer_new_and_alloc (4);
340 /* pushing gives away my reference */
341 gst_pad_push (mysrcpad, buffer1);
343 GST_DEBUG ("added 1st");
344 fail_unless (overrun_count == 0);
345 fail_unless (underrun_count == 1);
347 buffer2 = gst_buffer_new_and_alloc (4);
348 gst_pad_push (mysrcpad, buffer2);
350 GST_DEBUG ("added 2nd");
351 fail_unless (overrun_count == 0);
352 fail_unless (underrun_count == 1);
354 buffer3 = gst_buffer_new_and_alloc (4);
355 /* buffer4 will be leaked, keep a ref so refcount can be checked below */
356 gst_buffer_ref (buffer3);
357 gst_pad_push (mysrcpad, buffer3);
359 GST_DEBUG ("added 3nd");
360 /* it still triggers overrun when leaking */
361 fail_unless (overrun_count == 1);
362 fail_unless (underrun_count == 1);
364 /* wait for underrun and check that we got buffer1 and buffer2 only */
366 mysinkpad = setup_sink_pad (queue, &sinktemplate);
371 fail_unless (overrun_count == 1);
372 fail_unless (underrun_count == 2);
374 fail_unless (g_list_length (buffers) == 2);
376 buffer = g_list_nth (buffers, 0)->data;
377 fail_unless (buffer == buffer1);
379 buffer = g_list_nth (buffers, 1)->data;
380 fail_unless (buffer == buffer2);
382 ASSERT_BUFFER_REFCOUNT (buffer3, "buffer", 1);
383 gst_buffer_unref (buffer3);
385 GST_DEBUG ("stopping");
386 fail_unless (gst_element_set_state (queue,
387 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
392 /* set queue size to 2 buffers
394 * check over/underuns
396 * check over/underuns again
397 * check which buffer was leaked
399 GST_START_TEST (test_leaky_downstream)
406 g_signal_connect (queue, "overrun", G_CALLBACK (queue_overrun), NULL);
407 g_object_set (G_OBJECT (queue), "max-size-buffers", 2, "leaky", 2, NULL);
409 GST_DEBUG ("starting");
414 fail_unless (gst_element_set_state (queue,
415 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
416 "could not set to playing");
420 gst_pad_push_event (mysrcpad, gst_event_new_stream_start ("test"));
422 fail_unless (overrun_count == 0);
423 fail_unless (underrun_count == 1);
425 buffer1 = gst_buffer_new_and_alloc (4);
426 /* pushing gives away one reference */
427 /* buffer1 will be leaked, keep a ref so refcount can be checked below */
428 gst_buffer_ref (buffer1);
429 gst_pad_push (mysrcpad, buffer1);
431 GST_DEBUG ("added 1st");
432 fail_unless (overrun_count == 0);
433 fail_unless (underrun_count == 1);
435 buffer2 = gst_buffer_new_and_alloc (4);
436 gst_pad_push (mysrcpad, buffer2);
438 GST_DEBUG ("added 2nd");
439 fail_unless (overrun_count == 0);
440 fail_unless (underrun_count == 1);
442 buffer3 = gst_buffer_new_and_alloc (4);
443 gst_pad_push (mysrcpad, buffer3);
445 GST_DEBUG ("added 3rd");
446 /* it still triggers overrun when leaking */
447 fail_unless (overrun_count == 1);
448 fail_unless (underrun_count == 1);
450 /* wait for underrun and check that we got buffer1 and buffer2 only */
452 mysinkpad = setup_sink_pad (queue, &sinktemplate);
457 fail_unless (overrun_count == 1);
458 fail_unless (underrun_count == 2);
460 fail_unless (g_list_length (buffers) == 2);
462 ASSERT_BUFFER_REFCOUNT (buffer1, "buffer", 1);
463 gst_buffer_unref (buffer1);
465 buffer = g_list_nth (buffers, 0)->data;
466 fail_unless (buffer == buffer2);
468 buffer = g_list_nth (buffers, 1)->data;
469 fail_unless (buffer == buffer3);
471 GST_DEBUG ("stopping");
472 fail_unless (gst_element_set_state (queue,
473 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
478 /* set queue size to 6 buffers and 7 seconds
479 * push 7 buffers with and without duration
480 * check current-level-time
482 GST_START_TEST (test_time_level)
484 GstBuffer *buffer = NULL;
487 g_signal_connect (queue, "overrun",
488 G_CALLBACK (queue_overrun_link_and_activate), NULL);
489 g_object_set (G_OBJECT (queue), "max-size-buffers", 6, NULL);
490 g_object_set (G_OBJECT (queue), "max-size-time", 7 * GST_SECOND, NULL);
492 GST_DEBUG ("starting");
497 fail_unless (gst_element_set_state (queue,
498 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
499 "could not set to playing");
503 gst_pad_push_event (mysrcpad, gst_event_new_stream_start ("test"));
505 /* push buffer without duration */
506 buffer = gst_buffer_new_and_alloc (4);
507 GST_BUFFER_TIMESTAMP (buffer) = GST_SECOND;
508 /* pushing gives away my reference */
509 gst_pad_push (mysrcpad, buffer);
511 /* level should be 1 seconds because buffer has no duration and starts at 1
512 * SECOND (sparse stream). */
513 g_object_get (G_OBJECT (queue), "current-level-time", &time, NULL);
514 fail_if (time != GST_SECOND);
516 /* second push should set the level to 2 second */
517 buffer = gst_buffer_new_and_alloc (4);
518 GST_BUFFER_TIMESTAMP (buffer) = 2 * GST_SECOND;
519 gst_pad_push (mysrcpad, buffer);
521 g_object_get (G_OBJECT (queue), "current-level-time", &time, NULL);
522 fail_if (time != 2 * GST_SECOND);
524 /* third push should set the level to 4 seconds, the 1 second diff with the
525 * previous buffer (without duration) and the 1 second duration of this
527 buffer = gst_buffer_new_and_alloc (4);
528 GST_BUFFER_TIMESTAMP (buffer) = 3 * GST_SECOND;
529 GST_BUFFER_DURATION (buffer) = 1 * GST_SECOND;
530 ASSERT_BUFFER_REFCOUNT (buffer, "buffer", 1);
531 gst_pad_push (mysrcpad, buffer);
533 g_object_get (G_OBJECT (queue), "current-level-time", &time, NULL);
534 fail_if (time != 4 * GST_SECOND);
536 /* fourth push should set the level to 6 seconds, the 2 second diff with the
537 * previous buffer, same duration. */
538 buffer = gst_buffer_new_and_alloc (4);
539 GST_BUFFER_TIMESTAMP (buffer) = 5 * GST_SECOND;
540 GST_BUFFER_DURATION (buffer) = 1 * GST_SECOND;
541 ASSERT_BUFFER_REFCOUNT (buffer, "buffer", 1);
542 gst_pad_push (mysrcpad, buffer);
544 g_object_get (G_OBJECT (queue), "current-level-time", &time, NULL);
545 fail_if (time != 6 * GST_SECOND);
547 /* fifth push should not adjust the level, the timestamp and duration are the
548 * same, meaning the previous buffer did not really have a duration. */
549 buffer = gst_buffer_new_and_alloc (4);
550 GST_BUFFER_TIMESTAMP (buffer) = 5 * GST_SECOND;
551 GST_BUFFER_DURATION (buffer) = 1 * GST_SECOND;
552 gst_pad_push (mysrcpad, buffer);
554 g_object_get (G_OBJECT (queue), "current-level-time", &time, NULL);
555 fail_if (time != 6 * GST_SECOND);
557 /* sixth push should adjust the level with 1 second, we now know the
558 * previous buffer actually had a duration of 2 SECONDS */
559 buffer = gst_buffer_new_and_alloc (4);
560 GST_BUFFER_TIMESTAMP (buffer) = 7 * GST_SECOND;
561 gst_pad_push (mysrcpad, buffer);
563 g_object_get (G_OBJECT (queue), "current-level-time", &time, NULL);
564 fail_if (time != 7 * GST_SECOND);
566 /* eighth push should cause overrun */
567 fail_unless (overrun_count == 0);
568 buffer = gst_buffer_new_and_alloc (4);
569 GST_BUFFER_TIMESTAMP (buffer) = 8 * GST_SECOND;
570 /* the next call to gst_pad_push will emit the overrun signal. The signal
571 * handler queue_overrun_link_and_activate() (above) increases overrun_count,
572 * activates and links mysinkpad. The queue task then dequeues a buffer and
573 * gst_pad_push() will return. */
574 gst_pad_push (mysrcpad, buffer);
576 fail_unless (overrun_count == 1);
578 GST_DEBUG ("stopping");
579 fail_unless (gst_element_set_state (queue,
580 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
585 GST_START_TEST (test_time_level_task_not_started)
591 GST_DEBUG ("starting");
596 fail_unless (gst_element_set_state (queue,
597 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
598 "could not set to playing");
602 gst_pad_push_event (mysrcpad, gst_event_new_stream_start ("test"));
604 gst_segment_init (&segment, GST_FORMAT_TIME);
605 segment.start = 1 * GST_SECOND;
606 segment.stop = 5 * GST_SECOND;
608 segment.position = 1 * GST_SECOND;
610 event = gst_event_new_segment (&segment);
611 gst_pad_push_event (mysrcpad, event);
613 g_object_get (G_OBJECT (queue), "current-level-time", &time, NULL);
614 fail_if (time != 0 * GST_SECOND);
616 segment.base = 4 * GST_SECOND;
617 event = gst_event_new_segment (&segment);
618 gst_pad_push_event (mysrcpad, event);
620 g_object_get (G_OBJECT (queue), "current-level-time", &time, NULL);
621 GST_DEBUG ("time now %" GST_TIME_FORMAT, GST_TIME_ARGS (time));
622 fail_if (time != 4 * GST_SECOND);
626 GST_DEBUG ("stopping");
627 fail_unless (gst_element_set_state (queue,
628 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
633 GST_START_TEST (test_sticky_not_linked)
638 GstFlowReturn flow_ret;
640 GST_DEBUG ("starting");
642 g_object_set (queue, "max-size-buffers", 1, NULL);
645 fail_unless (gst_element_set_state (queue,
646 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
647 "could not set to playing");
651 gst_pad_push_event (mysrcpad, gst_event_new_stream_start ("test"));
653 gst_segment_init (&segment, GST_FORMAT_TIME);
654 segment.start = 1 * GST_SECOND;
655 segment.stop = 5 * GST_SECOND;
657 segment.position = 1 * GST_SECOND;
659 event = gst_event_new_segment (&segment);
660 ret = gst_pad_push_event (mysrcpad, event);
661 fail_unless (ret == TRUE);
663 /* the first few buffers can return OK as they are queued and gst_queue_loop
664 * is woken up, tries to push and sets ->srcresult to NOT_LINKED
666 flow_ret = GST_FLOW_OK;
667 while (flow_ret != GST_FLOW_NOT_LINKED)
668 flow_ret = gst_pad_push (mysrcpad, gst_buffer_new ());
670 /* send a new sticky event so that it will be pushed on the next gst_pad_push
672 event = gst_event_new_segment (&segment);
673 ret = gst_pad_push_event (mysrcpad, event);
674 fail_unless (ret == TRUE);
676 /* make sure that gst_queue_sink_event doesn't return FALSE if the queue is
677 * unlinked, as that would make gst_pad_push return ERROR
679 flow_ret = gst_pad_push (mysrcpad, gst_buffer_new ());
680 fail_unless_equals_int (flow_ret, GST_FLOW_NOT_LINKED);
682 GST_DEBUG ("stopping");
683 fail_unless (gst_element_set_state (queue,
684 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
691 event_equals_newsegment (GstEvent * event, gboolean update, gdouble rate,
692 GstFormat format, gint64 start, gint64 stop, gint64 position)
695 gdouble ns_rate, ns_arate;
701 if (GST_EVENT_TYPE (event) != GST_EVENT_SEGMENT) {
705 gst_event_parse_new_segment (event, &ns_update, &ns_rate, &ns_arate,
706 &ns_format, &ns_start, &ns_stop, &ns_position);
708 GST_DEBUG ("update %d, rate %lf, format %s, start %" GST_TIME_FORMAT
709 ", stop %" GST_TIME_FORMAT ", position %" GST_TIME_FORMAT, ns_update,
710 ns_rate, gst_format_get_name (ns_format), GST_TIME_ARGS (ns_start),
711 GST_TIME_ARGS (ns_stop), GST_TIME_ARGS (ns_position));
713 return (ns_update == update && ns_rate == rate && ns_format == format &&
714 ns_start == start && ns_stop == stop && ns_position == position);
717 GST_START_TEST (test_newsegment)
724 g_signal_connect (queue, "overrun", G_CALLBACK (queue_overrun), NULL);
725 g_object_set (G_OBJECT (queue), "max-size-buffers", 1, "max-size-time",
726 (guint64) 0, "leaky", 2, NULL);
728 GST_DEBUG ("starting");
730 fail_unless (gst_element_set_state (queue,
731 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
732 "could not set to playing");
733 fail_unless (overrun_count == 0);
734 fail_unless (underrun_count == 0);
736 event = gst_event_new_new_segment (FALSE, 2.0, 1.0, GST_FORMAT_TIME, 0,
738 gst_pad_push_event (mysrcpad, event);
740 GST_DEBUG ("added 1st newsegment");
741 fail_unless (overrun_count == 0);
742 fail_unless (underrun_count == 0);
744 event = gst_event_new_new_segment (FALSE, 1.0, 1.0, GST_FORMAT_TIME, 0,
746 gst_pad_push_event (mysrcpad, event);
748 GST_DEBUG ("added 2nd newsegment");
749 fail_unless (overrun_count == 0);
750 fail_unless (underrun_count == 0);
752 event = gst_event_new_new_segment (FALSE, 1.0, 1.0, GST_FORMAT_TIME,
753 4 * GST_SECOND, 5 * GST_SECOND, 4 * GST_SECOND);
754 gst_pad_push_event (mysrcpad, event);
756 GST_DEBUG ("added 3rd newsegment");
757 fail_unless (overrun_count == 0);
758 fail_unless (underrun_count == 0);
760 buffer1 = gst_buffer_new_and_alloc (4);
761 /* buffer1 will be leaked, keep a ref so refcount can be checked below */
762 gst_buffer_ref (buffer1);
763 /* pushing gives away one reference */
764 gst_pad_push (mysrcpad, buffer1);
766 GST_DEBUG ("added 1st buffer");
767 fail_unless (overrun_count == 0);
768 fail_unless (underrun_count == 0);
770 buffer2 = gst_buffer_new_and_alloc (4);
771 /* next push will cause overrun and leak all newsegment events and buffer1 */
772 gst_pad_push (mysrcpad, buffer2);
774 GST_DEBUG ("added 2nd buffer");
775 /* it still triggers overrun when leaking */
776 fail_unless (overrun_count == 1);
777 fail_unless (underrun_count == 0);
779 /* wait for underrun and check that we got one accumulated newsegment event,
780 * one real newsegment event and buffer2 only */
782 mysinkpad = setup_sink_pad (queue, &sinktemplate);
786 fail_unless (overrun_count == 1);
787 fail_unless (underrun_count == 1);
789 fail_unless (g_list_length (events) == 2);
791 event = g_list_nth (events, 0)->data;
792 fail_unless (event_equals_newsegment (event, FALSE, 1.0, GST_FORMAT_TIME, 0,
795 event = g_list_nth (events, 1)->data;
796 fail_unless (event_equals_newsegment (event, FALSE, 1.0, GST_FORMAT_TIME,
797 4 * GST_SECOND, 5 * GST_SECOND, 4 * GST_SECOND));
799 fail_unless (g_list_length (buffers) == 1);
801 ASSERT_BUFFER_REFCOUNT (buffer1, "buffer", 1);
802 gst_buffer_unref (buffer1);
804 buffer = g_list_nth (buffers, 0)->data;
805 fail_unless (buffer == buffer2);
807 GST_DEBUG ("stopping");
808 fail_unless (gst_element_set_state (queue,
809 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
816 thread_func (gpointer data)
819 for (i = 0; i < 100; i++) {
823 caps = gst_caps_new_any ();
824 query = gst_query_new_allocation (caps, FALSE);
825 ok = gst_pad_peer_query (mysrcpad, query);
826 gst_query_unref (query);
827 gst_caps_unref (caps);
838 static gboolean query_func (GstPad * pad, GstObject * parent, GstQuery * query);
841 query_func (GstPad * pad, GstObject * parent, GstQuery * query)
848 GST_START_TEST (test_queries_while_flushing)
854 mysinkpad = gst_check_setup_sink_pad (queue, &sinktemplate);
855 gst_pad_set_query_function (mysinkpad, query_func);
856 gst_pad_set_active (mysinkpad, TRUE);
858 /* hard to reproduce, so just run it a few times in a row */
859 for (i = 0; i < 500; ++i) {
860 GST_DEBUG ("starting");
862 fail_unless (gst_element_set_state (queue,
863 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
864 "could not set to playing");
868 thread = g_thread_new ("deactivating thread", thread_func, NULL);
871 event = gst_event_new_flush_start ();
872 gst_pad_push_event (mysrcpad, event);
874 g_thread_join (thread);
876 GST_DEBUG ("stopping");
877 fail_unless (gst_element_set_state (queue,
878 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS,
879 "could not set to null");
888 Suite *s = suite_create ("queue");
889 TCase *tc_chain = tcase_create ("general");
891 suite_add_tcase (s, tc_chain);
892 tcase_add_checked_fixture (tc_chain, setup, cleanup);
893 tcase_add_test (tc_chain, test_non_leaky_underrun);
894 tcase_add_test (tc_chain, test_non_leaky_overrun);
895 tcase_add_test (tc_chain, test_leaky_upstream);
896 tcase_add_test (tc_chain, test_leaky_downstream);
897 tcase_add_test (tc_chain, test_time_level);
898 tcase_add_test (tc_chain, test_time_level_task_not_started);
899 tcase_add_test (tc_chain, test_queries_while_flushing);
901 tcase_add_test (tc_chain, test_newsegment);
903 tcase_add_test (tc_chain, test_sticky_not_linked);
908 GST_CHECK_MAIN (queue);