Diff
Modified: branches/safari-600.1.4.15-branch/LayoutTests/ChangeLog (180664 => 180665)
--- branches/safari-600.1.4.15-branch/LayoutTests/ChangeLog 2015-02-26 07:25:05 UTC (rev 180664)
+++ branches/safari-600.1.4.15-branch/LayoutTests/ChangeLog 2015-02-26 08:00:36 UTC (rev 180665)
@@ -1,3 +1,20 @@
+2015-02-25 Babak Shafiei <[email protected]>
+
+ Merge r180274.
+
+ 2015-02-18 Eric Carlson <[email protected]>
+
+ [iOS] pause video when a tab moves to the background on some devices
+ https://bugs.webkit.org/show_bug.cgi?id=141753
+ <rdar://problem/19814562>
+
+ Reviewed by Jer Noble.
+
+ * media/video-background-playback-expected.txt: BackgroundPlaybackNotPermitted -> BackgroundProcessPlaybackRestricted.
+ * media/video-background-playback.html: Ditto.
+ * media/video-background-tab-playback-expected.txt: Added.
+ * media/video-background-tab-playback.html: Added.
+
2015-02-20 Lucas Forschler <[email protected]>
Merge r180278
Modified: branches/safari-600.1.4.15-branch/LayoutTests/media/video-background-playback-expected.txt (180664 => 180665)
--- branches/safari-600.1.4.15-branch/LayoutTests/media/video-background-playback-expected.txt 2015-02-26 07:25:05 UTC (rev 180664)
+++ branches/safari-600.1.4.15-branch/LayoutTests/media/video-background-playback-expected.txt 2015-02-26 08:00:36 UTC (rev 180665)
@@ -1,7 +1,7 @@
Test switching application state when <video> is not allowed to play in background.
-RUN(internals.setMediaSessionRestrictions('video', 'BackgroundPlaybackNotPermitted'))
+RUN(internals.setMediaSessionRestrictions('video', 'BackgroundProcessPlaybackRestricted'))
EVENT(canplaythrough)
EVENT(canplaythrough)
Modified: branches/safari-600.1.4.15-branch/LayoutTests/media/video-background-playback.html (180664 => 180665)
--- branches/safari-600.1.4.15-branch/LayoutTests/media/video-background-playback.html 2015-02-26 07:25:05 UTC (rev 180664)
+++ branches/safari-600.1.4.15-branch/LayoutTests/media/video-background-playback.html 2015-02-26 08:00:36 UTC (rev 180665)
@@ -78,7 +78,7 @@
audio = elements[1];
audio.src = "" "content/silence");
- run("internals.setMediaSessionRestrictions('video', 'BackgroundPlaybackNotPermitted')");
+ run("internals.setMediaSessionRestrictions('video', 'BackgroundProcessPlaybackRestricted')");
state = "foreground";
consoleWrite("");
}
Copied: branches/safari-600.1.4.15-branch/LayoutTests/media/video-background-tab-playback-expected.txt (from rev 180274, trunk/LayoutTests/media/video-background-tab-playback-expected.txt) (0 => 180665)
--- branches/safari-600.1.4.15-branch/LayoutTests/media/video-background-tab-playback-expected.txt (rev 0)
+++ branches/safari-600.1.4.15-branch/LayoutTests/media/video-background-tab-playback-expected.txt 2015-02-26 08:00:36 UTC (rev 180665)
@@ -0,0 +1,26 @@
+
+Test tab with <video> moving to background when playback is not allowed in background.
+
+RUN(internals.setMediaSessionRestrictions('video', 'BackgroundTabPlaybackRestricted'))
+
+EVENT(canplaythrough)
+
+RUN(video.play())
+EVENT(playing)
+
+** Simulate switching the tab to background, video should pause.
+RUN(testRunner.setPageVisibility('hidden'))
+
+
+** 100ms timer fired...
+EXPECTED (video.paused == 'true') OK
+
+** Simulate switch back to foreground, video should remain paused.
+RUN(internals.applicationWillEnterForeground())
+
+
+** 100ms timer fired...
+EXPECTED (video.paused == 'true') OK
+
+END OF TEST
+
Copied: branches/safari-600.1.4.15-branch/LayoutTests/media/video-background-tab-playback.html (from rev 180274, trunk/LayoutTests/media/video-background-tab-playback.html) (0 => 180665)
--- branches/safari-600.1.4.15-branch/LayoutTests/media/video-background-tab-playback.html (rev 0)
+++ branches/safari-600.1.4.15-branch/LayoutTests/media/video-background-tab-playback.html 2015-02-26 08:00:36 UTC (rev 180665)
@@ -0,0 +1,67 @@
+<html>
+ <head>
+ <script src=""
+ <script src=""
+ <script>
+ var state = 0;
+
+ function checkState()
+ {
+ consoleWrite("<br>** 100ms timer fired...");
+ switch (state) {
+ case "background":
+ testExpected("video.paused", true);
+ state = "foreground";
+ consoleWrite("<br>** Simulate switch back to foreground, video should remain paused.");
+ run("internals.applicationWillEnterForeground()");
+ setTimeout(checkState, 100);
+ consoleWrite("");
+ break;
+ case "foreground":
+ testExpected("video.paused", true);
+ consoleWrite("");
+ testRunner.resetPageVisibility();
+ endTest();
+ break;
+ }
+ }
+
+ function playing(evt)
+ {
+ consoleWrite("<br>** Simulate switching the tab to background, video should pause.");
+ run("testRunner.setPageVisibility('hidden')");
+ setTimeout(checkState, 100);
+ state = "background";
+ consoleWrite("");
+ }
+
+ function canplaythrough(evt)
+ {
+ consoleWrite("");
+ run("video.play()");
+ }
+
+ function start()
+ {
+ if (!window.internals) {
+ failTest('This test requires window.internals.');
+ return;
+ }
+
+ findMediaElement();
+ video.src = "" "content/test");
+ waitForEvent('canplaythrough', canplaythrough);
+ waitForEvent('playing', playing);
+
+ run("internals.setMediaSessionRestrictions('video', 'BackgroundTabPlaybackRestricted')");
+ state = "foreground";
+ consoleWrite("");
+ }
+ </script>
+ </head>
+
+ <body _onload_="start()">
+ <video controls></video>
+ <p>Test tab with <video> moving to background when playback is not allowed in background.</p>
+ </body>
+</html>
Modified: branches/safari-600.1.4.15-branch/Source/WebCore/ChangeLog (180664 => 180665)
--- branches/safari-600.1.4.15-branch/Source/WebCore/ChangeLog 2015-02-26 07:25:05 UTC (rev 180664)
+++ branches/safari-600.1.4.15-branch/Source/WebCore/ChangeLog 2015-02-26 08:00:36 UTC (rev 180665)
@@ -1,3 +1,35 @@
+2015-02-25 Babak Shafiei <[email protected]>
+
+ Merge r180274.
+
+ 2015-02-18 Eric Carlson <[email protected]>
+
+ [iOS] pause video when a tab moves to the background on some devices
+ https://bugs.webkit.org/show_bug.cgi?id=141753
+ <rdar://problem/19814562>
+
+ Reviewed by Jer Noble.
+
+ Test: media/video-background-tab-playback.html
+
+ * platform/audio/MediaSession.cpp:
+ (WebCore::MediaSession::clientDataBufferingTimerFired): Pause video when the element becomes
+ hidden if the BackgroundTabPlaybackRestricted is set.
+
+ * platform/audio/MediaSessionManager.cpp:
+ (WebCore::MediaSessionManager::applicationWillEnterBackground): Rename BackgroundPlaybackNotPermitted
+ to BackgroundProcessPlaybackRestricted.
+ (WebCore::MediaSessionManager::applicationWillEnterForeground): Ditto.
+ * platform/audio/MediaSessionManager.h:
+
+ * platform/audio/ios/MediaSessionManagerIOS.mm:
+ (WebCore::MediaSessionManageriOS::resetRestrictions): Set BackgroundTabPlaybackRestricted on
+ devices with restricted memory. BackgroundPlaybackNotPermitted -> BackgroundProcessPlaybackRestricted.
+
+ * testing/Internals.cpp:
+ (WebCore::Internals::setMediaSessionRestrictions): Add support for BackgroundTabPlaybackRestricted.
+ BackgroundPlaybackNotPermitted -> BackgroundProcessPlaybackRestricted.
+
2015-02-24 Dean Jackson <[email protected]>
Merged r180588.
Modified: branches/safari-600.1.4.15-branch/Source/WebCore/platform/audio/MediaSession.cpp (180664 => 180665)
--- branches/safari-600.1.4.15-branch/Source/WebCore/platform/audio/MediaSession.cpp 2015-02-26 07:25:05 UTC (rev 180664)
+++ branches/safari-600.1.4.15-branch/Source/WebCore/platform/audio/MediaSession.cpp 2015-02-26 08:00:36 UTC (rev 180665)
@@ -172,7 +172,16 @@
void MediaSession::visibilityChanged()
{
+ LOG(Media, "MediaSession::visibilityChanged(%p)- visible = %s", this, m_client.elementIsHidden() ? "false" : "true");
+
updateClientDataBuffering();
+
+ if (m_state != Playing || !m_client.elementIsHidden())
+ return;
+
+ MediaSessionManager::SessionRestrictions restrictions = MediaSessionManager::sharedManager().restrictions(mediaType());
+ if ((restrictions & MediaSessionManager::BackgroundTabPlaybackRestricted) == MediaSessionManager::BackgroundTabPlaybackRestricted)
+ pauseSession();
}
void MediaSession::updateClientDataBuffering()
Modified: branches/safari-600.1.4.15-branch/Source/WebCore/platform/audio/MediaSessionManager.cpp (180664 => 180665)
--- branches/safari-600.1.4.15-branch/Source/WebCore/platform/audio/MediaSessionManager.cpp 2015-02-26 07:25:05 UTC (rev 180664)
+++ branches/safari-600.1.4.15-branch/Source/WebCore/platform/audio/MediaSessionManager.cpp 2015-02-26 08:00:36 UTC (rev 180665)
@@ -282,7 +282,7 @@
LOG(Media, "MediaSessionManager::applicationWillEnterBackground");
Vector<MediaSession*> sessions = m_sessions;
for (auto* session : sessions) {
- if (m_restrictions[session->mediaType()] & BackgroundPlaybackNotPermitted)
+ if (m_restrictions[session->mediaType()] & BackgroundProcessPlaybackRestricted)
session->beginInterruption(MediaSession::EnteringBackground);
}
}
@@ -292,7 +292,7 @@
LOG(Media, "MediaSessionManager::applicationWillEnterForeground");
Vector<MediaSession*> sessions = m_sessions;
for (auto* session : sessions) {
- if (m_restrictions[session->mediaType()] & BackgroundPlaybackNotPermitted)
+ if (m_restrictions[session->mediaType()] & BackgroundProcessPlaybackRestricted)
session->endInterruption(MediaSession::MayResumePlaying);
}
}
Modified: branches/safari-600.1.4.15-branch/Source/WebCore/platform/audio/MediaSessionManager.h (180664 => 180665)
--- branches/safari-600.1.4.15-branch/Source/WebCore/platform/audio/MediaSessionManager.h 2015-02-26 07:25:05 UTC (rev 180664)
+++ branches/safari-600.1.4.15-branch/Source/WebCore/platform/audio/MediaSessionManager.h 2015-02-26 08:00:36 UTC (rev 180665)
@@ -75,7 +75,8 @@
InlineVideoPlaybackRestricted = 1 << 1,
MetadataPreloadingNotPermitted = 1 << 2,
AutoPreloadingNotPermitted = 1 << 3,
- BackgroundPlaybackNotPermitted = 1 << 4,
+ BackgroundProcessPlaybackRestricted = 1 << 4,
+ BackgroundTabPlaybackRestricted = 1 << 5,
};
typedef unsigned SessionRestrictions;
Modified: branches/safari-600.1.4.15-branch/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm (180664 => 180665)
--- branches/safari-600.1.4.15-branch/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm 2015-02-26 07:25:05 UTC (rev 180664)
+++ branches/safari-600.1.4.15-branch/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm 2015-02-26 08:00:36 UTC (rev 180665)
@@ -32,6 +32,7 @@
#import "MediaPlayer.h"
#import "MediaSession.h"
#import "SoftLinking.h"
+#import "SystemMemory.h"
#import "WebCoreSystemInterface.h"
#import "WebCoreThreadRun.h"
#import <AVFoundation/AVAudioSession.h>
@@ -127,6 +128,8 @@
void MediaSessionManageriOS::resetRestrictions()
{
+ static const size_t systemMemoryRequiredForVideoInBackgroundTabs = 1024 * 1024 * 1024;
+
LOG(Media, "MediaSessionManageriOS::resetRestrictions");
MediaSessionManager::resetRestrictions();
@@ -135,14 +138,19 @@
if (deviceClass == wkDeviceClassiPhone || deviceClass == wkDeviceClassiPod)
addRestriction(MediaSession::Video, InlineVideoPlaybackRestricted);
+ if (systemTotalMemory() < systemMemoryRequiredForVideoInBackgroundTabs) {
+ LOG(Media, "MediaSessionManageriOS::resetRestrictions - restricting video in background tabs because system memory = %zul", systemTotalMemory());
+ addRestriction(MediaSession::Video, BackgroundTabPlaybackRestricted);
+ }
+
addRestriction(MediaSession::Video, ConcurrentPlaybackNotPermitted);
- addRestriction(MediaSession::Video, BackgroundPlaybackNotPermitted);
+ addRestriction(MediaSession::Video, BackgroundProcessPlaybackRestricted);
removeRestriction(MediaSession::Audio, ConcurrentPlaybackNotPermitted);
- removeRestriction(MediaSession::Audio, BackgroundPlaybackNotPermitted);
+ removeRestriction(MediaSession::Audio, BackgroundProcessPlaybackRestricted);
removeRestriction(MediaSession::WebAudio, ConcurrentPlaybackNotPermitted);
- removeRestriction(MediaSession::WebAudio, BackgroundPlaybackNotPermitted);
+ removeRestriction(MediaSession::WebAudio, BackgroundProcessPlaybackRestricted);
removeRestriction(MediaSession::Audio, MetadataPreloadingNotPermitted);
removeRestriction(MediaSession::Video, MetadataPreloadingNotPermitted);
Modified: branches/safari-600.1.4.15-branch/Source/WebCore/testing/Internals.cpp (180664 => 180665)
--- branches/safari-600.1.4.15-branch/Source/WebCore/testing/Internals.cpp 2015-02-26 07:25:05 UTC (rev 180664)
+++ branches/safari-600.1.4.15-branch/Source/WebCore/testing/Internals.cpp 2015-02-26 08:00:36 UTC (rev 180665)
@@ -2334,8 +2334,10 @@
restrictions += MediaSessionManager::MetadataPreloadingNotPermitted;
if (equalIgnoringCase(restrictionsString, "AutoPreloadingNotPermitted"))
restrictions += MediaSessionManager::AutoPreloadingNotPermitted;
- if (equalIgnoringCase(restrictionsString, "BackgroundPlaybackNotPermitted"))
- restrictions += MediaSessionManager::BackgroundPlaybackNotPermitted;
+ if (equalIgnoringCase(restrictionsString, "BackgroundProcessPlaybackRestricted"))
+ restrictions += MediaSessionManager::BackgroundProcessPlaybackRestricted;
+ if (equalIgnoringCase(restrictionsString, "BackgroundTabPlaybackRestricted"))
+ restrictions += MediaSessionManager::BackgroundTabPlaybackRestricted;
MediaSessionManager::sharedManager().addRestriction(mediaType, restrictions);
}