Skip to content

Commit

Permalink
[GStreamer][WebAudio] Misc cleanups
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=262183

Reviewed by Xabier Rodriguez-Calvar.

The source pad caps don't change, so we can build and store the GstAudioInfo once instead of for
every push iteration. webKitWebAudioSrcAllocateBuffers was also renamed to
webKitWebAudioSrcAllocateBuffer for consistency.

* Source/WebCore/platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp:
(webKitWebAudioSrcConstructed):
(webKitWebAudioSrcAllocateBuffer):
(webKitWebAudioSrcRenderIteration):
(webKitWebAudioSrcAllocateBuffers): Deleted.

Canonical link: https://commits.webkit.org/268584@main
  • Loading branch information
philn committed Sep 28, 2023
1 parent f025f71 commit fe502bf
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ struct _WebKitWebAudioSrcPrivate {

GRefPtr<GstElement> source;
GRefPtr<GstCaps> caps;
GstAudioInfo info;

// src pad of the element, interleaved wav data is pushed to it.
GstPad* sourcePad;
Expand Down Expand Up @@ -228,6 +229,7 @@ static void webKitWebAudioSrcConstructed(GObject* object)

priv->source = makeGStreamerElement("appsrc", "webaudioSrc");
priv->caps = adoptGRef(getGStreamerAudioCaps(priv->sampleRate, priv->bus->numberOfChannels()));
gst_audio_info_from_caps(&priv->info, priv->caps.get());

// Configure the appsrc for minimal latency.
g_object_set(priv->source.get(), "max-bytes", static_cast<guint64>(2 * priv->bufferSize * priv->bus->numberOfChannels()), "block", TRUE,
Expand Down Expand Up @@ -289,7 +291,7 @@ static void webKitWebAudioSrcGetProperty(GObject* object, guint propertyId, GVal
}
}

static GRefPtr<GstBuffer> webKitWebAudioSrcAllocateBuffers(WebKitWebAudioSrc* src)
static GRefPtr<GstBuffer> webKitWebAudioSrcAllocateBuffer(WebKitWebAudioSrc* src)
{
WebKitWebAudioSrcPrivate* priv = src->priv;

Expand All @@ -313,17 +315,15 @@ static GRefPtr<GstBuffer> webKitWebAudioSrcAllocateBuffers(WebKitWebAudioSrc* sr
}

ASSERT(buffer);
ASSERT(priv->caps);

// Attach audio meta on buffer.
GstAudioInfo info;
gst_audio_info_from_caps(&info, priv->caps.get());
gst_buffer_add_audio_meta(buffer.get(), &info, priv->framesToPull, nullptr);
ASSERT(&priv->info);
gst_buffer_add_audio_meta(buffer.get(), &priv->info, priv->framesToPull, nullptr);

GstMappedBuffer mappedBuffer(buffer.get(), GST_MAP_READWRITE);
ASSERT(mappedBuffer);
for (unsigned channelIndex = 0; channelIndex < priv->bus->numberOfChannels(); channelIndex++)
priv->bus->setChannelMemory(channelIndex, reinterpret_cast<float*>(mappedBuffer.data() + channelIndex * priv->bufferSize), priv->framesToPull);
{
GstMappedBuffer mappedBuffer(buffer.get(), GST_MAP_READ);
ASSERT(mappedBuffer);
for (unsigned channelIndex = 0; channelIndex < priv->bus->numberOfChannels(); channelIndex++)
priv->bus->setChannelMemory(channelIndex, reinterpret_cast<float*>(mappedBuffer.data() + channelIndex * priv->bufferSize), priv->framesToPull);
}

return buffer;
}
Expand Down Expand Up @@ -381,7 +381,7 @@ static void webKitWebAudioSrcRenderAndPushFrames(const GRefPtr<GstElement>& elem
static void webKitWebAudioSrcRenderIteration(WebKitWebAudioSrc* src)
{
auto* priv = src->priv;
auto buffer = webKitWebAudioSrcAllocateBuffers(src);
auto buffer = webKitWebAudioSrcAllocateBuffer(src);
if (!buffer) {
gst_task_stop(priv->task.get());
return;
Expand Down

0 comments on commit fe502bf

Please sign in to comment.