Search in sources :

Example 1 with DecryptionException

use of com.google.android.exoplayer2.drm.DecryptionException 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 DecryptionException

use of com.google.android.exoplayer2.drm.DecryptionException in project ExoPlayer by google.

the class VpxDecoder method decode.

@Override
protected VpxDecoderException decode(DecoderInputBuffer inputBuffer, VpxOutputBuffer outputBuffer, boolean reset) {
    ByteBuffer inputData = inputBuffer.data;
    int inputSize = inputData.limit();
    CryptoInfo cryptoInfo = inputBuffer.cryptoInfo;
    final long result = inputBuffer.isEncrypted() ? vpxSecureDecode(vpxDecContext, inputData, inputSize, exoMediaCrypto, cryptoInfo.mode, cryptoInfo.key, 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);
            DecryptionException cause = new DecryptionException(vpxGetErrorCode(vpxDecContext), message);
            return new VpxDecoderException(message, cause);
        } else {
            return new VpxDecoderException("Decode error: " + vpxGetErrorMessage(vpxDecContext));
        }
    }
    outputBuffer.init(inputBuffer.timeUs, outputMode);
    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.");
    }
    return null;
}
Also used : CryptoInfo(com.google.android.exoplayer2.decoder.CryptoInfo) ByteBuffer(java.nio.ByteBuffer) DecryptionException(com.google.android.exoplayer2.drm.DecryptionException)

Aggregations

CryptoInfo (com.google.android.exoplayer2.decoder.CryptoInfo)2 DecryptionException (com.google.android.exoplayer2.drm.DecryptionException)2 ByteBuffer (java.nio.ByteBuffer)2