Title: [119938] trunk/Source/WebCore
Revision
119938
Author
jer.no...@apple.com
Date
2012-06-10 11:09:52 -0700 (Sun, 10 Jun 2012)

Log Message

WebCore should use a single definition of an invalid media time.
https://bugs.webkit.org/show_bug.cgi?id=88572

Reviewed by Eric Carlson.

No new tests; no change in functionality, so covered by existing tests.

Add a new, universal definition for an invalid media time:
* platform/graphics/MediaPlayer.h:
(WebCore::MediaPlayer::invalidTime):

Use this new definition instead of the hodge podge of (identical) local
definitions for an invalid media time:
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::HTMLMediaElement):
(WebCore::HTMLMediaElement::invalidateCachedTime):
(WebCore::HTMLMediaElement::currentTime):
(WebCore::HTMLMediaElement::initialTime):
(WebCore::HTMLMediaElement::playbackProgressTimerFired):
(WebCore::HTMLMediaElement::prepareMediaFragmentURI):
(WebCore::HTMLMediaElement::applyMediaFragmentURI):
* html/MediaFragmentURIParser.cpp:
(WebCore::MediaFragmentURIParser::invalidTimeValue):
(WebCore::MediaFragmentURIParser::MediaFragmentURIParser):
(WebCore::MediaFragmentURIParser::startTime):
(WebCore::MediaFragmentURIParser::endTime):
(WebCore::MediaFragmentURIParser::parseTimeFragment):
* platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp:
(WebCore::MediaPlayerPrivateAVFoundation::MediaPlayerPrivateAVFoundation):
(WebCore::MediaPlayerPrivateAVFoundation::duration):
(WebCore::MediaPlayerPrivateAVFoundation::seeking):
(WebCore::MediaPlayerPrivateAVFoundation::seekCompleted):
(WebCore::MediaPlayerPrivateAVFoundation::invalidateCachedDuration):
* platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h:
(MediaPlayerPrivateAVFoundation):
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::platformDuration):
* platform/graphics/mac/MediaPlayerPrivateQTKit.mm:
(WebCore::MediaPlayerPrivateQTKit::duration):
(WebCore::MediaPlayerPrivateQTKit::updateStates):
(WebCore::MediaPlayerPrivateQTKit::timeChanged):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (119937 => 119938)


--- trunk/Source/WebCore/ChangeLog	2012-06-10 17:15:55 UTC (rev 119937)
+++ trunk/Source/WebCore/ChangeLog	2012-06-10 18:09:52 UTC (rev 119938)
@@ -1,3 +1,47 @@
+2012-06-07  Jer Noble  <jer.no...@apple.com>
+
+        WebCore should use a single definition of an invalid media time.
+        https://bugs.webkit.org/show_bug.cgi?id=88572
+
+        Reviewed by Eric Carlson.
+
+        No new tests; no change in functionality, so covered by existing tests.
+
+        Add a new, universal definition for an invalid media time:
+        * platform/graphics/MediaPlayer.h:
+        (WebCore::MediaPlayer::invalidTime):
+
+        Use this new definition instead of the hodge podge of (identical) local
+        definitions for an invalid media time:
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::HTMLMediaElement):
+        (WebCore::HTMLMediaElement::invalidateCachedTime):
+        (WebCore::HTMLMediaElement::currentTime):
+        (WebCore::HTMLMediaElement::initialTime):
+        (WebCore::HTMLMediaElement::playbackProgressTimerFired):
+        (WebCore::HTMLMediaElement::prepareMediaFragmentURI):
+        (WebCore::HTMLMediaElement::applyMediaFragmentURI):
+        * html/MediaFragmentURIParser.cpp:
+        (WebCore::MediaFragmentURIParser::invalidTimeValue):
+        (WebCore::MediaFragmentURIParser::MediaFragmentURIParser):
+        (WebCore::MediaFragmentURIParser::startTime):
+        (WebCore::MediaFragmentURIParser::endTime):
+        (WebCore::MediaFragmentURIParser::parseTimeFragment):
+        * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp:
+        (WebCore::MediaPlayerPrivateAVFoundation::MediaPlayerPrivateAVFoundation):
+        (WebCore::MediaPlayerPrivateAVFoundation::duration):
+        (WebCore::MediaPlayerPrivateAVFoundation::seeking):
+        (WebCore::MediaPlayerPrivateAVFoundation::seekCompleted):
+        (WebCore::MediaPlayerPrivateAVFoundation::invalidateCachedDuration):
+        * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h:
+        (MediaPlayerPrivateAVFoundation):
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::platformDuration):
+        * platform/graphics/mac/MediaPlayerPrivateQTKit.mm:
+        (WebCore::MediaPlayerPrivateQTKit::duration):
+        (WebCore::MediaPlayerPrivateQTKit::updateStates):
+        (WebCore::MediaPlayerPrivateQTKit::timeChanged):
+
 2012-06-10  Darin Adler  <da...@apple.com>
 
         Remove unneeded callRemovedLastRef function from TreeShared refactoring

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (119937 => 119938)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2012-06-10 17:15:55 UTC (rev 119937)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2012-06-10 18:09:52 UTC (rev 119938)
@@ -143,8 +143,6 @@
 #define LOG_CACHED_TIME_WARNINGS 0
 #endif
 
-static const float invalidMediaTime = -1;
-
 #if ENABLE(MEDIA_SOURCE)
 // URL protocol used to signal that the media source API is being used.
 static const char* mediaSourceURLProtocol = "x-media-source";
@@ -224,11 +222,11 @@
 #if ENABLE(MEDIA_SOURCE)      
     , m_sourceState(SOURCE_CLOSED)
 #endif
-    , m_cachedTime(invalidMediaTime)
+    , m_cachedTime(MediaPlayer::invalidTime())
     , m_cachedTimeWallClockUpdateTime(0)
     , m_minimumWallClockTimeToCacheMediaTime(0)
-    , m_fragmentStartTime(invalidMediaTime)
-    , m_fragmentEndTime(invalidMediaTime)
+    , m_fragmentStartTime(MediaPlayer::invalidTime())
+    , m_fragmentEndTime(MediaPlayer::invalidTime())
     , m_pendingLoadFlags(0)
     , m_playing(false)
     , m_isWaitingUntilMediaCanStart(false)
@@ -2048,7 +2046,7 @@
     static const double minimumTimePlayingBeforeCacheSnapshot = 0.5;
 
     m_minimumWallClockTimeToCacheMediaTime = WTF::currentTime() + minimumTimePlayingBeforeCacheSnapshot;
-    m_cachedTime = invalidMediaTime;
+    m_cachedTime = MediaPlayer::invalidTime();
 }
 
 // playback state
@@ -2066,7 +2064,7 @@
         return m_lastSeekTime;
     }
 
-    if (m_cachedTime != invalidMediaTime && m_paused) {
+    if (m_cachedTime != MediaPlayer::invalidTime() && m_paused) {
 #if LOG_CACHED_TIME_WARNINGS
         float delta = m_cachedTime - m_player->currentTime();
         if (delta > minCachedDeltaForWarning)
@@ -2079,7 +2077,7 @@
     double now = WTF::currentTime();
     double maximumDurationToCacheMediaTime = m_player->maximumDurationToCacheMediaTime();
 
-    if (maximumDurationToCacheMediaTime && m_cachedTime != invalidMediaTime && !m_paused && now > m_minimumWallClockTimeToCacheMediaTime) {
+    if (maximumDurationToCacheMediaTime && m_cachedTime != MediaPlayer::invalidTime() && !m_paused && now > m_minimumWallClockTimeToCacheMediaTime) {
         double wallClockDelta = now - m_cachedTimeWallClockUpdateTime;
 
         // Not too soon, use the cached time only if it hasn't expired.
@@ -2096,7 +2094,7 @@
     }
 
 #if LOG_CACHED_TIME_WARNINGS
-    if (maximumDurationToCacheMediaTime && now > m_minimumWallClockTimeToCacheMediaTime && m_cachedTime != invalidMediaTime) {
+    if (maximumDurationToCacheMediaTime && now > m_minimumWallClockTimeToCacheMediaTime && m_cachedTime != MediaPlayer::invalidTime()) {
         double wallClockDelta = now - m_cachedTimeWallClockUpdateTime;
         float delta = m_cachedTime + (m_playbackRate * wallClockDelta) - m_player->currentTime();
         LOG(Media, "HTMLMediaElement::currentTime - cached time was %f seconds off of media time when it expired", delta);
@@ -2126,7 +2124,7 @@
 
 double HTMLMediaElement::initialTime() const
 {
-    if (m_fragmentStartTime != invalidMediaTime)
+    if (m_fragmentStartTime != MediaPlayer::invalidTime())
         return m_fragmentStartTime;
 
     if (!m_player)
@@ -2726,8 +2724,8 @@
 {
     ASSERT(m_player);
 
-    if (m_fragmentEndTime != invalidMediaTime && currentTime() >= m_fragmentEndTime && m_playbackRate > 0) {
-        m_fragmentEndTime = invalidMediaTime;
+    if (m_fragmentEndTime != MediaPlayer::invalidTime() && currentTime() >= m_fragmentEndTime && m_playbackRate > 0) {
+        m_fragmentEndTime = MediaPlayer::invalidTime();
         if (!m_mediaController && !m_paused) {
             // changes paused to true and fires a simple event named pause at the media element.
             pauseInternal();
@@ -4409,7 +4407,7 @@
         if (m_fragmentStartTime > dur)
             m_fragmentStartTime = dur;
     } else
-        m_fragmentStartTime = invalidMediaTime;
+        m_fragmentStartTime = MediaPlayer::invalidTime();
     
     double end = fragmentParser.endTime();
     if (end != MediaFragmentURIParser::invalidTimeValue() && end > 0 && end > m_fragmentStartTime) {
@@ -4417,15 +4415,15 @@
         if (m_fragmentEndTime > dur)
             m_fragmentEndTime = dur;
     } else
-        m_fragmentEndTime = invalidMediaTime;
+        m_fragmentEndTime = MediaPlayer::invalidTime();
     
-    if (m_fragmentStartTime != invalidMediaTime && m_readyState < HAVE_FUTURE_DATA)
+    if (m_fragmentStartTime != MediaPlayer::invalidTime() && m_readyState < HAVE_FUTURE_DATA)
         prepareToPlay();
 }
 
 void HTMLMediaElement::applyMediaFragmentURI()
 {
-    if (m_fragmentStartTime != invalidMediaTime) {
+    if (m_fragmentStartTime != MediaPlayer::invalidTime()) {
         ExceptionCode ignoredException;
         m_sentEndEvent = false;
         seek(m_fragmentStartTime, ignoredException);

Modified: trunk/Source/WebCore/html/MediaFragmentURIParser.cpp (119937 => 119938)


--- trunk/Source/WebCore/html/MediaFragmentURIParser.cpp	2012-06-10 17:15:55 UTC (rev 119937)
+++ trunk/Source/WebCore/html/MediaFragmentURIParser.cpp	2012-06-10 18:09:52 UTC (rev 119938)
@@ -30,6 +30,7 @@
 #include "MediaFragmentURIParser.h"
 
 #include "HTMLElement.h"
+#include "MediaPlayer.h"
 #include "ProcessingInstruction.h"
 #include "SegmentedString.h"
 #include "Text.h"
@@ -41,7 +42,6 @@
 
 const int secondsPerHour = 3600;
 const int secondsPerMinute = 60;
-const double invalidMediaTime = -1;
 const unsigned nptIdentiferLength = 4; // "npt:"
 
 static String collectDigits(const LChar* input, unsigned length, unsigned& position)
@@ -72,21 +72,21 @@
 
 double MediaFragmentURIParser::invalidTimeValue()
 {
-    return invalidMediaTime;
+    return MediaPlayer::invalidTime();
 }
 
 MediaFragmentURIParser::MediaFragmentURIParser(const KURL& url)
     : m_url(url)
     , m_timeFormat(None)
-    , m_startTime(invalidMediaTime)
-    , m_endTime(invalidMediaTime)
+    , m_startTime(MediaPlayer::invalidTime())
+    , m_endTime(MediaPlayer::invalidTime())
 {
 }
 
 double MediaFragmentURIParser::startTime()
 {
     if (!m_url.isValid())
-        return invalidMediaTime;
+        return MediaPlayer::invalidTime();
     if (m_timeFormat == None)
         parseTimeFragment();
     return m_startTime;
@@ -95,7 +95,7 @@
 double MediaFragmentURIParser::endTime()
 {
     if (!m_url.isValid())
-        return invalidMediaTime;
+        return MediaPlayer::invalidTime();
     if (m_timeFormat == None)
         parseTimeFragment();
     return m_endTime;
@@ -184,8 +184,8 @@
         // in the same format. The format is specified by name, followed by a colon (:), with npt: being
         // the default.
         
-        double start = invalidMediaTime;
-        double end = invalidMediaTime;
+        double start = MediaPlayer::invalidTime();
+        double end = MediaPlayer::invalidTime();
         if (parseNPTFragment(fragment.second.characters8(), fragment.second.length(), start, end)) {
             m_startTime = start;
             m_endTime = end;

Modified: trunk/Source/WebCore/platform/graphics/MediaPlayer.h (119937 => 119938)


--- trunk/Source/WebCore/platform/graphics/MediaPlayer.h	2012-06-10 17:15:55 UTC (rev 119937)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayer.h	2012-06-10 18:09:52 UTC (rev 119938)
@@ -263,6 +263,7 @@
     bool paused() const;
     bool seeking() const;
 
+    static float invalidTime() { return -1.0f;}
     float duration() const;
     float currentTime() const;
     void seek(float time);

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp (119937 => 119938)


--- trunk/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp	2012-06-10 17:15:55 UTC (rev 119937)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp	2012-06-10 18:09:52 UTC (rev 119938)
@@ -55,10 +55,10 @@
     , m_preload(MediaPlayer::Auto)
     , m_cachedMaxTimeLoaded(0)
     , m_cachedMaxTimeSeekable(0)
-    , m_cachedDuration(invalidTime())
-    , m_reportedDuration(invalidTime())
-    , m_maxTimeLoadedAtLastDidLoadingProgress(invalidTime())
-    , m_seekTo(invalidTime())
+    , m_cachedDuration(MediaPlayer::invalidTime())
+    , m_reportedDuration(MediaPlayer::invalidTime())
+    , m_maxTimeLoadedAtLastDidLoadingProgress(MediaPlayer::invalidTime())
+    , m_seekTo(MediaPlayer::invalidTime())
     , m_requestedRate(1)
     , m_delayCallbacks(0)
     , m_mainThreadCallPending(false)
@@ -234,11 +234,11 @@
 
 float MediaPlayerPrivateAVFoundation::duration() const
 {
-    if (m_cachedDuration != invalidTime())
+    if (m_cachedDuration != MediaPlayer::invalidTime())
         return m_cachedDuration;
 
     float duration = platformDuration();
-    if (!duration || duration == invalidTime())
+    if (!duration || duration == MediaPlayer::invalidTime())
         return 0;
 
     m_cachedDuration = duration;
@@ -284,7 +284,7 @@
     if (!metaDataAvailable())
         return false;
 
-    return m_seekTo != invalidTime();
+    return m_seekTo != MediaPlayer::invalidTime();
 }
 
 IntSize MediaPlayerPrivateAVFoundation::naturalSize() const
@@ -565,7 +565,7 @@
     LOG(Media, "MediaPlayerPrivateAVFoundation::seekCompleted(%p) - finished = %d", this, finished);
     UNUSED_PARAM(finished);
     
-    m_seekTo = invalidTime();
+    m_seekTo = MediaPlayer::invalidTime();
     updateStates();
     m_player->timeChanged();
 }
@@ -586,13 +586,13 @@
 {
     LOG(Media, "MediaPlayerPrivateAVFoundation::invalidateCachedDuration(%p)", this);
     
-    m_cachedDuration = invalidTime();
+    m_cachedDuration = MediaPlayer::invalidTime();
 
     // For some media files, reported duration is estimated and updated as media is loaded
     // so report duration changed when the estimate is upated.
     float duration = this->duration();
     if (duration != m_reportedDuration) {
-        if (m_reportedDuration != invalidTime())
+        if (m_reportedDuration != MediaPlayer::invalidTime())
             m_player->durationChanged();
         m_reportedDuration = duration;
     }

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h (119937 => 119938)


--- trunk/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h	2012-06-10 17:15:55 UTC (rev 119937)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h	2012-06-10 18:09:52 UTC (rev 119938)
@@ -237,7 +237,6 @@
 
     static void mainThreadCallback(void*);
     
-    float invalidTime() const { return -1.0f; }
     void invalidateCachedDuration();
 
     const String& assetURL() const { return m_assetURL; }

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm (119937 => 119938)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm	2012-06-10 17:15:55 UTC (rev 119937)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm	2012-06-10 18:09:52 UTC (rev 119938)
@@ -122,8 +122,6 @@
 }
 #endif
 
-static const float invalidTime = -1.0f;
-
 PassOwnPtr<MediaPlayerPrivateInterface> MediaPlayerPrivateAVFoundationObjC::create(MediaPlayer* player)
 { 
     return adoptPtr(new MediaPlayerPrivateAVFoundationObjC(player));
@@ -416,7 +414,7 @@
     // Do not ask the asset for duration before it has been loaded or it will fetch the
     // answer synchronously.
     if (!m_avAsset || assetStatus() < MediaPlayerAVAssetStatusLoaded)
-         return invalidTime();
+         return MediaPlayer::invalidTime();
     
     CMTime cmDuration;
     
@@ -436,8 +434,8 @@
             return numeric_limits<float>::infinity();
     }
 
-    LOG(Media, "MediaPlayerPrivateAVFoundationObjC::platformDuration(%p) - invalid duration, returning %.0f", this, invalidTime());
-    return invalidTime();
+    LOG(Media, "MediaPlayerPrivateAVFoundationObjC::platformDuration(%p) - invalid duration, returning %.0f", this, MediaPlayer::invalidTime());
+    return MediaPlayer::invalidTime();
 }
 
 float MediaPlayerPrivateAVFoundationObjC::currentTime() const

Modified: trunk/Source/WebCore/platform/graphics/mac/MediaPlayerPrivateQTKit.mm (119937 => 119938)


--- trunk/Source/WebCore/platform/graphics/mac/MediaPlayerPrivateQTKit.mm	2012-06-10 17:15:55 UTC (rev 119937)
+++ trunk/Source/WebCore/platform/graphics/mac/MediaPlayerPrivateQTKit.mm	2012-06-10 18:09:52 UTC (rev 119938)
@@ -717,7 +717,7 @@
     if (!metaDataAvailable())
         return 0;
 
-    if (m_cachedDuration != -1.0f)
+    if (m_cachedDuration != MediaPlayer::invalidTime())
         return m_cachedDuration;
 
     QTTime time = [m_qtMovie.get() duration];
@@ -1049,9 +1049,9 @@
     }
     
     // If this movie is reloading and we mean to restore the current time/rate, this might be the right time to do it.
-    if (loadState >= QTMovieLoadStateLoaded && oldNetworkState < MediaPlayer::Loaded && m_timeToRestore != -1.0f) {
+    if (loadState >= QTMovieLoadStateLoaded && oldNetworkState < MediaPlayer::Loaded && m_timeToRestore != MediaPlayer::invalidTime()) {
         QTTime qttime = createQTTime(m_timeToRestore);
-        m_timeToRestore = -1.0f;
+        m_timeToRestore = MediaPlayer::invalidTime();
             
         // Disable event callbacks from setCurrentTime for restoring time in a recreated video
         [m_objcObserver.get() setDelayCallbacks:YES];
@@ -1128,7 +1128,7 @@
     if (loadState >= QTMovieLoadStateLoaded) {
         float dur = duration();
         if (dur != m_reportedDuration) {
-            if (m_reportedDuration != -1.0f)
+            if (m_reportedDuration != MediaPlayer::invalidTime())
                 m_player->durationChanged();
             m_reportedDuration = dur;
         }
@@ -1167,7 +1167,7 @@
     if (m_seekTo != -1)
         m_seekTo = currentTime();
 
-    m_timeToRestore = -1.0f;
+    m_timeToRestore = MediaPlayer::invalidTime();
     updateStates();
     m_player->timeChanged();
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to