Chong Zhang | a4f6751 | 2017-04-24 17:18:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | |
| 17 | //#define LOG_NDEBUG 0 |
| 18 | #define LOG_TAG "android.hardware.cas@1.0-MediaCasService" |
| 19 | |
| 20 | #include <android/hardware/cas/1.0/ICasListener.h> |
| 21 | #include <media/cas/CasAPI.h> |
| 22 | #include <media/cas/DescramblerAPI.h> |
| 23 | #include <utils/Log.h> |
| 24 | |
| 25 | #include "CasImpl.h" |
| 26 | #include "DescramblerImpl.h" |
| 27 | #include "MediaCasService.h" |
| 28 | |
| 29 | namespace android { |
| 30 | namespace hardware { |
| 31 | namespace cas { |
| 32 | namespace V1_0 { |
| 33 | namespace implementation { |
| 34 | |
| 35 | MediaCasService::MediaCasService() : |
| 36 | mCasLoader("createCasFactory"), |
| 37 | mDescramblerLoader("createDescramblerFactory") { |
| 38 | } |
| 39 | |
| 40 | MediaCasService::~MediaCasService() { |
| 41 | } |
| 42 | |
| 43 | Return<void> MediaCasService::enumeratePlugins(enumeratePlugins_cb _hidl_cb) { |
| 44 | |
| 45 | ALOGV("%s", __FUNCTION__); |
| 46 | |
| 47 | vector<HidlCasPluginDescriptor> results; |
| 48 | mCasLoader.enumeratePlugins(&results); |
| 49 | |
| 50 | _hidl_cb(results); |
| 51 | return Void(); |
| 52 | } |
| 53 | |
| 54 | Return<bool> MediaCasService::isSystemIdSupported(int32_t CA_system_id) { |
| 55 | ALOGV("isSystemIdSupported: CA_system_id=%d", CA_system_id); |
| 56 | |
| 57 | return mCasLoader.findFactoryForScheme(CA_system_id); |
| 58 | } |
| 59 | |
| 60 | Return<sp<ICas>> MediaCasService::createPlugin( |
| 61 | int32_t CA_system_id, const sp<ICasListener>& listener) { |
| 62 | |
| 63 | ALOGV("%s: CA_system_id=%d", __FUNCTION__, CA_system_id); |
| 64 | |
| 65 | sp<ICas> result; |
| 66 | |
| 67 | CasFactory *factory; |
| 68 | sp<SharedLibrary> library; |
| 69 | if (mCasLoader.findFactoryForScheme(CA_system_id, &library, &factory)) { |
| 70 | CasPlugin *plugin = NULL; |
| 71 | sp<CasImpl> casImpl = new CasImpl(listener); |
| 72 | if (factory->createPlugin(CA_system_id, (uint64_t)casImpl.get(), |
| 73 | &CasImpl::OnEvent, &plugin) == OK && plugin != NULL) { |
| 74 | casImpl->init(library, plugin); |
| 75 | result = casImpl; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | return result; |
| 80 | } |
| 81 | |
| 82 | Return<bool> MediaCasService::isDescramblerSupported(int32_t CA_system_id) { |
| 83 | ALOGV("%s: CA_system_id=%d", __FUNCTION__, CA_system_id); |
| 84 | |
| 85 | return mDescramblerLoader.findFactoryForScheme(CA_system_id); |
| 86 | } |
| 87 | |
| 88 | Return<sp<IDescramblerBase>> MediaCasService::createDescrambler(int32_t CA_system_id) { |
| 89 | |
| 90 | ALOGV("%s: CA_system_id=%d", __FUNCTION__, CA_system_id); |
| 91 | |
| 92 | sp<IDescrambler> result; |
| 93 | |
| 94 | DescramblerFactory *factory; |
| 95 | sp<SharedLibrary> library; |
| 96 | if (mDescramblerLoader.findFactoryForScheme( |
| 97 | CA_system_id, &library, &factory)) { |
| 98 | DescramblerPlugin *plugin = NULL; |
| 99 | if (factory->createPlugin(CA_system_id, &plugin) == OK |
| 100 | && plugin != NULL) { |
| 101 | result = new DescramblerImpl(library, plugin); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | return result; |
| 106 | } |
| 107 | |
| 108 | } // namespace implementation |
| 109 | } // namespace V1_0 |
| 110 | } // namespace cas |
| 111 | } // namespace hardware |
| 112 | } // namespace android |