public final class ChunkExtractorWrapper extends Object implements ExtractorOutput, TrackOutput
Extractor
wrapper for loading chunks containing a single track.
The wrapper allows switching of the ChunkExtractorWrapper.SingleTrackMetadataOutput
and TrackOutput
which receive parsed data.
Modifier and Type | Class and Description |
---|---|
static interface |
ChunkExtractorWrapper.SingleTrackMetadataOutput
Receives metadata associated with the track as extracted by the wrapped
Extractor . |
Constructor and Description |
---|
ChunkExtractorWrapper(Extractor extractor,
Format manifestFormat,
boolean preferManifestDrmInitData,
boolean resendFormatOnInit) |
Modifier and Type | Method and Description |
---|---|
void |
endTracks()
Called when all tracks have been identified, meaning no new
trackId values will be
passed to ExtractorOutput.track(int) . |
void |
format(Format format)
Called when the
Format of the track has been extracted from the stream. |
void |
init(ChunkExtractorWrapper.SingleTrackMetadataOutput metadataOutput,
TrackOutput trackOutput)
Initializes the extractor to output to the provided
ChunkExtractorWrapper.SingleTrackMetadataOutput and
TrackOutput instances, and configures it to receive data from a new chunk. |
int |
read(ExtractorInput input)
Reads from the provided
ExtractorInput . |
int |
sampleData(ExtractorInput input,
int length,
boolean allowEndOfInput)
Called to write sample data to the output.
|
void |
sampleData(ParsableByteArray data,
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 |
seekMap(SeekMap seekMap)
Called when a
SeekMap has been extracted from the stream. |
TrackOutput |
track(int id)
Called by the
Extractor to get the TrackOutput for a specific track. |
public ChunkExtractorWrapper(Extractor extractor, Format manifestFormat, boolean preferManifestDrmInitData, boolean resendFormatOnInit)
extractor
- The extractor to wrap.manifestFormat
- A manifest defined Format
whose data should be merged into any
sample Format
output from the Extractor
.preferManifestDrmInitData
- Whether DrmInitData
defined in manifestFormat
should be preferred when the sample and manifest Format
s are merged.resendFormatOnInit
- Whether the extractor should resend the previous Format
when
it is initialized via init(SingleTrackMetadataOutput, TrackOutput)
.public void init(ChunkExtractorWrapper.SingleTrackMetadataOutput metadataOutput, TrackOutput trackOutput)
ChunkExtractorWrapper.SingleTrackMetadataOutput
and
TrackOutput
instances, and configures it to receive data from a new chunk.metadataOutput
- The ChunkExtractorWrapper.SingleTrackMetadataOutput
that will receive metadata.trackOutput
- The TrackOutput
that will receive sample data.public int read(ExtractorInput input) throws IOException, InterruptedException
ExtractorInput
.input
- The ExtractorInput
from which to read.Extractor.RESULT_CONTINUE
and Extractor.RESULT_END_OF_INPUT
.IOException
- If an error occurred reading from the source.InterruptedException
- If the thread was interrupted.public TrackOutput track(int id)
ExtractorOutput
Extractor
to get the TrackOutput
for a specific track.
The same TrackOutput
is returned if multiple calls are made with the same
trackId
.
track
in interface ExtractorOutput
id
- A track identifier.TrackOutput
for the given track identifier.public void endTracks()
ExtractorOutput
trackId
values will be
passed to ExtractorOutput.track(int)
.endTracks
in interface ExtractorOutput
public void seekMap(SeekMap seekMap)
ExtractorOutput
SeekMap
has been extracted from the stream.seekMap
in interface ExtractorOutput
seekMap
- The extracted SeekMap
.public void format(Format format)
TrackOutput
Format
of the track has been extracted from the stream.format
in interface TrackOutput
format
- The extracted Format
.public int sampleData(ExtractorInput input, int length, boolean allowEndOfInput) throws IOException, InterruptedException
TrackOutput
sampleData
in interface TrackOutput
input
- 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 data, int length)
TrackOutput
sampleData
in interface TrackOutput
data
- 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 TrackOutput
timeUs
- 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.