From: Xavi Artigas Date: Fri, 8 Jun 2012 15:08:56 +0000 (+0200) Subject: Added tutorial 12 X-Git-Tag: 1.19.3~489^2~562^2~200 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5569f4178372f1f6f83a79c78d133f41612cb179;p=platform%2Fupstream%2Fgstreamer.git Added tutorial 12 --- diff --git a/gst-sdk/tutorials/basic-tutorial-12.c b/gst-sdk/tutorials/basic-tutorial-12.c new file mode 100644 index 0000000..3a4d5b0 --- /dev/null +++ b/gst-sdk/tutorials/basic-tutorial-12.c @@ -0,0 +1,110 @@ +#include +#include + +typedef struct _CustomData { + gboolean is_live; + GstElement *pipeline; + GMainLoop *loop; +} CustomData; + +/* playbin2 flags */ +typedef enum { + GST_PLAY_FLAG_BUFFERING = (1 << 8) /* We want to allow buffering */ +} GstPlayFlags; + +static void cb_message (GstBus *bus, GstMessage *msg, CustomData *data) { + + switch (GST_MESSAGE_TYPE (msg)) { + case GST_MESSAGE_ERROR: { + GError *err; + gchar *debug; + + gst_message_parse_error (msg, &err, &debug); + g_print ("Error: %s\n", err->message); + g_error_free (err); + g_free (debug); + + gst_element_set_state (data->pipeline, GST_STATE_READY); + g_main_loop_quit (data->loop); + break; + } + case GST_MESSAGE_EOS: + /* end-of-stream */ + gst_element_set_state (data->pipeline, GST_STATE_READY); + g_main_loop_quit (data->loop); + break; + case GST_MESSAGE_CLOCK_LOST: + /* Get a new clock */ + gst_element_set_state (data->pipeline, GST_STATE_PAUSED); + gst_element_set_state (data->pipeline, GST_STATE_PLAYING); + break; + case GST_MESSAGE_BUFFERING: { + gint percent = 0; + + /* If the stream is live, we do not care about buffering. */ + if (data->is_live) break; + + gst_message_parse_buffering (msg, &percent); + g_print ("Buffering (%3d%%)\r", percent); + /* Wait until buffering is complete before start/resume playing */ + if (percent < 100) + gst_element_set_state (data->pipeline, GST_STATE_PAUSED); + else + gst_element_set_state (data->pipeline, GST_STATE_PLAYING); + break; + } + default: + /* Unhandled message */ + break; + } +} + +int main(int argc, char *argv[]) { + GstElement *pipeline; + GstBus *bus; + GstStateChangeReturn ret; + GMainLoop *main_loop; + CustomData data; + guint flags; + + /* Initialize GStreamer */ + gst_init (&argc, &argv); + + /* Initialize our data structure */ + memset (&data, 0, sizeof (data)); + + /* Build the pipeline */ + pipeline = gst_parse_launch ("playbin2 uri=http://docs.gstreamer.com/media/sintel_trailer-480p.webm", NULL); + bus = gst_element_get_bus (pipeline); + + /* Set the buffering flag */ + g_object_get (pipeline, "flags", &flags, NULL); + flags |= GST_PLAY_FLAG_BUFFERING; + g_object_set (pipeline, "flags", flags, NULL); + + /* Start playing */ + ret = gst_element_set_state (pipeline, GST_STATE_PLAYING); + if (ret == GST_STATE_CHANGE_FAILURE) { + g_printerr ("Unable to set the pipeline to the playing state.\n"); + gst_object_unref (pipeline); + return -1; + } else if (ret == GST_STATE_CHANGE_NO_PREROLL) { + data.is_live = TRUE; + } + + main_loop = g_main_loop_new (NULL, FALSE); + data.loop = main_loop; + data.pipeline = pipeline; + + gst_bus_add_signal_watch (bus); + g_signal_connect (bus, "message", G_CALLBACK (cb_message), &data); + + g_main_loop_run (main_loop); + + /* Free resources */ + g_main_loop_unref (main_loop); + gst_object_unref (bus); + gst_element_set_state (pipeline, GST_STATE_NULL); + gst_object_unref (pipeline); + return 0; +} \ No newline at end of file diff --git a/gst-sdk/tutorials/vs2010/basic-tutorial-10/basic-tutorial-10.vcxproj b/gst-sdk/tutorials/vs2010/basic-tutorial-12/basic-tutorial-12.vcxproj similarity index 96% rename from gst-sdk/tutorials/vs2010/basic-tutorial-10/basic-tutorial-10.vcxproj rename to gst-sdk/tutorials/vs2010/basic-tutorial-12/basic-tutorial-12.vcxproj index ff1ae2c..7d51383 100644 --- a/gst-sdk/tutorials/vs2010/basic-tutorial-10/basic-tutorial-10.vcxproj +++ b/gst-sdk/tutorials/vs2010/basic-tutorial-12/basic-tutorial-12.vcxproj @@ -19,7 +19,7 @@ - + Win32Proj diff --git a/gst-sdk/tutorials/vs2010/basic-tutorial-10/basic-tutorial-10.vcxproj.filters b/gst-sdk/tutorials/vs2010/basic-tutorial-12/basic-tutorial-12.vcxproj.filters similarity index 69% rename from gst-sdk/tutorials/vs2010/basic-tutorial-10/basic-tutorial-10.vcxproj.filters rename to gst-sdk/tutorials/vs2010/basic-tutorial-12/basic-tutorial-12.vcxproj.filters index b0c0be2..3f66ae1 100644 --- a/gst-sdk/tutorials/vs2010/basic-tutorial-10/basic-tutorial-10.vcxproj.filters +++ b/gst-sdk/tutorials/vs2010/basic-tutorial-12/basic-tutorial-12.vcxproj.filters @@ -1,6 +1,6 @@  - + \ No newline at end of file diff --git a/gst-sdk/tutorials/vs2010/tutorials.sln b/gst-sdk/tutorials/vs2010/tutorials.sln index 8f34033..afa1ea7 100644 --- a/gst-sdk/tutorials/vs2010/tutorials.sln +++ b/gst-sdk/tutorials/vs2010/tutorials.sln @@ -23,6 +23,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "playback-tutorial-2", "play EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "basic-tutorial-9", "basic-tutorial-9\basic-tutorial-9.vcxproj", "{7B61F2C6-5202-48B7-8589-164F81BC636C}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "basic-tutorial-12", "basic-tutorial-12\basic-tutorial-12.vcxproj", "{A2E63C29-3375-4930-B7D3-2F23EC824EAF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -119,6 +121,14 @@ Global {7B61F2C6-5202-48B7-8589-164F81BC636C}.Release|Win32.Build.0 = Release|Win32 {7B61F2C6-5202-48B7-8589-164F81BC636C}.Release|x64.ActiveCfg = Release|x64 {7B61F2C6-5202-48B7-8589-164F81BC636C}.Release|x64.Build.0 = Release|x64 + {A2E63C29-3375-4930-B7D3-2F23EC824EAF}.Debug|Win32.ActiveCfg = Debug|Win32 + {A2E63C29-3375-4930-B7D3-2F23EC824EAF}.Debug|Win32.Build.0 = Debug|Win32 + {A2E63C29-3375-4930-B7D3-2F23EC824EAF}.Debug|x64.ActiveCfg = Debug|x64 + {A2E63C29-3375-4930-B7D3-2F23EC824EAF}.Debug|x64.Build.0 = Debug|x64 + {A2E63C29-3375-4930-B7D3-2F23EC824EAF}.Release|Win32.ActiveCfg = Release|Win32 + {A2E63C29-3375-4930-B7D3-2F23EC824EAF}.Release|Win32.Build.0 = Release|Win32 + {A2E63C29-3375-4930-B7D3-2F23EC824EAF}.Release|x64.ActiveCfg = Release|x64 + {A2E63C29-3375-4930-B7D3-2F23EC824EAF}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE