Unreviewed, rolling out r254565.
https://bugs.webkit.org/show_bug.cgi?id=206331

It caused many timeouts for the layout tests of the GTK port
(Requested by clopez on #webkit).

Reverted changeset:

"[GStreamer] Several buffering fixes"
https://bugs.webkit.org/show_bug.cgi?id=206234
https://trac.webkit.org/changeset/254565

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@254660 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 2a0e586..f6cbb3d 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,17 @@
+2020-01-15  Commit Queue  <commit-queue@webkit.org>
+
+        Unreviewed, rolling out r254565.
+        https://bugs.webkit.org/show_bug.cgi?id=206331
+
+        It caused many timeouts for the layout tests of the GTK port
+        (Requested by clopez on #webkit).
+
+        Reverted changeset:
+
+        "[GStreamer] Several buffering fixes"
+        https://bugs.webkit.org/show_bug.cgi?id=206234
+        https://trac.webkit.org/changeset/254565
+
 2020-01-15  Alex Christensen  <achristensen@webkit.org>
 
         Keep RefPtr instead of raw pointer to message queue on WebCoreResourceHandleAsOperationQueueDelegate
diff --git a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp
index 8aa1bd6..85aaf04 100644
--- a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp
+++ b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp
@@ -1053,7 +1053,7 @@
     MediaTime previousDuration = durationMediaTime();
     m_cachedDuration = MediaTime::invalidTime();
 
-    // Avoid emitting durationChanged in the case where the previous
+    // Avoid emiting durationchanged in the case where the previous
     // duration was 0 because that case is already handled by the
     // HTMLMediaElement.
     if (previousDuration && durationMediaTime() != previousDuration)
@@ -1456,7 +1456,7 @@
     double fillStatus = 100.0;
     GstBufferingMode mode = GST_BUFFERING_DOWNLOAD;
 
-    if (gst_element_query(pipeline(), query.get())) {
+    if (gst_element_query(m_source.get(), query.get())) {
         gst_query_parse_buffering_stats(query.get(), &mode, nullptr, nullptr, nullptr);
 
         int percentage;
@@ -1470,10 +1470,7 @@
         return;
     }
 
-    if (mode != GST_BUFFERING_DOWNLOAD)
-        GST_INFO_OBJECT(pipeline(), "Ignoring buffering in %s", enumToString(GST_TYPE_BUFFERING_MODE, mode).data());
-    else
-        updateBufferingStatus(mode, fillStatus);
+    updateBufferingStatus(mode, fillStatus);
 }
 
 void MediaPlayerPrivateGStreamer::loadStateChanged()
@@ -2201,11 +2198,6 @@
                 if (const char* uri = gst_structure_get_string(structure, "uri"))
                     m_hasTaintedOrigin = webKitSrcWouldTaintOrigin(WEBKIT_WEB_SRC_CAST(m_source.get()), SecurityOrigin::create(URL(URL(), uri)));
             }
-        } else if (gst_structure_has_name(structure, "GstCacheDownloadComplete")) {
-            GST_INFO_OBJECT(pipeline(), "Stream is fully downloaded, stopping monitoring downloading progress.");
-            m_fillTimer.stop();
-            m_bufferingPercentage = 100;
-            updateStates();
         } else
             GST_DEBUG_OBJECT(pipeline(), "Unhandled element message: %" GST_PTR_FORMAT, structure);
         break;
@@ -2300,29 +2292,29 @@
 
 void MediaPlayerPrivateGStreamer::updateBufferingStatus(GstBufferingMode mode, double percentage)
 {
-    bool wasBuffering = m_isBuffering;
-
     GST_DEBUG_OBJECT(pipeline(), "[Buffering] mode: %s, status: %f%%", enumToString(GST_TYPE_BUFFERING_MODE, mode).data(), percentage);
 
     m_didDownloadFinish = percentage == 100;
     m_isBuffering = !m_didDownloadFinish;
 
-    if (!m_didDownloadFinish)
-        m_isBuffering = true;
-
-    m_bufferingPercentage = percentage;
     switch (mode) {
     case GST_BUFFERING_STREAM: {
         updateMaxTimeLoaded(percentage);
 
         m_bufferingPercentage = percentage;
-        if (m_didDownloadFinish || (!wasBuffering && m_isBuffering))
+        if (m_didDownloadFinish)
             updateStates();
 
         break;
     }
     case GST_BUFFERING_DOWNLOAD: {
         updateMaxTimeLoaded(percentage);
+
+        // Media is now fully loaded. It will play even if network connection is
+        // cut. Buffering is done, remove the fill source from the main loop.
+        if (m_didDownloadFinish)
+            m_fillTimer.stop();
+
         updateStates();
         break;
     }
@@ -2585,17 +2577,9 @@
             FALLTHROUGH;
         case GST_STATE_PLAYING:
             if (m_isBuffering) {
-                GRefPtr<GstQuery> query = adoptGRef(gst_query_new_buffering(GST_FORMAT_PERCENT));
-
-                m_isBuffering = m_bufferingPercentage == 100;
-                if (gst_element_query(m_pipeline.get(), query.get())) {
-                    gboolean isBuffering = m_isBuffering;
-                    gst_query_parse_buffering_percent(query.get(), &isBuffering, nullptr);
-                    m_isBuffering = isBuffering;
-                }
-
-                if (!m_isBuffering) {
-                    GST_INFO_OBJECT(pipeline(), "[Buffering] Complete.");
+                if (m_bufferingPercentage == 100) {
+                    GST_DEBUG_OBJECT(pipeline(), "[Buffering] Complete.");
+                    m_isBuffering = false;
                     m_readyState = MediaPlayer::ReadyState::HaveEnoughData;
                     m_networkState = m_didDownloadFinish ? MediaPlayer::NetworkState::Idle : MediaPlayer::NetworkState::Loading;
                 } else {
@@ -2625,14 +2609,14 @@
             }
 
             if (didBuffering && !m_isBuffering && !m_isPaused && m_playbackRate) {
-                GST_INFO_OBJECT(pipeline(), "[Buffering] Restarting playback.");
+                GST_DEBUG_OBJECT(pipeline(), "[Buffering] Restarting playback.");
                 changePipelineState(GST_STATE_PLAYING);
             }
         } else if (m_currentState == GST_STATE_PLAYING) {
             m_isPaused = false;
 
             if ((m_isBuffering && !m_isLiveStream) || !m_playbackRate) {
-                GST_INFO_OBJECT(pipeline(), "[Buffering] Pausing stream for buffering.");
+                GST_DEBUG_OBJECT(pipeline(), "[Buffering] Pausing stream for buffering.");
                 changePipelineState(GST_STATE_PAUSED);
             }
         } else