• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 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 //#define LOG_NDEBUG 0
18 #define LOG_TAG "NdkMediaCrypto"
19 
20 
21 #include <media/NdkMediaCrypto.h>
22 #include <media/NdkMediaCodec.h>
23 #include <media/NdkMediaFormatPriv.h>
24 
25 
26 #include <cutils/properties.h>
27 #include <utils/Log.h>
28 #include <utils/StrongPointer.h>
29 #include <mediadrm/DrmUtils.h>
30 #include <mediadrm/ICrypto.h>
31 #include <android_util_Binder.h>
32 
33 #include <jni.h>
34 
35 using namespace android;
36 
makeCrypto()37 static sp<ICrypto> makeCrypto() {
38     return DrmUtils::MakeCrypto();
39 }
40 
41 struct AMediaCrypto {
42     sp<ICrypto> mCrypto;
43 };
44 
45 
46 extern "C" {
47 
48 
49 EXPORT
AMediaCrypto_isCryptoSchemeSupported(const AMediaUUID uuid)50 bool AMediaCrypto_isCryptoSchemeSupported(const AMediaUUID uuid) {
51     sp<ICrypto> crypto = makeCrypto();
52     if (crypto == NULL) {
53         return false;
54     }
55     return crypto->isCryptoSchemeSupported(uuid);
56 }
57 
58 EXPORT
AMediaCrypto_requiresSecureDecoderComponent(const char * mime)59 bool AMediaCrypto_requiresSecureDecoderComponent(const char *mime) {
60     sp<ICrypto> crypto = makeCrypto();
61     if (crypto == NULL) {
62         return false;
63     }
64     return crypto->requiresSecureDecoderComponent(mime);
65 }
66 
67 EXPORT
AMediaCrypto_new(const AMediaUUID uuid,const void * data,size_t datasize)68 AMediaCrypto* AMediaCrypto_new(const AMediaUUID uuid, const void *data, size_t datasize) {
69 
70     sp<ICrypto> tmp = makeCrypto();
71     if (tmp == NULL) {
72         return NULL;
73     }
74 
75     if (tmp->createPlugin(uuid, data, datasize) != 0) {
76         return NULL;
77     }
78 
79     AMediaCrypto *crypto = new AMediaCrypto();
80     crypto->mCrypto = tmp;
81 
82     return crypto;
83 }
84 
85 EXPORT
AMediaCrypto_delete(AMediaCrypto * crypto)86 void AMediaCrypto_delete(AMediaCrypto* crypto) {
87     delete crypto;
88 }
89 
90 
91 
92 } // extern "C"
93 
94