• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Shenzhen Kaihong DID Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "codec_component_manager_service.h"
17 #include <hdf_base.h>
18 #include "codec_component_config.h"
19 #include "codec_component_service.h"
20 #include "codec_log_wrapper.h"
21 #include "component_node.h"
22 namespace OHOS {
23 namespace HDI {
24 namespace Codec {
25 namespace V1_0 {
26 using OHOS::Codec::Omx::ComponentNode;
CodecComponentManagerImplGetInstance(void)27 extern "C" ICodecComponentManager *CodecComponentManagerImplGetInstance(void)
28 {
29     return new (std::nothrow) CodecComponentManagerService();
30 }
31 
CodecComponentManagerService()32 CodecComponentManagerService::CodecComponentManagerService() : componentId_(0)
33 {
34     mgr_ = std::make_shared<OHOS::Codec::Omx::ComponentMgr>();
35 }
36 
GetComponentNum(int32_t & count)37 int32_t CodecComponentManagerService::GetComponentNum(int32_t &count)
38 {
39     return OHOS::Codec::Omx::CodecComponentConfig::GetInstance()->GetComponentNum(count);
40 }
41 
GetComponentCapabilityList(std::vector<CodecCompCapability> & capList,int32_t count)42 int32_t CodecComponentManagerService::GetComponentCapabilityList(std::vector<CodecCompCapability> &capList,
43                                                                  int32_t count)
44 {
45     return OHOS::Codec::Omx::CodecComponentConfig::GetInstance()->GetComponentCapabilityList(capList, count);
46 }
47 
CreateComponent(sptr<ICodecComponent> & component,uint32_t & componentId,const std::string & compName,int64_t appData,const sptr<ICodecCallback> & callbacks)48 int32_t CodecComponentManagerService::CreateComponent(sptr<ICodecComponent> &component, uint32_t &componentId,
49                                                       const std::string &compName, int64_t appData,
50                                                       const sptr<ICodecCallback> &callbacks)
51 {
52     CODEC_LOGD("compName[%{public}s]", compName.c_str());
53     std::shared_ptr<ComponentNode> node = std::make_shared<ComponentNode>(callbacks, appData, mgr_);
54     auto err = node->OpenHandle(compName);
55     if (err != HDF_SUCCESS) {
56         CODEC_LOGE("OpenHandle faled, err[%{public}d]", err);
57         node = nullptr;
58         return err;
59     }
60 
61     sptr<ICodecComponent> codecComponent = new CodecComponentService(node);
62     std::unique_lock<std::mutex> autoLock(mutex_);
63     componentId = GetNextComponentId();
64     componentMap_.emplace(std::make_pair(componentId, codecComponent));
65     component = codecComponent;
66     CODEC_LOGD("componentId[%{public}d]", componentId);
67     return HDF_SUCCESS;
68 }
69 
DestoryComponent(uint32_t componentId)70 int32_t CodecComponentManagerService::DestoryComponent(uint32_t componentId)
71 {
72     CODEC_LOGD("componentId[%{public}d]", componentId);
73     auto iter = componentMap_.find(componentId);
74     if (iter == componentMap_.end() || iter->second == nullptr) {
75         CODEC_LOGE("can not find component service by componentId[%{public}d]", componentId);
76         return HDF_ERR_INVALID_PARAM;
77     }
78     std::unique_lock<std::mutex> autoLock(mutex_);
79     componentMap_.erase(iter);
80     iter->second = nullptr;
81     return HDF_SUCCESS;
82 }
83 
GetNextComponentId(void)84 uint32_t CodecComponentManagerService::GetNextComponentId(void)
85 {
86     uint32_t tempId = 0;
87     do {
88         tempId = ++componentId_;
89     } while (componentMap_.find(tempId) != componentMap_.end());
90     return tempId;
91 }
92 
LoadCapabilityData(const DeviceResourceNode & node)93 void CodecComponentManagerService::LoadCapabilityData(const DeviceResourceNode &node)
94 {
95     resourceNode_ = node;
96 }
97 }  // namespace V1_0
98 }  // namespace Codec
99 }  // namespace HDI
100 }  // namespace OHOS
101