Diff
Modified: trunk/Source/WebCore/ChangeLog (270960 => 270961)
--- trunk/Source/WebCore/ChangeLog 2020-12-17 23:47:56 UTC (rev 270960)
+++ trunk/Source/WebCore/ChangeLog 2020-12-18 01:21:42 UTC (rev 270961)
@@ -1,3 +1,60 @@
+2020-12-17 Chris Dumez <[email protected]>
+
+ [GPUProcess] https://www.waveplayer.info/createmediaelementsource-test/ demo is flaky
+ https://bugs.webkit.org/show_bug.cgi?id=219951
+
+ Reviewed by Geoff Garen.
+
+ The issue was with the following line in AudioSourceProviderAVFObjC::prepare:
+ `m_ringBuffer = m_ringBufferCallback(description, capacity).moveToUniquePtr();`
+
+ In the case where m_ringBuffer was non-null before the assignment, we would have
+ 2 RingBuffers that would coexist for a very small period of time. When the new
+ one was created, we would send an IPC to the remote process with the shared
+ memory handle of the new RingBuffer. However, very shortly after, the old
+ ring buffer would get destroyed, causing us to send another IPC to the remote
+ process with a null handle (since the shared memory associated with the old
+ ring buffer is getting destroyed). As a result, of this ordering issue, the
+ remote process would end up with a RingBuffer with a null shared memory handle
+ and no audio would be rendered.
+
+ We could have addressed the issue like so:
+ ```
+ m_ringBuffer = nullptr;
+ m_ringBuffer = m_ringBufferCallback(description, capacity).moveToUniquePtr();
+ ```
+ However, this would be super fragile. Instead, I have made the following changes:
+ 1. If there is already a ringBuffer, reuse it instead of reconstructing it.
+ Calling allocate() with the new parameters on the existing ring buffer is
+ sufficient in this case.
+ 2. Because of 1, the ring buffer creation callback no longer needs to call
+ CARingBuffer::allocate().
+
+ I also made the following changes to make the code simpler and to reduce code
+ duplication:
+ - The storage change handler passed to SharedRingBufferStorage is now given
+ as parameter the CAAudioStreamDescription & frameCount. What the handler
+ always does is send an IPC to the remote process to tell it that the
+ storage changed and in all cases, it needs to provide these 2 parameters
+ as well. This is because the remote process will need to call
+ CARingBuffer::allocate(), which requires those 2 parameters. This
+ simplifies our code in some cases since we no longer need a mechanism
+ to retrieve those 2 parameters from inside the storage change handler.
+ - The logic of the StorageChange IPC recipient to update its ringbuffer
+ with the new shared memory handle is complicated and was duplicated
+ in a LOT of places. To address this, I introduced a new
+ SharedRingBufferStorage::updateReadOnlyStorage() function which does
+ exactly what we need.
+
+ * platform/audio/cocoa/CARingBuffer.cpp:
+ (WebCore::CARingBuffer::allocate):
+ * platform/audio/cocoa/CARingBuffer.h:
+ * platform/graphics/avfoundation/AudioSourceProviderAVFObjC.h:
+ * platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm:
+ (WebCore::AudioSourceProviderAVFObjC::AudioSourceProviderAVFObjC):
+ (WebCore::AudioSourceProviderAVFObjC::prepare):
+ (WebCore::AudioSourceProviderAVFObjC::setRingBufferCreationCallback):
+
2020-12-17 Zalan Bujtas <[email protected]>
[LFC][IFC] Reserve vector capacity for inline runs and line boxes
Modified: trunk/Source/WebCore/platform/audio/cocoa/CARingBuffer.cpp (270960 => 270961)
--- trunk/Source/WebCore/platform/audio/cocoa/CARingBuffer.cpp 2020-12-17 23:47:56 UTC (rev 270960)
+++ trunk/Source/WebCore/platform/audio/cocoa/CARingBuffer.cpp 2020-12-18 01:21:42 UTC (rev 270961)
@@ -71,7 +71,7 @@
m_frameCountMask = frameCount - 1;
m_capacityBytes = m_bytesPerFrame * frameCount;
- m_buffers->allocate(m_capacityBytes * m_channelCount);
+ m_buffers->allocate(m_capacityBytes * m_channelCount, format, frameCount);
m_pointers.resize(m_channelCount);
Byte* channelData = static_cast<Byte*>(m_buffers->data());
Modified: trunk/Source/WebCore/platform/audio/cocoa/CARingBuffer.h (270960 => 270961)
--- trunk/Source/WebCore/platform/audio/cocoa/CARingBuffer.h 2020-12-17 23:47:56 UTC (rev 270960)
+++ trunk/Source/WebCore/platform/audio/cocoa/CARingBuffer.h 2020-12-18 01:21:42 UTC (rev 270961)
@@ -42,7 +42,7 @@
WTF_MAKE_FAST_ALLOCATED;
public:
virtual ~CARingBufferStorage() = default;
- virtual void allocate(size_t) = 0;
+ virtual void allocate(size_t, const CAAudioStreamDescription& format, size_t frameCount) = 0;
virtual void deallocate() = 0;
virtual void* data() = 0;
virtual void getCurrentFrameBounds(uint64_t& startTime, uint64_t& endTime) = 0;
@@ -59,7 +59,7 @@
~CARingBufferStorageVector() = default;
private:
- void allocate(size_t byteCount) final { m_buffer.grow(byteCount); }
+ void allocate(size_t byteCount, const CAAudioStreamDescription&, size_t) final { m_buffer.grow(byteCount); }
void deallocate() final { m_buffer.clear(); }
void* data() final { return m_buffer.data(); }
void getCurrentFrameBounds(uint64_t& startTime, uint64_t& endTime) final;
@@ -98,7 +98,7 @@
TooMuch, // fetch start time is earlier than buffer start time and fetch end time is later than buffer end time
};
- WEBCORE_EXPORT void allocate(const CAAudioStreamDescription&, size_t);
+ WEBCORE_EXPORT void allocate(const CAAudioStreamDescription&, size_t frameCount);
WEBCORE_EXPORT void deallocate();
WEBCORE_EXPORT Error store(const AudioBufferList*, size_t frameCount, uint64_t startFrame);
Modified: trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.h (270960 => 270961)
--- trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.h 2020-12-17 23:47:56 UTC (rev 270960)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.h 2020-12-18 01:21:42 UTC (rev 270961)
@@ -63,7 +63,7 @@
using AudioCallback = Function<void(uint64_t startFrame, uint64_t numberOfFrames)>;
WEBCORE_EXPORT void setAudioCallback(AudioCallback&&);
- using RingBufferCreationCallback = Function<UniqueRef<CARingBuffer>(const CAAudioStreamDescription&, size_t)>;
+ using RingBufferCreationCallback = Function<UniqueRef<CARingBuffer>()>;
WEBCORE_EXPORT void setRingBufferCreationCallback(RingBufferCreationCallback&&);
private:
@@ -111,7 +111,7 @@
class TapStorage;
RefPtr<TapStorage> m_tapStorage;
AudioCallback m_audioCallback;
- RingBufferCreationCallback m_ringBufferCallback;
+ RingBufferCreationCallback m_ringBufferCreationCallback;
};
}
Modified: trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm (270960 => 270961)
--- trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm 2020-12-17 23:47:56 UTC (rev 270960)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm 2020-12-18 01:21:42 UTC (rev 270961)
@@ -80,6 +80,7 @@
AudioSourceProviderAVFObjC::AudioSourceProviderAVFObjC(AVPlayerItem *item)
: m_avPlayerItem(item)
+ , m_ringBufferCreationCallback([] { return makeUniqueRef<CARingBuffer>(); })
{
}
@@ -338,12 +339,9 @@
size_t capacity = std::max(static_cast<size_t>(2 * maxFrames), static_cast<size_t>(kRingBufferDuration * sampleRate));
CAAudioStreamDescription description { *processingFormat };
- if (m_ringBufferCallback)
- m_ringBuffer = m_ringBufferCallback(description, capacity).moveToUniquePtr();
- else {
- m_ringBuffer = makeUnique<CARingBuffer>();
- m_ringBuffer->allocate(description, capacity);
- }
+ if (!m_ringBuffer)
+ m_ringBuffer = m_ringBufferCreationCallback().moveToUniquePtr();
+ m_ringBuffer->allocate(description, capacity);
// AudioBufferList is a variable-length struct, so create on the heap with a generic new() operator
// with a custom size, and initialize the struct manually.
@@ -438,7 +436,7 @@
void AudioSourceProviderAVFObjC::setRingBufferCreationCallback(RingBufferCreationCallback&& callback)
{
ASSERT(!m_avAudioMix);
- m_ringBufferCallback = WTFMove(callback);
+ m_ringBufferCreationCallback = WTFMove(callback);
}
}
Modified: trunk/Source/WebKit/ChangeLog (270960 => 270961)
--- trunk/Source/WebKit/ChangeLog 2020-12-17 23:47:56 UTC (rev 270960)
+++ trunk/Source/WebKit/ChangeLog 2020-12-18 01:21:42 UTC (rev 270961)
@@ -1,5 +1,94 @@
2020-12-17 Chris Dumez <[email protected]>
+ [GPUProcess] https://www.waveplayer.info/createmediaelementsource-test/ demo is flaky
+ https://bugs.webkit.org/show_bug.cgi?id=219951
+
+ Reviewed by Geoff Garen.
+
+ The issue was with the following line in AudioSourceProviderAVFObjC::prepare:
+ `m_ringBuffer = m_ringBufferCallback(description, capacity).moveToUniquePtr();`
+
+ In the case where m_ringBuffer was non-null before the assignment, we would have
+ 2 RingBuffers that would coexist for a very small period of time. When the new
+ one was created, we would send an IPC to the remote process with the shared
+ memory handle of the new RingBuffer. However, very shortly after, the old
+ ring buffer would get destroyed, causing us to send another IPC to the remote
+ process with a null handle (since the shared memory associated with the old
+ ring buffer is getting destroyed). As a result, of this ordering issue, the
+ remote process would end up with a RingBuffer with a null shared memory handle
+ and no audio would be rendered.
+
+ We could have addressed the issue like so:
+ ```
+ m_ringBuffer = nullptr;
+ m_ringBuffer = m_ringBufferCallback(description, capacity).moveToUniquePtr();
+ ```
+ However, this would be super fragile. Instead, I have made the following changes:
+ 1. If there is already a ringBuffer, reuse it instead of reconstructing it.
+ Calling allocate() with the new parameters on the existing ring buffer is
+ sufficient in this case.
+ 2. Because of 1, the ring buffer creation callback no longer needs to call
+ CARingBuffer::allocate().
+
+ I also made the following changes to make the code simpler and to reduce code
+ duplication:
+ - The storage change handler passed to SharedRingBufferStorage is now given
+ as parameter the CAAudioStreamDescription & frameCount. What the handler
+ always does is send an IPC to the remote process to tell it that the
+ storage changed and in all cases, it needs to provide these 2 parameters
+ as well. This is because the remote process will need to call
+ CARingBuffer::allocate(), which requires those 2 parameters. This
+ simplifies our code in some cases since we no longer need a mechanism
+ to retrieve those 2 parameters from inside the storage change handler.
+ - The logic of the StorageChange IPC recipient to update its ringbuffer
+ with the new shared memory handle is complicated and was duplicated
+ in a LOT of places. To address this, I introduced a new
+ SharedRingBufferStorage::updateReadOnlyStorage() function which does
+ exactly what we need.
+
+ * GPUProcess/media/RemoteAudioDestinationManager.cpp:
+ (WebKit::RemoteAudioDestination::audioSamplesStorageChanged):
+ * GPUProcess/media/RemoteAudioSourceProviderProxy.cpp:
+ (WebKit::RemoteAudioSourceProviderProxy::create):
+ (WebKit::RemoteAudioSourceProviderProxy::createRingBuffer):
+ (WebKit::RemoteAudioSourceProviderProxy::storageChanged):
+ * GPUProcess/media/RemoteAudioSourceProviderProxy.h:
+ * GPUProcess/webrtc/RemoteAudioMediaStreamTrackRenderer.cpp:
+ (WebKit::RemoteAudioMediaStreamTrackRenderer::audioSamplesStorageChanged):
+ * GPUProcess/webrtc/RemoteMediaRecorder.cpp:
+ (WebKit::RemoteMediaRecorder::audioSamplesStorageChanged):
+ * Shared/Cocoa/SharedRingBufferStorage.cpp:
+ (WebKit::SharedRingBufferStorage::setStorage):
+ (WebKit::SharedRingBufferStorage::updateReadOnlyStorage):
+ (WebKit::SharedRingBufferStorage::allocate):
+ (WebKit::SharedRingBufferStorage::deallocate):
+ * Shared/Cocoa/SharedRingBufferStorage.h:
+ (WebKit::SharedRingBufferStorage::SharedRingBufferStorage):
+ (WebKit::SharedRingBufferStorage::storage const):
+ * UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp:
+ (WebKit::UserMediaCaptureManagerProxy::SourceProxy::SourceProxy):
+ (WebKit::UserMediaCaptureManagerProxy::SourceProxy::storageChanged):
+ * UIProcess/SpeechRecognitionRemoteRealtimeMediaSource.cpp:
+ (WebKit::SpeechRecognitionRemoteRealtimeMediaSource::setStorage):
+ * WebProcess/GPU/media/RemoteAudioDestinationProxy.cpp:
+ (WebKit::RemoteAudioDestinationProxy::RemoteAudioDestinationProxy):
+ (WebKit::RemoteAudioDestinationProxy::storageChanged):
+ * WebProcess/GPU/media/RemoteAudioDestinationProxy.h:
+ * WebProcess/GPU/media/RemoteAudioSourceProviderManager.cpp:
+ (WebKit::RemoteAudioSourceProviderManager::RemoteAudio::setStorage):
+ * WebProcess/GPU/webrtc/AudioMediaStreamTrackRenderer.cpp:
+ (WebKit::AudioMediaStreamTrackRenderer::AudioMediaStreamTrackRenderer):
+ (WebKit::AudioMediaStreamTrackRenderer::storageChanged):
+ * WebProcess/GPU/webrtc/AudioMediaStreamTrackRenderer.h:
+ * WebProcess/GPU/webrtc/MediaRecorderPrivate.cpp:
+ (WebKit::MediaRecorderPrivate::startRecording):
+ (WebKit::MediaRecorderPrivate::storageChanged):
+ * WebProcess/GPU/webrtc/MediaRecorderPrivate.h:
+ * WebProcess/cocoa/RemoteCaptureSampleManager.cpp:
+ (WebKit::RemoteCaptureSampleManager::RemoteAudio::setStorage):
+
+2020-12-17 Chris Dumez <[email protected]>
+
Unreviewed build fix after r270938.
Add missing include.
Modified: trunk/Source/WebKit/GPUProcess/media/RemoteAudioDestinationManager.cpp (270960 => 270961)
--- trunk/Source/WebKit/GPUProcess/media/RemoteAudioDestinationManager.cpp 2020-12-17 23:47:56 UTC (rev 270960)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteAudioDestinationManager.cpp 2020-12-18 01:21:42 UTC (rev 270961)
@@ -72,19 +72,7 @@
void audioSamplesStorageChanged(const SharedMemory::IPCHandle& ipcHandle, const WebCore::CAAudioStreamDescription& description, uint64_t numberOfFrames)
{
- m_description = description;
-
- if (ipcHandle.handle.isNull()) {
- m_ringBuffer->deallocate();
- storage().setReadOnly(false);
- storage().setStorage(nullptr);
- return;
- }
-
- auto memory = SharedMemory::map(ipcHandle.handle, SharedMemory::Protection::ReadOnly);
- storage().setStorage(WTFMove(memory));
- storage().setReadOnly(true);
- m_ringBuffer->allocate(description, numberOfFrames);
+ storage().updateReadOnlyStorage(m_ringBuffer.get(), ipcHandle.handle, description, numberOfFrames);
}
#endif
@@ -164,7 +152,6 @@
#if PLATFORM(COCOA)
WebCore::AudioOutputUnitAdaptor m_audioOutputUnitAdaptor;
- WebCore::CAAudioStreamDescription m_description;
UniqueRef<WebCore::CARingBuffer> m_ringBuffer;
MachSemaphore m_renderSemaphore;
uint64_t m_startFrame { 0 };
Modified: trunk/Source/WebKit/GPUProcess/media/RemoteAudioSourceProviderProxy.cpp (270960 => 270961)
--- trunk/Source/WebKit/GPUProcess/media/RemoteAudioSourceProviderProxy.cpp 2020-12-17 23:47:56 UTC (rev 270960)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteAudioSourceProviderProxy.cpp 2020-12-18 01:21:42 UTC (rev 270961)
@@ -37,8 +37,8 @@
{
auto remoteProvider = adoptRef(*new RemoteAudioSourceProviderProxy(identifier, WTFMove(connection)));
- localProvider.setRingBufferCreationCallback([remoteProvider](auto description, auto capacity) {
- return remoteProvider->createRingBuffer(description, capacity);
+ localProvider.setRingBufferCreationCallback([remoteProvider]() {
+ return remoteProvider->createRingBuffer();
});
localProvider.setAudioCallback([remoteProvider](auto startFrame, auto numberOfFrames) {
remoteProvider->newAudioSamples(startFrame, numberOfFrames);
@@ -55,15 +55,11 @@
RemoteAudioSourceProviderProxy::~RemoteAudioSourceProviderProxy() = default;
-UniqueRef<CARingBuffer> RemoteAudioSourceProviderProxy::createRingBuffer(const CAAudioStreamDescription& description, size_t capacity)
+UniqueRef<CARingBuffer> RemoteAudioSourceProviderProxy::createRingBuffer()
{
- m_ringBufferDescription = description;
- m_ringBufferCapacity = capacity;
- auto ringBuffer = makeUniqueRef<CARingBuffer>(makeUniqueRef<SharedRingBufferStorage>([protectedThis = makeRef(*this)](SharedMemory* memory) mutable {
- protectedThis->storageChanged(memory);
+ return makeUniqueRef<CARingBuffer>(makeUniqueRef<SharedRingBufferStorage>([protectedThis = makeRef(*this)](SharedMemory* memory, const CAAudioStreamDescription& format, size_t frameCount) mutable {
+ protectedThis->storageChanged(memory, format, frameCount);
}));
- ringBuffer->allocate(description, capacity);
- return ringBuffer;
}
void RemoteAudioSourceProviderProxy::newAudioSamples(uint64_t startFrame, uint64_t numberOfFrames)
@@ -71,7 +67,7 @@
m_connection->send(Messages::RemoteAudioSourceProviderManager::AudioSamplesAvailable { m_identifier, startFrame, numberOfFrames }, 0);
}
-void RemoteAudioSourceProviderProxy::storageChanged(SharedMemory* memory)
+void RemoteAudioSourceProviderProxy::storageChanged(SharedMemory* memory, const CAAudioStreamDescription& format, size_t frameCount)
{
SharedMemory::Handle handle;
if (memory)
@@ -83,7 +79,7 @@
#else
uint64_t dataSize = 0;
#endif
- m_connection->send(Messages::RemoteAudioSourceProviderManager::AudioStorageChanged { m_identifier, SharedMemory::IPCHandle { WTFMove(handle), dataSize }, m_ringBufferDescription, m_ringBufferCapacity }, 0);
+ m_connection->send(Messages::RemoteAudioSourceProviderManager::AudioStorageChanged { m_identifier, SharedMemory::IPCHandle { WTFMove(handle), dataSize }, format, frameCount }, 0);
}
} // namespace WebKit
Modified: trunk/Source/WebKit/GPUProcess/media/RemoteAudioSourceProviderProxy.h (270960 => 270961)
--- trunk/Source/WebKit/GPUProcess/media/RemoteAudioSourceProviderProxy.h 2020-12-17 23:47:56 UTC (rev 270960)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteAudioSourceProviderProxy.h 2020-12-18 01:21:42 UTC (rev 270961)
@@ -47,13 +47,13 @@
static Ref<RemoteAudioSourceProviderProxy> create(WebCore::MediaPlayerIdentifier, Ref<IPC::Connection>&&, WebCore::AudioSourceProviderAVFObjC&);
~RemoteAudioSourceProviderProxy();
- UniqueRef<WebCore::CARingBuffer> createRingBuffer(const WebCore::CAAudioStreamDescription&, size_t);
+ UniqueRef<WebCore::CARingBuffer> createRingBuffer();
void newAudioSamples(uint64_t startFrame, uint64_t endFrame);
private:
RemoteAudioSourceProviderProxy(WebCore::MediaPlayerIdentifier, Ref<IPC::Connection>&&);
- void storageChanged(SharedMemory*);
+ void storageChanged(SharedMemory*, const WebCore::CAAudioStreamDescription& format, size_t frameCount);
// AudioSourceProviderClient
void setFormat(size_t numberOfChannels, float sampleRate) final { }
@@ -60,9 +60,6 @@
WebCore::MediaPlayerIdentifier m_identifier;
Ref<IPC::Connection> m_connection;
-
- WebCore::CAAudioStreamDescription m_ringBufferDescription;
- size_t m_ringBufferCapacity { 0 };
};
} // namespace WebKit
Modified: trunk/Source/WebKit/GPUProcess/webrtc/RemoteAudioMediaStreamTrackRenderer.cpp (270960 => 270961)
--- trunk/Source/WebKit/GPUProcess/webrtc/RemoteAudioMediaStreamTrackRenderer.cpp 2020-12-17 23:47:56 UTC (rev 270960)
+++ trunk/Source/WebKit/GPUProcess/webrtc/RemoteAudioMediaStreamTrackRenderer.cpp 2020-12-18 01:21:42 UTC (rev 270961)
@@ -105,19 +105,8 @@
MESSAGE_CHECK(WebAudioBufferList::isSupportedDescription(description, numberOfFrames));
m_description = description;
- if (ipcHandle.handle.isNull()) {
- m_ringBuffer->deallocate();
- storage().setReadOnly(false);
- storage().setStorage(nullptr);
- return;
- }
+ storage().updateReadOnlyStorage(m_ringBuffer.get(), ipcHandle.handle, description, numberOfFrames);
- auto memory = SharedMemory::map(ipcHandle.handle, SharedMemory::Protection::ReadOnly);
- storage().setStorage(WTFMove(memory));
- storage().setReadOnly(true);
-
- m_ringBuffer->allocate(description, numberOfFrames);
-
m_audioBufferList = makeUnique<WebAudioBufferList>(m_description);
}
Modified: trunk/Source/WebKit/GPUProcess/webrtc/RemoteMediaRecorder.cpp (270960 => 270961)
--- trunk/Source/WebKit/GPUProcess/webrtc/RemoteMediaRecorder.cpp 2020-12-17 23:47:56 UTC (rev 270960)
+++ trunk/Source/WebKit/GPUProcess/webrtc/RemoteMediaRecorder.cpp 2020-12-18 01:21:42 UTC (rev 270961)
@@ -74,18 +74,7 @@
m_description = description;
- if (ipcHandle.handle.isNull()) {
- m_ringBuffer->deallocate();
- storage().setReadOnly(false);
- storage().setStorage(nullptr);
- return;
- }
-
- auto memory = SharedMemory::map(ipcHandle.handle, SharedMemory::Protection::ReadOnly);
- storage().setStorage(WTFMove(memory));
- storage().setReadOnly(true);
-
- m_ringBuffer->allocate(m_description, numberOfFrames);
+ storage().updateReadOnlyStorage(*m_ringBuffer, ipcHandle.handle, description, numberOfFrames);
m_audioBufferList = makeUnique<WebAudioBufferList>(m_description);
}
Modified: trunk/Source/WebKit/Shared/Cocoa/SharedRingBufferStorage.cpp (270960 => 270961)
--- trunk/Source/WebKit/Shared/Cocoa/SharedRingBufferStorage.cpp 2020-12-17 23:47:56 UTC (rev 270960)
+++ trunk/Source/WebKit/Shared/Cocoa/SharedRingBufferStorage.cpp 2020-12-18 01:21:42 UTC (rev 270961)
@@ -28,28 +28,39 @@
#if USE(MEDIATOOLBOX)
+#include <WebCore/CARingBuffer.h>
+
namespace WebKit {
-void SharedRingBufferStorage::setStorage(RefPtr<SharedMemory>&& storage)
+void SharedRingBufferStorage::setStorage(RefPtr<SharedMemory>&& storage, const CAAudioStreamDescription& format, size_t frameCount)
{
ASSERT(storage || !m_readOnly);
m_storage = WTFMove(storage);
if (m_storageChangedHandler)
- m_storageChangedHandler(m_storage.get());
+ m_storageChangedHandler(m_storage.get(), format, frameCount);
}
-void SharedRingBufferStorage::setReadOnly(bool readOnly)
+void SharedRingBufferStorage::updateReadOnlyStorage(WebCore::CARingBuffer& ringBuffer, const SharedMemory::Handle& handle, const CAAudioStreamDescription& format, size_t frameCount)
{
- ASSERT(m_storage || !readOnly);
- m_readOnly = readOnly;
+ if (handle.isNull()) {
+ ringBuffer.deallocate();
+ m_readOnly = false;
+ m_storage = nullptr;
+ return;
+ }
+
+ auto memory = SharedMemory::map(handle, SharedMemory::Protection::ReadOnly);
+ m_storage = WTFMove(memory);
+ m_readOnly = true;
+ ringBuffer.allocate(format, frameCount);
}
-void SharedRingBufferStorage::allocate(size_t byteCount)
+void SharedRingBufferStorage::allocate(size_t byteCount, const CAAudioStreamDescription& format, size_t frameCount)
{
if (!m_readOnly) {
auto sharedMemory = SharedMemory::allocate(byteCount + sizeof(FrameBounds));
new (NotNull, sharedMemory->data()) FrameBounds;
- setStorage(WTFMove(sharedMemory));
+ setStorage(WTFMove(sharedMemory), format, frameCount);
}
}
@@ -56,7 +67,7 @@
void SharedRingBufferStorage::deallocate()
{
if (!m_readOnly)
- setStorage(nullptr);
+ setStorage(nullptr, { }, 0);
}
auto SharedRingBufferStorage::sharedFrameBounds() const -> FrameBounds*
Modified: trunk/Source/WebKit/Shared/Cocoa/SharedRingBufferStorage.h (270960 => 270961)
--- trunk/Source/WebKit/Shared/Cocoa/SharedRingBufferStorage.h 2020-12-17 23:47:56 UTC (rev 270960)
+++ trunk/Source/WebKit/Shared/Cocoa/SharedRingBufferStorage.h 2020-12-18 01:21:42 UTC (rev 270961)
@@ -32,11 +32,15 @@
#include <WebCore/CARingBuffer.h>
#include <wtf/Function.h>
+namespace WebCore {
+class CARingBuffer;
+}
+
namespace WebKit {
class SharedRingBufferStorage : public WebCore::CARingBufferStorage {
public:
- SharedRingBufferStorage(Function<void(SharedMemory*)>&& storageChangedHandler = nullptr)
+ SharedRingBufferStorage(Function<void(SharedMemory*, const WebCore::CAAudioStreamDescription& format, size_t frameCount)>&& storageChangedHandler = nullptr)
: m_storageChangedHandler(WTFMove(storageChangedHandler))
{
}
@@ -43,14 +47,11 @@
void invalidate() { m_storageChangedHandler = nullptr; }
- RefPtr<SharedMemory> storage() const { return m_storage; }
- void setStorage(RefPtr<SharedMemory>&&);
+ SharedMemory* storage() const { return m_storage.get(); }
+ void updateReadOnlyStorage(WebCore::CARingBuffer&, const SharedMemory::Handle&, const WebCore::CAAudioStreamDescription& format, size_t frameCount);
- bool readOnly() const { return m_readOnly; }
- void setReadOnly(bool);
-
// WebCore::CARingBufferStorage
- void allocate(size_t) final;
+ void allocate(size_t, const WebCore::CAAudioStreamDescription& format, size_t frameCount) final;
void deallocate() final;
void* data() final;
void getCurrentFrameBounds(uint64_t& startTime, uint64_t& endTime) final;
@@ -67,9 +68,10 @@
Atomic<unsigned> boundsBufferIndex { 0 };
};
+ void setStorage(RefPtr<SharedMemory>&&, const WebCore::CAAudioStreamDescription& format, size_t frameCount);
FrameBounds* sharedFrameBounds() const;
- Function<void(SharedMemory*)> m_storageChangedHandler;
+ Function<void(SharedMemory*, const WebCore::CAAudioStreamDescription& format, size_t frameCount)> m_storageChangedHandler;
RefPtr<SharedMemory> m_storage;
bool m_readOnly { false };
uint64_t m_startFrame { 0 };
Modified: trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp (270960 => 270961)
--- trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp 2020-12-17 23:47:56 UTC (rev 270960)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp 2020-12-18 01:21:42 UTC (rev 270961)
@@ -59,7 +59,7 @@
: m_id(id)
, m_connection(WTFMove(connection))
, m_source(WTFMove(source))
- , m_ringBuffer(makeUniqueRef<SharedRingBufferStorage>(std::bind(&SourceProxy::storageChanged, this, std::placeholders::_1)))
+ , m_ringBuffer(makeUniqueRef<SharedRingBufferStorage>(std::bind(&SourceProxy::storageChanged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)))
{
m_source->addObserver(*this);
switch (m_source->type()) {
@@ -194,7 +194,7 @@
return m_rotationSession->rotate(sample, rotation, ImageRotationSessionVT::IsCGImageCompatible::No);
}
- void storageChanged(SharedMemory* storage)
+ void storageChanged(SharedMemory* storage, const WebCore::CAAudioStreamDescription& format, size_t frameCount)
{
SharedMemory::Handle handle;
if (storage)
@@ -206,7 +206,7 @@
#else
uint64_t dataSize = 0;
#endif
- m_connection->send(Messages::RemoteCaptureSampleManager::AudioStorageChanged(m_id, SharedMemory::IPCHandle { WTFMove(handle), dataSize }, m_description, m_numberOfFrames), 0);
+ m_connection->send(Messages::RemoteCaptureSampleManager::AudioStorageChanged(m_id, SharedMemory::IPCHandle { WTFMove(handle), dataSize }, format, frameCount), 0);
}
bool preventSourceFromStopping()
Modified: trunk/Source/WebKit/UIProcess/SpeechRecognitionRemoteRealtimeMediaSource.cpp (270960 => 270961)
--- trunk/Source/WebKit/UIProcess/SpeechRecognitionRemoteRealtimeMediaSource.cpp 2020-12-17 23:47:56 UTC (rev 270960)
+++ trunk/Source/WebKit/UIProcess/SpeechRecognitionRemoteRealtimeMediaSource.cpp 2020-12-18 01:21:42 UTC (rev 270961)
@@ -77,23 +77,8 @@
{
m_description = description;
- RefPtr<SharedMemory> memory;
- if (!handle.isNull()) {
- memory = SharedMemory::map(handle, SharedMemory::Protection::ReadOnly);
- LOG_ERROR("Unable to create shared memory for remote source");
- }
-
auto& storage = static_cast<SharedRingBufferStorage&>(m_ringBuffer->storage());
- if (!memory) {
- m_ringBuffer->deallocate();
- storage.setReadOnly(false);
- storage.setStorage(nullptr);
- return;
- }
-
- storage.setStorage(memory.releaseNonNull());
- storage.setReadOnly(true);
- m_ringBuffer->allocate(description, numberOfFrames);
+ storage.updateReadOnlyStorage(*m_ringBuffer, handle, description, numberOfFrames);
m_buffer = makeUnique<WebAudioBufferList>(description, numberOfFrames);
}
Modified: trunk/Source/WebKit/WebProcess/GPU/media/RemoteAudioDestinationProxy.cpp (270960 => 270961)
--- trunk/Source/WebKit/WebProcess/GPU/media/RemoteAudioDestinationProxy.cpp 2020-12-17 23:47:56 UTC (rev 270960)
+++ trunk/Source/WebKit/WebProcess/GPU/media/RemoteAudioDestinationProxy.cpp 2020-12-18 01:21:42 UTC (rev 270961)
@@ -61,7 +61,7 @@
#if PLATFORM(COCOA)
: WebCore::AudioDestinationCocoa(callback, numberOfOutputChannels, sampleRate, false)
, m_numberOfFrames(hardwareSampleRate() * ringBufferSizeInSecond)
- , m_ringBuffer(makeUnique<WebCore::CARingBuffer>(makeUniqueRef<SharedRingBufferStorage>(std::bind(&RemoteAudioDestinationProxy::storageChanged, this, std::placeholders::_1))))
+ , m_ringBuffer(makeUnique<WebCore::CARingBuffer>(makeUniqueRef<SharedRingBufferStorage>(std::bind(&RemoteAudioDestinationProxy::storageChanged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3))))
, m_sampleRate(hardwareSampleRate())
#else
: WebCore::AudioDestinationGStreamer(callback, numberOfOutputChannels, sampleRate)
@@ -182,7 +182,7 @@
}
#if PLATFORM(COCOA)
-void RemoteAudioDestinationProxy::storageChanged(SharedMemory* storage)
+void RemoteAudioDestinationProxy::storageChanged(SharedMemory* storage, const WebCore::CAAudioStreamDescription& format, size_t frameCount)
{
SharedMemory::Handle handle;
if (storage)
@@ -195,11 +195,7 @@
uint64_t dataSize = 0;
#endif
- AudioStreamBasicDescription streamFormat;
- getAudioStreamBasicDescription(streamFormat);
- WebCore::CAAudioStreamDescription description(streamFormat);
-
- WebProcess::singleton().ensureGPUProcessConnection().connection().send(Messages::RemoteAudioDestinationManager::AudioSamplesStorageChanged { m_destinationID, SharedMemory::IPCHandle { WTFMove(handle), dataSize }, streamFormat, m_numberOfFrames }, 0);
+ WebProcess::singleton().ensureGPUProcessConnection().connection().send(Messages::RemoteAudioDestinationManager::AudioSamplesStorageChanged { m_destinationID, SharedMemory::IPCHandle { WTFMove(handle), dataSize }, format, frameCount }, 0);
}
#endif
Modified: trunk/Source/WebKit/WebProcess/GPU/media/RemoteAudioDestinationProxy.h (270960 => 270961)
--- trunk/Source/WebKit/WebProcess/GPU/media/RemoteAudioDestinationProxy.h 2020-12-17 23:47:56 UTC (rev 270960)
+++ trunk/Source/WebKit/WebProcess/GPU/media/RemoteAudioDestinationProxy.h 2020-12-18 01:21:42 UTC (rev 270961)
@@ -96,7 +96,7 @@
#endif
#if PLATFORM(COCOA)
- void storageChanged(SharedMemory*);
+ void storageChanged(SharedMemory*, const WebCore::CAAudioStreamDescription& format, size_t frameCount);
#endif
RemoteAudioDestinationIdentifier m_destinationID;
Modified: trunk/Source/WebKit/WebProcess/GPU/media/RemoteAudioSourceProviderManager.cpp (270960 => 270961)
--- trunk/Source/WebKit/WebProcess/GPU/media/RemoteAudioSourceProviderManager.cpp 2020-12-17 23:47:56 UTC (rev 270960)
+++ trunk/Source/WebKit/WebProcess/GPU/media/RemoteAudioSourceProviderManager.cpp 2020-12-18 01:21:42 UTC (rev 270961)
@@ -124,23 +124,8 @@
{
m_description = description;
- RefPtr<SharedMemory> memory;
- if (!handle.isNull()) {
- memory = SharedMemory::map(handle, SharedMemory::Protection::ReadOnly);
- RELEASE_LOG_ERROR_IF(!memory, Media, "Unable to create shared memory for audio provider %llu", m_provider->identifier().toUInt64());
- }
-
auto& storage = static_cast<SharedRingBufferStorage&>(m_ringBuffer->storage());
- if (!memory) {
- m_ringBuffer->deallocate();
- storage.setReadOnly(false);
- storage.setStorage(nullptr);
- return;
- }
-
- storage.setStorage(memory.releaseNonNull());
- storage.setReadOnly(true);
- m_ringBuffer->allocate(description, numberOfFrames);
+ storage.updateReadOnlyStorage(*m_ringBuffer, handle, description, numberOfFrames);
m_buffer = makeUnique<WebAudioBufferList>(description, numberOfFrames);
}
Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/AudioMediaStreamTrackRenderer.cpp (270960 => 270961)
--- trunk/Source/WebKit/WebProcess/GPU/webrtc/AudioMediaStreamTrackRenderer.cpp 2020-12-17 23:47:56 UTC (rev 270960)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/AudioMediaStreamTrackRenderer.cpp 2020-12-18 01:21:42 UTC (rev 270961)
@@ -46,7 +46,7 @@
AudioMediaStreamTrackRenderer::AudioMediaStreamTrackRenderer(Ref<IPC::Connection>&& connection)
: m_connection(WTFMove(connection))
, m_identifier(AudioMediaStreamTrackRendererIdentifier::generate())
- , m_ringBuffer(makeUnique<WebCore::CARingBuffer>(makeUniqueRef<SharedRingBufferStorage>(std::bind(&AudioMediaStreamTrackRenderer::storageChanged, this, std::placeholders::_1))))
+ , m_ringBuffer(makeUnique<WebCore::CARingBuffer>(makeUniqueRef<SharedRingBufferStorage>(std::bind(&AudioMediaStreamTrackRenderer::storageChanged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3))))
{
m_connection->send(Messages::RemoteAudioMediaStreamTrackRendererManager::CreateRenderer { m_identifier }, 0);
}
@@ -98,7 +98,7 @@
m_connection->send(Messages::RemoteAudioMediaStreamTrackRenderer::AudioSamplesAvailable { time, numberOfFrames }, m_identifier);
}
-void AudioMediaStreamTrackRenderer::storageChanged(SharedMemory* storage)
+void AudioMediaStreamTrackRenderer::storageChanged(SharedMemory* storage, const WebCore::CAAudioStreamDescription& format, size_t frameCount)
{
SharedMemory::Handle handle;
if (storage)
@@ -110,7 +110,7 @@
#else
uint64_t dataSize = 0;
#endif
- m_connection->send(Messages::RemoteAudioMediaStreamTrackRenderer::AudioSamplesStorageChanged { SharedMemory::IPCHandle { WTFMove(handle), dataSize }, m_description, static_cast<uint64_t>(m_numberOfFrames) }, m_identifier);
+ m_connection->send(Messages::RemoteAudioMediaStreamTrackRenderer::AudioSamplesStorageChanged { SharedMemory::IPCHandle { WTFMove(handle), dataSize }, format, frameCount }, m_identifier);
}
}
Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/AudioMediaStreamTrackRenderer.h (270960 => 270961)
--- trunk/Source/WebKit/WebProcess/GPU/webrtc/AudioMediaStreamTrackRenderer.h 2020-12-17 23:47:56 UTC (rev 270960)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/AudioMediaStreamTrackRenderer.h 2020-12-18 01:21:42 UTC (rev 270961)
@@ -49,7 +49,7 @@
private:
explicit AudioMediaStreamTrackRenderer(Ref<IPC::Connection>&&);
- void storageChanged(SharedMemory*);
+ void storageChanged(SharedMemory*, const WebCore::CAAudioStreamDescription& format, size_t frameCount);
// WebCore::AudioMediaStreamTrackRenderer
void start() final;
Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/MediaRecorderPrivate.cpp (270960 => 270961)
--- trunk/Source/WebKit/WebProcess/GPU/webrtc/MediaRecorderPrivate.cpp 2020-12-17 23:47:56 UTC (rev 270960)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/MediaRecorderPrivate.cpp 2020-12-18 01:21:42 UTC (rev 270961)
@@ -59,7 +59,7 @@
auto selectedTracks = MediaRecorderPrivate::selectTracks(m_stream);
if (selectedTracks.audioTrack)
- m_ringBuffer = makeUnique<CARingBuffer>(makeUniqueRef<SharedRingBufferStorage>(std::bind(&MediaRecorderPrivate::storageChanged, this, std::placeholders::_1)));
+ m_ringBuffer = makeUnique<CARingBuffer>(makeUniqueRef<SharedRingBufferStorage>(std::bind(&MediaRecorderPrivate::storageChanged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)));
m_connection->sendWithAsyncReply(Messages::RemoteMediaRecorderManager::CreateRecorder { m_identifier, !!selectedTracks.audioTrack, !!selectedTracks.videoTrack, m_options }, [this, weakThis = makeWeakPtr(this), audioTrack = makeRefPtr(selectedTracks.audioTrack), videoTrack = makeRefPtr(selectedTracks.videoTrack), callback = WTFMove(callback)](auto&& exception, String&& mimeType, unsigned audioBitRate, unsigned videoBitRate) mutable {
if (!weakThis) {
@@ -107,7 +107,7 @@
m_connection->send(Messages::RemoteMediaRecorder::AudioSamplesAvailable { time, numberOfFrames }, m_identifier);
}
-void MediaRecorderPrivate::storageChanged(SharedMemory* storage)
+void MediaRecorderPrivate::storageChanged(SharedMemory* storage, const WebCore::CAAudioStreamDescription& format, size_t frameCount)
{
SharedMemory::Handle handle;
if (storage)
@@ -119,7 +119,7 @@
#else
uint64_t dataSize = 0;
#endif
- m_connection->send(Messages::RemoteMediaRecorder::AudioSamplesStorageChanged { SharedMemory::IPCHandle { WTFMove(handle), dataSize }, m_description, static_cast<uint64_t>(m_numberOfFrames) }, m_identifier);
+ m_connection->send(Messages::RemoteMediaRecorder::AudioSamplesStorageChanged { SharedMemory::IPCHandle { WTFMove(handle), dataSize }, format, frameCount }, m_identifier);
}
void MediaRecorderPrivate::fetchData(CompletionHandler<void(RefPtr<WebCore::SharedBuffer>&&, const String& mimeType, double)>&& completionHandler)
Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/MediaRecorderPrivate.h (270960 => 270961)
--- trunk/Source/WebKit/WebProcess/GPU/webrtc/MediaRecorderPrivate.h 2020-12-17 23:47:56 UTC (rev 270960)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/MediaRecorderPrivate.h 2020-12-18 01:21:42 UTC (rev 270961)
@@ -63,7 +63,7 @@
void pauseRecording(CompletionHandler<void()>&&) final;
void resumeRecording(CompletionHandler<void()>&&) final;
- void storageChanged(SharedMemory*);
+ void storageChanged(SharedMemory*, const WebCore::CAAudioStreamDescription& format, size_t frameCount);
MediaRecorderIdentifier m_identifier;
Ref<WebCore::MediaStreamPrivate> m_stream;
Modified: trunk/Source/WebKit/WebProcess/cocoa/RemoteCaptureSampleManager.cpp (270960 => 270961)
--- trunk/Source/WebKit/WebProcess/cocoa/RemoteCaptureSampleManager.cpp 2020-12-17 23:47:56 UTC (rev 270960)
+++ trunk/Source/WebKit/WebProcess/cocoa/RemoteCaptureSampleManager.cpp 2020-12-18 01:21:42 UTC (rev 270961)
@@ -120,25 +120,8 @@
void RemoteCaptureSampleManager::RemoteAudio::setStorage(const SharedMemory::Handle& handle, const WebCore::CAAudioStreamDescription& description, uint64_t numberOfFrames)
{
m_description = description;
-
- RefPtr<SharedMemory> memory;
- if (!handle.isNull()) {
- memory = SharedMemory::map(handle, SharedMemory::Protection::ReadOnly);
- RELEASE_LOG_ERROR_IF(!memory, WebRTC, "Unable to create shared memory for audio source %llu", m_source->identifier().toUInt64());
- }
-
auto& storage = static_cast<SharedRingBufferStorage&>(m_ringBuffer->storage());
- if (!memory) {
- m_ringBuffer->deallocate();
- storage.setReadOnly(false);
- storage.setStorage(nullptr);
- return;
- }
-
- storage.setStorage(memory.releaseNonNull());
- storage.setReadOnly(true);
- m_ringBuffer->allocate(description, numberOfFrames);
- m_buffer = makeUnique<WebAudioBufferList>(description, numberOfFrames);
+ storage.updateReadOnlyStorage(*m_ringBuffer, handle, description, numberOfFrames);
}
void RemoteCaptureSampleManager::RemoteAudio::audioSamplesAvailable(MediaTime time, uint64_t numberOfFrames)