[GStreamer] Remove the HLS queue buffering query hack
authorphiln@webkit.org <philn@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 27 Mar 2019 11:34:53 +0000 (11:34 +0000)
committerphiln@webkit.org <philn@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 27 Mar 2019 11:34:53 +0000 (11:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196244

Reviewed by Xabier Rodriguez-Calvar.

Because the http src element now provides network statistics to
the player we can now compute an estimation of the data loading in
case the buffering query isn't handled by any element of the
pipeline.

No new tests, existing HLS tests cover this change.

* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::fillTimerFired):
(WebCore::findHLSQueue): Deleted.
(WebCore::isHLSProgressing): Deleted.

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

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

index 6de624d..519441c 100644 (file)
@@ -1,3 +1,22 @@
+2019-03-27  Philippe Normand  <pnormand@igalia.com>
+
+        [GStreamer] Remove the HLS queue buffering query hack
+        https://bugs.webkit.org/show_bug.cgi?id=196244
+
+        Reviewed by Xabier Rodriguez-Calvar.
+
+        Because the http src element now provides network statistics to
+        the player we can now compute an estimation of the data loading in
+        case the buffering query isn't handled by any element of the
+        pipeline.
+
+        No new tests, existing HLS tests cover this change.
+
+        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
+        (WebCore::MediaPlayerPrivateGStreamer::fillTimerFired):
+        (WebCore::findHLSQueue): Deleted.
+        (WebCore::isHLSProgressing): Deleted.
+
 2019-03-26  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         Unreviewed Windows build fix
index 0f0dd49..aeab396 100644 (file)
@@ -1374,8 +1374,8 @@ void MediaPlayerPrivateGStreamer::handleMessage(GstMessage* message)
                 }
             }
         } else if (gst_structure_has_name(structure, "webkit-network-statistics")) {
-            if (gst_structure_get_uint64(structure, "read-position", &m_networkReadPosition))
-                GST_DEBUG_OBJECT(pipeline(), "Updated network read position %" G_GUINT64_FORMAT, m_networkReadPosition);
+            if (gst_structure_get(structure, "read-position", G_TYPE_UINT64, &m_networkReadPosition, "size", G_TYPE_UINT64, &m_httpResponseTotalSize, nullptr))
+                GST_DEBUG_OBJECT(pipeline(), "Updated network read position %" G_GUINT64_FORMAT ", size: %" G_GUINT64_FORMAT, m_networkReadPosition, m_httpResponseTotalSize);
         } else
             GST_DEBUG_OBJECT(pipeline(), "Unhandled element message: %" GST_PTR_FORMAT, structure);
         break;
@@ -1582,62 +1582,26 @@ void MediaPlayerPrivateGStreamer::purgeInvalidTextTracks(Vector<String> validTra
 }
 #endif
 
-static gint findHLSQueue(gconstpointer a, gconstpointer)
-{
-    GValue* item = static_cast<GValue*>(const_cast<gpointer>(a));
-    GstElement* element = GST_ELEMENT(g_value_get_object(item));
-    if (g_str_has_prefix(GST_ELEMENT_NAME(element), "queue")) {
-        GstElement* parent = GST_ELEMENT(GST_ELEMENT_PARENT(element));
-        if (!GST_IS_OBJECT(parent))
-            return 1;
-
-        if (g_str_has_prefix(GST_ELEMENT_NAME(GST_ELEMENT_PARENT(parent)), "hlsdemux"))
-            return 0;
-    }
-
-    return 1;
-}
-
-static bool isHLSProgressing(GstElement* playbin, GstQuery* query)
-{
-    GValue item = { };
-    GstIterator* binIterator = gst_bin_iterate_recurse(GST_BIN(playbin));
-    bool foundHLSQueue = gst_iterator_find_custom(binIterator, reinterpret_cast<GCompareFunc>(findHLSQueue), &item, nullptr);
-    gst_iterator_free(binIterator);
-
-    if (!foundHLSQueue)
-        return false;
-
-    GstElement* queueElement = GST_ELEMENT(g_value_get_object(&item));
-    bool queryResult = gst_element_query(queueElement, query);
-    g_value_unset(&item);
-
-    return queryResult;
-}
-
 void MediaPlayerPrivateGStreamer::fillTimerFired()
 {
-    GstQuery* query = gst_query_new_buffering(GST_FORMAT_PERCENT);
-
-    if (G_UNLIKELY(!gst_element_query(m_pipeline.get(), query))) {
-        // This query always fails for live pipelines. In the case of HLS, try and find
-        // the queue inside the HLS element to get a proxy measure of progress. Note
-        // that the percentage value is rather meaningless as used below.
-        // This is a hack, see https://bugs.webkit.org/show_bug.cgi?id=141469.
-        if (!isHLSProgressing(m_pipeline.get(), query)) {
-            gst_query_unref(query);
-            return;
-        }
-    }
+    GRefPtr<GstQuery> query = adoptGRef(gst_query_new_buffering(GST_FORMAT_PERCENT));
+    double fillStatus = 100.0;
 
-    gint64 start, stop;
-    gdouble fillStatus = 100.0;
+    if (gst_element_query(m_pipeline.get(), query.get())) {
+        int64_t stop;
+        GstFormat format;
+        gst_query_parse_buffering_range(query.get(), &format, nullptr, &stop, nullptr);
+        ASSERT(format == GST_FORMAT_PERCENT);
 
-    gst_query_parse_buffering_range(query, nullptr, &start, &stop, nullptr);
-    gst_query_unref(query);
-
-    if (stop != -1)
-        fillStatus = 100.0 * stop / GST_FORMAT_PERCENT_MAX;
+        if (stop != -1)
+            fillStatus = 100.0 * stop / GST_FORMAT_PERCENT_MAX;
+    } else if (m_httpResponseTotalSize) {
+        GST_DEBUG_OBJECT(pipeline(), "[Buffering] Query failed, falling back to network read position estimation");
+        fillStatus = 100.0 * (m_networkReadPosition / m_httpResponseTotalSize);
+    } else {
+        GST_DEBUG_OBJECT(pipeline(), "[Buffering] Unable to determine on-disk buffering status");
+        return;
+    }
 
     GST_DEBUG_OBJECT(pipeline(), "[Buffering] Download buffer filled up to %f%%", fillStatus);
 
index dfcb5f1..bc1a512 100644 (file)
@@ -287,6 +287,7 @@ private:
 #endif
     virtual bool isMediaSource() const { return false; }
 
+    uint64_t m_httpResponseTotalSize { 0 };
     uint64_t m_networkReadPosition { 0 };
     mutable uint64_t m_readPositionAtLastDidLoadingProgress { 0 };
 
index 9a12e81..e1e497e 100644 (file)
@@ -998,8 +998,6 @@ void CachedResourceStreamingClient::dataReceived(PlatformMediaResource&, const c
     if (LIKELY (priv->requestedPosition == priv->readPosition))
         priv->requestedPosition = newPosition;
     priv->readPosition = newPosition;
-    gst_element_post_message(GST_ELEMENT_CAST(src), gst_message_new_element(GST_OBJECT_CAST(src),
-        gst_structure_new("webkit-network-statistics", "read-position", G_TYPE_UINT64, priv->readPosition, nullptr)));
 
     uint64_t newSize = 0;
     if (priv->haveSize && (newPosition > priv->size)) {
@@ -1017,6 +1015,9 @@ void CachedResourceStreamingClient::dataReceived(PlatformMediaResource&, const c
         gst_element_post_message(GST_ELEMENT_CAST(src), gst_message_new_duration_changed(GST_OBJECT_CAST(src)));
     }
 
+    gst_element_post_message(GST_ELEMENT_CAST(src), gst_message_new_element(GST_OBJECT_CAST(src),
+        gst_structure_new("webkit-network-statistics", "read-position", G_TYPE_UINT64, priv->readPosition, "size", G_TYPE_UINT64, priv->size, nullptr)));
+
     checkUpdateBlocksize(length);
 
     if (!priv->wasResponseReceived)