Title: [285985] trunk/Source/WebCore
Revision
285985
Author
you...@apple.com
Date
2021-11-17 23:53:25 -0800 (Wed, 17 Nov 2021)

Log Message

Audio Rate Gets Messed up With Safari WebRTC and Bluetooth Switching
https://bugs.webkit.org/show_bug.cgi?id=232822
<rdar://problem/85418545>

Reviewed by Eric Carlson.

We usually create the unit, start the unit and stop the unit.
After that cycle, if we restart the unit, we expect the configuration to stay the same in WebProcess.
But, in LocalAudioMediaStreamTrackRendererInternalUnit::stop, we were disposing the audio unit and recreating it if necesary in LocalAudioMediaStreamTrackRendererInternalUnit::start.
If the sample rate changed, the new audio unit would use the new sample rate while WebProcess will use the old sample rate.
To prevent this, we now always reuse the same description to initialize the audio unit.

Manually tested.

* platform/mediastream/cocoa/AudioMediaStreamTrackRendererInternalUnit.cpp:
(WebCore::LocalAudioMediaStreamTrackRendererInternalUnit::createAudioUnitIfNeeded):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (285984 => 285985)


--- trunk/Source/WebCore/ChangeLog	2021-11-18 07:46:05 UTC (rev 285984)
+++ trunk/Source/WebCore/ChangeLog	2021-11-18 07:53:25 UTC (rev 285985)
@@ -1,5 +1,24 @@
 2021-11-17  Youenn Fablet  <you...@apple.com>
 
+        Audio Rate Gets Messed up With Safari WebRTC and Bluetooth Switching
+        https://bugs.webkit.org/show_bug.cgi?id=232822
+        <rdar://problem/85418545>
+
+        Reviewed by Eric Carlson.
+
+        We usually create the unit, start the unit and stop the unit.
+        After that cycle, if we restart the unit, we expect the configuration to stay the same in WebProcess.
+        But, in LocalAudioMediaStreamTrackRendererInternalUnit::stop, we were disposing the audio unit and recreating it if necesary in LocalAudioMediaStreamTrackRendererInternalUnit::start.
+        If the sample rate changed, the new audio unit would use the new sample rate while WebProcess will use the old sample rate.
+        To prevent this, we now always reuse the same description to initialize the audio unit.
+
+        Manually tested.
+
+        * platform/mediastream/cocoa/AudioMediaStreamTrackRendererInternalUnit.cpp:
+        (WebCore::LocalAudioMediaStreamTrackRendererInternalUnit::createAudioUnitIfNeeded):
+
+2021-11-17  Youenn Fablet  <you...@apple.com>
+
         Add support for more rvfc metadata
         https://bugs.webkit.org/show_bug.cgi?id=233185
 

Modified: trunk/Source/WebCore/platform/mediastream/cocoa/AudioMediaStreamTrackRendererInternalUnit.cpp (285984 => 285985)


--- trunk/Source/WebCore/platform/mediastream/cocoa/AudioMediaStreamTrackRendererInternalUnit.cpp	2021-11-18 07:46:05 UTC (rev 285984)
+++ trunk/Source/WebCore/platform/mediastream/cocoa/AudioMediaStreamTrackRendererInternalUnit.cpp	2021-11-18 07:53:25 UTC (rev 285985)
@@ -162,7 +162,6 @@
     if (m_remoteIOUnit)
         return;
 
-    CAAudioStreamDescription outputDescription;
     AudioComponentInstance remoteIOUnit { nullptr };
 
     AudioComponentDescription ioUnitDescription { kAudioUnitType_Output, 0, kAudioUnitManufacturer_Apple, 0, 0 };
@@ -211,16 +210,19 @@
         return;
     }
 
-    UInt32 size = sizeof(outputDescription.streamDescription());
-    error  = PAL::AudioUnitGetProperty(remoteIOUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &outputDescription.streamDescription(), &size);
-    if (error) {
-        RELEASE_LOG_ERROR(WebRTC, "AudioMediaStreamTrackRendererInternalUnit::createAudioUnit unable to get input stream format, error = %d", error);
-        return;
+    if (!m_outputDescription) {
+        CAAudioStreamDescription outputDescription;
+        UInt32 size = sizeof(outputDescription.streamDescription());
+        error  = PAL::AudioUnitGetProperty(remoteIOUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &outputDescription.streamDescription(), &size);
+        if (error) {
+            RELEASE_LOG_ERROR(WebRTC, "AudioMediaStreamTrackRendererInternalUnit::createAudioUnit unable to get input stream format, error = %d", error);
+            return;
+        }
+
+        outputDescription.streamDescription().mSampleRate = AudioSession::sharedSession().sampleRate();
+        m_outputDescription = makeUnique<CAAudioStreamDescription>(outputDescription);
     }
-
-    outputDescription.streamDescription().mSampleRate = AudioSession::sharedSession().sampleRate();
-
-    error = PAL::AudioUnitSetProperty(remoteIOUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &outputDescription.streamDescription(), sizeof(outputDescription.streamDescription()));
+    error = PAL::AudioUnitSetProperty(remoteIOUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &m_outputDescription->streamDescription(), sizeof(m_outputDescription->streamDescription()));
     if (error) {
         RELEASE_LOG_ERROR(WebRTC, "AudioMediaStreamTrackRendererInternalUnit::createAudioUnit unable to set input stream format, error = %d", error);
         return;
@@ -232,7 +234,6 @@
         return;
     }
 
-    m_outputDescription = makeUnique<CAAudioStreamDescription>(outputDescription);
     m_remoteIOUnit = remoteIOUnit;
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to