WebKit Bugzilla
Attachment 370851 Details for
Bug 198307
: Add an option to mute audio capture automatically when page is not visible
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-198307-20190529081527.patch (text/plain), 32.36 KB, created by
youenn fablet
on 2019-05-29 08:15:28 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
youenn fablet
Created:
2019-05-29 08:15:28 PDT
Size:
32.36 KB
patch
obsolete
>Subversion Revision: 245747 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index b9109bb2f669ccdb8f83b5a0d95c2c91b4210f1f..a026a32a3ac4ee003d4f205506f8c8d49f22dae0 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,45 @@ >+2019-05-29 Youenn Fablet <youenn@apple.com> >+ >+ Add an option to mute audio capture automatically when page is not visible >+ https://bugs.webkit.org/show_bug.cgi?id=198307 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Reuse video capture mechanism for audio capture. >+ In case document gets in the background, interrupt the audio track if the audio factory allows it. >+ CoreAudioCaptureSourceIOS allows to interrupt the audio capture if the app has not the right background mode. >+ It also allows interrupting the audio capture based on a runtime flag. >+ >+ Test: platform/ios/mediastream/audio-muted-in-background-tab.html >+ >+ * dom/Document.cpp: >+ (WebCore::Document::notifyMediaCaptureOfVisibilityChanged): >+ * page/RuntimeEnabledFeatures.h: >+ (WebCore::RuntimeEnabledFeatures::interruptAudioOnPageVisibilityChangeEnabled const): >+ (WebCore::RuntimeEnabledFeatures::setInterruptAudioOnPageVisibilityChangeEnabled): >+ * platform/mediastream/RealtimeMediaSourceCenter.cpp: >+ (WebCore::RealtimeMediaSourceCenter::RealtimeMediaSourceCenter): >+ (WebCore::RealtimeMediaSourceCenter::initializeShouldInterruptAudioOnPageVisibilityChange): >+ (WebCore::RealtimeMediaSourceCenter::setCapturePageState): >+ (WebCore::RealtimeMediaSourceCenter::visibilityDidChange): >+ * platform/mediastream/RealtimeMediaSourceCenter.h: >+ (WebCore::RealtimeMediaSourceCenter::setShouldInterruptAudioOnPageVisibilityChange): >+ * platform/mediastream/RealtimeMediaSourceFactory.h: >+ (WebCore::AudioCaptureFactory::setAudioCapturePageState): >+ (WebCore::VideoCaptureFactory::setVideoCapturePageState): >+ * platform/mediastream/ios/CoreAudioCaptureSourceIOS.h: >+ * platform/mediastream/ios/CoreAudioCaptureSourceIOS.mm: >+ (WebCore::CoreAudioCaptureSourceFactory::setAudioCapturePageState): >+ (WebCore::CoreAudioCaptureSourceFactoryIOS::shouldInterruptAudioOnPageVisibilityChange): >+ * platform/mediastream/mac/CoreAudioCaptureSource.h: >+ * platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp: >+ (WebCore::RealtimeMediaSourceCenter::initializeShouldInterruptAudioOnPageVisibilityChange): >+ * testing/Internals.cpp: >+ (WebCore::Internals::resetToConsistentState): >+ (WebCore::Internals::setShouldInterruptAudioOnPageVisibilityChange): >+ * testing/Internals.h: >+ * testing/Internals.idl: >+ > 2019-05-24 Youenn Fablet <youenn@apple.com> > > media/video-remote-control-playpause.html is timing out after r245712 >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index 1bcd85dc15ae0de39b9d57c50cab9a6f5aa2187a..cf5644912a8d81f37c666bf911122704e557a28e 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,23 @@ >+2019-05-29 Youenn Fablet <youenn@apple.com> >+ >+ Add an option to mute audio capture automatically when page is not visible >+ https://bugs.webkit.org/show_bug.cgi?id=198307 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add API to set the new runtime flag. >+ Make source proxy factories implement this automatic muting. >+ >+ * Shared/WebPreferences.yaml: >+ * UIProcess/API/Cocoa/WKPreferences.mm: >+ (-[WKPreferences _interruptAudioOnPageVisibilityChangeEnabled]): >+ (-[WKPreferences _setInterruptAudioOnPageVisibilityChangeEnabled:]): >+ * UIProcess/API/Cocoa/WKPreferencesPrivate.h: >+ * WebProcess/cocoa/UserMediaCaptureManager.cpp: >+ (WebKit::UserMediaCaptureManager::setAudioCapturePageState): >+ (WebKit::UserMediaCaptureManager::setVideoCapturePageState): >+ * WebProcess/cocoa/UserMediaCaptureManager.h: >+ > 2019-05-24 Youenn Fablet <youenn@apple.com> > > REGRESSION (r245715?) [WK2] Layout Test http/wpt/cache-storage/cache-storage-networkprocess-crash.html is a flaky failure >diff --git a/Source/WebCore/SourcesCocoa.txt b/Source/WebCore/SourcesCocoa.txt >index c081198a172ab2094caa64c2d1a63a94873a844f..bd29e5b48cbd60a92435f3cab1be1b7c8fafbb81 100644 >--- a/Source/WebCore/SourcesCocoa.txt >+++ b/Source/WebCore/SourcesCocoa.txt >@@ -542,6 +542,7 @@ platform/mediastream/mac/DisplayCaptureSourceCocoa.cpp > platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.cpp > platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.mm > platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp >+platform/mediastream/mac/RealtimeMediaSourceCenterMac.mm > platform/mediastream/mac/RealtimeOutgoingAudioSourceCocoa.cpp > platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.cpp > platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm >diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >index e6a1f5f1d719b4af63fd9dda7e1afd745a6de907..f0cd6a41c77b09ef0bd6705022d13c9b2075d41e 100644 >--- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj >+++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >@@ -7266,6 +7266,7 @@ > 4162A44F101145AE00DFF3ED /* DedicatedWorkerGlobalScope.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DedicatedWorkerGlobalScope.idl; sourceTree = "<group>"; }; > 4162A4551011464700DFF3ED /* JSDedicatedWorkerGlobalScope.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDedicatedWorkerGlobalScope.cpp; sourceTree = "<group>"; }; > 4162A4561011464700DFF3ED /* JSDedicatedWorkerGlobalScope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDedicatedWorkerGlobalScope.h; sourceTree = "<group>"; }; >+ 416CE4A4229DF12E00A8A686 /* RealtimeMediaSourceCenterMac.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = RealtimeMediaSourceCenterMac.mm; sourceTree = "<group>"; }; > 416D759F20C6441300D02D2C /* NetworkLoadInformation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkLoadInformation.h; sourceTree = "<group>"; }; > 416E0B37209BC3C2004A95D9 /* FetchIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchIdentifier.h; sourceTree = "<group>"; }; > 416E29A5102FA962007FC14E /* WorkerReportingProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkerReportingProxy.h; sourceTree = "<group>"; }; >@@ -15861,6 +15862,7 @@ > 5CDD833A1E4324BB00621E83 /* RealtimeIncomingVideoSourceCocoa.h */, > 5CDD83391E4324BB00621E83 /* RealtimeIncomingVideoSourceCocoa.mm */, > 4A0FFAA31AAF5EF60062803B /* RealtimeMediaSourceCenterMac.cpp */, >+ 416CE4A4229DF12E00A8A686 /* RealtimeMediaSourceCenterMac.mm */, > 41103AA71E39790A00769F14 /* RealtimeOutgoingAudioSourceCocoa.cpp */, > 41103AA81E39790A00769F14 /* RealtimeOutgoingAudioSourceCocoa.h */, > 5CDD833B1E4324BB00621B83 /* RealtimeOutgoingVideoSourceCocoa.cpp */, >diff --git a/Source/WebCore/dom/Document.cpp b/Source/WebCore/dom/Document.cpp >index e70a9f7fe551ab5b554646fc3677d19e921e2ece..c8e0b6076a48567dc60f37008bf5fa80111fffc1 100644 >--- a/Source/WebCore/dom/Document.cpp >+++ b/Source/WebCore/dom/Document.cpp >@@ -7629,7 +7629,7 @@ void Document::notifyMediaCaptureOfVisibilityChanged() > if (!page()) > return; > >- RealtimeMediaSourceCenter::singleton().setVideoCapturePageState(hidden(), page()->isMediaCaptureMuted()); >+ RealtimeMediaSourceCenter::singleton().setCapturePageState(hidden(), page()->isMediaCaptureMuted()); > #endif > } > >diff --git a/Source/WebCore/page/RuntimeEnabledFeatures.h b/Source/WebCore/page/RuntimeEnabledFeatures.h >index 3b49857f289a925add58ea7345b8cf1ed18f15b7..be1623084278210ae69e3642a0db715110466b4d 100644 >--- a/Source/WebCore/page/RuntimeEnabledFeatures.h >+++ b/Source/WebCore/page/RuntimeEnabledFeatures.h >@@ -355,6 +355,9 @@ public: > bool pageAtRuleSupportEnabled() const { return m_pageAtRuleSupportEnabled; } > void setPageAtRuleSupportEnabled(bool isEnabled) { m_pageAtRuleSupportEnabled = isEnabled; } > >+ bool interruptAudioOnPageVisibilityChangeEnabled() const { return m_interruptAudioOnPageVisibilityChangeEnabled; } >+ void setInterruptAudioOnPageVisibilityChangeEnabled(bool enabled) { m_interruptAudioOnPageVisibilityChangeEnabled = enabled; } >+ > WEBCORE_EXPORT static RuntimeEnabledFeatures& sharedFeatures(); > > private: >@@ -537,6 +540,7 @@ private: > bool m_isITPFirstPartyWebsiteDataRemovalEnabled { false }; > > bool m_referrerPolicyAttributeEnabled { false }; >+ bool m_interruptAudioOnPageVisibilityChangeEnabled { false }; > > friend class WTF::NeverDestroyed<RuntimeEnabledFeatures>; > }; >diff --git a/Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.cpp b/Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.cpp >index 3706fad7ffc03f7ecce6ef38c41b7ae3d2d35338..fd75a1fd94fa7870f3f8b57601ed7e0f83c0e5cf 100644 >--- a/Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.cpp >+++ b/Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.cpp >@@ -38,6 +38,7 @@ > #include "CaptureDeviceManager.h" > #include "Logging.h" > #include "MediaStreamPrivate.h" >+#include "RuntimeEnabledFeatures.h" > #include <wtf/SHA1.h> > > namespace WebCore { >@@ -50,6 +51,8 @@ RealtimeMediaSourceCenter& RealtimeMediaSourceCenter::singleton() > } > > RealtimeMediaSourceCenter::RealtimeMediaSourceCenter() >+ : m_shouldInterruptAudioOnPageVisibilityChange { RuntimeEnabledFeatures::sharedFeatures().interruptAudioOnPageVisibilityChangeEnabled() } >+ > { > m_supportedConstraints.setSupportsWidth(true); > m_supportedConstraints.setSupportsHeight(true); >@@ -262,8 +265,10 @@ void RealtimeMediaSourceCenter::validateRequestConstraints(ValidConstraintsHandl > validHandler(WTFMove(audioDevices), WTFMove(videoDevices), WTFMove(deviceIdentifierHashSalt)); > } > >-void RealtimeMediaSourceCenter::setVideoCapturePageState(bool interrupted, bool pageMuted) >+void RealtimeMediaSourceCenter::setCapturePageState(bool interrupted, bool pageMuted) > { >+ if (m_shouldInterruptAudioOnPageVisibilityChange) >+ audioCaptureFactory().setAudioCapturePageState(interrupted, pageMuted); > videoCaptureFactory().setVideoCapturePageState(interrupted, pageMuted); > } > >@@ -317,6 +322,13 @@ DisplayCaptureFactory& RealtimeMediaSourceCenter::displayCaptureFactory() > return m_displayCaptureFactoryOverride ? *m_displayCaptureFactoryOverride : defaultDisplayCaptureFactory(); > } > >+#if !PLATFORM(COCOA) >+bool RealtimeMediaSourceCenter::shouldInterruptAudioOnPageVisibilityChange() >+{ >+ return false; >+} >+#endif >+ > } // namespace WebCore > > #endif // ENABLE(MEDIA_STREAM) >diff --git a/Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.h b/Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.h >index 3bb2594bb091d3637761db9a4dd1233382169827..7b4ed317cfeaa83ca23352715880facf7437091c 100644 >--- a/Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.h >+++ b/Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.h >@@ -86,10 +86,15 @@ public: > > WEBCORE_EXPORT void setDevicesChangedObserver(std::function<void()>&&); > >- void setVideoCapturePageState(bool, bool); >+ void setCapturePageState(bool interrupted, bool pageMuted); > > void captureDevicesChanged(); > >+ WEBCORE_EXPORT static bool shouldInterruptAudioOnPageVisibilityChange(); >+ >+ // For testing only >+ void setShouldInterruptAudioOnPageVisibilityChange(bool shouldInterrupt) { m_shouldInterruptAudioOnPageVisibilityChange = shouldInterrupt; } >+ > private: > RealtimeMediaSourceCenter(); > friend class NeverDestroyed<RealtimeMediaSourceCenter>; >@@ -113,6 +118,8 @@ private: > AudioCaptureFactory* m_audioCaptureFactoryOverride { nullptr }; > VideoCaptureFactory* m_videoCaptureFactoryOverride { nullptr }; > DisplayCaptureFactory* m_displayCaptureFactoryOverride { nullptr }; >+ >+ bool m_shouldInterruptAudioOnPageVisibilityChange { false }; > }; > > } // namespace WebCore >diff --git a/Source/WebCore/platform/mediastream/RealtimeMediaSourceFactory.h b/Source/WebCore/platform/mediastream/RealtimeMediaSourceFactory.h >index 4897c64e9372c2a6bc81938554c982561e20f78c..a3d52f0fcb773634cbf453ff94acea5a1a2fc562 100644 >--- a/Source/WebCore/platform/mediastream/RealtimeMediaSourceFactory.h >+++ b/Source/WebCore/platform/mediastream/RealtimeMediaSourceFactory.h >@@ -57,6 +57,11 @@ public: > virtual ~AudioCaptureFactory() = default; > virtual CaptureSourceOrError createAudioCaptureSource(const CaptureDevice&, String&&, const MediaConstraints*) = 0; > virtual CaptureDeviceManager& audioCaptureDeviceManager() = 0; >+ virtual void setAudioCapturePageState(bool interrupted, bool pageMuted) >+ { >+ UNUSED_PARAM(interrupted); >+ UNUSED_PARAM(pageMuted); >+ } > > protected: > AudioCaptureFactory() = default; >@@ -71,7 +76,11 @@ public: > virtual ~VideoCaptureFactory() = default; > virtual CaptureSourceOrError createVideoCaptureSource(const CaptureDevice&, String&&, const MediaConstraints*) = 0; > virtual CaptureDeviceManager& videoCaptureDeviceManager() = 0; >- virtual void setVideoCapturePageState(bool, bool) { } >+ virtual void setVideoCapturePageState(bool interrupted, bool pageMuted) >+ { >+ UNUSED_PARAM(interrupted); >+ UNUSED_PARAM(pageMuted); >+ } > > protected: > VideoCaptureFactory() = default; >@@ -82,7 +91,6 @@ public: > virtual ~DisplayCaptureFactory() = default; > virtual CaptureSourceOrError createDisplayCaptureSource(const CaptureDevice&, const MediaConstraints*) = 0; > virtual CaptureDeviceManager& displayCaptureDeviceManager() = 0; >- virtual void setDisplayCapturePageState(bool , bool) { } > > protected: > DisplayCaptureFactory() = default; >diff --git a/Source/WebCore/platform/mediastream/ios/CoreAudioCaptureSourceIOS.mm b/Source/WebCore/platform/mediastream/ios/CoreAudioCaptureSourceIOS.mm >index 6fb3dad39c2d9e978dc521b7bb83f699a93253ff..4c8264897aada8d690c31f80756857fee9c97bbd 100644 >--- a/Source/WebCore/platform/mediastream/ios/CoreAudioCaptureSourceIOS.mm >+++ b/Source/WebCore/platform/mediastream/ios/CoreAudioCaptureSourceIOS.mm >@@ -126,6 +126,12 @@ CoreAudioCaptureSourceFactory& CoreAudioCaptureSourceFactory::singleton() > return factory.get(); > } > >+void CoreAudioCaptureSourceFactory::setAudioCapturePageState(bool interrupted, bool pageMuted) >+{ >+ if (auto* activeSource = this->activeSource()) >+ activeSource->setInterrupted(interrupted, pageMuted); >+} >+ > } > > #endif // ENABLE(MEDIA_STREAM) && PLATFORM(IOS_FAMILY) >diff --git a/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.h b/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.h >index 1ab816ca077dd8fe56a97b46c4f3107df2ebae89..adbefe7c025a0fe8138895b018f2269c1a64ac0a 100644 >--- a/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.h >+++ b/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.h >@@ -142,6 +142,9 @@ private: > } > > CaptureDeviceManager& audioCaptureDeviceManager() final; >+#if PLATFORM(IOS_FAMILY) >+ void setAudioCapturePageState(bool interrupted, bool pageMuted) final; >+#endif > }; > > } // namespace WebCore >diff --git a/Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp b/Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp >index a6a0dab5c0b55d1251937ab0ce46db1dc829f9f9..a328cd3a83ecbfca049e54abf70de9d78faf331b 100644 >--- a/Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp >+++ b/Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp >@@ -38,6 +38,7 @@ > #include "DisplayCaptureManagerCocoa.h" > #include "Logging.h" > #include "MediaStreamPrivate.h" >+#include "RuntimeEnabledFeatures.h" > #include "ScreenDisplayCaptureSourceMac.h" > #include "WindowDisplayCaptureSourceMac.h" > #include <wtf/MainThread.h> >diff --git a/Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.mm b/Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.mm >new file mode 100644 >index 0000000000000000000000000000000000000000..78a5d0e820f432922805a4c8b585303cc87a1925 >--- /dev/null >+++ b/Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.mm >@@ -0,0 +1,59 @@ >+/* >+ * Copyright (C) 2013-2016 Apple, Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer >+ * in the documentation and/or other materials provided with the >+ * distribution. >+ * 3. Neither the name of Ericsson nor the names of its contributors >+ * may be used to endorse or promote products derived from this >+ * software without specific prior written permission. >+ * >+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS >+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT >+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR >+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT >+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, >+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT >+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, >+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY >+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE >+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+#include "RealtimeMediaSourceCenter.h" >+ >+#if ENABLE(MEDIA_STREAM) >+ >+namespace WebCore { >+ >+bool RealtimeMediaSourceCenter::shouldInterruptAudioOnPageVisibilityChange() >+{ >+#if PLATFORM(IOS) >+ NSArray *modes = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIBackgroundModes"]; >+ if (!modes) >+ return true; >+ >+ int modesCount = [modes count]; >+ for (int i = 0; i < modesCount; i++) { >+ if ([[modes objectAtIndex:i] isEqual: @"audio"]) >+ return false; >+ } >+ return true; >+#else >+ return false; >+#endif >+} >+ >+ >+} // namespace WebCore >+ >+#endif // ENABLE(MEDIA_STREAM) >diff --git a/Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.cpp b/Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.cpp >index 69fad4b415e03fe2fd07af76d475c18e0387ab6d..6d83b5095b5054c43cf9e0fd246e1026d6eae54b 100644 >--- a/Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.cpp >+++ b/Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.cpp >@@ -96,7 +96,7 @@ public: > > private: > #if PLATFORM(IOS_FAMILY) >- void setVideoCapturePageState(bool interrupted, bool pageMuted) >+ void setVideoCapturePageState(bool interrupted, bool pageMuted) final > { > if (activeSource()) > activeSource()->setInterrupted(interrupted, pageMuted); >@@ -139,6 +139,13 @@ public: > return MockRealtimeAudioSource::create(String { device.persistentId() }, String { device.label() }, WTFMove(hashSalt), constraints); > } > private: >+#if PLATFORM(IOS_FAMILY) >+ void setAudioCapturePageState(bool interrupted, bool pageMuted) final >+ { >+ if (activeSource()) >+ activeSource()->setInterrupted(interrupted, pageMuted); >+ } >+#endif > CaptureDeviceManager& audioCaptureDeviceManager() final { return MockRealtimeMediaSourceCenter::singleton().audioCaptureDeviceManager(); } > }; > >diff --git a/Source/WebCore/testing/Internals.cpp b/Source/WebCore/testing/Internals.cpp >index 510ef0d31b6ea420e4ab09bfe81f415a318f2efe..0759b1fa2187d92b761910a65272925f2af4ca57 100644 >--- a/Source/WebCore/testing/Internals.cpp >+++ b/Source/WebCore/testing/Internals.cpp >@@ -531,6 +531,10 @@ void Internals::resetToConsistentState(Page& page) > page.setFullscreenControlsHidden(false); > > MediaEngineConfigurationFactory::disableMock(); >+ >+#if ENABLE(MEDIA_STREAM) >+ RealtimeMediaSourceCenter::singleton().setShouldInterruptAudioOnPageVisibilityChange(false); >+#endif > } > > Internals::Internals(Document& document) >@@ -1501,6 +1505,10 @@ void Internals::applyRotationForOutgoingVideoSources(RTCPeerConnection& connecti > #endif > > #if ENABLE(MEDIA_STREAM) >+void Internals::setShouldInterruptAudioOnPageVisibilityChange(bool shouldInterrupt) >+{ >+ RealtimeMediaSourceCenter::singleton().setShouldInterruptAudioOnPageVisibilityChange(shouldInterrupt); >+} > > void Internals::setMockMediaCaptureDevicesEnabled(bool enabled) > { >diff --git a/Source/WebCore/testing/Internals.h b/Source/WebCore/testing/Internals.h >index 3ac66f72598030c089f71202b4481308379f7946..895a0eb2912ecbb255374f700b4d74bff0e2fe01 100644 >--- a/Source/WebCore/testing/Internals.h >+++ b/Source/WebCore/testing/Internals.h >@@ -516,6 +516,7 @@ public: > #endif > > #if ENABLE(MEDIA_STREAM) >+ void setShouldInterruptAudioOnPageVisibilityChange(bool); > void setMockMediaCaptureDevicesEnabled(bool); > void setMediaCaptureRequiresSecureConnection(bool); > void setCustomPrivateRecorderCreator(); >diff --git a/Source/WebCore/testing/Internals.idl b/Source/WebCore/testing/Internals.idl >index ca2bc545b3e04a7868c3d48940ae077249d147a7..114e445bc47a59eb6f317ca77a31c4061e679d60 100644 >--- a/Source/WebCore/testing/Internals.idl >+++ b/Source/WebCore/testing/Internals.idl >@@ -672,6 +672,7 @@ enum CompositingPolicy { > [Conditional=WEB_RTC] void setH264HardwareEncoderAllowed(boolean allowed); > [Conditional=WEB_RTC] void applyRotationForOutgoingVideoSources(RTCPeerConnection connection); > >+ [Conditional=MEDIA_STREAM] void setShouldInterruptAudioOnPageVisibilityChange(boolean shouldInterrupt); > [Conditional=MEDIA_STREAM] void setCameraMediaStreamTrackOrientation(MediaStreamTrack track, short orientation); > [Conditional=MEDIA_STREAM] void observeMediaStreamTrack(MediaStreamTrack track); > [Conditional=MEDIA_STREAM] Promise<ImageData> grabNextMediaStreamTrackFrame(); >diff --git a/Source/WebKit/Scripts/PreferencesTemplates/WebPreferencesStoreDefaultsMap.cpp.erb b/Source/WebKit/Scripts/PreferencesTemplates/WebPreferencesStoreDefaultsMap.cpp.erb >index 7825e122844e87f3589cca311dde77fc2b8f1598..17bae3753712efc5d27685bfeda5ad8f994cb508 100644 >--- a/Source/WebKit/Scripts/PreferencesTemplates/WebPreferencesStoreDefaultsMap.cpp.erb >+++ b/Source/WebKit/Scripts/PreferencesTemplates/WebPreferencesStoreDefaultsMap.cpp.erb >@@ -36,6 +36,7 @@ > // FIXME: These should added via options in WebPreferences.yaml, rather than hardcoded. > #include <WebCore/DeprecatedGlobalSettings.h> > #include <WebCore/LibWebRTCProvider.h> >+#include <WebCore/RealtimeMediaSourceCenter.h> > #include <WebCore/SecurityOrigin.h> > #include <WebCore/Settings.h> > #include <WebCore/TextEncodingRegistry.h> >diff --git a/Source/WebKit/Shared/WebPreferences.yaml b/Source/WebKit/Shared/WebPreferences.yaml >index e59efb801cb31ae07dee12253c15715489d8df56..976c4a6d04b727264b122c944ca92cc9bbf5b5ea 100644 >--- a/Source/WebKit/Shared/WebPreferences.yaml >+++ b/Source/WebKit/Shared/WebPreferences.yaml >@@ -545,6 +545,11 @@ PeerConnectionEnabled: > webcoreBinding: RuntimeEnabledFeatures > condition: ENABLE(WEB_RTC) > >+InterruptAudioOnPageVisibilityChangeEnabled: >+ type: bool >+ defaultValue: WebCore::RealtimeMediaSourceCenter::shouldInterruptAudioOnPageVisibilityChange() >+ webcoreBinding: RuntimeEnabledFeatures >+ > WebRTCUnifiedPlanEnabled: > type: bool > defaultValue: true >diff --git a/Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm b/Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm >index 65384ec1d046e403e0693821dd8e83b1960404f8..df0b0020dbefd0f33f6d7760b6d472630bff4cd8 100644 >--- a/Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm >+++ b/Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm >@@ -649,6 +649,16 @@ - (void)_setInactiveMediaCaptureSteamRepromptIntervalInMinutes:(double)interval > _preferences->setInactiveMediaCaptureSteamRepromptIntervalInMinutes(interval); > } > >+- (BOOL)_interruptAudioOnPageVisibilityChangeEnabled >+{ >+ return _preferences->interruptAudioOnPageVisibilityChangeEnabled(); >+} >+ >+- (void)_setInterruptAudioOnPageVisibilityChangeEnabled:(BOOL)enabled >+{ >+ _preferences->setInterruptAudioOnPageVisibilityChangeEnabled(enabled); >+} >+ > - (BOOL)_enumeratingAllNetworkInterfacesEnabled > { > return _preferences->enumeratingAllNetworkInterfacesEnabled(); >diff --git a/Source/WebKit/UIProcess/API/Cocoa/WKPreferencesPrivate.h b/Source/WebKit/UIProcess/API/Cocoa/WKPreferencesPrivate.h >index 077a3932c7a1a4c44d7528968ccb2d16e8b592fb..ef181936cf137e6e18647148f9172eb9292c9e86 100644 >--- a/Source/WebKit/UIProcess/API/Cocoa/WKPreferencesPrivate.h >+++ b/Source/WebKit/UIProcess/API/Cocoa/WKPreferencesPrivate.h >@@ -120,6 +120,7 @@ typedef NS_ENUM(NSInteger, _WKEditableLinkBehavior) { > @property (nonatomic, setter=_setICECandidateFilteringEnabled:) BOOL _iceCandidateFilteringEnabled WK_API_AVAILABLE(macos(10.13.4), ios(11.3)); > @property (nonatomic, setter=_setWebRTCLegacyAPIEnabled:) BOOL _webRTCLegacyAPIEnabled WK_API_AVAILABLE(macos(10.13), ios(11.0)); > @property (nonatomic, setter=_setInactiveMediaCaptureSteamRepromptIntervalInMinutes:) double _inactiveMediaCaptureSteamRepromptIntervalInMinutes WK_API_AVAILABLE(macos(10.13.4), ios(11.3)); >+@property (nonatomic, setter=_setInterruptAudioOnPageVisibilityChangeEnabled:) BOOL _interruptAudioOnPageVisibilityChangeEnabled WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); > > @property (nonatomic, setter=_setJavaScriptCanAccessClipboard:) BOOL _javaScriptCanAccessClipboard WK_API_AVAILABLE(macos(10.13), ios(11.0)); > @property (nonatomic, setter=_setDOMPasteAllowed:) BOOL _domPasteAllowed WK_API_AVAILABLE(macos(10.13), ios(11.0)); >diff --git a/Source/WebKit/WebProcess/cocoa/UserMediaCaptureManager.cpp b/Source/WebKit/WebProcess/cocoa/UserMediaCaptureManager.cpp >index b465ad25239e6b278d3fb407747d89b872998751..86a8bc5df083db5a9aefa6676f54566d1ffd2569 100644 >--- a/Source/WebKit/WebProcess/cocoa/UserMediaCaptureManager.cpp >+++ b/Source/WebKit/WebProcess/cocoa/UserMediaCaptureManager.cpp >@@ -363,6 +363,20 @@ void UserMediaCaptureManager::applyConstraintsFailed(uint64_t id, String&& faile > source.applyConstraintsFailed(WTFMove(failedConstraint), WTFMove(message)); > } > >+#if PLATFORM(IOS) >+void UserMediaCaptureManager::setAudioCapturePageState(bool interrupted, bool pageMuted) >+{ >+ if (auto* activeSource = static_cast<AudioCaptureFactory*>(this)->activeSource()) >+ activeSource->setInterrupted(interrupted, pageMuted); >+} >+ >+void UserMediaCaptureManager::setVideoCapturePageState(bool interrupted, bool pageMuted) >+{ >+ if (auto* activeSource = static_cast<VideoCaptureFactory*>(this)->activeSource()) >+ activeSource->setInterrupted(interrupted, pageMuted); >+} >+#endif >+ > } > > #endif >diff --git a/Source/WebKit/WebProcess/cocoa/UserMediaCaptureManager.h b/Source/WebKit/WebProcess/cocoa/UserMediaCaptureManager.h >index b11ae744c3de1b0bed2712e648a669e1f2305d9f..baed0cd9e09b49d221e94018f649fe6dbcf92519 100644 >--- a/Source/WebKit/WebProcess/cocoa/UserMediaCaptureManager.h >+++ b/Source/WebKit/WebProcess/cocoa/UserMediaCaptureManager.h >@@ -79,6 +79,11 @@ private: > WebCore::CaptureDeviceManager& videoCaptureDeviceManager() final { return m_noOpCaptureDeviceManager; } > WebCore::CaptureDeviceManager& displayCaptureDeviceManager() final { return m_noOpCaptureDeviceManager; } > >+#if PLATFORM(IOS_FAMILY) >+ void setAudioCapturePageState(bool interrupted, bool pageMuted) final; >+ void setVideoCapturePageState(bool interrupted, bool pageMuted) final; >+#endif >+ > // IPC::MessageReceiver > void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final; > >diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index 69c447a8f10edc5b070ff296fe1ef30b1ce3cd64..07472647c6b1038b9eca1230fa9a565021f81275 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,13 @@ >+2019-05-29 Youenn Fablet <youenn@apple.com> >+ >+ Add an option to mute audio capture automatically when page is not visible >+ https://bugs.webkit.org/show_bug.cgi?id=198307 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * platform/ios/mediastream/audio-muted-in-background-tab-expected.txt: Added. >+ * platform/ios/mediastream/audio-muted-in-background-tab.html: Added. >+ > 2019-05-24 Youenn Fablet <youenn@apple.com> > > media/video-remote-control-playpause.html is timing out after r245712 >diff --git a/LayoutTests/platform/ios/mediastream/audio-muted-in-background-tab-expected.txt b/LayoutTests/platform/ios/mediastream/audio-muted-in-background-tab-expected.txt >new file mode 100644 >index 0000000000000000000000000000000000000000..408e29c7cbb9b4d05f04cd545bedff012e59472a >--- /dev/null >+++ b/LayoutTests/platform/ios/mediastream/audio-muted-in-background-tab-expected.txt >@@ -0,0 +1,7 @@ >+ >+PASS Setup stream >+PASS Hide page, video and audio should be muted >+PASS Show page, video and audio should be unmuted >+PASS Hide and mute page, video and audio should be muted >+PASS Show page, video and audio should remain muted >+ >diff --git a/LayoutTests/platform/ios/mediastream/audio-muted-in-background-tab.html b/LayoutTests/platform/ios/mediastream/audio-muted-in-background-tab.html >new file mode 100644 >index 0000000000000000000000000000000000000000..80e49edadf1f7a21ac00caf92cf543886817611a >--- /dev/null >+++ b/LayoutTests/platform/ios/mediastream/audio-muted-in-background-tab.html >@@ -0,0 +1,72 @@ >+ >+<!doctype html> >+<html> >+ <head> >+ <meta charset="utf-8"> >+ <title>Don't unmute audio when a tab becomes visible unless it was muted when the tab was hidden</title> >+ <script src="../../../resources/testharness.js"></script> >+ <script src="../../../resources/testharnessreport.js"></script> >+ </head> >+ <body> >+ <script> >+ let audioTrack; >+ let videoTrack; >+ >+ promise_test((t) => { >+ if (window.testRunner) >+ testRunner.setUserMediaPermission(true); >+ if (!window.internals) >+ return Promise.reject("this test needs internals API"); >+ >+ internals.setShouldInterruptAudioOnPageVisibilityChange(true); >+ >+ return navigator.mediaDevices.getUserMedia({ audio: true, video: true }).then((stream) => { >+ audioTrack = stream.getAudioTracks()[0]; >+ videoTrack = stream.getVideoTracks()[0]; >+ >+ assert_false(audioTrack.muted, "audio track is active"); >+ assert_false(videoTrack.muted, "video track is active"); >+ }) >+ >+ .then(() => { >+ test(() => { >+ if (window.internals) >+ window.internals.setPageVisibility(false); >+ assert_true(audioTrack.muted, "audio track is muted"); >+ assert_true(videoTrack.muted, "video track is muted"); >+ }, "Hide page, video and audio should be muted"); >+ }) >+ >+ .then(() => { >+ test(() => { >+ if (window.internals) >+ window.internals.setPageVisibility(true); >+ assert_false(audioTrack.muted, "audio track is active"); >+ assert_false(videoTrack.muted, "video track is active"); >+ }, "Show page, video and audio should be unmuted"); >+ }) >+ >+ .then(() => { >+ test(() => { >+ if (window.internals) { >+ window.internals.setPageVisibility(false); >+ window.internals.setPageMuted("capturedevices"); >+ } >+ assert_true(audioTrack.muted, "audio track is muted"); >+ assert_true(videoTrack.muted, "video track is muted"); >+ }, "Hide and mute page, video and audio should be muted"); >+ }) >+ >+ .then(() => { >+ test(() => { >+ if (window.internals) >+ window.internals.setPageVisibility(true); >+ assert_true(audioTrack.muted, "audio track is muted"); >+ assert_true(videoTrack.muted, "video track is muted"); >+ }, "Show page, video and audio should remain muted"); >+ }) >+ }, "Setup stream"); >+ >+ </script> >+ </body> >+</html>
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 198307
:
370807
|
370851
|
370862
|
370967
|
370986
|
371013
|
371060