Class FakeSampleStream
- java.lang.Object
-
- com.google.android.exoplayer2.testutil.FakeSampleStream
-
- All Implemented Interfaces:
SampleStream
public class FakeSampleStream extends Object implements SampleStream
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFakeSampleStream.FakeSampleStreamItem-
Nested classes/interfaces inherited from interface com.google.android.exoplayer2.source.SampleStream
SampleStream.ReadDataResult, SampleStream.ReadFlags
-
-
Field Summary
-
Fields inherited from interface com.google.android.exoplayer2.source.SampleStream
FLAG_OMIT_SAMPLE_DATA, FLAG_PEEK, FLAG_REQUIRE_FORMAT
-
-
Constructor Summary
Constructors Constructor Description FakeSampleStream(Allocator allocator, MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher, Format initialFormat, List<FakeSampleStream.FakeSampleStreamItem> fakeSampleStreamItems)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappend(List<FakeSampleStream.FakeSampleStreamItem> items)AppendsFakeSampleStreamItemsto the list of items that should be written to the queue.voiddiscardTo(long positionUs, boolean toKeyframe)Discards data from the queue.longgetLargestQueuedTimestampUs()Returns the timestamp of the largest queued sample in the queue, orLong.MIN_VALUEif no samples are queued.booleanisLoadingFinished()Returns whether data has been written to the sample queue until the end of stream signal.booleanisReady()Returns whether data is available to be read.voidmaybeThrowError()Throws an error that's preventing data from being read.intreadData(FormatHolder formatHolder, DecoderInputBuffer buffer, @com.google.android.exoplayer2.source.SampleStream.ReadFlags int readFlags)Attempts to read from the stream.voidrelease()Release the stream and its underlying sample queue.voidreset()Resets the sample queue.booleanseekToUs(long positionUs)Seeks the stream to a new position using already available data in the queue.intskipData(long positionUs)Attempts to skip to the keyframe before the specified position, or to the end of the stream ifpositionUsis beyond it.voidwriteData(long startPositionUs)Writes all not yet writtensample stream itemsto the sample queue starting at the given position.
-
-
-
Constructor Detail
-
FakeSampleStream
public FakeSampleStream(Allocator allocator, @Nullable MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher, Format initialFormat, List<FakeSampleStream.FakeSampleStreamItem> fakeSampleStreamItems)
- Parameters:
allocator- AnAllocator.mediaSourceEventDispatcher- AMediaSourceEventListener.EventDispatcherto notify of media events.drmSessionManager- ADrmSessionManagerfor DRM interactions.drmEventDispatcher- ADrmSessionEventListener.EventDispatcherto notify of DRM events.initialFormat- The firstFormatto output.fakeSampleStreamItems- Theitemsto output.
-
-
Method Detail
-
append
public void append(List<FakeSampleStream.FakeSampleStreamItem> items)
AppendsFakeSampleStreamItemsto the list of items that should be written to the queue.Note that this data is only written to the queue once
writeData(long)is called.- Parameters:
items- The items to append.
-
writeData
public void writeData(long startPositionUs)
Writes all not yet writtensample stream itemsto the sample queue starting at the given position.- Parameters:
startPositionUs- The start position, in microseconds.
-
seekToUs
public boolean seekToUs(long positionUs)
Seeks the stream to a new position using already available data in the queue.- Parameters:
positionUs- The new position, in microseconds.- Returns:
- Whether seeking inside the available data was possible.
-
reset
public void reset()
Resets the sample queue.A new call to
writeData(long)is required to fill the queue again.
-
isLoadingFinished
public boolean isLoadingFinished()
Returns whether data has been written to the sample queue until the end of stream signal.
-
getLargestQueuedTimestampUs
public long getLargestQueuedTimestampUs()
Returns the timestamp of the largest queued sample in the queue, orLong.MIN_VALUEif no samples are queued.
-
discardTo
public void discardTo(long positionUs, boolean toKeyframe)Discards data from the queue.- Parameters:
positionUs- The position to discard to, in microseconds.toKeyframe- Whether to discard to keyframes only.
-
release
public void release()
Release the stream and its underlying sample queue.
-
isReady
public boolean isReady()
Description copied from interface:SampleStreamReturns whether data is available to be read.Note: If the stream has ended then a buffer with the end of stream flag can always be read from
SampleStream.readData(com.google.android.exoplayer2.FormatHolder, com.google.android.exoplayer2.decoder.DecoderInputBuffer, @com.google.android.exoplayer2.source.SampleStream.ReadFlags int). Hence an ended stream is always ready.- Specified by:
isReadyin interfaceSampleStream- Returns:
- Whether data is available to be read.
-
maybeThrowError
public void maybeThrowError() throws IOExceptionDescription copied from interface:SampleStreamThrows an error that's preventing data from being read. Does nothing if no such error exists.- Specified by:
maybeThrowErrorin interfaceSampleStream- Throws:
IOException- The underlying error.
-
readData
public int readData(FormatHolder formatHolder, DecoderInputBuffer buffer, @com.google.android.exoplayer2.source.SampleStream.ReadFlags int readFlags)
Description copied from interface:SampleStreamAttempts to read from the stream.If the stream has ended then
C.BUFFER_FLAG_END_OF_STREAMflag is set onbufferandC.RESULT_BUFFER_READis returned. Else if no data is available thenC.RESULT_NOTHING_READis returned. Else if the format of the media is changing or ifformatRequiredis set thenformatHolderis populated andC.RESULT_FORMAT_READis returned. Elsebufferis populated andC.RESULT_BUFFER_READis returned.- Specified by:
readDatain interfaceSampleStream- Parameters:
formatHolder- AFormatHolderto populate in the case of reading a format.buffer- ADecoderInputBufferto populate in the case of reading a sample or the end of the stream. If the end of the stream has been reached, theC.BUFFER_FLAG_END_OF_STREAMflag will be set on the buffer.readFlags- Flags controlling the behavior of this read operation.- Returns:
- The
resultof the read operation.
-
skipData
public int skipData(long positionUs)
Description copied from interface:SampleStreamAttempts to skip to the keyframe before the specified position, or to the end of the stream ifpositionUsis beyond it.- Specified by:
skipDatain interfaceSampleStream- Parameters:
positionUs- The specified time.- Returns:
- The number of samples that were skipped.
-
-