Added tutorial 12
authorXavi Artigas <xartigas@fluendo.com>
Fri, 8 Jun 2012 15:08:56 +0000 (17:08 +0200)
committerXavi Artigas <xartigas@fluendo.com>
Fri, 8 Jun 2012 15:08:56 +0000 (17:08 +0200)
gst-sdk/tutorials/basic-tutorial-12.c [new file with mode: 0644]
gst-sdk/tutorials/vs2010/basic-tutorial-12/basic-tutorial-12.vcxproj [moved from gst-sdk/tutorials/vs2010/basic-tutorial-10/basic-tutorial-10.vcxproj with 96% similarity]
gst-sdk/tutorials/vs2010/basic-tutorial-12/basic-tutorial-12.vcxproj.filters [moved from gst-sdk/tutorials/vs2010/basic-tutorial-10/basic-tutorial-10.vcxproj.filters with 69% similarity]
gst-sdk/tutorials/vs2010/tutorials.sln

diff --git a/gst-sdk/tutorials/basic-tutorial-12.c b/gst-sdk/tutorials/basic-tutorial-12.c
new file mode 100644 (file)
index 0000000..3a4d5b0
--- /dev/null
@@ -0,0 +1,110 @@
+#include <gst/gst.h>\r
+#include <string.h>\r
+  \r
+typedef struct _CustomData {\r
+  gboolean is_live;\r
+  GstElement *pipeline;\r
+  GMainLoop *loop;\r
+} CustomData;\r
+  \r
+/* playbin2 flags */\r
+typedef enum {\r
+  GST_PLAY_FLAG_BUFFERING     = (1 << 8)  /* We want to allow buffering */\r
+} GstPlayFlags;\r
+  \r
+static void cb_message (GstBus *bus, GstMessage *msg, CustomData *data) {\r
+  \r
+  switch (GST_MESSAGE_TYPE (msg)) {\r
+    case GST_MESSAGE_ERROR: {\r
+      GError *err;\r
+      gchar *debug;\r
+      \r
+      gst_message_parse_error (msg, &err, &debug);\r
+      g_print ("Error: %s\n", err->message);\r
+      g_error_free (err);\r
+      g_free (debug);\r
+      \r
+      gst_element_set_state (data->pipeline, GST_STATE_READY);\r
+      g_main_loop_quit (data->loop);\r
+      break;\r
+    }\r
+    case GST_MESSAGE_EOS:\r
+      /* end-of-stream */\r
+      gst_element_set_state (data->pipeline, GST_STATE_READY);\r
+      g_main_loop_quit (data->loop);\r
+      break;\r
+    case GST_MESSAGE_CLOCK_LOST:\r
+      /* Get a new clock */\r
+      gst_element_set_state (data->pipeline, GST_STATE_PAUSED);\r
+      gst_element_set_state (data->pipeline, GST_STATE_PLAYING);\r
+      break;\r
+    case GST_MESSAGE_BUFFERING: {\r
+      gint percent = 0;\r
+      \r
+      /* If the stream is live, we do not care about buffering. */\r
+      if (data->is_live) break;\r
+      \r
+      gst_message_parse_buffering (msg, &percent);\r
+      g_print ("Buffering (%3d%%)\r", percent);\r
+      /* Wait until buffering is complete before start/resume playing */\r
+      if (percent < 100)\r
+        gst_element_set_state (data->pipeline, GST_STATE_PAUSED);\r
+      else\r
+        gst_element_set_state (data->pipeline, GST_STATE_PLAYING);\r
+      break;\r
+    }\r
+    default:\r
+      /* Unhandled message */\r
+      break;\r
+    }\r
+}\r
+  \r
+int main(int argc, char *argv[]) {\r
+  GstElement *pipeline;\r
+  GstBus *bus;\r
+  GstStateChangeReturn ret;\r
+  GMainLoop *main_loop;\r
+  CustomData data;\r
+  guint flags;\r
+  \r
+  /* Initialize GStreamer */\r
+  gst_init (&argc, &argv);\r
+  \r
+  /* Initialize our data structure */\r
+  memset (&data, 0, sizeof (data));\r
+  \r
+  /* Build the pipeline */\r
+  pipeline = gst_parse_launch ("playbin2 uri=http://docs.gstreamer.com/media/sintel_trailer-480p.webm", NULL);\r
+  bus = gst_element_get_bus (pipeline);\r
+  \r
+  /* Set the buffering flag */\r
+  g_object_get (pipeline, "flags", &flags, NULL);\r
+  flags |= GST_PLAY_FLAG_BUFFERING;\r
+  g_object_set (pipeline, "flags", flags, NULL);\r
+   \r
+  /* Start playing */\r
+  ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);\r
+  if (ret == GST_STATE_CHANGE_FAILURE) {\r
+    g_printerr ("Unable to set the pipeline to the playing state.\n");\r
+    gst_object_unref (pipeline);\r
+    return -1;\r
+  } else if (ret == GST_STATE_CHANGE_NO_PREROLL) {\r
+    data.is_live = TRUE;\r
+  }\r
+  \r
+  main_loop = g_main_loop_new (NULL, FALSE);\r
+  data.loop = main_loop;\r
+  data.pipeline = pipeline;\r
+  \r
+  gst_bus_add_signal_watch (bus);\r
+  g_signal_connect (bus, "message", G_CALLBACK (cb_message), &data);\r
+  \r
+  g_main_loop_run (main_loop);\r
+  \r
+  /* Free resources */\r
+  g_main_loop_unref (main_loop);\r
+  gst_object_unref (bus);\r
+  gst_element_set_state (pipeline, GST_STATE_NULL);\r
+  gst_object_unref (pipeline);\r
+  return 0;\r
+}
\ No newline at end of file
@@ -19,7 +19,7 @@
     </ProjectConfiguration>\r
   </ItemGroup>\r
   <ItemGroup>\r
-    <ClCompile Include="..\..\basic-tutorial-10.c" />\r
+    <ClCompile Include="..\..\basic-tutorial-12.c" />\r
   </ItemGroup>\r
   <PropertyGroup Label="Globals">\r
     <Keyword>Win32Proj</Keyword>\r
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>\r
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
   <ItemGroup>\r
-    <ClCompile Include="..\..\basic-tutorial-10.c" />\r
+    <ClCompile Include="..\..\basic-tutorial-12.c" />\r
   </ItemGroup>\r
 </Project>
\ No newline at end of file
index 8f34033..afa1ea7 100644 (file)
@@ -23,6 +23,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "playback-tutorial-2", "play
 EndProject\r
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "basic-tutorial-9", "basic-tutorial-9\basic-tutorial-9.vcxproj", "{7B61F2C6-5202-48B7-8589-164F81BC636C}"\r
 EndProject\r
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "basic-tutorial-12", "basic-tutorial-12\basic-tutorial-12.vcxproj", "{A2E63C29-3375-4930-B7D3-2F23EC824EAF}"\r
+EndProject\r
 Global\r
        GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
                Debug|Win32 = Debug|Win32\r
@@ -119,6 +121,14 @@ Global
                {7B61F2C6-5202-48B7-8589-164F81BC636C}.Release|Win32.Build.0 = Release|Win32\r
                {7B61F2C6-5202-48B7-8589-164F81BC636C}.Release|x64.ActiveCfg = Release|x64\r
                {7B61F2C6-5202-48B7-8589-164F81BC636C}.Release|x64.Build.0 = Release|x64\r
+               {A2E63C29-3375-4930-B7D3-2F23EC824EAF}.Debug|Win32.ActiveCfg = Debug|Win32\r
+               {A2E63C29-3375-4930-B7D3-2F23EC824EAF}.Debug|Win32.Build.0 = Debug|Win32\r
+               {A2E63C29-3375-4930-B7D3-2F23EC824EAF}.Debug|x64.ActiveCfg = Debug|x64\r
+               {A2E63C29-3375-4930-B7D3-2F23EC824EAF}.Debug|x64.Build.0 = Debug|x64\r
+               {A2E63C29-3375-4930-B7D3-2F23EC824EAF}.Release|Win32.ActiveCfg = Release|Win32\r
+               {A2E63C29-3375-4930-B7D3-2F23EC824EAF}.Release|Win32.Build.0 = Release|Win32\r
+               {A2E63C29-3375-4930-B7D3-2F23EC824EAF}.Release|x64.ActiveCfg = Release|x64\r
+               {A2E63C29-3375-4930-B7D3-2F23EC824EAF}.Release|x64.Build.0 = Release|x64\r
        EndGlobalSection\r
        GlobalSection(SolutionProperties) = preSolution\r
                HideSolutionNode = FALSE\r