Search in sources :

Example 1 with DecoderInputBuffer

use of com.google.android.exoplayer2.decoder.DecoderInputBuffer in project ExoPlayer by google.

the class OpusDecoder method decode.

@Override
public OpusDecoderException decode(DecoderInputBuffer inputBuffer, SimpleOutputBuffer outputBuffer, boolean reset) {
    if (reset) {
        opusReset(nativeDecoderContext);
        // When seeking to 0, skip number of samples as specified in opus header. When seeking to
        // any other time, skip number of samples as specified by seek preroll.
        skipSamples = (inputBuffer.timeUs == 0) ? headerSkipSamples : headerSeekPreRollSamples;
    }
    ByteBuffer inputData = inputBuffer.data;
    CryptoInfo cryptoInfo = inputBuffer.cryptoInfo;
    int result = inputBuffer.isEncrypted() ? opusSecureDecode(nativeDecoderContext, inputBuffer.timeUs, inputData, inputData.limit(), outputBuffer, SAMPLE_RATE, exoMediaCrypto, cryptoInfo.mode, cryptoInfo.key, cryptoInfo.iv, cryptoInfo.numSubSamples, cryptoInfo.numBytesOfClearData, cryptoInfo.numBytesOfEncryptedData) : opusDecode(nativeDecoderContext, inputBuffer.timeUs, inputData, inputData.limit(), outputBuffer, SAMPLE_RATE);
    if (result < 0) {
        if (result == DRM_ERROR) {
            String message = "Drm error: " + opusGetErrorMessage(nativeDecoderContext);
            DecryptionException cause = new DecryptionException(opusGetErrorCode(nativeDecoderContext), message);
            return new OpusDecoderException(message, cause);
        } else {
            return new OpusDecoderException("Decode error: " + opusGetErrorMessage(result));
        }
    }
    ByteBuffer outputData = outputBuffer.data;
    outputData.position(0);
    outputData.limit(result);
    if (skipSamples > 0) {
        int bytesPerSample = channelCount * 2;
        int skipBytes = skipSamples * bytesPerSample;
        if (result <= skipBytes) {
            skipSamples -= result / bytesPerSample;
            outputBuffer.addFlag(C.BUFFER_FLAG_DECODE_ONLY);
            outputData.position(result);
        } else {
            skipSamples = 0;
            outputData.position(skipBytes);
        }
    }
    return null;
}
Also used : CryptoInfo(com.google.android.exoplayer2.decoder.CryptoInfo) ByteBuffer(java.nio.ByteBuffer) DecryptionException(com.google.android.exoplayer2.drm.DecryptionException)

Example 2 with DecoderInputBuffer

use of com.google.android.exoplayer2.decoder.DecoderInputBuffer in project ExoPlayer by google.

the class VpxDecoder method decode.

@Override
@Nullable
protected VpxDecoderException decode(DecoderInputBuffer inputBuffer, VideoDecoderOutputBuffer outputBuffer, boolean reset) {
    if (reset && lastSupplementalData != null) {
        // Don't propagate supplemental data across calls to flush the decoder.
        lastSupplementalData.clear();
    }
    ByteBuffer inputData = Util.castNonNull(inputBuffer.data);
    int inputSize = inputData.limit();
    CryptoInfo cryptoInfo = inputBuffer.cryptoInfo;
    final long result = inputBuffer.isEncrypted() ? vpxSecureDecode(vpxDecContext, inputData, inputSize, cryptoConfig, cryptoInfo.mode, Assertions.checkNotNull(cryptoInfo.key), Assertions.checkNotNull(cryptoInfo.iv), cryptoInfo.numSubSamples, cryptoInfo.numBytesOfClearData, cryptoInfo.numBytesOfEncryptedData) : vpxDecode(vpxDecContext, inputData, inputSize);
    if (result != NO_ERROR) {
        if (result == DRM_ERROR) {
            String message = "Drm error: " + vpxGetErrorMessage(vpxDecContext);
            CryptoException cause = new CryptoException(vpxGetErrorCode(vpxDecContext), message);
            return new VpxDecoderException(message, cause);
        } else {
            return new VpxDecoderException("Decode error: " + vpxGetErrorMessage(vpxDecContext));
        }
    }
    if (inputBuffer.hasSupplementalData()) {
        ByteBuffer supplementalData = Assertions.checkNotNull(inputBuffer.supplementalData);
        int size = supplementalData.remaining();
        if (size > 0) {
            if (lastSupplementalData == null || lastSupplementalData.capacity() < size) {
                lastSupplementalData = ByteBuffer.allocate(size);
            } else {
                lastSupplementalData.clear();
            }
            lastSupplementalData.put(supplementalData);
            lastSupplementalData.flip();
        }
    }
    if (!inputBuffer.isDecodeOnly()) {
        outputBuffer.init(inputBuffer.timeUs, outputMode, lastSupplementalData);
        int getFrameResult = vpxGetFrame(vpxDecContext, outputBuffer);
        if (getFrameResult == 1) {
            outputBuffer.addFlag(C.BUFFER_FLAG_DECODE_ONLY);
        } else if (getFrameResult == -1) {
            return new VpxDecoderException("Buffer initialization failed.");
        }
        outputBuffer.format = inputBuffer.format;
    }
    return null;
}
Also used : CryptoInfo(com.google.android.exoplayer2.decoder.CryptoInfo) CryptoException(com.google.android.exoplayer2.decoder.CryptoException) ByteBuffer(java.nio.ByteBuffer) Nullable(androidx.annotation.Nullable)

Example 3 with DecoderInputBuffer

use of com.google.android.exoplayer2.decoder.DecoderInputBuffer in project ExoPlayer by google.

the class SampleQueue method peekSampleMetadata.

// See comments in setUpstreamFormat
@SuppressWarnings("ReferenceEquality")
private synchronized int peekSampleMetadata(FormatHolder formatHolder, DecoderInputBuffer buffer, boolean formatRequired, boolean loadingFinished, SampleExtrasHolder extrasHolder) {
    buffer.waitingForKeys = false;
    if (!hasNextSample()) {
        if (loadingFinished || isLastSampleQueued) {
            buffer.setFlags(C.BUFFER_FLAG_END_OF_STREAM);
            return C.RESULT_BUFFER_READ;
        } else if (upstreamFormat != null && (formatRequired || upstreamFormat != downstreamFormat)) {
            onFormatResult(Assertions.checkNotNull(upstreamFormat), formatHolder);
            return C.RESULT_FORMAT_READ;
        } else {
            return C.RESULT_NOTHING_READ;
        }
    }
    Format format = sharedSampleMetadata.get(getReadIndex()).format;
    if (formatRequired || format != downstreamFormat) {
        onFormatResult(format, formatHolder);
        return C.RESULT_FORMAT_READ;
    }
    int relativeReadIndex = getRelativeIndex(readPosition);
    if (!mayReadSample(relativeReadIndex)) {
        buffer.waitingForKeys = true;
        return C.RESULT_NOTHING_READ;
    }
    buffer.setFlags(flags[relativeReadIndex]);
    buffer.timeUs = timesUs[relativeReadIndex];
    if (buffer.timeUs < startTimeUs) {
        buffer.addFlag(C.BUFFER_FLAG_DECODE_ONLY);
    }
    extrasHolder.size = sizes[relativeReadIndex];
    extrasHolder.offset = offsets[relativeReadIndex];
    extrasHolder.cryptoData = cryptoDatas[relativeReadIndex];
    return C.RESULT_BUFFER_READ;
}
Also used : Format(com.google.android.exoplayer2.Format)

Example 4 with DecoderInputBuffer

use of com.google.android.exoplayer2.decoder.DecoderInputBuffer in project ExoPlayer by google.

the class MergingMediaPeriodTest method selectTracks_createsSampleStreamsFromChildPeriods.

@Test
public void selectTracks_createsSampleStreamsFromChildPeriods() throws Exception {
    MergingMediaPeriod mergingMediaPeriod = prepareMergingPeriod(new MergingPeriodDefinition(/* timeOffsetUs= */
    0, /* singleSampleTimeUs= */
    0, childFormat11, childFormat12), new MergingPeriodDefinition(/* timeOffsetUs= */
    0, /* singleSampleTimeUs= */
    0, childFormat21, childFormat22));
    ExoTrackSelection selectionForChild1 = new FixedTrackSelection(mergingMediaPeriod.getTrackGroups().get(1), /* track= */
    0);
    ExoTrackSelection selectionForChild2 = new FixedTrackSelection(mergingMediaPeriod.getTrackGroups().get(2), /* track= */
    0);
    SampleStream[] streams = new SampleStream[4];
    mergingMediaPeriod.selectTracks(/* selections= */
    new ExoTrackSelection[] { null, selectionForChild1, selectionForChild2, null }, /* mayRetainStreamFlags= */
    new boolean[] { false, false, false, false }, streams, /* streamResetFlags= */
    new boolean[] { false, false, false, false }, /* positionUs= */
    0);
    mergingMediaPeriod.continueLoading(/* positionUs= */
    0);
    assertThat(streams[0]).isNull();
    assertThat(streams[3]).isNull();
    FormatHolder formatHolder = new FormatHolder();
    DecoderInputBuffer inputBuffer = new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_NORMAL);
    assertThat(streams[1].readData(formatHolder, inputBuffer, FLAG_REQUIRE_FORMAT)).isEqualTo(C.RESULT_FORMAT_READ);
    assertThat(formatHolder.format).isEqualTo(childFormat12);
    assertThat(streams[2].readData(formatHolder, inputBuffer, FLAG_REQUIRE_FORMAT)).isEqualTo(C.RESULT_FORMAT_READ);
    assertThat(formatHolder.format).isEqualTo(childFormat21);
}
Also used : ExoTrackSelection(com.google.android.exoplayer2.trackselection.ExoTrackSelection) DecoderInputBuffer(com.google.android.exoplayer2.decoder.DecoderInputBuffer) FormatHolder(com.google.android.exoplayer2.FormatHolder) FixedTrackSelection(com.google.android.exoplayer2.trackselection.FixedTrackSelection) Test(org.junit.Test)

Example 5 with DecoderInputBuffer

use of com.google.android.exoplayer2.decoder.DecoderInputBuffer in project ExoPlayer by google.

the class C2Mp3TimestampTrackerTest method setUp.

@Before
public void setUp() {
    timestampTracker = new C2Mp3TimestampTracker();
    buffer = new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DISABLED);
    buffer.data = ByteBuffer.wrap(createByteArray(0xFF, 0xFB, 0xE8, 0x3C));
    buffer.timeUs = 100_000;
    invalidBuffer = new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DISABLED);
    invalidBuffer.data = ByteBuffer.wrap(createByteArray(0, 0, 0, 0));
    invalidBuffer.timeUs = 120_000;
}
Also used : DecoderInputBuffer(com.google.android.exoplayer2.decoder.DecoderInputBuffer) Before(org.junit.Before)

Aggregations

Test (org.junit.Test)11 EventStream (com.google.android.exoplayer2.source.dash.manifest.EventStream)9 DecoderInputBuffer (com.google.android.exoplayer2.decoder.DecoderInputBuffer)8 EventMessage (com.google.android.exoplayer2.metadata.emsg.EventMessage)8 Nullable (androidx.annotation.Nullable)7 Format (com.google.android.exoplayer2.Format)7 ByteBuffer (java.nio.ByteBuffer)6 FormatHolder (com.google.android.exoplayer2.FormatHolder)5 CryptoInfo (com.google.android.exoplayer2.decoder.CryptoInfo)5 ReadDataResult (com.google.android.exoplayer2.source.SampleStream.ReadDataResult)3 Before (org.junit.Before)3 CryptoException (com.google.android.exoplayer2.decoder.CryptoException)2 DecryptionException (com.google.android.exoplayer2.drm.DecryptionException)2 ExoTrackSelection (com.google.android.exoplayer2.trackselection.ExoTrackSelection)2 FixedTrackSelection (com.google.android.exoplayer2.trackselection.FixedTrackSelection)2 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)2 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)2 SurfaceTexture (android.graphics.SurfaceTexture)1 Handler (android.os.Handler)1 Surface (android.view.Surface)1