Search in sources :

Example 1 with CryptoInfo

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;
}
Also used : CryptoData(com.google.android.exoplayer2.extractor.TrackOutput.CryptoData) CryptoInfo(android.media.MediaCodec.CryptoInfo) Matcher(java.util.regex.Matcher) Nullable(androidx.annotation.Nullable) SeekPoint(com.google.android.exoplayer2.extractor.SeekPoint) SuppressLint(android.annotation.SuppressLint) Nullable(androidx.annotation.Nullable)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 CryptoInfo (android.media.MediaCodec.CryptoInfo)1 Nullable (androidx.annotation.Nullable)1 SeekPoint (com.google.android.exoplayer2.extractor.SeekPoint)1 CryptoData (com.google.android.exoplayer2.extractor.TrackOutput.CryptoData)1 Matcher (java.util.regex.Matcher)1