examples : Port to 0.11
authorEdward Hervey <bilboed@bilboed.com>
Fri, 4 Nov 2011 15:23:03 +0000 (16:23 +0100)
committerEdward Hervey <bilboed@bilboed.com>
Fri, 4 Nov 2011 15:23:03 +0000 (16:23 +0100)
tests/examples/camerabin/gst-camera.c
tests/examples/camerabin2/gst-camera2.c
tests/examples/camerabin2/gst-camerabin2-test.c
tests/examples/mxf/mxfdemux-structure.c
tests/examples/scaletempo/demo-player.c

index 5b33f54..b870e8f 100644 (file)
@@ -219,8 +219,7 @@ handle_element_message (GstMessage * msg)
   const GValue *image;
   GstBuffer *buf = NULL;
   guint8 *data = NULL;
-  gchar *caps_string;
-  guint size = 0;
+  gsize size = 0;
   gchar *filename = NULL;
   FILE *f = NULL;
   size_t written;
@@ -232,8 +231,6 @@ handle_element_message (GstMessage * msg)
     image = gst_structure_get_value (st, "buffer");
     if (image) {
       buf = gst_value_get_buffer (image);
-      data = GST_BUFFER_DATA (buf);
-      size = GST_BUFFER_SIZE (buf);
       if (g_str_equal (gst_structure_get_name (st), "raw-image")) {
         filename = g_strdup_printf ("test_%04u.raw", num_pics);
       } else if (g_str_equal (gst_structure_get_name (st), "preview-image")) {
@@ -243,13 +240,12 @@ handle_element_message (GstMessage * msg)
         g_print ("unknown buffer received\n");
         return;
       }
-      caps_string = gst_caps_to_string (GST_BUFFER_CAPS (buf));
-      g_print ("writing buffer to %s, buffer caps: %s\n",
-          filename, caps_string);
-      g_free (caps_string);
+      g_print ("writing buffer to %s\n", filename);
       f = g_fopen (filename, "w");
       if (f) {
+        data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
         written = fwrite (data, size, 1, f);
+        gst_buffer_unmap (buf, data, size);
         if (!written) {
           g_print ("errro writing file\n");
         }
@@ -270,11 +266,11 @@ my_bus_sync_callback (GstBus * bus, GstMessage * message, gpointer data)
   if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT)
     return GST_BUS_PASS;
 
-  if (!gst_structure_has_name (message->structure, "prepare-xwindow-id"))
+  if (!gst_message_has_name (message, "prepare-xwindow-id"))
     return GST_BUS_PASS;
 
   /* FIXME: make sure to get XID in main thread */
-  gst_x_overlay_set_window_handle (GST_X_OVERLAY (message->src),
+  gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (message->src),
 #if GTK_CHECK_VERSION (2, 91, 6)
       GDK_WINDOW_XID (gtk_widget_get_window (ui_drawing)));
 #else
@@ -465,7 +461,7 @@ me_gst_setup_pipeline_create_post_bin (const gchar * post, gboolean video)
   }
 
   caps = gst_caps_new_simple ("video/x-raw-yuv",
-      "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('I', '4', '2', '0'), NULL);
+      "format", G_TYPE_STRING, "I420", NULL);
   g_object_set (G_OBJECT (filter), "caps", caps, NULL);
   gst_caps_unref (caps);
 
@@ -1110,7 +1106,7 @@ create_menu_items_from_structure (GstStructure * structure)
   GString *item_str = NULL;
   guint j, num_items_created = 0, num_framerates = 1;
   gint w = 0, h = 0, n = 0, d = 1;
-  guint32 fourcc = 0;
+  const gchar *format = NULL;
 
   g_return_val_if_fail (structure != NULL, 0);
 
@@ -1120,8 +1116,8 @@ create_menu_items_from_structure (GstStructure * structure)
   if (0 == strcmp (structure_name, "video/x-raw-yuv")) {
     item_str = g_string_new_len ("", 128);
 
-    if (gst_structure_has_field_typed (structure, "format", GST_TYPE_FOURCC)) {
-      gst_structure_get_fourcc (structure, "format", &fourcc);
+    if (gst_structure_has_field_typed (structure, "format", G_TYPE_STRING)) {
+      format = gst_structure_get_string (structure, "format");
     }
 
     if (gst_structure_has_field_typed (structure, "width", GST_TYPE_INT_RANGE)) {
@@ -1170,15 +1166,14 @@ create_menu_items_from_structure (GstStructure * structure)
         d = gst_value_get_fraction_denominator (item);
       }
       g_string_assign (item_str, structure_name);
-      g_string_append_printf (item_str, " (%" GST_FOURCC_FORMAT ")",
-          GST_FOURCC_ARGS (fourcc));
+      g_string_append_printf (item_str, " (%s)", format);
       g_string_append_printf (item_str, ", %dx%d at %d/%d", w, h, n, d);
       gtk_list_store_append (store, &iter);
       gtk_list_store_set (store, &iter, 0, item_str->str, -1);
 
       video_caps =
-          gst_caps_new_simple (structure_name, "format", GST_TYPE_FOURCC,
-          fourcc,
+          gst_caps_new_simple (structure_name, "format", G_TYPE_STRING,
+          format,
           "width", G_TYPE_INT, w, "height", G_TYPE_INT, h,
           "framerate", GST_TYPE_FRACTION, n, d, NULL);
       video_caps_list = g_list_append (video_caps_list, video_caps);
index bd612e7..8293716 100644 (file)
@@ -32,7 +32,7 @@
 #include "gst-camera2.h"
 
 #include <gst/gst.h>
-#include <gst/interfaces/xoverlay.h>
+#include <gst/interfaces/videooverlay.h>
 #include <gtk/gtk.h>
 #include <gdk/gdkx.h>
 #include <gdk/gdkkeysyms.h>
@@ -92,12 +92,12 @@ bus_sync_callback (GstBus * bus, GstMessage * message, gpointer data)
   if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT)
     return GST_BUS_PASS;
 
-  if (!gst_structure_has_name (message->structure, "prepare-xwindow-id"))
+  if (!gst_message_has_name (message, "prepare-xwindow-id"))
     return GST_BUS_PASS;
 
   /* FIXME: make sure to get XID in main thread */
   ui_drawing = GTK_WIDGET (gtk_builder_get_object (builder, "viewfinderArea"));
-  gst_x_overlay_set_window_handle (GST_X_OVERLAY (message->src),
+  gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (message->src),
 #if GTK_CHECK_VERSION (2, 91, 6)
       GDK_WINDOW_XID (gtk_widget_get_window (ui_drawing)));
 #else
index f112dbc..6ca2ffc 100644 (file)
 #define GST_USE_UNSTABLE_API 1
 
 #include <gst/gst.h>
-#include <gst/interfaces/xoverlay.h>
+#include <gst/interfaces/videooverlay.h>
 #include <gst/interfaces/photography.h>
 #include <string.h>
 #include <sys/time.h>
@@ -311,18 +311,16 @@ create_host_window (void)
   }
 }
 
-static gboolean
-camera_src_get_timestamp_probe (GstPad * pad, GstMiniObject * obj,
-    gpointer udata)
+static GstPadProbeReturn
+camera_src_get_timestamp_probe (GstPad * pad, GstPadProbeType type,
+    GstMiniObject * obj, gpointer udata)
 {
   CaptureTiming *timing;
 
   timing = (CaptureTiming *) g_list_first (capture_times)->data;
   timing->camera_capture = gst_util_get_timestamp ();
 
-  gst_pad_remove_data_probe (pad, camera_probe_id);
-
-  return TRUE;
+  return GST_PAD_PROBE_REMOVE;
 }
 
 static gboolean
@@ -334,7 +332,7 @@ viewfinder_get_timestamp_probe (GstPad * pad, GstMiniObject * obj,
   timing = (CaptureTiming *) g_list_first (capture_times)->data;
   timing->precapture = gst_util_get_timestamp ();
 
-  gst_pad_remove_data_probe (pad, viewfinder_probe_id);
+  gst_pad_remove_probe (pad, viewfinder_probe_id);
 
   return TRUE;
 }
@@ -346,8 +344,7 @@ sync_bus_callback (GstBus * bus, GstMessage * message, gpointer data)
   const GValue *image;
   GstBuffer *buf = NULL;
   guint8 *data_buf = NULL;
-  gchar *caps_string;
-  guint size = 0;
+  gsize size = 0;
   gchar *preview_filename = NULL;
   FILE *f = NULL;
   size_t written;
@@ -356,10 +353,10 @@ sync_bus_callback (GstBus * bus, GstMessage * message, gpointer data)
     case GST_MESSAGE_ELEMENT:{
       st = gst_message_get_structure (message);
       if (st) {
-        if (gst_structure_has_name (message->structure, "prepare-xwindow-id")) {
+        if (gst_message_has_name (message, "prepare-xwindow-id")) {
           if (!no_xwindow && window) {
-            gst_x_overlay_set_window_handle (GST_X_OVERLAY (GST_MESSAGE_SRC
-                    (message)), window);
+            gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY
+                (GST_MESSAGE_SRC (message)), window);
             gst_message_unref (message);
             message = NULL;
             return GST_BUS_DROP;
@@ -376,8 +373,10 @@ sync_bus_callback (GstBus * bus, GstMessage * message, gpointer data)
             /* set up probe to check when the viewfinder gets data */
             GstPad *pad = gst_element_get_static_pad (viewfinder_sink, "sink");
 
-            viewfinder_probe_id = gst_pad_add_buffer_probe (pad,
-                (GCallback) viewfinder_get_timestamp_probe, NULL);
+            viewfinder_probe_id =
+                gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_BUFFER,
+                (GstPadProbeCallback) viewfinder_get_timestamp_probe, NULL,
+                NULL);
 
             gst_object_unref (pad);
           }
@@ -386,14 +385,12 @@ sync_bus_callback (GstBus * bus, GstMessage * message, gpointer data)
           image = gst_structure_get_value (st, "buffer");
           if (image) {
             buf = gst_value_get_buffer (image);
-            data_buf = GST_BUFFER_DATA (buf);
-            size = GST_BUFFER_SIZE (buf);
             preview_filename = g_strdup_printf ("test_vga.rgb");
-            caps_string = gst_caps_to_string (GST_BUFFER_CAPS (buf));
-            g_free (caps_string);
             f = g_fopen (preview_filename, "w");
             if (f) {
+              data_buf = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
               written = fwrite (data_buf, size, 1, f);
+              gst_buffer_unmap (buf, data_buf, size);
               if (!written) {
                 g_print ("error writing file\n");
               }
@@ -915,8 +912,7 @@ run_pipeline (gpointer user_data)
 
   g_object_get (camerabin, "camera-source", &video_source, NULL);
   if (video_source) {
-    if (GST_IS_ELEMENT (video_source) &&
-        gst_element_implements_interface (video_source, GST_TYPE_PHOTOGRAPHY)) {
+    if (GST_IS_ELEMENT (video_source) && GST_IS_PHOTOGRAPHY (video_source)) {
       /* Set GstPhotography interface options. If option not given as
          command-line parameter use default of the source element. */
       if (scene_mode != SCENE_MODE_NONE)
@@ -953,8 +949,8 @@ run_pipeline (gpointer user_data)
     GstPad *pad;
 
     pad = gst_element_get_static_pad (video_source, "imgsrc");
-    camera_probe_id = gst_pad_add_buffer_probe (pad,
-        (GCallback) camera_src_get_timestamp_probe, NULL);
+    camera_probe_id = gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_BUFFER,
+        (GstPadProbeCallback) camera_src_get_timestamp_probe, NULL, NULL);
 
     gst_object_unref (pad);
   }
index 6f735c4..03ab7b9 100644 (file)
@@ -30,8 +30,14 @@ static gchar *
 g_value_to_string (const GValue * val)
 {
   if (G_VALUE_TYPE (val) == GST_TYPE_BUFFER) {
-    const GstBuffer *buf = gst_value_get_buffer (val);
-    gchar *ret = g_base64_encode (GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
+    GstBuffer *buf = gst_value_get_buffer (val);
+    gpointer data;
+    gsize size;
+    gchar *ret;
+
+    data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
+    ret = g_base64_encode (data, size);
+    gst_buffer_unmap (buf, data, size);
 
     return ret;
   } else {
index 0adf0e1..1a0bd33 100644 (file)
@@ -68,19 +68,19 @@ no_pipeline (DemoPlayer * player)
   return FALSE;
 }
 
-static gboolean
-demo_player_event_listener (GstElement * host, GstEvent * event, gpointer data)
+static GstPadProbeReturn
+demo_player_event_listener (GstPad * pad, GstPadProbeType type,
+    GstEvent * event, gpointer data)
 {
   DemoPlayer *player = DEMO_PLAYER (data);
   DemoPlayerPrivate *priv = DEMO_PLAYER_GET_PRIVATE (player);
 
-  if (GST_EVENT_TYPE (event) == GST_EVENT_NEWSEGMENT) {
-    gdouble rate, applied_rate;
+  if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
+    const GstSegment *segment;
     gdouble new_rate;
 
-    gst_event_parse_new_segment_full (event, NULL, &rate, &applied_rate, NULL,
-        NULL, NULL, NULL);
-    new_rate = rate * applied_rate;
+    gst_event_parse_segment (event, &segment);
+    new_rate = segment->rate * segment->applied_rate;
     if (priv->rate != new_rate) {
       priv->rate = new_rate;
       g_signal_emit (player, demo_player_signals[SIGNAL_RATE_CHANGE], 0,
@@ -88,7 +88,7 @@ demo_player_event_listener (GstElement * host, GstEvent * event, gpointer data)
     }
   }
 
-  return TRUE;
+  return GST_PAD_PROBE_OK;
 }
 
 static void
@@ -174,8 +174,9 @@ demo_player_build_pipeline (DemoPlayer * player)
   LINK_ELEMENTS (format, resample);
   LINK_ELEMENTS (resample, asink);
 
-  gst_pad_add_event_probe (gst_element_get_static_pad (asink, "sink"),
-      G_CALLBACK (demo_player_event_listener), player);
+  gst_pad_add_probe (gst_element_get_static_pad (asink, "sink"),
+      GST_PAD_PROBE_TYPE_EVENT,
+      (GstPadProbeCallback) demo_player_event_listener, player, NULL);
 
   ghostpad = gst_element_get_static_pad (filter, "sink");
   gst_element_add_pad (audioline, gst_ghost_pad_new ("sink", ghostpad));
@@ -196,8 +197,9 @@ demo_player_build_pipeline (DemoPlayer * player)
   priv->scaletempo_line = audioline;
   MAKE_ELEMENT (NULL, priv->scalerate_line, audiosink_name,
       "scaling_audio_sink");
-  gst_pad_add_event_probe (gst_element_get_static_pad (priv->scalerate_line,
-          "sink"), G_CALLBACK (demo_player_event_listener), player);
+  gst_pad_add_probe (gst_element_get_static_pad (priv->scalerate_line,
+          "sink"), GST_PAD_PROBE_TYPE_EVENT,
+      (GstPadProbeCallback) demo_player_event_listener, player, NULL);
   g_object_ref (priv->scaletempo_line);
   g_object_ref (priv->scalerate_line);
 }
@@ -221,9 +223,8 @@ _set_rate (DemoPlayer * player, gdouble new_rate, gint second)
   priv = DEMO_PLAYER_GET_PRIVATE (player);
 
   if (second < 0) {
-    GstFormat fmt = GST_FORMAT_TIME;
     seek_type = GST_SEEK_TYPE_SET;
-    if (!gst_element_query_position (priv->pipeline, &fmt, &pos)) {
+    if (!gst_element_query_position (priv->pipeline, GST_FORMAT_TIME, &pos)) {
       // This should be the default but too many upstream elements seek anyway
       pos = GST_CLOCK_TIME_NONE;
       seek_type = GST_SEEK_TYPE_NONE;
@@ -461,12 +462,12 @@ demo_player_get_position_func (DemoPlayer * player)
 {
   DemoPlayerPrivate *priv = DEMO_PLAYER_GET_PRIVATE (player);
   gint64 pos;
-  GstFormat fmt = GST_FORMAT_TIME;
 
   if (!priv->pipeline)
     return -1;
 
-  if (!gst_element_query_position (priv->pipeline, &fmt, &pos) || pos < 0) {
+  if (!gst_element_query_position (priv->pipeline, GST_FORMAT_TIME, &pos)
+      || pos < 0) {
     return -1;
   }
 
@@ -478,12 +479,12 @@ demo_player_get_duration_func (DemoPlayer * player)
 {
   DemoPlayerPrivate *priv = DEMO_PLAYER_GET_PRIVATE (player);
   gint64 dur;
-  GstFormat fmt = GST_FORMAT_TIME;
 
   if (!priv->pipeline)
     return -1;
 
-  if (!gst_element_query_duration (priv->pipeline, &fmt, &dur) || dur < 0) {
+  if (!gst_element_query_duration (priv->pipeline, GST_FORMAT_TIME, &dur)
+      || dur < 0) {
     return -1;
   }