This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 29002 - [MSE] It is possible to append media segments when no corresponding init segment has been appended
Summary: [MSE] It is possible to append media segments when no corresponding init segm...
Status: RESOLVED INVALID
Alias: None
Product: HTML WG
Classification: Unclassified
Component: Media Source Extensions (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Matt Wolenetz
QA Contact: HTML WG Bugzilla archive list
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-07-29 07:47 UTC by Jean-Yves Avenard
Modified: 2015-08-13 11:57 UTC (History)
3 users (show)

See Also:


Attachments

Description Jean-Yves Avenard 2015-07-29 07:47:10 UTC
In the segment parser loop three states are defined:

http://w3c.github.io/media-source/index.html#sourcebuffer-waiting-for-segment
WAITING_FOR_SEGMENT     Waiting for the start of an initialization segment or media segment to be appended.
PARSING_INIT_SEGMENT     Currently parsing an initialization segment.
PARSING_MEDIA_SEGMENT     Currently parsing a media segment.


Now you can't go from the WAITING_FOR_SEGMENT state to PARSING_MEDIA_SEGMENT state unless the "first initialization segment received flag" (http://w3c.github.io/media-source/index.html#first-init-segment-received-flag) is true.

Now consider the following situation.

1. sb.appendBuffer(init_segment1);
2. sb.appendBuffer(media_segment1);
3. sb.appendBuffer(invalid_init_segment2);
4. sb.appendBuffer(media_segment2);

In 1. The init segment is valid, and the first initialization segment received flag is set to true
In 2. Coded Frame Processing algorithm is run and frames are added to the trackbuffers.
In 3. will have the sourcebuffer throw an "error" event, and the mediasource state is changed to "ended" as per the "Append Error Algorithm".
The append state is reset back to WAITING_FOR_SEGMENT

Now come step 4. We move from WAITING_FOR_SEGMENT to PARSING_MEDIA_SEGMENT ; the frames are then inserted into their respective trackbuffers. Even though, no corresponding init segment has been appended ; which would result in unplayable frames stored in the trackbuffer.

Suggestion ; when an error is encountered, clear the "first initialization segment received flag" or much better specify that you must enter a new valid init segment and until then no new media segment can be appended.
This could be done by adding a new append state: WAITING_FOR_INIT_SEGMENT which is the initial append state

It would go like so:
WAITING_FOR_INIT_SEGMENT -> PARSING_INIT_SEGMENT -> WAITING_FOR_SEGMENT -> PARSING_MEDIA_SEGMENT | PARSING_INIT_SEGMENT

And should an error occur in the Initialization Segment Received algorithm (http://w3c.github.io/media-source/index.html#sourcebuffer-init-segment-received) or if the segment parser loop rejected an invalid init segment the append state would be set back to WAITING_FOR_INIT_SEGMENT
Comment 1 Matt Wolenetz 2015-08-11 14:58:20 UTC
My understanding of this scenario is that in #3, the MSE append error algorithm runs the end of stream algorithm with error set to DECODE ERROR, and since the HTMLMediaElement is already beyond HAVE_NOTHING (should be in at least HAVE_METADATA due to step #1), then the "media data is corrupted" step (http://www.w3.org/TR/html5/embedded-content-0.html#fatal-decode-error) of the HTMLMediaELement is run.

Unless I'm mistaken, this should cause subsequent attempt to append to MSE to fail, since the HTMLMediaElement error is not null:
"If the HTMLMediaElement.error attribute is not null, then throw an InvalidStateError exception and abort these steps:

This particular scenario aside, I'm resolving this bug as INVALID.
Please reactivate or file another bug if there is another scenario that unexpectedly allows reaching PARSING_MEDIA_SEGMENT for no corresponding, successfully parsed init segment.
Comment 2 Jean-Yves Avenard 2015-08-13 11:57:43 UTC
I see, step 3 in the Prepare Append Algorithm is new ; I had missed that change.