Class: shaka.media.MediaSourceEngine

Constructor

new MediaSourceEngine(video, closedCaptionParsernon-null, textDisplayernon-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 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.
Implements:
Source:

Members

(private) destroyed_ :boolean

Type:
  • boolean
Source:

(private) mediaSource_ :MediaSource

Type:
  • MediaSource
Source:

(private, non-null) mediaSourceOpen_ :shaka.util.PublicPromise

Type:
Source:

(private, non-null) queues_ :Object.<string, !Array.<shaka.media.MediaSourceEngine.Operation>>

Type:
Source:

(private, non-null) sourceBuffers_ :Object.<shaka.util.ManifestParserUtils.ContentType, SourceBuffer>

Type:
Source:

(private, non-null) transmuxers_ :Object.<string, !shaka.media.Transmuxer>

Type:
Source:

Methods

(static) isBrowserSupported() → {boolean}

Returns true if the browser has the basic APIs we need.
Source:
Returns:
Type
boolean

(static) isStreamSupported(stream) → {boolean}

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

(static) probeSupport() → (non-null) {Object.<string, boolean>}

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

(private) 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:

(private) append_(contentType, datanon-null)

Append data to the SourceBuffer.
Parameters:
Name Type Description
contentType shaka.util.ManifestParserUtils.ContentType
data ArrayBuffer
Source:
Throws:
QuotaExceededError if the browser's buffer is full

appendBuffer(contentType, datanon-null, startTimenullable, endTimenullable, hasClosedCaptionsnullable) → (non-null) {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 ArrayBuffer
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
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) → (nullable) {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) → (nullable) {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) → (non-null) {Promise}

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

createMediaSource(pnon-null) → (non-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

(export) destroy() → (non-null) {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) → (non-null) {Promise}

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

(private) enqueueBlockingOperation_(run) → (non-null) {Promise}

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

(private) enqueueOperation_(contentType, start) → (non-null) {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) → (non-null) {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

(private) 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:

(private) 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}

Gets the current buffered ranges.
Source:
Returns:
Type
shaka.extern.BufferedInfo

getDuration() → {number}

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

getTextDisplayer() → (non-null) {shaka.extern.TextDisplayer}

Source:
Returns:
Type
shaka.extern.TextDisplayer

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

Initialize MediaSourceEngine. Note that it is not valid to call this multiple times, except to add or reinitialize text streams.
Parameters:
Name Type 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.
Source:
Throws:
  • InvalidAccessError if blank MIME types are given
  • NotSupportedError if unsupported MIME types are given
  • QuotaExceededError if the browser can't support that many buffers
Returns:
Type
Promise

isBuffered(contentType, time, smallGapLimitopt) → {boolean}

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

(private) onError_(contentType, eventnon-null)

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

(private) onUpdateEnd_(contentType)

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

open() → (non-null) {Promise}

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

(private) 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)

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

remove(contentType, startTime, endTime) → (non-null) {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

(private) 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:

(private) 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) → (non-null) {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

setSelectedClosedCaptionId(id)

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

setStreamProperties(contentType, timestampOffset, appendWindowStart, appendWindowEnd) → (non-null) {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.
Source:
Returns:
Type
Promise

(private) setTimestampOffset_(contentType, timestampOffset)

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

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: