Chong Zhang | d5927ae | 2017-01-03 11:07:18 -0800 | [diff] [blame] | 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 | |
Chong Zhang | 2659c2f | 2017-04-27 13:18:20 -0700 | [diff] [blame] | 22 | #include <android/hardware/cas/native/1.0/IDescrambler.h> |
| 23 | |
Chong Zhang | d5927ae | 2017-01-03 11:07:18 -0800 | [diff] [blame] | 24 | #include <media/stagefright/foundation/ABase.h> |
| 25 | #include <utils/Mutex.h> |
Chong Zhang | d5927ae | 2017-01-03 11:07:18 -0800 | [diff] [blame] | 26 | |
| 27 | namespace android { |
| 28 | class IMemory; |
| 29 | class MemoryDealer; |
Chong Zhang | 2659c2f | 2017-04-27 13:18:20 -0700 | [diff] [blame] | 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; |
Chong Zhang | d5927ae | 2017-01-03 11:07:18 -0800 | [diff] [blame] | 36 | |
| 37 | struct JDescrambler : public RefBase { |
| 38 | JDescrambler(JNIEnv *env, jobject descramberBinderObj); |
| 39 | |
Chong Zhang | 2659c2f | 2017-04-27 13:18:20 -0700 | [diff] [blame] | 40 | status_t descramble( |
Chong Zhang | d5927ae | 2017-01-03 11:07:18 -0800 | [diff] [blame] | 41 | jbyte key, |
Chong Zhang | d5927ae | 2017-01-03 11:07:18 -0800 | [diff] [blame] | 42 | ssize_t totalLength, |
Chong Zhang | 2659c2f | 2017-04-27 13:18:20 -0700 | [diff] [blame] | 43 | const hidl_vec<SubSample>& subSamples, |
Chong Zhang | d5927ae | 2017-01-03 11:07:18 -0800 | [diff] [blame] | 44 | const void *srcPtr, |
| 45 | jint srcOffset, |
| 46 | void *dstPtr, |
Chong Zhang | dadee0c | 2017-03-14 10:05:36 -0700 | [diff] [blame] | 47 | jint dstOffset, |
Chong Zhang | 2659c2f | 2017-04-27 13:18:20 -0700 | [diff] [blame] | 48 | Status *status, |
| 49 | uint32_t *bytesWritten, |
| 50 | hidl_string *detailedError); |
| 51 | |
| 52 | static sp<IDescrambler> GetDescrambler(JNIEnv *env, jobject obj); |
Chong Zhang | d5927ae | 2017-01-03 11:07:18 -0800 | [diff] [blame] | 53 | |
| 54 | protected: |
| 55 | virtual ~JDescrambler(); |
| 56 | |
| 57 | private: |
| 58 | sp<IDescrambler> mDescrambler; |
| 59 | sp<IMemory> mMem; |
| 60 | sp<MemoryDealer> mDealer; |
Chong Zhang | 2659c2f | 2017-04-27 13:18:20 -0700 | [diff] [blame] | 61 | SharedBuffer mDescramblerSrcBuffer; |
| 62 | |
Chong Zhang | d5927ae | 2017-01-03 11:07:18 -0800 | [diff] [blame] | 63 | Mutex mSharedMemLock; |
| 64 | |
Chong Zhang | 2659c2f | 2017-04-27 13:18:20 -0700 | [diff] [blame] | 65 | bool ensureBufferCapacity(size_t neededSize); |
Chong Zhang | d5927ae | 2017-01-03 11:07:18 -0800 | [diff] [blame] | 66 | |
| 67 | DISALLOW_EVIL_CONSTRUCTORS(JDescrambler); |
| 68 | }; |
| 69 | |
| 70 | } // namespace android |
| 71 | |
| 72 | #endif // _ANDROID_MEDIA_DESCRAMBLER_H_ |