blob: e2d3357023345bbc8d76bbb5712d650cf53544fa [file] [log] [blame]
Henry Fang3e3cbb72019-01-31 22:46:57 +00001/*
2 * Copyright (C) 2019 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.1-MediaCasService"
19
20#include <android/hardware/cas/1.1/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
29namespace android {
30namespace hardware {
31namespace cas {
32namespace V1_1 {
33namespace implementation {
34
35MediaCasService::MediaCasService()
36 : mCasLoader("createCasFactory"), mDescramblerLoader("createDescramblerFactory") {}
37
38MediaCasService::~MediaCasService() {}
39
40Return<void> MediaCasService::enumeratePlugins(enumeratePlugins_cb _hidl_cb) {
41 ALOGV("%s", __FUNCTION__);
42
43 vector<HidlCasPluginDescriptor> results;
44 mCasLoader.enumeratePlugins(&results);
45
46 _hidl_cb(results);
47 return Void();
48}
49
50Return<bool> MediaCasService::isSystemIdSupported(int32_t CA_system_id) {
51 ALOGV("isSystemIdSupported: CA_system_id=%d", CA_system_id);
52
53 return mCasLoader.findFactoryForScheme(CA_system_id);
54}
55
56Return<sp<V1_0::ICas>> MediaCasService::createPlugin(int32_t /* CA_system_id */,
57 const sp<V1_0::ICasListener>& /* listener */) {
58 ALOGE("%s:Use createPluginExt to create plugin with cas@1.1", __FUNCTION__);
59
60 sp<V1_0::ICas> result;
61 /*
62 CasFactory *factory;
63 sp<SharedLibrary> library;
64 if (mCasLoader.findFactoryForScheme(CA_system_id, &library, &factory)) {
65 CasPlugin *plugin = NULL;
66 sp<CasImpl> casImpl = new CasImpl(listener);
67 if (factory->createPlugin(CA_system_id, casImpl.get(),
68 CasImpl::OnEvent, &plugin) == OK && plugin != NULL) {
69 casImpl->init(library, plugin);
70 result = casImpl;
71 }
72 }
73 */
74 return result;
75}
76
77Return<sp<ICas>> MediaCasService::createPluginExt(int32_t CA_system_id,
78 const sp<ICasListener>& listener) {
79 ALOGV("%s: CA_system_id=%d", __FUNCTION__, CA_system_id);
80
81 sp<ICas> result;
82
83 CasFactory* factory;
84 sp<SharedLibrary> library;
85 if (mCasLoader.findFactoryForScheme(CA_system_id, &library, &factory)) {
86 CasPlugin* plugin = NULL;
87 sp<CasImpl> casImpl = new CasImpl(listener);
88 if (factory->createPlugin(CA_system_id, casImpl.get(), &CasImpl::CallBackExt, &plugin) ==
89 OK &&
90 plugin != NULL) {
91 casImpl->init(library, plugin);
92 result = casImpl;
93 }
94 }
95
96 return result;
97}
98
99Return<bool> MediaCasService::isDescramblerSupported(int32_t CA_system_id) {
100 ALOGV("%s: CA_system_id=%d", __FUNCTION__, CA_system_id);
101
102 return mDescramblerLoader.findFactoryForScheme(CA_system_id);
103}
104
105Return<sp<IDescramblerBase>> MediaCasService::createDescrambler(int32_t CA_system_id) {
106 ALOGV("%s: CA_system_id=%d", __FUNCTION__, CA_system_id);
107
108 sp<IDescrambler> result;
109
110 DescramblerFactory* factory;
111 sp<SharedLibrary> library;
112 if (mDescramblerLoader.findFactoryForScheme(CA_system_id, &library, &factory)) {
113 DescramblerPlugin* plugin = NULL;
114 if (factory->createPlugin(CA_system_id, &plugin) == OK && plugin != NULL) {
115 result = new DescramblerImpl(library, plugin);
116 }
117 }
118
119 return result;
120}
121
122} // namespace implementation
123} // namespace V1_1
124} // namespace cas
125} // namespace hardware
126} // namespace android