kbrown / rpms / libreoffice

Forked from rpms/libreoffice 2 years ago
Clone

Blame SOURCES/0001-Resolves-tdf-96989-videos-playback-at-maximum-possib.patch

f325b2
From b09dbbfb58d67d1640709f71a7053a7ccea70cec Mon Sep 17 00:00:00 2001
f325b2
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
f325b2
Date: Thu, 17 Mar 2016 12:21:16 +0000
f325b2
Subject: [PATCH] Resolves: tdf#96989 videos playback at maximum possible
f325b2
 volume
f325b2
f325b2
On systems with flat-volumes then setting the volume directly on the playbin to
f325b2
100% results in resetting the global volume to the maximum possible volume.
f325b2
f325b2
We expect to set as % of the current system volume. Putting an intermediate
f325b2
volume object into the pipeline does the more expected thing.
f325b2
f325b2
(cherry picked from commit d4b48e0de7f817c0d4607382724778acf191f9f8)
f325b2
f325b2
Change-Id: I911d6fffba0983e4fd7b455e820959a96115de34
f325b2
---
f325b2
 avmedia/source/gstreamer/gstplayer.cxx | 90 ++++++++++++++++++++--------------
f325b2
 avmedia/source/gstreamer/gstplayer.hxx |  1 +
f325b2
 2 files changed, 54 insertions(+), 37 deletions(-)
f325b2
f325b2
diff --git a/avmedia/source/gstreamer/gstplayer.cxx b/avmedia/source/gstreamer/gstplayer.cxx
f325b2
index b820ae1..50f54ea 100644
f325b2
--- a/avmedia/source/gstreamer/gstplayer.cxx
f325b2
+++ b/avmedia/source/gstreamer/gstplayer.cxx
f325b2
@@ -131,7 +131,7 @@ void MissingPluginInstaller::report(
f325b2
 {
f325b2
     // assert(gst_is_missing_plugin_message(message));
f325b2
     gchar * det = gst_missing_plugin_message_get_installer_detail(message);
f325b2
-    if (det == nullptr) {
f325b2
+    if (det == NULL) {
f325b2
         SAL_WARN(
f325b2
             "avmedia.gstreamer",
f325b2
             "gst_missing_plugin_message_get_installer_detail failed");
f325b2
@@ -268,8 +268,8 @@ void MissingPluginInstallerThread::execute() {
f325b2
         for (auto const & i: details) {
f325b2
             args.push_back(const_cast<char *>(i.getStr()));
f325b2
         }
f325b2
-        args.push_back(nullptr);
f325b2
-        gst_install_plugins_sync(args.data(), nullptr);
f325b2
+        args.push_back(NULL);
f325b2
+        gst_install_plugins_sync(args.data(), NULL);
f325b2
         {
f325b2
             osl::MutexGuard g(inst.mutex_);
f325b2
             if (inst.queued_.empty() || inst.launchNewThread_) {
f325b2
@@ -290,6 +290,7 @@ Player::Player( const uno::Reference< lang::XMultiServiceFactory >& rxMgr ) :
f325b2
     GstPlayer_BASE( m_aMutex ),
f325b2
     mxMgr( rxMgr ),
f325b2
     mpPlaybin( NULL ),
f325b2
+    mpVolumeControl( NULL ),
f325b2
     mbFakeVideo (false ),
f325b2
     mnUnmutedVolume( 0 ),
f325b2
     mbPlayPending ( false ),
f325b2
@@ -351,6 +352,7 @@ void SAL_CALL Player::disposing()
f325b2
             g_object_unref( G_OBJECT( mpPlaybin ) );
f325b2
 
f325b2
             mpPlaybin = NULL;
f325b2
+            mpVolumeControl = NULL;
f325b2
         }
f325b2
 
f325b2
         if( mpXOverlay ) {
f325b2
@@ -576,41 +578,55 @@ GstBusSyncReply Player::processSyncMessage( GstMessage *message )
f325b2
 
f325b2
 void Player::preparePlaybin( const OUString& rURL, GstElement *pSink )
f325b2
 {
f325b2
-        GstBus *pBus;
f325b2
+    GstBus *pBus;
f325b2
 
f325b2
-        if( mpPlaybin != NULL ) {
f325b2
-            gst_element_set_state( mpPlaybin, GST_STATE_NULL );
f325b2
-            mbPlayPending = false;
f325b2
-            g_object_unref( mpPlaybin );
f325b2
-        }
f325b2
+    if( mpPlaybin != NULL ) {
f325b2
+        gst_element_set_state( mpPlaybin, GST_STATE_NULL );
f325b2
+        mbPlayPending = false;
f325b2
+        g_object_unref( mpPlaybin );
f325b2
+    }
f325b2
 
f325b2
-        mpPlaybin = gst_element_factory_make( "playbin", NULL );
f325b2
-        if( pSink != NULL ) // used for getting preferred size etc.
f325b2
-        {
f325b2
-            g_object_set( G_OBJECT( mpPlaybin ), "video-sink", pSink, NULL );
f325b2
-            mbFakeVideo = true;
f325b2
-        }
f325b2
-        else
f325b2
-            mbFakeVideo = false;
f325b2
+    mpPlaybin = gst_element_factory_make( "playbin", NULL );
f325b2
+
f325b2
+    //tdf#96989 on systems with flat-volumes setting the volume directly on the
f325b2
+    //playbin to 100% results in setting the global volums to 100% of the
f325b2
+    //maximum. We expect to set as % of the current volume.
f325b2
+    mpVolumeControl = gst_element_factory_make( "volume", NULL );
f325b2
+    GstElement *pAudioSink = gst_element_factory_make( "autoaudiosink", NULL );
f325b2
+    GstElement* pAudioOutput = gst_bin_new("audio-output-bin");
f325b2
+    gst_bin_add_many(GST_BIN(pAudioOutput), mpVolumeControl, pAudioSink, NULL);
f325b2
+    gst_element_link(mpVolumeControl, pAudioSink);
f325b2
+    GstPad *pPad = gst_element_get_static_pad(mpVolumeControl, "sink");
f325b2
+    gst_element_add_pad(GST_ELEMENT(pAudioOutput), gst_ghost_pad_new("sink", pPad));
f325b2
+    gst_object_unref(GST_OBJECT(pPad));
f325b2
+    g_object_set(G_OBJECT(mpPlaybin), "audio-sink", pAudioOutput, NULL);
f325b2
+
f325b2
+    if( pSink != NULL ) // used for getting preferred size etc.
f325b2
+    {
f325b2
+        g_object_set( G_OBJECT( mpPlaybin ), "video-sink", pSink, NULL );
f325b2
+        mbFakeVideo = true;
f325b2
+    }
f325b2
+    else
f325b2
+        mbFakeVideo = false;
f325b2
 
f325b2
-        OString ascURL = OUStringToOString( rURL, RTL_TEXTENCODING_UTF8 );
f325b2
-        g_object_set( G_OBJECT( mpPlaybin ), "uri", ascURL.getStr() , NULL );
f325b2
+    OString ascURL = OUStringToOString( rURL, RTL_TEXTENCODING_UTF8 );
f325b2
+    g_object_set( G_OBJECT( mpPlaybin ), "uri", ascURL.getStr() , NULL );
f325b2
 
f325b2
-        pBus = gst_element_get_bus( mpPlaybin );
f325b2
-        if (mbWatchID)
f325b2
-        {
f325b2
-            g_source_remove(mnWatchID);
f325b2
-            mbWatchID = false;
f325b2
-        }
f325b2
-        mnWatchID = gst_bus_add_watch( pBus, pipeline_bus_callback, this );
f325b2
-        mbWatchID = true;
f325b2
-        DBG( "%p set sync handler", this );
f325b2
+    pBus = gst_element_get_bus( mpPlaybin );
f325b2
+    if (mbWatchID)
f325b2
+    {
f325b2
+        g_source_remove(mnWatchID);
f325b2
+        mbWatchID = false;
f325b2
+    }
f325b2
+    mnWatchID = gst_bus_add_watch( pBus, pipeline_bus_callback, this );
f325b2
+    mbWatchID = true;
f325b2
+    DBG( "%p set sync handler", this );
f325b2
 #ifdef AVMEDIA_GST_0_10
f325b2
-        gst_bus_set_sync_handler( pBus, pipeline_bus_sync_handler, this );
f325b2
+    gst_bus_set_sync_handler( pBus, pipeline_bus_sync_handler, this );
f325b2
 #else
f325b2
-        gst_bus_set_sync_handler( pBus, pipeline_bus_sync_handler, this, NULL );
f325b2
+    gst_bus_set_sync_handler( pBus, pipeline_bus_sync_handler, this, NULL );
f325b2
 #endif
f325b2
-        g_object_unref( pBus );
f325b2
+    g_object_unref( pBus );
f325b2
 }
f325b2
 
f325b2
 bool Player::create( const OUString& rURL )
f325b2
@@ -784,7 +800,7 @@ void SAL_CALL Player::setMute( sal_Bool bSet )
f325b2
             nVolume = 0.0;
f325b2
         }
f325b2
 
f325b2
-        g_object_set( G_OBJECT( mpPlaybin ), "volume", nVolume, NULL );
f325b2
+        g_object_set( G_OBJECT( mpVolumeControl ), "volume", nVolume, NULL);
f325b2
 
f325b2
         mbMuted = bSet;
f325b2
     }
f325b2
@@ -812,10 +828,10 @@ void SAL_CALL Player::setVolumeDB( sal_Int16 nVolumeDB )
f325b2
     DBG( "set volume: %d gst volume: %lf", nVolumeDB, mnUnmutedVolume );
f325b2
 
f325b2
     // change volume
f325b2
-     if( !mbMuted && mpPlaybin )
f325b2
-     {
f325b2
-         g_object_set( G_OBJECT( mpPlaybin ), "volume", (gdouble) mnUnmutedVolume, NULL );
f325b2
-     }
f325b2
+    if( !mbMuted && mpPlaybin )
f325b2
+    {
f325b2
+        g_object_set( G_OBJECT( mpVolumeControl ), "volume", mnUnmutedVolume, NULL );
f325b2
+    }
f325b2
 }
f325b2
 
f325b2
 
f325b2
@@ -830,7 +846,7 @@ sal_Int16 SAL_CALL Player::getVolumeDB()
f325b2
     if( mpPlaybin ) {
f325b2
         double nGstVolume = 0.0;
f325b2
 
f325b2
-        g_object_get( G_OBJECT( mpPlaybin ), "volume", &nGstVolume, NULL );
f325b2
+        g_object_get( G_OBJECT( mpVolumeControl ), "volume", &nGstVolume, NULL );
f325b2
 
f325b2
         nVolumeDB = (sal_Int16) ( 20.0*log10 ( nGstVolume ) );
f325b2
     }
f325b2
diff --git a/avmedia/source/gstreamer/gstplayer.hxx b/avmedia/source/gstreamer/gstplayer.hxx
f325b2
index c5fc4f6..ed60e79 100644
f325b2
--- a/avmedia/source/gstreamer/gstplayer.hxx
f325b2
+++ b/avmedia/source/gstreamer/gstplayer.hxx
f325b2
@@ -83,6 +83,7 @@ protected:
f325b2
 
f325b2
     // Add elements and pipeline here
f325b2
     GstElement*             mpPlaybin;  // the playbin is also a pipeline
f325b2
+    GstElement*             mpVolumeControl;  // the playbin is also a pipeline
f325b2
     bool                mbFakeVideo;
f325b2
 
f325b2
     gdouble                 mnUnmutedVolume;
f325b2
-- 
f325b2
2.7.1
f325b2