Skip to content
Permalink
Browse files
[GStreamer][MediaStream] AudioSource triggering critical warnings
https://bugs.webkit.org/show_bug.cgi?id=224180

Patch by Philippe Normand <pnormand@igalia.com> on 2021-04-06
Reviewed by Xabier Rodriguez-Calvar.

Keep track of audio channel offsets and store them as metadata in audio buffers. This is
used by downstream elements such as the audio convert elements.

* Modules/webaudio/MediaStreamAudioSourceGStreamer.cpp:
(WebCore::copyBusData):
(WebCore::MediaStreamAudioSource::consumeAudio):

Canonical link: https://commits.webkit.org/236167@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@275510 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
philn authored and webkit-commit-queue committed Apr 6, 2021
1 parent e15d654 commit 09faeb2b7a8894fa6a2cd1ee7b5d6da241937026
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
@@ -1,3 +1,17 @@
2021-04-06 Philippe Normand <pnormand@igalia.com>

[GStreamer][MediaStream] AudioSource triggering critical warnings
https://bugs.webkit.org/show_bug.cgi?id=224180

Reviewed by Xabier Rodriguez-Calvar.

Keep track of audio channel offsets and store them as metadata in audio buffers. This is
used by downstream elements such as the audio convert elements.

* Modules/webaudio/MediaStreamAudioSourceGStreamer.cpp:
(WebCore::copyBusData):
(WebCore::MediaStreamAudioSource::consumeAudio):

2021-04-06 Antti Koivisto <antti@apple.com>

[LFC][Integration] Disable LFC if paginated context has inline boxes
@@ -29,20 +29,25 @@

namespace WebCore {

static void copyBusData(AudioBus& bus, GstBuffer* buffer, bool isMuted)
static Vector<size_t> copyBusData(AudioBus& bus, GstBuffer* buffer, bool isMuted)
{
Vector<size_t> offsets;
GstMappedBuffer mappedBuffer(buffer, GST_MAP_WRITE);
if (isMuted) {
memset(mappedBuffer.data(), 0, mappedBuffer.size());
return;
return offsets;
}

DisableMallocRestrictionsForCurrentThreadScope disableMallocRestrictions;
offsets.reserveInitialCapacity(sizeof(size_t) * bus.numberOfChannels());
size_t size = mappedBuffer.size() / bus.numberOfChannels();
for (size_t channelIndex = 0; channelIndex < bus.numberOfChannels(); ++channelIndex) {
AudioChannel& channel = *bus.channel(channelIndex);
float* destination = reinterpret_cast<float*>(mappedBuffer.data() + (channelIndex * size));
memcpy(destination, channel.data(), size);
const auto& channel = *bus.channel(channelIndex);
auto offset = reinterpret_cast<size_t>(channelIndex * size);
memcpy(reinterpret_cast<float*>(mappedBuffer.data() + offset), channel.data(), sizeof(float) * channel.length());
offsets.uncheckedAppend(offset);
}
return offsets;
}

void MediaStreamAudioSource::consumeAudio(AudioBus& bus, size_t numberOfFrames)
@@ -62,7 +67,12 @@ void MediaStreamAudioSource::consumeAudio(AudioBus& bus, size_t numberOfFrames)

auto caps = adoptGRef(gst_audio_info_to_caps(&info));
auto buffer = adoptGRef(gst_buffer_new_allocate(nullptr, size, nullptr));
copyBusData(bus, buffer.get(), muted());
auto offsets = copyBusData(bus, buffer.get(), muted());
#if GST_CHECK_VERSION(1, 16, 0)
gst_buffer_add_audio_meta(buffer.get(), &info, numberOfFrames, offsets.data());
#else
UNUSED_VARIABLE(offsets);
#endif
auto sample = adoptGRef(gst_sample_new(buffer.get(), caps.get(), nullptr, nullptr));
GStreamerAudioData audioBuffer(WTFMove(sample), info);
GStreamerAudioStreamDescription description(&info);

0 comments on commit 09faeb2

Please sign in to comment.