Title: [259716] trunk/Source/WebCore
Revision
259716
Author
[email protected]
Date
2020-04-08 08:03:09 -0700 (Wed, 08 Apr 2020)

Log Message

Handle errors when grabbing grabbing microphone audio samples from the AudioUnit
https://bugs.webkit.org/show_bug.cgi?id=210185

Reviewed by Eric Carlson.

We compute the buffer size to copy microphone samples when setting up the Audio Unit.
This is based on the preferred buffer size and sample rate.
But these values might change over time by the web page durig the capture.
If the preferred buffer size increases (for instance if the page stops using WebAudio), our buffer might be too small.
Capture will fail but we will not notify the web application.

Update the code to reconfigure the AudioUnit if AudioUnitRender returns an error of type kAudio_ParamError.
Update the code to only increment the number of microphoneProcsCalled if AudioUnitRender succeeds.
This will ensure that, should AudioUnitRender fails for some time, the timer will kick in and fail the capture.
Page will be notified and can call getUserMedia again to restart capture.

* platform/mediastream/mac/CoreAudioCaptureSource.cpp:
(WebCore::CoreAudioSharedUnit::processMicrophoneSamples):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (259715 => 259716)


--- trunk/Source/WebCore/ChangeLog	2020-04-08 14:32:12 UTC (rev 259715)
+++ trunk/Source/WebCore/ChangeLog	2020-04-08 15:03:09 UTC (rev 259716)
@@ -1,3 +1,24 @@
+2020-04-08  Youenn Fablet  <[email protected]>
+
+        Handle errors when grabbing grabbing microphone audio samples from the AudioUnit
+        https://bugs.webkit.org/show_bug.cgi?id=210185
+
+        Reviewed by Eric Carlson.
+
+        We compute the buffer size to copy microphone samples when setting up the Audio Unit.
+        This is based on the preferred buffer size and sample rate.
+        But these values might change over time by the web page durig the capture.
+        If the preferred buffer size increases (for instance if the page stops using WebAudio), our buffer might be too small.
+        Capture will fail but we will not notify the web application.
+
+        Update the code to reconfigure the AudioUnit if AudioUnitRender returns an error of type kAudio_ParamError.
+        Update the code to only increment the number of microphoneProcsCalled if AudioUnitRender succeeds.
+        This will ensure that, should AudioUnitRender fails for some time, the timer will kick in and fail the capture.
+        Page will be notified and can call getUserMedia again to restart capture.
+
+        * platform/mediastream/mac/CoreAudioCaptureSource.cpp:
+        (WebCore::CoreAudioSharedUnit::processMicrophoneSamples):
+
 2020-04-08  Keith Rollin  <[email protected]>
 
         Enable the use of XCBuild by default in Apple builds

Modified: trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.cpp (259715 => 259716)


--- trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.cpp	2020-04-08 14:32:12 UTC (rev 259715)
+++ trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.cpp	2020-04-08 15:03:09 UTC (rev 259716)
@@ -408,17 +408,24 @@
 
 OSStatus CoreAudioSharedUnit::processMicrophoneSamples(AudioUnitRenderActionFlags& ioActionFlags, const AudioTimeStamp& timeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* /*ioData*/)
 {
-    ++m_microphoneProcsCalled;
-
     // Pull through the vpio unit to our mic buffer.
     m_microphoneSampleBuffer->reset();
     AudioBufferList& bufferList = m_microphoneSampleBuffer->bufferList();
     auto err = AudioUnitRender(m_ioUnit, &ioActionFlags, &timeStamp, inBusNumber, inNumberFrames, &bufferList);
     if (err) {
-        RELEASE_LOG_ERROR(WebRTC, "CoreAudioSharedUnit::processMicrophoneSamples(%p) AudioUnitRender failed with error %d (%.4s)", this, (int)err, (char*)&err);
+        RELEASE_LOG_ERROR(WebRTC, "CoreAudioSharedUnit::processMicrophoneSamples(%p) AudioUnitRender failed with error %d (%.4s), bufferList size %d, inNumberFrames %d ", this, (int)err, (char*)&err, (int)bufferList.mBuffers[0].mDataByteSize, (int)inNumberFrames);
+        if (err == kAudio_ParamError) {
+            // Our buffer might be too small, the preferred buffer size or sample rate might have changed.
+            callOnMainThread([] {
+                CoreAudioSharedUnit::singleton().reconfigure();
+            });
+        }
+        // We return early so that if this error happens, we do not increment m_microphoneProcsCalled and fail the capture once timer kicks in.
         return err;
     }
 
+    ++m_microphoneProcsCalled;
+
     double adjustedHostTime = m_DTSConversionRatio * timeStamp.mHostTime;
     uint64_t sampleTime = timeStamp.mSampleTime;
 #if !LOG_DISABLED
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to