<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[205820] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/205820">205820</a></dd>
<dt>Author</dt> <dd>jer.noble@apple.com</dd>
<dt>Date</dt> <dd>2016-09-12 14:09:15 -0700 (Mon, 12 Sep 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fix failing mediasource-play.html and mediasource-config-change-mp4-v-bitrate.html tests
https://bugs.webkit.org/show_bug.cgi?id=161819

Reviewed by Eric Carlson.

Source/WebCore:

Fixes tests: imported/w3c/web-platform-tests/media-source/mediasource-play.html
             imported/w3c/web-platform-tests/media-source/mediasource-sourcebuffer-mode.html

The newest revision of the web-platform-test suite for Media Source tests new behavior
added to the MSE specification. Specifically, setting a MediaSource's duration will no
longer implicitly truncate the source's active SourceBuffer objects.

* Modules/mediasource/MediaSource.cpp:
(WebCore::MediaSource::setDuration): Return exception if issued by setDurationInternal.
(WebCore::MediaSource::setDurationInternal): Bring &quot;duration change&quot; algorithm up to spec.
* Modules/mediasource/MediaSource.h:
* Modules/mediasource/SampleMap.h:
(WebCore::PresentationOrderSampleMap::begin): Add const accessor.
(WebCore::PresentationOrderSampleMap::end): Ditto.
(WebCore::PresentationOrderSampleMap::rbegin): Ditto.
(WebCore::PresentationOrderSampleMap::rend): DItto.
(WebCore::DecodeOrderSampleMap::begin): Ditto.
(WebCore::DecodeOrderSampleMap::end): Ditto.
(WebCore::DecodeOrderSampleMap::rbegin): Ditto.
(WebCore::DecodeOrderSampleMap::rend): Ditto.
* Modules/mediasource/SourceBuffer.cpp:
(WebCore::SourceBuffer::highestPresentationTimestamp): Added convenience method.
(WebCore::SourceBuffer::removeCodedFrames): Drive-by fix; use .values() rather than
    pulling the value out of each HashMap iterator.
* Modules/mediasource/SourceBuffer.h:

LayoutTests:

* media/media-source/media-source-end-of-stream-readyState.html:
* media/media-source/media-source-end-of-stream-readyState-expected.txt:
* platform/mac/TestExpectations:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsmediamediasourcemediasourceendofstreamreadyStateexpectedtxt">trunk/LayoutTests/media/media-source/media-source-end-of-stream-readyState-expected.txt</a></li>
<li><a href="#trunkLayoutTestsmediamediasourcemediasourceendofstreamreadyStatehtml">trunk/LayoutTests/media/media-source/media-source-end-of-stream-readyState.html</a></li>
<li><a href="#trunkLayoutTestsplatformmacTestExpectations">trunk/LayoutTests/platform/mac/TestExpectations</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesmediasourceMediaSourcecpp">trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesmediasourceMediaSourceh">trunk/Source/WebCore/Modules/mediasource/MediaSource.h</a></li>
<li><a href="#trunkSourceWebCoreModulesmediasourceSampleMaph">trunk/Source/WebCore/Modules/mediasource/SampleMap.h</a></li>
<li><a href="#trunkSourceWebCoreModulesmediasourceSourceBuffercpp">trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesmediasourceSourceBufferh">trunk/Source/WebCore/Modules/mediasource/SourceBuffer.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (205819 => 205820)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-09-12 21:04:25 UTC (rev 205819)
+++ trunk/LayoutTests/ChangeLog        2016-09-12 21:09:15 UTC (rev 205820)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2016-09-12  Jer Noble  &lt;jer.noble@apple.com&gt;
+
+        Fix failing mediasource-play.html and mediasource-config-change-mp4-v-bitrate.html tests
+        https://bugs.webkit.org/show_bug.cgi?id=161819
+
+        Reviewed by Eric Carlson.
+
+        * media/media-source/media-source-end-of-stream-readyState.html:
+        * media/media-source/media-source-end-of-stream-readyState-expected.txt:
+        * platform/mac/TestExpectations:
+
</ins><span class="cx"> 2016-09-12  Matt Baker  &lt;mattbaker@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Web Inspector: Object.shallowEqual() should return false if object prototype chains differ
</span></span></pre></div>
<a id="trunkLayoutTestsmediamediasourcemediasourceendofstreamreadyStateexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/media/media-source/media-source-end-of-stream-readyState-expected.txt (205819 => 205820)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/media/media-source/media-source-end-of-stream-readyState-expected.txt        2016-09-12 21:04:25 UTC (rev 205819)
+++ trunk/LayoutTests/media/media-source/media-source-end-of-stream-readyState-expected.txt        2016-09-12 21:09:15 UTC (rev 205820)
</span><span class="lines">@@ -8,6 +8,6 @@
</span><span class="cx"> EXPECTED (sourceBuffer.buffered.end(0).toFixed(3) == '5') OK
</span><span class="cx"> RUN(source.endOfStream())
</span><span class="cx"> EXPECTED (source.duration.toFixed(3) == '5') OK
</span><del>-EVENT(updateend)
</del><ins>+EXPECTED (sourceBuffer.updating == 'false') OK
</ins><span class="cx"> END OF TEST
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsmediamediasourcemediasourceendofstreamreadyStatehtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/media/media-source/media-source-end-of-stream-readyState.html (205819 => 205820)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/media/media-source/media-source-end-of-stream-readyState.html        2016-09-12 21:04:25 UTC (rev 205819)
+++ trunk/LayoutTests/media/media-source/media-source-end-of-stream-readyState.html        2016-09-12 21:09:15 UTC (rev 205820)
</span><span class="lines">@@ -36,9 +36,10 @@
</span><span class="cx">         testExpected('sourceBuffer.buffered.end(0).toFixed(3)', 5);
</span><span class="cx"> 
</span><span class="cx">         waitForEventOn(source, 'sourceopen', function() { failTest(&quot;Should not transit to 'open' state during endOfStream().&quot;) }, false, true);
</span><del>-        waitForEventOn(sourceBuffer, 'updateend', endTest, false, true);
</del><span class="cx">         run('source.endOfStream()');
</span><span class="cx">         testExpected('source.duration.toFixed(3)', 5);
</span><ins>+        testExpected('sourceBuffer.updating', false);
+        endTest();
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     &lt;/script&gt;
</span></span></pre></div>
<a id="trunkLayoutTestsplatformmacTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/mac/TestExpectations (205819 => 205820)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac/TestExpectations        2016-09-12 21:04:25 UTC (rev 205819)
+++ trunk/LayoutTests/platform/mac/TestExpectations        2016-09-12 21:09:15 UTC (rev 205820)
</span><span class="lines">@@ -1047,8 +1047,10 @@
</span><span class="cx"> [ Yosemite+ ] imported/w3c/web-platform-tests/media-source/SourceBuffer-abort-removed.html [ Pass ]
</span><span class="cx"> [ Yosemite+ ] imported/w3c/web-platform-tests/media-source/SourceBuffer-abort.html [ Pass ]
</span><span class="cx"> [ Yosemite+ ] imported/w3c/web-platform-tests/media-source/mediasource-closed.html [ Pass ]
</span><ins>+[ Yosemite+ ] imported/w3c/web-platform-tests/media-source/mediasource-config-change-mp4-v-bitrate.html [ Pass ]
</ins><span class="cx"> [ Yosemite+ ] imported/w3c/web-platform-tests/media-source/mediasource-endofstream-invaliderror.html [ Pass ]
</span><span class="cx"> [ Yosemite+ ] imported/w3c/web-platform-tests/media-source/mediasource-multiple-attach.html [ Pass ]
</span><ins>+[ Yosemite+ ] imported/w3c/web-platform-tests/media-source/mediasource-play.html [ Pass ]
</ins><span class="cx"> [ Yosemite+ ] imported/w3c/web-platform-tests/media-source/mediasource-sourcebufferlist.html [ Pass ]
</span><span class="cx"> 
</span><span class="cx"> # Flaky Media Source tests
</span><span class="lines">@@ -1060,7 +1062,6 @@
</span><span class="cx"> webkit.org/b/161725 [ Yosemite+ ] imported/w3c/web-platform-tests/media-source/mediasource-append-buffer.html [ Failure ]
</span><span class="cx"> webkit.org/b/161725 [ Yosemite+ ] imported/w3c/web-platform-tests/media-source/mediasource-config-change-mp4-v-bitrate.html [ Failure ]
</span><span class="cx"> webkit.org/b/161725 [ Yosemite+ ] imported/w3c/web-platform-tests/media-source/mediasource-is-type-supported.html [ Failure ]
</span><del>-webkit.org/b/161725 [ Yosemite+ ] imported/w3c/web-platform-tests/media-source/mediasource-play.html [ Failure ]
</del><span class="cx"> webkit.org/b/161725 [ Yosemite+ ] imported/w3c/web-platform-tests/media-source/mediasource-remove.html [ Failure ]
</span><span class="cx"> webkit.org/b/161725 [ Yosemite+ ] imported/w3c/web-platform-tests/media-source/mediasource-sourcebuffer-mode.html [ Failure ]
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (205819 => 205820)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-09-12 21:04:25 UTC (rev 205819)
+++ trunk/Source/WebCore/ChangeLog        2016-09-12 21:09:15 UTC (rev 205820)
</span><span class="lines">@@ -1,3 +1,36 @@
</span><ins>+2016-09-12  Jer Noble  &lt;jer.noble@apple.com&gt;
+
+        Fix failing mediasource-play.html and mediasource-config-change-mp4-v-bitrate.html tests
+        https://bugs.webkit.org/show_bug.cgi?id=161819
+
+        Reviewed by Eric Carlson.
+
+        Fixes tests: imported/w3c/web-platform-tests/media-source/mediasource-play.html
+                     imported/w3c/web-platform-tests/media-source/mediasource-sourcebuffer-mode.html
+
+        The newest revision of the web-platform-test suite for Media Source tests new behavior
+        added to the MSE specification. Specifically, setting a MediaSource's duration will no
+        longer implicitly truncate the source's active SourceBuffer objects.
+
+        * Modules/mediasource/MediaSource.cpp:
+        (WebCore::MediaSource::setDuration): Return exception if issued by setDurationInternal.
+        (WebCore::MediaSource::setDurationInternal): Bring &quot;duration change&quot; algorithm up to spec.
+        * Modules/mediasource/MediaSource.h:
+        * Modules/mediasource/SampleMap.h:
+        (WebCore::PresentationOrderSampleMap::begin): Add const accessor.
+        (WebCore::PresentationOrderSampleMap::end): Ditto.
+        (WebCore::PresentationOrderSampleMap::rbegin): Ditto.
+        (WebCore::PresentationOrderSampleMap::rend): DItto.
+        (WebCore::DecodeOrderSampleMap::begin): Ditto.
+        (WebCore::DecodeOrderSampleMap::end): Ditto.
+        (WebCore::DecodeOrderSampleMap::rbegin): Ditto.
+        (WebCore::DecodeOrderSampleMap::rend): Ditto.
+        * Modules/mediasource/SourceBuffer.cpp:
+        (WebCore::SourceBuffer::highestPresentationTimestamp): Added convenience method.
+        (WebCore::SourceBuffer::removeCodedFrames): Drive-by fix; use .values() rather than
+            pulling the value out of each HashMap iterator.
+        * Modules/mediasource/SourceBuffer.h:
+
</ins><span class="cx"> 2016-09-12  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Switch remaining users of Document::inPageCache() to pageCacheState()
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediasourceMediaSourcecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp (205819 => 205820)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp        2016-09-12 21:04:25 UTC (rev 205819)
+++ trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp        2016-09-12 21:09:15 UTC (rev 205820)
</span><span class="lines">@@ -357,41 +357,49 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // 4. Run the duration change algorithm with new duration set to the value being assigned to this attribute.
</span><del>-    setDurationInternal(MediaTime::createWithDouble(duration));
</del><ins>+    auto result = setDurationInternal(MediaTime::createWithDouble(duration));
+    if (result)
+        ec = result.value();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void MediaSource::setDurationInternal(const MediaTime&amp; duration)
</del><ins>+Optional&lt;ExceptionCode&gt; MediaSource::setDurationInternal(const MediaTime&amp; duration)
</ins><span class="cx"> {
</span><del>-    // Duration Change Algorithm
-    // https://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html#duration-change-algorithm
</del><ins>+    // 2.4.6 Duration Change
+    // https://rawgit.com/w3c/media-source/45627646344eea0170dd1cbc5a3d508ca751abb8/media-source-respec.html#duration-change-algorithm
</ins><span class="cx"> 
</span><ins>+    MediaTime newDuration = duration;
+
</ins><span class="cx">     // 1. If the current value of duration is equal to new duration, then return.
</span><del>-    if (duration == m_duration)
-        return;
</del><ins>+    if (newDuration == m_duration)
+        return { };
</ins><span class="cx"> 
</span><del>-    // 2. Set old duration to the current value of duration.
-    MediaTime oldDuration = m_duration;
</del><ins>+    // 2. If new duration is less than the highest presentation timestamp of any buffered coded frames
+    // for all SourceBuffer objects in sourceBuffers, then throw an InvalidStateError exception and
+    // abort these steps.
+    // 3. Let highest end time be the largest track buffer ranges end time across all the track buffers
+    // across all SourceBuffer objects in sourceBuffers.
+    MediaTime highestPresentationTimestamp;
+    MediaTime highestEndTime;
+    for (auto&amp; sourceBuffer : *m_sourceBuffers) {
+        highestPresentationTimestamp = std::max(highestPresentationTimestamp, sourceBuffer-&gt;highestPresentationTimestamp());
+        highestEndTime = std::max(highestEndTime, sourceBuffer-&gt;buffered()-&gt;ranges().maximumBufferedTime());
+    }
+    if (highestPresentationTimestamp.isValid() &amp;&amp; newDuration &lt; highestPresentationTimestamp)
+        return INVALID_STATE_ERR;
</ins><span class="cx"> 
</span><del>-    // 3. Update duration to new duration.
-    m_duration = duration;
</del><ins>+    // 4. If new duration is less than highest end time, then
+    // 4.1. Update new duration to equal highest end time.
+    if (highestEndTime.isValid() &amp;&amp; newDuration &lt; highestEndTime)
+        newDuration = highestEndTime;
</ins><span class="cx"> 
</span><del>-    // 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() &amp;&amp; duration &lt; oldDuration) {
-        for (auto&amp; sourceBuffer : *m_sourceBuffers)
-            sourceBuffer-&gt;rangeRemoval(duration, oldDuration);
-    }
</del><ins>+    // 5. Update duration to new duration.
+    m_duration = newDuration;
</ins><span class="cx"> 
</span><del>-    // 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.
</del><ins>+    // 6. Update the media duration to new duration and run the HTMLMediaElement duration change algorithm.
</ins><span class="cx">     LOG(MediaSource, &quot;MediaSource::setDurationInternal(%p) - duration(%g)&quot;, this, duration.toDouble());
</span><span class="cx">     m_private-&gt;durationChanged();
</span><ins>+
+    return { };
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void MediaSource::setReadyState(const AtomicString&amp; state)
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediasourceMediaSourceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediasource/MediaSource.h (205819 => 205820)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediasource/MediaSource.h        2016-09-12 21:04:25 UTC (rev 205819)
+++ trunk/Source/WebCore/Modules/mediasource/MediaSource.h        2016-09-12 21:09:15 UTC (rev 205820)
</span><span class="lines">@@ -84,7 +84,7 @@
</span><span class="cx">     void completeSeek();
</span><span class="cx"> 
</span><span class="cx">     void setDuration(double, ExceptionCode&amp;);
</span><del>-    void setDurationInternal(const MediaTime&amp;);
</del><ins>+    Optional&lt;ExceptionCode&gt; setDurationInternal(const MediaTime&amp;);
</ins><span class="cx">     MediaTime currentTime() const;
</span><span class="cx">     const AtomicString&amp; readyState() const { return m_readyState; }
</span><span class="cx">     void setReadyState(const AtomicString&amp;);
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediasourceSampleMaph"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediasource/SampleMap.h (205819 => 205820)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediasource/SampleMap.h        2016-09-12 21:04:25 UTC (rev 205819)
+++ trunk/Source/WebCore/Modules/mediasource/SampleMap.h        2016-09-12 21:09:15 UTC (rev 205820)
</span><span class="lines">@@ -42,13 +42,19 @@
</span><span class="cx"> public:
</span><span class="cx">     typedef std::map&lt;MediaTime, RefPtr&lt;MediaSample&gt;&gt; MapType;
</span><span class="cx">     typedef MapType::iterator iterator;
</span><ins>+    typedef MapType::const_iterator const_iterator;
</ins><span class="cx">     typedef MapType::reverse_iterator reverse_iterator;
</span><ins>+    typedef MapType::const_reverse_iterator const_reverse_iterator;
</ins><span class="cx">     typedef std::pair&lt;iterator, iterator&gt; iterator_range;
</span><span class="cx"> 
</span><span class="cx">     iterator begin() { return m_samples.begin(); }
</span><ins>+    const_iterator begin() const { return m_samples.begin(); }
</ins><span class="cx">     iterator end() { return m_samples.end(); }
</span><ins>+    const_iterator end() const { return m_samples.end(); }
</ins><span class="cx">     reverse_iterator rbegin() { return m_samples.rbegin(); }
</span><ins>+    const_reverse_iterator rbegin() const { return m_samples.rbegin(); }
</ins><span class="cx">     reverse_iterator rend() { return m_samples.rend(); }
</span><ins>+    const_reverse_iterator rend() const { return m_samples.rend(); }
</ins><span class="cx"> 
</span><span class="cx">     iterator findSampleWithPresentationTime(const MediaTime&amp;);
</span><span class="cx">     iterator findSampleContainingPresentationTime(const MediaTime&amp;);
</span><span class="lines">@@ -69,13 +75,19 @@
</span><span class="cx">     typedef std::pair&lt;MediaTime, MediaTime&gt; KeyType;
</span><span class="cx">     typedef std::map&lt;KeyType, RefPtr&lt;MediaSample&gt;&gt; MapType;
</span><span class="cx">     typedef MapType::iterator iterator;
</span><ins>+    typedef MapType::const_iterator const_iterator;
</ins><span class="cx">     typedef MapType::reverse_iterator reverse_iterator;
</span><ins>+    typedef MapType::const_reverse_iterator const_reverse_iterator;
</ins><span class="cx">     typedef std::pair&lt;reverse_iterator, reverse_iterator&gt; reverse_iterator_range;
</span><span class="cx"> 
</span><span class="cx">     iterator begin() { return m_samples.begin(); }
</span><ins>+    const_iterator begin() const { return m_samples.begin(); }
</ins><span class="cx">     iterator end() { return m_samples.end(); }
</span><ins>+    const_iterator end() const { return m_samples.end(); }
</ins><span class="cx">     reverse_iterator rbegin() { return m_samples.rbegin(); }
</span><ins>+    const_reverse_iterator rbegin() const { return m_samples.rbegin(); }
</ins><span class="cx">     reverse_iterator rend() { return m_samples.rend(); }
</span><ins>+    const_reverse_iterator rend() const { return m_samples.rend(); }
</ins><span class="cx"> 
</span><span class="cx">     iterator findSampleWithDecodeKey(const KeyType&amp;);
</span><span class="cx">     reverse_iterator reverseFindSampleWithDecodeKey(const KeyType&amp;);
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediasourceSourceBuffercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp (205819 => 205820)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp        2016-09-12 21:04:25 UTC (rev 205819)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp        2016-09-12 21:09:15 UTC (rev 205820)
</span><span class="lines">@@ -395,6 +395,18 @@
</span><span class="cx">     scheduleEvent(eventNames().updateendEvent);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+MediaTime SourceBuffer::highestPresentationTimestamp() const
+{
+    MediaTime highestTime;
+    for (auto&amp; trackBuffer : m_trackBufferMap.values()) {
+        auto lastSampleIter = trackBuffer.samples.presentationOrder().rbegin();
+        if (lastSampleIter == trackBuffer.samples.presentationOrder().rend())
+            continue;
+        highestTime = std::max(highestTime, lastSampleIter-&gt;first);
+    }
+    return highestTime;
+}
+
</ins><span class="cx"> void SourceBuffer::removedFromMediaSource()
</span><span class="cx"> {
</span><span class="cx">     if (isRemoved())
</span><span class="lines">@@ -741,9 +753,7 @@
</span><span class="cx"> 
</span><span class="cx">     // 2. Let end be the end presentation timestamp for the removal range.
</span><span class="cx">     // 3. For each track buffer in this source buffer, run the following steps:
</span><del>-    for (auto&amp; iter : m_trackBufferMap) {
-        TrackBuffer&amp; trackBuffer = iter.value;
-
</del><ins>+    for (auto&amp; trackBuffer : m_trackBufferMap.values()) {
</ins><span class="cx">         // 3.1. Let remove end timestamp be the current value of duration
</span><span class="cx">         // 3.2 If this track buffer has a random access point timestamp that is greater than or equal to end, then update
</span><span class="cx">         // remove end timestamp to that random access point timestamp.
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediasourceSourceBufferh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediasource/SourceBuffer.h (205819 => 205820)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediasource/SourceBuffer.h        2016-09-12 21:04:25 UTC (rev 205819)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBuffer.h        2016-09-12 21:09:15 UTC (rev 205820)
</span><span class="lines">@@ -124,6 +124,8 @@
</span><span class="cx">     bool isBufferedDirty() const { return m_bufferedDirty; }
</span><span class="cx">     void setBufferedDirty(bool flag) { m_bufferedDirty = flag; }
</span><span class="cx"> 
</span><ins>+    MediaTime highestPresentationTimestamp() const;
+
</ins><span class="cx">     // ActiveDOMObject API.
</span><span class="cx">     bool hasPendingActivity() const override;
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>