<!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>[160282] 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/160282">160282</a></dd>
<dt>Author</dt> <dd>jer.noble@apple.com</dd>
<dt>Date</dt> <dd>2013-12-07 22:43:27 -0800 (Sat, 07 Dec 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>[MSE] Bring end-of-stream algorithm section up to current spec.
https://bugs.webkit.org/show_bug.cgi?id=125270

Reviewed by Darin Adler.

Source/WebCore:

Test: media/media-source/media-source-end-of-stream.html

Separate the &quot;endOfStream()&quot; method from the &quot;end of stream algorithm&quot;.

* Modules/mediasource/MediaSource.cpp:
(WebCore::SourceBufferIsUpdating): Added predicate function.
(WebCore::MediaSource::endOfStream): Call streamEndedWithError().
(WebCore::MediaSource::streamEndedWithError): Added.
* Modules/mediasource/MediaSource.h:
* Modules/mediasource/SourceBuffer.cpp:
(WebCore::SourceBuffer::appendBufferTimerFired): Call streamEndedWithError().
(WebCore::SourceBuffer::sourceBufferPrivateDidReceiveSample): Ditto.
* Modules/mediasource/SourceBuffer.h:
* html/HTMLMediaElement.cpp:
(HTMLMediaElement::mediaLoadingFailedFatally): Renamed from mediaEngineError.
(HTMLMediaElement::mediaLoadingFailed): Call renamed method.
* html/HTMLMediaElement.h:
* platform/graphics/avfoundation/objc/MediaSourcePrivateAVFObjC.mm:
(WebCore::MediaSourcePrivateAVFObjC::markEndOfStream): Set load state to Loaded.
* platform/mock/mediasource/MockMediaPlayerMediaSource.cpp:
(WebCore::MockMediaPlayerMediaSource::setNetworkState): Simple setter.
* platform/mock/mediasource/MockMediaPlayerMediaSource.h:
* platform/mock/mediasource/MockMediaSourcePrivate.cpp:
(WebCore::MockMediaSourcePrivate::MockMediaSourcePrivate): Set the intitial duration to NaN.
(WebCore::MockMediaSourcePrivate::markEndOfStream): Set load state to Loaded.

LayoutTests:

* media/media-source/media-source-end-of-stream-expected.txt: Added.
* media/media-source/media-source-end-of-stream.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</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="#trunkSourceWebCoreModulesmediasourceSourceBuffercpp">trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesmediasourceSourceBufferh">trunk/Source/WebCore/Modules/mediasource/SourceBuffer.h</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLMediaElementcpp">trunk/Source/WebCore/html/HTMLMediaElement.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLMediaElementh">trunk/Source/WebCore/html/HTMLMediaElement.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsavfoundationobjcMediaSourcePrivateAVFObjCmm">trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaSourcePrivateAVFObjC.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformmockmediasourceMockMediaPlayerMediaSourcecpp">trunk/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformmockmediasourceMockMediaPlayerMediaSourceh">trunk/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.h</a></li>
<li><a href="#trunkSourceWebCoreplatformmockmediasourceMockMediaSourcePrivatecpp">trunk/Source/WebCore/platform/mock/mediasource/MockMediaSourcePrivate.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsmediamediasourcemediasourceendofstreamexpectedtxt">trunk/LayoutTests/media/media-source/media-source-end-of-stream-expected.txt</a></li>
<li><a href="#trunkLayoutTestsmediamediasourcemediasourceendofstreamhtml">trunk/LayoutTests/media/media-source/media-source-end-of-stream.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (160281 => 160282)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2013-12-08 06:39:39 UTC (rev 160281)
+++ trunk/LayoutTests/ChangeLog        2013-12-08 06:43:27 UTC (rev 160282)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2013-12-05  Jer Noble  &lt;jer.noble@apple.com&gt;
+
+        [MSE] Bring end-of-stream algorithm section up to current spec.
+        https://bugs.webkit.org/show_bug.cgi?id=125270
+
+        Reviewed by Darin Adler.
+
+        * media/media-source/media-source-end-of-stream-expected.txt: Added.
+        * media/media-source/media-source-end-of-stream.html: Added.
+
</ins><span class="cx"> 2013-12-06  Filip Pizlo  &lt;fpizlo@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         FTL should support all of Branch/LogicalNot
</span></span></pre></div>
<a id="trunkLayoutTestsmediamediasourcemediasourceendofstreamexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/media/media-source/media-source-end-of-stream-expected.txt (0 => 160282)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/media/media-source/media-source-end-of-stream-expected.txt                                (rev 0)
+++ trunk/LayoutTests/media/media-source/media-source-end-of-stream-expected.txt        2013-12-08 06:43:27 UTC (rev 160282)
</span><span class="lines">@@ -0,0 +1,37 @@
</span><ins>+
+RUN(video.src = URL.createObjectURL(source))
+EVENT(sourceopen)
+RUN(source.endOfStream(&quot;network&quot;))
+EVENT(error)
+EXPECTED (video.error.code == '4') OK
+RUN(video.src = URL.createObjectURL(source))
+EVENT(sourceopen)
+RUN(source.endOfStream(&quot;decode&quot;))
+EVENT(error)
+EXPECTED (video.error.code == '4') OK
+RUN(video.src = URL.createObjectURL(source))
+EVENT(sourceopen)
+RUN(sourceBuffer = source.addSourceBuffer(&quot;video/mock; codecs=mock&quot;))
+RUN(sourceBuffer.appendBuffer(initSegment))
+EVENT(updateend)
+RUN(source.endOfStream(&quot;network&quot;))
+EVENT(error)
+EXPECTED (video.error.code == '2') OK
+RUN(video.src = URL.createObjectURL(source))
+EVENT(sourceopen)
+RUN(sourceBuffer = source.addSourceBuffer(&quot;video/mock; codecs=mock&quot;))
+RUN(sourceBuffer.appendBuffer(initSegment))
+EVENT(updateend)
+RUN(source.endOfStream(&quot;decode&quot;))
+EVENT(error)
+EXPECTED (video.error.code == '3') OK
+RUN(video.src = URL.createObjectURL(source))
+EVENT(sourceopen)
+RUN(sourceBuffer = source.addSourceBuffer(&quot;video/mock; codecs=mock&quot;))
+RUN(sourceBuffer.appendBuffer(initSegment))
+EVENT(updateend)
+RUN(source.endOfStream(&quot;&quot;))
+EVENT(suspend)
+EXPECTED (video.networkState == '1') OK
+END OF TEST
+
</ins></span></pre></div>
<a id="trunkLayoutTestsmediamediasourcemediasourceendofstreamhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/media/media-source/media-source-end-of-stream.html (0 => 160282)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/media/media-source/media-source-end-of-stream.html                                (rev 0)
+++ trunk/LayoutTests/media/media-source/media-source-end-of-stream.html        2013-12-08 06:43:27 UTC (rev 160282)
</span><span class="lines">@@ -0,0 +1,112 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+    &lt;title&gt;mock-media-source&lt;/title&gt;
+    &lt;script src=&quot;mock-media-source.js&quot;&gt;&lt;/script&gt;
+    &lt;script src=&quot;../video-test.js&quot;&gt;&lt;/script&gt;
+    &lt;script&gt;
+    var source;
+    var sourceBuffer;
+    var initSegment;
+
+    if (window.internals)
+        internals.initializeMockMediaSource();
+
+    function runTest() {
+        findMediaElement();
+
+        source = new MediaSource();
+        waitForEventOn(source, 'sourceopen', sourceOpen1, false, true);
+        run('video.src = URL.createObjectURL(source)');
+    }
+
+    function sourceOpen1() {
+        waitForEventOnce('error', videoError1);
+        run('source.endOfStream(&quot;network&quot;)');
+    }
+
+    function videoError1() {
+        testExpected('video.error.code', MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED);
+
+        source = new MediaSource();
+        waitForEventOn(source, 'sourceopen', sourceOpen2, false, true);
+        run('video.src = URL.createObjectURL(source)');
+    }    
+
+    function sourceOpen2() {
+        waitForEventOnce('error', videoError2);
+        run('source.endOfStream(&quot;decode&quot;)');
+    }
+
+    function videoError2() {
+        testExpected('video.error.code', MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED);
+
+        source = new MediaSource();
+        waitForEventOn(source, 'sourceopen', sourceOpen3, false, true);
+        run('video.src = URL.createObjectURL(source)');
+    }
+
+    function sourceOpen3() {
+        run('sourceBuffer = source.addSourceBuffer(&quot;video/mock; codecs=mock&quot;)');
+        waitForEventOn(sourceBuffer, 'updateend', updateEnd3);
+        initSegment = makeAInit(100, [makeATrack(1, 'mock', TRACK_KIND.VIDEO)]);
+        run('sourceBuffer.appendBuffer(initSegment)');
+    }
+
+    function updateEnd3() {
+        waitForEventOnce('error', videoError3);
+        run('source.endOfStream(&quot;network&quot;)');
+    }
+
+    function videoError3() {
+        testExpected('video.error.code', MediaError.MEDIA_ERR_NETWORK);
+
+        source = new MediaSource();
+        waitForEventOn(source, 'sourceopen', sourceOpen4, false, true);
+        run('video.src = URL.createObjectURL(source)');
+    }
+
+    function sourceOpen4() {
+        run('sourceBuffer = source.addSourceBuffer(&quot;video/mock; codecs=mock&quot;)');
+        waitForEventOn(sourceBuffer, 'updateend', updateEnd4);
+        initSegment = makeAInit(100, [makeATrack(1, 'mock', TRACK_KIND.VIDEO)]);
+        run('sourceBuffer.appendBuffer(initSegment)');
+    }
+
+    function updateEnd4() {
+        waitForEventOnce('error', videoError4);
+        run('source.endOfStream(&quot;decode&quot;)');
+    }
+
+    function videoError4() {
+        testExpected('video.error.code', MediaError.MEDIA_ERR_DECODE);
+
+        source = new MediaSource();
+        waitForEventOn(source, 'sourceopen', sourceOpen5, false, true);
+        run('video.src = URL.createObjectURL(source)');
+    }
+
+    function sourceOpen5() {
+        run('sourceBuffer = source.addSourceBuffer(&quot;video/mock; codecs=mock&quot;)');
+        waitForEventOn(sourceBuffer, 'updateend', updateEnd5);
+        initSegment = makeAInit(100, [makeATrack(1, 'mock', TRACK_KIND.VIDEO)]);
+        run('sourceBuffer.appendBuffer(initSegment)');
+    }
+
+    function updateEnd5() {
+        waitForEventOnce('suspend', videoSuspend5);
+        run('source.endOfStream(&quot;&quot;)');
+    }
+
+    function videoSuspend5() {
+        testExpected('video.networkState', HTMLMediaElement.NETWORK_IDLE);
+
+        endTest();
+    }
+
+    &lt;/script&gt;
+&lt;/head&gt;
+&lt;body onload=&quot;runTest()&quot;&gt;
+    &lt;video&gt;&lt;/video&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (160281 => 160282)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2013-12-08 06:39:39 UTC (rev 160281)
+++ trunk/Source/WebCore/ChangeLog        2013-12-08 06:43:27 UTC (rev 160282)
</span><span class="lines">@@ -1,3 +1,36 @@
</span><ins>+2013-12-05  Jer Noble  &lt;jer.noble@apple.com&gt;
+
+        [MSE] Bring end-of-stream algorithm section up to current spec.
+        https://bugs.webkit.org/show_bug.cgi?id=125270
+
+        Reviewed by Darin Adler.
+
+        Test: media/media-source/media-source-end-of-stream.html
+
+        Separate the &quot;endOfStream()&quot; method from the &quot;end of stream algorithm&quot;.
+
+        * Modules/mediasource/MediaSource.cpp:
+        (WebCore::SourceBufferIsUpdating): Added predicate function.
+        (WebCore::MediaSource::endOfStream): Call streamEndedWithError().
+        (WebCore::MediaSource::streamEndedWithError): Added.
+        * Modules/mediasource/MediaSource.h:
+        * Modules/mediasource/SourceBuffer.cpp:
+        (WebCore::SourceBuffer::appendBufferTimerFired): Call streamEndedWithError().
+        (WebCore::SourceBuffer::sourceBufferPrivateDidReceiveSample): Ditto.
+        * Modules/mediasource/SourceBuffer.h:
+        * html/HTMLMediaElement.cpp:
+        (HTMLMediaElement::mediaLoadingFailedFatally): Renamed from mediaEngineError.
+        (HTMLMediaElement::mediaLoadingFailed): Call renamed method.
+        * html/HTMLMediaElement.h:
+        * platform/graphics/avfoundation/objc/MediaSourcePrivateAVFObjC.mm:
+        (WebCore::MediaSourcePrivateAVFObjC::markEndOfStream): Set load state to Loaded.
+        * platform/mock/mediasource/MockMediaPlayerMediaSource.cpp:
+        (WebCore::MockMediaPlayerMediaSource::setNetworkState): Simple setter.
+        * platform/mock/mediasource/MockMediaPlayerMediaSource.h:
+        * platform/mock/mediasource/MockMediaSourcePrivate.cpp:
+        (WebCore::MockMediaSourcePrivate::MockMediaSourcePrivate): Set the intitial duration to NaN.
+        (WebCore::MockMediaSourcePrivate::markEndOfStream): Set load state to Loaded.
+
</ins><span class="cx"> 2013-12-04  Jer Noble  &lt;jer.noble@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [MSE][Mac] Crash when removing MediaSource from HTMLMediaElement.
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediasourceMediaSourcecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp (160281 => 160282)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp        2013-12-08 06:39:39 UTC (rev 160281)
+++ trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp        2013-12-08 06:43:27 UTC (rev 160282)
</span><span class="lines">@@ -43,6 +43,7 @@
</span><span class="cx"> #include &quot;HTMLMediaElement.h&quot;
</span><span class="cx"> #include &quot;Logging.h&quot;
</span><span class="cx"> #include &quot;MIMETypeRegistry.h&quot;
</span><ins>+#include &quot;MediaError.h&quot;
</ins><span class="cx"> #include &quot;MediaPlayer.h&quot;
</span><span class="cx"> #include &quot;MediaSourceRegistry.h&quot;
</span><span class="cx"> #include &quot;SourceBufferPrivate.h&quot;
</span><span class="lines">@@ -303,12 +304,14 @@
</span><span class="cx">     onReadyStateChange(oldState, state);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static bool SourceBufferIsUpdating(RefPtr&lt;SourceBuffer&gt;&amp; sourceBuffer)
+{
+    return sourceBuffer-&gt;updating();
+}
+
</ins><span class="cx"> void MediaSource::endOfStream(const AtomicString&amp; error, ExceptionCode&amp; ec)
</span><span class="cx"> {
</span><del>-    DEFINE_STATIC_LOCAL(const AtomicString, network, (&quot;network&quot;, AtomicString::ConstructFromLiteral));
-    DEFINE_STATIC_LOCAL(const AtomicString, decode, (&quot;decode&quot;, AtomicString::ConstructFromLiteral));
-
-    // 3.1 http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html#dom-endofstream
</del><ins>+    // 2.2 https://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html#widl-MediaSource-endOfStream-void-EndOfStreamError-error
</ins><span class="cx">     // 1. If the readyState attribute is not in the &quot;open&quot; state then throw an
</span><span class="cx">     // INVALID_STATE_ERR exception and abort these steps.
</span><span class="cx">     if (!isOpen()) {
</span><span class="lines">@@ -316,22 +319,75 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    MediaSourcePrivate::EndOfStreamStatus eosStatus = MediaSourcePrivate::EosNoError;
-
-    if (error.isNull() || error.isEmpty())
-        eosStatus = MediaSourcePrivate::EosNoError;
-    else if (error == network)
-        eosStatus = MediaSourcePrivate::EosNetworkError;
-    else if (error == decode)
-        eosStatus = MediaSourcePrivate::EosDecodeError;
-    else {
-        ec = INVALID_ACCESS_ERR;
</del><ins>+    // 2. If the updating attribute equals true on any SourceBuffer in sourceBuffers, then throw an
+    // INVALID_STATE_ERR exception and abort these steps.
+    if (std::any_of(m_sourceBuffers-&gt;begin(), m_sourceBuffers-&gt;end(), SourceBufferIsUpdating)) {
+        ec = INVALID_STATE_ERR;
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    // 2. Change the readyState attribute value to &quot;ended&quot;.
</del><ins>+    // 3. Run the end of stream algorithm with the error parameter set to error.
+    streamEndedWithError(error, ec);
+}
+
+void MediaSource::streamEndedWithError(const AtomicString&amp; error, ExceptionCode&amp; ec)
+{
+    DEFINE_STATIC_LOCAL(const AtomicString, network, (&quot;network&quot;, AtomicString::ConstructFromLiteral));
+    DEFINE_STATIC_LOCAL(const AtomicString, decode, (&quot;decode&quot;, AtomicString::ConstructFromLiteral));
+
+    // 2.4.7 https://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html#end-of-stream-algorithm
+    // 1. Change the readyState attribute value to &quot;ended&quot;.
+    // 2. Queue a task to fire a simple event named sourceended at the MediaSource.
</ins><span class="cx">     setReadyState(endedKeyword());
</span><del>-    m_private-&gt;markEndOfStream(eosStatus);
</del><ins>+
+    // 3.
+    if (error.isEmpty()) {
+        // ↳ If error is not set, is null, or is an empty string
+        // 1. Run the duration change algorithm with new duration set to the highest end timestamp
+        // across all SourceBuffer objects in sourceBuffers.
+        MediaTime maxEndTimestamp;
+        for (auto it = m_sourceBuffers-&gt;begin(), end = m_sourceBuffers-&gt;end(); it != end; ++it)
+            maxEndTimestamp = std::max((*it)-&gt;highestPresentationEndTimestamp(), maxEndTimestamp);
+        m_private-&gt;setDuration(maxEndTimestamp.toDouble());
+
+        // 2. Notify the media element that it now has all of the media data.
+        m_private-&gt;markEndOfStream(MediaSourcePrivate::EosNoError);
+    } else if (error == network) {
+        // ↳ If error is set to &quot;network&quot;
+        ASSERT(m_mediaElement);
+        if (m_mediaElement-&gt;readyState() == HTMLMediaElement::HAVE_NOTHING) {
+            //  ↳ If the HTMLMediaElement.readyState attribute equals HAVE_NOTHING
+            //    Run the &quot;If the media data cannot be fetched at all, due to network errors, causing
+            //    the user agent to give up trying to fetch the resource&quot; steps of the resource fetch algorithm.
+            //    NOTE: This step is handled by HTMLMediaElement::mediaLoadingFailed().
+            m_mediaElement-&gt;mediaLoadingFailed(MediaPlayer::NetworkError);
+        } else {
+            //  ↳ If the HTMLMediaElement.readyState attribute is greater than HAVE_NOTHING
+            //    Run the &quot;If the connection is interrupted after some media data has been received, causing the
+            //    user agent to give up trying to fetch the resource&quot; steps of the resource fetch algorithm.
+            //    NOTE: This step is handled by HTMLMediaElement::mediaLoadingFailedFatally().
+            m_mediaElement-&gt;mediaLoadingFailedFatally(MediaPlayer::NetworkError);
+        }
+    } else if (error == decode) {
+        // ↳ If error is set to &quot;decode&quot;
+        ASSERT(m_mediaElement);
+        if (m_mediaElement-&gt;readyState() == HTMLMediaElement::HAVE_NOTHING) {
+            //  ↳ If the HTMLMediaElement.readyState attribute equals HAVE_NOTHING
+            //    Run the &quot;If the media data can be fetched but is found by inspection to be in an unsupported
+            //    format, or can otherwise not be rendered at all&quot; steps of the resource fetch algorithm.
+            //    NOTE: This step is handled by HTMLMediaElement::mediaLoadingFailed().
+            m_mediaElement-&gt;mediaLoadingFailed(MediaPlayer::FormatError);
+        } else {
+            //  ↳ If the HTMLMediaElement.readyState attribute is greater than HAVE_NOTHING
+            //    Run the media data is corrupted steps of the resource fetch algorithm.
+            //    NOTE: This step is handled by HTMLMediaElement::mediaLoadingFailedFatally().
+            m_mediaElement-&gt;mediaLoadingFailedFatally(MediaPlayer::DecodeError);
+        }
+    } else {
+        // ↳ Otherwise
+        //   Throw an INVALID_ACCESS_ERR exception.
+        ec = INVALID_ACCESS_ERR;
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> SourceBuffer* MediaSource::addSourceBuffer(const String&amp; type, ExceptionCode&amp; ec)
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediasourceMediaSourceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediasource/MediaSource.h (160281 => 160282)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediasource/MediaSource.h        2013-12-08 06:39:39 UTC (rev 160281)
+++ trunk/Source/WebCore/Modules/mediasource/MediaSource.h        2013-12-08 06:43:27 UTC (rev 160282)
</span><span class="lines">@@ -64,6 +64,7 @@
</span><span class="cx">     void openIfInEndedState();
</span><span class="cx">     bool isOpen() const;
</span><span class="cx">     void sourceBufferDidChangeAcitveState(SourceBuffer*, bool);
</span><ins>+    void streamEndedWithError(const AtomicString&amp; error, ExceptionCode&amp;);
</ins><span class="cx"> 
</span><span class="cx">     // HTMLMediaSource
</span><span class="cx">     virtual bool attachToElement(HTMLMediaElement*) OVERRIDE;
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediasourceSourceBuffercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp (160281 => 160282)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp        2013-12-08 06:39:39 UTC (rev 160281)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp        2013-12-08 06:43:27 UTC (rev 160282)
</span><span class="lines">@@ -429,7 +429,7 @@
</span><span class="cx">         // 2. If the input buffer contains bytes that violate the SourceBuffer byte stream format specification,
</span><span class="cx">         // then run the end of stream algorithm with the error parameter set to &quot;decode&quot; and abort this algorithm.
</span><span class="cx">         if (result == SourceBufferPrivate::ParsingFailed) {
</span><del>-            m_source-&gt;endOfStream(decodeError(), IgnorableExceptionCode());
</del><ins>+            m_source-&gt;streamEndedWithError(decodeError(), IgnorableExceptionCode());
</ins><span class="cx">             break;
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -806,7 +806,7 @@
</span><span class="cx">             // abort these steps.
</span><span class="cx">             MediaTime presentationStartTime = MediaTime::zeroTime();
</span><span class="cx">             if (presentationTimestamp &lt; presentationStartTime || decodeTimestamp &lt; presentationStartTime) {
</span><del>-                m_source-&gt;endOfStream(decodeError(), IgnorableExceptionCode());
</del><ins>+                m_source-&gt;streamEndedWithError(decodeError(), IgnorableExceptionCode());
</ins><span class="cx">                 return;
</span><span class="cx">             }
</span><span class="cx">         }
</span><span class="lines">@@ -985,6 +985,11 @@
</span><span class="cx">         if (trackBuffer.highestPresentationTimestamp.isInvalid() || frameEndTimestamp &gt; trackBuffer.highestPresentationTimestamp)
</span><span class="cx">             trackBuffer.highestPresentationTimestamp = frameEndTimestamp;
</span><span class="cx"> 
</span><ins>+        // 1.21 If highest presentation end timestamp is unset or frame end timestamp is greater than highest
+        // presentation end timestamp, then set highest presentation end timestamp equal to frame end timestamp.
+        if (m_highestPresentationEndTimestamp.isInvalid() || frameEndTimestamp &gt; m_highestPresentationEndTimestamp)
+            m_highestPresentationEndTimestamp = frameEndTimestamp;
+
</ins><span class="cx">         m_buffered-&gt;add(presentationTimestamp.toDouble(), (presentationTimestamp + frameDuration + microsecond).toDouble());
</span><span class="cx"> 
</span><span class="cx">         break;
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediasourceSourceBufferh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediasource/SourceBuffer.h (160281 => 160282)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediasource/SourceBuffer.h        2013-12-08 06:39:39 UTC (rev 160281)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBuffer.h        2013-12-08 06:43:27 UTC (rev 160282)
</span><span class="lines">@@ -75,6 +75,7 @@
</span><span class="cx"> 
</span><span class="cx">     void abortIfUpdating();
</span><span class="cx">     void removedFromMediaSource();
</span><ins>+    const MediaTime&amp; highestPresentationEndTimestamp() const { return m_highestPresentationEndTimestamp; }
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><span class="cx">     VideoTrackList* videoTracks();
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLMediaElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (160281 => 160282)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLMediaElement.cpp        2013-12-08 06:39:39 UTC (rev 160281)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp        2013-12-08 06:43:27 UTC (rev 160282)
</span><span class="lines">@@ -1669,9 +1669,9 @@
</span><span class="cx">         renderer()-&gt;updateFromElement();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void HTMLMediaElement::mediaEngineError(PassRefPtr&lt;MediaError&gt; err)
</del><ins>+void HTMLMediaElement::mediaLoadingFailedFatally(MediaPlayer::NetworkState error)
</ins><span class="cx"> {
</span><del>-    LOG(Media, &quot;HTMLMediaElement::mediaEngineError(%d)&quot;, static_cast&lt;int&gt;(err-&gt;code()));
</del><ins>+    LOG(Media, &quot;HTMLMediaElement::mediaLoadingFailedFatally(%d)&quot;, static_cast&lt;int&gt;(error));
</ins><span class="cx"> 
</span><span class="cx">     // 1 - The user agent should cancel the fetching process.
</span><span class="cx">     stopPeriodicTimers();
</span><span class="lines">@@ -1679,7 +1679,12 @@
</span><span class="cx"> 
</span><span class="cx">     // 2 - Set the error attribute to a new MediaError object whose code attribute is 
</span><span class="cx">     // set to MEDIA_ERR_NETWORK/MEDIA_ERR_DECODE.
</span><del>-    m_error = err;
</del><ins>+    if (error == MediaPlayer::NetworkError)
+        m_error = MediaError::create(MediaError::MEDIA_ERR_NETWORK);
+    else if (error == MediaPlayer::DecodeError)
+        m_error = MediaError::create(MediaError::MEDIA_ERR_DECODE);
+    else
+        ASSERT_NOT_REACHED();
</ins><span class="cx"> 
</span><span class="cx">     // 3 - Queue a task to fire a simple event named error at the media element.
</span><span class="cx">     scheduleEvent(eventNames().errorEvent);
</span><span class="lines">@@ -1783,10 +1788,8 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx">     
</span><del>-    if (error == MediaPlayer::NetworkError &amp;&amp; m_readyState &gt;= HAVE_METADATA)
-        mediaEngineError(MediaError::create(MediaError::MEDIA_ERR_NETWORK));
-    else if (error == MediaPlayer::DecodeError)
-        mediaEngineError(MediaError::create(MediaError::MEDIA_ERR_DECODE));
</del><ins>+    if ((error == MediaPlayer::NetworkError &amp;&amp; m_readyState &gt;= HAVE_METADATA) || error == MediaPlayer::DecodeError)
+        mediaLoadingFailedFatally(error);
</ins><span class="cx">     else if ((error == MediaPlayer::FormatError || error == MediaPlayer::NetworkError) &amp;&amp; m_loadState == LoadingFromSrcAttr)
</span><span class="cx">         noneSupported();
</span><span class="cx">     
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLMediaElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (160281 => 160282)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLMediaElement.h        2013-12-08 06:39:39 UTC (rev 160281)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h        2013-12-08 06:43:27 UTC (rev 160282)
</span><span class="lines">@@ -395,6 +395,9 @@
</span><span class="cx"> 
</span><span class="cx">     unsigned long long fileSize() const;
</span><span class="cx"> 
</span><ins>+    void mediaLoadingFailed(MediaPlayer::NetworkState);
+    void mediaLoadingFailedFatally(MediaPlayer::NetworkState);
+
</ins><span class="cx"> protected:
</span><span class="cx">     HTMLMediaElement(const QualifiedName&amp;, Document&amp;, bool);
</span><span class="cx">     virtual ~HTMLMediaElement();
</span><span class="lines">@@ -563,15 +566,12 @@
</span><span class="cx">     void clearMediaPlayer(int flags);
</span><span class="cx">     bool havePotentialSourceChild();
</span><span class="cx">     void noneSupported();
</span><del>-    void mediaEngineError(PassRefPtr&lt;MediaError&gt; err);
</del><span class="cx">     void cancelPendingEventsAndCallbacks();
</span><span class="cx">     void waitForSourceChange();
</span><span class="cx">     void prepareToPlay();
</span><span class="cx"> 
</span><span class="cx">     URL selectNextSourceChild(ContentType*, String* keySystem, InvalidURLAction);
</span><span class="cx"> 
</span><del>-    void mediaLoadingFailed(MediaPlayer::NetworkState);
-
</del><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><span class="cx">     void updateActiveTextTrackCues(double);
</span><span class="cx">     HTMLTrackElement* showingTrackWithSameKind(HTMLTrackElement*) const;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsavfoundationobjcMediaSourcePrivateAVFObjCmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaSourcePrivateAVFObjC.mm (160281 => 160282)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaSourcePrivateAVFObjC.mm        2013-12-08 06:39:39 UTC (rev 160281)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaSourcePrivateAVFObjC.mm        2013-12-08 06:43:27 UTC (rev 160282)
</span><span class="lines">@@ -101,9 +101,10 @@
</span><span class="cx">     m_duration = duration;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void MediaSourcePrivateAVFObjC::markEndOfStream(EndOfStreamStatus) 
</del><ins>+void MediaSourcePrivateAVFObjC::markEndOfStream(EndOfStreamStatus status)
</ins><span class="cx"> {
</span><del>-    // FIXME(125159): implement markEndOfStream()
</del><ins>+    if (status == EosNoError)
+        m_player-&gt;setNetworkState(MediaPlayer::Loaded);
</ins><span class="cx">     m_isEnded = true;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmockmediasourceMockMediaPlayerMediaSourcecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.cpp (160281 => 160282)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.cpp        2013-12-08 06:39:39 UTC (rev 160281)
+++ trunk/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.cpp        2013-12-08 06:43:27 UTC (rev 160282)
</span><span class="lines">@@ -236,6 +236,15 @@
</span><span class="cx">     m_player-&gt;readyStateChanged();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void MockMediaPlayerMediaSource::setNetworkState(MediaPlayer::NetworkState networkState)
+{
+    if (networkState == m_networkState)
+        return;
+
+    m_networkState = networkState;
+    m_player-&gt;networkStateChanged();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+}
+
</ins><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmockmediasourceMockMediaPlayerMediaSourceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.h (160281 => 160282)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.h        2013-12-08 06:39:39 UTC (rev 160281)
+++ trunk/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.h        2013-12-08 06:43:27 UTC (rev 160282)
</span><span class="lines">@@ -51,6 +51,7 @@
</span><span class="cx"> 
</span><span class="cx">     virtual MediaPlayer::ReadyState readyState() const OVERRIDE;
</span><span class="cx">     void setReadyState(MediaPlayer::ReadyState);
</span><ins>+    void setNetworkState(MediaPlayer::NetworkState);
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     MockMediaPlayerMediaSource(MediaPlayer*);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmockmediasourceMockMediaSourcePrivatecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mock/mediasource/MockMediaSourcePrivate.cpp (160281 => 160282)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mock/mediasource/MockMediaSourcePrivate.cpp        2013-12-08 06:39:39 UTC (rev 160281)
+++ trunk/Source/WebCore/platform/mock/mediasource/MockMediaSourcePrivate.cpp        2013-12-08 06:43:27 UTC (rev 160282)
</span><span class="lines">@@ -42,7 +42,7 @@
</span><span class="cx"> 
</span><span class="cx"> MockMediaSourcePrivate::MockMediaSourcePrivate(MockMediaPlayerMediaSource* parent)
</span><span class="cx">     : m_player(parent)
</span><del>-    , m_duration(0)
</del><ins>+    , m_duration(std::numeric_limits&lt;float&gt;::quiet_NaN())
</ins><span class="cx">     , m_isEnded(false)
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="lines">@@ -96,7 +96,8 @@
</span><span class="cx"> 
</span><span class="cx"> void MockMediaSourcePrivate::markEndOfStream(EndOfStreamStatus status)
</span><span class="cx"> {
</span><del>-    UNUSED_PARAM(status);
</del><ins>+    if (status == EosNoError)
+        m_player-&gt;setNetworkState(MediaPlayer::Loaded);
</ins><span class="cx">     m_isEnded = true;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>