Add playback tutorial 5
authorXavi Artigas <xartigas@fluendo.com>
Thu, 21 Jun 2012 14:08:19 +0000 (16:08 +0200)
committerXavi Artigas <xartigas@fluendo.com>
Thu, 21 Jun 2012 14:08:19 +0000 (16:08 +0200)
gst-sdk/tutorials/playback-tutorial-5.c [new file with mode: 0644]
gst-sdk/tutorials/vs2010/playback-tutorial-5/playback-tutorial-5.vcxproj [new file with mode: 0644]
gst-sdk/tutorials/vs2010/playback-tutorial-5/playback-tutorial-5.vcxproj.filters [new file with mode: 0644]
gst-sdk/tutorials/vs2010/tutorials.sln

diff --git a/gst-sdk/tutorials/playback-tutorial-5.c b/gst-sdk/tutorials/playback-tutorial-5.c
new file mode 100644 (file)
index 0000000..ce04f81
--- /dev/null
@@ -0,0 +1,182 @@
+#include <string.h>\r
+#include <gst/gst.h>\r
+#include <gst/interfaces/colorbalance.h>\r
+  \r
+typedef struct _CustomData {
+  GstElement *pipeline;
+  GMainLoop *loop;
+} CustomData;\r
+  \r
+/* playbin2 flags */
+typedef enum {
+  GST_PLAY_FLAG_DEINTERLACE   = (1 << 9)
+} GstPlayFlags;\r
+  \r
+/* Process a color balance command */\r
+static void update_color_channel (const gchar *channel_name, gboolean increase, GstColorBalance *cb) {\r
+  gdouble step;\r
+  gint value;\r
+  GstColorBalanceChannel *channel = NULL;\r
+  const GList *channels, *l;\r
+  \r
+  /* Retrieve the list of channels and locate the requested one */\r
+  channels = gst_color_balance_list_channels (cb);\r
+  for (l = channels; l != NULL; l = l->next) {\r
+    GstColorBalanceChannel *tmp = (GstColorBalanceChannel *)l->data;\r
+    \r
+    if (g_strrstr (tmp->label, channel_name)) {\r
+      channel = tmp;\r
+      break;\r
+    }\r
+  }\r
+  if (!channel)\r
+    return;\r
+  \r
+  /* Change the channel's value */\r
+  step = 0.1 * (channel->max_value - channel->min_value);\r
+  value = gst_color_balance_get_value (cb, channel);\r
+  if (increase) {\r
+    value += step;\r
+    if (value > channel->max_value)\r
+        value = channel->max_value;\r
+  } else {\r
+    value -= step;\r
+    if (value < channel->min_value)\r
+        value = channel->min_value;\r
+  }\r
+  gst_color_balance_set_value (cb, channel, value);\r
+}\r
+  \r
+/* Toggle the deinterlacing flag */\r
+static void toggle_deinterlace (GstElement *pipeline) {\r
+  gint flags;\r
+  gint64 current_position = GST_CLOCK_TIME_NONE;\r
+  GstFormat format = GST_FORMAT_TIME;\r
+  \r
+  /* Find current position, since it will be lost when we stop */\r
+  gst_element_query_position (pipeline, &format, &current_position);\r
+  /* Stop */\r
+  gst_element_set_state (pipeline, GST_STATE_READY);\r
+  /* Toggle deinterlacing flag (it will be ignored while PLAYING) */\r
+  g_object_get (pipeline, "flags", &flags, NULL);\r
+  flags ^= GST_PLAY_FLAG_DEINTERLACE;\r
+  g_object_set (pipeline, "flags", flags, NULL);\r
+  /* Resume */\r
+  gst_element_set_state (pipeline, GST_STATE_PLAYING);\r
+  /* Wait until the state change takes effect */\r
+  gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);\r
+  /* Set current position, if we were able to recover it previously */\r
+  if (GST_CLOCK_TIME_IS_VALID (current_position)) {\r
+    gst_element_seek_simple (pipeline, format, GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE, current_position);\r
+  }\r
+}\r
+  \r
+/* Output the current values of all Color Balance channels and the Deinterlace flag */\r
+static void print_current_values (GstElement *pipeline) {\r
+  gint flags;\r
+  const GList *channels, *l;\r
+  \r
+  /* Output Color Balance values */\r
+  channels = gst_color_balance_list_channels (GST_COLOR_BALANCE (pipeline));\r
+  for (l = channels; l != NULL; l = l->next) {\r
+    GstColorBalanceChannel *channel = (GstColorBalanceChannel *)l->data;\r
+    gint value = gst_color_balance_get_value (GST_COLOR_BALANCE (pipeline), channel);\r
+    g_print ("%s: %3d%% ", channel->label,\r
+        100 * (value - channel->min_value) / (channel->max_value - channel->min_value));\r
+  }\r
+  \r
+  /* Output Deinterlace flag value */\r
+  g_object_get (pipeline, "flags", &flags, NULL);\r
+  g_print ("Deinterlacing: %s\n", flags & GST_PLAY_FLAG_DEINTERLACE ? "ON" : "OFF");\r
+}\r
+  \r
+/* Process keyboard input */\r
+static gboolean handle_keyboard (GIOChannel *source, GIOCondition cond, CustomData *data) {\r
+  gchar *str = NULL;\r
+  \r
+  if (!g_io_channel_read_line (source, &str, NULL, NULL, NULL) == G_IO_STATUS_NORMAL) {\r
+    return TRUE;\r
+  }\r
+  \r
+  switch (g_ascii_tolower (str[0])) {\r
+  case 'c':\r
+    update_color_channel ("CONTRAST", g_ascii_isupper (str[0]), GST_COLOR_BALANCE (data->pipeline));\r
+    break;\r
+  case 'b':\r
+    update_color_channel ("BRIGHTNESS", g_ascii_isupper (str[0]), GST_COLOR_BALANCE (data->pipeline));\r
+    break;\r
+  case 'h':\r
+    update_color_channel ("HUE", g_ascii_isupper (str[0]), GST_COLOR_BALANCE (data->pipeline));\r
+    break;\r
+  case 's':\r
+    update_color_channel ("SATURATION", g_ascii_isupper (str[0]), GST_COLOR_BALANCE (data->pipeline));\r
+    break;\r
+  case 'd':\r
+    toggle_deinterlace (data->pipeline);\r
+    break;\r
+  case 'q':\r
+    g_main_loop_quit (data->loop);\r
+    break;\r
+  default:\r
+    break;\r
+  }\r
+  \r
+  g_free (str);\r
+  \r
+  print_current_values (data->pipeline);\r
+  \r
+  return TRUE;\r
+}\r
+  \r
+int main(int argc, char *argv[]) {\r
+  CustomData data;\r
+  GstStateChangeReturn ret;\r
+  GIOChannel *io_stdin;\r
+   \r
+  /* Initialize GStreamer */\r
+  gst_init (&argc, &argv);\r
+  
+  /* Initialize our data structure */\r
+  memset (&data, 0, sizeof (data));\r
+  \r
+  /* Print usage map */\r
+  g_print (\r
+    "USAGE: Choose one of the following options, then press enter:\n"\r
+    " 'C' to increase contrast, 'c' to decrease contrast\n"\r
+    " 'B' to increase brightness, 'b' to decrease brightness\n"\r
+    " 'H' to increase hue, 'h' to decrease hue\n"\r
+    " 'S' to increase saturation, 's' to decrease saturation\n"\r
+    " 'D' to toggle deinterlacing ON and OFF\n"\r
+    " 'Q' to quit\n");\r
+  \r
+  /* Build the pipeline */\r
+  data.pipeline = gst_parse_launch ("playbin2 uri=http://docs.gstreamer.com/media/sintel_trailer-480i.avi", NULL);\r
+  \r
+  /* Add a keyboard watch so we get notified of keystrokes */\r
+#ifdef _WIN32\r
+  io_stdin = g_io_channel_win32_new_fd (fileno (stdin));\r
+#else\r
+  io_stdin = g_io_channel_unix_new (fileno (stdin));\r
+#endif\r
+  g_io_add_watch (io_stdin, G_IO_IN, (GIOFunc)handle_keyboard, &data);\r
+  \r
+  /* Start playing */\r
+  ret = gst_element_set_state (data.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 (data.pipeline);\r
+    return -1;\r
+  }\r
+  print_current_values (data.pipeline);\r
+   \r
+  /* Create a GLib Main Loop and set it to run */\r
+  data.loop = g_main_loop_new (NULL, FALSE);\r
+  g_main_loop_run (data.loop);\r
+  \r
+  /* Free resources */\r
+  g_main_loop_unref (data.loop);\r
+  g_io_channel_unref (io_stdin);\r
+  gst_element_set_state (data.pipeline, GST_STATE_NULL);\r
+  gst_object_unref (data.pipeline);\r
+  return 0;\r
+}\r
diff --git a/gst-sdk/tutorials/vs2010/playback-tutorial-5/playback-tutorial-5.vcxproj b/gst-sdk/tutorials/vs2010/playback-tutorial-5/playback-tutorial-5.vcxproj
new file mode 100644 (file)
index 0000000..3bfe49f
--- /dev/null
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <ItemGroup Label="ProjectConfigurations">\r
+    <ProjectConfiguration Include="Debug|Win32">\r
+      <Configuration>Debug</Configuration>\r
+      <Platform>Win32</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Debug|x64">\r
+      <Configuration>Debug</Configuration>\r
+      <Platform>x64</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Release|Win32">\r
+      <Configuration>Release</Configuration>\r
+      <Platform>Win32</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Release|x64">\r
+      <Configuration>Release</Configuration>\r
+      <Platform>x64</Platform>\r
+    </ProjectConfiguration>\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <ClCompile Include="..\..\playback-tutorial-5.c" />\r
+  </ItemGroup>\r
+  <PropertyGroup Label="Globals">\r
+    <Keyword>Win32Proj</Keyword>\r
+    <ProjectGuid>{57F94395-E9A1-430E-AF28-165FD9BE0872}</ProjectGuid>\r
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>\r
+  </PropertyGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />\r
+  <PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <UseDebugLibraries>true</UseDebugLibraries>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <UseDebugLibraries>false</UseDebugLibraries>\r
+    <WholeProgramOptimization>true</WholeProgramOptimization>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+  </PropertyGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />\r
+  <ImportGroup Label="ExtensionSettings">\r
+  </ImportGroup>\r
+  <ImportGroup Label="PropertySheets" Condition="'$(Platform)'=='Win32'">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
+    <Import Project="$(GSTREAMER_SDK_ROOT_X86)\share\vs\2010\libs\gstreamer-0.10.props" Condition="exists('$(GSTREAMER_SDK_ROOT_X86)\share\vs\2010\libs\gstreamer-0.10.props')" />\r
+    <Import Project="$(GSTREAMER_SDK_ROOT_X86)\share\vs\2010\libs\gstreamer-interfaces-0.10.props" Condition="exists('$(GSTREAMER_SDK_ROOT_X86)\share\vs\2010\libs\gstreamer-interfaces-0.10.props')" />\r
+    <Import Project="$(GSTREAMER_SDK_ROOT_X86)\share\vs\2010\msvc\x86.props" Condition="exists('$(GSTREAMER_SDK_ROOT_X86)\share\vs\2010\msvc\x86.props')" />\r
+  </ImportGroup>\r
+  <ImportGroup Label="PropertySheets" Condition="'$(Platform)'=='x64'">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
+    <Import Project="$(GSTREAMER_SDK_ROOT_X86_64)\share\vs\2010\libs\gstreamer-0.10.props" Condition="exists('$(GSTREAMER_SDK_ROOT_X86_64)\share\vs\2010\libs\gstreamer-0.10.props')" />\r
+    <Import Project="$(GSTREAMER_SDK_ROOT_X86_64)\share\vs\2010\libs\gstreamer-interfaces-0.10.props" Condition="exists('$(GSTREAMER_SDK_ROOT_X86_64)\share\vs\2010\libs\gstreamer-interfaces-0.10.props')" />\r
+    <Import Project="$(GSTREAMER_SDK_ROOT_X86_64)\share\vs\2010\msvc\x86_64.props" Condition="exists('$(GSTREAMER_SDK_ROOT_X86_64)\share\vs\2010\msvc\x86_64.props')" />\r
+  </ImportGroup>\r
+  <PropertyGroup Label="UserMacros" />\r
+  <PropertyGroup Condition="'$(Configuration)'=='Debug'">\r
+    <LinkIncremental>true</LinkIncremental>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)'=='Release'">\r
+    <LinkIncremental>false</LinkIncremental>\r
+  </PropertyGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">\r
+    <ClCompile>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <WarningLevel>Level3</WarningLevel>\r
+      <Optimization>Disabled</Optimization>\r
+      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+    </ClCompile>\r
+    <Link>\r
+      <SubSystem>Console</SubSystem>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>\r
+      <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">\r
+    <ClCompile>\r
+      <WarningLevel>Level3</WarningLevel>\r
+      <PrecompiledHeader>\r
+      </PrecompiledHeader>\r
+      <Optimization>MaxSpeed</Optimization>\r
+      <FunctionLevelLinking>true</FunctionLevelLinking>\r
+      <IntrinsicFunctions>true</IntrinsicFunctions>\r
+      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+    </ClCompile>\r
+    <Link>\r
+      <SubSystem>Console</SubSystem>\r
+      <GenerateDebugInformation>false</GenerateDebugInformation>\r
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />\r
+  <ImportGroup Label="ExtensionTargets">\r
+  </ImportGroup>\r
+</Project>
\ No newline at end of file
diff --git a/gst-sdk/tutorials/vs2010/playback-tutorial-5/playback-tutorial-5.vcxproj.filters b/gst-sdk/tutorials/vs2010/playback-tutorial-5/playback-tutorial-5.vcxproj.filters
new file mode 100644 (file)
index 0000000..d11ad27
--- /dev/null
@@ -0,0 +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="..\..\playback-tutorial-5.c" />\r
+  </ItemGroup>\r
+</Project>
\ No newline at end of file
index 224fb25..34d0e6e 100644 (file)
@@ -29,6 +29,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "playback-tutorial-4", "play
 EndProject\r
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "playback-tutorial-3", "playback-tutorial-3\playback-tutorial-3.vcxproj", "{B84F4F87-E804-456C-874E-AC76E0116268}"\r
 EndProject\r
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "playback-tutorial-5", "playback-tutorial-5\playback-tutorial-5.vcxproj", "{57F94395-E9A1-430E-AF28-165FD9BE0872}"\r
+EndProject\r
 Global\r
        GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
                Debug|Win32 = Debug|Win32\r
@@ -149,6 +151,14 @@ Global
                {B84F4F87-E804-456C-874E-AC76E0116268}.Release|Win32.Build.0 = Release|Win32\r
                {B84F4F87-E804-456C-874E-AC76E0116268}.Release|x64.ActiveCfg = Release|x64\r
                {B84F4F87-E804-456C-874E-AC76E0116268}.Release|x64.Build.0 = Release|x64\r
+               {57F94395-E9A1-430E-AF28-165FD9BE0872}.Debug|Win32.ActiveCfg = Debug|Win32\r
+               {57F94395-E9A1-430E-AF28-165FD9BE0872}.Debug|Win32.Build.0 = Debug|Win32\r
+               {57F94395-E9A1-430E-AF28-165FD9BE0872}.Debug|x64.ActiveCfg = Debug|x64\r
+               {57F94395-E9A1-430E-AF28-165FD9BE0872}.Debug|x64.Build.0 = Debug|x64\r
+               {57F94395-E9A1-430E-AF28-165FD9BE0872}.Release|Win32.ActiveCfg = Release|Win32\r
+               {57F94395-E9A1-430E-AF28-165FD9BE0872}.Release|Win32.Build.0 = Release|Win32\r
+               {57F94395-E9A1-430E-AF28-165FD9BE0872}.Release|x64.ActiveCfg = Release|x64\r
+               {57F94395-E9A1-430E-AF28-165FD9BE0872}.Release|x64.Build.0 = Release|x64\r
        EndGlobalSection\r
        GlobalSection(SolutionProperties) = preSolution\r
                HideSolutionNode = FALSE\r