1 /*
2 * Copyright (c) 2025 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 "dynamic_loader/camera_napi_ex_proxy.h"
17
18 #include "camera_log.h"
19
20
21 namespace OHOS {
22 namespace CameraStandard {
GetCameraNapiExProxy()23 std::shared_ptr<CameraNapiExProxy> CameraNapiExProxy::GetCameraNapiExProxy()
24 {
25 auto dynamiclib = CameraDynamicLoader::GetDynamiclib(NAPI_EXT_SO);
26 CHECK_RETURN_RET_ELOG(
27 dynamiclib == nullptr, nullptr, "get extension lib fail");
28 std::shared_ptr<CameraNapiExProxy> sessionForSysProxy = std::make_shared<CameraNapiExProxy>(dynamiclib);
29 return sessionForSysProxy;
30 }
CameraNapiExProxy(std::shared_ptr<Dynamiclib> napiExLib)31 CameraNapiExProxy::CameraNapiExProxy(std::shared_ptr<Dynamiclib> napiExLib) : napiExLib_(
32 napiExLib)
33 {
34 MEDIA_DEBUG_LOG("CameraNapiExProxy construct");
35 CHECK_RETURN_ELOG(napiExLib_ == nullptr, "napiExLib is null");
36 }
37
~CameraNapiExProxy()38 CameraNapiExProxy::~CameraNapiExProxy()
39 {
40 MEDIA_DEBUG_LOG("CameraNapiExProxy destruct");
41 CameraDynamicLoader::FreeDynamicLibDelayed(NAPI_EXT_SO);
42 napiExLib_ = nullptr;
43 }
44
45 typedef napi_value (*CreateSessionInstanceForSys)(napi_env, int32_t);
CreateSessionForSys(napi_env env,int32_t jsModeName)46 napi_value CameraNapiExProxy::CreateSessionForSys(napi_env env, int32_t jsModeName)
47 {
48 CAMERA_SYNC_TRACE;
49 MEDIA_DEBUG_LOG("CameraNapiExProxy::CreateSessionForSys is called");
50 napi_value result = nullptr;
51 CHECK_RETURN_RET_ELOG(napiExLib_ == nullptr, result, "napiExLib_ is null");
52 CreateSessionInstanceForSys createSessionInstanceForSys =
53 (CreateSessionInstanceForSys)napiExLib_->GetFunction("createSessionInstanceForSys");
54 CHECK_RETURN_RET_ELOG(
55 createSessionInstanceForSys == nullptr, result, "get function createSessionInstanceForSys fail");
56 result = createSessionInstanceForSys(env, jsModeName);
57 CHECK_RETURN_RET_ELOG(
58 result == nullptr, result, "createSessionInstanceForSys fail");
59 return result;
60 }
61
62 typedef napi_value (*CreateDeprecatedSessionInstanceForSys)(napi_env);
CreateDeprecatedSessionForSys(napi_env env)63 napi_value CameraNapiExProxy::CreateDeprecatedSessionForSys(napi_env env)
64 {
65 MEDIA_DEBUG_LOG("CameraNapiExProxy::CreateDeprecatedSessionForSys is called");
66 napi_value result = nullptr;
67 CHECK_RETURN_RET_ELOG(napiExLib_ == nullptr, result, "napiExLib_ is null");
68 CreateDeprecatedSessionInstanceForSys createDeprecatedSessionInstanceForSys =
69 (CreateDeprecatedSessionInstanceForSys)napiExLib_->GetFunction("createDeprecatedSessionInstanceForSys");
70 CHECK_RETURN_RET_ELOG(createDeprecatedSessionInstanceForSys == nullptr, result,
71 "get function createDeprecatedSessionInstanceForSys fail");
72 result = createDeprecatedSessionInstanceForSys(env);
73 CHECK_RETURN_RET_ELOG(
74 result == nullptr, result, "createDeprecatedSessionInstanceForSys fail");
75 return result;
76 }
77
78 typedef napi_value (*CreateModeManagerInstance)(napi_env);
CreateModeManager(napi_env env)79 napi_value CameraNapiExProxy::CreateModeManager(napi_env env)
80 {
81 MEDIA_DEBUG_LOG("CameraNapiExProxy::CreateModeManager is called");
82 napi_value result = nullptr;
83 CHECK_RETURN_RET_ELOG(napiExLib_ == nullptr, result, "napiExLib_ is null");
84 CreateModeManagerInstance createModeManagerInstance =
85 (CreateModeManagerInstance)napiExLib_->GetFunction("createModeManagerInstance");
86 CHECK_RETURN_RET_ELOG(createModeManagerInstance == nullptr, result,
87 "get function createModeManagerInstance fail");
88 result = createModeManagerInstance(env);
89 CHECK_RETURN_RET_ELOG(
90 result == nullptr, result, "createModeManagerInstance fail");
91 return result;
92 }
93
94 typedef napi_value (*CreateDepthDataOutputInstance)(napi_env, DepthProfile&);
CreateDepthDataOutput(napi_env env,DepthProfile & depthProfile)95 napi_value CameraNapiExProxy::CreateDepthDataOutput(napi_env env, DepthProfile& depthProfile)
96 {
97 MEDIA_DEBUG_LOG("CameraNapiExProxy::CreateDepthDataOutput is called");
98 napi_value result = nullptr;
99 CHECK_RETURN_RET_ELOG(napiExLib_ == nullptr, result, "napiExLib_ is null");
100 CreateDepthDataOutputInstance createDepthDataOutputInstance =
101 (CreateDepthDataOutputInstance)napiExLib_->GetFunction("createDepthDataOutputInstance");
102 CHECK_RETURN_RET_ELOG(
103 createDepthDataOutputInstance == nullptr, result, "get function createDepthDataOutputInstance fail");
104 result = createDepthDataOutputInstance(env, depthProfile);
105 CHECK_RETURN_RET_ELOG(
106 result == nullptr, result, "createDepthDataOutputInstance fail");
107 return result;
108 }
109
110 typedef bool (*CheckAndGetSysOutput)(napi_env, napi_value, sptr<CaptureOutput>&);
CheckAndGetOutput(napi_env env,napi_value obj,sptr<CaptureOutput> & output)111 bool CameraNapiExProxy::CheckAndGetOutput(napi_env env, napi_value obj, sptr<CaptureOutput> &output)
112 {
113 MEDIA_DEBUG_LOG("CameraNapiExProxy::CheckAndGetOutput is called");
114 bool result = false;
115 CHECK_RETURN_RET_ELOG(napiExLib_ == nullptr, result, "napiExLib_ is null");
116 CheckAndGetSysOutput checkAndGetOutput =
117 (CheckAndGetSysOutput)napiExLib_->GetFunction("checkAndGetOutput");
118 CHECK_RETURN_RET_ELOG(
119 checkAndGetOutput == nullptr, result, "get function checkAndGetOutput fail");
120 result = checkAndGetOutput(env, obj, output);
121 return result;
122 }
123 } // namespace CameraStandard
124 } // namespace OHOS