[iOS] don't get out of sync when interrupt/resume calls are not balanced
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Feb 2015 15:47:51 +0000 (15:47 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Feb 2015 15:47:51 +0000 (15:47 +0000)
https://bugs.webkit.org/show_bug.cgi?id=141310

Reviewed by Jer Noble.

Source/WebCore:

No new tests, updated media/video-interruption-with-resume-allowing-play.html.

* platform/audio/MediaSession.cpp:
(WebCore::MediaSession::beginInterruption): Count interruptions.
(WebCore::MediaSession::endInterruption): Ignore calls when m_interruptionCount is already zero.
* platform/audio/MediaSession.h:

LayoutTests:

* media/video-interruption-with-resume-allowing-play-expected.txt:
* media/video-interruption-with-resume-allowing-play.html: Updated to test unbalanced calls
    to begin/end interruption.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@179869 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/media/video-interruption-with-resume-allowing-play-expected.txt
LayoutTests/media/video-interruption-with-resume-allowing-play.html
Source/WebCore/ChangeLog
Source/WebCore/platform/audio/MediaSession.cpp
Source/WebCore/platform/audio/MediaSession.h

index 2adbc50..9492f9b 100644 (file)
@@ -1,3 +1,14 @@
+2015-02-10  Eric Carlson  <eric.carlson@apple.com>
+
+        [iOS] don't get out of sync when interrupt/resume calls are not balanced
+        https://bugs.webkit.org/show_bug.cgi?id=141310
+
+        Reviewed by Jer Noble.
+
+        * media/video-interruption-with-resume-allowing-play-expected.txt:
+        * media/video-interruption-with-resume-allowing-play.html: Updated to test unbalanced calls 
+            to begin/end interruption.
+
 2015-02-10  Marcos Chavarría Teijeiro  <chavarria1991@gmail.com>
 
         Unreviewed GTK Gardening.
index 747c775..9518a46 100644 (file)
@@ -15,5 +15,15 @@ RUN(internals.endMediaSessionInterruption('MayResumePlaying'))
 EVENT(playing)
 EXPECTED (video.paused == 'false') OK
 
+EXPECTED (video.paused == 'false') OK
+RUN(internals.beginMediaSessionInterruption())
+
+100ms timer fired...
+EXPECTED (video.paused == 'true') OK
+RUN(internals.endMediaSessionInterruption('MayResumePlaying'))
+
+EVENT(playing)
+EXPECTED (video.paused == 'false') OK
+
 END OF TEST
 
index 85213f0..6b53702 100644 (file)
@@ -4,6 +4,7 @@
         <script src=video-test.js></script>
         <script>
             var state = 0;
+            var resumeCount = 0;
 
             function checkState()
             {
@@ -15,6 +16,7 @@
                     setTimeout(checkState, 100);
                     consoleWrite("");
                     break;
+
                 case "interrupted":
                     consoleWrite("100ms timer fired...");
                     testExpected("video.paused", true);
                     run("internals.endMediaSessionInterruption('MayResumePlaying')");
                     consoleWrite("");
                     break;
+
                 case "resuming":
                     testExpected("video.paused", false);
                     consoleWrite("");
-                    endTest();
+                    if (++resumeCount == 2)
+                        endTest();
+                    state = "playing";
+                    setTimeout(checkState, 100);
                     break;
                 }
             }
index a708a4b..149005e 100644 (file)
@@ -1,3 +1,17 @@
+2015-02-10  Eric Carlson  <eric.carlson@apple.com>
+
+        [iOS] don't get out of sync when interrupt/resume calls are not balanced
+        https://bugs.webkit.org/show_bug.cgi?id=141310
+
+        Reviewed by Jer Noble.
+
+        No new tests, updated media/video-interruption-with-resume-allowing-play.html.
+
+        * platform/audio/MediaSession.cpp:
+        (WebCore::MediaSession::beginInterruption): Count interruptions.
+        (WebCore::MediaSession::endInterruption): Ignore calls when m_interruptionCount is already zero.
+        * platform/audio/MediaSession.h:
+
 2015-02-10  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] GMutexLocker build issue
index c78b921..c40fcac 100644 (file)
@@ -81,9 +81,9 @@ void MediaSession::setState(State state)
 
 void MediaSession::beginInterruption(InterruptionType type)
 {
-    LOG(Media, "MediaSession::beginInterruption(%p), state = %s", this, stateName(m_state));
+    LOG(Media, "MediaSession::beginInterruption(%p), state = %s, interruption count = %i", this, stateName(m_state), m_interruptionCount);
 
-    if (type == EnteringBackground && client().overrideBackgroundPlaybackRestriction())
+    if (++m_interruptionCount > 1 || (type == EnteringBackground && client().overrideBackgroundPlaybackRestriction()))
         return;
 
     m_stateToRestore = state();
@@ -95,7 +95,15 @@ void MediaSession::beginInterruption(InterruptionType type)
 
 void MediaSession::endInterruption(EndInterruptionFlags flags)
 {
-    LOG(Media, "MediaSession::endInterruption(%p) - flags = %i, stateToRestore = %s", this, (int)flags, stateName(m_stateToRestore));
+    LOG(Media, "MediaSession::endInterruption(%p) - flags = %i, stateToRestore = %s, interruption count = %i", this, (int)flags, stateName(m_stateToRestore), m_interruptionCount);
+
+    if (!m_interruptionCount) {
+        LOG(Media, "MediaSession::endInterruption(%p) - !! ignoring spurious interruption end !!", this);
+        return;
+    }
+
+    if (--m_interruptionCount)
+        return;
 
     State stateToRestore = m_stateToRestore;
     m_stateToRestore = Idle;
index 9954562..3d54c46 100644 (file)
@@ -122,6 +122,7 @@ private:
     Timer m_clientDataBufferingTimer;
     State m_state;
     State m_stateToRestore;
+    int m_interruptionCount { 0 };
     bool m_notifyingClient;
 };