Class: shaka.media.SourceBufferManager

Constructor

new SourceBufferManager(mediaSourcenon-null, fullMimeType, estimatornon-null)

Creates a SourceBufferManager (SBM), which manages a SourceBuffer and provides an enhanced interface based on Promises. The SBM manages access to a SourceBuffer object through a fetch operation and a clear operation. It also maintains a "virtual source buffer" to keep track of which segments have been appended to the actual underlying SourceBuffer. The SBM uses this virtual source buffer because it cannot rely on the browser to tell it what is in the underlying SourceBuffer because a SegmentIndex may use PTS (presentation timestamps) and a browser may use DTS (decoding timestamps) or vice-versa.
Parameters:
Name Type Description
mediaSource MediaSource The MediaSource, which must be in the 'open' state.
fullMimeType string The full MIME type of the SourceBuffer to create, which |mediaSource| must support.
estimator shaka.util.IBandwidthEstimator A bandwidth estimator to attach to all requests.
Source:
Throws:
if no more SourceBuffers are allowed.
Type
QuotaExceededError

Members

(private, static, constant) FUDGE_FACTOR_ :number

A fudge factor to apply to buffered ranges to account for rounding error.
Type:
  • number
Source:

(private) contentDatabase_ :shaka.util.ContentDatabaseReader

Type:
Source:

(private, non-null) estimator_ :shaka.util.IBandwidthEstimator

Type:
Source:

(private, non-null) eventManager_ :shaka.util.EventManager

Type:
Source:

(private, non-null) inserted_ :Array.<!shaka.media.SegmentReference>

Contains a list of segments that have been inserted into the SourceBuffer. These segments may or may not have been evicted by the browser.
Type:
Source:

(private, non-null) mediaSource_ :MediaSource

Type:
  • MediaSource
Source:

(private) mimeType_ :string

Type:
  • string
Source:

(private) operationPromise_ :shaka.util.PublicPromise

Type:
Source:

(private) segmentRequestTimeout_ :number

Type:
  • number
Source:

(private, non-null) sourceBuffer_ :SourceBuffer

Type:
  • SourceBuffer
Source:

(private) task_ :shaka.util.Task

Type:
Source:

(private) timestampCorrection_ :number

Type:
  • number
Source:

Methods

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

Aborts the current operation if one exists. The returned promise will never be rejected.
Source:
Returns:
Type
Promise

(private) abort_()

Abort the current operation on the source buffer.
Source:

(private) append_(datanon-null) → (non-null) {Promise}

Append to the source buffer.
Parameters:
Name Type Description
data ArrayBuffer
Source:
Returns:
Type
Promise

bufferedAheadOf(timestamp) → {number}

Computes how far ahead of the given timestamp we have buffered according to the underlying SourceBuffer.
Parameters:
Name Type Description
timestamp number The timestamp in seconds.
Source:
Returns:
in seconds
Type
number

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

Resets the virtual source buffer and clears all media from the underlying SourceBuffer. The returned promise will resolve immediately if there is no media within the underlying SourceBuffer. This cannot be called if another operation is in progress.
Source:
Returns:
Type
Promise

(private) clear_() → (non-null) {Promise}

Clear the source buffer.
Source:
Returns:
Type
Promise

clearAfter(timestamp) → (non-null) {Promise}

Resets the virtual source buffer and clears all media from the underlying SourceBuffer after the given timestamp. The returned promise will resolve immediately if there is no media within the underlying SourceBuffer. This cannot be called if another operation is in progress.
Parameters:
Name Type Description
timestamp number
Source:
Returns:
Type
Promise

(private) clearAfter_(timestamp) → (non-null) {Promise}

Clear the source buffer after the given timestamp (aligned to the next segment boundary).
Parameters:
Name Type Description
timestamp number
Source:
Returns:
Type
Promise

correct(timestampCorrection)

Corrects each SegmentReference in the virtual source buffer by the given timestamp correction. The previous timestamp correction, if it exists, is replaced.
Parameters:
Name Type Description
timestampCorrection number
Source:

destroy()

Destroys the SourceBufferManager.
Source:

detectMultipleBufferedRanges() → {boolean}

Emits an error message and returns true if there are multiple buffered ranges; otherwise, does nothing and returns false.
Source:
Returns:
Type
boolean

fetch(referencenon-null, timestampOffset, initData) → (non-null) {Promise.<?number>}

Fetches the segment corresponding to the given SegmentReference and appends the it to the underlying SourceBuffer. This cannot be called if another operation is in progress.
Parameters:
Name Type Description
reference shaka.media.SegmentReference
timestampOffset number An offset, in seconds, that will be applied to each timestamp within the segment before appending it to the underlying SourceBuffer.
initData ArrayBuffer Optional initialization segment that will be appended to the underlying SourceBuffer before the retrieved segment.
Source:
Returns:
A promise to a timestamp correction, which may be null if a timestamp correction could not be computed. A timestamp correction is computed if the underlying SourceBuffer is initially empty. The timestamp correction, if one is computed, is not automatically applied to the virtual source buffer; to apply a timestamp correction, call correct().
Type
Promise.<?number>

getLastInserted() → {shaka.media.SegmentReference}

Gets the SegmentReference corresponding to the last inserted segment.
Source:
Returns:
Type
shaka.media.SegmentReference

isBuffered(timestamp) → {boolean}

Checks if the given timestamp is buffered according to the underlying SourceBuffer.
Parameters:
Name Type Description
timestamp number The timestamp in seconds.
Source:
Returns:
True if the timestamp is buffered.
Type
boolean

isInserted(timestamp) → {boolean}

Checks if the given timestamp is buffered according to the virtual source buffer. Note that as a SegmentIndex may use PTS and a browser may use DTS or vice-versa, and due to MSE implementation details, isInserted(t) does not imply isBuffered(t) nor does isBuffered(t) imply isInserted(t).
Parameters:
Name Type Description
timestamp number The timestamp in seconds.
Source:
Returns:
True if the timestamp is buffered.
Type
boolean

(private) logPrefix_() → {string}

Returns a string with the form 'SBM MIME_TYPE:' for logging purposes.
Source:
Returns:
Type
string

(private) onSourceBufferUpdateEnd_(eventnon-null)

|sourceBuffer_|'s 'updateend' callback.
Parameters:
Name Type Description
event Event
Source:

setSegmentRequestTimeout(timeout)

Sets the segment request timeout in seconds.
Parameters:
Name Type Description
timeout number
Source:

(private) startTask_() → (non-null) {Promise}

Starts the task and returns a Promise which is resolved/rejected after the task ends and is cleaned up.
Source:
Returns:
Type
Promise