• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "params.h"
22 #include "config.h"
23 namespace OHOS::Camera {
24 #ifdef __ARCH64__
25 #define PIPELINE_CONFIG_LIB_PATH HDF_LIBRARY_DIR"64/libcamera_pipeline_config.z.so"
26 #else
27 #define PIPELINE_CONFIG_LIB_PATH HDF_LIBRARY_DIR"/libcamera_pipeline_config.z.so"
28 #endif
29 
30 using HdfGetModuleConfigRootFunc = const struct HdfConfigRoot* (*)(void);
31 using HdfGetPipelineSpecsModuleConfigRootFunc = const struct HdfConfigPipelineSpecsRoot* (*)(void);
32 
GetHandle()33 extern "C" void* GetHandle()
34 {
35     static void* handle = ::dlopen(PIPELINE_CONFIG_LIB_PATH, RTLD_NOW);
36     char* errStr = dlerror();
37     if (errStr) {
38         return nullptr;
39     }
40     return handle;
41 }
42 
HdfGetModuleConfigRoot(void)43 extern "C" const struct HdfConfigRoot* HdfGetModuleConfigRoot(void)
44 {
45     static const struct HdfConfigRoot* pHdfConfigRoot = nullptr;
46     static struct HdfConfigRoot defaultConfigRoot = {
47         .module = nullptr,
48         .streamInfo = nullptr,
49         .streamInfoSize = 0,
50         .sceneInfo = nullptr,
51         .sceneInfoSize = 0,
52     };
53     if (pHdfConfigRoot == nullptr) {
54         void* handle = GetHandle();
55         if (!handle) {
56             return &defaultConfigRoot;
57         }
58         HdfGetModuleConfigRootFunc HdfGetModuleConfigRootF =
59             reinterpret_cast<HdfGetModuleConfigRootFunc>(dlsym(handle, "HdfGetModuleConfigRoot"));
60         char* errStr = dlerror();
61         if (errStr) {
62             return &defaultConfigRoot;
63         }
64         pHdfConfigRoot = HdfGetModuleConfigRootF();
65         if (pHdfConfigRoot == nullptr) {
66             return &defaultConfigRoot;
67         }
68     }
69 
70     return pHdfConfigRoot;
71 }
72 
HdfGetPipelineSpecsModuleConfigRoot(void)73 extern "C" const struct HdfConfigPipelineSpecsRoot* HdfGetPipelineSpecsModuleConfigRoot(void)
74 {
75     static const struct HdfConfigPipelineSpecsRoot* pHdfConfigPipelineSpecsRoot = nullptr;
76     static struct HdfConfigPipelineSpecsRoot defaultPipelineSpecsRoot = {
77         .module = nullptr,
78         .pipelineSpec = nullptr,
79         .pipelineSpecSize = 0,
80     };
81     if (pHdfConfigPipelineSpecsRoot == nullptr) {
82         void* handle = GetHandle();
83         if (!handle) {
84             return &defaultPipelineSpecsRoot;
85         }
86         HdfGetPipelineSpecsModuleConfigRootFunc HdfGetPipelineSpecsModuleConfigRootF =
87             reinterpret_cast<HdfGetPipelineSpecsModuleConfigRootFunc>(
88                 dlsym(handle, "HdfGetPipelineSpecsModuleConfigRoot"));
89         char* errStr = dlerror();
90         if (errStr) {
91             return &defaultPipelineSpecsRoot;
92         }
93         pHdfConfigPipelineSpecsRoot = HdfGetPipelineSpecsModuleConfigRootF();
94         if (pHdfConfigPipelineSpecsRoot == nullptr) {
95             return &defaultPipelineSpecsRoot;
96         }
97     }
98 
99     return pHdfConfigPipelineSpecsRoot;
100 }
101 }
102 #endif
103