4 typedef struct _CustomData {
\r
6 GstElement *pipeline;
\r
10 static void cb_message (GstBus *bus, GstMessage *msg, CustomData *data) {
\r
12 switch (GST_MESSAGE_TYPE (msg)) {
\r
13 case GST_MESSAGE_ERROR: {
\r
17 gst_message_parse_error (msg, &err, &debug);
\r
18 g_print ("Error: %s\n", err->message);
\r
22 gst_element_set_state (data->pipeline, GST_STATE_READY);
\r
23 g_main_loop_quit (data->loop);
\r
26 case GST_MESSAGE_EOS:
\r
28 gst_element_set_state (data->pipeline, GST_STATE_READY);
\r
29 g_main_loop_quit (data->loop);
\r
31 case GST_MESSAGE_BUFFERING: {
\r
34 /* If the stream is live, we do not care about buffering. */
\r
35 if (data->is_live) break;
\r
37 gst_message_parse_buffering (msg, &percent);
\r
38 g_print ("Buffering (%3d%%)\r", percent);
\r
39 /* Wait until buffering is complete before start/resume playing */
\r
41 gst_element_set_state (data->pipeline, GST_STATE_PAUSED);
\r
43 gst_element_set_state (data->pipeline, GST_STATE_PLAYING);
\r
46 case GST_MESSAGE_CLOCK_LOST:
\r
47 /* Get a new clock */
\r
48 gst_element_set_state (data->pipeline, GST_STATE_PAUSED);
\r
49 gst_element_set_state (data->pipeline, GST_STATE_PLAYING);
\r
52 /* Unhandled message */
\r
57 int main(int argc, char *argv[]) {
\r
58 GstElement *pipeline;
\r
60 GstStateChangeReturn ret;
\r
61 GMainLoop *main_loop;
\r
64 /* Initialize GStreamer */
\r
65 gst_init (&argc, &argv);
\r
67 /* Initialize our data structure */
\r
68 memset (&data, 0, sizeof (data));
\r
70 /* Build the pipeline */
\r
71 pipeline = gst_parse_launch ("playbin uri=https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm", NULL);
\r
72 bus = gst_element_get_bus (pipeline);
\r
75 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
\r
76 if (ret == GST_STATE_CHANGE_FAILURE) {
\r
77 g_printerr ("Unable to set the pipeline to the playing state.\n");
\r
78 gst_object_unref (pipeline);
\r
80 } else if (ret == GST_STATE_CHANGE_NO_PREROLL) {
\r
81 data.is_live = TRUE;
\r
84 main_loop = g_main_loop_new (NULL, FALSE);
\r
85 data.loop = main_loop;
\r
86 data.pipeline = pipeline;
\r
88 gst_bus_add_signal_watch (bus);
\r
89 g_signal_connect (bus, "message", G_CALLBACK (cb_message), &data);
\r
91 g_main_loop_run (main_loop);
\r
93 /* Free resources */
\r
94 g_main_loop_unref (main_loop);
\r
95 gst_object_unref (bus);
\r
96 gst_element_set_state (pipeline, GST_STATE_NULL);
\r
97 gst_object_unref (pipeline);
\r