Modified: trunk/Source/WebCore/ChangeLog (276244 => 276245)
--- trunk/Source/WebCore/ChangeLog 2021-04-19 09:56:09 UTC (rev 276244)
+++ trunk/Source/WebCore/ChangeLog 2021-04-19 10:28:56 UTC (rev 276245)
@@ -1,5 +1,21 @@
2021-04-19 Youenn Fablet <[email protected]>
+ Make RealtimeIncomingAudioSourceCocoa preallocate audio buffer
+ https://bugs.webkit.org/show_bug.cgi?id=224672
+
+ Reviewed by Eric Carlson.
+
+ Instead of allocating the buffer on valid data, we wait for data to be of the correct sample rate.
+ We preallocate the buffer accordingly in constructor to avoid allocation in the webrtc audio thread.
+ Default is 1 channel since mono is what webrtc encoders mostly do these days.
+ Covered by existing tests.
+
+ * platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.cpp:
+ (WebCore::RealtimeIncomingAudioSourceCocoa::RealtimeIncomingAudioSourceCocoa):
+ (WebCore::RealtimeIncomingAudioSourceCocoa::OnData):
+
+2021-04-19 Youenn Fablet <[email protected]>
+
Move from RecursiveLock to Lock in RealtimeMediaSource
https://bugs.webkit.org/show_bug.cgi?id=224671
Modified: trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.cpp (276244 => 276245)
--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.cpp 2021-04-19 09:56:09 UTC (rev 276244)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.cpp 2021-04-19 10:28:56 UTC (rev 276245)
@@ -53,11 +53,6 @@
return adoptRef(*new RealtimeIncomingAudioSourceCocoa(WTFMove(audioTrack), WTFMove(audioTrackId)));
}
-RealtimeIncomingAudioSourceCocoa::RealtimeIncomingAudioSourceCocoa(rtc::scoped_refptr<webrtc::AudioTrackInterface>&& audioTrack, String&& audioTrackId)
- : RealtimeIncomingAudioSource(WTFMove(audioTrack), WTFMove(audioTrackId))
-{
-}
-
static inline AudioStreamBasicDescription streamDescription(size_t sampleRate, size_t channelCount)
{
AudioStreamBasicDescription streamFormat;
@@ -65,8 +60,20 @@
return streamFormat;
}
+RealtimeIncomingAudioSourceCocoa::RealtimeIncomingAudioSourceCocoa(rtc::scoped_refptr<webrtc::AudioTrackInterface>&& audioTrack, String&& audioTrackId)
+ : RealtimeIncomingAudioSource(WTFMove(audioTrack), WTFMove(audioTrackId))
+ , m_sampleRate(LibWebRTCAudioFormat::sampleRate)
+ , m_numberOfChannels(1)
+ , m_streamDescription(streamDescription(m_sampleRate, m_numberOfChannels))
+ , m_audioBufferList(makeUnique<WebAudioBufferList>(m_streamDescription))
+{
+}
+
void RealtimeIncomingAudioSourceCocoa::OnData(const void* audioData, int bitsPerSample, int sampleRate, size_t numberOfChannels, size_t numberOfFrames)
{
+ if (sampleRate != m_sampleRate)
+ return;
+
#if !RELEASE_LOG_DISABLED
if (!(++m_chunksReceived % 200)) {
callOnMainThread([identifier = LOGIDENTIFIER, this, protectedThis = makeRef(*this), chunksReceived = m_chunksReceived] {
@@ -75,7 +82,7 @@
}
#endif
- if (!m_audioBufferList || m_sampleRate != sampleRate || m_numberOfChannels != numberOfChannels) {
+ if (!m_audioBufferList || m_numberOfChannels != numberOfChannels) {
callOnMainThread([identifier = LOGIDENTIFIER, this, protectedThis = makeRef(*this), sampleRate, numberOfChannels] {
ALWAYS_LOG_IF(loggerPtr(), identifier, "new audio buffer list for sampleRate ", sampleRate, " and ", numberOfChannels, " channel(s)");
});