Interface SampleStream
-
- All Known Implementing Classes:
ChunkSampleStream,ChunkSampleStream.EmbeddedSampleStream,EmptySampleStream,FakeSampleStream
public interface SampleStreamA stream of media samples (and associated format information).
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceSampleStream.ReadDataResultstatic interfaceSampleStream.ReadFlags
-
Field Summary
Fields Modifier and Type Field Description static intFLAG_OMIT_SAMPLE_DATASpecifies thatDecoderInputBuffer.data,DecoderInputBuffer.supplementalDataandDecoderInputBuffer.cryptoInfoshould not be populated when reading a sample buffer.static intFLAG_PEEKSpecifies that the read position should not be advanced if a sample buffer is read.static intFLAG_REQUIRE_FORMATSpecifies that if a sample buffer would normally be read next, the format of the stream should be read instead.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleanisReady()Returns whether data is available to be read.voidmaybeThrowError()Throws an error that's preventing data from being read.@com.google.android.exoplayer2.source.SampleStream.ReadDataResult intreadData(FormatHolder formatHolder, DecoderInputBuffer buffer, @com.google.android.exoplayer2.source.SampleStream.ReadFlags int readFlags)Attempts to read from the stream.intskipData(long positionUs)Attempts to skip to the keyframe before the specified position, or to the end of the stream ifpositionUsis beyond it.
-
-
-
Field Detail
-
FLAG_PEEK
static final int FLAG_PEEK
Specifies that the read position should not be advanced if a sample buffer is read.- See Also:
- Constant Field Values
-
FLAG_REQUIRE_FORMAT
static final int FLAG_REQUIRE_FORMAT
Specifies that if a sample buffer would normally be read next, the format of the stream should be read instead. In detail, the effect of this flag is as follows:- If a sample buffer would be read were the flag not set, then the stream format will be read instead.
- If nothing would be read were the flag not set, then the stream format will be read if it's known. If the stream format is not known then behavior is unchanged.
- If an end of stream buffer would be read were the flag not set, then behavior is unchanged.
- See Also:
- Constant Field Values
-
FLAG_OMIT_SAMPLE_DATA
static final int FLAG_OMIT_SAMPLE_DATA
Specifies thatDecoderInputBuffer.data,DecoderInputBuffer.supplementalDataandDecoderInputBuffer.cryptoInfoshould not be populated when reading a sample buffer.This flag is useful for efficiently reading or (when combined with
FLAG_PEEK) peeking sample metadata. It can also be used for efficiency by a caller wishing to skip a sample buffer.- See Also:
- Constant Field Values
-
-
Method Detail
-
isReady
boolean isReady()
Returns 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
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.- Returns:
- Whether data is available to be read.
-
maybeThrowError
void maybeThrowError() throws IOExceptionThrows an error that's preventing data from being read. Does nothing if no such error exists.- Throws:
IOException- The underlying error.
-
readData
@com.google.android.exoplayer2.source.SampleStream.ReadDataResult int readData(FormatHolder formatHolder, DecoderInputBuffer buffer, @com.google.android.exoplayer2.source.SampleStream.ReadFlags int readFlags)
Attempts 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.- 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. - Throws:
DecoderInputBuffer.InsufficientCapacityException- If thebufferhas insufficient capacity to hold the data of a sample being read. The buffertimestampand flags are populated if this exception is thrown, but the read position is not advanced.
-
skipData
int skipData(long positionUs)
Attempts to skip to the keyframe before the specified position, or to the end of the stream ifpositionUsis beyond it.- Parameters:
positionUs- The specified time.- Returns:
- The number of samples that were skipped.
-
-