Changeset 294838 in webkit
- Timestamp:
- May 25, 2022, 4:49:33 PM (4 years ago)
- Location:
- branches/safari-613-branch/Source/WebCore
- Files:
-
- 3 edited
-
ChangeLog (modified) (1 diff)
-
platform/mediastream/mac/BaseAudioSharedUnit.h (modified) (1 diff)
-
platform/mediastream/mac/CoreAudioCaptureSource.cpp (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/safari-613-branch/Source/WebCore/ChangeLog
r294836 r294838 1 2022-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 1 44 2022-05-19 Alan Coon <alancoon@apple.com> 2 45 -
branches/safari-613-branch/Source/WebCore/platform/mediastream/mac/BaseAudioSharedUnit.h
r289311 r294838 78 78 79 79 virtual CapabilityValueOrRange sampleRateCapacities() const = 0; 80 virtual int actualSampleRate() const { return sampleRate(); } 80 81 81 82 void devicesChanged(const Vector<CaptureDevice>&); -
branches/safari-613-branch/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.cpp
r291923 r294838 102 102 void isProducingMicrophoneSamplesChanged() final; 103 103 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); 107 108 OSStatus defaultOutputDevice(uint32_t*); 108 109 OSStatus defaultInputDevice(uint32_t*); … … 150 151 151 152 bool m_isReconfiguring { false }; 152 Lock m_speakerSamplesProducerLock;153 mutable Lock m_speakerSamplesProducerLock; 153 154 CoreAudioSpeakerSamplesProducer* m_speakerSamplesProducer WTF_GUARDED_BY_LOCK(m_speakerSamplesProducerLock) { nullptr }; 154 155 }; … … 259 260 #endif 260 261 261 err = configureMicrophoneProc(); 262 // FIXME: Add support for different speaker/microphone sample rates. 263 int actualSampleRate = this->actualSampleRate(); 264 err = configureMicrophoneProc(actualSampleRate); 262 265 if (err) 263 266 return err; 264 267 265 err = configureSpeakerProc( );268 err = configureSpeakerProc(actualSampleRate); 266 269 if (err) 267 270 return err; … … 286 289 } 287 290 288 OSStatus CoreAudioSharedUnit::configureMicrophoneProc() 289 { 291 int CoreAudioSharedUnit::actualSampleRate() const 292 { 293 Locker locker { m_speakerSamplesProducerLock }; 294 return m_speakerSamplesProducer ? m_speakerSamplesProducer->format().streamDescription().mSampleRate : sampleRate(); 295 } 296 297 OSStatus CoreAudioSharedUnit::configureMicrophoneProc(int sampleRate) 298 { 299 ASSERT(isMainThread()); 300 290 301 if (!isProducingMicrophoneSamples()) 291 302 return noErr; … … 307 318 } 308 319 309 microphoneProcFormat.mSampleRate = sampleRate ();320 microphoneProcFormat.mSampleRate = sampleRate; 310 321 err = PAL::AudioUnitSetProperty(m_ioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, inputBus, µphoneProcFormat, size); 311 322 if (err) { … … 320 331 } 321 332 322 OSStatus CoreAudioSharedUnit::configureSpeakerProc() 323 { 333 OSStatus CoreAudioSharedUnit::configureSpeakerProc(int sampleRate) 334 { 335 ASSERT(isMainThread()); 336 324 337 AURenderCallbackStruct callback = { speakerCallback, this }; 325 338 auto err = PAL::AudioUnitSetProperty(m_ioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, outputBus, &callback, sizeof(callback)); … … 333 346 { 334 347 Locker locker { m_speakerSamplesProducerLock }; 335 if (m_speakerSamplesProducer) 348 if (m_speakerSamplesProducer) { 349 ASSERT(speakerProcFormat.mSampleRate == sampleRate); 336 350 speakerProcFormat = m_speakerSamplesProducer->format().streamDescription(); 337 else {351 } else { 338 352 err = PAL::AudioUnitGetProperty(m_ioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, outputBus, &speakerProcFormat, &size); 339 353 if (err) { … … 341 355 return err; 342 356 } 343 speakerProcFormat.mSampleRate = sampleRate();344 357 } 345 358 } 359 speakerProcFormat.mSampleRate = sampleRate; 346 360 347 361 err = PAL::AudioUnitSetProperty(m_ioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, outputBus, &speakerProcFormat, size); … … 493 507 OSStatus CoreAudioSharedUnit::startInternal() 494 508 { 509 ASSERT(isMainThread()); 510 495 511 setIsProducingMicrophoneSamples(true); 496 512 … … 573 589 void CoreAudioSharedUnit::stopInternal() 574 590 { 591 ASSERT(isMainThread()); 592 575 593 m_verifyCapturingTimer.stop(); 576 594 … … 632 650 void CoreAudioSharedUnit::registerSpeakerSamplesProducer(CoreAudioSpeakerSamplesProducer& producer) 633 651 { 652 ASSERT(isMainThread()); 653 634 654 setIsRenderingAudio(true); 635 655 … … 649 669 void CoreAudioSharedUnit::unregisterSpeakerSamplesProducer(CoreAudioSpeakerSamplesProducer& producer) 650 670 { 671 ASSERT(isMainThread()); 672 651 673 { 652 674 Locker locker { m_speakerSamplesProducerLock }; … … 827 849 initializeToStartProducingData(); 828 850 unit().startProducingData(); 851 m_currentSettings = { }; 829 852 } 830 853 … … 853 876 RealtimeMediaSourceSettings settings; 854 877 settings.setVolume(volume()); 855 settings.setSampleRate( sampleRate());878 settings.setSampleRate(unit().actualSampleRate()); 856 879 settings.setDeviceId(hashedId()); 857 880 settings.setLabel(name());
Note:
See TracChangeset
for help on using the changeset viewer.