Allow MediaSessionManager to restrict media playback
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Jan 2014 19:42:27 +0000 (19:42 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Jan 2014 19:42:27 +0000 (19:42 +0000)
commitcb645f645d73d45b0af22eca5e7895848162e7bd
treee5e6137e6aabd104c0d4e64b1bc800f5c9ae8a43
parent12ad448dea8aa85eba5b14d22a0f6d64f155942a
Allow MediaSessionManager to restrict media playback
https://bugs.webkit.org/show_bug.cgi?id=126780

Reviewed by Jer Noble.

Source/WebCore:

Test: media/video-concurrent-playback.html

* WebCore.exp.in: Export functions needed by Internals.

Add HTMLMediaSession.
* WebCore.xcodeproj/project.pbxproj:
* CMakeLists.txt:
* GNUmakefile.list.am:
* WebCore.vcxproj/WebCore.vcxproj:
* WebCore.vcxproj/WebCore.vcxproj.filters:
* WebCore.xcodeproj/project.pbxproj:

Add a media session object to manage HTMLMediaElement restrictions.
* html/HTMLMediaSession.cpp: Added.
* html/HTMLMediaSession.h: Added.

Move media restriction management to a MediaSession.
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::HTMLMediaElement): Use the media session to manage restrictions.
(WebCore::HTMLMediaElement::parseAttribute): Ditto.
(WebCore::HTMLMediaElement::insertedInto): Ditto.
(WebCore::HTMLMediaElement::parseAttribute): Ditto.
(WebCore::HTMLMediaElement::loadInternal): Ditto.
(WebCore::HTMLMediaElement::loadResource): Ditto.
(WebCore::HTMLMediaElement::setReadyState): Ditto.
(WebCore::HTMLMediaElement::autoplay): Ditto.
(WebCore::HTMLMediaElement::play): Ditto.
(WebCore::HTMLMediaElement::pause): Ditto
(WebCore::HTMLMediaElement::pauseInternal): Ditto
(WebCore::HTMLMediaElement::suspend): Ditto
(WebCore::HTMLMediaElement::resume): Ditto.
(WebCore::HTMLMediaElement::updatePlayState): Tell media session playback is about to start.
(WebCore::HTMLMediaElement::deliverNotification): Ditto.
(WebCore::HTMLMediaElement::webkitShowPlaybackTargetPicker): Ditto.
(WebCore::HTMLMediaElement::mediaPlayerIsFullscreenPermitted): Ditto.
(WebCore::HTMLMediaElement::removeBehaviorsRestrictionsAfterFirstUserGesture): Ditto.
(WebCore::HTMLMediaElement::pausePlayback): New, allows the media session to pause playback.
* html/HTMLMediaElement.h:

* html/HTMLVideoElement.cpp:
(WebCore::HTMLVideoElement::webkitEnterFullscreen): Use the media session to manage restrictions.

* platform/audio/MediaSession.cpp:
(WebCore::MediaSession::beginInterruption): Add logging.
(WebCore::MediaSession::endInterruption): Ditto.
(WebCore::MediaSession::pauseSession): New, allows the session manager to pause playback.
* platform/audio/MediaSession.h:

Add per-media type restrictions.
* platform/audio/MediaSessionManager.cpp:
(WebCore::MediaSessionManager::MediaSessionManager): Initialize restrictions.
(WebCore::MediaSessionManager::addRestriction): New.
(WebCore::MediaSessionManager::removeRestriction): New.
(WebCore::MediaSessionManager::restrictions): New.
(WebCore::MediaSessionManager::sessionWillBeginPlayback): New. If only one session if the same
    type is allowed to play, pause all others.
* platform/audio/MediaSessionManager.h:

* platform/audio/ios/MediaSessionManagerIOS.h: Added.
* platform/audio/ios/MediaSessionManagerIOS.mm: Added.
(WebCore::MediaSessionManager::sharedManager):
(WebCore::m_objcObserver):
(-[WebAVAudioSessionHelper initWithCallback:]):
(-[WebAVAudioSessionHelper dealloc]):
(-[WebAVAudioSessionHelper interruption:]):

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

Allow tests to set media session restrictions.
* testing/Internals.cpp:
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests:

* media/video-concurrent-playback-expected.txt: Added.
* media/video-concurrent-playback.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@161899 268f45cc-cd09-0410-ab3c-d52691b4dbfc
24 files changed:
LayoutTests/ChangeLog
LayoutTests/media/video-concurrent-playback-expected.txt [new file with mode: 0644]
LayoutTests/media/video-concurrent-playback.html [new file with mode: 0644]
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/WebCore.exp.in
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/html/HTMLMediaSession.cpp [new file with mode: 0644]
Source/WebCore/html/HTMLMediaSession.h [new file with mode: 0644]
Source/WebCore/html/HTMLVideoElement.cpp
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 [new file with mode: 0644]
Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm [new file with mode: 0644]
Source/WebCore/platform/audio/mac/AudioDestinationMac.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl