Constructor
new MediaSourceEngine(video, textDisplayernon-null, playerInterfacenon-null, lcevcDecopt, nullable)
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. | |
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. | |
playerInterface |
shaka.media.MediaSourceEngine.PlayerInterface | Interface for common player methods. | |
lcevcDec |
shaka.lcevc.Dec |
<optional> <nullable> |
Optional - LCEVC Decoder Object |
- 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
SourceBufferMode_ :string
Type:
- string
Properties:
Name | Value | Type | Description |
---|---|---|---|
SEQUENCE |
sequence | string | |
SEGMENTS |
segments | string |
attemptTimestampOffsetCalculation_ :boolean
Type:
- boolean
- Source:
audioCompensation_ :shaka.util.PublicPromise.<number>
Type:
- shaka.util.PublicPromise.<number>
- Source:
expectedEncryption_ :Object.<shaka.util.ManifestParserUtils.ContentType, boolean>
Type:
- Object.<shaka.util.ManifestParserUtils.ContentType, boolean>
- Source:
firstAudioReferenceStartTime_ :number
Type:
- number
- Source:
firstVideoReferenceStartTime_ :number
Type:
- number
- Source:
ignoreManifestTimestampsInSegmentsMode_ :boolean
Type:
- boolean
- Source:
queues_ :Object.<string, !Array.<shaka.media.MediaSourceEngine.Operation>>
Type:
- Object.<string, !Array.<shaka.media.MediaSourceEngine.Operation>>
- Source:
sourceBuffers_ :Object.<shaka.util.ManifestParserUtils.ContentType, SourceBuffer>
Type:
- Object.<shaka.util.ManifestParserUtils.ContentType, SourceBuffer>
- Source:
sourceBufferTypes_ :Object.<shaka.util.ManifestParserUtils.ContentType, string>
Type:
- Object.<shaka.util.ManifestParserUtils.ContentType, string>
- Source:
textSequenceModeOffset_ :shaka.util.PublicPromise.<number>
Type:
- shaka.util.PublicPromise.<number>
- Source:
transmuxers_ :Object.<string, !shaka.extern.Transmuxer>
Type:
- Object.<string, !shaka.extern.Transmuxer>
- Source:
Methods
isStreamSupported(stream, contentType) → {Promise.<boolean>}
Checks if a certain type is supported.
Parameters:
Name | Type | Description |
---|---|---|
stream |
shaka.extern.Stream | |
contentType |
shaka.util.ManifestParserUtils.ContentType |
- Source:
Returns:
- Type
- Promise.<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 |
addExtraFeaturesToMimeType_(mimeType) → {string}
Parameters:
Name | Type | Description |
---|---|---|
mimeType |
string |
Returns:
- Type
- string
append_(contentType, data, timestampOffset)
Append data to the SourceBuffer.
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType | |
data |
BufferSource | |
timestampOffset |
number |
appendBuffer(contentType, datanon-null, referencenullable, stream, hasClosedCaptionsnullable, seekedopt, adaptationopt, isChunkedDataopt) → {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 | Default | Description |
---|---|---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType | |||
data |
BufferSource | |||
reference |
shaka.media.SegmentReference |
<nullable> |
The segment reference we are appending, or null for init segments | |
stream |
shaka.extern.Stream | |||
hasClosedCaptions |
boolean |
<nullable> |
True if the buffer contains CEA closed captions | |
seeked |
boolean |
<optional> |
false | True if we just seeked |
adaptation |
boolean |
<optional> |
false | True if we just automatically switched active variant(s). |
isChunkedData |
boolean |
<optional> |
false | True if we add to the buffer from the partial read of the segment. |
- 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
change_(contentType, mimeType, transmuxernullable)
Prepare the SourceBuffer to parse a potentially new type or codec.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType | ||
mimeType |
string | ||
transmuxer |
shaka.extern.Transmuxer |
<nullable> |
changeType(contentType, mimeType, transmuxernullable) → {Promise}
Enqueue an operation to prepare the SourceBuffer to parse a potentially new
type or codec.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType | ||
mimeType |
string | ||
transmuxer |
shaka.extern.Transmuxer |
<nullable> |
Returns:
- Type
- Promise
clear(contentType) → {Promise}
Enqueue an operation to clear the SourceBuffer.
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType |
Returns:
- Type
- Promise
clearSelectedClosedCaptionId()
Disable embedded closed captions.
codecSwitchIfNecessary_(contentType, mimeType, codecs, streamsByTypenon-null) → {Promise.<boolean>}
Codec switch if necessary, this will not resolve until the codec
switch is over.
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType | |
mimeType |
string | |
codecs |
string | |
streamsByType |
Map.<shaka.util.ManifestParserUtils.ContentType, shaka.extern.Stream> |
Returns:
true if there was a codec switch,
false otherwise.
- Type
- Promise.<boolean>
configure(config)
Called by the Player to provide an updated configuration any time it
changes. Must be called at least once before init().
Parameters:
Name | Type | Description |
---|---|---|
config |
shaka.extern.MediaSourceConfiguration |
- 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
doDestroy_()
- Source:
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(): (Promise|undefined) |
Returns:
- Type
- Promise
enqueueOperation_(contentType, start, urinullable) → {Promise}
Enqueue an operation and start it if appropriate.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType | ||
start |
function() | ||
uri |
string |
<nullable> |
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 |
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 |
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:
getCaptionParser(mimeType) → {shaka.media.IClosedCaptionParser}
Create a new closed caption parser. This will ONLY be replaced by tests as
a way to inject fake closed caption parser instances.
Parameters:
Name | Type | Description |
---|---|---|
mimeType |
string |
- Source:
Returns:
getDuration() → {number}
Get the current MediaSource duration.
Returns:
- Type
- number
getTextDisplayer() → {shaka.extern.TextDisplayer}
Returns:
getTimestampAndDispatchMetadata_(contentType, datanon-null, referencenullable, mimeTypenon-null) → {{timestamp: ?number, metadata: !Array.<shaka.extern.ID3Metadata>}}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType | ||
data |
BufferSource | ||
reference |
shaka.media.SegmentReference |
<nullable> |
The segment reference we are appending, or null for init segments |
mimeType |
string |
- Source:
Returns:
- Type
- {timestamp: ?number, metadata: !Array.<shaka.extern.ID3Metadata>}
init(streamsByTypenon-null, sequenceModeopt, manifestTypeopt, ignoreManifestTimestampsInSegmentsModeopt) → {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. | ||
sequenceMode |
boolean |
<optional> |
false | If true, the media segments are appended to the SourceBuffer in strict sequence. |
manifestType |
string |
<optional> |
Indicates the type of the manifest. | |
ignoreManifestTimestampsInSegmentsMode |
boolean |
<optional> |
false | If true, don't adjust the timestamp offset to account for manifest segment durations being out of sync with segment durations. In other words, assume that there are no gaps in the segments when appending to the SourceBuffer, even if the manifest and segment times disagree. Indicates if the manifest has text streams. |
- Source:
Returns:
- Type
- Promise
initSourceBuffer_(contentType, stream, codecs) → {Promise}
Initialize a specific SourceBuffer.
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType | |
stream |
shaka.extern.Stream | |
codecs |
string |
- 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
isCodecSwitchNecessary_(contentType, stream, refMimeType, refCodecs) → {boolean}
Returns true if it's necessary codec switch to load the new stream.
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType | |
stream |
shaka.extern.Stream | |
refMimeType |
string | |
refCodecs |
string |
Returns:
- Type
- boolean
isResetMediaSourceNecessary(contentType, stream, mimeType, codecs) → {boolean}
Returns true if it's necessary reset the media source to load the
new stream.
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType | |
stream |
shaka.extern.Stream | |
mimeType |
string | |
codecs |
string |
Returns:
- Type
- boolean
isStreamingAllowed() → {boolean}
Indicate if the streaming is allowed by MediaSourceEngine.
If we using MediaSource we allways returns true.
- Source:
Returns:
- Type
- boolean
onError_(contentType)
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType |
onUpdateEnd_(contentType)
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType |
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 |
reinitText(mimeType, sequenceMode, external)
Reinitialize the TextEngine for a new text type.
Parameters:
Name | Type | Description |
---|---|---|
mimeType |
string | |
sequenceMode |
boolean | |
external |
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 |
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 |
reset(streamsByTypenon-null) → {Promise}
Resets the Media Source
Parameters:
Name | Type | Description |
---|---|---|
streamsByType |
Map.<shaka.util.ManifestParserUtils.ContentType, shaka.extern.Stream> |
Returns:
- Type
- Promise
reset_(streamsByTypenon-null)
Resets the MediaSource and re-adds source buffers due to codec mismatch
Parameters:
Name | Type | Description |
---|---|---|
streamsByType |
Map.<shaka.util.ManifestParserUtils.ContentType, shaka.extern.Stream> |
resetCaptionParser()
Fully reset the state of the caption parser owned by MediaSourceEngine.
resync(contentType, timestampOffset) → {Promise}
Adjust timestamp offset to maintain AV sync across discontinuities.
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType | |
timestampOffset |
number |
Returns:
- Type
- Promise
setAppendWindow_(contentType, appendWindowStart, appendWindowEnd)
Set the SourceBuffer's append window end.
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType | |
appendWindowStart |
number | |
appendWindowEnd |
number |
setDuration(duration) → {Promise}
Parameters:
Name | Type | Description |
---|---|---|
duration |
number |
Returns:
- Type
- Promise
setSegmentRelativeVttTiming(segmentRelativeVttTiming)
Parameters:
Name | Type | Description |
---|---|---|
segmentRelativeVttTiming |
boolean |
setSelectedClosedCaptionId(id)
Set the selected closed captions Id and language.
Parameters:
Name | Type | Description |
---|---|---|
id |
string |
setStreamProperties(contentType, timestampOffset, appendWindowStart, appendWindowEnd, ignoreTimestampOffset, mimeType, codecs, streamsByTypenon-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. |
ignoreTimestampOffset |
boolean | If true, the timestampOffset will not be applied in this step. |
mimeType |
string | |
codecs |
string | |
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. |
Returns:
- Type
- Promise
setTextDisplayer(textDisplayernon-null)
Parameters:
Name | Type | Description |
---|---|---|
textDisplayer |
shaka.extern.TextDisplayer |
setTimestampOffset_(contentType, timestampOffset)
Set the SourceBuffer's timestamp offset.
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType | |
timestampOffset |
number |
startOperation_(contentType)
Starts the next operation in the queue.
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType |
updateLcevcDec(lcevcDecnullable)
Update LCEVC Decoder object when ready for LCEVC Decode.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
lcevcDec |
shaka.lcevc.Dec |
<nullable> |
workAroundBrokenPlatforms_(segmentnon-null, startTimenullable, contentType, urinullable) → {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 | ||
uri |
string |
<nullable> |
Returns:
- Type
- BufferSource
Type Definitions
Operation
An operation in queue.
Type:
- {start: function(), p: !shaka.util.PublicPromise, uri: ?string}
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
start |
function | The function which starts the operation. | |
p |
shaka.util.PublicPromise | The PublicPromise which is associated with this operation. | |
uri |
string |
<nullable> |
A segment URI (if any) associated with this operation. |
PlayerInterface
Player interface
Type:
- {getKeySystem: function(): ?string, onMetadata: function(!Array.<shaka.extern.ID3Metadata>, number, ?number)}
Properties:
Name | Type | Description |
---|---|---|
getKeySystem |
function | Gets currently used key system or null if not used. |
onMetadata |
function | Callback to use when metadata arrives. |