Class SampleQueue
- java.lang.Object
-
- com.google.android.exoplayer2.source.SampleQueue
-
- All Implemented Interfaces:
TrackOutput
@Deprecated public class SampleQueue extends Object implements TrackOutput
Deprecated.com.google.android.exoplayer2 is deprecated. Please migrate to androidx.media3 (which contains the same ExoPlayer code). See the migration guide for more details, including a script to help with the migration.A queue of media samples.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceSampleQueue.UpstreamFormatChangedListenerDeprecated.A listener for changes to the upstream format.-
Nested classes/interfaces inherited from interface com.google.android.exoplayer2.extractor.TrackOutput
TrackOutput.CryptoData, TrackOutput.SampleDataPart
-
-
Field Summary
-
Fields inherited from interface com.google.android.exoplayer2.extractor.TrackOutput
SAMPLE_DATA_PART_ENCRYPTION, SAMPLE_DATA_PART_MAIN, SAMPLE_DATA_PART_SUPPLEMENTAL
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedSampleQueue(Allocator allocator, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher)Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static SampleQueuecreateWithDrm(Allocator allocator, Looper playbackLooper, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher)Deprecated.static SampleQueuecreateWithDrm(Allocator allocator, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher)Deprecated.Creates a sample queue with DRM resource management.static SampleQueuecreateWithoutDrm(Allocator allocator)Deprecated.Creates a sample queue without DRM resource management.longdiscardSampleMetadataToRead()Deprecated.voiddiscardTo(long timeUs, boolean toKeyframe, boolean stopAtReadPosition)Deprecated.Discards up to but not including the sample immediately before or at the specified time.voiddiscardToEnd()Deprecated.Discards all samples in the queue and advances the read position.voiddiscardToRead()Deprecated.Discards up to but not including the read position.voiddiscardUpstreamFrom(long timeUs)Deprecated.Discards samples from the write side of the queue.voiddiscardUpstreamSamples(int discardFromIndex)Deprecated.Discards samples from the write side of the queue.voidformat(Format format)Deprecated.Called when theFormatof the track has been extracted from the stream.protected FormatgetAdjustedUpstreamFormat(Format format)Deprecated.intgetFirstIndex()Deprecated.Returns the current absolute start index.longgetFirstTimestampUs()Deprecated.Returns the timestamp of the first sample, orLong.MIN_VALUEif the queue is empty.longgetLargestQueuedTimestampUs()Deprecated.Returns the largest sample timestamp that has been queued since the lastreset().longgetLargestReadTimestampUs()Deprecated.Returns the largest sample timestamp that has been read since the lastreset().intgetReadIndex()Deprecated.Returns the current absolute read index.intgetSkipCount(long timeUs, boolean allowEndOfQueue)Deprecated.Returns the number of samples that need to beskippedto advance the read position to the keyframe before or at the specified time.FormatgetUpstreamFormat()Deprecated.Returns the upstreamFormatin which samples are being queued.intgetWriteIndex()Deprecated.Returns the current absolute write index.protected voidinvalidateUpstreamFormatAdjustment()Deprecated.Invalidates the last upstream format adjustment.booleanisLastSampleQueued()Deprecated.Returns whether the last sample of the stream has knowingly been queued.booleanisReady(boolean loadingFinished)Deprecated.Returns whether there is data available for reading.voidmaybeThrowError()Deprecated.Throws an error that's preventing data from being read.longpeekSourceId()Deprecated.Peeks the source id of the next sample to be read, or the current upstream source id if the queue is empty or if the read position is at the end of the queue.voidpreRelease()Deprecated.CallsdiscardToEnd()and releases any resources owned by the queue.intread(FormatHolder formatHolder, DecoderInputBuffer buffer, @com.google.android.exoplayer2.source.SampleStream.ReadFlags int readFlags, boolean loadingFinished)Deprecated.Attempts to read from the queue.voidrelease()Deprecated.Callsreset(true)and releases any resources owned by the queue.voidreset()Deprecated.Convenience method forreset(false).voidreset(boolean resetUpstreamFormat)Deprecated.Clears all samples from the queue.intsampleData(DataReader input, int length, boolean allowEndOfInput, @com.google.android.exoplayer2.extractor.TrackOutput.SampleDataPart int sampleDataPart)Deprecated.Called to write sample data to the output.voidsampleData(ParsableByteArray data, int length, @com.google.android.exoplayer2.extractor.TrackOutput.SampleDataPart int sampleDataPart)Deprecated.Called to write sample data to the output.voidsampleMetadata(long timeUs, @com.google.android.exoplayer2.C.BufferFlags int flags, int size, int offset, TrackOutput.CryptoData cryptoData)Deprecated.Called when metadata associated with a sample has been extracted from the stream.booleanseekTo(int sampleIndex)Deprecated.Attempts to seek the read position to the specified sample index.booleanseekTo(long timeUs, boolean allowTimeBeyondBuffer)Deprecated.Attempts to seek the read position to the keyframe before or at the specified time.voidsetSampleOffsetUs(long sampleOffsetUs)Deprecated.Sets an offset that will be added to the timestamps (and sub-sample timestamps) of samples that are subsequently queued.voidsetStartTimeUs(long startTimeUs)Deprecated.Sets the start time for the queue.voidsetUpstreamFormatChangeListener(SampleQueue.UpstreamFormatChangedListener listener)Deprecated.Sets a listener to be notified of changes to the upstream format.voidskip(int count)Deprecated.Advances the read position by the specified number of samples.voidsourceId(long sourceId)Deprecated.Sets a source identifier for subsequent samples.voidsplice()Deprecated.Indicates samples that are subsequently queued should be spliced into those already queued.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.google.android.exoplayer2.extractor.TrackOutput
sampleData, sampleData
-
-
-
-
Constructor Detail
-
SampleQueue
protected SampleQueue(Allocator allocator, @Nullable DrmSessionManager drmSessionManager, @Nullable DrmSessionEventListener.EventDispatcher drmEventDispatcher)
Deprecated.
-
-
Method Detail
-
createWithoutDrm
public static SampleQueue createWithoutDrm(Allocator allocator)
Deprecated.Creates a sample queue without DRM resource management.- Parameters:
allocator- AnAllocatorfrom which allocations for sample data can be obtained.
-
createWithDrm
public static SampleQueue createWithDrm(Allocator allocator, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher)
Deprecated.Creates a sample queue with DRM resource management.For each sample added to the queue, a
DrmSessionwill be attached containing the keys needed to decrypt it.- Parameters:
allocator- AnAllocatorfrom which allocations for sample data can be obtained.drmSessionManager- TheDrmSessionManagerto obtainDrmSessionsfrom. The created instance does not take ownership of thisDrmSessionManager.drmEventDispatcher- ADrmSessionEventListener.EventDispatcherto notify of events related to this SampleQueue.
-
createWithDrm
@Deprecated public static SampleQueue createWithDrm(Allocator allocator, Looper playbackLooper, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher)
Deprecated.UsecreateWithDrm(Allocator, DrmSessionManager, EventDispatcher)instead. TheplaybackLoopershould be configured on theDrmSessionManagerwithDrmSessionManager.setPlayer(Looper, PlayerId).
-
release
@CallSuper public void release()
Deprecated.Callsreset(true)and releases any resources owned by the queue.
-
reset
public final void reset()
Deprecated.Convenience method forreset(false).
-
reset
@CallSuper public void reset(boolean resetUpstreamFormat)
Deprecated.Clears all samples from the queue.- Parameters:
resetUpstreamFormat- Whether the upstream format should be cleared. If set to false, samples queued after the reset (and before a subsequent call toformat(Format)) are assumed to have the current upstream format. If set to true,format(Format)must be called after the reset before any more samples can be queued.
-
setStartTimeUs
public final void setStartTimeUs(long startTimeUs)
Deprecated.Sets the start time for the queue. Samples with earlier timestamps will be discarded or have theC.BUFFER_FLAG_DECODE_ONLYflag set when read.- Parameters:
startTimeUs- The start time, in microseconds.
-
sourceId
public final void sourceId(long sourceId)
Deprecated.Sets a source identifier for subsequent samples.- Parameters:
sourceId- The source identifier.
-
splice
public final void splice()
Deprecated.Indicates samples that are subsequently queued should be spliced into those already queued.
-
getWriteIndex
public final int getWriteIndex()
Deprecated.Returns the current absolute write index.
-
discardUpstreamSamples
public final void discardUpstreamSamples(int discardFromIndex)
Deprecated.Discards samples from the write side of the queue.- Parameters:
discardFromIndex- The absolute index of the first sample to be discarded. Must be in the range [getReadIndex(),getWriteIndex()].
-
discardUpstreamFrom
public final void discardUpstreamFrom(long timeUs)
Deprecated.Discards samples from the write side of the queue.- Parameters:
timeUs- Samples will be discarded from the write end of the queue until a sample with a timestamp smaller than timeUs is encountered (this sample is not discarded). Must be larger thangetLargestReadTimestampUs().
-
preRelease
@CallSuper public void preRelease()
Deprecated.CallsdiscardToEnd()and releases any resources owned by the queue.
-
maybeThrowError
@CallSuper public void maybeThrowError() throws IOExceptionDeprecated.Throws an error that's preventing data from being read. Does nothing if no such error exists.- Throws:
IOException- The underlying error.
-
getFirstIndex
public final int getFirstIndex()
Deprecated.Returns the current absolute start index.
-
getReadIndex
public final int getReadIndex()
Deprecated.Returns the current absolute read index.
-
peekSourceId
public final long peekSourceId()
Deprecated.Peeks the source id of the next sample to be read, or the current upstream source id if the queue is empty or if the read position is at the end of the queue.- Returns:
- The source id.
-
getUpstreamFormat
@Nullable public final Format getUpstreamFormat()
Deprecated.Returns the upstreamFormatin which samples are being queued.
-
getLargestQueuedTimestampUs
public final long getLargestQueuedTimestampUs()
Deprecated.Returns the largest sample timestamp that has been queued since the lastreset().Samples that were discarded by calling
discardUpstreamSamples(int)are not considered as having been queued. Samples that were dequeued from the front of the queue are considered as having been queued.- Returns:
- The largest sample timestamp that has been queued, or
Long.MIN_VALUEif no samples have been queued.
-
getLargestReadTimestampUs
public final long getLargestReadTimestampUs()
Deprecated.Returns the largest sample timestamp that has been read since the lastreset().- Returns:
- The largest sample timestamp that has been read, or
Long.MIN_VALUEif no samples have been read.
-
isLastSampleQueued
public final boolean isLastSampleQueued()
Deprecated.Returns whether the last sample of the stream has knowingly been queued. A return value offalsemeans that the last sample had not been queued or that it's unknown whether the last sample has been queued.Samples that were discarded by calling
discardUpstreamSamples(int)are not considered as having been queued. Samples that were dequeued from the front of the queue are considered as having been queued.
-
getFirstTimestampUs
public final long getFirstTimestampUs()
Deprecated.Returns the timestamp of the first sample, orLong.MIN_VALUEif the queue is empty.
-
isReady
@CallSuper public boolean isReady(boolean loadingFinished)
Deprecated.Returns whether there is data available for reading.Note: If the stream has ended then a buffer with the end of stream flag can always be read from
read(com.google.android.exoplayer2.FormatHolder, com.google.android.exoplayer2.decoder.DecoderInputBuffer, @com.google.android.exoplayer2.source.SampleStream.ReadFlags int, boolean). Hence an ended stream is always ready.- Parameters:
loadingFinished- Whether no more samples will be written to the sample queue. When true, this method returns true if the sample queue is empty, because an empty sample queue means the end of stream has been reached. When false, this method returns false if the sample queue is empty.
-
read
@CallSuper public int read(FormatHolder formatHolder, DecoderInputBuffer buffer, @com.google.android.exoplayer2.source.SampleStream.ReadFlags int readFlags, boolean loadingFinished)
Deprecated.Attempts to read from the queue.Formatsread from this method may be associated to aDrmSessionthroughFormatHolder.drmSession.- 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.loadingFinished- True if an empty queue should be considered the end of the stream.- Returns:
- The result, which can be
C.RESULT_NOTHING_READ,C.RESULT_FORMAT_READorC.RESULT_BUFFER_READ. - 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.
-
seekTo
public final boolean seekTo(int sampleIndex)
Deprecated.Attempts to seek the read position to the specified sample index.- Parameters:
sampleIndex- The sample index.- Returns:
- Whether the seek was successful.
-
seekTo
public final boolean seekTo(long timeUs, boolean allowTimeBeyondBuffer)Deprecated.Attempts to seek the read position to the keyframe before or at the specified time.- Parameters:
timeUs- The time to seek to.allowTimeBeyondBuffer- Whether the operation can succeed iftimeUsis beyond the end of the queue, by seeking to the last sample (or keyframe).- Returns:
- Whether the seek was successful.
-
getSkipCount
public final int getSkipCount(long timeUs, boolean allowEndOfQueue)Deprecated.Returns the number of samples that need to beskippedto advance the read position to the keyframe before or at the specified time.- Parameters:
timeUs- The time to advance to.allowEndOfQueue- Whether the end of the queue is considered a keyframe whentimeUsis larger than the largest queued timestamp.- Returns:
- The number of samples that need to be skipped, which may be equal to 0.
-
skip
public final void skip(int count)
Deprecated.Advances the read position by the specified number of samples.- Parameters:
count- The number of samples to advance the read position by. Must be at least 0 and at mostgetWriteIndex()-getReadIndex().
-
discardTo
public final void discardTo(long timeUs, boolean toKeyframe, boolean stopAtReadPosition)Deprecated.Discards up to but not including the sample immediately before or at the specified time.- Parameters:
timeUs- The time to discard up to.toKeyframe- If true then discards samples up to the keyframe before or at the specified time, rather than any sample before or at that time.stopAtReadPosition- If true then samples are only discarded if they're before the read position. If false then samples at and beyond the read position may be discarded, in which case the read position is advanced to the first remaining sample.
-
discardToRead
public final void discardToRead()
Deprecated.Discards up to but not including the read position.
-
discardToEnd
public final void discardToEnd()
Deprecated.Discards all samples in the queue and advances the read position.
-
setSampleOffsetUs
public final void setSampleOffsetUs(long sampleOffsetUs)
Deprecated.Sets an offset that will be added to the timestamps (and sub-sample timestamps) of samples that are subsequently queued.- Parameters:
sampleOffsetUs- The timestamp offset in microseconds.
-
setUpstreamFormatChangeListener
public final void setUpstreamFormatChangeListener(@Nullable SampleQueue.UpstreamFormatChangedListener listener)Deprecated.Sets a listener to be notified of changes to the upstream format.- Parameters:
listener- The listener.
-
format
public final void format(Format format)
Deprecated.Description copied from interface:TrackOutputCalled when theFormatof the track has been extracted from the stream.- Specified by:
formatin interfaceTrackOutput- Parameters:
format- The extractedFormat.
-
sampleData
public final int sampleData(DataReader input, int length, boolean allowEndOfInput, @com.google.android.exoplayer2.extractor.TrackOutput.SampleDataPart int sampleDataPart) throws IOException
Deprecated.Description copied from interface:TrackOutputCalled to write sample data to the output.- Specified by:
sampleDatain interfaceTrackOutput- Parameters:
input- ADataReaderfrom which to read the sample data.length- The maximum length to read from the input.allowEndOfInput- True if encountering the end of the input having read no data is allowed, and should result inC.RESULT_END_OF_INPUTbeing returned. False if it should be considered an error, causing anEOFExceptionto be thrown.sampleDataPart- The part of the sample data to which this call corresponds.- Returns:
- The number of bytes appended.
- Throws:
IOException- If an error occurred reading from the input.
-
sampleData
public final void sampleData(ParsableByteArray data, int length, @com.google.android.exoplayer2.extractor.TrackOutput.SampleDataPart int sampleDataPart)
Deprecated.Description copied from interface:TrackOutputCalled to write sample data to the output.- Specified by:
sampleDatain interfaceTrackOutput- Parameters:
data- AParsableByteArrayfrom which to read the sample data.length- The number of bytes to read, starting fromdata.getPosition().sampleDataPart- The part of the sample data to which this call corresponds.
-
sampleMetadata
public void sampleMetadata(long timeUs, @com.google.android.exoplayer2.C.BufferFlags int flags, int size, int offset, @Nullable TrackOutput.CryptoData cryptoData)Deprecated.Description copied from interface:TrackOutputCalled when metadata associated with a sample has been extracted from the stream.The corresponding sample data will have already been passed to the output via calls to
TrackOutput.sampleData(DataReader, int, boolean)orTrackOutput.sampleData(ParsableByteArray, int).- Specified by:
sampleMetadatain interfaceTrackOutput- Parameters:
timeUs- The media timestamp associated with the sample, in microseconds.flags- Flags associated with the sample. SeeC.BUFFER_FLAG_*.size- The size of the sample data, in bytes.offset- The number of bytes that have been passed toTrackOutput.sampleData(DataReader, int, boolean)orTrackOutput.sampleData(ParsableByteArray, int)since the last byte belonging to the sample whose metadata is being passed.cryptoData- The encryption data required to decrypt the sample. May be null.
-
invalidateUpstreamFormatAdjustment
protected final void invalidateUpstreamFormatAdjustment()
Deprecated.Invalidates the last upstream format adjustment.getAdjustedUpstreamFormat(Format)will be called to adjust the upstreamFormatagain before the next sample is queued.
-
getAdjustedUpstreamFormat
@CallSuper protected Format getAdjustedUpstreamFormat(Format format)
Deprecated.Adjusts the upstreamFormat(i.e., theFormatthat was most recently passed toformat(Format)).The default implementation incorporates the sample offset passed to
setSampleOffsetUs(long)intoFormat.subsampleOffsetUs.
-
discardSampleMetadataToRead
public long discardSampleMetadataToRead()
Deprecated.
-
-