Refine MediaSession interruptions
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Feb 2014 19:09:34 +0000 (19:09 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Feb 2014 19:09:34 +0000 (19:09 +0000)
commite74a7aa5536d22ae898c073e935c7bc04c921136
tree81e0813215775795ef51dae231091ae179f09238
parent7675291e25a7f5100758815d57d697eef0ff8595
Refine MediaSession interruptions
https://bugs.webkit.org/show_bug.cgi?id=128125

Reviewed by Jer Noble.

Source/WebCore:

Test: media/video-background-playback.html

* WebCore.exp.in: Export applicationWillEnterForeground and applicationWillEnterBackground for
    Internals.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::play): Ask the media session if playback is allowed instead of check
    to see if it is interrupted directly.
(WebCore::HTMLMediaElement::pause): Ask the media session if pausing is allowed instead of check
    to see if it is interrupted directly.
(WebCore::HTMLMediaElement::mediaType): Return media type based on media characteristics once
    the information is available.
(WebCore::HTMLMediaElement::resumePlayback): New.
* html/HTMLMediaElement.h:

* html/HTMLMediaSession.cpp:
(WebCore::restrictionName): New, use for logging only.
(WebCore::HTMLMediaSession::addBehaviorRestriction): Log  restriction changes.
(WebCore::HTMLMediaSession::removeBehaviorRestriction): Ditto.
* html/HTMLMediaSession.h:

* platform/audio/MediaSession.cpp:
(WebCore::stateName): New, used for logging.
(WebCore::MediaSession::MediaSession): Don't cache client media type because it can change.
(WebCore::MediaSession::setState): Log state changes.
(WebCore::MediaSession::beginInterruption): Remember the current state in case we want to use it
    to restore state when the interruption ends.
(WebCore::MediaSession::endInterruption): Resume playback if appropriate.
(WebCore::MediaSession::clientWillBeginPlayback): Track the client's playback state.
(WebCore::MediaSession::clientWillPausePlayback): Ditto.
(WebCore::MediaSession::mediaType): Ask client for state.
* platform/audio/MediaSession.h:

* platform/audio/MediaSessionManager.cpp:
(WebCore::MediaSessionManager::MediaSessionManager): m_interruptions -> m_interrupted.
(WebCore::MediaSessionManager::beginInterruption): Don't assume interruptions are always balanced.
(WebCore::MediaSessionManager::endInterruption): Ditto.
(WebCore::MediaSessionManager::addSession):
(WebCore::MediaSessionManager::applicationWillEnterBackground): Interrupt client if it is not
    allowed to play in the background.
(WebCore::MediaSessionManager::applicationWillEnterForeground): End client interruption if it
    was stopped by an interruption.
* platform/audio/MediaSessionManager.h:

* platform/audio/ios/MediaSessionManagerIOS.h:
* platform/audio/ios/MediaSessionManagerIOS.mm:
(WebCore::MediaSessionManageriOS::~MediaSessionManageriOS): Clear the helper callback.
(WebCore::MediaSessionManageriOS::resetRestrictions): Mark video as not allowed to play
    while the application is in the background. Register for application suspend/resume
    notifications.
(-[WebMediaSessionHelper clearCallback]): Set _callback to nil.
(-[WebMediaSessionHelper applicationWillEnterForeground:]): New, notify client of application
    state change.
(-[WebMediaSessionHelper applicationWillResignActive:]): Ditto.

* platform/audio/mac/AudioDestinationMac.h: Add resumePlayback.

* testing/Internals.cpp:
(WebCore::Internals::applicationWillEnterForeground): New, simulate application context switch.
(WebCore::Internals::applicationWillEnterBackground): Ditto.
(WebCore::Internals::setMediaSessionRestrictions): Add "BackgroundPlaybackNotPermitted" restriction.
* testing/Internals.h:
* testing/Internals.idl:

Source/WebKit:

* WebKit.vcxproj/WebKitExportGenerator/WebKitExports.def.in: Export applicationWillEnterForeground
    and applicationWillEnterBackground for Internals.

LayoutTests:

* media/video-background-playback-expected.txt: Added.
* media/video-background-playback.html: Added.
* media/video-interruption-active-when-element-created-expected.txt: Removed.
* media/video-interruption-active-when-element-created.html: Removed.
* media/video-interruption-with-resume-allowing-play-expected.txt:
* media/video-interruption-with-resume-allowing-play.html:
* media/video-interruption-with-resume-not-allowing-play-expected.txt:
* media/video-interruption-with-resume-not-allowing-play.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@163390 268f45cc-cd09-0410-ab3c-d52691b4dbfc
27 files changed:
LayoutTests/ChangeLog
LayoutTests/media/video-background-playback-expected.txt [new file with mode: 0644]
LayoutTests/media/video-background-playback.html [new file with mode: 0644]
LayoutTests/media/video-interruption-active-when-element-created-expected.txt [deleted file]
LayoutTests/media/video-interruption-active-when-element-created.html [deleted file]
LayoutTests/media/video-interruption-with-resume-allowing-play-expected.txt
LayoutTests/media/video-interruption-with-resume-allowing-play.html
LayoutTests/media/video-interruption-with-resume-not-allowing-play-expected.txt
LayoutTests/media/video-interruption-with-resume-not-allowing-play.html
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/html/HTMLMediaSession.cpp
Source/WebCore/html/HTMLMediaSession.h
Source/WebCore/platform/audio/MediaSession.cpp
Source/WebCore/platform/audio/MediaSession.h
Source/WebCore/platform/audio/MediaSessionManager.cpp
Source/WebCore/platform/audio/MediaSessionManager.h
Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.h
Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm
Source/WebCore/platform/audio/mac/AudioDestinationMac.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebKit/ChangeLog
Source/WebKit/WebKit.vcxproj/WebKitExportGenerator/WebKitExports.def.in