| CARVIEW |
Media Source Extensions™
More details about this document
- This version:
- https://w3c.github.io/media-source/
- Latest published version:
- https://www.w3.org/TR/media-source-2/
- Latest editor's draft:
- https://w3c.github.io/media-source/
- History:
- https://www.w3.org/standards/history/media-source-2/
- Commit history
- Latest Recommendation:
- https://www.w3.org/TR/2016/REC-media-source-20161117/
- Editors:
- Jean-Yves Avenard (Apple Inc.)
- Mark Watson (Netflix Inc.)
- Former editors:
- Matthew Wolenetz (W3C Invited Expert) - Until
- Jerry Smith (Microsoft Corporation) - Until
- Aaron Colwell (Google Inc.) - Until
- Adrian Bateman (Microsoft Corporation) - Until
- Feedback:
- GitHub w3c/media-source (pull requests, new issue, open issues)
- public-media-wg@w3.org with subject line [media-source-2] … message topic … (archives)
- Browser support:
- caniuse.com
Copyright © 2025 World Wide Web Consortium. W3C® liability, trademark and permissive document license rules apply.
Abstract
This specification extendsHTMLMediaElement [HTML] to allow JavaScript to generate
media streams for playback. Allowing JavaScript to generate streams facilitates a variety of
use cases like adaptive streaming and time shifting live streams.
Status of This Document
This section describes the status of this document at the time of its publication. A list of current W3C publications and the latest revision of this technical report can be found in the W3C standards and drafts index.
On top of editorial updates, substantive changes since publication as a W3C Recommendation in November 2016 are:
- the addition of a
changeType()method to switch among codecs or bytestreams - the possibility to create and use
MediaSourceobjects off the main thread in dedicated workers - the removal of the
createObjectURL()extension to theURLobject following its integration in the File API [FILEAPI] - the addition of
ManagedMediaSource,ManagedSourceBuffer, andBufferedChangeEventinterfaces supporting power-efficient streaming and active buffered media cleanup by the user agent
For a full list of changes made since the previous version, see the commits.
The working group maintains a list of all bug reports that the editors have not yet tried to address.
Implementors should be aware that this specification is not stable. Implementors who are not taking part in the discussions are likely to find the specification changing out from under them in incompatible ways. Vendors interested in implementing this specification before it eventually reaches the Candidate Recommendation stage should track the GitHub repository and take part in the discussions.
This document was published by the Media Working Group as an Editor's Draft.
Publication as an Editor's Draft does not imply endorsement by W3C and its Members.
This is a draft document and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to cite this document as other than a work in progress.
This document was produced by a group operating under the W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent that the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
This document is governed by the 18 August 2025 W3C Process Document.
This section is non-normative.
This specification allows JavaScript to dynamically construct media streams for
<audio> and <video>. It defines a MediaSource object that can serve as a source
of media data for an HTMLMediaElement. MediaSource objects have one or more
SourceBuffer objects. Applications append data segments to the SourceBuffer
objects, and can adapt the quality of appended data based on system performance and other
factors. Data from the SourceBuffer objects is managed as track buffers for audio,
video and text data that is decoded and played. Byte stream specifications used with these
extensions are available in the byte stream format registry [MSE-REGISTRY].
This specification was designed with the following goals in mind:
- Allow JavaScript to construct media streams independent of how the media is fetched.
- Define a splicing and buffering model that facilitates use cases like adaptive streaming, ad-insertion, time-shifting, and video editing.
- Minimize the need for media parsing in JavaScript.
- Leverage the browser cache as much as possible.
- Provide requirements for byte stream format specifications.
- Not require support for any particular media format or codec.
This specification defines:
- Normative behavior for user agents to enable interoperability between user agents and web applications when processing media data.
- Normative requirements to enable other specifications to define media formats to be used within this specification.
- Active Track Buffers
-
The track buffers that provide coded frames for the
enabledaudioTracks, theselectedvideoTracks, and the"showing"or"hidden"textTracks. All these tracks are associated withSourceBufferobjects in theactiveSourceBufferslist. - Append Window
-
A presentation timestamp range used to filter out coded frames while appending. The append window represents a single continuous time range with a single start time and end time. Coded frames with presentation timestamp within this range are allowed to be appended to the
SourceBufferwhile coded frames outside this range are filtered out. The append window start and end times are controlled by theappendWindowStartandappendWindowEndattributes respectively. - Coded Frame
-
A unit of media data that has a presentation timestamp, a decode timestamp, and a coded frame duration.
- Coded Frame Duration
-
The duration of a coded frame. For video and text, the duration indicates how long the video frame or text SHOULD be displayed. For audio, the duration represents the sum of all the samples contained within the coded frame. For example, if an audio frame contained 441 samples @44100Hz the frame duration would be 10 milliseconds.
- Coded Frame End Timestamp
-
The sum of a coded frame presentation timestamp and its coded frame duration. It represents the presentation timestamp that immediately follows the coded frame.
- Coded Frame Group
-
A group of coded frames that are adjacent and have monotonically increasing decode timestamps without any gaps. Discontinuities detected by the coded frame processing algorithm and
abort()calls trigger the start of a new coded frame group. - Decode Timestamp
-
The decode timestamp indicates the latest time at which the frame needs to be decoded assuming instantaneous decoding and rendering of this and any dependant frames (this is equal to the presentation timestamp of the earliest frame, in presentation order, that is dependant on this frame). If frames can be decoded out of presentation order, then the decode timestamp MUST be present in or derivable from the byte stream. The user agent MUST run the append error algorithm if this is not the case. If frames cannot be decoded out of presentation order and a decode timestamp is not present in the byte stream, then the decode timestamp is equal to the presentation timestamp.
- Initialization Segment
-
A sequence of bytes that contain all of the initialization information required to decode a sequence of media segments. This includes codec initialization data, Track ID mappings for multiplexed segments, and timestamp offsets (e.g., edit lists).
NoteThe byte stream format specifications in the byte stream format registry [MSE-REGISTRY] contain format specific examples.
- Media Segment
-
A sequence of bytes that contain packetized & timestamped media data for a portion of the media timeline. Media segments are always associated with the most recently appended initialization segment.
NoteThe byte stream format specifications in the byte stream format registry [MSE-REGISTRY] contain format specific examples.
- MediaSource object URL
-
A
MediaSourceobject URL is a unique blob URL created bycreateObjectURL(). It is used to attach aMediaSourceobject to an HTMLMediaElement.These URLs are the same as a blob URLs, except that anything in the definition of that feature that refers to
FileandBlobobjects is hereby extended to also apply toMediaSourceobjects.The origin of the MediaSource object URL is the relevant settings object of this during the call to
createObjectURL().NoteFor example, the origin of the MediaSource object URL affects the way that the media element is consumed by canvas.
- Parent Media Source
-
The parent media source of a
SourceBufferobject is theMediaSourceobject that created it. - Presentation Start Time
-
The presentation start time is the earliest time point in the presentation and specifies the initial playback position and earliest possible position. All presentations created using this specification have a presentation start time of 0.
NoteFor the purposes of determining if
HTMLMediaElement'sbufferedcontains aTimeRangesthat includes the current playback position, implementations MAY choose to allow a current playback position at or after presentation start time and before the firstTimeRangesto play the firstTimeRangesif thatTimeRangesstarts within a reasonably short time, like 1 second, after presentation start time. This allowance accommodates the reality that muxed streams commonly do not begin all tracks precisely at presentation start time. Implementations MUST report the actual buffered range, regardless of this allowance. - Presentation Interval
-
The presentation interval of a coded frame is the time interval from its presentation timestamp to the presentation timestamp plus the coded frame's duration. For example, if a coded frame has a presentation timestamp of 10 seconds and a coded frame duration of 100 milliseconds, then the presentation interval would be [10-10.1). Note that the start of the range is inclusive, but the end of the range is exclusive.
- Presentation Order
-
The order that coded frames are rendered in the presentation. The presentation order is achieved by ordering coded frames in monotonically increasing order by their presentation timestamps.
- Presentation Timestamp
-
A reference to a specific time in the presentation. The presentation timestamp in a coded frame indicates when the frame SHOULD be rendered.
- Random Access Point
-
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.
- SourceBuffer byte stream format specification
-
The specific byte stream format specification that describes the format of the byte stream accepted by a
SourceBufferinstance. The byte stream format specification, for aSourceBufferobject, is initially selected based on the type passed to theaddSourceBuffer()call that created the object, and can be updated bychangeType()calls on the object. -
SourceBufferconfiguration -
A specific set of tracks distributed across one or more
SourceBufferobjects owned by a singleMediaSourceinstance.Implementations MUST support at least 1
MediaSourceobject with the following configurations:- A single SourceBuffer with 1 audio track and/or 1 video track.
- Two SourceBuffers with one handling a single audio track and the other handling a single video track.
MediaSource objects MUST support each of the configurations above, but they are only required to support one configuration at a time. Supporting multiple configurations at once or additional configurations is a quality of implementation issue.
- Track Description
-
A byte stream format specific structure that provides the Track ID, codec configuration, and other metadata for a single track. Each track description inside a single initialization segment has a unique Track ID. The user agent MUST run the append error algorithm if the Track ID is not unique within the initialization segment.
- Track ID
-
A Track ID is a byte stream format specific identifier that marks sections of the byte stream as being part of a specific track. The Track ID in a track description identifies which sections of a media segment belong to that track.
The MediaSource interface 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.
Each MediaSource object has a [[live seekable
range]] internal slot that stores a normalized TimeRanges object. It
is initialized to an empty TimeRanges object when the MediaSource object is
created, is maintained by setLiveSeekableRange() and
clearLiveSeekableRange(), and is used in 10.
HTMLMediaElement Extensions
to modify HTMLMediaElement's seekable behavior.
Each MediaSource object has a [[has ever been
attached]] internal slot that stores a boolean. It is initialized to false when
the MediaSource object is created, and is set true in the extended
HTMLMediaElement's resource fetch algorithm as described in the attaching to a media element algorithm. The extended resource fetch algorithm uses this internal
slot to conditionally fail attachment of a MediaSource using a MediaSourceHandle
set on a HTMLMediaElement's srcObject attribute.
WebIDLenum ReadyState {
"closed",
"open",
"ended",
};
-
closed - Indicates the source is not currently attached to a media element.
-
open -
The source has been opened by a media element and is ready for data to be appended to the
SourceBufferobjects inMediaSource'ssourceBuffers. -
ended -
The source is still attached to a media element, but
MediaSource'sendOfStream()has been called.
WebIDLenum EndOfStreamError {
"network",
"decode",
};
-
network -
Terminates playback and signals that a network error has occurred.
NoteJavaScript applications SHOULD use this status code to terminate playback with a network error. For example, if a network error occurs while fetching media data.
-
decode -
Terminates playback and signals that a decoding error has occurred.
NoteJavaScript applications SHOULD use this status code to terminate playback with a decode error. For example, if a parsing error occurs while processing out-of-band media data.
WebIDL[Exposed=(Window,DedicatedWorker)]
interface MediaSource : EventTarget {
constructor();
[SameObject, Exposed=DedicatedWorker]
readonly attribute MediaSourceHandle handle;
readonly attribute SourceBufferList sourceBuffers;
readonly attribute SourceBufferList activeSourceBuffers;
readonly attribute ReadyState readyState;
attribute unrestricted double duration;
attribute EventHandler onsourceopen;
attribute EventHandler onsourceended;
attribute EventHandler onsourceclose;
static readonly attribute boolean canConstructInDedicatedWorker;
SourceBuffer addSourceBuffer(DOMString type);
undefined removeSourceBuffer(SourceBuffer sourceBuffer);
undefined endOfStream(optional EndOfStreamError error);
undefined setLiveSeekableRange(double start, double end);
undefined clearLiveSeekableRange();
static boolean isTypeSupported(DOMString type);
};
Contains a handle useful for attachment of a dedicated worker MediaSource object to an
HTMLMediaElement via srcObject. The handle remains the same object
for this MediaSource object across accesses of this attribute, but it is distinct for
each MediaSource object.
This specification may eventually enable visibility of this attribute on MediaSource
objects on the main Window context. If so, specification care will be necessary to prevent
potential backwards incompatible changes, such as could happen if exceptions were thrown on
accesses to this attribute.
On getting, run the following steps:
- If the handle for this
MediaSourceobject has not yet been created, then run the following steps:- Let created handle be the result of creating a new
MediaSourceHandleobject and associated resources, linked internally to thisMediaSource. - Update the attribute to be created handle.
- Let created handle be the result of creating a new
- Return the
MediaSourceHandleobject that is this attribute's value.
Contains the list of SourceBuffer objects associated with this MediaSource. When
MediaSource's readyState equals "closed" this list
will be empty. Once readyState transitions to "open"
SourceBuffer objects can be added to this list by using addSourceBuffer().
Contains the subset of sourceBuffers that are providing the
selected video track, the enabled audio track(s), and the
"showing" or "hidden" text
track(s).
SourceBuffer objects in this list MUST appear in the same order as they appear in the
sourceBuffers attribute; e.g., if only sourceBuffers[0] and
sourceBuffers[3] are in activeSourceBuffers, then activeSourceBuffers[0]
MUST equal sourceBuffers[0] and activeSourceBuffers[1] MUST equal sourceBuffers[3].
Section 3.15.5 Changes to selected/enabled track state describes how this attribute gets updated.
Indicates the current state of the MediaSource object. When the MediaSource
is created readyState MUST be set to "closed".
Allows the web application to set the presentation duration. The duration is initially set
to NaN when the MediaSource object is created.
On getting, run the following steps:
- If the
readyStateattribute is "closed" then return NaN and abort these steps. - Return the current value of the attribute.
On setting, run the following steps:
- If the value being set is negative or NaN then throw a
TypeErrorexception and abort these steps. - If the
readyStateattribute is not "open" then throw anInvalidStateErrorexception and abort these steps. - If the
updatingattribute equals true on anySourceBufferinsourceBuffers, then throw anInvalidStateErrorexception and abort these steps. - Run the duration change algorithm with new duration set to
the value being assigned to this attribute.
Note
The duration change algorithm will adjust new duration higher if there is any currently buffered coded frame with a higher end time.
NoteappendBuffer()andendOfStream()can update the duration under certain circumstances.
Returns true.
This attribute enables main thread and dedicated worker feature detection of support for
creating and using a MediaSource object in a dedicated worker, and mitigates the need
for higher latency detection polyfills like attempting creation of a MediaSource object
from a dedicated worker, especially if the feature is not supported.
Adds a new SourceBuffer to sourceBuffers.
- If type is an empty string then throw a
TypeErrorexception and abort these steps. - If type contains a MIME type that is not supported or contains a MIME type that is
not supported with the types specified for the other
SourceBufferobjects insourceBuffers, then throw aNotSupportedErrorexception and abort these steps. - If the user agent can't handle any more SourceBuffer objects or if creating a
SourceBuffer based on type would result in an unsupported SourceBuffer configuration,
then throw a
QuotaExceededErrorexception and abort these steps.NoteFor example, a user agent MAY throw a
QuotaExceededErrorexception if the media element has reached theHAVE_METADATAreadyState. This can occur if the user agent's media engine does not support adding more tracks during playback. - If the
readyStateattribute is not in the "open" state then throw anInvalidStateErrorexception and abort these steps. - Let buffer be a new instance of a
ManagedSourceBufferif this is aManagedMediaSource, or aSourceBufferotherwise, with their respective associated resources. - Set buffer's
[[generate timestamps flag]]to the value in the "Generate Timestamps Flag" column of the Media Source Extensions™ Byte Stream Format Registry entry that is associated with type. - If buffer's
[[generate timestamps flag]]is true, set buffer'smodeto "sequence". Otherwise, set buffer'smodeto "segments". - Append buffer to this's
sourceBuffers. - Queue a task to fire an event named
addsourcebufferat this'ssourceBuffers. - Return buffer.
Removes a SourceBuffer from sourceBuffers.
- If sourceBuffer specifies an object that is not in
sourceBuffersthen throw aNotFoundErrorexception and abort these steps. - If the sourceBuffer.
updatingattribute equals true, then run the following steps:- Abort the buffer append algorithm if it is running.
- Set the sourceBuffer.
updatingattribute to false. - Queue a task to fire an event named
abortat sourceBuffer. - Queue a task to fire an event named
updateendat sourceBuffer.
- Let SourceBuffer audioTracks list equal the
AudioTrackListobject returned by sourceBuffer.audioTracks. - If the SourceBuffer audioTracks list is not empty, then run the following steps:
- For each
AudioTrackobject in the SourceBuffer audioTracks list, run the following steps:- Set the
sourceBufferattribute on theAudioTrackobject to null. - Remove the
AudioTrackobject from the SourceBuffer audioTracks list.NoteThis should trigger
AudioTrackList[HTML] logic to queue a task to fire an event named removetrack usingTrackEventwith thetrackattribute initialized to theAudioTrackobject, at the SourceBuffer audioTracks list. If theenabledattribute on theAudioTrackobject was true at the beginning of this removal step, then this should also triggerAudioTrackList[HTML] logic to queue a task to fire an event named change at the SourceBuffer audioTracks list. - Use the mirror if necessary algorithm to run the following steps in
Window, to remove theAudioTrackobject (or instead, theWindowmirror of it if theMediaSourceobject was constructed in aDedicatedWorkerGlobalScope) from the media element:- Let HTMLMediaElement audioTracks list equal the
AudioTrackListobject returned by theaudioTracksattribute on the HTMLMediaElement. - Remove the
AudioTrackobject from the HTMLMediaElement audioTracks list.NoteThis should trigger
AudioTrackList[HTML] logic to queue a task to fire an event named removetrack usingTrackEventwith thetrackattribute initialized to theAudioTrackobject, at the HTMLMediaElement audioTracks list. If theenabledattribute on theAudioTrackobject was true at the beginning of this removal step, then this should also triggerAudioTrackList[HTML] logic to queue a task to fire an event named change at the HTMLMediaElement audioTracks list.
- Let HTMLMediaElement audioTracks list equal the
- Set the
- For each
- Let SourceBuffer videoTracks list equal the
VideoTrackListobject returned by sourceBuffer.videoTracks. - If the SourceBuffer videoTracks list is not empty, then run the following steps:
- For each
VideoTrackobject in the SourceBuffer videoTracks list, run the following steps:- Set the
sourceBufferattribute on theVideoTrackobject to null. - Remove the
VideoTrackobject from the SourceBuffer videoTracks list.NoteThis should trigger
VideoTrackList[HTML] logic to queue a task to fire an event named removetrack usingTrackEventwith thetrackattribute initialized to theVideoTrackobject, at the SourceBuffer videoTracks list. If theselectedattribute on theVideoTrackobject was true at the beginning of this removal step, then this should also triggerVideoTrackList[HTML] logic to queue a task to fire an event named change at the SourceBuffer videoTracks list. - Use the mirror if necessary algorithm to run the following steps in
Window, to remove theVideoTrackobject (or instead, theWindowmirror of it if theMediaSourceobject was constructed in aDedicatedWorkerGlobalScope) from the media element:- Let HTMLMediaElement videoTracks list equal the
VideoTrackListobject returned by thevideoTracksattribute on the HTMLMediaElement. - Remove the
VideoTrackobject from the HTMLMediaElement videoTracks list.NoteThis should trigger
VideoTrackList[HTML] logic to queue a task to fire an event named removetrack usingTrackEventwith thetrackattribute initialized to theVideoTrackobject, at the HTMLMediaElement videoTracks list. If theselectedattribute on theVideoTrackobject was true at the beginning of this removal step, then this should also triggerVideoTrackList[HTML] logic to queue a task to fire an event named change at the HTMLMediaElement videoTracks list.
- Let HTMLMediaElement videoTracks list equal the
- Set the
- For each
- Let SourceBuffer textTracks list equal the
TextTrackListobject returned by sourceBuffer.textTracks. - If the SourceBuffer textTracks list is not empty, then run the following steps:
- For each
TextTrackobject in the SourceBuffer textTracks list, run the following steps:- Set the
sourceBufferattribute on theTextTrackobject to null. - Remove the
TextTrackobject from the SourceBuffer textTracks list.NoteThis should trigger
TextTrackList[HTML] logic to queue a task to fire an event named removetrack usingTrackEventwith thetrackattribute initialized to theTextTrackobject, at the SourceBuffer textTracks list. If themodeattribute on theTextTrackobject was"showing"or"hidden"at the beginning of this removal step, then this should also triggerTextTrackList[HTML] logic to queue a task to fire an event named change at the SourceBuffer textTracks list. - Use the mirror if necessary algorithm to run the following steps in
Window, to remove theTextTrackobject (or instead, theWindowmirror of it if theMediaSourceobject was constructed in aDedicatedWorkerGlobalScope) from the media element:- Let HTMLMediaElement textTracks list equal the
TextTrackListobject returned by thetextTracksattribute on the HTMLMediaElement. - Remove the
TextTrackobject from the HTMLMediaElement textTracks list.NoteThis should trigger
TextTrackList[HTML] logic to queue a task to fire an event named removetrack usingTrackEventwith thetrackattribute initialized to theTextTrackobject, at the HTMLMediaElement textTracks list. If themodeattribute on theTextTrackobject was"showing"or"hidden"at the beginning of this removal step, then this should also triggerTextTrackList[HTML] logic to queue a task to fire an event named change at the HTMLMediaElement textTracks list.
- Let HTMLMediaElement textTracks list equal the
- Set the
- For each
- If sourceBuffer is in
activeSourceBuffers, then remove sourceBuffer fromactiveSourceBuffersand queue a task to fire an event namedremovesourcebufferat theSourceBufferListreturned byactiveSourceBuffers. - Remove sourceBuffer from
sourceBuffersand queue a task to fire an event namedremovesourcebufferat theSourceBufferListreturned bysourceBuffers. - Destroy all resources for sourceBuffer.
Signals the end of the stream.
- If the
readyStateattribute is not in the "open" state then throw anInvalidStateErrorexception and abort these steps. - If the
updatingattribute equals true on anySourceBufferinsourceBuffers, then throw anInvalidStateErrorexception and abort these steps. - Run the end of stream algorithm with the error parameter set to error.
Updates [[live seekable range]] that is used in section
10.
HTMLMediaElement Extensions to modify HTMLMediaElement's
seekable behavior.
When this method is invoked, the user agent must run the following steps:
- If the
readyStateattribute is not "open" then throw anInvalidStateErrorexception and abort these steps. - If start is negative or greater than end, then throw a
TypeErrorexception and abort these steps. - Set
[[live seekable range]]to be a new normalized TimeRanges object containing a single range whose start position is start and end position is end.
Updates [[live seekable range]] that is used in section
10.
HTMLMediaElement Extensions to modify HTMLMediaElement's
seekable behavior.
When this method is invoked, the user agent must run the following steps:
- If the
readyStateattribute is not "open" then throw anInvalidStateErrorexception and abort these steps. - If
[[live seekable range]]contains a range, then set[[live seekable range]]to be a new emptyTimeRangesobject.
Check to see whether the MediaSource is capable of creating SourceBuffer
objects for the specified MIME type.
If true is returned from this method, it only indicates that the MediaSource
implementation is capable of creating SourceBuffer objects for the specified MIME type.
An addSourceBuffer() call SHOULD still fail if sufficient resources are not
available to support the addition of a new SourceBuffer.
This method returning true implies that HTMLMediaElement's
canPlayType() will return "maybe" or "probably" since it does not make
sense for a MediaSource to support a type the HTMLMediaElement knows it cannot play.
When this method is invoked, the user agent must run the following steps:
- If type is an empty string, then return false.
- If type does not contain a valid MIME type string, then return false.
- If type contains a media type or media subtype that the MediaSource does not support, then return false.
- If type contains a codec that the MediaSource does not support, then return false.
- If the MediaSource does not support the specified combination of media type, media subtype, and codecs then return false.
- Return true.
| Event name | Interface | Dispatched when... |
|---|---|---|
| sourceopen |
Event
|
MediaSource's readyState transitions from "closed"
to "open" or from "ended" to "open".
|
| sourceended |
Event
|
MediaSource's readyState transitions from "open"
to "ended".
|
| sourceclose |
Event
|
MediaSource's readyState transitions from "open"
to "closed" or "ended" to "closed".
|
When a Window HTMLMediaElement is attached to a DedicatedWorkerGlobalScope
MediaSource, each context has algorithms that depend on information from the other.
HTMLMediaElement is exposed only to Window contexts, but MediaSource and
related objects defined in this specification are exposed in Window and
DedicatedWorkerGlobalScope contexts. This lets applications construct a
MediaSource object in either of those types of context and attach it to an
HTMLMediaElement object in a Window context using a MediaSource object URL or
a MediaSourceHandle as described in the attaching to a media element algorithm. A
MediaSource object is not Transferable; it is only visible in the context where
it was created.
The rest of this section describes a model for bounding information latency for
attachments of a Window media element to a DedicatedWorkerGlobalScope
MediaSource. While the model describes communication using message passing,
implementations MAY choose to communicate in potentially faster ways, such as using
shared memory and locks. Attachments to a Window MediaSource synchronously have
the information already without communicating it across contexts.
A MediaSource that is constructed in a DedicatedWorkerGlobalScope has a
[[port to main]] internal slot that stores a
MessagePort setup during attachment and nulled during detachment. A Window
[[port to main]] is always null.
An HTMLMediaElement extended by this specification and attached to a
DedicatedWorkerGlobalScope MediaSource similarly has a [[port to worker]] internal slot that stores a MessagePort
and a [[channel with worker]] internal slot
that stores a MessageChannel, both setup during attachment and nulled during
detachment. Both [[port to worker]] and [[channel with worker]] are null unless attached to a DedicatedWorkerGlobalScope
MediaSource.
Algorithms in this specification that need to communicate information from a Window
HTMLMediaElement to an attached DedicatedWorkerGlobalScope MediaSource, or
vice versa, will use these internal ports implicitly to post a message to their
counterpart, where the implicit handler of the message runs steps as described in the
algorithms.
There are distinct mechanisms for attaching a MediaSource to a media element
depending on where the MediaSource object was constructed, in a Window versus
in a DedicatedWorkerGlobalScope:
-
Attaching a
MediaSourcethat was constructed in aWindowcan be done by assigning a MediaSource object URL for thatMediaSourceto the media elementsrcattribute or the src attribute of a <source> inside a media element. A MediaSource object URL is created by passing a MediaSource object tocreateObjectURL().Though implementations MAY allow MediaSource object URL creation in a
DedicatedWorkerGlobalScopefor aMediaSourceconstructed in that worker, attempting to use that MediaSource object URL to attach to a media element using either thesrcattribute or the src attribute of a <source> inside a media element MUST fail in the media element's resource fetch algorithm, as extended below.NoteExtending the object URL attachment mechanism to worker MediaSource object URLs would further propagate this idiom that is less preferred versus using srcObject, and would unnecessarily increase user agent interoperability risk and implementation complexity.
- Attaching a
MediaSourcethat was constructed in aDedicatedWorkerGlobalScopecan only be done by obtaining a handle from it usinghandle, transferring thatMediaSourceHandleto theWindowcontext and assigning it to the media elementsrcObjectattribute. For the purposes of aligning this specification withHTMLMediaElementresource loading and fetching algorithms, the underlyingDedicatedWorkerGlobalScopeMediaSourceis the MediaSource object mentioned there, and theMediaSourceHandleobject is the media provider object.
If the resource fetch algorithm was invoked with a media provider object that is a
MediaSource object, a MediaSourceHandle object or a URL record whose object is
a MediaSource object, then let mode be local, skip the first step in the resource fetch algorithm (which may otherwise set mode to remote) and continue the execution
of the resource fetch algorithm.
The first step of the resource fetch algorithm is expected to eventually align with
selecting local mode for URL records whose objects are media provider objects. The
intent is that if the HTMLMediaElement's src attribute or
selected child source's src attribute is a blob: URL matching a
MediaSource object URL when the respective src attribute was last changed, then
that MediaSource object is used as the media provider object and current media
resource in the local mode logic in the resource fetch algorithm. This also means
that the remote mode logic that includes observance of any preload attribute is skipped
when a MediaSource object is attached. Even with that eventual change to [HTML], the
execution of the following steps at the beginning of the local mode logic is still
required when the current media resource is a MediaSource object.
At the beginning of the "Otherwise (mode is local)" section of the resource fetch algorithm, execute the additional steps, below.
Relative to the action which triggered the media element's resource selection algorithm, these steps are asynchronous. The resource fetch algorithm is run after the task that invoked the resource selection algorithm is allowed to continue and a stable state is reached. Implementations may delay the steps in the "Otherwise" clause, below, until the MediaSource object is ready for use.
- If the resource fetch algorithm was invoked with a media provider object that
is a
MediaSourceobject, aMediaSourceHandleobject or a URL record whose object is aMediaSourceobject, then:-
If the media provider object is a URL record whose object is a
MediaSourcethat was constructed in aDedicatedWorkerGlobalScope, such as would occur if attempting to use a MediaSource object URL from aDedicatedWorkerGlobalScopeMediaSource -
Run the "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" steps of the resource fetch algorithm's media data processing steps list.
NoteThis prevents using MediaSource object URLs for DedicatedWorker MediaSource attachments. Transferring
MediaSource'shandlefrom the DedicatedWorker to the Window context and assigning it to the media element'ssrcObjectattribute is the only way to attach such a MediaSource. -
If the media provider object is a
MediaSourceHandlewhose[[Detached]]internal slot is true - Run the "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" steps of the resource fetch algorithm's media data processing steps list.
-
If the media provider object is a
MediaSourceHandlewhose underlyingMediaSource's[[has ever been attached]]internal slot is true -
Run the "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" steps of the resource fetch algorithm's media data processing steps list.
NoteThis prevents loading an underlying
MediaSourcemore than once using aMediaSourceHandle, even if theMediaSourcewas constructed onWindowand had been loaded previously using a MediaSource object URL. This doesn't preclude subsequent use of a MediaSource object URL for aWindowMediaSourcefrom succeeding though. -
If
readyStateis NOT set to "closed" - Run the "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" steps of the resource fetch algorithm's media data processing steps list.
- Otherwise
-
- Set the
MediaSource's[[has ever been attached]]internal slot to true. - Set the media element's delaying-the-load-event-flag to false.
-
-
If the
MediaSourcewas constructed in aDedicatedWorkerGlobalScope, then setup worker attachment communication and open theMediaSource: -
- Set
[[channel with worker]]to be a newMessageChannel. - Set
[[port to worker]]to theport1value of[[channel with worker]]. - Execute StructuredSerializeWithTransfer with the
port2of[[channel with worker]]as both the value and the sole member of the transferList, and let the result be serialized port2. - Queue a task on the
MediaSource'sDedicatedWorkerGlobalScopethat will- Execute StructuredDeserializeWithTransfer with serialized
port2 and
DedicatedWorkerGlobalScope's realm, and set[[port to main]]to be the resulting deserialized clone of the transferredport2value of[[channel with worker]]. - Set the
readyStateattribute to "open". - Queue a task to fire an event named
sourceopenat theMediaSource.
- Execute StructuredDeserializeWithTransfer with serialized
port2 and
- Set
-
Otherwise, the
MediaSourcewas constructed in aWindow: -
- Set
[[channel with worker]]null. - Set
[[port to worker]]null. - Set
[[port to main]]null. - Set the
readyStateattribute to "open". - Queue a task to fire an event named
sourceopenat theMediaSource.
- Set
-
If the
- Continue the resource fetch algorithm by running the remaining
"Otherwise (mode is local)" steps, with these requirements:
- Text in the resource fetch algorithm or the media data processing steps list that refers to "the download",
"bytes received", or "whenever new data for the current media resource
becomes available" refers to data passed in via
appendBuffer(). - References to HTTP in the resource fetch algorithm and the
media data processing steps list shall not apply because
the HTMLMediaElement does not fetch media data via HTTP when a
MediaSourceis attached.
- Text in the resource fetch algorithm or the media data processing steps list that refers to "the download",
"bytes received", or "whenever new data for the current media resource
becomes available" refers to data passed in via
- Set the
-
If the media provider object is a URL record whose object is a
An attached MediaSource does not use the remote mode steps in the resource fetch algorithm, so the media element will not fire "suspend" events. Though future versions of this specification will likely remove "progress" and "stalled" events from a media element with an attached MediaSource, user agents conforming to this version of the specification may still fire these two events as these [HTML] references changed after implementations of this specification stabilized.
The following steps are run in any case where the media element is going to transition
to NETWORK_EMPTY and queue a task to fire an event named
emptied at the media element. These steps SHOULD be run right
before the transition.
-
-
If the
MediaSourcewas constructed in aDedicatedWorkerGlobalScope: -
- Notify the
MediaSourceusing an internaldetachmessage posted to[[port to worker]]. - Set
[[port to worker]]null. - Set
[[channel with worker]]null. - The implicit message handler for this
detachnotification runs the remainder of these steps in theDedicatedWorkerGlobalScopeMediaSource.
- Notify the
-
Otherwise, the
MediaSourcewas constructed in aWindow: -
Continue the remainder of these steps on the
WindowMediaSource.
-
If the
- Set
[[port to main]]null. - Set the
readyStateattribute to "closed". - If this is a
ManagedMediaSource, then setstreamingattribute tofalse. - Update
durationto NaN. - Remove all the
SourceBufferobjects fromactiveSourceBuffers. - Queue a task to fire an event named
removesourcebufferatactiveSourceBuffers. - Remove all the
SourceBufferobjects fromsourceBuffers. - Queue a task to fire an event named
removesourcebufferatsourceBuffers. - Queue a task to fire an event named
sourcecloseat theMediaSource.
Going forward, this algorithm is intended to be externally called and run in any case
where the attached MediaSource, if any, must be detached from the media element. It
MAY be called on HTMLMediaElement [HTML] operations like load() and resource fetch algorithm failures in addition to, or in place of, when the media element transitions
to NETWORK_EMPTY. Resource fetch algorithm failures are those
which abort either the resource fetch algorithm or the resource selection algorithm,
with the exception that the "Final step" [HTML] is not considered a failure that
triggers detachment.
Run the following steps as part of the "Wait until the user agent has established whether or not the media data for the new playback position is available, and, if it is, until it has decoded enough data to play back that position" step of the seek algorithm:
-
Note
The media element looks for media segments containing the new playback position in each
SourceBufferobject inactiveSourceBuffers. Any position within aTimeRangesin the current value of theHTMLMediaElement'sbufferedattribute has all necessary media segments buffered for that position.-
If new playback position is not in any
TimeRangesofHTMLMediaElement'sbuffered -
- If the
HTMLMediaElement'sreadyStateattribute is greater thanHAVE_METADATA, then set theHTMLMediaElement'sreadyStateattribute toHAVE_METADATA.NotePer
HTMLMediaElement ready states[HTML] logic,HTMLMediaElement'sreadyStatechanges may trigger events on the HTMLMediaElement. - The media element waits until an
appendBuffer()call causes the coded frame processing algorithm to set theHTMLMediaElement'sreadyStateattribute to a value greater thanHAVE_METADATA.NoteThe web application can use
bufferedandHTMLMediaElement'sbufferedto determine what the media element needs to resume playback.
- If the
- Otherwise
-
Continue
Note
If the
readyStateattribute is "ended" and the new playback position is within aTimeRangescurrently inHTMLMediaElement'sbuffered, then the seek operation must continue to completion here even if one or more currently selected or enabled track buffers' largest range end timestamp is less than new playback position. This condition should only occur due to logic inbufferedwhenreadyStateis "ended".
-
If new playback position is not in any
- The media element resets all decoders and initializes each one with data from the appropriate initialization segment.
- The media element feeds coded frames from the active track buffers into the decoders starting with the closest random access point before the new playback position.
- Resume the seek algorithm at the "Await a stable state" step.
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. Changes to activeSourceBuffers also
cause these steps to run because they affect the conditions that trigger state
transitions.
Having enough data to ensure uninterrupted playback is an
implementation specific condition where the user agent determines that it currently has
enough data to play the presentation without stalling for a meaningful period of time.
This condition is constantly evaluated to determine when to transition the media
element into and out of the HAVE_ENOUGH_DATA ready state. These
transitions indicate when the user agent believes it has enough data buffered or it
needs more data respectively.
An implementation MAY choose to use bytes buffered, time buffered, the append rate, or
any other metric it sees fit to determine when it has enough data. The metrics used MAY
change during playback so web applications SHOULD only rely on the value of
HTMLMediaElement's readyState to determine whether more data
is needed or not.
When the media element needs more data, the user agent SHOULD transition it from
HAVE_ENOUGH_DATA to HAVE_FUTURE_DATA early
enough for a web application to be able to respond without causing an interruption in
playback. For example, transitioning when the current playback position is 500ms before
the end of the buffered data gives the application roughly 500ms to append more data
before playback stalls.
-
If the
HTMLMediaElement'sreadyStateattribute equalsHAVE_NOTHING: -
- Abort these steps.
-
If
HTMLMediaElement'sbuffereddoes not contain aTimeRangesfor the current playback position: -
- Set the
HTMLMediaElement'sreadyStateattribute toHAVE_METADATA.NotePer
HTMLMediaElement ready states[HTML] logic,HTMLMediaElement'sreadyStatechanges may trigger events on the HTMLMediaElement. - Abort these steps.
- Set the
-
If
HTMLMediaElement'sbufferedcontains aTimeRangesthat includes the current playback position and enough data to ensure uninterrupted playback: -
- Set the
HTMLMediaElement'sreadyStateattribute toHAVE_ENOUGH_DATA.NotePer
HTMLMediaElement ready states[HTML] logic,HTMLMediaElement'sreadyStatechanges may trigger events on the HTMLMediaElement. - Playback may resume at this point if it was previously suspended by a
transition to
HAVE_CURRENT_DATA. - Abort these steps.
- Set the
-
If
HTMLMediaElement'sbufferedcontains aTimeRangesthat includes the current playback position and some time beyond the current playback position, then run the following steps: -
- Set the
HTMLMediaElement'sreadyStateattribute toHAVE_FUTURE_DATA.NotePer
HTMLMediaElement ready states[HTML] logic,HTMLMediaElement'sreadyStatechanges may trigger events on the HTMLMediaElement. - Playback may resume at this point if it was previously suspended by a
transition to
HAVE_CURRENT_DATA. - Abort these steps.
- Set the
-
If
HTMLMediaElement'sbufferedcontains aTimeRangesthat ends at the current playback position and does not have a range covering the time immediately after the current position: -
- Set the
HTMLMediaElement'sreadyStateattribute toHAVE_CURRENT_DATA.NotePer
HTMLMediaElement ready states[HTML] logic,HTMLMediaElement'sreadyStatechanges may trigger events on the HTMLMediaElement. - Playback is suspended at this point since the media element doesn't have enough data to advance the media timeline.
- Abort these steps.
- Set the
During playback activeSourceBuffers needs to be updated if the
selected video track, the enabled audio track(s), or a
text track mode changes. When one or more of these changes occur the
following steps need to be followed. Also, when MediaSource was constructed in a
DedicatedWorkerGlobalScope, then each change that occurs to a Window mirror of
a track created previously by the implicit handler for the internal create track
mirror message MUST also be made to the corresponding DedicatedWorkerGlobalScope
track using an internal update track state message posted to
[[port to worker]] whose implicit handler makes the change and
runs the following steps. Likewise, each change that occurs to a
DedicatedWorkerGlobalScope track MUST also be made to the corresponding Window
mirror of the track using an internal update track state message posted to
[[port to main]] whose implicit handler makes the change to the mirror.
- If the selected video track changes, then run the following steps:
-
- If the
SourceBufferassociated with the previously selected video track is not associated with any other enabled tracks, run the following steps:- Remove the
SourceBufferfromactiveSourceBuffers. - Queue a task to fire an event named
removesourcebufferatactiveSourceBuffers
- Remove the
- If the
SourceBufferassociated with the newly selected video track is not already inactiveSourceBuffers, run the following steps:- Add the
SourceBuffertoactiveSourceBuffers. - Queue a task to fire an event named
addsourcebufferatactiveSourceBuffers
- Add the
- If the
-
If an audio track becomes disabled and the
SourceBufferassociated with this track is not associated with any other enabled or selected track, then run the following steps: -
- Remove the
SourceBufferassociated with the audio track fromactiveSourceBuffers - Queue a task to fire an event named
removesourcebufferatactiveSourceBuffers
- Remove the
-
If an audio track becomes enabled and the
SourceBufferassociated with this track is not already inactiveSourceBuffers, then run the following steps: -
- Add the
SourceBufferassociated with the audio track toactiveSourceBuffers - Queue a task to fire an event named
addsourcebufferatactiveSourceBuffers
- Add the
-
If a text track
modebecomes"disabled"and theSourceBufferassociated with this track is not associated with any other enabled or selected track, then run the following steps: -
- Remove the
SourceBufferassociated with the text track fromactiveSourceBuffers - Queue a task to fire an event named
removesourcebufferatactiveSourceBuffers
- Remove the
-
If a text track
modebecomes"showing"or"hidden"and theSourceBufferassociated with this track is not already inactiveSourceBuffers, then run the following steps: -
- Add the
SourceBufferassociated with the text track toactiveSourceBuffers - Queue a task to fire an event named
addsourcebufferatactiveSourceBuffers
- Add the
Follow these steps when duration needs to change to a new
duration.
- If the current value of
durationis equal to new duration, then return. - If new duration is less than the highest presentation timestamp of any
buffered coded frames for all
SourceBufferobjects insourceBuffers, then throw anInvalidStateErrorexception and abort these steps. - Let highest end time be the largest track buffer ranges
end time across all the track buffers across all
SourceBufferobjects insourceBuffers. - If new duration is less than highest end time, then
Note
This condition can occur because the coded frame removal algorithm preserves coded frames that start before the start of the removal range.
- Update new duration to equal highest end time.
- Update
durationto new duration. - Use the mirror if necessary algorithm to run the following steps in
Windowto update the media element's duration:- Update the media element's
durationto new duration. - Run the HTMLMediaElement duration change algorithm.
- Update the media element's
This algorithm gets called when the application signals the end of stream via an
endOfStream() call or an algorithm needs to signal a decode error. This
algorithm takes an error parameter that indicates whether an error
will be signalled.
- Change the
readyStateattribute value to "ended". - Queue a task to fire an event named
sourceendedat theMediaSource. -
- If error is not set
-
- Run the duration change algorithm with new duration set to the largest track buffer ranges end time across all the
track buffers across all
SourceBufferobjects insourceBuffers.NoteThis allows the duration to properly reflect the end of the appended media segments. For example, if the duration was explicitly set to 10 seconds and only media segments for 0 to 5 seconds were appended before endOfStream() was called, then the duration will get updated to 5 seconds.
- Notify the media element that it now has all of the media data.
- Run the duration change algorithm with new duration set to the largest track buffer ranges end time across all the
track buffers across all
-
If error is set to "
network" -
Use the mirror if necessary algorithm to run the following steps in
Window:-
If the
HTMLMediaElement'sreadyStateattribute equalsHAVE_NOTHING - Run the "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" steps of the resource fetch algorithm's media data processing steps list.
-
If the
HTMLMediaElement'sreadyStateattribute is greater thanHAVE_NOTHING - Run the "If the connection is interrupted after some media data has been received, causing the user agent to give up trying to fetch the resource" steps of the resource fetch algorithm's media data processing steps list.
-
If the
-
If error is set to "
decode" -
Use the mirror if necessary algorithm to run the following steps in
Window:-
If the
HTMLMediaElement'sreadyStateattribute equalsHAVE_NOTHING - Run the "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" steps of the resource fetch algorithm's media data processing steps list.
-
If the
HTMLMediaElement'sreadyStateattribute is greater thanHAVE_NOTHING - Run the media data is corrupted steps of the resource fetch algorithm's media data processing steps list.
-
If the
This algorithm is used to run steps on Window from a MediaSource attached from
either the same Window or from a DedicatedWorkerGlobalScope, usually to update
the state of the attached HTMLMediaElement. This algorithm takes a steps
parameter that lists the steps to run on Window.
-
If the
MediaSourcewas constructed in aDedicatedWorkerGlobalScope: -
Post an internal
mirror on windowmessage to[[port to main]]whose implicit handler inWindowwill run steps. Return control to the caller without awaiting that handler's receipt of the message.NoteThe purpose of the mirror message mechanism is to ensure that:- steps run asynchronously as their own task on
Windowrather than these steps somehow happening in the middle of some otherWindowtask's execution, and - steps are run without blocking the synchronous execution and return of this
algorithm on
DedicatedWorkerGlobalScope.
- steps run asynchronously as their own task on
- Otherwise:
- Run steps.
The MediaSourceHandle interface represents a proxy for a MediaSource object that is
useful for attaching a DedicatedWorkerGlobalScope MediaSource to a Window
HTMLMediaElement using srcObject as described in the attaching to a media element algorithm.
This distinct object is necessary to attach a cross-context MediaSource to a media
element because MediaSource objects themselves are not transferable since they are
event targets.
Each MediaSourceHandle object has a [[has ever
been assigned as srcobject]] internal slot that stores a boolean. It is
initialized to false when the MediaSourceHandle object is created, is set true in the
extended HTMLMediaElement's srcObject setter as described in
section 10.
HTMLMediaElement Extensions, and if true, prevents successful transfer of
the MediaSourceHandle as described in section 4.1
Transfer.
MediaSourceHandle objects are Transferable, each having a [[Detached]] internal slot that is used to ensure that once the
handle object instance has been transferred, that instance cannot be transferred again.
WebIDL[Transferable, Exposed=(Window,DedicatedWorker)]
interface MediaSourceHandle {};
The MediaSourceHandle transfer steps and transfer-receiving steps require the
implementation to maintain an implicit internal slot referencing the underlying
MediaSource to enable attaching to a media element using
srcObject and consequent setup of an attachment's cross-context communication model.
Implementors should be aware that assumption of "move" semantics implied by
Transferable is not always reality. For example, extensions or internal
implementations of postMessage using broadcast may cause unintended multiple recipients
of a transferred MediaSourceHandle. For this reason, implementations are guided to
not resolve which potential clone of a transferred MediaSourceHandle is still valid
for attachment until and unless any handle for the underlying MediaSource object is
used in the asynchronous portion of the media element's resource selection algorithm.
This is similar to the existing behavior for attachment via MediaSource object URLs,
which can be cloned easily, where such a URL is valid for at most one attachment start
(across all of its potentially many clones).
Implementations MUST support at most one attachment (load) via
srcObject ever for the MediaSource object underlying a
MediaSourceHandle, regardless of potential cloning of the MediaSourceHandle due
to varying implementations of Transferable.
See attaching to a media element for how this is enforced during the asynchronous portion of the media element's resource selection algorithm.
MediaSourceHandle is only exposed on Window and DedicatedWorkerGlobalScope
contexts, and cannot successfully transfer between different agent clusters [ECMASCRIPT]. Transfer of a MediaSourceHandle object can only succeed
within the same agent cluster.
For example, transfer of a MediaSourceHandle object from either a Window or
DedicatedWorkerGlobalScope to either a SharedWorker or a ServiceWorker will not
succeed. Developers should be aware of this difference versus MediaSource object URLs
which are DOMStrings that can be communicated many ways. Even so, attaching to a media element using a MediaSource object URL can only succeed for a MediaSource
that was constructed in a Window context. See also the integration of the
agent and agent cluster formalisms for Web Application APIs
[HTML] where related concepts such as dedicated worker agents are defined.
Transfer steps for a MediaSourceHandle object MUST include the following step:
- If the
MediaSourceHandle's[[has ever been assigned as srcobject]]internal slot is true, then the transfer steps must fail by throwing aDataCloneErrorexception.
WebIDLenum AppendMode {
"segments",
"sequence",
};
-
segments - The timestamps in the media segment determine where the coded frames are placed in the presentation. Media segments can be appended in any order.
-
sequence -
Media segments will be treated as adjacent in time independent of the timestamps in the
media segment. Coded frames in a new media segment will be placed immediately after the
coded frames in the previous media segment. The
timestampOffsetattribute will be updated if a new offset is needed to make the new media segments adjacent to the previous media segment. Setting thetimestampOffsetattribute in "sequence" mode allows a media segment to be placed at a specific position in the timeline without any knowledge of the timestamps in the media segment.
WebIDL[Exposed=(Window,DedicatedWorker)]
interface SourceBuffer : EventTarget {
attribute AppendMode mode;
readonly attribute boolean updating;
readonly attribute TimeRanges buffered;
attribute double timestampOffset;
readonly attribute AudioTrackList audioTracks;
readonly attribute VideoTrackList videoTracks;
readonly attribute TextTrackList textTracks;
attribute double appendWindowStart;
attribute unrestricted double appendWindowEnd;
attribute EventHandler onupdatestart;
attribute EventHandler onupdate;
attribute EventHandler onupdateend;
attribute EventHandler onerror;
attribute EventHandler onabort;
undefined appendBuffer(BufferSource data);
undefined abort();
undefined changeType(DOMString type);
undefined remove(double start, unrestricted double end);
};
-
modeof typeAppendMode -
Controls how a sequence of media segments are handled. This attribute is initially set by
addSourceBuffer()after the object is created, and can be updated bychangeType()or setting this attribute.On getting, Return the initial value or the last value that was successfully set.
On setting, run the following steps:
- If this object has been removed from the
sourceBuffersattribute of the parent media source, then throw anInvalidStateErrorexception and abort these steps. - If the
updatingattribute equals true, then throw anInvalidStateErrorexception and abort these steps. - Let new mode equal the new value being assigned to this attribute.
- If
[[generate timestamps flag]]equals true and new mode equals "segments", then throw aTypeErrorexception and abort these steps. -
If the
readyStateattribute of the parent media source is in the "ended" state then run the following steps:- Set the
readyStateattribute of the parent media source to "open" - Queue a task to fire an event named
sourceopenat the parent media source.
- Set the
- If the
[[append state]]equals PARSING_MEDIA_SEGMENT, then throw anInvalidStateErrorand abort these steps. - If the new mode equals "
sequence", then set the[[group start timestamp]]to the[[group end timestamp]]. - Update the attribute to new mode.
- If this object has been removed from the
-
updatingof typeboolean, readonly -
Indicates whether the asynchronous continuation of an
appendBuffer()orremove()operation is still being processed. This attribute is initially set to false when the object is created. -
bufferedof typeTimeRanges, readonly -
Indicates what
TimeRangesare buffered in theSourceBuffer. This attribute is initially set to an emptyTimeRangesobject when the object is created.When the attribute is read the following steps MUST occur:
- If this object has been removed from the
sourceBuffersattribute of the parent media source then throw anInvalidStateErrorexception and abort these steps. - Let highest end time be the largest track buffer ranges end time
across all the track buffers managed by this
SourceBufferobject. - Let intersection ranges equal a
TimeRangesobject containing a single range from 0 to highest end time. - For each audio and video track buffer managed by this
SourceBuffer, run the following steps:NoteText track buffers are included in the calculation of highest end time, above, but excluded from the buffered range calculation here. They are not necessarily continuous, nor should any discontinuity within them trigger playback stall when the other media tracks are continuous over the same time range.
- Let track ranges equal the track buffer ranges for the current track buffer.
- If
readyStateis "ended", then set the end time on the last range in track ranges to highest end time. - Let new intersection ranges equal the intersection between the intersection ranges and the track ranges.
- Replace the ranges in intersection ranges with the new intersection ranges.
- If intersection ranges does not contain the exact same range information as the current value of this attribute, then update the current value of this attribute to intersection ranges.
- Return the current value of this attribute.
- If this object has been removed from the
-
timestampOffsetof typedouble -
Controls the offset applied to timestamps inside subsequent media segments that are appended to this
SourceBuffer. ThetimestampOffsetis initially set to 0 which indicates that no offset is being applied.On getting, Return the initial value or the last value that was successfully set.
On setting, run the following steps:
- Let new timestamp offset equal the new value being assigned to this attribute.
- If this object has been removed from the
sourceBuffersattribute of the parent media source, then throw anInvalidStateErrorexception and abort these steps. - If the
updatingattribute equals true, then throw anInvalidStateErrorexception and abort these steps. -
If the
readyStateattribute of the parent media source is in the "ended" state then run the following steps:- Set the
readyStateattribute of the parent media source to "open" - Queue a task to fire an event named
sourceopenat the parent media source.
- Set the
- If the
[[append state]]equals PARSING_MEDIA_SEGMENT, then throw anInvalidStateErrorand abort these steps. - If the
modeattribute equals "sequence", then set the[[group start timestamp]]to new timestamp offset. - Update the attribute to new timestamp offset.
-
audioTracksof typeAudioTrackList, readonly -
The list of
AudioTrackobjects created by this object. -
videoTracksof typeVideoTrackList, readonly -
The list of
VideoTrackobjects created by this object. -
textTracksof typeTextTrackList, readonly -
The list of
TextTrackobjects created by this object. -
appendWindowStartof typedouble -
The presentation timestamp for the start of the append window. This attribute is initially set to the presentation start time.
On getting, Return the initial value or the last value that was successfully set.
On setting, run the following steps:
- If this object has been removed from the
sourceBuffersattribute of the parent media source, then throw anInvalidStateErrorexception and abort these steps. - If the
updatingattribute equals true, then throw anInvalidStateErrorexception and abort these steps. - If the new value is less than 0 or greater than or equal to
appendWindowEndthen throw aTypeErrorexception and abort these steps. - Update the attribute to the new value.
- If this object has been removed from the
-
appendWindowEndof typeunrestricted double -
The presentation timestamp for the end of the append window. This attribute is initially set to positive Infinity.
On getting, Return the initial value or the last value that was successfully set.
On setting, run the following steps:
- If this object has been removed from the
sourceBuffersattribute of the parent media source, then throw anInvalidStateErrorexception and abort these steps. - If the
updatingattribute equals true, then throw anInvalidStateErrorexception and abort these steps. - If the new value equals NaN, then throw a
TypeErrorand abort these steps. - If the new value is less than or equal to
appendWindowStartthen throw aTypeErrorexception and abort these steps. - Update the attribute to the new value.
- If this object has been removed from the
-
onupdatestartof typeEventHandler -
The event handler for the
updatestartevent. -
onupdateof typeEventHandler -
The event handler for the
updateevent. -
onupdateendof typeEventHandler -
The event handler for the
updateendevent. -
onerrorof typeEventHandler -
The event handler for the
errorevent. -
onabortof typeEventHandler -
The event handler for the
abortevent.
-
appendBuffer -
Appends the segment data in an
BufferSource[WEBIDL] to theSourceBuffer.When this method is invoked, the user agent must run the following steps:
- Run the prepare append algorithm.
- Add data to the end of the
[[input buffer]]. - Set the
updatingattribute to true. - Queue a task to fire an event named
updatestartat thisSourceBufferobject. - Asynchronously run the buffer append algorithm.
-
abort -
Aborts the current segment and resets the segment parser.
When this method is invoked, the user agent must run the following steps:
- If this object has been removed from the
sourceBuffersattribute of the parent media source then throw anInvalidStateErrorexception and abort these steps. - If the
readyStateattribute of the parent media source is not in the "open" state then throw anInvalidStateErrorexception and abort these steps. - If the range removal algorithm is running, then throw an
InvalidStateErrorexception and abort these steps. - If the
updatingattribute equals true, then run the following steps:- Abort the buffer append algorithm if it is running.
- Set the
updatingattribute to false. - Queue a task to fire an event named
abortat thisSourceBufferobject. - Queue a task to fire an event named
updateendat thisSourceBufferobject.
- Run the reset parser state algorithm.
- Set
appendWindowStartto the presentation start time. - Set
appendWindowEndto positive Infinity.
- If this object has been removed from the
-
changeType -
Changes the MIME type associated with this object. Subsequent
appendBuffer()calls will expect the newly appended bytes to conform to the new type.When this method is invoked, the user agent must run the following steps:
- If type is an empty string then throw a
TypeErrorexception and abort these steps. - If this object has been removed from the
sourceBuffersattribute of the parent media source, then throw anInvalidStateErrorexception and abort these steps. - If the
updatingattribute equals true, then throw anInvalidStateErrorexception and abort these steps. - If type contains a MIME type that is not supported or contains a MIME type that
is not supported with the types specified (currently or previously) of
SourceBufferobjects in thesourceBuffersattribute of the parent media source, then throw aNotSupportedErrorexception and abort these steps. -
If the
readyStateattribute of the parent media source is in the "ended" state then run the following steps:- Set the
readyStateattribute of the parent media source to "open". - Queue a task to fire an event named
sourceopenat the parent media source.
- Set the
- Run the reset parser state algorithm.
- Update the
[[generate timestamps flag]]on thisSourceBufferobject to the value in the "Generate Timestamps Flag" column of the byte stream format registry [MSE-REGISTRY] entry that is associated with type. -
-
If the
[[generate timestamps flag]]equals true: -
Set the
modeattribute on thisSourceBufferobject to "sequence", including running the associated steps for that attribute being set. - Otherwise:
-
Keep the previous value of the
modeattribute on thisSourceBufferobject, without running any associated steps for that attribute being set.
-
If the
- Set the
[[pending initialization segment for changeType flag]]on thisSourceBufferobject to true.
- If type is an empty string then throw a
-
remove -
Removes media for a specific time range. The start of the removal range, in seconds measured from presentation start time The end of the removal range, in seconds measured from presentation start time.
When this method is invoked, the user agent must run the following steps:
- If this object has been removed from the
sourceBuffersattribute of the parent media source then throw anInvalidStateErrorexception and abort these steps. - If the
updatingattribute equals true, then throw anInvalidStateErrorexception and abort these steps. - If
durationequals NaN, then throw aTypeErrorexception and abort these steps. - If start is negative or greater than
duration, then throw aTypeErrorexception and abort these steps. - If end is less than or equal to start or end equals
NaN, then throw a
TypeErrorexception and abort these steps. -
If the
readyStateattribute of the parent media source is in the "ended" state then run the following steps:- Set the
readyStateattribute of the parent media source to "open" - Queue a task to fire an event named
sourceopenat the parent media source.
- Set the
- Run the range removal algorithm with start and end as the start and end of the removal range.
- If this object has been removed from the
A track buffer stores the track descriptions and coded frames for an individual track. The track buffer is updated as initialization segments and media segments are appended to the SourceBuffer.
Each track buffer has a last decode timestamp variable that stores the decode timestamp of the last coded frame appended in the current coded frame group. The variable is initially unset to indicate that no coded frames have been appended yet.
Each track buffer has a last frame duration variable that stores the coded frame duration of the last coded frame appended in the current coded frame group. The variable is initially unset to indicate that no coded frames have been appended yet.
Each track buffer has a highest end timestamp variable that stores the highest coded frame end timestamp across all coded frames in the current coded frame group that were appended to this track buffer. The variable is initially unset to indicate that no coded frames have been appended yet.
Each track buffer has a need random access point flag variable that keeps track of whether the track buffer is waiting for a random access point coded frame. The variable is initially set to true to indicate that random access point coded frame is needed before anything can be added to the track buffer.
Each track buffer has a track buffer ranges variable that represents the presentation time ranges occupied by the coded frames currently stored in the track buffer.
For track buffer ranges, these presentation time ranges are based on presentation timestamps, frame durations, and potentially coded frame group start times for coded
frame groups across track buffers in a muxed SourceBuffer.
For specification purposes, this information is treated as if it were stored in a
normalized TimeRanges object. Intersected track buffer ranges are
used to report HTMLMediaElement's buffered, and MUST therefore
support uninterrupted playback within each range of HTMLMediaElement's
buffered.
These coded frame group start times differ slightly from those mentioned in the coded frame processing algorithm in that they are the earliest presentation timestamp
across all track buffers following a discontinuity. Discontinuities can occur within the
coded frame processing algorithm or result from the coded frame removal
algorithm, regardless of mode. The threshold for determining
disjointness of track buffer ranges is implementation-specific. For example, to
reduce unexpected playback stalls, implementations MAY approximate the coded frame processing algorithm's discontinuity detection logic by coalescing adjacent ranges
separated by a gap smaller than 2 times the maximum frame duration buffered so far in
this track buffer. Implementations MAY also use coded frame group start times as
range start times across track buffers in a muxed SourceBuffer to further reduce
unexpected playback stalls.
| Event name | Interface | Dispatched when... |
|---|---|---|
| updatestart |
Event
|
SourceBuffer's updating transitions from false to true.
|
| update |
Event
|
A SourceBuffer's append or remove successfully completed. SourceBuffer's
updating transitions from true to false.
|
| updateend |
Event
|
The append or remove of a SourceBuffer ended.
|
| error |
Event
|
An error occurred during the append to a SourceBuffer. updating
transitions from true to false.
|
| abort |
Event
|
The SourceBuffer's append was aborted by an abort() call.
updating transitions from true to false.
|
Each SourceBuffer object has an [[append
state]] internal slot that keeps track of the high-level segment parsing state.
It is initially set to WAITING_FOR_SEGMENT and can transition to the following
states as data is appended.
| Append state name | Description |
|---|---|
| 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. |
Each SourceBuffer object has an [[input
buffer]] internal slot that is a byte buffer that holds unparsed bytes across
appendBuffer() calls. The buffer is empty when the SourceBuffer
object is created.
Each SourceBuffer object has a [[buffer full
flag]] internal slot that keeps track of whether appendBuffer()
is allowed to accept more bytes. It is set to false when the SourceBuffer object is
created and gets updated as data is appended and removed.
Each SourceBuffer object has a [[group start
timestamp]] internal slot that keeps track of the starting timestamp for a new
coded frame group in the "sequence" mode. It is unset when the
SourceBuffer object is created and gets updated when the mode
attribute equals "sequence" and the timestampOffset
attribute is set, or the coded frame processing algorithm runs.
Each SourceBuffer object has a [[group end
timestamp]] internal slot that stores the highest coded frame end timestamp
across all coded frames in the current coded frame group. It is set to 0 when
the SourceBuffer object is created and gets updated by the coded frame processing
algorithm.
The [[group end timestamp]] stores the highest coded frame end timestamp across all track buffers in a SourceBuffer. Therefore, care should
be taken in setting the mode attribute when appending multiplexed
segments in which the timestamps are not aligned across tracks.
Each SourceBuffer object has a [[generate timestamps flag]] internal slot that is a boolean that keeps track
of whether timestamps need to be generated for the coded frames passed to the
coded frame processing algorithm. This flag is set by
addSourceBuffer() when the SourceBuffer object is created and is
updated by changeType().
When the segment parser loop algorithm is invoked, run the following steps:
-
Loop Top: If the
[[input buffer]]is empty, then jump to the need more data step below. - If the
[[input buffer]]contains bytes that violate the SourceBuffer byte stream format specification, then run the append error algorithm and abort this algorithm. - Remove any bytes that the byte stream format specifications say MUST be ignored
from the start of the
[[input buffer]]. -
If the
[[append state]]equals WAITING_FOR_SEGMENT, then run the following steps:- If the beginning of the
[[input buffer]]indicates the start of an initialization segment, set the[[append state]]to PARSING_INIT_SEGMENT. - If the beginning of the
[[input buffer]]indicates the start of a media segment, set[[append state]]to PARSING_MEDIA_SEGMENT. - Jump to the loop top step above.
- If the beginning of the
-
If the
[[append state]]equals PARSING_INIT_SEGMENT, then run the following steps:- If the
[[input buffer]]does not contain a complete initialization segment yet, then jump to the need more data step below. - Run the initialization segment received algorithm.
- Remove the initialization segment bytes from the beginning of the
[[input buffer]]. - Set
[[append state]]to WAITING_FOR_SEGMENT. - Jump to the loop top step above.
- If the
-
If the
[[append state]]equals PARSING_MEDIA_SEGMENT, then run the following steps:- If the
[[first initialization segment received flag]]is false or the[[pending initialization segment for changeType flag]]is true, then run the append error algorithm and abort this algorithm. - If the
[[input buffer]]contains one or more complete coded frames, then run the coded frame processing algorithm.NoteThe frequency at which the coded frame processing algorithm is run is implementation-specific. The coded frame processing algorithm MAY be called when the input buffer contains the complete media segment or it MAY be called multiple times as complete coded frames are added to the input buffer.
- If this
SourceBufferis full and cannot accept more media data, then set the[[buffer full flag]]to true. - If the
[[input buffer]]does not contain a complete media segment, then jump to the need more data step below. - Remove the media segment bytes from the beginning of the
[[input buffer]]. - Set
[[append state]]to WAITING_FOR_SEGMENT. - Jump to the loop top step above.
- If the
- Need more data: Return control to the calling algorithm.
When the parser state needs to be reset, run the following steps:
- If the
[[append state]]equals PARSING_MEDIA_SEGMENT and the[[input buffer]]contains some complete coded frames, then run the coded frame processing algorithm until all of these complete coded frames have been processed. - Unset the last decode timestamp on all track buffers.
- Unset the last frame duration on all track buffers.
- Unset the highest end timestamp on all track buffers.
- Set the need random access point flag on all track buffers to true.
- If the
modeattribute equals "sequence", then set the[[group start timestamp]]to the[[group end timestamp]] - Remove all bytes from the
[[input buffer]]. - Set
[[append state]]to WAITING_FOR_SEGMENT.
This algorithm is called when an error occurs during an append.
- Run the reset parser state algorithm.
- Set the
updatingattribute to false. - Queue a task to fire an event named
errorat thisSourceBufferobject. - Queue a task to fire an event named
updateendat thisSourceBufferobject. - Run the end of stream algorithm with the error parameter set
to "
decode".
When an append operation begins, the following steps are run to validate and prepare
the SourceBuffer.
- If the
SourceBufferhas been removed from thesourceBuffersattribute of the parent media source then throw anInvalidStateErrorexception and abort these steps. - If the
updatingattribute equals true, then throw anInvalidStateErrorexception and abort these steps. - Let recent element error be determined as follows:
-
If the
MediaSourcewas constructed in aWindow -
Let recent element error be true if the
HTMLMediaElement'serrorattribute is not null. If that attribute is null, then let recent element error be false. - Otherwise
-
Let recent element error be the value resulting from the steps for the
Windowcase, but run on theWindowHTMLMediaElementon any change to itserrorattribute and communicated by using[[port to worker]]implicit messages. If such a message has not yet been received, then let recent element error be false.
-
If the
- If recent element error is true, then throw an
InvalidStateErrorexception and abort these steps. -
If the
readyStateattribute of the parent media source is in the "ended" state then run the following steps:- Set the
readyStateattribute of the parent media source to "open" - Queue a task to fire an event named
sourceopenat the parent media source.
- Set the
- Run the coded frame eviction algorithm.
-
If the
[[buffer full flag]]equals true, then throw aQuotaExceededErrorexception and abort these steps.NoteThis is the signal that the implementation was unable to evict enough data to accommodate the append or the append is too big. The web application SHOULD use
remove()to explicitly free up space and/or reduce the size of the append.
When appendBuffer() is called, the following steps are run to process
the appended data.
- Run the segment parser loop algorithm.
- If the segment parser loop algorithm in the previous step was aborted, then abort this algorithm.
- Set the
updatingattribute to false. - Queue a task to fire an event named
updateat thisSourceBufferobject. - Queue a task to fire an event named
updateendat thisSourceBufferobject.
Follow these steps when a caller needs to initiate a JavaScript visible range removal operation that blocks other SourceBuffer updates:
- Let start equal the starting presentation timestamp for the removal range, in seconds measured from presentation start time.
- Let end equal the end presentation timestamp for the removal range, in seconds measured from presentation start time.
- Set the
updatingattribute to true. - Queue a task to fire an event named
updatestartat thisSourceBufferobject. - Return control to the caller and run the rest of the steps asynchronously.
- Run the coded frame removal algorithm with start and end as the start and end of the removal range.
- Set the
updatingattribute to false. - Queue a task to fire an event named
updateat thisSourceBufferobject. - Queue a task to fire an event named
updateendat thisSourceBufferobject.
The following steps are run when the segment parser loop successfully parses a complete initialization segment:
Each SourceBuffer object has a [[first initialization segment received flag]] internal slot that tracks whether the first initialization segment has been appended and received by this algorithm. This flag is set to false when the SourceBuffer is created and updated by the algorithm below.
Each SourceBuffer object has a [[pending
initialization segment for changeType flag]] internal slot that tracks whether an
initialization segment is needed since the most recent
changeType(). This flag is set to false when the SourceBuffer is
created, set to true by changeType() and reset to false by the
algorithm below.
- Update the
durationattribute if it currently equals NaN:- If the initialization segment contains a duration:
- Run the duration change algorithm with new duration set to the duration in the initialization segment.
- Otherwise:
- Run the duration change algorithm with new duration set to positive Infinity.
- If the initialization segment has no audio, video, or text tracks, then run the append error algorithm and abort these steps.
- If the
[[first initialization segment received flag]]is true, then run the following steps:- Verify the following properties. If any of the checks fail then run the
append error algorithm and abort these steps.
- The number of audio, video, and text tracks match what was in the first initialization segment.
- If more than one track for a single type are present (e.g., 2 audio tracks), then the Track IDs match the ones in the first initialization segment.
- The codecs for each track are supported by the user agent.
Note
User agents MAY consider codecs, that would otherwise be supported, as "not supported" here if the codecs were not specified in type parameter passed to (a) the most recently successful
changeType()on thisSourceBufferobject, or (b) if no successfulchangeType()has yet occurred on this object, theaddSourceBuffer()that created thisSourceBufferobject. For example, if the most recently successfulchangeType()was called with'video/webm'or'video/webm; codecs="vp8"', and a video track containing vp9 appears in the initialization segment, then the user agent MAY use this step to trigger a decode error even if the other two properties' checks, above, pass. Implementations are encouraged to trigger error in such cases only when the codec is indeed not supported or the other two properties' checks fail. Web authors are encouraged to usechangeType(),addSourceBuffer()andisTypeSupported()with precise codec parameters to more proactively detect user agent support.changeType()is required if theSourceBufferobject's bytestream format is changing.
- Add the appropriate track descriptions from this initialization segment to each of the track buffers.
- Set the need random access point flag on all track buffers to true.
- Verify the following properties. If any of the checks fail then run the
append error algorithm and abort these steps.
- Let active track flag equal false.
-
If the
[[first initialization segment received flag]]is false, then run the following steps:- If the initialization segment contains tracks with codecs the user agent
does not support, then run the append error algorithm and abort these steps.
Note
User agents MAY consider codecs, that would otherwise be supported, as "not supported" here if the codecs were not specified in type parameter passed to (a) the most recently successful
changeType()on thisSourceBufferobject, or (b) if no successfulchangeType()has yet occurred on this object, theaddSourceBuffer()that created thisSourceBufferobject. For example,MediaSource.isTypeSupported('video/webm;codecs="vp8,vorbis"')may return true, but ifaddSourceBuffer()was called with'video/webm;codecs="vp8"'and a Vorbis track appears in the initialization segment, then the user agent MAY use this step to trigger a decode error. Implementations are encouraged to trigger error in such cases only when the codec is indeed not supported. Web authors are encouraged to usechangeType(),addSourceBuffer()andisTypeSupported()with precise codec parameters to more proactively detect user agent support.changeType()is required if theSourceBufferobject's bytestream format is changing. -
For each audio track in the initialization segment, run following steps:
- Let audio byte stream track ID be the Track ID for the current track being processed.
- Let audio language be a BCP 47 language tag for the language specified in the initialization segment for this track or an empty string if no language info is present.
- If audio language equals the 'und' BCP 47 value, then assign an empty string to audio language.
- Let audio label be a label specified in the initialization segment for this track or an empty string if no label info is present.
- Let audio kinds be a sequence of kind strings specified in the initialization segment for this track or a sequence with a single empty string element in it if no kind information is provided.
- For each value in audio kinds, run the following steps:
- Let current audio kind equal the value from audio kinds for this iteration of the loop.
- Let new audio track be a new
AudioTrackobject. - Generate a unique ID and assign it to the
idproperty on new audio track. - Assign audio language to the
languageproperty on new audio track. - Assign audio label to the
labelproperty on new audio track. - Assign current audio kind to the
kindproperty on new audio track. -
If this
SourceBufferobject'saudioTracks'slengthequals 0, then run the following steps:- Set the
enabledproperty on new audio track to true. - Set active track flag to true.
- Set the
- Add new audio track to the
audioTracksattribute on thisSourceBufferobject.NoteThis should trigger
AudioTrackList[HTML] logic to queue a task to fire an event named addtrack usingTrackEventwith thetrackattribute initialized to new audio track, at theAudioTrackListobject referenced by theaudioTracksattribute on thisSourceBufferobject. -
-
If the parent media source was constructed in a
DedicatedWorkerGlobalScope: -
Post an internal
create track mirrormessage to[[port to main]]whose implicit handler inWindowruns the following steps:- Let mirrored audio track be a new
AudioTrackobject. - Assign the same property values to mirrored audio track as were determined for new audio track.
- Add mirrored audio track to the
audioTracksattribute on the HTMLMediaElement.
- Let mirrored audio track be a new
- Otherwise:
-
Add new audio track to the
audioTracksattribute on the HTMLMediaElement.
NoteThis should trigger
AudioTrackList[HTML] logic to queue a task to fire an event named addtrack usingTrackEventwith thetrackattribute initialized to mirrored audio track or new audio track, at theAudioTrackListobject referenced by theaudioTracksattribute on the HTMLMediaElement. -
If the parent media source was constructed in a
- Create a new track buffer to store coded frames for this track.
- Add the track description for this track to the track buffer.
-
For each video track in the initialization segment, run following steps:
- Let video byte stream track ID be the Track ID for the current track being processed.
- Let video language be a BCP 47 language tag for the language specified in the initialization segment for this track or an empty string if no language info is present.
- If video language equals the 'und' BCP 47 value, then assign an empty string to video language.
- Let video label be a label specified in the initialization segment for this track or an empty string if no label info is present.
- Let video kinds be a sequence of kind strings specified in the initialization segment for this track or a sequence with a single empty string element in it if no kind information is provided.
- For each value in video kinds, run the following steps:
- Let current video kind equal the value from video kinds for this iteration of the loop.
- Let new video track be a new
VideoTrackobject. - Generate a unique ID and assign it to the
idproperty on new video track. - Assign video language to the
languageproperty on new video track. - Assign video label to the
labelproperty on new video track. - Assign current video kind to the
kindproperty on new video track. -
If this
SourceBufferobject'svideoTracks'slengthequals 0, then run the following steps:- Set the
selectedproperty on new video track to true. - Set active track flag to true.
- Set the
- Add new video track to the
videoTracksattribute on thisSourceBufferobject.NoteThis should trigger
VideoTrackList[HTML] logic to queue a task to fire an event named addtrack usingTrackEventwith thetrackattribute initialized to new video track, at theVideoTrackListobject referenced by thevideoTracksattribute on thisSourceBufferobject. -
-
If the parent media source was constructed in a
DedicatedWorkerGlobalScope: -
Post an internal
create track mirrormessage to[[port to main]]whose implicit handler inWindowruns the following steps:- Let mirrored video track be a new
VideoTrackobject. - Assign the same property values to mirrored video track as were determined for new video track.
- Add mirrored video track to the
videoTracksattribute on the HTMLMediaElement.
- Let mirrored video track be a new
- Otherwise:
-
Add new video track to the
videoTracksattribute on the HTMLMediaElement.
NoteThis should trigger
VideoTrackList[HTML] logic to queue a task to fire an event named addtrack usingTrackEventwith thetrackattribute initialized to mirrored video track or new video track, at theVideoTrackListobject referenced by thevideoTracksattribute on the HTMLMediaElement. -
If the parent media source was constructed in a
- Create a new track buffer to store coded frames for this track.
- Add the track description for this track to the track buffer.
-
For each text track in the initialization segment, run following steps:
- Let text byte stream track ID be the Track ID for the current track being processed.
- Let text language be a BCP 47 language tag for the language specified in the initialization segment for this track or an empty string if no language info is present.
- If text language equals the 'und' BCP 47 value, then assign an empty string to text language.
- Let text label be a label specified in the initialization segment for this track or an empty string if no label info is present.
- Let text kinds be a sequence of kind strings specified in the initialization segment for this track or a sequence with a single empty string element in it if no kind information is provided.
- For each value in text kinds, run the following steps:
- Let current text kind equal the value from text kinds for this iteration of the loop.
- Let new text track be a new
TextTrackobject. - Generate a unique ID and assign it to the
idproperty on new text track. - Assign text language to the
languageproperty on new text track. - Assign text label to the
labelproperty on new text track. - Assign current text kind to the
kindproperty on new text track. - Populate the remaining properties on new text track with the appropriate information from the initialization segment.
- If the
modeproperty on new text track equals"showing"or"hidden", then set active track flag to true. - Add new text track to the
textTracksattribute on thisSourceBufferobject.NoteThis should trigger
TextTrackList[HTML] logic to queue a task to fire an event named addtrack usingTrackEventwith thetrackattribute initialized to new text track, at theTextTrackListobject referenced by thetextTracksattribute on thisSourceBufferobject. -
-
If the parent media source was constructed in a
DedicatedWorkerGlobalScope: -
Post an internal
create track mirrormessage to[[port to main]]whose implicit handler inWindowruns the following steps:- Let mirrored text track be a new
TextTrackobject. - Assign the same property values to mirrored text track as were determined for new text track.
- Add mirrored text track to the
textTracksattribute on the HTMLMediaElement.
- Let mirrored text track be a new
- Otherwise:
-
Add new text track to the
textTracksattribute on the HTMLMediaElement.
NoteThis should trigger
TextTrackList[HTML] logic to queue a task to fire an event named addtrack usingTrackEventwith thetrackattribute initialized to mirrored text track or new text track, at theTextTrackListobject referenced by thetextTracksattribute on the HTMLMediaElement. -
If the parent media source was constructed in a
- Create a new track buffer to store coded frames for this track.
- Add the track description for this track to the track buffer.
- If active track flag equals true, then run the following steps:
- Add this
SourceBuffertoactiveSourceBuffers. - Queue a task to fire an event named
addsourcebufferatactiveSourceBuffers
- Add this
- Set
[[first initialization segment received flag]]to true.
- If the initialization segment contains tracks with codecs the user agent
does not support, then run the append error algorithm and abort these steps.
- Set
[[pending initialization segment for changeType flag]]to false. - If the active track flag equals true, then run the following steps:
- Use the parent media source's mirror if necessary algorithm to run the
following step in
Window:- If the
HTMLMediaElement'sreadyStateattribute is greater thanHAVE_CURRENT_DATA, then set theHTMLMediaElement'sreadyStateattribute toHAVE_METADATA.NotePer
HTMLMediaElement ready states[HTML] logic,HTMLMediaElement'sreadyStatechanges may trigger events on the HTMLMediaElement.
- If the
- If each object in
sourceBuffersof the parent media source has[[first initialization segment received flag]]equal to true, then use the parent media source's mirror if necessary algorithm to run the following step inWindow:- If the
HTMLMediaElement'sreadyStateattribute isHAVE_NOTHING, then set theHTMLMediaElement'sreadyStateattribute toHAVE_METADATA.NotePer
HTMLMediaElement ready states[HTML] logic,HTMLMediaElement'sreadyStatechanges may trigger events on the HTMLMediaElement. If transition fromHAVE_NOTHINGtoHAVE_METADATAoccurs, it should trigger HTMLMediaElement logic to queue a task to fire an event named loadedmetadata at the media element.
- If the
When complete coded frames have been parsed by the segment parser loop then the following steps are run:
-
For each coded frame in the media segment run the following steps:
-
Loop Top:
-
If
[[generate timestamps flag]]equals true: -
- Let presentation timestamp equal 0.
- Let decode timestamp equal 0.
- Otherwise:
-
- Let presentation timestamp be a double precision floating point
representation of the coded frame's presentation timestamp in seconds.
Note
Special processing may be needed to determine the presentation and decode timestamps for timed text frames since this information may not be explicitly present in the underlying format or may be dependent on the order of the frames. Some metadata text tracks, like MPEG2-TS PSI data, may only have implied timestamps. Format specific rules for these situations SHOULD be in the byte stream format specifications or in separate extension specifications.
- Let decode timestamp be a double precision floating point
representation of the coded frame's decode timestamp in seconds.
Note
Implementations don't have to internally store timestamps in a double precision floating point representation. This representation is used here because it is the representation for timestamps in the HTML spec. The intention here is to make the behavior clear without adding unnecessary complexity to the algorithm to deal with the fact that adding a timestampOffset may cause a timestamp rollover in the underlying timestamp representation used by the byte stream format. Implementations can use any internal timestamp representation they wish, but the addition of timestampOffset SHOULD behave in a similar manner to what would happen if a double precision floating point representation was used.
- Let presentation timestamp be a double precision floating point
representation of the coded frame's presentation timestamp in seconds.
-
If
- Let frame duration be a double precision floating point representation of the coded frame's duration in seconds.
- If
modeequals "sequence" and[[group start timestamp]]is set, then run the following steps:- Set
timestampOffsetequal to[[group start timestamp]]minus presentation timestamp. - Set
[[group end timestamp]]equal to[[group start timestamp]]. - Set the need random access point flag on all track buffers to true.
- Unset
[[group start timestamp]].
- Set
-
If
timestampOffsetis not 0, then run the following steps:- Add
timestampOffsetto the presentation timestamp. - Add
timestampOffsetto the decode timestamp.
- Add
- Let track buffer equal the track buffer that the coded frame will be added to.
-
- If last decode timestamp for track buffer is set and decode timestamp is less than last decode timestamp:
- OR
- If last decode timestamp for track buffer is set and the difference between decode timestamp and last decode timestamp is greater than 2 times last frame duration:
-
-
-
If
modeequals "segments": -
Set
[[group end timestamp]]to presentation timestamp. -
If
modeequals "sequence": -
Set
[[group start timestamp]]equal to the[[group end timestamp]].
-
If
- Unset the last decode timestamp on all track buffers.
- Unset the last frame duration on all track buffers.
- Unset the highest end timestamp on all track buffers.
- Set the need random access point flag on all track buffers to true.
- Jump to the Loop Top step above to restart processing of the current coded frame.
-
- Otherwise:
- Continue.
- Let frame end timestamp equal the sum of presentation timestamp and frame duration.
- If presentation timestamp is less than
appendWindowStart, then set the need random access point flag to true, drop the coded frame, and jump to the top of the loop to start processing the next coded frame.NoteSome implementations MAY choose to collect some of these coded frames with presentation timestamp less than
appendWindowStartand use them to generate a splice at the first coded frame that has a presentation timestamp greater than or equal toappendWindowStarteven if that frame is not a random access point. Supporting this requires multiple decoders or faster than real-time decoding so for now this behavior will not be a normative requirement. - If frame end timestamp is greater than
appendWindowEnd, then set the need random access point flag to true, drop the coded frame, and jump to the top of the loop to start processing the next coded frame.NoteSome implementations MAY choose to collect coded frames with presentation timestamp less than
appendWindowEndand frame end timestamp greater thanappendWindowEndand use them to generate a splice across the portion of the collected coded frames within the append window at time of collection, and the beginning portion of later processed frames which only partially overlap the end of the collected coded frames. Supporting this requires multiple decoders or faster than real-time decoding so for now this behavior will not be a normative requirement. In conjunction with collecting coded frames that spanappendWindowStart, implementations MAY thus support gapless audio splicing. - If the need random access point flag on track buffer equals true, then
run the following steps:
- If the coded frame is not a random access point, then drop the coded frame and jump to the top of the loop to start processing the next coded frame.
- Set the need random access point flag on track buffer to false.
- Let spliced audio frame be an unset variable for holding audio splice information
- Let spliced timed text frame be an unset variable for holding timed text splice information
- If last decode timestamp for track buffer is unset and presentation
timestamp falls within the presentation interval of a coded frame in
track buffer, then run the following steps:
- Let overlapped frame be the coded frame in track buffer that matches the condition above.
-
- If track buffer contains audio coded frames:
- Run the audio splice frame algorithm and if a splice frame is returned, assign it to spliced audio frame.
- If track buffer contains video coded frames:
-
- Let remove window timestamp equal the overlapped frame presentation timestamp plus 1 microsecond.
- If the presentation timestamp is less than the remove window
timestamp, then remove overlapped frame from track buffer.
Note
This is to compensate for minor errors in frame timestamp computations that can appear when converting back and forth between double precision floating point numbers and rationals. This tolerance allows a frame to replace an existing one as long as it is within 1 microsecond of the existing frame's start time. Frames that come slightly before an existing frame are handled by the removal step below.
- If track buffer contains timed text coded frames:
- Run the text splice frame algorithm and if a splice frame is returned, assign it to spliced timed text frame.
- Remove existing coded frames in track buffer:
- If highest end timestamp for track buffer is not set:
- Remove all coded frames from track buffer that have a presentation timestamp greater than or equal to presentation timestamp and less than frame end timestamp.
- If highest end timestamp for track buffer is set and less than or equal to presentation timestamp:
- Remove all coded frames from track buffer that have a presentation timestamp greater than or equal to highest end timestamp and less than frame end timestamp.
- Remove all possible decoding dependencies on the coded frames removed in
the previous two steps by removing all coded frames from track buffer between
those frames removed in the previous two steps and the next random access point
after those removed frames.
Note
Removing all coded frames until the next random access point is a conservative estimate of the decoding dependencies since it assumes all frames between the removed frames and the next random access point depended on the frames that were removed.
-
- If spliced audio frame is set:
- Add spliced audio frame to the track buffer.
- If spliced timed text frame is set:
- Add spliced timed text frame to the track buffer.
- Otherwise:
- Add the coded frame with the presentation timestamp, decode timestamp, and frame duration to the track buffer.
- Set last decode timestamp for track buffer to decode timestamp.
- Set last frame duration for track buffer to frame duration.
- If highest end timestamp for track buffer is unset or frame end
timestamp is greater than highest end timestamp, then set highest end timestamp for track buffer to frame end timestamp.
Note
The greater than check is needed because bidirectional prediction between coded frames can cause presentation timestamp to not be monotonically increasing even though the decode timestamps are monotonically increasing.
- If frame end timestamp is greater than
[[group end timestamp]], then set[[group end timestamp]]equal to frame end timestamp. - If
[[generate timestamps flag]]equals true, then settimestampOffsetequal to frame end timestamp.
-
Loop Top:
-
If the
HTMLMediaElement'sreadyStateattribute isHAVE_METADATAand the new coded frames causeHTMLMediaElement'sbufferedto have aTimeRangesfor the current playback position, then set theHTMLMediaElement'sreadyStateattribute toHAVE_CURRENT_DATA.NotePer
HTMLMediaElement ready states[HTML] logic,HTMLMediaElement'sreadyStatechanges may trigger events on the HTMLMediaElement. -
If the
HTMLMediaElement'sreadyStateattribute isHAVE_CURRENT_DATAand the new coded frames causeHTMLMediaElement'sbufferedto have aTimeRangesthat includes the current playback position and some time beyond the current playback position, then set theHTMLMediaElement'sreadyStateattribute toHAVE_FUTURE_DATA.NotePer
HTMLMediaElement ready states[HTML] logic,HTMLMediaElement'sreadyStatechanges may trigger events on the HTMLMediaElement. -
If the
HTMLMediaElement'sreadyStateattribute isHAVE_FUTURE_DATAand the new coded frames causeHTMLMediaElement'sbufferedto have aTimeRangesthat includes the current playback position and enough data to ensure uninterrupted playback, then set theHTMLMediaElement'sreadyStateattribute toHAVE_ENOUGH_DATA.NotePer
HTMLMediaElement ready states[HTML] logic,HTMLMediaElement'sreadyStatechanges may trigger events on the HTMLMediaElement. - If the media segment contains data beyond the current
duration, then run the duration change algorithm with new duration set to the maximum of the current duration and the[[group end timestamp]].
Follow these steps when coded frames for a specific time range need to be removed from the SourceBuffer:
- Let start be the starting presentation timestamp for the removal range.
- Let end be the end presentation timestamp for the removal range.
-
For each track buffer in this
SourceBuffer, run the following steps:- Let remove end timestamp be the current value of
duration -
If this track buffer has a random access point timestamp that is greater than or equal to end, then update remove end timestamp to that random access point timestamp.
NoteRandom access point timestamps can be different across tracks because the dependencies between coded frames within a track are usually different than the dependencies in another track.
- Remove all media data, from this track buffer, that contain starting
timestamps greater than or equal to start and less than the remove end
timestamp.
-
For each removed frame, if the frame has a decode timestamp equal to the last decode timestamp for the frame's track, run the following steps:
-
If
modeequals "segments": -
Set
[[group end timestamp]]to presentation timestamp. -
If
modeequals "sequence": -
Set
[[group start timestamp]]equal to the[[group end timestamp]].
-
If
- Unset the last decode timestamp on all track buffers.
- Unset the last frame duration on all track buffers.
- Unset the highest end timestamp on all track buffers.
- Set the need random access point flag on all track buffers to true.
-
- Remove all possible decoding dependencies on the coded frames removed in
the previous step by removing all coded frames from this track buffer
between those frames removed in the previous step and the next random access point after those removed frames.
Note
Removing all coded frames until the next random access point is a conservative estimate of the decoding dependencies since it assumes all frames between the removed frames and the next random access point depended on the frames that were removed.
-
If this object is in
activeSourceBuffers, the current playback position is greater than or equal to start and less than the remove end timestamp, andHTMLMediaElement'sreadyStateis greater thanHAVE_METADATA, then set theHTMLMediaElement'sreadyStateattribute toHAVE_METADATAand stall playback.NotePer
HTMLMediaElement ready states[HTML] logic,HTMLMediaElement'sreadyStatechanges may trigger events on the HTMLMediaElement.NoteThis transition occurs because media data for the current position has been removed. Playback cannot progress until media for the current playback position is appended or the 3.15.5 Changes to selected/enabled track state.
- Let remove end timestamp be the current value of
- If the
[[buffer full flag]]equals true and this object is ready to accept more bytes, then set the[[buffer full flag]]to false.
This algorithm is run to free up space in this SourceBuffer when new data is
appended.
- Let new data equal the data that is about to be appended to this
SourceBuffer.
Issue 289: Editorial? Coded Frame eviction algorithm needs to note that "buffer full flag" may be updated immediately based on |new data|
Need to recognize step here that implementations MAY decide to set
[[buffer full flag]]true here if it predicts that processing new data in addition to any existing bytes in[[input buffer]]would exceed the capacity of theSourceBuffer. Such a step enables more proactive push-back from implementations before accepting new data which would overflow resources, for example. In practice, at least one implementation already does this. - If the
[[buffer full flag]]equals false, then abort these steps. - Let removal ranges equal a list of presentation time ranges
that can be evicted from the presentation to make room for the new data.
Note
Implementations MAY use different methods for selecting removal ranges so web applications SHOULD NOT depend on a specific behavior. The web application can use the
bufferedattribute to observe whether portions of the buffered data have been evicted. - For each range in removal ranges, run the coded frame removal algorithm with start and end equal to the removal range start and end timestamp respectively.
Follow these steps when the coded frame processing algorithm needs to generate a splice frame for two overlapping audio coded frames:
- Let track buffer be the track buffer that will contain the splice.
- Let new coded frame be the new coded frame, that is being added to track buffer, which triggered the need for a splice.
- Let presentation timestamp be the presentation timestamp for new coded frame.
- Let decode timestamp be the decode timestamp for new coded frame.
- Let frame duration be the coded frame duration of new coded frame.
- Let overlapped frame be the coded frame in track buffer with a presentation interval that contains presentation timestamp.
- Update presentation timestamp and decode timestamp to the nearest audio sample
timestamp based on sample rate of the audio in overlapped frame. If a timestamp is
equidistant from both audio sample timestamps, then use the higher timestamp (e.g.,
floor(x * sample_rate + 0.5) / sample_rate).NoteFor example, given the following values:
- The presentation timestamp of overlapped frame equals 10.
- The sample rate of overlapped frame equals 8000 Hz
- presentation timestamp equals 10.01255
- decode timestamp equals 10.01255
presentation timestamp and decode timestamp are updated to 10.0125 since 10.01255 is closer to 10 + 100/8000 (10.0125) than 10 + 101/8000 (10.012625)
- If the user agent does not support crossfading then run the following steps:
- Remove overlapped frame from track buffer.
- Add a silence frame to track buffer with the following properties:
- The presentation timestamp set to the overlapped frame presentation timestamp.
- The decode timestamp set to the overlapped frame decode timestamp.
- The coded frame duration set to difference between presentation timestamp and the overlapped frame presentation timestamp.
NoteSome implementations MAY apply fades to/from silence to coded frames on either side of the inserted silence to make the transition less jarring.
- Return to caller without providing a splice frame.
Note
This is intended to allow new coded frame to be added to the track buffer as if overlapped frame had not been in the track buffer to begin with.
- Let frame end timestamp equal the sum of presentation timestamp and frame duration.
- Let splice end timestamp equal the sum of presentation timestamp and the splice duration of 5 milliseconds.
- Let fade out coded frames equal overlapped frame as well as any additional frames in track buffer that have a presentation timestamp greater than presentation timestamp and less than splice end timestamp.
- Remove all the frames included in fade out coded frames from track buffer.
- Return a splice frame with the following properties:
- The presentation timestamp set to the overlapped frame presentation timestamp.
- The decode timestamp set to the overlapped frame decode timestamp.
- The coded frame duration set to difference between frame end timestamp and the overlapped frame presentation timestamp.
- The fade out coded frames equals fade out coded frames.
- The fade in coded frame equals new coded frame.
Note
If the new coded frame is less than 5 milliseconds in duration, then coded frames that are appended after the new coded frame will be needed to properly render the splice.
- The splice timestamp equals presentation timestamp.
NoteSee the audio splice rendering algorithm for details on how this splice frame is rendered.
The following steps are run when a spliced frame, generated by the audio splice frame algorithm, needs to be rendered by the media element:
- Let fade out coded frames be the coded frames that are faded out during the splice.
- Let fade in coded frames be the coded frames that are faded in during the splice.
- Let presentation timestamp be the presentation timestamp of the first coded frame in fade out coded frames.
- Let end timestamp be the sum of the presentation timestamp and the coded frame duration of the last frame in fade in coded frames.
- Let splice timestamp be the presentation timestamp where the splice starts. This corresponds with the presentation timestamp of the first frame in fade in coded frames.
- Let splice end timestamp equal splice timestamp plus five milliseconds.
- Let fade out samples be the samples generated by decoding fade out coded frames.
- Trim fade out samples so that it only contains samples between presentation timestamp and splice end timestamp.
- Let fade in samples be the samples generated by decoding fade in coded frames.
- If fade out samples and fade in samples do not have a common sample rate and channel layout, then convert fade out samples and fade in samples to a common sample rate and channel layout.
- Let output samples be a buffer to hold the output samples.
- Apply a linear gain fade out with a starting gain of 1 and an ending gain of 0 to the samples between splice timestamp and splice end timestamp in fade out samples.
- Apply a linear gain fade in with a starting gain of 0 and an ending gain of 1 to the samples between splice timestamp and splice end timestamp in fade in samples.
- Copy samples between presentation timestamp to splice timestamp from fade out samples into output samples.
- For each sample between splice timestamp and splice end timestamp, compute the sum of a sample from fade out samples and the corresponding sample in fade in samples and store the result in output samples.
- Copy samples between splice end timestamp to end timestamp from fade in samples into output samples.
- Render output samples.
Here is a graphical representation of this algorithm.
Follow these steps when the coded frame processing algorithm needs to generate a splice frame for two overlapping timed text coded frames:
- Let track buffer be the track buffer that will contain the splice.
- Let new coded frame be the new coded frame, that is being added to track buffer, which triggered the need for a splice.
- Let presentation timestamp be the presentation timestamp for new coded frame
- Let decode timestamp be the decode timestamp for new coded frame.
- Let frame duration be the coded frame duration of new coded frame.
- Let frame end timestamp equal the sum of presentation timestamp and frame duration.
- Let first overlapped frame be the coded frame in track buffer with a presentation interval that contains presentation timestamp.
- Let overlapped presentation timestamp be the presentation timestamp of the first overlapped frame.
- Let overlapped frames equal first overlapped frame as well as any additional frames in track buffer that have a presentation timestamp greater than presentation timestamp and less than frame end timestamp.
- Remove all the frames included in overlapped frames from track buffer.
- Update the coded frame duration of the first overlapped frame to presentation timestamp minus overlapped presentation timestamp.
- Add first overlapped frame to the track buffer.
- Return to caller without providing a splice frame.
Note
This is intended to allow new coded frame to be added to the track buffer as if it hadn't overlapped any frames in track buffer to begin with.
SourceBufferList is a simple container object for SourceBuffer objects. It
provides read-only array access and fires events when the list is modified.
WebIDL[Exposed=(Window,DedicatedWorker)]
interface SourceBufferList : EventTarget {
readonly attribute unsigned long length;
attribute EventHandler onaddsourcebuffer;
attribute EventHandler onremovesourcebuffer;
getter SourceBuffer (unsigned long index);
};
-
lengthof typeunsigned long, readonly -
Indicates the number of
SourceBufferobjects in the list. -
onaddsourcebufferof typeEventHandler -
The event handler for the
addsourcebufferevent. -
onremovesourcebufferof typeEventHandler -
The event handler for the
removesourcebufferevent.
- getter
-
Allows the SourceBuffer objects in the list to be accessed with an array operator (i.e., []).
When this method is invoked, the user agent must run the following steps:
- If index is greater than or equal to the
lengthattribute then return undefined and abort these steps. - Return the index'th
SourceBufferobject in the list.
- If index is greater than or equal to the
| Event name | Interface | Dispatched when... |
|---|---|---|
| addsourcebuffer |
Event
|
When a SourceBuffer is added to the list.
|
| removesourcebuffer |
Event
|
When a SourceBuffer is removed from the list.
|
A ManagedMediaSource is a MediaSource that actively manages its memory content.
Unlike a MediaSource, the user agent can evict content through the
memory cleanup algorithm from its sourceBuffers
(populated with ManagedSourceBuffer) for any reason.
WebIDL[Exposed=(Window,DedicatedWorker)]
interface ManagedMediaSource : MediaSource {
constructor();
readonly attribute boolean streaming;
attribute EventHandler onstartstreaming;
attribute EventHandler onendstreaming;
};
-
streaming -
On getting:
- Return the current value of the attribute.
| Event name | Interface | Dispatched when... |
|---|---|---|
| startstreaming |
Event
|
A ManagedMediaSource's streaming attribute changed from
false to true.
|
| endstreaming |
Event
|
A ManagedMediaSource's streaming attribute changed from
true to false.
|
The following steps are run periodically, whenever the SourceBuffer Monitoring algorithm is scheduled to run.
Having enough managed data to ensure uninterrupted playback is an implementation
defined condition where the user agent determines that it currently has enough data to play
the presentation without stalling for a meaningful period of time. This condition is
constantly evaluated to determine when to transition the value of
streaming. These transitions indicate when the user agent believes
it has enough data buffered or it needs more data respectively.
Being able to retrieve and buffer data in an efficient way is an implementation defined condition where the user agent determines that it can fetch new data in an energy efficient manner while able to achieve the desired memory usage.
- Run the
MediaSourceSourceBuffer Monitoring algorithm. - Let can play uninterrupted and efficiently be a flag that is true if the
bufferedattribute contains aTimeRangesthat includes the current playback position and enough managed data to ensure uninterrupted playback and is able to retrieve and buffer data in an efficient way-
If can play uninterrupted and efficiently is not equal to
streaming, queue an element task on the media element that runs the following steps: -
- Set this
streamingattribute to can play uninterrupted and efficiently. - If can play uninterrupted and efficiently is false fire an event called
startstreamingat theManagedMediaSource. - Otherwise, fire an event called
endstreamingat theManagedMediaSource.
- Set this
-
If can play uninterrupted and efficiently is not equal to
-
-
For each buffer in this's
sourceBuffers: -
- Run the buffer's memory cleanup algorithm.
-
For each buffer in this's
WebIDL[Exposed=(Window,DedicatedWorker)]
interface BufferedChangeEvent : Event {
constructor(DOMString type, optional BufferedChangeEventInit eventInitDict = {});
[SameObject] readonly attribute TimeRanges addedRanges;
[SameObject] readonly attribute TimeRanges removedRanges;
};
dictionary BufferedChangeEventInit : EventInit {
TimeRanges addedRanges;
TimeRanges removedRanges;
};
-
addedRanges -
The time ranges added between the last
updatestartandupdateendevents (which would have occurred during the last run of the coded frame processing algorithm). -
removedRanges -
The time ranges removed between the last
updatestartandupdateendevents (which would have occurred during the last run of the coded frame removal or coded frame eviction algorithm or if the user agent evicted content in response to a memory cleanup).
WebIDL[Exposed=(Window,DedicatedWorker)]
interface ManagedSourceBuffer : SourceBuffer {
attribute EventHandler onbufferedchange;
};
-
onbufferedchange -
An event handler IDL attribute whose event handler event type is
bufferedchange.
| Event name | Interface | Dispatched when... |
|---|---|---|
| bufferedchange |
BufferedChangeEvent
|
The ManagedSourceBuffer's buffered range changed following a call to
appendBuffer(), remove(),
endOfStream(), or as a consequence of the user agent running the
memory cleanup algorithm.
|
The following steps are run at the completion of all operations to the
ManagedSourceBuffer buffer that would cause a buffer's
buffered to change. That is once appendBuffer(),
remove() or memory cleanup algorithm have
completed.
- Let previous buffered ranges equal the
bufferedattribute before the changes occurred. - Let new buffered ranges equal the new
bufferedTimeRanges. - Let added equal the previous buffered ranges subtracted from new buffered ranges.
- Let removed equal the new buffered ranges subtracted from previous buffered ranges.
- Let eventInitDict be a new
BufferedChangeEventInitdictionary initialized with added as itsaddedRangesand removed as itsremovedRanges - Queue a task to fire an event named
bufferedchangeat buffer using theBufferedChangeEventinterface, initialized with eventInitDict.
-
-
If this is not in this's
ManagedMediaSourceparentactiveSourceBuffers: -
- Run the coded frame removal algorithm with start set to 0, end set to positive infinity, and abort these steps.
-
If this is not in this's
- Let removal ranges equal a list of presentation time ranges
that can be evicted from the presentation to ensure uninterrupted playback from
currentTimeuntil such presentation could be retrieved again.NoteImplementations can use different strategies for selecting removal ranges so web applications shouldn't depend on a specific behavior. The web application would listen to the
bufferedchangeevent to observe whether portions of the buffered data have been evicted. - For each range in removal ranges, run the coded frame removal algorithm with start and end equal to the removal range start and end timestamp respectively.
This section specifies what existing HTMLMediaElement's seekable
and HTMLMediaElement's buffered attributes on the
HTMLMediaElement MUST return when a MediaSource is attached to the element, and
what the existing HTMLMediaElement's srcObject attribute MUST also
do when it is set to be a MediaSourceHandle object.
10.1
HTMLMediaElement's seekable
The HTMLMediaElement's seekable attribute returns a new static
normalized TimeRanges object created based on the following steps:
- If the
MediaSourcewas constructed in aDedicatedWorkerGlobalScopethat is terminated or is closing then return an emptyTimeRangesobject and abort these steps.NoteThis case is intended to handle implementations that may no longer maintain any previous information about buffered or seekable media in a MediaSource that was constructed in a DedicatedWorkerGlobalScope that has been terminated by
terminate()or user agent execution of terminate a worker for the MediaSource's DedicatedWorkerGlobalScope, for instance as the eventual result ofclose()execution.Issue 277: MSE-in-Workers: Consider (eventually) transitioning attached element to error upon termination of MediaSource's worker/what should media element do? mse-in-workersShould there be some (eventual) media element error transition in the case of an attached worker MediaSource having its context destroyed? The experimental Chromium implementation of worker MSE just keeps the element readyState, networkState and error the same as prior to that context destruction, though the seekable and buffered attributes each report an empty TimeRange.
- Let recent duration and recent live seekable range respectively be the recent values of
durationand[[live seekable range]], determined as follows:-
If the
MediaSourcewas constructed in aWindow -
Set recent duration to be
durationand set recent live seekable range to be[[live seekable range]]. - Otherwise:
-
Set recent duration and recent live seekable range respectively to be what the
durationand[[live seekable range]]were recently, updated by handling implicit messages posted by theMediaSourceto its[[port to main]]on every change todurationor[[live seekable range]].
-
If the
-
- If recent duration equals NaN:
-
Return an empty
TimeRangesobject. - If recent duration equals positive Infinity:
-
- If recent live seekable range is not empty:
- Let union ranges be the union of recent live
seekable range and the
HTMLMediaElement'sbufferedattribute. - Return a single range with a start time equal to the earliest start time in union ranges and an end time equal to the highest end time in union ranges and abort these steps.
- Let union ranges be the union of recent live
seekable range and the
- If the
HTMLMediaElement'sbufferedattribute returns an emptyTimeRangesobject, then return an emptyTimeRangesobject and abort these steps. - Return a single range with a start time of 0 and an end time equal to the
highest end time reported by the
HTMLMediaElement'sbufferedattribute.
- If recent live seekable range is not empty:
- Otherwise:
- Return a single range with a start time of 0 and an end time equal to recent duration.
10.2
HTMLMediaElement's buffered
The HTMLMediaElement's buffered attribute returns a static
normalized TimeRanges object based on the following steps.
- If the
MediaSourcewas constructed in aDedicatedWorkerGlobalScopethat is terminated or is closing then return an emptyTimeRangesobject and abort these steps.NoteThis case is intended to handle implementations that may no longer maintain any previous information about buffered or seekable media in a MediaSource that was constructed in a DedicatedWorkerGlobalScope that has been terminated by
terminate()or user agent execution of terminate a worker for the MediaSource's DedicatedWorkerGlobalScope, for instance as the eventual result ofclose()execution.Issue 277: MSE-in-Workers: Consider (eventually) transitioning attached element to error upon termination of MediaSource's worker/what should media element do? mse-in-workersShould there be some (eventual) media element error transition in the case of an attached worker MediaSource having its context destroyed? The experimental Chromium implementation of worker MSE just keeps the element readyState, networkState and error the same as prior to that context destruction, though the seekable and buffered attributes each report an empty TimeRange.
- Let recent intersection ranges be determined as follows:
-
If the
MediaSourcewas constructed in aWindow -
- Let recent intersection ranges equal an empty
TimeRangesobject. - If
activeSourceBuffers.length does not equal 0 then run the following steps:- Let active ranges be the ranges
returned by
bufferedfor eachSourceBufferobject inactiveSourceBuffers. - Let highest end time be the largest range end time in the active ranges.
- Let recent intersection ranges equal a
TimeRangesobject containing a single range from 0 to highest end time. - For each
SourceBufferobject inactiveSourceBuffersrun the following steps:- Let source ranges equal the ranges returned
by the
bufferedattribute on the currentSourceBuffer. - If
readyStateis "ended", then set the end time on the last range in source ranges to highest end time. - Let new intersection ranges equal the intersection between the recent intersection ranges and the source ranges.
- Replace the ranges in recent intersection ranges with the new intersection ranges.
- Let source ranges equal the ranges returned
by the
- Let active ranges be the ranges
returned by
- Let recent intersection ranges equal an empty
- Otherwise:
-
Let recent intersection ranges be the
TimeRangesresulting from the steps for theWindowcase, but run with theMediaSourceand itsSourceBufferobjects in theirDedicatedWorkerGlobalScopeand communicated by using[[port to main]]implicit messages on every update to theactiveSourceBuffers,readyState, or any of the buffering state that would change any of the values of each of thosebufferedattributes of theactiveSourceBuffers.NoteThe overhead of recalculating and communicating recent intersection ranges so frequently is one reason for allowing implementation flexibility to query this information on-demand using other mechanisms such as shared memory and locks as mentioned in cross-context communication model.
-
If the
- If the current value of this attribute has not been set by this algorithm or recent intersection ranges does not contain the exact same range information as the current value of this attribute, then update the current value of this attribute to recent intersection ranges.
- Return the current value of this attribute.
10.3
HTMLMediaElement's srcObject
If a HTMLMediaElement's srcObject attribute is assigned a
MediaSourceHandle, then set [[has ever been assigned as srcobject]] for that MediaSourceHandle to true as part of the synchronous steps of
the extended HTMLMediaElement's srcObject setter that occur
before invoking the element's load algorithm.
This prevents transferring that MediaSourceHandle object ever again, enabling clear
synchronous exception if that is attempted.
MediaSourceHandle needs to be added to HTMLMediaElement's MediaProvider IDL
typedef and related text involving media provider objects.
This section specifies extensions to the [HTML] AudioTrack definition.
WebIDL[Exposed=(Window,DedicatedWorker)]
partial interface AudioTrack {
readonly attribute SourceBuffer? sourceBuffer;
};
AudioTrack needs Window+DedicatedWorker exposure.
-
sourceBufferof typeSourceBuffer, readonly , nullable -
On getting, run the following step:
-
If this track was created by a
SourceBufferthat was created on the same realm as this track, and if thatSourceBufferhas not been removed from thesourceBuffersattribute of its parent media source: -
Return the
SourceBufferthat created this track. - Otherwise:
- Return null.
NoteFor example, if aDedicatedWorkerGlobalScopeSourceBuffernotified its internalcreate track mirrorhandler inWindowto create this track, then theWindowcopy of the track would return null for this attribute. -
If this track was created by a
This section specifies extensions to the [HTML] VideoTrack definition.
WebIDL[Exposed=(Window,DedicatedWorker)]
partial interface VideoTrack {
readonly attribute SourceBuffer? sourceBuffer;
};
VideoTrack needs Window+DedicatedWorker exposure.
-
sourceBufferof typeSourceBuffer, readonly , nullable -
On getting, run the following step:
-
If this track was created by a
SourceBufferthat was created on the same realm as this track, and if thatSourceBufferhas not been removed from thesourceBuffersattribute of its parent media source: -
Return the
SourceBufferthat created this track. - Otherwise:
- Return null.
NoteFor example, if aDedicatedWorkerGlobalScopeSourceBuffernotified its internalcreate track mirrorhandler inWindowto create this track, then theWindowcopy of the track would return null for this attribute. -
If this track was created by a
This section specifies extensions to the [HTML] TextTrack definition.
WebIDL[Exposed=(Window,DedicatedWorker)]
partial interface TextTrack {
readonly attribute SourceBuffer? sourceBuffer;
};
-
sourceBufferof typeSourceBuffer, readonly , nullable -
On getting, run the following step:
-
If this track was created by a
SourceBufferthat was created on the same realm as this track, and if thatSourceBufferhas not been removed from thesourceBuffersattribute of its parent media source: -
Return the
SourceBufferthat created this track. - Otherwise:
- Return null.
NoteFor example, if aDedicatedWorkerGlobalScopeSourceBuffernotified its internalcreate track mirrorhandler inWindowto create this track, then theWindowcopy of the track would return null for this attribute. -
If this track was created by a
The bytes provided through appendBuffer() for a SourceBuffer form a
logical byte stream. The format and semantics of these byte streams are defined in byte stream format specifications. The byte stream format
registry [MSE-REGISTRY] provides mappings between a MIME type that may be passed to
addSourceBuffer(), isTypeSupported() or
changeType() and the byte stream format expected by a SourceBuffer
using that MIME type for parsing newly appended data. Implementations are encouraged to
register mappings for byte stream formats they support to facilitate interoperability. The
byte stream format registry [MSE-REGISTRY] is the authoritative source for these
mappings. If an implementation claims to support a MIME type listed in the registry, its
SourceBuffer implementation MUST conform to the byte stream format specification
listed in the registry entry.
The byte stream format specifications in the registry are not intended to define new storage formats. They simply outline the subset of existing storage format structures that implementations of this specification will accept.
Byte stream format parsing and validation is implemented in the segment parser loop algorithm.
This section provides general requirements for all byte stream format specifications:
- A byte stream format specification MUST define initialization segments and media segments.
- A byte stream format SHOULD provide references for sourcing
AudioTrack,VideoTrack, andTextTrackattribute values from data in initialization segments.NoteIf the byte stream format covers a format similar to one covered in the in-band tracks spec [INBANDTRACKS], then it SHOULD try to use the same attribute mappings so that Media Source Extensions playback and non-Media Source Extensions playback provide the same track information.
- It MUST be possible to identify segment boundaries and segment type (initialization or media) by examining the byte stream alone.
- The user agent MUST run the append error algorithm when any of the following
conditions are met:
-
The number and type of tracks are not consistent.
NoteFor example, if the first initialization segment has 2 audio tracks and 1 video track, then all initialization segments that follow it in the byte stream MUST describe 2 audio tracks and 1 video track.
- Track IDs are not the same across initialization segments, for segments describing multiple tracks of a single type (e.g., 2 audio tracks).
-
Unsupported codec changes occur across initialization segments.
NoteSee the initialization segment received algorithm,
addSourceBuffer()andchangeType()for details and examples of codec changes.
-
- The user agent MUST support the following:
- Track IDs changing across initialization segments if the segments describe only one track of each type.
-
Video frame size changes. The user agent MUST support seamless playback.
NoteThis will cause the <video> display region to change size if the web application does not use CSS or HTML attributes (width/height) to constrain the element size.
-
Audio channel count changes. The user agent MAY support this seamlessly and could trigger downmixing.
NoteThis 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.
- The following rules apply to all media segments within a byte stream. A user agent
MUST:
- Map all timestamps to the same media timeline.
- Support seamless playback of media segments having a timestamp gap smaller than
the audio frame size. User agents MUST NOT reflect these gaps in the
bufferedattribute.NoteThis is intended to simplify switching between audio streams where the frame boundaries don't always line up across encodings (e.g., Vorbis).
- The user agent MUST run the append error algorithm when any combination of an
initialization segment and any contiguous sequence of media segments satisfies the
following conditions:
- The number and type (audio, video, text, etc.) of all tracks in the media segments are not identified.
- The decoding capabilities needed to decode each track (i.e., codec and codec parameters) are not provided.
- Encryption parameters necessary to decrypt the content (except the encryption key itself) are not provided for all encrypted tracks.
- All information necessary to decode and render the earliest random access point
in the sequence of media segments and all subsequence samples in the sequence (in
presentation time) are not provided. This includes in particular,
- Information that determines the intrinsic width and height of the video (specifically, this requires either the picture or pixel aspect ratio, together with the encoded resolution).
- Information necessary to convert the video decoder output to a format suitable for display
- Information necessary to compute the global presentation timestamp of every sample in the sequence of media segments is not provided.
For example, if I1 is associated with M1, M2, M3 then the above MUST hold for all the combinations I1+M1, I1+M2, I1+M1+M2, I1+M2+M3, etc.
Byte stream specifications MUST at a minimum define constraints which ensure that the above requirements hold. Additional constraints MAY be defined, for example to simplify implementation.
As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative.
The key words MAY, MUST, MUST NOT, SHOULD, and SHOULD NOT in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.
<video id="v" autoplay></video>
<script>
const video = document.getElementById("v");
const mediaSource = new MediaSource();
mediaSource.addEventListener("sourceopen", onSourceOpen);
video.src = window.URL.createObjectURL(mediaSource);
async function onSourceOpen(e) {
const mediaSource = e.target;
if (mediaSource.sourceBuffers.length > 0) return;
const sourceBuffer = mediaSource.addSourceBuffer(
'video/webm; codecs="vorbis,vp8"',
);
video.addEventListener("seeking", (e) => onSeeking(mediaSource, e.target));
video.addEventListener("progress", () =>
appendNextMediaSegment(mediaSource),
);
try {
const initSegment = await getInitializationSegment();
if (initSegment == null) {
// Error fetching the initialization segment. Signal end of stream with an error.
mediaSource.endOfStream("network");
return;
}
// Append the initialization segment.
sourceBuffer.addEventListener("updateend", function firstAppendHandler() {
sourceBuffer.removeEventListener("updateend", firstAppendHandler);
// Append some initial media data.
appendNextMediaSegment(mediaSource);
});
sourceBuffer.appendBuffer(initSegment);
} catch (error) {
// Handle errors that might occur during initialization segment fetching.
console.error("Error fetching initialization segment:", error);
mediaSource.endOfStream("network");
}
}
async function appendNextMediaSegment(mediaSource) {
if (
mediaSource.readyState === "closed" ||
mediaSource.sourceBuffers[0].updating
)
return;
// If we have run out of stream data, then signal end of stream.
if (!haveMoreMediaSegments()) {
mediaSource.endOfStream();
return;
}
try {
const mediaSegment = await getNextMediaSegment();
// NOTE: If mediaSource.readyState == "ended", this appendBuffer() call will
// cause mediaSource.readyState to transition to "open". The web application
// should be prepared to handle multiple "sourceopen" events.
mediaSource.sourceBuffers[0].appendBuffer(mediaSegment);
}
catch (error) {
// Handle errors that might occur during media segment fetching.
console.error("Error fetching media segment:", error);
mediaSource.endOfStream("network");
}
}
function onSeeking(mediaSource, video) {
if (mediaSource.readyState === "open") {
// Abort current segment append.
mediaSource.sourceBuffers[0].abort();
}
// Notify the media segment loading code to start fetching data at the
// new playback position.
seekToMediaSegmentAt(video.currentTime);
// Append a media segment from the new playback position.
appendNextMediaSegment(mediaSource);
}
function onProgress(mediaSource, e) {
appendNextMediaSegment(mediaSource);
}
// Example of async function for getting initialization segment
async function getInitializationSegment() {
// Implement fetching of the initialization segment
// This is just a placeholder function
}
// Example function for checking if there are more media segments
function haveMoreMediaSegments() {
// Implement logic to determine if there are more media segments
// This is just a placeholder function
}
// Example function for getting the next media segment
async function getNextMediaSegment() {
// Implement fetching of the next media segment
// This is just a placeholder function
}
// Example function for seeking to a specific media segment
function seekToMediaSegmentAt(currentTime) {
// Implement seeking logic
// This is just a placeholder function
}
</script>
<script>
async function setUpVideoStream() {
// Specific video format and codec
const mediaType = 'video/mp4; codecs="mp4a.40.2,avc1.4d4015"';
// Check if the type of video format / codec is supported.
if (!window.ManagedMediaSource?.isTypeSupported(mediaType)) {
return; // Not supported, do something else.
}
// Set up video and its managed source.
const video = document.createElement("video");
const source = new ManagedMediaSource();
video.controls = true;
await new Promise((resolve) => {
video.src = URL.createObjectURL(source);
source.addEventListener("sourceopen", resolve, { once: true });
document.body.appendChild(video);
});
const sourceBuffer = source.addSourceBuffer(mediaType);
// Set up the event handlers
sourceBuffer.onbufferedchange = (e) => {
console.log("onbufferedchange event fired.");
console.log(`Added Ranges: ${timeRangesToString(e.addedRanges)}`);
console.log(`Removed Ranges: ${timeRangesToString(e.removedRanges)}`);
};
source.onstartstreaming = async () => {
const response = await fetch("./videos/bipbop.mp4");
const buffer = await response.arrayBuffer();
await new Promise((resolve) => {
sourceBuffer.addEventListener("updateend", resolve, { once: true });
sourceBuffer.appendBuffer(buffer);
});
};
source.onendstreaming = async () => {
// Stop fetching new segments here
};
}
// Helper function...
function timeRangesToString(timeRanges) {
const ranges = [];
for (let i = 0; i < timeRanges.length; i++) {
ranges.push([timeRanges.start(i), timeRanges.end(i)]);
}
return "[" + ranges.map(([start, end]) => `[${start}, ${end})` ) + "]";
}
</script>
<body onload="setUpVideoStream()"></body>
The editors would like to thank Alex Giladi, Bob Lund, Chris Needham, Chris Poole, Chris Wilson, Cyril Concolato, Dale Curtis, David Dorwin, David Singer, Duncan Rowden, François Daoust, Frank Galligan, Glenn Adams, Jer Noble, Joe Steele, John Simmons, Kagami Sascha Rosylight, Kevin Streeter, Marcos Cáceres, Mark Vickers, Matt Ward, Matthew Gregan, Michael(tm) Smith, Michael Thornburgh, Mounir Lamouri, Paul Adenot, Philip Jägenstedt, Philippe Le Hegaret, Pierre Lemieux, Ralph Giles, Steven Robertson, and Tatsuya Igarashi for their contributions to this specification.
This section is non-normative.
The video playback quality metrics described in previous revisions of this specification
(e.g., sections 5 and 10 of the Candidate Recommendation) are
now being developed as part of [MEDIA-PLAYBACK-QUALITY]. Some implementations may have
implemented the earlier draft VideoPlaybackQuality object and the HTMLVideoElement
extension method getVideoPlaybackQuality() described in those previous
revisions.
- Issue 276: MSE-in-Workers: Consider adding a "closing" readyState to explain new `InvalidStateError` exception when closing underway
- Issue 280: MSE-in-Workers: {Audio,Video,Text}Track{,List} IDL in HTML need additional DedicatedWorker in Exposed
- Issue 289: Editorial? Coded Frame eviction algorithm needs to note that "buffer full flag" may be updated immediately based on |new data|
- Issue 277: MSE-in-Workers: Consider (eventually) transitioning attached element to error upon termination of MediaSource's worker/what should media element do?
- Issue 277: MSE-in-Workers: Consider (eventually) transitioning attached element to error upon termination of MediaSource's worker/what should media element do?
- Issue
- Issue 280: MSE-in-Workers: {Audio,Video,Text}Track{,List} IDL in HTML need additional DedicatedWorker in Exposed
- Issue 280: MSE-in-Workers: {Audio,Video,Text}Track{,List} IDL in HTML need additional DedicatedWorker in Exposed
- Issue 280: MSE-in-Workers: {Audio,Video,Text}Track{,List} IDL in HTML need additional DedicatedWorker in Exposed
- [dom]
- DOM Standard. Anne van Kesteren. WHATWG. Living Standard. URL: https://dom.spec.whatwg.org/
- [ECMASCRIPT]
- ECMAScript Language Specification. Ecma International. URL: https://tc39.es/ecma262/multipage/
- [FILEAPI]
- File API. Marijn Kruisselbrink. W3C. 4 December 2024. W3C Working Draft. URL: https://www.w3.org/TR/FileAPI/
- [HTML]
- HTML Standard. Anne van Kesteren; Domenic Denicola; Dominic Farolino; Ian Hickson; Philip Jägenstedt; Simon Pieters. WHATWG. Living Standard. URL: https://html.spec.whatwg.org/multipage/
- [infra]
- Infra Standard. Anne van Kesteren; Domenic Denicola. WHATWG. Living Standard. URL: https://infra.spec.whatwg.org/
- [MSE-REGISTRY]
- Media Source Extensions™ Byte Stream Format Registry. Matthew Wolenetz; Jerry Smith; Aaron Colwell. W3C. URL: https://w3c.github.io/mse-byte-stream-format-registry/
- [RFC2119]
- Key words for use in RFCs to Indicate Requirement Levels. S. Bradner. IETF. March 1997. Best Current Practice. URL: https://www.rfc-editor.org/rfc/rfc2119
- [RFC8174]
- Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words. B. Leiba. IETF. May 2017. Best Current Practice. URL: https://www.rfc-editor.org/rfc/rfc8174
- [WEBIDL]
- Web IDL Standard. Edgar Chen; Timothy Gu. WHATWG. Living Standard. URL: https://webidl.spec.whatwg.org/
- [INBANDTRACKS]
- Sourcing In-band Media Resource Tracks from Media Containers into HTML. Silvia Pfeiffer; Bob Lund. W3C. 26 April 2015. Unofficial Draft. URL: https://dev.w3.org/html5/html-sourcing-inband-tracks/
- [MEDIA-PLAYBACK-QUALITY]
- Media Playback Quality. Mounir Lamouri; Chris Cunningham. W3C. W3C Editor's Draft. URL: https://w3c.github.io/media-playback-quality/
- [url]
- URL Standard. Anne van Kesteren. WHATWG. Living Standard. URL: https://url.spec.whatwg.org/
Referenced in:
- § 2. Definitions (2) (3) (4) (5) (6) (7) (8) (9)
- § 3.15.3 Seeking
- § 3.15.6 Duration change
- § 5. SourceBuffer interface
- § 5.3 Track Buffers (2) (3) (4) (5) (6) (7) (8) (9) (10)
- § 5.5.1 Segment Parser Loop (2) (3)
- § 5.5.2 Reset Parser State (2)
- § 5.5.7 Initialization Segment Received (2) (3)
- § 5.5.8 Coded Frame Processing (2) (3) (4) (5) (6) (7) (8) (9) (10) (11) (12) (13) (14) (15) (16) (17)
- § 5.5.9 Coded Frame Removal (2) (3) (4) (5)
- § 5.5.11 Audio Splice Frame (2) (3)
- § 5.5.12 Audio Splice Rendering (2)
- § 5.5.13 Text Splice Frame (2) (3)
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
- § 2. Definitions (2) (3) (4) (5) (6) (7) (8) (9) (10)
- § 3.15.6 Duration change
- § 5.1 Attributes (2)
- § 5.3 Track Buffers (2)
- § 5.5.6 Range Removal (2)
- § 5.5.8 Coded Frame Processing (2) (3) (4) (5)
- § 5.5.9 Coded Frame Removal (2) (3)
- § 5.5.11 Audio Splice Frame (2) (3) (4) (5) (6) (7) (8) (9)
- § 5.5.12 Audio Splice Rendering (2) (3) (4)
- § 5.5.13 Text Splice Frame (2) (3)
- § 14. Byte Stream Formats
Referenced in:
Referenced in:
Referenced in:
Referenced in:
- § Status of This Document
- § 2. Definitions (2) (3) (4) (5) (6)
- § 3. MediaSource interface (2) (3) (4) (5) (6) (7) (8) (9) (10) (11)
- § 3.1 handle attribute (2) (3) (4) (5) (6)
- § 3.2 sourceBuffers attribute (2)
- § 3.4 readyState attribute (2)
- § 3.5 duration attribute
- § 3.6 canConstructInDedicatedWorker attribute (2)
- § 3.8 removeSourceBuffer() method (2) (3)
- § 3.12 isTypeSupported() method (2) (3)
- § 3.13 Event Summary (2) (3)
- § 3.14 Cross-context communication model (2) (3) (4) (5) (6) (7) (8) (9) (10)
- § 3.15.1 Attaching to a media element (2) (3) (4) (5) (6) (7) (8) (9) (10) (11) (12) (13) (14) (15) (16) (17) (18) (19) (20) (21) (22) (23) (24) (25) (26) (27) (28)
- § 3.15.2 Detaching from a media element (2) (3) (4) (5) (6) (7)
- § 3.15.5 Changes to selected/enabled track state
- § 3.15.7 End of stream
- § 3.15.8 Mirror if necessary (2)
- § 4. MediaSourceHandle interface (2) (3) (4)
- § 4.1 Transfer (2) (3) (4)
- § 5.5.4 Prepare Append
- § 7. ManagedMediaSource interface (2) (3)
- § 7.3.1 ManagedSourceBuffer Monitoring
- § 10. HTMLMediaElement Extensions
- § 10.1 HTMLMediaElement's seekable (2) (3)
- § 10.2 HTMLMediaElement's buffered (2) (3)
Referenced in:
Referenced in:
- § 3. MediaSource interface
- § 3.15.3 Seeking (2) (3) (4)
- § 3.15.4 SourceBuffer Monitoring (2) (3) (4) (5) (6) (7) (8) (9) (10)
- § 3.15.7 End of stream (2) (3) (4)
- § 5.5.7 Initialization Segment Received (2) (3) (4) (5) (6)
- § 5.5.8 Coded Frame Processing (2) (3) (4) (5) (6) (7) (8) (9)
- § 5.5.9 Coded Frame Removal (2) (3)
Referenced in:
Referenced in:
- § 3. MediaSource interface
- § 3.2 sourceBuffers attribute
- § 3.5 duration attribute
- § 3.7 addSourceBuffer() method
- § 3.9 endOfStream() method
- § 3.10 setLiveSeekableRange() method
- § 3.11 clearLiveSeekableRange() method
- § 3.13 Event Summary (2) (3) (4)
- § 3.15.1 Attaching to a media element (2)
- § 5.1 Attributes (2)
- § 5.2 Methods (2) (3)
- § 5.5.4 Prepare Append
Referenced in:
Referenced in:
Referenced in:
Referenced in:
- § 3. MediaSource interface (2) (3)
- § 3.3 activeSourceBuffers attribute (2)
- § 3.5 duration attribute
- § 3.7 addSourceBuffer() method (2) (3) (4)
- § 3.8 removeSourceBuffer() method (2) (3) (4)
- § 3.9 endOfStream() method
- § 3.15.2 Detaching from a media element (2)
- § 3.15.6 Duration change (2)
- § 3.15.7 End of stream
- § 5.1 Attributes (2) (3) (4) (5)
- § 5.2 Methods (2) (3) (4)
- § 5.5.4 Prepare Append
- § 5.5.7 Initialization Segment Received
- § 7. ManagedMediaSource interface
- § 7.3.2 Memory Cleanup
- § Attributes (2) (3)
Referenced in:
- § 2. Definitions
- § 3. MediaSource interface
- § 3.3 activeSourceBuffers attribute
- § 3.8 removeSourceBuffer() method (2) (3)
- § 3.15.2 Detaching from a media element (2)
- § 3.15.3 Seeking
- § 3.15.4 SourceBuffer Monitoring (2)
- § 3.15.5 Changes to selected/enabled track state (2) (3) (4) (5) (6) (7) (8) (9) (10) (11) (12) (13) (14) (15) (16)
- § 5.5.7 Initialization Segment Received (2)
- § 5.5.9 Coded Frame Removal
- § 9.3.2 Memory cleanup
- § 10.2 HTMLMediaElement's buffered (2) (3) (4) (5)
Referenced in:
- § 3. MediaSource interface (2) (3)
- § 3.2 sourceBuffers attribute (2)
- § 3.4 readyState attribute
- § 3.5 duration attribute (2)
- § 3.7 addSourceBuffer() method
- § 3.9 endOfStream() method
- § 3.10 setLiveSeekableRange() method
- § 3.11 clearLiveSeekableRange() method
- § 3.13 Event Summary (2) (3)
- § 3.15.1 Attaching to a media element (2) (3)
- § 3.15.2 Detaching from a media element
- § 3.15.3 Seeking (2)
- § 3.15.7 End of stream
- § 5.1 Attributes (2) (3) (4) (5)
- § 5.2 Methods (2) (3) (4) (5)
- § 5.5.4 Prepare Append (2)
- § 10.2 HTMLMediaElement's buffered (2)
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
- § 3.14 Cross-context communication model
- § 3.15.1 Attaching to a media element (2)
- § 3.15.2 Detaching from a media element
- § 3.15.5 Changes to selected/enabled track state
- § 3.15.8 Mirror if necessary
- § 5.5.7 Initialization Segment Received (2) (3)
- § 10.1 HTMLMediaElement's seekable
- § 10.2 HTMLMediaElement's buffered
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
- § 3. MediaSource interface (2)
- § 3.1 handle attribute (2)
- § 3.14 Cross-context communication model
- § 3.15.1 Attaching to a media element (2) (3) (4) (5) (6) (7)
- § 4. MediaSourceHandle interface (2) (3) (4) (5) (6)
- § 4.1 Transfer (2) (3) (4) (5) (6) (7) (8) (9) (10)
- § 10. HTMLMediaElement Extensions
- § 10.3 HTMLMediaElement's srcObject (2) (3) (4)
Referenced in:
- § 1. Introduction (2) (3)
- § 2. Definitions (2) (3) (4) (5) (6)
- § 3. MediaSource interface (2) (3) (4) (5) (6)
- § 3.2 sourceBuffers attribute
- § 3.3 activeSourceBuffers attribute
- § 3.5 duration attribute
- § 3.7 addSourceBuffer() method (2) (3)
- § 3.8 removeSourceBuffer() method
- § 3.9 endOfStream() method
- § 3.12 isTypeSupported() method (2) (3)
- § 3.15.2 Detaching from a media element (2)
- § 3.15.3 Seeking
- § 3.15.4 SourceBuffer Monitoring
- § 3.15.5 Changes to selected/enabled track state (2) (3) (4) (5) (6) (7) (8) (9) (10) (11) (12)
- § 3.15.6 Duration change (2)
- § 3.15.7 End of stream
- § 5. SourceBuffer interface
- § 5.1 Attributes (2) (3) (4)
- § 5.2 Methods (2) (3) (4) (5) (6) (7) (8) (9)
- § 5.3 Track Buffers (2) (3)
- § 5.4 Event Summary (2) (3) (4) (5) (6)
- § 5.5.1 Segment Parser Loop (2) (3) (4) (5) (6) (7) (8) (9) (10) (11)
- § 5.5.3 Append Error (2)
- § 5.5.4 Prepare Append (2)
- § 5.5.5 Buffer Append (2)
- § 5.5.6 Range Removal (2) (3)
- § 5.5.7 Initialization Segment Received (2) (3) (4) (5) (6) (7) (8) (9) (10) (11) (12) (13) (14) (15)
- § 5.5.9 Coded Frame Removal
- § 5.5.10 Coded Frame Eviction (2)
- § 6. SourceBufferList interface (2)
- § 6.1 Attributes
- § 6.2 Methods
- § 6.3 Event Summary (2)
- § 9. ManagedSourceBuffer interface
- § 10.2 HTMLMediaElement's buffered (2) (3) (4)
- § 11. AudioTrack extensions
- § Attributes (2) (3) (4) (5) (6) (7) (8) (9) (10) (11) (12) (13) (14) (15)
- § 12. VideoTrack extensions
- § 13. TextTrack extensions
- § 14. Byte Stream Formats (2) (3)
Referenced in:
Referenced in:
Referenced in:
Referenced in:
- § 3.5 duration attribute
- § 3.8 removeSourceBuffer() method (2)
- § 3.9 endOfStream() method
- § 5. SourceBuffer interface
- § 5.1 Attributes (2) (3) (4)
- § 5.2 Methods (2) (3) (4) (5)
- § 5.4 Event Summary (2) (3) (4)
- § 5.5.3 Append Error
- § 5.5.4 Prepare Append
- § 5.5.5 Buffer Append
- § 5.5.6 Range Removal (2)
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
- § 2. Definitions
- § 3.15.6 Duration change
- § 3.15.7 End of stream
- § 5.1 Attributes (2) (3) (4)
- § 5.3 Track Buffers (2) (3) (4) (5) (6) (7) (8)
- § 5.5.1 Segment Parser Loop
- § 5.5.2 Reset Parser State (2) (3) (4)
- § 5.5.7 Initialization Segment Received (2) (3) (4) (5) (6) (7)
- § 5.5.8 Coded Frame Processing (2) (3) (4) (5) (6)
- § 5.5.9 Coded Frame Removal (2) (3) (4) (5) (6) (7) (8)
- § 5.5.11 Audio Splice Frame
- § 5.5.13 Text Splice Frame
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in: