• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device 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 "hdf_base.h"
17 #include "algo_plugin_manager.h"
18 #ifdef CAMERA_BUILT_ON_OHOS_LITE
19 #define IPP_ALGO_PATH HDF_ETC_DIR"/camera/ipp_algo_config.hcb"
20 #else
21 #define IPP_ALGO_PATH HDF_CONFIG_DIR"/ipp_algo_config.hcb"
22 #endif
23 
24 namespace OHOS::Camera {
AlgoPluginManager()25 AlgoPluginManager::AlgoPluginManager() {}
~AlgoPluginManager()26 AlgoPluginManager::~AlgoPluginManager()
27 {
28     UnloadPlugin();
29     algoPluginList_.clear();
30 }
31 
LoadPlugin()32 RetCode AlgoPluginManager::LoadPlugin()
33 {
34     parser_ = std::make_unique<IppAlgoParser>(IPP_ALGO_PATH);
35     RetCode ret = parser_->Init();
36     if (ret != RC_OK) {
37         CAMERA_LOGE("can't load algo plugin %{public}s", IPP_ALGO_PATH);
38         return RC_ERROR;
39     }
40     algoPluginList_ = parser_->ConstructPluginByHcsData();
41     for (auto it : algoPluginList_) {
42         if (it->LoadLib() != RC_OK) {
43             CAMERA_LOGE("load algorithm lib: %{public}s failed", it->GetName().c_str());
44             continue;
45         }
46     }
47     return RC_OK;
48 }
49 
GetAlgoPlugin(int32_t mode)50 std::shared_ptr<AlgoPlugin> AlgoPluginManager::GetAlgoPlugin(int32_t mode)
51 {
52     std::shared_ptr<AlgoPlugin> plugin = nullptr;
53     for (auto& it : algoPluginList_) {
54         if (it->GetMode() == mode) {
55             plugin = it;
56             break;
57         }
58     }
59 
60     return plugin;
61 }
62 
UnloadPlugin()63 void AlgoPluginManager::UnloadPlugin()
64 {
65     for (auto it : algoPluginList_) {
66         it->UnloadLib();
67     }
68     return;
69 }
70 } // namespace OHOS::Camera
71