xref: /aosp_15_r20/hardware/interfaces/cas/aidl/default/MediaCasService.cpp (revision 4d7e907c777eeecc4c5bd7cf640a754fac206ff7)
1 /*
2  * Copyright (C) 2022 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_TAG "android.hardware.cas-MediaCasService"
18 
19 #include <media/cas/CasAPI.h>
20 #include <media/cas/DescramblerAPI.h>
21 #include <utils/Log.h>
22 
23 #include "CasImpl.h"
24 #include "DescramblerImpl.h"
25 #include "MediaCasService.h"
26 
27 namespace aidl {
28 namespace android {
29 namespace hardware {
30 namespace cas {
31 
MediaCasService()32 MediaCasService::MediaCasService()
33     : mCasLoader("createCasFactory"), mDescramblerLoader("createDescramblerFactory") {}
34 
~MediaCasService()35 MediaCasService::~MediaCasService() {}
36 
enumeratePlugins(vector<AidlCasPluginDescriptor> * aidlCasPluginDescriptors)37 ScopedAStatus MediaCasService::enumeratePlugins(
38         vector<AidlCasPluginDescriptor>* aidlCasPluginDescriptors) {
39     ALOGV("%s", __FUNCTION__);
40 
41     mCasLoader.enumeratePlugins(aidlCasPluginDescriptors);
42     return ScopedAStatus::ok();
43 }
44 
isSystemIdSupported(int32_t CA_system_id,bool * _aidl_return)45 ScopedAStatus MediaCasService::isSystemIdSupported(int32_t CA_system_id, bool* _aidl_return) {
46     ALOGV("isSystemIdSupported: CA_system_id=%d", CA_system_id);
47 
48     *_aidl_return = mCasLoader.findFactoryForScheme(CA_system_id);
49     return ScopedAStatus::ok();
50 }
51 
createPlugin(int32_t CA_system_id,const shared_ptr<ICasListener> & listener,shared_ptr<ICas> * _aidl_return)52 ScopedAStatus MediaCasService::createPlugin(int32_t CA_system_id,
53                                             const shared_ptr<ICasListener>& listener,
54                                             shared_ptr<ICas>* _aidl_return) {
55     ALOGV("%s: CA_system_id=%d", __FUNCTION__, CA_system_id);
56     if (listener == NULL) ALOGV("%s: Listener is NULL", __FUNCTION__);
57 
58     CasFactory* factory;
59     shared_ptr<SharedLibrary> library;
60     if (mCasLoader.findFactoryForScheme(CA_system_id, &library, &factory)) {
61         CasPlugin* plugin = NULL;
62         shared_ptr<CasImpl> casImpl = ::ndk::SharedRefBase::make<CasImpl>(listener);
63         if (factory->createPlugin(CA_system_id, casImpl.get(), &CasImpl::CallBackExt, &plugin) ==
64                     OK &&
65             plugin != NULL) {
66             casImpl->init(plugin);
67             *_aidl_return = casImpl;
68             casImpl->setPluginStatusUpdateCallback();
69         }
70     }
71 
72     return ScopedAStatus::ok();
73 }
74 
isDescramblerSupported(int32_t CA_system_id,bool * _aidl_return)75 ScopedAStatus MediaCasService::isDescramblerSupported(int32_t CA_system_id, bool* _aidl_return) {
76     ALOGV("%s: CA_system_id=%d", __FUNCTION__, CA_system_id);
77 
78     *_aidl_return = mDescramblerLoader.findFactoryForScheme(CA_system_id);
79     return ScopedAStatus::ok();
80 }
81 
createDescrambler(int32_t CA_system_id,shared_ptr<IDescrambler> * _aidl_return)82 ScopedAStatus MediaCasService::createDescrambler(int32_t CA_system_id,
83                                                  shared_ptr<IDescrambler>* _aidl_return) {
84     ALOGV("%s: CA_system_id=%d", __FUNCTION__, CA_system_id);
85 
86     DescramblerFactory* factory;
87     shared_ptr<SharedLibrary> library;
88     if (mDescramblerLoader.findFactoryForScheme(CA_system_id, &library, &factory)) {
89         DescramblerPlugin* plugin = NULL;
90         if (factory->createPlugin(CA_system_id, &plugin) == OK && plugin != NULL) {
91             *_aidl_return = ::ndk::SharedRefBase::make<DescramblerImpl>(plugin);
92         }
93     }
94 
95     return ScopedAStatus::ok();
96 }
97 
98 }  // namespace cas
99 }  // namespace hardware
100 }  // namespace android
101 }  // namespace aidl
102