Marco Nelissen | 050eb32 | 2014-05-09 15:10:23 -0700 | [diff] [blame] | 1 | /* |
| 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 Nelissen | c7a11b2 | 2014-05-30 10:13:25 -0700 | [diff] [blame] | 17 | //#define LOG_NDEBUG 0 |
Marco Nelissen | 050eb32 | 2014-05-09 15:10:23 -0700 | [diff] [blame] | 18 | #define LOG_TAG "NdkMediaCrypto" |
| 19 | |
| 20 | |
Colin Cross | 7e8d4ba | 2017-05-04 16:17:42 -0700 | [diff] [blame] | 21 | #include <media/NdkMediaCrypto.h> |
| 22 | #include <media/NdkMediaCodec.h> |
Marco Nelissen | 98603d8 | 2018-07-17 11:06:55 -0700 | [diff] [blame] | 23 | #include <media/NdkMediaFormatPriv.h> |
Marco Nelissen | 050eb32 | 2014-05-09 15:10:23 -0700 | [diff] [blame] | 24 | |
| 25 | |
Jeff Tinker | a69729d | 2016-02-12 08:47:00 -0800 | [diff] [blame] | 26 | #include <cutils/properties.h> |
Marco Nelissen | 050eb32 | 2014-05-09 15:10:23 -0700 | [diff] [blame] | 27 | #include <utils/Log.h> |
| 28 | #include <utils/StrongPointer.h> |
Robert Shih | 28c2ed3 | 2019-10-27 22:55:12 -0700 | [diff] [blame] | 29 | #include <mediadrm/DrmUtils.h> |
Marco Nelissen | 13aa1a4 | 2019-09-27 10:21:55 -0700 | [diff] [blame] | 30 | #include <mediadrm/ICrypto.h> |
Marco Nelissen | 050eb32 | 2014-05-09 15:10:23 -0700 | [diff] [blame] | 31 | #include <android_util_Binder.h> |
| 32 | |
| 33 | #include <jni.h> |
| 34 | |
| 35 | using namespace android; |
| 36 | |
Marco Nelissen | 050eb32 | 2014-05-09 15:10:23 -0700 | [diff] [blame] | 37 | static sp<ICrypto> makeCrypto() { |
Robert Shih | 28c2ed3 | 2019-10-27 22:55:12 -0700 | [diff] [blame] | 38 | return DrmUtils::MakeCrypto(); |
Marco Nelissen | 050eb32 | 2014-05-09 15:10:23 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | struct AMediaCrypto { |
| 42 | sp<ICrypto> mCrypto; |
| 43 | }; |
| 44 | |
| 45 | |
| 46 | extern "C" { |
| 47 | |
| 48 | |
Marco Nelissen | 3425fd5 | 2014-05-14 11:12:46 -0700 | [diff] [blame] | 49 | EXPORT |
Marco Nelissen | 829e097 | 2014-05-13 16:22:19 -0700 | [diff] [blame] | 50 | bool AMediaCrypto_isCryptoSchemeSupported(const AMediaUUID uuid) { |
Marco Nelissen | 050eb32 | 2014-05-09 15:10:23 -0700 | [diff] [blame] | 51 | sp<ICrypto> crypto = makeCrypto(); |
| 52 | if (crypto == NULL) { |
| 53 | return false; |
| 54 | } |
| 55 | return crypto->isCryptoSchemeSupported(uuid); |
| 56 | } |
| 57 | |
Marco Nelissen | 3425fd5 | 2014-05-14 11:12:46 -0700 | [diff] [blame] | 58 | EXPORT |
Marco Nelissen | 050eb32 | 2014-05-09 15:10:23 -0700 | [diff] [blame] | 59 | bool 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 Nelissen | 3425fd5 | 2014-05-14 11:12:46 -0700 | [diff] [blame] | 67 | EXPORT |
Marco Nelissen | 050eb32 | 2014-05-09 15:10:23 -0700 | [diff] [blame] | 68 | AMediaCrypto* 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 Nelissen | 3425fd5 | 2014-05-14 11:12:46 -0700 | [diff] [blame] | 85 | EXPORT |
Marco Nelissen | 050eb32 | 2014-05-09 15:10:23 -0700 | [diff] [blame] | 86 | void AMediaCrypto_delete(AMediaCrypto* crypto) { |
| 87 | delete crypto; |
| 88 | } |
| 89 | |
| 90 | |
| 91 | |
| 92 | } // extern "C" |
| 93 | |