1 #include <gst/gst.h>
3 #include <unistd.h>
5 /*
6 * queue test code
7 * starts a fakesrc num_buffers=50 ! { queue ! fakesink } thread
8 * by first setting the output thread to play, then the whole pipeline
9 */
11 static gint handoff_count = 0;
13 /* handoff callback */
14 static void
15 handoff (GstElement * element, gpointer data)
16 {
17 ++handoff_count;
18 g_print ("handoff (%d) ", handoff_count);
19 }
21 static void
22 construct_pipeline (GstElement * pipeline, GstElement * thread)
23 {
24 GstElement *src, *sink, *queue;
26 src = gst_element_factory_make ("fakesrc", NULL);
27 sink = gst_element_factory_make ("fakesink", "sink");
28 queue = gst_element_factory_make ("queue", NULL);
30 gst_bin_add_many (GST_BIN (thread), queue, sink, NULL);
31 gst_bin_add_many (GST_BIN (pipeline), src, thread, NULL);
33 gst_element_link_many (src, queue, sink, NULL);
35 g_object_set (G_OBJECT (src), "num_buffers", 50, NULL);
37 g_object_set (G_OBJECT (sink), "signal-handoffs", TRUE, NULL);
38 g_signal_connect (G_OBJECT (sink), "handoff", G_CALLBACK (handoff), NULL);
39 }
41 void
42 change_state (GstElement * element, GstBuffer * buf, GstElement * pipeline)
43 {
44 gst_element_set_state (pipeline, GST_STATE_NULL);
45 }
47 int
48 main (gint argc, gchar * argv[])
49 {
50 GstElement *pipeline;
51 GstElement *thread = NULL;
53 gst_init (&argc, &argv);
55 pipeline = gst_thread_new ("main_pipeline");
56 thread = gst_element_factory_make ("thread", NULL);
57 construct_pipeline (pipeline, thread);
59 g_print ("First run: to show the pipeline works\n");
60 gst_element_set_state (pipeline, GST_STATE_PLAYING);
61 g_print ("SLEEPING 1 sec\n");
62 sleep (1);
64 g_print ("Pipeline done. Resetting to NULL.\n");
65 gst_element_set_state (pipeline, GST_STATE_NULL);
67 if (handoff_count == 0) {
68 g_print ("ERROR: no buffers have passed\n");
69 return -1;
70 }
72 handoff_count = 0;
74 g_print
75 ("Second run: setting consumer thread to playing, then complete pipeline\n");
76 gst_element_set_state (thread, GST_STATE_PLAYING);
77 g_print ("SLEEPING 1 sec\n");
78 sleep (1);
79 gst_bin_sync_children_state (GST_BIN (pipeline));
80 g_print ("SLEEPING 2 sec\n");
81 sleep (2);
83 if (handoff_count == 0) {
84 g_print ("ERROR: no buffers have passed\n");
85 return -1;
86 }
88 return 0;
89 }