blob: 792fc00d479b07a92dae7af0fa626ef389b17587 [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>
Marco Nelissenb4e0c3b2019-09-27 10:21:55 -070030#include <mediadrm/ICrypto.h>
31#include <mediadrm/IMediaDrmService.h>
Marco Nelissen050eb322014-05-09 15:10:23 -070032#include <android_util_Binder.h>
33
34#include <jni.h>
35
36using namespace android;
37
Marco Nelissen050eb322014-05-09 15:10:23 -070038static sp<ICrypto> makeCrypto() {
39 sp<IServiceManager> sm = defaultServiceManager();
Jeff Tinker30038072016-04-25 13:41:35 -070040 sp<IBinder> binder = sm->getService(String16("media.drm"));
Marco Nelissen050eb322014-05-09 15:10:23 -070041
Jeff Tinker30038072016-04-25 13:41:35 -070042 sp<IMediaDrmService> service = interface_cast<IMediaDrmService>(binder);
43 if (service == NULL) {
Marco Nelissen050eb322014-05-09 15:10:23 -070044 return NULL;
45 }
46
Jeff Tinker30038072016-04-25 13:41:35 -070047 sp<ICrypto> crypto = service->makeCrypto();
48 if (crypto == NULL || (crypto->initCheck() != OK && crypto->initCheck() != NO_INIT)) {
49 return NULL;
50 }
Marco Nelissen050eb322014-05-09 15:10:23 -070051 return crypto;
52}
53
54struct AMediaCrypto {
55 sp<ICrypto> mCrypto;
56};
57
58
59extern "C" {
60
61
Marco Nelissen3425fd52014-05-14 11:12:46 -070062EXPORT
Marco Nelissen829e0972014-05-13 16:22:19 -070063bool AMediaCrypto_isCryptoSchemeSupported(const AMediaUUID uuid) {
Marco Nelissen050eb322014-05-09 15:10:23 -070064 sp<ICrypto> crypto = makeCrypto();
65 if (crypto == NULL) {
66 return false;
67 }
68 return crypto->isCryptoSchemeSupported(uuid);
69}
70
Marco Nelissen3425fd52014-05-14 11:12:46 -070071EXPORT
Marco Nelissen050eb322014-05-09 15:10:23 -070072bool AMediaCrypto_requiresSecureDecoderComponent(const char *mime) {
73 sp<ICrypto> crypto = makeCrypto();
74 if (crypto == NULL) {
75 return false;
76 }
77 return crypto->requiresSecureDecoderComponent(mime);
78}
79
Marco Nelissen3425fd52014-05-14 11:12:46 -070080EXPORT
Marco Nelissen050eb322014-05-09 15:10:23 -070081AMediaCrypto* AMediaCrypto_new(const AMediaUUID uuid, const void *data, size_t datasize) {
82
83 sp<ICrypto> tmp = makeCrypto();
84 if (tmp == NULL) {
85 return NULL;
86 }
87
88 if (tmp->createPlugin(uuid, data, datasize) != 0) {
89 return NULL;
90 }
91
92 AMediaCrypto *crypto = new AMediaCrypto();
93 crypto->mCrypto = tmp;
94
95 return crypto;
96}
97
Marco Nelissen3425fd52014-05-14 11:12:46 -070098EXPORT
Marco Nelissen050eb322014-05-09 15:10:23 -070099void AMediaCrypto_delete(AMediaCrypto* crypto) {
100 delete crypto;
101}
102
103
104
105} // extern "C"
106