Changeset 259632 in webkit
- Timestamp:
- Apr 7, 2020 4:14:01 AM (4 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r259631 r259632 1 2020-04-07 Youenn Fablet <youenn@apple.com> 2 3 Remove unnecessary memory allocation from RealtimeIncomingAudioSourceCocoa::OnData 4 https://bugs.webkit.org/show_bug.cgi?id=209969 5 6 Reviewed by Eric Carlson. 7 8 Instead of allocating a new buffer for every audio chunk and copy the audio chunk, 9 Create a WebAudioBufferList once (without any buffer allocation) and set the audio buffer pointer 10 given by libwebrtc as the WebAudioBufferList buffer pointer. 11 We do not take care of muted state anymore since this is done by consumers anyway. 12 Covered by existing tests. 13 14 * platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.cpp: 15 (WebCore::RealtimeIncomingAudioSourceCocoa::OnData): 16 * platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.h: 17 1 18 2020-04-07 Claudio Saavedra <csaavedra@igalia.com> 2 19 -
trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.cpp
r248288 r259632 35 35 #include "LibWebRTCAudioFormat.h" 36 36 #include "Logging.h" 37 #include "WebAudioBufferList.h"38 #include "WebAudioSourceProviderAVFObjC.h"39 37 #include <pal/avfoundation/MediaTimeAVFoundation.h> 40 38 … … 70 68 void RealtimeIncomingAudioSourceCocoa::OnData(const void* audioData, int bitsPerSample, int sampleRate, size_t numberOfChannels, size_t numberOfFrames) 71 69 { 70 #if !RELEASE_LOG_DISABLED 71 if (!(++m_chunksReceived % 200)) { 72 callOnMainThread([identifier = LOGIDENTIFIER, this, protectedThis = makeRef(*this), chunksReceived = m_chunksReceived] { 73 ALWAYS_LOG_IF(loggerPtr(), identifier, "chunk ", chunksReceived); 74 }); 75 } 76 #endif 77 72 78 CMTime startTime = CMTimeMake(m_numberOfFrames, sampleRate); 73 79 auto mediaTime = PAL::toMediaTime(startTime); 74 80 m_numberOfFrames += numberOfFrames; 75 81 76 AudioStreamBasicDescription newDescription = streamDescription(sampleRate, numberOfChannels); 82 if (!m_audioBufferList || m_sampleRate != sampleRate || m_numberOfChannels != numberOfChannels) { 83 callOnMainThread([identifier = LOGIDENTIFIER, this, protectedThis = makeRef(*this), sampleRate, numberOfChannels] { 84 ALWAYS_LOG_IF(loggerPtr(), identifier, "new audio buffer list for sampleRate ", sampleRate, " and ", numberOfChannels, " channel(s)"); 85 }); 77 86 78 // FIXME: We should not need to do the extra memory allocation and copy.79 // Instead, we should be able to directly pass audioData pointer.80 WebAudioBufferList audioBufferList { CAAudioStreamDescription(newDescription), WTF::safeCast<uint32_t>(numberOfFrames) };81 audioBufferList.buffer(0)->mDataByteSize = numberOfChannels * numberOfFrames * bitsPerSample / 8;82 audioBufferList.buffer(0)->mNumberChannels = numberOfChannels;87 m_sampleRate = sampleRate; 88 m_numberOfChannels = numberOfChannels; 89 m_streamDescription = streamDescription(sampleRate, numberOfChannels); 90 m_audioBufferList = makeUnique<WebAudioBufferList>(m_streamDescription); 91 } 83 92 84 if (muted())85 memset(audioBufferList.buffer(0)->mData, 0, audioBufferList.buffer(0)->mDataByteSize);86 else87 memcpy(audioBufferList.buffer(0)->mData, audioData, audioBufferList.buffer(0)->mDataByteSize);93 auto& bufferList = *m_audioBufferList->buffer(0); 94 bufferList.mDataByteSize = numberOfChannels * numberOfFrames * bitsPerSample / 8; 95 bufferList.mNumberChannels = numberOfChannels; 96 bufferList.mData = const_cast<void*>(audioData); 88 97 89 #if !RELEASE_LOG_DISABLED 90 ALWAYS_LOG_IF(loggerPtr() && !(++m_chunksReceived % 200), LOGIDENTIFIER, "chunk ", m_chunksReceived); 91 #endif 92 93 audioSamplesAvailable(mediaTime, audioBufferList, CAAudioStreamDescription(newDescription), numberOfFrames); 98 audioSamplesAvailable(mediaTime, *m_audioBufferList, m_streamDescription, numberOfFrames); 94 99 } 95 100 -
trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.h
r240120 r259632 31 31 32 32 #include "RealtimeIncomingAudioSource.h" 33 33 #include "WebAudioBufferList.h" 34 34 #include <CoreAudio/CoreAudioTypes.h> 35 35 … … 52 52 uint64_t m_numberOfFrames { 0 }; 53 53 54 int m_sampleRate { 0 }; 55 size_t m_numberOfChannels { 0 }; 56 CAAudioStreamDescription m_streamDescription; 57 std::unique_ptr<WebAudioBufferList> m_audioBufferList; 54 58 #if !RELEASE_LOG_DISABLED 55 59 size_t m_chunksReceived { 0 };
Note: See TracChangeset
for help on using the changeset viewer.