Title: [189322] trunk/Source/WebCore
Revision
189322
Author
[email protected]
Date
2015-09-03 16:53:33 -0700 (Thu, 03 Sep 2015)

Log Message

[iOS] Playback does not pause when deselecting route and locking screen.
https://bugs.webkit.org/show_bug.cgi?id=148724

Reviewed by Eric Carlson.

When deselecting a route, the route change notification can be delayed for some amount
of time. If the screen is locked before the notification is fired, the PlatformMediaSessionManager
can refuse to pause the video when entering the background due to a wireless playback route
still being active.

When the media element transitions from having an active route to not having one (or vice versa),
re-run the interruption check. In order to correctly determine, when that occurs, whether
we are in an 'application background' state, cache that value to an ivar when handling
application{Will,Did}Enter{Background,Foreground}.

Because we only want to run this step during an actual transition between playing to a route ->
playing locally, cache the value of isPlayingToWirelessPlayback to another ivar, and only
inform the PlatformMediaSessionManager when that value actually changes.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::mediaPlayerCurrentPlaybackTargetIsWirelessChanged):
* platform/audio/PlatformMediaSession.cpp:
(WebCore::PlatformMediaSession::isPlayingToWirelessPlaybackTargetChanged): Set or clear m_isPlayingToWirelessPlaybackTarget.
* platform/audio/PlatformMediaSession.h:
(WebCore::PlatformMediaSession::isPlayingToWirelessPlaybackTarget): Simple getter.
* platform/audio/PlatformMediaSessionManager.cpp:
(WebCore::PlatformMediaSessionManager::applicationWillEnterBackground): Set m_isApplicationInBackground.
(WebCore::PlatformMediaSessionManager::applicationDidEnterBackground): Ditto.
(WebCore::PlatformMediaSessionManager::applicationWillEnterForeground): Clear m_isApplicationInBackground.
(WebCore::PlatformMediaSessionManager::sessionIsPlayingToWirelessPlaybackTargetChanged): Run interruption
    if application is in background.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (189321 => 189322)


--- trunk/Source/WebCore/ChangeLog	2015-09-03 23:49:09 UTC (rev 189321)
+++ trunk/Source/WebCore/ChangeLog	2015-09-03 23:53:33 UTC (rev 189322)
@@ -1,3 +1,37 @@
+2015-09-03  Jer Noble  <[email protected]>
+
+        [iOS] Playback does not pause when deselecting route and locking screen.
+        https://bugs.webkit.org/show_bug.cgi?id=148724
+
+        Reviewed by Eric Carlson.
+
+        When deselecting a route, the route change notification can be delayed for some amount
+        of time. If the screen is locked before the notification is fired, the PlatformMediaSessionManager
+        can refuse to pause the video when entering the background due to a wireless playback route
+        still being active.
+
+        When the media element transitions from having an active route to not having one (or vice versa),
+        re-run the interruption check. In order to correctly determine, when that occurs, whether
+        we are in an 'application background' state, cache that value to an ivar when handling
+        application{Will,Did}Enter{Background,Foreground}.
+
+        Because we only want to run this step during an actual transition between playing to a route ->
+        playing locally, cache the value of isPlayingToWirelessPlayback to another ivar, and only
+        inform the PlatformMediaSessionManager when that value actually changes.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::mediaPlayerCurrentPlaybackTargetIsWirelessChanged):
+        * platform/audio/PlatformMediaSession.cpp:
+        (WebCore::PlatformMediaSession::isPlayingToWirelessPlaybackTargetChanged): Set or clear m_isPlayingToWirelessPlaybackTarget.
+        * platform/audio/PlatformMediaSession.h:
+        (WebCore::PlatformMediaSession::isPlayingToWirelessPlaybackTarget): Simple getter.
+        * platform/audio/PlatformMediaSessionManager.cpp:
+        (WebCore::PlatformMediaSessionManager::applicationWillEnterBackground): Set m_isApplicationInBackground.
+        (WebCore::PlatformMediaSessionManager::applicationDidEnterBackground): Ditto.
+        (WebCore::PlatformMediaSessionManager::applicationWillEnterForeground): Clear m_isApplicationInBackground.
+        (WebCore::PlatformMediaSessionManager::sessionIsPlayingToWirelessPlaybackTargetChanged): Run interruption
+            if application is in background.
+
 2015-09-03  Brady Eidson  <[email protected]>
 
         Move SecurityOriginData from WK2 to WebCore.

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (189321 => 189322)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2015-09-03 23:49:09 UTC (rev 189321)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2015-09-03 23:53:33 UTC (rev 189322)
@@ -5031,9 +5031,10 @@
 void HTMLMediaElement::mediaPlayerCurrentPlaybackTargetIsWirelessChanged(MediaPlayer*)
 {
     LOG(Media, "HTMLMediaElement::mediaPlayerCurrentPlaybackTargetIsWirelessChanged(%p) - webkitCurrentPlaybackTargetIsWireless = %s", this, boolString(webkitCurrentPlaybackTargetIsWireless()));
-
+    ASSERT(m_player);
     configureMediaControls();
     scheduleEvent(eventNames().webkitcurrentplaybacktargetiswirelesschangedEvent);
+    m_mediaSession->isPlayingToWirelessPlaybackTargetChanged(m_player->isCurrentPlaybackTargetWireless());
     updateMediaState(UpdateMediaState::Asynchronously);
 }
 

Modified: trunk/Source/WebCore/platform/audio/PlatformMediaSession.cpp (189321 => 189322)


--- trunk/Source/WebCore/platform/audio/PlatformMediaSession.cpp	2015-09-03 23:49:09 UTC (rev 189321)
+++ trunk/Source/WebCore/platform/audio/PlatformMediaSession.cpp	2015-09-03 23:53:33 UTC (rev 189322)
@@ -255,6 +255,15 @@
     return m_client.elementIsHidden();
 }
 
+void PlatformMediaSession::isPlayingToWirelessPlaybackTargetChanged(bool isWireless)
+{
+    if (isWireless == m_isPlayingToWirelessPlaybackTarget)
+        return;
+
+    m_isPlayingToWirelessPlaybackTarget = isWireless;
+    PlatformMediaSessionManager::sharedManager().sessionIsPlayingToWirelessPlaybackTargetChanged(*this);
+}
+
 PlatformMediaSession::DisplayType PlatformMediaSession::displayType() const
 {
     return m_client.displayType();

Modified: trunk/Source/WebCore/platform/audio/PlatformMediaSession.h (189321 => 189322)


--- trunk/Source/WebCore/platform/audio/PlatformMediaSession.h	2015-09-03 23:49:09 UTC (rev 189321)
+++ trunk/Source/WebCore/platform/audio/PlatformMediaSession.h	2015-09-03 23:53:33 UTC (rev 189322)
@@ -125,7 +125,8 @@
     bool isHidden() const;
 
     virtual bool canPlayToWirelessPlaybackTarget() const { return false; }
-    virtual bool isPlayingToWirelessPlaybackTarget() const { return false; }
+    virtual bool isPlayingToWirelessPlaybackTarget() const { return m_isPlayingToWirelessPlaybackTarget; }
+    void isPlayingToWirelessPlaybackTargetChanged(bool);
 
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
     // MediaPlaybackTargetClient
@@ -151,6 +152,7 @@
     State m_stateToRestore;
     int m_interruptionCount { 0 };
     bool m_notifyingClient;
+    bool m_isPlayingToWirelessPlaybackTarget { false };
 
     friend class PlatformMediaSessionManager;
 };

Modified: trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp (189321 => 189322)


--- trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp	2015-09-03 23:49:09 UTC (rev 189321)
+++ trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp	2015-09-03 23:53:33 UTC (rev 189322)
@@ -275,6 +275,12 @@
 void PlatformMediaSessionManager::applicationWillEnterBackground() const
 {
     LOG(Media, "PlatformMediaSessionManager::applicationWillEnterBackground");
+
+    if (m_isApplicationInBackground)
+        return;
+
+    m_isApplicationInBackground = true;
+    
     Vector<PlatformMediaSession*> sessions = m_sessions;
     for (auto* session : sessions) {
         if (m_restrictions[session->mediaType()] & BackgroundProcessPlaybackRestricted)
@@ -299,6 +305,12 @@
 void PlatformMediaSessionManager::applicationWillEnterForeground() const
 {
     LOG(Media, "PlatformMediaSessionManager::applicationWillEnterForeground");
+
+    if (!m_isApplicationInBackground)
+        return;
+
+    m_isApplicationInBackground = false;
+
     Vector<PlatformMediaSession*> sessions = m_sessions;
     for (auto* session : sessions) {
         if (m_restrictions[session->mediaType()] & BackgroundProcessPlaybackRestricted)
@@ -306,6 +318,15 @@
     }
 }
 
+void PlatformMediaSessionManager::sessionIsPlayingToWirelessPlaybackTargetChanged(PlatformMediaSession& session)
+{
+    if (!m_isApplicationInBackground || !(m_restrictions[session.mediaType()] & BackgroundProcessPlaybackRestricted))
+        return;
+
+    if (session.state() != PlatformMediaSession::Interrupted && session.shouldDoInterruption(PlatformMediaSession::EnteringBackground))
+        session.doInterruption();
+}
+
 #if !PLATFORM(COCOA)
 void PlatformMediaSessionManager::updateSessionState()
 {

Modified: trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.h (189321 => 189322)


--- trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.h	2015-09-03 23:49:09 UTC (rev 189321)
+++ trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.h	2015-09-03 23:53:33 UTC (rev 189322)
@@ -88,6 +88,8 @@
     void setCurrentSession(PlatformMediaSession&);
     PlatformMediaSession* currentSession();
 
+    void sessionIsPlayingToWirelessPlaybackTargetChanged(PlatformMediaSession&);
+
 protected:
     friend class PlatformMediaSession;
     explicit PlatformMediaSessionManager();
@@ -126,6 +128,7 @@
 #endif
 
     bool m_interrupted { false };
+    mutable bool m_isApplicationInBackground { false };
 };
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to