Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1071)

Unified Diff: Source/modules/mediasource/MediaSource.cpp

Issue 319213002: Fix MediaSource.duration setter behavior to match the current spec. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix release build buster Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/mediasource/MediaSource.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/mediasource/MediaSource.cpp
diff --git a/Source/modules/mediasource/MediaSource.cpp b/Source/modules/mediasource/MediaSource.cpp
index 2185806ade015d07eedd1cf3e321640083658c9a..7a427438b4ecd38a6286e44fe92f4dcfafd3c96e 100644
--- a/Source/modules/mediasource/MediaSource.cpp
+++ b/Source/modules/mediasource/MediaSource.cpp
@@ -359,10 +359,37 @@ void MediaSource::setDuration(double duration, ExceptionState& exceptionState)
// 4. Run the duration change algorithm with new duration set to the value being
// assigned to this attribute.
- // Synchronously process duration change algorithm to enforce any required
- // seek is started prior to returning.
- m_attachedElement->durationChanged(duration);
- m_webMediaSource->setDuration(duration);
+ durationChangeAlgorithm(duration);
+}
+
+void MediaSource::durationChangeAlgorithm(double newDuration)
+{
+ // Section 2.6.4 Duration change
+ // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#duration-change-algorithm
+ // 1. If the current value of duration is equal to new duration, then return.
+ if (newDuration == duration())
+ return;
+
+ // 2. Set old duration to the current value of duration.
+ double oldDuration = duration();
+
+ bool requestSeek = m_attachedElement->currentTime() > newDuration;
+
+ // 3. Update duration to new duration.
+ m_webMediaSource->setDuration(newDuration);
+
+ // 4. If the new duration is less than old duration, then call remove(new duration, old duration) on all all objects in sourceBuffers.
+ if (newDuration < oldDuration) {
+ for (size_t i = 0; i < m_sourceBuffers->length(); ++i)
+ m_sourceBuffers->item(i)->remove(newDuration, oldDuration, ASSERT_NO_EXCEPTION);
+ }
+
+ // 5. If a user agent is unable to partially render audio frames or text cues that start before and end after the duration, then run the following steps:
+ // NOTE: Currently we assume that the media engine is able to render partial frames/cues. If a media
+ // engine gets added that doesn't support this, then we'll need to add logic to handle the substeps.
+
+ // 6. Update the media controller duration to new duration and run the HTMLMediaElement duration change algorithm.
+ m_attachedElement->durationChanged(newDuration, requestSeek);
}
void MediaSource::setReadyState(const AtomicString& state)
« no previous file with comments | « Source/modules/mediasource/MediaSource.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698