void MediaSource::setDurationInternal(const MediaTime& duration) { // Duration Change Algorithm // https://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html#duration-change-algorithm // 1. If the current value of duration is equal to new duration, then return. if (duration == m_duration) return; // 2. Set old duration to the current value of duration. MediaTime oldDuration = m_duration; // 3. Update duration to new duration. m_duration = duration; // 4. If the new duration is less than old duration, then call remove(new duration, old duration) // on all objects in sourceBuffers. if (oldDuration.isValid() && duration < oldDuration) { for (auto& sourceBuffer : *m_sourceBuffers) sourceBuffer->rangeRemoval(duration, oldDuration); } // 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: // 5.1 Update new duration to the highest end time reported by the buffered attribute across all SourceBuffer objects // in sourceBuffers. // 5.2 Update duration to new duration. // NOTE: Assume UA is able to partially render audio frames. // 6. Update the media controller duration to new duration and run the HTMLMediaElement duration change algorithm. LOG(MediaSource, "MediaSource::setDurationInternal(%p) - duration(%g)", this, duration.toDouble()); m_private->durationChanged(); }