Changeset 214721 in webkit
- Timestamp:
- Apr 1, 2017 5:55:20 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r214713 r214721 1 2017-04-01 Chris Dumez <cdumez@apple.com> 2 3 We should pause silent WebAudio rendering in background tabs 4 https://bugs.webkit.org/show_bug.cgi?id=170299 5 <rdar://problem/31289132> 6 7 Reviewed by Eric Carlson. 8 9 Add layout test coverage. 10 11 * webaudio/silent-audio-interrupted-in-background-expected.txt: Added. 12 * webaudio/silent-audio-interrupted-in-background.html: Added. 13 1 14 2017-04-01 Alexey Proskuryakov <ap@apple.com> 2 15 -
trunk/LayoutTests/platform/ios/TestExpectations
r214561 r214721 312 312 webkit.org/b/165799 svg/animations/animations-paused-in-background-page-iframe.html [ Skip ] 313 313 webkit.org/b/165799 svg/animations/animations-paused-in-background-page.html [ Skip ] 314 webkit.org/b/165799 webaudio/silent-audio-interrupted-in-background.html [ Skip ] 314 315 315 316 # AutoFill button is not supported -
trunk/Source/WebCore/ChangeLog
r214720 r214721 1 2017-04-01 Chris Dumez <cdumez@apple.com> 2 3 We should pause silent WebAudio rendering in background tabs 4 https://bugs.webkit.org/show_bug.cgi?id=170299 5 <rdar://problem/31289132> 6 7 Reviewed by Eric Carlson. 8 9 We should pause silent WebAudio rendering in background tabs since it uses CPU and is 10 not observable by the user. Such silent WebAudio rendering seems to be used by 11 doubleclick ads. 12 13 Test: webaudio/silent-audio-interrupted-in-background.html 14 15 * Modules/webaudio/AudioContext.cpp: 16 (WebCore::AudioContext::lazyInitialize): 17 (WebCore::AudioContext::uninitialize): 18 Have AudioContext register / unregister itself with the Document to get 19 visibility change notifications, similarly to what HTMLMediaElement was 20 already doing. 21 22 (WebCore::AudioContext::visibilityStateChanged): 23 Begin / End session interruption whenever the page visiblity changes. 24 25 * Modules/webaudio/AudioContext.h: 26 * WebCore.xcodeproj/project.pbxproj: 27 28 * dom/Document.cpp: 29 (WebCore::Document::registerForVisibilityStateChangedCallbacks): 30 (WebCore::Document::unregisterForVisibilityStateChangedCallbacks): 31 (WebCore::Document::visibilityStateChanged): 32 * dom/Document.h: 33 * dom/Element.h: 34 * dom/VisibilityChangeClient.h: Added. 35 (WebCore::VisibilityChangeClient::~VisibilityChangeClient): 36 * html/HTMLMediaElement.h: 37 Introduce a new VisibilityChangeClient interface and have both AudioContext 38 and HTMLMediaElement subclass it. Previously, the visibilityStateChanged() 39 function was on Element but this prevented AudioContext from registering 40 itself since AudioContext is not an Element. 41 1 42 2017-04-01 Dan Bernstein <mitz@apple.com> 2 43 -
trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp
r211964 r214721 55 55 #include "HRTFPanner.h" 56 56 #include "JSDOMPromise.h" 57 #include "Logging.h" 57 58 #include "NetworkingContext.h" 58 59 #include "OfflineAudioCompletionEvent.h" … … 105 106 106 107 namespace WebCore { 108 109 #define RELEASE_LOG_IF_ALLOWED(fmt, ...) RELEASE_LOG_IF(document()->page() && document()->page()->isAlwaysOnLoggingAllowed(), Media, "%p - AudioContext::" fmt, this, ##__VA_ARGS__) 107 110 108 111 bool AudioContext::isSampleRateRangeGood(float sampleRate) … … 216 219 if (!isOfflineContext()) { 217 220 document()->addAudioProducer(this); 221 document()->registerForVisibilityStateChangedCallbacks(this); 218 222 219 223 // This starts the audio thread. The destination node's provideInput() method will now be called repeatedly to render audio. … … 260 264 if (!isOfflineContext()) { 261 265 document()->removeAudioProducer(this); 266 document()->unregisterForVisibilityStateChangedCallbacks(this); 262 267 263 268 ASSERT(s_hardwareContextCount); … … 362 367 } 363 368 return emptyString(); 369 } 370 371 void AudioContext::visibilityStateChanged() 372 { 373 // Do not suspend if audio is audible. 374 if (mediaState() == MediaProducer::IsPlayingAudio) 375 return; 376 377 if (document()->hidden()) { 378 if (state() == State::Running) { 379 RELEASE_LOG_IF_ALLOWED("visibilityStateChanged() Suspending playback after going to the background"); 380 m_mediaSession->beginInterruption(PlatformMediaSession::EnteringBackground); 381 } 382 } else { 383 if (state() == State::Interrupted) { 384 RELEASE_LOG_IF_ALLOWED("visibilityStateChanged() Resuming playback after entering foreground"); 385 m_mediaSession->endInterruption(PlatformMediaSession::MayResumePlaying); 386 } 387 } 364 388 } 365 389 -
trunk/Source/WebCore/Modules/webaudio/AudioContext.h
r211240 r214721 36 36 #include "MediaProducer.h" 37 37 #include "PlatformMediaSession.h" 38 #include "VisibilityChangeClient.h" 38 39 #include <atomic> 39 40 #include <wtf/HashSet.h> … … 76 77 // For thread safety between the audio thread and the main thread, it has a rendering graph locking mechanism. 77 78 78 class AudioContext : public ActiveDOMObject, public ThreadSafeRefCounted<AudioContext>, public EventTargetWithInlineData, public MediaCanStartListener, public MediaProducer, private PlatformMediaSessionClient {79 class AudioContext : public ActiveDOMObject, public ThreadSafeRefCounted<AudioContext>, public EventTargetWithInlineData, public MediaCanStartListener, public MediaProducer, private PlatformMediaSessionClient, private VisibilityChangeClient { 79 80 public: 80 81 // Create an AudioContext for rendering to the audio hardware. … … 320 321 bool canProduceAudio() const final { return true; } 321 322 323 void visibilityStateChanged() final; 324 322 325 // EventTarget 323 326 void refEventTarget() override { ref(); } -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r214680 r214721 3283 3283 832B843419D8E55100B26055 /* SVGAnimateElementBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 832B843319D8E55100B26055 /* SVGAnimateElementBase.h */; }; 3284 3284 832B843619D8E57400B26055 /* SVGAnimateElementBase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 832B843519D8E57400B26055 /* SVGAnimateElementBase.cpp */; }; 3285 83407FC11E8D9C1700E048D3 /* VisibilityChangeClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 83407FC01E8D9C1200E048D3 /* VisibilityChangeClient.h */; settings = {ATTRIBUTES = (Private, ); }; }; 3285 3286 834476EE1DA5BC57002B6ED2 /* JSScrollToOptions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 83E9B3001DA5A51E00FFE8F6 /* JSScrollToOptions.cpp */; }; 3286 3287 834476EF1DA5BC5E002B6ED2 /* JSScrollToOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 83E9B3011DA5A51E00FFE8F6 /* JSScrollToOptions.h */; }; … … 11262 11263 832B843319D8E55100B26055 /* SVGAnimateElementBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGAnimateElementBase.h; sourceTree = "<group>"; }; 11263 11264 832B843519D8E57400B26055 /* SVGAnimateElementBase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGAnimateElementBase.cpp; sourceTree = "<group>"; }; 11265 83407FC01E8D9C1200E048D3 /* VisibilityChangeClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VisibilityChangeClient.h; sourceTree = "<group>"; }; 11264 11266 8348BFA91B85729500912F36 /* ClassCollection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ClassCollection.cpp; sourceTree = "<group>"; }; 11265 11267 8348BFAA1B85729500912F36 /* ClassCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ClassCollection.h; sourceTree = "<group>"; }; … … 25688 25690 CEF418CC1179678C009D112C /* ViewportArguments.cpp */, 25689 25691 CEF418CD1179678C009D112C /* ViewportArguments.h */, 25692 83407FC01E8D9C1200E048D3 /* VisibilityChangeClient.h */, 25690 25693 419BC2DC1685329900D64D6D /* VisitedLinkState.cpp */, 25691 25694 419BC2DD1685329900D64D6D /* VisitedLinkState.h */, … … 29642 29645 3FFFF9AE159D9B060020BBD5 /* ViewportStyleResolver.h in Headers */, 29643 29646 93309E20099E64920056E581 /* VisiblePosition.h in Headers */, 29647 83407FC11E8D9C1700E048D3 /* VisibilityChangeClient.h in Headers */, 29644 29648 A883DF280F3D045D00F19BF6 /* VisibleSelection.h in Headers */, 29645 29649 93309E1E099E64920056E581 /* VisibleUnits.h in Headers */, -
trunk/Source/WebCore/dom/Document.cpp
r214659 r214721 1531 1531 } 1532 1532 1533 void Document::registerForVisibilityStateChangedCallbacks( Element* element)1534 { 1535 m_visibilityStateCallback Elements.add(element);1536 } 1537 1538 void Document::unregisterForVisibilityStateChangedCallbacks( Element* element)1539 { 1540 m_visibilityStateCallback Elements.remove(element);1533 void Document::registerForVisibilityStateChangedCallbacks(VisibilityChangeClient* client) 1534 { 1535 m_visibilityStateCallbackClients.add(client); 1536 } 1537 1538 void Document::unregisterForVisibilityStateChangedCallbacks(VisibilityChangeClient* client) 1539 { 1540 m_visibilityStateCallbackClients.remove(client); 1541 1541 } 1542 1542 … … 1544 1544 { 1545 1545 dispatchEvent(Event::create(eventNames().visibilitychangeEvent, false, false)); 1546 for (auto* element : m_visibilityStateCallbackElements)1547 element->visibilityStateChanged();1546 for (auto* client : m_visibilityStateCallbackClients) 1547 client->visibilityStateChanged(); 1548 1548 } 1549 1549 -
trunk/Source/WebCore/dom/Document.h
r214702 r214721 164 164 class TextResourceDecoder; 165 165 class TreeWalker; 166 class VisibilityChangeClient; 166 167 class VisitedLinkState; 167 168 class XPathEvaluator; … … 1007 1008 #endif 1008 1009 1009 void registerForVisibilityStateChangedCallbacks( Element*);1010 void unregisterForVisibilityStateChangedCallbacks( Element*);1010 void registerForVisibilityStateChangedCallbacks(VisibilityChangeClient*); 1011 void unregisterForVisibilityStateChangedCallbacks(VisibilityChangeClient*); 1011 1012 1012 1013 #if ENABLE(VIDEO) … … 1521 1522 #endif 1522 1523 1523 HashSet< Element*> m_visibilityStateCallbackElements;1524 HashSet<VisibilityChangeClient*> m_visibilityStateCallbackClients; 1524 1525 #if ENABLE(VIDEO) 1525 1526 HashSet<HTMLMediaElement*> m_allowsMediaDocumentInlinePlaybackElements; -
trunk/Source/WebCore/dom/Element.h
r214510 r214721 401 401 virtual void willStopBeingFullscreenElement() { } 402 402 403 // Use Document::registerForVisibilityStateChangedCallbacks() to subscribe to this.404 virtual void visibilityStateChanged() { }405 406 403 #if ENABLE(VIDEO_TRACK) 407 404 virtual void captionPreferencesChanged() { } -
trunk/Source/WebCore/html/HTMLMediaElement.h
r214443 r214721 38 38 #include "MediaProducer.h" 39 39 #include "UserInterfaceLayoutDirection.h" 40 #include "VisibilityChangeClient.h" 40 41 41 42 #if ENABLE(VIDEO_TRACK) … … 112 113 , private MediaPlayerClient 113 114 , private MediaProducer 115 , private VisibilityChangeClient 114 116 #if ENABLE(VIDEO_TRACK) 115 117 , private AudioTrackClient
Note: See TracChangeset
for help on using the changeset viewer.