2
/*** block from ../../../docs/manual/advanced-dataaccess.xml ***/
5
static GMainLoop *loop;
6
static volatile gint counter;
8
static gboolean prerolled = FALSE;
9
static GstPad *sinkpad;
12
dec_counter (GstElement * pipeline)
17
if (g_atomic_int_dec_and_test (&counter)) {
18
/* all probes blocked and no-more-pads signaled, post
19
* message on the bus. */
22
gst_bus_post (bus, gst_message_new_application (
23
GST_OBJECT_CAST (pipeline),
24
gst_structure_new_empty ("ExPrerolled")));
28
/* called when a source pad of uridecodebin is blocked */
29
static GstPadProbeReturn
30
cb_blocked (GstPad *pad,
31
GstPadProbeInfo *info,
34
GstElement *pipeline = GST_ELEMENT (user_data);
37
return GST_PAD_PROBE_REMOVE;
39
dec_counter (pipeline);
41
return GST_PAD_PROBE_OK;
44
/* called when uridecodebin has a new pad */
46
cb_pad_added (GstElement *element,
50
GstElement *pipeline = GST_ELEMENT (user_data);
55
g_atomic_int_inc (&counter);
57
gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM,
58
(GstPadProbeCallback) cb_blocked, pipeline, NULL);
60
/* try to link to the video pad */
61
gst_pad_link (pad, sinkpad);
64
/* called when uridecodebin has created all pads */
66
cb_no_more_pads (GstElement *element,
69
GstElement *pipeline = GST_ELEMENT (user_data);
74
dec_counter (pipeline);
77
/* called when a new message is posted on the bus */
79
cb_message (GstBus *bus,
83
GstElement *pipeline = GST_ELEMENT (user_data);
85
switch (GST_MESSAGE_TYPE (message)) {
86
case GST_MESSAGE_ERROR:
87
g_print ("we received an error!\n");
88
g_main_loop_quit (loop);
91
g_print ("we reached EOS\n");
92
g_main_loop_quit (loop);
94
case GST_MESSAGE_APPLICATION:
96
if (gst_message_has_name (message, "ExPrerolled")) {
97
/* it's our message */
98
g_print ("we are all prerolled, do seek\n");
99
gst_element_seek (pipeline,
100
1.0, GST_FORMAT_TIME,
101
GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE,
102
GST_SEEK_TYPE_SET, 2 * GST_SECOND,
103
GST_SEEK_TYPE_SET, 5 * GST_SECOND);
105
gst_element_set_state (pipeline, GST_STATE_PLAYING);
118
GstElement *pipeline, *src, *csp, *vs, *sink;
121
gst_init (&argc, &argv);
122
loop = g_main_loop_new (NULL, FALSE);
125
g_print ("usage: %s <uri>", argv[0]);
130
pipeline = gst_pipeline_new ("my-pipeline");
132
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
133
gst_bus_add_signal_watch (bus);
134
g_signal_connect (bus, "message", (GCallback) cb_message,
137
src = gst_element_factory_make ("uridecodebin", "src");
139
g_error ("Could not create 'uridecodebin' element");
141
g_object_set (src, "uri", argv[1], NULL);
143
csp = gst_element_factory_make ("videoconvert", "csp");
145
g_error ("Could not create 'videoconvert' element");
147
vs = gst_element_factory_make ("videoscale", "vs");
149
g_error ("Could not create 'videoscale' element");
151
sink = gst_element_factory_make ("autovideosink", "sink");
153
g_error ("Could not create 'autovideosink' element");
155
gst_bin_add_many (GST_BIN (pipeline), src, csp, vs, sink, NULL);
157
/* can't link src yet, it has no pads */
158
gst_element_link_many (csp, vs, sink, NULL);
160
sinkpad = gst_element_get_static_pad (csp, "sink");
162
/* for each pad block that is installed, we will increment
163
* the counter. for each pad block that is signaled, we
164
* decrement the counter. When the counter is 0 we post
165
* an app message to tell the app that all pads are
166
* blocked. Start with 1 that is decremented when no-more-pads
167
* is signaled to make sure that we only post the message
168
* after no-more-pads */
169
g_atomic_int_set (&counter, 1);
171
g_signal_connect (src, "pad-added",
172
(GCallback) cb_pad_added, pipeline);
173
g_signal_connect (src, "no-more-pads",
174
(GCallback) cb_no_more_pads, pipeline);
176
gst_element_set_state (pipeline, GST_STATE_PAUSED);
178
g_main_loop_run (loop);
180
gst_element_set_state (pipeline, GST_STATE_NULL);
182
gst_object_unref (sinkpad);
183
gst_object_unref (bus);
184
gst_object_unref (pipeline);
185
g_main_loop_unref (loop);