Merge branch 'master' into 0.11
[platform/upstream/gst-plugins-base.git] / tests / examples / seek / seek.c
index 9502c8d..6e4592b 100644 (file)
@@ -47,9 +47,9 @@
 #include <gdk/gdkquartzwindow.h>
 #endif
 
-#include <gst/interfaces/xoverlay.h>
+#include <gst/video/videooverlay.h>
+#include <gst/video/colorbalance.h>
 #include <gst/interfaces/navigation.h>
-#include <gst/interfaces/colorbalance.h>
 
 GST_DEBUG_CATEGORY_STATIC (seek_debug);
 #define GST_CAT_DEFAULT (seek_debug)
@@ -140,7 +140,7 @@ typedef struct
 
   GstElement *navigation_element;
   GstElement *colorbalance_element;
-  GstElement *xoverlay_element;
+  GstElement *overlay_element;
 
   /* Settings */
   gboolean accurate_seek;
@@ -178,7 +178,7 @@ typedef struct
   gboolean need_streams;
   gint n_video, n_audio, n_text;
 
-  GStaticMutex state_mutex;
+  GMutex state_mutex;
 
   GArray *vis_entries;          /* Array of VisEntry structs */
 
@@ -259,11 +259,11 @@ playbin_set_uri (GstElement * playbin, const gchar * location,
 }
 
 static void
-make_playbin2_pipeline (SeekApp * app, const gchar * location)
+make_playbin_pipeline (SeekApp * app, const gchar * location)
 {
   GstElement *pipeline;
 
-  app->pipeline = pipeline = gst_element_factory_make ("playbin2", "playbin2");
+  app->pipeline = pipeline = gst_element_factory_make ("playbin", "playbin");
   g_assert (pipeline);
 
   playbin_set_uri (pipeline, location,
@@ -293,7 +293,7 @@ typedef struct
 Pipeline;
 
 static const Pipeline pipelines[] = {
-  {"playbin2", make_playbin2_pipeline},
+  {"playbin", make_playbin_pipeline},
 #ifndef GST_DISABLE_PARSE
   {"parse-launch", make_parselaunch_pipeline},
 #endif
@@ -349,8 +349,8 @@ query_positions (SeekApp * app)
 
     format = seek_formats[i].format;
 
-    if (gst_element_query_position (app->pipeline, &format, &position) &&
-        gst_element_query_duration (app->pipeline, &format, &total)) {
+    if (gst_element_query_position (app->pipeline, format, &position) &&
+        gst_element_query_duration (app->pipeline, format, &total)) {
       g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
           seek_formats[i].name, position, total);
     } else {
@@ -431,8 +431,8 @@ update_scale (SeekApp * app)
   //position = 0;
   //duration = 0;
 
-  gst_element_query_position (app->pipeline, &format, &app->position);
-  gst_element_query_duration (app->pipeline, &format, &app->duration);
+  gst_element_query_position (app->pipeline, format, &app->position);
+  gst_element_query_duration (app->pipeline, format, &app->duration);
 
   if (app->stats)
     query_positions (app);
@@ -447,8 +447,8 @@ update_scale (SeekApp * app)
   if (app->seek_format) {
     format = app->seek_format->value;
     seek_pos = seek_dur = -1;
-    gst_element_query_position (app->pipeline, &format, &seek_pos);
-    gst_element_query_duration (app->pipeline, &format, &seek_dur);
+    gst_element_query_position (app->pipeline, format, &seek_pos);
+    gst_element_query_duration (app->pipeline, format, &seek_dur);
 
     str = g_strdup_printf ("%" G_GINT64_FORMAT, seek_pos);
     gtk_label_set_text (GTK_LABEL (app->seek_position_label), str);
@@ -730,7 +730,7 @@ failed:
 static void
 pause_cb (GtkButton * button, SeekApp * app)
 {
-  g_static_mutex_lock (&app->state_mutex);
+  g_mutex_lock (&app->state_mutex);
   if (app->state != GST_STATE_PAUSED) {
     GstStateChangeReturn ret;
 
@@ -751,13 +751,13 @@ pause_cb (GtkButton * button, SeekApp * app)
     gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
         "Paused");
   }
-  g_static_mutex_unlock (&app->state_mutex);
+  g_mutex_unlock (&app->state_mutex);
 
   return;
 
 failed:
   {
-    g_static_mutex_unlock (&app->state_mutex);
+    g_mutex_unlock (&app->state_mutex);
     g_print ("PAUSE failed\n");
     gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
         "Pause failed");
@@ -774,7 +774,7 @@ stop_cb (GtkButton * button, SeekApp * app)
     g_print ("READY pipeline\n");
     gtk_statusbar_pop (GTK_STATUSBAR (app->statusbar), app->status_id);
 
-    g_static_mutex_lock (&app->state_mutex);
+    g_mutex_lock (&app->state_mutex);
     ret = gst_element_set_state (app->pipeline, STOP_STATE);
     if (ret == GST_STATE_CHANGE_FAILURE)
       goto failed;
@@ -792,7 +792,7 @@ stop_cb (GtkButton * button, SeekApp * app)
 
     if (app->pipeline_type == 0)
       clear_streams (app);
-    g_static_mutex_unlock (&app->state_mutex);
+    g_mutex_unlock (&app->state_mutex);
 
     gtk_widget_set_sensitive (GTK_WIDGET (app->seek_scale), TRUE);
     for (i = 0; i < G_N_ELEMENTS (app->navigation_buttons); i++)
@@ -802,7 +802,7 @@ stop_cb (GtkButton * button, SeekApp * app)
 
 failed:
   {
-    g_static_mutex_unlock (&app->state_mutex);
+    g_mutex_unlock (&app->state_mutex);
     g_print ("STOP failed\n");
     gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
         "Stop failed");
@@ -1073,7 +1073,7 @@ update_streams (SeekApp * app)
     /* remove previous info */
     clear_streams (app);
 
-    /* here we get and update the different streams detected by playbin2 */
+    /* here we get and update the different streams detected by playbin */
     g_object_get (app->pipeline, "n-video", &app->n_video, NULL);
     g_object_get (app->pipeline, "n-audio", &app->n_audio, NULL);
     g_object_get (app->pipeline, "n-text", &app->n_text, NULL);
@@ -1208,7 +1208,7 @@ init_visualization_features (SeekApp * app)
 
   app->vis_entries = g_array_new (FALSE, FALSE, sizeof (VisEntry));
 
-  list = gst_registry_feature_filter (gst_registry_get_default (),
+  list = gst_registry_feature_filter (gst_registry_get (),
       filter_vis_features, FALSE, NULL);
 
   for (walk = list; walk; walk = g_list_next (walk)) {
@@ -1241,7 +1241,7 @@ vis_combo_cb (GtkComboBox * combo, SeekApp * app)
     if (!element)
       return;
 
-    /* set vis plugin for playbin2 */
+    /* set vis plugin for playbin */
     g_object_set (app->pipeline, "vis-plugin", element, NULL);
   }
 }
@@ -1311,38 +1311,37 @@ mute_notify_cb (GstElement * pipeline, GParamSpec * arg, SeekApp * app)
 static void
 shot_cb (GtkButton * button, SeekApp * app)
 {
-  GstBuffer *buffer;
+  GstSample *sample = NULL;
   GstCaps *caps;
 
+  GST_DEBUG ("taking snapshot");
+
   /* convert to our desired format (RGB24) */
-  caps = gst_caps_new_simple ("video/x-raw-rgb",
-      "bpp", G_TYPE_INT, 24, "depth", G_TYPE_INT, 24,
+  caps = gst_caps_new_simple ("video/x-raw", "format", G_TYPE_STRING, "RGB",
       /* Note: we don't ask for a specific width/height here, so that
        * videoscale can adjust dimensions from a non-1/1 pixel aspect
        * ratio to a 1/1 pixel-aspect-ratio */
-      "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
-      "endianness", G_TYPE_INT, G_BIG_ENDIAN,
-      "red_mask", G_TYPE_INT, 0xff0000,
-      "green_mask", G_TYPE_INT, 0x00ff00,
-      "blue_mask", G_TYPE_INT, 0x0000ff, NULL);
-
-  /* convert the latest frame to the requested format */
-  g_signal_emit_by_name (app->pipeline, "convert-frame", caps, &buffer);
+      "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1, NULL);
+
+  /* convert the latest sample to the requested format */
+  g_signal_emit_by_name (app->pipeline, "convert-sample", caps, &sample);
   gst_caps_unref (caps);
 
-  if (buffer) {
+  if (sample) {
+    GstBuffer *buffer;
     GstCaps *caps;
     GstStructure *s;
     gboolean res;
     gint width, height;
     GdkPixbuf *pixbuf;
     GError *error = NULL;
+    GstMapInfo map;
 
     /* get the snapshot buffer format now. We set the caps on the appsink so
      * that it can only be an rgb buffer. The only thing we have not specified
      * on the caps is the height, which is dependant on the pixel-aspect-ratio
      * of the source material */
-    caps = GST_BUFFER_CAPS (buffer);
+    caps = gst_sample_get_caps (sample);
     if (!caps) {
       g_warning ("could not get snapshot format\n");
       goto done;
@@ -1359,15 +1358,18 @@ shot_cb (GtkButton * button, SeekApp * app)
 
     /* create pixmap from buffer and save, gstreamer video buffers have a stride
      * that is rounded up to the nearest multiple of 4 */
-    pixbuf = gdk_pixbuf_new_from_data (GST_BUFFER_DATA (buffer),
+    buffer = gst_sample_get_buffer (sample);
+    gst_buffer_map (buffer, &map, GST_MAP_READ);
+    pixbuf = gdk_pixbuf_new_from_data (map.data,
         GDK_COLORSPACE_RGB, FALSE, 8, width, height,
         GST_ROUND_UP_4 (width * 3), NULL, NULL);
 
     /* save the pixbuf */
     gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
+    gst_buffer_unmap (buffer, &map);
 
   done:
-    gst_buffer_unref (buffer);
+    gst_sample_unref (sample);
   }
 }
 
@@ -1479,10 +1481,10 @@ msg_sync_step_done (GstBus * bus, GstMessage * message, SeekApp * app)
     return;
   }
 
-  if (g_static_mutex_trylock (&app->state_mutex)) {
+  if (g_mutex_trylock (&app->state_mutex)) {
     if (app->shuttling)
       do_shuttle (app);
-    g_static_mutex_unlock (&app->state_mutex);
+    g_mutex_unlock (&app->state_mutex);
   } else {
     /* ignore step messages that come while we are doing a state change */
     g_print ("state change is busy\n");
@@ -1663,7 +1665,7 @@ update_formats (SeekApp * app)
   GstIterator *it;
   gboolean done;
   GList *l;
-  gpointer item;
+  GValue item = { 0, };
   gchar *selected;
   gint selected_idx = 0, i;
 
@@ -1681,9 +1683,13 @@ update_formats (SeekApp * app)
 
   while (!done) {
     switch (gst_iterator_next (it, &item)) {
-      case GST_ITERATOR_OK:
-        app->formats = g_list_prepend (app->formats, item);
+      case GST_ITERATOR_OK:{
+        GstFormatDefinition *def = g_value_get_pointer (&item);
+
+        app->formats = g_list_prepend (app->formats, def);
+        g_value_reset (&item);
         break;
+      }
       case GST_ITERATOR_RESYNC:
         g_list_free (app->formats);
         app->formats = NULL;
@@ -1696,6 +1702,7 @@ update_formats (SeekApp * app)
         break;
     }
   }
+  g_value_unset (&item);
 
   app->formats = g_list_reverse (app->formats);
   gst_iterator_free (it);
@@ -1935,7 +1942,7 @@ static void
 find_interface_elements (SeekApp * app)
 {
   GstIterator *it;
-  gpointer item;
+  GValue item = { 0, };
   gboolean done = FALSE, hardware = FALSE;
 
   if (app->pipeline_type == 0)
@@ -1957,7 +1964,7 @@ find_interface_elements (SeekApp * app)
   while (!done) {
     switch (gst_iterator_next (it, &item)) {
       case GST_ITERATOR_OK:{
-        GstElement *element = GST_ELEMENT (item);
+        GstElement *element = GST_ELEMENT (g_value_get_object (&item));
 
         if (is_valid_color_balance_element (element)) {
           if (!app->colorbalance_element) {
@@ -1981,7 +1988,7 @@ find_interface_elements (SeekApp * app)
           }
         }
 
-        gst_object_unref (element);
+        g_value_reset (&item);
 
         if (hardware && app->colorbalance_element)
           done = TRUE;
@@ -2002,6 +2009,7 @@ find_interface_elements (SeekApp * app)
     }
   }
 
+  g_value_unset (&item);
   gst_iterator_free (it);
 }
 
@@ -2038,13 +2046,12 @@ navigation_cmd_cb (GtkButton * button, SeekApp * app)
 static GstBusSyncReply
 bus_sync_handler (GstBus * bus, GstMessage * message, SeekApp * app)
 {
-  if ((GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT) &&
-      gst_structure_has_name (message->structure, "prepare-xwindow-id")) {
+  if (gst_is_video_overlay_prepare_window_handle_message (message)) {
     GstElement *element = GST_ELEMENT (GST_MESSAGE_SRC (message));
 
-    if (app->xoverlay_element)
-      gst_object_unref (app->xoverlay_element);
-    app->xoverlay_element = GST_ELEMENT (gst_object_ref (element));
+    if (app->overlay_element)
+      gst_object_unref (app->overlay_element);
+    app->overlay_element = GST_ELEMENT (gst_object_ref (element));
 
     g_print ("got prepare-xwindow-id, setting XID %" G_GUINTPTR_FORMAT "\n",
         app->embed_xid);
@@ -2061,7 +2068,8 @@ bus_sync_handler (GstBus * bus, GstMessage * message, SeekApp * app)
      * shouldn't be done from a non-GUI thread without explicit locking).  */
     g_assert (app->embed_xid != 0);
 
-    gst_x_overlay_set_window_handle (GST_X_OVERLAY (element), app->embed_xid);
+    gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (element),
+        app->embed_xid);
 
     find_interface_elements (app);
   }
@@ -2083,8 +2091,8 @@ draw_cb (GtkWidget * widget, cairo_t * cr, SeekApp * app)
     return TRUE;
   }
 
-  if (app->xoverlay_element)
-    gst_x_overlay_expose (GST_X_OVERLAY (app->xoverlay_element));
+  if (app->overlay_element)
+    gst_video_overlay_expose (GST_VIDEO_OVERLAY (app->overlay_element));
 
   return FALSE;
 }
@@ -2255,7 +2263,7 @@ connect_bus_signals (SeekApp * app)
 
 #if defined (GDK_WINDOWING_X11) || defined (GDK_WINDOWING_WIN32) || defined (GDK_WINDOWING_QUARTZ)
   if (app->pipeline_type != 0) {
-    /* handle prepare-xwindow-id element message synchronously, but only for non-playbin2 */
+    /* handle prepare-xwindow-id element message synchronously, but only for non-playbin */
     gst_bus_set_sync_handler (bus, (GstBusSyncHandler) bus_sync_handler, app);
   }
 #endif
@@ -2925,8 +2933,8 @@ create_ui (SeekApp * app)
     GtkWidget *volume_label, *shot_button;
     GtkWidget *label;
 
-    playbin = gtk_expander_new ("playbin2 options");
-    /* the playbin2 panel controls for the video/audio/subtitle tracks */
+    playbin = gtk_expander_new ("playbin options");
+    /* the playbin panel controls for the video/audio/subtitle tracks */
     panel = gtk_hbox_new (FALSE, 0);
     app->video_combo = gtk_combo_box_text_new ();
     app->audio_combo = gtk_combo_box_text_new ();
@@ -2943,7 +2951,7 @@ create_ui (SeekApp * app)
         G_CALLBACK (audio_combo_cb), app);
     g_signal_connect (G_OBJECT (app->text_combo), "changed",
         G_CALLBACK (text_combo_cb), app);
-    /* playbin2 panel for flag checkboxes and volume/mute */
+    /* playbin panel for flag checkboxes and volume/mute */
     boxes = gtk_grid_new ();
     gtk_grid_set_row_spacing (GTK_GRID (boxes), 2);
     gtk_grid_set_row_homogeneous (GTK_GRID (boxes), FALSE);
@@ -3035,7 +3043,7 @@ create_ui (SeekApp * app)
         G_CALLBACK (mute_toggle_cb), app);
     g_signal_connect (G_OBJECT (app->volume_spinbutton), "value-changed",
         G_CALLBACK (volume_spinbutton_changed_cb), app);
-    /* playbin2 panel for snapshot */
+    /* playbin panel for snapshot */
     boxes2 = gtk_hbox_new (FALSE, 0);
     shot_button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
     gtk_widget_set_tooltip_text (shot_button,
@@ -3198,7 +3206,7 @@ set_defaults (SeekApp * app)
 
   app->need_streams = TRUE;
 
-  g_static_mutex_init (&app->state_mutex);
+  g_mutex_init (&app->state_mutex);
 
   app->play_rate = 1.0;
 }
@@ -3211,10 +3219,10 @@ reset_app (SeekApp * app)
 
   g_list_free (app->formats);
 
-  g_static_mutex_free (&app->state_mutex);
+  g_mutex_clear (&app->state_mutex);
 
-  if (app->xoverlay_element)
-    gst_object_unref (app->xoverlay_element);
+  if (app->overlay_element)
+    gst_object_unref (app->overlay_element);
   if (app->navigation_element)
     gst_object_unref (app->navigation_element);
 
@@ -3243,11 +3251,6 @@ main (int argc, char **argv)
 
   set_defaults (&app);
 
-#if !GLIB_CHECK_VERSION (2, 31, 0)
-  if (!g_thread_supported ())
-    g_thread_init (NULL);
-#endif
-
   ctx = g_option_context_new ("- test seeking in gsteamer");
   g_option_context_add_main_entries (ctx, options, NULL);
   g_option_context_add_group (ctx, gst_init_get_option_group ());
@@ -3324,7 +3327,7 @@ main (int argc, char **argv)
   g_assert (app.embed_xid != 0);
 
   if (app.pipeline_type == 0) {
-    gst_x_overlay_set_window_handle (GST_X_OVERLAY (app.pipeline),
+    gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (app.pipeline),
         app.embed_xid);
   }
 #endif