haikuwebkit/LayoutTests/media/video-interruption-with-res...

58 lines
1.7 KiB
HTML
Raw Permalink Normal View History

Teach MediaSessionManager to manage interruptions https://bugs.webkit.org/show_bug.cgi?id=126530 Reviewed by Sam Weinig. Source/WebCore: Tests: media/video-interruption-active-when-element-created.html media/video-interruption-with-resume-allowing-play.html media/video-interruption-with-resume-not-allowing-play.html * WebCore.exp.in: Export functions needed by Internals. Add MediaSession and MediaSessionManager. * CMakeLists.txt: * GNUmakefile.list.am: * WebCore.vcxproj/WebCore.vcxproj: * WebCore.vcxproj/WebCore.vcxproj.filters: * WebCore.xcodeproj/project.pbxproj: Automatically pause/play for interruptions. Move media restriction management to a MediaSession. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::HTMLMediaElement): Get rid of m_loadInitiatedByUserGesture and m_userStartedPlayback, they aren't needed. (WebCore::HTMLMediaElement::load): Ditto. (WebCore::HTMLMediaElement::loadInternal): Use the media session to manage restrictions. (WebCore::HTMLMediaElement::play): Remove redundant iOS code. Postpone playback if called during an interruption. (WebCore::HTMLMediaElement::pause): Remember to not resume playback when it ends if called during an interruption. (WebCore::HTMLMediaElement::potentiallyPlaying): Rearrange code to make it easier to understand. (WebCore::HTMLMediaElement::couldPlayIfEnoughData): Ditto. (WebCore::HTMLMediaElement::pausedForUserInteraction): Return true if paused because of an interruption. (WebCore::HTMLMediaElement::removeBehaviorsRestrictionsAfterFirstUserGesture): Be explicit about which restrictions are removed. (WebCore::HTMLMediaElement::mediaType): MediaSessionManager::<Type> -> MediaSession::<Type>. (WebCore::HTMLMediaElement::beginInterruption): New. (WebCore::HTMLMediaElement::endInterruption): Ditto. * html/HTMLMediaElement.h: Pulled MediaSessionManagerToken out of MediaSessionManager.cpp, added functionality to manage interruptions. * platform/audio/MediaSession.cpp: Added. (WebCore::MediaSession::create): (WebCore::MediaSession::MediaSession): (WebCore::MediaSession::~MediaSession): (WebCore::MediaSession::beginInterruption): Inform client of interruption state change. (WebCore::MediaSession::endInterruption): Ditto. * platform/audio/MediaSession.h: Added. * platform/audio/MediaSessionManager.cpp: (WebCore::MediaSessionManager::MediaSessionManager): Initialize interruption counter. (WebCore::MediaSessionManager::has): MediaType is defined in MediaSession. (WebCore::MediaSessionManager::count): Ditto. (WebCore::MediaSessionManager::beginInterruption): Inform all clients of interruption start if not already in an interruption. (WebCore::MediaSessionManager::endInterruption): Inform all clients if interruption has ended. (WebCore::MediaSessionManager::addSession): Renamed from addToken. Set session interruption state. (WebCore::MediaSessionManager::removeSession): Renamed from removeToken. * platform/audio/MediaSessionManager.h: * platform/audio/mac/AudioDestinationMac.cpp: (WebCore::AudioDestinationMac::AudioDestinationMac): MediaSessionManagerToken -> MediaSession. * platform/audio/mac/AudioDestinationMac.h: * platform/audio/mac/MediaSessionManagerMac.cpp: (MediaSessionManager::updateSessionState): Ditto. Make it possible for tests to begin and end interruptions. * testing/Internals.cpp: (WebCore::Internals::beginMediaSessionInterruption): (WebCore::Internals::endMediaSessionInterruption): * testing/Internals.h: * testing/Internals.idl: Source/WebKit: * CMakeLists.txt: Add ${WEBCORE_DIR}/platform/animation to WebCore include directories. Source/WebKit2: * CMakeLists.txt: Add ${WEBCORE_DIR}/platform/animation to WebCore include directories. LayoutTests: * media/video-interruption-active-when-element-created-expected.txt: Added. * media/video-interruption-active-when-element-created.html: Added. * media/video-interruption-with-resume-allowing-play-expected.txt: Added. * media/video-interruption-with-resume-allowing-play.html: Added. * media/video-interruption-with-resume-not-allowing-play-expected.txt: Added. * media/video-interruption-with-resume-not-allowing-play.html: Added. Canonical link: https://commits.webkit.org/144518@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@161481 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-01-08 05:45:55 +00:00
<html>
<head>
<script src=media-file.js></script>
<script src=video-test.js></script>
<script>
var state = 0;
function playing()
{
[iOS] AirPlay should not stop when the screen locks https://bugs.webkit.org/show_bug.cgi?id=148315 <rdar://problem/22770703> Patch by Eric Carlson <eric.carlson@apple.com> on 2015-10-01 Reviewed by Jer Noble. Source/WebCore: Tested by media/video-interruption-with-resume-allowing-play.html media/video-interruption-with-resume-not-allowing-play.html * Modules/webaudio/AudioContext.h: overrideBackgroundPlaybackRestriction -> shouldOverrideBackgroundPlaybackRestriction. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::suspendPlayback): Fix a typo in the logging. (WebCore::HTMLMediaElement::mayResumePlayback): Ditto. (WebCore::HTMLMediaElement::shouldOverrideBackgroundPlaybackRestriction): Renamed from overrideBackgroundPlaybackRestriction. (WebCore::HTMLMediaElement::overrideBackgroundPlaybackRestriction): Deleted. * html/HTMLMediaElement.h: * platform/audio/PlatformMediaSession.cpp: (WebCore::stateName): (WebCore::interruptionName): New, log the name of the interruption. (WebCore::PlatformMediaSession::beginInterruption): Log the interruption type. Don't increment the interruption counter if we are going to ignore it. Incorporate logic from doInterruption. (WebCore::PlatformMediaSession::doInterruption): Deleted. (WebCore::PlatformMediaSession::shouldDoInterruption): Deleted. (WebCore::PlatformMediaSession::forceInterruption): Deleted. * platform/audio/PlatformMediaSession.h: Add SuspendedUnderLock interruption type. * platform/audio/PlatformMediaSessionManager.cpp: (WebCore::PlatformMediaSessionManager::applicationDidEnterBackground): Deleted. * platform/audio/PlatformMediaSessionManager.h: * platform/audio/ios/MediaSessionManagerIOS.h: * platform/audio/ios/MediaSessionManagerIOS.mm: (WebCore::MediaSessionManageriOS::applicationDidEnterBackground): Call beginInterruption when appropriate. LayoutTests: * media/video-interruption-with-resume-allowing-play.html: * media/video-interruption-with-resume-not-allowing-play.html: Canonical link: https://commits.webkit.org/167843@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@190434 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-10-01 22:32:56 +00:00
run("internals.beginMediaSessionInterruption('System')");;
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: Canonical link: https://commits.webkit.org/146196@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@163390 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-02-04 19:09:34 +00:00
setTimeout(checkState, 100);
Teach MediaSessionManager to manage interruptions https://bugs.webkit.org/show_bug.cgi?id=126530 Reviewed by Sam Weinig. Source/WebCore: Tests: media/video-interruption-active-when-element-created.html media/video-interruption-with-resume-allowing-play.html media/video-interruption-with-resume-not-allowing-play.html * WebCore.exp.in: Export functions needed by Internals. Add MediaSession and MediaSessionManager. * CMakeLists.txt: * GNUmakefile.list.am: * WebCore.vcxproj/WebCore.vcxproj: * WebCore.vcxproj/WebCore.vcxproj.filters: * WebCore.xcodeproj/project.pbxproj: Automatically pause/play for interruptions. Move media restriction management to a MediaSession. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::HTMLMediaElement): Get rid of m_loadInitiatedByUserGesture and m_userStartedPlayback, they aren't needed. (WebCore::HTMLMediaElement::load): Ditto. (WebCore::HTMLMediaElement::loadInternal): Use the media session to manage restrictions. (WebCore::HTMLMediaElement::play): Remove redundant iOS code. Postpone playback if called during an interruption. (WebCore::HTMLMediaElement::pause): Remember to not resume playback when it ends if called during an interruption. (WebCore::HTMLMediaElement::potentiallyPlaying): Rearrange code to make it easier to understand. (WebCore::HTMLMediaElement::couldPlayIfEnoughData): Ditto. (WebCore::HTMLMediaElement::pausedForUserInteraction): Return true if paused because of an interruption. (WebCore::HTMLMediaElement::removeBehaviorsRestrictionsAfterFirstUserGesture): Be explicit about which restrictions are removed. (WebCore::HTMLMediaElement::mediaType): MediaSessionManager::<Type> -> MediaSession::<Type>. (WebCore::HTMLMediaElement::beginInterruption): New. (WebCore::HTMLMediaElement::endInterruption): Ditto. * html/HTMLMediaElement.h: Pulled MediaSessionManagerToken out of MediaSessionManager.cpp, added functionality to manage interruptions. * platform/audio/MediaSession.cpp: Added. (WebCore::MediaSession::create): (WebCore::MediaSession::MediaSession): (WebCore::MediaSession::~MediaSession): (WebCore::MediaSession::beginInterruption): Inform client of interruption state change. (WebCore::MediaSession::endInterruption): Ditto. * platform/audio/MediaSession.h: Added. * platform/audio/MediaSessionManager.cpp: (WebCore::MediaSessionManager::MediaSessionManager): Initialize interruption counter. (WebCore::MediaSessionManager::has): MediaType is defined in MediaSession. (WebCore::MediaSessionManager::count): Ditto. (WebCore::MediaSessionManager::beginInterruption): Inform all clients of interruption start if not already in an interruption. (WebCore::MediaSessionManager::endInterruption): Inform all clients if interruption has ended. (WebCore::MediaSessionManager::addSession): Renamed from addToken. Set session interruption state. (WebCore::MediaSessionManager::removeSession): Renamed from removeToken. * platform/audio/MediaSessionManager.h: * platform/audio/mac/AudioDestinationMac.cpp: (WebCore::AudioDestinationMac::AudioDestinationMac): MediaSessionManagerToken -> MediaSession. * platform/audio/mac/AudioDestinationMac.h: * platform/audio/mac/MediaSessionManagerMac.cpp: (MediaSessionManager::updateSessionState): Ditto. Make it possible for tests to begin and end interruptions. * testing/Internals.cpp: (WebCore::Internals::beginMediaSessionInterruption): (WebCore::Internals::endMediaSessionInterruption): * testing/Internals.h: * testing/Internals.idl: Source/WebKit: * CMakeLists.txt: Add ${WEBCORE_DIR}/platform/animation to WebCore include directories. Source/WebKit2: * CMakeLists.txt: Add ${WEBCORE_DIR}/platform/animation to WebCore include directories. LayoutTests: * media/video-interruption-active-when-element-created-expected.txt: Added. * media/video-interruption-active-when-element-created.html: Added. * media/video-interruption-with-resume-allowing-play-expected.txt: Added. * media/video-interruption-with-resume-allowing-play.html: Added. * media/video-interruption-with-resume-not-allowing-play-expected.txt: Added. * media/video-interruption-with-resume-not-allowing-play.html: Added. Canonical link: https://commits.webkit.org/144518@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@161481 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-01-08 05:45:55 +00:00
}
function checkState()
{
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: Canonical link: https://commits.webkit.org/146196@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@163390 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-02-04 19:09:34 +00:00
consoleWrite("<br>100ms timer fired...");
Teach MediaSessionManager to manage interruptions https://bugs.webkit.org/show_bug.cgi?id=126530 Reviewed by Sam Weinig. Source/WebCore: Tests: media/video-interruption-active-when-element-created.html media/video-interruption-with-resume-allowing-play.html media/video-interruption-with-resume-not-allowing-play.html * WebCore.exp.in: Export functions needed by Internals. Add MediaSession and MediaSessionManager. * CMakeLists.txt: * GNUmakefile.list.am: * WebCore.vcxproj/WebCore.vcxproj: * WebCore.vcxproj/WebCore.vcxproj.filters: * WebCore.xcodeproj/project.pbxproj: Automatically pause/play for interruptions. Move media restriction management to a MediaSession. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::HTMLMediaElement): Get rid of m_loadInitiatedByUserGesture and m_userStartedPlayback, they aren't needed. (WebCore::HTMLMediaElement::load): Ditto. (WebCore::HTMLMediaElement::loadInternal): Use the media session to manage restrictions. (WebCore::HTMLMediaElement::play): Remove redundant iOS code. Postpone playback if called during an interruption. (WebCore::HTMLMediaElement::pause): Remember to not resume playback when it ends if called during an interruption. (WebCore::HTMLMediaElement::potentiallyPlaying): Rearrange code to make it easier to understand. (WebCore::HTMLMediaElement::couldPlayIfEnoughData): Ditto. (WebCore::HTMLMediaElement::pausedForUserInteraction): Return true if paused because of an interruption. (WebCore::HTMLMediaElement::removeBehaviorsRestrictionsAfterFirstUserGesture): Be explicit about which restrictions are removed. (WebCore::HTMLMediaElement::mediaType): MediaSessionManager::<Type> -> MediaSession::<Type>. (WebCore::HTMLMediaElement::beginInterruption): New. (WebCore::HTMLMediaElement::endInterruption): Ditto. * html/HTMLMediaElement.h: Pulled MediaSessionManagerToken out of MediaSessionManager.cpp, added functionality to manage interruptions. * platform/audio/MediaSession.cpp: Added. (WebCore::MediaSession::create): (WebCore::MediaSession::MediaSession): (WebCore::MediaSession::~MediaSession): (WebCore::MediaSession::beginInterruption): Inform client of interruption state change. (WebCore::MediaSession::endInterruption): Ditto. * platform/audio/MediaSession.h: Added. * platform/audio/MediaSessionManager.cpp: (WebCore::MediaSessionManager::MediaSessionManager): Initialize interruption counter. (WebCore::MediaSessionManager::has): MediaType is defined in MediaSession. (WebCore::MediaSessionManager::count): Ditto. (WebCore::MediaSessionManager::beginInterruption): Inform all clients of interruption start if not already in an interruption. (WebCore::MediaSessionManager::endInterruption): Inform all clients if interruption has ended. (WebCore::MediaSessionManager::addSession): Renamed from addToken. Set session interruption state. (WebCore::MediaSessionManager::removeSession): Renamed from removeToken. * platform/audio/MediaSessionManager.h: * platform/audio/mac/AudioDestinationMac.cpp: (WebCore::AudioDestinationMac::AudioDestinationMac): MediaSessionManagerToken -> MediaSession. * platform/audio/mac/AudioDestinationMac.h: * platform/audio/mac/MediaSessionManagerMac.cpp: (MediaSessionManager::updateSessionState): Ditto. Make it possible for tests to begin and end interruptions. * testing/Internals.cpp: (WebCore::Internals::beginMediaSessionInterruption): (WebCore::Internals::endMediaSessionInterruption): * testing/Internals.h: * testing/Internals.idl: Source/WebKit: * CMakeLists.txt: Add ${WEBCORE_DIR}/platform/animation to WebCore include directories. Source/WebKit2: * CMakeLists.txt: Add ${WEBCORE_DIR}/platform/animation to WebCore include directories. LayoutTests: * media/video-interruption-active-when-element-created-expected.txt: Added. * media/video-interruption-active-when-element-created.html: Added. * media/video-interruption-with-resume-allowing-play-expected.txt: Added. * media/video-interruption-with-resume-allowing-play.html: Added. * media/video-interruption-with-resume-not-allowing-play-expected.txt: Added. * media/video-interruption-with-resume-not-allowing-play.html: Added. Canonical link: https://commits.webkit.org/144518@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@161481 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-01-08 05:45:55 +00:00
testExpected("video.paused", true);
switch (state) {
case "interrupted":
state = "resuming";
setTimeout(checkState, 100);
run("internals.endMediaSessionInterruption('')");
break;
case "resuming":
consoleWrite("");
endTest();
break;
}
}
function canplaythrough()
{
state = "interrupted";
run("video.play()");
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: Canonical link: https://commits.webkit.org/146196@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@163390 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-02-04 19:09:34 +00:00
consoleWrite("");
Teach MediaSessionManager to manage interruptions https://bugs.webkit.org/show_bug.cgi?id=126530 Reviewed by Sam Weinig. Source/WebCore: Tests: media/video-interruption-active-when-element-created.html media/video-interruption-with-resume-allowing-play.html media/video-interruption-with-resume-not-allowing-play.html * WebCore.exp.in: Export functions needed by Internals. Add MediaSession and MediaSessionManager. * CMakeLists.txt: * GNUmakefile.list.am: * WebCore.vcxproj/WebCore.vcxproj: * WebCore.vcxproj/WebCore.vcxproj.filters: * WebCore.xcodeproj/project.pbxproj: Automatically pause/play for interruptions. Move media restriction management to a MediaSession. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::HTMLMediaElement): Get rid of m_loadInitiatedByUserGesture and m_userStartedPlayback, they aren't needed. (WebCore::HTMLMediaElement::load): Ditto. (WebCore::HTMLMediaElement::loadInternal): Use the media session to manage restrictions. (WebCore::HTMLMediaElement::play): Remove redundant iOS code. Postpone playback if called during an interruption. (WebCore::HTMLMediaElement::pause): Remember to not resume playback when it ends if called during an interruption. (WebCore::HTMLMediaElement::potentiallyPlaying): Rearrange code to make it easier to understand. (WebCore::HTMLMediaElement::couldPlayIfEnoughData): Ditto. (WebCore::HTMLMediaElement::pausedForUserInteraction): Return true if paused because of an interruption. (WebCore::HTMLMediaElement::removeBehaviorsRestrictionsAfterFirstUserGesture): Be explicit about which restrictions are removed. (WebCore::HTMLMediaElement::mediaType): MediaSessionManager::<Type> -> MediaSession::<Type>. (WebCore::HTMLMediaElement::beginInterruption): New. (WebCore::HTMLMediaElement::endInterruption): Ditto. * html/HTMLMediaElement.h: Pulled MediaSessionManagerToken out of MediaSessionManager.cpp, added functionality to manage interruptions. * platform/audio/MediaSession.cpp: Added. (WebCore::MediaSession::create): (WebCore::MediaSession::MediaSession): (WebCore::MediaSession::~MediaSession): (WebCore::MediaSession::beginInterruption): Inform client of interruption state change. (WebCore::MediaSession::endInterruption): Ditto. * platform/audio/MediaSession.h: Added. * platform/audio/MediaSessionManager.cpp: (WebCore::MediaSessionManager::MediaSessionManager): Initialize interruption counter. (WebCore::MediaSessionManager::has): MediaType is defined in MediaSession. (WebCore::MediaSessionManager::count): Ditto. (WebCore::MediaSessionManager::beginInterruption): Inform all clients of interruption start if not already in an interruption. (WebCore::MediaSessionManager::endInterruption): Inform all clients if interruption has ended. (WebCore::MediaSessionManager::addSession): Renamed from addToken. Set session interruption state. (WebCore::MediaSessionManager::removeSession): Renamed from removeToken. * platform/audio/MediaSessionManager.h: * platform/audio/mac/AudioDestinationMac.cpp: (WebCore::AudioDestinationMac::AudioDestinationMac): MediaSessionManagerToken -> MediaSession. * platform/audio/mac/AudioDestinationMac.h: * platform/audio/mac/MediaSessionManagerMac.cpp: (MediaSessionManager::updateSessionState): Ditto. Make it possible for tests to begin and end interruptions. * testing/Internals.cpp: (WebCore::Internals::beginMediaSessionInterruption): (WebCore::Internals::endMediaSessionInterruption): * testing/Internals.h: * testing/Internals.idl: Source/WebKit: * CMakeLists.txt: Add ${WEBCORE_DIR}/platform/animation to WebCore include directories. Source/WebKit2: * CMakeLists.txt: Add ${WEBCORE_DIR}/platform/animation to WebCore include directories. LayoutTests: * media/video-interruption-active-when-element-created-expected.txt: Added. * media/video-interruption-active-when-element-created.html: Added. * media/video-interruption-with-resume-allowing-play-expected.txt: Added. * media/video-interruption-with-resume-allowing-play.html: Added. * media/video-interruption-with-resume-not-allowing-play-expected.txt: Added. * media/video-interruption-with-resume-not-allowing-play.html: Added. Canonical link: https://commits.webkit.org/144518@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@161481 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-01-08 05:45:55 +00:00
}
function start()
{
if (!window.internals) {
failTest('This test requires window.internals.');
return;
}
findMediaElement();
waitForEvent('canplaythrough', canplaythrough);
waitForEvent('playing', playing);
video.src = findMediaFile("video", "content/test");
}
</script>
</head>
<body onload="start()">
<video controls ></video>
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: Canonical link: https://commits.webkit.org/146196@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@163390 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-02-04 19:09:34 +00:00
<p>Test that playback is paused by an interruption, and that ending the interruption does automatically resume playback.</p>
Teach MediaSessionManager to manage interruptions https://bugs.webkit.org/show_bug.cgi?id=126530 Reviewed by Sam Weinig. Source/WebCore: Tests: media/video-interruption-active-when-element-created.html media/video-interruption-with-resume-allowing-play.html media/video-interruption-with-resume-not-allowing-play.html * WebCore.exp.in: Export functions needed by Internals. Add MediaSession and MediaSessionManager. * CMakeLists.txt: * GNUmakefile.list.am: * WebCore.vcxproj/WebCore.vcxproj: * WebCore.vcxproj/WebCore.vcxproj.filters: * WebCore.xcodeproj/project.pbxproj: Automatically pause/play for interruptions. Move media restriction management to a MediaSession. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::HTMLMediaElement): Get rid of m_loadInitiatedByUserGesture and m_userStartedPlayback, they aren't needed. (WebCore::HTMLMediaElement::load): Ditto. (WebCore::HTMLMediaElement::loadInternal): Use the media session to manage restrictions. (WebCore::HTMLMediaElement::play): Remove redundant iOS code. Postpone playback if called during an interruption. (WebCore::HTMLMediaElement::pause): Remember to not resume playback when it ends if called during an interruption. (WebCore::HTMLMediaElement::potentiallyPlaying): Rearrange code to make it easier to understand. (WebCore::HTMLMediaElement::couldPlayIfEnoughData): Ditto. (WebCore::HTMLMediaElement::pausedForUserInteraction): Return true if paused because of an interruption. (WebCore::HTMLMediaElement::removeBehaviorsRestrictionsAfterFirstUserGesture): Be explicit about which restrictions are removed. (WebCore::HTMLMediaElement::mediaType): MediaSessionManager::<Type> -> MediaSession::<Type>. (WebCore::HTMLMediaElement::beginInterruption): New. (WebCore::HTMLMediaElement::endInterruption): Ditto. * html/HTMLMediaElement.h: Pulled MediaSessionManagerToken out of MediaSessionManager.cpp, added functionality to manage interruptions. * platform/audio/MediaSession.cpp: Added. (WebCore::MediaSession::create): (WebCore::MediaSession::MediaSession): (WebCore::MediaSession::~MediaSession): (WebCore::MediaSession::beginInterruption): Inform client of interruption state change. (WebCore::MediaSession::endInterruption): Ditto. * platform/audio/MediaSession.h: Added. * platform/audio/MediaSessionManager.cpp: (WebCore::MediaSessionManager::MediaSessionManager): Initialize interruption counter. (WebCore::MediaSessionManager::has): MediaType is defined in MediaSession. (WebCore::MediaSessionManager::count): Ditto. (WebCore::MediaSessionManager::beginInterruption): Inform all clients of interruption start if not already in an interruption. (WebCore::MediaSessionManager::endInterruption): Inform all clients if interruption has ended. (WebCore::MediaSessionManager::addSession): Renamed from addToken. Set session interruption state. (WebCore::MediaSessionManager::removeSession): Renamed from removeToken. * platform/audio/MediaSessionManager.h: * platform/audio/mac/AudioDestinationMac.cpp: (WebCore::AudioDestinationMac::AudioDestinationMac): MediaSessionManagerToken -> MediaSession. * platform/audio/mac/AudioDestinationMac.h: * platform/audio/mac/MediaSessionManagerMac.cpp: (MediaSessionManager::updateSessionState): Ditto. Make it possible for tests to begin and end interruptions. * testing/Internals.cpp: (WebCore::Internals::beginMediaSessionInterruption): (WebCore::Internals::endMediaSessionInterruption): * testing/Internals.h: * testing/Internals.idl: Source/WebKit: * CMakeLists.txt: Add ${WEBCORE_DIR}/platform/animation to WebCore include directories. Source/WebKit2: * CMakeLists.txt: Add ${WEBCORE_DIR}/platform/animation to WebCore include directories. LayoutTests: * media/video-interruption-active-when-element-created-expected.txt: Added. * media/video-interruption-active-when-element-created.html: Added. * media/video-interruption-with-resume-allowing-play-expected.txt: Added. * media/video-interruption-with-resume-allowing-play.html: Added. * media/video-interruption-with-resume-not-allowing-play-expected.txt: Added. * media/video-interruption-with-resume-not-allowing-play.html: Added. Canonical link: https://commits.webkit.org/144518@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@161481 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-01-08 05:45:55 +00:00
</body>
</html>