blob: 741e58b45726d7fc9a4bf4181191df9c7c6fefe9 [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>
Robert Shih28c2ed32019-10-27 22:55:12 -070029#include <mediadrm/DrmUtils.h>
Marco Nelissen13aa1a42019-09-27 10:21:55 -070030#include <mediadrm/ICrypto.h>
Marco Nelissen050eb322014-05-09 15:10:23 -070031#include <android_util_Binder.h>
32
33#include <jni.h>
34
35using namespace android;
36
Marco Nelissen050eb322014-05-09 15:10:23 -070037static sp<ICrypto> makeCrypto() {
Robert Shih28c2ed32019-10-27 22:55:12 -070038 return DrmUtils::MakeCrypto();
Marco Nelissen050eb322014-05-09 15:10:23 -070039}
40
41struct AMediaCrypto {
42 sp<ICrypto> mCrypto;
43};
44
45
46extern "C" {
47
48
Marco Nelissen3425fd52014-05-14 11:12:46 -070049EXPORT
Marco Nelissen829e0972014-05-13 16:22:19 -070050bool AMediaCrypto_isCryptoSchemeSupported(const AMediaUUID uuid) {
Marco Nelissen050eb322014-05-09 15:10:23 -070051 sp<ICrypto> crypto = makeCrypto();
52 if (crypto == NULL) {
53 return false;
54 }
55 return crypto->isCryptoSchemeSupported(uuid);
56}
57
Marco Nelissen3425fd52014-05-14 11:12:46 -070058EXPORT
Marco Nelissen050eb322014-05-09 15:10:23 -070059bool 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
Marco Nelissen3425fd52014-05-14 11:12:46 -070067EXPORT
Marco Nelissen050eb322014-05-09 15:10:23 -070068AMediaCrypto* 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
Marco Nelissen3425fd52014-05-14 11:12:46 -070085EXPORT
Marco Nelissen050eb322014-05-09 15:10:23 -070086void AMediaCrypto_delete(AMediaCrypto* crypto) {
87 delete crypto;
88}
89
90
91
92} // extern "C"
93