@UnstableApi
public class DefaultSsChunkSource implements SsChunkSource


A default SsChunkSource implementation.

Summary

Nested types

Public constructors

DefaultSsChunkSource(
    LoaderErrorThrower manifestLoaderErrorThrower,
    SsManifest manifest,
    int streamElementIndex,
    ExoTrackSelection trackSelection,
    DataSource dataSource,
    @Nullable CmcdConfiguration cmcdConfiguration,
    SubtitleParser.Factory subtitleParserFactory,
    boolean parseSubtitlesDuringExtraction
)

Public methods

long
getAdjustedSeekPositionUs(
    long positionUs,
    SeekParameters seekParameters
)

Adjusts a seek position given the specified SeekParameters.

final void
getNextChunk(
    LoadingInfo loadingInfo,
    long loadPositionUs,
    List<MediaChunk> queue,
    ChunkHolder out
)

Returns the next chunk to load.

int
getPreferredQueueSize(long playbackPositionUs, List<MediaChunk> queue)

Evaluates whether MediaChunks should be removed from the back of the queue.

void

If the source is currently having difficulty providing chunks, then this method throws the underlying error.

void

Called when the ChunkSampleStream has finished loading a chunk obtained from this source.

boolean
onChunkLoadError(
    Chunk chunk,
    boolean cancelable,
    LoadErrorHandlingPolicy.LoadErrorInfo loadErrorInfo,
    LoadErrorHandlingPolicy loadErrorHandlingPolicy
)

Called when the ChunkSampleStream encounters an error loading a chunk obtained from this source.

void

Releases any held resources.

boolean
shouldCancelLoad(
    long playbackPositionUs,
    Chunk loadingChunk,
    List<MediaChunk> queue
)

Returns whether an ongoing load of a chunk should be canceled.

void

Updates the manifest.

void

Updates the track selection.

Public constructors

DefaultSsChunkSource

public DefaultSsChunkSource(
    LoaderErrorThrower manifestLoaderErrorThrower,
    SsManifest manifest,
    int streamElementIndex,
    ExoTrackSelection trackSelection,
    DataSource dataSource,
    @Nullable CmcdConfiguration cmcdConfiguration,
    SubtitleParser.Factory subtitleParserFactory,
    boolean parseSubtitlesDuringExtraction
)
Parameters
LoaderErrorThrower manifestLoaderErrorThrower

Throws errors affecting loading of manifests.

SsManifest manifest

The initial manifest.

int streamElementIndex

The index of the stream element in the manifest.

ExoTrackSelection trackSelection

The track selection.

DataSource dataSource

A DataSource suitable for loading the media data.

@Nullable CmcdConfiguration cmcdConfiguration

The CmcdConfiguration for this chunk source.

SubtitleParser.Factory subtitleParserFactory

The SubtitleParser.Factory for parsing subtitles during extraction.

boolean parseSubtitlesDuringExtraction

Whether to parse subtitles during extraction or rendering.

Public methods

getAdjustedSeekPositionUs

public long getAdjustedSeekPositionUs(
    long positionUs,
    SeekParameters seekParameters
)

Adjusts a seek position given the specified SeekParameters. Chunk boundaries are used as sync points.

Parameters
long positionUs

The seek position in microseconds.

SeekParameters seekParameters

Parameters that control how the seek is performed.

Returns
long

The adjusted seek position, in microseconds.

getNextChunk

public final void getNextChunk(
    LoadingInfo loadingInfo,
    long loadPositionUs,
    List<MediaChunk> queue,
    ChunkHolder out
)

Returns the next chunk to load.

If a chunk is available then chunk is set. If the end of the stream has been reached then endOfStream is set. If a chunk is not available but the end of the stream has not been reached, the ChunkHolder is not modified.

Parameters
LoadingInfo loadingInfo

The LoadingInfo when loading request is made.

long loadPositionUs

The current load position in microseconds. If queue is empty, this is the starting position from which chunks should be provided. Else it's equal to endTimeUs of the last chunk in the queue.

List<MediaChunk> queue

The queue of buffered MediaChunks.

ChunkHolder out

A holder to populate.

getPreferredQueueSize

public int getPreferredQueueSize(long playbackPositionUs, List<MediaChunk> queue)

Evaluates whether MediaChunks should be removed from the back of the queue.

Removing MediaChunks from the back of the queue can be useful if they could be replaced with chunks of a significantly higher quality (e.g. because the available bandwidth has substantially increased).

Will only be called if no MediaChunk in the queue is currently loading.

Parameters
long playbackPositionUs

The current playback position, in microseconds.

List<MediaChunk> queue

The queue of buffered MediaChunks.

Returns
int

The preferred queue size.

maybeThrowError

public void maybeThrowError()

If the source is currently having difficulty providing chunks, then this method throws the underlying error. Otherwise does nothing.

Throws
java.io.IOException

The underlying error.

onChunkLoadCompleted

public void onChunkLoadCompleted(Chunk chunk)

Called when the ChunkSampleStream has finished loading a chunk obtained from this source.

Parameters
Chunk chunk

The chunk whose load has been completed.

onChunkLoadError

public boolean onChunkLoadError(
    Chunk chunk,
    boolean cancelable,
    LoadErrorHandlingPolicy.LoadErrorInfo loadErrorInfo,
    LoadErrorHandlingPolicy loadErrorHandlingPolicy
)

Called when the ChunkSampleStream encounters an error loading a chunk obtained from this source.

Parameters
Chunk chunk

The chunk whose load encountered the error.

boolean cancelable

Whether the load can be canceled.

LoadErrorHandlingPolicy.LoadErrorInfo loadErrorInfo

The load error info.

LoadErrorHandlingPolicy loadErrorHandlingPolicy

The load error handling policy to customize the behaviour of handling the load error.

Returns
boolean

Whether the load should be canceled so that a replacement chunk can be loaded instead. Must be false if cancelable is false. If true, getNextChunk will be called to obtain the replacement chunk.

release

public void release()

Releases any held resources.

shouldCancelLoad

public boolean shouldCancelLoad(
    long playbackPositionUs,
    Chunk loadingChunk,
    List<MediaChunk> queue
)

Returns whether an ongoing load of a chunk should be canceled.

Parameters
long playbackPositionUs

The current playback position, in microseconds.

Chunk loadingChunk

The currently loading Chunk.

List<MediaChunk> queue

The queue of buffered MediaChunks.

Returns
boolean

Whether the ongoing load of loadingChunk should be canceled.

updateManifest

public void updateManifest(SsManifest newManifest)

Updates the manifest.

Parameters
SsManifest newManifest

The new manifest.

updateTrackSelection

public void updateTrackSelection(ExoTrackSelection trackSelection)

Updates the track selection.

Parameters
ExoTrackSelection trackSelection

The new track selection instance. Must be equivalent to the previous one.