<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>27342</bug_id>
          
          <creation_ts>2014-11-17 06:37:21 +0000</creation_ts>
          <short_desc>Clarify if the source buffer is still valid when appendBuffer/appendStream meets &apos;decode&apos; error</short_desc>
          <delta_ts>2014-12-03 06:39:45 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>HTML WG</product>
          <component>Media Source Extensions</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>CR</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Qin Jiajia">jiajia.qin</reporter>
          <assigned_to name="Aaron Colwell">acolwell</assigned_to>
          <cc>acolwell</cc>
    
    <cc>cyril.concolato</cc>
    
    <cc>jiajia.qin</cc>
    
    <cc>mike</cc>
    
    <cc>philipj</cc>
    
    <cc>public-html-media</cc>
          
          <qa_contact name="HTML WG Bugzilla archive list">public-html-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>114984</commentid>
    <comment_count>0</comment_count>
    <who name="Qin Jiajia">jiajia.qin</who>
    <bug_when>2014-11-17 06:37:21 +0000</bug_when>
    <thetext>Currently, when SourceBuffer.appendBuffer/appendStream fails in segment parser loop algorithm, it will run the end of stream algorithm with the error parameter set to &quot;decode&quot;. However, in end of stream algorithm, &apos;If error is set to &quot;decode&quot;. If the HTMLMediaElement.readyState attribute is greater than HAVE_NOTHING. Run the media data is corrupted steps of the resource fetch algorithm&apos; will result aborting the overall resource selection algorithm and the media player pipeline will be shutdown. So, if we execute SourceBuffer.appendBuffer/appendStream again, the media data will be ignored since the demuxer has been shutdown. What&apos;s more, if the MediaSource&apos;s readyState is set to &apos;closed&apos;. Then, that SourceBuffer will be cleared. 

But if we only look at MSE spec, when executing end of stream algorithn, it changes the readyState attribute value to &quot;ended&quot; not &quot;closed&quot;. It seems that we can still use the current MediaSource and SourceBuffer which called the end of stream algorithm. But it&apos;s kind of conflict with above paragraph.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115019</commentid>
    <comment_count>1</comment_count>
    <who name="Aaron Colwell">acolwell</who>
    <bug_when>2014-11-17 17:31:29 +0000</bug_when>
    <thetext>If you look at the &quot;If the media data is corrupted&quot; step in the HTML5 spec (http://www.w3.org/TR/html5/embedded-content-0.html#fatal-decode-error) you will see that there is a step that causes networkState to get set to NETWORK_EMPTY. This causes the &quot;Detaching from a media element&quot; algorithm (https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#mediasource-detach) to run. That is why there is a transition to &quot;closed&quot;.

Based on this, I don&apos;t believe there is a conflict in the MSE spec. A compliant implementation should transition readyState to &quot;ended&quot; as a result of running the end of stream algorithm, and then transition readyState to &quot;closed&quot; as a result of the detaching from a media element algorithm being run because networkState got transitioned to NETWORK_EMPTY.

I can add a note under the &quot;Run the media data is corrupt steps of the resource fetch algorithm.&quot; saying something like &quot;This step can cause the &apos;detaching from a media element algorithm&apos; to run.&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115042</commentid>
    <comment_count>2</comment_count>
    <who name="Qin Jiajia">jiajia.qin</who>
    <bug_when>2014-11-18 07:19:07 +0000</bug_when>
    <thetext>(In reply to Aaron Colwell from comment #1)
&gt; If you look at the &quot;If the media data is corrupted&quot; step in the HTML5 spec
&gt; (http://www.w3.org/TR/html5/embedded-content-0.html#fatal-decode-error) you
&gt; will see that there is a step that causes networkState to get set to
&gt; NETWORK_EMPTY. This causes the &quot;Detaching from a media element&quot; algorithm
&gt; (https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-
&gt; source.html#mediasource-detach) to run. That is why there is a transition to
&gt; &quot;closed&quot;.
You are right if media element is going to transition to NETWORK_EMPTY. But, if it changes to NETWORK_IDLE, what will happen to MediaSource? Does it still work?

&gt; Based on this, I don&apos;t believe there is a conflict in the MSE spec. A
&gt; compliant implementation should transition readyState to &quot;ended&quot; as a result
&gt; of running the end of stream algorithm, and then transition readyState to
&gt; &quot;closed&quot; as a result of the detaching from a media element algorithm being
&gt; run because networkState got transitioned to NETWORK_EMPTY.
&gt; 
&gt; I can add a note under the &quot;Run the media data is corrupt steps of the
&gt; resource fetch algorithm.&quot; saying something like &quot;This step can cause the
&gt; &apos;detaching from a media element algorithm&apos; to run.&quot;
Only transition to NETWORK_EMPTY will call &quot;Detaching from a media element&quot; or NETWORK_EMPTY and NETWORK_IDLE both can call this algorithm?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115071</commentid>
    <comment_count>3</comment_count>
    <who name="Aaron Colwell">acolwell</who>
    <bug_when>2014-11-18 19:14:56 +0000</bug_when>
    <thetext>(In reply to Qin Jiajia from comment #2)
&gt; (In reply to Aaron Colwell from comment #1)
&gt; &gt; If you look at the &quot;If the media data is corrupted&quot; step in the HTML5 spec
&gt; &gt; (http://www.w3.org/TR/html5/embedded-content-0.html#fatal-decode-error) you
&gt; &gt; will see that there is a step that causes networkState to get set to
&gt; &gt; NETWORK_EMPTY. This causes the &quot;Detaching from a media element&quot; algorithm
&gt; &gt; (https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-
&gt; &gt; source.html#mediasource-detach) to run. That is why there is a transition to
&gt; &gt; &quot;closed&quot;.
&gt; You are right if media element is going to transition to NETWORK_EMPTY. But,
&gt; if it changes to NETWORK_IDLE, what will happen to MediaSource? Does it
&gt; still work?

Ok. Now I see what you are saying. My eyes were playing tricks on me and I was actually reading step 4 of the &quot;If the media data is corrupted&quot; algorithm in the opposite sense. Based on my current understanding, the condition in the &quot;end of stream algorithm&quot; actually guarantees that networkState will always transition to NETWORK_IDLE instead of NETWORK_EMPTY so I see your point now.

I&apos;ll need to think about this a little more because I had always intended for this path to result in the MediaSource closing. If we decide to change this to allow further appending, at a minimum we&apos;ll need to call the &quot;reset parser state&quot; algorithm to recover from the corrupted data and put the parser in a known state. I&apos;ll need to look at the HTML5 spec a little closer to get a sense of what is still allowed if the &quot;resource selection algorithm&quot; is aborted. It isn&apos;t clear to me right now whether allowing appends to proceed after this makes sense or is consistent with &quot;normal non-MSE&quot; playback. 

In the non-MSE case, I believe the UA doesn&apos;t try to download any more data once the &quot;resource selection algorithm&quot; gets aborted. This seems like it would be equivalent to preventing further appends until the &quot;resource selection algorithm&quot; is initiated again. Perhaps the MediaSource shouldn&apos;t close, but instead appendBuffer/appendStream should throw an InvalidStateException if HTMLMediaElement.error is non-null? What do you think?

&gt; 
&gt; &gt; Based on this, I don&apos;t believe there is a conflict in the MSE spec. A
&gt; &gt; compliant implementation should transition readyState to &quot;ended&quot; as a result
&gt; &gt; of running the end of stream algorithm, and then transition readyState to
&gt; &gt; &quot;closed&quot; as a result of the detaching from a media element algorithm being
&gt; &gt; run because networkState got transitioned to NETWORK_EMPTY.
&gt; &gt; 
&gt; &gt; I can add a note under the &quot;Run the media data is corrupt steps of the
&gt; &gt; resource fetch algorithm.&quot; saying something like &quot;This step can cause the
&gt; &gt; &apos;detaching from a media element algorithm&apos; to run.&quot;
&gt; Only transition to NETWORK_EMPTY will call &quot;Detaching from a media element&quot;
&gt; or NETWORK_EMPTY and NETWORK_IDLE both can call this algorithm?

As specified right now only the transition to NETWORK_EMPTY. I would not be surprised if Chrome currently doesn&apos;t make this distinction and always closes the MediaSource. If this is happening, this is technically a bug in Chrome right now.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115112</commentid>
    <comment_count>4</comment_count>
    <who name="Qin Jiajia">jiajia.qin</who>
    <bug_when>2014-11-19 10:38:10 +0000</bug_when>
    <thetext>(In reply to Aaron Colwell from comment #3)
&gt; (In reply to Qin Jiajia from comment #2)
&gt; &gt; (In reply to Aaron Colwell from comment #1)
&gt; &gt; &gt; If you look at the &quot;If the media data is corrupted&quot; step in the HTML5 spec
&gt; &gt; &gt; (http://www.w3.org/TR/html5/embedded-content-0.html#fatal-decode-error) you
&gt; &gt; &gt; will see that there is a step that causes networkState to get set to
&gt; &gt; &gt; NETWORK_EMPTY. This causes the &quot;Detaching from a media element&quot; algorithm
&gt; &gt; &gt; (https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-
&gt; &gt; &gt; source.html#mediasource-detach) to run. That is why there is a transition to
&gt; &gt; &gt; &quot;closed&quot;.
&gt; &gt; You are right if media element is going to transition to NETWORK_EMPTY. But,
&gt; &gt; if it changes to NETWORK_IDLE, what will happen to MediaSource? Does it
&gt; &gt; still work?
&gt; 
&gt; Ok. Now I see what you are saying. My eyes were playing tricks on me and I
&gt; was actually reading step 4 of the &quot;If the media data is corrupted&quot;
&gt; algorithm in the opposite sense. Based on my current understanding, the
&gt; condition in the &quot;end of stream algorithm&quot; actually guarantees that
&gt; networkState will always transition to NETWORK_IDLE instead of NETWORK_EMPTY
&gt; so I see your point now.
&gt; 
&gt; I&apos;ll need to think about this a little more because I had always intended
&gt; for this path to result in the MediaSource closing. If we decide to change
&gt; this to allow further appending, at a minimum we&apos;ll need to call the &quot;reset
&gt; parser state&quot; algorithm to recover from the corrupted data and put the
&gt; parser in a known state. I&apos;ll need to look at the HTML5 spec a little closer
&gt; to get a sense of what is still allowed if the &quot;resource selection
&gt; algorithm&quot; is aborted. It isn&apos;t clear to me right now whether allowing
&gt; appends to proceed after this makes sense or is consistent with &quot;normal
&gt; non-MSE&quot; playback. 
&gt; 
&gt; In the non-MSE case, I believe the UA doesn&apos;t try to download any more data
&gt; once the &quot;resource selection algorithm&quot; gets aborted. This seems like it
&gt; would be equivalent to preventing further appends until the &quot;resource
&gt; selection algorithm&quot; is initiated again. Perhaps the MediaSource shouldn&apos;t
&gt; close, but instead appendBuffer/appendStream should throw an
&gt; InvalidStateException if HTMLMediaElement.error is non-null? What do you
&gt; think?
I think if MediaSource doesn&apos;t close, it means this MediaSource is still workable. Assume that let appendBuffer/appendStream throws an InvalidStateException when HTMLMediaElement.error is non-null. So, in what kind of situation, the SourceBuffer can apppendBuffer/appendstream again when having met the &apos;decode&apos; error? It seems there is no such kind of situation. Then, it becomes meaningless not to close MediaSource when there is &apos;decode&apos; error.

But in another side, if we meet &apos;decode&apos; error, maybe we only need to call &apos; reset parser state algorithm&apos;, wait for new data and don&apos;t need to notify HTMLMediaElement. So the media pipeline is still active. Then, the UA can use appendBuffer/appendStream for new data.

In sum, We need to figure out whether MediaSource/SourceBuffer can still use when appendBuffer/appendStream faild (via end of stream algorithm with parameter &apos;decode&apos;).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115134</commentid>
    <comment_count>5</comment_count>
    <who name="Aaron Colwell">acolwell</who>
    <bug_when>2014-11-19 17:16:51 +0000</bug_when>
    <thetext>(In reply to Qin Jiajia from comment #4)
&gt; (In reply to Aaron Colwell from comment #3)
&gt; &gt; (In reply to Qin Jiajia from comment #2)
&gt; &gt; &gt; (In reply to Aaron Colwell from comment #1)
&gt; &gt; &gt; &gt; If you look at the &quot;If the media data is corrupted&quot; step in the HTML5 spec
&gt; &gt; &gt; &gt; (http://www.w3.org/TR/html5/embedded-content-0.html#fatal-decode-error) you
&gt; &gt; &gt; &gt; will see that there is a step that causes networkState to get set to
&gt; &gt; &gt; &gt; NETWORK_EMPTY. This causes the &quot;Detaching from a media element&quot; algorithm
&gt; &gt; &gt; &gt; (https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-
&gt; &gt; &gt; &gt; source.html#mediasource-detach) to run. That is why there is a transition to
&gt; &gt; &gt; &gt; &quot;closed&quot;.
&gt; &gt; &gt; You are right if media element is going to transition to NETWORK_EMPTY. But,
&gt; &gt; &gt; if it changes to NETWORK_IDLE, what will happen to MediaSource? Does it
&gt; &gt; &gt; still work?
&gt; &gt; 
&gt; &gt; Ok. Now I see what you are saying. My eyes were playing tricks on me and I
&gt; &gt; was actually reading step 4 of the &quot;If the media data is corrupted&quot;
&gt; &gt; algorithm in the opposite sense. Based on my current understanding, the
&gt; &gt; condition in the &quot;end of stream algorithm&quot; actually guarantees that
&gt; &gt; networkState will always transition to NETWORK_IDLE instead of NETWORK_EMPTY
&gt; &gt; so I see your point now.
&gt; &gt; 
&gt; &gt; I&apos;ll need to think about this a little more because I had always intended
&gt; &gt; for this path to result in the MediaSource closing. If we decide to change
&gt; &gt; this to allow further appending, at a minimum we&apos;ll need to call the &quot;reset
&gt; &gt; parser state&quot; algorithm to recover from the corrupted data and put the
&gt; &gt; parser in a known state. I&apos;ll need to look at the HTML5 spec a little closer
&gt; &gt; to get a sense of what is still allowed if the &quot;resource selection
&gt; &gt; algorithm&quot; is aborted. It isn&apos;t clear to me right now whether allowing
&gt; &gt; appends to proceed after this makes sense or is consistent with &quot;normal
&gt; &gt; non-MSE&quot; playback. 
&gt; &gt; 
&gt; &gt; In the non-MSE case, I believe the UA doesn&apos;t try to download any more data
&gt; &gt; once the &quot;resource selection algorithm&quot; gets aborted. This seems like it
&gt; &gt; would be equivalent to preventing further appends until the &quot;resource
&gt; &gt; selection algorithm&quot; is initiated again. Perhaps the MediaSource shouldn&apos;t
&gt; &gt; close, but instead appendBuffer/appendStream should throw an
&gt; &gt; InvalidStateException if HTMLMediaElement.error is non-null? What do you
&gt; &gt; think?
&gt; I think if MediaSource doesn&apos;t close, it means this MediaSource is still
&gt; workable. Assume that let appendBuffer/appendStream throws an
&gt; InvalidStateException when HTMLMediaElement.error is non-null. So, in what
&gt; kind of situation, the SourceBuffer can apppendBuffer/appendstream again
&gt; when having met the &apos;decode&apos; error? It seems there is no such kind of
&gt; situation. Then, it becomes meaningless not to close MediaSource when there
&gt; is &apos;decode&apos; error.

I think we should make the MediaSource case consistent with what would happen in the non-MediaSource case. I believe in the non-MediaSource case playback of the buffered data and seeking is allowed to continue eventhough more data is not fetched anymore. This is why I was suggesting simply throwing an exception when error is non-null instead of closing the MediaSource. It keeps the buffered data around, but doesn&apos;t allow any more to be added.

&gt; 
&gt; But in another side, if we meet &apos;decode&apos; error, maybe we only need to call &apos;
&gt; reset parser state algorithm&apos;, wait for new data and don&apos;t need to notify
&gt; HTMLMediaElement. So the media pipeline is still active. Then, the UA can
&gt; use appendBuffer/appendStream for new data.

This feels less consistent with the non-MediaSource case to me. This is essentially equivalent to the &quot;resource fetch algorithm&quot; continuing to run even though step 1 of the &quot;If the media data is corrupted&quot; sequence explicitly says &quot;The user agent should cancel the fetching process.&quot; Since the UA isn&apos;t in direct control of fetching in the MediaSource case, it seems like preventing appends, and possibly removes, achieves a good approximation of that intent.

&gt; 
&gt; In sum, We need to figure out whether MediaSource/SourceBuffer can still use
&gt; when appendBuffer/appendStream faild (via end of stream algorithm with
&gt; parameter &apos;decode&apos;).

At this point, I believe the answer is no. Appends should not be allowed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115188</commentid>
    <comment_count>6</comment_count>
    <who name="Qin Jiajia">jiajia.qin</who>
    <bug_when>2014-11-20 07:01:59 +0000</bug_when>
    <thetext>(In reply to Aaron Colwell from comment #5)
&gt; (In reply to Qin Jiajia from comment #4)
&gt; &gt; (In reply to Aaron Colwell from comment #3)
&gt; &gt; &gt; (In reply to Qin Jiajia from comment #2)
&gt; &gt; &gt; &gt; (In reply to Aaron Colwell from comment #1)
&gt; &gt; &gt; &gt; &gt; If you look at the &quot;If the media data is corrupted&quot; step in the HTML5 spec
&gt; &gt; &gt; &gt; &gt; (http://www.w3.org/TR/html5/embedded-content-0.html#fatal-decode-error) you
&gt; &gt; &gt; &gt; &gt; will see that there is a step that causes networkState to get set to
&gt; &gt; &gt; &gt; &gt; NETWORK_EMPTY. This causes the &quot;Detaching from a media element&quot; algorithm
&gt; &gt; &gt; &gt; &gt; (https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-
&gt; &gt; &gt; &gt; &gt; source.html#mediasource-detach) to run. That is why there is a transition to
&gt; &gt; &gt; &gt; &gt; &quot;closed&quot;.
&gt; &gt; &gt; &gt; You are right if media element is going to transition to NETWORK_EMPTY. But,
&gt; &gt; &gt; &gt; if it changes to NETWORK_IDLE, what will happen to MediaSource? Does it
&gt; &gt; &gt; &gt; still work?
&gt; &gt; &gt; 
&gt; &gt; &gt; Ok. Now I see what you are saying. My eyes were playing tricks on me and I
&gt; &gt; &gt; was actually reading step 4 of the &quot;If the media data is corrupted&quot;
&gt; &gt; &gt; algorithm in the opposite sense. Based on my current understanding, the
&gt; &gt; &gt; condition in the &quot;end of stream algorithm&quot; actually guarantees that
&gt; &gt; &gt; networkState will always transition to NETWORK_IDLE instead of NETWORK_EMPTY
&gt; &gt; &gt; so I see your point now.
&gt; &gt; &gt; 
&gt; &gt; &gt; I&apos;ll need to think about this a little more because I had always intended
&gt; &gt; &gt; for this path to result in the MediaSource closing. If we decide to change
&gt; &gt; &gt; this to allow further appending, at a minimum we&apos;ll need to call the &quot;reset
&gt; &gt; &gt; parser state&quot; algorithm to recover from the corrupted data and put the
&gt; &gt; &gt; parser in a known state. I&apos;ll need to look at the HTML5 spec a little closer
&gt; &gt; &gt; to get a sense of what is still allowed if the &quot;resource selection
&gt; &gt; &gt; algorithm&quot; is aborted. It isn&apos;t clear to me right now whether allowing
&gt; &gt; &gt; appends to proceed after this makes sense or is consistent with &quot;normal
&gt; &gt; &gt; non-MSE&quot; playback. 
&gt; &gt; &gt; 
&gt; &gt; &gt; In the non-MSE case, I believe the UA doesn&apos;t try to download any more data
&gt; &gt; &gt; once the &quot;resource selection algorithm&quot; gets aborted. This seems like it
&gt; &gt; &gt; would be equivalent to preventing further appends until the &quot;resource
&gt; &gt; &gt; selection algorithm&quot; is initiated again. Perhaps the MediaSource shouldn&apos;t
&gt; &gt; &gt; close, but instead appendBuffer/appendStream should throw an
&gt; &gt; &gt; InvalidStateException if HTMLMediaElement.error is non-null? What do you
&gt; &gt; &gt; think?
&gt; &gt; I think if MediaSource doesn&apos;t close, it means this MediaSource is still
&gt; &gt; workable. Assume that let appendBuffer/appendStream throws an
&gt; &gt; InvalidStateException when HTMLMediaElement.error is non-null. So, in what
&gt; &gt; kind of situation, the SourceBuffer can apppendBuffer/appendstream again
&gt; &gt; when having met the &apos;decode&apos; error? It seems there is no such kind of
&gt; &gt; situation. Then, it becomes meaningless not to close MediaSource when there
&gt; &gt; is &apos;decode&apos; error.
&gt; 
&gt; I think we should make the MediaSource case consistent with what would
&gt; happen in the non-MediaSource case. I believe in the non-MediaSource case
&gt; playback of the buffered data and seeking is allowed to continue eventhough
&gt; more data is not fetched anymore. This is why I was suggesting simply
&gt; throwing an exception when error is non-null instead of closing the
&gt; MediaSource. It keeps the buffered data around, but doesn&apos;t allow any more
&gt; to be added.
&gt; 
Agree. Thanks for your explanation.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115821</commentid>
    <comment_count>7</comment_count>
    <who name="Aaron Colwell">acolwell</who>
    <bug_when>2014-12-03 06:39:45 +0000</bug_when>
    <thetext>Change committed...
https://github.com/w3c/media-source/commit/0c052b1ac9841aedc0c378b7eda447dbc95c5034</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>