Changeset 212144 in webkit
- Timestamp:
- Feb 10, 2017 1:29:32 PM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r212140 r212144 1 2017-02-10 Youenn Fablet <youenn@apple.com> 2 3 [WebRTC] Implement Outgoing libwebrtc audio source support 4 https://bugs.webkit.org/show_bug.cgi?id=168118 5 6 Reviewed by Eric Carlson. 7 8 No new automated tests as we need the audio rendering to work to test the whole loop. 9 10 Using an AudioSampleDataSource to convert the captured data to libwebrtc expected format. 11 Capturing and pushing data happens in the capture thread. 12 Pulling of converted data happens in libwebrtc thread. 13 14 Introducing LibWebRTCAudioFormat.h to centralize libwbebrtc expected audio format. 15 16 * WebCore.xcodeproj/project.pbxproj: 17 * platform/audio/WebAudioBufferList.cpp: 18 (WebCore::WebAudioBufferList::WebAudioBufferList): Missing initialization leads to assertion failure. 19 * platform/audio/mac/AudioSampleBufferList.cpp: 20 (WebCore::AudioSampleBufferList::copyFrom): In case of interleaved channels, there is one buffer but two channels. 21 * platform/audio/mac/AudioSampleDataSource.cpp: 22 (WebCore::AudioSampleDataSource::pushSamples): 23 (WebCore::AudioSampleDataSource::pullAvalaibleSamplesAsChunks): 24 * platform/audio/mac/AudioSampleDataSource.h: 25 * platform/mediastream/libwebrtc/LibWebRTCAudioFormat.h: Added. 26 * platform/mediastream/mac/RealtimeOutgoingAudioSource.cpp: 27 (WebCore::libwebrtcAudioFormat): 28 (WebCore::RealtimeOutgoingAudioSource::RealtimeOutgoingAudioSource): 29 (WebCore::RealtimeOutgoingAudioSource::sourceMutedChanged): 30 (WebCore::RealtimeOutgoingAudioSource::audioSamplesAvailable): 31 (WebCore::RealtimeOutgoingAudioSource::pullAudioData): 32 * platform/mediastream/mac/RealtimeOutgoingAudioSource.h: 33 1 34 2017-02-10 Ryosuke Niwa <rniwa@webkit.org> 2 35 -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r211962 r212144 8877 8877 41D015C80F4B5C71004A662F /* ContentType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContentType.h; sourceTree = "<group>"; }; 8878 8878 41D015C90F4B5C71004A662F /* ContentType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ContentType.cpp; sourceTree = "<group>"; }; 8879 41D51BB21E4E2E8100131A5B /* LibWebRTCAudioFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LibWebRTCAudioFormat.h; path = libwebrtc/LibWebRTCAudioFormat.h; sourceTree = "<group>"; }; 8879 8880 41E1B1CA0FF5986900576B3B /* AbstractWorker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AbstractWorker.cpp; sourceTree = "<group>"; }; 8880 8881 41E1B1CB0FF5986900576B3B /* AbstractWorker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AbstractWorker.h; sourceTree = "<group>"; }; … … 16846 16847 isa = PBXGroup; 16847 16848 children = ( 16849 41D51BB21E4E2E8100131A5B /* LibWebRTCAudioFormat.h */, 16848 16850 415080341E3F00AA0051D75D /* LibWebRTCAudioModule.cpp */, 16849 16851 415080351E3F00AA0051D75D /* LibWebRTCAudioModule.h */, -
trunk/Source/WebCore/platform/audio/WebAudioBufferList.cpp
r211959 r212144 65 65 for (uint32_t buffer = 0; buffer < m_list->mNumberBuffers; ++buffer) { 66 66 m_list->mBuffers[buffer].mData = data; 67 m_list->mBuffers[buffer].mDataByteSize = bytesPerBuffer; 67 68 data += bytesPerBuffer; 68 69 } -
trunk/Source/WebCore/platform/audio/mac/AudioSampleBufferList.cpp
r211978 r212144 261 261 AudioConverterGetProperty(converter, kAudioConverterCurrentOutputStreamDescription, &propertyDataSize, &outputFormat); 262 262 263 ASSERT( outputFormat.mChannelsPerFrame== m_bufferList->bufferCount());263 ASSERT(CAAudioStreamDescription(outputFormat).numberOfChannelStreams() == m_bufferList->bufferCount()); 264 264 for (uint32_t i = 0; i < m_bufferList->bufferCount(); ++i) { 265 265 ASSERT(m_bufferList->buffer(i)->mData); -
trunk/Source/WebCore/platform/audio/mac/AudioSampleDataSource.cpp
r211978 r212144 202 202 std::unique_lock<Lock> lock(m_lock, std::try_to_lock); 203 203 ASSERT(is<WebAudioBufferList>(audioData)); 204 pushSamplesInternal( downcast<WebAudioBufferList>(audioData), sampleTime, sampleCount);204 pushSamplesInternal(*downcast<WebAudioBufferList>(audioData).list(), sampleTime, sampleCount); 205 205 } 206 206 … … 287 287 } 288 288 289 bool AudioSampleDataSource::pullAvalaibleSamplesAsChunks(AudioBufferList& buffer, size_t sampleCountPerChunk, uint64_t timeStamp, Function<void()>&& consumeFilledBuffer) 290 { 291 std::unique_lock<Lock> lock(m_lock, std::try_to_lock); 292 if (!lock.owns_lock() || !m_ringBuffer) 293 return false; 294 295 ASSERT(buffer.mNumberBuffers == m_ringBuffer->channelCount()); 296 if (buffer.mNumberBuffers != m_ringBuffer->channelCount()) 297 return false; 298 299 uint64_t startFrame = 0; 300 uint64_t endFrame = 0; 301 m_ringBuffer->getCurrentFrameBounds(startFrame, endFrame); 302 if (timeStamp < startFrame) 303 return false; 304 305 startFrame = timeStamp; 306 while (endFrame - startFrame >= sampleCountPerChunk) { 307 if (m_ringBuffer->fetch(&buffer, sampleCountPerChunk, startFrame, CARingBuffer::Copy)) 308 return false; 309 consumeFilledBuffer(); 310 startFrame += sampleCountPerChunk; 311 } 312 return true; 313 } 314 289 315 bool AudioSampleDataSource::pullSamples(AudioBufferList& buffer, size_t sampleCount, uint64_t timeStamp, double hostTime, PullMode mode) 290 316 { -
trunk/Source/WebCore/platform/audio/mac/AudioSampleDataSource.h
r211978 r212144 60 60 bool pullSamples(AudioBufferList&, size_t, uint64_t, double, PullMode); 61 61 62 bool pullAvalaibleSamplesAsChunks(AudioBufferList&, size_t frameCount, uint64_t timeStamp, Function<void()>&&); 63 62 64 void setPaused(bool); 63 65 -
trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.cpp
r211978 r212144 32 32 #if USE(LIBWEBRTC) 33 33 34 #include "NotImplemented.h" 34 #include "CAAudioStreamDescription.h" 35 #include "LibWebRTCAudioFormat.h" 36 #include "LibWebRTCUtils.h" 35 37 36 38 namespace WebCore { 37 39 38 void RealtimeOutgoingAudioSource::audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t)40 static inline AudioStreamBasicDescription libwebrtcAudioFormat(size_t channelCount) 39 41 { 40 notImplemented(); 42 AudioStreamBasicDescription streamFormat; 43 FillOutASBDForLPCM(streamFormat, LibWebRTCAudioFormat::sampleRate, channelCount, LibWebRTCAudioFormat::sampleSize, LibWebRTCAudioFormat::sampleSize, LibWebRTCAudioFormat::isFloat, LibWebRTCAudioFormat::isBigEndian, LibWebRTCAudioFormat::isNonInterleaved); 44 return streamFormat; 45 } 46 47 RealtimeOutgoingAudioSource::RealtimeOutgoingAudioSource(Ref<RealtimeMediaSource>&& audioSource) 48 : m_audioSource(WTFMove(audioSource)) 49 , m_sampleConverter(AudioSampleDataSource::create(LibWebRTCAudioFormat::sampleRate * 2)) 50 { 51 m_audioSource->addObserver(*this); 52 } 53 54 void RealtimeOutgoingAudioSource::sourceMutedChanged() 55 { 56 m_isMuted = m_audioSource->muted(); 57 } 58 59 void RealtimeOutgoingAudioSource::audioSamplesAvailable(const MediaTime& time, const PlatformAudioData& audioData, const AudioStreamDescription& streamDescription, size_t sampleCount) 60 { 61 if (m_inputStreamDescription != streamDescription) { 62 m_inputStreamDescription = toCAAudioStreamDescription(streamDescription); 63 auto status = m_sampleConverter->setInputFormat(m_inputStreamDescription); 64 ASSERT_UNUSED(status, !status); 65 66 status = m_sampleConverter->setOutputFormat(libwebrtcAudioFormat(streamDescription.numberOfChannels())); 67 ASSERT(!status); 68 } 69 m_sampleConverter->pushSamples(time, audioData, sampleCount); 70 71 callOnWebRTCSignalingThread([protectedThis = makeRef(*this)] { 72 protectedThis->pullAudioData(); 73 }); 74 } 75 76 void RealtimeOutgoingAudioSource::pullAudioData() 77 { 78 size_t bufferSize = LibWebRTCAudioFormat::chunkSampleCount * LibWebRTCAudioFormat::sampleByteSize * m_inputStreamDescription.numberOfChannels(); 79 m_audioBuffer.reserveCapacity(bufferSize); 80 81 AudioBufferList bufferList; 82 bufferList.mNumberBuffers = 1; 83 bufferList.mBuffers[0].mNumberChannels = m_inputStreamDescription.numberOfChannels(); 84 bufferList.mBuffers[0].mDataByteSize = bufferSize; 85 bufferList.mBuffers[0].mData = m_audioBuffer.data(); 86 87 m_sampleConverter->pullAvalaibleSamplesAsChunks(bufferList, LibWebRTCAudioFormat::chunkSampleCount, m_startFrame, [this] { 88 m_startFrame += LibWebRTCAudioFormat::chunkSampleCount; 89 if (m_isMuted) 90 return; 91 for (auto sink : m_sinks) 92 sink->OnData(m_audioBuffer.data(), LibWebRTCAudioFormat::sampleSize, LibWebRTCAudioFormat::sampleRate, m_inputStreamDescription.numberOfChannels(), LibWebRTCAudioFormat::chunkSampleCount); 93 }); 41 94 } 42 95 -
trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.h
r211978 r212144 31 31 #if USE(LIBWEBRTC) 32 32 33 #include "AudioSampleDataSource.h" 33 34 #include "LibWebRTCMacros.h" 34 35 #include "RealtimeMediaSource.h" … … 50 51 51 52 private: 52 explicit RealtimeOutgoingAudioSource(Ref<RealtimeMediaSource>&& audioSource) : m_audioSource(WTFMove(audioSource)) { m_audioSource->addObserver(*this); }53 explicit RealtimeOutgoingAudioSource(Ref<RealtimeMediaSource>&&); 53 54 54 55 virtual void AddSink(webrtc::AudioTrackSinkInterface* sink) { m_sinks.append(sink); } … … 64 65 // RealtimeMediaSource::Observer API 65 66 void sourceStopped() final { } 66 void sourceMutedChanged() final { }67 void sourceMutedChanged() final; 67 68 void sourceSettingsChanged() final { } 68 69 bool preventSourceFromStopping() final { return false; } 69 70 void audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t) final; 70 71 71 void convertAndSendMonoSamples(); 72 void convertAndSendStereoSamples(); 72 void pullAudioData(); 73 73 74 74 Vector<webrtc::AudioTrackSinkInterface*> m_sinks; 75 75 Ref<RealtimeMediaSource> m_audioSource; 76 76 rtc::scoped_refptr<webrtc::AudioTrackInterface> m_track; 77 Ref<AudioSampleDataSource> m_sampleConverter; 78 CAAudioStreamDescription m_inputStreamDescription; 79 80 Vector<uint16_t> m_audioBuffer; 81 uint64_t m_startFrame { 0 }; 82 bool m_isMuted { false }; 77 83 }; 78 84
Note: See TracChangeset
for help on using the changeset viewer.