blob: 015fad22e13b988a8f02699f051bef7666217d32 [file] [log] [blame]
Chong Zhangd5927ae2017-01-03 11:07:18 -08001/*
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 Zhang2659c2f2017-04-27 13:18:20 -070022#include <android/hardware/cas/native/1.0/IDescrambler.h>
23
Chong Zhangd5927ae2017-01-03 11:07:18 -080024#include <media/stagefright/foundation/ABase.h>
25#include <utils/Mutex.h>
Chong Zhangd5927ae2017-01-03 11:07:18 -080026
27namespace android {
28class IMemory;
29class MemoryDealer;
Chong Zhang2659c2f2017-04-27 13:18:20 -070030
31using hardware::hidl_memory;
32using hardware::hidl_string;
33using hardware::hidl_vec;
34using namespace hardware::cas::V1_0;
35using namespace hardware::cas::native::V1_0;
Chong Zhangd5927ae2017-01-03 11:07:18 -080036
37struct JDescrambler : public RefBase {
38 JDescrambler(JNIEnv *env, jobject descramberBinderObj);
39
Chong Zhang2659c2f2017-04-27 13:18:20 -070040 status_t descramble(
Chong Zhangd5927ae2017-01-03 11:07:18 -080041 jbyte key,
Chong Zhangd5927ae2017-01-03 11:07:18 -080042 ssize_t totalLength,
Chong Zhang2659c2f2017-04-27 13:18:20 -070043 const hidl_vec<SubSample>& subSamples,
Chong Zhangd5927ae2017-01-03 11:07:18 -080044 const void *srcPtr,
45 jint srcOffset,
46 void *dstPtr,
Chong Zhangdadee0c2017-03-14 10:05:36 -070047 jint dstOffset,
Chong Zhang2659c2f2017-04-27 13:18:20 -070048 Status *status,
49 uint32_t *bytesWritten,
50 hidl_string *detailedError);
51
52 static sp<IDescrambler> GetDescrambler(JNIEnv *env, jobject obj);
Chong Zhangd5927ae2017-01-03 11:07:18 -080053
54protected:
55 virtual ~JDescrambler();
56
57private:
58 sp<IDescrambler> mDescrambler;
59 sp<IMemory> mMem;
60 sp<MemoryDealer> mDealer;
Chong Zhang2659c2f2017-04-27 13:18:20 -070061 SharedBuffer mDescramblerSrcBuffer;
62
Chong Zhangd5927ae2017-01-03 11:07:18 -080063 Mutex mSharedMemLock;
64
Chong Zhang2659c2f2017-04-27 13:18:20 -070065 bool ensureBufferCapacity(size_t neededSize);
Chong Zhangd5927ae2017-01-03 11:07:18 -080066
67 DISALLOW_EVIL_CONSTRUCTORS(JDescrambler);
68};
69
70} // namespace android
71
72#endif // _ANDROID_MEDIA_DESCRAMBLER_H_