use of android.media.MediaCodec.CryptoInfo in project ExoPlayer by google.
the class OutputConsumerAdapterV30 method toExoPlayerCryptoData.
@Nullable
private CryptoData toExoPlayerCryptoData(int trackIndex, @Nullable CryptoInfo cryptoInfo) {
if (cryptoInfo == null) {
return null;
}
@Nullable CryptoInfo lastReceivedCryptoInfo = lastReceivedCryptoInfos.get(trackIndex);
CryptoData cryptoDataToOutput;
// MediaParser keeps identity and value equality aligned for efficient comparison.
if (lastReceivedCryptoInfo == cryptoInfo) {
// They match, we can reuse the last one we created.
cryptoDataToOutput = Assertions.checkNotNull(lastOutputCryptoDatas.get(trackIndex));
} else {
// They don't match, we create a new CryptoData.
// TODO: Access pattern encryption info directly once the Android SDK makes it visible.
// See [Internal ref: b/154248283].
int encryptedBlocks;
int clearBlocks;
try {
Matcher matcher = REGEX_CRYPTO_INFO_PATTERN.matcher(cryptoInfo.toString());
matcher.find();
encryptedBlocks = Integer.parseInt(Util.castNonNull(matcher.group(1)));
clearBlocks = Integer.parseInt(Util.castNonNull(matcher.group(2)));
} catch (RuntimeException e) {
// Should never happen.
Log.e(TAG, "Unexpected error while parsing CryptoInfo: " + cryptoInfo, e);
// Assume no-pattern encryption.
encryptedBlocks = 0;
clearBlocks = 0;
}
cryptoDataToOutput = new CryptoData(cryptoInfo.mode, cryptoInfo.key, encryptedBlocks, clearBlocks);
lastReceivedCryptoInfos.set(trackIndex, cryptoInfo);
lastOutputCryptoDatas.set(trackIndex, cryptoDataToOutput);
}
return cryptoDataToOutput;
}
Aggregations