1 /* 2 * Copyright 2017, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef _ANDROID_MEDIA_DESCRAMBLER_H_ 18 #define _ANDROID_MEDIA_DESCRAMBLER_H_ 19 20 #include "jni.h" 21 22 #include <android/hardware/cas/native/1.0/IDescrambler.h> 23 24 #include <media/stagefright/foundation/ABase.h> 25 #include <utils/Mutex.h> 26 27 namespace android { 28 class IMemory; 29 class MemoryDealer; 30 31 using hardware::hidl_memory; 32 using hardware::hidl_string; 33 using hardware::hidl_vec; 34 using namespace hardware::cas::V1_0; 35 using namespace hardware::cas::native::V1_0; 36 37 struct JDescrambler : public RefBase { 38 JDescrambler(JNIEnv *env, jobject descramberBinderObj); 39 40 status_t descramble( 41 jbyte key, 42 ssize_t totalLength, 43 const hidl_vec<SubSample>& subSamples, 44 const void *srcPtr, 45 jint srcOffset, 46 void *dstPtr, 47 jint dstOffset, 48 Status *status, 49 uint32_t *bytesWritten, 50 hidl_string *detailedError); 51 52 static sp<IDescrambler> GetDescrambler(JNIEnv *env, jobject obj); 53 54 protected: 55 virtual ~JDescrambler(); 56 57 private: 58 sp<IDescrambler> mDescrambler; 59 sp<IMemory> mMem; 60 sp<MemoryDealer> mDealer; 61 SharedBuffer mDescramblerSrcBuffer; 62 63 Mutex mSharedMemLock; 64 65 bool ensureBufferCapacity(size_t neededSize); 66 67 DISALLOW_EVIL_CONSTRUCTORS(JDescrambler); 68 }; 69 70 } // namespace android 71 72 #endif // _ANDROID_MEDIA_DESCRAMBLER_H_ 73