[GStreamer] Use RunLoop::Timer for ready state timer in MediaPlayerPrivateGStreamer
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Nov 2015 10:13:27 +0000 (10:13 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Nov 2015 10:13:27 +0000 (10:13 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150836

Reviewed by Philippe Normand.

We don't really need a GThreadSafeMainLoopSource for this simple timer.

* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer):
(WebCore::MediaPlayerPrivateGStreamer::~MediaPlayerPrivateGStreamer):
(WebCore::MediaPlayerPrivateGStreamer::readyTimerFired):
(WebCore::MediaPlayerPrivateGStreamer::changePipelineState):
(WebCore::MediaPlayerPrivateGStreamer::loadingFailed):
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@192019 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp
Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h

index b85b180472cd19770115be02ea976de9e30a0b0f..6123d59cf93b5ffa7012cb34809678fb23699144 100644 (file)
@@ -1,3 +1,20 @@
+2015-11-04  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GStreamer] Use RunLoop::Timer for ready state timer in MediaPlayerPrivateGStreamer
+        https://bugs.webkit.org/show_bug.cgi?id=150836
+
+        Reviewed by Philippe Normand.
+
+        We don't really need a GThreadSafeMainLoopSource for this simple timer.
+
+        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
+        (WebCore::MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer):
+        (WebCore::MediaPlayerPrivateGStreamer::~MediaPlayerPrivateGStreamer):
+        (WebCore::MediaPlayerPrivateGStreamer::readyTimerFired):
+        (WebCore::MediaPlayerPrivateGStreamer::changePipelineState):
+        (WebCore::MediaPlayerPrivateGStreamer::loadingFailed):
+        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h:
+
 2015-11-04  Frederic Wang  <fred.wang@free.fr>
 
         Add support for the USE_TYPO_METRICS flag on iOS
index 0a5670ce78c96380fd500b6fc39b84b5ab87d845..17b22a606f57bb855ef96de2bee3124ff6f49eb6 100644 (file)
@@ -41,7 +41,6 @@
 #include <limits>
 #include <wtf/HexNumber.h>
 #include <wtf/MediaTime.h>
-#include <wtf/RunLoop.h>
 #include <wtf/glib/GUniquePtr.h>
 #include <wtf/text/CString.h>
 
 #include "AudioSourceProviderGStreamer.h"
 #endif
 
-// Max interval in seconds to stay in the READY state on manual
-// state change requests.
-static const unsigned gReadyStateTimerInterval = 60;
-
 GST_DEBUG_CATEGORY_EXTERN(webkit_media_player_debug);
 #define GST_CAT_DEFAULT webkit_media_player_debug
 
@@ -202,6 +197,7 @@ MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer(MediaPlayer* player)
     , m_volumeAndMuteInitialized(false)
     , m_hasVideo(false)
     , m_hasAudio(false)
+    , m_readyTimerHandler(RunLoop::main(), this, &MediaPlayerPrivateGStreamer::readyTimerFired)
     , m_totalBytes(0)
     , m_preservesPitch(false)
 #if ENABLE(WEB_AUDIO)
@@ -209,6 +205,9 @@ MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer(MediaPlayer* player)
 #endif
     , m_requestedState(GST_STATE_VOID_PENDING)
 {
+#if USE(GLIB) && !PLATFORM(EFL)
+    m_readyTimerHandler.setPriority(G_PRIORITY_DEFAULT_IDLE);
+#endif
 }
 
 MediaPlayerPrivateGStreamer::~MediaPlayerPrivateGStreamer()
@@ -235,7 +234,7 @@ MediaPlayerPrivateGStreamer::~MediaPlayerPrivateGStreamer()
         g_signal_handlers_disconnect_by_func(G_OBJECT(m_autoAudioSink.get()),
             reinterpret_cast<gpointer>(setAudioStreamPropertiesCallback), this);
 
-    m_readyTimerHandler.cancel();
+    m_readyTimerHandler.stop();
     if (m_missingPluginsCallback) {
         m_missingPluginsCallback->invalidate();
         m_missingPluginsCallback = nullptr;
@@ -366,6 +365,11 @@ float MediaPlayerPrivateGStreamer::playbackPosition() const
     return result;
 }
 
+void MediaPlayerPrivateGStreamer::readyTimerFired()
+{
+    changePipelineState(GST_STATE_NULL);
+}
+
 bool MediaPlayerPrivateGStreamer::changePipelineState(GstState newState)
 {
     ASSERT(m_pipeline);
@@ -393,12 +397,13 @@ bool MediaPlayerPrivateGStreamer::changePipelineState(GstState newState)
     // if we stay for too long on READY.
     // Also lets remove the timer if we request a state change for any state other than READY.
     // See also https://bugs.webkit.org/show_bug.cgi?id=117354
-    if (newState == GST_STATE_READY && !m_readyTimerHandler.isScheduled()) {
-        m_readyTimerHandler.scheduleAfterDelay("[WebKit] mediaPlayerPrivateReadyStateTimeoutCallback", std::function<void()>([this] { changePipelineState(GST_STATE_NULL); }),
-            std::chrono::seconds(gReadyStateTimerInterval));
-    } else if (newState != GST_STATE_READY && m_readyTimerHandler.isScheduled()) {
-        m_readyTimerHandler.cancel();
-    }
+    if (newState == GST_STATE_READY && !m_readyTimerHandler.isActive()) {
+        // Max interval in seconds to stay in the READY state on manual
+        // state change requests.
+        static const double readyStateTimerDelay = 60;
+        m_readyTimerHandler.startOneShot(readyStateTimerDelay);
+    } else if (newState != GST_STATE_READY)
+        m_readyTimerHandler.stop();
 
     return true;
 }
@@ -1687,7 +1692,7 @@ void MediaPlayerPrivateGStreamer::loadingFailed(MediaPlayer::NetworkState error)
     }
 
     // Loading failed, remove ready timer.
-    m_readyTimerHandler.cancel();
+    m_readyTimerHandler.stop();
 }
 
 static HashSet<String> mimeTypeCache()
index 17913df275989c9334b683f2ce2ce4cca3ffd766..ae9abb7e2570c44477661f279b5f5b5b5903ac2c 100644 (file)
@@ -33,6 +33,7 @@
 #include <gst/gst.h>
 #include <gst/pbutils/install-plugins.h>
 #include <wtf/Forward.h>
+#include <wtf/RunLoop.h>
 #include <wtf/WeakPtr.h>
 #include <wtf/glib/GThreadSafeMainLoopSource.h>
 
@@ -188,6 +189,8 @@ private:
     MediaTime totalFrameDelay() override { return MediaTime::zeroTime(); }
 #endif
 
+    void readyTimerFired();
+
     WeakPtrFactory<MediaPlayerPrivateGStreamer> m_weakPtrFactory;
 
     GRefPtr<GstElement> m_source;
@@ -229,7 +232,7 @@ private:
     GThreadSafeMainLoopSource m_textTimerHandler;
     GThreadSafeMainLoopSource m_videoTimerHandler;
     GThreadSafeMainLoopSource m_videoCapsTimerHandler;
-    GThreadSafeMainLoopSource m_readyTimerHandler;
+    RunLoop::Timer<MediaPlayerPrivateGStreamer> m_readyTimerHandler;
     mutable unsigned long long m_totalBytes;
     URL m_url;
     bool m_preservesPitch;