use of com.google.android.exoplayer2.extractor.ExtractorOutput in project ExoPlayer by google.
the class ExtractorMediaPeriod method track.
// ExtractorOutput implementation. Called by the loading thread.
@Override
public TrackOutput track(int id, int type) {
DefaultTrackOutput trackOutput = sampleQueues.get(id);
if (trackOutput == null) {
trackOutput = new DefaultTrackOutput(allocator);
trackOutput.setUpstreamFormatChangeListener(this);
sampleQueues.put(id, trackOutput);
}
return trackOutput;
}
use of com.google.android.exoplayer2.extractor.ExtractorOutput in project ExoPlayer by google.
the class FlacExtractor method decodeStreamMetadata.
// Requires initialized.
@RequiresNonNull({ "decoderJni", "extractorOutput", "trackOutput" })
// Ensures stream metadata decoded.
@EnsuresNonNull({ "streamMetadata", "outputFrameHolder" })
@SuppressWarnings("nullness:contracts.postcondition")
private void decodeStreamMetadata(ExtractorInput input) throws IOException {
if (streamMetadataDecoded) {
return;
}
FlacDecoderJni flacDecoderJni = decoderJni;
FlacStreamMetadata streamMetadata;
try {
streamMetadata = flacDecoderJni.decodeStreamMetadata();
} catch (IOException e) {
flacDecoderJni.reset(/* newPosition= */
0);
input.setRetryPosition(/* position= */
0, e);
throw e;
}
streamMetadataDecoded = true;
if (this.streamMetadata == null) {
this.streamMetadata = streamMetadata;
outputBuffer.reset(streamMetadata.getMaxDecodedFrameSize());
outputFrameHolder = new OutputFrameHolder(ByteBuffer.wrap(outputBuffer.getData()));
binarySearchSeeker = outputSeekMap(flacDecoderJni, streamMetadata, input.getLength(), extractorOutput, outputFrameHolder);
@Nullable Metadata metadata = streamMetadata.getMetadataCopyWithAppendedEntriesFrom(id3Metadata);
outputFormat(streamMetadata, metadata, trackOutput);
}
}
use of com.google.android.exoplayer2.extractor.ExtractorOutput in project ExoPlayer by google.
the class FlacExtractor method outputSeekMap.
/**
* Outputs a {@link SeekMap} and returns a {@link FlacBinarySearchSeeker} if one is required to
* handle seeks.
*/
@Nullable
private static FlacBinarySearchSeeker outputSeekMap(FlacDecoderJni decoderJni, FlacStreamMetadata streamMetadata, long streamLength, ExtractorOutput output, OutputFrameHolder outputFrameHolder) {
boolean haveSeekTable = decoderJni.getSeekPoints(/* timeUs= */
0) != null;
FlacBinarySearchSeeker binarySearchSeeker = null;
SeekMap seekMap;
if (haveSeekTable) {
seekMap = new FlacSeekMap(streamMetadata.getDurationUs(), decoderJni);
} else if (streamLength != C.LENGTH_UNSET && streamMetadata.totalSamples > 0) {
long firstFramePosition = decoderJni.getDecodePosition();
binarySearchSeeker = new FlacBinarySearchSeeker(streamMetadata, firstFramePosition, streamLength, decoderJni, outputFrameHolder);
seekMap = binarySearchSeeker.getSeekMap();
} else {
seekMap = new SeekMap.Unseekable(streamMetadata.getDurationUs());
}
output.seekMap(seekMap);
return binarySearchSeeker;
}
use of com.google.android.exoplayer2.extractor.ExtractorOutput in project ExoPlayer by google.
the class FlacExtractorSeekTest method seeking_binarySearch_handlesSeekingForward.
@Test
public void seeking_binarySearch_handlesSeekingForward() throws IOException {
String fileName = TEST_FILE_BINARY_SEARCH;
Uri fileUri = TestUtil.buildAssetUri(fileName);
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
long firstSeekTimeUs = 987_000;
TestUtil.seekToTimeUs(extractor, seekMap, firstSeekTimeUs, dataSource, trackOutput, fileUri);
long targetSeekTimeUs = 1_234_000;
int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
assertFirstFrameAfterSeekContainsTargetSeekTime(fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
use of com.google.android.exoplayer2.extractor.ExtractorOutput in project ExoPlayer by google.
the class FlacExtractorSeekTest method seeking_binarySearch_handlesSeekingBackward.
@Test
public void seeking_binarySearch_handlesSeekingBackward() throws IOException {
String fileName = TEST_FILE_BINARY_SEARCH;
Uri fileUri = TestUtil.buildAssetUri(fileName);
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
long firstSeekTimeUs = 1_234_000;
TestUtil.seekToTimeUs(extractor, seekMap, firstSeekTimeUs, dataSource, trackOutput, fileUri);
long targetSeekTimeUs = 987_00;
int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
assertFirstFrameAfterSeekContainsTargetSeekTime(fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
Aggregations