diff options
| author | 2018-03-01 18:50:18 +0000 | |
|---|---|---|
| committer | 2018-03-01 18:50:18 +0000 | |
| commit | 5130fdb0ace94f09c712ef7355567cedccaeb8a8 (patch) | |
| tree | 413132286f1f303d8467f6a50aeec8b5fc7123c4 | |
| parent | 341c2366cce599da1b4fb9db502bdfbe4dbfd84b (diff) | |
| parent | cd5385531165b6e13d8b6856a0678c228de5a22f (diff) | |
Merge "cas: explicitly define possible key id values"
| -rw-r--r-- | api/current.txt | 5 | ||||
| -rw-r--r-- | media/java/android/media/MediaDescrambler.java | 46 | ||||
| -rw-r--r-- | media/jni/android_media_MediaCodec.cpp | 2 | ||||
| -rw-r--r-- | media/jni/android_media_MediaDescrambler.cpp | 69 | ||||
| -rw-r--r-- | media/jni/android_media_MediaDescrambler.h | 56 |
5 files changed, 122 insertions, 56 deletions
diff --git a/api/current.txt b/api/current.txt index fbf1c22e040e..e9902b14d34d 100644 --- a/api/current.txt +++ b/api/current.txt @@ -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 { diff --git a/media/java/android/media/MediaDescrambler.java b/media/java/android/media/MediaDescrambler.java index 40c837b13cc8..99bd2549cbc7 100644 --- a/media/java/android/media/MediaDescrambler.java +++ b/media/java/android/media/MediaDescrambler.java @@ -125,6 +125,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; diff --git a/media/jni/android_media_MediaCodec.cpp b/media/jni/android_media_MediaCodec.cpp index 62030bba44f5..a1022c082909 100644 --- a/media/jni/android_media_MediaCodec.cpp +++ b/media/jni/android_media_MediaCodec.cpp @@ -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); diff --git a/media/jni/android_media_MediaDescrambler.cpp b/media/jni/android_media_MediaDescrambler.cpp index add4746322b8..aa79ce0a44ab 100644 --- a/media/jni/android_media_MediaDescrambler.cpp +++ b/media/jni/android_media_MediaDescrambler.cpp @@ -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 }, }; diff --git a/media/jni/android_media_MediaDescrambler.h b/media/jni/android_media_MediaDescrambler.h index 2354dc2d24fd..0ae41876d1f5 100644 --- a/media/jni/android_media_MediaDescrambler.h +++ b/media/jni/android_media_MediaDescrambler.h @@ -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; - -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); -}; +namespace cas { +namespace native { +namespace V1_0 { +struct IDescrambler; +}}}} +using hardware::cas::native::V1_0::IDescrambler; + +sp<IDescrambler> GetDescrambler(JNIEnv *env, jobject obj); } // namespace android |