blob: b8af5ff09d23e996465ce5e94f2aafbfcd6c1ad0 [file] [log] [blame]
Marco Nelissen050eb322014-05-09 15:10:23 -07001/*
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
Marco Nelissenc7a11b22014-05-30 10:13:25 -070017//#define LOG_NDEBUG 0
Marco Nelissen050eb322014-05-09 15:10:23 -070018#define LOG_TAG "NdkMediaCrypto"
19
20
Colin Cross7e8d4ba2017-05-04 16:17:42 -070021#include <media/NdkMediaCrypto.h>
22#include <media/NdkMediaCodec.h>
Marco Nelissen98603d82018-07-17 11:06:55 -070023#include <media/NdkMediaFormatPriv.h>
Marco Nelissen050eb322014-05-09 15:10:23 -070024
25
Jeff Tinkera69729d2016-02-12 08:47:00 -080026#include <cutils/properties.h>
Marco Nelissen050eb322014-05-09 15:10:23 -070027#include <utils/Log.h>
28#include <utils/StrongPointer.h>
29#include <binder/IServiceManager.h>
30#include <media/ICrypto.h>
Jeff Tinkera69729d2016-02-12 08:47:00 -080031#include <media/IMediaDrmService.h>
Marco Nelissen050eb322014-05-09 15:10:23 -070032#include <android_runtime/AndroidRuntime.h>
33#include <android_util_Binder.h>
34
35#include <jni.h>
36
37using namespace android;
38
Marco Nelissen050eb322014-05-09 15:10:23 -070039static sp<ICrypto> makeCrypto() {
40 sp<IServiceManager> sm = defaultServiceManager();
Jeff Tinker30038072016-04-25 13:41:35 -070041 sp<IBinder> binder = sm->getService(String16("media.drm"));
Marco Nelissen050eb322014-05-09 15:10:23 -070042
Jeff Tinker30038072016-04-25 13:41:35 -070043 sp<IMediaDrmService> service = interface_cast<IMediaDrmService>(binder);
44 if (service == NULL) {
Marco Nelissen050eb322014-05-09 15:10:23 -070045 return NULL;
46 }
47
Jeff Tinker30038072016-04-25 13:41:35 -070048 sp<ICrypto> crypto = service->makeCrypto();
49 if (crypto == NULL || (crypto->initCheck() != OK && crypto->initCheck() != NO_INIT)) {
50 return NULL;
51 }
Marco Nelissen050eb322014-05-09 15:10:23 -070052 return crypto;
53}
54
55struct AMediaCrypto {
56 sp<ICrypto> mCrypto;
57};
58
59
60extern "C" {
61
62
Marco Nelissen3425fd52014-05-14 11:12:46 -070063EXPORT
Marco Nelissen829e0972014-05-13 16:22:19 -070064bool AMediaCrypto_isCryptoSchemeSupported(const AMediaUUID uuid) {
Marco Nelissen050eb322014-05-09 15:10:23 -070065 sp<ICrypto> crypto = makeCrypto();
66 if (crypto == NULL) {
67 return false;
68 }
69 return crypto->isCryptoSchemeSupported(uuid);
70}
71
Marco Nelissen3425fd52014-05-14 11:12:46 -070072EXPORT
Marco Nelissen050eb322014-05-09 15:10:23 -070073bool 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
Marco Nelissen3425fd52014-05-14 11:12:46 -070081EXPORT
Marco Nelissen050eb322014-05-09 15:10:23 -070082AMediaCrypto* 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
Marco Nelissen3425fd52014-05-14 11:12:46 -070099EXPORT
Marco Nelissen050eb322014-05-09 15:10:23 -0700100void AMediaCrypto_delete(AMediaCrypto* crypto) {
101 delete crypto;
102}
103
104
105
106} // extern "C"
107