1 | #include <gst/gst.h> |
---|
2 | |
---|
3 | #include <unistd.h> |
---|
4 | |
---|
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 | */ |
---|
10 | |
---|
11 | static volatile gint handoff_count = 0; |
---|
12 | |
---|
13 | /* handoff callback */ |
---|
14 | static void |
---|
15 | handoff (GstElement * element, gpointer data) |
---|
16 | { |
---|
17 | ++handoff_count; |
---|
18 | g_print ("handoff (%d) ", handoff_count); |
---|
19 | } |
---|
20 | |
---|
21 | static void |
---|
22 | construct_pipeline (GstElement * pipeline, GstElement * thread) |
---|
23 | { |
---|
24 | GstElement *src, *sink, *queue; |
---|
25 | |
---|
26 | src = gst_element_factory_make ("fakesrc", NULL); |
---|
27 | sink = gst_element_factory_make ("fakesink", "sink"); |
---|
28 | queue = gst_element_factory_make ("queue", NULL); |
---|
29 | |
---|
30 | gst_bin_add_many (GST_BIN (thread), queue, sink, NULL); |
---|
31 | gst_bin_add_many (GST_BIN (pipeline), src, thread, NULL); |
---|
32 | |
---|
33 | gst_element_link_many (src, queue, sink, NULL); |
---|
34 | |
---|
35 | g_object_set (G_OBJECT (src), "num_buffers", 50, NULL); |
---|
36 | |
---|
37 | g_object_set (G_OBJECT (sink), "signal-handoffs", TRUE, NULL); |
---|
38 | g_signal_connect (G_OBJECT (sink), "handoff", G_CALLBACK (handoff), NULL); |
---|
39 | } |
---|
40 | |
---|
41 | void |
---|
42 | change_state (GstElement * element, GstBuffer * buf, GstElement * pipeline) |
---|
43 | { |
---|
44 | gst_element_set_state (pipeline, GST_STATE_NULL); |
---|
45 | } |
---|
46 | |
---|
47 | int |
---|
48 | main (gint argc, gchar * argv[]) |
---|
49 | { |
---|
50 | GstElement *pipeline; |
---|
51 | GstElement *thread = NULL; |
---|
52 | |
---|
53 | gst_init (&argc, &argv); |
---|
54 | |
---|
55 | pipeline = gst_thread_new ("main_pipeline"); |
---|
56 | thread = gst_element_factory_make ("thread", NULL); |
---|
57 | construct_pipeline (pipeline, thread); |
---|
58 | |
---|
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); |
---|
63 | |
---|
64 | g_print ("Pipeline done. Resetting to NULL.\n"); |
---|
65 | gst_element_set_state (pipeline, GST_STATE_NULL); |
---|
66 | |
---|
67 | if (handoff_count == 0) { |
---|
68 | g_print ("ERROR: no buffers have passed\n"); |
---|
69 | return -1; |
---|
70 | } |
---|
71 | |
---|
72 | handoff_count = 0; |
---|
73 | |
---|
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_element_set_state (pipeline, gst_element_get_state (pipeline)); |
---|
80 | g_print ("SLEEPING 2 sec\n"); |
---|
81 | sleep (2); |
---|
82 | |
---|
83 | if (handoff_count == 0) { |
---|
84 | g_print ("ERROR: no buffers have passed\n"); |
---|
85 | return -1; |
---|
86 | } |
---|
87 | |
---|
88 | return 0; |
---|
89 | } |
---|