Title: [268579] trunk/Source/WebCore
Revision
268579
Author
[email protected]
Date
2020-10-16 04:22:06 -0700 (Fri, 16 Oct 2020)

Log Message

[GStreamer] Audio worklet support
https://bugs.webkit.org/show_bug.cgi?id=217760

Reviewed by Xabier Rodriguez-Calvar.

This patch hooks WebAudio worklet rendering support into the GStreamer WebAudio backend.

* platform/audio/gstreamer/AudioDestinationGStreamer.cpp:
(WebCore::AudioDestinationGStreamer::AudioDestinationGStreamer):
(WebCore::AudioDestinationGStreamer::start): Set the render callback if it was provided.
* platform/audio/gstreamer/AudioDestinationGStreamer.h:
* platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp:
(webKitWebAudioSrcAllocateBuffersAndRenderAudio): Invoke the bus rendering through the
render callback if it was set.
(webkitWebAudioSourceSetDispatchToRenderThreadCallback):
* platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (268578 => 268579)


--- trunk/Source/WebCore/ChangeLog	2020-10-16 10:55:59 UTC (rev 268578)
+++ trunk/Source/WebCore/ChangeLog	2020-10-16 11:22:06 UTC (rev 268579)
@@ -1,3 +1,22 @@
+2020-10-16  Philippe Normand  <[email protected]>
+
+        [GStreamer] Audio worklet support
+        https://bugs.webkit.org/show_bug.cgi?id=217760
+
+        Reviewed by Xabier Rodriguez-Calvar.
+
+        This patch hooks WebAudio worklet rendering support into the GStreamer WebAudio backend.
+
+        * platform/audio/gstreamer/AudioDestinationGStreamer.cpp:
+        (WebCore::AudioDestinationGStreamer::AudioDestinationGStreamer):
+        (WebCore::AudioDestinationGStreamer::start): Set the render callback if it was provided.
+        * platform/audio/gstreamer/AudioDestinationGStreamer.h:
+        * platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp:
+        (webKitWebAudioSrcAllocateBuffersAndRenderAudio): Invoke the bus rendering through the
+        render callback if it was set.
+        (webkitWebAudioSourceSetDispatchToRenderThreadCallback):
+        * platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.h:
+
 2020-10-16  Kimmo Kinnunen  <[email protected]>
 
         Refactor WebGL implementation to use only GraphicsContextGL part 1

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


--- trunk/Source/WebCore/platform/audio/gstreamer/AudioDestinationGStreamer.cpp	2020-10-16 10:55:59 UTC (rev 268578)
+++ trunk/Source/WebCore/platform/audio/gstreamer/AudioDestinationGStreamer.cpp	2020-10-16 11:22:06 UTC (rev 268579)
@@ -87,11 +87,8 @@
     gst_bus_add_signal_watch_full(bus.get(), RunLoopSourcePriority::RunLoopDispatcher);
     g_signal_connect(bus.get(), "message", G_CALLBACK(messageCallback), this);
 
-    GstElement* webkitAudioSrc = reinterpret_cast<GstElement*>(g_object_new(WEBKIT_TYPE_WEB_AUDIO_SRC,
-                                                                            "rate", sampleRate,
-                                                                            "bus", m_renderBus.get(),
-                                                                            "provider", &m_callback,
-                                                                            "frames", AudioUtilities::renderQuantumSize, nullptr));
+    m_src = reinterpret_cast<GstElement*>(g_object_new(WEBKIT_TYPE_WEB_AUDIO_SRC, "rate", sampleRate,
+        "bus", m_renderBus.get(), "provider", &m_callback, "frames", AudioUtilities::renderQuantumSize, nullptr));
 
     GRefPtr<GstElement> audioSink = createPlatformAudioSink();
     m_audioSinkAvailable = audioSink;
@@ -119,10 +116,10 @@
 
     GstElement* audioConvert = gst_element_factory_make("audioconvert", nullptr);
     GstElement* audioResample = gst_element_factory_make("audioresample", nullptr);
-    gst_bin_add_many(GST_BIN_CAST(m_pipeline), webkitAudioSrc, audioConvert, audioResample, audioSink.get(), nullptr);
+    gst_bin_add_many(GST_BIN_CAST(m_pipeline), m_src.get(), audioConvert, audioResample, audioSink.get(), nullptr);
 
     // Link src pads from webkitAudioSrc to audioConvert ! audioResample ! autoaudiosink.
-    gst_element_link_pads_full(webkitAudioSrc, "src", audioConvert, "sink", GST_PAD_LINK_CHECK_NOTHING);
+    gst_element_link_pads_full(m_src.get(), "src", audioConvert, "sink", GST_PAD_LINK_CHECK_NOTHING);
     gst_element_link_pads_full(audioConvert, "src", audioResample, "sink", GST_PAD_LINK_CHECK_NOTHING);
     gst_element_link_pads_full(audioResample, "src", audioSink.get(), "sink", GST_PAD_LINK_CHECK_NOTHING);
 }
@@ -165,12 +162,15 @@
     return TRUE;
 }
 
-void AudioDestinationGStreamer::start(Function<void(Function<void()>&&)>&&)
+void AudioDestinationGStreamer::start(Function<void(Function<void()>&&)>&& dispatchToRenderThread)
 {
     ASSERT(m_audioSinkAvailable);
     if (!m_audioSinkAvailable)
         return;
 
+    if (dispatchToRenderThread)
+        webkitWebAudioSourceSetDispatchToRenderThreadCallback(WEBKIT_WEB_AUDIO_SRC(m_src.get()), WTFMove(dispatchToRenderThread));
+
     if (gst_element_set_state(m_pipeline, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
         g_warning("Error: Failed to set pipeline to playing");
         m_isPlaying = false;

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


--- trunk/Source/WebCore/platform/audio/gstreamer/AudioDestinationGStreamer.h	2020-10-16 10:55:59 UTC (rev 268578)
+++ trunk/Source/WebCore/platform/audio/gstreamer/AudioDestinationGStreamer.h	2020-10-16 11:22:06 UTC (rev 268579)
@@ -21,7 +21,8 @@
 
 #include "AudioBus.h"
 #include "AudioDestination.h"
-#include <wtf/RefPtr.h>
+#include "GRefPtrGStreamer.h"
+#include <wtf/Forward.h>
 
 typedef struct _GstElement GstElement;
 typedef struct _GstPad GstPad;
@@ -52,6 +53,7 @@
     bool m_isPlaying;
     bool m_audioSinkAvailable;
     GstElement* m_pipeline;
+    GRefPtr<GstElement> m_src;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp (268578 => 268579)


--- trunk/Source/WebCore/platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp	2020-10-16 10:55:59 UTC (rev 268578)
+++ trunk/Source/WebCore/platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp	2020-10-16 11:22:06 UTC (rev 268579)
@@ -30,6 +30,8 @@
 #include <gst/app/gstappsrc.h>
 #include <gst/audio/audio-info.h>
 #include <gst/pbutils/missing-plugins.h>
+#include <wtf/Condition.h>
+#include <wtf/Lock.h>
 #include <wtf/glib/GUniquePtr.h>
 #include <wtf/glib/WTFGType.h>
 
@@ -77,6 +79,10 @@
 
     bool enableGapBufferSupport;
 
+    Optional<Function<void(Function<void()>&&)>> dispatchToRenderThreadCallback;
+    Lock dispatchMutex;
+    Condition dispatchCondition;
+
     _WebKitWebAudioSrcPrivate()
     {
         sourcePad = webkitGstGhostPadFromStaticTemplate(&srcTemplate, "src", nullptr);
@@ -340,8 +346,18 @@
     }
 
     // FIXME: Add support for local/live audio input.
-    priv->provider->render(nullptr, priv->bus, priv->framesToPull, outputTimestamp);
 
+    if (src->priv->dispatchToRenderThreadCallback.hasValue()) {
+        LockHolder holder(priv->dispatchMutex);
+        (*priv->dispatchToRenderThreadCallback)([src, outputTimestamp]() mutable {
+            auto* priv = src->priv;
+            priv->provider->render(nullptr, priv->bus, priv->framesToPull, outputTimestamp);
+            priv->dispatchCondition.notifyOne();
+        });
+        priv->dispatchCondition.wait(priv->dispatchMutex);
+    } else
+        priv->provider->render(nullptr, priv->bus, priv->framesToPull, outputTimestamp);
+
     return makeOptional(channelBufferList);
 }
 
@@ -434,4 +450,10 @@
     return returnValue;
 }
 
+void webkitWebAudioSourceSetDispatchToRenderThreadCallback(WebKitWebAudioSrc* src, Function<void(Function<void()>&&)>&& function)
+{
+    ASSERT(function);
+    src->priv->dispatchToRenderThreadCallback = WTFMove(function);
+}
+
 #endif // ENABLE(WEB_AUDIO) && USE(GSTREAMER)

Modified: trunk/Source/WebCore/platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.h (268578 => 268579)


--- trunk/Source/WebCore/platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.h	2020-10-16 10:55:59 UTC (rev 268578)
+++ trunk/Source/WebCore/platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.h	2020-10-16 11:22:06 UTC (rev 268579)
@@ -16,11 +16,12 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#ifndef WebKitWebAudioSourceGStreamer_h
-#define WebKitWebAudioSourceGStreamer_h
+#pragma once
+
 #if USE(GSTREAMER)
 
 #include <gst/gst.h>
+#include <wtf/Forward.h>
 
 #define WEBKIT_TYPE_WEB_AUDIO_SRC (webkit_web_audio_src_get_type())
 #define WEBKIT_WEB_AUDIO_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEB_AUDIO_SRC, WebKitWebAudioSrc))
@@ -29,5 +30,7 @@
 
 GType webkit_web_audio_src_get_type();
 
+void webkitWebAudioSourceSetDispatchToRenderThreadCallback(WebKitWebAudioSrc*, Function<void(Function<void()>&&)>&&);
+
 #endif // USE(GSTREAMER)
-#endif
+
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to