• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
29 namespace android {
30 namespace hardware {
31 namespace cas {
32 namespace V1_1 {
33 namespace implementation {
34 
35 class Wrapper : public V1_1::ICasListener {
36   public:
wrap(sp<V1_0::ICasListener> impl)37     static sp<V1_1::ICasListener> wrap(sp<V1_0::ICasListener> impl) {
38         sp<V1_1::ICasListener> cast = V1_1::ICasListener::castFrom(impl);
39         if (cast == NULL) {
40             cast = new Wrapper(impl);
41         }
42         return cast;
43     }
44 
onEvent(int32_t event,int32_t arg,const hidl_vec<uint8_t> & data)45     virtual Return<void> onEvent(int32_t event, int32_t arg,
46                                  const hidl_vec<uint8_t>& data) override {
47         mImpl->onEvent(event, arg, data);
48         return Void();
49     }
50 
onSessionEvent(const hidl_vec<uint8_t> &,int32_t,int32_t,const hidl_vec<uint8_t> &)51     virtual Return<void> onSessionEvent(const hidl_vec<uint8_t>& /* sessionId */,
52                                         int32_t /* event */, int32_t /* arg */,
53                                         const hidl_vec<uint8_t>& /*data*/) override {
54         ALOGV("Do nothing on Session Event for cas@1.0 client in cas@1.1");
55         return Void();
56     }
57 
58   private:
Wrapper(sp<V1_0::ICasListener> impl)59     Wrapper(sp<V1_0::ICasListener> impl) : mImpl(impl){};
60     sp<V1_0::ICasListener> mImpl;
61 };
62 
MediaCasService()63 MediaCasService::MediaCasService()
64     : mCasLoader("createCasFactory"), mDescramblerLoader("createDescramblerFactory") {}
65 
~MediaCasService()66 MediaCasService::~MediaCasService() {}
67 
enumeratePlugins(enumeratePlugins_cb _hidl_cb)68 Return<void> MediaCasService::enumeratePlugins(enumeratePlugins_cb _hidl_cb) {
69     ALOGV("%s", __FUNCTION__);
70 
71     vector<HidlCasPluginDescriptor> results;
72     mCasLoader.enumeratePlugins(&results);
73 
74     _hidl_cb(results);
75     return Void();
76 }
77 
isSystemIdSupported(int32_t CA_system_id)78 Return<bool> MediaCasService::isSystemIdSupported(int32_t CA_system_id) {
79     ALOGV("isSystemIdSupported: CA_system_id=%d", CA_system_id);
80 
81     return mCasLoader.findFactoryForScheme(CA_system_id);
82 }
83 
createPlugin(int32_t CA_system_id,const sp<V1_0::ICasListener> & listener)84 Return<sp<V1_0::ICas>> MediaCasService::createPlugin(int32_t CA_system_id,
85                                                      const sp<V1_0::ICasListener>& listener) {
86     ALOGV("%s:Use createPluginExt to create plugin in cas@1.1", __FUNCTION__);
87 
88     sp<ICas> result;
89 
90     sp<V1_1::ICasListener> listenerV1_1 = Wrapper::wrap(listener);
91 
92     result = createPluginExt(CA_system_id, listenerV1_1);
93 
94     return result;
95 }
96 
createPluginExt(int32_t CA_system_id,const sp<ICasListener> & listener)97 Return<sp<ICas>> MediaCasService::createPluginExt(int32_t CA_system_id,
98                                                   const sp<ICasListener>& listener) {
99     ALOGV("%s: CA_system_id=%d", __FUNCTION__, CA_system_id);
100     if (listener == NULL) ALOGV("%s: Listener is NULL", __FUNCTION__);
101 
102     sp<ICas> result;
103 
104     CasFactory* factory;
105     sp<SharedLibrary> library;
106     if (mCasLoader.findFactoryForScheme(CA_system_id, &library, &factory)) {
107         CasPlugin* plugin = NULL;
108         sp<CasImpl> casImpl = new CasImpl(listener);
109         if (factory->createPlugin(CA_system_id, casImpl.get(), &CasImpl::CallBackExt, &plugin) ==
110                     OK &&
111             plugin != NULL) {
112             casImpl->init(library, plugin);
113             result = casImpl;
114         }
115     }
116 
117     return result;
118 }
119 
isDescramblerSupported(int32_t CA_system_id)120 Return<bool> MediaCasService::isDescramblerSupported(int32_t CA_system_id) {
121     ALOGV("%s: CA_system_id=%d", __FUNCTION__, CA_system_id);
122 
123     return mDescramblerLoader.findFactoryForScheme(CA_system_id);
124 }
125 
createDescrambler(int32_t CA_system_id)126 Return<sp<IDescramblerBase>> MediaCasService::createDescrambler(int32_t CA_system_id) {
127     ALOGV("%s: CA_system_id=%d", __FUNCTION__, CA_system_id);
128 
129     sp<IDescrambler> result;
130 
131     DescramblerFactory* factory;
132     sp<SharedLibrary> library;
133     if (mDescramblerLoader.findFactoryForScheme(CA_system_id, &library, &factory)) {
134         DescramblerPlugin* plugin = NULL;
135         if (factory->createPlugin(CA_system_id, &plugin) == OK && plugin != NULL) {
136             result = new DescramblerImpl(library, plugin);
137         }
138     }
139 
140     return result;
141 }
142 
143 }  // namespace implementation
144 }  // namespace V1_1
145 }  // namespace cas
146 }  // namespace hardware
147 }  // namespace android
148