public class DefaultTrackOutput extends Object implements TrackOutput
TrackOutput that buffers extracted samples in a queue, and allows for consumption from
that queue.| Constructor and Description |
|---|
DefaultTrackOutput(Allocator allocator) |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clears the queue, returning all allocations to the allocator.
|
boolean |
configureSpliceTo(DefaultTrackOutput nextQueue)
Attempts to configure a splice from this queue to the next.
|
void |
discardUntil(long timeUs)
Discards samples from the queue up to the specified time.
|
void |
discardUpstreamSamples(int discardFromIndex)
Discards samples from the write side of the queue.
|
void |
format(MediaFormat format)
Invoked when the
MediaFormat of the track has been extracted from the stream. |
MediaFormat |
getFormat()
The format most recently received by the output, or null if a format has yet to be received.
|
long |
getLargestParsedTimestampUs()
The largest timestamp of any sample received by the output, or
Long.MIN_VALUE if a
sample has yet to be received. |
int |
getReadIndex()
Returns the current absolute read index.
|
boolean |
getSample(SampleHolder holder)
Removes the next sample from the head of the queue, writing it into the provided holder.
|
int |
getWriteIndex()
Returns the current absolute write index.
|
boolean |
hasFormat()
True if the output has received a format.
|
boolean |
isEmpty()
True if at least one sample can be read from the queue.
|
int |
sampleData(DataSource dataSource,
int length,
boolean allowEndOfInput)
Invoked to write sample data to the output.
|
int |
sampleData(ExtractorInput input,
int length,
boolean allowEndOfInput)
Invoked to write sample data to the output.
|
void |
sampleData(ParsableByteArray buffer,
int length)
Invoked to write sample data to the output.
|
void |
sampleMetadata(long timeUs,
int flags,
int size,
int offset,
byte[] encryptionKey)
Invoked when metadata associated with a sample has been extracted from the stream.
|
boolean |
skipToKeyframeBefore(long timeUs)
Attempts to skip to the keyframe before the specified time, if it's present in the buffer.
|
public void clear()
public int getWriteIndex()
public void discardUpstreamSamples(int discardFromIndex)
discardFromIndex - The absolute index of the first sample to be discarded.public int getReadIndex()
public boolean hasFormat()
public MediaFormat getFormat()
public long getLargestParsedTimestampUs()
Long.MIN_VALUE if a
sample has yet to be received.public boolean isEmpty()
public boolean getSample(SampleHolder holder)
The first sample returned is guaranteed to be a keyframe, since any non-keyframe samples queued prior to the first keyframe are discarded.
holder - A SampleHolder into which the sample should be read.public void discardUntil(long timeUs)
timeUs - The time up to which samples should be discarded, in microseconds.public boolean skipToKeyframeBefore(long timeUs)
timeUs - The seek time.public boolean configureSpliceTo(DefaultTrackOutput nextQueue)
nextQueue - The queue being spliced to.public int sampleData(DataSource dataSource, int length, boolean allowEndOfInput) throws IOException
dataSource - A DataSource 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.IOException - If an error occurred reading from the input.public void format(MediaFormat format)
TrackOutputMediaFormat of the track has been extracted from the stream.format in interface TrackOutputformat - The extracted MediaFormat.public int sampleData(ExtractorInput input, int length, boolean allowEndOfInput) throws IOException, 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.IOException - If an error occurred reading from the input.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 SampleHolder.flags.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.