blob: 67d12a4ec436e9da4587ce368a3e05752f2cf90b [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
21#include "NdkMediaCrypto.h"
22#include "NdkMediaCodec.h"
23#include "NdkMediaFormatPriv.h"
24
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 <media/IMediaPlayerService.h>
33#include <android_runtime/AndroidRuntime.h>
34#include <android_util_Binder.h>
35
36#include <jni.h>
37
38using namespace android;
39
Marco Nelissen050eb322014-05-09 15:10:23 -070040static sp<ICrypto> makeCrypto() {
41 sp<IServiceManager> sm = defaultServiceManager();
Jeff Tinkera69729d2016-02-12 08:47:00 -080042 sp<ICrypto> crypto;
Marco Nelissen050eb322014-05-09 15:10:23 -070043
Jeff Tinkera69729d2016-02-12 08:47:00 -080044 char value[PROPERTY_VALUE_MAX];
45 if (property_get("media.mediadrmservice.enable", value, NULL)
46 && (!strcmp("1", value) || !strcasecmp("true", value))) {
47 sp<IBinder> binder =
48 sm->getService(String16("media.drm"));
49 sp<IMediaDrmService> service =
50 interface_cast<IMediaDrmService>(binder);
51 if (service == NULL) {
52 return NULL;
53 }
54 crypto = service->makeCrypto();
55 } else {
56 sp<IBinder> binder =
57 sm->getService(String16("media.player"));
58 sp<IMediaPlayerService> service =
59 interface_cast<IMediaPlayerService>(binder);
60 if (service == NULL) {
61 return NULL;
62 }
63 crypto = service->makeCrypto();
Marco Nelissen050eb322014-05-09 15:10:23 -070064 }
65
Marco Nelissen050eb322014-05-09 15:10:23 -070066 if (crypto == NULL || (crypto->initCheck() != OK && crypto->initCheck() != NO_INIT)) {
67 return NULL;
68 }
69
70 return crypto;
71}
72
73struct AMediaCrypto {
74 sp<ICrypto> mCrypto;
75};
76
77
78extern "C" {
79
80
Marco Nelissen3425fd52014-05-14 11:12:46 -070081EXPORT
Marco Nelissen829e0972014-05-13 16:22:19 -070082bool AMediaCrypto_isCryptoSchemeSupported(const AMediaUUID uuid) {
Marco Nelissen050eb322014-05-09 15:10:23 -070083 sp<ICrypto> crypto = makeCrypto();
84 if (crypto == NULL) {
85 return false;
86 }
87 return crypto->isCryptoSchemeSupported(uuid);
88}
89
Marco Nelissen3425fd52014-05-14 11:12:46 -070090EXPORT
Marco Nelissen050eb322014-05-09 15:10:23 -070091bool AMediaCrypto_requiresSecureDecoderComponent(const char *mime) {
92 sp<ICrypto> crypto = makeCrypto();
93 if (crypto == NULL) {
94 return false;
95 }
96 return crypto->requiresSecureDecoderComponent(mime);
97}
98
Marco Nelissen3425fd52014-05-14 11:12:46 -070099EXPORT
Marco Nelissen050eb322014-05-09 15:10:23 -0700100AMediaCrypto* AMediaCrypto_new(const AMediaUUID uuid, const void *data, size_t datasize) {
101
102 sp<ICrypto> tmp = makeCrypto();
103 if (tmp == NULL) {
104 return NULL;
105 }
106
107 if (tmp->createPlugin(uuid, data, datasize) != 0) {
108 return NULL;
109 }
110
111 AMediaCrypto *crypto = new AMediaCrypto();
112 crypto->mCrypto = tmp;
113
114 return crypto;
115}
116
Marco Nelissen3425fd52014-05-14 11:12:46 -0700117EXPORT
Marco Nelissen050eb322014-05-09 15:10:23 -0700118void AMediaCrypto_delete(AMediaCrypto* crypto) {
119 delete crypto;
120}
121
122
123
124} // extern "C"
125