Changeset 270961 in webkit
- Timestamp:
- Dec 17, 2020, 5:21:42 PM (6 years ago)
- Location:
- trunk/Source
- Files:
-
- 23 edited
-
WebCore/ChangeLog (modified) (1 diff)
-
WebCore/platform/audio/cocoa/CARingBuffer.cpp (modified) (1 diff)
-
WebCore/platform/audio/cocoa/CARingBuffer.h (modified) (3 diffs)
-
WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.h (modified) (2 diffs)
-
WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm (modified) (3 diffs)
-
WebKit/ChangeLog (modified) (1 diff)
-
WebKit/GPUProcess/media/RemoteAudioDestinationManager.cpp (modified) (2 diffs)
-
WebKit/GPUProcess/media/RemoteAudioSourceProviderProxy.cpp (modified) (4 diffs)
-
WebKit/GPUProcess/media/RemoteAudioSourceProviderProxy.h (modified) (3 diffs)
-
WebKit/GPUProcess/webrtc/RemoteAudioMediaStreamTrackRenderer.cpp (modified) (1 diff)
-
WebKit/GPUProcess/webrtc/RemoteMediaRecorder.cpp (modified) (1 diff)
-
WebKit/Shared/Cocoa/SharedRingBufferStorage.cpp (modified) (2 diffs)
-
WebKit/Shared/Cocoa/SharedRingBufferStorage.h (modified) (3 diffs)
-
WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp (modified) (3 diffs)
-
WebKit/UIProcess/SpeechRecognitionRemoteRealtimeMediaSource.cpp (modified) (1 diff)
-
WebKit/WebProcess/GPU/media/RemoteAudioDestinationProxy.cpp (modified) (3 diffs)
-
WebKit/WebProcess/GPU/media/RemoteAudioDestinationProxy.h (modified) (1 diff)
-
WebKit/WebProcess/GPU/media/RemoteAudioSourceProviderManager.cpp (modified) (1 diff)
-
WebKit/WebProcess/GPU/webrtc/AudioMediaStreamTrackRenderer.cpp (modified) (3 diffs)
-
WebKit/WebProcess/GPU/webrtc/AudioMediaStreamTrackRenderer.h (modified) (1 diff)
-
WebKit/WebProcess/GPU/webrtc/MediaRecorderPrivate.cpp (modified) (3 diffs)
-
WebKit/WebProcess/GPU/webrtc/MediaRecorderPrivate.h (modified) (1 diff)
-
WebKit/WebProcess/cocoa/RemoteCaptureSampleManager.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r270958 r270961 1 2020-12-17 Chris Dumez <cdumez@apple.com> 2 3 [GPUProcess] https://www.waveplayer.info/createmediaelementsource-test/ demo is flaky 4 https://bugs.webkit.org/show_bug.cgi?id=219951 5 6 Reviewed by Geoff Garen. 7 8 The issue was with the following line in AudioSourceProviderAVFObjC::prepare: 9 `m_ringBuffer = m_ringBufferCallback(description, capacity).moveToUniquePtr();` 10 11 In the case where m_ringBuffer was non-null before the assignment, we would have 12 2 RingBuffers that would coexist for a very small period of time. When the new 13 one was created, we would send an IPC to the remote process with the shared 14 memory handle of the new RingBuffer. However, very shortly after, the old 15 ring buffer would get destroyed, causing us to send another IPC to the remote 16 process with a null handle (since the shared memory associated with the old 17 ring buffer is getting destroyed). As a result, of this ordering issue, the 18 remote process would end up with a RingBuffer with a null shared memory handle 19 and no audio would be rendered. 20 21 We could have addressed the issue like so: 22 ``` 23 m_ringBuffer = nullptr; 24 m_ringBuffer = m_ringBufferCallback(description, capacity).moveToUniquePtr(); 25 ``` 26 However, this would be super fragile. Instead, I have made the following changes: 27 1. If there is already a ringBuffer, reuse it instead of reconstructing it. 28 Calling allocate() with the new parameters on the existing ring buffer is 29 sufficient in this case. 30 2. Because of 1, the ring buffer creation callback no longer needs to call 31 CARingBuffer::allocate(). 32 33 I also made the following changes to make the code simpler and to reduce code 34 duplication: 35 - The storage change handler passed to SharedRingBufferStorage is now given 36 as parameter the CAAudioStreamDescription & frameCount. What the handler 37 always does is send an IPC to the remote process to tell it that the 38 storage changed and in all cases, it needs to provide these 2 parameters 39 as well. This is because the remote process will need to call 40 CARingBuffer::allocate(), which requires those 2 parameters. This 41 simplifies our code in some cases since we no longer need a mechanism 42 to retrieve those 2 parameters from inside the storage change handler. 43 - The logic of the StorageChange IPC recipient to update its ringbuffer 44 with the new shared memory handle is complicated and was duplicated 45 in a LOT of places. To address this, I introduced a new 46 SharedRingBufferStorage::updateReadOnlyStorage() function which does 47 exactly what we need. 48 49 * platform/audio/cocoa/CARingBuffer.cpp: 50 (WebCore::CARingBuffer::allocate): 51 * platform/audio/cocoa/CARingBuffer.h: 52 * platform/graphics/avfoundation/AudioSourceProviderAVFObjC.h: 53 * platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm: 54 (WebCore::AudioSourceProviderAVFObjC::AudioSourceProviderAVFObjC): 55 (WebCore::AudioSourceProviderAVFObjC::prepare): 56 (WebCore::AudioSourceProviderAVFObjC::setRingBufferCreationCallback): 57 1 58 2020-12-17 Zalan Bujtas <zalan@apple.com> 2 59 -
trunk/Source/WebCore/platform/audio/cocoa/CARingBuffer.cpp
r270938 r270961 72 72 m_capacityBytes = m_bytesPerFrame * frameCount; 73 73 74 m_buffers->allocate(m_capacityBytes * m_channelCount );74 m_buffers->allocate(m_capacityBytes * m_channelCount, format, frameCount); 75 75 76 76 m_pointers.resize(m_channelCount); -
trunk/Source/WebCore/platform/audio/cocoa/CARingBuffer.h
r270938 r270961 43 43 public: 44 44 virtual ~CARingBufferStorage() = default; 45 virtual void allocate(size_t ) = 0;45 virtual void allocate(size_t, const CAAudioStreamDescription& format, size_t frameCount) = 0; 46 46 virtual void deallocate() = 0; 47 47 virtual void* data() = 0; … … 60 60 61 61 private: 62 void allocate(size_t byteCount ) final { m_buffer.grow(byteCount); }62 void allocate(size_t byteCount, const CAAudioStreamDescription&, size_t) final { m_buffer.grow(byteCount); } 63 63 void deallocate() final { m_buffer.clear(); } 64 64 void* data() final { return m_buffer.data(); } … … 99 99 }; 100 100 101 WEBCORE_EXPORT void allocate(const CAAudioStreamDescription&, size_t );101 WEBCORE_EXPORT void allocate(const CAAudioStreamDescription&, size_t frameCount); 102 102 WEBCORE_EXPORT void deallocate(); 103 103 -
trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.h
r268577 r270961 64 64 using AudioCallback = Function<void(uint64_t startFrame, uint64_t numberOfFrames)>; 65 65 WEBCORE_EXPORT void setAudioCallback(AudioCallback&&); 66 using RingBufferCreationCallback = Function<UniqueRef<CARingBuffer>( const CAAudioStreamDescription&, size_t)>;66 using RingBufferCreationCallback = Function<UniqueRef<CARingBuffer>()>; 67 67 WEBCORE_EXPORT void setRingBufferCreationCallback(RingBufferCreationCallback&&); 68 68 … … 112 112 RefPtr<TapStorage> m_tapStorage; 113 113 AudioCallback m_audioCallback; 114 RingBufferCreationCallback m_ringBufferC allback;114 RingBufferCreationCallback m_ringBufferCreationCallback; 115 115 }; 116 116 -
trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm
r268577 r270961 81 81 AudioSourceProviderAVFObjC::AudioSourceProviderAVFObjC(AVPlayerItem *item) 82 82 : m_avPlayerItem(item) 83 , m_ringBufferCreationCallback([] { return makeUniqueRef<CARingBuffer>(); }) 83 84 { 84 85 } … … 339 340 340 341 CAAudioStreamDescription description { *processingFormat }; 341 if (m_ringBufferCallback) 342 m_ringBuffer = m_ringBufferCallback(description, capacity).moveToUniquePtr(); 343 else { 344 m_ringBuffer = makeUnique<CARingBuffer>(); 345 m_ringBuffer->allocate(description, capacity); 346 } 342 if (!m_ringBuffer) 343 m_ringBuffer = m_ringBufferCreationCallback().moveToUniquePtr(); 344 m_ringBuffer->allocate(description, capacity); 347 345 348 346 // AudioBufferList is a variable-length struct, so create on the heap with a generic new() operator … … 439 437 { 440 438 ASSERT(!m_avAudioMix); 441 m_ringBufferC allback = WTFMove(callback);439 m_ringBufferCreationCallback = WTFMove(callback); 442 440 } 443 441 -
trunk/Source/WebKit/ChangeLog
r270951 r270961 1 2020-12-17 Chris Dumez <cdumez@apple.com> 2 3 [GPUProcess] https://www.waveplayer.info/createmediaelementsource-test/ demo is flaky 4 https://bugs.webkit.org/show_bug.cgi?id=219951 5 6 Reviewed by Geoff Garen. 7 8 The issue was with the following line in AudioSourceProviderAVFObjC::prepare: 9 `m_ringBuffer = m_ringBufferCallback(description, capacity).moveToUniquePtr();` 10 11 In the case where m_ringBuffer was non-null before the assignment, we would have 12 2 RingBuffers that would coexist for a very small period of time. When the new 13 one was created, we would send an IPC to the remote process with the shared 14 memory handle of the new RingBuffer. However, very shortly after, the old 15 ring buffer would get destroyed, causing us to send another IPC to the remote 16 process with a null handle (since the shared memory associated with the old 17 ring buffer is getting destroyed). As a result, of this ordering issue, the 18 remote process would end up with a RingBuffer with a null shared memory handle 19 and no audio would be rendered. 20 21 We could have addressed the issue like so: 22 ``` 23 m_ringBuffer = nullptr; 24 m_ringBuffer = m_ringBufferCallback(description, capacity).moveToUniquePtr(); 25 ``` 26 However, this would be super fragile. Instead, I have made the following changes: 27 1. If there is already a ringBuffer, reuse it instead of reconstructing it. 28 Calling allocate() with the new parameters on the existing ring buffer is 29 sufficient in this case. 30 2. Because of 1, the ring buffer creation callback no longer needs to call 31 CARingBuffer::allocate(). 32 33 I also made the following changes to make the code simpler and to reduce code 34 duplication: 35 - The storage change handler passed to SharedRingBufferStorage is now given 36 as parameter the CAAudioStreamDescription & frameCount. What the handler 37 always does is send an IPC to the remote process to tell it that the 38 storage changed and in all cases, it needs to provide these 2 parameters 39 as well. This is because the remote process will need to call 40 CARingBuffer::allocate(), which requires those 2 parameters. This 41 simplifies our code in some cases since we no longer need a mechanism 42 to retrieve those 2 parameters from inside the storage change handler. 43 - The logic of the StorageChange IPC recipient to update its ringbuffer 44 with the new shared memory handle is complicated and was duplicated 45 in a LOT of places. To address this, I introduced a new 46 SharedRingBufferStorage::updateReadOnlyStorage() function which does 47 exactly what we need. 48 49 * GPUProcess/media/RemoteAudioDestinationManager.cpp: 50 (WebKit::RemoteAudioDestination::audioSamplesStorageChanged): 51 * GPUProcess/media/RemoteAudioSourceProviderProxy.cpp: 52 (WebKit::RemoteAudioSourceProviderProxy::create): 53 (WebKit::RemoteAudioSourceProviderProxy::createRingBuffer): 54 (WebKit::RemoteAudioSourceProviderProxy::storageChanged): 55 * GPUProcess/media/RemoteAudioSourceProviderProxy.h: 56 * GPUProcess/webrtc/RemoteAudioMediaStreamTrackRenderer.cpp: 57 (WebKit::RemoteAudioMediaStreamTrackRenderer::audioSamplesStorageChanged): 58 * GPUProcess/webrtc/RemoteMediaRecorder.cpp: 59 (WebKit::RemoteMediaRecorder::audioSamplesStorageChanged): 60 * Shared/Cocoa/SharedRingBufferStorage.cpp: 61 (WebKit::SharedRingBufferStorage::setStorage): 62 (WebKit::SharedRingBufferStorage::updateReadOnlyStorage): 63 (WebKit::SharedRingBufferStorage::allocate): 64 (WebKit::SharedRingBufferStorage::deallocate): 65 * Shared/Cocoa/SharedRingBufferStorage.h: 66 (WebKit::SharedRingBufferStorage::SharedRingBufferStorage): 67 (WebKit::SharedRingBufferStorage::storage const): 68 * UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp: 69 (WebKit::UserMediaCaptureManagerProxy::SourceProxy::SourceProxy): 70 (WebKit::UserMediaCaptureManagerProxy::SourceProxy::storageChanged): 71 * UIProcess/SpeechRecognitionRemoteRealtimeMediaSource.cpp: 72 (WebKit::SpeechRecognitionRemoteRealtimeMediaSource::setStorage): 73 * WebProcess/GPU/media/RemoteAudioDestinationProxy.cpp: 74 (WebKit::RemoteAudioDestinationProxy::RemoteAudioDestinationProxy): 75 (WebKit::RemoteAudioDestinationProxy::storageChanged): 76 * WebProcess/GPU/media/RemoteAudioDestinationProxy.h: 77 * WebProcess/GPU/media/RemoteAudioSourceProviderManager.cpp: 78 (WebKit::RemoteAudioSourceProviderManager::RemoteAudio::setStorage): 79 * WebProcess/GPU/webrtc/AudioMediaStreamTrackRenderer.cpp: 80 (WebKit::AudioMediaStreamTrackRenderer::AudioMediaStreamTrackRenderer): 81 (WebKit::AudioMediaStreamTrackRenderer::storageChanged): 82 * WebProcess/GPU/webrtc/AudioMediaStreamTrackRenderer.h: 83 * WebProcess/GPU/webrtc/MediaRecorderPrivate.cpp: 84 (WebKit::MediaRecorderPrivate::startRecording): 85 (WebKit::MediaRecorderPrivate::storageChanged): 86 * WebProcess/GPU/webrtc/MediaRecorderPrivate.h: 87 * WebProcess/cocoa/RemoteCaptureSampleManager.cpp: 88 (WebKit::RemoteCaptureSampleManager::RemoteAudio::setStorage): 89 1 90 2020-12-17 Chris Dumez <cdumez@apple.com> 2 91 -
trunk/Source/WebKit/GPUProcess/media/RemoteAudioDestinationManager.cpp
r270938 r270961 73 73 void audioSamplesStorageChanged(const SharedMemory::IPCHandle& ipcHandle, const WebCore::CAAudioStreamDescription& description, uint64_t numberOfFrames) 74 74 { 75 m_description = description; 76 77 if (ipcHandle.handle.isNull()) { 78 m_ringBuffer->deallocate(); 79 storage().setReadOnly(false); 80 storage().setStorage(nullptr); 81 return; 82 } 83 84 auto memory = SharedMemory::map(ipcHandle.handle, SharedMemory::Protection::ReadOnly); 85 storage().setStorage(WTFMove(memory)); 86 storage().setReadOnly(true); 87 m_ringBuffer->allocate(description, numberOfFrames); 75 storage().updateReadOnlyStorage(m_ringBuffer.get(), ipcHandle.handle, description, numberOfFrames); 88 76 } 89 77 #endif … … 165 153 WebCore::AudioOutputUnitAdaptor m_audioOutputUnitAdaptor; 166 154 167 WebCore::CAAudioStreamDescription m_description;168 155 UniqueRef<WebCore::CARingBuffer> m_ringBuffer; 169 156 MachSemaphore m_renderSemaphore; -
trunk/Source/WebKit/GPUProcess/media/RemoteAudioSourceProviderProxy.cpp
r270804 r270961 38 38 auto remoteProvider = adoptRef(*new RemoteAudioSourceProviderProxy(identifier, WTFMove(connection))); 39 39 40 localProvider.setRingBufferCreationCallback([remoteProvider]( auto description, auto capacity) {41 return remoteProvider->createRingBuffer( description, capacity);40 localProvider.setRingBufferCreationCallback([remoteProvider]() { 41 return remoteProvider->createRingBuffer(); 42 42 }); 43 43 localProvider.setAudioCallback([remoteProvider](auto startFrame, auto numberOfFrames) { … … 56 56 RemoteAudioSourceProviderProxy::~RemoteAudioSourceProviderProxy() = default; 57 57 58 UniqueRef<CARingBuffer> RemoteAudioSourceProviderProxy::createRingBuffer( const CAAudioStreamDescription& description, size_t capacity)58 UniqueRef<CARingBuffer> RemoteAudioSourceProviderProxy::createRingBuffer() 59 59 { 60 m_ringBufferDescription = description; 61 m_ringBufferCapacity = capacity; 62 auto ringBuffer = makeUniqueRef<CARingBuffer>(makeUniqueRef<SharedRingBufferStorage>([protectedThis = makeRef(*this)](SharedMemory* memory) mutable { 63 protectedThis->storageChanged(memory); 60 return makeUniqueRef<CARingBuffer>(makeUniqueRef<SharedRingBufferStorage>([protectedThis = makeRef(*this)](SharedMemory* memory, const CAAudioStreamDescription& format, size_t frameCount) mutable { 61 protectedThis->storageChanged(memory, format, frameCount); 64 62 })); 65 ringBuffer->allocate(description, capacity);66 return ringBuffer;67 63 } 68 64 … … 72 68 } 73 69 74 void RemoteAudioSourceProviderProxy::storageChanged(SharedMemory* memory )70 void RemoteAudioSourceProviderProxy::storageChanged(SharedMemory* memory, const CAAudioStreamDescription& format, size_t frameCount) 75 71 { 76 72 SharedMemory::Handle handle; … … 84 80 uint64_t dataSize = 0; 85 81 #endif 86 m_connection->send(Messages::RemoteAudioSourceProviderManager::AudioStorageChanged { m_identifier, SharedMemory::IPCHandle { WTFMove(handle), dataSize }, m_ringBufferDescription, m_ringBufferCapacity}, 0);82 m_connection->send(Messages::RemoteAudioSourceProviderManager::AudioStorageChanged { m_identifier, SharedMemory::IPCHandle { WTFMove(handle), dataSize }, format, frameCount }, 0); 87 83 } 88 84 -
trunk/Source/WebKit/GPUProcess/media/RemoteAudioSourceProviderProxy.h
r270804 r270961 48 48 ~RemoteAudioSourceProviderProxy(); 49 49 50 UniqueRef<WebCore::CARingBuffer> createRingBuffer( const WebCore::CAAudioStreamDescription&, size_t);50 UniqueRef<WebCore::CARingBuffer> createRingBuffer(); 51 51 void newAudioSamples(uint64_t startFrame, uint64_t endFrame); 52 52 … … 54 54 RemoteAudioSourceProviderProxy(WebCore::MediaPlayerIdentifier, Ref<IPC::Connection>&&); 55 55 56 void storageChanged(SharedMemory* );56 void storageChanged(SharedMemory*, const WebCore::CAAudioStreamDescription& format, size_t frameCount); 57 57 58 58 // AudioSourceProviderClient … … 61 61 WebCore::MediaPlayerIdentifier m_identifier; 62 62 Ref<IPC::Connection> m_connection; 63 64 WebCore::CAAudioStreamDescription m_ringBufferDescription;65 size_t m_ringBufferCapacity { 0 };66 63 }; 67 64 -
trunk/Source/WebKit/GPUProcess/webrtc/RemoteAudioMediaStreamTrackRenderer.cpp
r270804 r270961 106 106 m_description = description; 107 107 108 if (ipcHandle.handle.isNull()) { 109 m_ringBuffer->deallocate(); 110 storage().setReadOnly(false); 111 storage().setStorage(nullptr); 112 return; 113 } 114 115 auto memory = SharedMemory::map(ipcHandle.handle, SharedMemory::Protection::ReadOnly); 116 storage().setStorage(WTFMove(memory)); 117 storage().setReadOnly(true); 118 119 m_ringBuffer->allocate(description, numberOfFrames); 108 storage().updateReadOnlyStorage(m_ringBuffer.get(), ipcHandle.handle, description, numberOfFrames); 120 109 121 110 m_audioBufferList = makeUnique<WebAudioBufferList>(m_description); -
trunk/Source/WebKit/GPUProcess/webrtc/RemoteMediaRecorder.cpp
r270804 r270961 75 75 m_description = description; 76 76 77 if (ipcHandle.handle.isNull()) { 78 m_ringBuffer->deallocate(); 79 storage().setReadOnly(false); 80 storage().setStorage(nullptr); 81 return; 82 } 83 84 auto memory = SharedMemory::map(ipcHandle.handle, SharedMemory::Protection::ReadOnly); 85 storage().setStorage(WTFMove(memory)); 86 storage().setReadOnly(true); 87 88 m_ringBuffer->allocate(m_description, numberOfFrames); 77 storage().updateReadOnlyStorage(*m_ringBuffer, ipcHandle.handle, description, numberOfFrames); 89 78 m_audioBufferList = makeUnique<WebAudioBufferList>(m_description); 90 79 } -
trunk/Source/WebKit/Shared/Cocoa/SharedRingBufferStorage.cpp
r270938 r270961 29 29 #if USE(MEDIATOOLBOX) 30 30 31 #include <WebCore/CARingBuffer.h> 32 31 33 namespace WebKit { 32 34 33 void SharedRingBufferStorage::setStorage(RefPtr<SharedMemory>&& storage )35 void SharedRingBufferStorage::setStorage(RefPtr<SharedMemory>&& storage, const CAAudioStreamDescription& format, size_t frameCount) 34 36 { 35 37 ASSERT(storage || !m_readOnly); 36 38 m_storage = WTFMove(storage); 37 39 if (m_storageChangedHandler) 38 m_storageChangedHandler(m_storage.get() );40 m_storageChangedHandler(m_storage.get(), format, frameCount); 39 41 } 40 42 41 void SharedRingBufferStorage:: setReadOnly(bool readOnly)43 void SharedRingBufferStorage::updateReadOnlyStorage(WebCore::CARingBuffer& ringBuffer, const SharedMemory::Handle& handle, const CAAudioStreamDescription& format, size_t frameCount) 42 44 { 43 ASSERT(m_storage || !readOnly); 44 m_readOnly = readOnly; 45 if (handle.isNull()) { 46 ringBuffer.deallocate(); 47 m_readOnly = false; 48 m_storage = nullptr; 49 return; 50 } 51 52 auto memory = SharedMemory::map(handle, SharedMemory::Protection::ReadOnly); 53 m_storage = WTFMove(memory); 54 m_readOnly = true; 55 ringBuffer.allocate(format, frameCount); 45 56 } 46 57 47 void SharedRingBufferStorage::allocate(size_t byteCount )58 void SharedRingBufferStorage::allocate(size_t byteCount, const CAAudioStreamDescription& format, size_t frameCount) 48 59 { 49 60 if (!m_readOnly) { 50 61 auto sharedMemory = SharedMemory::allocate(byteCount + sizeof(FrameBounds)); 51 62 new (NotNull, sharedMemory->data()) FrameBounds; 52 setStorage(WTFMove(sharedMemory) );63 setStorage(WTFMove(sharedMemory), format, frameCount); 53 64 } 54 65 } … … 57 68 { 58 69 if (!m_readOnly) 59 setStorage(nullptr );70 setStorage(nullptr, { }, 0); 60 71 } 61 72 -
trunk/Source/WebKit/Shared/Cocoa/SharedRingBufferStorage.h
r270938 r270961 33 33 #include <wtf/Function.h> 34 34 35 namespace WebCore { 36 class CARingBuffer; 37 } 38 35 39 namespace WebKit { 36 40 37 41 class SharedRingBufferStorage : public WebCore::CARingBufferStorage { 38 42 public: 39 SharedRingBufferStorage(Function<void(SharedMemory* )>&& storageChangedHandler = nullptr)43 SharedRingBufferStorage(Function<void(SharedMemory*, const WebCore::CAAudioStreamDescription& format, size_t frameCount)>&& storageChangedHandler = nullptr) 40 44 : m_storageChangedHandler(WTFMove(storageChangedHandler)) 41 45 { … … 44 48 void invalidate() { m_storageChangedHandler = nullptr; } 45 49 46 RefPtr<SharedMemory> storage() const { return m_storage; } 47 void setStorage(RefPtr<SharedMemory>&&); 48 49 bool readOnly() const { return m_readOnly; } 50 void setReadOnly(bool); 50 SharedMemory* storage() const { return m_storage.get(); } 51 void updateReadOnlyStorage(WebCore::CARingBuffer&, const SharedMemory::Handle&, const WebCore::CAAudioStreamDescription& format, size_t frameCount); 51 52 52 53 // WebCore::CARingBufferStorage 53 void allocate(size_t ) final;54 void allocate(size_t, const WebCore::CAAudioStreamDescription& format, size_t frameCount) final; 54 55 void deallocate() final; 55 56 void* data() final; … … 68 69 }; 69 70 71 void setStorage(RefPtr<SharedMemory>&&, const WebCore::CAAudioStreamDescription& format, size_t frameCount); 70 72 FrameBounds* sharedFrameBounds() const; 71 73 72 Function<void(SharedMemory* )> m_storageChangedHandler;74 Function<void(SharedMemory*, const WebCore::CAAudioStreamDescription& format, size_t frameCount)> m_storageChangedHandler; 73 75 RefPtr<SharedMemory> m_storage; 74 76 bool m_readOnly { false }; -
trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp
r270804 r270961 60 60 , m_connection(WTFMove(connection)) 61 61 , m_source(WTFMove(source)) 62 , m_ringBuffer(makeUniqueRef<SharedRingBufferStorage>(std::bind(&SourceProxy::storageChanged, this, std::placeholders::_1 )))62 , m_ringBuffer(makeUniqueRef<SharedRingBufferStorage>(std::bind(&SourceProxy::storageChanged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3))) 63 63 { 64 64 m_source->addObserver(*this); … … 195 195 } 196 196 197 void storageChanged(SharedMemory* storage )197 void storageChanged(SharedMemory* storage, const WebCore::CAAudioStreamDescription& format, size_t frameCount) 198 198 { 199 199 SharedMemory::Handle handle; … … 207 207 uint64_t dataSize = 0; 208 208 #endif 209 m_connection->send(Messages::RemoteCaptureSampleManager::AudioStorageChanged(m_id, SharedMemory::IPCHandle { WTFMove(handle), dataSize }, m_description, m_numberOfFrames), 0);209 m_connection->send(Messages::RemoteCaptureSampleManager::AudioStorageChanged(m_id, SharedMemory::IPCHandle { WTFMove(handle), dataSize }, format, frameCount), 0); 210 210 } 211 211 -
trunk/Source/WebKit/UIProcess/SpeechRecognitionRemoteRealtimeMediaSource.cpp
r270804 r270961 78 78 m_description = description; 79 79 80 RefPtr<SharedMemory> memory;81 if (!handle.isNull()) {82 memory = SharedMemory::map(handle, SharedMemory::Protection::ReadOnly);83 LOG_ERROR("Unable to create shared memory for remote source");84 }85 86 80 auto& storage = static_cast<SharedRingBufferStorage&>(m_ringBuffer->storage()); 87 if (!memory) { 88 m_ringBuffer->deallocate(); 89 storage.setReadOnly(false); 90 storage.setStorage(nullptr); 91 return; 92 } 93 94 storage.setStorage(memory.releaseNonNull()); 95 storage.setReadOnly(true); 96 m_ringBuffer->allocate(description, numberOfFrames); 81 storage.updateReadOnlyStorage(*m_ringBuffer, handle, description, numberOfFrames); 97 82 m_buffer = makeUnique<WebAudioBufferList>(description, numberOfFrames); 98 83 } -
trunk/Source/WebKit/WebProcess/GPU/media/RemoteAudioDestinationProxy.cpp
r270951 r270961 62 62 : WebCore::AudioDestinationCocoa(callback, numberOfOutputChannels, sampleRate, false) 63 63 , m_numberOfFrames(hardwareSampleRate() * ringBufferSizeInSecond) 64 , m_ringBuffer(makeUnique<WebCore::CARingBuffer>(makeUniqueRef<SharedRingBufferStorage>(std::bind(&RemoteAudioDestinationProxy::storageChanged, this, std::placeholders::_1 ))))64 , m_ringBuffer(makeUnique<WebCore::CARingBuffer>(makeUniqueRef<SharedRingBufferStorage>(std::bind(&RemoteAudioDestinationProxy::storageChanged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)))) 65 65 , m_sampleRate(hardwareSampleRate()) 66 66 #else … … 183 183 184 184 #if PLATFORM(COCOA) 185 void RemoteAudioDestinationProxy::storageChanged(SharedMemory* storage )185 void RemoteAudioDestinationProxy::storageChanged(SharedMemory* storage, const WebCore::CAAudioStreamDescription& format, size_t frameCount) 186 186 { 187 187 SharedMemory::Handle handle; … … 196 196 #endif 197 197 198 AudioStreamBasicDescription streamFormat; 199 getAudioStreamBasicDescription(streamFormat); 200 WebCore::CAAudioStreamDescription description(streamFormat); 201 202 WebProcess::singleton().ensureGPUProcessConnection().connection().send(Messages::RemoteAudioDestinationManager::AudioSamplesStorageChanged { m_destinationID, SharedMemory::IPCHandle { WTFMove(handle), dataSize }, streamFormat, m_numberOfFrames }, 0); 198 WebProcess::singleton().ensureGPUProcessConnection().connection().send(Messages::RemoteAudioDestinationManager::AudioSamplesStorageChanged { m_destinationID, SharedMemory::IPCHandle { WTFMove(handle), dataSize }, format, frameCount }, 0); 203 199 } 204 200 #endif -
trunk/Source/WebKit/WebProcess/GPU/media/RemoteAudioDestinationProxy.h
r270947 r270961 97 97 98 98 #if PLATFORM(COCOA) 99 void storageChanged(SharedMemory* );99 void storageChanged(SharedMemory*, const WebCore::CAAudioStreamDescription& format, size_t frameCount); 100 100 #endif 101 101 -
trunk/Source/WebKit/WebProcess/GPU/media/RemoteAudioSourceProviderManager.cpp
r270804 r270961 125 125 m_description = description; 126 126 127 RefPtr<SharedMemory> memory;128 if (!handle.isNull()) {129 memory = SharedMemory::map(handle, SharedMemory::Protection::ReadOnly);130 RELEASE_LOG_ERROR_IF(!memory, Media, "Unable to create shared memory for audio provider %llu", m_provider->identifier().toUInt64());131 }132 133 127 auto& storage = static_cast<SharedRingBufferStorage&>(m_ringBuffer->storage()); 134 if (!memory) { 135 m_ringBuffer->deallocate(); 136 storage.setReadOnly(false); 137 storage.setStorage(nullptr); 138 return; 139 } 140 141 storage.setStorage(memory.releaseNonNull()); 142 storage.setReadOnly(true); 143 m_ringBuffer->allocate(description, numberOfFrames); 128 storage.updateReadOnlyStorage(*m_ringBuffer, handle, description, numberOfFrames); 144 129 m_buffer = makeUnique<WebAudioBufferList>(description, numberOfFrames); 145 130 } -
trunk/Source/WebKit/WebProcess/GPU/webrtc/AudioMediaStreamTrackRenderer.cpp
r270804 r270961 47 47 : m_connection(WTFMove(connection)) 48 48 , m_identifier(AudioMediaStreamTrackRendererIdentifier::generate()) 49 , m_ringBuffer(makeUnique<WebCore::CARingBuffer>(makeUniqueRef<SharedRingBufferStorage>(std::bind(&AudioMediaStreamTrackRenderer::storageChanged, this, std::placeholders::_1 ))))49 , m_ringBuffer(makeUnique<WebCore::CARingBuffer>(makeUniqueRef<SharedRingBufferStorage>(std::bind(&AudioMediaStreamTrackRenderer::storageChanged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)))) 50 50 { 51 51 m_connection->send(Messages::RemoteAudioMediaStreamTrackRendererManager::CreateRenderer { m_identifier }, 0); … … 99 99 } 100 100 101 void AudioMediaStreamTrackRenderer::storageChanged(SharedMemory* storage )101 void AudioMediaStreamTrackRenderer::storageChanged(SharedMemory* storage, const WebCore::CAAudioStreamDescription& format, size_t frameCount) 102 102 { 103 103 SharedMemory::Handle handle; … … 111 111 uint64_t dataSize = 0; 112 112 #endif 113 m_connection->send(Messages::RemoteAudioMediaStreamTrackRenderer::AudioSamplesStorageChanged { SharedMemory::IPCHandle { WTFMove(handle), dataSize }, m_description, static_cast<uint64_t>(m_numberOfFrames)}, m_identifier);113 m_connection->send(Messages::RemoteAudioMediaStreamTrackRenderer::AudioSamplesStorageChanged { SharedMemory::IPCHandle { WTFMove(handle), dataSize }, format, frameCount }, m_identifier); 114 114 } 115 115 -
trunk/Source/WebKit/WebProcess/GPU/webrtc/AudioMediaStreamTrackRenderer.h
r270804 r270961 50 50 explicit AudioMediaStreamTrackRenderer(Ref<IPC::Connection>&&); 51 51 52 void storageChanged(SharedMemory* );52 void storageChanged(SharedMemory*, const WebCore::CAAudioStreamDescription& format, size_t frameCount); 53 53 54 54 // WebCore::AudioMediaStreamTrackRenderer -
trunk/Source/WebKit/WebProcess/GPU/webrtc/MediaRecorderPrivate.cpp
r270804 r270961 60 60 auto selectedTracks = MediaRecorderPrivate::selectTracks(m_stream); 61 61 if (selectedTracks.audioTrack) 62 m_ringBuffer = makeUnique<CARingBuffer>(makeUniqueRef<SharedRingBufferStorage>(std::bind(&MediaRecorderPrivate::storageChanged, this, std::placeholders::_1 )));62 m_ringBuffer = makeUnique<CARingBuffer>(makeUniqueRef<SharedRingBufferStorage>(std::bind(&MediaRecorderPrivate::storageChanged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3))); 63 63 64 64 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 { … … 108 108 } 109 109 110 void MediaRecorderPrivate::storageChanged(SharedMemory* storage )110 void MediaRecorderPrivate::storageChanged(SharedMemory* storage, const WebCore::CAAudioStreamDescription& format, size_t frameCount) 111 111 { 112 112 SharedMemory::Handle handle; … … 120 120 uint64_t dataSize = 0; 121 121 #endif 122 m_connection->send(Messages::RemoteMediaRecorder::AudioSamplesStorageChanged { SharedMemory::IPCHandle { WTFMove(handle), dataSize }, m_description, static_cast<uint64_t>(m_numberOfFrames)}, m_identifier);122 m_connection->send(Messages::RemoteMediaRecorder::AudioSamplesStorageChanged { SharedMemory::IPCHandle { WTFMove(handle), dataSize }, format, frameCount }, m_identifier); 123 123 } 124 124 -
trunk/Source/WebKit/WebProcess/GPU/webrtc/MediaRecorderPrivate.h
r270804 r270961 64 64 void resumeRecording(CompletionHandler<void()>&&) final; 65 65 66 void storageChanged(SharedMemory* );66 void storageChanged(SharedMemory*, const WebCore::CAAudioStreamDescription& format, size_t frameCount); 67 67 68 68 MediaRecorderIdentifier m_identifier; -
trunk/Source/WebKit/WebProcess/cocoa/RemoteCaptureSampleManager.cpp
r270804 r270961 121 121 { 122 122 m_description = description; 123 124 RefPtr<SharedMemory> memory;125 if (!handle.isNull()) {126 memory = SharedMemory::map(handle, SharedMemory::Protection::ReadOnly);127 RELEASE_LOG_ERROR_IF(!memory, WebRTC, "Unable to create shared memory for audio source %llu", m_source->identifier().toUInt64());128 }129 130 123 auto& storage = static_cast<SharedRingBufferStorage&>(m_ringBuffer->storage()); 131 if (!memory) { 132 m_ringBuffer->deallocate(); 133 storage.setReadOnly(false); 134 storage.setStorage(nullptr); 135 return; 136 } 137 138 storage.setStorage(memory.releaseNonNull()); 139 storage.setReadOnly(true); 140 m_ringBuffer->allocate(description, numberOfFrames); 141 m_buffer = makeUnique<WebAudioBufferList>(description, numberOfFrames); 124 storage.updateReadOnlyStorage(*m_ringBuffer, handle, description, numberOfFrames); 142 125 } 143 126
Note:
See TracChangeset
for help on using the changeset viewer.