1 /* GStreamer unit tests for queue2
2 *
3 * Copyright (C) 2011 Tim-Philipp Müller <tim centricular net>
4 *
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.
9 *
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.
14 *
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., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include <gst/check/gstcheck.h>
25
26 static GstElement *
setup_queue2(GstElement * pipe,GstElement * input,GstElement * output)27 setup_queue2 (GstElement * pipe, GstElement * input, GstElement * output)
28 {
29 GstElement *queue2;
30 GstPad *sinkpad, *srcpad;
31
32 queue2 = gst_element_factory_make ("queue2", NULL);
33 fail_unless (queue2 != NULL, "failed to create 'queue2' element");
34
35 gst_bin_add (GST_BIN (pipe), queue2);
36 gst_bin_add (GST_BIN (pipe), input);
37 gst_bin_add (GST_BIN (pipe), output);
38
39 sinkpad = gst_element_get_static_pad (queue2, "sink");
40 fail_unless (sinkpad != NULL, "failed to get queue2 sink pad");
41
42 srcpad = gst_element_get_static_pad (input, "src");
43 fail_unless (srcpad != NULL, "failed to find src pad for input element");
44
45 fail_unless_equals_int (GST_PAD_LINK_OK, gst_pad_link (srcpad, sinkpad));
46 gst_object_unref (srcpad);
47 gst_object_unref (sinkpad);
48
49 srcpad = gst_element_get_static_pad (queue2, "src");
50 fail_unless (srcpad != NULL);
51
52 sinkpad = gst_element_get_static_pad (output, "sink");
53 fail_unless (sinkpad != NULL, "failed to find sink pad of output element");
54
55 fail_unless_equals_int (GST_PAD_LINK_OK, gst_pad_link (srcpad, sinkpad));
56
57 gst_object_unref (srcpad);
58 gst_object_unref (sinkpad);
59
60 return queue2;
61 }
62
GST_START_TEST(test_simple_pipeline)63 GST_START_TEST (test_simple_pipeline)
64 {
65 GstElement *pipe, *input, *output;
66 GstMessage *msg;
67
68 pipe = gst_pipeline_new ("pipeline");
69
70 input = gst_element_factory_make ("fakesrc", NULL);
71 fail_unless (input != NULL, "failed to create 'fakesrc' element");
72 g_object_set (input, "num-buffers", 256, "sizetype", 3, NULL);
73
74 output = gst_element_factory_make ("fakesink", NULL);
75 fail_unless (output != NULL, "failed to create 'fakesink' element");
76
77 setup_queue2 (pipe, input, output);
78
79 gst_element_set_state (pipe, GST_STATE_PLAYING);
80
81 msg = gst_bus_poll (GST_ELEMENT_BUS (pipe),
82 GST_MESSAGE_EOS | GST_MESSAGE_ERROR, -1);
83
84 fail_if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR,
85 "Expected EOS message, got ERROR message");
86 gst_message_unref (msg);
87
88 GST_LOG ("Got EOS, cleaning up");
89
90 gst_element_set_state (pipe, GST_STATE_NULL);
91 gst_object_unref (pipe);
92 }
93
94 GST_END_TEST;
95
GST_START_TEST(test_simple_pipeline_ringbuffer)96 GST_START_TEST (test_simple_pipeline_ringbuffer)
97 {
98 GstElement *pipe, *queue2, *input, *output;
99 GstMessage *msg;
100
101 pipe = gst_pipeline_new ("pipeline");
102
103 input = gst_element_factory_make ("fakesrc", NULL);
104 fail_unless (input != NULL, "failed to create 'fakesrc' element");
105 g_object_set (input, "num-buffers", 256, "sizetype", 3, NULL);
106
107 output = gst_element_factory_make ("fakesink", NULL);
108 fail_unless (output != NULL, "failed to create 'fakesink' element");
109
110 queue2 = setup_queue2 (pipe, input, output);
111 g_object_set (queue2, "ring-buffer-max-size", (guint64) 1024 * 50, NULL);
112
113 gst_element_set_state (pipe, GST_STATE_PLAYING);
114
115 msg = gst_bus_poll (GST_ELEMENT_BUS (pipe),
116 GST_MESSAGE_EOS | GST_MESSAGE_ERROR, -1);
117
118 fail_if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR,
119 "Expected EOS message, got ERROR message");
120 gst_message_unref (msg);
121
122 GST_LOG ("Got EOS, cleaning up");
123
124 gst_element_set_state (pipe, GST_STATE_NULL);
125 gst_object_unref (pipe);
126 }
127
128 GST_END_TEST;
129
130 static void
do_test_simple_shutdown_while_running(guint64 ring_buffer_max_size)131 do_test_simple_shutdown_while_running (guint64 ring_buffer_max_size)
132 {
133 GstElement *pipe, *q2;
134 GstElement *input;
135 GstElement *output;
136 GstMessage *msg;
137
138 pipe = gst_pipeline_new ("pipeline");
139
140 input = gst_element_factory_make ("fakesrc", NULL);
141 fail_unless (input != NULL, "failed to create 'fakesrc' element");
142 g_object_set (input, "format", GST_FORMAT_TIME, "sizetype", 2,
143 "sizemax", 10, NULL);
144
145 output = gst_element_factory_make ("fakesink", NULL);
146 fail_unless (output != NULL, "failed to create 'fakesink' element");
147
148 q2 = setup_queue2 (pipe, input, output);
149
150 if (ring_buffer_max_size > 0) {
151 g_object_set (q2, "ring-buffer-max-size", ring_buffer_max_size,
152 "temp-template", NULL, NULL);
153 }
154
155 gst_element_set_state (pipe, GST_STATE_PAUSED);
156
157 /* wait until pipeline is up and running */
158 msg = gst_bus_poll (GST_ELEMENT_BUS (pipe),
159 GST_MESSAGE_ERROR | GST_MESSAGE_ASYNC_DONE, -1);
160 fail_if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR, "Got ERROR message");
161 gst_message_unref (msg);
162
163 GST_LOG ("pipeline is running now");
164 gst_element_set_state (pipe, GST_STATE_PLAYING);
165 g_usleep (G_USEC_PER_SEC / 20);
166
167 /* now shut down only the sink, so the queue gets a wrong-state flow return */
168 gst_element_set_state (output, GST_STATE_NULL);
169 GST_LOG ("Cleaning up");
170
171 gst_element_set_state (pipe, GST_STATE_NULL);
172 gst_object_unref (pipe);
173 }
174
GST_START_TEST(test_simple_shutdown_while_running)175 GST_START_TEST (test_simple_shutdown_while_running)
176 {
177 int i;
178
179 /* run a couple of iterations, gives higher chance of different code paths
180 * being executed at time the flush is detected (esp. useful to make sure
181 * things are cleaned up properly when running under valgrind) */
182 for (i = 0; i < 10; ++i) {
183 do_test_simple_shutdown_while_running (0);
184 }
185 }
186
187 GST_END_TEST;
188
GST_START_TEST(test_simple_shutdown_while_running_ringbuffer)189 GST_START_TEST (test_simple_shutdown_while_running_ringbuffer)
190 {
191 int i;
192
193 /* run a couple of iterations, gives higher chance of different code paths
194 * being executed at time the flush is detected (esp. useful to make sure
195 * things are cleaned up properly when running under valgrind) */
196 for (i = 0; i < 10; ++i) {
197 do_test_simple_shutdown_while_running (1024 * 1024);
198 }
199 }
200
201 GST_END_TEST;
202
GST_START_TEST(test_simple_create_destroy)203 GST_START_TEST (test_simple_create_destroy)
204 {
205 GstElement *queue2;
206
207 queue2 = gst_element_factory_make ("queue2", NULL);
208 gst_object_unref (queue2);
209 }
210
211 GST_END_TEST;
212
213 static gboolean
queue2_dummypad_query(GstPad * sinkpad,GstObject * parent,GstQuery * query)214 queue2_dummypad_query (GstPad * sinkpad, GstObject * parent, GstQuery * query)
215 {
216 gboolean res = TRUE;
217
218 switch (GST_QUERY_TYPE (query)) {
219 case GST_QUERY_CAPS:
220 {
221 GstCaps *filter, *caps;
222
223 gst_query_parse_caps (query, &filter);
224 caps = (filter ? gst_caps_ref (filter) : gst_caps_new_any ());
225 gst_query_set_caps_result (query, caps);
226 gst_caps_unref (caps);
227 break;
228 }
229 default:
230 res = gst_pad_query_default (sinkpad, parent, query);
231 break;
232 }
233 return res;
234 }
235
236 static gpointer
pad_push_datablock_thread(gpointer data)237 pad_push_datablock_thread (gpointer data)
238 {
239 GstPad *pad = data;
240 GstBuffer *buf;
241
242 buf = gst_buffer_new_allocate (NULL, 80 * 1000, NULL);
243 gst_pad_push (pad, buf);
244
245 return NULL;
246 }
247
248 static GstPadProbeReturn
block_without_queries_probe(GstPad * pad,GstPadProbeInfo * info,gpointer user_data)249 block_without_queries_probe (GstPad * pad, GstPadProbeInfo * info,
250 gpointer user_data)
251 {
252 GstPadProbeReturn ret = GST_PAD_PROBE_OK;
253
254 /* allows queries to pass through */
255 if ((GST_PAD_PROBE_INFO_TYPE (info) & GST_PAD_PROBE_TYPE_QUERY_BOTH) != 0)
256 ret = GST_PAD_PROBE_PASS;
257
258 return ret;
259 }
260
261 #define CHECK_FOR_BUFFERING_MSG(PIPELINE, EXPECTED_PERC) \
262 G_STMT_START { \
263 gint buf_perc; \
264 GstMessage *msg; \
265 GST_LOG ("waiting for %d%% buffering message", (EXPECTED_PERC)); \
266 msg = gst_bus_poll (GST_ELEMENT_BUS (PIPELINE), \
267 GST_MESSAGE_BUFFERING | GST_MESSAGE_ERROR, -1); \
268 fail_if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR, \
269 "Expected BUFFERING message, got ERROR message"); \
270 gst_message_parse_buffering (msg, &buf_perc); \
271 gst_message_unref (msg); \
272 fail_unless (buf_perc == (EXPECTED_PERC), \
273 "Got incorrect percentage: %d%% expected: %d%%", buf_perc, \
274 (EXPECTED_PERC)); \
275 } G_STMT_END
276
GST_START_TEST(test_watermark_and_fill_level)277 GST_START_TEST (test_watermark_and_fill_level)
278 {
279 /* This test checks the behavior of the fill level and
280 * the low/high watermarks. It also checks if the
281 * low/high-percent and low/high-watermark properties
282 * are coupled together properly. */
283
284 GstElement *pipe;
285 GstElement *queue2, *fakesink;
286 GstPad *inputpad;
287 GstPad *queue2_sinkpad;
288 GstPad *sinkpad;
289 GstSegment segment;
290 GThread *thread;
291 gint low_perc, high_perc;
292
293
294 /* Setup test pipeline with one multiqueue and one fakesink */
295
296 pipe = gst_pipeline_new ("pipeline");
297 queue2 = gst_element_factory_make ("queue2", NULL);
298 fail_unless (queue2 != NULL);
299 gst_bin_add (GST_BIN (pipe), queue2);
300
301 fakesink = gst_element_factory_make ("fakesink", NULL);
302 fail_unless (fakesink != NULL);
303 gst_bin_add (GST_BIN (pipe), fakesink);
304
305 /* Block fakesink sinkpad flow to ensure the queue isn't emptied
306 * by the prerolling sink */
307 sinkpad = gst_element_get_static_pad (fakesink, "sink");
308 gst_pad_add_probe (sinkpad, GST_PAD_PROBE_TYPE_BLOCK,
309 block_without_queries_probe, NULL, NULL);
310 gst_object_unref (sinkpad);
311
312 g_object_set (queue2,
313 "use-buffering", (gboolean) TRUE,
314 "max-size-bytes", (guint) 1000 * 1000,
315 "max-size-buffers", (guint) 0,
316 "max-size-time", (guint64) 0,
317 "low-watermark", (gdouble) 0.01, "high-watermark", (gdouble) 0.10, NULL);
318
319 g_object_get (queue2, "low-percent", &low_perc,
320 "high-percent", &high_perc, NULL);
321
322 /* Check that low/high-watermark and low/high-percent are
323 * coupled properly. (low/high-percent are deprecated and
324 * exist for backwards compatibility.) */
325 fail_unless_equals_int (low_perc, 1);
326 fail_unless_equals_int (high_perc, 10);
327
328 gst_segment_init (&segment, GST_FORMAT_TIME);
329
330 inputpad = gst_pad_new ("dummysrc", GST_PAD_SRC);
331 gst_pad_set_query_function (inputpad, queue2_dummypad_query);
332
333 queue2_sinkpad = gst_element_get_static_pad (queue2, "sink");
334 fail_unless (queue2_sinkpad != NULL);
335 fail_unless (gst_pad_link (inputpad, queue2_sinkpad) == GST_PAD_LINK_OK);
336
337 gst_pad_set_active (inputpad, TRUE);
338
339 gst_pad_push_event (inputpad, gst_event_new_stream_start ("test"));
340 gst_pad_push_event (inputpad, gst_event_new_segment (&segment));
341
342 gst_object_unref (queue2_sinkpad);
343
344 fail_unless (gst_element_link (queue2, fakesink));
345
346 /* Start pipeline in paused state to ensure the sink remains
347 * in preroll mode and blocks */
348 gst_element_set_state (pipe, GST_STATE_PAUSED);
349
350 /* When the use-buffering property is set to TRUE, a buffering
351 * message is posted. Since the queue is empty at that point,
352 * the buffering message contains a value of 0%. */
353 CHECK_FOR_BUFFERING_MSG (pipe, 0);
354
355 /* Feed data. queue will be filled to 80% (because it pushes 80000 bytes),
356 * which is below the high-threshold, provoking a buffering message. */
357 thread = g_thread_new ("push1", pad_push_datablock_thread, inputpad);
358 g_thread_join (thread);
359
360 /* Check for the buffering message; it should indicate 80% fill level
361 * (Note that the percentage from the message is normalized) */
362 CHECK_FOR_BUFFERING_MSG (pipe, 80);
363
364 /* Increase the buffer size and lower the watermarks to test
365 * if <1% watermarks are supported. */
366 g_object_set (queue2,
367 "max-size-bytes", (guint) 20 * 1000 * 1000,
368 "low-watermark", (gdouble) 0.0001, "high-watermark", (gdouble) 0.005,
369 NULL);
370
371 /* First buffering message is posted after the max-size-bytes limit
372 * is set to 20000000 bytes & the low-watermark is set. Since the
373 * queue contains 80000 bytes, and the high watermark still is
374 * 0.1 at this point, and the buffer level 80000 / 20000000 = 0.004 is
375 * normalized by 0.1: 0.004 / 0.1 => buffering percentage 4%. */
376 CHECK_FOR_BUFFERING_MSG (pipe, 4);
377 /* Second buffering message is posted after the high-watermark limit
378 * is set to 0.005. This time, the buffer level is normalized this way:
379 * 0.004 / 0.005 => buffering percentage 80%. */
380 CHECK_FOR_BUFFERING_MSG (pipe, 80);
381
382 gst_element_set_state (pipe, GST_STATE_NULL);
383 gst_object_unref (pipe);
384 gst_object_unref (inputpad);
385 }
386
387 GST_END_TEST;
388
389 static gpointer
push_buffer(GstPad * sinkpad)390 push_buffer (GstPad * sinkpad)
391 {
392 GstBuffer *buffer;
393
394 buffer = gst_buffer_new_and_alloc (1 * 1024);
395
396 gst_pad_chain (sinkpad, buffer);
397
398 return NULL;
399 }
400
GST_START_TEST(test_filled_read)401 GST_START_TEST (test_filled_read)
402 {
403 GstElement *queue2;
404 GstBuffer *buffer;
405 GstPad *sinkpad, *srcpad;
406 GThread *thread;
407 GstSegment segment;
408
409 queue2 = gst_element_factory_make ("queue2", NULL);
410 sinkpad = gst_element_get_static_pad (queue2, "sink");
411 srcpad = gst_element_get_static_pad (queue2, "src");
412
413 g_object_set (queue2, "ring-buffer-max-size", (guint64) 5 * 1024,
414 "use-buffering", FALSE,
415 "max-size-buffers", (guint) 0, "max-size-time", (guint64) 0,
416 "max-size-bytes", (guint) 4 * 1024, NULL);
417
418 gst_pad_activate_mode (srcpad, GST_PAD_MODE_PULL, TRUE);
419 gst_element_set_state (queue2, GST_STATE_PLAYING);
420
421 gst_segment_init (&segment, GST_FORMAT_BYTES);
422 gst_pad_send_event (sinkpad, gst_event_new_stream_start ("test"));
423 gst_pad_send_event (sinkpad, gst_event_new_segment (&segment));
424
425 /* fill up the buffer */
426 buffer = gst_buffer_new_and_alloc (4 * 1024);
427 fail_unless (gst_pad_chain (sinkpad, buffer) == GST_FLOW_OK);
428
429 thread =
430 g_thread_try_new ("gst-check", (GThreadFunc) push_buffer, sinkpad, NULL);
431 fail_unless (thread != NULL);
432
433 buffer = NULL;
434 fail_unless (gst_pad_get_range (srcpad, 1024, 4 * 1024,
435 &buffer) == GST_FLOW_OK);
436
437 fail_unless (gst_buffer_get_size (buffer) == 4 * 1024);
438 gst_buffer_unref (buffer);
439
440 gst_element_set_state (queue2, GST_STATE_NULL);
441
442 g_thread_join (thread);
443
444 gst_object_unref (sinkpad);
445 gst_object_unref (srcpad);
446 gst_object_unref (queue2);
447 }
448
449 GST_END_TEST;
450
451
452 static GstPadProbeReturn
block_callback(GstPad * pad,GstPadProbeInfo * info,gpointer user_data)453 block_callback (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
454 {
455 return GST_PAD_PROBE_OK;
456 }
457
GST_START_TEST(test_percent_overflow)458 GST_START_TEST (test_percent_overflow)
459 {
460 GstElement *queue2;
461 GstBuffer *buffer;
462 GstPad *sinkpad, *srcpad;
463 gulong block_probe;
464 guint64 i;
465 guint64 current_level_time;
466 GstSegment segment;
467
468 queue2 = gst_element_factory_make ("queue2", NULL);
469 sinkpad = gst_element_get_static_pad (queue2, "sink");
470 srcpad = gst_element_get_static_pad (queue2, "src");
471
472 block_probe = gst_pad_add_probe (srcpad,
473 GST_PAD_PROBE_TYPE_BLOCK | GST_PAD_PROBE_TYPE_BUFFER,
474 block_callback, NULL, NULL);
475
476 g_object_set (queue2, "use-buffering", TRUE,
477 "use-rate-estimate", FALSE,
478 "max-size-buffers", 0,
479 "max-size-time", 2 * GST_SECOND, "max-size-bytes", 0, NULL);
480
481 gst_pad_activate_mode (srcpad, GST_PAD_MODE_PUSH, TRUE);
482 gst_element_set_state (queue2, GST_STATE_PAUSED);
483
484 gst_segment_init (&segment, GST_FORMAT_TIME);
485 segment.start = 0;
486 segment.time = 0;
487 segment.position = 0;
488 gst_pad_send_event (sinkpad, gst_event_new_stream_start ("test"));
489 gst_pad_send_event (sinkpad, gst_event_new_segment (&segment));
490
491 /* push 2 seconds of data with valid but excessively high timestamps */
492 for (i = 0; i < 20; i++) {
493 buffer = gst_buffer_new_and_alloc (1024);
494 GST_BUFFER_PTS (buffer) =
495 G_GUINT64_CONSTANT (18446744071709551616) + i * (GST_SECOND / 10);
496 GST_BUFFER_DTS (buffer) =
497 G_GUINT64_CONSTANT (18446744071709551616) + i * (GST_SECOND / 10);
498 GST_BUFFER_DURATION (buffer) = (GST_SECOND / 10);
499 fail_unless (gst_pad_chain (sinkpad, buffer) == GST_FLOW_OK);
500 }
501
502 g_object_get (queue2, "current-level-time", ¤t_level_time, NULL);
503
504 gst_pad_remove_probe (srcpad, block_probe);
505
506 gst_element_set_state (queue2, GST_STATE_NULL);
507
508 gst_object_unref (sinkpad);
509 gst_object_unref (srcpad);
510 gst_object_unref (queue2);
511 }
512
513 GST_END_TEST;
514
GST_START_TEST(test_small_ring_buffer)515 GST_START_TEST (test_small_ring_buffer)
516 {
517 GstElement *pipeline;
518 GstElement *queue2;
519 const gchar *desc;
520 GstBus *bus;
521 GstMessage *msg;
522
523 /* buffer too small to seek used to crash, test for regression */
524 desc = "fakesrc sizetype=2 sizemax=4096 num-buffers=100 datarate=1000 ! "
525 "queue2 ring-buffer-max-size=1000 name=q2 ! fakesink sync=true";
526
527 pipeline = gst_parse_launch (desc, NULL);
528 fail_if (pipeline == NULL);
529
530 queue2 = gst_bin_get_by_name (GST_BIN (pipeline), "q2");
531 fail_if (queue2 == NULL);
532
533 /* bring the pipeline to PLAYING, then start switching */
534 bus = gst_element_get_bus (pipeline);
535 fail_if (bus == NULL);
536 gst_element_set_state (pipeline, GST_STATE_PLAYING);
537 /* Wait for the pipeline to hit playing */
538 gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
539
540 /* now wait for completion or error */
541 msg = gst_bus_poll (bus, GST_MESSAGE_EOS | GST_MESSAGE_ERROR, -1);
542 fail_if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR,
543 "Expected EOS message, got ERROR message");
544 gst_message_unref (msg);
545
546 gst_element_set_state (pipeline, GST_STATE_NULL);
547 gst_object_unref (queue2);
548 gst_object_unref (bus);
549 gst_object_unref (pipeline);
550 }
551
552 GST_END_TEST;
553
554 #define DOWNSTREAM_BITRATE (8 * 100 * 1000)
555
556 static GstPadProbeReturn
bitrate_query_probe(GstPad * pad,GstPadProbeInfo * info,gpointer user_data)557 bitrate_query_probe (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
558 {
559 GstPadProbeReturn ret = GST_PAD_PROBE_OK;
560
561 /* allows queries to pass through */
562 if ((GST_PAD_PROBE_INFO_TYPE (info) & GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM) !=
563 0) {
564 GstQuery *query = GST_PAD_PROBE_INFO_QUERY (info);
565
566 switch (GST_QUERY_TYPE (query)) {
567 case GST_QUERY_BITRATE:{
568 gst_query_set_bitrate (query, DOWNSTREAM_BITRATE);
569 ret = GST_PAD_PROBE_HANDLED;
570 break;
571 }
572 default:
573 break;
574 }
575 }
576
577 return ret;
578 }
579
GST_START_TEST(test_bitrate_query)580 GST_START_TEST (test_bitrate_query)
581 {
582 /* This test checks the behavior of the bitrate query usage with the
583 * fill levels and buffering messages */
584
585 GstElement *pipe;
586 GstElement *queue2, *fakesink;
587 GstPad *inputpad;
588 GstPad *queue2_sinkpad;
589 GstPad *sinkpad;
590 GstSegment segment;
591 GThread *thread;
592
593 /* Setup test pipeline with one queue2 and one fakesink */
594
595 pipe = gst_pipeline_new ("pipeline");
596 queue2 = gst_element_factory_make ("queue2", NULL);
597 fail_unless (queue2 != NULL);
598 gst_bin_add (GST_BIN (pipe), queue2);
599
600 fakesink = gst_element_factory_make ("fakesink", NULL);
601 fail_unless (fakesink != NULL);
602 gst_bin_add (GST_BIN (pipe), fakesink);
603
604 /* Block fakesink sinkpad flow to ensure the queue isn't emptied
605 * by the prerolling sink */
606 sinkpad = gst_element_get_static_pad (fakesink, "sink");
607 gst_pad_add_probe (sinkpad, GST_PAD_PROBE_TYPE_BLOCK,
608 block_without_queries_probe, NULL, NULL);
609 gst_pad_add_probe (sinkpad, GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM,
610 bitrate_query_probe, NULL, NULL);
611 gst_object_unref (sinkpad);
612
613 g_object_set (queue2,
614 "use-buffering", (gboolean) TRUE,
615 "use-bitrate-query", (gboolean) TRUE,
616 "max-size-bytes", (guint) 0,
617 "max-size-buffers", (guint) 0,
618 "max-size-time", (guint64) 1 * GST_SECOND, NULL);
619
620 gst_segment_init (&segment, GST_FORMAT_TIME);
621
622 inputpad = gst_pad_new ("dummysrc", GST_PAD_SRC);
623 gst_pad_set_query_function (inputpad, queue2_dummypad_query);
624
625 queue2_sinkpad = gst_element_get_static_pad (queue2, "sink");
626 fail_unless (queue2_sinkpad != NULL);
627 fail_unless (gst_pad_link (inputpad, queue2_sinkpad) == GST_PAD_LINK_OK);
628
629 gst_pad_set_active (inputpad, TRUE);
630
631 gst_pad_push_event (inputpad, gst_event_new_stream_start ("test"));
632 gst_pad_push_event (inputpad, gst_event_new_segment (&segment));
633
634 gst_object_unref (queue2_sinkpad);
635
636 fail_unless (gst_element_link (queue2, fakesink));
637
638 /* Start pipeline in paused state to ensure the sink remains
639 * in preroll mode and blocks */
640 gst_element_set_state (pipe, GST_STATE_PAUSED);
641
642 /* When the use-buffering property is set to TRUE, a buffering
643 * message is posted. Since the queue is empty at that point,
644 * the buffering message contains a value of 0%. */
645 CHECK_FOR_BUFFERING_MSG (pipe, 0);
646
647 /* Feed data. queue will be filled to 80% (80000 bytes is pushed and
648 * with a bitrate of 100 * 1000, 80000 bytes is 80% of 1 second of data as
649 * set in the max-size-time limit) */
650 thread = g_thread_new ("push1", pad_push_datablock_thread, inputpad);
651 g_thread_join (thread);
652
653 /* Check for the buffering message; it should indicate 80% fill level
654 * (Note that the percentage from the message is normalized) */
655 CHECK_FOR_BUFFERING_MSG (pipe, 80);
656
657 gst_element_set_state (pipe, GST_STATE_NULL);
658 gst_object_unref (pipe);
659 gst_object_unref (inputpad);
660 }
661
662 GST_END_TEST;
663
664 static Suite *
queue2_suite(void)665 queue2_suite (void)
666 {
667 Suite *s = suite_create ("queue2");
668 TCase *tc_chain = tcase_create ("general");
669
670 suite_add_tcase (s, tc_chain);
671 tcase_add_test (tc_chain, test_simple_create_destroy);
672 tcase_add_test (tc_chain, test_simple_pipeline);
673 tcase_add_test (tc_chain, test_simple_pipeline_ringbuffer);
674 tcase_add_test (tc_chain, test_simple_shutdown_while_running);
675 tcase_add_test (tc_chain, test_simple_shutdown_while_running_ringbuffer);
676 tcase_add_test (tc_chain, test_watermark_and_fill_level);
677 tcase_add_test (tc_chain, test_filled_read);
678 tcase_add_test (tc_chain, test_percent_overflow);
679 tcase_add_test (tc_chain, test_small_ring_buffer);
680 tcase_add_test (tc_chain, test_bitrate_query);
681
682 return s;
683 }
684
685 GST_CHECK_MAIN (queue2)
686