⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 294838 in webkit


Ignore:
Timestamp:
May 25, 2022, 4:49:33 PM (4 years ago)
Author:
Alan Coon
Message:

Cherry-pick r293664. rdar://problem/92362769

VPIO requires the same sample rate for microphone and speaker formats
​https://bugs.webkit.org/show_bug.cgi?id=239956

Reviewed by Eric Carlson.

VPIO requires the speaker sample rate and microphone sample rate to be the same.
This is not guaranteed to be true : getUserMedia/applyConstraints may set the microphone sample rate to different values.
If audio rendering already started at capture start time, we use the audio rendering sample rate.
This is not strictly compliant, given required constraints but they are not widely used.
Applications that want to make sure to use a specific sample rate would need to pause audio rendering when starting to capture.
We reset exposed settings when starting to capture to expose the actual sample rate to JavaScript through MediaStreamTrack.getSettings().

Manually tested.

  • platform/mediastream/mac/BaseAudioSharedUnit.h:
  • platform/mediastream/mac/CoreAudioCaptureSource.cpp:

Canonical link: ​https://commits.webkit.org/250168@main
git-svn-id: ​https://svn.webkit.org/repository/webkit/trunk@293664 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Location:
branches/safari-613-branch/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-613-branch/Source/WebCore/ChangeLog

    r294836 r294838  
     12022-05-19  Alan Coon  <alancoon@apple.com>
     2
     3        Cherry-pick r293664. rdar://problem/92362769
     4
     5    VPIO requires the same sample rate for microphone and speaker formats
     6    https://bugs.webkit.org/show_bug.cgi?id=239956
     7   
     8    Reviewed by Eric Carlson.
     9   
     10    VPIO requires the speaker sample rate and microphone sample rate to be the same.
     11    This is not guaranteed to be true : getUserMedia/applyConstraints may set the microphone sample rate to different values.
     12    If audio rendering already started at capture start time, we use the audio rendering sample rate.
     13    This is not strictly compliant, given required constraints but they are not widely used.
     14    Applications that want to make sure to use a specific sample rate would need to pause audio rendering when starting to capture.
     15    We reset exposed settings when starting to capture to expose the actual sample rate to JavaScript through MediaStreamTrack.getSettings().
     16   
     17    Manually tested.
     18   
     19    * platform/mediastream/mac/BaseAudioSharedUnit.h:
     20    * platform/mediastream/mac/CoreAudioCaptureSource.cpp:
     21   
     22    Canonical link: https://commits.webkit.org/250168@main
     23    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@293664 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     24
     25    2022-05-02  Youenn Fablet  <youenn@apple.com>
     26
     27            VPIO requires the same sample rate for microphone and speaker formats
     28            https://bugs.webkit.org/show_bug.cgi?id=239956
     29
     30            Reviewed by Eric Carlson.
     31
     32            VPIO requires the speaker sample rate and microphone sample rate to be the same.
     33            This is not guaranteed to be true : getUserMedia/applyConstraints may set the microphone sample rate to different values.
     34            If audio rendering already started at capture start time, we use the audio rendering sample rate.
     35            This is not strictly compliant, given required constraints but they are not widely used.
     36            Applications that want to make sure to use a specific sample rate would need to pause audio rendering when starting to capture.
     37            We reset exposed settings when starting to capture to expose the actual sample rate to JavaScript through MediaStreamTrack.getSettings().
     38
     39            Manually tested.
     40
     41            * platform/mediastream/mac/BaseAudioSharedUnit.h:
     42            * platform/mediastream/mac/CoreAudioCaptureSource.cpp:
     43
    1442022-05-19  Alan Coon  <alancoon@apple.com>
    245
  • branches/safari-613-branch/Source/WebCore/platform/mediastream/mac/BaseAudioSharedUnit.h

    r289311 r294838  
    7878
    7979    virtual CapabilityValueOrRange sampleRateCapacities() const = 0;
     80    virtual int actualSampleRate() const { return sampleRate(); }
    8081
    8182    void devicesChanged(const Vector<CaptureDevice>&);
  • branches/safari-613-branch/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.cpp

    r291923 r294838  
    102102    void isProducingMicrophoneSamplesChanged() final;
    103103    void validateOutputDevice(uint32_t deviceID) final;
    104 
    105     OSStatus configureSpeakerProc();
    106     OSStatus configureMicrophoneProc();
     104    int actualSampleRate() const final;
     105
     106    OSStatus configureSpeakerProc(int sampleRate);
     107    OSStatus configureMicrophoneProc(int sampleRate);
    107108    OSStatus defaultOutputDevice(uint32_t*);
    108109    OSStatus defaultInputDevice(uint32_t*);
    … …  
    150151
    151152    bool m_isReconfiguring { false };
    152     Lock m_speakerSamplesProducerLock;
     153    mutable Lock m_speakerSamplesProducerLock;
    153154    CoreAudioSpeakerSamplesProducer* m_speakerSamplesProducer WTF_GUARDED_BY_LOCK(m_speakerSamplesProducerLock) { nullptr };
    154155};
    … …  
    259260#endif
    260261
    261     err = configureMicrophoneProc();
     262    // FIXME: Add support for different speaker/microphone sample rates.
     263    int actualSampleRate = this->actualSampleRate();
     264    err = configureMicrophoneProc(actualSampleRate);
    262265    if (err)
    263266        return err;
    264267
    265     err = configureSpeakerProc();
     268    err = configureSpeakerProc(actualSampleRate);
    266269    if (err)
    267270        return err;
    … …  
    286289}
    287290
    288 OSStatus CoreAudioSharedUnit::configureMicrophoneProc()
    289 {
     291int CoreAudioSharedUnit::actualSampleRate() const
     292{
     293    Locker locker { m_speakerSamplesProducerLock };
     294    return m_speakerSamplesProducer ? m_speakerSamplesProducer->format().streamDescription().mSampleRate : sampleRate();
     295}
     296
     297OSStatus CoreAudioSharedUnit::configureMicrophoneProc(int sampleRate)
     298{
     299    ASSERT(isMainThread());
     300
    290301    if (!isProducingMicrophoneSamples())
    291302        return noErr;
    … …  
    307318    }
    308319
    309     microphoneProcFormat.mSampleRate = sampleRate();
     320    microphoneProcFormat.mSampleRate = sampleRate;
    310321    err = PAL::AudioUnitSetProperty(m_ioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, inputBus, &microphoneProcFormat, size);
    311322    if (err) {
    … …  
    320331}
    321332
    322 OSStatus CoreAudioSharedUnit::configureSpeakerProc()
    323 {
     333OSStatus CoreAudioSharedUnit::configureSpeakerProc(int sampleRate)
     334{
     335    ASSERT(isMainThread());
     336
    324337    AURenderCallbackStruct callback = { speakerCallback, this };
    325338    auto err = PAL::AudioUnitSetProperty(m_ioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, outputBus, &callback, sizeof(callback));
    … …  
    333346    {
    334347        Locker locker { m_speakerSamplesProducerLock };
    335         if (m_speakerSamplesProducer)
     348        if (m_speakerSamplesProducer) {
     349            ASSERT(speakerProcFormat.mSampleRate == sampleRate);
    336350            speakerProcFormat = m_speakerSamplesProducer->format().streamDescription();
    337         else {
     351        } else {
    338352            err = PAL::AudioUnitGetProperty(m_ioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, outputBus, &speakerProcFormat, &size);
    339353            if (err) {
    … …  
    341355                return err;
    342356            }
    343             speakerProcFormat.mSampleRate = sampleRate();
    344357        }
    345358    }
     359    speakerProcFormat.mSampleRate = sampleRate;
    346360
    347361    err = PAL::AudioUnitSetProperty(m_ioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, outputBus, &speakerProcFormat, size);
    … …  
    493507OSStatus CoreAudioSharedUnit::startInternal()
    494508{
     509    ASSERT(isMainThread());
     510
    495511    setIsProducingMicrophoneSamples(true);
    496512
    … …  
    573589void CoreAudioSharedUnit::stopInternal()
    574590{
     591    ASSERT(isMainThread());
     592
    575593    m_verifyCapturingTimer.stop();
    576594
    … …  
    632650void CoreAudioSharedUnit::registerSpeakerSamplesProducer(CoreAudioSpeakerSamplesProducer& producer)
    633651{
     652    ASSERT(isMainThread());
     653
    634654    setIsRenderingAudio(true);
    635655
    … …  
    649669void CoreAudioSharedUnit::unregisterSpeakerSamplesProducer(CoreAudioSpeakerSamplesProducer& producer)
    650670{
     671    ASSERT(isMainThread());
     672
    651673    {
    652674        Locker locker { m_speakerSamplesProducerLock };
    … …  
    827849    initializeToStartProducingData();
    828850    unit().startProducingData();
     851    m_currentSettings = { };
    829852}
    830853
    … …  
    853876        RealtimeMediaSourceSettings settings;
    854877        settings.setVolume(volume());
    855         settings.setSampleRate(sampleRate());
     878        settings.setSampleRate(unit().actualSampleRate());
    856879        settings.setDeviceId(hashedId());
    857880        settings.setLabel(name());
Note: See TracChangeset for help on using the changeset viewer.