e4c4141
From 90b9271771927a72dc27e71957376dd67c8f6d43 Mon Sep 17 00:00:00 2001
e4c4141
From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= <tim.muller@collabora.co.uk>
e4c4141
Date: Sun, 29 Jul 2012 19:14:05 +0200
e4c4141
Subject: [PATCH 1/7] tentative initial attempt at re-work for new playbin
e4c4141
e4c4141
Change-Id: I257bdda8469be624d0cbeab21cff2c2e1c94cc6f
e4c4141
Signed-off-by: David Tardon <dtardon@redhat.com>
e4c4141
---
e4c4141
 avmedia/source/gstreamer/gstplayer.cxx | 94 ++++++++++++++++++++++++++--------
e4c4141
 1 file changed, 74 insertions(+), 20 deletions(-)
e4c4141
e4c4141
diff --git a/avmedia/source/gstreamer/gstplayer.cxx b/avmedia/source/gstreamer/gstplayer.cxx
e4c4141
index 863d1e8..d95342a 100644
e4c4141
--- a/avmedia/source/gstreamer/gstplayer.cxx
e4c4141
+++ b/avmedia/source/gstreamer/gstplayer.cxx
e4c4141
@@ -38,7 +38,9 @@
e4c4141
 #include "gstframegrabber.hxx"
e4c4141
 #include "gstwindow.hxx"
e4c4141
 
e4c4141
-#include <gst/interfaces/xoverlay.h>
e4c4141
+#ifndef AVMEDIA_GST_0_10
e4c4141
+#  include <gst/video/videooverlay.h>
e4c4141
+#endif
e4c4141
 
e4c4141
 #define AVMEDIA_GST_PLAYER_IMPLEMENTATIONNAME "com.sun.star.comp.avmedia.Player_GStreamer"
e4c4141
 #define AVMEDIA_GST_PLAYER_SERVICENAME "com.sun.star.media.Player_GStreamer"
e4c4141
@@ -96,7 +98,7 @@ Player::~Player()
e4c4141
         if( mpPlaybin )
e4c4141
         {
e4c4141
             gst_element_set_state( mpPlaybin, GST_STATE_NULL );
e4c4141
-            gst_object_unref( GST_OBJECT( mpPlaybin ) );
e4c4141
+            g_object_unref( G_OBJECT( mpPlaybin ) );
e4c4141
 
e4c4141
             mpPlaybin = NULL;
e4c4141
         }
e4c4141
@@ -110,7 +112,7 @@ Player::~Player()
e4c4141
 
e4c4141
 // ------------------------------------------------------------------------------
e4c4141
 
e4c4141
-static gboolean gst_pipeline_bus_callback( GstBus *, GstMessage *message, gpointer data )
e4c4141
+static gboolean pipeline_bus_callback( GstBus *, GstMessage *message, gpointer data )
e4c4141
 {
e4c4141
     Player* pPlayer = static_cast<Player*>(data);
e4c4141
 
e4c4141
@@ -119,7 +121,7 @@ static gboolean gst_pipeline_bus_callback( GstBus *, GstMessage *message, gpoint
e4c4141
     return TRUE;
e4c4141
 }
e4c4141
 
e4c4141
-static GstBusSyncReply gst_pipeline_bus_sync_handler( GstBus *, GstMessage * message, gpointer data )
e4c4141
+static GstBusSyncReply pipeline_bus_sync_handler( GstBus *, GstMessage * message, gpointer data )
e4c4141
 {
e4c4141
     Player* pPlayer = static_cast<Player*>(data);
e4c4141
 
e4c4141
@@ -144,7 +146,7 @@ void Player::processMessage( GstMessage *message )
e4c4141
             if( newstate == GST_STATE_PAUSED &&
e4c4141
                 pendingstate == GST_STATE_VOID_PENDING &&
e4c4141
                 mpXOverlay )
e4c4141
-                gst_x_overlay_expose( mpXOverlay );
e4c4141
+                gst_video_overlay_expose( mpXOverlay );
e4c4141
 
e4c4141
         if (mbPlayPending)
e4c4141
             mbPlayPending = ((newstate == GST_STATE_READY) || (newstate == GST_STATE_PAUSED));
e4c4141
@@ -154,6 +156,26 @@ void Player::processMessage( GstMessage *message )
e4c4141
     }
e4c4141
 }
e4c4141
 
e4c4141
+static gboolean wrap_element_query_position (GstElement *element, GstFormat format, gint64 *cur)
e4c4141
+{
e4c4141
+#ifdef AVMEDIA_GST_0_10
e4c4141
+    GstFormat my_format = format;
e4c4141
+    return gst_element_query_position( mpPlaybin, &my_format, cur) && my_format == format && *cur > 0L;
e4c4141
+#else
e4c4141
+    return gst_element_query_position( element, format, cur );
e4c4141
+#endif
e4c4141
+}
e4c4141
+
e4c4141
+static gboolean wrap_element_query_duration (GstElement *element, GstFormat format, gint64 *duration)
e4c4141
+{
e4c4141
+#ifdef AVMEDIA_GST_0_10
e4c4141
+    GstFormat my_format = format;
e4c4141
+    return gst_element_query_duration( mpPlaybin, &my_format, duration) && my_format == format && *duration > 0L;
e4c4141
+#else
e4c4141
+    return gst_element_query_duration( element, format, duration );
e4c4141
+#endif
e4c4141
+}
e4c4141
+
e4c4141
 GstBusSyncReply Player::processSyncMessage( GstMessage *message )
e4c4141
 {
e4c4141
     DBG( "%p processSyncMessage: %s", this, GST_MESSAGE_TYPE_NAME( message ) );
e4c4141
@@ -169,17 +191,17 @@ GstBusSyncReply Player::processSyncMessage( GstMessage *message )
e4c4141
     }
e4c4141
 #endif
e4c4141
 
e4c4141
-    if (message->structure) {
e4c4141
-        if( !strcmp( gst_structure_get_name( message->structure ), "prepare-xwindow-id" ) && mnWindowID != 0 ) {
e4c4141
-            if( mpXOverlay )
e4c4141
-                g_object_unref( G_OBJECT ( mpXOverlay ) );
e4c4141
-            mpXOverlay = GST_X_OVERLAY( GST_MESSAGE_SRC( message ) );
e4c4141
-            g_object_ref( G_OBJECT ( mpXOverlay ) );
e4c4141
-            gst_x_overlay_set_xwindow_id( mpXOverlay, mnWindowID );
e4c4141
-            return GST_BUS_DROP;
e4c4141
-        }
e4c4141
+    if (gst_message_has_name (message, "prepare-xwindow-id") && mnWindowID != 0 )
e4c4141
+    {
e4c4141
+        if( mpXOverlay )
e4c4141
+            g_object_unref( G_OBJECT ( mpXOverlay ) );
e4c4141
+        mpXOverlay = GST_VIDEO_OVERLAY( GST_MESSAGE_SRC( message ) );
e4c4141
+        g_object_ref( G_OBJECT ( mpXOverlay ) );
e4c4141
+        gst_video_overlay_set_window_handle( mpXOverlay, mnWindowID );
e4c4141
+        return GST_BUS_DROP;
e4c4141
     }
e4c4141
 
e4c4141
+#ifdef AVMEDIA_GST_0_10
e4c4141
     if( GST_MESSAGE_TYPE( message ) == GST_MESSAGE_STATE_CHANGED ) {
e4c4141
         if( message->src == GST_OBJECT( mpPlaybin ) ) {
e4c4141
             GstState newstate, pendingstate;
e4c4141
@@ -193,10 +215,8 @@ GstBusSyncReply Player::processSyncMessage( GstMessage *message )
e4c4141
                 DBG( "%p change to paused received", this );
e4c4141
 
e4c4141
                 if( mnDuration == 0) {
e4c4141
-                    GstFormat format = GST_FORMAT_TIME;
e4c4141
                     gint64 gst_duration = 0L;
e4c4141
-
e4c4141
-                    if( gst_element_query_duration( mpPlaybin, &format, &gst_duration) && format == GST_FORMAT_TIME && gst_duration > 0L )
e4c4141
+                    if( wrap_element_query_duration( mpPlaybin, GST_FORMAT_TIME, &gst_duration) )
e4c4141
                         mnDuration = gst_duration;
e4c4141
                 }
e4c4141
 
e4c4141
@@ -234,6 +254,40 @@ GstBusSyncReply Player::processSyncMessage( GstMessage *message )
e4c4141
                 }
e4c4141
             }
e4c4141
         }
e4c4141
+#else
e4c4141
+    // We get to use the exciting new playbin2 ! (now known as playbin)
e4c4141
+    if( GST_MESSAGE_TYPE( message ) == GST_MESSAGE_ASYNC_DONE ) {
e4c4141
+        if( mnDuration == 0) {
e4c4141
+            gint64 gst_duration = 0L;
e4c4141
+            if( wrap_element_query_duration( mpPlaybin, GST_FORMAT_TIME, &gst_duration) )
e4c4141
+                mnDuration = gst_duration;
e4c4141
+        }
e4c4141
+        if( mnWidth == 0 ) {
e4c4141
+            GstPad *pad = NULL;
e4c4141
+            GstCaps *caps;
e4c4141
+
e4c4141
+            g_signal_emit_by_name( mpPlaybin, "get-video-pad", 0, &pad );
e4c4141
+
e4c4141
+            if( pad ) {
e4c4141
+                int w = 0, h = 0;
e4c4141
+
e4c4141
+                caps = gst_pad_get_current_caps( pad );
e4c4141
+
e4c4141
+                if( gst_structure_get( gst_caps_get_structure (caps, 0),
e4c4141
+                                       "width", G_TYPE_INT, &w,
e4c4141
+                                       "height", G_TYPE_INT, &h,
e4c4141
+                                       NULL ) ) {
e4c4141
+                    mnWidth = w;
e4c4141
+                    mnHeight = h;
e4c4141
+
e4c4141
+                    DBG( "queried size: %d x %d", mnWidth, mnHeight );
e4c4141
+
e4c4141
+                    maSizeCondition.set();
e4c4141
+                }
e4c4141
+                gst_caps_unref( caps );
e4c4141
+            }
e4c4141
+        }
e4c4141
+#endif
e4c4141
     } else if( GST_MESSAGE_TYPE( message ) == GST_MESSAGE_ERROR ) {
e4c4141
         if( mnWidth == 0 ) {
e4c4141
             // an error occurred, set condition so that OOo thread doesn't wait for us
e4c4141
@@ -265,9 +319,9 @@ void Player::preparePlaybin( const ::rtl::OUString& rURL, bool bFakeVideo )
e4c4141
         g_object_set( G_OBJECT( mpPlaybin ), "uri", ascURL.getStr() , NULL );
e4c4141
 
e4c4141
         pBus = gst_element_get_bus( mpPlaybin );
e4c4141
-        gst_bus_add_watch( pBus, gst_pipeline_bus_callback, this );
e4c4141
+        gst_bus_add_watch( pBus, pipeline_bus_callback, this );
e4c4141
         DBG( "%p set sync handler", this );
e4c4141
-        gst_bus_set_sync_handler( pBus, gst_pipeline_bus_sync_handler, this );
e4c4141
+        gst_bus_set_sync_handler( pBus, pipeline_bus_sync_handler, this );
e4c4141
         g_object_unref( pBus );
e4c4141
 }
e4c4141
 
e4c4141
@@ -387,7 +441,7 @@ double SAL_CALL Player::getMediaTime(  )
e4c4141
         // get current position in the stream
e4c4141
         GstFormat format = GST_FORMAT_TIME;
e4c4141
         gint64 gst_position;
e4c4141
-        if( gst_element_query_position( mpPlaybin, &format, &gst_position ) && format == GST_FORMAT_TIME && gst_position > 0L )
e4c4141
+        if( wrap_element_query_position( mpPlaybin, GST_FORMAT_TIME, &gst_position ) )
e4c4141
             position = gst_position / 1E9;
e4c4141
     }
e4c4141
 
e4c4141
-- 
e4c4141
1.7.11.4
e4c4141