Update Media Source Extensions to object-oriented API.
--- a/media-source/media-source.html Fri Jun 29 08:24:15 2012 -0400
+++ b/media-source/media-source.html Mon Jul 02 16:05:53 2012 -0700
@@ -42,13 +42,12 @@
<div class="head">
<p><a href="http://www.w3.org/"><img src="http://www.w3.org/Icons/w3c_home" alt="W3C" width="72" height="48"></a></p>
<h1>Media Source Extensions</h1>
- <h2>W3C Editor's Draft 26 June 2012</h2>
+ <h2>W3C Editor's Draft 02 July 2012</h2>
<dl>
<dt>Latest published version:</dt>
<dd>Not yet published</dd>
<dt>Latest editor's draft:</dt>
<dd><a href="http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html">http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html</a></dd>
-
<dt>Editors:</dt>
<dd>Aaron Colwell, Google, Inc.</dd>
<dd>Adrian Bateman, Microsoft Corporation</dd>
@@ -114,10 +113,10 @@
<li><a href="#definitions">1.2 Definitions</a></li>
</ul>
</li>
- <li><a href="#source-buffer-model">2 Source Buffer Model</a></li>
+ <li><a href="#source-buffer-model">2. Source Buffer Model</a></li>
<li>
<ul>
- <li><a href="#source-buffer-add-id">2.1. Adding a new Source ID</a></li>
+ <li><a href="#source-buffer-create">2.1. Creating Source Buffers</a></li>
<li><a href="#source-buffer-basic-append">2.2. Basic appending model</a></li>
<li><a href="#source-buffer-init-segment-constraints">2.3. Initialization Segment constraints</a></li>
<li><a href="#source-buffer-media-segment-constraints">2.4. Media Segment constraints</a></li>
@@ -126,18 +125,24 @@
<li><a href="#source-buffer-overlapping-segments">2.7. Appending a Media Segment over a buffered region</a></li>
<li><a href="#source-buffer-to-track-buffer">2.8. Source Buffer to Track Buffer transfer</a></li>
<li><a href="#source-buffer-segment-eviction">2.9. Media Segment Eviction</a></li>
- <li><a href="#source-buffer-remove-id">2.10. Removing a Source ID</a></li>
+ <li><a href="#source-buffer-remove">2.10. Removing Source Buffers</a></li>
</ul>
</li>
<li>
-<a href="#mediasource">3. Media Element Extensions</a>
- <li><a href="#event-summary">4. Event Summary</a></li>
- <li><a href="#algorithms">5. Algorithms</a></li>
- <ul style="list-style-type:none">
- <li><a href="#algorithms-attach">5.1 Attaching to a media element</a></li>
- <li><a href="#algorithms-detach">5.2 Detaching from a media element</a></li>
- <li><a href="#seeking">5.3 Seeking</a></li>
- </ul>
+<a href="#mediasource">3. MediaSource Object</a>
+ <ul>
+ <li><a href="#mediasource-methods">3.1. Methods and Attributes</a></li>
+ <li><a href="#mediasource-events">3.2. Event Summary</a></li>
+ <li><a href="#mediasource-algorithms">3.3. Algorithms</a></li>
+ </ul>
+ </li>
+ <li><a href="#sourcebuffer">4. SourceBuffer Object</a></li>
+ <li>
+<a href="#sourcebufferlist">5. SourceBufferList Object</a>
+ <ul>
+ <li><a href="#sourcebufferlist-methods">5.1. Methods and Attributes</a></li>
+ <li><a href="#sourcebufferlist-events">5.2. Event Summary</a></li>
+ </ul>
</li>
<li><a href="#byte-stream-formats">6. Byte Stream Formats</a></li>
<li>
@@ -147,13 +152,12 @@
</ul>
</li>
<li><a href="#examples">7. Examples</a></li>
- <li><a href="#open-issues">8. Open Issues</a></li>
- <li><a href="#revision-history">9. Revision History</a></li>
+ <li><a href="#revision-history">8. Revision History</a></li>
</ul>
<h2 id="introduction">1. Introduction</h2>
<p>This proposal allows JavaScript to dynamically construct media streams for <audio> and <video>.
- It defines extensions to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#htmlmediaelement">HTMLMediaElement</a></code> that allow JavaScript to pass media segments to the user agent.
+ It defines objects that allow JavaScript to pass media segments to an <code><a href="http://dev.w3.org/html5/spec/media-elements.html#htmlmediaelement">HTMLMediaElement</a></code>.
A buffering model is also included to describe how the user agent should act when different media segments are
appended at different times. Byte stream specifications for WebM & ISO Base Media File Format are given to specify the
expected format of media segments used with these extensions.</p>
@@ -171,19 +175,8 @@
</ul>
<h3 id="definitions">1.2. Definitions</h3>
- <h4 id="active-ids">1.2.1. Active IDs</h4>
- <p>The set of <a href="#source-id">source IDs</a> that are providing the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-videotrack-selected">selected video track</a></code> and the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-audiotrack-enabled">enabled audio tracks</a></code>.</p>
-
- <h4 id="source-id">1.2.2. Source ID</h4>
- <p>An ID registered with <code><a href="#dom-sourceaddid">sourceAddId()</a></code> that identifies a distinct sequence of <a href="#init-segment">initialization segments</a> & <a href="#media-segment">media segments</a> appended to a specific <a href="#source-buffer">source buffer</a>.</p>
- <h4 id="source-buffer">1.2.3. Source Buffer</h4>
- <p>A hypothetical buffer that contains the <a href="#media-segment">media segments</a> for a particular <a href="#source-id">source ID</a>. When <a href="#media-segment">media segments</a> are passed to <code><a href="#dom-sourceappend">sourceAppend()</a></code> they update the state of this buffer. The source buffer only allows a single <a href="#media-segment">media segment</a> to cover a specific point in the presentation timeline of each track. If a <a href="#media-segment">media segment</a> gets appended that contains media data overlapping (in presentation time) with media data from an existing segment, then the new media data will override the old media data. Since <a href="#media-segment">media segments</a> depend on <a href="#init-segment">initialization segments</a> the source buffer is also responsible for maintaining these associations. During playback, the media element pulls segment data out of the source buffers, demultiplexes it if necessary, and enqueues it into <a href="#track-buffer">track buffers</a> so it will get decoded and displayed. <code><a href="#dom-sourcebuffered">sourceBuffered()</a></code> describes the time ranges that are covered by <a href="#media-segment">media segments</a> in the source buffer.</p>
-
- <h4 id="track-buffer">1.2.4. Track Buffer</h4>
- <p>A hypothetical buffer that represents initialization and media data for a single <code><a href="http://dev.w3.org/html5/spec/media-elements.html#audiotrack">AudioTrack</a></code> or <code><a href="http://dev.w3.org/html5/spec/media-elements.html#videotrack">VideoTrack</a></code> that has been queued for playback. This buffer may not exist in actual implementations, but it is intended to represent media data that will be decoded no matter what <a href="#media-segment">media segments</a> are appended to update the <a href="#source-buffer">source buffer</a>. This distinction is important when considering appends that happen close to the current playback position. Details about transfers between the <a href="#source-buffer">source buffer</a> and track buffers are given <a href="#source-buffer-to-track-buffer">here</a>.</p>
-
- <h4 id="init-segment">1.2.5. Initialization Segment</h4>
+ <h4 id="init-segment">1.2.1. Initialization Segment</h4>
<p>A sequence of bytes that contains all of the initialization information required to decode a sequence of <a href="#media-segment">media segments</a>. This includes codec initialization data, trackID mappings for multiplexed segments, and timestamp offsets (e.g. edit lists).</p>
<dl class="example">
@@ -194,7 +187,7 @@
<dd>The concatenation of the the EBML Header, Segment Header, Info element, and Tracks element.</dd>
</dl>
- <h4 id="media-segment">1.2.6. Media Segment</h4>
+ <h4 id="media-segment">1.2.2. Media Segment</h4>
<p>A sequence of bytes that contain packetized & timestamped media data for a portion of the presentation timeline. Media segments are always associated with the most recently appended <a href="#init-segment">initialization segment</a>.</p>
<dl class="domintro">
@@ -205,22 +198,34 @@
<dd>A Cluster element</dd>
</dl>
- <h4 id="random-access-point">1.2.7. Random Access Point</h4>
+ <h4 id="source-buffer">1.2.3. Source Buffer</h4>
+ <p>A hypothetical buffer that contains a distinct sequence of <a href="#init-segment">initialization segments</a> & <a href="#media-segment">media segments</a>. When <a href="#media-segment">media segments</a> are passed to <code><a href="#dom-append">append()</a></code> they update the state of this buffer. The source buffer only allows a single <a href="#media-segment">media segment</a> to cover a specific point in the presentation timeline of each track. If a <a href="#media-segment">media segment</a> gets appended that contains media data overlapping (in presentation time) with media data from an existing segment, then the new media data will override the old media data. Since <a href="#media-segment">media segments</a> depend on <a href="#init-segment">initialization segments</a> the source buffer is also responsible for maintaining these associations. During playback, the media element pulls segment data out of the source buffers, demultiplexes it if necessary, and enqueues it into <a href="#track-buffer">track buffers</a> so it will get decoded and displayed. <code><a href="#dom-buffered">buffered</a></code> describes the time ranges that are covered by <a href="#media-segment">media segments</a> in the source buffer.</p>
+
+ <h4 id="active-source-buffers">1.2.4. Active Source Buffers</h4>
+ <p>The set of <a href="#source-buffer">source buffers</a> that are providing the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-videotrack-selected">selected video track</a></code>, the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-audiotrack-enabled">enabled audio tracks</a></code>, and the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-texttrack-showing">"showing"</a></code> or <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-texttrack-hidden">"hidden"</a></code> text tracks. This is a subset of all the source buffers associated with a specific <code><a href="#dom-mediasource">MediaSource</a></code> object. Details about how this set is managed are given <a href="#active-source-buffer-changes">here</a>.</p>
+
+
+ <h4 id="track-buffer">1.2.5. Track Buffer</h4>
+ <p>A hypothetical buffer that represents initialization and media data for a single <code><a href="http://dev.w3.org/html5/spec/media-elements.html#audiotrack">AudioTrack</a></code>, <code><a href="http://dev.w3.org/html5/spec/media-elements.html#videotrack">VideoTrack</a></code>, or <code><a href="http://dev.w3.org/html5/spec/media-elements.html#texttrack">TextTrack</a></code> that has been queued for playback. This buffer may not exist in actual implementations, but it is intended to represent media data that will be decoded no matter what <a href="#media-segment">media segments</a> are appended to update the <a href="#source-buffer">source buffer</a>. This distinction is important when considering appends that happen close to the current playback position. Details about transfers between the <a href="#source-buffer">source buffer</a> and track buffers are given <a href="#source-buffer-to-track-buffer">here</a>.</p>
+
+
+ <h4 id="random-access-point">1.2.6. Random Access Point</h4>
<p>A position in a <a href="#media-segment">media segment</a> where decoding and continuous playback can begin without relying on any previous data in the segment. For video this tends to be the location of I-frames. In the case of audio, most audio frames can be treated as a random access point. Since video tracks tend to have a more sparse distribution of random access points, the location of these points are usually considered the random access points for multiplexed streams.</p>
+
<h2 id="source-buffer-model">2. Source Buffer Model</h2>
<p>The subsections below outline the buffering model for this proposal. It describes how to add and remove <a href="#source-buffer">source buffers</a> from the presentation and describes the various rules and behaviors associated with appending data to an individual <a href="#source-buffer">source buffer</a>. At the highest level, the web application simply creates <a href="#source-buffer">source buffers</a> and appends a sequence of <a href="#init-segment">initialization segments</a> and <a href="#media-segment">media segments</a> to update the buffer's state. The media element pulls media data out of the <a href="#source-buffer">source buffers</a>, plays it, and fires events just like it would if a normal URL was passed to the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#attr-media-src">src</a></code> attribute. The web application is expected to monitor media element events to determine when it needs to append more <a href="#media-segment">media segments</a>.</p>
- <h3 id="source-buffer-add-id">2.1. Adding a new Source ID</h3>
- <p>Creating a new <a href="#source-buffer">source buffer</a> is initiated by calling <code><a href="#dom-sourceaddid">sourceAddId()</a></code>. This method allows the web application to specify the <a href="#source-id">source ID</a> it wants to associate with a new <a href="#source-buffer">source buffer</a> and indicates the format of the data it intends to append. The user agent looks at the type information and determines whether it supports the desired format and has sufficient resources to handle a new <a href="#source-buffer">source buffer</a> for this device. If the user agent can't support another <a href="#source-id">source ID</a> then it will throw an appropriate exception to signal why the request couldn't be satisfied.</p>
+ <h3 id="source-buffer-create">2.1. Creating Source Buffers</h3>
+ <p><code><a href="#dom-sourcebuffer">SourceBuffer</a></code> objects can be created once a <code><a href="#dom-mediasource">MediaSource</a></code> object enters the <code><a href="#dom-%22open%22">"open"</a></code> state. The application calls <code><a href="#dom-addsourcebuffer">addSourceBuffer()</a></code> with a type string that indicates the format of the data it intends to append to the new SourceBuffer. If the user agent supports the format and has sufficent resources, a new <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> object is created, added to <code><a href="#dom-sourcebuffers">sourceBuffers</a></code>, and returned by the method. If the user agent doesn't support the specified format or can't support another <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> then it will throw an appropriate exception to signal why the request couldn't be satisfied.</p>
<h3 id="source-buffer-basic-append">2.2. Basic appending model</h3>
- <p>Updating the state of a <a href="#source-buffer">source buffer</a> requires appending at least one <a href="#init-segment">initialization segment</a> and one or more <a href="#media-segment">media segments</a> via <code><a href="#dom-sourceappend">sourceAppend()</a></code>. The following list outlines some of the basic rules for appending segments.
+ <p>Updating the state of a <a href="#source-buffer">source buffer</a> requires appending at least one <a href="#init-segment">initialization segment</a> and one or more <a href="#media-segment">media segments</a> via <code><a href="#dom-append">append()</a></code>. The following list outlines some of the basic rules for appending segments.
<ul>
<li>The first segment appended MUST be an <a href="#init-segment">initialization segment</a>.</li>
<li>All <a href="#media-segment">media segments</a> are associated with the most recently appended <a href="#init-segment">initialization segment</a>.</li>
- <li>A whole segment must be appended before another segment can be started unless <code><a href="#dom-sourceabort">sourceAbort()</a></code> is called.</li>
- <li>Segments can be appended in pieces. (i.e. A 4096 byte segment can be spread across four 1024 byte calls to <code><a href="#dom-sourceappend">sourceAppend()</a></code>).</li>
+ <li>A whole segment must be appended before another segment can be started unless <code><a href="#dom-abort">abort()</a></code> is called.</li>
+ <li>Segments can be appended in pieces. (i.e. A 4096 byte segment can be spread across four 1024 byte calls to <code><a href="#dom-append">append()</a></code>).</li>
<li>If a <a href="#media-segment">media segment</a> requires different configuration information (e.g. codec parameters, new internal trackIDs, metadata) from what is in the most recently appended <a href="#init-segment">initialization segment</a>, a new <a href="#init-segment">initialization segment</a> with the new configuration information MUST be appended before the <a href="#media-segment">media segment</a> requiring this information is appended.</li>
<li>A new <a href="#media-segment">media segment</a> can overlap, in presentation time, a segment that was previously appended. The new segment will override the previous data.</li>
<li>Media segments can be appended in any order.<br>Note: In practice finite buffer space and maintaining uninterrupted playback will bias appending towards time increasing order near the current playback position. Out of order appends facilitate adaptive streaming, ad insertion, and video editing use cases.</li>
@@ -229,31 +234,31 @@
</p>
<h3 id="source-buffer-init-segment-constraints">2.3. Initialization Segment constraints</h3>
- <p>To simplify the implementation and facilitate interoperability, a few constraints are placed on the <a href="#init-segment">initialization segments</a> that are appended to a specific <a href="#source-id">source ID</a>:
+ <p>To simplify the implementation and facilitate interoperability, a few constraints are placed on the <a href="#init-segment">initialization segments</a> that are appended to a specific <code><a href="#dom-sourcebuffer">SourceBuffer</a></code>:
<ul>
- <li>The number and type of tracks MUST be consistent across all <a href="#init-segment">initialization segments</a>. <br>For example, if the first <a href="#init-segment">initialization segment</a> has 2 audio tracks and 1 video track, then all <a href="#init-segment">initialization segments</a> that follow, for this <a href="#source-id">source ID</a> MUST describe 2 audio tracks and 1 video track.</li>
+ <li>The number and type of tracks MUST be consistent across all <a href="#init-segment">initialization segments</a>. <br>For example, if the first <a href="#init-segment">initialization segment</a> has 2 audio tracks and 1 video track, then all <a href="#init-segment">initialization segments</a> that follow, for this <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> MUST describe 2 audio tracks and 1 video track.</li>
<li>Internal trackIDs do not need to be the same across <a href="#init-segment">initialization segments</a> only if the segment describes one track of each type.<br> For example, if an <a href="#init-segment">initialization segment</a> describes a single audio track and a single video track, the internal trackIDs do not need to be the same.</li>
<li>Internal trackIDs MUST be the same across <a href="#init-segment">initialization segments</a> if multiple tracks for a single type are described. (e.g. 2 audio tracks).</li>
- <li>Codecs changes are not allowed. <br> For example, you can't have an <a href="#init-segment">initialization segment</a> that specifies a single AAC track and then follows it with one that contains AMR-WB. Support for multiple codecs is handled with multiple <a href="#source-id">source IDs</a>.</li>
+ <li>Codecs changes are not allowed. <br> For example, you can't have an <a href="#init-segment">initialization segment</a> that specifies a single AAC track and then follows it with one that contains AMR-WB. Support for multiple codecs is handled with multiple <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> objects.</li>
<li>Video frame size changes are allowed and MUST be supported seamlessly.<br> Note: This will cause the <video> display region to change size if you don't use CSS or HTML attributes (width/height) to constrain the element size.</li>
<li>Audio channel count changes are allowed, but they may not be seamless and could trigger downmixing.<br> Note: This is a quality of implementation issue because changing the channel count may require reinitializing the audio device, resamplers, and channel mixers which tends to be audible.</li>
</ul>
</p>
<h3 id="source-buffer-media-segment-constraints">2.4. Media Segment constraints</h3>
- <p>To simplify the implementation and facilitate interoperability, a few constraints are placed on the <a href="#media-segment">media segments</a> that are appended to a specific <a href="#source-id">source ID</a>:
+ <p>To simplify the implementation and facilitate interoperability, a few constraints are placed on the <a href="#media-segment">media segments</a> that are appended to a specific <code><a href="#dom-sourcebuffer">SourceBuffer</a></code>:
<ul>
<li>All timestamps must be mapped to the same presentation timeline.</li>
<li>Segments should start with a <a href="#random-access-point">random access point</a> to facilitate seamless splicing at the segment boundary.</li>
- <li>Gaps between <a href="#media-segment">media segments</a> that are smaller than the audio frame size are allowed and should be rendered as silence. Such gaps should not be reflected by <code><a href="#dom-sourcebuffered">sourceBuffered()</a></code>.<br>Note: This is intended to simplify switching between audio streams where the frame boundaries don't always line up across encodings (e.g. Vorbis).</li>
+ <li>Gaps between <a href="#media-segment">media segments</a> that are smaller than the audio frame size are allowed and should be rendered as silence. Such gaps should not be reflected by <code><a href="#dom-buffered">buffered</a></code>.<br>Note: This is intended to simplify switching between audio streams where the frame boundaries don't always line up across encodings (e.g. Vorbis).</li>
</ul>
</p>
<h3 id="source-buffer-first-init-segment">2.5. Appending the first Initialization Segment</h3>
- <p>Once a new <a href="#source-id">source ID</a> has been added, the <a href="#source-buffer">source buffer</a> expects an <a href="#init-segment">initialization segment</a> to be appended first. This first segment indicates the number and type of streams contained in the <a href="#media-segment">media segments</a> that follow. This allows the media element to configure the necessary decoders and output devices. This first segment can also cause a <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">readyState</a></code> transition to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_metadata">HAVE_METADATA</a></code> if this is the first <a href="#source-id">source ID</a> registered, or if it is the first track of a specific type (i.e. first audio or first video track). If neither of the conditions hold then the tracks for this new <a href="#source-id">source ID</a> will just appear as disabled tracks and won't affect the current <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">readyState</a></code> until they are selected. The media element will also add the appropriate tracks to the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-audiotracks">audioTracks</a></code> & <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-videotracks">videoTracks</a></code> collections and fire the necessary <code><a href="http://dev.w3.org/html5/spec/media-elements.html#handler-tracklist-onchange">change</a></code> events. The description for <code><a href="#dom-sourceappend">sourceAppend()</a></code> contains all the details.</p>
+ <p>Once a new <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> has been created, it expects an <a href="#init-segment">initialization segment</a> to be appended first. This first segment indicates the number and type of streams contained in the <a href="#media-segment">media segments</a> that follow. This allows the media element to configure the necessary decoders and output devices. This first segment can also cause a <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> transition to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_metadata">HAVE_METADATA</a></code> if this is the first <code><a href="#dom-sourcebuffer">SourceBuffer</a></code>, or if it is the first track of a specific type (i.e. first audio, first video track, or first text track). If neither of the conditions hold then the tracks for this new <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> will just appear as disabled tracks and won't affect the current <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> until they are selected. The media element will also add the appropriate tracks to the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-audiotracks">audioTracks</a></code>, <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-videotracks">videoTracks</a></code>, & <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-texttracks">textTracks</a></code> collections and fire the necessary <code><a href="http://dev.w3.org/html5/spec/media-elements.html#handler-tracklist-onchange">change</a></code> events. The description for <code><a href="#dom-append">append()</a></code> contains all the details.</p>
<h3 id="source-buffer-media-segment-unbuffered">2.6. Appending a Media Segment to an unbuffered region</h3>
- <p>If a <a href="#media-segment">media segment</a> is appended to a time range that is not covered by existing segments in the <a href="#source-buffer">source buffer</a>, then its data is copied directly into the <a href="#source-buffer">source buffer</a>. Addition of this data may trigger <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">readyState</a></code> transitions depending on what other data is buffered and whether the media element has determined if it can start playback. Calls to <code><a href="#dom-sourcebuffered">sourceBuffered()</a></code> will always reflect the current <code><a href="http://dev.w3.org/html5/spec/media-elements.html#timeranges">TimeRanges</a></code> buffered in the <a href="#source-buffer">source buffer</a>.</p>
+ <p>If a <a href="#media-segment">media segment</a> is appended to a time range that is not covered by existing segments in the <a href="#source-buffer">source buffer</a>, then its data is copied directly into the <a href="#source-buffer">source buffer</a>. Addition of this data may trigger <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> transitions depending on what other data is buffered and whether the media element has determined if it can start playback. Calls to <code><a href="#dom-buffered">buffered</a></code> will always reflect the current <code><a href="http://dev.w3.org/html5/spec/media-elements.html#timeranges">TimeRanges</a></code> buffered in the <code><a href="#dom-sourcebuffer">SourceBuffer</a></code>.</p>
<h3 id="source-buffer-overlapping-segments">2.7. Appending a Media Segment over a buffered region</h3>
<p>There are several ways that <a href="#media-segment">media segments</a> can overlap segments in the <a href="#source-buffer">source buffer</a>. Behavior for the different overlap situations are described below. If more than one overlap applies, then the <a href="#source-buffer-overlap-start">start overlap</a> gets resolved first, followed by any <a href="#source-buffer-overlap-complete">complete overlaps</a>, and finally the <a href="#source-buffer-overlap-end">end overlap</a>. If a segment contains multiple tracks then the overlap is resolved independently for each track.</p>
@@ -264,207 +269,107 @@
<h4 id="source-buffer-overlap-start">2.7.2 Start Overlap</h4>
<img src="start_overlap.png">
<p>The figure above shows how the <a href="#source-buffer">source buffer</a> gets updated when the beginning of a new <a href="#media-segment">media segment</a> overlaps a segment in the buffer. In this case the new segment replaces all the old media data in the overlapping region. Since <a href="#media-segment">media segments</a> are constrained to starting with <a href="#random-access-point">random access points</a>, this provides a seamless transition between segments.</p>
- <p>The one case that requires special attention is where an audio frame overlaps with the start of the new <a href="#media-segment">media segment</a>. The base level behavior that MUST be supported requires dropping the old audio frame that overlaps the start of the new segment and inserting silence for the small gap that is created. A higher quality implementation could support outputting a portion of the old segment and all of the new segment or crossfade during the overlapping region. This is a quality of implementation issue. The key property here though is the small silence gap should not be reflected in the ranges reported by <code><a href="#dom-sourcebuffered">sourceBuffered()</a></code></p>
+ <p>The one case that requires special attention is where an audio frame overlaps with the start of the new <a href="#media-segment">media segment</a>. The base level behavior that MUST be supported requires dropping the old audio frame that overlaps the start of the new segment and inserting silence for the small gap that is created. A higher quality implementation could support outputting a portion of the old segment and all of the new segment or crossfade during the overlapping region. This is a quality of implementation issue. The key property here though is the small silence gap should not be reflected in the ranges reported by <code><a href="#dom-buffered">buffered</a></code></p>
<h4 id="source-buffer-overlap-end">2.7.3 End Overlap</h4>
<img src="end_overlap.png">
- <p>The figure above shows how the <a href="#source-buffer">source buffer</a> gets updated when the end of a new <a href="#media-segment">media segment</a> overlaps a segment in the buffer. In this case, the media element tries to keep as much of the old segment as possible. The amount saved depends on where the closest <a href="#random-access-point">random access point</a>, in the old segment, is to the end of the new segment. In the case of audio, if the gap is smaller than the size of an audio frame, then the media element should insert silence for this gap and not reflect it in <code><a href="#dom-sourcebuffered">sourceBuffered()</a></code>.</p>
- <p>An implementation may keep old segment data before the end of the new segment to avoid creating a gap if it wishes. Doing this though can significantly increase implementation complexity and could cause delays at the splice point. The key property that must be preserved is the entirety of the new segment gets added to the <a href="#source-buffer">source buffer</a> and it is up to the implementation how much of the old segment data is retained. The web application can use <code><a href="#dom-sourcebuffered">sourceBuffered()</a></code> to determine how much of the old segment was preserved.</p>
+ <p>The figure above shows how the <a href="#source-buffer">source buffer</a> gets updated when the end of a new <a href="#media-segment">media segment</a> overlaps a segment in the buffer. In this case, the media element tries to keep as much of the old segment as possible. The amount saved depends on where the closest <a href="#random-access-point">random access point</a>, in the old segment, is to the end of the new segment. In the case of audio, if the gap is smaller than the size of an audio frame, then the media element should insert silence for this gap and not reflect it in <code><a href="#dom-buffered">buffered</a></code>.</p>
+ <p>An implementation may keep old segment data before the end of the new segment to avoid creating a gap if it wishes. Doing this though can significantly increase implementation complexity and could cause delays at the splice point. The key property that must be preserved is the entirety of the new segment gets added to the <a href="#source-buffer">source buffer</a> and it is up to the implementation how much of the old segment data is retained. The web application can use <code><a href="#dom-buffered">buffered</a></code> to determine how much of the old segment was preserved.</p>
<h4 id="source-buffer-overlap-middle">2.7.4 Middle Overlap</h4>
<img src="middle_overlap.png">
<p>The figure above shows how the <a href="#source-buffer">source buffer</a> gets updated when the new <a href="#media-segment">media segment</a> is in the middle of the old segment. This condition is handled by first resolving the <a href="#source-buffer-overlap-start">start overlap</a> and then resolving the <a href="#source-buffer-overlap-end">end overlap</a>.</p>
<h3 id="source-buffer-to-track-buffer">2.8. Source Buffer to Track Buffer transfer</h3>
- <p>The <a href="#source-buffer">source buffer</a> represents the media that the web application would like the media element to play. The <a href="#track-buffer">track buffer</a> contains the data that will actually get decoded and rendered. In most cases the <a href="#track-buffer">track buffer</a> will simply contain a subset of the <a href="#source-buffer">source buffer</a> near the current playback position. These two buffers start to diverge though when <a href="#media-segment">media segments</a> that overlay or are very close to the current playback position are appended. Depending on the contents of the new <a href="#media-segment">media segment</a> it may not be possible to switch to the new data immediately because there isn't a <a href="#random-access-point">random access point</a> close enough to the current playback position. The quality of the implementation determines how much data is considered "in the <a href="#track-buffer">track buffer</a>". It should transfer data to the <a href="#track-buffer">track buffer</a> as late as possible whilst maintaining seamless playback. Some implementations may be able to instantiate multiple decoders or decode the new data significantly faster than real-time to achieve a seamless splice immediately. Other implementations may delay until the next <a href="#random-access-point">random access point</a> before switching to the newly appended data. Notice that this difference in behavior is only observable when appending close to the current playback position. The <a href="#track-buffer">track buffer</a> represents a media subsegment, like a group of pictures or something with similar decode dependencies, that the media element commits to playing. This commitment may be influenced by a variety of things like limited decoding resources, hardware decode buffers, a jitter buffer, or the desire to limit implementation complexity.</p>
+ <p>The <a href="#source-buffer">source buffer</a> represents the media that the web application would like the media element to play. The <a href="#track-buffer">track buffer</a> contains the data that will actually get decoded and rendered. In most cases the <a href="#track-buffer">track buffer</a> will simply contain a subset of the <a href="#source-buffer">source buffer</a> near the current playback position. These two buffers start to diverge though when <a href="#media-segment">media segments</a> that overlap or are very close to the current playback position are appended. Depending on the contents of the new <a href="#media-segment">media segment</a> it may not be possible to switch to the new data immediately because there isn't a <a href="#random-access-point">random access point</a> close enough to the current playback position. The quality of the implementation determines how much data is considered "in the <a href="#track-buffer">track buffer</a>". It should transfer data to the <a href="#track-buffer">track buffer</a> as late as possible whilst maintaining seamless playback. Some implementations may be able to instantiate multiple decoders or decode the new data significantly faster than real-time to achieve a seamless splice immediately. Other implementations may delay until the next <a href="#random-access-point">random access point</a> before switching to the newly appended data. Notice that this difference in behavior is only observable when appending close to the current playback position. The <a href="#track-buffer">track buffer</a> represents a media subsegment, like a group of pictures or something with similar decode dependencies, that the media element commits to playing. This commitment may be influenced by a variety of things like limited decoding resources, hardware decode buffers, a jitter buffer, or the desire to limit implementation complexity.</p>
<p>Here is an example to help clarify the role of the <a href="#track-buffer">track buffer</a>. Say the current playback position has a timestamp of 8 and the media element pulled frames with timestamp 9 & 10 into the track buffer. The web application then appends a higher quality <a href="#media-segment">media segment</a> that starts with a <a href="#random-access-point">random access point</a> at timestamp 9. The <a href="#source-buffer">source buffer</a> will get updated with the higher quality data, but the media element won't be able to switch to this higher quality data until the next <a href="#random-access-point">random access point</a> at timestamp 20. This is because a frame for timestamp 9 is already in the track buffer. As you can see the track buffer represents the "point of no return." for decoding. If a seek occurs the media element may choose to use the higher quality data since a seek might imply flushing the <a href="#track-buffer">track buffer</a> and the user expects a break in playback.</p>
<h3 id="source-buffer-segment-eviction">2.9. Media Segment Eviction</h3>
- <p>When a new <a href="#media-segment">media segment</a> is appended, memory constraints may cause previously appended segments to get evicted from the <a href="#source-buffer">source buffer</a>. The eviction algorithm is implementation dependent, but segments that aren't likely to be needed soon are the most likely to get evicted. The <code><a href="#dom-sourcebuffered">sourceBuffered()</a></code> method allows the web application to monitor what time ranges are currently buffered in the <a href="#source-buffer">source buffer</a>.</p>
+ <p>When a new <a href="#media-segment">media segment</a> is appended, memory constraints may cause previously appended segments to get evicted from the <a href="#source-buffer">source buffer</a>. The eviction algorithm is implementation dependent, but segments that aren't likely to be needed soon are the most likely to get evicted. The <code><a href="#dom-buffered">buffered</a></code> method allows the web application to monitor what time ranges are currently buffered in the <a href="#source-buffer">source buffer</a>.</p>
- <h3 id="source-buffer-remove-id">2.10. Removing a Source ID</h3>
- <p>Removing a <a href="#source-id">source ID</a> with <code><a href="#dom-sourceremoveid">sourceRemoveId()</a></code> releases all resources associated with the ID. This includes destroying the <a href="#source-buffer">source buffer</a>, <a href="#track-buffer">track buffers</a>, and decoders. The media element will also remove the appropriate tracks from <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-audiotracks">audioTracks</a></code> & <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-videotracks">videoTracks</a></code> and fire the necessary <code><a href="http://dev.w3.org/html5/spec/media-elements.html#handler-tracklist-onchange">change</a></code> events. Playback may become degraded or stop if the currently selected <code><a href="http://dev.w3.org/html5/spec/media-elements.html#videotrack">VideoTrack</a></code> or the only enabled <code><a href="http://dev.w3.org/html5/spec/media-elements.html#audiotrack">AudioTracks</a></code> are removed.</p>
-
- <h2 id="mediasource">3. Media Element Extensions</h2>
- <p>We extend HTML media elements to allow media data to be streamed into them from JavaScript.</p>
- <pre class="idl">
-partial interface HTMLMediaElement {
- // URL passed to src attribute to enable the media source logic.
- readonly attribute DOMString <a href="#dom-mediasourceurl">mediaSourceURL</a>;
-
- // Manages IDs for appending media to the source.
- void <a href="#dom-sourceaddid">sourceAddId</a>(DOMString id, DOMString type);
- void <a href="#dom-sourceremoveid">sourceRemoveId</a>(DOMString id);
-
- // Returns the time ranges buffered for a specific ID.
- TimeRanges <a href="#dom-sourcebuffered">sourceBuffered</a>(DOMString id);
-
- // Append segment data.
- void <a href="#dom-sourceappend">sourceAppend</a>(DOMString id, Uint8Array data);
-
- // Abort the current segment.
- void <a href="#dom-sourceabort">sourceAbort</a>(DOMString id);
-
- // end of stream status codes.
- const unsigned short <a href="#dom-eos_no_error">EOS_NO_ERROR</a> = 0;
- const unsigned short <a href="#dom-eos_network_err">EOS_NETWORK_ERR</a> = 1;
- const unsigned short <a href="#dom-eos_decode_err">EOS_DECODE_ERR</a> = 2;
-
- void <a href="#dom-sourceendofstream">sourceEndOfStream</a>(unsigned short status);
+ <h3 id="source-buffer-remove">2.10. Removing Source Buffers</h3>
+ <p>Removing a <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> with <code><a href="#dom-remove">remove()</a></code> releases all resources associated with the object. This includes destroying the all the segment data, <a href="#track-buffer">track buffers</a>, and decoders. The media element will also remove the appropriate tracks from <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-audiotracks">audioTracks</a></code>, <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-videotracks">videoTracks</a></code>, & <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-texttracks">textTracks</a></code> and fire the necessary <code><a href="http://dev.w3.org/html5/spec/media-elements.html#handler-tracklist-onchange">change</a></code> events. Playback may become degraded or stop if the currently selected <code><a href="http://dev.w3.org/html5/spec/media-elements.html#videotrack">VideoTrack</a></code> or the only enabled <code><a href="http://dev.w3.org/html5/spec/media-elements.html#audiotrack">AudioTracks</a></code> are removed.</p>
- // states
- const unsigned short <a href="#dom-source_closed">SOURCE_CLOSED</a> = 0;
- const unsigned short <a href="#dom-source_open">SOURCE_OPEN</a> = 1;
- const unsigned short <a href="#dom-source_ended">SOURCE_ENDED</a> = 2;
-
- readonly attribute unsigned short <a href="#dom-sourcestate">sourceState</a>;
-
- [TreatNonCallableAsNull] attribute Function? <a href="#dom-onsourceopen">onsourceopen</a>;
- [TreatNonCallableAsNull] attribute Function? <a href="#dom-onsourceended">onsourceended</a>;
- [TreatNonCallableAsNull] attribute Function? <a href="#dom-onsourceclose">onsourceclose</a>;
-};
-
- </pre>
+ <h2 id="mediasource">3. MediaSource Object</h2>
+ <p>The MediaSource object represents a source of media data for an HTMLMediaElement. It keeps track of the <code><a href="#dom-readyState">readyState</a></code> for this source as well as a list of <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> objects that can be used to add media data to the presentation. MediaSource objects are created by the web application and then attached to an HTMLMediaElement. The application uses the <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> objects in <code><a href="#dom-sourcebuffers">sourceBuffers</a></code> to add media data to this source. The HTMLMediaElement fetches this media data from the <code><a href="#dom-mediasource">MediaSource</a></code> object when it is needed during playback.</p>
- <p>The <dfn id="dom-mediasourceurl"><code>mediaSourceURL</code></dfn> attribute returns the URL used to enable the Media Source extension methods. To enable the Media Source extensions on a media element, assign this URL to the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#attr-media-src">src</a></code> attribute. The format of the URL is browser specific and may be unique for each HTMLMediaElement. The <code><a href="#dom-mediasourceurl">mediaSourceURL</a></code> on one HTMLMediaElement should not be assigned to the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#attr-media-src">src</a></code> attribute on a different HTMLMediaElement.
- </p>
- <div class="example">
- <p>Example mediaSourceURL: </p>
- <p style="margin-left:2em">x-media-source:e183f43d-c8a3-4905-bf89-e8e920041c7c</p>
- <p>Note the browser specific scheme and use of a UUID for the path to make it unique.</p>
- </div>
- <div class="issue">Using <code><a href="#dom-mediasourceurl">mediaSourceURL</a></code> is one approach to switching the media element into "media source" mode. Alternative approaches should be explored to improve consistency with other APIs and provide a declarative mechanism for enabling "media source" mode.</div>
+ <pre class="idl">
+[Constructor]
+interface <dfn id="dom-mediasource">MediaSource</dfn> : EventTarget {
+ // All the source buffers created by this object.
+ readonly attribute <a href="#dom-sourcebufferlist">SourceBufferList</a> <a href="#dom-sourcebuffers">sourceBuffers</a>;
- <p>The <dfn id="dom-sourceaddid"><code>sourceAddId(id, type)</code></dfn> method must run the following steps:</p>
+ // Subset of sourceBuffers that provide data for the selected/enabled tracks.
+ readonly attribute <a href="#dom-sourcebufferlist">SourceBufferList</a> <a href="#dom-activesourcebuffers">activeSourceBuffers</a>;
+
+ // Adds another source buffer.
+ <a href="#dom-sourcebuffer">SourceBuffer</a> <a href="#dom-addsourcebuffer">addSourceBuffer</a>(DOMString type);
+
+ enum State { "closed", "open", "ended" };
+ readonly attribute State <a href="#dom-readystate">readyState</a>;
+
+ enum EndOfStreamError { "network", "decode" };
+ void <a href="#dom-endofstream">endOfStream</a>(optional EndOfStreamError error);
+};
+ </pre>
+ <h3 id="mediasource-methods">3.1. Methods and Attributes</h3>
+
+ <p>The <dfn id="dom-sourcebuffers"><code>sourceBuffers</code></dfn> attribute contains the list of <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> objects associated with this <code><a href="#dom-mediasource">MediaSource</a></code>. When <code><a href="#dom-readyState">readyState</a></code> equals <code><a href="#dom-closed">"closed"</a></code> this list will be empty. Once <code><a href="#dom-readyState">readyState</a></code> transitions to <code><a href="#dom-%22open%22">"open"</a></code> SourceBuffer objects can be added to this list by using <code><a href="#dom-addsourcebuffer">addSourceBuffer()</a></code>.</p>
+
+ <p>The <dfn id="dom-activesourcebuffers"><code>activeSourceBuffers</code></dfn> attribute contains the subset of <code><a href="#dom-sourcebuffers">sourceBuffers</a></code> that represents the <a href="#active-source-buffers">active source buffers</a>.</p>
+
+ <p>The <dfn id="dom-addsourcebuffer"><code>addSourceBuffer(type)</code></dfn> method must run the following steps:</p>
<ol>
- <li>If <var title="true">id</var> is null or an empty string then throw an <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_access_err">INVALID_ACCESS_ERR</a></code> exception and abort these steps.</li>
- <li>If <var title="true">id</var> specifies an ID that has been previously added then throw a <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code> exception and abort these steps.</li>
<li>If <var title="true">type</var> is null or an empty then throw an <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_access_err">INVALID_ACCESS_ERR</a></code> exception and abort these steps.</li>
- <li>If <var title="true">type</var> contains a MIME type that is not supported or contains a MIME type that is not supported with the types specified for other sourceIDs, then throw a <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-not_supported_err">NOT_SUPPORTED_ERR</a></code> exception and abort these steps.</li>
- <li>If the user agent can't handle any more IDs then throw a <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-quota_exceeded_err">QUOTA_EXCEEDED_ERR</a></code> exception and abort these steps.</li>
- <li>If the <code><a href="#dom-sourcestate">sourceState</a></code> attribute is not in the <code><a href="#dom-source_open">SOURCE_OPEN</a></code> state then throw an <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code> exception and abort these steps.</li>
- <li>Allocate source buffer resources for <var title="true">id</var>.</li>
+ <li>If <var title="true">type</var> contains a MIME type that is not supported or contains a MIME type that is not supported with the types specified for the other <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> objects in <code><a href="#dom-sourcebuffers">sourceBuffers</a></code>, then throw a <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-not_supported_err">NOT_SUPPORTED_ERR</a></code> exception and abort these steps.</li>
+ <li>If the user agent can't handle any more SourceBuffer objects then throw a <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-quota_exceeded_err">QUOTA_EXCEEDED_ERR</a></code> exception and abort these steps.</li>
+ <li>If the <code><a href="#dom-readyState">readyState</a></code> attribute is not in the <code><a href="#dom-%22open%22">"open"</a></code> state then throw an <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code> exception and abort these steps.</li>
+ <li>Create a new <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> object and associated resources.</li>
+ <li>Add the new object to <code><a href="#dom-sourcebuffers">sourceBuffers</a></code> and fire a <code><a href="#dom-addsourcebuffer">addsourcebuffer</a></code> on that object.</li>
+ <li>Return the new object to the caller.</li>
</ol>
- <p>The <dfn id="dom-sourceremoveid"><code>sourceRemoveId(id)</code></dfn> method must run the following steps:</p>
- <ol>
- <li>If <var title="true">id</var> is null or an empty string then throw an <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_access_err">INVALID_ACCESS_ERR</a></code> exception and abort these steps.</li>
- <li>If the <code><a href="#dom-sourcestate">sourceState</a></code> attribute is in the <code><a href="#dom-source_closed">SOURCE_CLOSED</a></code> state then throw an <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code> exception and abort these steps.</li>
- <li>If <var title="true">id</var> specifies an ID that has not been previously added then abort these steps.</li>
- <li>Remove track information from <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-audiotracks">audioTracks</a></code> and <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-videotracks">videoTracks</a></code> for all tracks associated with <var title="true">id</var> and fire a simple event named <code><a href="http://dev.w3.org/html5/spec/media-elements.html#handler-tracklist-onchange">change</a></code> on the modified lists.</li>
- <li>Destroy source buffer resources for <var title="true">id</var>.</li>
- </ol>
-
- <p>The <dfn id="dom-sourcebuffered"><code>sourceBuffered(id)</code></dfn> method must run the following steps:</p>
- <ol>
- <li>If <var title="true">id</var> is null or an empty string then throw an <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_access_err">INVALID_ACCESS_ERR</a></code> exception and abort these steps.</li>
- <li>If <var title="true">id</var> specifies an ID that has not been previously added with <code><a href="#dom-sourceaddid">sourceAddId()</a></code> then throw a <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-syntax_err">SYNTAX_ERR</a></code> exception and abort these steps.</li>
- <li>If the <code><a href="#dom-sourcestate">sourceState</a></code> attribute is in the <code><a href="#dom-source_closed">SOURCE_CLOSED</a></code> state then throw an <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code> exception and abort these steps.</li>
- <li>Return <code><a href="http://dev.w3.org/html5/spec/media-elements.html#timeranges">TimeRanges</a></code> for the source buffer associated with <var title="true">id</var>.</li>
- </ol>
+ <p>The <dfn id="dom-readystate"><code>readyState</code></dfn> attribute indicates the current state of the <code><a href="#dom-mediasource">MediaSource</a></code> object. It can have the following values:</p>
+ <dl>
+ <dt><dfn id='dom-"closed"'><code>"closed"</code></dfn></dt>
+ <dd>Indicates the source is not currently attached to a media element.</dd>
- <p>The <dfn id="dom-sourceappend"><code>sourceAppend(id, data)</code></dfn> method must run the following steps:</p>
- <ol>
- <li>If <var title="true">id</var> is null or an empty string then throw an <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_access_err">INVALID_ACCESS_ERR</a></code> exception and abort these steps.</li>
- <li>If <var title="true">id</var> specifies an ID that has not been previously added with <code><a href="#dom-sourceaddid">sourceAddId()</a></code> then throw a <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-syntax_err">SYNTAX_ERR</a></code> exception and abort these steps.</li>
- <li>If <var title="true">data</var> is null then throw an <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_access_err">INVALID_ACCESS_ERR</a></code> exception and abort these steps.</li>
- <li>If the <code><a href="#dom-sourcestate">sourceState</a></code> attribute is not in the <code><a href="#dom-source_open">SOURCE_OPEN</a></code> state then throw an <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code> exception and abort these steps.</li>
- <li>If <var title="true">data</var>.byteLength is 0 abort these steps.</li>
- <li>Copy contents of <var title="true">data</var> into the source buffer associated with <var title="true">id</var>.</li>
- <li>Handle end of segment cases:</li>
- <dl class="switch">
- <dt>If <var title="true">data</var> completes the first <a href="#init-segment">initialization segment</a> appended to the <a href="#source-buffer">source buffer</a> run the following steps:</dt>
- <dd>
- <ol>
- <li>Handle state transitions:</li>
- <dl class="switch">
- <dt>If the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">readyState</a></code> attribute is <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_nothing">HAVE_NOTHING</a></code>:</dt>
- <dd>Set <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">readyState</a></code> attribute to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_metadata">HAVE_METADATA</a></code> and fire the <a href="http://dev.w3.org/html5/spec/media-elements.html#mediaevents">appropriate event</a> for this transition.</dd>
- <dt>If the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">readyState</a></code> attribute is greater than <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_current_data">HAVE_CURRENT_DATA</a></code> and the <a href="#init-segment">initialization segment</a> contains the first video or first audio track in the presentation:</dt>
- <dd>
- Set <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">readyState</a></code> attribute to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_metadata">HAVE_METADATA</a></code> and fire the <a href="http://dev.w3.org/html5/spec/media-elements.html#mediaevents">appropriate event</a> for this transition.
- </dd>
- <dt>Otherwise:</dt>
- <dd>Continue</dd>
- </dl>
- <li>Update <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-audiotracks">audioTracks</a></code>
-</li>
- <dl class="switch">
- <dt>If <a href="#init-segment">initialization segment</a> contains the first audio track:</dt>
- <dd>Add an <code><a href="http://dev.w3.org/html5/spec/media-elements.html#audiotrack">AudioTrack</a></code> and mark it as enabled.</dd>
- <dt>If <a href="#init-segment">initialization segment</a> contains audio tracks beyond those already in the presentation:</dt>
- <dd>Add a disabled <code><a href="http://dev.w3.org/html5/spec/media-elements.html#audiotrack">AudioTrack</a></code> for each audio track in the <a href="#init-segment">initialization segment</a>.</dd>
- </dl>
- <li>Update <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-videotracks">videoTracks</a></code>:</li>
- <dl class="switch">
- <dt>If <a href="#init-segment">initialization segment</a> contains the first video track:</dt>
- <dd>Add a <code><a href="http://dev.w3.org/html5/spec/media-elements.html#videotrack">VideoTrack</a></code> and mark it as selected.</dd>
- <dt>If <a href="#init-segment">initialization segment</a> contains the video tracks beyond those already in the presentation:</dt>
- <dd>Add a disabled <code><a href="http://dev.w3.org/html5/spec/media-elements.html#videotrack">VideoTrack</a></code> for each video track in the <a href="#init-segment">initialization segment</a>.</dd>
- </dl>
- </ol>
- </dd>
- <dt>If the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">readyState</a></code> attribute is <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_metadata">HAVE_METADATA</a></code> and <var title="true">data</var> causes all <a href="#active-ids">active IDs</a> to have media data for the current playback position.</dt>
- <dd>Set <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">readyState</a></code> attribute to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_current_data">HAVE_CURRENT_DATA</a></code> and fire the <a href="http://dev.w3.org/html5/spec/media-elements.html#mediaevents">appropriate event</a> for this transition.</dd>
- <dt>If the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">readyState</a></code> attribute is <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_current_data">HAVE_CURRENT_DATA</a></code> and <var title="true">data</var> causes all <a href="#active-ids">active IDs</a> to have media data beyond the current playback position.</dt>
- <dd>Set <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">readyState</a></code> attribute to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_future_data">HAVE_FUTURE_DATA</a></code> and fire the <a href="http://dev.w3.org/html5/spec/media-elements.html#mediaevents">appropriate event</a> for this transition.</dd>
- <dt>If the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">readyState</a></code> attribute is <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_future_data">HAVE_FUTURE_DATA</a></code> and <var title="true">data</var> causes all <a href="#active-ids">active IDs</a> to have enough data to start playback.</dt>
- <dd>Set <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">readyState</a></code> attribute to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_enough_data">HAVE_ENOUGH_DATA</a></code> and fire the <a href="http://dev.w3.org/html5/spec/media-elements.html#mediaevents">appropriate event</a> for this transition.</dd>
- </dl>
- </ol>
+ <dt><dfn id='dom-"open"'><code>"open"</code></dfn></dt>
+ <dd>The source has been opened by a media element and is ready for data to be appended to the <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> objects in <code><a href="#dom-sourcebuffers">sourceBuffers</a></code>.</dd>
- <p>The <dfn id="dom-sourceabort"><code>sourceAbort(id)</code></dfn> method must run the following steps:</p>
- <ol>
- <li>If <var title="true">id</var> is null or an empty string then throw an <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_access_err">INVALID_ACCESS_ERR</a></code> exception and abort these steps.</li>
- <li>If <var title="true">id</var> specifies an ID that has not been previously added with <code><a href="#dom-sourceaddid">sourceAddId()</a></code> then throw a <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-syntax_err">SYNTAX_ERR</a></code> exception and abort these steps.</li>
- <li>If the <code><a href="#dom-sourcestate">sourceState</a></code> attribute is not in the <code><a href="#dom-source_open">SOURCE_OPEN</a></code> state then throw an <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code> exception and abort these steps.</li>
- <li>The media element aborts parsing the current segment.</li>
- <dl class="switch">
- <dt>If waiting for the start of a new segment</dt>
- <dd>Continue</dd>
- <dt>If the current segment is an <a href="#init-segment">initialization segment</a>
-</dt>
- <dd>Flush any data associated with this partial segment.</dd>
- <dt>If the current segment is a <a href="#media-segment">media segment</a>
-</dt>
- <dd>The media element may keep any media data it finds valuable in the partial segment. For example if the abort happens in the middle of a 10 second <a href="#media-segment">media segment</a>, the media element may choose to keep the 5 seconds of media data it has already parsed in the source buffer. <code><a href="#dom-sourcebuffered">sourceBuffered()</a></code> will reflect what data, if any, was kept.</dd>
- </dl>
- <li>The media element resets the segment parser so that it can accept a new <a href="#init-segment">initialization segment</a>.</li>
- </ol>
+ <dt><dfn id='dom-"ended"'><code>"ended"</code></dfn></dt>
+ <dd>The source is still attached to a media element, but <code><a href="#dom-endofstream">endOfStream()</a></code> has been called. Appending data to <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> objects in this state is not allowed.</dd>
+ </dl>
+ <p>When the <code><a href="#dom-mediasource">MediaSource</a></code> is created <code><a href="#dom-readyState">readyState</a></code> must be set to <code><a href="#dom-closed">"closed"</a></code>.
+ </p>
- <h5>End of stream status values:</h5>
+
+ <h5>End of stream error values:</h5>
<dl>
- <dt>
-<dfn id="dom-eos_no_error"><code>EOS_NO_ERROR</code></dfn> (numeric value 0)</dt>
- <dd>The stream ended normally without any errors.</dd>
-
- <dt>
-<dfn id="dom-eos_network_err"><code>EOS_NETWORK_ERR</code></dfn> (numeric value 1)</dt>
+ <dt><dfn id='dom-"network"'><code>"network"</code></dfn></dt>
<dd>The stream ended prematurely because of a network error. If the JavaScript code fetching media data encounters a network error it should use this status code to terminate playback. This will cause the media element's error handling code to run and the <code>error</code> attribute to be set to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-mediaerror-media_err_network">MediaError.MEDIA_ERR_NETWORK</a></code>
</dd>
- <dt>
-<dfn id="dom-eos_decode_err"><code>EOS_DECODE_ERR</code></dfn> (numeric value 2)</dt>
+ <dt><dfn id='dom-"decode"'><code>"decode"</code></dfn></dt>
<dd>The stream ended prematurely because there was an error while decoding the media data. If the JavaScript code fetching media data has problems parsing the data it should use this status code to terminate playback. This will cause the media element's error handling code to run and the <code>error</code> attribute to be set to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-mediaerror-media_err_decode">MediaError.MEDIA_ERR_DECODE</a></code>
</dd>
</dl>
- <p>The <dfn id="dom-sourceendofstream"><code>sourceEndOfStream(status)</code></dfn> method must run the following steps:</p>
+ <p>The <dfn id="dom-endofstream"><code>endOfStream(error)</code></dfn> method must run the following steps:</p>
<ol>
- <li>If the <code><a href="#dom-sourcestate">sourceState</a></code> attribute is not in the <code><a href="#dom-source_open">SOURCE_OPEN</a></code> state then throw an <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code> exception and abort these steps.</li>
- <li>Change the <code><a href="#dom-sourcestate">sourceState</a></code> attribute value to <code><a href="#dom-source_ended">SOURCE_ENDED</a></code>.</li>
+ <li>If the <code><a href="#dom-readyState">readyState</a></code> attribute is not in the <code><a href="#dom-%22open%22">"open"</a></code> state then throw an <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code> exception and abort these steps.</li>
+ <li>Change the <code><a href="#dom-readyState">readyState</a></code> attribute value to <code><a href="#dom-%22ended%22">"ended"</a></code>.</li>
<dl class="switch">
- <dt>If <var title="true">status</var> is set to <code><a href="#dom-eos_no_error">EOS_NO_ERROR</a></code>
-</dt>
- <dd>Notify the media element that it now has all of the media data. Playback should continue until all the media passed in via <code><a href="#dom-sourceappend">sourceAppend()</a></code> has been played.</dd>
- <dt>If <var title="true">status</var> is set to <code><a href="#dom-eos_network_err">EOS_NETWORK_ERR</a></code>
+ <dt>If <var title="true">error</var> is not set, null, or an empty string</dt>
+ <dd>Notify the media element that it now has all of the media data. Playback should continue until all the media passed in via <code><a href="#dom-append">append()</a></code> has been played.</dd>
+ <dt>If <var title="true">error</var> is set to <code><a href="#dom-%22network%22">"network"</a></code>
</dt>
<dd>Run the "If the connection is interrupted, causing the user agent to give up trying to fetch the resource" section of the <a href="http://dev.w3.org/html5/spec/media-elements.html#concept-media-load-resource">resource fetch algorithm</a>
</dd>
- <dt>If <var title="true">status</var> is set to <code><a href="#dom-eos_decode_err">EOS_DECODE_ERR</a></code>
+ <dt>If <var title="true">error</var> is set to <code><a href="#dom-%22decode%22">"decode"</a></code>
</dt>
<dd>Run the "If the media data is corrupted" section of the <a href="http://dev.w3.org/html5/spec/media-elements.html#concept-media-load-resource">resource fetch algorithm</a>
</dd>
@@ -473,48 +378,8 @@
</dl>
</ol>
- <p>The <dfn id="dom-sourcestate"><code>sourceState</code></dfn> attribute represents the state of the source. It can have the following values:</p>
- <dl>
- <dt>
-<dfn id="dom-source_closed"><code>SOURCE_CLOSED</code></dfn> (numeric value 0)</dt>
- <dd>Indicates the source is not currently attached to a media element.</dd>
-
- <dt>
-<dfn id="dom-source_open"><code>SOURCE_OPEN</code></dfn> (numeric value 1)</dt>
- <dd>The source has been opened by a media element.</dd>
-
- <dt>
-<dfn id="dom-source_ended"><code>SOURCE_ENDED</code></dfn> (numeric value 2)</dt>
- <dd>
-<code><a href="#dom-sourceendofstream">sourceEndOfStream()</a></code> has been called on this source.</dd>
- </dl>
- <p>When the media element is created <code><a href="#dom-sourcestate">sourceState</a></code> must be set to <code><a href="#dom-source_closed">SOURCE_CLOSED</a></code> (0).
- </p>
- <h2 id="event-summary">4. Event Summary</h2>
- <table>
- <thead>
- <tr>
- <th><a href="http://dev.w3.org/html5/spec/webappapis.html#event-handlers" title="event handlers">Event handler</a></th>
- <th><a href="http://dev.w3.org/html5/spec/webappapis.html#event-handler-event-type">Event handler event type</a></th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td><dfn id="dom-onsourceopen"><code>onsourceopen</code></dfn></td>
- <td><code><a href="#dom-sourceopen">sourceopen</a></code></td>
- </tr>
- <tr>
- <td><dfn id="dom-onsourceended"><code>onsourceended</code></dfn></td>
- <td><code><a href="#dom-sourceended">sourceended</a></code></td>
- </tr>
- <tr>
- <td><dfn id="dom-onsourceclose"><code>onsourceclose</code></dfn></td>
- <td><code><a href="#dom-sourceclose">sourceclose</a></code></td>
- </tr>
- </tbody>
- </table>
- <hr>
+ <h3 id="mediasource-events">3.2. Event Summary</h3>
<table>
<thead>
<tr>
@@ -527,69 +392,79 @@
<tr>
<td><dfn id="dom-sourceopen"><code>sourceopen</code></dfn></td>
<td><code>Event</code></td>
- <td>When the source transitions from <code><a href="#dom-source_closed">SOURCE_CLOSED</a></code> to <code><a href="#dom-source_open">SOURCE_OPEN</a></code> or from <code><a href="#dom-source_ended">SOURCE_ENDED</a></code> to <code><a href="#dom-source_open">SOURCE_OPEN</a></code>.</td>
+ <td>When <code><a href="#dom-readyState">readyState</a></code> transitions from <code><a href="#dom-closed">"closed"</a></code> to <code><a href="#dom-%22open%22">"open"</a></code> or from <code><a href="#dom-%22ended%22">"ended"</a></code> to <code><a href="#dom-%22open%22">"open"</a></code>.</td>
</tr>
<tr>
<td><dfn id="dom-sourceended"><code>sourceended</code></dfn></td>
<td><code>Event</code></td>
- <td>When the source transitions from <code><a href="#dom-source_open">SOURCE_OPEN</a></code> to <code><a href="#dom-source_ended">SOURCE_ENDED</a></code>.</td>
+ <td>When <code><a href="#dom-readyState">readyState</a></code> transitions from <code><a href="#dom-%22open%22">"open"</a></code> to <code><a href="#dom-%22ended%22">"ended"</a></code>.</td>
</tr>
<tr>
<td><dfn id="dom-sourceclose"><code>sourceclose</code></dfn></td>
<td><code>Event</code></td>
- <td>When the source transitions from <code><a href="#dom-source_open">SOURCE_OPEN</a></code> or <code><a href="#dom-source_ended">SOURCE_ENDED</a></code> to <code><a href="#dom-source_closed">SOURCE_CLOSED</a></code>.</td>
+ <td>When <code><a href="#dom-readyState">readyState</a></code> transitions from <code><a href="#dom-%22open%22">"open"</a></code> to <code><a href="#dom-closed">"closed"</a></code> or <code><a href="#dom-%22ended%22">"ended"</a></code> to <code><a href="#dom-closed">"closed"</a></code>.</td>
</tr>
</tbody>
</table>
- <h2 id="algorithms">5. Algorithms</h2>
- <h3 id="algorithms-attach">5.1 Attaching to a media element</h3>
+ <h3 id="mediasource-algorithms">3.3. Algorithms</h3>
+ <h4 id="mediasource-attach">3.3.1 Attaching to a media element</h4>
+ <p> A <code><a href="#dom-mediasource">MediaSource</a></code> object can be attached to a media element by assigning a MediaSource object URL to the media element <code><a href="http://dev.w3.org/html5/spec/media-elements.html#attr-media-src">src</a></code> attribute or the src attribute of a <source> inside a media element. MediaSource object URLs are created by passing a MediaSource object to window.URL.createObjectURL().</p>
+ <p>The following steps are run when a media element attempts the <a href="http://dev.w3.org/html5/spec/media-elements.html#concept-media-load-resource">resource fetch algorithm</a> with a MediaSource object URL.</p>
<ol>
- <li>Set the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#attr-media-src">src</a></code> attribute on a media element or the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#attr-media-src">src</a></code> attribute on a <source> element associated with a media element to <code><a href="#dom-mediasourceurl">mediaSourceURL</a></code>
-</li>
- <li>
-<p>When the media element attempts the <a href="http://dev.w3.org/html5/spec/media-elements.html#concept-media-load-resource">resource fetch algorithm</a> with the URL from <code><a href="#dom-mediasourceurl">mediaSourceURL</a></code> it will take one of the following actions:</p>
- <dl class="switch">
- <dt>If <code><a href="#dom-sourcestate">sourceState</a></code> is NOT set to <code><a href="#dom-source_closed">SOURCE_CLOSED</a></code>
+ <dl class="switch">
+ <dt>If <code><a href="#dom-readyState">readyState</a></code> is NOT set to <code><a href="#dom-closed">"closed"</a></code>
</dt>
- <dd>Abort media element's <a href="http://dev.w3.org/html5/spec/media-elements.html#concept-media-load-resource">resource fetch algorithm</a> and run the steps to report a <code>MEDIA_ERR_SRC_NOT_SUPPORTED</code> error.</dd>
- <dt>Otherwise</dt>
- <dd>
- <ol>
- <li>Set <code><a href="#dom-sourcestate">sourceState</a></code> attribute to <code><a href="#dom-source_open">SOURCE_OPEN</a></code>
+ <dd>Abort media element's <a href="http://dev.w3.org/html5/spec/media-elements.html#concept-media-load-resource">resource fetch algorithm</a> and run the steps to report a <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-mediaerror-media_err_src_not_supported">MEDIA_ERR_SRC_NOT_SUPPORTED</a></code> error.</dd>
+ <dt>Otherwise</dt>
+ <dd>
+ <ol>
+ <li>Set <code><a href="#dom-readyState">readyState</a></code> attribute to <code><a href="#dom-%22open%22">"open"</a></code>
</li>
- <li>Fire a simple event named <code><a href="#dom-sourceopen">sourceopen</a></code>.</li>
- <li>Allow <a href="http://dev.w3.org/html5/spec/media-elements.html#concept-media-load-resource">resource fetch algorithm</a> to progress based on data passed in via <code><a href="#dom-sourceappend">sourceAppend()</a></code>
+ <li>Fire a simple event named <code><a href="#dom-sourceopen">sourceopen</a></code>.</li>
+ <li>Allow <a href="http://dev.w3.org/html5/spec/media-elements.html#concept-media-load-resource">resource fetch algorithm</a> to progress based on data passed in via <code><a href="#dom-append">append()</a></code>
</li>
- </ol>
- </dd>
- </dl>
- </li>
+ </ol>
+ </dd>
+ </dl>
</ol>
- <h3 id="algorithms-detach">5.2 Detaching from a media element</h3>
+ <h4 id="mediasource-detach">3.3.2 Detaching from a media element</h4>
<p>The following steps are run in any case where the media element is going to transition to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-network_empty">NETWORK_EMPTY</a></code> and fire an <code><a href="http://dev.w3.org/html5/spec/media-elements.html#event-mediacontroller-emptied">emptied</a></code> event. These steps should be run right before the transition.</p>
<ol>
- <li>Set <code><a href="#dom-sourcestate">sourceState</a></code> attribute to <code><a href="#dom-source_closed">SOURCE_CLOSED</a></code>
+ <li>Set <code><a href="#dom-readyState">readyState</a></code> attribute to <code><a href="#dom-closed">"closed"</a></code>
</li>
+ <li>Remove all the <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> objects from <code><a href="#dom-sourcebuffers">sourceBuffers</a></code> and fire a <code><a href="#dom-removesourcebuffer">removesourcebuffer</a></code> event for each one.</li>
<li>Fire a simple event named <code><a href="#dom-sourceclose">sourceclose</a></code>.</li>
</ol>
-
- <h3 id="seeking">5.3 Seeking</h3>
+ <h4 id="mediasource-seeking">3.3.3 Seeking</h4>
<ol>
<li>The media element <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-seeking">seeking algorithm</a></code> starts and has reached the stage where it is about to fire the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#event-media-seeking">seeking</a></code> event.</li>
- <li>If the <code><a href="#dom-sourcestate">sourceState</a></code> attribute is set to <code><a href="#dom-source_ended">SOURCE_ENDED</a></code>, then the media element sets the <code><a href="#dom-sourcestate">sourceState</a></code> attribute to <code><a href="#dom-source_open">SOURCE_OPEN</a></code> and fires a simple event named <code><a href="#dom-sourceopen">sourceopen</a></code>
+ <li>
+ <dl class="switch">
+ <dt>If the <code><a href="#dom-readyState">readyState</a></code> attribute is set to <code><a href="#dom-%22ended%22">"ended"</a></code>
+</dt>
+ <dd>
+ <ol>
+ <li>Set the <code><a href="#dom-readyState">readyState</a></code> attribute to <code><a href="#dom-%22open%22">"open"</a></code>
</li>
+ <li>Fire a simple event named <code><a href="#dom-sourceopen">sourceopen</a></code> on the <code><a href="#dom-mediasource">MediaSource</a></code> object.</li>
+ </ol>
+ </dd>
+ <dt>Otherwise</dt>
+ <dd>Continue</dd>
+ </dl>
+ </li>
<li>The media element <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-seeking">seeking algorithm</a></code> fires the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#event-media-seeking">seeking</a></code> event</li>
- <li>The media element looks for <a href="#media-segment">media segments</a> containing the desired seek point in the <a href="#source-buffer">source buffers</a> for all the <a href="#active-ids">active IDs</a>
+ <li>The media element looks for <a href="#media-segment">media segments</a> containing the desired seek point in each <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> object in <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code>
</li>
<dl class="switch">
- <dt>If one or more of the <a href="#active-ids">active IDs</a> is missing <a href="#media-segment">media segments</a> for the desired seek point</dt>
+ <dt>If one or more of the objects in <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code> is missing <a href="#media-segment">media segments</a> for the desired seek point</dt>
<dd>
<ol>
- <li>Set <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">readyState</a></code> attribute to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_metadata">HAVE_METADATA</a></code> and fire the <a href="http://dev.w3.org/html5/spec/media-elements.html#mediaevents">appropriate event</a> for this transition.</li>
- <li>The media element waits for the necessary <a href="#media-segment">media segments</a> to be passed to <code><a href="#dom-sourceappend">sourceAppend()</a></code>. The web application can use <code><a href="#dom-sourcebuffered">sourceBuffered()</a></code> to determine what the media element needs to resume playback.</li>
+ <li>Set <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> attribute to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_metadata">HAVE_METADATA</a></code> and fire the <a href="http://dev.w3.org/html5/spec/media-elements.html#mediaevents">appropriate event</a> for this transition.</li>
+ <li>The media element waits for the necessary <a href="#media-segment">media segments</a> to be passed to <code><a href="#dom-append">append()</a></code>. The web application can use <code><a href="#dom-buffered">buffered</a></code> to determine what the media element needs to resume playback.</li>
</ol>
</dd>
<dt>Otherwise</dt>
@@ -600,44 +475,229 @@
<li>The media element resumes the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-seeking">seeking algorithm</a></code> and fires the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#event-media-seeked">seeked</a></code> event indicating that the seek has completed.</li>
</ol>
- <h3 id="buffer-monitoring">5.4 Source Buffer Monitoring</h3>
- <p>The following steps are periodically run during playback to make sure that all of the <a href="#source-buffer">source buffers</a> for the <a href="#active-ids">active IDs</a> have enough data to ensure uninterrupted playback. Appending new segments and changing the set of <a href="#active-ids">active IDs</a> also cause these steps to run because they affect the conditions that trigger state transitions. The web application can monitor changes in <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">readyState</a></code> to drive <a href="#media-segment">media segment</a> appending.</p>
+
+ <h4 id="buffer-monitoring">3.3.4 SourceBuffer Monitoring</h4>
+ <p>The following steps are periodically run during playback to make sure that all of the <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> objects in <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code> have enough data to ensure uninterrupted playback. Appending new segments and changes to <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code> also cause these steps to run because they affect the conditions that trigger state transitions. The web application can monitor changes in <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> to drive <a href="#media-segment">media segment</a> appending.</p>
<dl class="switch">
- <dt>If <code><a href="#dom-sourcebuffered">sourceBuffered()</a></code> for all <a href="#active-ids">active IDs</a> does not contain <code><a href="http://dev.w3.org/html5/spec/media-elements.html#timeranges">TimeRanges</a></code> for the current playback position:</dt>
+ <dt>If <code><a href="#dom-buffered">buffered</a></code> for all objects in <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code> do not contain <code><a href="http://dev.w3.org/html5/spec/media-elements.html#timeranges">TimeRanges</a></code> for the current playback position:</dt>
<dd>
<ol>
- <li>Set <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">readyState</a></code> attribute to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_metadata">HAVE_METADATA</a></code> and fire the <a href="http://dev.w3.org/html5/spec/media-elements.html#mediaevents">appropriate event</a> for this transition.</li>
+ <li>Set <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> attribute to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_metadata">HAVE_METADATA</a></code> and fire the <a href="http://dev.w3.org/html5/spec/media-elements.html#mediaevents">appropriate event</a> for this transition.</li>
<li>Abort remaining steps</li>
</ol>
</dd>
- <dt>If <code><a href="#dom-sourcebuffered">sourceBuffered()</a></code> for all <a href="#active-ids">active IDs</a> contain <code><a href="http://dev.w3.org/html5/spec/media-elements.html#timeranges">TimeRanges</a></code> that include the current playback position and enough data to ensure uninterrupted playback:</dt>
+ <dt>If <code><a href="#dom-buffered">buffered</a></code> for all objects in <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code> contain <code><a href="http://dev.w3.org/html5/spec/media-elements.html#timeranges">TimeRanges</a></code> that include the current playback position and enough data to ensure uninterrupted playback:</dt>
<dd>
<ol>
- <li>Set <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">readyState</a></code> attribute to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_enough_data">HAVE_ENOUGH_DATA</a></code> and fire the <a href="http://dev.w3.org/html5/spec/media-elements.html#mediaevents">appropriate event</a> for this transition.</li>
+ <li>Set <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> attribute to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_enough_data">HAVE_ENOUGH_DATA</a></code> and fire the <a href="http://dev.w3.org/html5/spec/media-elements.html#mediaevents">appropriate event</a> for this transition.</li>
<li>Playback may resume at this point if it was previously suspended by a transition to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_current_data">HAVE_CURRENT_DATA</a></code>.</li>
<li>Abort remaining steps</li>
</ol>
</dd>
- <dt>If <code><a href="#dom-sourcebuffered">sourceBuffered()</a></code> for at least one <a href="#active-ids">active ID</a> contains a <code><a href="http://dev.w3.org/html5/spec/media-elements.html#timeranges">TimeRange</a></code> that includes the current playback position but not enough data to ensure uninterrupted playback:</dt>
+ <dt>If <code><a href="#dom-buffered">buffered</a></code> for at least one object in <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code> contains a <code><a href="http://dev.w3.org/html5/spec/media-elements.html#timeranges">TimeRange</a></code> that includes the current playback position but not enough data to ensure uninterrupted playback:</dt>
<dd>
<ol>
- <li>Set <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">readyState</a></code> attribute to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_future_data">HAVE_FUTURE_DATA</a></code> and fire the <a href="http://dev.w3.org/html5/spec/media-elements.html#mediaevents">appropriate event</a> for this transition.</li>
+ <li>Set <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> attribute to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_future_data">HAVE_FUTURE_DATA</a></code> and fire the <a href="http://dev.w3.org/html5/spec/media-elements.html#mediaevents">appropriate event</a> for this transition.</li>
<li>Playback may resume at this point if it was previously suspended by a transition to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_current_data">HAVE_CURRENT_DATA</a></code>.</li>
<li>Abort remaining steps</li>
</ol>
</dd>
- <dt>If <code><a href="#dom-sourcebuffered">sourceBuffered()</a></code> for at least one <a href="#active-ids">active ID</a> contains a <code><a href="http://dev.w3.org/html5/spec/media-elements.html#timeranges">TimeRange</a></code> that ends at the current playback position and does not have a range covering the time immediately after the current position:</dt>
+ <dt>If <code><a href="#dom-buffered">buffered</a></code> for at least one object in <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code> contains a <code><a href="http://dev.w3.org/html5/spec/media-elements.html#timeranges">TimeRange</a></code> that ends at the current playback position and does not have a range covering the time immediately after the current position:</dt>
<dd>
<ol>
- <li>Set <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">readyState</a></code> attribute to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_current_data">HAVE_CURRENT_DATA</a></code> and fire the <a href="http://dev.w3.org/html5/spec/media-elements.html#mediaevents">appropriate event</a> for this transition.</li>
+ <li>Set <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> attribute to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_current_data">HAVE_CURRENT_DATA</a></code> and fire the <a href="http://dev.w3.org/html5/spec/media-elements.html#mediaevents">appropriate event</a> for this transition.</li>
<li>Playback is suspended at this point since the media element doesn't have enough data to advance the timeline.</li>
<li>Abort remaining steps.</li>
</ol>
</dd>
</dl>
+ <h4 id="active-source-buffer-changes">3.3.5 Changes to selected/enabled track state.</h4>
+ <p>During playback <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code> needs to be updated if the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-videotrack-selected">selected video track</a></code>, the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-audiotrack-enabled">enabled audio tracks</a></code>, or a text track <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-texttrack-mode">mode</a></code> changes. When one or more of these changes occur the following steps need to be followed.</p>
+ <dl class="switch">
+ <dt>If the selected video track changes</dt>
+ <dd>
+ <ol>
+ <li>If the <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> associated with the previously selected video track is not associated with any other enabled tracks then remove it from <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code>
+</li>
+ <li>If the <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> associated with the newly selected video track is not already in <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code> then add it.</li>
+ </ol>
+ </dd>
+ <dt>If an audio track becomes disabled and the <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> associated with this track is not associated with any other enabled or selected track</dt>
+ <dd>Remove the <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> associated with the audio track from <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code>
+</dd>
+ <dt>If an audio track becomes enabled and the <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> associated with this track is not already in <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code>
+</dt>
+ <dd>Add the <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> associated with the audio track to <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code>
+</dd>
+ <dt>If a text track <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-texttrack-mode">mode</a></code> becomes <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-texttrack-disabled">"disabled"</a></code> and the <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> associated with this track is not associated with any other enabled or selected track</dt>
+ <dd>Remove the <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> associated with the text track from <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code>
+</dd>
+ <dt>If a text track <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-texttrack-mode">mode</a></code> becomes <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-texttrack-showing">"showing"</a></code> or <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-texttrack-hidden">"hidden"</a></code> and the <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> associated with this track is not already in <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code>
+</dt>
+ <dd>Add the <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> associated with the text track to <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code>
+</dd>
+ </dl>
+
+
+ <h2 id="sourcebuffer">4. SourceBuffer Object</h2>
+ <pre class="idl">
+interface <dfn id="dom-sourcebuffer">SourceBuffer</dfn> : EventTarget {
+ // Returns the time ranges buffered.
+ readonly attribute TimeRanges <a href="#dom-buffered">buffered</a>;
+
+ // Append segment data.
+ void <a href="#dom-append">append</a>(Uint8Array data);
+
+ // Abort the current segment append sequence.
+ void <a href="#dom-abort">abort</a>();
+};
+ </pre>
+ <p>The <dfn id="dom-buffered"><code>buffered</code></dfn> attribute indicates what <code><a href="http://dev.w3.org/html5/spec/media-elements.html#timeranges">TimeRanges</a></code> are buffered in the <code><a href="#dom-sourcebuffer">SourceBuffer</a></code>. When attribute is read the following steps must occur:</p>
+ <ol>
+ <li>If this object has been removed from the <code><a href="#dom-sourcebuffers">sourceBuffers</a></code> attribute of the <code><a href="#dom-mediasource">MediaSource</a></code> object that created it then throw an <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code> exception and abort these steps.</li>
+ <li>Return <code><a href="http://dev.w3.org/html5/spec/media-elements.html#timeranges">TimeRanges</a></code> for the <a href="#media-segment">media segments</a> buffered.</li>
+ </ol>
+
+ <p>The <dfn id="dom-append"><code>append(data)</code></dfn> method must run the following steps:</p>
+ <ol>
+ <li>If <var title="true">data</var> is null then throw an <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_access_err">INVALID_ACCESS_ERR</a></code> exception and abort these steps.</li>
+ <li>If this object has been removed from the <code><a href="#dom-sourcebuffers">sourceBuffers</a></code> attribute of the <code><a href="#dom-mediasource">MediaSource</a></code> object that created it then throw an <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code> exception and abort these steps.</li>
+ <li>If the <code><a href="#dom-readyState">readyState</a></code> attribute of the <code><a href="#dom-mediasource">MediaSource</a></code> object that created this object is not in the <code><a href="#dom-%22open%22">"open"</a></code> state then throw an <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code> exception and abort these steps.</li>
+ <li>If <var title="true">data</var>.byteLength is 0 abort these steps.</li>
+ <li>Copy contents of <var title="true">data</var> into the source buffer.</li>
+ <li>Handle end of segment cases:</li>
+ <dl class="switch">
+ <dt>If <var title="true">data</var> completes the first <a href="#init-segment">initialization segment</a> appended to the <a href="#source-buffer">source buffer</a> run the following steps:</dt>
+ <dd>
+ <ol>
+ <li>Handle state transitions:</li>
+ <dl class="switch">
+ <dt>If the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> attribute is <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_nothing">HAVE_NOTHING</a></code>:</dt>
+ <dd>Set <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> attribute to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_metadata">HAVE_METADATA</a></code> and fire the <a href="http://dev.w3.org/html5/spec/media-elements.html#mediaevents">appropriate event</a> for this transition.</dd>
+ <dt>If the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> attribute is greater than <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_current_data">HAVE_CURRENT_DATA</a></code> and the <a href="#init-segment">initialization segment</a> contains the first video or first audio track in the presentation:</dt>
+ <dd>
+ Set <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> attribute to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_metadata">HAVE_METADATA</a></code> and fire the <a href="http://dev.w3.org/html5/spec/media-elements.html#mediaevents">appropriate event</a> for this transition.
+ </dd>
+ <dt>Otherwise:</dt>
+ <dd>Continue</dd>
+ </dl>
+ <li>Update <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-audiotracks">audioTracks</a></code>
+</li>
+ <dl class="switch">
+ <dt>If <a href="#init-segment">initialization segment</a> contains the first audio track:</dt>
+ <dd>
+ <ol>
+ <li>Add an <code><a href="http://dev.w3.org/html5/spec/media-elements.html#audiotrack">AudioTrack</a></code> and mark it as enabled.</li>
+ <li>Add this <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> to <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code>.</li>
+ </ol>
+ </dd>
+ <dt>If <a href="#init-segment">initialization segment</a> contains audio tracks beyond those already in the presentation:</dt>
+ <dd>Add a disabled <code><a href="http://dev.w3.org/html5/spec/media-elements.html#audiotrack">AudioTrack</a></code> for each audio track in the <a href="#init-segment">initialization segment</a>.</dd>
+ </dl>
+ <li>Update <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-videotracks">videoTracks</a></code>:</li>
+ <dl class="switch">
+ <dt>If <a href="#init-segment">initialization segment</a> contains the first video track:</dt>
+ <dd>
+ <ol>
+ <li>Add a <code><a href="http://dev.w3.org/html5/spec/media-elements.html#videotrack">VideoTrack</a></code> and mark it as selected.</li>
+ <li>Add this <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> to <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code>.</li>
+ </ol>
+ </dd>
+ <dt>If <a href="#init-segment">initialization segment</a> contains the video tracks beyond those already in the presentation:</dt>
+ <dd>Add a disabled <code><a href="http://dev.w3.org/html5/spec/media-elements.html#videotrack">VideoTrack</a></code> for each video track in the <a href="#init-segment">initialization segment</a>.</dd>
+ </dl>
+ <li>Update <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-texttracks">textTracks</a></code>
+</li>
+ <dl class="switch">
+ <dd>
+ <ol>
+ <li>Add a <code><a href="http://dev.w3.org/html5/spec/media-elements.html#texttrack">TextTrack</a></code> for each text track in the <a href="#init-segment">initialization segment</a>.</li>
+ <li>If the text track <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-texttrack-mode">mode</a></code> is <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-texttrack-showing">"showing"</a></code> or <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-texttrack-hidden">"hidden"</a></code> then add this <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> to <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code>.</li>
+ </ol>
+ </dd>
+ </dl>
+ </ol>
+ </dd>
+ <dt>If the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> attribute is <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_metadata">HAVE_METADATA</a></code> and <var title="true">data</var> causes all objects in <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code> to have media data for the current playback position.</dt>
+ <dd>Set <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> attribute to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_current_data">HAVE_CURRENT_DATA</a></code> and fire the <a href="http://dev.w3.org/html5/spec/media-elements.html#mediaevents">appropriate event</a> for this transition.</dd>
+ <dt>If the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> attribute is <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_current_data">HAVE_CURRENT_DATA</a></code> and <var title="true">data</var> causes all objects in <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code> to have media data beyond the current playback position.</dt>
+ <dd>Set <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> attribute to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_future_data">HAVE_FUTURE_DATA</a></code> and fire the <a href="http://dev.w3.org/html5/spec/media-elements.html#mediaevents">appropriate event</a> for this transition.</dd>
+ <dt>If the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> attribute is <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_future_data">HAVE_FUTURE_DATA</a></code> and <var title="true">data</var> causes all objects in <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code> to have enough data to start playback.</dt>
+ <dd>Set <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> attribute to <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_enough_data">HAVE_ENOUGH_DATA</a></code> and fire the <a href="http://dev.w3.org/html5/spec/media-elements.html#mediaevents">appropriate event</a> for this transition.</dd>
+ </dl>
+ </ol>
+
+ <p>The <dfn id="dom-abort"><code>abort()</code></dfn> method must run the following steps:</p>
+ <ol>
+ <li>If this object has been removed from the <code><a href="#dom-sourcebuffers">sourceBuffers</a></code> attribute of the <code><a href="#dom-mediasource">MediaSource</a></code> object that created it then throw an <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code> exception and abort these steps.</li>
+ <li>If the <code><a href="#dom-readyState">readyState</a></code> attribute of the <code><a href="#dom-mediasource">MediaSource</a></code> object that created this object is not in the <code><a href="#dom-%22open%22">"open"</a></code> state then throw an <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code> exception and abort these steps.</li>
+ <li>The media element aborts parsing the current segment.</li>
+ <dl class="switch">
+ <dt>If waiting for the start of a new segment</dt>
+ <dd>Continue</dd>
+ <dt>If the current segment is an <a href="#init-segment">initialization segment</a>
+</dt>
+ <dd>Flush any data associated with this partial segment.</dd>
+ <dt>If the current segment is a <a href="#media-segment">media segment</a>
+</dt>
+ <dd>The media element may keep any media data it finds valuable in the partial segment. For example if the abort happens in the middle of a 10 second <a href="#media-segment">media segment</a>, the media element may choose to keep the 5 seconds of media data it has already parsed in the source buffer. <code><a href="#dom-buffered">buffered</a></code> will reflect what data, if any, was kept.</dd>
+ </dl>
+ <li>The media element resets the segment parser so that it can accept a new <a href="#init-segment">initialization segment</a> or <a href="#media-segment">media segment</a>.</li>
+ </ol>
+
+ <h2 id="sourcebufferlist">5. SourceBufferList Object</h2>
+ <p>SourceBufferList is a simple container object for <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> objects. It provides a read-only array accessor, fires events when the list is modified, and provides a way to remove SourceBuffer objects from the list.</p>
+
+ <pre class="idl">
+interface <dfn id="dom-sourcebufferlist">SourceBufferList</dfn> : EventTarget {
+ readonly attribute unsigned long <a href="#dom-length">length</a>;
+ <a href="#dom-getter">getter</a> <a href="#dom-sourcebuffer">SourceBuffer</a> (unsigned long index);
+ void <a href="#dom-remove">remove</a>(<a href="#dom-sourcebuffer">SourceBuffer</a> buffer);
+};
+ </pre>
+ <h3 id="sourcebufferlist-methods">5.1. Methods and Attributes</h3>
+ <p>The <dfn id="dom-length"><code>length</code></dfn> attribute indicates the number of <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> objects in the list.</p>
+ <p>The <dfn id="dom-getter"><code>getter SourceBuffer (unsigned long <var title="true">index</var>)</code></dfn> method allows the SourceBuffer objects in the list to be accessed with an array operator (i.e. []). This method must run the following steps:</p>
+ <ol>
+ <li>If <var title="true">index</var> is greater than or equal to the <code><a href="#dom-length">length</a></code> attribute then return undefined and abort these steps.</li>
+ <li>Return the <var title="true">index</var>'th <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> object in the list.</li>
+ </ol>
+ <p>The <dfn id="dom-remove"><code>remove(buffer)</code></dfn> method must run the following steps:</p>
+ <ol>
+ <li>If <var title="true">buffer</var> is null then throw an <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_access_err">INVALID_ACCESS_ERR</a></code> exception and abort these steps.</li>
+ <li>If the list is empty then throw an <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code> exception and abort these steps.</li>
+ <li>If <var title="true">buffer</var> specifies an object that is not in this list then throw a <code><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-not_found_err">NOT_FOUND_ERR</a></code> exception and abort these steps.</li>
+ <li>Remove track information from <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-audiotracks">audioTracks</a></code>, <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-videotracks">videoTracks</a></code>, and <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-texttracks">textTracks</a></code> for all tracks associated with <var title="true">buffer</var> and fire a simple event named <code><a href="http://dev.w3.org/html5/spec/media-elements.html#handler-tracklist-onchange">change</a></code> on the modified lists.</li>
+ <li>Destroy all resources for <var title="true">buffer</var>.</li>
+ <li>Remove <var title="true">buffer</var> from the list and fire an <code><a href="#dom-removesourcebuffer">removesourcebuffer</a></code> event.</li>
+ </ol>
+
+ <h3 id="sourcebufferlist-events">5.2. Event Summary</h3>
+ <table>
+ <thead>
+ <tr>
+ <th>Event name</th>
+ <th>Interface</th>
+ <th>Dispatched when...</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td><dfn id="dom-addsourcebuffer"><code>addsourcebuffer</code></dfn></td>
+ <td><code>Event</code></td>
+ <td>When a <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> is added to the list.</td>
+ </tr>
+ <tr>
+ <td><dfn id="dom-removesourcebuffer"><code>removesourcebuffer</code></dfn></td>
+ <td><code>Event</code></td>
+ <td>When a <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> is removed from the list.</td>
+ </tr>
+ </tbody>
+ </table>
+
<h2 id="byte-stream-formats">6. Byte Stream Formats</h2>
- <p>The bytes provided through <code><a href="#dom-sourceappend">sourceAppend()</a></code> for a <a href="#source-id">source ID</a> form a logical byte stream. The format of this byte stream depends on the media container format in use and is defined in a byte stream format specification. Byte stream format specifications based on WebM and the ISO Base Media File Format are provided below. If these formats are supported then the byte stream formats described below MUST be supported.</p>
+ <p>The bytes provided through <code><a href="#dom-append">append()</a></code> for a <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> form a logical byte stream. The format of this byte stream depends on the media container format in use and is defined in a byte stream format specification. Byte stream format specifications based on WebM and the ISO Base Media File Format are provided below. If these formats are supported then the byte stream formats described below MUST be supported.</p>
<p>This section provides general requirements for all byte stream formats:</p>
<ul>
<li>A byte stream format specification MAY define <a href="#init-segment">initialization segments</a> and MUST define <a href="#media-segment">media segments</a>.</li>
@@ -736,99 +796,82 @@
<div class="blockContent">
<pre class="code">
<script>
- var sourceID = "123";
-
- function onOpen(e) {
- var video = e.target;
+ function onSourceOpen(videoTag, e) {
+ var mediaSource = e.target;
+ var sourceBuffer = mediaSource.addSourceBuffer('video/webm; codecs="vorbis,vp8"');
- var headers = GetStreamHeaders();
+ videoTag.addEventListener('seeking', onSeeking.bind(videoTag, mediaSource));
+ videoTag.addEventListener('progress', onProgress.bind(videoTag, mediaSource));
- if (headers == null) {
- // Error fetching headers. Signal end of stream with an error.
- video.sourceEndOfStream(HTMLMediaElement.EOS_NETWORK_ERR);
+ var initSegment = GetInitializationSegment();
+
+ if (initSegment == null) {
+ // Error fetching the initialization segment. Signal end of stream with an error.
+ mediaSource.endOfStream("network");
+ return;
}
- video.sourceAddId(sourceID, 'video/webm; codecs="vorbis,vp8"');
-
- // Append the stream headers (i.e. WebM Header, Info, and Tracks elements)
- video.sourceAppend(sourceID, headers);
+ // Append the initialization segment.
+ sourceBuffer.append(initSegment);
// Append some initial media data.
- video.sourceAppend(sourceID, GetNextCluster());
+ appendNextMediaSegment(mediaSource);
}
- function onSeeking(e) {
+ function appendNextMediaSegment(mediaSource) {
+ if (mediaSource.readyState == "ended")
+ return;
+
+ // If we have run out of stream data, then signal end of stream.
+ if (!HaveMoreMediaSegments()) {
+ mediaSource.endOfStream();
+ return;
+ }
+
+ var mediaSegment = GetNextMediaSegment();
+
+ if (!mediaSegment) {
+ // Error fetching the next media segment.
+ mediaSource.endOfStream("network");
+ return;
+ }
+
+ mediaSource.sourceBuffers[0].append(mediaSegment);
+ }
+
+ function onSeeking(mediaSource, e) {
var video = e.target;
// Abort current segment append.
- video.sourceAbort(sourceID);
+ mediaSource.sourceBuffers[0].abort();
- // Notify the cluster loading code to start fetching data at the
+ // Notify the media segment loading code to start fetching data at the
// new playback position.
- SeekToClusterAt(video.currentTime);
+ SeekToMediaSegmentAt(video.currentTime);
- // Append clusters from the new playback position.
- video.sourceAppend(sourceID, GetNextCluster());
- video.sourceAppend(sourceID, GetNextCluster());
+ // Append media segments from the new playback position.
+ appendNextMediaSegment(mediaSource);
+ appendNextMediaSegment(mediaSource);
}
- function onProgress(e) {
- var video = e.target;
-
- if (video.sourceState == video.SOURCE_ENDED)
- return;
-
- // If we have run out of stream data, then signal end of stream.
- if (!HaveMoreClusters()) {
- video.sourceEndOfStream(HTMLMediaElement.EOS_NO_ERROR);
- return;
- }
-
- video.sourceAppend(sourceID, GetNextCluster());
+ function onProgress(mediaSource, e) {
+ appendNextMediaSegment(mediaSource);
}
-
- var video = document.getElementById('v');
- video.addEventListener('sourceopen', onOpen);
- video.addEventListener('seeking', onSeeking);
- video.addEventListener('progress', onProgress);
</script>
<video id="v" autoplay> </video>
<script>
var video = document.getElementById('v');
- video.src = video.mediaSourceURL;
+ var mediaSource = new MediaSource();
+ mediaSource.addEventListener('sourceopen', onSourceOpen.bind(this, video));
+ video.src = window.URL.createObjectURL(mediaSource);
</script>
</pre>
</div>
</div>
- <h2 id="open-issues">8. Open Issues</h2>
- <p>This section contains issues that have come up during the spec update process, but haven't been resolved yet. The issues and potential solutions are listed below. The potential solutions are just initial thoughts and have not been subjected to rigorous discussion yet.</p>
-
- <h3>8.1. Buffer Management</h3>
- <p class="issue">Concerns were raised about limiting the amount of data that JavaScript can append on memory constrained devices. We have briefly discussed making sourceAppend() asynchronous and allowing an "append done" event to fire when the user agent is ready to accept more data.</p>
-
- <h3>8.2. Capability Detection</h3>
- <p class="issue">Since user agents may have different limitations on how they handle media segment overlaps, the web application needs a mechanism to detect the user agent's capabilities. We have briefly discussed adding a parameter, similar to 'codec', to the MIME type passed to sourceAddId(). We have not discussed any specific details beyond that.</p>
-
- <h3>8.3. Append URL</h3>
- <p class="issue">There have been discussions about changing sourceAppend() to take a URL and optional start & end offset parameters instead of a Uint8Array. The current byte stream specs don't really require access to the raw bytes and if JavaScript wants to construct its own stream from bytes it could use a BlobBuilder and a Blob URL. Going down this path removes the need for a streaming XHR API and could improve interactions with the browser cache. Download progress could be reported through an "append progress" event so that bitrate calculations could be made by JavaScript.</p>
-
- <h3>8.4. Timestamp Offset</h3>
- <p class="issue">There have been some discussions about adding a method that applies an offset to the timestamps in media segments. Ad insertion and mashups where the content being appended does not have timestamps that match the desired location in the presentation timeline are the primary motivators for this feature. A method along the lines of sourceTimestampMapping(presentationTimestamp, segmentTimestamp) could specify the timestamp mapping to use for future media segments that get appended. The mapping would be applied at append time before the data goes into the source buffer. Adding a feature like this would prevent the web application from having to rewrite timestamps in the media segments. The exact semantics and details of this feature still need to be worked out.</p>
-
- <h3>8.5. Timed Text</h3>
- <p class="issue">The current text focuses on behavior for audio and video. Behavior for timed text still needs to be defined.</p>
-
- <h3>8.6. WebAudio Integration</h3>
- <p class="issue">This proposal may overlap with portions of the <a href="http://www.w3.org/TR/2012/WD-webaudio-20120315/">Audio WG draft</a>. Further investigation is needed around how these two proposals will work together.</p>
-
- <h3>8.7. Track Identification and Management</h3>
- <p class="issue">Define how language and kind can be set on <code><a href="http://dev.w3.org/html5/spec/media-elements.html#audiotrack">AudioTrack</a></code> & <code><a href="http://dev.w3.org/html5/spec/media-elements.html#videotrack">VideoTrack</a></code> objects. This information may be inside the manifest instead of <a href="#init-segment">initialization segments</a> so we need a way for JavaScript to set this.</p>
- <p class="issue">Specify a way to identify which <a href="#source-id">source ID</a> an <code><a href="http://dev.w3.org/html5/spec/media-elements.html#audiotrack">AudioTrack</a></code> or <code><a href="http://dev.w3.org/html5/spec/media-elements.html#videotrack">VideoTrack</a></code> is associated with.</p>
-
- <h2 id="revision-history">9. Revision History</h2>
+ <h2 id="revision-history">8. Revision History</h2>
<table>
<thead>
<tr>
@@ -838,7 +881,15 @@
</thead>
<tbody>
<tr>
- <td>0.5</td>
+ <td>02 July 2012</td>
+ <td>Converted to the object-oriented API</td>
+ </tr>
+ <tr>
+ <td><a href="http://dvcs.w3.org/hg/html-media/raw-file/9bbfe09653e4/media-source/media-source.html">26 June 2012</a></td>
+ <td>Converted to Editor's draft.</td>
+ </tr>
+ <tr>
+ <td><a href="http://dvcs.w3.org/hg/html-media/raw-file/e433598d22a7/media-source/media-source.html">0.5</a></td>
<td>Minor updates before proposing to W3C HTML-WG.</td>
</tr>
<tr>
--- a/media-source/media-source.xml Fri Jun 29 08:24:15 2012 -0400
+++ b/media-source/media-source.xml Mon Jul 02 16:05:53 2012 -0700
@@ -41,12 +41,12 @@
<div class="head">
<p><a href="http://www.w3.org/"><img src="http://www.w3.org/Icons/w3c_home" alt="W3C" width="72" height="48" /></a></p>
<h1>Media Source Extensions</h1>
- <h2>W3C Editor's Draft 26 June 2012</h2>
+ <h2>W3C Editor's Draft 02 July 2012</h2>
<dl>
<dt>Latest published version:</dt>
<dd>Not yet published</dd>
- <dt>Latest editor's draft:</dt>
- <dd><a href="http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html">http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html</a></dd>
+ <dt>Latest editor's draft:</dt>
+ <dd><a href="http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html">http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html</a></dd>
<dt>Editors:</dt>
<dd>Aaron Colwell, Google, Inc.</dd>
<dd>Adrian Bateman, Microsoft Corporation</dd>
@@ -110,10 +110,10 @@
<li><a href="#definitions">1.2 Definitions</a></li>
</ul>
</li>
- <li><a href="#source-buffer-model">2 Source Buffer Model</a></li>
+ <li><a href="#source-buffer-model">2. Source Buffer Model</a></li>
<li>
<ul>
- <li><a href="#source-buffer-add-id">2.1. Adding a new Source ID</a></li>
+ <li><a href="#source-buffer-create">2.1. Creating Source Buffers</a></li>
<li><a href="#source-buffer-basic-append">2.2. Basic appending model</a></li>
<li><a href="#source-buffer-init-segment-constraints">2.3. Initialization Segment constraints</a></li>
<li><a href="#source-buffer-media-segment-constraints">2.4. Media Segment constraints</a></li>
@@ -122,17 +122,22 @@
<li><a href="#source-buffer-overlapping-segments">2.7. Appending a Media Segment over a buffered region</a></li>
<li><a href="#source-buffer-to-track-buffer">2.8. Source Buffer to Track Buffer transfer</a></li>
<li><a href="#source-buffer-segment-eviction">2.9. Media Segment Eviction</a></li>
- <li><a href="#source-buffer-remove-id">2.10. Removing a Source ID</a></li>
+ <li><a href="#source-buffer-remove">2.10. Removing Source Buffers</a></li>
</ul>
</li>
- <li><a href="#mediasource">3. Media Element Extensions</a>
- <li><a href="#event-summary">4. Event Summary</a></li>
- <li><a href="#algorithms">5. Algorithms</a></li>
- <ul style="list-style-type:none">
- <li><a href="#algorithms-attach">5.1 Attaching to a media element</a></li>
- <li><a href="#algorithms-detach">5.2 Detaching from a media element</a></li>
- <li><a href="#seeking">5.3 Seeking</a></li>
- </ul>
+ <li><a href="#mediasource">3. MediaSource Object</a>
+ <ul>
+ <li><a href="#mediasource-methods">3.1. Methods and Attributes</a></li>
+ <li><a href="#mediasource-events">3.2. Event Summary</a></li>
+ <li><a href="#mediasource-algorithms">3.3. Algorithms</a></li>
+ </ul>
+ </li>
+ <li><a href="#sourcebuffer">4. SourceBuffer Object</a></li>
+ <li><a href="#sourcebufferlist">5. SourceBufferList Object</a>
+ <ul>
+ <li><a href="#sourcebufferlist-methods">5.1. Methods and Attributes</a></li>
+ <li><a href="#sourcebufferlist-events">5.2. Event Summary</a></li>
+ </ul>
</li>
<li><a href="#byte-stream-formats">6. Byte Stream Formats</a></li>
<li>
@@ -142,13 +147,12 @@
</ul>
</li>
<li><a href="#examples">7. Examples</a></li>
- <li><a href="#open-issues">8. Open Issues</a></li>
- <li><a href="#revision-history">9. Revision History</a></li>
+ <li><a href="#revision-history">8. Revision History</a></li>
</ul>
<h2 id="introduction">1. Introduction</h2>
<p>This proposal allows JavaScript to dynamically construct media streams for <audio> and <video>.
- It defines extensions to <videoref name="htmlmediaelement">HTMLMediaElement</videoref> that allow JavaScript to pass media segments to the user agent.
+ It defines objects that allow JavaScript to pass media segments to an <videoref name="htmlmediaelement">HTMLMediaElement</videoref>.
A buffering model is also included to describe how the user agent should act when different media segments are
appended at different times. Byte stream specifications for WebM & ISO Base Media File Format are given to specify the
expected format of media segments used with these extensions.</p>
@@ -166,19 +170,8 @@
</ul>
<h3 id="definitions">1.2. Definitions</h3>
- <h4 id="active-ids">1.2.1. Active IDs</h4>
- <p>The set of <source-ids/> that are providing the <videoref name="dom-videotrack-selected">selected video track</videoref> and the <videoref name="dom-audiotrack-enabled">enabled audio tracks</videoref>.</p>
-
- <h4 id="source-id">1.2.2. Source ID</h4>
- <p>An ID registered with <sourceAddId/> that identifies a distinct sequence of <init-segments/> & <media-segments/> appended to a specific <source-buffer/>.</p>
- <h4 id="source-buffer">1.2.3. Source Buffer</h4>
- <p>A hypothetical buffer that contains the <media-segments/> for a particular <source-id/>. When <media-segments/> are passed to <sourceAppend/> they update the state of this buffer. The source buffer only allows a single <media-segment/> to cover a specific point in the presentation timeline of each track. If a <media-segment/> gets appended that contains media data overlapping (in presentation time) with media data from an existing segment, then the new media data will override the old media data. Since <media-segments/> depend on <init-segments/> the source buffer is also responsible for maintaining these associations. During playback, the media element pulls segment data out of the source buffers, demultiplexes it if necessary, and enqueues it into <track-buffers/> so it will get decoded and displayed. <sourceBuffered/> describes the time ranges that are covered by <media-segments/> in the source buffer.</p>
-
- <h4 id="track-buffer">1.2.4. Track Buffer</h4>
- <p>A hypothetical buffer that represents initialization and media data for a single <audio-track/> or <video-track/> that has been queued for playback. This buffer may not exist in actual implementations, but it is intended to represent media data that will be decoded no matter what <media-segments/> are appended to update the <source-buffer/>. This distinction is important when considering appends that happen close to the current playback position. Details about transfers between the <source-buffer/> and track buffers are given <a href="#source-buffer-to-track-buffer">here</a>.</p>
-
- <h4 id="init-segment">1.2.5. Initialization Segment</h4>
+ <h4 id="init-segment">1.2.1. Initialization Segment</h4>
<p>A sequence of bytes that contains all of the initialization information required to decode a sequence of <media-segments/>. This includes codec initialization data, trackID mappings for multiplexed segments, and timestamp offsets (e.g. edit lists).</p>
<dl class="example">
@@ -189,7 +182,7 @@
<dd>The concatenation of the the EBML Header, Segment Header, Info element, and Tracks element.</dd>
</dl>
- <h4 id="media-segment">1.2.6. Media Segment</h4>
+ <h4 id="media-segment">1.2.2. Media Segment</h4>
<p>A sequence of bytes that contain packetized & timestamped media data for a portion of the presentation timeline. Media segments are always associated with the most recently appended <init-segment/>.</p>
<dl class="domintro">
@@ -200,22 +193,34 @@
<dd>A Cluster element</dd>
</dl>
- <h4 id="random-access-point">1.2.7. Random Access Point</h4>
+ <h4 id="source-buffer">1.2.3. Source Buffer</h4>
+ <p>A hypothetical buffer that contains a distinct sequence of <init-segments/> & <media-segments/>. When <media-segments/> are passed to <append/> they update the state of this buffer. The source buffer only allows a single <media-segment/> to cover a specific point in the presentation timeline of each track. If a <media-segment/> gets appended that contains media data overlapping (in presentation time) with media data from an existing segment, then the new media data will override the old media data. Since <media-segments/> depend on <init-segments/> the source buffer is also responsible for maintaining these associations. During playback, the media element pulls segment data out of the source buffers, demultiplexes it if necessary, and enqueues it into <track-buffers/> so it will get decoded and displayed. <buffered/> describes the time ranges that are covered by <media-segments/> in the source buffer.</p>
+
+ <h4 id="active-source-buffers">1.2.4. Active Source Buffers</h4>
+ <p>The set of <source-buffers/> that are providing the <videoref name="dom-videotrack-selected">selected video track</videoref>, the <videoref name="dom-audiotrack-enabled">enabled audio tracks</videoref>, and the <videoref name="dom-texttrack-showing">"showing"</videoref> or <videoref name="dom-texttrack-hidden">"hidden"</videoref> text tracks. This is a subset of all the source buffers associated with a specific <MediaSource/> object. Details about how this set is managed are given <a href="#active-source-buffer-changes">here</a>.</p>
+
+
+ <h4 id="track-buffer">1.2.5. Track Buffer</h4>
+ <p>A hypothetical buffer that represents initialization and media data for a single <audio-track/>, <video-track/>, or <text-track/> that has been queued for playback. This buffer may not exist in actual implementations, but it is intended to represent media data that will be decoded no matter what <media-segments/> are appended to update the <source-buffer/>. This distinction is important when considering appends that happen close to the current playback position. Details about transfers between the <source-buffer/> and track buffers are given <a href="#source-buffer-to-track-buffer">here</a>.</p>
+
+
+ <h4 id="random-access-point">1.2.6. Random Access Point</h4>
<p>A position in a <media-segment/> where decoding and continuous playback can begin without relying on any previous data in the segment. For video this tends to be the location of I-frames. In the case of audio, most audio frames can be treated as a random access point. Since video tracks tend to have a more sparse distribution of random access points, the location of these points are usually considered the random access points for multiplexed streams.</p>
+
<h2 id="source-buffer-model">2. Source Buffer Model</h2>
<p>The subsections below outline the buffering model for this proposal. It describes how to add and remove <source-buffers/> from the presentation and describes the various rules and behaviors associated with appending data to an individual <source-buffer/>. At the highest level, the web application simply creates <source-buffers/> and appends a sequence of <init-segments/> and <media-segments/> to update the buffer's state. The media element pulls media data out of the <source-buffers/>, plays it, and fires events just like it would if a normal URL was passed to the <media-src/> attribute. The web application is expected to monitor media element events to determine when it needs to append more <media-segments/>.</p>
- <h3 id="source-buffer-add-id">2.1. Adding a new Source ID</h3>
- <p>Creating a new <source-buffer/> is initiated by calling <sourceAddId/>. This method allows the web application to specify the <source-id/> it wants to associate with a new <source-buffer/> and indicates the format of the data it intends to append. The user agent looks at the type information and determines whether it supports the desired format and has sufficient resources to handle a new <source-buffer/> for this device. If the user agent can't support another <source-id/> then it will throw an appropriate exception to signal why the request couldn't be satisfied.</p>
+ <h3 id="source-buffer-create">2.1. Creating Source Buffers</h3>
+ <p><SourceBuffer/> objects can be created once a <MediaSource/> object enters the <open/> state. The application calls <addSourceBuffer/> with a type string that indicates the format of the data it intends to append to the new SourceBuffer. If the user agent supports the format and has sufficent resources, a new <SourceBuffer/> object is created, added to <sourceBuffers/>, and returned by the method. If the user agent doesn't support the specified format or can't support another <SourceBuffer/> then it will throw an appropriate exception to signal why the request couldn't be satisfied.</p>
<h3 id="source-buffer-basic-append">2.2. Basic appending model</h3>
- <p>Updating the state of a <source-buffer/> requires appending at least one <init-segment/> and one or more <media-segments/> via <sourceAppend/>. The following list outlines some of the basic rules for appending segments.
+ <p>Updating the state of a <source-buffer/> requires appending at least one <init-segment/> and one or more <media-segments/> via <append/>. The following list outlines some of the basic rules for appending segments.
<ul>
<li>The first segment appended MUST be an <init-segment/>.</li>
<li>All <media-segments/> are associated with the most recently appended <init-segment/>.</li>
- <li>A whole segment must be appended before another segment can be started unless <sourceAbort/> is called.</li>
- <li>Segments can be appended in pieces. (i.e. A 4096 byte segment can be spread across four 1024 byte calls to <sourceAppend/>).</li>
+ <li>A whole segment must be appended before another segment can be started unless <abort/> is called.</li>
+ <li>Segments can be appended in pieces. (i.e. A 4096 byte segment can be spread across four 1024 byte calls to <append/>).</li>
<li>If a <media-segment/> requires different configuration information (e.g. codec parameters, new internal trackIDs, metadata) from what is in the most recently appended <init-segment/>, a new <init-segment/> with the new configuration information MUST be appended before the <media-segment/> requiring this information is appended.</li>
<li>A new <media-segment/> can overlap, in presentation time, a segment that was previously appended. The new segment will override the previous data.</li>
<li>Media segments can be appended in any order.<br/>Note: In practice finite buffer space and maintaining uninterrupted playback will bias appending towards time increasing order near the current playback position. Out of order appends facilitate adaptive streaming, ad insertion, and video editing use cases.</li>
@@ -224,31 +229,31 @@
</p>
<h3 id="source-buffer-init-segment-constraints">2.3. Initialization Segment constraints</h3>
- <p>To simplify the implementation and facilitate interoperability, a few constraints are placed on the <init-segments/> that are appended to a specific <source-id/>:
+ <p>To simplify the implementation and facilitate interoperability, a few constraints are placed on the <init-segments/> that are appended to a specific <SourceBuffer/>:
<ul>
- <li>The number and type of tracks MUST be consistent across all <init-segments/>. <br/>For example, if the first <init-segment/> has 2 audio tracks and 1 video track, then all <init-segments/> that follow, for this <source-id/> MUST describe 2 audio tracks and 1 video track.</li>
+ <li>The number and type of tracks MUST be consistent across all <init-segments/>. <br/>For example, if the first <init-segment/> has 2 audio tracks and 1 video track, then all <init-segments/> that follow, for this <SourceBuffer/> MUST describe 2 audio tracks and 1 video track.</li>
<li>Internal trackIDs do not need to be the same across <init-segments/> only if the segment describes one track of each type.<br/> For example, if an <init-segment/> describes a single audio track and a single video track, the internal trackIDs do not need to be the same.</li>
<li>Internal trackIDs MUST be the same across <init-segments/> if multiple tracks for a single type are described. (e.g. 2 audio tracks).</li>
- <li>Codecs changes are not allowed. <br/> For example, you can't have an <init-segment/> that specifies a single AAC track and then follows it with one that contains AMR-WB. Support for multiple codecs is handled with multiple <source-ids/>.</li>
+ <li>Codecs changes are not allowed. <br/> For example, you can't have an <init-segment/> that specifies a single AAC track and then follows it with one that contains AMR-WB. Support for multiple codecs is handled with multiple <SourceBuffer/> objects.</li>
<li>Video frame size changes are allowed and MUST be supported seamlessly.<br/> Note: This will cause the <video> display region to change size if you don't use CSS or HTML attributes (width/height) to constrain the element size.</li>
<li>Audio channel count changes are allowed, but they may not be seamless and could trigger downmixing.<br/> Note: This is a quality of implementation issue because changing the channel count may require reinitializing the audio device, resamplers, and channel mixers which tends to be audible.</li>
</ul>
</p>
<h3 id="source-buffer-media-segment-constraints">2.4. Media Segment constraints</h3>
- <p>To simplify the implementation and facilitate interoperability, a few constraints are placed on the <media-segments/> that are appended to a specific <source-id/>:
+ <p>To simplify the implementation and facilitate interoperability, a few constraints are placed on the <media-segments/> that are appended to a specific <SourceBuffer/>:
<ul>
<li>All timestamps must be mapped to the same presentation timeline.</li>
<li>Segments should start with a <random-access-point/> to facilitate seamless splicing at the segment boundary.</li>
- <li>Gaps between <media-segments/> that are smaller than the audio frame size are allowed and should be rendered as silence. Such gaps should not be reflected by <sourceBuffered/>.<br/>Note: This is intended to simplify switching between audio streams where the frame boundaries don't always line up across encodings (e.g. Vorbis).</li>
+ <li>Gaps between <media-segments/> that are smaller than the audio frame size are allowed and should be rendered as silence. Such gaps should not be reflected by <buffered/>.<br/>Note: This is intended to simplify switching between audio streams where the frame boundaries don't always line up across encodings (e.g. Vorbis).</li>
</ul>
</p>
<h3 id="source-buffer-first-init-segment">2.5. Appending the first Initialization Segment</h3>
- <p>Once a new <source-id/> has been added, the <source-buffer/> expects an <init-segment/> to be appended first. This first segment indicates the number and type of streams contained in the <media-segments/> that follow. This allows the media element to configure the necessary decoders and output devices. This first segment can also cause a <ready-state/> transition to <have-metadata/> if this is the first <source-id/> registered, or if it is the first track of a specific type (i.e. first audio or first video track). If neither of the conditions hold then the tracks for this new <source-id/> will just appear as disabled tracks and won't affect the current <ready-state/> until they are selected. The media element will also add the appropriate tracks to the <audiotracks/> & <videotracks/> collections and fire the necessary <videoref name="handler-tracklist-onchange">change</videoref> events. The description for <sourceAppend/> contains all the details.</p>
+ <p>Once a new <SourceBuffer/> has been created, it expects an <init-segment/> to be appended first. This first segment indicates the number and type of streams contained in the <media-segments/> that follow. This allows the media element to configure the necessary decoders and output devices. This first segment can also cause a <ready-state/> transition to <have-metadata/> if this is the first <SourceBuffer/>, or if it is the first track of a specific type (i.e. first audio, first video track, or first text track). If neither of the conditions hold then the tracks for this new <SourceBuffer/> will just appear as disabled tracks and won't affect the current <ready-state/> until they are selected. The media element will also add the appropriate tracks to the <audiotracks/>, <videotracks/>, & <texttracks/> collections and fire the necessary <videoref name="handler-tracklist-onchange">change</videoref> events. The description for <append/> contains all the details.</p>
<h3 id="source-buffer-media-segment-unbuffered">2.6. Appending a Media Segment to an unbuffered region</h3>
- <p>If a <media-segment/> is appended to a time range that is not covered by existing segments in the <source-buffer/>, then its data is copied directly into the <source-buffer/>. Addition of this data may trigger <ready-state/> transitions depending on what other data is buffered and whether the media element has determined if it can start playback. Calls to <sourceBuffered/> will always reflect the current <timeranges/> buffered in the <source-buffer/>.</p>
+ <p>If a <media-segment/> is appended to a time range that is not covered by existing segments in the <source-buffer/>, then its data is copied directly into the <source-buffer/>. Addition of this data may trigger <ready-state/> transitions depending on what other data is buffered and whether the media element has determined if it can start playback. Calls to <buffered/> will always reflect the current <timeranges/> buffered in the <SourceBuffer/>.</p>
<h3 id="source-buffer-overlapping-segments">2.7. Appending a Media Segment over a buffered region</h3>
<p>There are several ways that <media-segments/> can overlap segments in the <source-buffer/>. Behavior for the different overlap situations are described below. If more than one overlap applies, then the <a href="#source-buffer-overlap-start">start overlap</a> gets resolved first, followed by any <a href="#source-buffer-overlap-complete">complete overlaps</a>, and finally the <a href="#source-buffer-overlap-end">end overlap</a>. If a segment contains multiple tracks then the overlap is resolved independently for each track.</p>
@@ -259,116 +264,283 @@
<h4 id="source-buffer-overlap-start">2.7.2 Start Overlap</h4>
<img src="start_overlap.png"/>
<p>The figure above shows how the <source-buffer/> gets updated when the beginning of a new <media-segment/> overlaps a segment in the buffer. In this case the new segment replaces all the old media data in the overlapping region. Since <media-segments/> are constrained to starting with <random-access-points/>, this provides a seamless transition between segments.</p>
- <p>The one case that requires special attention is where an audio frame overlaps with the start of the new <media-segment/>. The base level behavior that MUST be supported requires dropping the old audio frame that overlaps the start of the new segment and inserting silence for the small gap that is created. A higher quality implementation could support outputting a portion of the old segment and all of the new segment or crossfade during the overlapping region. This is a quality of implementation issue. The key property here though is the small silence gap should not be reflected in the ranges reported by <sourceBuffered/></p>
+ <p>The one case that requires special attention is where an audio frame overlaps with the start of the new <media-segment/>. The base level behavior that MUST be supported requires dropping the old audio frame that overlaps the start of the new segment and inserting silence for the small gap that is created. A higher quality implementation could support outputting a portion of the old segment and all of the new segment or crossfade during the overlapping region. This is a quality of implementation issue. The key property here though is the small silence gap should not be reflected in the ranges reported by <buffered/></p>
<h4 id="source-buffer-overlap-end">2.7.3 End Overlap</h4>
<img src="end_overlap.png"/>
- <p>The figure above shows how the <source-buffer/> gets updated when the end of a new <media-segment/> overlaps a segment in the buffer. In this case, the media element tries to keep as much of the old segment as possible. The amount saved depends on where the closest <random-access-point/>, in the old segment, is to the end of the new segment. In the case of audio, if the gap is smaller than the size of an audio frame, then the media element should insert silence for this gap and not reflect it in <sourceBuffered/>.</p>
- <p>An implementation may keep old segment data before the end of the new segment to avoid creating a gap if it wishes. Doing this though can significantly increase implementation complexity and could cause delays at the splice point. The key property that must be preserved is the entirety of the new segment gets added to the <source-buffer/> and it is up to the implementation how much of the old segment data is retained. The web application can use <sourceBuffered/> to determine how much of the old segment was preserved.</p>
+ <p>The figure above shows how the <source-buffer/> gets updated when the end of a new <media-segment/> overlaps a segment in the buffer. In this case, the media element tries to keep as much of the old segment as possible. The amount saved depends on where the closest <random-access-point/>, in the old segment, is to the end of the new segment. In the case of audio, if the gap is smaller than the size of an audio frame, then the media element should insert silence for this gap and not reflect it in <buffered/>.</p>
+ <p>An implementation may keep old segment data before the end of the new segment to avoid creating a gap if it wishes. Doing this though can significantly increase implementation complexity and could cause delays at the splice point. The key property that must be preserved is the entirety of the new segment gets added to the <source-buffer/> and it is up to the implementation how much of the old segment data is retained. The web application can use <buffered/> to determine how much of the old segment was preserved.</p>
<h4 id="source-buffer-overlap-middle">2.7.4 Middle Overlap</h4>
<img src="middle_overlap.png"/>
<p>The figure above shows how the <source-buffer/> gets updated when the new <media-segment/> is in the middle of the old segment. This condition is handled by first resolving the <a href="#source-buffer-overlap-start">start overlap</a> and then resolving the <a href="#source-buffer-overlap-end">end overlap</a>.</p>
<h3 id="source-buffer-to-track-buffer">2.8. Source Buffer to Track Buffer transfer</h3>
- <p>The <source-buffer/> represents the media that the web application would like the media element to play. The <track-buffer/> contains the data that will actually get decoded and rendered. In most cases the <track-buffer/> will simply contain a subset of the <source-buffer/> near the current playback position. These two buffers start to diverge though when <media-segments/> that overlay or are very close to the current playback position are appended. Depending on the contents of the new <media-segment/> it may not be possible to switch to the new data immediately because there isn't a <random-access-point/> close enough to the current playback position. The quality of the implementation determines how much data is considered "in the <track-buffer/>". It should transfer data to the <track-buffer/> as late as possible whilst maintaining seamless playback. Some implementations may be able to instantiate multiple decoders or decode the new data significantly faster than real-time to achieve a seamless splice immediately. Other implementations may delay until the next <random-access-point/> before switching to the newly appended data. Notice that this difference in behavior is only observable when appending close to the current playback position. The <track-buffer/> represents a media subsegment, like a group of pictures or something with similar decode dependencies, that the media element commits to playing. This commitment may be influenced by a variety of things like limited decoding resources, hardware decode buffers, a jitter buffer, or the desire to limit implementation complexity.</p>
+ <p>The <source-buffer/> represents the media that the web application would like the media element to play. The <track-buffer/> contains the data that will actually get decoded and rendered. In most cases the <track-buffer/> will simply contain a subset of the <source-buffer/> near the current playback position. These two buffers start to diverge though when <media-segments/> that overlap or are very close to the current playback position are appended. Depending on the contents of the new <media-segment/> it may not be possible to switch to the new data immediately because there isn't a <random-access-point/> close enough to the current playback position. The quality of the implementation determines how much data is considered "in the <track-buffer/>". It should transfer data to the <track-buffer/> as late as possible whilst maintaining seamless playback. Some implementations may be able to instantiate multiple decoders or decode the new data significantly faster than real-time to achieve a seamless splice immediately. Other implementations may delay until the next <random-access-point/> before switching to the newly appended data. Notice that this difference in behavior is only observable when appending close to the current playback position. The <track-buffer/> represents a media subsegment, like a group of pictures or something with similar decode dependencies, that the media element commits to playing. This commitment may be influenced by a variety of things like limited decoding resources, hardware decode buffers, a jitter buffer, or the desire to limit implementation complexity.</p>
<p>Here is an example to help clarify the role of the <track-buffer/>. Say the current playback position has a timestamp of 8 and the media element pulled frames with timestamp 9 & 10 into the track buffer. The web application then appends a higher quality <media-segment/> that starts with a <random-access-point/> at timestamp 9. The <source-buffer/> will get updated with the higher quality data, but the media element won't be able to switch to this higher quality data until the next <random-access-point/> at timestamp 20. This is because a frame for timestamp 9 is already in the track buffer. As you can see the track buffer represents the "point of no return." for decoding. If a seek occurs the media element may choose to use the higher quality data since a seek might imply flushing the <track-buffer/> and the user expects a break in playback.</p>
<h3 id="source-buffer-segment-eviction">2.9. Media Segment Eviction</h3>
- <p>When a new <media-segment/> is appended, memory constraints may cause previously appended segments to get evicted from the <source-buffer/>. The eviction algorithm is implementation dependent, but segments that aren't likely to be needed soon are the most likely to get evicted. The <sourceBuffered/> method allows the web application to monitor what time ranges are currently buffered in the <source-buffer/>.</p>
+ <p>When a new <media-segment/> is appended, memory constraints may cause previously appended segments to get evicted from the <source-buffer/>. The eviction algorithm is implementation dependent, but segments that aren't likely to be needed soon are the most likely to get evicted. The <buffered/> method allows the web application to monitor what time ranges are currently buffered in the <source-buffer/>.</p>
- <h3 id="source-buffer-remove-id">2.10. Removing a Source ID</h3>
- <p>Removing a <source-id/> with <sourceRemoveId/> releases all resources associated with the ID. This includes destroying the <source-buffer/>, <track-buffers/>, and decoders. The media element will also remove the appropriate tracks from <audiotracks/> & <videotracks/> and fire the necessary <videoref name="handler-tracklist-onchange">change</videoref> events. Playback may become degraded or stop if the currently selected <video-track/> or the only enabled <audio-tracks/> are removed.</p>
+ <h3 id="source-buffer-remove">2.10. Removing Source Buffers</h3>
+ <p>Removing a <SourceBuffer/> with <remove/> releases all resources associated with the object. This includes destroying the all the segment data, <track-buffers/>, and decoders. The media element will also remove the appropriate tracks from <audiotracks/>, <videotracks/>, & <texttracks/> and fire the necessary <videoref name="handler-tracklist-onchange">change</videoref> events. Playback may become degraded or stop if the currently selected <video-track/> or the only enabled <audio-tracks/> are removed.</p>
- <h2 id="mediasource">3. Media Element Extensions</h2>
- <p>We extend HTML media elements to allow media data to be streamed into them from JavaScript.</p>
+ <h2 id="mediasource">3. MediaSource Object</h2>
+ <p>The MediaSource object represents a source of media data for an HTMLMediaElement. It keeps track of the <readyState/> for this source as well as a list of <SourceBuffer/> objects that can be used to add media data to the presentation. MediaSource objects are created by the web application and then attached to an HTMLMediaElement. The application uses the <SourceBuffer/> objects in <sourceBuffers/> to add media data to this source. The HTMLMediaElement fetches this media data from the <MediaSource/> object when it is needed during playback.</p>
+
<pre class="idl">
-partial interface HTMLMediaElement {
- // URL passed to src attribute to enable the media source logic.
- readonly attribute DOMString <precoderef>mediaSourceURL</precoderef>;
+[Constructor]
+interface <dfn id="dom-mediasource">MediaSource</dfn> : EventTarget {
+ // All the source buffers created by this object.
+ readonly attribute <precoderef>SourceBufferList</precoderef> <precoderef>sourceBuffers</precoderef>;
- // Manages IDs for appending media to the source.
- void <premethodref>sourceAddId</premethodref>(DOMString id, DOMString type);
- void <premethodref>sourceRemoveId</premethodref>(DOMString id);
+ // Subset of sourceBuffers that provide data for the selected/enabled tracks.
+ readonly attribute <precoderef>SourceBufferList</precoderef> <precoderef>activeSourceBuffers</precoderef>;
- // Returns the time ranges buffered for a specific ID.
- TimeRanges <premethodref>sourceBuffered</premethodref>(DOMString id);
+ // Adds another source buffer.
+ <precoderef>SourceBuffer</precoderef> <premethodref>addSourceBuffer</premethodref>(DOMString type);
+
+ enum State { "closed", "open", "ended" };
+ readonly attribute State <precoderef>readyState</precoderef>;
+
+ enum EndOfStreamError { "network", "decode" };
+ void <premethodref>endOfStream</premethodref>(optional EndOfStreamError error);
+};
+ </pre>
+ <h3 id="mediasource-methods">3.1. Methods and Attributes</h3>
+
+ <p>The <codedfn>sourceBuffers</codedfn> attribute contains the list of <SourceBuffer/> objects associated with this <MediaSource/>. When <readyState/> equals <closed/> this list will be empty. Once <readyState/> transitions to <open/> SourceBuffer objects can be added to this list by using <addSourceBuffer/>.</p>
+
+ <p>The <codedfn>activeSourceBuffers</codedfn> attribute contains the subset of <sourceBuffers/> that represents the <active-source-buffers/>.</p>
+
+ <p>The <methoddfn name="addSourceBuffer">addSourceBuffer(<var title="true">type</var>)</methoddfn> method must run the following steps:</p>
+ <ol>
+ <li>If <var title="true">type</var> is null or an empty then throw an <invalid-access-err/> exception and abort these steps.</li>
+ <li>If <var title="true">type</var> contains a MIME type that is not supported or contains a MIME type that is not supported with the types specified for the other <SourceBuffer/> objects in <sourceBuffers/>, then throw a <not-supported-err/> exception and abort these steps.</li>
+ <li>If the user agent can't handle any more SourceBuffer objects then throw a <quota-exceeded-err/> exception and abort these steps.</li>
+ <li>If the <readyState/> attribute is not in the <open/> state then throw an <invalid-state-err/> exception and abort these steps.</li>
+ <li>Create a new <SourceBuffer/> object and associated resources.</li>
+ <li>Add the new object to <sourceBuffers/> and fire a <coderef>addsourcebuffer</coderef> on that object.</li>
+ <li>Return the new object to the caller.</li>
+ </ol>
+
+ <p>The <codedfn>readyState</codedfn> attribute indicates the current state of the <MediaSource/> object. It can have the following values:</p>
+ <dl>
+ <dt><codedfn>"closed"</codedfn></dt>
+ <dd>Indicates the source is not currently attached to a media element.</dd>
+
+ <dt><codedfn>"open"</codedfn></dt>
+ <dd>The source has been opened by a media element and is ready for data to be appended to the <SourceBuffer/> objects in <sourceBuffers/>.</dd>
+
+ <dt><codedfn>"ended"</codedfn></dt>
+ <dd>The source is still attached to a media element, but <methodref>endOfStream</methodref> has been called. Appending data to <SourceBuffer/> objects in this state is not allowed.</dd>
+ </dl>
+ <p>When the <MediaSource/> is created <readyState/> must be set to <closed/>.
+ </p>
+
+
+ <h5>End of stream error values:</h5>
+ <dl>
+ <dt><codedfn>"network"</codedfn></dt>
+ <dd>The stream ended prematurely because of a network error. If the JavaScript code fetching media data encounters a network error it should use this status code to terminate playback. This will cause the media element's error handling code to run and the <code>error</code> attribute to be set to <videoref name="dom-mediaerror-media_err_network">MediaError.MEDIA_ERR_NETWORK</videoref></dd>
+
+ <dt><codedfn>"decode"</codedfn></dt>
+ <dd>The stream ended prematurely because there was an error while decoding the media data. If the JavaScript code fetching media data has problems parsing the data it should use this status code to terminate playback. This will cause the media element's error handling code to run and the <code>error</code> attribute to be set to <videoref name="dom-mediaerror-media_err_decode">MediaError.MEDIA_ERR_DECODE</videoref></dd>
+ </dl>
+
+ <p>The <methoddfn name="endOfStream">endOfStream(<var title="true">error</var>)</methoddfn> method must run the following steps:</p>
+ <ol>
+ <li>If the <readyState/> attribute is not in the <open/> state then throw an <invalid-state-err/> exception and abort these steps.</li>
+ <li>Change the <readyState/> attribute value to <ended/>.</li>
+ <dl class="switch">
+ <dt>If <var title="true">error</var> is not set, null, or an empty string</dt>
+ <dd>Notify the media element that it now has all of the media data. Playback should continue until all the media passed in via <append/> has been played.</dd>
+ <dt>If <var title="true">error</var> is set to <coderef>"network"</coderef></dt>
+ <dd>Run the "If the connection is interrupted, causing the user agent to give up trying to fetch the resource" section of the <resource-fetch-algorithm/></dd>
+ <dt>If <var title="true">error</var> is set to <coderef>"decode"</coderef></dt>
+ <dd>Run the "If the media data is corrupted" section of the <resource-fetch-algorithm/></dd>
+ <dt>Otherwise</dt>
+ <dd>Throw an <invalid-access-err/> exception.</dd>
+ </dl>
+ </ol>
+
+
+ <h3 id="mediasource-events">3.2. Event Summary</h3>
+ <table>
+ <thead>
+ <tr>
+ <th>Event name</th>
+ <th>Interface</th>
+ <th>Dispatched when...</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td><codedfn>sourceopen</codedfn></td>
+ <td><code>Event</code></td>
+ <td>When <readyState/> transitions from <closed/> to <open/> or from <ended/> to <open/>.</td>
+ </tr>
+ <tr>
+ <td><codedfn>sourceended</codedfn></td>
+ <td><code>Event</code></td>
+ <td>When <readyState/> transitions from <open/> to <ended/>.</td>
+ </tr>
+ <tr>
+ <td><codedfn>sourceclose</codedfn></td>
+ <td><code>Event</code></td>
+ <td>When <readyState/> transitions from <open/> to <closed/> or <ended/> to <closed/>.</td>
+ </tr>
+ </tbody>
+ </table>
+
+ <h3 id="mediasource-algorithms">3.3. Algorithms</h3>
+ <h4 id="mediasource-attach">3.3.1 Attaching to a media element</h4>
+ <p> A <MediaSource/> object can be attached to a media element by assigning a MediaSource object URL to the media element <media-src/> attribute or the src attribute of a <source> inside a media element. MediaSource object URLs are created by passing a MediaSource object to window.URL.createObjectURL().</p>
+ <p>The following steps are run when a media element attempts the <resource-fetch-algorithm/> with a MediaSource object URL.</p>
+ <ol>
+ <dl class="switch">
+ <dt>If <readyState/> is NOT set to <closed/></dt>
+ <dd>Abort media element's <resource-fetch-algorithm/> and run the steps to report a <MEDIA_ERR_SRC_NOT_SUPPORTED/> error.</dd>
+ <dt>Otherwise</dt>
+ <dd>
+ <ol>
+ <li>Set <readyState/> attribute to <open/></li>
+ <li>Fire a simple event named <coderef>sourceopen</coderef>.</li>
+ <li>Allow <resource-fetch-algorithm/> to progress based on data passed in via <append/></li>
+ </ol>
+ </dd>
+ </dl>
+ </ol>
+
+ <h4 id="mediasource-detach">3.3.2 Detaching from a media element</h4>
+ <p>The following steps are run in any case where the media element is going to transition to <videoref name="dom-media-network_empty">NETWORK_EMPTY</videoref> and fire an <videoref name="event-mediacontroller-emptied">emptied</videoref> event. These steps should be run right before the transition.</p>
+ <ol>
+ <li>Set <readyState/> attribute to <closed/></li>
+ <li>Remove all the <SourceBuffer/> objects from <sourceBuffers/> and fire a <coderef>removesourcebuffer</coderef> event for each one.</li>
+ <li>Fire a simple event named <coderef>sourceclose</coderef>.</li>
+ </ol>
+
+ <h4 id="mediasource-seeking">3.3.3 Seeking</h4>
+ <ol>
+ <li>The media element <videoref name="dom-media-seeking">seeking algorithm</videoref> starts and has reached the stage where it is about to fire the <videoref name="event-media-seeking">seeking</videoref> event.</li>
+ <li>
+ <dl class="switch">
+ <dt>If the <readyState/> attribute is set to <ended/></dt>
+ <dd>
+ <ol>
+ <li>Set the <readyState/> attribute to <open/></li>
+ <li>Fire a simple event named <coderef>sourceopen</coderef> on the <MediaSource/> object.</li>
+ </ol>
+ </dd>
+ <dt>Otherwise</dt>
+ <dd>Continue</dd>
+ </dl>
+ </li>
+ <li>The media element <videoref name="dom-media-seeking">seeking algorithm</videoref> fires the <videoref name="event-media-seeking">seeking</videoref> event</li>
+ <li>The media element looks for <media-segments/> containing the desired seek point in each <SourceBuffer/> object in <activeSourceBuffers/></li>
+ <dl class="switch">
+ <dt>If one or more of the objects in <activeSourceBuffers/> is missing <media-segments/> for the desired seek point</dt>
+ <dd>
+ <ol>
+ <li>Set <ready-state/> attribute to <have-metadata/> and fire the <appropriate-event/> for this transition.</li>
+ <li>The media element waits for the necessary <media-segments/> to be passed to <append/>. The web application can use <buffered/> to determine what the media element needs to resume playback.</li>
+ </ol>
+ </dd>
+ <dt>Otherwise</dt>
+ <dd>Continue</dd>
+ </dl>
+ <li>The media element resets all decoders and initializes each one with data from the appropriate <init-segment/>.</li>
+ <li>The media element feeds data from the <media-segments/> into the decoders until the desired seek point is reached.</li>
+ <li>The media element resumes the <videoref name="dom-media-seeking">seeking algorithm</videoref> and fires the <videoref name="event-media-seeked">seeked</videoref> event indicating that the seek has completed.</li>
+ </ol>
+
+
+ <h4 id="buffer-monitoring">3.3.4 SourceBuffer Monitoring</h4>
+ <p>The following steps are periodically run during playback to make sure that all of the <SourceBuffer/> objects in <activeSourceBuffers/> have enough data to ensure uninterrupted playback. Appending new segments and changes to <activeSourceBuffers/> also cause these steps to run because they affect the conditions that trigger state transitions. The web application can monitor changes in <ready-state/> to drive <media-segment/> appending.</p>
+ <dl class="switch">
+ <dt>If <buffered/> for all objects in <activeSourceBuffers/> do not contain <timeranges/> for the current playback position:</dt>
+ <dd>
+ <ol>
+ <li>Set <ready-state/> attribute to <have-metadata/> and fire the <appropriate-event/> for this transition.</li>
+ <li>Abort remaining steps</li>
+ </ol>
+ </dd>
+ <dt>If <buffered/> for all objects in <activeSourceBuffers/> contain <timeranges/> that include the current playback position and enough data to ensure uninterrupted playback:</dt>
+ <dd>
+ <ol>
+ <li>Set <ready-state/> attribute to <have-enough-data/> and fire the <appropriate-event/> for this transition.</li>
+ <li>Playback may resume at this point if it was previously suspended by a transition to <have-current-data/>.</li>
+ <li>Abort remaining steps</li>
+ </ol>
+ </dd>
+ <dt>If <buffered/> for at least one object in <activeSourceBuffers/> contains a <timerange/> that includes the current playback position but not enough data to ensure uninterrupted playback:</dt>
+ <dd>
+ <ol>
+ <li>Set <ready-state/> attribute to <have-future-data/> and fire the <appropriate-event/> for this transition.</li>
+ <li>Playback may resume at this point if it was previously suspended by a transition to <have-current-data/>.</li>
+ <li>Abort remaining steps</li>
+ </ol>
+ </dd>
+ <dt>If <buffered/> for at least one object in <activeSourceBuffers/> contains a <timerange/> that ends at the current playback position and does not have a range covering the time immediately after the current position:</dt>
+ <dd>
+ <ol>
+ <li>Set <ready-state/> attribute to <have-current-data/> and fire the <appropriate-event/> for this transition.</li>
+ <li>Playback is suspended at this point since the media element doesn't have enough data to advance the timeline.</li>
+ <li>Abort remaining steps.</li>
+ </ol>
+ </dd>
+ </dl>
+
+ <h4 id="active-source-buffer-changes">3.3.5 Changes to selected/enabled track state.</h4>
+ <p>During playback <activeSourceBuffers/> needs to be updated if the <videoref name="dom-videotrack-selected">selected video track</videoref>, the <videoref name="dom-audiotrack-enabled">enabled audio tracks</videoref>, or a text track <videoref name="dom-texttrack-mode">mode</videoref> changes. When one or more of these changes occur the following steps need to be followed.</p>
+ <dl class="switch">
+ <dt>If the selected video track changes</dt>
+ <dd>
+ <ol>
+ <li>If the <SourceBuffer/> associated with the previously selected video track is not associated with any other enabled tracks then remove it from <activeSourceBuffers/></li>
+ <li>If the <SourceBuffer/> associated with the newly selected video track is not already in <activeSourceBuffers/> then add it.</li>
+ </ol>
+ </dd>
+ <dt>If an audio track becomes disabled and the <SourceBuffer/> associated with this track is not associated with any other enabled or selected track</dt>
+ <dd>Remove the <SourceBuffer/> associated with the audio track from <activeSourceBuffers/></dd>
+ <dt>If an audio track becomes enabled and the <SourceBuffer/> associated with this track is not already in <activeSourceBuffers/></dt>
+ <dd>Add the <SourceBuffer/> associated with the audio track to <activeSourceBuffers/></dd>
+ <dt>If a text track <videoref name="dom-texttrack-mode">mode</videoref> becomes <videoref name="dom-texttrack-disabled">"disabled"</videoref> and the <SourceBuffer/> associated with this track is not associated with any other enabled or selected track</dt>
+ <dd>Remove the <SourceBuffer/> associated with the text track from <activeSourceBuffers/></dd>
+ <dt>If a text track <videoref name="dom-texttrack-mode">mode</videoref> becomes <videoref name="dom-texttrack-showing">"showing"</videoref> or <videoref name="dom-texttrack-hidden">"hidden"</videoref> and the <SourceBuffer/> associated with this track is not already in <activeSourceBuffers/></dt>
+ <dd>Add the <SourceBuffer/> associated with the text track to <activeSourceBuffers/></dd>
+ </dl>
+
+
+ <h2 id="sourcebuffer">4. SourceBuffer Object</h2>
+ <pre class="idl">
+interface <dfn id="dom-sourcebuffer">SourceBuffer</dfn> : EventTarget {
+ // Returns the time ranges buffered.
+ readonly attribute TimeRanges <precoderef>buffered</precoderef>;
// Append segment data.
- void <premethodref>sourceAppend</premethodref>(DOMString id, Uint8Array data);
-
- // Abort the current segment.
- void <premethodref>sourceAbort</premethodref>(DOMString id);
-
- // end of stream status codes.
- const unsigned short <precoderef>EOS_NO_ERROR</precoderef> = 0;
- const unsigned short <precoderef>EOS_NETWORK_ERR</precoderef> = 1;
- const unsigned short <precoderef>EOS_DECODE_ERR</precoderef> = 2;
-
- void <premethodref>sourceEndOfStream</premethodref>(unsigned short status);
-
- // states
- const unsigned short <precoderef>SOURCE_CLOSED</precoderef> = 0;
- const unsigned short <precoderef>SOURCE_OPEN</precoderef> = 1;
- const unsigned short <precoderef>SOURCE_ENDED</precoderef> = 2;
-
- readonly attribute unsigned short <precoderef>sourceState</precoderef>;
-
- [TreatNonCallableAsNull] attribute Function? <precoderef>onsourceopen</precoderef>;
- [TreatNonCallableAsNull] attribute Function? <precoderef>onsourceended</precoderef>;
- [TreatNonCallableAsNull] attribute Function? <precoderef>onsourceclose</precoderef>;
-};
-
- </pre>
+ void <premethodref>append</premethodref>(Uint8Array data);
- <p>The <codedfn>mediaSourceURL</codedfn> attribute returns the URL used to enable the Media Source extension methods. To enable the Media Source extensions on a media element, assign this URL to the <media-src/> attribute. The format of the URL is browser specific and may be unique for each HTMLMediaElement. The <coderef>mediaSourceURL</coderef> on one HTMLMediaElement should not be assigned to the <media-src/> attribute on a different HTMLMediaElement.
- </p>
- <div class="example">
- <p>Example mediaSourceURL: </p>
- <p style="margin-left:2em">x-media-source:e183f43d-c8a3-4905-bf89-e8e920041c7c</p>
- <p>Note the browser specific scheme and use of a UUID for the path to make it unique.</p>
- </div>
- <div class="issue">Using <coderef>mediaSourceURL</coderef> is one approach to switching the media element into "media source" mode. Alternative approaches should be explored to improve consistency with other APIs and provide a declarative mechanism for enabling "media source" mode.</div>
-
- <p>The <methoddfn name="sourceAddId">sourceAddId(<var title="true">id</var>, <var title="true">type</var>)</methoddfn> method must run the following steps:</p>
- <ol>
- <li>If <var title="true">id</var> is null or an empty string then throw an <invalid-access-err/> exception and abort these steps.</li>
- <li>If <var title="true">id</var> specifies an ID that has been previously added then throw a <invalid-state-err/> exception and abort these steps.</li>
- <li>If <var title="true">type</var> is null or an empty then throw an <invalid-access-err/> exception and abort these steps.</li>
- <li>If <var title="true">type</var> contains a MIME type that is not supported or contains a MIME type that is not supported with the types specified for other sourceIDs, then throw a <not-supported-err/> exception and abort these steps.</li>
- <li>If the user agent can't handle any more IDs then throw a <quota-exceeded-err/> exception and abort these steps.</li>
- <li>If the <sourceState/> attribute is not in the <coderef>SOURCE_OPEN</coderef> state then throw an <invalid-state-err/> exception and abort these steps.</li>
- <li>Allocate source buffer resources for <var title="true">id</var>.</li>
- </ol>
-
- <p>The <methoddfn name="sourceRemoveId">sourceRemoveId(<var title="true">id</var>)</methoddfn> method must run the following steps:</p>
+ // Abort the current segment append sequence.
+ void <premethodref>abort</premethodref>();
+};
+ </pre>
+ <p>The <codedfn>buffered</codedfn> attribute indicates what <timeranges/> are buffered in the <SourceBuffer/>. When attribute is read the following steps must occur:</p>
<ol>
- <li>If <var title="true">id</var> is null or an empty string then throw an <invalid-access-err/> exception and abort these steps.</li>
- <li>If the <sourceState/> attribute is in the <coderef>SOURCE_CLOSED</coderef> state then throw an <invalid-state-err/> exception and abort these steps.</li>
- <li>If <var title="true">id</var> specifies an ID that has not been previously added then abort these steps.</li>
- <li>Remove track information from <audiotracks/> and <videotracks/> for all tracks associated with <var title="true">id</var> and fire a simple event named <videoref name="handler-tracklist-onchange">change</videoref> on the modified lists.</li>
- <li>Destroy source buffer resources for <var title="true">id</var>.</li>
+ <li>If this object has been removed from the <sourceBuffers/> attribute of the <MediaSource/> object that created it then throw an <invalid-state-err/> exception and abort these steps.</li>
+ <li>Return <timeranges/> for the <media-segments/> buffered.</li>
</ol>
- <p>The <methoddfn name="sourceBuffered">sourceBuffered(<var title="true">id</var>)</methoddfn> method must run the following steps:</p>
- <ol>
- <li>If <var title="true">id</var> is null or an empty string then throw an <invalid-access-err/> exception and abort these steps.</li>
- <li>If <var title="true">id</var> specifies an ID that has not been previously added with <sourceAddId/> then throw a <syntax-err/> exception and abort these steps.</li>
- <li>If the <sourceState/> attribute is in the <coderef>SOURCE_CLOSED</coderef> state then throw an <invalid-state-err/> exception and abort these steps.</li>
- <li>Return <timeranges/> for the source buffer associated with <var title="true">id</var>.</li>
- </ol>
-
- <p>The <methoddfn name="sourceAppend">sourceAppend(<var title="true">id</var>, <var title="true">data</var>)</methoddfn> method must run the following steps:</p>
+ <p>The <methoddfn name="append">append(<var title="true">data</var>)</methoddfn> method must run the following steps:</p>
<ol>
- <li>If <var title="true">id</var> is null or an empty string then throw an <invalid-access-err/> exception and abort these steps.</li>
- <li>If <var title="true">id</var> specifies an ID that has not been previously added with <sourceAddId/> then throw a <syntax-err/> exception and abort these steps.</li>
<li>If <var title="true">data</var> is null then throw an <invalid-access-err/> exception and abort these steps.</li>
- <li>If the <sourceState/> attribute is not in the <coderef>SOURCE_OPEN</coderef> state then throw an <invalid-state-err/> exception and abort these steps.</li>
+ <li>If this object has been removed from the <sourceBuffers/> attribute of the <MediaSource/> object that created it then throw an <invalid-state-err/> exception and abort these steps.</li>
+ <li>If the <readyState/> attribute of the <MediaSource/> object that created this object is not in the <open/> state then throw an <invalid-state-err/> exception and abort these steps.</li>
<li>If <var title="true">data</var>.byteLength is 0 abort these steps.</li>
- <li>Copy contents of <var title="true">data</var> into the source buffer associated with <var title="true">id</var>.</li>
+ <li>Copy contents of <var title="true">data</var> into the source buffer.</li>
<li>Handle end of segment cases:</li>
<dl class="switch">
<dt>If <var title="true">data</var> completes the first <init-segment/> appended to the <source-buffer/> run the following steps:</dt>
@@ -388,33 +560,51 @@
<li>Update <audiotracks/></li>
<dl class="switch">
<dt>If <init-segment/> contains the first audio track:</dt>
- <dd>Add an <audio-track/> and mark it as enabled.</dd>
+ <dd>
+ <ol>
+ <li>Add an <audio-track/> and mark it as enabled.</li>
+ <li>Add this <SourceBuffer/> to <activeSourceBuffers/>.</li>
+ </ol>
+ </dd>
<dt>If <init-segment/> contains audio tracks beyond those already in the presentation:</dt>
<dd>Add a disabled <audio-track/> for each audio track in the <init-segment/>.</dd>
</dl>
<li>Update <videotracks/>:</li>
<dl class="switch">
<dt>If <init-segment/> contains the first video track:</dt>
- <dd>Add a <video-track/> and mark it as selected.</dd>
+ <dd>
+ <ol>
+ <li>Add a <video-track/> and mark it as selected.</li>
+ <li>Add this <SourceBuffer/> to <activeSourceBuffers/>.</li>
+ </ol>
+ </dd>
<dt>If <init-segment/> contains the video tracks beyond those already in the presentation:</dt>
<dd>Add a disabled <video-track/> for each video track in the <init-segment/>.</dd>
</dl>
+ <li>Update <texttracks/></li>
+ <dl class="switch">
+ <dd>
+ <ol>
+ <li>Add a <text-track/> for each text track in the <init-segment/>.</li>
+ <li>If the text track <videoref name="dom-texttrack-mode">mode</videoref> is <videoref name="dom-texttrack-showing">"showing"</videoref> or <videoref name="dom-texttrack-hidden">"hidden"</videoref> then add this <SourceBuffer/> to <activeSourceBuffers/>.</li>
+ </ol>
+ </dd>
+ </dl>
</ol>
</dd>
- <dt>If the <ready-state/> attribute is <have-metadata/> and <var title="true">data</var> causes all <active-ids/> to have media data for the current playback position.</dt>
+ <dt>If the <ready-state/> attribute is <have-metadata/> and <var title="true">data</var> causes all objects in <activeSourceBuffers/> to have media data for the current playback position.</dt>
<dd>Set <ready-state/> attribute to <have-current-data/> and fire the <appropriate-event/> for this transition.</dd>
- <dt>If the <ready-state/> attribute is <have-current-data/> and <var title="true">data</var> causes all <active-ids/> to have media data beyond the current playback position.</dt>
+ <dt>If the <ready-state/> attribute is <have-current-data/> and <var title="true">data</var> causes all objects in <activeSourceBuffers/> to have media data beyond the current playback position.</dt>
<dd>Set <ready-state/> attribute to <have-future-data/> and fire the <appropriate-event/> for this transition.</dd>
- <dt>If the <ready-state/> attribute is <have-future-data/> and <var title="true">data</var> causes all <active-ids/> to have enough data to start playback.</dt>
+ <dt>If the <ready-state/> attribute is <have-future-data/> and <var title="true">data</var> causes all objects in <activeSourceBuffers/> to have enough data to start playback.</dt>
<dd>Set <ready-state/> attribute to <have-enough-data/> and fire the <appropriate-event/> for this transition.</dd>
</dl>
</ol>
- <p>The <methoddfn name="sourceAbort">sourceAbort(<var title="true">id</var>)</methoddfn> method must run the following steps:</p>
+ <p>The <methoddfn name="abort">abort()</methoddfn> method must run the following steps:</p>
<ol>
- <li>If <var title="true">id</var> is null or an empty string then throw an <invalid-access-err/> exception and abort these steps.</li>
- <li>If <var title="true">id</var> specifies an ID that has not been previously added with <sourceAddId/> then throw a <syntax-err/> exception and abort these steps.</li>
- <li>If the <sourceState/> attribute is not in the <coderef>SOURCE_OPEN</coderef> state then throw an <invalid-state-err/> exception and abort these steps.</li>
+ <li>If this object has been removed from the <sourceBuffers/> attribute of the <MediaSource/> object that created it then throw an <invalid-state-err/> exception and abort these steps.</li>
+ <li>If the <readyState/> attribute of the <MediaSource/> object that created this object is not in the <open/> state then throw an <invalid-state-err/> exception and abort these steps.</li>
<li>The media element aborts parsing the current segment.</li>
<dl class="switch">
<dt>If waiting for the start of a new segment</dt>
@@ -422,77 +612,39 @@
<dt>If the current segment is an <init-segment/></dt>
<dd>Flush any data associated with this partial segment.</dd>
<dt>If the current segment is a <media-segment/></dt>
- <dd>The media element may keep any media data it finds valuable in the partial segment. For example if the abort happens in the middle of a 10 second <media-segment/>, the media element may choose to keep the 5 seconds of media data it has already parsed in the source buffer. <sourceBuffered/> will reflect what data, if any, was kept.</dd>
+ <dd>The media element may keep any media data it finds valuable in the partial segment. For example if the abort happens in the middle of a 10 second <media-segment/>, the media element may choose to keep the 5 seconds of media data it has already parsed in the source buffer. <buffered/> will reflect what data, if any, was kept.</dd>
</dl>
- <li>The media element resets the segment parser so that it can accept a new <init-segment/>.</li>
- </ol>
-
- <h5>End of stream status values:</h5>
- <dl>
- <dt><codedfn>EOS_NO_ERROR</codedfn> (numeric value 0)</dt>
- <dd>The stream ended normally without any errors.</dd>
-
- <dt><codedfn>EOS_NETWORK_ERR</codedfn> (numeric value 1)</dt>
- <dd>The stream ended prematurely because of a network error. If the JavaScript code fetching media data encounters a network error it should use this status code to terminate playback. This will cause the media element's error handling code to run and the <code>error</code> attribute to be set to <videoref name="dom-mediaerror-media_err_network">MediaError.MEDIA_ERR_NETWORK</videoref></dd>
-
- <dt><codedfn>EOS_DECODE_ERR</codedfn> (numeric value 2)</dt>
- <dd>The stream ended prematurely because there was an error while decoding the media data. If the JavaScript code fetching media data has problems parsing the data it should use this status code to terminate playback. This will cause the media element's error handling code to run and the <code>error</code> attribute to be set to <videoref name="dom-mediaerror-media_err_decode">MediaError.MEDIA_ERR_DECODE</videoref></dd>
- </dl>
-
- <p>The <methoddfn name="sourceEndOfStream">sourceEndOfStream(<var title="true">status</var>)</methoddfn> method must run the following steps:</p>
- <ol>
- <li>If the <sourceState/> attribute is not in the <coderef>SOURCE_OPEN</coderef> state then throw an <invalid-state-err/> exception and abort these steps.</li>
- <li>Change the <sourceState/> attribute value to <coderef>SOURCE_ENDED</coderef>.</li>
- <dl class="switch">
- <dt>If <var title="true">status</var> is set to <coderef>EOS_NO_ERROR</coderef></dt>
- <dd>Notify the media element that it now has all of the media data. Playback should continue until all the media passed in via <sourceAppend/> has been played.</dd>
- <dt>If <var title="true">status</var> is set to <coderef>EOS_NETWORK_ERR</coderef></dt>
- <dd>Run the "If the connection is interrupted, causing the user agent to give up trying to fetch the resource" section of the <resource-fetch-algorithm/></dd>
- <dt>If <var title="true">status</var> is set to <coderef>EOS_DECODE_ERR</coderef></dt>
- <dd>Run the "If the media data is corrupted" section of the <resource-fetch-algorithm/></dd>
- <dt>Otherwise</dt>
- <dd>Throw an <invalid-access-err/> exception.</dd>
- </dl>
+ <li>The media element resets the segment parser so that it can accept a new <init-segment/> or <media-segment/>.</li>
</ol>
- <p>The <codedfn>sourceState</codedfn> attribute represents the state of the source. It can have the following values:</p>
- <dl>
- <dt><codedfn>SOURCE_CLOSED</codedfn> (numeric value 0)</dt>
- <dd>Indicates the source is not currently attached to a media element.</dd>
-
- <dt><codedfn>SOURCE_OPEN</codedfn> (numeric value 1)</dt>
- <dd>The source has been opened by a media element.</dd>
-
- <dt><codedfn>SOURCE_ENDED</codedfn> (numeric value 2)</dt>
- <dd><methodref>sourceEndOfStream</methodref> has been called on this source.</dd>
- </dl>
- <p>When the media element is created <sourceState/> must be set to <coderef>SOURCE_CLOSED</coderef> (0).
- </p>
+ <h2 id="sourcebufferlist">5. SourceBufferList Object</h2>
+ <p>SourceBufferList is a simple container object for <SourceBuffer/> objects. It provides a read-only array accessor, fires events when the list is modified, and provides a way to remove SourceBuffer objects from the list.</p>
- <h2 id="event-summary">4. Event Summary</h2>
- <table>
- <thead>
- <tr>
- <th><a href="http://dev.w3.org/html5/spec/webappapis.html#event-handlers" title="event handlers">Event handler</a></th>
- <th><a href="http://dev.w3.org/html5/spec/webappapis.html#event-handler-event-type">Event handler event type</a></th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td><codedfn>onsourceopen</codedfn></td>
- <td><coderef>sourceopen</coderef></td>
- </tr>
- <tr>
- <td><codedfn>onsourceended</codedfn></td>
- <td><coderef>sourceended</coderef></td>
- </tr>
- <tr>
- <td><codedfn>onsourceclose</codedfn></td>
- <td><coderef>sourceclose</coderef></td>
- </tr>
- </tbody>
- </table>
- <hr />
+ <pre class="idl">
+interface <dfn id="dom-sourcebufferlist">SourceBufferList</dfn> : EventTarget {
+ readonly attribute unsigned long <precoderef>length</precoderef>;
+ <precoderef>getter</precoderef> <precoderef>SourceBuffer</precoderef> (unsigned long index);
+ void <premethodref>remove</premethodref>(<precoderef>SourceBuffer</precoderef> buffer);
+};
+ </pre>
+ <h3 id="sourcebufferlist-methods">5.1. Methods and Attributes</h3>
+ <p>The <codedfn>length</codedfn> attribute indicates the number of <SourceBuffer/> objects in the list.</p>
+ <p>The <dfn id="dom-getter"><code>getter SourceBuffer (unsigned long <var title="true">index</var>)</code></dfn> method allows the SourceBuffer objects in the list to be accessed with an array operator (i.e. []). This method must run the following steps:</p>
+ <ol>
+ <li>If <var title="true">index</var> is greater than or equal to the <length/> attribute then return undefined and abort these steps.</li>
+ <li>Return the <var title="true">index</var>'th <SourceBuffer/> object in the list.</li>
+ </ol>
+ <p>The <methoddfn name="remove">remove(<var title="true">buffer</var>)</methoddfn> method must run the following steps:</p>
+ <ol>
+ <li>If <var title="true">buffer</var> is null then throw an <invalid-access-err/> exception and abort these steps.</li>
+ <li>If the list is empty then throw an <invalid-state-err/> exception and abort these steps.</li>
+ <li>If <var title="true">buffer</var> specifies an object that is not in this list then throw a <not-found-err/> exception and abort these steps.</li>
+ <li>Remove track information from <audiotracks/>, <videotracks/>, and <texttracks/> for all tracks associated with <var title="true">buffer</var> and fire a simple event named <videoref name="handler-tracklist-onchange">change</videoref> on the modified lists.</li>
+ <li>Destroy all resources for <var title="true">buffer</var>.</li>
+ <li>Remove <var title="true">buffer</var> from the list and fire an <removesourcebuffer/> event.</li>
+ </ol>
+
+ <h3 id="sourcebufferlist-events">5.2. Event Summary</h3>
<table>
<thead>
<tr>
@@ -503,111 +655,20 @@
</thead>
<tbody>
<tr>
- <td><codedfn>sourceopen</codedfn></td>
+ <td><codedfn>addsourcebuffer</codedfn></td>
<td><code>Event</code></td>
- <td>When the source transitions from <coderef>SOURCE_CLOSED</coderef> to <coderef>SOURCE_OPEN</coderef> or from <coderef>SOURCE_ENDED</coderef> to <coderef>SOURCE_OPEN</coderef>.</td>
+ <td>When a <SourceBuffer/> is added to the list.</td>
</tr>
<tr>
- <td><codedfn>sourceended</codedfn></td>
+ <td><codedfn>removesourcebuffer</codedfn></td>
<td><code>Event</code></td>
- <td>When the source transitions from <coderef>SOURCE_OPEN</coderef> to <coderef>SOURCE_ENDED</coderef>.</td>
- </tr>
- <tr>
- <td><codedfn>sourceclose</codedfn></td>
- <td><code>Event</code></td>
- <td>When the source transitions from <coderef>SOURCE_OPEN</coderef> or <coderef>SOURCE_ENDED</coderef> to <coderef>SOURCE_CLOSED</coderef>.</td>
+ <td>When a <SourceBuffer/> is removed from the list.</td>
</tr>
</tbody>
</table>
- <h2 id="algorithms">5. Algorithms</h2>
- <h3 id="algorithms-attach">5.1 Attaching to a media element</h3>
- <ol>
- <li>Set the <media-src/> attribute on a media element or the <media-src/> attribute on a <source> element associated with a media element to <coderef>mediaSourceURL</coderef></li>
- <li><p>When the media element attempts the <resource-fetch-algorithm/> with the URL from <coderef>mediaSourceURL</coderef> it will take one of the following actions:</p>
- <dl class="switch">
- <dt>If <sourceState/> is NOT set to <coderef>SOURCE_CLOSED</coderef></dt>
- <dd>Abort media element's <resource-fetch-algorithm/> and run the steps to report a <code>MEDIA_ERR_SRC_NOT_SUPPORTED</code> error.</dd>
- <dt>Otherwise</dt>
- <dd>
- <ol>
- <li>Set <sourceState/> attribute to <coderef>SOURCE_OPEN</coderef></li>
- <li>Fire a simple event named <coderef>sourceopen</coderef>.</li>
- <li>Allow <resource-fetch-algorithm/> to progress based on data passed in via <sourceAppend/></li>
- </ol>
- </dd>
- </dl>
- </li>
- </ol>
-
- <h3 id="algorithms-detach">5.2 Detaching from a media element</h3>
- <p>The following steps are run in any case where the media element is going to transition to <videoref name="dom-media-network_empty">NETWORK_EMPTY</videoref> and fire an <videoref name="event-mediacontroller-emptied">emptied</videoref> event. These steps should be run right before the transition.</p>
- <ol>
- <li>Set <sourceState/> attribute to <coderef>SOURCE_CLOSED</coderef></li>
- <li>Fire a simple event named <coderef>sourceclose</coderef>.</li>
- </ol>
-
-
- <h3 id="seeking">5.3 Seeking</h3>
- <ol>
- <li>The media element <videoref name="dom-media-seeking">seeking algorithm</videoref> starts and has reached the stage where it is about to fire the <videoref name="event-media-seeking">seeking</videoref> event.</li>
- <li>If the <sourceState/> attribute is set to <coderef>SOURCE_ENDED</coderef>, then the media element sets the <sourceState/> attribute to <coderef>SOURCE_OPEN</coderef> and fires a simple event named <coderef>sourceopen</coderef></li>
- <li>The media element <videoref name="dom-media-seeking">seeking algorithm</videoref> fires the <videoref name="event-media-seeking">seeking</videoref> event</li>
- <li>The media element looks for <media-segments/> containing the desired seek point in the <source-buffers/> for all the <active-ids/></li>
- <dl class="switch">
- <dt>If one or more of the <active-ids/> is missing <media-segments/> for the desired seek point</dt>
- <dd>
- <ol>
- <li>Set <ready-state/> attribute to <have-metadata/> and fire the <appropriate-event/> for this transition.</li>
- <li>The media element waits for the necessary <media-segments/> to be passed to <sourceAppend/>. The web application can use <sourceBuffered/> to determine what the media element needs to resume playback.</li>
- </ol>
- </dd>
- <dt>Otherwise</dt>
- <dd>Continue</dd>
- </dl>
- <li>The media element resets all decoders and initializes each one with data from the appropriate <init-segment/>.</li>
- <li>The media element feeds data from the <media-segments/> into the decoders until the desired seek point is reached.</li>
- <li>The media element resumes the <videoref name="dom-media-seeking">seeking algorithm</videoref> and fires the <videoref name="event-media-seeked">seeked</videoref> event indicating that the seek has completed.</li>
- </ol>
-
- <h3 id="buffer-monitoring">5.4 Source Buffer Monitoring</h3>
- <p>The following steps are periodically run during playback to make sure that all of the <source-buffers/> for the <active-ids/> have enough data to ensure uninterrupted playback. Appending new segments and changing the set of <active-ids/> also cause these steps to run because they affect the conditions that trigger state transitions. The web application can monitor changes in <ready-state/> to drive <media-segment/> appending.</p>
- <dl class="switch">
- <dt>If <sourceBuffered/> for all <active-ids/> does not contain <timeranges/> for the current playback position:</dt>
- <dd>
- <ol>
- <li>Set <ready-state/> attribute to <have-metadata/> and fire the <appropriate-event/> for this transition.</li>
- <li>Abort remaining steps</li>
- </ol>
- </dd>
- <dt>If <sourceBuffered/> for all <active-ids/> contain <timeranges/> that include the current playback position and enough data to ensure uninterrupted playback:</dt>
- <dd>
- <ol>
- <li>Set <ready-state/> attribute to <have-enough-data/> and fire the <appropriate-event/> for this transition.</li>
- <li>Playback may resume at this point if it was previously suspended by a transition to <have-current-data/>.</li>
- <li>Abort remaining steps</li>
- </ol>
- </dd>
- <dt>If <sourceBuffered/> for at least one <active-id/> contains a <timerange/> that includes the current playback position but not enough data to ensure uninterrupted playback:</dt>
- <dd>
- <ol>
- <li>Set <ready-state/> attribute to <have-future-data/> and fire the <appropriate-event/> for this transition.</li>
- <li>Playback may resume at this point if it was previously suspended by a transition to <have-current-data/>.</li>
- <li>Abort remaining steps</li>
- </ol>
- </dd>
- <dt>If <sourceBuffered/> for at least one <active-id/> contains a <timerange/> that ends at the current playback position and does not have a range covering the time immediately after the current position:</dt>
- <dd>
- <ol>
- <li>Set <ready-state/> attribute to <have-current-data/> and fire the <appropriate-event/> for this transition.</li>
- <li>Playback is suspended at this point since the media element doesn't have enough data to advance the timeline.</li>
- <li>Abort remaining steps.</li>
- </ol>
- </dd>
- </dl>
-
<h2 id="byte-stream-formats">6. Byte Stream Formats</h2>
- <p>The bytes provided through <sourceAppend/> for a <source-id/> form a logical byte stream. The format of this byte stream depends on the media container format in use and is defined in a byte stream format specification. Byte stream format specifications based on WebM and the ISO Base Media File Format are provided below. If these formats are supported then the byte stream formats described below MUST be supported.</p>
+ <p>The bytes provided through <append/> for a <SourceBuffer/> form a logical byte stream. The format of this byte stream depends on the media container format in use and is defined in a byte stream format specification. Byte stream format specifications based on WebM and the ISO Base Media File Format are provided below. If these formats are supported then the byte stream formats described below MUST be supported.</p>
<p>This section provides general requirements for all byte stream formats:</p>
<ul>
<li>A byte stream format specification MAY define <init-segments/> and MUST define <media-segments/>.</li>
@@ -703,99 +764,82 @@
<div class="blockContent">
<pre class="code">
<script>
- var sourceID = "123";
-
- function onOpen(e) {
- var video = e.target;
+ function onSourceOpen(videoTag, e) {
+ var mediaSource = e.target;
+ var sourceBuffer = mediaSource.addSourceBuffer('video/webm; codecs="vorbis,vp8"');
- var headers = GetStreamHeaders();
+ videoTag.addEventListener('seeking', onSeeking.bind(videoTag, mediaSource));
+ videoTag.addEventListener('progress', onProgress.bind(videoTag, mediaSource));
- if (headers == null) {
- // Error fetching headers. Signal end of stream with an error.
- video.sourceEndOfStream(HTMLMediaElement.EOS_NETWORK_ERR);
+ var initSegment = GetInitializationSegment();
+
+ if (initSegment == null) {
+ // Error fetching the initialization segment. Signal end of stream with an error.
+ mediaSource.endOfStream("network");
+ return;
}
- video.sourceAddId(sourceID, 'video/webm; codecs="vorbis,vp8"');
-
- // Append the stream headers (i.e. WebM Header, Info, and Tracks elements)
- video.sourceAppend(sourceID, headers);
+ // Append the initialization segment.
+ sourceBuffer.append(initSegment);
// Append some initial media data.
- video.sourceAppend(sourceID, GetNextCluster());
+ appendNextMediaSegment(mediaSource);
}
- function onSeeking(e) {
+ function appendNextMediaSegment(mediaSource) {
+ if (mediaSource.readyState == "ended")
+ return;
+
+ // If we have run out of stream data, then signal end of stream.
+ if (!HaveMoreMediaSegments()) {
+ mediaSource.endOfStream();
+ return;
+ }
+
+ var mediaSegment = GetNextMediaSegment();
+
+ if (!mediaSegment) {
+ // Error fetching the next media segment.
+ mediaSource.endOfStream("network");
+ return;
+ }
+
+ mediaSource.sourceBuffers[0].append(mediaSegment);
+ }
+
+ function onSeeking(mediaSource, e) {
var video = e.target;
// Abort current segment append.
- video.sourceAbort(sourceID);
+ mediaSource.sourceBuffers[0].abort();
- // Notify the cluster loading code to start fetching data at the
+ // Notify the media segment loading code to start fetching data at the
// new playback position.
- SeekToClusterAt(video.currentTime);
+ SeekToMediaSegmentAt(video.currentTime);
- // Append clusters from the new playback position.
- video.sourceAppend(sourceID, GetNextCluster());
- video.sourceAppend(sourceID, GetNextCluster());
+ // Append media segments from the new playback position.
+ appendNextMediaSegment(mediaSource);
+ appendNextMediaSegment(mediaSource);
}
- function onProgress(e) {
- var video = e.target;
-
- if (video.sourceState == video.SOURCE_ENDED)
- return;
-
- // If we have run out of stream data, then signal end of stream.
- if (!HaveMoreClusters()) {
- video.sourceEndOfStream(HTMLMediaElement.EOS_NO_ERROR);
- return;
- }
-
- video.sourceAppend(sourceID, GetNextCluster());
+ function onProgress(mediaSource, e) {
+ appendNextMediaSegment(mediaSource);
}
-
- var video = document.getElementById('v');
- video.addEventListener('sourceopen', onOpen);
- video.addEventListener('seeking', onSeeking);
- video.addEventListener('progress', onProgress);
</script>
<video id="v" autoplay> </video>
<script>
var video = document.getElementById('v');
- video.src = video.mediaSourceURL;
+ var mediaSource = new MediaSource();
+ mediaSource.addEventListener('sourceopen', onSourceOpen.bind(this, video));
+ video.src = window.URL.createObjectURL(mediaSource);
</script>
</pre>
</div>
</div>
- <h2 id="open-issues">8. Open Issues</h2>
- <p>This section contains issues that have come up during the spec update process, but haven't been resolved yet. The issues and potential solutions are listed below. The potential solutions are just initial thoughts and have not been subjected to rigorous discussion yet.</p>
-
- <h3>8.1. Buffer Management</h3>
- <p class="issue">Concerns were raised about limiting the amount of data that JavaScript can append on memory constrained devices. We have briefly discussed making sourceAppend() asynchronous and allowing an "append done" event to fire when the user agent is ready to accept more data.</p>
-
- <h3>8.2. Capability Detection</h3>
- <p class="issue">Since user agents may have different limitations on how they handle media segment overlaps, the web application needs a mechanism to detect the user agent's capabilities. We have briefly discussed adding a parameter, similar to 'codec', to the MIME type passed to sourceAddId(). We have not discussed any specific details beyond that.</p>
-
- <h3>8.3. Append URL</h3>
- <p class="issue">There have been discussions about changing sourceAppend() to take a URL and optional start & end offset parameters instead of a Uint8Array. The current byte stream specs don't really require access to the raw bytes and if JavaScript wants to construct its own stream from bytes it could use a BlobBuilder and a Blob URL. Going down this path removes the need for a streaming XHR API and could improve interactions with the browser cache. Download progress could be reported through an "append progress" event so that bitrate calculations could be made by JavaScript.</p>
-
- <h3>8.4. Timestamp Offset</h3>
- <p class="issue">There have been some discussions about adding a method that applies an offset to the timestamps in media segments. Ad insertion and mashups where the content being appended does not have timestamps that match the desired location in the presentation timeline are the primary motivators for this feature. A method along the lines of sourceTimestampMapping(presentationTimestamp, segmentTimestamp) could specify the timestamp mapping to use for future media segments that get appended. The mapping would be applied at append time before the data goes into the source buffer. Adding a feature like this would prevent the web application from having to rewrite timestamps in the media segments. The exact semantics and details of this feature still need to be worked out.</p>
-
- <h3>8.5. Timed Text</h3>
- <p class="issue">The current text focuses on behavior for audio and video. Behavior for timed text still needs to be defined.</p>
-
- <h3>8.6. WebAudio Integration</h3>
- <p class="issue">This proposal may overlap with portions of the <a href="http://www.w3.org/TR/2012/WD-webaudio-20120315/">Audio WG draft</a>. Further investigation is needed around how these two proposals will work together.</p>
-
- <h3>8.7. Track Identification and Management</h3>
- <p class="issue">Define how language and kind can be set on <audio-track/> & <video-track/> objects. This information may be inside the manifest instead of <init-segments/> so we need a way for JavaScript to set this.</p>
- <p class="issue">Specify a way to identify which <source-id/> an <audio-track/> or <video-track/> is associated with.</p>
-
- <h2 id="revision-history">9. Revision History</h2>
+ <h2 id="revision-history">8. Revision History</h2>
<table>
<thead>
<tr>
@@ -805,7 +849,15 @@
</thead>
<tbody>
<tr>
- <td>0.5</td>
+ <td>02 July 2012</td>
+ <td>Converted to the object-oriented API</td>
+ </tr>
+ <tr>
+ <td><a href="http://dvcs.w3.org/hg/html-media/raw-file/9bbfe09653e4/media-source/media-source.html">26 June 2012</a></td>
+ <td>Converted to Editor's draft.</td>
+ </tr>
+ <tr>
+ <td><a href="http://dvcs.w3.org/hg/html-media/raw-file/e433598d22a7/media-source/media-source.html">0.5</a></td>
<td>Minor updates before proposing to W3C HTML-WG.</td>
</tr>
<tr>
Binary file media-source/pipeline_model.png has changed
--- a/media-source/spec-html.xsl Fri Jun 29 08:24:15 2012 -0400
+++ b/media-source/spec-html.xsl Mon Jul 02 16:05:53 2012 -0700
@@ -38,48 +38,123 @@
</xsl:call-template>
</xsl:template>
- <xsl:template match="//sourceAddId">
+ <!-- MediaSource tags -->
+ <xsl:template match="//sourceBuffers">
<xsl:call-template name="coderef_helper">
- <xsl:with-param name="fragment">sourceaddid</xsl:with-param>
- <xsl:with-param name="link_text">sourceAddId()</xsl:with-param>
+ <xsl:with-param name="fragment">sourcebuffers</xsl:with-param>
+ <xsl:with-param name="link_text">sourceBuffers</xsl:with-param>
</xsl:call-template>
</xsl:template>
-
- <xsl:template match="//sourceRemoveId">
+ <xsl:template match="//activeSourceBuffers">
<xsl:call-template name="coderef_helper">
- <xsl:with-param name="fragment">sourceremoveid</xsl:with-param>
- <xsl:with-param name="link_text">sourceRemoveId()</xsl:with-param>
- </xsl:call-template>
- </xsl:template>
-
- <xsl:template match="//sourceAppend">
- <xsl:call-template name="coderef_helper">
- <xsl:with-param name="fragment">sourceappend</xsl:with-param>
- <xsl:with-param name="link_text">sourceAppend()</xsl:with-param>
+ <xsl:with-param name="fragment">activesourcebuffers</xsl:with-param>
+ <xsl:with-param name="link_text">activeSourceBuffers</xsl:with-param>
</xsl:call-template>
</xsl:template>
- <xsl:template match="//sourceAbort">
+ <xsl:template match="//addSourceBuffer">
<xsl:call-template name="coderef_helper">
- <xsl:with-param name="fragment">sourceabort</xsl:with-param>
- <xsl:with-param name="link_text">sourceAbort()</xsl:with-param>
+ <xsl:with-param name="fragment">addsourcebuffer</xsl:with-param>
+ <xsl:with-param name="link_text">addSourceBuffer()</xsl:with-param>
</xsl:call-template>
</xsl:template>
- <xsl:template match="//sourceBuffered">
+ <xsl:template match="//readyState">
<xsl:call-template name="coderef_helper">
- <xsl:with-param name="fragment">sourcebuffered</xsl:with-param>
- <xsl:with-param name="link_text">sourceBuffered()</xsl:with-param>
+ <xsl:with-param name="fragment">readyState</xsl:with-param>
+ <xsl:with-param name="link_text">readyState</xsl:with-param>
</xsl:call-template>
</xsl:template>
- <xsl:template match="//sourceState">
+ <!-- SourceBufferList tags -->
+ <xsl:template match="//length">
<xsl:call-template name="coderef_helper">
- <xsl:with-param name="fragment">sourcestate</xsl:with-param>
- <xsl:with-param name="link_text">sourceState</xsl:with-param>
+ <xsl:with-param name="fragment">length</xsl:with-param>
+ <xsl:with-param name="link_text">length</xsl:with-param>
</xsl:call-template>
</xsl:template>
-
+ <xsl:template match="//remove">
+ <xsl:call-template name="coderef_helper">
+ <xsl:with-param name="fragment">remove</xsl:with-param>
+ <xsl:with-param name="link_text">remove()</xsl:with-param>
+ </xsl:call-template>
+ </xsl:template>
+
+ <xsl:template match="//addsourcebuffer">
+ <xsl:call-template name="coderef_helper">
+ <xsl:with-param name="fragment">addsourcebuffer</xsl:with-param>
+ <xsl:with-param name="link_text">addsourcebuffer</xsl:with-param>
+ </xsl:call-template>
+ </xsl:template>
+
+ <xsl:template match="//removesourcebuffer">
+ <xsl:call-template name="coderef_helper">
+ <xsl:with-param name="fragment">removesourcebuffer</xsl:with-param>
+ <xsl:with-param name="link_text">removesourcebuffer</xsl:with-param>
+ </xsl:call-template>
+ </xsl:template>
+
+ <!-- SourceBuffer tags -->
+ <xsl:template match="//append">
+ <xsl:call-template name="coderef_helper">
+ <xsl:with-param name="fragment">append</xsl:with-param>
+ <xsl:with-param name="link_text">append()</xsl:with-param>
+ </xsl:call-template>
+ </xsl:template>
+
+ <xsl:template match="//abort">
+ <xsl:call-template name="coderef_helper">
+ <xsl:with-param name="fragment">abort</xsl:with-param>
+ <xsl:with-param name="link_text">abort()</xsl:with-param>
+ </xsl:call-template>
+ </xsl:template>
+
+ <xsl:template match="//buffered">
+ <xsl:call-template name="coderef_helper">
+ <xsl:with-param name="fragment">buffered</xsl:with-param>
+ <xsl:with-param name="link_text">buffered</xsl:with-param>
+ </xsl:call-template>
+ </xsl:template>
+
+ <xsl:template match="//SourceBuffer">
+ <xsl:call-template name="coderef_helper">
+ <xsl:with-param name="fragment">sourcebuffer</xsl:with-param>
+ <xsl:with-param name="link_text">SourceBuffer</xsl:with-param>
+ </xsl:call-template>
+ </xsl:template>
+
+ <xsl:template match="//SourceBufferList">
+ <xsl:call-template name="coderef_helper">
+ <xsl:with-param name="fragment">sourcebufferlist</xsl:with-param>
+ <xsl:with-param name="link_text">SourceBufferList</xsl:with-param>
+ </xsl:call-template>
+ </xsl:template>
+
+ <xsl:template match="//MediaSource">
+ <xsl:call-template name="coderef_helper">
+ <xsl:with-param name="fragment">mediasource</xsl:with-param>
+ <xsl:with-param name="link_text">MediaSource</xsl:with-param>
+ </xsl:call-template>
+ </xsl:template>
+
+ <xsl:template match="//open">
+ <xsl:call-template name="coderef_helper">
+ <xsl:with-param name="fragment">"open"</xsl:with-param>
+ <xsl:with-param name="link_text">"open"</xsl:with-param>
+ </xsl:call-template>
+ </xsl:template>
+ <xsl:template match="//closed">
+ <xsl:call-template name="coderef_helper">
+ <xsl:with-param name="fragment">closed</xsl:with-param>
+ <xsl:with-param name="link_text">"closed"</xsl:with-param>
+ </xsl:call-template>
+ </xsl:template>
+ <xsl:template match="//ended">
+ <xsl:call-template name="coderef_helper">
+ <xsl:with-param name="fragment">"ended"</xsl:with-param>
+ <xsl:with-param name="link_text">"ended"</xsl:with-param>
+ </xsl:call-template>
+ </xsl:template>
<xsl:template match="//codedfn">
<dfn><xsl:attribute name="id">dom-<xsl:value-of select="translate(.,$upper,$lower)"/></xsl:attribute><code><xsl:value-of select="."/></code></dfn>
@@ -139,20 +214,16 @@
</xsl:call-template>
</xsl:template>
- <xsl:template match="//active-id">
- <a><xsl:attribute name="href">#active-ids</xsl:attribute>active ID</a>
+ <xsl:template match="//active-source-buffer">
+ <a><xsl:attribute name="href">#active-source-buffers</xsl:attribute>active source buffers</a>
</xsl:template>
- <xsl:template match="//active-ids">
- <a><xsl:attribute name="href">#active-ids</xsl:attribute>active IDs</a>
+ <xsl:template match="//active-source-buffers">
+ <a><xsl:attribute name="href">#active-source-buffers</xsl:attribute>active source buffers</a>
</xsl:template>
- <xsl:template match="//source-id">
- <a><xsl:attribute name="href">#source-id</xsl:attribute>source ID</a>
- </xsl:template>
-
- <xsl:template match="//source-ids">
- <a><xsl:attribute name="href">#source-id</xsl:attribute>source IDs</a>
+ <xsl:template match="//source-buffers">
+ <a><xsl:attribute name="href">#source-buffer</xsl:attribute>source buffers</a>
</xsl:template>
<xsl:template match="//source-buffer">
@@ -267,11 +338,24 @@
</xsl:call-template>
</xsl:template>
+ <xsl:template match="//text-track">
+ <xsl:call-template name="code_videoref_helper">
+ <xsl:with-param name="fragment">texttrack</xsl:with-param>
+ <xsl:with-param name="link_text">TextTrack</xsl:with-param>
+ </xsl:call-template>
+ </xsl:template>
+
+ <xsl:template match="//texttracks">
+ <xsl:call-template name="code_videoref_helper">
+ <xsl:with-param name="fragment">dom-media-texttracks</xsl:with-param>
+ <xsl:with-param name="link_text">textTracks</xsl:with-param>
+ </xsl:call-template>
+ </xsl:template>
<xsl:template match="//ready-state">
<xsl:call-template name="code_videoref_helper">
<xsl:with-param name="fragment">dom-media-readystate</xsl:with-param>
- <xsl:with-param name="link_text">readyState</xsl:with-param>
+ <xsl:with-param name="link_text">HTMLMediaElement.readyState</xsl:with-param>
</xsl:call-template>
</xsl:template>
@@ -310,6 +394,13 @@
</xsl:call-template>
</xsl:template>
+ <xsl:template match="//MEDIA_ERR_SRC_NOT_SUPPORTED">
+ <xsl:call-template name="code_videoref_helper">
+ <xsl:with-param name="fragment">dom-mediaerror-media_err_src_not_supported</xsl:with-param>
+ <xsl:with-param name="link_text">MEDIA_ERR_SRC_NOT_SUPPORTED</xsl:with-param>
+ </xsl:call-template>
+ </xsl:template>
+
<xsl:template name="exception_helper">
<xsl:param name="fragment" />
<xsl:param name="link_text" />
@@ -335,8 +426,15 @@
<xsl:with-param name="fragment">syntax_err</xsl:with-param>
<xsl:with-param name="link_text">SYNTAX_ERR</xsl:with-param>
</xsl:call-template>
- </xsl:template>
+ </xsl:template>
+
+ <xsl:template match="//not-found-err">
+ <xsl:call-template name="exception_helper">
+ <xsl:with-param name="fragment">not_found_err</xsl:with-param>
+ <xsl:with-param name="link_text">NOT_FOUND_ERR</xsl:with-param>
+ </xsl:call-template>
+ </xsl:template>
<xsl:template match="//not-supported-err">
<xsl:call-template name="exception_helper">
<xsl:with-param name="fragment">not_supported_err</xsl:with-param>