Title: [123386] trunk
Revision
123386
Author
jer.no...@apple.com
Date
2012-07-23 14:39:19 -0700 (Mon, 23 Jul 2012)

Log Message

MediaController.currentTime should be kept stable during script execution.
https://bugs.webkit.org/show_bug.cgi?id=88555

Reviewed by Eric Carlson.

Source/WebCore:

Test: media/media-controller-time-constant.html

To keep MediaController.currentTime stable, add a new m_position variable and
a new m_clearPositionTimer timer.  Both must be mutable variables as they will
be updated from within const functions.  Calls to currentTime() will result in
stable values until the next runloop iteration.

* html/MediaController.cpp:
(MediaController::MediaController):
(MediaController::currentTime):
(MediaController::setCurrentTime):
(MediaController::clearPositionTimerFired):
* html/MediaController.h:

LayoutTests:

* media/media-controller-time-constant-expected.txt: Added.
* media/media-controller-time-constant.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (123385 => 123386)


--- trunk/LayoutTests/ChangeLog	2012-07-23 21:38:06 UTC (rev 123385)
+++ trunk/LayoutTests/ChangeLog	2012-07-23 21:39:19 UTC (rev 123386)
@@ -1,3 +1,13 @@
+2012-06-12  Jer Noble  <jer.no...@apple.com>
+
+        MediaController.currentTime should be kept stable during script execution.
+        https://bugs.webkit.org/show_bug.cgi?id=88555
+
+        Reviewed by Eric Carlson.
+
+        * media/media-controller-time-constant-expected.txt: Added.
+        * media/media-controller-time-constant.html: Added.
+
 2012-07-23  Caio Marcelo de Oliveira Filho  <caio.olive...@openbossa.org>
 
         [Qt] dom/xhtml/level3/core rebaseline after new test fonts

Added: trunk/LayoutTests/media/media-controller-time-constant-expected.txt (0 => 123386)


--- trunk/LayoutTests/media/media-controller-time-constant-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/media/media-controller-time-constant-expected.txt	2012-07-23 21:39:19 UTC (rev 123386)
@@ -0,0 +1,11 @@
+This tests that currentTime is kept stable during script execution.
+RUN(controller = video.controller)
+EVENT(canplaythrough)
+RUN(video.play())
+RUN(controller.play())
+EVENT(playing)
+RUN(firstTime = controller.currentTime)
+RUN(secondTime = controller.currentTime)
+EXPECTED (firstTime - secondTime == '0') OK
+END OF TEST
+

Added: trunk/LayoutTests/media/media-controller-time-constant.html (0 => 123386)


--- trunk/LayoutTests/media/media-controller-time-constant.html	                        (rev 0)
+++ trunk/LayoutTests/media/media-controller-time-constant.html	2012-07-23 21:39:19 UTC (rev 123386)
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <script src=""
+        <script src=""
+
+        <script>
+        var controller;
+        var video;
+        var firstTime;
+        var secondTime;
+
+        function start() {
+            video = document.getElementById('video');
+            run('controller = video.controller');
+            controller.addEventListener('canplaythrough', canplaythrough, true);
+            var src = "" 'content/test');
+            video.src = ""
+        }
+        
+        function canplaythrough() {
+            consoleWrite("EVENT(canplaythrough)");
+            controller.removeEventListener('canplaythrough', canplaythrough, true);
+            run('video.play()');
+            controller.addEventListener('playing', playing, true);
+            run('controller.play()');
+        }
+        
+        function playing() { 
+            consoleWrite("EVENT(playing)");
+            controller.removeEventListener('playing', playing, true);
+            run('firstTime = controller.currentTime');
+            run('secondTime = controller.currentTime');
+            testExpected('firstTime - secondTime', 0);
+            endTest();
+        }
+        </script>
+    </head>
+    <body _onload_="start()">
+        <video id="video" mediaGroup="group" controls></video>
+        <div>This tests that currentTime is kept stable during script execution.</div>
+    </body>
+</html>
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (123385 => 123386)


--- trunk/Source/WebCore/ChangeLog	2012-07-23 21:38:06 UTC (rev 123385)
+++ trunk/Source/WebCore/ChangeLog	2012-07-23 21:39:19 UTC (rev 123386)
@@ -1,3 +1,24 @@
+2012-06-12  Jer Noble  <jer.no...@apple.com>
+
+        MediaController.currentTime should be kept stable during script execution.
+        https://bugs.webkit.org/show_bug.cgi?id=88555
+
+        Reviewed by Eric Carlson.
+
+        Test: media/media-controller-time-constant.html
+
+        To keep MediaController.currentTime stable, add a new m_position variable and 
+        a new m_clearPositionTimer timer.  Both must be mutable variables as they will
+        be updated from within const functions.  Calls to currentTime() will result in
+        stable values until the next runloop iteration.
+
+        * html/MediaController.cpp:
+        (MediaController::MediaController):
+        (MediaController::currentTime):
+        (MediaController::setCurrentTime):
+        (MediaController::clearPositionTimerFired):
+        * html/MediaController.h:
+
 2012-07-23  Huang Dongsung  <luxte...@company100.net>
 
         Destroy CSS decoded data more eagerly once they become dead caches.

Modified: trunk/Source/WebCore/html/MediaController.cpp (123385 => 123386)


--- trunk/Source/WebCore/html/MediaController.cpp	2012-07-23 21:38:06 UTC (rev 123385)
+++ trunk/Source/WebCore/html/MediaController.cpp	2012-07-23 21:39:19 UTC (rev 123386)
@@ -47,10 +47,12 @@
     : m_paused(false)
     , m_defaultPlaybackRate(1)
     , m_volume(1)
+    , m_position(MediaPlayer::invalidTime())
     , m_muted(false)
     , m_readyState(HAVE_NOTHING)
     , m_playbackState(WAITING)
     , m_asyncEventTimer(this, &MediaController::asyncEventTimerFired)
+    , m_clearPositionTimer(this, &MediaController::clearPositionTimerFired)
     , m_closedCaptionsVisible(false)
     , m_clock(Clock::create())
     , m_scriptExecutionContext(context)
@@ -143,8 +145,13 @@
     if (m_mediaElements.isEmpty())
         return 0;
 
-    // Some clocks may return times outside the range of [0..duration].
-    return max(0.0f, min(duration(), m_clock->currentTime()));
+    if (m_position == MediaPlayer::invalidTime()) {
+        // Some clocks may return times outside the range of [0..duration].
+        m_position = max(0.0f, min(duration(), m_clock->currentTime()));
+        m_clearPositionTimer.startOneShot(0);
+    }
+
+    return m_position;
 }
 
 void MediaController::setCurrentTime(float time, ExceptionCode& code)
@@ -493,6 +500,11 @@
         dispatchEvent(pendingEvents[index].release(), ec);
 }
 
+void MediaController::clearPositionTimerFired(Timer<MediaController>*)
+{
+    m_position = MediaPlayer::invalidTime();
+}
+
 bool MediaController::hasAudio() const
 {
     for (size_t index = 0; index < m_mediaElements.size(); ++index) {

Modified: trunk/Source/WebCore/html/MediaController.h (123385 => 123386)


--- trunk/Source/WebCore/html/MediaController.h	2012-07-23 21:38:06 UTC (rev 123385)
+++ trunk/Source/WebCore/html/MediaController.h	2012-07-23 21:39:19 UTC (rev 123386)
@@ -123,6 +123,7 @@
     void bringElementUpToSpeed(HTMLMediaElement*);
     void scheduleEvent(const AtomicString& eventName);
     void asyncEventTimerFired(Timer<MediaController>*);
+    void clearPositionTimerFired(Timer<MediaController>*);
     bool hasEnded() const;
 
     // EventTarget
@@ -140,11 +141,13 @@
     bool m_paused;
     float m_defaultPlaybackRate;
     float m_volume;
+    mutable float m_position;
     bool m_muted;
     ReadyState m_readyState;
     PlaybackState m_playbackState;
     Vector<RefPtr<Event> > m_pendingEvents;
     Timer<MediaController> m_asyncEventTimer;
+    mutable Timer<MediaController> m_clearPositionTimer;
     String m_mediaGroup;
     bool m_closedCaptionsVisible;
     PassRefPtr<Clock> m_clock;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to