1 /*
2  * Copyright (c) 2023 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  *     http://www.apache.org/licenses/LICENSE-2.0
7  * Unless required by applicable law or agreed to in writing, software
8  * distributed under the License is distributed on an "AS IS" BASIS,
9  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10  * See the License for the specific language governing permissions and
11  * limitations under the License.
12  */
13 
14 #ifndef STREAM_PIPELINE_DATA_STRUCTURE_H
15 #define STREAM_PIPELINE_DATA_STRUCTURE_H
16 
17 #include <dlfcn.h>
18 #include "stream_pipeline_data_structure.h"
19 #include "hdf_base.h"
20 #include "camera.h"
21 namespace OHOS::Camera {
22 #ifdef __ARCH64__
23 #define PIPELINE_CONFIG_LIB_PATH HDF_LIBRARY_DIR"64/libcamera_pipeline_config.z.so"
24 #else
25 #define PIPELINE_CONFIG_LIB_PATH HDF_LIBRARY_DIR"/libcamera_pipeline_config.z.so"
26 #endif
27 
28 using HdfGetModuleConfigRootFunc = const struct HdfConfigRoot* (*)(void);
29 using HdfGetPipelineSpecsModuleConfigRootFunc = const struct HdfConfigPipelineSpecsRoot* (*)(void);
30 
GetHandle()31 extern "C" void* GetHandle()
32 {
33     static void* handle = ::dlopen(PIPELINE_CONFIG_LIB_PATH, RTLD_NOW);
34     char* errStr = dlerror();
35     if (errStr) {
36         return nullptr;
37     }
38     return handle;
39 }
40 
HdfGetModuleConfigRoot(void)41 extern "C" const struct HdfConfigRoot* HdfGetModuleConfigRoot(void)
42 {
43     static const struct HdfConfigRoot* pHdfConfigRoot = nullptr;
44     if (pHdfConfigRoot == nullptr) {
45         void* handle = GetHandle();
46         if (!handle) {
47             return nullptr;
48         }
49         HdfGetModuleConfigRootFunc HdfGetModuleConfigRootF =
50             reinterpret_cast<HdfGetModuleConfigRootFunc>(dlsym(handle, "HdfGetModuleConfigRoot"));
51         char* errStr = dlerror();
52         if (errStr) {
53             return nullptr;
54         }
55         pHdfConfigRoot = HdfGetModuleConfigRootF();
56     }
57 
58     return pHdfConfigRoot;
59 }
60 
HdfGetPipelineSpecsModuleConfigRoot(void)61 extern "C" const struct HdfConfigPipelineSpecsRoot* HdfGetPipelineSpecsModuleConfigRoot(void)
62 {
63     static const struct HdfConfigPipelineSpecsRoot* pHdfConfigPipelineSpecsRoot = nullptr;
64     if (pHdfConfigPipelineSpecsRoot == nullptr) {
65         void* handle = GetHandle();
66         if (!handle) {
67             return nullptr;
68         }
69         HdfGetPipelineSpecsModuleConfigRootFunc HdfGetPipelineSpecsModuleConfigRootF =
70             reinterpret_cast<HdfGetPipelineSpecsModuleConfigRootFunc>(
71                 dlsym(handle, "HdfGetPipelineSpecsModuleConfigRoot"));
72         char* errStr = dlerror();
73         if (errStr) {
74             return nullptr;
75         }
76         pHdfConfigPipelineSpecsRoot = HdfGetPipelineSpecsModuleConfigRootF();
77     }
78 
79     return pHdfConfigPipelineSpecsRoot;
80 }
81 }
82 #endif
83