Skip to content

Commit

Permalink
Add pattern information to ExoPlayer's CryptoInfo
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=152708351
  • Loading branch information
AquilesCanta authored and ojw28 committed Apr 11, 2017
1 parent 0aee235 commit 2a4df60
Showing 1 changed file with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,21 @@ public final class CryptoInfo {
* @see android.media.MediaCodec.CryptoInfo#numSubSamples
*/
public int numSubSamples;
/**
* @see android.media.MediaCodec.CryptoInfo.Pattern
*/
public int patternBlocksToEncrypt;
/**
* @see android.media.MediaCodec.CryptoInfo.Pattern
*/
public int patternBlocksToSkip;

private final android.media.MediaCodec.CryptoInfo frameworkCryptoInfo;
private final PatternHolderV24 patternHolder;

public CryptoInfo() {
frameworkCryptoInfo = Util.SDK_INT >= 16 ? newFrameworkCryptoInfoV16() : null;
patternHolder = Util.SDK_INT >= 24 ? new PatternHolderV24(frameworkCryptoInfo) : null;
}

/**
Expand All @@ -67,11 +77,21 @@ public void set(int numSubSamples, int[] numBytesOfClearData, int[] numBytesOfEn
this.key = key;
this.iv = iv;
this.mode = mode;
patternBlocksToEncrypt = 0;
patternBlocksToSkip = 0;
if (Util.SDK_INT >= 16) {
updateFrameworkCryptoInfoV16();
}
}

public void setPattern(int patternBlocksToEncrypt, int patternBlocksToSkip) {
this.patternBlocksToEncrypt = patternBlocksToEncrypt;
this.patternBlocksToSkip = patternBlocksToSkip;
if (Util.SDK_INT >= 24) {
patternHolder.set(patternBlocksToEncrypt, patternBlocksToSkip);
}
}

/**
* Returns an equivalent {@link android.media.MediaCodec.CryptoInfo} instance.
* <p>
Expand All @@ -93,8 +113,35 @@ private android.media.MediaCodec.CryptoInfo newFrameworkCryptoInfoV16() {

@TargetApi(16)
private void updateFrameworkCryptoInfoV16() {
frameworkCryptoInfo.set(numSubSamples, numBytesOfClearData, numBytesOfEncryptedData, key, iv,
mode);
// Update fields directly because the framework's CryptoInfo.set performs an unnecessary object
// allocation on Android N.
frameworkCryptoInfo.numSubSamples = numSubSamples;
frameworkCryptoInfo.numBytesOfClearData = numBytesOfClearData;
frameworkCryptoInfo.numBytesOfEncryptedData = numBytesOfEncryptedData;
frameworkCryptoInfo.key = key;
frameworkCryptoInfo.iv = iv;
frameworkCryptoInfo.mode = mode;
if (Util.SDK_INT >= 24) {
patternHolder.set(patternBlocksToEncrypt, patternBlocksToSkip);
}
}

@TargetApi(24)
private static final class PatternHolderV24 {

private final android.media.MediaCodec.CryptoInfo frameworkCryptoInfo;
private final android.media.MediaCodec.CryptoInfo.Pattern pattern;

private PatternHolderV24(android.media.MediaCodec.CryptoInfo frameworkCryptoInfo) {
this.frameworkCryptoInfo = frameworkCryptoInfo;
pattern = new android.media.MediaCodec.CryptoInfo.Pattern(0, 0);
}

private void set(int blocksToEncrypt, int blocksToSkip) {
pattern.set(blocksToEncrypt, blocksToSkip);
frameworkCryptoInfo.setPattern(pattern);
}

}

}

0 comments on commit 2a4df60

Please # to comment.