Changeset 252961 in webkit
- Timestamp:
- Nov 30, 2019 11:08:09 AM (4 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r252960 r252961 1 2019-11-30 youenn fablet <youenn@apple.com> 2 3 Simplify CoreAudioCaptureSource suspension logic 4 https://bugs.webkit.org/show_bug.cgi?id=201720 5 6 Reviewed by Eric Carlson. 7 8 Instead of going through the source to suspend/resume the audio unit, 9 we directly go to the shared unit, which nows notifies the clients that they are muted or unmuted. 10 11 To simplify things, we no longer schedule tasks to resume/suspend/reconfigure. 12 All of these orders are started from the main thread synchronously. 13 14 No observable change of behavior. 15 16 * platform/mediastream/mac/BaseAudioSharedUnit.cpp: 17 (WebCore::BaseAudioSharedUnit::startProducingData): 18 (WebCore::BaseAudioSharedUnit::reconfigure): 19 (WebCore::BaseAudioSharedUnit::resume): 20 (WebCore::BaseAudioSharedUnit::suspend): 21 * platform/mediastream/mac/BaseAudioSharedUnit.h: 22 * platform/mediastream/mac/CoreAudioCaptureSource.cpp: 23 (WebCore::CoreAudioCaptureSourceFactory::beginInterruption): 24 (WebCore::CoreAudioCaptureSourceFactory::endInterruption): 25 (WebCore::CoreAudioCaptureSourceFactory::scheduleReconfiguration): 26 (WebCore::CoreAudioCaptureSource::initializeToStartProducingData): 27 (WebCore::CoreAudioCaptureSource::startProducingData): 28 (WebCore::CoreAudioCaptureSource::stopProducingData): 29 (WebCore::CoreAudioCaptureSource::settingsDidChange): 30 (WebCore::CoreAudioCaptureSource::scheduleReconfiguration): Deleted. 31 (WebCore::CoreAudioCaptureSource::beginInterruption): Deleted. 32 (WebCore::CoreAudioCaptureSource::endInterruption): Deleted. 33 * platform/mediastream/mac/CoreAudioCaptureSource.h: 34 1 35 2019-11-30 youenn fablet <youenn@apple.com> 2 36 -
trunk/Source/WebCore/platform/mediastream/mac/BaseAudioSharedUnit.cpp
r252660 r252961 78 78 return; 79 79 80 if (m_suspended) { 81 RELEASE_LOG_INFO(WebRTC, "BaseAudioSharedUnit::startProducingData - exiting early as suspended"); 82 return; 83 } 84 80 85 if (hasAudioUnit()) { 81 86 cleanupAudioUnit(); … … 85 90 if (startInternal()) 86 91 captureFailed(); 87 }88 89 OSStatus BaseAudioSharedUnit::resume()90 {91 ASSERT(isMainThread());92 ASSERT(m_suspended);93 ASSERT(!isProducingData());94 95 m_suspended = false;96 97 if (!hasAudioUnit())98 return 0;99 100 startInternal();101 102 return 0;103 92 } 104 93 … … 143 132 } 144 133 134 void BaseAudioSharedUnit::reconfigure() 135 { 136 ASSERT(isMainThread()); 137 if (m_suspended) { 138 m_needsReconfiguration = true; 139 return; 140 } 141 reconfigureAudioUnit(); 142 } 143 144 OSStatus BaseAudioSharedUnit::resume() 145 { 146 ASSERT(isMainThread()); 147 ASSERT(m_suspended); 148 ASSERT(!isProducingData()); 149 150 RELEASE_LOG_INFO(WebRTC, "BaseAudioSharedUnit::resume"); 151 152 m_suspended = false; 153 154 if (m_needsReconfiguration) { 155 m_needsReconfiguration = false; 156 reconfigure(); 157 } 158 159 if (!hasAudioUnit()) 160 return 0; 161 162 if (m_producingCount) 163 startInternal(); 164 165 forEachClient([](auto& client) { 166 client.notifyMutedChange(false); 167 }); 168 169 return 0; 170 } 171 145 172 OSStatus BaseAudioSharedUnit::suspend() 146 173 { 147 174 ASSERT(isMainThread()); 148 175 176 RELEASE_LOG_INFO(WebRTC, "BaseAudioSharedUnit::suspend"); 177 149 178 m_suspended = true; 150 179 stopInternal(); 180 181 forEachClient([](auto& client) { 182 client.notifyMutedChange(true); 183 }); 151 184 152 185 return 0; -
trunk/Source/WebCore/platform/mediastream/mac/BaseAudioSharedUnit.h
r252660 r252961 42 42 void startProducingData(); 43 43 void stopProducingData(); 44 void reconfigure(); 44 45 virtual bool isProducingData() const = 0; 45 46 … … 67 68 virtual bool hasAudioUnit() const = 0; 68 69 virtual void setCaptureDevice(String&&, uint32_t) = 0; 69 virtual OSStatus reconfigureAudioUnit() = 0;70 70 71 71 virtual CapabilityValueOrRange sampleRateCapacities() const = 0; … … 79 79 virtual OSStatus startInternal() = 0; 80 80 virtual void stopInternal() = 0; 81 virtual OSStatus reconfigureAudioUnit() = 0; 81 82 82 83 void setSuspended(bool value) { m_suspended = value; } … … 89 90 int m_sampleRate; 90 91 bool m_suspended { false }; 92 bool m_needsReconfiguration { false }; 91 93 92 94 int32_t m_producingCount { 0 }; -
trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.cpp
r252681 r252961 278 278 } 279 279 m_ioUnitInitialized = true; 280 setSuspended(false);281 280 282 281 unduck(); … … 648 647 return; 649 648 } 650 ASSERT(isMainThread());651 652 if (auto* source = coreAudioActiveSource()) {653 source->beginInterruption();654 return;655 }656 649 CoreAudioSharedUnit::singleton().suspend(); 657 650 } … … 665 658 return; 666 659 } 667 ASSERT(isMainThread()); 668 669 if (auto* source = coreAudioActiveSource()) { 670 source->endInterruption(); 671 return; 672 } 673 CoreAudioSharedUnit::singleton().reconfigureAudioUnit(); 660 CoreAudioSharedUnit::singleton().resume(); 674 661 } 675 662 … … 682 669 return; 683 670 } 684 ASSERT(isMainThread()); 685 686 if (auto* source = coreAudioActiveSource()) { 687 source->scheduleReconfiguration(); 688 return; 689 } 690 CoreAudioSharedUnit::singleton().reconfigureAudioUnit(); 671 CoreAudioSharedUnit::singleton().reconfigure(); 691 672 } 692 673 … … 737 718 738 719 if (shouldReconfigure) 739 scheduleReconfiguration();720 unit.reconfigure(); 740 721 741 722 unit.addClient(*this); … … 757 738 #endif 758 739 759 auto& unit = this->unit();760 761 auto isSuspended = unit.isSuspended();762 ALWAYS_LOG_IF(loggerPtr(), LOGIDENTIFIER, isSuspended);763 764 if (isSuspended) {765 m_suspendType = SuspensionType::WhilePlaying;766 return;767 }768 769 740 initializeToStartProducingData(); 770 unit .startProducingData();741 unit().startProducingData(); 771 742 } 772 743 773 744 void CoreAudioCaptureSource::stopProducingData() 774 745 { 775 auto& unit = this->unit(); 776 777 auto isSuspended = unit.isSuspended(); 778 ALWAYS_LOG_IF(loggerPtr(), LOGIDENTIFIER, isSuspended); 779 780 if (isSuspended) { 781 m_suspendType = SuspensionType::WhilePaused; 782 return; 783 } 784 785 unit.stopProducingData(); 746 unit().stopProducingData(); 786 747 } 787 748 … … 823 784 void CoreAudioCaptureSource::settingsDidChange(OptionSet<RealtimeMediaSourceSettings::Flag> settings) 824 785 { 786 bool shouldReconfigure = false; 825 787 if (settings.contains(RealtimeMediaSourceSettings::Flag::EchoCancellation)) { 826 788 unit().setEnableEchoCancellation(echoCancellation()); 827 s cheduleReconfiguration();789 shouldReconfigure = true; 828 790 } 829 791 if (settings.contains(RealtimeMediaSourceSettings::Flag::SampleRate)) { 830 792 unit().setSampleRate(sampleRate()); 831 scheduleReconfiguration(); 832 } 793 shouldReconfigure = true; 794 } 795 if (shouldReconfigure) 796 unit().reconfigure(); 833 797 834 798 m_currentSettings = WTF::nullopt; 835 799 } 836 800 837 void CoreAudioCaptureSource::scheduleReconfiguration()838 {839 ALWAYS_LOG_IF(loggerPtr(), LOGIDENTIFIER);840 841 ASSERT(isMainThread());842 auto& unit = this->unit();843 if (!unit.hasAudioUnit() || m_reconfigurationState != ReconfigurationState::None)844 return;845 846 m_reconfigurationState = ReconfigurationState::Ongoing;847 scheduleDeferredTask([this, &unit] {848 if (unit.isSuspended()) {849 m_reconfigurationState = ReconfigurationState::Required;850 return;851 }852 853 unit.reconfigureAudioUnit();854 m_reconfigurationState = ReconfigurationState::None;855 });856 }857 858 void CoreAudioCaptureSource::beginInterruption()859 {860 ALWAYS_LOG_IF(loggerPtr(), LOGIDENTIFIER);861 862 ASSERT(isMainThread());863 auto& unit = this->unit();864 if (!unit.hasAudioUnit() || unit.isSuspended() || m_suspendPending)865 return;866 867 m_suspendPending = true;868 scheduleDeferredTask([this, &unit] {869 m_suspendType = unit.isProducingData() ? SuspensionType::WhilePlaying : SuspensionType::WhilePaused;870 unit.suspend();871 notifyMutedChange(true);872 m_suspendPending = false;873 });874 }875 876 void CoreAudioCaptureSource::endInterruption()877 {878 ALWAYS_LOG_IF(loggerPtr(), LOGIDENTIFIER);879 880 ASSERT(isMainThread());881 auto& unit = this->unit();882 if (!unit.hasAudioUnit() || !unit.isSuspended() || m_resumePending)883 return;884 885 auto type = m_suspendType;886 m_suspendType = SuspensionType::None;887 if (type != SuspensionType::WhilePlaying && m_reconfigurationState != ReconfigurationState::Required)888 return;889 890 m_resumePending = true;891 scheduleDeferredTask([this, type, &unit] {892 if (m_reconfigurationState == ReconfigurationState::Required)893 unit.reconfigureAudioUnit();894 if (type == SuspensionType::WhilePlaying) {895 unit.resume();896 notifyMutedChange(false);897 }898 m_reconfigurationState = ReconfigurationState::None;899 m_resumePending = false;900 });901 }902 903 801 bool CoreAudioCaptureSource::interrupted() const 904 802 { -
trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.h
r252737 r252961 63 63 CMClockRef timebaseClock(); 64 64 65 void beginInterruption();66 void endInterruption();67 void scheduleReconfiguration();68 69 65 protected: 70 66 CoreAudioCaptureSource(String&& deviceID, String&& label, String&& hashSalt, uint32_t persistentID); … … 104 100 Optional<RealtimeMediaSourceSettings> m_currentSettings; 105 101 106 enum class SuspensionType { None, WhilePaused, WhilePlaying };107 SuspensionType m_suspendType { SuspensionType::None };108 109 enum class ReconfigurationState { None, Required, Ongoing };110 ReconfigurationState m_reconfigurationState { ReconfigurationState::None };111 112 bool m_reconfigurationRequired { false };113 bool m_suspendPending { false };114 bool m_resumePending { false };115 102 bool m_isReadyToStart { false }; 116 103
Note: See TracChangeset
for help on using the changeset viewer.