Fixed various addsourcebuffer & removesourcebuffer bugs and allow append() in ended state.
authorAaron Colwell <acolwell@google.com>
Mon, 01 Oct 2012 15:20:37 -0700
changeset 35 7bab66368f2c
parent 34 390143e813b7
child 36 c3de559a1c37
Fixed various addsourcebuffer & removesourcebuffer bugs and allow append() in ended state.

https://www.w3.org/Bugs/Public/show_bug.cgi?id=18578
- Removed the special handling for empty sourceBuffers in removeSourceBuffer() algorithm since it redundant with the "not found" case.

https://www.w3.org/Bugs/Public/show_bug.cgi?id=18589
- Updated failed attach text run the "If the media data cannot be fetched at all ..." steps of the resource fetch algorithm.

https://www.w3.org/Bugs/Public/show_bug.cgi?id=18633
- Fixed addsourcebuffer & removesourcebuffer event links

https://www.w3.org/Bugs/Public/show_bug.cgi?id=18634
- Updated detach algorithm to only fire removesourcebuffer once when all the SourceBuffers are removed.
- Added steps for activeSourceBuffer to detach algorithm.
- Added missing "queue a task to fire and event named ..." steps to various steps in section 3.3.5.

https://www.w3.org/Bugs/Public/show_bug.cgi?id=18708
- Updated append() algorithm to transition from "ended" to "open" and fire a sourceopen event.
media-source/media-source.html
media-source/media-source.xml
media-source/spec-html.xsl
--- a/media-source/media-source.html	Mon Sep 17 20:00:58 2012 -0700
+++ b/media-source/media-source.html	Mon Oct 01 15:20:37 2012 -0700
@@ -42,7 +42,7 @@
     <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 13 September 2012</h2>
+      <h2>W3C Editor's Draft 1 October 2012</h2>
       <dl>
 	<dt>Latest published version:</dt>
 	<dd>Not yet published</dd>
@@ -375,20 +375,19 @@
       <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 <a href="http://dev.w3.org/html5/spec/webappapis.html#queue-a-task">queue a task</a> to <a href="http://dev.w3.org/html5/spec/webappapis.html#fire-a-simple-event">fire a simple event</a> named
-   <code><a href="#dom-addsourcebuffer">addsourcebuffer</a></code> at <code><a href="#dom-sourcebuffers">sourceBuffers</a></code>.</li>
+   <code><a href="#dom-evt-addsourcebuffer">addsourcebuffer</a></code> at <code><a href="#dom-sourcebuffers">sourceBuffers</a></code>.</li>
       <li>Return the new object.</li>
     </ol>
     <p>The <dfn id="dom-removesourcebuffer"><code>removeSourceBuffer(sourceBuffer)</code></dfn> method must run the following steps:</p>
     <ol>
       <li>If <var title="true">sourceBuffer</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 <code><a href="#dom-sourcebuffers">sourceBuffers</a></code> 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">sourceBuffer</var> specifies an object that is not 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_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">sourceBuffer</var> and <a href="http://dev.w3.org/html5/spec/webappapis.html#queue-a-task">queue a task</a> to <a href="http://dev.w3.org/html5/spec/webappapis.html#fire-a-simple-event">fire a simple event</a> named
    <code><a href="http://dev.w3.org/html5/spec/media-elements.html#handler-tracklist-onchange">change</a></code> at the modified lists.</li>
       <li>If <var title="true">sourceBuffer</var> is in <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code>, then remove it from <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code> and <a href="http://dev.w3.org/html5/spec/webappapis.html#queue-a-task">queue a task</a> to <a href="http://dev.w3.org/html5/spec/webappapis.html#fire-a-simple-event">fire a simple event</a> named
-   <code><a href="#dom-removesourcebuffer">removesourcebuffer</a></code> at <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code>.</li>
+   <code><a href="#dom-evt-removesourcebuffer">removesourcebuffer</a></code> at <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code>.</li>
       <li>Remove <var title="true">sourceBuffer</var> from <code><a href="#dom-sourcebuffers">sourceBuffers</a></code> and <a href="http://dev.w3.org/html5/spec/webappapis.html#queue-a-task">queue a task</a> to <a href="http://dev.w3.org/html5/spec/webappapis.html#fire-a-simple-event">fire a simple event</a> named
-   <code><a href="#dom-removesourcebuffer">removesourcebuffer</a></code> at <code><a href="#dom-sourcebuffers">sourceBuffers</a></code>.</li>
+   <code><a href="#dom-evt-removesourcebuffer">removesourcebuffer</a></code> at <code><a href="#dom-sourcebuffers">sourceBuffers</a></code>.</li>
       <li>Destroy all resources for <var title="true">sourceBuffer</var>.</li>
     </ol>
 
@@ -425,7 +424,7 @@
       <li>Change the <code><a href="#dom-readystate">readyState</a></code> attribute value to <code><a href="#dom-%22ended%22">"ended"</a></code>.</li>
       <li>
 <a href="http://dev.w3.org/html5/spec/webappapis.html#queue-a-task">queue a task</a> to <a href="http://dev.w3.org/html5/spec/webappapis.html#fire-a-simple-event">fire a simple event</a> named
-   <code><a href="#dom-sourceended">sourceended</a></code> at the <code><a href="#dom-mediasource">MediaSource</a></code>.</li>
+   <code><a href="#dom-evt-sourceended">sourceended</a></code> at the <code><a href="#dom-mediasource">MediaSource</a></code>.</li>
       <dl class="switch">
           <dt>If <var title="true">error</var> is not set, null, or an empty string</dt>
           <dd>
@@ -440,10 +439,12 @@
 </dt>
           <dd>
 	    <dl class="switch">
-	      <dt>If <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> attribute equals <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_nothing">HAVE_NOTHING</a></code>
+	      <dt>If the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> attribute equals <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_nothing">HAVE_NOTHING</a></code>
 </dt>
-	      <dd>Run the "<i>If the media data cannot be fetched at all, due to network errors, causing the user agent to give up trying to fetch the resource</i>" steps of the <a href="http://dev.w3.org/html5/spec/media-elements.html#concept-media-load-resource">resource fetch algorithm</a>.</dd>
-	      <dt>If <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> attribute greater than <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_nothing">HAVE_NOTHING</a></code>
+	      <dd>Run the 
+    "<i>If the media data cannot be fetched at all, due to network errors, causing the user agent to give up trying to fetch the resource</i>"
+   steps of the <a href="http://dev.w3.org/html5/spec/media-elements.html#concept-media-load-resource">resource fetch algorithm</a>.</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_nothing">HAVE_NOTHING</a></code>
 </dt>
 	      <dd>Run the "<i>If the connection is interrupted after some media data has been received, causing the user agent to give up trying to fetch the resource</i>" steps of the <a href="http://dev.w3.org/html5/spec/media-elements.html#concept-media-load-resource">resource fetch algorithm</a>.</dd>
 	    </dl>
@@ -452,10 +453,10 @@
 </dt>
           <dd>
 	    <dl class="switch">
-	      <dt>If <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> attribute equals <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_nothing">HAVE_NOTHING</a></code>
+	      <dt>If the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> attribute equals <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_nothing">HAVE_NOTHING</a></code>
 </dt>
 	      <dd>Run the "<i>If the media data can be fetched but is found by inspection to be in an unsupported format, or can otherwise not be rendered at all</i>" steps of the <a href="http://dev.w3.org/html5/spec/media-elements.html#concept-media-load-resource">resource fetch algorithm</a>.</dd>
-	      <dt>If <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> attribute greater than <code><a href="http://dev.w3.org/html5/spec/media-elements.html#dom-media-have_nothing">HAVE_NOTHING</a></code>
+	      <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_nothing">HAVE_NOTHING</a></code>
 </dt>
 	      <dd>Run the <a href="http://dev.w3.org/html5/spec/media-elements.html#fatal-decode-error">media data is corrupted</a> steps of the <a href="http://dev.w3.org/html5/spec/media-elements.html#concept-media-load-resource">resource fetch algorithm</a>.</dd>
 	    </dl>
@@ -477,17 +478,17 @@
       </thead>
       <tbody>
         <tr>
-          <td><dfn id="dom-sourceopen"><code>sourceopen</code></dfn></td>
+          <td><dfn id="dom-evt-sourceopen"><code>sourceopen</code></dfn></td>
           <td><code>Event</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><dfn id="dom-evt-sourceended"><code>sourceended</code></dfn></td>
           <td><code>Event</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><dfn id="dom-evt-sourceclose"><code>sourceclose</code></dfn></td>
           <td><code>Event</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>
@@ -503,12 +504,14 @@
       <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><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>
+        <dd>Run the 
+    "<i>If the media data cannot be fetched at all, due to network errors, causing the user agent to give up trying to fetch the resource</i>"
+   steps of the <a href="http://dev.w3.org/html5/spec/media-elements.html#concept-media-load-resource">resource fetch algorithm</a>.</dd>
         <dt>Otherwise</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>.</li>
+            <li>Fire a simple event named <code><a href="#dom-evt-sourceopen">sourceopen</a></code>.</li>
             <li>Allow the <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>
@@ -520,10 +523,17 @@
     <ol>
       <li>Set the <code><a href="#dom-readystate">readyState</a></code> attribute to <code><a href="#dom-closed">"closed"</a></code>.</li>
       <li>Set the <code><a href="#dom-duration">duration</a></code> attribute to NaN.</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>Remove all the <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> objects from <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code>.</li>
       <li>
 <a href="http://dev.w3.org/html5/spec/webappapis.html#queue-a-task">queue a task</a> to <a href="http://dev.w3.org/html5/spec/webappapis.html#fire-a-simple-event">fire a simple event</a> named
-   <code><a href="#dom-sourceclose">sourceclose</a></code> at the <code><a href="#dom-mediasource">MediaSource</a></code>.</li>
+   <code><a href="#dom-evt-removesourcebuffer">removesourcebuffer</a></code> at <code><a href="#dom-activesourcebuffers">activeSourceBuffers</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>.</li>
+      <li>
+<a href="http://dev.w3.org/html5/spec/webappapis.html#queue-a-task">queue a task</a> to <a href="http://dev.w3.org/html5/spec/webappapis.html#fire-a-simple-event">fire a simple event</a> named
+   <code><a href="#dom-evt-removesourcebuffer">removesourcebuffer</a></code> at <code><a href="#dom-sourcebuffers">sourceBuffers</a></code>.</li>
+      <li>
+<a href="http://dev.w3.org/html5/spec/webappapis.html#queue-a-task">queue a task</a> to <a href="http://dev.w3.org/html5/spec/webappapis.html#fire-a-simple-event">fire a simple event</a> named
+   <code><a href="#dom-evt-sourceclose">sourceclose</a></code> at the <code><a href="#dom-mediasource">MediaSource</a></code>.</li>
     </ol>
 
     <h4 id="mediasource-seeking">3.3.3 Seeking</h4>
@@ -537,7 +547,7 @@
 	    <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>
+	      <li>Fire a simple event named <code><a href="#dom-evt-sourceopen">sourceopen</a></code> on the <code><a href="#dom-mediasource">MediaSource</a></code> object.</li>
 	    </ol>
 	  </dd>
 	  <dt>Otherwise</dt>
@@ -603,28 +613,75 @@
     <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>
+      <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>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, run the following steps:
+  	  <ol>
+	    <li>Remove the <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> from <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code>.</li>
+	    <li>
+<a href="http://dev.w3.org/html5/spec/webappapis.html#queue-a-task">queue a task</a> to <a href="http://dev.w3.org/html5/spec/webappapis.html#fire-a-simple-event">fire a simple event</a> named
+   <code><a href="#dom-evt-removesourcebuffer">removesourcebuffer</a></code> at <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>
+	  </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>, run the following steps:
+	  <ol>
+	    <li>Add the <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> to <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code>.</li>
+	    <li>
+<a href="http://dev.w3.org/html5/spec/webappapis.html#queue-a-task">queue a task</a> to <a href="http://dev.w3.org/html5/spec/webappapis.html#fire-a-simple-event">fire a simple event</a> named
+   <code><a href="#dom-evt-addsourcebuffer">addsourcebuffer</a></code> at <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code>
+</li>
+	  </ol>
+	  </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>
+      <dd>
+	<ol>
+	  <li>Remove the <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> associated with the audio track from <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code>
+</li>
+	  <li>
+<a href="http://dev.w3.org/html5/spec/webappapis.html#queue-a-task">queue a task</a> to <a href="http://dev.w3.org/html5/spec/webappapis.html#fire-a-simple-event">fire a simple event</a> named
+   <code><a href="#dom-evt-removesourcebuffer">removesourcebuffer</a></code> at <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code>
+</li>
+	</ol>
+      </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>
+      <dd>
+	<ol>
+	  <li>Add the <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> associated with the audio track to <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code>
+</li>
+	  <li>
+<a href="http://dev.w3.org/html5/spec/webappapis.html#queue-a-task">queue a task</a> to <a href="http://dev.w3.org/html5/spec/webappapis.html#fire-a-simple-event">fire a simple event</a> named
+   <code><a href="#dom-evt-addsourcebuffer">addsourcebuffer</a></code> at <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code>
+</li>
+	</ol>
+      </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>
+      <dd>
+	<ol>
+	  <li>Remove the <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> associated with the text track from <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code>
+</li>
+	  <li>
+<a href="http://dev.w3.org/html5/spec/webappapis.html#queue-a-task">queue a task</a> to <a href="http://dev.w3.org/html5/spec/webappapis.html#fire-a-simple-event">fire a simple event</a> named
+   <code><a href="#dom-evt-removesourcebuffer">removesourcebuffer</a></code> at <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code>
+</li>
+	</ol>
+      </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>
+      <dd>
+	<ol>
+	  <li>Add the <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> associated with the text track to <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code>
+</li>
+	  <li>
+<a href="http://dev.w3.org/html5/spec/webappapis.html#queue-a-task">queue a task</a> to <a href="http://dev.w3.org/html5/spec/webappapis.html#fire-a-simple-event">fire a simple event</a> named
+   <code><a href="#dom-evt-addsourcebuffer">addsourcebuffer</a></code> at <code><a href="#dom-activesourcebuffers">activeSourceBuffers</a></code>
+</li>
+	</ol>
+      </dd>
     </dl>
 
     <h4 id="duration-change-algorithm">3.3.6 Duration change</h4>
@@ -632,7 +689,9 @@
     <ol>
       <li>If the current value of <code><a href="#dom-duration">duration</a></code> is equal to <var title="true">new duration</var>, then abort these steps.</li>
       <li>Update <code><a href="#dom-duration">duration</a></code> to <var title="true">new duration</var>.</li>
-      <li>Remove all media data with timestamps that are greater than <var title="true">new duration</var> from all <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> objects in <code><a href="#dom-sourcebuffers">sourceBuffers</a></code>.</li>
+      <li>Remove all media data with timestamps that are greater than <var title="true">new duration</var> from all <code><a href="#dom-sourcebuffer">SourceBuffer</a></code> objects in <code><a href="#dom-sourcebuffers">sourceBuffers</a></code>.
+      <p class="note">Note: This preserves audio frames that start before and end after the <code><a href="#dom-duration">duration</a></code>. The user agent must end playback at <code><a href="#dom-duration">duration</a></code> even if the audio frame extends beyond this time.</p>
+      </li>
       <li>Update the <code><a href="http://dev.w3.org/html5/spec/media-elements.html#media-controller-duration">media controller duration</a></code> to <var title="true">new duration</var> and run the <a href="http://dev.w3.org/html5/spec/media-elements.html#durationChange">HTMLMediaElement duration change algorithm</a>.</li>
     </ol>
 
@@ -668,9 +727,19 @@
 
     <p>The <dfn id="dom-append"><code>append(data)</code></dfn> method must run the following steps:</p>
     <ol>
+      <li>Let <var title="true">media source</var> be the <code><a href="#dom-mediasource">MediaSource</a></code> object that created this object.</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 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 this object has been removed from the <code><a href="#dom-sourcebuffers">sourceBuffers</a></code> attribute of <var title="true">media source</var> 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 <var title="true">media source</var> is in the <code><a href="#dom-closed">"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 the <code><a href="#dom-readystate">readyState</a></code> attribute of <var title="true">media source</var> is in the <code><a href="#dom-%22ended%22">"ended"</a></code> state then run the following steps:
+      <ol>
+	<li>Set the <code><a href="#dom-readystate">readyState</a></code> attribute of <var title="true">media source</var> to <code><a href="#dom-%22open%22">"open"</a></code>
+</li>
+	<li>
+<a href="http://dev.w3.org/html5/spec/webappapis.html#queue-a-task">queue a task</a> to <a href="http://dev.w3.org/html5/spec/webappapis.html#fire-a-simple-event">fire a simple event</a> named
+   <code><a href="#dom-evt-sourceopen">sourceopen</a></code> at <var title="true">media source</var> .</li>
+      </ol>
+      </li>
       <li>If <var title="true">data</var>.byteLength is 0 abort these steps.</li>
       <li>If <var title="true">data</var> contains anything that violates the <a href="#byte-stream-formats">byte stream format specifications</a>, then call <code><a href="#dom-endofstream">endOfStream("decode")</a></code>, and abort these steps.</li>
       <li>Add <var title="true">data</var> to the source buffer:
@@ -805,12 +874,12 @@
       </thead>
       <tbody>
         <tr>
-          <td><dfn id="dom-addsourcebuffer"><code>addsourcebuffer</code></dfn></td>
+          <td><dfn id="dom-evt-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><dfn id="dom-evt-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>
@@ -1007,9 +1076,13 @@
         </tr>
       </thead>
       <tbody>
+	<tr>
+	  <td>1 October 2012</td>
+          <td>Fixed various addsourcebuffer &amp; removesourcebuffer bugs and allow append() in ended state.</td>
+        </tr>
         <tr>
-	  <td>13 September 2012</td>
-          <td>Added decode error &amp; network error algorithms.</td>
+	  <td><a href="http://dvcs.w3.org/hg/html-media/raw-file/349559debcc3/media-source/media-source.html">13 September 2012</a></td>
+          <td>Updated endOfStream() behavior to change based on the value of HTMLMediaElement.readyState.</td>
         </tr>
         <tr>
 	  <td><a href="http://dvcs.w3.org/hg/html-media/raw-file/ca093bbbbefb/media-source/media-source.html">24 August 2012</a></td>
--- a/media-source/media-source.xml	Mon Sep 17 20:00:58 2012 -0700
+++ b/media-source/media-source.xml	Mon Oct 01 15:20:37 2012 -0700
@@ -41,7 +41,7 @@
     <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 13 September 2012</h2>
+      <h2>W3C Editor's Draft 1 October 2012</h2>
       <dl>
 	<dt>Latest published version:</dt>
 	<dd>Not yet published</dd>
@@ -365,13 +365,12 @@
       <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 <queue-a-task-to-fire-an-event-named/> <coderef>addsourcebuffer</coderef> at <sourceBuffers/>.</li>
+      <li>Add the new object to <sourceBuffers/> and <queue-a-task-to-fire-an-event-named/> <addsourcebuffer/> at <sourceBuffers/>.</li>
       <li>Return the new object.</li>
     </ol>
     <p>The <methoddfn name="removeSourceBuffer">removeSourceBuffer(<var title="true">sourceBuffer</var>)</methoddfn> method must run the following steps:</p>
     <ol>
       <li>If <var title="true">sourceBuffer</var> is null then throw an <invalid-access-err/> exception and abort these steps.</li>
-      <li>If <sourceBuffers/> is empty then throw an <invalid-state-err/> exception and abort these steps.</li>
       <li>If <var title="true">sourceBuffer</var> specifies an object that is not in <sourceBuffers/> 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">sourceBuffer</var> and <queue-a-task-to-fire-an-event-named/> <videoref name="handler-tracklist-onchange">change</videoref> at the modified lists.</li>
       <li>If <var title="true">sourceBuffer</var> is in <activeSourceBuffers/>, then remove it from <activeSourceBuffers/> and <queue-a-task-to-fire-an-event-named/> <removesourcebuffer/> at <activeSourceBuffers/>.</li>
@@ -410,7 +409,7 @@
     <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>
-      <li><queue-a-task-to-fire-an-event-named/> <coderef>sourceended</coderef> at the <MediaSource/>.</li>
+      <li><queue-a-task-to-fire-an-event-named/> <sourceended/> at the <MediaSource/>.</li>
       <dl class="switch">
           <dt>If <var title="true">error</var> is not set, null, or an empty string</dt>
           <dd>
@@ -424,18 +423,18 @@
           <dt>If <var title="true">error</var> is set to <coderef>&quot;network&quot;</coderef></dt>
           <dd>
 	    <dl class="switch">
-	      <dt>If <ready-state/> attribute equals <have-nothing/></dt>
-	      <dd>Run the &quot;<i>If the media data cannot be fetched at all, due to network errors, causing the user agent to give up trying to fetch the resource</i>&quot; steps of the <resource-fetch-algorithm/>.</dd>
-	      <dt>If <ready-state/> attribute greater than <have-nothing/></dt>
+	      <dt>If the <ready-state/> attribute equals <have-nothing/></dt>
+	      <dd>Run the <media-data-cannot-be-fetched/> steps of the <resource-fetch-algorithm/>.</dd>
+	      <dt>If the <ready-state/> attribute is greater than <have-nothing/></dt>
 	      <dd>Run the &quot;<i>If the connection is interrupted after some media data has been received, causing the user agent to give up trying to fetch the resource</i>&quot; steps of the <resource-fetch-algorithm/>.</dd>
 	    </dl>
 	  </dd>
           <dt>If <var title="true">error</var> is set to <coderef>&quot;decode&quot;</coderef></dt>
           <dd>
 	    <dl class="switch">
-	      <dt>If <ready-state/> attribute equals <have-nothing/></dt>
+	      <dt>If the <ready-state/> attribute equals <have-nothing/></dt>
 	      <dd>Run the &quot;<i>If the media data can be fetched but is found by inspection to be in an unsupported format, or can otherwise not be rendered at all</i>&quot; steps of the <resource-fetch-algorithm/>.</dd>
-	      <dt>If <ready-state/> attribute greater than <have-nothing/></dt>
+	      <dt>If the <ready-state/> attribute is greater than <have-nothing/></dt>
 	      <dd>Run the <media-data-is-corrupted/> steps of the <resource-fetch-algorithm/>.</dd>
 	    </dl>
 	  </dd>
@@ -456,17 +455,17 @@
       </thead>
       <tbody>
         <tr>
-          <td><codedfn>sourceopen</codedfn></td>
+          <td><eventdfn>sourceopen</eventdfn></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><eventdfn>sourceended</eventdfn></td>
           <td><code>Event</code></td>
           <td>When <readyState/> transitions from <open/> to <ended/>.</td>
         </tr>
         <tr>
-          <td><codedfn>sourceclose</codedfn></td>
+          <td><eventdfn>sourceclose</eventdfn></td>
           <td><code>Event</code></td>
 	  <td>When <readyState/> transitions from <open/> to <closed/> or <ended/> to <closed/>.</td>
         </tr>
@@ -481,12 +480,12 @@
     <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>
+        <dd>Run the <media-data-cannot-be-fetched/> steps of the <resource-fetch-algorithm/>.</dd>
         <dt>Otherwise</dt>
         <dd>
           <ol>
             <li>Set the <readyState/> attribute to <open/>.</li>
-            <li>Fire a simple event named <coderef>sourceopen</coderef>.</li>
+            <li>Fire a simple event named <sourceopen/>.</li>
             <li>Allow the <resource-fetch-algorithm/> to progress based on data passed in via <append/>.</li>
           </ol>
         </dd>
@@ -498,8 +497,11 @@
     <ol>
       <li>Set the <readyState/> attribute to <closed/>.</li>
       <li>Set the <duration/> attribute to NaN.</li>
-      <li>Remove all the <SourceBuffer/> objects from <sourceBuffers/> and fire a <coderef>removesourcebuffer</coderef> event for each one.</li>
-      <li><queue-a-task-to-fire-an-event-named/> <coderef>sourceclose</coderef> at the <MediaSource/>.</li>
+      <li>Remove all the <SourceBuffer/> objects from <activeSourceBuffers/>.</li>
+      <li><queue-a-task-to-fire-an-event-named/> <removesourcebuffer/> at <activeSourceBuffers/>.</li>
+      <li>Remove all the <SourceBuffer/> objects from <sourceBuffers/>.</li>
+      <li><queue-a-task-to-fire-an-event-named/> <removesourcebuffer/> at <sourceBuffers/>.</li>
+      <li><queue-a-task-to-fire-an-event-named/> <sourceclose/> at the <MediaSource/>.</li>
     </ol>
 
     <h4 id="mediasource-seeking">3.3.3 Seeking</h4>
@@ -511,7 +513,7 @@
 	  <dd>
 	    <ol>
 	      <li>Set the <readyState/> attribute to <open/></li>
-	      <li>Fire a simple event named <coderef>sourceopen</coderef> on the <MediaSource/> object.</li>
+	      <li>Fire a simple event named <sourceopen/> on the <MediaSource/> object.</li>
 	    </ol>
 	  </dd>
 	  <dt>Otherwise</dt>
@@ -576,21 +578,51 @@
     <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>
+      <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>
+	  <li>If the <SourceBuffer/> associated with the previously selected video track is not associated with any other enabled tracks, run the following steps:
+  	  <ol>
+	    <li>Remove the <SourceBuffer/> from <activeSourceBuffers/>.</li>
+	    <li><queue-a-task-to-fire-an-event-named/> <removesourcebuffer/> at <activeSourceBuffers/></li>
+	  </ol>
+	  </li>
+	  <li>If the <SourceBuffer/> associated with the newly selected video track is not already in <activeSourceBuffers/>, run the following steps:
+	  <ol>
+	    <li>Add the <SourceBuffer/> to <activeSourceBuffers/>.</li>
+	    <li><queue-a-task-to-fire-an-event-named/> <addsourcebuffer/> at <activeSourceBuffers/></li>
+	  </ol>
+	  </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>
+      <dd>
+	<ol>
+	  <li>Remove the <SourceBuffer/> associated with the audio track from <activeSourceBuffers/></li>
+	  <li><queue-a-task-to-fire-an-event-named/> <removesourcebuffer/> at <activeSourceBuffers/></li>
+	</ol>
+      </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>
+      <dd>
+	<ol>
+	  <li>Add the <SourceBuffer/> associated with the audio track to <activeSourceBuffers/></li>
+	  <li><queue-a-task-to-fire-an-event-named/> <addsourcebuffer/> at <activeSourceBuffers/></li>
+	</ol>
+      </dd>
       <dt>If a text track <videoref name="dom-texttrack-mode">mode</videoref> becomes <videoref name="dom-texttrack-disabled">&quot;disabled&quot;</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>
+      <dd>
+	<ol>
+	  <li>Remove the <SourceBuffer/> associated with the text track from <activeSourceBuffers/></li>
+	  <li><queue-a-task-to-fire-an-event-named/> <removesourcebuffer/> at <activeSourceBuffers/></li>
+	</ol>
+      </dd>
       <dt>If a text track <videoref name="dom-texttrack-mode">mode</videoref> becomes <videoref name="dom-texttrack-showing">&quot;showing&quot;</videoref> or <videoref name="dom-texttrack-hidden">&quot;hidden&quot;</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>
+      <dd>
+	<ol>
+	  <li>Add the <SourceBuffer/> associated with the text track to <activeSourceBuffers/></li>
+	  <li><queue-a-task-to-fire-an-event-named/> <addsourcebuffer/> at <activeSourceBuffers/></li>
+	</ol>
+      </dd>
     </dl>
 
     <h4 id="duration-change-algorithm">3.3.6 Duration change</h4>
@@ -598,7 +630,9 @@
     <ol>
       <li>If the current value of <duration/> is equal to <new-duration/>, then abort these steps.</li>
       <li>Update <duration/> to <new-duration/>.</li>
-      <li>Remove all media data with timestamps that are greater than <new-duration/> from all <SourceBuffer/> objects in <sourceBuffers/>.</li>
+      <li>Remove all media data with timestamps that are greater than <new-duration/> from all <SourceBuffer/> objects in <sourceBuffers/>.
+      <p class="note">Note: This preserves audio frames that start before and end after the <duration/>. The user agent must end playback at <duration/> even if the audio frame extends beyond this time.</p>
+      </li>
       <li>Update the <hme-duration/> to <new-duration/> and run the <hme-duration-change-algorithm/>.</li>
     </ol>
 
@@ -634,9 +668,16 @@
 
     <p>The <methoddfn name="append">append(<var title="true">data</var>)</methoddfn> method must run the following steps:</p>
     <ol>
+      <li>Let <var title="true">media source</var> be the <MediaSource/> object that created this object.</li>
       <li>If <var title="true">data</var> is null then throw an <invalid-access-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 this object has been removed from the <sourceBuffers/> attribute of <var title="true">media source</var> then throw an <invalid-state-err/> exception and abort these steps.</li>
+      <li>If the <readyState/> attribute of <var title="true">media source</var> is in the <closed/> state then throw an <invalid-state-err/> exception and abort these steps.</li>
+      <li>If the <readyState/> attribute of <var title="true">media source</var> is in the <ended/> state then run the following steps:
+      <ol>
+	<li>Set the <readyState/> attribute of <var title="true">media source</var> to <open/></li>
+	<li><queue-a-task-to-fire-an-event-named/> <sourceopen/> at <var title="true">media source</var> .</li>
+      </ol>
+      </li>
       <li>If <var title="true">data</var>.byteLength is 0 abort these steps.</li>
       <li>If <var title="true">data</var> contains anything that violates the <a href="#byte-stream-formats">byte stream format specifications</a>, then call <eos-decode/>, and abort these steps.</li>
       <li>Add <var title="true">data</var> to the source buffer:
@@ -766,12 +807,12 @@
       </thead>
       <tbody>
         <tr>
-          <td><codedfn>addsourcebuffer</codedfn></td>
+          <td><eventdfn>addsourcebuffer</eventdfn></td>
           <td><code>Event</code></td>
           <td>When a <SourceBuffer/> is added to the list.</td>
         </tr>
         <tr>
-          <td><codedfn>removesourcebuffer</codedfn></td>
+          <td><eventdfn>removesourcebuffer</eventdfn></td>
           <td><code>Event</code></td>
           <td>When a <SourceBuffer/> is removed from the list.</td>
         </tr>
@@ -966,8 +1007,12 @@
         </tr>
       </thead>
       <tbody>
+	<tr>
+	  <td>1 October 2012</td>
+          <td>Fixed various addsourcebuffer &amp; removesourcebuffer bugs and allow append() in ended state.</td>
+        </tr>
         <tr>
-	  <td>13 September 2012</td>
+	  <td><a href="http://dvcs.w3.org/hg/html-media/raw-file/349559debcc3/media-source/media-source.html">13 September 2012</a></td>
           <td>Updated endOfStream() behavior to change based on the value of HTMLMediaElement.readyState.</td>
         </tr>
         <tr>
--- a/media-source/spec-html.xsl	Mon Sep 17 20:00:58 2012 -0700
+++ b/media-source/spec-html.xsl	Mon Oct 01 15:20:37 2012 -0700
@@ -31,6 +31,12 @@
     <code><a><xsl:attribute name="href">#dom-<xsl:value-of select="$fragment"/></xsl:attribute><xsl:value-of select="$link_text"/></a></code>
   </xsl:template>
 
+  <xsl:template name="eventref_helper">
+    <xsl:param name="fragment" />
+    <xsl:param name="link_text" />
+    <code><a><xsl:attribute name="href">#dom-evt-<xsl:value-of select="$fragment"/></xsl:attribute><xsl:value-of select="$link_text"/></a></code>
+  </xsl:template>
+
   <xsl:template match="//coderef">
     <xsl:call-template name="coderef_helper">
       <xsl:with-param name="fragment"><xsl:value-of select="translate(.,$upper,$lower)"/></xsl:with-param>
@@ -114,6 +120,27 @@
     </xsl:call-template>
   </xsl:template>
 
+  <xsl:template match="//sourceopen">
+    <xsl:call-template name="eventref_helper">
+      <xsl:with-param name="fragment">sourceopen</xsl:with-param>
+      <xsl:with-param name="link_text">sourceopen</xsl:with-param>
+    </xsl:call-template>
+  </xsl:template>
+
+  <xsl:template match="//sourceended">
+    <xsl:call-template name="eventref_helper">
+      <xsl:with-param name="fragment">sourceended</xsl:with-param>
+      <xsl:with-param name="link_text">sourceended</xsl:with-param>
+    </xsl:call-template>
+  </xsl:template>
+
+  <xsl:template match="//sourceclose">
+    <xsl:call-template name="eventref_helper">
+      <xsl:with-param name="fragment">sourceclose</xsl:with-param>
+      <xsl:with-param name="link_text">sourceclose</xsl:with-param>
+    </xsl:call-template>
+  </xsl:template>
+
   <!-- SourceBufferList tags -->
   <xsl:template match="//length">
     <xsl:call-template name="coderef_helper">
@@ -123,14 +150,14 @@
   </xsl:template>
 
   <xsl:template match="//addsourcebuffer">
-    <xsl:call-template name="coderef_helper">
+    <xsl:call-template name="eventref_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:call-template name="eventref_helper">
       <xsl:with-param name="fragment">removesourcebuffer</xsl:with-param>
       <xsl:with-param name="link_text">removesourcebuffer</xsl:with-param>
     </xsl:call-template>
@@ -265,6 +292,10 @@
     </xsl:call-template>
   </xsl:template>
 
+  <xsl:template match="//eventdfn">
+    <dfn><xsl:attribute name="id">dom-evt-<xsl:value-of select="translate(.,$upper,$lower)"/></xsl:attribute><code><xsl:value-of select="."/></code></dfn>
+  </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>
   </xsl:template>
@@ -337,6 +368,10 @@
     </xsl:call-template>
   </xsl:template>
 
+  <xsl:template match="//media-data-cannot-be-fetched">
+    &quot;<i>If the media data cannot be fetched at all, due to network errors, causing the user agent to give up trying to fetch the resource</i>&quot;
+  </xsl:template>
+
   <xsl:template match="//media-err-decode">
     <xsl:call-template name="code_videoref_helper">
       <xsl:with-param name="fragment">dom-mediaerror-media_err_decode</xsl:with-param>