Title: [202857] trunk/Source/WebCore
Revision
202857
Author
[email protected]
Date
2016-07-06 06:27:40 -0700 (Wed, 06 Jul 2016)

Log Message

[GStreamer] duration query improvements
https://bugs.webkit.org/show_bug.cgi?id=159458

Reviewed by Carlos Garcia Campos.

Currently the player caches the result of the duration query but
this is overkill because it's cached by playbin already. The only
time where the player needs to cache the duration is when EOS was
reached because in that situation the query would fail.

No new tests, existing media tests cover this patch.

* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer): Member variables update.
(WebCore::MediaPlayerPrivateGStreamer::load): Stop the fill timer
before loading a new URL, the same player can be used for
different assets.
(WebCore::MediaPlayerPrivateGStreamer::playbackPosition): Perform
a duration query, the duration value is no longer locally cached.
(WebCore::MediaPlayerPrivateGStreamer::duration): Return cached value only after EOS was reached.
(WebCore::MediaPlayerPrivateGStreamer::fillTimerFired): Perform
a duration query, the duration value is no longer locally cached.
(WebCore::MediaPlayerPrivateGStreamer::maxTimeSeekable): Ditto.
(WebCore::MediaPlayerPrivateGStreamer::maxTimeLoaded): Ditto.
(WebCore::MediaPlayerPrivateGStreamer::didLoadingProgress): Ditto.
(WebCore::MediaPlayerPrivateGStreamer::updateStates): Remove duration caching support.
(WebCore::MediaPlayerPrivateGStreamer::didEnd): Ditto.
(WebCore::MediaPlayerPrivateGStreamer::durationChanged): Ditto.
(WebCore::MediaPlayerPrivateGStreamer::cacheDuration): Deleted.
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (202856 => 202857)


--- trunk/Source/WebCore/ChangeLog	2016-07-06 13:02:43 UTC (rev 202856)
+++ trunk/Source/WebCore/ChangeLog	2016-07-06 13:27:40 UTC (rev 202857)
@@ -1,3 +1,36 @@
+2016-07-06  Philippe Normand  <[email protected]>
+
+        [GStreamer] duration query improvements
+        https://bugs.webkit.org/show_bug.cgi?id=159458
+
+        Reviewed by Carlos Garcia Campos.
+
+        Currently the player caches the result of the duration query but
+        this is overkill because it's cached by playbin already. The only
+        time where the player needs to cache the duration is when EOS was
+        reached because in that situation the query would fail.
+
+        No new tests, existing media tests cover this patch.
+
+        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
+        (WebCore::MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer): Member variables update.
+        (WebCore::MediaPlayerPrivateGStreamer::load): Stop the fill timer
+        before loading a new URL, the same player can be used for
+        different assets.
+        (WebCore::MediaPlayerPrivateGStreamer::playbackPosition): Perform
+        a duration query, the duration value is no longer locally cached.
+        (WebCore::MediaPlayerPrivateGStreamer::duration): Return cached value only after EOS was reached.
+        (WebCore::MediaPlayerPrivateGStreamer::fillTimerFired): Perform
+        a duration query, the duration value is no longer locally cached.
+        (WebCore::MediaPlayerPrivateGStreamer::maxTimeSeekable): Ditto.
+        (WebCore::MediaPlayerPrivateGStreamer::maxTimeLoaded): Ditto.
+        (WebCore::MediaPlayerPrivateGStreamer::didLoadingProgress): Ditto.
+        (WebCore::MediaPlayerPrivateGStreamer::updateStates): Remove duration caching support.
+        (WebCore::MediaPlayerPrivateGStreamer::didEnd): Ditto.
+        (WebCore::MediaPlayerPrivateGStreamer::durationChanged): Ditto.
+        (WebCore::MediaPlayerPrivateGStreamer::cacheDuration): Deleted.
+        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h:
+
 2016-07-06  Manuel Rego Casasnovas  <[email protected]>
 
         [css-grid] Height percentages are not properly resolved for item's children

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp (202856 => 202857)


--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp	2016-07-06 13:02:43 UTC (rev 202856)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp	2016-07-06 13:27:40 UTC (rev 202857)
@@ -151,14 +151,13 @@
     , m_playbackRate(1)
     , m_lastPlaybackRate(1)
     , m_errorOccured(false)
-    , m_mediaDuration(0)
     , m_downloadFinished(false)
+    , m_durationAtEOS(0)
     , m_fillTimer(*this, &MediaPlayerPrivateGStreamer::fillTimerFired)
     , m_maxTimeLoaded(0)
     , m_bufferingPercentage(0)
     , m_preload(player->preload())
     , m_delayingLoad(false)
-    , m_mediaDurationKnown(true)
     , m_maxTimeLoadedAtLastDidLoadingProgress(0)
     , m_volumeAndMuteInitialized(false)
     , m_hasVideo(false)
@@ -237,6 +236,9 @@
     if (!m_pipeline)
         createGSTPlayBin();
 
+    if (m_fillTimer.isActive())
+        m_fillTimer.stop();
+
     ASSERT(m_pipeline);
 
     m_url = URL(URL(), cleanURL);
@@ -256,6 +258,7 @@
     m_readyState = MediaPlayer::HaveNothing;
     m_player->readyStateChanged();
     m_volumeAndMuteInitialized = false;
+    m_durationAtEOS = 0;
 
     if (!m_delayingLoad)
         commitLoad();
@@ -299,8 +302,10 @@
         // what the Media element spec expects us to do.
         if (m_seeking)
             return m_seekTime;
-        if (m_mediaDuration)
-            return m_mediaDuration;
+
+        float mediaDuration = duration();
+        if (mediaDuration)
+            return mediaDuration;
         return 0;
     }
 
@@ -416,12 +421,12 @@
     if (m_errorOccured)
         return 0.0f;
 
-    // Media duration query failed already, don't attempt new useless queries.
-    if (!m_mediaDurationKnown)
-        return numeric_limits<float>::infinity();
+    if (m_durationAtEOS)
+        return m_durationAtEOS;
 
-    if (m_mediaDuration)
-        return m_mediaDuration;
+    // The duration query would fail on a not-prerolled pipeline.
+    if (GST_STATE(m_pipeline.get()) < GST_STATE_PAUSED)
+        return 0.0f;
 
     GstFormat timeFormat = GST_FORMAT_TIME;
     gint64 timeLength = 0;
@@ -434,8 +439,7 @@
 
     LOG_MEDIA_MESSAGE("Duration: %" GST_TIME_FORMAT, GST_TIME_ARGS(timeLength));
 
-    m_mediaDuration = static_cast<double>(timeLength) / GST_SECOND;
-    return m_mediaDuration;
+    return static_cast<double>(timeLength) / GST_SECOND;
     // FIXME: handle 3.14.9.5 properly
 }
 
@@ -1177,16 +1181,15 @@
 
     LOG_MEDIA_MESSAGE("[Buffering] Download buffer filled up to %f%%", fillStatus);
 
-    if (!m_mediaDuration)
-        durationChanged();
+    float mediaDuration = duration();
 
     // Update maxTimeLoaded only if the media duration is
     // available. Otherwise we can't compute it.
-    if (m_mediaDuration) {
+    if (mediaDuration) {
         if (fillStatus == 100.0)
-            m_maxTimeLoaded = m_mediaDuration;
+            m_maxTimeLoaded = mediaDuration;
         else
-            m_maxTimeLoaded = static_cast<float>((fillStatus * m_mediaDuration) / 100.0);
+            m_maxTimeLoaded = static_cast<float>((fillStatus * mediaDuration) / 100.0);
         LOG_MEDIA_MESSAGE("[Buffering] Updated maxTimeLoaded: %f", m_maxTimeLoaded);
     }
 
@@ -1208,12 +1211,13 @@
     if (m_errorOccured)
         return 0.0f;
 
-    LOG_MEDIA_MESSAGE("maxTimeSeekable");
+    float mediaDuration = duration();
+    LOG_MEDIA_MESSAGE("maxTimeSeekable, duration: %f", mediaDuration);
     // infinite duration means live stream
-    if (std::isinf(duration()))
+    if (std::isinf(mediaDuration))
         return 0.0f;
 
-    return duration();
+    return mediaDuration;
 }
 
 float MediaPlayerPrivateGStreamer::maxTimeLoaded() const
@@ -1222,8 +1226,8 @@
         return 0.0f;
 
     float loaded = m_maxTimeLoaded;
-    if (m_isEndReached && m_mediaDuration)
-        loaded = m_mediaDuration;
+    if (m_isEndReached)
+        loaded = duration();
     LOG_MEDIA_MESSAGE("maxTimeLoaded: %f", loaded);
     return loaded;
 }
@@ -1230,7 +1234,7 @@
 
 bool MediaPlayerPrivateGStreamer::didLoadingProgress() const
 {
-    if (!m_pipeline || !m_mediaDuration || (!isMediaSource() && !totalBytes()))
+    if (!m_pipeline || !duration() || (!isMediaSource() && !totalBytes()))
         return false;
     float currentMaxTimeLoaded = maxTimeLoaded();
     bool didLoadingProgress = currentMaxTimeLoaded != m_maxTimeLoadedAtLastDidLoadingProgress;
@@ -1374,13 +1378,7 @@
         if (m_isEndReached && state == GST_STATE_READY)
             break;
 
-        if (state <= GST_STATE_READY) {
-            m_resetPipeline = true;
-            m_mediaDuration = 0;
-        } else {
-            m_resetPipeline = false;
-            cacheDuration();
-        }
+        m_resetPipeline = state <= GST_STATE_READY;
 
         bool didBuffering = m_buffering;
 
@@ -1615,11 +1613,8 @@
     // HTMLMediaElement. In some cases like reverse playback the
     // position is not always reported as 0 for instance.
     float now = currentTime();
-    if (now > 0 && now <= duration() && m_mediaDuration != now) {
-        m_mediaDurationKnown = true;
-        m_mediaDuration = now;
+    if (now > 0 && now <= duration())
         m_player->durationChanged();
-    }
 
     m_isEndReached = true;
     timeChanged();
@@ -1626,37 +1621,20 @@
 
     if (!m_player->client().mediaPlayerIsLooping()) {
         m_paused = true;
+        m_durationAtEOS = duration();
         changePipelineState(GST_STATE_READY);
         m_downloadFinished = false;
     }
 }
 
-void MediaPlayerPrivateGStreamer::cacheDuration()
-{
-    if (m_mediaDuration || !m_mediaDurationKnown)
-        return;
-
-    float newDuration = duration();
-    if (std::isinf(newDuration)) {
-        // Only pretend that duration is not available if the the query failed in a stable pipeline state.
-        GstState state;
-        if (gst_element_get_state(m_pipeline.get(), &state, nullptr, 0) == GST_STATE_CHANGE_SUCCESS && state > GST_STATE_READY)
-            m_mediaDurationKnown = false;
-        return;
-    }
-
-    m_mediaDuration = newDuration;
-}
-
 void MediaPlayerPrivateGStreamer::durationChanged()
 {
-    float previousDuration = m_mediaDuration;
+    float previousDuration = duration();
 
-    cacheDuration();
     // Avoid emiting durationchanged in the case where the previous
     // duration was 0 because that case is already handled by the
     // HTMLMediaElement.
-    if (previousDuration && m_mediaDuration != previousDuration)
+    if (previousDuration && duration() != previousDuration)
         m_player->durationChanged();
 }
 

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h (202856 => 202857)


--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h	2016-07-06 13:02:43 UTC (rev 202856)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h	2016-07-06 13:27:40 UTC (rev 202857)
@@ -137,7 +137,6 @@
 
     float playbackPosition() const;
 
-    void cacheDuration();
     void updateStates();
     void asyncStateChangeDone();
 
@@ -219,14 +218,13 @@
     float m_playbackRate;
     float m_lastPlaybackRate;
     bool m_errorOccured;
-    mutable gfloat m_mediaDuration;
     bool m_downloadFinished;
+    float m_durationAtEOS;
     Timer m_fillTimer;
     float m_maxTimeLoaded;
     int m_bufferingPercentage;
     MediaPlayer::Preload m_preload;
     bool m_delayingLoad;
-    bool m_mediaDurationKnown;
     mutable float m_maxTimeLoadedAtLastDidLoadingProgress;
     bool m_volumeAndMuteInitialized;
     bool m_hasVideo;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to