Merge "cas: explicitly define possible key id values"
This commit is contained in:
committed by
Android (Google) Code Review
commit
5130fdb0ac
@@ -23443,6 +23443,11 @@ package android.media {
|
||||
method protected void finalize();
|
||||
method public boolean requiresSecureDecoderComponent(java.lang.String);
|
||||
method public void setMediaCasSession(android.media.MediaCas.Session);
|
||||
field public static final byte SCRAMBLE_CONTROL_EVEN_KEY = 2; // 0x2
|
||||
field public static final byte SCRAMBLE_CONTROL_ODD_KEY = 3; // 0x3
|
||||
field public static final byte SCRAMBLE_CONTROL_RESERVED = 1; // 0x1
|
||||
field public static final byte SCRAMBLE_CONTROL_UNSCRAMBLED = 0; // 0x0
|
||||
field public static final byte SCRAMBLE_FLAG_PES_HEADER = 1; // 0x1
|
||||
}
|
||||
|
||||
public class MediaDescription implements android.os.Parcelable {
|
||||
|
||||
@@ -124,6 +124,38 @@ public final class MediaDescrambler implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scramble control value indicating that the samples are not scrambled.
|
||||
* @see #descramble(ByteBuffer, ByteBuffer, android.media.MediaCodec.CryptoInfo)
|
||||
*/
|
||||
public static final byte SCRAMBLE_CONTROL_UNSCRAMBLED = 0;
|
||||
|
||||
/**
|
||||
* Scramble control value reserved and shouldn't be used currently.
|
||||
* @see #descramble(ByteBuffer, ByteBuffer, android.media.MediaCodec.CryptoInfo)
|
||||
*/
|
||||
public static final byte SCRAMBLE_CONTROL_RESERVED = 1;
|
||||
|
||||
/**
|
||||
* Scramble control value indicating that the even key is used.
|
||||
* @see #descramble(ByteBuffer, ByteBuffer, android.media.MediaCodec.CryptoInfo)
|
||||
*/
|
||||
public static final byte SCRAMBLE_CONTROL_EVEN_KEY = 2;
|
||||
|
||||
/**
|
||||
* Scramble control value indicating that the odd key is used.
|
||||
* @see #descramble(ByteBuffer, ByteBuffer, android.media.MediaCodec.CryptoInfo)
|
||||
*/
|
||||
public static final byte SCRAMBLE_CONTROL_ODD_KEY = 3;
|
||||
|
||||
/**
|
||||
* Scramble flag for a hint indicating that the descrambling request is for
|
||||
* retrieving the PES header info only.
|
||||
*
|
||||
* @see #descramble(ByteBuffer, ByteBuffer, android.media.MediaCodec.CryptoInfo)
|
||||
*/
|
||||
public static final byte SCRAMBLE_FLAG_PES_HEADER = (1 << 0);
|
||||
|
||||
/**
|
||||
* Descramble a ByteBuffer of data described by a
|
||||
* {@link android.media.MediaCodec.CryptoInfo} structure.
|
||||
@@ -133,7 +165,15 @@ public final class MediaDescrambler implements AutoCloseable {
|
||||
* @param dstBuf ByteBuffer to hold the descrambled data, which starts at
|
||||
* dstBuf.position().
|
||||
* @param cryptoInfo a {@link android.media.MediaCodec.CryptoInfo} structure
|
||||
* describing the subsamples contained in src.
|
||||
* describing the subsamples contained in srcBuf. The iv and mode fields in
|
||||
* CryptoInfo are not used. key[0] contains the MPEG2TS scrambling control bits
|
||||
* (as defined in ETSI TS 100 289 (2011): "Digital Video Broadcasting (DVB);
|
||||
* Support for use of the DVB Scrambling Algorithm version 3 within digital
|
||||
* broadcasting systems"), and the value must be one of {@link #SCRAMBLE_CONTROL_UNSCRAMBLED},
|
||||
* {@link #SCRAMBLE_CONTROL_RESERVED}, {@link #SCRAMBLE_CONTROL_EVEN_KEY} or
|
||||
* {@link #SCRAMBLE_CONTROL_ODD_KEY}. key[1] is a set of bit flags, with the
|
||||
* only possible bit being {@link #SCRAMBLE_FLAG_PES_HEADER} currently.
|
||||
* key[2~15] are not used.
|
||||
*
|
||||
* @return number of bytes that have been successfully descrambled, with negative
|
||||
* values indicating errors.
|
||||
@@ -169,6 +209,7 @@ public final class MediaDescrambler implements AutoCloseable {
|
||||
try {
|
||||
return native_descramble(
|
||||
cryptoInfo.key[0],
|
||||
cryptoInfo.key[1],
|
||||
cryptoInfo.numSubSamples,
|
||||
cryptoInfo.numBytesOfClearData,
|
||||
cryptoInfo.numBytesOfEncryptedData,
|
||||
@@ -204,7 +245,8 @@ public final class MediaDescrambler implements AutoCloseable {
|
||||
private native final void native_setup(@NonNull IHwBinder decramblerBinder);
|
||||
private native final void native_release();
|
||||
private native final int native_descramble(
|
||||
byte key, int numSubSamples, int[] numBytesOfClearData, int[] numBytesOfEncryptedData,
|
||||
byte key, byte flags, int numSubSamples,
|
||||
int[] numBytesOfClearData, int[] numBytesOfEncryptedData,
|
||||
@NonNull ByteBuffer srcBuf, int srcOffset, int srcLimit,
|
||||
ByteBuffer dstBuf, int dstOffset, int dstLimit) throws RemoteException;
|
||||
|
||||
|
||||
@@ -1011,7 +1011,7 @@ static void android_media_MediaCodec_native_configure(
|
||||
|
||||
sp<IDescrambler> descrambler;
|
||||
if (descramblerBinderObj != NULL) {
|
||||
descrambler = JDescrambler::GetDescrambler(env, descramblerBinderObj);
|
||||
descrambler = GetDescrambler(env, descramblerBinderObj);
|
||||
}
|
||||
|
||||
err = codec->configure(format, bufferProducer, crypto, descrambler, flags);
|
||||
|
||||
@@ -25,18 +25,64 @@
|
||||
|
||||
#include <android/hardware/cas/native/1.0/BpHwDescrambler.h>
|
||||
#include <android/hardware/cas/native/1.0/BnHwDescrambler.h>
|
||||
#include <android/hardware/cas/native/1.0/IDescrambler.h>
|
||||
#include <binder/MemoryDealer.h>
|
||||
#include <hidl/HidlSupport.h>
|
||||
#include <hidlmemory/FrameworkUtils.h>
|
||||
#include <media/stagefright/foundation/ADebug.h>
|
||||
#include <media/cas/DescramblerAPI.h>
|
||||
#include <nativehelper/ScopedLocalRef.h>
|
||||
|
||||
namespace android {
|
||||
class IMemory;
|
||||
class MemoryDealer;
|
||||
|
||||
namespace hardware {
|
||||
class HidlMemory;
|
||||
};
|
||||
using hardware::fromHeap;
|
||||
using hardware::HidlMemory;
|
||||
using hardware::hidl_string;
|
||||
using hardware::hidl_vec;
|
||||
using namespace hardware::cas::V1_0;
|
||||
using namespace hardware::cas::native::V1_0;
|
||||
|
||||
struct JDescrambler : public RefBase {
|
||||
JDescrambler(JNIEnv *env, jobject descramberBinderObj);
|
||||
|
||||
status_t descramble(
|
||||
uint32_t key,
|
||||
ssize_t totalLength,
|
||||
const hidl_vec<SubSample>& subSamples,
|
||||
const void *srcPtr,
|
||||
jint srcOffset,
|
||||
void *dstPtr,
|
||||
jint dstOffset,
|
||||
Status *status,
|
||||
uint32_t *bytesWritten,
|
||||
hidl_string *detailedError);
|
||||
|
||||
|
||||
protected:
|
||||
virtual ~JDescrambler();
|
||||
|
||||
private:
|
||||
sp<IDescrambler> mDescrambler;
|
||||
sp<IMemory> mMem;
|
||||
sp<MemoryDealer> mDealer;
|
||||
sp<HidlMemory> mHidlMemory;
|
||||
SharedBuffer mDescramblerSrcBuffer;
|
||||
|
||||
Mutex mSharedMemLock;
|
||||
|
||||
bool ensureBufferCapacity(size_t neededSize);
|
||||
|
||||
DISALLOW_EVIL_CONSTRUCTORS(JDescrambler);
|
||||
};
|
||||
|
||||
struct fields_t {
|
||||
jfieldID context;
|
||||
jbyte flagPesHeader;
|
||||
};
|
||||
|
||||
static fields_t gFields;
|
||||
@@ -111,8 +157,7 @@ JDescrambler::~JDescrambler() {
|
||||
mDealer.clear();
|
||||
}
|
||||
|
||||
// static
|
||||
sp<IDescrambler> JDescrambler::GetDescrambler(JNIEnv *env, jobject obj) {
|
||||
sp<IDescrambler> GetDescrambler(JNIEnv *env, jobject obj) {
|
||||
if (obj != NULL) {
|
||||
sp<hardware::IBinder> hwBinder =
|
||||
JHwRemoteBinder::GetNativeContext(env, obj)->getBinder();
|
||||
@@ -155,7 +200,7 @@ bool JDescrambler::ensureBufferCapacity(size_t neededSize) {
|
||||
}
|
||||
|
||||
status_t JDescrambler::descramble(
|
||||
jbyte key,
|
||||
uint32_t key,
|
||||
ssize_t totalLength,
|
||||
const hidl_vec<SubSample>& subSamples,
|
||||
const void *srcPtr,
|
||||
@@ -228,6 +273,12 @@ static void android_media_MediaDescrambler_native_init(JNIEnv *env) {
|
||||
|
||||
gFields.context = env->GetFieldID(clazz.get(), "mNativeContext", "J");
|
||||
CHECK(gFields.context != NULL);
|
||||
|
||||
jfieldID fieldPesHeader = env->GetStaticFieldID(
|
||||
clazz.get(), "SCRAMBLE_FLAG_PES_HEADER", "B");
|
||||
CHECK(fieldPesHeader != NULL);
|
||||
|
||||
gFields.flagPesHeader = env->GetStaticByteField(clazz.get(), fieldPesHeader);
|
||||
}
|
||||
|
||||
static void android_media_MediaDescrambler_native_setup(
|
||||
@@ -323,7 +374,7 @@ static jthrowable createServiceSpecificException(
|
||||
}
|
||||
|
||||
static jint android_media_MediaDescrambler_native_descramble(
|
||||
JNIEnv *env, jobject thiz, jbyte key, jint numSubSamples,
|
||||
JNIEnv *env, jobject thiz, jbyte key, jbyte flags, jint numSubSamples,
|
||||
jintArray numBytesOfClearDataObj, jintArray numBytesOfEncryptedDataObj,
|
||||
jobject srcBuf, jint srcOffset, jint srcLimit,
|
||||
jobject dstBuf, jint dstOffset, jint dstLimit) {
|
||||
@@ -364,12 +415,18 @@ static jint android_media_MediaDescrambler_native_descramble(
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t scramblingControl = (uint32_t)key;
|
||||
|
||||
if (flags & gFields.flagPesHeader) {
|
||||
scramblingControl |= DescramblerPlugin::kScrambling_Flag_PesHeader;
|
||||
}
|
||||
|
||||
Status status;
|
||||
uint32_t bytesWritten;
|
||||
hidl_string detailedError;
|
||||
|
||||
err = descrambler->descramble(
|
||||
key, totalLength, subSamples,
|
||||
scramblingControl, totalLength, subSamples,
|
||||
srcPtr, srcOffset, dstPtr, dstOffset,
|
||||
&status, &bytesWritten, &detailedError);
|
||||
|
||||
@@ -401,7 +458,7 @@ static const JNINativeMethod gMethods[] = {
|
||||
(void *)android_media_MediaDescrambler_native_init },
|
||||
{ "native_setup", "(Landroid/os/IHwBinder;)V",
|
||||
(void *)android_media_MediaDescrambler_native_setup },
|
||||
{ "native_descramble", "(BI[I[ILjava/nio/ByteBuffer;IILjava/nio/ByteBuffer;II)I",
|
||||
{ "native_descramble", "(BBI[I[ILjava/nio/ByteBuffer;IILjava/nio/ByteBuffer;II)I",
|
||||
(void *)android_media_MediaDescrambler_native_descramble },
|
||||
};
|
||||
|
||||
|
||||
@@ -19,57 +19,19 @@
|
||||
|
||||
#include "jni.h"
|
||||
|
||||
#include <android/hardware/cas/native/1.0/IDescrambler.h>
|
||||
|
||||
#include <media/stagefright/foundation/ABase.h>
|
||||
#include <utils/Mutex.h>
|
||||
#include <utils/RefBase.h>
|
||||
|
||||
namespace android {
|
||||
class IMemory;
|
||||
class MemoryDealer;
|
||||
|
||||
namespace hardware {
|
||||
class HidlMemory;
|
||||
};
|
||||
using hardware::HidlMemory;
|
||||
using hardware::hidl_string;
|
||||
using hardware::hidl_vec;
|
||||
using namespace hardware::cas::V1_0;
|
||||
using namespace hardware::cas::native::V1_0;
|
||||
namespace cas {
|
||||
namespace native {
|
||||
namespace V1_0 {
|
||||
struct IDescrambler;
|
||||
}}}}
|
||||
using hardware::cas::native::V1_0::IDescrambler;
|
||||
|
||||
struct JDescrambler : public RefBase {
|
||||
JDescrambler(JNIEnv *env, jobject descramberBinderObj);
|
||||
|
||||
status_t descramble(
|
||||
jbyte key,
|
||||
ssize_t totalLength,
|
||||
const hidl_vec<SubSample>& subSamples,
|
||||
const void *srcPtr,
|
||||
jint srcOffset,
|
||||
void *dstPtr,
|
||||
jint dstOffset,
|
||||
Status *status,
|
||||
uint32_t *bytesWritten,
|
||||
hidl_string *detailedError);
|
||||
|
||||
static sp<IDescrambler> GetDescrambler(JNIEnv *env, jobject obj);
|
||||
|
||||
protected:
|
||||
virtual ~JDescrambler();
|
||||
|
||||
private:
|
||||
sp<IDescrambler> mDescrambler;
|
||||
sp<IMemory> mMem;
|
||||
sp<MemoryDealer> mDealer;
|
||||
sp<HidlMemory> mHidlMemory;
|
||||
SharedBuffer mDescramblerSrcBuffer;
|
||||
|
||||
Mutex mSharedMemLock;
|
||||
|
||||
bool ensureBufferCapacity(size_t neededSize);
|
||||
|
||||
DISALLOW_EVIL_CONSTRUCTORS(JDescrambler);
|
||||
};
|
||||
sp<IDescrambler> GetDescrambler(JNIEnv *env, jobject obj);
|
||||
|
||||
} // namespace android
|
||||
|
||||
|
||||
Reference in New Issue
Block a user