<!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>[177225] 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/177225">177225</a></dd>
<dt>Author</dt> <dd>jer.noble@apple.com</dd>
<dt>Date</dt> <dd>2014-12-12 11:27:51 -0800 (Fri, 12 Dec 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>[MSE] Add support for SourceBuffer.mode.
https://bugs.webkit.org/show_bug.cgi?id=139265

Reviewed by Eric Carlson.

Source/WebCore:

Support setting SourceBuffer's mode property, and add support for &quot;sequence&quot; mode. Prior
to this change, &quot;segments&quot; mode was implied.

* Modules/mediasource/MediaSource.cpp:
(WebCore::MediaSource::addSourceBuffer):
(WebCore::MediaSource::regenerateActiveSourceBuffers):
* Modules/mediasource/SourceBuffer.cpp:
(WebCore::SourceBuffer::segmentsKeyword):
(WebCore::SourceBuffer::sequenceKeyword):
(WebCore::SourceBuffer::SourceBuffer):
(WebCore::SourceBuffer::setTimestampOffset):
(WebCore::SourceBuffer::sourceBufferPrivateDidReceiveSample):
(WebCore::SourceBuffer::setMode):
* Modules/mediasource/SourceBuffer.h:
* Modules/mediasource/SourceBuffer.idl:

LayoutTests:

* http/tests/media/media-source/mediasource-util.js:
* platform/mac/TestExpectations:

Add an expected-failure; the test fails due to lack of support for a non-DOM-visible
algorithm variable unsupported by the Mac port.
* platform/mac/http/tests/media/media-source/mediasource-sourcebuffer-mode-expected.txt: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestshttptestsmediamediasourcemediasourceutiljs">trunk/LayoutTests/http/tests/media/media-source/mediasource-util.js</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="#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="#trunkSourceWebCoreModulesmediasourceSourceBufferidl">trunk/Source/WebCore/Modules/mediasource/SourceBuffer.idl</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsplatformmachttptestsmediamediasourcemediasourcesourcebuffermodeexpectedtxt">trunk/LayoutTests/platform/mac/http/tests/media/media-source/mediasource-sourcebuffer-mode-expected.txt</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (177224 => 177225)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-12-12 16:59:16 UTC (rev 177224)
+++ trunk/LayoutTests/ChangeLog        2014-12-12 19:27:51 UTC (rev 177225)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2014-12-12  Jer Noble  &lt;jer.noble@apple.com&gt;
+
+        [MSE] Add support for SourceBuffer.mode.
+        https://bugs.webkit.org/show_bug.cgi?id=139265
+
+        Reviewed by Eric Carlson.
+
+        * http/tests/media/media-source/mediasource-util.js:
+        * platform/mac/TestExpectations:
+
+        Add an expected-failure; the test fails due to lack of support for a non-DOM-visible
+        algorithm variable unsupported by the Mac port.
+        * platform/mac/http/tests/media/media-source/mediasource-sourcebuffer-mode-expected.txt: Added.
+
</ins><span class="cx"> 2014-12-12  Radu Stavila  &lt;stavila@adobe.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [SVG Masking] Enable the use of &lt;mask&gt; elements for -webkit-mask-image
</span></span></pre></div>
<a id="trunkLayoutTestshttptestsmediamediasourcemediasourceutiljs"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/http/tests/media/media-source/mediasource-util.js (177224 => 177225)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/media/media-source/mediasource-util.js        2014-12-12 16:59:16 UTC (rev 177224)
+++ trunk/LayoutTests/http/tests/media/media-source/mediasource-util.js        2014-12-12 19:27:51 UTC (rev 177225)
</span><span class="lines">@@ -28,18 +28,18 @@
</span><span class="cx">         },
</span><span class="cx">         {
</span><span class="cx">             url: 'mp4/test.mp4',
</span><del>-            type: 'video/mp4; codecs=&quot;mp4a.40.2, avc1.4D401E&quot;',
</del><ins>+            type: 'video/mp4; codecs=&quot;mp4a.40.2,avc1.4d400d&quot;',
</ins><span class="cx">             duration: 6.0424,
</span><span class="cx">             init: { offset: 0, size: 1279 },
</span><span class="cx">             media: [
</span><del>-                {  offset: 1406, size: 23863, timecode: 0 },
-                {  offset: 25270, size: 25435, timecode: 0.797 },
-                {  offset: 50705, size: 24796, timecode: 1.594 },
-                {  offset: 75501, size: 25167, timecode: 2.390 },
-                {  offset: 100668, size: 22976, timecode: 3.187 },
-                {  offset: 123644, size: 25030, timecode: 3.984},
-                {  offset: 148674, size: 24929, timecode: 4.781 },
-                {  offset: 173603, size: 19271, timecode: 5.578 },
</del><ins>+                {  offset: 1407, size: 23863, timecode: 0 },
+                {  offset: 25270, size: 25435, timecode: 0.7968 },
+                {  offset: 50705, size: 24796, timecode: 1.5936 },
+                {  offset: 75501, size: 25167, timecode: 2.3904 },
+                {  offset: 100668, size: 22976, timecode: 3.1872 },
+                {  offset: 123644, size: 25030, timecode: 3.984 },
+                {  offset: 148674, size: 24929, timecode: 4.7808 },
+                {  offset: 173603, size: 19271, timecode: 5.5776 },
</ins><span class="cx">             ],
</span><span class="cx">         }
</span><span class="cx">     ];
</span></span></pre></div>
<a id="trunkLayoutTestsplatformmacTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/mac/TestExpectations (177224 => 177225)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac/TestExpectations        2014-12-12 16:59:16 UTC (rev 177224)
+++ trunk/LayoutTests/platform/mac/TestExpectations        2014-12-12 19:27:51 UTC (rev 177225)
</span><span class="lines">@@ -1249,6 +1249,7 @@
</span><span class="cx"> [ Yosemite+ ] http/tests/media/media-source/mediasource-play.html [ Pass ]
</span><span class="cx"> [ Yosemite+ ] http/tests/media/media-source/mediasource-remove.html [ Pass ]
</span><span class="cx"> [ Yosemite+ ] http/tests/media/media-source/mediasource-sourcebufferlist.html [ Pass ]
</span><ins>+[ Yosemite+ ] http/tests/media/media-source/mediasource-sourcebuffer-mode.html [ Pass ]
</ins><span class="cx"> 
</span><span class="cx"> # These two tests have &quot;Error: InvalidStateError: DOM Exception 11&quot; in output.
</span><span class="cx"> [ Yosemite+ ] media/media-source/media-source-duplicate-seeked.html [ Failure ]
</span></span></pre></div>
<a id="trunkLayoutTestsplatformmachttptestsmediamediasourcemediasourcesourcebuffermodeexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/platform/mac/http/tests/media/media-source/mediasource-sourcebuffer-mode-expected.txt (0 => 177225)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac/http/tests/media/media-source/mediasource-sourcebuffer-mode-expected.txt                                (rev 0)
+++ trunk/LayoutTests/platform/mac/http/tests/media/media-source/mediasource-sourcebuffer-mode-expected.txt        2014-12-12 19:27:51 UTC (rev 177225)
</span><span class="lines">@@ -0,0 +1,14 @@
</span><ins>+ 
+PASS Test initial value of SourceBuffer.mode is &quot;segments&quot; 
+PASS Test setting SourceBuffer.mode 
+PASS Test setting a removed SourceBuffer's mode 
+PASS Test setting SourceBuffer.mode while still updating 
+PASS Test setting SourceBuffer.mode triggers parent MediaSource 'ended' to 'open' transition. 
+FAIL Test setting SourceBuffer.mode and SourceBuffer.timestampOffset while parsing media segment. assert_throws: Setting valid sourceBuffer.mode while still parsing media segment threw InvalidStateError. function &quot;function () { sourceBuffer.mode = 'segments'; }&quot; did not throw(stack: assert@http://127.0.0.1:8000/w3c/resources/testharness.js:2060:73
+assert_throws@http://127.0.0.1:8000/w3c/resources/testharness.js:946:19
+http://127.0.0.1:8000/media/media-source/mediasource-sourcebuffer-mode.html:114:32
+handleWaitCallback_@http://127.0.0.1:8000/media/media-source/mediasource-util.js:97:17
+[native code]
+step@http://127.0.0.1:8000/w3c/resources/testharness.js:1159:30
+http://127.0.0.1:8000/w3c/resources/testharness.js:1188:33)
+
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (177224 => 177225)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-12-12 16:59:16 UTC (rev 177224)
+++ trunk/Source/WebCore/ChangeLog        2014-12-12 19:27:51 UTC (rev 177225)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+2014-12-12  Jer Noble  &lt;jer.noble@apple.com&gt;
+
+        [MSE] Add support for SourceBuffer.mode.
+        https://bugs.webkit.org/show_bug.cgi?id=139265
+
+        Reviewed by Eric Carlson.
+
+        Support setting SourceBuffer's mode property, and add support for &quot;sequence&quot; mode. Prior
+        to this change, &quot;segments&quot; mode was implied.
+
+        * Modules/mediasource/MediaSource.cpp:
+        (WebCore::MediaSource::addSourceBuffer):
+        (WebCore::MediaSource::regenerateActiveSourceBuffers):
+        * Modules/mediasource/SourceBuffer.cpp:
+        (WebCore::SourceBuffer::segmentsKeyword):
+        (WebCore::SourceBuffer::sequenceKeyword):
+        (WebCore::SourceBuffer::SourceBuffer):
+        (WebCore::SourceBuffer::setTimestampOffset):
+        (WebCore::SourceBuffer::sourceBufferPrivateDidReceiveSample):
+        (WebCore::SourceBuffer::setMode):
+        * Modules/mediasource/SourceBuffer.h:
+        * Modules/mediasource/SourceBuffer.idl:
+
</ins><span class="cx"> 2014-12-12  Radu Stavila  &lt;stavila@adobe.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [SVG Masking] Enable the use of &lt;mask&gt; elements for -webkit-mask-image
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediasourceMediaSourcecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp (177224 => 177225)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp        2014-12-12 16:59:16 UTC (rev 177224)
+++ trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp        2014-12-12 19:27:51 UTC (rev 177225)
</span><span class="lines">@@ -1,5 +1,6 @@
</span><span class="cx"> /*
</span><span class="cx">  * Copyright (C) 2013 Google Inc. All rights reserved.
</span><ins>+ * Copyright (C) 2013-2014 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions are
</span><span class="lines">@@ -504,7 +505,9 @@
</span><span class="cx"> {
</span><span class="cx">     LOG(MediaSource, &quot;MediaSource::addSourceBuffer(%s) %p&quot;, type.ascii().data(), this);
</span><span class="cx"> 
</span><del>-    // 2.2 https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#widl-MediaSource-addSourceBuffer-SourceBuffer-DOMString-type
</del><ins>+    // 2.2 http://www.w3.org/TR/media-source/#widl-MediaSource-addSourceBuffer-SourceBuffer-DOMString-type
+    // When this method is invoked, the user agent must run the following steps:
+
</ins><span class="cx">     // 1. If type is null or an empty then throw an INVALID_ACCESS_ERR exception and
</span><span class="cx">     // abort these steps.
</span><span class="cx">     if (type.isNull() || type.isEmpty()) {
</span><span class="lines">@@ -538,11 +541,25 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     RefPtr&lt;SourceBuffer&gt; buffer = SourceBuffer::create(sourceBufferPrivate.releaseNonNull(), this);
</span><del>-    // 6. Add the new object to sourceBuffers and fire a addsourcebuffer on that object.
</del><ins>+
+    // 6. Set the generate timestamps flag on the new object to the value in the &quot;Generate Timestamps Flag&quot;
+    // column of the byte stream format registry [MSE-REGISTRY] entry that is associated with type.
+    // NOTE: In the current byte stream format registry &lt;http://www.w3.org/2013/12/byte-stream-format-registry/&gt;
+    // only the &quot;MPEG Audio Byte Stream Format&quot; has the &quot;Generate Timestamps Flag&quot; value set.
+    bool shouldGenerateTimestamps = contentType.type() == &quot;audio/aac&quot; || contentType.type() == &quot;audio/mpeg&quot;;
+    buffer-&gt;setShouldGenerateTimestamps(shouldGenerateTimestamps);
+
+    // 7. If the generate timestamps flag equals true:
+    // ↳ Set the mode attribute on the new object to &quot;sequence&quot;.
+    // Otherwise:
+    // ↳ Set the mode attribute on the new object to &quot;segments&quot;.
+    buffer-&gt;setMode(shouldGenerateTimestamps ? SourceBuffer::sequenceKeyword() : SourceBuffer::segmentsKeyword(), IGNORE_EXCEPTION);
+
+    // 8. Add the new object to sourceBuffers and fire a addsourcebuffer on that object.
</ins><span class="cx">     m_sourceBuffers-&gt;add(buffer);
</span><span class="cx">     regenerateActiveSourceBuffers();
</span><span class="cx"> 
</span><del>-    // 7. Return the new object to the caller.
</del><ins>+    // 9. Return the new object to the caller.
</ins><span class="cx">     return buffer.get();
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediasourceSourceBuffercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp (177224 => 177225)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp        2014-12-12 16:59:16 UTC (rev 177224)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp        2014-12-12 19:27:51 UTC (rev 177225)
</span><span class="lines">@@ -71,6 +71,18 @@
</span><span class="cx">     return fudgeFactor;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+const AtomicString&amp; SourceBuffer::segmentsKeyword()
+{
+    static NeverDestroyed&lt;AtomicString&gt; segments(&quot;segments&quot;);
+    return segments.get();
+}
+
+const AtomicString&amp; SourceBuffer::sequenceKeyword()
+{
+    static NeverDestroyed&lt;AtomicString&gt; segments(&quot;sequence&quot;);
+    return segments.get();
+}
+
</ins><span class="cx"> struct SourceBuffer::TrackBuffer {
</span><span class="cx">     MediaTime lastDecodeTimestamp;
</span><span class="cx">     MediaTime lastFrameDuration;
</span><span class="lines">@@ -109,8 +121,10 @@
</span><span class="cx">     , m_private(WTF::move(sourceBufferPrivate))
</span><span class="cx">     , m_source(source)
</span><span class="cx">     , m_asyncEventQueue(*this)
</span><ins>+    , m_mode(segmentsKeyword())
</ins><span class="cx">     , m_appendBufferTimer(*this, &amp;SourceBuffer::appendBufferTimerFired)
</span><del>-    , m_highestPresentationEndTimestamp(MediaTime::invalidTime())
</del><ins>+    , m_groupStartTimestamp(MediaTime::invalidTime())
+    , m_groupEndTimestamp(MediaTime::zeroTime())
</ins><span class="cx">     , m_buffered(TimeRanges::create())
</span><span class="cx">     , m_appendState(WaitingForSegment)
</span><span class="cx">     , m_timeOfBufferingMonitor(monotonicallyIncreasingTime())
</span><span class="lines">@@ -124,6 +138,7 @@
</span><span class="cx">     , m_receivedFirstInitializationSegment(false)
</span><span class="cx">     , m_active(false)
</span><span class="cx">     , m_bufferFull(false)
</span><ins>+    , m_shouldGenerateTimestamps(false)
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(m_source);
</span><span class="cx"> 
</span><span class="lines">@@ -186,9 +201,14 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    // FIXME: Add step 6 text when mode attribute is implemented.
</del><ins>+    MediaTime newTimestampOffset = MediaTime::createWithDouble(offset);
+
+    // 6. If the mode attribute equals &quot;sequence&quot;, then set the group start timestamp to new timestamp offset.
+    if (m_mode == sequenceKeyword())
+        m_groupStartTimestamp = newTimestampOffset;
+
</ins><span class="cx">     // 7. Update the attribute to the new value.
</span><del>-    m_timestampOffset = MediaTime::createWithDouble(offset);
</del><ins>+    m_timestampOffset = newTimestampOffset;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void SourceBuffer::appendBuffer(PassRefPtr&lt;ArrayBuffer&gt; data, ExceptionCode&amp; ec)
</span><span class="lines">@@ -1197,95 +1217,126 @@
</span><span class="cx">     RefPtr&lt;MediaSample&gt; sample = prpSample;
</span><span class="cx"> 
</span><span class="cx">     // 3.5.8 Coded Frame Processing
</span><ins>+    // http://www.w3.org/TR/media-source/#sourcebuffer-coded-frame-processing
+
</ins><span class="cx">     // When complete coded frames have been parsed by the segment parser loop then the following steps
</span><span class="cx">     // are run:
</span><span class="cx">     // 1. For each coded frame in the media segment run the following steps:
</span><span class="cx">     // 1.1. Loop Top
</span><span class="cx">     do {
</span><del>-        // 1.1 (ctd) Let presentation timestamp be a double precision floating point representation of
-        // the coded frame's presentation timestamp in seconds.
-        MediaTime presentationTimestamp = sample-&gt;presentationTime();
</del><ins>+        MediaTime presentationTimestamp;
+        MediaTime decodeTimestamp;
</ins><span class="cx"> 
</span><del>-        // 1.2 Let decode timestamp be a double precision floating point representation of the coded frame's
-        // decode timestamp in seconds.
-        MediaTime decodeTimestamp = sample-&gt;decodeTime();
</del><ins>+        if (m_shouldGenerateTimestamps) {
+            // ↳ If generate timestamps flag equals true:
+            // 1. Let presentation timestamp equal 0.
+            presentationTimestamp = MediaTime::zeroTime();
</ins><span class="cx"> 
</span><del>-        // 1.3 Let frame duration be a double precision floating point representation of the coded frame's
</del><ins>+            // 2. Let decode timestamp equal 0.
+            decodeTimestamp = MediaTime::zeroTime();
+        } else {
+            // ↳ Otherwise:
+            // 1. Let presentation timestamp be a double precision floating point representation of
+            // the coded frame's presentation timestamp in seconds.
+            presentationTimestamp = sample-&gt;presentationTime();
+
+            // 2. Let decode timestamp be a double precision floating point representation of the coded frame's
+            // decode timestamp in seconds.
+            decodeTimestamp = sample-&gt;decodeTime();
+        }
+
+        // 1.2 Let frame duration be a double precision floating point representation of the coded frame's
</ins><span class="cx">         // duration in seconds.
</span><span class="cx">         MediaTime frameDuration = sample-&gt;duration();
</span><span class="cx"> 
</span><del>-        // 1.4 If mode equals &quot;sequence&quot; and group start timestamp is set, then run the following steps:
-        // FIXME: add support for &quot;sequence&quot; mode
</del><ins>+        // 1.3 If mode equals &quot;sequence&quot; and group start timestamp is set, then run the following steps:
+        if (m_mode == sequenceKeyword()) {
+            // 1.3.1 Set timestampOffset equal to group start timestamp - presentation timestamp.
+            m_timestampOffset = m_groupStartTimestamp;
</ins><span class="cx"> 
</span><del>-        // 1.5 If timestampOffset is not 0, then run the following steps:
</del><ins>+            // 1.3.2 Set group end timestamp equal to group start timestamp.
+            m_groupEndTimestamp = m_groupStartTimestamp;
+
+            // 1.3.3 Set the need random access point flag on all track buffers to true.
+            for (auto&amp; trackBuffer : m_trackBufferMap.values())
+                trackBuffer.needRandomAccessFlag = true;
+
+            // 1.3.4 Unset group start timestamp.
+            m_groupStartTimestamp = MediaTime::invalidTime();
+        }
+
+        // 1.4 If timestampOffset is not 0, then run the following steps:
</ins><span class="cx">         if (m_timestampOffset) {
</span><del>-            // 1.5.1 Add timestampOffset to the presentation timestamp.
</del><ins>+            // 1.4.1 Add timestampOffset to the presentation timestamp.
</ins><span class="cx">             presentationTimestamp += m_timestampOffset;
</span><span class="cx"> 
</span><del>-            // 1.5.2 Add timestampOffset to the decode timestamp.
</del><ins>+            // 1.4.2 Add timestampOffset to the decode timestamp.
</ins><span class="cx">             decodeTimestamp += m_timestampOffset;
</span><del>-
-            // 1.5.3 If the presentation timestamp or decode timestamp is less than the presentation start
-            // time, then run the end of stream algorithm with the error parameter set to &quot;decode&quot;, and
-            // abort these steps.
-            MediaTime presentationStartTime = MediaTime::zeroTime();
-            if (presentationTimestamp &lt; presentationStartTime || decodeTimestamp &lt; presentationStartTime) {
-#if !LOG_DISABLED
-                LOG(MediaSource, &quot;SourceBuffer::sourceBufferPrivateDidReceiveSample(%p) - failing because %s&quot;, this, presentationTimestamp &lt; presentationStartTime ? &quot;presentationTimestamp &lt; presentationStartTime&quot; : &quot;decodeTimestamp &lt; presentationStartTime&quot;);
-#endif
-                m_source-&gt;streamEndedWithError(decodeError(), IgnorableExceptionCode());
-                return;
-            }
</del><span class="cx">         }
</span><span class="cx"> 
</span><del>-        // 1.6 Let track buffer equal the track buffer that the coded frame will be added to.
</del><ins>+        // 1.5 Let track buffer equal the track buffer that the coded frame will be added to.
</ins><span class="cx">         AtomicString trackID = sample-&gt;trackID();
</span><span class="cx">         auto it = m_trackBufferMap.find(trackID);
</span><span class="cx">         if (it == m_trackBufferMap.end())
</span><span class="cx">             it = m_trackBufferMap.add(trackID, TrackBuffer()).iterator;
</span><span class="cx">         TrackBuffer&amp; trackBuffer = it-&gt;value;
</span><span class="cx"> 
</span><del>-        // 1.7 If last decode timestamp for track buffer is set and decode timestamp is less than last
</del><ins>+        // 1.6 ↳ If last decode timestamp for track buffer is set and decode timestamp is less than last
</ins><span class="cx">         // decode timestamp:
</span><span class="cx">         // OR
</span><del>-        // If last decode timestamp for track buffer is set and the difference between decode timestamp and
</del><ins>+        // ↳ If last decode timestamp for track buffer is set and the difference between decode timestamp and
</ins><span class="cx">         // last decode timestamp is greater than 2 times last frame duration:
</span><span class="cx">         if (trackBuffer.lastDecodeTimestamp.isValid() &amp;&amp; (decodeTimestamp &lt; trackBuffer.lastDecodeTimestamp
</span><span class="cx">             || abs(decodeTimestamp - trackBuffer.lastDecodeTimestamp) &gt; (trackBuffer.lastFrameDuration * 2))) {
</span><del>-            // 1.7.1 If mode equals &quot;segments&quot;:
-            // Set highest presentation end timestamp to presentation timestamp.
-            m_highestPresentationEndTimestamp = presentationTimestamp;
</del><span class="cx"> 
</span><del>-            // If mode equals &quot;sequence&quot;:
-            // Set group start timestamp equal to the highest presentation end timestamp.
-            // FIXME: Add support for &quot;sequence&quot; mode.
</del><ins>+            // 1.6.1:
+            if (m_mode == segmentsKeyword()) {
+                // ↳ If mode equals &quot;segments&quot;:
+                // Set group end timestamp to presentation timestamp.
+                m_groupEndTimestamp = presentationTimestamp;
+            } else if (m_mode == sequenceKeyword()) {
+                // ↳ If mode equals &quot;sequence&quot;:
+                // Set group start timestamp equal to the group end timestamp.
+                m_groupStartTimestamp = m_groupEndTimestamp;
+            }
</ins><span class="cx"> 
</span><span class="cx">             for (auto&amp; trackBuffer : m_trackBufferMap.values()) {
</span><del>-                // 1.7.2 Unset the last decode timestamp on all track buffers.
</del><ins>+                // 1.6.2 Unset the last decode timestamp on all track buffers.
</ins><span class="cx">                 trackBuffer.lastDecodeTimestamp = MediaTime::invalidTime();
</span><del>-                // 1.7.3 Unset the last frame duration on all track buffers.
</del><ins>+                // 1.6.3 Unset the last frame duration on all track buffers.
</ins><span class="cx">                 trackBuffer.lastFrameDuration = MediaTime::invalidTime();
</span><del>-                // 1.7.4 Unset the highest presentation timestamp on all track buffers.
</del><ins>+                // 1.6.4 Unset the highest presentation timestamp on all track buffers.
</ins><span class="cx">                 trackBuffer.highestPresentationTimestamp = MediaTime::invalidTime();
</span><del>-                // 1.7.5 Set the need random access point flag on all track buffers to true.
</del><ins>+                // 1.6.5 Set the need random access point flag on all track buffers to true.
</ins><span class="cx">                 trackBuffer.needRandomAccessFlag = true;
</span><span class="cx">             }
</span><span class="cx"> 
</span><del>-            // 1.7.6 Jump to the Loop Top step above to restart processing of the current coded frame.
</del><ins>+            // 1.6.6 Jump to the Loop Top step above to restart processing of the current coded frame.
</ins><span class="cx">             continue;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        // 1.8 Let frame end timestamp equal the sum of presentation timestamp and frame duration.
</del><ins>+        // 1.7 Let frame end timestamp equal the sum of presentation timestamp and frame duration.
</ins><span class="cx">         MediaTime frameEndTimestamp = presentationTimestamp + frameDuration;
</span><span class="cx"> 
</span><del>-        // 1.9 If presentation timestamp is less than appendWindowStart, then set the need random access
</del><ins>+        // 1.8 If presentation timestamp is less than appendWindowStart, then set the need random access
</ins><span class="cx">         // point flag to true, drop the coded frame, and jump to the top of the loop to start processing
</span><span class="cx">         // the next coded frame.
</span><del>-        // 1.10 If frame end timestamp is greater than appendWindowEnd, then set the need random access
</del><ins>+        // 1.9 If frame end timestamp is greater than appendWindowEnd, then set the need random access
</ins><span class="cx">         // point flag to true, drop the coded frame, and jump to the top of the loop to start processing
</span><span class="cx">         // the next coded frame.
</span><span class="cx">         // FIXME: implement append windows
</span><span class="cx"> 
</span><ins>+        // 1.10 If the decode timestamp is less than the presentation start time, then run the end of stream
+        // algorithm with the error parameter set to &quot;decode&quot;, and abort these steps.
+        // NOTE: Until &lt;https://www.w3.org/Bugs/Public/show_bug.cgi?id=27487&gt; is resolved, we will only check
+        // the presentation timestamp.
+        MediaTime presentationStartTime = MediaTime::zeroTime();
+        if (presentationTimestamp &lt; presentationStartTime) {
+            LOG(MediaSource, &quot;SourceBuffer::sourceBufferPrivateDidReceiveSample(%p) - failing because presentationTimestamp &lt; presentationStartTime&quot;, this);
+            m_source-&gt;streamEndedWithError(decodeError(), IgnorableExceptionCode());
+            return;
+        }
+
</ins><span class="cx">         // 1.11 If the need random access point flag on track buffer equals true, then run the following steps:
</span><span class="cx">         if (trackBuffer.needRandomAccessFlag) {
</span><span class="cx">             // 1.11.1 If the coded frame is not a random access point, then drop the coded frame and jump
</span><span class="lines">@@ -1352,7 +1403,7 @@
</span><span class="cx">                 erasedSamples.addRange(iter_pair.first, iter_pair.second);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        // If highest presentation timestamp for track buffer is set and less than presentation timestamp
</del><ins>+        // If highest presentation timestamp for track buffer is set and less than or equal to presentation timestamp
</ins><span class="cx">         if (trackBuffer.highestPresentationTimestamp.isValid() &amp;&amp; trackBuffer.highestPresentationTimestamp &lt;= presentationTimestamp) {
</span><span class="cx">             // Remove all coded frames from track buffer that have a presentation timestamp greater than highest
</span><span class="cx">             // presentation timestamp and less than or equal to frame end timestamp.
</span><span class="lines">@@ -1367,8 +1418,7 @@
</span><span class="cx">                 if (!bufferedLength)
</span><span class="cx">                     break;
</span><span class="cx"> 
</span><del>-                bool ignoreValid;
-                MediaTime highestBufferedTime = m_buffered-&gt;ranges().end(bufferedLength - 1, ignoreValid);
</del><ins>+                MediaTime highestBufferedTime = m_buffered-&gt;ranges().maximumBufferedTime();
</ins><span class="cx"> 
</span><span class="cx">                 PresentationOrderSampleMap::iterator_range range;
</span><span class="cx">                 if (highestBufferedTime - trackBuffer.highestPresentationTimestamp &lt; trackBuffer.lastFrameDuration)
</span><span class="lines">@@ -1437,11 +1487,15 @@
</span><span class="cx">         if (trackBuffer.highestPresentationTimestamp.isInvalid() || frameEndTimestamp &gt; trackBuffer.highestPresentationTimestamp)
</span><span class="cx">             trackBuffer.highestPresentationTimestamp = frameEndTimestamp;
</span><span class="cx"> 
</span><del>-        // 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;
</del><ins>+        // 1.21 If frame end timestamp is greater than group end timestamp, then set group end timestamp equal
+        // to frame end timestamp.
+        if (m_groupEndTimestamp.isInvalid() || frameEndTimestamp &gt; m_groupEndTimestamp)
+            m_groupEndTimestamp = frameEndTimestamp;
</ins><span class="cx"> 
</span><ins>+        // 1.22 If generate timestamps flag equals true, then set timestampOffset equal to frame end timestamp.
+        if (m_shouldGenerateTimestamps)
+            m_timestampOffset = frameEndTimestamp;
+
</ins><span class="cx">         m_buffered-&gt;add(presentationTimestamp.toDouble(), (presentationTimestamp + frameDuration + microsecond).toDouble());
</span><span class="cx">         m_bufferedSinceLastMonitor += frameDuration.toDouble();
</span><span class="cx"> 
</span><span class="lines">@@ -1451,9 +1505,9 @@
</span><span class="cx">     // Steps 2-4 will be handled by MediaSource::monitorSourceBuffers()
</span><span class="cx"> 
</span><span class="cx">     // 5. If the media segment contains data beyond the current duration, then run the duration change algorithm with new
</span><del>-    // duration set to the maximum of the current duration and the highest end timestamp reported by HTMLMediaElement.buffered.
-    if (highestPresentationEndTimestamp() &gt; m_source-&gt;duration())
-        m_source-&gt;setDurationInternal(highestPresentationEndTimestamp());
</del><ins>+    // duration set to the maximum of the current duration and the group end timestamp.
+    if (m_groupEndTimestamp &gt; m_source-&gt;duration())
+        m_source-&gt;setDurationInternal(m_groupEndTimestamp);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool SourceBuffer::hasAudio() const
</span><span class="lines">@@ -1826,6 +1880,48 @@
</span><span class="cx">     return downcast&lt;Document&gt;(*scriptExecutionContext());
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void SourceBuffer::setMode(const AtomicString&amp; newMode, ExceptionCode&amp; ec)
+{
+    // 3.1 Attributes - mode
+    // http://www.w3.org/TR/media-source/#widl-SourceBuffer-mode
+
+    // On setting, run the following steps:
+
+    // 1. Let new mode equal the new value being assigned to this attribute.
+    // 2. If generate timestamps flag equals true and new mode equals &quot;segments&quot;, then throw an INVALID_ACCESS_ERR exception and abort these steps.
+    if (m_shouldGenerateTimestamps &amp;&amp; newMode == segmentsKeyword()) {
+        ec = INVALID_ACCESS_ERR;
+        return;
+    }
+
+    // 3. If this object has been removed from the sourceBuffers attribute of the parent media source, then throw an INVALID_STATE_ERR exception and abort these steps.
+    // 4. If the updating attribute equals true, then throw an INVALID_STATE_ERR exception and abort these steps.
+    if (isRemoved() || m_updating) {
+        ec = INVALID_STATE_ERR;
+        return;
+    }
+
+    // 5. If the readyState attribute of the parent media source is in the &quot;ended&quot; state then run the following steps:
+    if (m_source-&gt;readyState() == MediaSource::endedKeyword()) {
+        // 5.1. Set the readyState attribute of the parent media source to &quot;open&quot;
+        // 5.2. Queue a task to fire a simple event named sourceopen at the parent media source.
+        m_source-&gt;openIfInEndedState();
+    }
+
+    // 6. If the append state equals PARSING_MEDIA_SEGMENT, then throw an INVALID_STATE_ERR and abort these steps.
+    if (m_appendState == ParsingMediaSegment) {
+        ec = INVALID_STATE_ERR;
+        return;
+    }
+
+    // 7. If the new mode equals &quot;sequence&quot;, then set the group start timestamp to the group end timestamp.
+    if (newMode == sequenceKeyword())
+        m_groupStartTimestamp = m_groupEndTimestamp;
+
+    // 8. Update the attribute to new mode.
+    m_mode = newMode;
+}
+
</ins><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediasourceSourceBufferh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediasource/SourceBuffer.h (177224 => 177225)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediasource/SourceBuffer.h        2014-12-12 16:59:16 UTC (rev 177224)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBuffer.h        2014-12-12 19:27:51 UTC (rev 177225)
</span><span class="lines">@@ -63,6 +63,9 @@
</span><span class="cx"> public:
</span><span class="cx">     static PassRef&lt;SourceBuffer&gt; create(PassRef&lt;SourceBufferPrivate&gt;, MediaSource*);
</span><span class="cx"> 
</span><ins>+    static const AtomicString&amp; segmentsKeyword();
+    static const AtomicString&amp; sequenceKeyword();
+
</ins><span class="cx">     virtual ~SourceBuffer();
</span><span class="cx"> 
</span><span class="cx">     // SourceBuffer.idl methods
</span><span class="lines">@@ -79,7 +82,6 @@
</span><span class="cx"> 
</span><span class="cx">     void abortIfUpdating();
</span><span class="cx">     void removedFromMediaSource();
</span><del>-    const MediaTime&amp; highestPresentationEndTimestamp() const { return m_highestPresentationEndTimestamp; }
</del><span class="cx">     void seekToTime(const MediaTime&amp;);
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><span class="lines">@@ -112,6 +114,12 @@
</span><span class="cx"> 
</span><span class="cx">     Document&amp; document() const;
</span><span class="cx"> 
</span><ins>+    const AtomicString&amp; mode() const { return m_mode; }
+    void setMode(const AtomicString&amp;, ExceptionCode&amp;);
+
+    bool shouldGenerateTimestamps() const { return m_shouldGenerateTimestamps; }
+    void setShouldGenerateTimestamps(bool flag) { m_shouldGenerateTimestamps = flag; }
+
</ins><span class="cx"> protected:
</span><span class="cx">     // EventTarget interface
</span><span class="cx">     virtual void refEventTarget() override { ref(); }
</span><span class="lines">@@ -182,6 +190,7 @@
</span><span class="cx">     Ref&lt;SourceBufferPrivate&gt; m_private;
</span><span class="cx">     MediaSource* m_source;
</span><span class="cx">     GenericEventQueue m_asyncEventQueue;
</span><ins>+    AtomicString m_mode;
</ins><span class="cx"> 
</span><span class="cx">     Vector&lt;unsigned char&gt; m_pendingAppendData;
</span><span class="cx">     Timer m_appendBufferTimer;
</span><span class="lines">@@ -195,7 +204,8 @@
</span><span class="cx">     Vector&lt;AtomicString&gt; m_textCodecs;
</span><span class="cx"> 
</span><span class="cx">     MediaTime m_timestampOffset;
</span><del>-    MediaTime m_highestPresentationEndTimestamp;
</del><ins>+    MediaTime m_groupStartTimestamp;
+    MediaTime m_groupEndTimestamp;
</ins><span class="cx"> 
</span><span class="cx">     HashMap&lt;AtomicString, TrackBuffer&gt; m_trackBufferMap;
</span><span class="cx">     RefPtr&lt;TimeRanges&gt; m_buffered;
</span><span class="lines">@@ -217,6 +227,7 @@
</span><span class="cx">     bool m_receivedFirstInitializationSegment;
</span><span class="cx">     bool m_active;
</span><span class="cx">     bool m_bufferFull;
</span><ins>+    bool m_shouldGenerateTimestamps;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediasourceSourceBufferidl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediasource/SourceBuffer.idl (177224 => 177225)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediasource/SourceBuffer.idl        2014-12-12 16:59:16 UTC (rev 177224)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBuffer.idl        2014-12-12 19:27:51 UTC (rev 177225)
</span><span class="lines">@@ -28,6 +28,11 @@
</span><span class="cx">  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</span><span class="cx">  */
</span><span class="cx">  
</span><ins>+[Conditional=MEDIA_SOURCE] enum AppendMode {
+    &quot;segments&quot;,
+    &quot;sequence&quot;
+};
+
</ins><span class="cx"> [
</span><span class="cx">     Conditional=MEDIA_SOURCE,
</span><span class="cx">     NoInterfaceObject,
</span><span class="lines">@@ -37,6 +42,8 @@
</span><span class="cx">     JSGenerateToNativeObject,
</span><span class="cx"> ] interface SourceBuffer : EventTarget {
</span><span class="cx"> 
</span><ins>+    [SetterRaisesException] attribute AppendMode mode;
+
</ins><span class="cx">     readonly attribute boolean updating;
</span><span class="cx">   
</span><span class="cx">     // Returns the time ranges buffered.
</span></span></pre>
</div>
</div>

</body>
</html>