Bug 1302331 - [Part1] Support MediaCodec.CryptoInfo in Sample class r=jchen,jolin

MozReview-Commit-ID: LT89uvRxm4z

--HG--
extra : rebase_source : f395efbaeca9271d1574588790f9c68fea8e1335
This commit is contained in:
Kilik Kuo 2016-09-17 13:17:33 +08:00
parent 46f1b7552f
commit 892fcf2a09
3 changed files with 38 additions and 5 deletions

View File

@ -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);

View File

@ -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) {

View File

@ -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) {