Class FakeChunkSource
- java.lang.Object
-
- com.google.android.exoplayer2.testutil.FakeChunkSource
-
- All Implemented Interfaces:
ChunkSource
public class FakeChunkSource extends Object implements ChunkSource
FakeChunkSource
with adaptive media chunks of a given duration.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FakeChunkSource.Factory
Factory for aFakeChunkSource
.
-
Constructor Summary
Constructors Constructor Description FakeChunkSource(ExoTrackSelection trackSelection, DataSource dataSource, FakeAdaptiveDataSet dataSet)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
getAdjustedSeekPositionUs(long positionUs, SeekParameters seekParameters)
Adjusts a seek position given the specifiedSeekParameters
.void
getNextChunk(long playbackPositionUs, long loadPositionUs, List<? extends MediaChunk> queue, ChunkHolder out)
Returns the next chunk to load.int
getPreferredQueueSize(long playbackPositionUs, List<? extends MediaChunk> queue)
Evaluates whetherMediaChunk
s should be removed from the back of the queue.void
maybeThrowError()
If the source is currently having difficulty providing chunks, then this method throws the underlying error.void
onChunkLoadCompleted(Chunk chunk)
Called when theChunkSampleStream
has finished loading a chunk obtained from this source.boolean
onChunkLoadError(Chunk chunk, boolean cancelable, LoadErrorHandlingPolicy.LoadErrorInfo loadErrorInfo, LoadErrorHandlingPolicy loadErrorHandlingPolicy)
Called when theChunkSampleStream
encounters an error loading a chunk obtained from this source.void
release()
Releases any held resources.boolean
shouldCancelLoad(long playbackPositionUs, Chunk loadingChunk, List<? extends MediaChunk> queue)
Returns whether an ongoing load of a chunk should be canceled.
-
-
-
Constructor Detail
-
FakeChunkSource
public FakeChunkSource(ExoTrackSelection trackSelection, DataSource dataSource, FakeAdaptiveDataSet dataSet)
-
-
Method Detail
-
getAdjustedSeekPositionUs
public long getAdjustedSeekPositionUs(long positionUs, SeekParameters seekParameters)
Description copied from interface:ChunkSource
Adjusts a seek position given the specifiedSeekParameters
. Chunk boundaries are used as sync points.- Specified by:
getAdjustedSeekPositionUs
in interfaceChunkSource
- Parameters:
positionUs
- The seek position in microseconds.seekParameters
- Parameters that control how the seek is performed.- Returns:
- The adjusted seek position, in microseconds.
-
maybeThrowError
public void maybeThrowError()
Description copied from interface:ChunkSource
If the source is currently having difficulty providing chunks, then this method throws the underlying error. Otherwise does nothing.- Specified by:
maybeThrowError
in interfaceChunkSource
-
getPreferredQueueSize
public int getPreferredQueueSize(long playbackPositionUs, List<? extends MediaChunk> queue)
Description copied from interface:ChunkSource
Evaluates whetherMediaChunk
s should be removed from the back of the queue.Removing
MediaChunk
s 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.- Specified by:
getPreferredQueueSize
in interfaceChunkSource
- Parameters:
playbackPositionUs
- The current playback position, in microseconds.queue
- The queue of bufferedMediaChunk
s.- Returns:
- The preferred queue size.
-
shouldCancelLoad
public boolean shouldCancelLoad(long playbackPositionUs, Chunk loadingChunk, List<? extends MediaChunk> queue)
Description copied from interface:ChunkSource
Returns whether an ongoing load of a chunk should be canceled.- Specified by:
shouldCancelLoad
in interfaceChunkSource
- Parameters:
playbackPositionUs
- The current playback position, in microseconds.loadingChunk
- The currently loadingChunk
.queue
- The queue of bufferedMediaChunks
.- Returns:
- Whether the ongoing load of
loadingChunk
should be canceled.
-
getNextChunk
public void getNextChunk(long playbackPositionUs, long loadPositionUs, List<? extends MediaChunk> queue, ChunkHolder out)
Description copied from interface:ChunkSource
Returns the next chunk to load.If a chunk is available then
ChunkHolder.chunk
is set. If the end of the stream has been reached thenChunkHolder.endOfStream
is set. If a chunk is not available but the end of the stream has not been reached, theChunkHolder
is not modified.- Specified by:
getNextChunk
in interfaceChunkSource
- Parameters:
playbackPositionUs
- The current playback position in microseconds. If playback of the period to which this chunk source belongs has not yet started, the value will be the starting position in the period minus the duration of any media in previous periods still to be played.loadPositionUs
- The current load position in microseconds. Ifqueue
is empty, this is the starting position from which chunks should be provided. Else it's equal toChunk.endTimeUs
of the last chunk in thequeue
.queue
- The queue of bufferedMediaChunk
s.out
- A holder to populate.
-
onChunkLoadCompleted
public void onChunkLoadCompleted(Chunk chunk)
Description copied from interface:ChunkSource
Called when theChunkSampleStream
has finished loading a chunk obtained from this source.- Specified by:
onChunkLoadCompleted
in interfaceChunkSource
- Parameters:
chunk
- The chunk whose load has been completed.
-
onChunkLoadError
public boolean onChunkLoadError(Chunk chunk, boolean cancelable, LoadErrorHandlingPolicy.LoadErrorInfo loadErrorInfo, LoadErrorHandlingPolicy loadErrorHandlingPolicy)
Description copied from interface:ChunkSource
Called when theChunkSampleStream
encounters an error loading a chunk obtained from this source.- Specified by:
onChunkLoadError
in interfaceChunkSource
- Parameters:
chunk
- The chunk whose load encountered the error.cancelable
- Whether the load can be canceled.loadErrorInfo
- The load error info.loadErrorHandlingPolicy
- The load error handling policy to customize the behaviour of handling the load error.- Returns:
- Whether the load should be canceled so that a replacement chunk can be loaded instead.
Must be
false
ifcancelable
isfalse
. Iftrue
,ChunkSource.getNextChunk(long, long, List, ChunkHolder)
will be called to obtain the replacement chunk.
-
release
public void release()
Description copied from interface:ChunkSource
Releases any held resources.- Specified by:
release
in interfaceChunkSource
-
-