Changeset 285985 in webkit


Ignore:
Timestamp:
Nov 17, 2021 11:53:25 PM (8 months ago)
Author:
youenn@apple.com
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):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r285984 r285985  
     12021-11-17  Youenn Fablet  <youenn@apple.com>
     2
     3        Audio Rate Gets Messed up With Safari WebRTC and Bluetooth Switching
     4        https://bugs.webkit.org/show_bug.cgi?id=232822
     5        <rdar://problem/85418545>
     6
     7        Reviewed by Eric Carlson.
     8
     9        We usually create the unit, start the unit and stop the unit.
     10        After that cycle, if we restart the unit, we expect the configuration to stay the same in WebProcess.
     11        But, in LocalAudioMediaStreamTrackRendererInternalUnit::stop, we were disposing the audio unit and recreating it if necesary in LocalAudioMediaStreamTrackRendererInternalUnit::start.
     12        If the sample rate changed, the new audio unit would use the new sample rate while WebProcess will use the old sample rate.
     13        To prevent this, we now always reuse the same description to initialize the audio unit.
     14
     15        Manually tested.
     16
     17        * platform/mediastream/cocoa/AudioMediaStreamTrackRendererInternalUnit.cpp:
     18        (WebCore::LocalAudioMediaStreamTrackRendererInternalUnit::createAudioUnitIfNeeded):
     19
    1202021-11-17  Youenn Fablet  <youenn@apple.com>
    221
  • trunk/Source/WebCore/platform/mediastream/cocoa/AudioMediaStreamTrackRendererInternalUnit.cpp

    r285023 r285985  
    163163        return;
    164164
    165     CAAudioStreamDescription outputDescription;
    166165    AudioComponentInstance remoteIOUnit { nullptr };
    167166
     
    212211    }
    213212
    214     UInt32 size = sizeof(outputDescription.streamDescription());
    215     error  = PAL::AudioUnitGetProperty(remoteIOUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &outputDescription.streamDescription(), &size);
    216     if (error) {
    217         RELEASE_LOG_ERROR(WebRTC, "AudioMediaStreamTrackRendererInternalUnit::createAudioUnit unable to get input stream format, error = %d", error);
    218         return;
    219     }
    220 
    221     outputDescription.streamDescription().mSampleRate = AudioSession::sharedSession().sampleRate();
    222 
    223     error = PAL::AudioUnitSetProperty(remoteIOUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &outputDescription.streamDescription(), sizeof(outputDescription.streamDescription()));
     213    if (!m_outputDescription) {
     214        CAAudioStreamDescription outputDescription;
     215        UInt32 size = sizeof(outputDescription.streamDescription());
     216        error  = PAL::AudioUnitGetProperty(remoteIOUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &outputDescription.streamDescription(), &size);
     217        if (error) {
     218            RELEASE_LOG_ERROR(WebRTC, "AudioMediaStreamTrackRendererInternalUnit::createAudioUnit unable to get input stream format, error = %d", error);
     219            return;
     220        }
     221
     222        outputDescription.streamDescription().mSampleRate = AudioSession::sharedSession().sampleRate();
     223        m_outputDescription = makeUnique<CAAudioStreamDescription>(outputDescription);
     224    }
     225    error = PAL::AudioUnitSetProperty(remoteIOUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &m_outputDescription->streamDescription(), sizeof(m_outputDescription->streamDescription()));
    224226    if (error) {
    225227        RELEASE_LOG_ERROR(WebRTC, "AudioMediaStreamTrackRendererInternalUnit::createAudioUnit unable to set input stream format, error = %d", error);
     
    233235    }
    234236
    235     m_outputDescription = makeUnique<CAAudioStreamDescription>(outputDescription);
    236237    m_remoteIOUnit = remoteIOUnit;
    237238}
Note: See TracChangeset for help on using the changeset viewer.