Class: shaka.media.MediaSourceEngine

MediaSourceEngine wraps all operations on MediaSource and SourceBuffers. All asynchronous operations return a Promise, and all operations are internally synchronized and serialized as needed. Operations that can be done in parallel will be done in parallel.

Constructor

new MediaSourceEngine(video, closedCaptionParsernon-null, textDisplayernon-null, onMetadataopt, non-null)

MediaSourceEngine wraps all operations on MediaSource and SourceBuffers. All asynchronous operations return a Promise, and all operations are internally synchronized and serialized as needed. Operations that can be done in parallel will be done in parallel.

Parameters:
Name Type Attributes Description
video HTMLMediaElement The video element, whose source is tied to MediaSource during the lifetime of the MediaSourceEngine.
closedCaptionParser shaka.media.IClosedCaptionParser The closed caption parser that should be used to parser closed captions from the video stream. MediaSourceEngine takes ownership of the parser. When MediaSourceEngine is destroyed, it will destroy the parser.
textDisplayer shaka.extern.TextDisplayer The text displayer that will be used with the text engine. MediaSourceEngine takes ownership of the displayer. When MediaSourceEngine is destroyed, it will destroy the displayer.
onMetadata function <optional>
Implements:
Source:

Members

createObjectURL :function(?):string

Internal reference to window.URL.createObjectURL function to avoid compatibility issues with other libraries and frameworks such as React Native. For use in unit tests only, not meant for external use.
Type:
  • function(?):string
Source:

RAW_FORMATS :Array.<string>

MIME types of raw formats.
Type:
  • Array.<string>
Source:

SourceBufferMode_ :string

Type:
  • string
Properties:
Name Value Type Description
SEQUENCE sequence string
SEGMENTS segments string
Source:

mediaSource_ :MediaSource

Type:
  • MediaSource
Source:

onMetadata_ :!function(!Array.<shaka.extern.ID3Metadata>, number, ?number)

Type:
  • !function(!Array.<shaka.extern.ID3Metadata>, number, ?number)
Source:

queues_ :Object.<string, !Array.<shaka.media.MediaSourceEngine.Operation>>

Type:
Source:

segmentRelativeVttTiming_ :boolean

Type:
  • boolean
Source:

sequenceMode_ :boolean

Type:
  • boolean
Source:

sourceBuffers_ :Object.<shaka.util.ManifestParserUtils.ContentType, SourceBuffer>

Type:
Source:

textSequenceModeOffset_ :shaka.util.PublicPromise.<number>

Type:
Source:

transmuxers_ :Object.<string, !shaka.media.Transmuxer>

Type:
Source:

url_ :string

Type:
  • string
Source:

Methods

isStreamSupported(stream) → {boolean}

Checks if a certain type is supported.
Parameters:
Name Type Description
stream shaka.extern.Stream
Source:
Returns:
Type
boolean

probeSupport() → {Object.<string, boolean>}

Returns a map of MediaSource support for well-known types.
Source:
Returns:
Type
Object.<string, boolean>

abort_(contentType)

Call abort() on the SourceBuffer. This resets MSE's last_decode_timestamp on all track buffers, which should trigger the splicing logic for overlapping segments.
Parameters:
Name Type Description
contentType shaka.util.ManifestParserUtils.ContentType
Source:

append_(contentType, data)

Append data to the SourceBuffer.
Parameters:
Name Type Description
contentType shaka.util.ManifestParserUtils.ContentType
data BufferSource
Source:

appendBuffer(contentType, datanon-null, startTimenullable, endTimenullable, hasClosedCaptionsnullable, seekedopt) → {Promise}

Enqueue an operation to append data to the SourceBuffer. Start and end times are needed for TextEngine, but not for MediaSource. Start and end times may be null for initialization segments; if present they are relative to the presentation timeline.
Parameters:
Name Type Attributes Description
contentType shaka.util.ManifestParserUtils.ContentType
data BufferSource
startTime number <nullable>
relative to the start of the presentation
endTime number <nullable>
relative to the start of the presentation
hasClosedCaptions boolean <nullable>
True if the buffer contains CEA closed captions
seeked boolean <optional>
True if we just seeked
Source:
Returns:
Type
Promise

bufferedAheadOf(contentType, time) → {number}

Computes how far ahead of the given timestamp is buffered for the given content type.
Parameters:
Name Type Description
contentType shaka.util.ManifestParserUtils.ContentType
time number
Source:
Returns:
The amount of time buffered ahead in seconds.
Type
number

bufferEnd(contentType) → {number}

Gets the last timestamp in buffer for the given content type.
Parameters:
Name Type Description
contentType shaka.util.ManifestParserUtils.ContentType
Source:
Returns:
The timestamp in seconds, or null if nothing is buffered.
Type
number

bufferStart(contentType) → {number}

Gets the first timestamp in buffer for the given content type.
Parameters:
Name Type Description
contentType shaka.util.ManifestParserUtils.ContentType
Source:
Returns:
The timestamp in seconds, or null if nothing is buffered.
Type
number

clear(contentType) → {Promise}

Enqueue an operation to clear the SourceBuffer.
Parameters:
Name Type Description
contentType shaka.util.ManifestParserUtils.ContentType
Source:
Returns:
Type
Promise

clearSelectedClosedCaptionId()

Disable embedded closed captions.
Source:

createMediaSource(pnon-null) → {MediaSource}

Create a MediaSource object, attach it to the video element, and return it. Resolves the given promise when the MediaSource is ready. Replaced by unit tests.
Parameters:
Name Type Description
p shaka.util.PublicPromise
Source:
Returns:
Type
MediaSource

destroy() → {Promise}

Request that this object be destroyed, releasing all resources and shutting down all operations. Returns a Promise which is resolved when destruction is complete. This Promise should never be rejected.
Implements:
Source:
Returns:
Type
Promise

ended() → {boolean}

Source:
Returns:
True if the MediaSource is in an "ended" state, or if the object has been destroyed.
Type
boolean

endOfStream(reasonopt) → {Promise}

Parameters:
Name Type Attributes Description
reason string <optional>
Valid reasons are 'network' and 'decode'.
Source:
See:
Returns:
Type
Promise

enqueueBlockingOperation_(run) → {Promise}

Enqueue an operation which must block all other operations on all SourceBuffers.
Parameters:
Name Type Description
run function()
Source:
Returns:
Type
Promise

enqueueOperation_(contentType, start) → {Promise}

Enqueue an operation and start it if appropriate.
Parameters:
Name Type Description
contentType shaka.util.ManifestParserUtils.ContentType
start function()
Source:
Returns:
Type
Promise

flush(contentType) → {Promise}

Enqueue an operation to flush the SourceBuffer. This is a workaround for what we believe is a Chromecast bug.
Parameters:
Name Type Description
contentType shaka.util.ManifestParserUtils.ContentType
Source:
Returns:
Type
Promise

flush_(contentType)

Nudge the playhead to force the media pipeline to be flushed. This seems to be necessary on Chromecast to get new content to replace old content.
Parameters:
Name Type Description
contentType shaka.util.ManifestParserUtils.ContentType
Source:

getBuffered_(contentType) → {TimeRanges}

Parameters:
Name Type Description
contentType shaka.util.ManifestParserUtils.ContentType
Source:
Returns:
The buffered ranges for the given content type, or null if the buffered ranges could not be obtained.
Type
TimeRanges

getBufferedInfo() → {shaka.extern.BufferedInfo}

Returns info about what is currently buffered.
Source:
Returns:
Type
shaka.extern.BufferedInfo

getDuration() → {number}

Get the current MediaSource duration.
Source:
Returns:
Type
number

init(streamsByTypenon-null, forceTransmuxTS, sequenceModeopt) → {Promise}

Initialize MediaSourceEngine. Note that it is not valid to call this multiple times, except to add or reinitialize text streams.
Parameters:
Name Type Attributes Default Description
streamsByType Map.<shaka.util.ManifestParserUtils.ContentType, shaka.extern.Stream> A map of content types to streams. All streams must be supported according to MediaSourceEngine.isStreamSupported.
forceTransmuxTS boolean If true, this will transmux TS content even if it is natively supported.
sequenceMode boolean <optional>
false If true, the media segments are appended to the SourceBuffer in strict sequence.
Source:
Returns:
Type
Promise

isBuffered(contentType, time) → {boolean}

Determines if the given time is inside the buffered range of the given content type.
Parameters:
Name Type Description
contentType shaka.util.ManifestParserUtils.ContentType
time number Playhead time
Source:
Returns:
Type
boolean

onError_(contentType)

Parameters:
Name Type Description
contentType shaka.util.ManifestParserUtils.ContentType
Source:

onSourceOpen_(pnon-null)

Parameters:
Name Type Description
p shaka.util.PublicPromise
Source:

onUpdateEnd_(contentType)

Parameters:
Name Type Description
contentType shaka.util.ManifestParserUtils.ContentType
Source:

open() → {Promise}

Source:
Returns:
Resolved when MediaSource is open and attached to the media element. This process is actually initiated by the constructor.
Type
Promise

popFromQueue_(contentType)

Pop from the front of the queue and start a new operation.
Parameters:
Name Type Description
contentType shaka.util.ManifestParserUtils.ContentType
Source:

reinitText(mimeType, sequenceMode)

Reinitialize the TextEngine for a new text type.
Parameters:
Name Type Description
mimeType string
sequenceMode boolean
Source:

remove(contentType, startTime, endTime) → {Promise}

Enqueue an operation to remove data from the SourceBuffer.
Parameters:
Name Type Description
contentType shaka.util.ManifestParserUtils.ContentType
startTime number relative to the start of the presentation
endTime number relative to the start of the presentation
Source:
Returns:
Type
Promise

remove_(contentType, startTime, endTime)

Remove data from the SourceBuffer.
Parameters:
Name Type Description
contentType shaka.util.ManifestParserUtils.ContentType
startTime number relative to the start of the presentation
endTime number relative to the start of the presentation
Source:

resetCaptionParser()

Fully reset the state of the caption parser owned by MediaSourceEngine.
Source:

setAppendWindow_(contentType, appendWindowStart, appendWindowEnd)

Set the SourceBuffer's append window end.
Parameters:
Name Type Description
contentType shaka.util.ManifestParserUtils.ContentType
appendWindowStart number
appendWindowEnd number
Source:

setDuration(duration) → {Promise}

We only support increasing duration at this time. Decreasing duration causes the MSE removal algorithm to run, which results in an 'updateend' event. Supporting this scenario would be complicated, and is not currently needed.
Parameters:
Name Type Description
duration number
Source:
Returns:
Type
Promise

setSegmentRelativeVttTiming(segmentRelativeVttTiming)

Parameters:
Name Type Description
segmentRelativeVttTiming boolean
Source:

setSelectedClosedCaptionId(id)

Set the selected closed captions Id and language.
Parameters:
Name Type Description
id string
Source:

setStreamProperties(contentType, timestampOffset, appendWindowStart, appendWindowEnd, sequenceMode) → {Promise}

Sets the timestamp offset and append window end for the given content type.
Parameters:
Name Type Description
contentType shaka.util.ManifestParserUtils.ContentType
timestampOffset number The timestamp offset. Segments which start at time t will be inserted at time t + timestampOffset instead. This value does not affect segments which have already been inserted.
appendWindowStart number The timestamp to set the append window start to. For future appends, frames/samples with timestamps less than this value will be dropped.
appendWindowEnd number The timestamp to set the append window end to. For future appends, frames/samples with timestamps greater than this value will be dropped.
sequenceMode boolean If true, the timestampOffset will not be applied in this step.
Source:
Returns:
Type
Promise

setTextDisplayer(textDisplayernon-null)

Parameters:
Name Type Description
textDisplayer shaka.extern.TextDisplayer
Source:

setTimestampOffset_(contentType, timestampOffset)

Set the SourceBuffer's timestamp offset.
Parameters:
Name Type Description
contentType shaka.util.ManifestParserUtils.ContentType
timestampOffset number
Source:

startOperation_(contentType)

Starts the next operation in the queue.
Parameters:
Name Type Description
contentType shaka.util.ManifestParserUtils.ContentType
Source:

workAroundBrokenPlatforms_(segmentnon-null, startTimenullable, contentType) → {BufferSource}

Apply platform-specific transformations to this segment to work around issues in the platform.
Parameters:
Name Type Attributes Description
segment BufferSource
startTime number <nullable>
contentType shaka.util.ManifestParserUtils.ContentType
Source:
Returns:
Type
BufferSource

Type Definitions

Operation

An operation in queue.

Type:
Properties:
Name Type Description
start function The function which starts the operation.
p shaka.util.PublicPromise The PublicPromise which is associated with this operation.
Source: