Class: shaka.media.SegmentIndex

Constructor

new SegmentIndex(referencesnon-null)

Parameters:
Name Type Description
references Array.<!shaka.media.SegmentReference> The list of SegmentReferences, which must be sorted first by their start times (ascending) and second by their end times (ascending).
Implements:
Source:

Members

immutable_ :boolean

Type:
  • boolean
Source:

numEvicted :number

The number of references that have been removed from the front of the array. Used to create stable positions in the find/get APIs.
Type:
  • number
Source:

Methods

assertCorrectReferences_(referencesnon-null)

Asserts that the given SegmentReferences are sorted.
Parameters:
Name Type Description
references Array.<shaka.media.SegmentReference>
Source:

forSingleSegment(startTime, duration, urisnon-null) → {shaka.media.SegmentIndex}

Create a SegmentIndex for a single segment of the given start time and duration at the given URIs.
Parameters:
Name Type Description
startTime number
duration number
uris Array.<string>
Source:
Returns:
Type
shaka.media.SegmentIndex

evict(time)

Removes all SegmentReferences that end before the given time.
Parameters:
Name Type Description
time number The time in seconds.
Source:

find(time) → {number}

Finds the position of the segment for the given time, in seconds, relative to the start of the presentation. Returns the position of the segment with the largest end time if more than one segment is known for the given time.
Parameters:
Name Type Description
time number
Source:
Returns:
The position of the segment, or null if the position of the segment could not be determined.
Type
number

fit(windowStart, windowEndnullable, isNewopt)

Drops references that start after windowEnd, or end before windowStart, and contracts the last reference so that it ends at windowEnd. Do not call on the last period of a live presentation (unknown duration). It is okay to call on the other periods of a live presentation, where the duration is known and another period has been added.
Parameters:
Name Type Attributes Default Description
windowStart number
windowEnd number <nullable>
isNew boolean <optional>
false Whether this is a new SegmentIndex and we shouldn't update the number of evicted elements.
Source:

forEachTopLevelReference(fn)

Iterates over all top-level segment references in this segment index.
Parameters:
Name Type Description
fn function(!shaka.media.SegmentReference)
Source:

get(position) → {shaka.media.SegmentReference}

Gets the SegmentReference for the segment at the given position.
Parameters:
Name Type Description
position number The position of the segment as returned by find().
Source:
Returns:
The SegmentReference, or null if no such SegmentReference exists.
Type
shaka.media.SegmentReference

getIteratorForTime(time) → {shaka.media.SegmentIterator}

Returns a new iterator that initially points to the segment that contains the given time. Like the normal iterator, next() must be called first to get to the first element. Returns null if we do not find a segment at the requested time.
Parameters:
Name Type Description
time number
Source:
Returns:
Type
shaka.media.SegmentIterator

isEmpty() → {boolean}

Source:
Returns:
Type
boolean

markImmutable()

Marks the index as immutable. Segments cannot be added or removed after this point. This doesn't affect the references themselves. This also makes the destroy/release methods do nothing. This is mainly for testing.
Source:

merge(referencesnon-null)

Merges the given SegmentReferences. Supports extending the original references only. Will replace old references with equivalent new ones, and keep any unique old ones. Used, for example, by the DASH and HLS parser, where manifests may not list all available references, so we must keep available references in memory to fill the availability window.
Parameters:
Name Type Description
references Array.<!shaka.media.SegmentReference> The list of SegmentReferences, which must be sorted first by their start times (ascending) and second by their end times (ascending).
Source:

mergeAndEvict(referencesnon-null, windowStart)

Merges the given SegmentReferences and evicts the ones that end before the given time. Supports extending the original references only. Will not replace old references or interleave new ones. Used, for example, by the DASH and HLS parser, where manifests may not list all available references, so we must keep available references in memory to fill the availability window.
Parameters:
Name Type Description
references Array.<!shaka.media.SegmentReference> The list of SegmentReferences, which must be sorted first by their start times (ascending) and second by their end times (ascending).
windowStart number The start of the availability window to filter out the references that are no longer available.
Source:

offset(offset)

Offset all segment references by a fixed amount.
Parameters:
Name Type Description
offset number The amount to add to each segment's start and end times.
Source:

release()

Request that this object release all internal references.
Implements:
Source:

updateEvery(interval, updateCallback)

Updates the references every so often. Stops when the references list returned by the callback is null.
Parameters:
Name Type Description
interval number The interval in seconds.
updateCallback function(): Array.<shaka.media.SegmentReference>
Source: