Title: [288948] trunk/Source/WebCore
Revision
288948
Author
[email protected]
Date
2022-02-02 02:07:20 -0800 (Wed, 02 Feb 2022)

Log Message

[GStreamer] Add support for custom message handling in simpleBusMessageCallback
https://bugs.webkit.org/show_bug.cgi?id=235822

Patch by Philippe Normand <[email protected]> on 2022-02-02
Reviewed by Xabier Rodriguez-Calvar.

Refactor most custom GStreamer message handlers to rely on the common "simple" handler,
which can now be augmented with an optional closure to do further message processing.

* platform/audio/gstreamer/AudioDestinationGStreamer.cpp:
(WebCore::AudioDestinationGStreamer::AudioDestinationGStreamer):
(WebCore::AudioDestinationGStreamer::~AudioDestinationGStreamer):
(WebCore::AudioDestinationGStreamer::handleMessage):
(WebCore::messageCallback): Deleted.
* platform/audio/gstreamer/AudioDestinationGStreamer.h:
* platform/graphics/gstreamer/GStreamerCommon.cpp:
(WebCore::disconnectSimpleBusMessageCallback):
(WebCore::CustomMessageHandlerHolder::CustomMessageHandlerHolder):
(WebCore::connectSimpleBusMessageCallback):
(WebCore::simpleBusMessageCallback): Deleted.
* platform/graphics/gstreamer/GStreamerCommon.h:
(WebCore::connectSimpleBusMessageCallback):
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::~MediaPlayerPrivateGStreamer):
(WebCore::MediaPlayerPrivateGStreamer::handleMessage):
(WebCore::MediaPlayerPrivateGStreamer::createGSTPlayBin):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (288947 => 288948)


--- trunk/Source/WebCore/ChangeLog	2022-02-02 09:12:57 UTC (rev 288947)
+++ trunk/Source/WebCore/ChangeLog	2022-02-02 10:07:20 UTC (rev 288948)
@@ -1,3 +1,31 @@
+2022-02-02  Philippe Normand  <[email protected]>
+
+        [GStreamer] Add support for custom message handling in simpleBusMessageCallback
+        https://bugs.webkit.org/show_bug.cgi?id=235822
+
+        Reviewed by Xabier Rodriguez-Calvar.
+
+        Refactor most custom GStreamer message handlers to rely on the common "simple" handler,
+        which can now be augmented with an optional closure to do further message processing.
+
+        * platform/audio/gstreamer/AudioDestinationGStreamer.cpp:
+        (WebCore::AudioDestinationGStreamer::AudioDestinationGStreamer):
+        (WebCore::AudioDestinationGStreamer::~AudioDestinationGStreamer):
+        (WebCore::AudioDestinationGStreamer::handleMessage):
+        (WebCore::messageCallback): Deleted.
+        * platform/audio/gstreamer/AudioDestinationGStreamer.h:
+        * platform/graphics/gstreamer/GStreamerCommon.cpp:
+        (WebCore::disconnectSimpleBusMessageCallback):
+        (WebCore::CustomMessageHandlerHolder::CustomMessageHandlerHolder):
+        (WebCore::connectSimpleBusMessageCallback):
+        (WebCore::simpleBusMessageCallback): Deleted.
+        * platform/graphics/gstreamer/GStreamerCommon.h:
+        (WebCore::connectSimpleBusMessageCallback):
+        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
+        (WebCore::MediaPlayerPrivateGStreamer::~MediaPlayerPrivateGStreamer):
+        (WebCore::MediaPlayerPrivateGStreamer::handleMessage):
+        (WebCore::MediaPlayerPrivateGStreamer::createGSTPlayBin):
+
 2022-02-02  Martin Robinson  <[email protected]>
 
         scroll-margin-top doesn't work on inline elements

Modified: trunk/Source/WebCore/platform/audio/gstreamer/AudioDestinationGStreamer.cpp (288947 => 288948)


--- trunk/Source/WebCore/platform/audio/gstreamer/AudioDestinationGStreamer.cpp	2022-02-02 09:12:57 UTC (rev 288947)
+++ trunk/Source/WebCore/platform/audio/gstreamer/AudioDestinationGStreamer.cpp	2022-02-02 10:07:20 UTC (rev 288948)
@@ -87,11 +87,6 @@
     return count;
 }
 
-gboolean messageCallback(GstBus*, GstMessage* message, AudioDestinationGStreamer* destination)
-{
-    return destination->handleMessage(message);
-}
-
 Ref<AudioDestination> AudioDestination::create(AudioIOCallback& callback, const String&, unsigned numberOfInputChannels, unsigned numberOfOutputChannels, float sampleRate)
 {
     initializeDebugCategory();
@@ -121,10 +116,9 @@
 {
     static Atomic<uint32_t> pipelineId;
     m_pipeline = gst_pipeline_new(makeString("audio-destination-", pipelineId.exchangeAdd(1)).ascii().data());
-    auto bus = adoptGRef(gst_pipeline_get_bus(GST_PIPELINE(m_pipeline.get())));
-    ASSERT(bus);
-    gst_bus_add_signal_watch_full(bus.get(), RunLoopSourcePriority::RunLoopDispatcher);
-    g_signal_connect(bus.get(), "message", G_CALLBACK(messageCallback), this);
+    connectSimpleBusMessageCallback(m_pipeline.get(), [this](GstMessage* message) {
+        this->handleMessage(message);
+    });
 
     m_src = GST_ELEMENT_CAST(g_object_new(WEBKIT_TYPE_WEB_AUDIO_SRC, "rate", sampleRate,
         "bus", m_renderBus.get(), "destination", this, "frames", AudioUtilities::renderQuantumSize, nullptr));
@@ -169,11 +163,7 @@
 AudioDestinationGStreamer::~AudioDestinationGStreamer()
 {
     GST_DEBUG_OBJECT(m_pipeline.get(), "Disposing");
-    auto bus = adoptGRef(gst_pipeline_get_bus(GST_PIPELINE(m_pipeline.get())));
-    ASSERT(bus);
-    g_signal_handlers_disconnect_by_func(bus.get(), reinterpret_cast<gpointer>(messageCallback), this);
-    gst_bus_remove_signal_watch(bus.get());
-
+    disconnectSimpleBusMessageCallback(m_pipeline.get());
     gst_element_set_state(m_pipeline.get(), GST_STATE_NULL);
     notifyStopResult(true);
 }
@@ -183,41 +173,16 @@
     return AudioUtilities::renderQuantumSize;
 }
 
-gboolean AudioDestinationGStreamer::handleMessage(GstMessage* message)
+bool AudioDestinationGStreamer::handleMessage(GstMessage* message)
 {
-    GUniqueOutPtr<GError> error;
-    GUniqueOutPtr<gchar> debug;
-
     switch (GST_MESSAGE_TYPE(message)) {
-    case GST_MESSAGE_WARNING:
-        gst_message_parse_warning(message, &error.outPtr(), &debug.outPtr());
-        g_warning("Warning: %d, %s. Debug output: %s", error->code,  error->message, debug.get());
-        break;
     case GST_MESSAGE_ERROR:
-        gst_message_parse_error(message, &error.outPtr(), &debug.outPtr());
-        g_warning("Error: %d, %s. Debug output: %s", error->code,  error->message, debug.get());
-        gst_element_set_state(m_pipeline.get(), GST_STATE_NULL);
         notifyIsPlaying(false);
         break;
-    case GST_MESSAGE_STATE_CHANGED:
-        if (GST_MESSAGE_SRC(message) == GST_OBJECT(m_pipeline.get())) {
-            GstState oldState, newState, pending;
-            gst_message_parse_state_changed(message, &oldState, &newState, &pending);
-
-            GST_INFO_OBJECT(m_pipeline.get(), "State changed (old: %s, new: %s, pending: %s)",
-                gst_element_state_get_name(oldState), gst_element_state_get_name(newState), gst_element_state_get_name(pending));
-
-            String dotFileName = makeString(GST_OBJECT_NAME(m_pipeline.get()), '_',
-                gst_element_state_get_name(oldState), '_', gst_element_state_get_name(newState));
-
-            GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN_CAST(m_pipeline.get()), GST_DEBUG_GRAPH_SHOW_ALL, dotFileName.utf8().data());
-        }
-        break;
     default:
-        GST_DEBUG_OBJECT(m_pipeline.get(), "Unhandled message: %s", GST_MESSAGE_TYPE_NAME(message));
         break;
     }
-    return TRUE;
+    return true;
 }
 
 void AudioDestinationGStreamer::start(Function<void(Function<void()>&&)>&& dispatchToRenderThread, CompletionHandler<void(bool)>&& completionHandler)

Modified: trunk/Source/WebCore/platform/audio/gstreamer/AudioDestinationGStreamer.h (288947 => 288948)


--- trunk/Source/WebCore/platform/audio/gstreamer/AudioDestinationGStreamer.h	2022-02-02 09:12:57 UTC (rev 288947)
+++ trunk/Source/WebCore/platform/audio/gstreamer/AudioDestinationGStreamer.h	2022-02-02 10:07:20 UTC (rev 288948)
@@ -38,7 +38,7 @@
     float sampleRate() const override { return m_sampleRate; }
     unsigned framesPerBuffer() const final;
 
-    gboolean handleMessage(GstMessage*);
+    bool handleMessage(GstMessage*);
     void notifyIsPlaying(bool);
 
 protected:

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp (288947 => 288948)


--- trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp	2022-02-02 09:12:57 UTC (rev 288947)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp	2022-02-02 10:07:20 UTC (rev 288948)
@@ -374,51 +374,67 @@
     return time.timeValue();
 }
 
-static void simpleBusMessageCallback(GstBus*, GstMessage* message, GstBin* pipeline)
-{
-    switch (GST_MESSAGE_TYPE(message)) {
-    case GST_MESSAGE_ERROR:
-        GST_ERROR_OBJECT(pipeline, "Got message: %" GST_PTR_FORMAT, message);
-        {
-            String dotFileName = makeString(GST_OBJECT_NAME(pipeline), "_error");
-            GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(pipeline, GST_DEBUG_GRAPH_SHOW_ALL, dotFileName.utf8().data());
-        }
-        break;
-    case GST_MESSAGE_STATE_CHANGED:
-        if (GST_MESSAGE_SRC(message) == GST_OBJECT(pipeline)) {
-            GstState oldState, newState, pending;
-            gst_message_parse_state_changed(message, &oldState, &newState, &pending);
-
-            GST_INFO_OBJECT(pipeline, "State changed (old: %s, new: %s, pending: %s)",
-                gst_element_state_get_name(oldState),
-                gst_element_state_get_name(newState),
-                gst_element_state_get_name(pending));
-
-            String dotFileName = makeString(
-                GST_OBJECT_NAME(pipeline), '_',
-                gst_element_state_get_name(oldState), '_',
-                gst_element_state_get_name(newState));
-
-            GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN(pipeline), GST_DEBUG_GRAPH_SHOW_ALL, dotFileName.utf8().data());
-        }
-        break;
-    default:
-        break;
-    }
-}
-
 void disconnectSimpleBusMessageCallback(GstElement* pipeline)
 {
     auto bus = adoptGRef(gst_pipeline_get_bus(GST_PIPELINE(pipeline)));
-    g_signal_handlers_disconnect_by_func(bus.get(), reinterpret_cast<gpointer>(simpleBusMessageCallback), pipeline);
+    g_signal_handlers_disconnect_by_data(bus.get(), pipeline);
     gst_bus_remove_signal_watch(bus.get());
 }
 
-void connectSimpleBusMessageCallback(GstElement* pipeline)
+struct CustomMessageHandlerHolder {
+    explicit CustomMessageHandlerHolder(Function<void(GstMessage*)>&& handler)
+    {
+        this->handler = WTFMove(handler);
+    }
+    Function<void(GstMessage*)> handler;
+};
+
+void connectSimpleBusMessageCallback(GstElement* pipeline, Function<void(GstMessage*)>&& customHandler)
 {
     auto bus = adoptGRef(gst_pipeline_get_bus(GST_PIPELINE(pipeline)));
     gst_bus_add_signal_watch_full(bus.get(), RunLoopSourcePriority::RunLoopDispatcher);
-    g_signal_connect(bus.get(), "message", G_CALLBACK(simpleBusMessageCallback), pipeline);
+
+    auto* holder = new CustomMessageHandlerHolder(WTFMove(customHandler));
+    GQuark quark = g_quark_from_static_string("pipeline-custom-message-handler");
+    g_object_set_qdata_full(G_OBJECT(pipeline), quark, holder, [](gpointer data) {
+        delete reinterpret_cast<CustomMessageHandlerHolder*>(data);
+    });
+
+    g_signal_connect(bus.get(), "message", G_CALLBACK(+[](GstBus*, GstMessage* message, GstElement* pipeline) {
+        switch (GST_MESSAGE_TYPE(message)) {
+        case GST_MESSAGE_ERROR: {
+            GST_ERROR_OBJECT(pipeline, "Got message: %" GST_PTR_FORMAT, message);
+            auto dotFileName = makeString(GST_OBJECT_NAME(pipeline), "_error");
+            GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN_CAST(pipeline), GST_DEBUG_GRAPH_SHOW_ALL, dotFileName.utf8().data());
+            break;
+        }
+        case GST_MESSAGE_STATE_CHANGED: {
+            if (GST_MESSAGE_SRC(message) != GST_OBJECT_CAST(pipeline))
+                break;
+
+            GstState oldState;
+            GstState newState;
+            GstState pending;
+            gst_message_parse_state_changed(message, &oldState, &newState, &pending);
+
+            GST_INFO_OBJECT(pipeline, "State changed (old: %s, new: %s, pending: %s)", gst_element_state_get_name(oldState),
+                gst_element_state_get_name(newState), gst_element_state_get_name(pending));
+
+            auto dotFileName = makeString(GST_OBJECT_NAME(pipeline), '_', gst_element_state_get_name(oldState), '_', gst_element_state_get_name(newState));
+            GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN_CAST(pipeline), GST_DEBUG_GRAPH_SHOW_ALL, dotFileName.utf8().data());
+            break;
+        }
+        default:
+            break;
+        }
+
+        GQuark quark = g_quark_from_static_string("pipeline-custom-message-handler");
+        auto* holder = reinterpret_cast<CustomMessageHandlerHolder*>(g_object_get_qdata(G_OBJECT(pipeline), quark));
+        if (!holder)
+            return;
+
+        holder->handler(message);
+    }), pipeline);
 }
 
 Vector<uint8_t> GstMappedBuffer::createVector() const

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h (288947 => 288948)


--- trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h	2022-02-02 09:12:57 UTC (rev 288947)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h	2022-02-02 10:07:20 UTC (rev 288948)
@@ -298,8 +298,8 @@
 };
 
 
-void connectSimpleBusMessageCallback(GstElement* pipeline);
-void disconnectSimpleBusMessageCallback(GstElement* pipeline);
+void connectSimpleBusMessageCallback(GstElement*, Function<void(GstMessage*)>&& = [](GstMessage*) { });
+void disconnectSimpleBusMessageCallback(GstElement*);
 
 enum class GstVideoDecoderPlatform { ImxVPU, Video4Linux, OpenMAX };
 

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


--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp	2022-02-02 09:12:57 UTC (rev 288947)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp	2022-02-02 10:07:20 UTC (rev 288948)
@@ -213,10 +213,7 @@
     }
 
     if (m_pipeline) {
-        auto bus = adoptGRef(gst_pipeline_get_bus(GST_PIPELINE(m_pipeline.get())));
-        ASSERT(bus);
-        g_signal_handlers_disconnect_matched(bus.get(), G_SIGNAL_MATCH_DATA, 0, 0, nullptr, nullptr, this);
-        gst_bus_remove_signal_watch(bus.get());
+        disconnectSimpleBusMessageCallback(m_pipeline.get());
         g_signal_handlers_disconnect_matched(m_pipeline.get(), G_SIGNAL_MATCH_DATA, 0, 0, nullptr, nullptr, this);
     }
 
@@ -1714,8 +1711,6 @@
         gst_message_parse_error(message, &err.outPtr(), &debug.outPtr());
         GST_ERROR("Error %d: %s (url="" err->code, err->message, m_url.string().utf8().data());
 
-        GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN(m_pipeline.get()), GST_DEBUG_GRAPH_SHOW_ALL, "webkit-video.error");
-
         error = MediaPlayer::NetworkState::Empty;
         if (g_error_matches(err.get(), GST_STREAM_ERROR, GST_STREAM_ERROR_CODEC_NOT_FOUND)
             || g_error_matches(err.get(), GST_STREAM_ERROR, GST_STREAM_ERROR_WRONG_TYPE)
@@ -1779,12 +1774,8 @@
         if (!messageSourceIsPlaybin || m_isDelayingLoad)
             break;
 
-        // Construct a filename for the graphviz dot file output.
         GstState newState;
         gst_message_parse_state_changed(message, &currentState, &newState, nullptr);
-        CString dotFileName = makeString(GST_OBJECT_NAME(m_pipeline.get()), '.',
-            gst_element_state_get_name(currentState), '_', gst_element_state_get_name(newState)).utf8();
-        GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN(m_pipeline.get()), GST_DEBUG_GRAPH_SHOW_ALL, dotFileName.data());
 
         GST_DEBUG_OBJECT(pipeline(), "Changed state from %s to %s", gst_element_state_get_name(currentState), gst_element_state_get_name(newState));
 
@@ -2705,10 +2696,10 @@
     // Let also other listeners subscribe to (application) messages in this bus.
     auto bus = adoptGRef(gst_pipeline_get_bus(GST_PIPELINE(m_pipeline.get())));
     gst_bus_enable_sync_message_emission(bus.get());
-    gst_bus_add_signal_watch_full(bus.get(), RunLoopSourcePriority::RunLoopDispatcher);
-    g_signal_connect_swapped(bus.get(), "message", G_CALLBACK(+[](MediaPlayerPrivateGStreamer* player, GstMessage* message) {
-        player->handleMessage(message);
-    }), this);
+    connectSimpleBusMessageCallback(m_pipeline.get(), [this](GstMessage* message) {
+        handleMessage(message);
+    });
+
     g_signal_connect_swapped(bus.get(), "sync-message::need-context", G_CALLBACK(+[](MediaPlayerPrivateGStreamer* player, GstMessage* message) {
         player->handleNeedContextMessage(message);
     }), this);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to