• 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 "NdkMediaFormatPriv.h"
24 
25 
26 #include <cutils/properties.h>
27 #include <utils/Log.h>
28 #include <utils/StrongPointer.h>
29 #include <binder/IServiceManager.h>
30 #include <media/ICrypto.h>
31 #include <media/IMediaDrmService.h>
32 #include <android_runtime/AndroidRuntime.h>
33 #include <android_util_Binder.h>
34 
35 #include <jni.h>
36 
37 using namespace android;
38 
makeCrypto()39 static sp<ICrypto> makeCrypto() {
40     sp<IServiceManager> sm = defaultServiceManager();
41     sp<IBinder> binder = sm->getService(String16("media.drm"));
42 
43     sp<IMediaDrmService> service = interface_cast<IMediaDrmService>(binder);
44     if (service == NULL) {
45         return NULL;
46     }
47 
48     sp<ICrypto> crypto = service->makeCrypto();
49     if (crypto == NULL || (crypto->initCheck() != OK && crypto->initCheck() != NO_INIT)) {
50         return NULL;
51     }
52     return crypto;
53 }
54 
55 struct AMediaCrypto {
56     sp<ICrypto> mCrypto;
57 };
58 
59 
60 extern "C" {
61 
62 
63 EXPORT
AMediaCrypto_isCryptoSchemeSupported(const AMediaUUID uuid)64 bool AMediaCrypto_isCryptoSchemeSupported(const AMediaUUID uuid) {
65     sp<ICrypto> crypto = makeCrypto();
66     if (crypto == NULL) {
67         return false;
68     }
69     return crypto->isCryptoSchemeSupported(uuid);
70 }
71 
72 EXPORT
AMediaCrypto_requiresSecureDecoderComponent(const char * mime)73 bool AMediaCrypto_requiresSecureDecoderComponent(const char *mime) {
74     sp<ICrypto> crypto = makeCrypto();
75     if (crypto == NULL) {
76         return false;
77     }
78     return crypto->requiresSecureDecoderComponent(mime);
79 }
80 
81 EXPORT
AMediaCrypto_new(const AMediaUUID uuid,const void * data,size_t datasize)82 AMediaCrypto* AMediaCrypto_new(const AMediaUUID uuid, const void *data, size_t datasize) {
83 
84     sp<ICrypto> tmp = makeCrypto();
85     if (tmp == NULL) {
86         return NULL;
87     }
88 
89     if (tmp->createPlugin(uuid, data, datasize) != 0) {
90         return NULL;
91     }
92 
93     AMediaCrypto *crypto = new AMediaCrypto();
94     crypto->mCrypto = tmp;
95 
96     return crypto;
97 }
98 
99 EXPORT
AMediaCrypto_delete(AMediaCrypto * crypto)100 void AMediaCrypto_delete(AMediaCrypto* crypto) {
101     delete crypto;
102 }
103 
104 
105 
106 } // extern "C"
107 
108