>From f903ab7baef01f170e9931db60f60e93068e1984 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dan=20Hor=C3=A1k?= <dan@danny.cz>
Date: Wed, 17 Oct 2012 18:23:24 +0200
Subject: [PATCH] initial port to gstreamer 1.0

---
 configure.ac.in          |   32 +++++++++++++++---
 src/gst/parole-gst.c     |   81 ++++++++++++++++++++++++++++++++++++++++++++--
 src/parole-conf-dialog.c |   12 +++++++
 src/parole-vis.c         |    4 ++
 4 files changed, 121 insertions(+), 8 deletions(-)

diff --git a/configure.ac.in b/configure.ac.in
index 40bdb1e..237ad70 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -75,12 +75,32 @@ AC_CHECK_HEADERS([errno.h signal.h stddef.h sys/ioctl.h fcntl.h\
 
 XDT_I18N([@LINGUAS@])
 
+dnl gstreamer version
+AC_ARG_WITH([gstreamer],
+            [AS_HELP_STRING([--with-gstreamer=0.10|1.0],[which gstreamer version to compile against (default: 0.10)])],
+            [case "$with_gstreamer" in
+                0.10|1.0) ;;
+                *) AC_MSG_ERROR([invalid gstreamer version specified]) ;;
+             esac],
+            [with_gstreamer=0.10]
+)
+
+case "$with_gstreamer" in
+  0.10) gstreamer_api_version=0.10
+       gstreamer_minimum_version=0.10.31
+       ;;
+  1.0) gstreamer_api_version=1.0
+       gstreamer_minimum_version=0.11.90
+       ;;
+esac
+AC_DEFINE_UNQUOTED(GSTREAMER_API_VERSION, $gstreamer_api_version, [Define the GStreamer+ API version])
+
 #==================================================== #
 #          Check for required packages 		      #
 #=====================================================#
 m4_define([gtk_minimum_version], [2.20.0])
 m4_define([glib_minimum_version], [2.32.0])
-m4_define([gstreamer_minimum_version], [0.10.24])
+#m4_define([gstreamer_minimum_version], [0.10.24])
 
 m4_define([dbus_minimum_version], [0.60])
 m4_define([dbus_glib_minimum_version], [0.70])
@@ -97,10 +117,12 @@ XDT_CHECK_PACKAGE([GTHREAD], [gthread-2.0], [glib_minimum_version])
 XDT_CHECK_PACKAGE([GMODULE], [gmodule-2.0], [glib_minimum_version])
 XDT_CHECK_PACKAGE([GIO], [gio-2.0], [glib_minimum_version])
 
-XDT_CHECK_PACKAGE([GST], [gstreamer-0.10], [gstreamer_minimum_version])
-XDT_CHECK_PACKAGE([GST_BASE], [gstreamer-base-0.10], [gstreamer_minimum_version])
-XDT_CHECK_PACKAGE([GST_VIDEO], [gstreamer-video-0.10], [gstreamer_minimum_version])
-XDT_CHECK_PACKAGE([GST_INTERFACES], [gstreamer-interfaces-0.10], [gstreamer_minimum_version])
+XDT_CHECK_PACKAGE([GST], [gstreamer-${gstreamer_api_version}], [gstreamer_minimum_version])
+XDT_CHECK_PACKAGE([GST_BASE], [gstreamer-base-${gstreamer_api_version}], [gstreamer_minimum_version])
+XDT_CHECK_PACKAGE([GST_VIDEO], [gstreamer-video-${gstreamer_api_version}], [gstreamer_minimum_version])
+if test x"${gstreamer_api_version}" = x"0.10"; then
+    XDT_CHECK_PACKAGE([GST_INTERFACES], [gstreamer-interfaces-${gstreamer_api_version}], [gstreamer_minimum_version])
+fi
 
 XDT_CHECK_PACKAGE([DBUS], [dbus-1], [dbus_minimum_version])
 XDT_CHECK_PACKAGE([DBUS_GLIB], [dbus-glib-1], [dbus_glib_minimum_version])
diff --git a/src/gst/parole-gst.c b/src/gst/parole-gst.c
index ef1a3a8..1dcef89 100644
--- a/src/gst/parole-gst.c
+++ b/src/gst/parole-gst.c
@@ -28,8 +28,15 @@
 
 #include <glib.h>
 
+#include "parole-gst.h"
+
+#if GST_CHECK_VERSION(1, 0, 0)
+#include <gst/video/videooverlay.h>
+#include <gst/video/navigation.h>
+#else
 #include <gst/interfaces/xoverlay.h>
 #include <gst/interfaces/navigation.h>
+#endif
 
 #include <gst/video/video.h>
 
@@ -38,8 +45,6 @@
 
 #include <gdk/gdkx.h>
 
-#include "parole-gst.h"
-
 #include "common/parole-common.h"
 #include "common/parole-rc-utils.h"
 
@@ -491,8 +496,13 @@ parole_gst_set_x_overlay (ParoleGst *gst)
     g_assert (video_sink != NULL);
     
     if ( GDK_IS_WINDOW (GTK_WIDGET (gst)->window) )
+#if GST_CHECK_VERSION(1, 0, 0)
+	gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (video_sink),
+				      GDK_WINDOW_XID (GTK_WIDGET (gst)->window));
+#else
 	gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (video_sink),
 				      GDK_WINDOW_XWINDOW (GTK_WIDGET (gst)->window));
+#endif
     
     gst_object_unref (video_sink);
     
@@ -523,14 +533,22 @@ parole_gst_expose_event (GtkWidget *widget, GdkEventExpose *ev)
 	case GST_STATE_PLAYING:
 	    if ( playing_video || gst->priv->vis_loaded)
 	    {
+#if GST_CHECK_VERSION(1, 0, 0)
+		gst_video_overlay_expose (GST_VIDEO_OVERLAY (gst->priv->video_sink));
+#else
 		gst_x_overlay_expose (GST_X_OVERLAY (gst->priv->video_sink));
+#endif
 	    }
 	    else
 		parole_gst_draw_logo (gst);
 	    break;
 	case GST_STATE_PAUSED:
 	    if ( playing_video || gst->priv->vis_loaded || gst->priv->target == GST_STATE_PLAYING )
+#if GST_CHECK_VERSION(1, 0, 0)
+		gst_video_overlay_expose (GST_VIDEO_OVERLAY (gst->priv->video_sink));
+#else
 		gst_x_overlay_expose (GST_X_OVERLAY (gst->priv->video_sink));
+#endif
 	    else
 		parole_gst_draw_logo (gst);
 	    break;
@@ -538,7 +556,11 @@ parole_gst_expose_event (GtkWidget *widget, GdkEventExpose *ev)
 	    if (gst->priv->target != GST_STATE_PLAYING)
 		parole_gst_draw_logo (gst);
 	    else
+#if GST_CHECK_VERSION(1, 0, 0)
+		gst_video_overlay_expose (GST_VIDEO_OVERLAY (gst->priv->video_sink));
+#else
 		gst_x_overlay_expose (GST_X_OVERLAY (gst->priv->video_sink));
+#endif
 	    break;
 	case GST_STATE_NULL:
 	case GST_STATE_VOID_PENDING:
@@ -604,7 +626,11 @@ parole_gst_tick_timeout (gpointer data)
 		  "duration", &duration,
 		  NULL);
     
+#if GST_CHECK_VERSION(1, 0, 0)
+    gst_element_query_position (gst->priv->playbin, format, &pos);
+#else
     gst_element_query_position (gst->priv->playbin, &format, &pos);
+#endif
     
     if ( G_UNLIKELY (format != GST_FORMAT_TIME ) )
 	goto out;
@@ -664,7 +690,11 @@ parole_gst_query_duration (ParoleGst *gst)
     gst_time = GST_FORMAT_TIME;
     
     gst_element_query_duration (gst->priv->playbin, 
+#if GST_CHECK_VERSION(1, 0, 0)
+				gst_time,
+#else
 				&gst_time,
+#endif
 				&absolute_duration);
     
     if (gst_time == GST_FORMAT_TIME)
@@ -759,7 +789,11 @@ parole_gst_load_subtitle (ParoleGst *gst)
 static void
 parole_gst_get_pad_capabilities (GObject *object, GParamSpec *pspec, ParoleGst *gst)
 {
+#if GST_CHECK_VERSION(1, 0, 0)
+    GstCaps *caps;
+#else
     GstPad *pad;
+#endif
     GstStructure *st;
     gint width;
     gint height;
@@ -767,12 +801,21 @@ parole_gst_get_pad_capabilities (GObject *object, GParamSpec *pspec, ParoleGst *
     guint den;
     const GValue *value;
     
+#if GST_CHECK_VERSION(1, 0, 0)
+    caps = GST_CAPS (object);
+    
+    if ( !GST_IS_CAPS (caps) || !GST_CAPS (caps) )
+	return;
+    
+    st = gst_caps_get_structure (GST_CAPS (caps), 0);
+#else
     pad = GST_PAD (object);
     
     if ( !GST_IS_PAD (pad) || !GST_PAD_CAPS (pad) )
 	return;
     
     st = gst_caps_get_structure (GST_PAD_CAPS (pad), 0);
+#endif
     
     if ( st )
     {
@@ -825,7 +868,11 @@ parole_gst_query_info (ParoleGst *gst)
 	{
 	    GstCaps *caps;
 	    
+#if GST_CHECK_VERSION(1, 0, 0)
+	    if ((caps = gst_pad_get_current_caps (videopad)))
+#else
 	    if ((caps = gst_pad_get_negotiated_caps (videopad)))
+#endif
 	    {
 		parole_gst_get_pad_capabilities (G_OBJECT (videopad), NULL, gst);
 		gst_caps_unref (caps);
@@ -985,10 +1032,18 @@ parole_gst_evaluate_state (ParoleGst *gst, GstState old, GstState new, GstState
 static void
 parole_gst_element_message_sync (GstBus *bus, GstMessage *message, ParoleGst *gst)
 {
+#if GST_CHECK_VERSION(1, 0, 0)
+    if ( !(gst_message_get_structure(message)) )
+#else
     if ( !message->structure )
+#endif
 	goto out;
 	
+#if GST_CHECK_VERSION(1, 0, 0)
+    if ( gst_structure_has_name (gst_message_get_structure(message), "prepare-xwindow-id") )
+#else
     if ( gst_structure_has_name (message->structure, "prepare-xwindow-id") )
+#endif
 	parole_gst_set_x_overlay (gst);
 out:
     ;
@@ -1102,7 +1157,11 @@ parole_gst_application_message (ParoleGst *gst, GstMessage *msg)
 {
     const gchar *name;
 
+#if GST_CHECK_VERSION(1, 0, 0)
+    name = gst_structure_get_name (gst_message_get_structure(msg));
+#else
     name = gst_structure_get_name (msg->structure);
+#endif
     
     if ( !name )
 	return;
@@ -1429,7 +1488,11 @@ parole_gst_seek_by_format (ParoleGst *gst, GstFormat format, gint step)
 {
     gint64 val = 1;
     
+#if GST_CHECK_VERSION(1, 0, 0)
+    if ( gst_element_query_position (gst->priv->playbin, format, &val) )
+#else
     if ( gst_element_query_position (gst->priv->playbin, &format, &val) )
+#endif
     {
 	val += step;
 	if ( !gst_element_seek (gst->priv->playbin, 1.0, format, 
@@ -1711,7 +1774,11 @@ parole_gst_constructed (GObject *object)
      * Handling 'prepare-xwindow-id' message async causes XSync 
      * error in some occasions So we handle this message synchronously
      */
-    gst_bus_set_sync_handler (gst->priv->bus, gst_bus_sync_signal_handler, gst);
+    gst_bus_set_sync_handler (gst->priv->bus, gst_bus_sync_signal_handler, gst
+#if GST_CHECK_VERSION (1, 0, 0)
+				, NULL
+#endif
+				);
     gst->priv->sig2 =
 	g_signal_connect (gst->priv->bus, "sync-message::element",
 			  G_CALLBACK (parole_gst_element_message_sync), gst);
@@ -2164,7 +2231,11 @@ gint parole_gst_get_current_cdda_track (ParoleGst *gst)
     
     format = gst_format_get_by_nick ("track");
     
+#if GST_CHECK_VERSION(1, 0, 0)
+    if ( gst_element_query_position (gst->priv->playbin, format, &pos) )
+#else
     if ( gst_element_query_position (gst->priv->playbin, &format, &pos) )
+#endif
     {
 	TRACE ("Pos %" G_GINT64_FORMAT, pos);
 	ret_val = (gint) pos;
@@ -2188,7 +2259,11 @@ gint64 parole_gst_get_stream_position (ParoleGst *gst)
     GstFormat format = GST_FORMAT_TIME;
     gint64 pos;
     
+#if GST_CHECK_VERSION(1, 0, 0)
+    gst_element_query_position (gst->priv->playbin, format, &pos);
+#else
     gst_element_query_position (gst->priv->playbin, &format, &pos);
+#endif
     
     return  pos / GST_SECOND;
 }
diff --git a/src/parole-conf-dialog.c b/src/parole-conf-dialog.c
index 3158cb1..23cb1c9 100644
--- a/src/parole-conf-dialog.c
+++ b/src/parole-conf-dialog.c
@@ -243,7 +243,11 @@ void parole_conf_dialog_vis_plugin_changed_cb (GtkComboBox *widget,  ParoleConfD
     if ( f )
     {
 	g_object_set (G_OBJECT (self->priv->conf),
+#if GST_CHECK_VERSION (1, 0, 0)
+		      "vis-name", GST_OBJECT_NAME (f),
+#else
 		      "vis-name", GST_PLUGIN_FEATURE_NAME (f),
+#endif
 		      NULL);
     }
     
@@ -334,10 +338,18 @@ parole_conf_dialog_set_default_vis_plugin (GtkTreeModel *model, GtkTreePath *pat
     
     if ( !g_strcmp0 (vis_name, "none") )
     {
+#if GST_CHECK_VERSION (1, 0, 0)
+	if ( !g_strcmp0 (GST_OBJECT_NAME (f), "Goom") )
+#else
 	if ( !g_strcmp0 (GST_PLUGIN_FEATURE_NAME (f), "Goom") )
+#endif
 	    ret = TRUE;
     }
+#if GST_CHECK_VERSION (1, 0, 0)
+    else if ( !g_strcmp0 (GST_OBJECT_NAME (f), vis_name) )
+#else
     else if ( !g_strcmp0 (GST_PLUGIN_FEATURE_NAME (f), vis_name) )
+#endif
     {
 	ret = TRUE;
     }
diff --git a/src/parole-vis.c b/src/parole-vis.c
index 5f0648b..ebec66e 100644
--- a/src/parole-vis.c
+++ b/src/parole-vis.c
@@ -60,7 +60,11 @@ GHashTable *parole_vis_get_plugins (void)
     
     hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
     
+#if GST_CHECK_VERSION (1, 0, 0)
+    plugins = gst_registry_feature_filter (gst_registry_get (),
+#else
     plugins = gst_registry_feature_filter (gst_registry_get_default (),
+#endif
 					   parole_vis_filter,
 					   FALSE,
 					   NULL);
-- 
1.7.7.6

