public final class DefaultTrackOutput extends java.lang.Object implements TrackOutput
TrackOutput that buffers extracted samples in a queue and allows for consumption from
that queue.| Modifier and Type | Class and Description |
|---|---|
static interface |
DefaultTrackOutput.UpstreamFormatChangedListener
A listener for changes to the upstream format.
|
| Constructor and Description |
|---|
DefaultTrackOutput(Allocator allocator) |
| Modifier and Type | Method and Description |
|---|---|
void |
disable()
Disables buffering of sample data and metadata.
|
void |
discardUpstreamSamples(int discardFromIndex)
Discards samples from the write side of the buffer.
|
void |
format(Format format)
Called when the
Format of the track has been extracted from the stream. |
long |
getLargestQueuedTimestampUs()
Returns the largest sample timestamp that has been queued since the last
reset(boolean). |
int |
getReadIndex()
Returns the current absolute read index.
|
Format |
getUpstreamFormat()
Returns the upstream
Format in which samples are being queued. |
int |
getWriteIndex()
Returns the current absolute write index.
|
boolean |
isEmpty()
Returns whether the buffer is empty.
|
int |
peekSourceId()
Peeks the source id of the next sample, or the current upstream source id if the buffer is
empty.
|
int |
readData(FormatHolder formatHolder,
DecoderInputBuffer buffer,
boolean formatRequired,
boolean loadingFinished,
long decodeOnlyUntilUs)
Attempts to read from the queue.
|
void |
reset(boolean enable)
Resets the output.
|
int |
sampleData(ExtractorInput input,
int length,
boolean allowEndOfInput)
Called to write sample data to the output.
|
void |
sampleData(ParsableByteArray buffer,
int length)
Called to write sample data to the output.
|
void |
sampleMetadata(long timeUs,
int flags,
int size,
int offset,
byte[] encryptionKey)
Called when metadata associated with a sample has been extracted from the stream.
|
void |
setSampleOffsetUs(long sampleOffsetUs)
Sets an offset that will be added to the timestamps (and sub-sample timestamps) of samples
subsequently queued to the buffer.
|
void |
setUpstreamFormatChangeListener(DefaultTrackOutput.UpstreamFormatChangedListener listener)
Sets a listener to be notified of changes to the upstream format.
|
void |
skipAll()
Skips all samples currently in the buffer.
|
boolean |
skipToKeyframeBefore(long timeUs,
boolean allowTimeBeyondBuffer)
Attempts to skip to the keyframe before or at the specified time.
|
void |
sourceId(int sourceId)
Sets a source identifier for subsequent samples.
|
void |
splice()
Indicates that samples subsequently queued to the buffer should be spliced into those already
queued.
|
public void reset(boolean enable)
enable - Whether the output should be enabled. False if it should be disabled.public void sourceId(int sourceId)
sourceId - The source identifier.public void splice()
public int getWriteIndex()
public void discardUpstreamSamples(int discardFromIndex)
discardFromIndex - The absolute index of the first sample to be discarded.public void disable()
public boolean isEmpty()
public int getReadIndex()
public int peekSourceId()
public Format getUpstreamFormat()
Format in which samples are being queued.public long getLargestQueuedTimestampUs()
reset(boolean).
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.
Long.MIN_VALUE if no
samples have been queued.public void skipAll()
public boolean skipToKeyframeBefore(long timeUs,
boolean allowTimeBeyondBuffer)
timeUs or earlier. If
allowTimeBeyondBuffer is false then it is also required that timeUs
falls within the buffer.timeUs - The seek time.allowTimeBeyondBuffer - Whether the skip can succeed if timeUs is beyond the end
of the buffer.public int readData(FormatHolder formatHolder, DecoderInputBuffer buffer, boolean formatRequired, boolean loadingFinished, long decodeOnlyUntilUs)
formatHolder - A FormatHolder to populate in the case of reading a format.buffer - A DecoderInputBuffer to populate in the case of reading a sample or the
end of the stream. If the end of the stream has been reached, the
C.BUFFER_FLAG_END_OF_STREAM flag will be set on the buffer.formatRequired - Whether the caller requires that the format of the stream be read even if
it's not changing. A sample will never be read if set to true, however it is still possible
for the end of stream or nothing to be read.loadingFinished - True if an empty queue should be considered the end of the stream.decodeOnlyUntilUs - If a buffer is read, the C.BUFFER_FLAG_DECODE_ONLY flag will
be set if the buffer's timestamp is less than this value.C.RESULT_NOTHING_READ, C.RESULT_FORMAT_READ or
C.RESULT_BUFFER_READ.public void setUpstreamFormatChangeListener(DefaultTrackOutput.UpstreamFormatChangedListener listener)
listener - The listener.public void setSampleOffsetUs(long sampleOffsetUs)
sampleOffsetUs - The timestamp offset in microseconds.public void format(Format format)
TrackOutputFormat of the track has been extracted from the stream.format in interface TrackOutputformat - The extracted Format.public int sampleData(ExtractorInput input, int length, boolean allowEndOfInput) throws java.io.IOException, java.lang.InterruptedException
TrackOutputsampleData in interface TrackOutputinput - An ExtractorInput from 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 in C.RESULT_END_OF_INPUT being returned. False if it
should be considered an error, causing an EOFException to be thrown.java.io.IOException - If an error occurred reading from the input.java.lang.InterruptedException - If the thread was interrupted.public void sampleData(ParsableByteArray buffer, int length)
TrackOutputsampleData in interface TrackOutputbuffer - A ParsableByteArray from which to read the sample data.length - The number of bytes to read.public void sampleMetadata(long timeUs,
int flags,
int size,
int offset,
byte[] encryptionKey)
TrackOutput
The corresponding sample data will have already been passed to the output via calls to
TrackOutput.sampleData(ExtractorInput, int, boolean) or
TrackOutput.sampleData(ParsableByteArray, int).
sampleMetadata in interface TrackOutputtimeUs - The media timestamp associated with the sample, in microseconds.flags - Flags associated with the sample. See C.BUFFER_FLAG_*.size - The size of the sample data, in bytes.offset - The number of bytes that have been passed to
TrackOutput.sampleData(ExtractorInput, int, boolean) or
TrackOutput.sampleData(ParsableByteArray, int) since the last byte belonging to the sample
whose metadata is being passed.encryptionKey - The encryption key associated with the sample. May be null.