blob: 1cc2f1a1a3a814b629858626966e9b9fa1d647ee [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
26#include <utils/Log.h>
27#include <utils/StrongPointer.h>
28#include <binder/IServiceManager.h>
29#include <media/ICrypto.h>
30#include <media/IMediaPlayerService.h>
31#include <android_runtime/AndroidRuntime.h>
32#include <android_util_Binder.h>
33
34#include <jni.h>
35
36using namespace android;
37
Marco Nelissene419d7c2014-05-15 14:17:25 -070038static media_status_t translate_error(status_t err) {
Marco Nelissen050eb322014-05-09 15:10:23 -070039 if (err == OK) {
Marco Nelissene419d7c2014-05-15 14:17:25 -070040 return AMEDIA_OK;
Marco Nelissen050eb322014-05-09 15:10:23 -070041 }
42 ALOGE("sf error code: %d", err);
Marco Nelissene419d7c2014-05-15 14:17:25 -070043 return AMEDIA_ERROR_UNKNOWN;
Marco Nelissen050eb322014-05-09 15:10:23 -070044}
45
46
47static sp<ICrypto> makeCrypto() {
48 sp<IServiceManager> sm = defaultServiceManager();
49
50 sp<IBinder> binder =
51 sm->getService(String16("media.player"));
52
53 sp<IMediaPlayerService> service =
54 interface_cast<IMediaPlayerService>(binder);
55
56 if (service == NULL) {
57 return NULL;
58 }
59
60 sp<ICrypto> crypto = service->makeCrypto();
61
62 if (crypto == NULL || (crypto->initCheck() != OK && crypto->initCheck() != NO_INIT)) {
63 return NULL;
64 }
65
66 return crypto;
67}
68
69struct AMediaCrypto {
70 sp<ICrypto> mCrypto;
71};
72
73
74extern "C" {
75
76
Marco Nelissen3425fd52014-05-14 11:12:46 -070077EXPORT
Marco Nelissen829e0972014-05-13 16:22:19 -070078bool AMediaCrypto_isCryptoSchemeSupported(const AMediaUUID uuid) {
Marco Nelissen050eb322014-05-09 15:10:23 -070079 sp<ICrypto> crypto = makeCrypto();
80 if (crypto == NULL) {
81 return false;
82 }
83 return crypto->isCryptoSchemeSupported(uuid);
84}
85
Marco Nelissen3425fd52014-05-14 11:12:46 -070086EXPORT
Marco Nelissen050eb322014-05-09 15:10:23 -070087bool AMediaCrypto_requiresSecureDecoderComponent(const char *mime) {
88 sp<ICrypto> crypto = makeCrypto();
89 if (crypto == NULL) {
90 return false;
91 }
92 return crypto->requiresSecureDecoderComponent(mime);
93}
94
Marco Nelissen3425fd52014-05-14 11:12:46 -070095EXPORT
Marco Nelissen050eb322014-05-09 15:10:23 -070096AMediaCrypto* AMediaCrypto_new(const AMediaUUID uuid, const void *data, size_t datasize) {
97
98 sp<ICrypto> tmp = makeCrypto();
99 if (tmp == NULL) {
100 return NULL;
101 }
102
103 if (tmp->createPlugin(uuid, data, datasize) != 0) {
104 return NULL;
105 }
106
107 AMediaCrypto *crypto = new AMediaCrypto();
108 crypto->mCrypto = tmp;
109
110 return crypto;
111}
112
Marco Nelissen3425fd52014-05-14 11:12:46 -0700113EXPORT
Marco Nelissen050eb322014-05-09 15:10:23 -0700114void AMediaCrypto_delete(AMediaCrypto* crypto) {
115 delete crypto;
116}
117
118
119
120} // extern "C"
121