Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 09ae5f60 authored by Santiago Seifert's avatar Santiago Seifert
Browse files

Add MediaCodec.CryptoInfo.getPattern

Allows MediaParser and MediaExtractor clients to know the
encrpytion pattern of the parsed/extracted media. Without
the getter, only MediaCodec can know the pattern, which
impossibilitates the use of app-bundled decoders.

Bug: 158743263
Test: atest CtsMediaTestCases:MediaCodecTest.testCryptoInfoPattern
Change-Id: Iaf77c8ecafad093cfa434a9ac31314895a44e78f
parent 0ad7b55f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -25456,6 +25456,7 @@ package android.media {
  public static final class MediaCodec.CryptoInfo {
    ctor public MediaCodec.CryptoInfo();
    method @NonNull public android.media.MediaCodec.CryptoInfo.Pattern getPattern();
    method public void set(int, @NonNull int[], @NonNull int[], @NonNull byte[], @NonNull byte[], int);
    method public void setPattern(android.media.MediaCodec.CryptoInfo.Pattern);
    field public byte[] iv;
+17 −9
Original line number Diff line number Diff line
@@ -2711,12 +2711,12 @@ final public class MediaCodec {
            }
        };

        private final Pattern zeroPattern = new Pattern(0, 0);
        private static final Pattern ZERO_PATTERN = new Pattern(0, 0);

        /**
         * The pattern applicable to the protected data in each subsample.
         */
        private Pattern pattern;
        private Pattern mPattern = ZERO_PATTERN;

        /**
         * Set the subsample count, clear/encrypted sizes, key, IV and mode fields of
@@ -2735,22 +2735,30 @@ final public class MediaCodec {
            key = newKey;
            iv = newIV;
            mode = newMode;
            pattern = zeroPattern;
            mPattern = ZERO_PATTERN;
        }

        /**
         * Returns the {@link Pattern encryption pattern}.
         */
        public @NonNull Pattern getPattern() {
            return new Pattern(mPattern.getEncryptBlocks(), mPattern.getSkipBlocks());
        }

        /**
         * Set the encryption pattern on a {@link MediaCodec.CryptoInfo} instance.
         * See {@link MediaCodec.CryptoInfo.Pattern}.
         * See {@link Pattern}.
         */
        public void setPattern(Pattern newPattern) {
            if (newPattern == null) {
                newPattern = zeroPattern;
                newPattern = ZERO_PATTERN;
            }
            pattern = newPattern;
            setPattern(newPattern.getEncryptBlocks(), newPattern.getSkipBlocks());
        }

        // Accessed from android_media_MediaExtractor.cpp.
        private void setPattern(int blocksToEncrypt, int blocksToSkip) {
            pattern = new Pattern(blocksToEncrypt, blocksToSkip);
            mPattern = new Pattern(blocksToEncrypt, blocksToSkip);
        }

        @Override
@@ -2772,9 +2780,9 @@ final public class MediaCodec {
            builder.append(", encrypted ");
            builder.append(Arrays.toString(numBytesOfEncryptedData));
            builder.append(", pattern (encrypt: ");
            builder.append(pattern.mEncryptBlocks);
            builder.append(mPattern.mEncryptBlocks);
            builder.append(", skip: ");
            builder.append(pattern.mSkipBlocks);
            builder.append(mPattern.mSkipBlocks);
            builder.append(")");
            return builder.toString();
        }
+1 −1
Original line number Diff line number Diff line
@@ -2662,7 +2662,7 @@ static void android_media_MediaCodec_native_init(JNIEnv *env, jclass) {
    gFields.cryptoInfoModeID = env->GetFieldID(clazz.get(), "mode", "I");
    CHECK(gFields.cryptoInfoModeID != NULL);

    gFields.cryptoInfoPatternID = env->GetFieldID(clazz.get(), "pattern",
    gFields.cryptoInfoPatternID = env->GetFieldID(clazz.get(), "mPattern",
        "Landroid/media/MediaCodec$CryptoInfo$Pattern;");
    CHECK(gFields.cryptoInfoPatternID != NULL);

+1 −0
Original line number Diff line number Diff line
@@ -25438,6 +25438,7 @@ package android.media {
  public static final class MediaCodec.CryptoInfo {
    ctor public MediaCodec.CryptoInfo();
    method @NonNull public android.media.MediaCodec.CryptoInfo.Pattern getPattern();
    method public void set(int, @NonNull int[], @NonNull int[], @NonNull byte[], @NonNull byte[], int);
    method public void setPattern(android.media.MediaCodec.CryptoInfo.Pattern);
    field public byte[] iv;