Search in sources :

Example 1 with OutputFrameHolder

use of com.google.android.exoplayer2.ext.flac.FlacBinarySearchSeeker.OutputFrameHolder in project ExoPlayer by google.

the class FlacExtractor method handlePendingSeek.

@RequiresNonNull("binarySearchSeeker")
private int handlePendingSeek(ExtractorInput input, PositionHolder seekPosition, ParsableByteArray outputBuffer, OutputFrameHolder outputFrameHolder, TrackOutput trackOutput) throws IOException {
    int seekResult = binarySearchSeeker.handlePendingSeek(input, seekPosition);
    ByteBuffer outputByteBuffer = outputFrameHolder.byteBuffer;
    if (seekResult == RESULT_CONTINUE && outputByteBuffer.limit() > 0) {
        outputSample(outputBuffer, outputByteBuffer.limit(), outputFrameHolder.timeUs, trackOutput);
    }
    return seekResult;
}
Also used : ByteBuffer(java.nio.ByteBuffer) SeekPoint(com.google.android.exoplayer2.extractor.SeekPoint) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 2 with OutputFrameHolder

use of com.google.android.exoplayer2.ext.flac.FlacBinarySearchSeeker.OutputFrameHolder 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;
}
Also used : SeekMap(com.google.android.exoplayer2.extractor.SeekMap) Nullable(androidx.annotation.Nullable)

Example 3 with OutputFrameHolder

use of com.google.android.exoplayer2.ext.flac.FlacBinarySearchSeeker.OutputFrameHolder 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);
    }
}
Also used : FlacStreamMetadata(com.google.android.exoplayer2.extractor.FlacStreamMetadata) Metadata(com.google.android.exoplayer2.metadata.Metadata) IOException(java.io.IOException) FlacStreamMetadata(com.google.android.exoplayer2.extractor.FlacStreamMetadata) Nullable(androidx.annotation.Nullable) OutputFrameHolder(com.google.android.exoplayer2.ext.flac.FlacBinarySearchSeeker.OutputFrameHolder) EnsuresNonNull(org.checkerframework.checker.nullness.qual.EnsuresNonNull) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 4 with OutputFrameHolder

use of com.google.android.exoplayer2.ext.flac.FlacBinarySearchSeeker.OutputFrameHolder in project ExoPlayer by google.

the class FlacExtractor method read.

@Override
public int read(final ExtractorInput input, PositionHolder seekPosition) throws IOException {
    if (input.getPosition() == 0 && !id3MetadataDisabled && id3Metadata == null) {
        id3Metadata = FlacMetadataReader.peekId3Metadata(input, /* parseData= */
        true);
    }
    FlacDecoderJni decoderJni = initDecoderJni(input);
    try {
        decodeStreamMetadata(input);
        if (binarySearchSeeker != null && binarySearchSeeker.isSeeking()) {
            return handlePendingSeek(input, seekPosition, outputBuffer, outputFrameHolder, trackOutput);
        }
        ByteBuffer outputByteBuffer = outputFrameHolder.byteBuffer;
        long lastDecodePosition = decoderJni.getDecodePosition();
        try {
            decoderJni.decodeSampleWithBacktrackPosition(outputByteBuffer, lastDecodePosition);
        } catch (FlacDecoderJni.FlacFrameDecodeException e) {
            throw new IOException("Cannot read frame at position " + lastDecodePosition, e);
        }
        int outputSize = outputByteBuffer.limit();
        if (outputSize == 0) {
            return RESULT_END_OF_INPUT;
        }
        outputSample(outputBuffer, outputSize, decoderJni.getLastFrameTimestamp(), trackOutput);
        return decoderJni.isEndOfData() ? RESULT_END_OF_INPUT : RESULT_CONTINUE;
    } finally {
        decoderJni.clearData();
    }
}
Also used : IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) SeekPoint(com.google.android.exoplayer2.extractor.SeekPoint)

Aggregations

Nullable (androidx.annotation.Nullable)2 SeekPoint (com.google.android.exoplayer2.extractor.SeekPoint)2 IOException (java.io.IOException)2 ByteBuffer (java.nio.ByteBuffer)2 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)2 OutputFrameHolder (com.google.android.exoplayer2.ext.flac.FlacBinarySearchSeeker.OutputFrameHolder)1 FlacStreamMetadata (com.google.android.exoplayer2.extractor.FlacStreamMetadata)1 SeekMap (com.google.android.exoplayer2.extractor.SeekMap)1 Metadata (com.google.android.exoplayer2.metadata.Metadata)1 EnsuresNonNull (org.checkerframework.checker.nullness.qual.EnsuresNonNull)1