com.google.android.exoplayer2.decoder.CryptoInfo Java Examples

The following examples show how to use com.google.android.exoplayer2.decoder.CryptoInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpusDecoder.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected 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);
  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;
}
 
Example #2
Source File: OpusDecoder.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected 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);
  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;
}
 
Example #3
Source File: VideoDecoder.java    From DanDanPlayForAndroid with MIT License 4 votes vote down vote up
@Override
protected VideoSoftDecoderException sendPacket(PacketBuffer inputBuffer) {

    boolean isEndOfStream = inputBuffer.isEndOfStream();
    boolean isDecodeOnly = inputBuffer.isDecodeOnly();

    ByteBuffer inputData = inputBuffer.data;
    int inputSize = 0;
    if (!inputBuffer.isEndOfStream()) {
        inputSize = inputData.limit();
    }
    CryptoInfo cryptoInfo = inputBuffer.cryptoInfo;
    final long result = inputBuffer.isEncrypted()
            ? ffmpegSecureDecode(ffmpegDecContext,
            inputData,
            inputSize,
            exoMediaCrypto,
            cryptoInfo.mode,
            cryptoInfo.key,
            cryptoInfo.iv,
            cryptoInfo.numSubSamples,
            cryptoInfo.numBytesOfClearData,
            cryptoInfo.numBytesOfEncryptedData,
            inputBuffer.timeUs,
            isDecodeOnly,
            isEndOfStream)
            : ffmpegDecode(ffmpegDecContext,
            inputData,
            inputSize,
            inputBuffer.timeUs,
            isDecodeOnly,
            isEndOfStream);
    if (result != NO_ERROR) {
        if (result == DRM_ERROR) {
            String message = "Drm error!!";
            DecryptionException cause = new DecryptionException(
                    ffmpegGetErrorCode(ffmpegDecContext), message);
            return new VideoSoftDecoderException(message, cause);
        } else if (result == DECODE_AGAIN) {
            inputBuffer.addFlag(Constant.BUFFER_FLAG_DECODE_AGAIN);
        } else {
            return new VideoSoftDecoderException("failed to decode, error code: " + ffmpegGetErrorCode(ffmpegDecContext));
        }
    }
    return null;
}
 
Example #4
Source File: OpusDecoder.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
@Nullable
protected 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);
  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;
}
 
Example #5
Source File: OpusDecoder.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
@Nullable
protected 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);
  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;
}