Constructor
new SegmentPrefetch(prefetchLimit, stream, fetchDispatcher, reverse, shouldPrefetchNextSegmentnullable, getPlaybackRatenullable, allowReferencenullable)
This class manages segment prefetch operations. Called by StreamingEngine to prefetch next N segments ahead of playhead, to reduce the chances of rebuffering.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
prefetchLimit |
number | ||
stream |
shaka.extern.Stream | ||
fetchDispatcher |
shaka.media.SegmentPrefetch.FetchDispatcher | ||
reverse |
boolean | ||
shouldPrefetchNextSegment |
function |
<nullable> |
|
getPlaybackRate |
function |
<nullable> |
|
allowReference |
function |
<nullable> |
If provided and it returns false for a reference, that reference is not prefetched but iteration continues with the following one. |
- Source:
Members
allowReference_ :function(!shaka.media.SegmentReference): boolean
Type:
- function(!shaka.media.SegmentReference): boolean
- Source:
getPlaybackRate_ :function(): number
Type:
- function(): number
- Source:
initSegmentPrefetchMap_ :Map<!shaka.media.InitSegmentReference, !shaka.media.SegmentPrefetchOperation>
Type:
- Source:
segmentPrefetchMap_ :Map<!shaka.media.SegmentReference, !shaka.media.SegmentPrefetchOperation>
Type:
- Source:
shouldPrefetchNextSegment_ :function(!shaka.media.SegmentReference, !shaka.extern.Stream): boolean
Type:
- function(!shaka.media.SegmentReference, !shaka.extern.Stream): boolean
- Source:
Methods
logPrefix_(stream) → {string}
The prefix of the logs that are created in this class.
Parameters:
| Name | Type | Description |
|---|---|---|
stream |
shaka.extern.Stream |
- Source:
Returns:
- Type
- string
abortPrefetchedSegment_(referencenon-null)
Remove a segment from prefetch map and abort it.
Parameters:
| Name | Type | Description |
|---|---|---|
reference |
shaka.media.SegmentReference | shaka.media.InitSegmentReference |
- Source:
clearAll(clearInitSegmentsopt)
Clear all segment data.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
clearInitSegments |
boolean |
<optional> |
true |
- Source:
clearInitSegments_()
Remove all init segments that don't have associated segments in
the segment prefetch map. If we don't have segments, but we have
initialization segments, it is not cleaned.
By default, with delete on get, the init segments should get removed as
they are used. With deleteOnGet set to false, we need to clear them
every so often once the segments that are associated with each init segment
is no longer prefetched.
- Source:
clearMap_(mapnon-null)
Clear All Helper
Parameters:
| Name | Type | Description |
|---|---|---|
map |
Map<T, !shaka.media.SegmentPrefetchOperation> |
- Source:
dispatchFetch_(prefetchMapnon-null, reference, segmentPrefetchOperationnon-null) → {Promise}
Starts a prefetch operation that is about to be added to |prefetchMap|.
If it fails, it is removed from the map, so that a later request for the
same reference, such as one made when streaming is retried, fetches it
again instead of getting the same failure.
Parameters:
| Name | Type | Description |
|---|---|---|
prefetchMap |
Map<T, !shaka.media.SegmentPrefetchOperation> | |
reference |
T | |
segmentPrefetchOperation |
shaka.media.SegmentPrefetchOperation |
- Source:
Returns:
- Type
- Promise
evict(time, clearInitSegmentsopt)
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
time |
number | |||
clearInitSegments |
boolean |
<optional> |
false |
- Source:
getPrefetchedSegment(referencenon-null, streamDataCallbacknullable) → {shaka.net.NetworkingEngine.PendingRequest}
Get the result of prefetched segment if already exists.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
reference |
shaka.media.SegmentReference | shaka.media.InitSegmentReference | ||
streamDataCallback |
?function(BufferSource): !Promise= |
<nullable> |
- Source:
Returns:
op
getStream() → {shaka.extern.Stream}
Get the current stream.
- Source:
Returns:
- Type
- shaka.extern.Stream
prefetchInitSegment(initSegmentReferencenon-null) → {Promise}
Fetch init segment.
Parameters:
| Name | Type | Description |
|---|---|---|
initSegmentReference |
shaka.media.InitSegmentReference |
- Source:
Returns:
- Type
- Promise
prefetchSegmentsByTime(currTime, skipFirstopt) → {Promise}
Fetch next segments ahead of current time.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
currTime |
number | |||
skipFirst |
boolean |
<optional> |
false |
- Source:
Returns:
- Type
- Promise
removeReference(referencenon-null)
Remove a reference of prefetched segment if already exists.
Parameters:
| Name | Type | Description |
|---|---|---|
reference |
shaka.media.SegmentReference | shaka.media.InitSegmentReference |
- Source:
replaceFetchDispatcher(fetchDispatcher)
Parameters:
| Name | Type | Description |
|---|---|---|
fetchDispatcher |
shaka.media.SegmentPrefetch.FetchDispatcher |
- Source:
resetLimit(newPrefetchLimit)
Reset the prefetchLimit and clear all internal states.
Called by StreamingEngine when configure() was called.
Parameters:
| Name | Type | Description |
|---|---|---|
newPrefetchLimit |
number |
- Source:
resetPosition()
- Source:
setReverse(reverse)
Parameters:
| Name | Type | Description |
|---|---|---|
reverse |
boolean |
- Source:
switchStream(stream)
Called by Streaming Engine when switching variant.
Parameters:
| Name | Type | Description |
|---|---|---|
stream |
shaka.extern.Stream |
- Source:
takeOverEquivalentReference_(referencenon-null) → {boolean}
A manifest update can create a new reference for a segment that is
already prefetched under another reference, e.g. in a multi-period live
DASH stream, the open-ended last Period extrapolates a segment that later
turns out to be the first one of the next Period. If the prefetch map has
a reference to the same media (see SegmentReference.isSameMedia()), its
prefetch operation is moved to the given reference, so that the segment is
not downloaded twice. The start time is compared too, so that a URI that
is used again at another time (e.g. a repeated filler segment) keeps its
own prefetch.
Parameters:
| Name | Type | Description |
|---|---|---|
reference |
shaka.media.SegmentReference |
- Source:
Returns:
True if an equivalent reference was taken over.
- Type
- boolean
Type Definitions
FetchDispatcher
A callback function that fetches a segment.
Type:
- function(!(shaka.media.InitSegmentReference|shaka.media.SegmentReference), shaka.extern.Stream, ?function(BufferSource): !Promise=): !shaka.net.NetworkingEngine.PendingRequest
- Source: