Title: [235293] releases/WebKitGTK/webkit-2.22/Source/WebCore
Revision
235293
Author
[email protected]
Date
2018-08-24 01:08:11 -0700 (Fri, 24 Aug 2018)

Log Message

Merge r235110 - [GStreamer][MSE] Generic main thread notification support
https://bugs.webkit.org/show_bug.cgi?id=188647

Patch by Philippe Normand <[email protected]> on 2018-08-21
Reviewed by Xabier Rodriguez-Calvar.

Using GstBus for main thread notifications has the side effect of "leaking" the
application messages to the media player, leading to CPU cycles wasting.

No new tests, existing MSE tests cover this change.

* platform/graphics/gstreamer/mse/WebKitMediaSourceGStreamer.cpp:
(webkit_media_src_init):
(webKitMediaSrcFinalize):
(webKitMediaSrcSetMediaPlayerPrivate):
* platform/graphics/gstreamer/mse/WebKitMediaSourceGStreamerPrivate.h:

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.22/Source/WebCore/ChangeLog (235292 => 235293)


--- releases/WebKitGTK/webkit-2.22/Source/WebCore/ChangeLog	2018-08-24 08:08:06 UTC (rev 235292)
+++ releases/WebKitGTK/webkit-2.22/Source/WebCore/ChangeLog	2018-08-24 08:08:11 UTC (rev 235293)
@@ -1,5 +1,23 @@
 2018-08-21  Philippe Normand  <[email protected]>
 
+        [GStreamer][MSE] Generic main thread notification support
+        https://bugs.webkit.org/show_bug.cgi?id=188647
+
+        Reviewed by Xabier Rodriguez-Calvar.
+
+        Using GstBus for main thread notifications has the side effect of "leaking" the
+        application messages to the media player, leading to CPU cycles wasting.
+
+        No new tests, existing MSE tests cover this change.
+
+        * platform/graphics/gstreamer/mse/WebKitMediaSourceGStreamer.cpp:
+        (webkit_media_src_init):
+        (webKitMediaSrcFinalize):
+        (webKitMediaSrcSetMediaPlayerPrivate):
+        * platform/graphics/gstreamer/mse/WebKitMediaSourceGStreamerPrivate.h:
+
+2018-08-21  Philippe Normand  <[email protected]>
+
         [GStreamer][MSE] Remove parsers from playback pipeline
         https://bugs.webkit.org/show_bug.cgi?id=188646
 

Modified: releases/WebKitGTK/webkit-2.22/Source/WebCore/platform/graphics/gstreamer/mse/WebKitMediaSourceGStreamer.cpp (235292 => 235293)


--- releases/WebKitGTK/webkit-2.22/Source/WebCore/platform/graphics/gstreamer/mse/WebKitMediaSourceGStreamer.cpp	2018-08-24 08:08:06 UTC (rev 235292)
+++ releases/WebKitGTK/webkit-2.22/Source/WebCore/platform/graphics/gstreamer/mse/WebKitMediaSourceGStreamer.cpp	2018-08-24 08:08:11 UTC (rev 235293)
@@ -40,14 +40,11 @@
 #include "VideoTrackPrivateGStreamer.h"
 #include "WebKitMediaSourceGStreamerPrivate.h"
 
-#include <gst/app/app.h>
-#include <gst/app/gstappsrc.h>
-#include <gst/gst.h>
-#include <gst/pbutils/missing-plugins.h>
 #include <gst/pbutils/pbutils.h>
 #include <gst/video/video.h>
 #include <wtf/Condition.h>
 #include <wtf/MainThread.h>
+#include <wtf/RefPtr.h>
 #include <wtf/text/CString.h>
 
 GST_DEBUG_CATEGORY_STATIC(webkit_media_src_debug);
@@ -85,6 +82,8 @@
 };
 
 static Stream* getStreamByAppsrc(WebKitMediaSrc*, GstElement*);
+static void seekNeedsDataMainThread(WebKitMediaSrc*);
+static void notifyReadyForMoreSamplesMainThread(WebKitMediaSrc*, Stream*);
 
 static void enabledAppsrcNeedData(GstAppSrc* appsrc, guint, gpointer userData)
 {
@@ -119,13 +118,11 @@
         GST_DEBUG("All expected appsrcSeekData() and appsrcNeedData() calls performed. Running next action (%d)", static_cast<int>(appsrcSeekDataNextAction));
 
         switch (appsrcSeekDataNextAction) {
-        case MediaSourceSeekToTime: {
-            GstStructure* structure = gst_structure_new_empty("seek-needs-data");
-            GstMessage* message = gst_message_new_application(GST_OBJECT(appsrc), structure);
-            gst_bus_post(webKitMediaSrc->priv->bus.get(), message);
-            GST_TRACE("seek-needs-data message posted to the bus");
+        case MediaSourceSeekToTime:
+            webKitMediaSrc->priv->notifier->notify(WebKitMediaSrcMainThreadNotification::SeekNeedsData, [webKitMediaSrc] {
+                seekNeedsDataMainThread(webKitMediaSrc);
+            });
             break;
-        }
         case Nothing:
             break;
         }
@@ -137,12 +134,10 @@
         // Search again for the Stream, just in case it was removed between the previous lock and this one.
         appsrcStream = getStreamByAppsrc(webKitMediaSrc, GST_ELEMENT(appsrc));
 
-        if (appsrcStream && appsrcStream->type != WebCore::Invalid) {
-            GstStructure* structure = gst_structure_new("ready-for-more-samples", "appsrc-stream", G_TYPE_POINTER, appsrcStream, nullptr);
-            GstMessage* message = gst_message_new_application(GST_OBJECT(appsrc), structure);
-            gst_bus_post(webKitMediaSrc->priv->bus.get(), message);
-            GST_TRACE("ready-for-more-samples message posted to the bus");
-        }
+        if (appsrcStream && appsrcStream->type != WebCore::Invalid)
+            webKitMediaSrc->priv->notifier->notify(WebKitMediaSrcMainThreadNotification::ReadyForMoreSamples, [webKitMediaSrc, appsrcStream] {
+                notifyReadyForMoreSamplesMainThread(webKitMediaSrc, appsrcStream);
+            });
 
         GST_OBJECT_UNLOCK(webKitMediaSrc);
     }
@@ -264,6 +259,7 @@
     source->priv->appsrcNeedDataCount = 0;
     source->priv->appsrcSeekDataNextAction = Nothing;
     source->priv->flowCombiner = GUniquePtr<GstFlowCombiner>(gst_flow_combiner_new());
+    source->priv->notifier = WebCore::MainThreadNotifier<WebKitMediaSrcMainThreadNotification>::create();
 
     // No need to reset Stream.appsrcNeedDataFlag because there are no Streams at this point yet.
 }
@@ -283,6 +279,8 @@
 
     priv->seekTime = MediaTime::invalidTime();
 
+    source->priv->notifier->invalidate();
+
     if (priv->mediaPlayerPrivate)
         webKitMediaSrcSetMediaPlayerPrivate(source, nullptr);
 
@@ -694,43 +692,12 @@
     GST_OBJECT_UNLOCK(source);
 }
 
-static void applicationMessageCallback(GstBus*, GstMessage* message, WebKitMediaSrc* source)
-{
-    ASSERT(WTF::isMainThread());
-    ASSERT(GST_MESSAGE_TYPE(message) == GST_MESSAGE_APPLICATION);
-
-    const GstStructure* structure = gst_message_get_structure(message);
-
-    if (gst_structure_has_name(structure, "seek-needs-data")) {
-        seekNeedsDataMainThread(source);
-        return;
-    }
-
-    if (gst_structure_has_name(structure, "ready-for-more-samples")) {
-        Stream* appsrcStream = nullptr;
-        gst_structure_get(structure, "appsrc-stream", G_TYPE_POINTER, &appsrcStream, nullptr);
-        ASSERT(appsrcStream);
-
-        notifyReadyForMoreSamplesMainThread(source, appsrcStream);
-        return;
-    }
-
-    ASSERT_NOT_REACHED();
-}
-
 void webKitMediaSrcSetMediaPlayerPrivate(WebKitMediaSrc* source, WebCore::MediaPlayerPrivateGStreamerMSE* mediaPlayerPrivate)
 {
     GST_OBJECT_LOCK(source);
-    if (source->priv->mediaPlayerPrivate && source->priv->mediaPlayerPrivate != mediaPlayerPrivate && source->priv->bus)
-        g_signal_handlers_disconnect_by_func(source->priv->bus.get(), gpointer(applicationMessageCallback), source);
 
     // Set to nullptr on MediaPlayerPrivateGStreamer destruction, never a dangling pointer.
     source->priv->mediaPlayerPrivate = mediaPlayerPrivate;
-    source->priv->bus = mediaPlayerPrivate ? adoptGRef(gst_pipeline_get_bus(GST_PIPELINE(mediaPlayerPrivate->pipeline()))) : nullptr;
-    if (source->priv->bus) {
-        // MediaPlayerPrivateGStreamer has called gst_bus_add_signal_watch() at this point, so we can subscribe.
-        g_signal_connect(source->priv->bus.get(), "message::application", G_CALLBACK(applicationMessageCallback), source);
-    }
     GST_OBJECT_UNLOCK(source);
 }
 

Modified: releases/WebKitGTK/webkit-2.22/Source/WebCore/platform/graphics/gstreamer/mse/WebKitMediaSourceGStreamerPrivate.h (235292 => 235293)


--- releases/WebKitGTK/webkit-2.22/Source/WebCore/platform/graphics/gstreamer/mse/WebKitMediaSourceGStreamerPrivate.h	2018-08-24 08:08:06 UTC (rev 235292)
+++ releases/WebKitGTK/webkit-2.22/Source/WebCore/platform/graphics/gstreamer/mse/WebKitMediaSourceGStreamerPrivate.h	2018-08-24 08:08:11 UTC (rev 235293)
@@ -24,6 +24,7 @@
 
 #include "AudioTrackPrivateGStreamer.h"
 #include "GUniquePtrGStreamer.h"
+#include "MainThreadNotifier.h"
 #include "SourceBufferPrivateGStreamer.h"
 #include "VideoTrackPrivateGStreamer.h"
 #include "WebKitMediaSourceGStreamer.h"
@@ -30,8 +31,7 @@
 
 #include <gst/app/gstappsrc.h>
 #include <gst/gst.h>
-#include <wtf/Condition.h>
-#include <wtf/RefPtr.h>
+#include <wtf/Forward.h>
 #include <wtf/glib/GRefPtr.h>
 
 namespace WebCore {
@@ -95,6 +95,11 @@
     MediaSourceSeekToTime
 };
 
+enum WebKitMediaSrcMainThreadNotification {
+    ReadyForMoreSamples = 1 << 0,
+    SeekNeedsData = 1 << 1
+};
+
 struct _WebKitMediaSrcPrivate {
     // Used to coordinate the release of Stream track info.
     Lock streamLock;
@@ -118,9 +123,9 @@
     int appsrcSeekDataCount;
     int appsrcNeedDataCount;
 
-    GRefPtr<GstBus> bus;
     WebCore::MediaPlayerPrivateGStreamerMSE* mediaPlayerPrivate;
 
+    RefPtr<WebCore::MainThreadNotifier<WebKitMediaSrcMainThreadNotification>> notifier;
     GUniquePtr<GstFlowCombiner> flowCombiner;
 };
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to