From 892fcf2a09f87333492529bdb882ed4df3ce5b53 Mon Sep 17 00:00:00 2001 From: Kilik Kuo Date: Sat, 17 Sep 2016 13:17:33 +0800 Subject: [PATCH] Bug 1302331 - [Part1] Support MediaCodec.CryptoInfo in Sample class r=jchen,jolin MozReview-Commit-ID: LT89uvRxm4z --HG-- extra : rebase_source : f395efbaeca9271d1574588790f9c68fea8e1335 --- .../java/org/mozilla/gecko/media/Codec.java | 2 +- .../org/mozilla/gecko/media/CodecProxy.java | 2 +- .../java/org/mozilla/gecko/media/Sample.java | 39 +++++++++++++++++-- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/mobile/android/base/java/org/mozilla/gecko/media/Codec.java b/mobile/android/base/java/org/mozilla/gecko/media/Codec.java index d12b6b763257..897c5a41e769 100644 --- a/mobile/android/base/java/org/mozilla/gecko/media/Codec.java +++ b/mobile/android/base/java/org/mozilla/gecko/media/Codec.java @@ -52,7 +52,7 @@ import java.util.Queue; } ByteBuffer buffer = codec.getOutputBuffer(index); try { - mRemote.onOutput(new Sample(buffer, info)); + mRemote.onOutput(new Sample(buffer, info, null)); } catch (TransactionTooLargeException ttle) { Log.e(LOGTAG, "Output is too large:" + ttle.getMessage()); outputDummy(info); diff --git a/mobile/android/base/java/org/mozilla/gecko/media/CodecProxy.java b/mobile/android/base/java/org/mozilla/gecko/media/CodecProxy.java index 30ed0a4df7b9..c784580e556f 100644 --- a/mobile/android/base/java/org/mozilla/gecko/media/CodecProxy.java +++ b/mobile/android/base/java/org/mozilla/gecko/media/CodecProxy.java @@ -137,7 +137,7 @@ public final class CodecProxy { return false; } Sample sample = (info.flags == MediaCodec.BUFFER_FLAG_END_OF_STREAM) ? - Sample.EOS : new Sample(ByteBuffer.wrap(bytes), info); + Sample.EOS : new Sample(ByteBuffer.wrap(bytes), info, null); try { mRemote.queueInput(sample); } catch (DeadObjectException e) { diff --git a/mobile/android/base/java/org/mozilla/gecko/media/Sample.java b/mobile/android/base/java/org/mozilla/gecko/media/Sample.java index 7c9ccf95d0eb..3fdbd92fe3e0 100644 --- a/mobile/android/base/java/org/mozilla/gecko/media/Sample.java +++ b/mobile/android/base/java/org/mozilla/gecko/media/Sample.java @@ -6,6 +6,7 @@ package org.mozilla.gecko.media; import android.media.MediaCodec; import android.media.MediaCodec.BufferInfo; +import android.media.MediaCodec.CryptoInfo; import android.os.Parcel; import android.os.Parcelable; @@ -17,15 +18,17 @@ public final class Sample implements Parcelable { static { BufferInfo eosInfo = new BufferInfo(); eosInfo.set(0, 0, Long.MIN_VALUE, MediaCodec.BUFFER_FLAG_END_OF_STREAM); - EOS = new Sample(null, eosInfo); + EOS = new Sample(null, eosInfo, null); } public BufferInfo info; public ByteBuffer bytes; + public CryptoInfo cryptoInfo; - public Sample(ByteBuffer bytes, BufferInfo info) { + public Sample(ByteBuffer bytes, BufferInfo info, CryptoInfo cryptoInfo) { this.info = info; this.bytes = bytes; + this.cryptoInfo = cryptoInfo; } protected Sample(Parcel in) { @@ -35,7 +38,7 @@ public final class Sample implements Parcelable { public static Sample createDummyWithInfo(BufferInfo info) { BufferInfo dummyInfo = new BufferInfo(); dummyInfo.set(0, 0, info.presentationTimeUs, info.flags); - return new Sample(null, dummyInfo); + return new Sample(null, dummyInfo, null); } public boolean isDummy() { @@ -74,6 +77,25 @@ public final class Sample implements Parcelable { } info = new BufferInfo(); info.set(0, size, pts, flags); + + int hasCryptoInfo = in.readInt(); + if (hasCryptoInfo == 1) { + byte[] iv = in.createByteArray(); + byte[] key = in.createByteArray(); + int mode = in.readInt(); + int[] numBytesOfClearData = in.createIntArray(); + int[] numBytesOfEncryptedData = in.createIntArray(); + int numSubSamples = in.readInt(); + cryptoInfo = new CryptoInfo(); + cryptoInfo.set(numSubSamples, + numBytesOfClearData, + numBytesOfEncryptedData, + key, + iv, + mode); + } else { + cryptoInfo = null; + } } @Override @@ -81,6 +103,17 @@ public final class Sample implements Parcelable { dest.writeLong(info.presentationTimeUs); dest.writeInt(info.flags); dest.writeByteArray(byteArrayFromBuffer(bytes, info.offset, info.size)); + if (cryptoInfo != null) { + dest.writeInt(1); + dest.writeByteArray(cryptoInfo.iv); + dest.writeByteArray(cryptoInfo.key); + dest.writeInt(cryptoInfo.mode); + dest.writeIntArray(cryptoInfo.numBytesOfClearData); + dest.writeIntArray(cryptoInfo.numBytesOfEncryptedData); + dest.writeInt(cryptoInfo.numSubSamples); + } else { + dest.writeInt(0); + } } public static byte[] byteArrayFromBuffer(ByteBuffer buffer, int offset, int size) {