| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights
reserved. | 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights
reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 1885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1896 startDeferredLoad(); | 1896 startDeferredLoad(); |
| 1897 } | 1897 } |
| 1898 | 1898 |
| 1899 void HTMLMediaElement::seek(double time, ExceptionState& exceptionState) | 1899 void HTMLMediaElement::seek(double time, ExceptionState& exceptionState) |
| 1900 { | 1900 { |
| 1901 WTF_LOG(Media, "HTMLMediaElement::seek(%f)", time); | 1901 WTF_LOG(Media, "HTMLMediaElement::seek(%f)", time); |
| 1902 | 1902 |
| 1903 // 4.8.10.9 Seeking | 1903 // 4.8.10.9 Seeking |
| 1904 | 1904 |
| 1905 // 1 - If the media element's readyState is HAVE_NOTHING, then raise an Inva
lidStateError exception. | 1905 // 1 - If the media element's readyState is HAVE_NOTHING, then raise an Inva
lidStateError exception. |
| 1906 if (m_readyState == HAVE_NOTHING || !m_player) { | 1906 if (m_readyState == HAVE_NOTHING) { |
| 1907 exceptionState.throwDOMException(InvalidStateError, "The element's ready
State is HAVE_NOTHING."); | 1907 exceptionState.throwDOMException(InvalidStateError, "The element's ready
State is HAVE_NOTHING."); |
| 1908 return; | 1908 return; |
| 1909 } | 1909 } |
| 1910 | 1910 |
| 1911 // If the media engine has been told to postpone loading data, let it go ahe
ad now. | 1911 // If the media engine has been told to postpone loading data, let it go ahe
ad now. |
| 1912 if (m_preload < MediaPlayer::Auto && m_readyState < HAVE_FUTURE_DATA) | 1912 if (m_preload < MediaPlayer::Auto && m_readyState < HAVE_FUTURE_DATA) |
| 1913 prepareToPlay(); | 1913 prepareToPlay(); |
| 1914 | 1914 |
| 1915 // Get the current time before setting m_seeking, m_lastSeekTime is returned
once it is set. | 1915 // Get the current time before setting m_seeking, m_lastSeekTime is returned
once it is set. |
| 1916 refreshCachedTime(); | 1916 refreshCachedTime(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1974 if (m_lastSeekTime < now) | 1974 if (m_lastSeekTime < now) |
| 1975 addPlayedRange(m_lastSeekTime, now); | 1975 addPlayedRange(m_lastSeekTime, now); |
| 1976 } | 1976 } |
| 1977 m_lastSeekTime = time; | 1977 m_lastSeekTime = time; |
| 1978 m_sentEndEvent = false; | 1978 m_sentEndEvent = false; |
| 1979 | 1979 |
| 1980 // 8 - Queue a task to fire a simple event named seeking at the element. | 1980 // 8 - Queue a task to fire a simple event named seeking at the element. |
| 1981 scheduleEvent(EventTypeNames::seeking); | 1981 scheduleEvent(EventTypeNames::seeking); |
| 1982 | 1982 |
| 1983 // 9 - Set the current playback position to the given new playback position | 1983 // 9 - Set the current playback position to the given new playback position |
| 1984 m_player->seek(time); | 1984 webMediaPlayer()->seek(time); |
| 1985 | 1985 |
| 1986 // 10-14 are handled, if necessary, when the engine signals a readystate cha
nge or otherwise | 1986 // 10-14 are handled, if necessary, when the engine signals a readystate cha
nge or otherwise |
| 1987 // satisfies seek completion and signals a time change. | 1987 // satisfies seek completion and signals a time change. |
| 1988 } | 1988 } |
| 1989 | 1989 |
| 1990 void HTMLMediaElement::finishSeek() | 1990 void HTMLMediaElement::finishSeek() |
| 1991 { | 1991 { |
| 1992 WTF_LOG(Media, "HTMLMediaElement::finishSeek"); | 1992 WTF_LOG(Media, "HTMLMediaElement::finishSeek"); |
| 1993 | 1993 |
| 1994 // 4.8.10.9 Seeking completion | 1994 // 4.8.10.9 Seeking completion |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2014 return webMediaPlayer() && webMediaPlayer()->hasAudio(); | 2014 return webMediaPlayer() && webMediaPlayer()->hasAudio(); |
| 2015 } | 2015 } |
| 2016 | 2016 |
| 2017 bool HTMLMediaElement::seeking() const | 2017 bool HTMLMediaElement::seeking() const |
| 2018 { | 2018 { |
| 2019 return m_seeking; | 2019 return m_seeking; |
| 2020 } | 2020 } |
| 2021 | 2021 |
| 2022 void HTMLMediaElement::refreshCachedTime() const | 2022 void HTMLMediaElement::refreshCachedTime() const |
| 2023 { | 2023 { |
| 2024 m_cachedTime = m_player->currentTime(); | 2024 if (!webMediaPlayer()) |
| 2025 return; |
| 2026 |
| 2027 m_cachedTime = webMediaPlayer()->currentTime(); |
| 2025 m_cachedTimeWallClockUpdateTime = WTF::currentTime(); | 2028 m_cachedTimeWallClockUpdateTime = WTF::currentTime(); |
| 2026 } | 2029 } |
| 2027 | 2030 |
| 2028 void HTMLMediaElement::invalidateCachedTime() | 2031 void HTMLMediaElement::invalidateCachedTime() |
| 2029 { | 2032 { |
| 2030 WTF_LOG(Media, "HTMLMediaElement::invalidateCachedTime"); | 2033 WTF_LOG(Media, "HTMLMediaElement::invalidateCachedTime"); |
| 2031 | 2034 |
| 2032 // Don't try to cache movie time when playback first starts as the time repo
rted by the engine | 2035 // Don't try to cache movie time when playback first starts as the time repo
rted by the engine |
| 2033 // sometimes fluctuates for a short amount of time, so the cached time will
be off if we take it | 2036 // sometimes fluctuates for a short amount of time, so the cached time will
be off if we take it |
| 2034 // too early. | 2037 // too early. |
| 2035 static const double minimumTimePlayingBeforeCacheSnapshot = 0.5; | 2038 static const double minimumTimePlayingBeforeCacheSnapshot = 0.5; |
| 2036 | 2039 |
| 2037 m_minimumWallClockTimeToCacheMediaTime = WTF::currentTime() + minimumTimePla
yingBeforeCacheSnapshot; | 2040 m_minimumWallClockTimeToCacheMediaTime = WTF::currentTime() + minimumTimePla
yingBeforeCacheSnapshot; |
| 2038 m_cachedTime = MediaPlayer::invalidTime(); | 2041 m_cachedTime = MediaPlayer::invalidTime(); |
| 2039 } | 2042 } |
| 2040 | 2043 |
| 2041 // playback state | 2044 // playback state |
| 2042 double HTMLMediaElement::currentTime() const | 2045 double HTMLMediaElement::currentTime() const |
| 2043 { | 2046 { |
| 2044 #if LOG_CACHED_TIME_WARNINGS | 2047 #if LOG_CACHED_TIME_WARNINGS |
| 2045 static const double minCachedDeltaForWarning = 0.01; | 2048 static const double minCachedDeltaForWarning = 0.01; |
| 2046 #endif | 2049 #endif |
| 2047 | 2050 |
| 2048 if (!m_player) | 2051 if (m_readyState == HAVE_NOTHING) |
| 2049 return 0; | 2052 return 0; |
| 2050 | 2053 |
| 2051 if (m_seeking) { | 2054 if (m_seeking) { |
| 2052 WTF_LOG(Media, "HTMLMediaElement::currentTime - seeking, returning %f",
m_lastSeekTime); | 2055 WTF_LOG(Media, "HTMLMediaElement::currentTime - seeking, returning %f",
m_lastSeekTime); |
| 2053 return m_lastSeekTime; | 2056 return m_lastSeekTime; |
| 2054 } | 2057 } |
| 2055 | 2058 |
| 2056 if (m_cachedTime != MediaPlayer::invalidTime() && m_paused) { | 2059 if (m_cachedTime != MediaPlayer::invalidTime() && m_paused) { |
| 2057 #if LOG_CACHED_TIME_WARNINGS | 2060 #if LOG_CACHED_TIME_WARNINGS |
| 2058 double delta = m_cachedTime - m_player->currentTime(); | 2061 double delta = m_cachedTime - webMediaPlayer()->currentTime(); |
| 2059 if (delta > minCachedDeltaForWarning) | 2062 if (delta > minCachedDeltaForWarning) |
| 2060 WTF_LOG(Media, "HTMLMediaElement::currentTime - WARNING, cached time
is %f seconds off of media time when paused", delta); | 2063 WTF_LOG(Media, "HTMLMediaElement::currentTime - WARNING, cached time
is %f seconds off of media time when paused", delta); |
| 2061 #endif | 2064 #endif |
| 2062 return m_cachedTime; | 2065 return m_cachedTime; |
| 2063 } | 2066 } |
| 2064 | 2067 |
| 2065 refreshCachedTime(); | 2068 refreshCachedTime(); |
| 2066 | 2069 |
| 2067 return m_cachedTime; | 2070 return m_cachedTime; |
| 2068 } | 2071 } |
| 2069 | 2072 |
| 2070 void HTMLMediaElement::setCurrentTime(double time, ExceptionState& exceptionStat
e) | 2073 void HTMLMediaElement::setCurrentTime(double time, ExceptionState& exceptionStat
e) |
| 2071 { | 2074 { |
| 2072 if (m_mediaController) { | 2075 if (m_mediaController) { |
| 2073 exceptionState.throwDOMException(InvalidStateError, "The element is slav
ed to a MediaController."); | 2076 exceptionState.throwDOMException(InvalidStateError, "The element is slav
ed to a MediaController."); |
| 2074 return; | 2077 return; |
| 2075 } | 2078 } |
| 2076 seek(time, exceptionState); | 2079 seek(time, exceptionState); |
| 2077 } | 2080 } |
| 2078 | 2081 |
| 2079 double HTMLMediaElement::duration() const | 2082 double HTMLMediaElement::duration() const |
| 2080 { | 2083 { |
| 2081 if (!m_player || m_readyState < HAVE_METADATA) | 2084 if (m_readyState < HAVE_METADATA) |
| 2082 return std::numeric_limits<double>::quiet_NaN(); | 2085 return std::numeric_limits<double>::quiet_NaN(); |
| 2083 | 2086 |
| 2084 // FIXME: Refactor so m_duration is kept current (in both MSE and | 2087 // FIXME: Refactor so m_duration is kept current (in both MSE and |
| 2085 // non-MSE cases) once we have transitioned from HAVE_NOTHING -> | 2088 // non-MSE cases) once we have transitioned from HAVE_NOTHING -> |
| 2086 // HAVE_METADATA. Currently, m_duration may be out of date for at least MSE | 2089 // HAVE_METADATA. Currently, m_duration may be out of date for at least MSE |
| 2087 // case because MediaSource and SourceBuffer do not notify the element | 2090 // case because MediaSource and SourceBuffer do not notify the element |
| 2088 // directly upon duration changes caused by endOfStream, remove, or append | 2091 // directly upon duration changes caused by endOfStream, remove, or append |
| 2089 // operations; rather the notification is triggered by the WebMediaPlayer | 2092 // operations; rather the notification is triggered by the WebMediaPlayer |
| 2090 // implementation observing that the underlying engine has updated duration | 2093 // implementation observing that the underlying engine has updated duration |
| 2091 // and notifying the element to consult its MediaSource for current | 2094 // and notifying the element to consult its MediaSource for current |
| 2092 // duration. See http://crbug.com/266644 | 2095 // duration. See http://crbug.com/266644 |
| 2093 | 2096 |
| 2094 if (m_mediaSource) | 2097 if (m_mediaSource) |
| 2095 return m_mediaSource->duration(); | 2098 return m_mediaSource->duration(); |
| 2096 | 2099 |
| 2097 return m_player->duration(); | 2100 return webMediaPlayer()->duration(); |
| 2098 } | 2101 } |
| 2099 | 2102 |
| 2100 bool HTMLMediaElement::paused() const | 2103 bool HTMLMediaElement::paused() const |
| 2101 { | 2104 { |
| 2102 return m_paused; | 2105 return m_paused; |
| 2103 } | 2106 } |
| 2104 | 2107 |
| 2105 double HTMLMediaElement::defaultPlaybackRate() const | 2108 double HTMLMediaElement::defaultPlaybackRate() const |
| 2106 { | 2109 { |
| 2107 return m_defaultPlaybackRate; | 2110 return m_defaultPlaybackRate; |
| (...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3021 | 3024 |
| 3022 void HTMLMediaElement::mediaPlayerTimeChanged() | 3025 void HTMLMediaElement::mediaPlayerTimeChanged() |
| 3023 { | 3026 { |
| 3024 WTF_LOG(Media, "HTMLMediaElement::mediaPlayerTimeChanged"); | 3027 WTF_LOG(Media, "HTMLMediaElement::mediaPlayerTimeChanged"); |
| 3025 | 3028 |
| 3026 updateActiveTextTrackCues(currentTime()); | 3029 updateActiveTextTrackCues(currentTime()); |
| 3027 | 3030 |
| 3028 invalidateCachedTime(); | 3031 invalidateCachedTime(); |
| 3029 | 3032 |
| 3030 // 4.8.10.9 steps 12-14. Needed if no ReadyState change is associated with t
he seek. | 3033 // 4.8.10.9 steps 12-14. Needed if no ReadyState change is associated with t
he seek. |
| 3031 if (m_seeking && m_readyState >= HAVE_CURRENT_DATA && !m_player->seeking()) | 3034 if (m_seeking && m_readyState >= HAVE_CURRENT_DATA && !webMediaPlayer()->see
king()) |
| 3032 finishSeek(); | 3035 finishSeek(); |
| 3033 | 3036 |
| 3034 // Always call scheduleTimeupdateEvent when the media engine reports a time
discontinuity, | 3037 // Always call scheduleTimeupdateEvent when the media engine reports a time
discontinuity, |
| 3035 // it will only queue a 'timeupdate' event if we haven't already posted one
at the current | 3038 // it will only queue a 'timeupdate' event if we haven't already posted one
at the current |
| 3036 // movie time. | 3039 // movie time. |
| 3037 scheduleTimeupdateEvent(false); | 3040 scheduleTimeupdateEvent(false); |
| 3038 | 3041 |
| 3039 double now = currentTime(); | 3042 double now = currentTime(); |
| 3040 double dur = duration(); | 3043 double dur = duration(); |
| 3041 | 3044 |
| (...skipping 929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3971 | 3974 |
| 3972 #if ENABLE(WEB_AUDIO) | 3975 #if ENABLE(WEB_AUDIO) |
| 3973 void HTMLMediaElement::clearWeakMembers(Visitor* visitor) | 3976 void HTMLMediaElement::clearWeakMembers(Visitor* visitor) |
| 3974 { | 3977 { |
| 3975 if (!visitor->isAlive(m_audioSourceNode) && audioSourceProvider()) | 3978 if (!visitor->isAlive(m_audioSourceNode) && audioSourceProvider()) |
| 3976 audioSourceProvider()->setClient(0); | 3979 audioSourceProvider()->setClient(0); |
| 3977 } | 3980 } |
| 3978 #endif | 3981 #endif |
| 3979 | 3982 |
| 3980 } | 3983 } |
| OLD | NEW |