1 /* GStreamer
2  *
3  * Copyright (C) 2010, Thiago Santos <thiago.sousa.santos@collabora.co.uk>
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 
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 
25 #include <gst/check/gstcheck.h>
26 #include <gst/app/gstappsrc.h>
27 #include <gst/app/gstappsink.h>
28 
29 #ifdef HAVE_VALGRIND
30 #include <valgrind/valgrind.h>
31 #else
32 #define RUNNING_ON_VALGRIND FALSE
33 #endif
34 
35 #define SAMPLE_CAPS "application/x-gst-check-test"
36 
37 static GstPad *mysinkpad;
38 
39 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
40     GST_PAD_SINK,
41     GST_PAD_ALWAYS,
42     GST_STATIC_CAPS_ANY);
43 
44 static GstElement *
setup_appsrc(void)45 setup_appsrc (void)
46 {
47   GstElement *appsrc;
48 
49   GST_DEBUG ("setup_appsrc");
50   appsrc = gst_check_setup_element ("appsrc");
51   mysinkpad = gst_check_setup_sink_pad (appsrc, &sinktemplate);
52 
53   gst_pad_set_active (mysinkpad, TRUE);
54 
55   return appsrc;
56 }
57 
58 static void
cleanup_appsrc(GstElement * appsrc)59 cleanup_appsrc (GstElement * appsrc)
60 {
61   GST_DEBUG ("cleanup_appsrc");
62 
63   gst_check_drop_buffers ();
64   gst_check_teardown_sink_pad (appsrc);
65   gst_check_teardown_element (appsrc);
66 }
67 
68 /*
69  * Pushes 4 buffers into appsrc and checks the caps on them on the output.
70  *
71  * Appsrc is configured with caps=SAMPLE_CAPS, so the buffers should have the
72  * same caps that they were pushed with.
73  *
74  * The 4 buffers have NULL, SAMPLE_CAPS, NULL, SAMPLE_CAPS caps,
75  * respectively.
76  */
GST_START_TEST(test_appsrc_non_null_caps)77 GST_START_TEST (test_appsrc_non_null_caps)
78 {
79   GstElement *src;
80   GstBuffer *buffer;
81   GstCaps *caps, *ccaps;
82 
83   src = setup_appsrc ();
84 
85   caps = gst_caps_from_string (SAMPLE_CAPS);
86   g_object_set (src, "caps", caps, NULL);
87 
88   ASSERT_SET_STATE (src, GST_STATE_PLAYING, GST_STATE_CHANGE_SUCCESS);
89 
90   buffer = gst_buffer_new_and_alloc (4);
91   fail_unless (gst_app_src_push_buffer (GST_APP_SRC (src),
92           buffer) == GST_FLOW_OK);
93 
94   buffer = gst_buffer_new_and_alloc (4);
95   fail_unless (gst_app_src_push_buffer (GST_APP_SRC (src),
96           buffer) == GST_FLOW_OK);
97 
98   buffer = gst_buffer_new_and_alloc (4);
99   fail_unless (gst_app_src_push_buffer (GST_APP_SRC (src),
100           buffer) == GST_FLOW_OK);
101 
102   buffer = gst_buffer_new_and_alloc (4);
103   fail_unless (gst_app_src_push_buffer (GST_APP_SRC (src),
104           buffer) == GST_FLOW_OK);
105 
106   fail_unless (gst_app_src_end_of_stream (GST_APP_SRC (src)) == GST_FLOW_OK);
107 
108   /* Give some time to the appsrc loop to push the buffers */
109   g_usleep (G_USEC_PER_SEC * 3);
110 
111   /* Check the output caps */
112   fail_unless (g_list_length (buffers) == 4);
113 
114   ccaps = gst_pad_get_current_caps (mysinkpad);
115   fail_unless (gst_caps_is_equal (ccaps, caps));
116   gst_caps_unref (ccaps);
117 
118   ASSERT_SET_STATE (src, GST_STATE_NULL, GST_STATE_CHANGE_SUCCESS);
119   gst_caps_unref (caps);
120   cleanup_appsrc (src);
121 }
122 
123 GST_END_TEST;
124 
125 static GstAppSinkCallbacks app_callbacks;
126 
127 typedef struct
128 {
129   GstElement *source;
130   GstElement *sink;
131 } ProgramData;
132 
133 static GstFlowReturn
on_new_sample_from_source(GstAppSink * elt,gpointer user_data)134 on_new_sample_from_source (GstAppSink * elt, gpointer user_data)
135 {
136   ProgramData *data = (ProgramData *) user_data;
137   GstSample *sample;
138   GstBuffer *buffer;
139   GstElement *source;
140 
141   sample = gst_app_sink_pull_sample (GST_APP_SINK (elt));
142   buffer = gst_sample_get_buffer (sample);
143   source = gst_bin_get_by_name (GST_BIN (data->sink), "testsource");
144   gst_app_src_push_buffer (GST_APP_SRC (source), gst_buffer_ref (buffer));
145   gst_sample_unref (sample);
146   g_object_unref (source);
147   return GST_FLOW_OK;
148 }
149 
150 /*
151  * appsink => appsrc pipelines executed 100 times:
152  * - appsink pipeline has sync=false
153  * - appsrc pipeline has sync=true
154  * - appsrc has block=true
155  * after 1 second an error message is posted on appsink pipeline bus
156  * when the error is received the appsrc pipeline is set to NULL
157  * and then the appsink pipeline is
158  * set to NULL too, this must not deadlock
159  */
160 
GST_START_TEST(test_appsrc_block_deadlock)161 GST_START_TEST (test_appsrc_block_deadlock)
162 {
163   GstElement *testsink;
164   ProgramData *data;
165 
166   GST_INFO ("iteration %d", __i__);
167 
168   data = g_new0 (ProgramData, 1);
169 
170   data->source =
171       gst_parse_launch ("videotestsrc ! video/x-raw,width=16,height=16 ! "
172       "appsink sync=false name=testsink", NULL);
173 
174   fail_unless (data->source != NULL);
175 
176   app_callbacks.new_sample = on_new_sample_from_source;
177   testsink = gst_bin_get_by_name (GST_BIN (data->source), "testsink");
178   gst_app_sink_set_callbacks (GST_APP_SINK_CAST (testsink), &app_callbacks,
179       data, NULL);
180 
181   gst_object_unref (testsink);
182 
183   data->sink =
184       gst_parse_launch
185       ("appsrc name=testsource block=1 max-bytes=1000 is-live=true ! "
186       "fakesink sync=true", NULL);
187 
188   fail_unless (data->sink != NULL);
189 
190   ASSERT_SET_STATE (data->sink, GST_STATE_PLAYING, GST_STATE_CHANGE_ASYNC);
191   ASSERT_SET_STATE (data->source, GST_STATE_PLAYING, GST_STATE_CHANGE_ASYNC);
192 
193   /* wait for preroll */
194   gst_element_get_state (data->source, NULL, NULL, GST_CLOCK_TIME_NONE);
195   gst_element_get_state (data->sink, NULL, NULL, GST_CLOCK_TIME_NONE);
196 
197   g_usleep (50 * (G_USEC_PER_SEC / 1000));
198 
199   ASSERT_SET_STATE (data->sink, GST_STATE_NULL, GST_STATE_CHANGE_SUCCESS);
200   ASSERT_SET_STATE (data->source, GST_STATE_NULL, GST_STATE_CHANGE_SUCCESS);
201 
202   gst_object_unref (data->source);
203   gst_object_unref (data->sink);
204   g_free (data);
205 }
206 
207 GST_END_TEST;
208 
209 typedef struct
210 {
211   GstCaps *caps1;
212   GstCaps *caps2;
213   GstCaps *expected_caps;
214 } Helper;
215 
216 static void
caps_notify_cb(GObject * obj,GObject * child,GParamSpec * pspec,Helper * h)217 caps_notify_cb (GObject * obj, GObject * child, GParamSpec * pspec, Helper * h)
218 {
219   GstCaps *caps = NULL;
220 
221   g_object_get (child, "caps", &caps, NULL);
222   if (caps) {
223     GST_LOG_OBJECT (child, "expected caps: %" GST_PTR_FORMAT, h->expected_caps);
224     GST_LOG_OBJECT (child, "caps set to  : %" GST_PTR_FORMAT, caps);
225     fail_unless (gst_caps_is_equal (caps, h->expected_caps));
226     gst_caps_unref (caps);
227   }
228 }
229 
230 static void
handoff_cb(GstElement * sink,GstBuffer * buf,GstPad * pad,Helper * h)231 handoff_cb (GstElement * sink, GstBuffer * buf, GstPad * pad, Helper * h)
232 {
233   /* have our buffer, now the caps should change */
234   h->expected_caps = h->caps2;
235   GST_INFO ("got buffer, expect caps %" GST_PTR_FORMAT " next", h->caps2);
236 }
237 
238 /* Make sure that if set_caps() is called twice before the source is started,
239  * the caps are just replaced and not put into the internal queue */
GST_START_TEST(test_appsrc_set_caps_twice)240 GST_START_TEST (test_appsrc_set_caps_twice)
241 {
242   GstElement *pipe, *src, *sink;
243   GstMessage *msg;
244   GstCaps *caps;
245   Helper h;
246 
247   h.caps1 = gst_caps_new_simple ("foo/bar", "bleh", G_TYPE_INT, 2, NULL);
248   h.caps2 = gst_caps_new_simple ("bar/foo", "xyz", G_TYPE_INT, 3, NULL);
249 
250   pipe = gst_pipeline_new ("pipeline");
251   src = gst_element_factory_make ("appsrc", NULL);
252   sink = gst_element_factory_make ("fakesink", NULL);
253   gst_bin_add_many (GST_BIN (pipe), src, sink, NULL);
254   gst_element_link (src, sink);
255 
256   g_signal_connect (pipe, "deep-notify::caps", G_CALLBACK (caps_notify_cb), &h);
257 
258   g_object_set (sink, "signal-handoffs", TRUE, NULL);
259   g_signal_connect (sink, "handoff", G_CALLBACK (handoff_cb), &h);
260 
261   /* case 1: set caps to caps1, then set again to caps2, all this before
262    * appsrc is started and before any buffers are in the queue yet. We don't
263    * want to see any trace of caps1 during negotiation in this case. */
264   gst_app_src_set_caps (GST_APP_SRC (src), h.caps1);
265   caps = gst_app_src_get_caps (GST_APP_SRC (src));
266   fail_unless (gst_caps_is_equal (caps, h.caps1));
267   gst_caps_unref (caps);
268 
269   gst_app_src_set_caps (GST_APP_SRC (src), h.caps2);
270   caps = gst_app_src_get_caps (GST_APP_SRC (src));
271   fail_unless (gst_caps_is_equal (caps, h.caps2));
272   gst_caps_unref (caps);
273 
274   gst_app_src_end_of_stream (GST_APP_SRC (src));
275 
276   h.expected_caps = h.caps2;
277 
278   gst_element_set_state (pipe, GST_STATE_PLAYING);
279 
280   msg =
281       gst_bus_timed_pop_filtered (GST_ELEMENT_BUS (pipe), -1, GST_MESSAGE_EOS);
282   gst_message_unref (msg);
283 
284   gst_element_set_state (pipe, GST_STATE_NULL);
285   gst_object_unref (pipe);
286 
287   GST_INFO ("Case #2");
288 
289   /* case 2: set caps to caps1, then push a buffer and set to caps2, again
290    * before appsrc is started. In this case appsrc should negotiate to caps1
291    * first, and then caps2 after pushing the first buffer. */
292 
293   /* We're creating a new pipeline/appsrc here because appsrc's behaviour
294    * change slightly after setting it to NULL/READY and then re-using it */
295   pipe = gst_pipeline_new ("pipeline");
296   src = gst_element_factory_make ("appsrc", NULL);
297   sink = gst_element_factory_make ("fakesink", NULL);
298   gst_bin_add_many (GST_BIN (pipe), src, sink, NULL);
299   gst_element_link (src, sink);
300 
301   g_signal_connect (pipe, "deep-notify::caps", G_CALLBACK (caps_notify_cb), &h);
302 
303   g_object_set (sink, "signal-handoffs", TRUE, NULL);
304   g_signal_connect (sink, "handoff", G_CALLBACK (handoff_cb), &h);
305 
306   gst_app_src_set_caps (GST_APP_SRC (src), h.caps1);
307   caps = gst_app_src_get_caps (GST_APP_SRC (src));
308   fail_unless (gst_caps_is_equal (caps, h.caps1));
309   gst_caps_unref (caps);
310 
311   /* first caps1, then buffer, then later caps2 */
312   h.expected_caps = h.caps1;
313 
314   gst_element_set_state (pipe, GST_STATE_PLAYING);
315 
316   gst_app_src_push_buffer (GST_APP_SRC (src), gst_buffer_new ());
317 
318   gst_app_src_set_caps (GST_APP_SRC (src), h.caps2);
319   caps = gst_app_src_get_caps (GST_APP_SRC (src));
320   fail_unless (gst_caps_is_equal (caps, h.caps2));
321   gst_caps_unref (caps);
322 
323   gst_app_src_end_of_stream (GST_APP_SRC (src));
324 
325   msg =
326       gst_bus_timed_pop_filtered (GST_ELEMENT_BUS (pipe), -1, GST_MESSAGE_EOS);
327   gst_message_unref (msg);
328 
329   gst_element_set_state (pipe, GST_STATE_NULL);
330   gst_object_unref (pipe);
331 
332   gst_caps_unref (h.caps2);
333   gst_caps_unref (h.caps1);
334 }
335 
336 GST_END_TEST;
337 
338 static gboolean
seek_cb(GstAppSrc * src,guint64 offset,gpointer data)339 seek_cb (GstAppSrc * src, guint64 offset, gpointer data)
340 {
341   /* Return fake true */
342   return TRUE;
343 }
344 
345 static void
caps_cb(GObject * obj,GObject * child,GParamSpec * pspec,GstCaps ** received_caps)346 caps_cb (GObject * obj, GObject * child, GParamSpec * pspec,
347     GstCaps ** received_caps)
348 {
349   GstCaps *caps = NULL;
350 
351   /* Collect the caps */
352   g_object_get (child, "caps", &caps, NULL);
353   if (caps) {
354     GST_LOG_OBJECT (child, "caps set to  : %" GST_PTR_FORMAT, caps);
355     gst_caps_replace (received_caps, caps);
356     gst_caps_unref (caps);
357   }
358 }
359 
GST_START_TEST(test_appsrc_caps_in_push_modes)360 GST_START_TEST (test_appsrc_caps_in_push_modes)
361 {
362   GstElement *pipe, *src, *sink;
363   GstMessage *msg;
364   GstCaps *caps, *caps1, *received_caps;
365   gint i;
366   GstMessageType msg_types;
367   GstAppSrcCallbacks cb = { 0 };
368   GstAppStreamType modes[] = { GST_APP_STREAM_TYPE_STREAM,
369     GST_APP_STREAM_TYPE_SEEKABLE,
370     GST_APP_STREAM_TYPE_RANDOM_ACCESS
371   };
372 
373   for (i = 0; i < sizeof (modes) / sizeof (modes[0]); i++) {
374     GST_INFO ("checking mode %d", modes[i]);
375     caps1 = gst_caps_new_simple ("foo/bar", "bleh", G_TYPE_INT, 2, NULL);
376     received_caps = NULL;
377 
378     pipe = gst_pipeline_new ("pipeline");
379     src = gst_element_factory_make ("appsrc", NULL);
380     sink = gst_element_factory_make ("fakesink", NULL);
381     gst_bin_add_many (GST_BIN (pipe), src, sink, NULL);
382     gst_element_link (src, sink);
383 
384     g_object_set (G_OBJECT (src), "stream-type", modes[i], NULL);
385     if (modes[i] != GST_APP_STREAM_TYPE_STREAM) {
386       cb.seek_data = seek_cb;
387       gst_app_src_set_callbacks (GST_APP_SRC (src), &cb, NULL, NULL);
388     }
389     g_signal_connect (pipe, "deep-notify::caps", G_CALLBACK (caps_cb),
390         &received_caps);
391 
392     gst_app_src_set_caps (GST_APP_SRC (src), caps1);
393     caps = gst_app_src_get_caps (GST_APP_SRC (src));
394     fail_unless (gst_caps_is_equal (caps, caps1));
395     gst_caps_unref (caps);
396 
397     gst_element_set_state (pipe, GST_STATE_PLAYING);
398 
399     if (modes[i] != GST_APP_STREAM_TYPE_RANDOM_ACCESS) {
400       gst_app_src_end_of_stream (GST_APP_SRC (src));
401       msg_types = GST_MESSAGE_EOS;
402     } else {
403       gst_app_src_push_buffer (GST_APP_SRC (src), gst_buffer_new ());
404       msg_types = GST_MESSAGE_ASYNC_DONE;
405     }
406 
407     msg = gst_bus_timed_pop_filtered (GST_ELEMENT_BUS (pipe), -1, msg_types);
408     gst_message_unref (msg);
409     /* The collected caps should match with one that was pushed */
410     fail_unless (received_caps && gst_caps_is_equal (received_caps, caps1));
411 
412     gst_element_set_state (pipe, GST_STATE_NULL);
413     gst_object_unref (pipe);
414     gst_caps_unref (caps1);
415     if (received_caps)
416       gst_caps_unref (received_caps);
417   }
418 }
419 
420 GST_END_TEST;
421 
422 /* This test simulates a pipeline blocked pushing caps using a blocking pad
423  * probe. This state is seen if the application push buffers and later change
424  * the caps on one stream before the other stream have prerolled. In this
425  * state, GStreamer 1.12 and previous would deadlock inside GstBaseSrc as
426  * it was holding the live lock while calling create(). AppSrc serialize the
427  * caps event into it's queue and then push it downstream when create() is
428  * called. */
429 
430 static GstPadProbeReturn
caps_event_probe_cb(GstPad * pad,GstPadProbeInfo * info,gpointer user_data)431 caps_event_probe_cb (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
432 {
433   GMainLoop *loop = user_data;
434 
435   if (GST_EVENT_TYPE (info->data) == GST_EVENT_CAPS) {
436     g_main_loop_quit (loop);
437     return GST_PAD_PROBE_OK;
438   }
439 
440   return GST_PAD_PROBE_PASS;
441 }
442 
GST_START_TEST(test_appsrc_blocked_on_caps)443 GST_START_TEST (test_appsrc_blocked_on_caps)
444 {
445   GstElement *pipeline = NULL, *app = NULL;
446   GstPad *pad = NULL;
447   GstCaps *caps = NULL;
448   GError *error = NULL;
449   GMainLoop *loop;
450 
451   loop = g_main_loop_new (NULL, FALSE);
452 
453   pipeline = gst_parse_launch ("appsrc is-live=1 name=app ! fakesink", &error);
454   g_assert_no_error (error);
455 
456   app = gst_bin_get_by_name (GST_BIN (pipeline), "app");
457   pad = gst_element_get_static_pad (app, "src");
458 
459   gst_pad_add_probe (pad,
460       GST_PAD_PROBE_TYPE_BLOCK | GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM,
461       caps_event_probe_cb, loop, NULL);
462   gst_object_unref (app);
463   gst_object_unref (pad);
464 
465   gst_element_set_state (pipeline, GST_STATE_PLAYING);
466 
467   caps = gst_caps_from_string ("application/x-test");
468   gst_app_src_set_caps (GST_APP_SRC (app), caps);
469   gst_caps_unref (caps);
470 
471   g_main_loop_run (loop);
472 
473 #if 0
474   /* This would work around the issue by deblocking the source on older
475    * version of GStreamer */
476   gst_element_send_event (app, gst_event_new_flush_start ());
477 #endif
478 
479   /* As appsrc change the caps GstBaseSrc::create() virtual function, the live
480    * lock use to remains held and prevented the state change from happening. */
481   gst_element_set_state (pipeline, GST_STATE_NULL);
482   gst_object_unref (pipeline);
483   g_main_loop_unref (loop);
484 }
485 
486 GST_END_TEST;
487 
488 static guint expect_offset;
489 static gboolean chainlist_called;
490 static gboolean done;
491 
492 static gboolean
event_func(GstPad * pad,GstObject * parent,GstEvent * event)493 event_func (GstPad * pad, GstObject * parent, GstEvent * event)
494 {
495   GST_LOG ("event %" GST_PTR_FORMAT, event);
496   if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
497     g_mutex_lock (&check_mutex);
498     done = TRUE;
499     g_cond_signal (&check_cond);
500     g_mutex_unlock (&check_mutex);
501   }
502   gst_event_unref (event);
503   return TRUE;
504 }
505 
506 static GstFlowReturn
chain_____func(GstPad * pad,GstObject * parent,GstBuffer * buf)507 chain_____func (GstPad * pad, GstObject * parent, GstBuffer * buf)
508 {
509   GST_LOG ("  buffer # %3u", (guint) GST_BUFFER_OFFSET (buf));
510 
511   fail_unless_equals_int (GST_BUFFER_OFFSET (buf), expect_offset);
512   ++expect_offset;
513   gst_buffer_unref (buf);
514 
515   return GST_FLOW_OK;
516 }
517 
518 static GstFlowReturn
chainlist_func(GstPad * pad,GstObject * parent,GstBufferList * list)519 chainlist_func (GstPad * pad, GstObject * parent, GstBufferList * list)
520 {
521   guint i, len;
522 
523   len = gst_buffer_list_length (list);
524 
525   GST_DEBUG ("buffer list with %u buffers", len);
526   for (i = 0; i < len; ++i) {
527     GstBuffer *buf = gst_buffer_list_get (list, i);
528     GST_LOG ("  buffer # %3u", (guint) GST_BUFFER_OFFSET (buf));
529 
530     fail_unless_equals_int (GST_BUFFER_OFFSET (buf), expect_offset);
531     ++expect_offset;
532   }
533   chainlist_called = TRUE;
534   gst_buffer_list_unref (list);
535   return GST_FLOW_OK;
536 }
537 
GST_START_TEST(test_appsrc_push_buffer_list)538 GST_START_TEST (test_appsrc_push_buffer_list)
539 {
540   GstElement *src;
541   guint i;
542 
543   src = gst_element_factory_make ("appsrc", "appsrc");
544 
545   mysinkpad = gst_check_setup_sink_pad (src, &sinktemplate);
546   gst_pad_set_chain_function (mysinkpad, chain_____func);
547   gst_pad_set_chain_list_function (mysinkpad, chainlist_func);
548   gst_pad_set_event_function (mysinkpad, event_func);
549   gst_pad_set_active (mysinkpad, TRUE);
550 
551   expect_offset = 0;
552   chainlist_called = FALSE;
553   done = FALSE;
554 
555   gst_element_set_state (src, GST_STATE_PLAYING);
556 
557 #define NUM_BUFFERS 100
558 
559   for (i = 0; i < NUM_BUFFERS; ++i) {
560     GstFlowReturn flow;
561     GstBuffer *buf;
562 
563     buf = gst_buffer_new ();
564     GST_BUFFER_OFFSET (buf) = i;
565 
566     if (i == 0 || g_random_boolean ()) {
567       GstBufferList *buflist = gst_buffer_list_new ();
568 
569       gst_buffer_list_add (buflist, buf);
570 
571       buf = gst_buffer_new ();
572       GST_BUFFER_OFFSET (buf) = ++i;
573       gst_buffer_list_add (buflist, buf);
574       if (g_random_boolean ()) {
575         flow = gst_app_src_push_buffer_list (GST_APP_SRC (src), buflist);
576       } else {
577         g_signal_emit_by_name (src, "push-buffer-list", buflist, &flow);
578         gst_buffer_list_unref (buflist);
579       }
580     } else {
581       flow = gst_app_src_push_buffer (GST_APP_SRC (src), buf);
582     }
583     fail_unless_equals_int (flow, GST_FLOW_OK);
584   }
585 
586   gst_app_src_end_of_stream (GST_APP_SRC (src));
587 
588   g_mutex_lock (&check_mutex);
589   while (!done)
590     g_cond_wait (&check_cond, &check_mutex);
591   g_mutex_unlock (&check_mutex);
592 
593   gst_element_set_state (src, GST_STATE_NULL);
594 
595   /* make sure the buffer list was pushed out as list! */
596   fail_unless (chainlist_called);
597 
598   /* can be NUM_BUFFERS or NUM_BUFFERS + 1 depending on whether last item
599    * was buffer list or not */
600   fail_unless (expect_offset >= NUM_BUFFERS);
601 
602   gst_check_teardown_sink_pad (src);
603 
604   gst_object_unref (src);
605 }
606 
607 GST_END_TEST;
608 
609 static Suite *
appsrc_suite(void)610 appsrc_suite (void)
611 {
612   Suite *s = suite_create ("appsrc");
613   TCase *tc_chain = tcase_create ("general");
614 
615   tcase_add_test (tc_chain, test_appsrc_non_null_caps);
616   tcase_add_test (tc_chain, test_appsrc_set_caps_twice);
617   tcase_add_test (tc_chain, test_appsrc_caps_in_push_modes);
618   tcase_add_test (tc_chain, test_appsrc_blocked_on_caps);
619   tcase_add_test (tc_chain, test_appsrc_push_buffer_list);
620 
621   if (RUNNING_ON_VALGRIND)
622     tcase_add_loop_test (tc_chain, test_appsrc_block_deadlock, 0, 5);
623   else
624     tcase_add_loop_test (tc_chain, test_appsrc_block_deadlock, 0, 100);
625 
626   suite_add_tcase (s, tc_chain);
627 
628   return s;
629 }
630 
631 GST_CHECK_MAIN (appsrc);
632