Media Source Extensions™

W3C Editor's Draft

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:
(Apple Inc.)
Mark Watson(Netflix Inc.)
Former editors:
(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)
[email protected]with subject line[media-source-2]…message topic…(archives)
Browser support:
caniuse.com

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 currentW3C publications and the latest revision of this technical report can be found in theW3Ctechnical reports indexat https://www.w3.org/TR/.

On top of editorial updates, substantive changes since publication as aW3CRecommendation inNovember 2016are:

For a full list of changes made since the previous version, see thecommits.

The working group maintainsa 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 theGitHub repositoryand take part in the discussions.

This document was published by theMedia Working Groupas an Editor's Draft.

Publication as an Editor's Draft does not imply endorsement byW3Cand 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 work in progress.

This document was produced by a group operating under the W3CPatent Policy. W3Cmaintains 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 which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of theW3CPatent Policy.

This document is governed by the 03 November 2023W3CProcess Document.

1. Introduction

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 SourceBufferobjects. Applications append data segments to theSourceBuffer objects, and can adapt the quality of appended data based on system performance and other factors. Data from theSourceBufferobjects 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].

Media Source Pipeline Model Diagram
Figure1 Media Source Pipeline Model Diagram

1.1 Goals

This specification was designed with the following goals in mind:

This specification defines:

2. Definitions

Active Track Buffers

Thetrack buffersthat providecoded framesfor theenabled audioTracks,theselected videoTracks,and the"showing"or "hidden"textTracks.All these tracks are associated withSourceBufferobjects in the activeSourceBufferslist.

Append Window

Apresentation timestamprange used to filter outcoded frameswhile appending. The append window represents a single continuous time range with a single start time and end time. Coded frames withpresentation timestampwithin this range are allowed to be appended to theSourceBufferwhile coded frames outside this range are filtered out. The append window start and end times are controlled by theappendWindowStartandappendWindowEnd attributes respectively.

Coded Frame

A unit of media data that has apresentation timestamp,adecode timestamp, and acoded frame duration.

Coded Frame Duration

The duration of acoded frame.For video and text, the duration indicates how long the video frame or textSHOULDbe 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 acoded framepresentation timestampand itscoded frame duration.It represents thepresentation timestampthat immediately follows the coded frame.

Coded Frame Group

A group ofcoded framesthat are adjacent and have monotonically increasing decode timestampswithout any gaps. Discontinuities detected by thecoded frame processingalgorithm andabort()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 thepresentation timestampof the earliest frame, inpresentation order,that is dependant on this frame). If frames can be decoded out of presentation order,then the decode timestampMUSTbe present in or derivable from the byte stream. The user agentMUSTrun theappend erroralgorithm if this is not the case. If frames cannot be decoded out ofpresentation orderand a decode timestamp is not present in the byte stream, then the decode timestamp is equal to thepresentation timestamp.

Initialization Segment

A sequence of bytes that contain all of the initialization information required to decode a sequence ofmedia segments.This includes codec initialization data, Track IDmappings for multiplexed segments, and timestamp offsets (e.g., edit lists).

Note

Thebyte stream format specificationsin 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 themedia timeline.Media segments are always associated with the most recently appendedinitialization segment.

Note

Thebyte stream format specificationsin the byte stream format registry [MSE-REGISTRY] contain format specific examples.

MediaSource object URL

AMediaSourceobject URL is a uniqueblob URLcreated by createObjectURL().It is used to attach aMediaSourceobject to an HTMLMediaElement.

These URLs are the same as ablob URLs,except that anything in the definition of that feature that refers toFileandBlobobjects is hereby extended to also apply toMediaSourceobjects.

Theoriginof the MediaSource object URL is therelevant settings objectof thisduring the call tocreateObjectURL().

Note

For example, theoriginof the MediaSource object URL affects the way that the media element isconsumed by canvas.

Parent Media Source

The parent media source of aSourceBufferobject is theMediaSourceobject that created it.

Presentation Start Time

The presentation start time is the earliest time point in the presentation and specifies the initialplayback positionandearliest possible position.All presentations created using this specification have a presentation start time of 0.

Note

For the purposes of determining ifHTMLMediaElement's bufferedcontains aTimeRangesthat includes the current playback position, implementationsMAYchoose to allow a current playback position at or afterpresentation start timeand before the firstTimeRangesto play the firstTimeRangesif thatTimeRangesstarts within a reasonably short time, like 1 second, afterpresentation start time.This allowance accommodates the reality that muxed streams commonly do not begin all tracks precisely at presentation start time.ImplementationsMUSTreport the actual buffered range, regardless of this allowance.

Presentation Interval

The presentation interval of acoded frameis the time interval from its presentation timestampto thepresentation timestampplus thecoded frame's duration.For example, if a coded frame has a presentation timestamp of 10 seconds and acoded frame durationof 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 thatcoded framesare rendered in the presentation. The presentation order is achieved by orderingcoded framesin monotonically increasing order by theirpresentation timestamps.

Presentation Timestamp

A reference to a specific time in the presentation. The presentation timestamp in a coded frameindicates when the frameSHOULDbe rendered.

Random Access Point

A position in amedia segmentwhere 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 specificbyte stream format specificationthat describes the format of the byte stream accepted by aSourceBufferinstance. Thebyte stream format specification,for aSourceBufferobject, is initially selected based on the typepassed 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 moreSourceBufferobjects owned by a singleMediaSourceinstance.

ImplementationsMUSTsupport at least 1MediaSourceobject 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 objectsMUSTsupport 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 theTrack ID,codec configuration, and other metadata for a single track. Each track description inside a singleinitialization segmenthas a uniqueTrack ID.The user agentMUSTrun theappend erroralgorithm if theTrack IDis 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 atrack descriptionidentifies which sections of amedia segmentbelong to that track.

3. MediaSourceinterface

TheMediaSourceinterface represents a source of media data for an HTMLMediaElement.It keeps track of thereadyStatefor this source as well as a list ofSourceBufferobjects 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 theSourceBufferobjects in sourceBuffersto add media data to this source. The HTMLMediaElement fetches this media data from theMediaSourceobject when it is needed during playback.

EachMediaSourceobject has a[[live seekable range]]internal slot that stores anormalized TimeRanges object.It is initialized to an emptyTimeRangesobject when theMediaSourceobject is created, is maintained bysetLiveSeekableRange()and clearLiveSeekableRange(),and is used in10. HTMLMediaElement Extensions to modifyHTMLMediaElement'sseekablebehavior.

EachMediaSourceobject has a[[has ever been attached]]internal slot that stores aboolean.It is initialized to false when theMediaSourceobject is created, and is set true in the extended HTMLMediaElement'sresource fetch algorithmas described in theattaching to a media elementalgorithm. The extendedresource fetch algorithmuses this internal slot to conditionally fail attachment of aMediaSourceusing aMediaSourceHandle set on aHTMLMediaElement'ssrcObjectattribute.

WebIDLenumReadyState{
"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, butMediaSource's endOfStream()has been called.
Issue 276:MSE-in-Workers: Consider adding a "closing" readyState to explain new `InvalidStateError` exception when closing underway
WebIDLenumEndOfStreamError{
"network",
"decode",
};
network

Terminates playback and signals that a network error has occurred.

Note

JavaScript applicationsSHOULDuse 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.

Note

JavaScript applicationsSHOULDuse 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)]
interfaceMediaSource:EventTarget{
constructor();

[SameObject,Exposed=DedicatedWorker]
readonly attributeMediaSourceHandlehandle;
readonly attributeSourceBufferListsourceBuffers;
readonly attributeSourceBufferListactiveSourceBuffers;
readonly attributeReadyStatereadyState;

attributeunrestricted doubleduration;
attributeEventHandleronsourceopen;
attributeEventHandleronsourceended;
attributeEventHandleronsourceclose;

static readonly attributebooleancanConstructInDedicatedWorker;

SourceBufferaddSourceBuffer(DOMStringtype);
undefinedremoveSourceBuffer(SourceBuffersourceBuffer);
undefinedendOfStream(optionalEndOfStreamErrorerror);
undefinedsetLiveSeekableRange(doublestart,doubleend);
undefinedclearLiveSeekableRange();
staticbooleanisTypeSupported(DOMStringtype);
};

3.1 handleattribute

Contains a handle useful for attachment of a dedicated workerMediaSourceobject to an HTMLMediaElementviasrcObject.The handle remains the same object for thisMediaSourceobject across accesses of this attribute, but it is distinct for eachMediaSourceobject.

Note

This specification may eventually enable visibility of this attribute onMediaSource 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:

  1. If the handle for thisMediaSourceobject has not yet been created, then run the following steps:
    1. Letcreated handlebe the result of creating a new MediaSourceHandleobject and associated resources, linked internally to this MediaSource.
    2. Update the attribute to becreated handle.
  2. Return theMediaSourceHandleobject that is this attribute's value.

3.2 sourceBuffersattribute

Contains the list ofSourceBufferobjects associated with thisMediaSource.When MediaSource'sreadyStateequals "closed"this list will be empty. OncereadyStatetransitions to "open" SourceBuffer objects can be added to this list by usingaddSourceBuffer().

3.3 activeSourceBuffersattribute

Contains the subset ofsourceBuffersthat are providing the selectedvideo track, theenabledaudio track(s), and the "showing"or"hidden"text track(s).

SourceBufferobjects in this listMUSTappear in the same order as they appear in the sourceBuffersattribute; e.g., if only sourceBuffers[0] and sourceBuffers[3] are inactiveSourceBuffers,then activeSourceBuffers[0] MUSTequal sourceBuffers[0] and activeSourceBuffers[1]MUSTequal sourceBuffers[3].

Note

Section3.15.5 Changes to selected/enabled track statedescribes how this attribute gets updated.

3.4 readyStateattribute

Indicates the current state of theMediaSourceobject. When theMediaSource is createdreadyStateMUSTbe set to "closed".

3.5 durationattribute

Allows the web application to set the presentation duration. The duration is initially set to NaN when theMediaSourceobject is created.

On getting, run the following steps:

  1. If thereadyStateattribute is "closed"then return NaN and abort these steps.
  2. Return the current value of the attribute.

On setting, run the following steps:

  1. If the value being set is negative or NaN then throw aTypeErrorexception and abort these steps.
  2. If thereadyStateattribute is not "open"then throw anInvalidStateErrorexception and abort these steps.
  3. If theupdatingattribute equals true on anySourceBufferin sourceBuffers,then throw anInvalidStateErrorexception and abort these steps.
  4. Run theduration changealgorithm withnew durationset to the value being assigned to this attribute.
    Note

    Theduration changealgorithm will adjustnew durationhigher if there is any currently buffered coded frame with a higher end time.

    Note

    appendBuffer()andendOfStream()can update the duration under certain circumstances.

3.6 canConstructInDedicatedWorkerattribute

Returns true.

Note

This attribute enables main thread and dedicated worker feature detection of support for creating and using aMediaSourceobject in a dedicated worker, and mitigates the need for higher latency detection polyfills like attempting creation of aMediaSourceobject from a dedicated worker, especially if the feature is not supported.

3.7 addSourceBuffer()method

Adds a newSourceBuffertosourceBuffers.

  1. Iftypeis an empty string then throw aTypeErrorexception and abort these steps.
  2. Iftypecontains a MIME type that is not supported or contains a MIME type that is not supported with the types specified for the otherSourceBufferobjects in sourceBuffers,then throw aNotSupportedErrorexception and abort these steps.
  3. If the user agent can't handle any more SourceBuffer objects or if creating a SourceBuffer based ontypewould result in an unsupportedSourceBuffer configuration, then throw aQuotaExceededErrorexception and abort these steps.
    Note

    For example, a user agentMAYthrow aQuotaExceededErrorexception 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.

  4. If thereadyStateattribute is not in the "open"state then throw anInvalidStateErrorexception and abort these steps.
  5. Letbufferbe a new instance of aManagedSourceBufferifthisis a ManagedMediaSource,or aSourceBufferotherwise, with their respective associated resources.
  6. Setbuffer's[[generate timestamps flag]]to the value in the "Generate Timestamps Flag" column of theMedia Source Extensions™ Byte Stream Format Registryentry that is associated with type.
  7. Ifbuffer's[[generate timestamps flag]]is true, setbuffer's modeto "sequence".Otherwise, setbuffer's modeto "segments".
  8. Appendbuffertothis'ssourceBuffers.
  9. Queue a tasktofire an eventnamedaddsourcebufferatthis's sourceBuffers.
  10. Returnbuffer.

3.8 removeSourceBuffer()method

Removes aSourceBufferfromsourceBuffers.

  1. IfsourceBufferspecifies an object that is not in sourceBuffersthen throw aNotFoundErrorexception and abort these steps.
  2. If thesourceBuffer.updatingattribute equals true, then run the following steps:
    1. Abort thebuffer appendalgorithm if it is running.
    2. Set thesourceBuffer.updatingattribute to false.
    3. Queue a tasktofire an eventnamedabortatsourceBuffer.
    4. Queue a tasktofire an eventnamedupdateendatsourceBuffer.
  3. LetSourceBuffer audioTracks listequal theAudioTrackListobject returned bysourceBuffer.audioTracks.
  4. If theSourceBuffer audioTracks listis not empty, then run the following steps:
    1. For eachAudioTrackobject in theSourceBuffer audioTracks list,run the following steps:
      1. Set thesourceBufferattribute on theAudioTrackobject to null.
      2. Remove theAudioTrackobject from theSourceBuffer audioTracks list.
        Note

        This should triggerAudioTrackList[HTML] logic toqueue a taskto fire an eventnamedremovetrackusingTrackEvent with thetrackattribute initialized to theAudioTrack object, at theSourceBuffer audioTracks list.If theenabled attribute on theAudioTrackobject was true at the beginning of this removal step, then this should also triggerAudioTrackList[HTML] logic toqueue a tasktofire an eventnamedchangeat the SourceBuffer audioTracks list.

      3. Use themirror if necessaryalgorithm to run the following steps in Window,to remove theAudioTrackobject (or instead, theWindowmirror of it if theMediaSourceobject was constructed in a DedicatedWorkerGlobalScope) from the media element:
        1. LetHTMLMediaElement audioTracks listequal the AudioTrackListobject returned by theaudioTracks attribute on the HTMLMediaElement.
        2. Remove theAudioTrackobject from theHTMLMediaElement audioTracks list.
          Note

          This should triggerAudioTrackList[HTML] logic toqueue a task tofire an eventnamedremovetrackusing TrackEventwith thetrackattribute initialized to the AudioTrackobject, at theHTMLMediaElement audioTracks list.If the enabledattribute on theAudioTrackobject was true at the beginning of this removal step, then this should also trigger AudioTrackList[HTML] logic toqueue a tasktofire an event namedchangeat theHTMLMediaElement audioTracks list.

  5. LetSourceBuffer videoTracks listequal theVideoTrackListobject returned bysourceBuffer.videoTracks.
  6. If theSourceBuffer videoTracks listis not empty, then run the following steps:
    1. For eachVideoTrackobject in theSourceBuffer videoTracks list,run the following steps:
      1. Set thesourceBufferattribute on theVideoTrackobject to null.
      2. Remove theVideoTrackobject from theSourceBuffer videoTracks list.
        Note

        This should triggerVideoTrackList[HTML] logic toqueue a taskto fire an eventnamedremovetrackusingTrackEvent with thetrackattribute initialized to theVideoTrack object, at theSourceBuffer videoTracks list.If theselected attribute on theVideoTrackobject was true at the beginning of this removal step, then this should also triggerVideoTrackList[HTML] logic toqueue a tasktofire an eventnamedchangeat the SourceBuffer videoTracks list.

      3. Use themirror if necessaryalgorithm to run the following steps in Window,to remove theVideoTrackobject (or instead, theWindowmirror of it if theMediaSourceobject was constructed in a DedicatedWorkerGlobalScope) from the media element:
        1. LetHTMLMediaElement videoTracks listequal the VideoTrackListobject returned by thevideoTracks attribute on the HTMLMediaElement.
        2. Remove theVideoTrackobject from theHTMLMediaElement videoTracks list.
          Note

          This should triggerVideoTrackList[HTML] logic toqueue a task tofire an eventnamedremovetrackusing TrackEventwith thetrackattribute initialized to the VideoTrackobject, at theHTMLMediaElement videoTracks list.If the selectedattribute on theVideoTrackobject was true at the beginning of this removal step, then this should also trigger VideoTrackList[HTML] logic toqueue a tasktofire an event namedchangeat theHTMLMediaElement videoTracks list.

  7. LetSourceBuffer textTracks listequal theTextTrackListobject returned bysourceBuffer.textTracks.
  8. If theSourceBuffer textTracks listis not empty, then run the following steps:
    1. For eachTextTrackobject in theSourceBuffer textTracks list,run the following steps:
      1. Set thesourceBufferattribute on theTextTrackobject to null.
      2. Remove theTextTrackobject from theSourceBuffer textTracks list.
        Note

        This should triggerTextTrackList[HTML] logic toqueue a taskto fire an eventnamedremovetrackusingTrackEventwith thetrackattribute initialized to theTextTrackobject, at theSourceBuffer textTracks list.If themodeattribute on the TextTrackobject was"showing"or"hidden"at the beginning of this removal step, then this should also triggerTextTrackList[HTML] logic toqueue a taskto fire an eventnamedchangeat theSourceBuffer textTracks list.

      3. Use themirror if necessaryalgorithm to run the following steps in Window,to remove theTextTrackobject (or instead, theWindowmirror of it if theMediaSourceobject was constructed in a DedicatedWorkerGlobalScope) from the media element:
        1. LetHTMLMediaElement textTracks listequal the TextTrackListobject returned by thetextTracks attribute on the HTMLMediaElement.
        2. Remove theTextTrackobject from theHTMLMediaElement textTracks list.
          Note

          This should triggerTextTrackList[HTML] logic toqueue a taskto fire an eventnamedremovetrackusingTrackEvent with thetrackattribute initialized to theTextTrack object, at theHTMLMediaElement textTracks list.If the modeattribute on theTextTrackobject was"showing"or"hidden"at the beginning of this removal step, then this should also trigger TextTrackList[HTML] logic toqueue a tasktofire an event namedchangeat theHTMLMediaElement textTracks list.

  9. IfsourceBufferis inactiveSourceBuffers,then removesourceBuffer fromactiveSourceBuffersandqueue a tasktofire an eventnamed removesourcebufferat theSourceBufferListreturned by activeSourceBuffers.
  10. RemovesourceBufferfromsourceBuffersandqueue a tasktofire an eventnamedremovesourcebufferat theSourceBufferListreturned by sourceBuffers.
  11. Destroy all resources forsourceBuffer.

3.9 endOfStream()method

Signals the end of the stream.

  1. If thereadyStateattribute is not in the "open"state then throw anInvalidStateErrorexception and abort these steps.
  2. If theupdatingattribute equals true on anySourceBufferin sourceBuffers,then throw anInvalidStateErrorexception and abort these steps.
  3. Run theend of streamalgorithm with the error parameter set to error.

3.10 setLiveSeekableRange()method

Updates[[live seekable range]]that is used in section 10. HTMLMediaElement Extensionsto modifyHTMLMediaElement's seekablebehavior.

When this method is invoked, the user agent must run the following steps:

  1. If thereadyStateattribute is not "open"then throw anInvalidStateErrorexception and abort these steps.
  2. Ifstartis negative or greater thanend,then throw aTypeError exception and abort these steps.
  3. Set[[live seekable range]]to be a newnormalized TimeRanges objectcontaining a single range whose start position is startand end position isend.

3.11 clearLiveSeekableRange()method

Updates[[live seekable range]]that is used in section 10. HTMLMediaElement Extensionsto modifyHTMLMediaElement's seekablebehavior.

When this method is invoked, the user agent must run the following steps:

  1. If thereadyStateattribute is not "open"then throw anInvalidStateErrorexception and abort these steps.
  2. If[[live seekable range]]contains a range, then set [[live seekable range]]to be a new emptyTimeRangesobject.

3.12 isTypeSupported()method

Check to see whether theMediaSourceis capable of creatingSourceBuffer objects for the specified MIME type.

Note

If true is returned from this method, it only indicates that theMediaSource implementation is capable of creatingSourceBufferobjects for the specified MIME type. AnaddSourceBuffer()callSHOULDstill fail if sufficient resources are not available to support the addition of a newSourceBuffer.

Note

This method returning true implies thatHTMLMediaElement's canPlayType()will return "maybe" or "probably" since it does not make sense for aMediaSourceto support a type the HTMLMediaElement knows it cannot play.

When this method is invoked, the user agent must run the following steps:

  1. Iftypeis an empty string, then return false.
  2. Iftypedoes not contain a valid MIME type string, then return false.
  3. Iftypecontains a media type or media subtype that the MediaSource does not support, then return false.
  4. Iftypecontains a codec that the MediaSource does not support, then return false.
  5. If the MediaSource does not support the specified combination of media type, media subtype, and codecs then return false.
  6. Return true.

3.13 Event Summary

Event name Interface Dispatched when...
sourceopen Event MediaSource'sreadyStatetransitions from "closed" to"open"or from"ended"to"open".
sourceended Event MediaSource'sreadyStatetransitions from "open" to"ended".
sourceclose Event MediaSource'sreadyStatetransitions from "open" to"closed"or"ended"to"closed".

3.14 Cross-context communication model

When aWindowHTMLMediaElementis attached to aDedicatedWorkerGlobalScope MediaSource,each context has algorithms that depend on information from the other.

Note

HTMLMediaElementis exposed only toWindowcontexts, butMediaSourceand related objects defined in this specification are exposed inWindowand DedicatedWorkerGlobalScopecontexts. This lets applications construct a MediaSourceobject in either of those types of context and attach it to an HTMLMediaElementobject in aWindowcontext using aMediaSource object URLor aMediaSourceHandleas described in theattaching to a media elementalgorithm. A MediaSourceobject is notTransferable;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 aWindowmedia element to aDedicatedWorkerGlobalScope MediaSource.While the model describes communication using message passing, implementationsMAYchoose to communicate in potentially faster ways, such as using shared memory and locks. Attachments to aWindowMediaSourcesynchronously have the information already without communicating it across contexts.

AMediaSourcethat is constructed in aDedicatedWorkerGlobalScopehas a [[port to main]]internal slot that stores a MessagePortsetup during attachment and nulled during detachment. AWindow [[port to main]]is always null.

AnHTMLMediaElementextended by this specification and attached to a DedicatedWorkerGlobalScopeMediaSourcesimilarly has a[[port to worker]]internal slot that stores aMessagePort and a[[channel with worker]]internal slot that stores aMessageChannel,both setup during attachment and nulled during detachment. Both[[port to worker]]and[[channel with worker]]are null unless attached to aDedicatedWorkerGlobalScope MediaSource.

Algorithms in this specification that need to communicate information from aWindow HTMLMediaElementto an attachedDedicatedWorkerGlobalScopeMediaSource,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.

3.15 Algorithms

3.15.1 Attaching to a media element

There are distinct mechanisms for attaching aMediaSourceto a media element depending on where theMediaSourceobject was constructed, in aWindowversus in aDedicatedWorkerGlobalScope:

If theresource fetch algorithmwas invoked with a media provider object that is a MediaSourceobject, aMediaSourceHandleobject or a URL record whose object is aMediaSourceobject, then let mode be local, skip the first step in theresource fetch algorithm(which may otherwise set mode to remote) and continue the execution of theresource fetch algorithm.

Note

The first step of theresource fetch algorithmis expected to eventually align with selecting local mode for URL records whose objects are media provider objects. The intent is that if theHTMLMediaElement'ssrcattribute or selected childsource'ssrcattribute is ablob:URL matching a MediaSource object URLwhen the respectivesrcattribute was last changed, then thatMediaSourceobject is used as the media provider object and current media resource in the local mode logic in theresource 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 aMediaSourceobject.

At the beginning of the "Otherwise (mode is local)" section of theresource fetch algorithm,execute the additional steps, below.

Note

Relative to the action which triggered the media element's resource selection algorithm, these steps are asynchronous. Theresource fetch algorithmis 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.

  1. If theresource fetch algorithmwas invoked with a media provider object that is aMediaSourceobject, aMediaSourceHandleobject or a URL record whose object is aMediaSourceobject, then:
    If the media provider object is a URL record whose object is aMediaSource that was constructed in aDedicatedWorkerGlobalScope,such as would occur if attempting to use aMediaSource object URLfrom a DedicatedWorkerGlobalScopeMediaSource
    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 theresource fetch algorithm'smedia data processing steps list.
    Note
    This prevents usingMediaSource object URLsfor DedicatedWorker MediaSource attachments. TransferringMediaSource'shandlefrom the DedicatedWorker to the Window context and assigning it to the media element's srcObjectattribute is the only way to attach such a MediaSource.
    If the media provider object is aMediaSourceHandlewhose [[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 theresource fetch algorithm'smedia data processing steps list.
    If the media provider object is aMediaSourceHandlewhose underlying MediaSource'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 theresource fetch algorithm'smedia data processing steps list.
    Note
    This prevents loading an underlyingMediaSourcemore than once using a MediaSourceHandle,even if theMediaSourcewas constructed on Windowand had been loaded previously using aMediaSource object URL. This doesn't preclude subsequent use of aMediaSource object URLfor a WindowMediaSourcefrom succeeding though.
    IfreadyStateis 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 theresource fetch algorithm'smedia data processing steps list.
    Otherwise
    1. Set theMediaSource's[[has ever been attached]] internal slot to true.
    2. Set the media element'sdelaying-the-load-event-flagto false.
    3. If theMediaSourcewas constructed in a DedicatedWorkerGlobalScope,then setup worker attachment communication and open theMediaSource:
      1. Set[[channel with worker]]to be a new MessageChannel.
      2. Set[[port to worker]]to the port1value of[[channel with worker]].
      3. ExecuteStructuredSerializeWithTransferwith the port2of[[channel with worker]]as both the value and the sole member of thetransferList, and let the result beserialized port2.
      4. Queue a taskon theMediaSource's DedicatedWorkerGlobalScopethat will
        1. ExecuteStructuredDeserializeWithTransferwithserialized port2andDedicatedWorkerGlobalScope'srealm,and set[[port to main]]to be the resulting deserialized clone of the transferred port2value of[[channel with worker]].
        2. Set thereadyStateattribute to "open".
        3. Queue a tasktofire an eventnamedsourceopenat theMediaSource.
      Otherwise, theMediaSourcewas constructed in aWindow:
      1. Set[[channel with worker]]null.
      2. Set[[port to worker]]null.
      3. Set[[port to main]]null.
      4. Set thereadyStateattribute to "open".
      5. Queue a tasktofire an eventnamedsourceopenat the MediaSource.
    4. Continue theresource fetch algorithmby running the remaining "Otherwise (mode is local)"steps, with these requirements:
      1. Text in theresource fetch algorithmor themedia data processing steps listthat refers to "the download", "bytes received", or "whenever new data for the current media resource becomes available" refers to data passed in via appendBuffer().
      2. References to HTTP in theresource fetch algorithmand the media data processing steps listshall not apply because the HTMLMediaElement does not fetch media data via HTTP when a MediaSourceis attached.
Note

An attached MediaSource does not use the remote mode steps in theresource 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.

3.15.2 Detaching from a media element

The following steps are run in any case where the media element is going to transition toNETWORK_EMPTYandqueue a tasktofire an eventnamed emptiedat the media element. These stepsSHOULDbe run right before the transition.

  1. If theMediaSourcewas constructed in aDedicatedWorkerGlobalScope:
    1. Notify theMediaSourceusing an internaldetachmessage posted to [[port to worker]].
    2. Set[[port to worker]]null.
    3. Set[[channel with worker]]null.
    4. The implicit message handler for thisdetachnotification runs the remainder of these steps in theDedicatedWorkerGlobalScopeMediaSource.
    Otherwise, theMediaSourcewas constructed in aWindow:
    Continue the remainder of these steps on theWindowMediaSource.
  2. Set[[port to main]]null.
  3. Set thereadyStateattribute to "closed".
  4. Ifthisis aManagedMediaSource,then setstreaming attribute tofalse.
  5. Updatedurationto NaN.
  6. Remove all theSourceBufferobjects fromactiveSourceBuffers.
  7. Queue a tasktofire an eventnamedremovesourcebufferat activeSourceBuffers.
  8. Remove all theSourceBufferobjects fromsourceBuffers.
  9. Queue a tasktofire an eventnamedremovesourcebufferat sourceBuffers.
  10. Queue a tasktofire an eventnamedsourcecloseat theMediaSource.
Note

Going forward, this algorithm is intended to be externally called and run in any case where the attachedMediaSource,if any, must be detached from the media element. It MAYbe called on HTMLMediaElement [HTML] operations like load() andresource fetch algorithmfailures in addition to, or in place of, when the media element transitions toNETWORK_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.

3.15.3 Seeking

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:

  1. Note

    The media element looks formedia segmentscontaining thenew playback positionin eachSourceBufferobject in activeSourceBuffers.Any position within aTimeRangesin the current value of theHTMLMediaElement'sbufferedattribute has all necessary media segments buffered for that position.

    Ifnew playback positionis not in anyTimeRangesofHTMLMediaElement's buffered
    1. If theHTMLMediaElement'sreadyStateattribute is greater thanHAVE_METADATA,then set the HTMLMediaElement'sreadyStateattribute to HAVE_METADATA.
      Note

      PerHTMLMediaElement ready states[HTML] logic,HTMLMediaElement's readyStatechanges may trigger events on the HTMLMediaElement.

    2. The media element waits until anappendBuffer()call causes thecoded frame processingalgorithm to set the HTMLMediaElement'sreadyStateattribute to a value greater thanHAVE_METADATA.
      Note

      The web application can usebufferedand HTMLMediaElement'sbufferedto determine what the media element needs to resume playback.

    Otherwise
    Continue
    Note

    If thereadyStateattribute is "ended"and the new playback positionis within aTimeRangescurrently in HTMLMediaElement'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 thannew playback position.This condition should only occur due to logic in bufferedwhenreadyStateis "ended".

  2. The media element resets all decoders and initializes each one with data from the appropriateinitialization segment.
  3. The media element feedscoded framesfrom theactive track buffersinto the decoders starting with the closestrandom access pointbefore thenew playback position.
  4. Resume theseek algorithmat the "Await a stable state" step.

3.15.4 SourceBuffer Monitoring

The following steps are periodically run during playback to make sure that all of the SourceBufferobjects inactiveSourceBuffershaveenough data to ensure uninterrupted playback.Changes toactiveSourceBuffersalso cause these steps to run because they affect the conditions that trigger state transitions.

Havingenough data to ensure uninterrupted playbackis 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 theHAVE_ENOUGH_DATAready state. These transitions indicate when the user agent believes it has enough data buffered or it needs more data respectively.

Note

An implementationMAYchoose 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 usedMAY change during playback so web applicationsSHOULDonly rely on the value of HTMLMediaElement'sreadyStateto determine whether more data is needed or not.

Note

When the media element needs more data, the user agentSHOULDtransition it from HAVE_ENOUGH_DATAtoHAVE_FUTURE_DATAearly 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 theHTMLMediaElement'sreadyStateattribute equals HAVE_NOTHING:
  1. Abort these steps.
IfHTMLMediaElement'sbuffereddoes not contain a TimeRangesfor the current playback position:
  1. Set theHTMLMediaElement'sreadyStateattribute to HAVE_METADATA.
    Note

    PerHTMLMediaElement ready states[HTML] logic,HTMLMediaElement's readyStatechanges may trigger events on the HTMLMediaElement.

  2. Abort these steps.
IfHTMLMediaElement'sbufferedcontains aTimeRanges that includes the current playback position andenough data to ensure uninterrupted playback:
  1. Set theHTMLMediaElement'sreadyStateattribute to HAVE_ENOUGH_DATA.
    Note

    PerHTMLMediaElement ready states[HTML] logic,HTMLMediaElement's readyStatechanges may trigger events on the HTMLMediaElement.

  2. Playback may resume at this point if it was previously suspended by a transition toHAVE_CURRENT_DATA.
  3. Abort these steps.
IfHTMLMediaElement'sbufferedcontains aTimeRanges that includes the current playback position and some time beyond the current playback position, then run the following steps:
  1. Set theHTMLMediaElement'sreadyStateattribute to HAVE_FUTURE_DATA.
    Note

    PerHTMLMediaElement ready states[HTML] logic,HTMLMediaElement's readyStatechanges may trigger events on the HTMLMediaElement.

  2. Playback may resume at this point if it was previously suspended by a transition toHAVE_CURRENT_DATA.
  3. Abort these steps.
IfHTMLMediaElement'sbufferedcontains aTimeRanges that ends at the current playback position and does not have a range covering the time immediately after the current position:
  1. Set theHTMLMediaElement'sreadyStateattribute to HAVE_CURRENT_DATA.
    Note

    PerHTMLMediaElement ready states[HTML] logic,HTMLMediaElement's readyStatechanges may trigger events on the HTMLMediaElement.

  2. Playback is suspended at this point since the media element doesn't have enough data to advance themedia timeline.
  3. Abort these steps.

3.15.5 Changes to selected/enabled track state

During playbackactiveSourceBuffersneeds to be updated if the selectedvideo track, theenabledaudio track(s), or a text trackmodechanges. When one or more of these changes occur the following steps need to be followed. Also, whenMediaSourcewas constructed in a DedicatedWorkerGlobalScope,then each change that occurs to aWindowmirror of a track created previously by the implicit handler for the internalcreate track mirrormessageMUSTalso be made to the correspondingDedicatedWorkerGlobalScope track using an internalupdate track statemessage posted to [[port to worker]]whose implicit handler makes the change and runs the following steps. Likewise, each change that occurs to a DedicatedWorkerGlobalScopetrackMUSTalso be made to the correspondingWindow mirror of the track using an internalupdate track statemessage 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:
  1. If theSourceBufferassociated with the previously selected video track is not associated with any other enabled tracks, run the following steps:
    1. Remove theSourceBufferfromactiveSourceBuffers.
    2. Queue a tasktofire an eventnamedremovesourcebufferat activeSourceBuffers
  2. If theSourceBufferassociated with the newly selected video track is not already inactiveSourceBuffers,run the following steps:
    1. Add theSourceBuffertoactiveSourceBuffers.
    2. Queue a tasktofire an eventnamedaddsourcebufferat activeSourceBuffers
If an audio track becomes disabled and theSourceBufferassociated with this track is not associated with any other enabled or selected track, then run the following steps:
  1. Remove theSourceBufferassociated with the audio track from activeSourceBuffers
  2. Queue a tasktofire an eventnamedremovesourcebufferat activeSourceBuffers
If an audio track becomes enabled and theSourceBufferassociated with this track is not already inactiveSourceBuffers,then run the following steps:
  1. Add theSourceBufferassociated with the audio track to activeSourceBuffers
  2. Queue a tasktofire an eventnamedaddsourcebufferat activeSourceBuffers
If a text trackmodebecomes"disabled" and theSourceBufferassociated with this track is not associated with any other enabled or selected track, then run the following steps:
  1. Remove theSourceBufferassociated with the text track from activeSourceBuffers
  2. Queue a tasktofire an eventnamedremovesourcebufferat activeSourceBuffers
If a text trackmodebecomes"showing"or "hidden"and theSourceBufferassociated with this track is not already inactiveSourceBuffers,then run the following steps:
  1. Add theSourceBufferassociated with the text track to activeSourceBuffers
  2. Queue a tasktofire an eventnamedaddsourcebufferat activeSourceBuffers

3.15.6 Duration change

Follow these steps whendurationneeds to change to anew duration.

  1. If the current value ofdurationis equal tonew duration,then return.
  2. Ifnew durationis less than the highestpresentation timestampof any bufferedcoded framesfor allSourceBufferobjects in sourceBuffers,then throw anInvalidStateErrorexception and abort these steps.
    Note

    Duration reductions that would truncate currently buffered media are disallowed. When truncation is necessary, useremove()to reduce the buffered range before updatingduration.

  3. Lethighest end timebe the largesttrack buffer ranges end time across all thetrack buffersacross allSourceBufferobjects in sourceBuffers.
  4. Ifnew durationis less thanhighest end time,then
    Note

    This condition can occur because thecoded frame removalalgorithm preserves coded frames that start before the start of the removal range.

    1. Updatenew durationto equalhighest end time.
  5. Updatedurationtonew duration.
  6. Use themirror if necessaryalgorithm to run the following steps inWindow to update the media element's duration:
    1. Update the media element'sdurationtonew duration.
    2. Run theHTMLMediaElement duration change algorithm.

3.15.7 End of stream

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 anerrorparameter that indicates whether an error will be signalled.

  1. Change thereadyStateattribute value to "ended".
  2. Queue a tasktofire an eventnamedsourceendedat theMediaSource.
  3. Iferroris not set
    1. Run theduration changealgorithm withnew durationset to the largesttrack buffer rangesend time across all the track buffersacross allSourceBufferobjects in sourceBuffers.
      Note

      This 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.

    2. Notify the media element that it now has all of the media data.
    Iferroris set to "network"
    Use themirror if necessaryalgorithm to run the following steps in Window:
    If theHTMLMediaElement'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 theresource fetch algorithm'smedia data processing steps list.
    If theHTMLMediaElement'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 theresource fetch algorithm'smedia data processing steps list.
    Iferroris set to "decode"
    Use themirror if necessaryalgorithm to run the following steps in Window:
    If theHTMLMediaElement'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 theresource fetch algorithm'smedia data processing steps list.
    If theHTMLMediaElement'sreadyStateattribute is greater thanHAVE_NOTHING
    Run themedia data is corruptedsteps of theresource fetch algorithm'smedia data processing steps list.

3.15.8 Mirror if necessary

This algorithm is used to run steps onWindowfrom aMediaSourceattached from either the sameWindowor from aDedicatedWorkerGlobalScope,usually to update the state of the attachedHTMLMediaElement.This algorithm takes asteps parameter that lists the steps to run onWindow.

If theMediaSourcewas constructed in aDedicatedWorkerGlobalScope:
Post an internalmirror on windowmessage to[[port to main]]whose implicit handler inWindowwill runsteps.Return control to the caller without awaiting that handler's receipt of the message.
Note
The purpose of the mirror message mechanism is to ensure that:
  1. stepsrun asynchronously as their own task onWindowrather than these stepssomehow happening in the middle of some otherWindowtask's execution, and
  2. stepsare run without blocking the synchronous execution and return of this algorithm onDedicatedWorkerGlobalScope.
Otherwise:
Runsteps.

4. MediaSourceHandleinterface

TheMediaSourceHandleinterface represents a proxy for aMediaSourceobject that is useful for attaching aDedicatedWorkerGlobalScopeMediaSourceto aWindow HTMLMediaElementusingsrcObjectas described in theattaching to a media elementalgorithm.

Note

This distinct object is necessary to attach a cross-contextMediaSourceto a media element becauseMediaSourceobjects themselves are not transferable since they are event targets.

EachMediaSourceHandleobject has a[[has ever been assigned as srcobject]]internal slot that stores aboolean.It is initialized to false when theMediaSourceHandleobject is created, is set true in the extendedHTMLMediaElement'ssrcObjectsetter as described in section10. HTMLMediaElement Extensions,and if true, prevents successful transfer of theMediaSourceHandleas described in section4.1 Transfer.

MediaSourceHandleobjects areTransferable,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)]
interfaceMediaSourceHandle{};

4.1 Transfer

TheMediaSourceHandletransfer stepsandtransfer-receiving stepsrequire the implementation to maintain an implicit internal slot referencing the underlying MediaSourceto enableattaching to a media elementusing srcObjectand consequent setup of an attachment'scross-context communication model.

Note

Implementors should be aware that assumption of "move" semantics implied by Transferableis not always reality. For example, extensions or internal implementations of postMessage using broadcast may cause unintended multiple recipients of a transferredMediaSourceHandle.For this reason, implementations are guided to not resolve which potential clone of a transferredMediaSourceHandleis still valid for attachment until and unless any handle for the underlyingMediaSourceobject is used in the asynchronous portion of the media element's resource selection algorithm. This is similar to the existing behavior for attachment viaMediaSource 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).

ImplementationsMUSTsupport at most one attachment (load) via srcObjectever for theMediaSourceobject underlying a MediaSourceHandle,regardless of potential cloning of theMediaSourceHandledue to varying implementations ofTransferable.

Note

Seeattaching to a media elementfor how this is enforced during the asynchronous portion of the media element's resource selection algorithm.

MediaSourceHandleis only exposed onWindowandDedicatedWorkerGlobalScope contexts, and cannot successfully transfer between differentagent clusters[ECMASCRIPT]. Transfer of aMediaSourceHandleobject can only succeed within the sameagent cluster.

Note

For example, transfer of aMediaSourceHandleobject from either aWindowor DedicatedWorkerGlobalScopeto either a SharedWorker or a ServiceWorker will not succeed. Developers should be aware of this difference versusMediaSource object URLs which areDOMStrings that can be communicated many ways. Even so,attaching to a media elementusing aMediaSource object URLcan only succeed for aMediaSource that was constructed in aWindowcontext. See also the integration of the agentandagent clusterformalisms for Web Application APIs [HTML] where related concepts such asdedicated worker agentsare defined.

Transfer stepsfor aMediaSourceHandleobjectMUSTinclude the following step:

  1. If theMediaSourceHandle's[[has ever been assigned as srcobject]]internal slot is true, then thetransfer stepsmust fail by throwing a DataCloneErrorexception.

5. SourceBufferinterface

WebIDLenumAppendMode{
"segments",
"sequence",
};
segments
The timestamps in the media segment determine where thecoded framesare 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. ThetimestampOffset attribute will be updated if a new offset is needed to make the new media segments adjacent to the previous media segment. Setting thetimestampOffset attribute 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)]
interfaceSourceBuffer:EventTarget{
attributeAppendModemode;
readonly attributebooleanupdating;
readonly attributeTimeRangesbuffered;
attributedoubletimestampOffset;
readonly attributeAudioTrackListaudioTracks;
readonly attributeVideoTrackListvideoTracks;
readonly attributeTextTrackListtextTracks;
attributedoubleappendWindowStart;
attributeunrestricted doubleappendWindowEnd;

attributeEventHandleronupdatestart;
attributeEventHandleronupdate;
attributeEventHandleronupdateend;
attributeEventHandleronerror;
attributeEventHandleronabort;

undefinedappendBuffer(BufferSourcedata);
undefinedabort();
undefinedchangeType(DOMStringtype);
undefinedremove(doublestart,unrestricted doubleend);
};
Issue 280:MSE-in-Workers: {Audio,Video,Text}Track{,List} IDL in HTML need additional DedicatedWorker in Exposed
[HTML]AudioTrackList,VideoTrackListandTextTrackListneed Window+DedicatedWorker exposure.

5.1 Attributes

modeof typeAppendMode

Controls how a sequence ofmedia segmentsare handled. This attribute is initially set byaddSourceBuffer()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:

  1. If this object has been removed from thesourceBuffersattribute of theparent media source,then throw anInvalidStateErrorexception and abort these steps.
  2. If theupdatingattribute equals true, then throw an InvalidStateErrorexception and abort these steps.
  3. Letnew modeequal the new value being assigned to this attribute.
  4. If[[generate timestamps flag]]equals true andnew mode equals "segments",then throw aTypeErrorexception and abort these steps.
  5. If thereadyStateattribute of theparent media sourceis in the "ended"state then run the following steps:

    1. Set thereadyStateattribute of theparent media source to "open"
    2. Queue a tasktofire an eventnamedsourceopenat theparent media source.
  6. If the[[append state]]equalsPARSING_MEDIA_SEGMENT,then throw anInvalidStateErrorand abort these steps.
  7. If thenew modeequals "sequence",then set the [[group start timestamp]]to the[[group end timestamp]].
  8. Update the attribute tonew mode.
updatingof typeboolean,readonly

Indicates whether the asynchronous continuation of anappendBuffer() orremove()operation is still being processed. This attribute is initially set to false when the object is created.

bufferedof typeTimeRanges,readonly

Indicates whatTimeRangesare buffered in theSourceBuffer.This attribute is initially set to an emptyTimeRangesobject when the object is created.

When the attribute is read the following stepsMUSToccur:

  1. If this object has been removed from thesourceBuffersattribute of theparent media sourcethen throw anInvalidStateErrorexception and abort these steps.
  2. Lethighest end timebe the largesttrack buffer rangesend time across all thetrack buffersmanaged by thisSourceBufferobject.
  3. Letintersection rangesequal aTimeRangesobject containing a single range from 0 tohighest end time.
  4. For each audio and videotrack buffermanaged by thisSourceBuffer,run the following steps:
    Note

    Texttrack buffersare included in the calculation ofhighest 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.

    1. Lettrack rangesequal thetrack buffer ranges for the currenttrack buffer.
    2. IfreadyStateis "ended",then set the end time on the last range intrack rangestohighest end time.
    3. Letnew intersection rangesequal the intersection between theintersection rangesand thetrack ranges.
    4. Replace the ranges inintersection rangeswith thenew intersection ranges.
  5. Ifintersection rangesdoes 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.
  6. Return the current value of this attribute.
timestampOffsetof typedouble

Controls the offset applied to timestamps inside subsequentmedia segmentsthat are appended to thisSourceBuffer.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:

  1. Letnew timestamp offsetequal the new value being assigned to this attribute.
  2. If this object has been removed from thesourceBuffersattribute of theparent media source,then throw anInvalidStateErrorexception and abort these steps.
  3. If theupdatingattribute equals true, then throw an InvalidStateErrorexception and abort these steps.
  4. If thereadyStateattribute of theparent media sourceis in the "ended"state then run the following steps:

    1. Set thereadyStateattribute of theparent media source to "open"
    2. Queue a tasktofire an eventnamedsourceopenat theparent media source.
  5. If the[[append state]]equalsPARSING_MEDIA_SEGMENT,then throw anInvalidStateErrorand abort these steps.
  6. If themodeattribute equals "sequence",then set the[[group start timestamp]]tonew timestamp offset.
  7. Update the attribute tonew timestamp offset.
audioTracksof typeAudioTrackList,readonly
The list ofAudioTrackobjects created by this object.
videoTracksof typeVideoTrackList,readonly
The list ofVideoTrackobjects created by this object.
textTracksof typeTextTrackList,readonly
The list ofTextTrackobjects created by this object.
appendWindowStartof typedouble

Thepresentation timestampfor the start of theappend window.This attribute is initially set to thepresentation start time.

On getting, Return the initial value or the last value that was successfully set.

On setting, run the following steps:

  1. If this object has been removed from thesourceBuffersattribute of theparent media source,then throw anInvalidStateErrorexception and abort these steps.
  2. If theupdatingattribute equals true, then throw an InvalidStateErrorexception and abort these steps.
  3. If the new value is less than 0 or greater than or equal to appendWindowEndthen throw aTypeErrorexception and abort these steps.
  4. Update the attribute to the new value.
appendWindowEndof typeunrestricted double

Thepresentation timestampfor the end of theappend 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:

  1. If this object has been removed from thesourceBuffersattribute of theparent media source,then throw anInvalidStateErrorexception and abort these steps.
  2. If theupdatingattribute equals true, then throw an InvalidStateErrorexception and abort these steps.
  3. If the new value equals NaN, then throw aTypeErrorand abort these steps.
  4. If the new value is less than or equal toappendWindowStartthen throw aTypeErrorexception and abort these steps.
  5. Update the attribute to the new value.
onupdatestartof typeEventHandler

The event handler for theupdatestartevent.

onupdateof typeEventHandler

The event handler for theupdateevent.

onupdateendof typeEventHandler

The event handler for theupdateendevent.

onerrorof typeEventHandler

The event handler for theerrorevent.

onabortof typeEventHandler

The event handler for theabortevent.

5.2 Methods

appendBuffer

Appends the segment data in anBufferSource[WEBIDL] to theSourceBuffer.

When this method is invoked, the user agent must run the following steps:

  1. Run theprepare appendalgorithm.
  2. Adddatato the end of the[[input buffer]].
  3. Set theupdatingattribute to true.
  4. Queue a tasktofire an eventnamedupdatestartat this SourceBufferobject.
  5. Asynchronously run thebuffer appendalgorithm.
abort

Aborts the current segment and resets the segment parser.

When this method is invoked, the user agent must run the following steps:

  1. If this object has been removed from thesourceBuffersattribute of theparent media sourcethen throw anInvalidStateErrorexception and abort these steps.
  2. If thereadyStateattribute of theparent media sourceis not in the "open"state then throw anInvalidStateErrorexception and abort these steps.
  3. If therange removalalgorithm is running, then throw an InvalidStateErrorexception and abort these steps.
  4. If theupdatingattribute equals true, then run the following steps:
    1. Abort thebuffer appendalgorithm if it is running.
    2. Set theupdatingattribute to false.
    3. Queue a tasktofire an eventnamedabortat this SourceBufferobject.
    4. Queue a tasktofire an eventnamedupdateendat this SourceBufferobject.
  5. Run thereset parser statealgorithm.
  6. SetappendWindowStartto thepresentation start time.
  7. SetappendWindowEndto positive Infinity.
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:

  1. Iftypeis an empty string then throw aTypeErrorexception and abort these steps.
  2. If this object has been removed from thesourceBuffersattribute of theparent media source,then throw anInvalidStateErrorexception and abort these steps.
  3. If theupdatingattribute equals true, then throw an InvalidStateErrorexception and abort these steps.
  4. Iftypecontains 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.
  5. If thereadyStateattribute of theparent media sourceis in the "ended"state then run the following steps:

    1. Set thereadyStateattribute of theparent media source to "open".
    2. Queue a tasktofire an eventnamedsourceopenat theparent media source.
  6. Run thereset parser statealgorithm.
  7. Update the[[generate timestamps flag]]on thisSourceBuffer object to the value in the "Generate Timestamps Flag" column of the byte stream format registry [MSE-REGISTRY] entry that is associated withtype.
  8. If the[[generate timestamps flag]]equals true:
    Set themodeattribute on thisSourceBufferobject to "sequence",including running the associated steps for that attribute being set.
    Otherwise:
    Keep the previous value of themodeattribute on this SourceBufferobject, without running any associated steps for that attribute being set.
  9. Set the[[pending initialization segment for changeType flag]] on thisSourceBufferobject to true.
remove

Removes media for a specific time range. Thestartof the removal range, in seconds measured frompresentation start timeTheendof the removal range, in seconds measured frompresentation start time.

When this method is invoked, the user agent must run the following steps:

  1. If this object has been removed from thesourceBuffersattribute of theparent media sourcethen throw anInvalidStateErrorexception and abort these steps.
  2. If theupdatingattribute equals true, then throw an InvalidStateErrorexception and abort these steps.
  3. Ifdurationequals NaN, then throw aTypeErrorexception and abort these steps.
  4. Ifstartis negative or greater thanduration,then throw aTypeErrorexception and abort these steps.
  5. Ifendis less than or equal tostartorendequals NaN, then throw aTypeErrorexception and abort these steps.
  6. If thereadyStateattribute of theparent media sourceis in the "ended"state then run the following steps:

    1. Set thereadyStateattribute of theparent media source to "open"
    2. Queue a tasktofire an eventnamedsourceopenat theparent media source.
  7. Run therange removalalgorithm withstartandendas the start and end of the removal range.

5.3 Track Buffers

Atrack bufferstores thetrack descriptionsandcoded framesfor an individual track. The track buffer is updated asinitialization segmentsandmedia segmentsare appended to theSourceBuffer.

Eachtrack bufferhas alast decode timestamp variable that stores the decode timestamp of the lastcoded frameappended in the currentcoded frame group.The variable is initially unset to indicate that no coded frameshave been appended yet.

Eachtrack bufferhas alast frame duration variable that stores thecoded frame durationof the lastcoded frameappended in the currentcoded frame group.The variable is initially unset to indicate that no coded frameshave been appended yet.

Eachtrack bufferhas ahighest end timestamp variable that stores the highestcoded frame end timestampacross allcoded framesin the currentcoded frame groupthat were appended to this track buffer. The variable is initially unset to indicate that nocoded frameshave been appended yet.

Eachtrack bufferhas aneed random access point flag variable that keeps track of whether the track buffer is waiting for arandom access pointcoded frame.The variable is initially set to true to indicate thatrandom access pointcoded frameis needed before anything can be added to thetrack buffer.

Eachtrack bufferhas atrack buffer ranges variable that represents the presentation time ranges occupied by thecoded frames currently stored in the track buffer.

Note

For track buffer ranges, these presentation time ranges are based onpresentation timestamps,frame durations, and potentially coded frame group start times for coded frame groups across track buffers in a muxedSourceBuffer.

For specification purposes, this information is treated as if it were stored in a normalized TimeRanges object.Intersectedtrack buffer rangesare used to reportHTMLMediaElement'sbuffered,andMUSTtherefore support uninterrupted playback within each range ofHTMLMediaElement's buffered.

Note

These coded frame group start times differ slightly from those mentioned in thecoded frame processingalgorithm in that they are the earliestpresentation timestamp across all track buffers following a discontinuity. Discontinuities can occur within the coded frame processingalgorithm or result from thecoded frame removal algorithm, regardless ofmode.The threshold for determining disjointness oftrack buffer rangesis implementation-specific. For example, to reduce unexpected playback stalls, implementationsMAYapproximate thecoded frame processingalgorithm's discontinuity detection logic by coalescing adjacent ranges separated by a gap smaller than 2 times the maximum frame duration buffered so far in thistrack buffer.ImplementationsMAYalso use coded frame group start times as range start times acrosstrack buffersin a muxedSourceBufferto further reduce unexpected playback stalls.

5.4 Event Summary

Event name Interface Dispatched when...
updatestart Event SourceBuffer'supdatingtransitions from false to true.
update Event ASourceBuffer's append or remove successfully completed.SourceBuffer's updatingtransitions from true to false.
updateend Event The append or remove of aSourceBufferended.
error Event An error occurred during the append to aSourceBuffer.updating transitions from true to false.
abort Event TheSourceBuffer's append was aborted by anabort()call. updatingtransitions from true to false.

5.5 Algorithms

5.5.1 Segment Parser Loop

EachSourceBufferobject has an[[append state]]internal slot that keeps track of the high-level segment parsing state. It is initially set toWAITING_FOR_SEGMENTand can transition to the following states as data is appended.

Append state name Description
WAITING_FOR_SEGMENT Waiting for the start of aninitialization segmentormedia segmentto be appended.
PARSING_INIT_SEGMENT Currently parsing aninitialization segment.
PARSING_MEDIA_SEGMENT Currently parsing amedia segment.

EachSourceBufferobject has an[[input buffer]]internal slot that is a byte buffer that holds unparsed bytes across appendBuffer()calls. The buffer is empty when theSourceBuffer object is created.

EachSourceBufferobject has a[[buffer full flag]]internal slot that keeps track of whetherappendBuffer() is allowed to accept more bytes. It is set to false when theSourceBufferobject is created and gets updated as data is appended and removed.

EachSourceBufferobject has a[[group start timestamp]]internal slot that keeps track of the starting timestamp for a new coded frame groupin the "sequence"mode. It is unset when the SourceBuffer object is created and gets updated when themode attribute equals "sequence"and thetimestampOffset attribute is set, or thecoded frame processingalgorithm runs.

EachSourceBufferobject has a[[group end timestamp]]internal slot that stores the highestcoded frame end timestamp across allcoded framesin the currentcoded frame group.It is set to 0 when the SourceBuffer object is created and gets updated by thecoded frame processing algorithm.

Note

The[[group end timestamp]]stores the highestcoded frame end timestampacross alltrack buffersin aSourceBuffer.Therefore, care should be taken in setting themodeattribute when appending multiplexed segments in which the timestamps are not aligned across tracks.

EachSourceBufferobject has a[[generate timestamps flag]]internal slot that is a boolean that keeps track of whether timestamps need to be generated for thecoded framespassed to the coded frame processingalgorithm. This flag is set by addSourceBuffer()when theSourceBufferobject is created and is updated bychangeType().

When the segment parser loop algorithm is invoked, run the following steps:

  1. Loop Top:If the[[input buffer]]is empty, then jump to the need more datastep below.
  2. If the[[input buffer]]contains bytes that violate the SourceBuffer byte stream format specification,then run theappend error algorithm and abort this algorithm.
  3. Remove any bytes that thebyte stream format specificationssayMUSTbe ignored from the start of the[[input buffer]].
  4. If the[[append state]]equalsWAITING_FOR_SEGMENT,then run the following steps:

    1. If the beginning of the[[input buffer]]indicates the start of aninitialization segment,set the[[append state]]to PARSING_INIT_SEGMENT.
    2. If the beginning of the[[input buffer]]indicates the start of amedia segment,set[[append state]]to PARSING_MEDIA_SEGMENT.
    3. Jump to theloop topstep above.
  5. If the[[append state]]equalsPARSING_INIT_SEGMENT,then run the following steps:

    1. If the[[input buffer]]does not contain a complete initialization segmentyet, then jump to theneed more datastep below.
    2. Run theinitialization segment receivedalgorithm.
    3. Remove theinitialization segmentbytes from the beginning of the [[input buffer]].
    4. Set[[append state]]toWAITING_FOR_SEGMENT.
    5. Jump to theloop topstep above.
  6. If the[[append state]]equalsPARSING_MEDIA_SEGMENT,then run the following steps:

    1. If the[[first initialization segment received flag]]is false or the[[pending initialization segment for changeType flag]]is true, then run theappend erroralgorithm and abort this algorithm.
    2. If the[[input buffer]]contains one or more completecoded frames,then run thecoded frame processingalgorithm.
      Note

      The frequency at which the coded frame processing algorithm is run is implementation-specific. The coded frame processing algorithmMAYbe called when the input buffer contains the complete media segment or itMAYbe called multiple times as complete coded frames are added to the input buffer.

    3. If thisSourceBufferis full and cannot accept more media data, then set the[[buffer full flag]]to true.
    4. If the[[input buffer]]does not contain a completemedia segment,then jump to theneed more datastep below.
    5. Remove themedia segmentbytes from the beginning of the [[input buffer]].
    6. Set[[append state]]toWAITING_FOR_SEGMENT.
    7. Jump to theloop topstep above.
  7. Need more data:Return control to the calling algorithm.

5.5.2 Reset Parser State

When the parser state needs to be reset, run the following steps:

  1. If the[[append state]]equalsPARSING_MEDIA_SEGMENTand the [[input buffer]]contains some completecoded frames,then run the coded frame processingalgorithm until all of these completecoded frameshave been processed.
  2. Unset thelast decode timestampon alltrack buffers.
  3. Unset thelast frame durationon alltrack buffers.
  4. Unset thehighest end timestampon alltrack buffers.
  5. Set theneed random access point flagon alltrack buffersto true.
  6. If themodeattribute equals "sequence",then set the[[group start timestamp]]to the[[group end timestamp]]
  7. Remove all bytes from the[[input buffer]].
  8. Set[[append state]]toWAITING_FOR_SEGMENT.

5.5.3 Append Error

This algorithm is called when an error occurs during an append.

  1. Run thereset parser statealgorithm.
  2. Set theupdatingattribute to false.
  3. Queue a tasktofire an eventnamederrorat thisSourceBuffer object.
  4. Queue a tasktofire an eventnamedupdateendat thisSourceBuffer object.
  5. Run theend of streamalgorithm with theerrorparameter set to "decode".

5.5.4 Prepare Append

When an append operation begins, the following steps are run to validate and prepare theSourceBuffer.

  1. If theSourceBufferhas been removed from thesourceBuffers attribute of theparent media sourcethen throw anInvalidStateErrorexception and abort these steps.
  2. If theupdatingattribute equals true, then throw an InvalidStateErrorexception and abort these steps.
  3. Letrecent element errorbe determined as follows:
    If theMediaSourcewas constructed in aWindow
    Letrecent element errorbe true if theHTMLMediaElement's errorattribute is not null. If that attribute is null, then letrecent element errorbe false.
    Otherwise
    Letrecent element errorbe 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 letrecent element errorbe false.
  4. Ifrecent element erroris true, then throw anInvalidStateErrorexception and abort these steps.
  5. If thereadyStateattribute of theparent media sourceis in the "ended"state then run the following steps:

    1. Set thereadyStateattribute of theparent media sourceto "open"
    2. Queue a tasktofire an eventnamedsourceopenat theparent media source.
  6. Run thecoded frame evictionalgorithm.
  7. If the[[buffer full flag]]equals true, then throw a QuotaExceededErrorexception and abort these steps.

    Note

    This is the signal that the implementation was unable to evict enough data to accommodate the append or the append is too big. The web applicationSHOULDuse remove()to explicitly free up space and/or reduce the size of the append.

5.5.5 Buffer Append

WhenappendBuffer()is called, the following steps are run to process the appended data.

  1. Run thesegment parser loopalgorithm.
  2. If thesegment parser loopalgorithm in the previous step was aborted, then abort this algorithm.
  3. Set theupdatingattribute to false.
  4. Queue a tasktofire an eventnamedupdateat thisSourceBuffer object.
  5. Queue a tasktofire an eventnamedupdateendat thisSourceBuffer object.

5.5.6 Range Removal

Follow these steps when a caller needs to initiate a JavaScript visible range removal operation that blocks other SourceBuffer updates:

  1. Letstartequal the startingpresentation timestampfor the removal range, in seconds measured frompresentation start time.
  2. Letendequal the endpresentation timestampfor the removal range, in seconds measured frompresentation start time.
  3. Set theupdatingattribute to true.
  4. Queue a tasktofire an eventnamedupdatestartat this SourceBufferobject.
  5. Return control to the caller and run the rest of the steps asynchronously.
  6. Run thecoded frame removalalgorithm withstartandendas the start and end of the removal range.
  7. Set theupdatingattribute to false.
  8. Queue a tasktofire an eventnamedupdateat thisSourceBuffer object.
  9. Queue a tasktofire an eventnamedupdateendat thisSourceBuffer object.

5.5.7 Initialization Segment Received

The following steps are run when thesegment parser loopsuccessfully parses a completeinitialization segment:

Each SourceBuffer object has a[[first initialization segment received flag]]internal slot that tracks whether the first initialization segmenthas 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 segmentis needed since the most recent changeType().This flag is set to false when the SourceBuffer is created, set to true bychangeType()and reset to false by the algorithm below.

  1. Update thedurationattribute if it currently equals NaN:
    If the initialization segment contains a duration:
    Run theduration changealgorithm withnew durationset to the duration in the initialization segment.
    Otherwise:
    Run theduration changealgorithm withnew durationset to positive Infinity.
  2. If theinitialization segmenthas no audio, video, or text tracks, then run the append erroralgorithm and abort these steps.
  3. If the[[first initialization segment received flag]]is true, then run the following steps:
    1. Verify the following properties. If any of the checks fail then run the append erroralgorithm 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 theTrack IDsmatch the ones in the firstinitialization segment.
      • The codecs for each track are supported by the user agent.
        Note

        User agentsMAYconsider codecs, that would otherwise be supported, as "not supported" here if the codecs were not specified intype 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 thisSourceBuffer object. For example, if the most recently successful changeType()was called with'video/webm'or 'video/webm; codecs= "vp8" ',and a video track containing vp9 appears in the initialization segment, then the user agentMAYuse 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 theSourceBuffer object's bytestream format is changing.

    2. Add the appropriatetrack descriptionsfrom thisinitialization segment to each of thetrack buffers.
    3. Set theneed random access point flagon all track buffers to true.
  4. Letactive track flagequal false.
  5. If the[[first initialization segment received flag]]is false, then run the following steps:

    1. If theinitialization segmentcontains tracks with codecs the user agent does not support, then run theappend erroralgorithm and abort these steps.
      Note

      User agentsMAYconsider codecs, that would otherwise be supported, as "not supported" here if the codecs were not specified intypeparameter passed to (a) the most recently successfulchangeType()on thisSourceBufferobject, or (b) if no successful changeType()has yet occurred on this object, the addSourceBuffer()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 theinitialization segment,then the user agentMAYuse 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 use changeType(),addSourceBuffer()and isTypeSupported()with precise codec parameters to more proactively detect user agent support.changeType()is required if theSourceBufferobject's bytestream format is changing.

    2. For each audio track in theinitialization segment,run following steps:

      1. Letaudio byte stream track IDbe theTrack IDfor the current track being processed.
      2. Letaudio languagebe a BCP 47 language tag for the language specified in theinitialization segmentfor this track or an empty string if no language info is present.
      3. Ifaudio languageequals the 'und' BCP 47 value, then assign an empty string toaudio language.
      4. Letaudio labelbe a label specified in theinitialization segmentfor this track or an empty string if no label info is present.
      5. Letaudio kindsbe a sequence of kind strings specified in theinitialization segmentfor this track or a sequence with a single empty string element in it if no kind information is provided.
      6. For each value inaudio kinds,run the following steps:
        1. Letcurrent audio kindequal the value fromaudio kinds for this iteration of the loop.
        2. Letnew audio trackbe a newAudioTrackobject.
        3. Generate a unique ID and assign it to theidproperty on new audio track.
        4. Assignaudio languageto thelanguageproperty onnew audio track.
        5. Assignaudio labelto thelabelproperty onnew audio track.
        6. Assigncurrent audio kindto thekindproperty onnew audio track.
        7. If thisSourceBufferobject'saudioTracks's lengthequals 0, then run the following steps:

          1. Set theenabledproperty onnew audio trackto true.
          2. Setactive track flagto true.
        8. Addnew audio trackto theaudioTracksattribute on thisSourceBufferobject.
          Note

          This should triggerAudioTrackList[HTML] logic toqueue a tasktofire an eventnamedaddtrackusing TrackEventwith thetrackattribute initialized to new audio track,at theAudioTrackListobject referenced by the audioTracksattribute on thisSourceBufferobject.

        9. If theparent media sourcewas constructed in a DedicatedWorkerGlobalScope:
          Post an internalcreate track mirrormessage to [[port to main]]whose implicit handler inWindow runs the following steps:
          1. Letmirrored audio trackbe a newAudioTrack object.
          2. Assign the same property values tomirrored audio trackas were determined fornew audio track.
          3. Addmirrored audio trackto the audioTracksattribute on the HTMLMediaElement.
          Otherwise:
          Addnew audio trackto theaudioTracks attribute on the HTMLMediaElement.
          Note

          This should triggerAudioTrackList[HTML] logic toqueue a tasktofire an eventnamedaddtrackusing TrackEventwith thetrackattribute initialized to mirrored audio trackornew audio track,at theAudioTrackList object referenced by theaudioTracksattribute on the HTMLMediaElement.

      7. Create a newtrack bufferto storecoded framesfor this track.
      8. Add thetrack descriptionfor this track to thetrack buffer.
    3. For each video track in theinitialization segment,run following steps:

      1. Letvideo byte stream track IDbe theTrack IDfor the current track being processed.
      2. Letvideo languagebe a BCP 47 language tag for the language specified in theinitialization segmentfor this track or an empty string if no language info is present.
      3. Ifvideo languageequals the 'und' BCP 47 value, then assign an empty string tovideo language.
      4. Letvideo labelbe a label specified in theinitialization segmentfor this track or an empty string if no label info is present.
      5. Letvideo kindsbe a sequence of kind strings specified in theinitialization segmentfor this track or a sequence with a single empty string element in it if no kind information is provided.
      6. For each value invideo kinds,run the following steps:
        1. Letcurrent video kindequal the value fromvideo kinds for this iteration of the loop.
        2. Letnew video trackbe a newVideoTrackobject.
        3. Generate a unique ID and assign it to theidproperty on new video track.
        4. Assignvideo languageto thelanguageproperty onnew video track.
        5. Assignvideo labelto thelabelproperty onnew video track.
        6. Assigncurrent video kindto thekindproperty onnew video track.
        7. If thisSourceBufferobject'svideoTracks's lengthequals 0, then run the following steps:

          1. Set theselectedproperty onnew video trackto true.
          2. Setactive track flagto true.
        8. Addnew video trackto thevideoTracksattribute on thisSourceBufferobject.
          Note

          This should triggerVideoTrackList[HTML] logic toqueue a tasktofire an eventnamedaddtrackusing TrackEventwith thetrackattribute initialized to new video track,at theVideoTrackListobject referenced by the videoTracksattribute on thisSourceBufferobject.

        9. If theparent media sourcewas constructed in a DedicatedWorkerGlobalScope:
          Post an internalcreate track mirrormessage to [[port to main]]whose implicit handler inWindow runs the following steps:
          1. Letmirrored video trackbe a newVideoTrack object.
          2. Assign the same property values tomirrored video trackas were determined fornew video track.
          3. Addmirrored video trackto the videoTracksattribute on the HTMLMediaElement.
          Otherwise:
          Addnew video trackto thevideoTracks attribute on the HTMLMediaElement.
          Note

          This should triggerVideoTrackList[HTML] logic toqueue a tasktofire an eventnamedaddtrackusing TrackEventwith thetrackattribute initialized to mirrored video trackornew video track,at theVideoTrackList object referenced by thevideoTracksattribute on the HTMLMediaElement.

      7. Create a newtrack bufferto storecoded framesfor this track.
      8. Add thetrack descriptionfor this track to thetrack buffer.
    4. For each text track in theinitialization segment,run following steps:

      1. Lettext byte stream track IDbe theTrack IDfor the current track being processed.
      2. Lettext languagebe a BCP 47 language tag for the language specified in theinitialization segmentfor this track or an empty string if no language info is present.
      3. Iftext languageequals the 'und' BCP 47 value, then assign an empty string totext language.
      4. Lettext labelbe a label specified in theinitialization segmentfor this track or an empty string if no label info is present.
      5. Lettext kindsbe a sequence of kind strings specified in theinitialization segmentfor this track or a sequence with a single empty string element in it if no kind information is provided.
      6. For each value intext kinds,run the following steps:
        1. Letcurrent text kindequal the value fromtext kindsfor this iteration of the loop.
        2. Letnew text trackbe a newTextTrackobject.
        3. Generate a unique ID and assign it to theidproperty on new text track.
        4. Assigntext languageto thelanguageproperty onnew text track.
        5. Assigntext labelto thelabelproperty onnew text track.
        6. Assigncurrent text kindto thekindproperty onnew text track.
        7. Populate the remaining properties onnew text trackwith the appropriate information from theinitialization segment.
        8. If themodeproperty onnew text trackequals "showing"or"hidden",then setactive track flagto true.
        9. Addnew text trackto thetextTracksattribute on thisSourceBufferobject.
          Note

          This should triggerTextTrackList[HTML] logic toqueue a tasktofire an eventnamedaddtrackusing TrackEventwith thetrackattribute initialized to new text track,at theTextTrackListobject referenced by the textTracksattribute on thisSourceBufferobject.

        10. If theparent media sourcewas constructed in a DedicatedWorkerGlobalScope:
          Post an internalcreate track mirrormessage to [[port to main]]whose implicit handler inWindow runs the following steps:
          1. Letmirrored text trackbe a newTextTrack object.
          2. Assign the same property values tomirrored text trackas were determined fornew text track.
          3. Addmirrored text trackto the textTracksattribute on the HTMLMediaElement.
          Otherwise:
          Addnew text trackto thetextTracksattribute on the HTMLMediaElement.
          Note

          This should triggerTextTrackList[HTML] logic toqueue a tasktofire an eventnamedaddtrackusing TrackEventwith thetrackattribute initialized to mirrored text trackornew text track,at theTextTrackList object referenced by thetextTracksattribute on the HTMLMediaElement.

      7. Create a newtrack bufferto storecoded framesfor this track.
      8. Add thetrack descriptionfor this track to thetrack buffer.
    5. Ifactive track flagequals true, then run the following steps:
      1. Add thisSourceBuffertoactiveSourceBuffers.
      2. Queue a tasktofire an eventnamedaddsourcebufferat activeSourceBuffers
    6. Set[[first initialization segment received flag]]to true.
  6. Set[[pending initialization segment for changeType flag]]to false.
  7. If theactive track flagequals true, then run the following steps:
  8. Use theparent media source'smirror if necessaryalgorithm to run the following step inWindow:
    1. If theHTMLMediaElement'sreadyStateattribute is greater thanHAVE_CURRENT_DATA,then set the HTMLMediaElement'sreadyStateattribute to HAVE_METADATA.
      Note

      PerHTMLMediaElement ready states[HTML] logic,HTMLMediaElement's readyStatechanges may trigger events on the HTMLMediaElement.

  9. If each object insourceBuffersof theparent media sourcehas [[first initialization segment received flag]]equal to true, then use theparent media source'smirror if necessaryalgorithm to run the following step inWindow:
    1. If theHTMLMediaElement'sreadyStateattribute is HAVE_NOTHING,then set theHTMLMediaElement's readyStateattribute toHAVE_METADATA.
      Note

      PerHTMLMediaElement ready states[HTML] logic,HTMLMediaElement's readyStatechanges may trigger events on the HTMLMediaElement. If transition fromHAVE_NOTHINGto HAVE_METADATAoccurs, it should trigger HTMLMediaElement logic toqueue a tasktofire an eventnamed loadedmetadataat the media element.

5.5.8 Coded Frame Processing

When completecoded frameshave been parsed by thesegment parser loopthen the following steps are run:

  1. For eachcoded framein themedia segmentrun the following steps:

    1. Loop Top:
      If[[generate timestamps flag]]equals true:
      1. Letpresentation timestampequal 0.
      2. Letdecode timestampequal 0.
      Otherwise:
      1. Letpresentation timestampbe a double precision floating point representation of the coded frame'spresentation timestampin 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 situationsSHOULDbe in thebyte stream format specificationsor in separate extension specifications.

      2. Letdecode timestampbe 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 timestampOffsetSHOULDbehave in a similar manner to what would happen if a double precision floating point representation was used.

    2. Letframe durationbe a double precision floating point representation of thecoded frame's durationin seconds.
    3. Ifmodeequals "sequence"and [[group start timestamp]]is set, then run the following steps:
      1. SettimestampOffsetequal to[[group start timestamp]]minuspresentation timestamp.
      2. Set[[group end timestamp]]equal to [[group start timestamp]].
      3. Set theneed random access point flagon alltrack buffersto true.
      4. Unset[[group start timestamp]].
    4. IftimestampOffsetis not 0, then run the following steps:

      1. AddtimestampOffsetto thepresentation timestamp.
      2. AddtimestampOffsetto thedecode timestamp.
    5. Lettrack bufferequal thetrack bufferthat the coded frame will be added to.
    6. Iflast decode timestampfortrack bufferis set anddecode timestamp is less thanlast decode timestamp:
      OR
      Iflast decode timestampfortrack bufferis set and the difference betweendecode timestampandlast decode timestampis greater than 2 timeslast frame duration:
      1. Ifmodeequals "segments":
        Set[[group end timestamp]]topresentation timestamp.
        Ifmodeequals "sequence":
        Set[[group start timestamp]]equal to the [[group end timestamp]].
      2. Unset thelast decode timestampon alltrack buffers.
      3. Unset thelast frame durationon alltrack buffers.
      4. Unset thehighest end timestampon alltrack buffers.
      5. Set theneed random access point flagon alltrack buffersto true.
      6. Jump to theLoop Topstep above to restart processing of the currentcoded frame.
      Otherwise:
      Continue.
    7. Letframe end timestampequal the sum ofpresentation timestampand frame duration.
    8. Ifpresentation timestampis less thanappendWindowStart, then set theneed random access point flagto true, drop the coded frame, and jump to the top of the loop to start processing the next coded frame.
      Note

      Some implementationsMAYchoose to collect some of these coded frames with presentation timestampless thanappendWindowStartand use them to generate a splice at the first coded frame that has apresentation timestampgreater than or equal toappendWindowStarteven if that frame is not arandom access point.Supporting this requires multiple decoders or faster than real-time decoding so for now this behavior will not be a normative requirement.

    9. Ifframe end timestampis greater thanappendWindowEnd,then set theneed random access point flagto true, drop the coded frame, and jump to the top of the loop to start processing the next coded frame.
      Note

      Some implementationsMAYchoose to collect coded frames withpresentation timestampless thanappendWindowEndandframe 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,implementationsMAY thus support gapless audio splicing.

    10. If theneed random access point flagontrack bufferequals true, then run the following steps:
      1. If the coded frame is not arandom access point,then drop the coded frame and jump to the top of the loop to start processing the next coded frame.
      2. Set theneed random access point flagontrack bufferto false.
    11. Letspliced audio framebe an unset variable for holding audio splice information
    12. Letspliced timed text framebe an unset variable for holding timed text splice information
    13. Iflast decode timestampfortrack bufferis unset andpresentation timestampfalls within thepresentation intervalof acoded framein track buffer,then run the following steps:
      1. Letoverlapped framebe thecoded frameintrack bufferthat matches the condition above.
      2. Iftrack buffercontains audiocoded frames:
        Run theaudio splice framealgorithm and if a splice frame is returned, assign it tospliced audio frame.
        Iftrack buffercontains videocoded frames:
        1. Letremove window timestampequal theoverlapped frame presentation timestampplus 1 microsecond.
        2. If thepresentation timestampis less than theremove window timestamp,then removeoverlapped framefromtrack 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.

        Iftrack buffercontains timed textcoded frames:
        Run thetext splice framealgorithm and if a splice frame is returned, assign it tospliced timed text frame.
    14. Remove existing coded frames intrack buffer:
      Ifhighest end timestampfortrack bufferis not set:
      Remove allcoded framesfromtrack bufferthat have apresentation timestampgreater than or equal topresentation timestampand less than frame end timestamp.
      Ifhighest end timestampfortrack bufferis set and less than or equal topresentation timestamp:
      Remove allcoded framesfromtrack bufferthat have apresentation timestampgreater than or equal tohighest end timestampand less than frame end timestamp.
    15. Remove all possible decoding dependencies on thecoded framesremoved in the previous two steps by removing allcoded framesfromtrack bufferbetween those frames removed in the previous two steps and the nextrandom access point after those removed frames.
      Note

      Removing allcoded framesuntil the nextrandom access pointis 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.

    16. Ifspliced audio frameis set:
      Addspliced audio frameto thetrack buffer.
      Ifspliced timed text frameis set:
      Addspliced timed text frameto thetrack buffer.
      Otherwise:
      Add thecoded framewith thepresentation timestamp,decode timestamp,andframe durationto thetrack buffer.
    17. Setlast decode timestampfortrack buffertodecode timestamp.
    18. Setlast frame durationfortrack buffertoframe duration.
    19. Ifhighest end timestampfortrack bufferis unset orframe end timestampis greater thanhighest end timestamp,then sethighest end timestampfortrack buffertoframe end timestamp.
      Note

      The greater than check is needed because bidirectional prediction between coded frames can causepresentation timestampto not be monotonically increasing even though the decode timestamps are monotonically increasing.

    20. Ifframe end timestampis greater than[[group end timestamp]],then set[[group end timestamp]]equal toframe end timestamp.
    21. If[[generate timestamps flag]]equals true, then set timestampOffsetequal toframe end timestamp.
  2. If theHTMLMediaElement'sreadyStateattribute is HAVE_METADATAand the newcoded framescause HTMLMediaElement'sbufferedto have aTimeRangesfor the current playback position, then set theHTMLMediaElement's readyStateattribute to HAVE_CURRENT_DATA.

    Note

    PerHTMLMediaElement ready states[HTML] logic,HTMLMediaElement's readyStatechanges may trigger events on the HTMLMediaElement.

  3. If theHTMLMediaElement'sreadyStateattribute is HAVE_CURRENT_DATAand the newcoded framescause HTMLMediaElement'sbufferedto have aTimeRangesthat includes the current playback position and some time beyond the current playback position, then set theHTMLMediaElement'sreadyState attribute toHAVE_FUTURE_DATA.

    Note

    PerHTMLMediaElement ready states[HTML] logic,HTMLMediaElement's readyStatechanges may trigger events on the HTMLMediaElement.

  4. If theHTMLMediaElement'sreadyStateattribute is HAVE_FUTURE_DATAand the newcoded framescause HTMLMediaElement'sbufferedto have aTimeRangesthat includes the current playback position andenough data to ensure uninterrupted playback,then set theHTMLMediaElement'sreadyState attribute toHAVE_ENOUGH_DATA.

    Note

    PerHTMLMediaElement ready states[HTML] logic,HTMLMediaElement's readyStatechanges may trigger events on the HTMLMediaElement.

  5. If themedia segmentcontains data beyond the currentduration, then run theduration changealgorithm withnew durationset to the maximum of the current duration and the[[group end timestamp]].

5.5.9 Coded Frame Removal

Follow these steps whencoded framesfor a specific time range need to be removed from the SourceBuffer:

  1. Letstartbe the startingpresentation timestampfor the removal range.
  2. Letendbe the endpresentation timestampfor the removal range.
  3. For eachtrack bufferin thisSourceBuffer,run the following steps:

    1. Letremove end timestampbe the current value of duration
    2. If thistrack bufferhas arandom access pointtimestamp that is greater than or equal toend,then updateremove end timestampto that random access point timestamp.

      Note

      Random access point timestamps can be different across tracks because the dependencies betweencoded frameswithin a track are usually different than the dependencies in another track.

    3. Remove all media data, from thistrack buffer,that contain starting timestamps greater than or equal tostartand less than theremove end timestamp.
      1. For each removed frame, if the frame has adecode timestampequal to thelast decode timestampfor the frame's track, run the following steps:

        Ifmodeequals "segments":
        Set[[group end timestamp]]topresentation timestamp.
        Ifmodeequals "sequence":
        Set[[group start timestamp]]equal to the [[group end timestamp]].
      2. Unset thelast decode timestampon alltrack buffers.
      3. Unset thelast frame durationon alltrack buffers.
      4. Unset thehighest end timestampon alltrack buffers.
      5. Set theneed random access point flagon alltrack buffersto true.
    4. Remove all possible decoding dependencies on thecoded framesremoved in the previous step by removing allcoded framesfrom thistrack buffer between those frames removed in the previous step and the nextrandom access pointafter those removed frames.
      Note

      Removing allcoded framesuntil the nextrandom access pointis 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.

    5. If this object is inactiveSourceBuffers,thecurrent playback positionis greater than or equal tostartand less than theremove end timestamp,andHTMLMediaElement's readyStateis greater than HAVE_METADATA,then set theHTMLMediaElement's readyStateattribute toHAVE_METADATA and stall playback.

      Note

      PerHTMLMediaElement ready states[HTML] logic,HTMLMediaElement's readyStatechanges may trigger events on the HTMLMediaElement.

      Note

      This transition occurs because media data for the current position has been removed. Playback cannot progress until media for thecurrent playback positionis appended or the 3.15.5 Changes to selected/enabled track state.

  4. If the[[buffer full flag]]equals true and this object is ready to accept more bytes, then set the[[buffer full flag]]to false.

5.5.10 Coded Frame Eviction

This algorithm is run to free up space in thisSourceBufferwhen new data is appended.

  1. Letnew dataequal 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 implementationsMAYdecide to set [[buffer full flag]]true here if it predicts that processing new datain 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 acceptingnew datawhich would overflow resources, for example. In practice, at least one implementation already does this.

  2. If the[[buffer full flag]]equals false, then abort these steps.
  3. Letremoval rangesequal a list of presentation time ranges that can be evicted from the presentation to make room for thenew data.
    Note

    ImplementationsMAYuse different methods for selectingremoval rangesso web applicationsSHOULD NOTdepend on a specific behavior. The web application can use thebufferedattribute to observe whether portions of the buffered data have been evicted.

  4. For each range inremoval ranges,run thecoded frame removalalgorithm with startandendequal to the removal range start and end timestamp respectively.

5.5.11 Audio Splice Frame

Follow these steps when thecoded frame processingalgorithm needs to generate a splice frame for two overlapping audiocoded frames:

  1. Lettrack bufferbe thetrack bufferthat will contain the splice.
  2. Letnew coded framebe the newcoded frame,that is being added totrack buffer,which triggered the need for a splice.
  3. Letpresentation timestampbe thepresentation timestampfornew coded frame.
  4. Letdecode timestampbe the decode timestamp fornew coded frame.
  5. Letframe durationbe thecoded frame durationofnew coded frame.
  6. Letoverlapped framebe thecoded frameintrack bufferwith a presentation intervalthat containspresentation timestamp.
  7. Updatepresentation timestampanddecode timestampto the nearest audio sample timestamp based on sample rate of the audio inoverlapped 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).
    Note

    For example, given the following values:

    • Thepresentation timestampofoverlapped frameequals 10.
    • The sample rate ofoverlapped frameequals 8000 Hz
    • presentation timestampequals 10.01255
    • decode timestampequals 10.01255

    presentation timestampanddecode timestampare updated to 10.0125 since 10.01255 is closer to 10 + 100/8000 (10.0125) than 10 + 101/8000 (10.012625)

  8. If the user agent does not support crossfading then run the following steps:
    1. Removeoverlapped framefromtrack buffer.
    2. Add a silence frame totrack bufferwith the following properties:
      Note

      Some implementationsMAYapply fades to/from silence to coded frames on either side of the inserted silence to make the transition less jarring.

    3. Return to caller without providing a splice frame.
      Note

      This is intended to allownew coded frameto be added to thetrack buffer as ifoverlapped framehad not been in thetrack bufferto begin with.

  9. Letframe end timestampequal the sum ofpresentation timestampand frame duration.
  10. Letsplice end timestampequal the sum ofpresentation timestampand the splice duration of 5 milliseconds.
  11. Letfade out coded framesequaloverlapped frameas well as any additional frames intrack bufferthat have apresentation timestampgreater than presentation timestampand less thansplice end timestamp.
  12. Remove all the frames included infade out coded framesfromtrack buffer.
  13. Return a splice frame with the following properties:
    Note

    See theaudio splice renderingalgorithm for details on how this splice frame is rendered.

5.5.12 Audio Splice Rendering

The following steps are run when a spliced frame, generated by theaudio splice framealgorithm, needs to be rendered by the media element:

  1. Letfade out coded framesbe thecoded framesthat are faded out during the splice.
  2. Letfade in coded framesbe thecoded framesthat are faded in during the splice.
  3. Letpresentation timestampbe thepresentation timestampof the first coded frame infade out coded frames.
  4. Letend timestampbe the sum of thepresentation timestampand the coded frame durationof the last frame infade in coded frames.
  5. Letsplice timestampbe thepresentation timestampwhere the splice starts. This corresponds with thepresentation timestampof the first frame in fade in coded frames.
  6. Letsplice end timestampequalsplice timestampplus five milliseconds.
  7. Letfade out samplesbe the samples generated by decodingfade out coded frames.
  8. Trimfade out samplesso that it only contains samples betweenpresentation timestampandsplice end timestamp.
  9. Letfade in samplesbe the samples generated by decodingfade in coded frames.
  10. Iffade out samplesandfade in samplesdo not have a common sample rate and channel layout, then convertfade out samplesandfade in samplesto a common sample rate and channel layout.
  11. Letoutput samplesbe a buffer to hold the output samples.
  12. Apply a linear gain fade out with a starting gain of 1 and an ending gain of 0 to the samples betweensplice timestampandsplice end timestampinfade out samples.
  13. Apply a linear gain fade in with a starting gain of 0 and an ending gain of 1 to the samples betweensplice timestampandsplice end timestampinfade in samples.
  14. Copy samples betweenpresentation timestamptosplice timestampfromfade out samplesintooutput samples.
  15. For each sample betweensplice timestampandsplice end timestamp,compute the sum of a sample fromfade out samplesand the corresponding sample infade in samplesand store the result inoutput samples.
  16. Copy samples betweensplice end timestamptoend timestampfromfade in samplesintooutput samples.
  17. Renderoutput samples.
Note

Here is a graphical representation of this algorithm.

Audio splice diagram

5.5.13 Text Splice Frame

Follow these steps when thecoded frame processingalgorithm needs to generate a splice frame for two overlapping timed textcoded frames:

  1. Lettrack bufferbe thetrack bufferthat will contain the splice.
  2. Letnew coded framebe the newcoded frame,that is being added totrack buffer,which triggered the need for a splice.
  3. Letpresentation timestampbe thepresentation timestampfornew coded frame
  4. Letdecode timestampbe the decode timestamp fornew coded frame.
  5. Letframe durationbe thecoded frame durationofnew coded frame.
  6. Letframe end timestampequal the sum ofpresentation timestampand frame duration.
  7. Letfirst overlapped framebe thecoded frameintrack bufferwith a presentation intervalthat containspresentation timestamp.
  8. Letoverlapped presentation timestampbe thepresentation timestampof thefirst overlapped frame.
  9. Letoverlapped framesequalfirst overlapped frameas well as any additional frames intrack bufferthat have apresentation timestampgreater than presentation timestampand less thanframe end timestamp.
  10. Remove all the frames included inoverlapped framesfromtrack buffer.
  11. Update thecoded frame durationof thefirst overlapped frameto presentation timestampminusoverlapped presentation timestamp.
  12. Addfirst overlapped frameto thetrack buffer.
  13. Return to caller without providing a splice frame.
    Note

    This is intended to allownew coded frameto be added to thetrack bufferas if it hadn't overlapped any frames intrack bufferto begin with.

6. SourceBufferListinterface

SourceBufferListis a simple container object forSourceBufferobjects. It provides read-only array access and fires events when the list is modified.

WebIDL[Exposed=(Window,DedicatedWorker)]
interfaceSourceBufferList:EventTarget{
readonly attributeunsigned longlength;

attributeEventHandleronaddsourcebuffer;
attributeEventHandleronremovesourcebuffer;

getterSourceBuffer(unsigned longindex);
};

6.1 Attributes

lengthof typeunsigned long,readonly

Indicates the number ofSourceBufferobjects in the list.

onaddsourcebufferof typeEventHandler

The event handler for theaddsourcebufferevent.

onremovesourcebufferof typeEventHandler

The event handler for theremovesourcebufferevent.

6.2 Methods

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:

  1. Ifindexis greater than or equal to the lengthattribute then return undefined and abort these steps.
  2. Return theindex'thSourceBufferobject in the list.

6.3 Event Summary

Event name Interface Dispatched when...
addsourcebuffer Event When aSourceBufferis added to the list.
removesourcebuffer Event When aSourceBufferis removed from the list.

7. ManagedMediaSourceinterface

AManagedMediaSourceis aMediaSourcethat actively manages its memory content. Unlike aMediaSource,theuser agentcan evict content through the memory cleanupalgorithm from itssourceBuffers (populated withManagedSourceBuffer) for any reason.

Note:Eviction reasons
WebIDL[Exposed=(Window,DedicatedWorker)]
interfaceManagedMediaSource:MediaSource{
constructor();
readonly attributebooleanstreaming;
attributeEventHandleronstartstreaming;
attributeEventHandleronendstreaming;
};

7.1 Attributes

streaming

On getting:

  1. Return the current value of the attribute.

7.2 Event Summary

Event name Interface Dispatched when...
startstreaming Event AManagedMediaSource'sstreamingattribute changed from falsetotrue.
endstreaming Event AManagedMediaSource'sstreamingattribute changed from truetofalse.

7.3 Algorithms

7.3.1 ManagedSourceBufferMonitoring

The following steps are run periodically, whenever theSourceBuffer Monitoringalgorithm is scheduled to run.

Havingenough managed data to ensure uninterrupted playbackis 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.

Beingable to retrieve and buffer data in an efficient wayis 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.

  1. Run theMediaSourceSourceBuffer Monitoringalgorithm.
  2. Letcan play uninterrupted and efficientlybe a flag that is true if the bufferedattribute contains aTimeRangesthat includes the current playback position andenough managed data to ensure uninterrupted playbackand is able to retrieve and buffer data in an efficient way
    Ifcan play uninterrupted and efficientlyis not equal to streaming,queue an element taskon themedia element that runs the following steps:
    1. Setthisstreamingattribute tocan play uninterrupted and efficiently.
    2. Ifcan play uninterrupted and efficientlyis falsefire an eventcalled startstreamingat theManagedMediaSource.
    3. Otherwise,fire an eventcalledendstreamingat the ManagedMediaSource.

7.3.2 Memory Cleanup

  1. For eachbufferinthis'ssourceBuffers:
    1. Run thebuffer'smemory cleanupalgorithm.

8. BufferedChangeEventinterface

WebIDL[Exposed=(Window,DedicatedWorker)]
interfaceBufferedChangeEvent:Event{
constructor(DOMStringtype,optionalBufferedChangeEventIniteventInitDict= {});

[SameObject] readonly attributeTimeRangesaddedRanges;
[SameObject] readonly attributeTimeRangesremovedRanges;
};

dictionaryBufferedChangeEventInit:EventInit{
TimeRangesaddedRanges;
TimeRangesremovedRanges;
};

8.1 Attributes

addedRanges
The time ranges added between the lastupdatestartandupdateendevents (which would have occurred during the last run of thecoded frame processingalgorithm).
removedRanges
The time ranges removed between the lastupdatestartandupdateendevents (which would have occurred during the last run of thecoded frame removalorcoded frame evictionalgorithm or if the user agent evicted content in response to a memory cleanup).

9. ManagedSourceBufferinterface

WebIDL[Exposed=(Window,DedicatedWorker)]
interfaceManagedSourceBuffer:SourceBuffer{
attributeEventHandleronbufferedchange;
};

9.1 Attributes

onbufferedchange

Anevent handler IDL attributewhoseevent handler event typeis bufferedchange.

9.2 Event Summary

Event name Interface Dispatched when...
bufferedchange BufferedChangeEvent TheManagedSourceBuffer's buffered range changed following a call to appendBuffer(),remove(), endOfStream(),or as a consequence of the user agent running the memory cleanupalgorithm.

9.3 Algorithms

9.3.1 Buffered Change

The following steps are run at the completion of all operations to the ManagedSourceBufferbufferthat would cause abuffer's bufferedto change. That is onceappendBuffer(), remove()ormemory cleanupalgorithm have completed.

  1. Letprevious buffered rangesequal the bufferedattribute before the changes occurred.
  2. Letnew buffered rangesequal the newbuffered TimeRanges.
  3. Letaddedequal theprevious buffered rangessubtracted fromnew buffered ranges.
  4. Letremovedequal thenew buffered rangessubtracted fromprevious buffered ranges.
  5. LeteventInitDictbe a newBufferedChangeEventInitdictionary initialized with addedas itsaddedRangesandremovedas its removedRanges
  6. Queue a tasktofire an eventnamedbufferedchangeatbufferusing the BufferedChangeEventinterface, initialized witheventInitDict.

9.3.2 Memory cleanup

  1. Ifthisis not inthis'sManagedMediaSourceparent activeSourceBuffers:
    1. Run thecoded frame removalalgorithm with start set to 0, end set to positive infinity, and abort these steps.
  2. Letremoval rangesequal 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.
    Note

    Implementations can use different strategies for selectingremoval rangesso web applications shouldn't depend on a specific behavior. The web application would listen to thebufferedchangeevent to observe whether portions of the buffered data have been evicted.

  3. For each range inremoval ranges,run thecoded frame removalalgorithm with startandendequal to the removal range start and end timestamp respectively.

10. HTMLMediaElement Extensions

This section specifies what existingHTMLMediaElement'sseekable andHTMLMediaElement'sbufferedattributes on the HTMLMediaElementMUSTreturn when aMediaSourceis attached to the element, and what the existingHTMLMediaElement'ssrcObjectattributeMUSTalso do when it is set to be aMediaSourceHandleobject.

TheHTMLMediaElement'sseekableattribute returns a new static normalized TimeRanges objectcreated based on the following steps:

  1. If theMediaSourcewas constructed in aDedicatedWorkerGlobalScopethat is terminated or is closing then return an emptyTimeRangesobject and abort these steps.
    Note

    This 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 ofterminate a workerfor the MediaSource's DedicatedWorkerGlobalScope, for instance as the eventual result of close()execution.

    Issue 277:MSE-in-Workers: Consider (eventually) transitioning attached element to error upon termination of MediaSource's worker/what should media element do?

    Should 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.

  2. Letrecent durationandrecent live seekable rangerespectively be the recent values ofdurationand [[live seekable range]],determined as follows:
    If theMediaSourcewas constructed in aWindow
    Setrecent durationto bedurationand setrecent live seekable rangeto be[[live seekable range]].
    Otherwise:
    Setrecent durationandrecent live seekable rangerespectively 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]].
  3. Ifrecent durationequals NaN:
    Return an emptyTimeRangesobject.
    Ifrecent durationequals positive Infinity:
    1. Ifrecent live seekable rangeis not empty:
      1. Letunion rangesbe the union ofrecent live seekable rangeand theHTMLMediaElement'sbuffered attribute.
      2. Return a single range with a start time equal to the earliest start time inunion rangesand an end time equal to the highest end time inunion rangesand abort these steps.
    2. If theHTMLMediaElement'sbufferedattribute returns an emptyTimeRangesobject, then return an emptyTimeRangesobject and abort these steps.
    3. Return a single range with a start time of 0 and an end time equal to the highest end time reported by theHTMLMediaElement's bufferedattribute.
    Otherwise:
    Return a single range with a start time of 0 and an end time equal torecent duration.

TheHTMLMediaElement'sbufferedattribute returns a static normalized TimeRanges objectbased on the following steps.

  1. If theMediaSourcewas constructed in aDedicatedWorkerGlobalScopethat is terminated or is closing then return an emptyTimeRangesobject and abort these steps.
    Note

    This 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 ofterminate a workerfor the MediaSource's DedicatedWorkerGlobalScope, for instance as the eventual result of close()execution.

    Issue 277:MSE-in-Workers: Consider (eventually) transitioning attached element to error upon termination of MediaSource's worker/what should media element do?

    Should 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.

  2. Letrecent intersection rangesbe determined as follows:
    If theMediaSourcewas constructed in aWindow
    1. Letrecent intersection rangesequal an emptyTimeRangesobject.
    2. IfactiveSourceBuffers.length does not equal 0 then run the following steps:
      1. Letactive rangesbe the ranges returned bybufferedfor eachSourceBufferobject in activeSourceBuffers.
      2. Lethighest end timebe the largest range end time in theactive ranges.
      3. Letrecent intersection rangesequal a TimeRangesobject containing a single range from 0 tohighest end time.
      4. For eachSourceBufferobject inactiveSourceBuffers run the following steps:
        1. Letsource rangesequal the ranges returned by thebufferedattribute on the current SourceBuffer.
        2. IfreadyStateis "ended",then set the end time on the last range insource rangestohighest end time.
        3. Letnew intersection rangesequal the intersection between therecent intersection rangesand thesource ranges.
        4. Replace the ranges inrecent intersection rangeswith thenew intersection ranges.
    Otherwise:
    Letrecent intersection rangesbe theTimeRangesresulting from the steps for theWindowcase, but run with theMediaSourceand itsSourceBuffer objects in theirDedicatedWorkerGlobalScopeand communicated by using [[port to main]]implicit messages on every update to the activeSourceBuffers,readyState,or any of the buffering state that would change any of the values of each of those bufferedattributes of theactiveSourceBuffers.
    Note

    The overhead of recalculating and communicatingrecent intersection rangesso 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 incross-context communication model.

  3. If the current value of this attribute has not been set by this algorithm orrecent intersection rangesdoes not contain the exact same range information as the current value of this attribute, then update the current value of this attribute torecent intersection ranges.
  4. Return the current value of this attribute.

If aHTMLMediaElement'ssrcObjectattribute is assigned a MediaSourceHandle,then set[[has ever been assigned as srcobject]]for thatMediaSourceHandleto true as part of the synchronous steps of the extendedHTMLMediaElement'ssrcObjectsetter that occur before invoking the element's load algorithm.

Note

This prevents transferring thatMediaSourceHandleobject ever again, enabling clear synchronous exception if that is attempted.

Issue

MediaSourceHandleneeds to be added toHTMLMediaElement's MediaProvider IDL typedef and related text involving media provider objects.

11. AudioTrackextensions

This section specifies extensions to the [HTML]AudioTrackdefinition.

WebIDL[Exposed=(Window,DedicatedWorker)]
partial interfaceAudioTrack{
readonly attributeSourceBuffer?sourceBuffer;
};
Issue 280:MSE-in-Workers: {Audio,Video,Text}Track{,List} IDL in HTML need additional DedicatedWorker in Exposed
[HTML]AudioTrackneeds Window+DedicatedWorker exposure.

Attributes

sourceBufferof typeSourceBuffer, readonly, nullable

On getting, run the following step:

If this track was created by aSourceBufferthat was created on the same realmas this track, and if thatSourceBufferhas not been removed from thesourceBuffersattribute of itsparent media source:
Return theSourceBufferthat created this track.
Otherwise:
Return null.
Note
For example, if aDedicatedWorkerGlobalScopeSourceBuffernotified its internalcreate track mirrorhandler inWindowto create this track, then the Windowcopy of the track would return null for this attribute.

12. VideoTrackextensions

This section specifies extensions to the [HTML]VideoTrackdefinition.

WebIDL[Exposed=(Window,DedicatedWorker)]
partial interfaceVideoTrack{
readonly attributeSourceBuffer?sourceBuffer;
};
Issue 280:MSE-in-Workers: {Audio,Video,Text}Track{,List} IDL in HTML need additional DedicatedWorker in Exposed
[HTML]VideoTrackneeds Window+DedicatedWorker exposure.

Attributes

sourceBufferof typeSourceBuffer, readonly, nullable

On getting, run the following step:

If this track was created by aSourceBufferthat was created on the same realmas this track, and if thatSourceBufferhas not been removed from thesourceBuffersattribute of itsparent media source:
Return theSourceBufferthat created this track.
Otherwise:
Return null.
Note
For example, if aDedicatedWorkerGlobalScopeSourceBuffernotified its internalcreate track mirrorhandler inWindowto create this track, then the Windowcopy of the track would return null for this attribute.

13. TextTrackextensions

This section specifies extensions to the [HTML]TextTrackdefinition.

WebIDL[Exposed=(Window,DedicatedWorker)]
partial interfaceTextTrack{
readonly attributeSourceBuffer?sourceBuffer;
};
Issue 280:MSE-in-Workers: {Audio,Video,Text}Track{,List} IDL in HTML need additional DedicatedWorker in Exposed
[HTML]TextTrackneeds Window+DedicatedWorker exposure.

Attributes

sourceBufferof typeSourceBuffer, readonly, nullable

On getting, run the following step:

If this track was created by aSourceBufferthat was created on the same realmas this track, and if thatSourceBufferhas not been removed from thesourceBuffersattribute of itsparent media source:
Return theSourceBufferthat created this track.
Otherwise:
Return null.
Note
For example, if aDedicatedWorkerGlobalScopeSourceBuffernotified its internalcreate track mirrorhandler inWindowto create this track, then the Windowcopy of the track would return null for this attribute.

14. Byte Stream Formats

The bytes provided throughappendBuffer()for aSourceBufferform a logical byte stream. The format and semantics of these byte streams are defined inbyte 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 aSourceBuffer 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 SourceBufferimplementationMUSTconform to thebyte stream format specification listed in the registry entry.

Note

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.

Note

Byte stream format parsing and validation is implemented in thesegment parser loop algorithm.

This section provides general requirements for all byte stream format specifications:

Byte stream specificationsMUSTat a minimum define constraints which ensure that the above requirements hold. Additional constraintsMAYbe defined, for example to simplify implementation.

15.Conformance

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 wordsMAY,MUST,MUST NOT,SHOULD,andSHOULD NOTin 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.

16. Examples

16.1 Using Media Source Extensions

<videoid="v"autoplay></video>
<script>
constvideo =document.getElementById("v");
constmediaSource =newMediaSource();
mediaSource.addEventListener("sourceopen",onSourceOpen);
video.src =window.URL.createObjectURL(mediaSource);

asyncfunctiononSourceOpen(e){
constmediaSource = e.target;

if(mediaSource.sourceBuffers.length >0)return;

constsourceBuffer = mediaSource.addSourceBuffer(
'video/webm; codecs= "vorbis,vp8" ',
);

video.addEventListener("seeking",(e) =>onSeeking(mediaSource, e.target));
video.addEventListener("progress",() =>
appendNextMediaSegment(mediaSource),
);

try{
constinitSegment =awaitgetInitializationSegment();

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",functionfirstAppendHandler(){
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");
}
}

asyncfunctionappendNextMediaSegment(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{
constmediaSegment =awaitgetNextMediaSegment();

//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");
}
}

functiononSeeking(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);
}

functiononProgress(mediaSource, e){
appendNextMediaSegment(mediaSource);
}

// Example of async function for getting initialization segment
asyncfunctiongetInitializationSegment(){
// Implement fetching of the initialization segment
// This is just a placeholder function
}

// Example function for checking if there are more media segments
functionhaveMoreMediaSegments(){
// Implement logic to determine if there are more media segments
// This is just a placeholder function
}

// Example function for getting the next media segment
asyncfunctiongetNextMediaSegment(){
// Implement fetching of the next media segment
// This is just a placeholder function
}

// Example function for seeking to a specific media segment
functionseekToMediaSegmentAt(currentTime){
// Implement seeking logic
// This is just a placeholder function
}
</script>

16.2 Using a Managed Media Source

<script>
asyncfunctionsetUpVideoStream(){
// Specific video format and codec
constmediaType ='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.
constvideo =document.createElement("video");
constsource =newManagedMediaSource();

video.controls =true;

awaitnewPromise((resolve) =>{
video.src = URL.createObjectURL(source);
source.addEventListener("sourceopen",resolve, {once:true});
document.body.appendChild(video);
});

constsourceBuffer = 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() => {
constresponse =awaitfetch("./videos/bipbop.mp4");
constbuffer =awaitresponse.arrayBuffer();
awaitnewPromise((resolve) =>{
sourceBuffer.addEventListener("updateend",resolve, {once:true});
sourceBuffer.appendBuffer(buffer);
});
};

source.onendstreaming =async() => {
// Stop fetching new segments here
};
}

// Helper function...
functiontimeRangesToString(timeRanges){
constranges = [];
for(leti =0;i < timeRanges.length; i++) {
ranges.push([timeRanges.start(i), timeRanges.end(i)]);
}
return"["+ ranges.map(([start, end]) =>`[${start},${end})`) +"]";
}
</script>
<bodyonload="setUpVideoStream()"></body>

17. Acknowledgments

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.

A. VideoPlaybackQuality

This section is non-normative.

The video playback quality metrics described in previous revisions of this specification (e.g., sections 5 and 10 of theCandidate Recommendation) are now being developed as part of [MEDIA-PLAYBACK-QUALITY]. Some implementations may have implemented the earlier draftVideoPlaybackQualityobject and theHTMLVideoElement extension methodgetVideoPlaybackQuality()described in those previous revisions.

B.Issue summary

C.References

C.1Normative references

[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. 24 May 2024. W3C Working Draft. URL:https://www.w3.org/TR/FileAPI/
[HTML]
HTML Standard.Anne van Kesteren; Domenic Denicola; 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/

C.2Informative references

[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. 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/