1 /*
2 * Copyright (c) 2021-2022 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 "session/camera_session_napi.h"
17
18 #include <cstdint>
19 #include <mutex>
20 #include <string>
21 #include <unordered_map>
22 #include <uv.h>
23 #include <vector>
24
25 #include "camera_error_code.h"
26 #include "camera_napi_const.h"
27 #include "camera_napi_param_parser.h"
28 #include "camera_napi_security_utils.h"
29 #include "camera_napi_template_utils.h"
30 #include "camera_napi_utils.h"
31 #include "camera_output_capability.h"
32 #include "capture_scene_const.h"
33 #include "capture_session.h"
34 #include "js_native_api.h"
35 #include "js_native_api_types.h"
36 #include "listener_base.h"
37 #include "napi/native_api.h"
38 #include "napi/native_common.h"
39 #include "output/photo_output_napi.h"
40 #include "camera_napi_object_types.h"
41 #include "napi/native_node_api.h"
42
43 namespace OHOS {
44 namespace CameraStandard {
45 namespace {
AsyncCompleteCallback(napi_env env,napi_status status,void * data)46 void AsyncCompleteCallback(napi_env env, napi_status status, void* data)
47 {
48 auto context = static_cast<CameraSessionAsyncContext*>(data);
49 CHECK_ERROR_RETURN_LOG(context == nullptr, "CameraSessionNapi AsyncCompleteCallback context is null");
50 MEDIA_INFO_LOG("CameraSessionNapi AsyncCompleteCallback %{public}s, status = %{public}d", context->funcName.c_str(),
51 context->status);
52 std::unique_ptr<JSAsyncContextOutput> jsContext = std::make_unique<JSAsyncContextOutput>();
53 jsContext->status = context->status;
54 if (!context->status) {
55 CameraNapiUtils::CreateNapiErrorObject(env, context->errorCode, context->errorMsg.c_str(), jsContext);
56 } else {
57 napi_get_undefined(env, &jsContext->data);
58 }
59 if (!context->funcName.empty() && context->taskId > 0) {
60 // Finish async trace
61 CAMERA_FINISH_ASYNC_TRACE(context->funcName, context->taskId);
62 jsContext->funcName = context->funcName;
63 }
64 CHECK_EXECUTE(context->work != nullptr,
65 CameraNapiUtils::InvokeJSAsyncMethod(env, context->deferred, context->callbackRef, context->work, *jsContext));
66 context->FreeHeldNapiValue(env);
67 delete context;
68 }
69 } // namespace
70
71 using namespace std;
72 thread_local napi_ref CameraSessionNapi::sConstructor_ = nullptr;
73 thread_local sptr<CaptureSession> CameraSessionNapi::sCameraSession_ = nullptr;
74 thread_local uint32_t CameraSessionNapi::cameraSessionTaskId = CAMERA_SESSION_TASKID;
75
76 const std::map<SceneMode, FunctionsType> CameraSessionNapi::modeToFunctionTypeMap_ = {
77 {SceneMode::CAPTURE, FunctionsType::PHOTO_FUNCTIONS},
78 {SceneMode::VIDEO, FunctionsType::VIDEO_FUNCTIONS},
79 {SceneMode::PORTRAIT, FunctionsType::PORTRAIT_PHOTO_FUNCTIONS}
80 };
81
82 const std::map<SceneMode, FunctionsType> CameraSessionNapi::modeToConflictFunctionTypeMap_ = {
83 {SceneMode::CAPTURE, FunctionsType::PHOTO_CONFLICT_FUNCTIONS},
84 {SceneMode::VIDEO, FunctionsType::VIDEO_CONFLICT_FUNCTIONS},
85 {SceneMode::PORTRAIT, FunctionsType::PORTRAIT_PHOTO_CONFLICT_FUNCTIONS}
86 };
87
88 const std::vector<napi_property_descriptor> CameraSessionNapi::camera_process_props = {
89 DECLARE_NAPI_FUNCTION("beginConfig", CameraSessionNapi::BeginConfig),
90 DECLARE_NAPI_FUNCTION("commitConfig", CameraSessionNapi::CommitConfig),
91
92 DECLARE_NAPI_FUNCTION("canAddInput", CameraSessionNapi::CanAddInput),
93 DECLARE_NAPI_FUNCTION("addInput", CameraSessionNapi::AddInput),
94 DECLARE_NAPI_FUNCTION("removeInput", CameraSessionNapi::RemoveInput),
95
96 DECLARE_NAPI_FUNCTION("canAddOutput", CameraSessionNapi::CanAddOutput),
97 DECLARE_NAPI_FUNCTION("addOutput", CameraSessionNapi::AddOutput),
98 DECLARE_NAPI_FUNCTION("removeOutput", CameraSessionNapi::RemoveOutput),
99
100 DECLARE_NAPI_FUNCTION("start", CameraSessionNapi::Start),
101 DECLARE_NAPI_FUNCTION("stop", CameraSessionNapi::Stop),
102 DECLARE_NAPI_FUNCTION("release", CameraSessionNapi::Release),
103
104 DECLARE_NAPI_FUNCTION("lockForControl", CameraSessionNapi::LockForControl),
105 DECLARE_NAPI_FUNCTION("unlockForControl", CameraSessionNapi::UnlockForControl),
106
107 DECLARE_NAPI_FUNCTION("on", CameraSessionNapi::On),
108 DECLARE_NAPI_FUNCTION("once", CameraSessionNapi::Once),
109 DECLARE_NAPI_FUNCTION("off", CameraSessionNapi::Off),
110 DECLARE_NAPI_FUNCTION("setUsage", CameraSessionNapi::SetUsage)
111 };
112
113 const std::vector<napi_property_descriptor> CameraSessionNapi::stabilization_props = {
114 DECLARE_NAPI_FUNCTION("isVideoStabilizationModeSupported", CameraSessionNapi::IsVideoStabilizationModeSupported),
115 DECLARE_NAPI_FUNCTION("getActiveVideoStabilizationMode", CameraSessionNapi::GetActiveVideoStabilizationMode),
116 DECLARE_NAPI_FUNCTION("setVideoStabilizationMode", CameraSessionNapi::SetVideoStabilizationMode)
117 };
118
119 const std::vector<napi_property_descriptor> CameraSessionNapi::flash_props = {
120 DECLARE_NAPI_FUNCTION("hasFlash", CameraSessionNapi::HasFlash),
121 DECLARE_NAPI_FUNCTION("isFlashModeSupported", CameraSessionNapi::IsFlashModeSupported),
122 DECLARE_NAPI_FUNCTION("getFlashMode", CameraSessionNapi::GetFlashMode),
123 DECLARE_NAPI_FUNCTION("setFlashMode", CameraSessionNapi::SetFlashMode),
124 DECLARE_NAPI_FUNCTION("isLcdFlashSupported", CameraSessionNapi::IsLcdFlashSupported),
125 DECLARE_NAPI_FUNCTION("enableLcdFlash", CameraSessionNapi::EnableLcdFlash)
126 };
127
128 const std::vector<napi_property_descriptor> CameraSessionNapi::auto_exposure_props = {
129 DECLARE_NAPI_FUNCTION("isExposureModeSupported", CameraSessionNapi::IsExposureModeSupported),
130 DECLARE_NAPI_FUNCTION("getExposureMode", CameraSessionNapi::GetExposureMode),
131 DECLARE_NAPI_FUNCTION("setExposureMode", CameraSessionNapi::SetExposureMode),
132 DECLARE_NAPI_FUNCTION("getExposureBiasRange", CameraSessionNapi::GetExposureBiasRange),
133 DECLARE_NAPI_FUNCTION("setExposureBias", CameraSessionNapi::SetExposureBias),
134 DECLARE_NAPI_FUNCTION("getExposureValue", CameraSessionNapi::GetExposureValue),
135 DECLARE_NAPI_FUNCTION("getMeteringPoint", CameraSessionNapi::GetMeteringPoint),
136 DECLARE_NAPI_FUNCTION("setMeteringPoint", CameraSessionNapi::SetMeteringPoint)
137 };
138
139 const std::vector<napi_property_descriptor> CameraSessionNapi::focus_props = {
140 DECLARE_NAPI_FUNCTION("isFocusModeSupported", CameraSessionNapi::IsFocusModeSupported),
141 DECLARE_NAPI_FUNCTION("getFocusMode", CameraSessionNapi::GetFocusMode),
142 DECLARE_NAPI_FUNCTION("setFocusMode", CameraSessionNapi::SetFocusMode),
143 DECLARE_NAPI_FUNCTION("getFocusPoint", CameraSessionNapi::GetFocusPoint),
144 DECLARE_NAPI_FUNCTION("setFocusPoint", CameraSessionNapi::SetFocusPoint),
145 DECLARE_NAPI_FUNCTION("getFocalLength", CameraSessionNapi::GetFocalLength),
146 DECLARE_NAPI_FUNCTION("isFocusRangeTypeSupported", CameraSessionNapi::IsFocusRangeTypeSupported),
147 DECLARE_NAPI_FUNCTION("getFocusRange", CameraSessionNapi::GetFocusRange),
148 DECLARE_NAPI_FUNCTION("setFocusRange", CameraSessionNapi::SetFocusRange),
149 DECLARE_NAPI_FUNCTION("isFocusDrivenTypeSupported", CameraSessionNapi::IsFocusDrivenTypeSupported),
150 DECLARE_NAPI_FUNCTION("getFocusDriven", CameraSessionNapi::GetFocusDriven),
151 DECLARE_NAPI_FUNCTION("setFocusDriven", CameraSessionNapi::SetFocusDriven)
152 };
153
154 const std::vector<napi_property_descriptor> CameraSessionNapi::color_reservation_props = {
155 DECLARE_NAPI_FUNCTION("getSupportedColorReservationTypes", CameraSessionNapi::GetSupportedColorReservationTypes),
156 DECLARE_NAPI_FUNCTION("getColorReservation", CameraSessionNapi::GetColorReservation),
157 DECLARE_NAPI_FUNCTION("setColorReservation", CameraSessionNapi::SetColorReservation)
158 };
159
160 const std::vector<napi_property_descriptor> CameraSessionNapi::quality_prioritization_props = {
161 DECLARE_NAPI_FUNCTION("setQualityPrioritization", CameraSessionNapi::SetQualityPrioritization),
162 };
163
164 const std::vector<napi_property_descriptor> CameraSessionNapi::manual_focus_props = {
165 DECLARE_NAPI_FUNCTION("getFocusDistance", CameraSessionNapi::GetFocusDistance),
166 DECLARE_NAPI_FUNCTION("setFocusDistance", CameraSessionNapi::SetFocusDistance),
167 };
168
169 const std::vector<napi_property_descriptor> CameraSessionNapi::zoom_props = {
170 DECLARE_NAPI_FUNCTION("getZoomRatioRange", CameraSessionNapi::GetZoomRatioRange),
171 DECLARE_NAPI_FUNCTION("getZoomRatio", CameraSessionNapi::GetZoomRatio),
172 DECLARE_NAPI_FUNCTION("setZoomRatio", CameraSessionNapi::SetZoomRatio),
173 DECLARE_NAPI_FUNCTION("prepareZoom", PrepareZoom),
174 DECLARE_NAPI_FUNCTION("unprepareZoom", UnPrepareZoom),
175 DECLARE_NAPI_FUNCTION("setSmoothZoom", SetSmoothZoom),
176 DECLARE_NAPI_FUNCTION("getZoomPointInfos", CameraSessionNapi::GetZoomPointInfos)
177 };
178
179 const std::vector<napi_property_descriptor> CameraSessionNapi::filter_props = {
180 DECLARE_NAPI_FUNCTION("getSupportedFilters", CameraSessionNapi::GetSupportedFilters),
181 DECLARE_NAPI_FUNCTION("getFilter", CameraSessionNapi::GetFilter),
182 DECLARE_NAPI_FUNCTION("setFilter", CameraSessionNapi::SetFilter)
183 };
184
185 const std::vector<napi_property_descriptor> CameraSessionNapi::beauty_props = {
186 DECLARE_NAPI_FUNCTION("getSupportedBeautyTypes", CameraSessionNapi::GetSupportedBeautyTypes),
187 DECLARE_NAPI_FUNCTION("getSupportedBeautyRange", CameraSessionNapi::GetSupportedBeautyRange),
188 DECLARE_NAPI_FUNCTION("getBeauty", CameraSessionNapi::GetBeauty),
189 DECLARE_NAPI_FUNCTION("setBeauty", CameraSessionNapi::SetBeauty),
190 DECLARE_NAPI_FUNCTION("getSupportedPortraitThemeTypes", GetSupportedPortraitThemeTypes),
191 DECLARE_NAPI_FUNCTION("isPortraitThemeSupported", IsPortraitThemeSupported),
192 DECLARE_NAPI_FUNCTION("setPortraitThemeType", SetPortraitThemeType)
193 };
194
195 const std::vector<napi_property_descriptor> CameraSessionNapi::color_effect_props = {
196 DECLARE_NAPI_FUNCTION("getSupportedColorEffects", CameraSessionNapi::GetSupportedColorEffects),
197 DECLARE_NAPI_FUNCTION("getColorEffect", CameraSessionNapi::GetColorEffect),
198 DECLARE_NAPI_FUNCTION("setColorEffect", CameraSessionNapi::SetColorEffect)
199 };
200
201 const std::vector<napi_property_descriptor> CameraSessionNapi::macro_props = {
202 DECLARE_NAPI_FUNCTION("isMacroSupported", CameraSessionNapi::IsMacroSupported),
203 DECLARE_NAPI_FUNCTION("enableMacro", CameraSessionNapi::EnableMacro)
204 };
205
206 const std::vector<napi_property_descriptor> CameraSessionNapi::depth_fusion_props = {
207 DECLARE_NAPI_FUNCTION("isDepthFusionSupported", CameraSessionNapi::IsDepthFusionSupported),
208 DECLARE_NAPI_FUNCTION("getDepthFusionThreshold", CameraSessionNapi::GetDepthFusionThreshold),
209 DECLARE_NAPI_FUNCTION("isDepthFusionEnabled", CameraSessionNapi::IsDepthFusionEnabled),
210 DECLARE_NAPI_FUNCTION("enableDepthFusion", CameraSessionNapi::EnableDepthFusion)
211 };
212
213 const std::vector<napi_property_descriptor> CameraSessionNapi::moon_capture_boost_props = {
214 DECLARE_NAPI_FUNCTION("isMoonCaptureBoostSupported", CameraSessionNapi::IsMoonCaptureBoostSupported),
215 DECLARE_NAPI_FUNCTION("enableMoonCaptureBoost", CameraSessionNapi::EnableMoonCaptureBoost)
216 };
217
218 const std::vector<napi_property_descriptor> CameraSessionNapi::features_props = {
219 DECLARE_NAPI_FUNCTION("isSceneFeatureSupported", CameraSessionNapi::IsFeatureSupported),
220 DECLARE_NAPI_FUNCTION("enableSceneFeature", CameraSessionNapi::EnableFeature)
221 };
222
223 const std::vector<napi_property_descriptor> CameraSessionNapi::color_management_props = {
224 DECLARE_NAPI_FUNCTION("getSupportedColorSpaces", CameraSessionNapi::GetSupportedColorSpaces),
225 DECLARE_NAPI_FUNCTION("getActiveColorSpace", CameraSessionNapi::GetActiveColorSpace),
226 DECLARE_NAPI_FUNCTION("setColorSpace", CameraSessionNapi::SetColorSpace)
227 };
228
229 const std::vector<napi_property_descriptor> CameraSessionNapi::preconfig_props = {
230 DECLARE_NAPI_FUNCTION("canPreconfig", CameraSessionNapi::CanPreconfig),
231 DECLARE_NAPI_FUNCTION("preconfig", CameraSessionNapi::Preconfig)
232 };
233
234 const std::vector<napi_property_descriptor> CameraSessionNapi::camera_output_capability_props = {
235 DECLARE_NAPI_FUNCTION("getCameraOutputCapabilities", CameraSessionNapi::GetCameraOutputCapabilities)
236 };
237
238 const std::vector<napi_property_descriptor> CameraSessionNapi::camera_ability_props = {
239 DECLARE_NAPI_FUNCTION("getSessionFunctions", CameraSessionNapi::GetSessionFunctions),
240 DECLARE_NAPI_FUNCTION("getSessionConflictFunctions", CameraSessionNapi::GetSessionConflictFunctions)
241 };
242
243 const std::vector<napi_property_descriptor> CameraSessionNapi::effect_suggestion_props = {
244 DECLARE_NAPI_FUNCTION("isEffectSuggestionSupported", CameraSessionNapi::IsEffectSuggestionSupported),
245 DECLARE_NAPI_FUNCTION("enableEffectSuggestion", CameraSessionNapi::EnableEffectSuggestion),
246 DECLARE_NAPI_FUNCTION("getSupportedEffectSuggestionType", CameraSessionNapi::GetSupportedEffectSuggestionType),
247 DECLARE_NAPI_FUNCTION("getSupportedEffectSuggestionTypes", CameraSessionNapi::GetSupportedEffectSuggestionType),
248 DECLARE_NAPI_FUNCTION("setEffectSuggestionStatus", CameraSessionNapi::SetEffectSuggestionStatus),
249 DECLARE_NAPI_FUNCTION("updateEffectSuggestion", CameraSessionNapi::UpdateEffectSuggestion)
250 };
251
252 const std::vector<napi_property_descriptor> CameraSessionNapi::auto_wb_props = {
253 DECLARE_NAPI_FUNCTION("getSupportedWhiteBalanceModes", CameraSessionNapi::GetSupportedWhiteBalanceModes),
254 DECLARE_NAPI_FUNCTION("isWhiteBalanceModeSupported", CameraSessionNapi::IsWhiteBalanceModeSupported),
255 DECLARE_NAPI_FUNCTION("getWhiteBalanceMode", CameraSessionNapi::GetWhiteBalanceMode),
256 DECLARE_NAPI_FUNCTION("setWhiteBalanceMode", CameraSessionNapi::SetWhiteBalanceMode),
257 };
258
259 const std::vector<napi_property_descriptor> CameraSessionNapi::manual_wb_props = {
260 DECLARE_NAPI_FUNCTION("getWhiteBalanceRange", CameraSessionNapi::GetManualWhiteBalanceRange),
261 DECLARE_NAPI_FUNCTION("isManualWhiteBalanceSupported", CameraSessionNapi::IsManualWhiteBalanceSupported),
262 DECLARE_NAPI_FUNCTION("getWhiteBalance", CameraSessionNapi::GetManualWhiteBalance),
263 DECLARE_NAPI_FUNCTION("setWhiteBalance", CameraSessionNapi::SetManualWhiteBalance),
264 };
265
266 const std::vector<napi_property_descriptor> CameraSessionNapi::aperture_props = {
267 DECLARE_NAPI_FUNCTION("getSupportedVirtualApertures", CameraSessionNapi::GetSupportedVirtualApertures),
268 DECLARE_NAPI_FUNCTION("getVirtualAperture", CameraSessionNapi::GetVirtualAperture),
269 DECLARE_NAPI_FUNCTION("setVirtualAperture", CameraSessionNapi::SetVirtualAperture),
270
271 DECLARE_NAPI_FUNCTION("getSupportedPhysicalApertures", CameraSessionNapi::GetSupportedPhysicalApertures),
272 DECLARE_NAPI_FUNCTION("getPhysicalAperture", CameraSessionNapi::GetPhysicalAperture),
273 DECLARE_NAPI_FUNCTION("setPhysicalAperture", CameraSessionNapi::SetPhysicalAperture)
274 };
275
276 const std::vector<napi_property_descriptor> CameraSessionNapi::auto_switch_props = {
277 DECLARE_NAPI_FUNCTION("isAutoDeviceSwitchSupported", CameraSessionNapi::IsAutoDeviceSwitchSupported),
278 DECLARE_NAPI_FUNCTION("enableAutoDeviceSwitch", CameraSessionNapi::EnableAutoDeviceSwitch)
279 };
280
OnExposureStateCallbackAsync(ExposureState state) const281 void ExposureCallbackListener::OnExposureStateCallbackAsync(ExposureState state) const
282 {
283 MEDIA_DEBUG_LOG("OnExposureStateCallbackAsync is called");
284 std::unique_ptr<ExposureCallbackInfo> callbackInfo =
285 std::make_unique<ExposureCallbackInfo>(state, shared_from_this());
286 ExposureCallbackInfo *event = callbackInfo.get();
287 auto task = [event]() {
288 ExposureCallbackInfo* callbackInfo = reinterpret_cast<ExposureCallbackInfo *>(event);
289 if (callbackInfo) {
290 auto listener = callbackInfo->listener_.lock();
291 CHECK_EXECUTE(listener != nullptr, listener->OnExposureStateCallback(callbackInfo->state_));
292 delete callbackInfo;
293 }
294 };
295 if (napi_ok != napi_send_event(env_, task, napi_eprio_immediate)) {
296 MEDIA_ERR_LOG("failed to execute work");
297 } else {
298 callbackInfo.release();
299 }
300 }
301
OnExposureStateCallback(ExposureState state) const302 void ExposureCallbackListener::OnExposureStateCallback(ExposureState state) const
303 {
304 MEDIA_DEBUG_LOG("OnExposureStateCallback is called");
305 napi_value result[ARGS_TWO] = {nullptr, nullptr};
306 napi_value retVal;
307
308 napi_get_undefined(env_, &result[PARAM0]);
309 napi_create_int32(env_, state, &result[PARAM1]);
310 ExecuteCallbackNapiPara callbackNapiPara { .recv = nullptr, .argc = ARGS_TWO, .argv = result, .result = &retVal };
311 ExecuteCallback("exposureStateChange", callbackNapiPara);
312 }
313
OnExposureState(const ExposureState state)314 void ExposureCallbackListener::OnExposureState(const ExposureState state)
315 {
316 MEDIA_DEBUG_LOG("OnExposureState is called, state: %{public}d", state);
317 OnExposureStateCallbackAsync(state);
318 }
319
OnFocusStateCallbackAsync(FocusState state) const320 void FocusCallbackListener::OnFocusStateCallbackAsync(FocusState state) const
321 {
322 MEDIA_DEBUG_LOG("OnFocusStateCallbackAsync is called");
323 std::unique_ptr<FocusCallbackInfo> callbackInfo = std::make_unique<FocusCallbackInfo>(state, shared_from_this());
324 FocusCallbackInfo *event = callbackInfo.get();
325 auto task = [event]() {
326 FocusCallbackInfo* callbackInfo = reinterpret_cast<FocusCallbackInfo *>(event);
327 if (callbackInfo) {
328 auto listener = callbackInfo->listener_.lock();
329 CHECK_EXECUTE(listener != nullptr, listener->OnFocusStateCallback(callbackInfo->state_));
330 delete callbackInfo;
331 }
332 };
333 if (napi_ok != napi_send_event(env_, task, napi_eprio_immediate)) {
334 MEDIA_ERR_LOG("failed to execute work");
335 } else {
336 callbackInfo.release();
337 }
338 }
339
OnFocusStateCallback(FocusState state) const340 void FocusCallbackListener::OnFocusStateCallback(FocusState state) const
341 {
342 MEDIA_DEBUG_LOG("OnFocusStateCallback is called");
343 napi_value result[ARGS_TWO] = {nullptr, nullptr};
344 napi_value retVal;
345 napi_get_undefined(env_, &result[PARAM0]);
346 napi_create_int32(env_, state, &result[PARAM1]);
347 ExecuteCallbackNapiPara callbackNapiPara { .recv = nullptr, .argc = ARGS_TWO, .argv = result, .result = &retVal };
348 ExecuteCallback("focusStateChange", callbackNapiPara);
349 }
350
OnFocusState(FocusState state)351 void FocusCallbackListener::OnFocusState(FocusState state)
352 {
353 MEDIA_DEBUG_LOG("OnFocusState is called, state: %{public}d", state);
354 OnFocusStateCallbackAsync(state);
355 }
356
OnMacroStatusCallbackAsync(MacroStatus status) const357 void MacroStatusCallbackListener::OnMacroStatusCallbackAsync(MacroStatus status) const
358 {
359 MEDIA_DEBUG_LOG("OnMacroStatusCallbackAsync is called");
360 auto callbackInfo = std::make_unique<MacroStatusCallbackInfo>(status, shared_from_this());
361 MacroStatusCallbackInfo *event = callbackInfo.get();
362 auto task = [event]() {
363 auto callbackInfo = reinterpret_cast<MacroStatusCallbackInfo*>(event);
364 if (callbackInfo) {
365 auto listener = callbackInfo->listener_.lock();
366 CHECK_EXECUTE(listener != nullptr, listener->OnMacroStatusCallback(callbackInfo->status_));
367 delete callbackInfo;
368 }
369 };
370 if (napi_ok != napi_send_event(env_, task, napi_eprio_immediate)) {
371 MEDIA_ERR_LOG("failed to execute work");
372 } else {
373 callbackInfo.release();
374 }
375 }
376
OnMacroStatusCallback(MacroStatus status) const377 void MacroStatusCallbackListener::OnMacroStatusCallback(MacroStatus status) const
378 {
379 MEDIA_DEBUG_LOG("OnMacroStatusCallback is called");
380 napi_value result[ARGS_TWO] = { nullptr, nullptr };
381 napi_value retVal;
382 napi_get_undefined(env_, &result[PARAM0]);
383 napi_get_boolean(env_, status == MacroStatus::ACTIVE, &result[PARAM1]);
384 ExecuteCallbackNapiPara callbackNapiPara { .recv = nullptr, .argc = ARGS_TWO, .argv = result, .result = &retVal };
385 ExecuteCallback("macroStatusChanged", callbackNapiPara);
386 }
387
OnMacroStatusChanged(MacroStatus status)388 void MacroStatusCallbackListener::OnMacroStatusChanged(MacroStatus status)
389 {
390 MEDIA_DEBUG_LOG("OnMacroStatusChanged is called, status: %{public}d", status);
391 OnMacroStatusCallbackAsync(status);
392 }
393
OnMoonCaptureBoostStatusCallbackAsync(MoonCaptureBoostStatus status) const394 void MoonCaptureBoostCallbackListener::OnMoonCaptureBoostStatusCallbackAsync(MoonCaptureBoostStatus status) const
395 {
396 MEDIA_DEBUG_LOG("OnMoonCaptureBoostStatusCallbackAsync is called");
397 auto callbackInfo = std::make_unique<MoonCaptureBoostStatusCallbackInfo>(status, shared_from_this());
398 MoonCaptureBoostStatusCallbackInfo *event = callbackInfo.get();
399 auto task = [event]() {
400 auto callbackInfo = reinterpret_cast<MoonCaptureBoostStatusCallbackInfo*>(event);
401 if (callbackInfo) {
402 auto listener = callbackInfo->listener_.lock();
403 CHECK_EXECUTE(listener != nullptr, listener->OnMoonCaptureBoostStatusCallback(callbackInfo->status_));
404 delete callbackInfo;
405 }
406 };
407 if (napi_ok != napi_send_event(env_, task, napi_eprio_immediate)) {
408 MEDIA_ERR_LOG("failed to execute work");
409 } else {
410 callbackInfo.release();
411 }
412 }
413
OnMoonCaptureBoostStatusCallback(MoonCaptureBoostStatus status) const414 void MoonCaptureBoostCallbackListener::OnMoonCaptureBoostStatusCallback(MoonCaptureBoostStatus status) const
415 {
416 MEDIA_DEBUG_LOG("OnMoonCaptureBoostStatusCallback is called");
417 napi_value result[ARGS_TWO] = { nullptr, nullptr };
418 napi_value retVal;
419 napi_get_undefined(env_, &result[PARAM0]);
420 napi_get_boolean(env_, status == MoonCaptureBoostStatus::ACTIVE, &result[PARAM1]);
421 ExecuteCallbackNapiPara callbackNapiPara { .recv = nullptr, .argc = ARGS_TWO, .argv = result, .result = &retVal };
422 ExecuteCallback("moonCaptureBoostStatus", callbackNapiPara);
423 }
424
OnMoonCaptureBoostStatusChanged(MoonCaptureBoostStatus status)425 void MoonCaptureBoostCallbackListener::OnMoonCaptureBoostStatusChanged(MoonCaptureBoostStatus status)
426 {
427 MEDIA_DEBUG_LOG("OnMoonCaptureBoostStatusChanged is called, status: %{public}d", status);
428 OnMoonCaptureBoostStatusCallbackAsync(status);
429 }
430
OnFeatureDetectionStatusChangedCallbackAsync(SceneFeature feature,FeatureDetectionStatus status) const431 void FeatureDetectionStatusCallbackListener::OnFeatureDetectionStatusChangedCallbackAsync(
432 SceneFeature feature, FeatureDetectionStatus status) const
433 {
434 MEDIA_DEBUG_LOG("OnFeatureDetectionStatusChangedCallbackAsync is called");
435 auto callbackInfo = std::make_unique<FeatureDetectionStatusCallbackInfo>(feature, status, shared_from_this());
436 FeatureDetectionStatusCallbackInfo *event = callbackInfo.get();
437 auto task = [event]() {
438 auto callbackInfo = reinterpret_cast<FeatureDetectionStatusCallbackInfo*>(event);
439 if (callbackInfo) {
440 auto listener = callbackInfo->listener_.lock();
441 CHECK_EXECUTE(listener != nullptr,
442 listener->OnFeatureDetectionStatusChangedCallback(callbackInfo->feature_, callbackInfo->status_));
443 delete callbackInfo;
444 }
445 };
446 if (napi_ok != napi_send_event(env_, task, napi_eprio_immediate)) {
447 MEDIA_ERR_LOG("failed to execute work");
448 } else {
449 callbackInfo.release();
450 }
451 }
452
OnFeatureDetectionStatusChangedCallback(SceneFeature feature,FeatureDetectionStatus status) const453 void FeatureDetectionStatusCallbackListener::OnFeatureDetectionStatusChangedCallback(
454 SceneFeature feature, FeatureDetectionStatus status) const
455 {
456 MEDIA_DEBUG_LOG("OnFeatureDetectionStatusChangedCallback is called");
457 std::string eventName = "featureDetection" + std::to_string(static_cast<int32_t>(feature));
458 std::string eventNameOld = "featureDetectionStatus" + std::to_string(static_cast<int32_t>(feature));
459
460 napi_value result[ARGS_TWO] = { nullptr, nullptr };
461 napi_value retVal;
462 napi_get_undefined(env_, &result[PARAM0]);
463 napi_create_object(env_, &result[PARAM1]);
464
465 napi_value featureNapiValue;
466 napi_create_int32(env_, feature, &featureNapiValue);
467 napi_set_named_property(env_, result[PARAM1], "featureType", featureNapiValue);
468
469 napi_value statusValue;
470 napi_get_boolean(env_, status == FeatureDetectionStatus::ACTIVE, &statusValue);
471 napi_set_named_property(env_, result[PARAM1], "detected", statusValue);
472
473 if (feature == SceneFeature::FEATURE_TRIPOD_DETECTION) {
474 napi_value tripodStatusValue;
475 auto fwkTripodStatus = GetFeatureStatus();
476 napi_create_int32(env_, fwkTripodStatus, &tripodStatusValue);
477 napi_set_named_property(env_, result[PARAM1], "tripodStatus", tripodStatusValue);
478 }
479 ExecuteCallbackNapiPara callbackNapiPara { .recv = nullptr, .argc = ARGS_TWO, .argv = result, .result = &retVal };
480 ExecuteCallback(eventName, callbackNapiPara);
481 ExecuteCallback(eventNameOld, callbackNapiPara);
482 }
483
OnFeatureDetectionStatusChanged(SceneFeature feature,FeatureDetectionStatus status)484 void FeatureDetectionStatusCallbackListener::OnFeatureDetectionStatusChanged(
485 SceneFeature feature, FeatureDetectionStatus status)
486 {
487 MEDIA_DEBUG_LOG(
488 "OnFeatureDetectionStatusChanged is called,feature:%{public}d, status: %{public}d", feature, status);
489 OnFeatureDetectionStatusChangedCallbackAsync(feature, status);
490 }
491
IsFeatureSubscribed(SceneFeature feature)492 bool FeatureDetectionStatusCallbackListener::IsFeatureSubscribed(SceneFeature feature)
493 {
494 std::string eventName = "featureDetection" + std::to_string(static_cast<int32_t>(feature));
495 std::string eventNameOld = "featureDetectionStatus" + std::to_string(static_cast<int32_t>(feature));
496
497 return !IsEmpty(eventName) || !IsEmpty(eventNameOld);
498 }
499
OnErrorCallbackAsync(int32_t errorCode) const500 void SessionCallbackListener::OnErrorCallbackAsync(int32_t errorCode) const
501 {
502 MEDIA_DEBUG_LOG("OnErrorCallbackAsync is called");
503 std::unique_ptr<SessionCallbackInfo> callbackInfo =
504 std::make_unique<SessionCallbackInfo>(errorCode, shared_from_this());
505 SessionCallbackInfo *event = callbackInfo.get();
506 auto task = [event]() {
507 SessionCallbackInfo* callbackInfo = reinterpret_cast<SessionCallbackInfo *>(event);
508 if (callbackInfo) {
509 auto listener = callbackInfo->listener_.lock();
510 CHECK_EXECUTE(listener != nullptr, listener->OnErrorCallback(callbackInfo->errorCode_));
511 delete callbackInfo;
512 }
513 };
514 if (napi_ok != napi_send_event(env_, task, napi_eprio_immediate)) {
515 MEDIA_ERR_LOG("failed to execute work");
516 } else {
517 callbackInfo.release();
518 }
519 }
520
OnErrorCallback(int32_t errorCode) const521 void SessionCallbackListener::OnErrorCallback(int32_t errorCode) const
522 {
523 MEDIA_DEBUG_LOG("OnErrorCallback is called");
524 napi_value result[ARGS_ONE] = {nullptr};
525 napi_value retVal;
526 napi_value propValue;
527
528 napi_create_object(env_, &result[PARAM0]);
529 napi_create_int32(env_, errorCode, &propValue);
530 napi_set_named_property(env_, result[PARAM0], "code", propValue);
531 ExecuteCallbackNapiPara callbackNapiPara { .recv = nullptr, .argc = ARGS_ONE, .argv = result, .result = &retVal };
532 ExecuteCallback("error", callbackNapiPara);
533 }
534
OnError(int32_t errorCode)535 void SessionCallbackListener::OnError(int32_t errorCode)
536 {
537 MEDIA_DEBUG_LOG("OnError is called, errorCode: %{public}d", errorCode);
538 OnErrorCallbackAsync(errorCode);
539 }
540
OnSmoothZoomCallbackAsync(int32_t duration) const541 void SmoothZoomCallbackListener::OnSmoothZoomCallbackAsync(int32_t duration) const
542 {
543 MEDIA_DEBUG_LOG("OnSmoothZoomCallbackAsync is called");
544 std::unique_ptr<SmoothZoomCallbackInfo> callbackInfo =
545 std::make_unique<SmoothZoomCallbackInfo>(duration, shared_from_this());
546 SmoothZoomCallbackInfo *event = callbackInfo.get();
547 auto task = [event]() {
548 SmoothZoomCallbackInfo* callbackInfo = reinterpret_cast<SmoothZoomCallbackInfo *>(event);
549 if (callbackInfo) {
550 auto listener = callbackInfo->listener_.lock();
551 CHECK_EXECUTE(listener != nullptr, listener->OnSmoothZoomCallback(callbackInfo->duration_));
552 delete callbackInfo;
553 }
554 };
555 if (napi_ok != napi_send_event(env_, task, napi_eprio_immediate)) {
556 MEDIA_ERR_LOG("failed to execute work");
557 } else {
558 callbackInfo.release();
559 }
560 }
561
OnSmoothZoomCallback(int32_t duration) const562 void SmoothZoomCallbackListener::OnSmoothZoomCallback(int32_t duration) const
563 {
564 MEDIA_DEBUG_LOG("OnSmoothZoomCallback is called");
565 napi_value result[ARGS_TWO];
566 napi_value retVal;
567 napi_value propValue;
568
569 napi_get_undefined(env_, &result[PARAM0]);
570 napi_create_object(env_, &result[PARAM1]);
571 napi_create_int32(env_, duration, &propValue);
572 napi_set_named_property(env_, result[PARAM1], "duration", propValue);
573
574 ExecuteCallbackNapiPara callbackNapiPara { .recv = nullptr, .argc = ARGS_TWO, .argv = result, .result = &retVal };
575 ExecuteCallback("smoothZoomInfoAvailable", callbackNapiPara);
576 }
577
OnSmoothZoom(int32_t duration)578 void SmoothZoomCallbackListener::OnSmoothZoom(int32_t duration)
579 {
580 MEDIA_DEBUG_LOG("OnSmoothZoom is called, duration: %{public}d", duration);
581 OnSmoothZoomCallbackAsync(duration);
582 }
583
OnAbilityChangeCallbackAsync() const584 void AbilityCallbackListener::OnAbilityChangeCallbackAsync() const
585 {
586 MEDIA_DEBUG_LOG("OnAbilityChangeCallbackAsync is called");
587 std::unique_ptr<AbilityCallbackInfo> callbackInfo = std::make_unique<AbilityCallbackInfo>(shared_from_this());
588 AbilityCallbackInfo *event = callbackInfo.get();
589 auto task = [event]() {
590 AbilityCallbackInfo* callbackInfo = reinterpret_cast<AbilityCallbackInfo *>(event);
591 if (callbackInfo) {
592 auto listener = callbackInfo->listener_.lock();
593 CHECK_EXECUTE(listener != nullptr, listener->OnAbilityChangeCallback());
594 delete callbackInfo;
595 }
596 };
597 if (napi_ok != napi_send_event(env_, task, napi_eprio_immediate)) {
598 MEDIA_ERR_LOG("failed to execute work");
599 } else {
600 callbackInfo.release();
601 }
602 }
603
OnAbilityChangeCallback() const604 void AbilityCallbackListener::OnAbilityChangeCallback() const
605 {
606 MEDIA_DEBUG_LOG("OnAbilityChangeCallback is called");
607 napi_value result[ARGS_TWO];
608 napi_value retVal;
609 napi_get_undefined(env_, &result[PARAM0]);
610 napi_get_undefined(env_, &result[PARAM1]);
611
612 ExecuteCallbackNapiPara callbackNapiPara { .recv = nullptr, .argc = ARGS_TWO, .argv = result, .result = &retVal };
613 ExecuteCallback("abilityChange", callbackNapiPara);
614 }
615
OnAbilityChange()616 void AbilityCallbackListener::OnAbilityChange()
617 {
618 MEDIA_DEBUG_LOG("OnAbilityChange is called");
619 OnAbilityChangeCallbackAsync();
620 }
621
OnEffectSuggestionCallbackAsync(EffectSuggestionType effectSuggestionType) const622 void EffectSuggestionCallbackListener::OnEffectSuggestionCallbackAsync(EffectSuggestionType effectSuggestionType) const
623 {
624 MEDIA_DEBUG_LOG("OnEffectSuggestionCallbackAsync is called");
625 std::unique_ptr<EffectSuggestionCallbackInfo> callbackInfo =
626 std::make_unique<EffectSuggestionCallbackInfo>(effectSuggestionType, shared_from_this());
627 EffectSuggestionCallbackInfo *event = callbackInfo.get();
628 auto task = [event]() {
629 EffectSuggestionCallbackInfo* callbackInfo = reinterpret_cast<EffectSuggestionCallbackInfo *>(event);
630 if (callbackInfo) {
631 auto listener = callbackInfo->listener_.lock();
632 CHECK_EXECUTE(listener != nullptr,
633 listener->OnEffectSuggestionCallback(callbackInfo->effectSuggestionType_));
634 delete callbackInfo;
635 }
636 };
637 if (napi_ok != napi_send_event(env_, task, napi_eprio_immediate)) {
638 MEDIA_ERR_LOG("failed to execute work");
639 } else {
640 callbackInfo.release();
641 }
642 }
643
OnEffectSuggestionCallback(EffectSuggestionType effectSuggestionType) const644 void EffectSuggestionCallbackListener::OnEffectSuggestionCallback(EffectSuggestionType effectSuggestionType) const
645 {
646 MEDIA_DEBUG_LOG("OnEffectSuggestionCallback is called");
647 napi_value result[ARGS_TWO] = {nullptr, nullptr};
648 napi_value retVal;
649 napi_get_undefined(env_, &result[PARAM0]);
650 napi_create_int32(env_, effectSuggestionType, &result[PARAM1]);
651 ExecuteCallbackNapiPara callbackNapiPara { .recv = nullptr, .argc = ARGS_TWO, .argv = result, .result = &retVal };
652 ExecuteCallback("effectSuggestionChange", callbackNapiPara);
653 }
654
OnEffectSuggestionChange(EffectSuggestionType effectSuggestionType)655 void EffectSuggestionCallbackListener::OnEffectSuggestionChange(EffectSuggestionType effectSuggestionType)
656 {
657 MEDIA_DEBUG_LOG("OnEffectSuggestionChange is called, effectSuggestionType: %{public}d", effectSuggestionType);
658 OnEffectSuggestionCallbackAsync(effectSuggestionType);
659 }
660
OnLcdFlashStatusCallbackAsync(LcdFlashStatusInfo lcdFlashStatusInfo) const661 void LcdFlashStatusCallbackListener::OnLcdFlashStatusCallbackAsync(LcdFlashStatusInfo lcdFlashStatusInfo) const
662 {
663 MEDIA_DEBUG_LOG("OnLcdFlashStatusCallbackAsync is called");
664 auto callbackInfo = std::make_unique<LcdFlashStatusStatusCallbackInfo>(lcdFlashStatusInfo, shared_from_this());
665 LcdFlashStatusStatusCallbackInfo *event = callbackInfo.get();
666 auto task = [event]() {
667 auto callbackInfo = reinterpret_cast<LcdFlashStatusStatusCallbackInfo*>(event);
668 if (callbackInfo) {
669 auto listener = callbackInfo->listener_.lock();
670 CHECK_EXECUTE(listener != nullptr,
671 listener->OnLcdFlashStatusCallback(callbackInfo->lcdFlashStatusInfo_));
672 delete callbackInfo;
673 }
674 };
675 if (napi_ok != napi_send_event(env_, task, napi_eprio_immediate)) {
676 MEDIA_ERR_LOG("failed to execute work");
677 } else {
678 callbackInfo.release();
679 }
680 }
681
OnLcdFlashStatusCallback(LcdFlashStatusInfo lcdFlashStatusInfo) const682 void LcdFlashStatusCallbackListener::OnLcdFlashStatusCallback(LcdFlashStatusInfo lcdFlashStatusInfo) const
683 {
684 MEDIA_DEBUG_LOG("OnLcdFlashStatusCallback is called");
685 napi_value result[ARGS_TWO] = { nullptr, nullptr };
686 napi_get_undefined(env_, &result[PARAM0]);
687 napi_value retVal;
688 napi_value propValue;
689 napi_create_object(env_, &result[PARAM1]);
690 napi_get_boolean(env_, lcdFlashStatusInfo.isLcdFlashNeeded, &propValue);
691 napi_set_named_property(env_, result[PARAM1], "isLcdFlashNeeded", propValue);
692 napi_create_int32(env_, lcdFlashStatusInfo.lcdCompensation, &propValue);
693 napi_set_named_property(env_, result[PARAM1], "lcdCompensation", propValue);
694 ExecuteCallbackNapiPara callbackNapiPara { .recv = nullptr, .argc = ARGS_TWO, .argv = result, .result = &retVal };
695 ExecuteCallback("lcdFlashStatus", callbackNapiPara);
696 }
697
OnLcdFlashStatusChanged(LcdFlashStatusInfo lcdFlashStatusInfo)698 void LcdFlashStatusCallbackListener::OnLcdFlashStatusChanged(LcdFlashStatusInfo lcdFlashStatusInfo)
699 {
700 MEDIA_DEBUG_LOG("OnLcdFlashStatusChanged is called, isLcdFlashNeeded: %{public}d, lcdCompensation: %{public}d",
701 lcdFlashStatusInfo.isLcdFlashNeeded, lcdFlashStatusInfo.lcdCompensation);
702 OnLcdFlashStatusCallbackAsync(lcdFlashStatusInfo);
703 }
704
OnAutoDeviceSwitchCallbackAsync(bool isDeviceSwitched,bool isDeviceCapabilityChanged) const705 void AutoDeviceSwitchCallbackListener::OnAutoDeviceSwitchCallbackAsync(
706 bool isDeviceSwitched, bool isDeviceCapabilityChanged) const
707 {
708 MEDIA_DEBUG_LOG("OnAutoDeviceSwitchCallbackAsync is called");
709 auto callbackInfo = std::make_unique<AutoDeviceSwitchCallbackListenerInfo>(
710 isDeviceSwitched, isDeviceCapabilityChanged, shared_from_this());
711 AutoDeviceSwitchCallbackListenerInfo *event = callbackInfo.get();
712 auto task = [event]() {
713 auto callbackInfo = reinterpret_cast<AutoDeviceSwitchCallbackListenerInfo*>(event);
714 if (callbackInfo) {
715 auto listener = callbackInfo->listener_.lock();
716 CHECK_EXECUTE(listener != nullptr, listener->OnAutoDeviceSwitchCallback(callbackInfo->isDeviceSwitched_,
717 callbackInfo->isDeviceCapabilityChanged_));
718 delete callbackInfo;
719 }
720 };
721 if (napi_ok != napi_send_event(env_, task, napi_eprio_immediate)) {
722 MEDIA_ERR_LOG("failed to execute work");
723 } else {
724 callbackInfo.release();
725 }
726 }
727
OnAutoDeviceSwitchCallback(bool isDeviceSwitched,bool isDeviceCapabilityChanged) const728 void AutoDeviceSwitchCallbackListener::OnAutoDeviceSwitchCallback(
729 bool isDeviceSwitched, bool isDeviceCapabilityChanged) const
730 {
731 MEDIA_INFO_LOG("OnAutoDeviceSwitchCallback is called");
732 napi_value result[ARGS_TWO] = { nullptr, nullptr };
733 napi_get_undefined(env_, &result[PARAM0]);
734 napi_value retVal;
735 napi_value propValue;
736 napi_create_object(env_, &result[PARAM1]);
737 napi_get_boolean(env_, isDeviceSwitched, &propValue);
738 napi_set_named_property(env_, result[PARAM1], "isDeviceSwitched", propValue);
739 napi_get_boolean(env_, isDeviceCapabilityChanged, &propValue);
740 napi_set_named_property(env_, result[PARAM1], "isDeviceCapabilityChanged", propValue);
741 ExecuteCallbackNapiPara callbackNapiPara { .recv = nullptr, .argc = ARGS_TWO, .argv = result, .result = &retVal };
742 ExecuteCallback("autoDeviceSwitchStatusChange", callbackNapiPara);
743 }
744
OnAutoDeviceSwitchStatusChange(bool isDeviceSwitched,bool isDeviceCapabilityChanged) const745 void AutoDeviceSwitchCallbackListener::OnAutoDeviceSwitchStatusChange(
746 bool isDeviceSwitched, bool isDeviceCapabilityChanged) const
747 {
748 MEDIA_INFO_LOG("isDeviceSwitched: %{public}d, isDeviceCapabilityChanged: %{public}d",
749 isDeviceSwitched, isDeviceCapabilityChanged);
750 OnAutoDeviceSwitchCallbackAsync(isDeviceSwitched, isDeviceCapabilityChanged);
751 }
752
CameraSessionNapi()753 CameraSessionNapi::CameraSessionNapi() : env_(nullptr) {}
754
~CameraSessionNapi()755 CameraSessionNapi::~CameraSessionNapi()
756 {
757 MEDIA_DEBUG_LOG("~CameraSessionNapi is called");
758 }
759
CameraSessionNapiDestructor(napi_env env,void * nativeObject,void * finalize_hint)760 void CameraSessionNapi::CameraSessionNapiDestructor(napi_env env, void* nativeObject, void* finalize_hint)
761 {
762 MEDIA_DEBUG_LOG("CameraSessionNapiDestructor is called");
763 }
764
Init(napi_env env,napi_value exports)765 napi_value CameraSessionNapi::Init(napi_env env, napi_value exports)
766 {
767 MEDIA_DEBUG_LOG("Init is called");
768 napi_status status;
769 napi_value ctorObj;
770 int32_t refCount = 1;
771 std::vector<std::vector<napi_property_descriptor>> descriptors = { camera_process_props, stabilization_props,
772 flash_props, auto_exposure_props, focus_props, zoom_props, filter_props, beauty_props, color_effect_props,
773 macro_props, depth_fusion_props, moon_capture_boost_props, features_props, color_management_props,
774 manual_focus_props, preconfig_props, camera_output_capability_props };
775 std::vector<napi_property_descriptor> camera_session_props = CameraNapiUtils::GetPropertyDescriptor(descriptors);
776 status = napi_define_class(env, CAMERA_SESSION_NAPI_CLASS_NAME, NAPI_AUTO_LENGTH,
777 CameraSessionNapiConstructor, nullptr,
778 camera_session_props.size(),
779 camera_session_props.data(), &ctorObj);
780 if (status == napi_ok) {
781 status = napi_create_reference(env, ctorObj, refCount, &sConstructor_);
782 if (status == napi_ok) {
783 status = napi_set_named_property(env, exports, CAMERA_SESSION_NAPI_CLASS_NAME, ctorObj);
784 CHECK_ERROR_RETURN_RET(status == napi_ok, exports);
785 }
786 }
787 MEDIA_ERR_LOG("Init call Failed!");
788 return nullptr;
789 }
790
791 // Constructor callback
CameraSessionNapiConstructor(napi_env env,napi_callback_info info)792 napi_value CameraSessionNapi::CameraSessionNapiConstructor(napi_env env, napi_callback_info info)
793 {
794 MEDIA_DEBUG_LOG("CameraSessionNapiConstructor is called");
795 napi_status status;
796 napi_value result = nullptr;
797 napi_value thisVar = nullptr;
798
799 napi_get_undefined(env, &result);
800 CAMERA_NAPI_GET_JS_OBJ_WITH_ZERO_ARGS(env, info, status, thisVar);
801
802 if (status == napi_ok && thisVar != nullptr) {
803 std::unique_ptr<CameraSessionNapi> obj = std::make_unique<CameraSessionNapi>();
804 if (obj != nullptr) {
805 obj->env_ = env;
806 CHECK_ERROR_RETURN_RET_LOG(sCameraSession_ == nullptr, result, "sCameraSession_ is null");
807 obj->cameraSession_ = sCameraSession_;
808 status = napi_wrap(env, thisVar, reinterpret_cast<void*>(obj.get()),
809 CameraSessionNapi::CameraSessionNapiDestructor, nullptr, nullptr);
810 if (status == napi_ok) {
811 obj.release();
812 return thisVar;
813 } else {
814 MEDIA_ERR_LOG("CameraSessionNapi Failure wrapping js to native napi");
815 }
816 }
817 }
818 MEDIA_ERR_LOG("CameraSessionNapiConstructor call Failed!");
819 return result;
820 }
821
QueryAndGetInputProperty(napi_env env,napi_value arg,const string & propertyName,napi_value & property)822 int32_t QueryAndGetInputProperty(napi_env env, napi_value arg, const string &propertyName, napi_value &property)
823 {
824 MEDIA_DEBUG_LOG("QueryAndGetInputProperty is called");
825 bool present = false;
826 int32_t retval = 0;
827 if ((napi_has_named_property(env, arg, propertyName.c_str(), &present) != napi_ok)
828 || (!present) || (napi_get_named_property(env, arg, propertyName.c_str(), &property) != napi_ok)) {
829 MEDIA_ERR_LOG("Failed to obtain property: %{public}s", propertyName.c_str());
830 retval = -1;
831 }
832
833 return retval;
834 }
835
GetPointProperties(napi_env env,napi_value pointObj,Point & point)836 int32_t GetPointProperties(napi_env env, napi_value pointObj, Point &point)
837 {
838 MEDIA_DEBUG_LOG("GetPointProperties is called");
839 napi_value propertyX = nullptr;
840 napi_value propertyY = nullptr;
841 double pointX = -1.0;
842 double pointY = -1.0;
843
844 if ((QueryAndGetInputProperty(env, pointObj, "x", propertyX) == 0) &&
845 (QueryAndGetInputProperty(env, pointObj, "y", propertyY) == 0)) {
846 if ((napi_get_value_double(env, propertyX, &pointX) != napi_ok) ||
847 (napi_get_value_double(env, propertyY, &pointY) != napi_ok)) {
848 MEDIA_ERR_LOG("GetPointProperties: get propery for x & y failed");
849 return -1;
850 } else {
851 point.x = pointX;
852 point.y = pointY;
853 }
854 } else {
855 return -1;
856 }
857
858 // Return 0 after focus point properties are successfully obtained
859 return 0;
860 }
861
GetPointNapiValue(napi_env env,Point & point)862 napi_value GetPointNapiValue(napi_env env, Point &point)
863 {
864 MEDIA_DEBUG_LOG("GetPointNapiValue is called");
865 napi_value result;
866 napi_value propValue;
867 napi_create_object(env, &result);
868 napi_create_double(env, CameraNapiUtils::FloatToDouble(point.x), &propValue);
869 napi_set_named_property(env, result, "x", propValue);
870 napi_create_double(env, CameraNapiUtils::FloatToDouble(point.y), &propValue);
871 napi_set_named_property(env, result, "y", propValue);
872 return result;
873 }
874
CreateCameraSession(napi_env env)875 napi_value CameraSessionNapi::CreateCameraSession(napi_env env)
876 {
877 MEDIA_DEBUG_LOG("CreateCameraSession is called");
878 CAMERA_SYNC_TRACE;
879 napi_status status;
880 napi_value result = nullptr;
881 napi_value constructor;
882
883 status = napi_get_reference_value(env, sConstructor_, &constructor);
884 if (status == napi_ok) {
885 int retCode = CameraManager::GetInstance()->CreateCaptureSession(sCameraSession_, SceneMode::NORMAL);
886 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
887 if (sCameraSession_ == nullptr) {
888 MEDIA_ERR_LOG("Failed to create Camera session instance");
889 napi_get_undefined(env, &result);
890 return result;
891 }
892 status = napi_new_instance(env, constructor, 0, nullptr, &result);
893 sCameraSession_ = nullptr;
894 if (status == napi_ok && result != nullptr) {
895 MEDIA_DEBUG_LOG("success to create Camera session napi instance");
896 return result;
897 } else {
898 MEDIA_ERR_LOG("Failed to create Camera session napi instance");
899 }
900 }
901 MEDIA_ERR_LOG("Failed to create Camera session napi instance last");
902 napi_get_undefined(env, &result);
903 return result;
904 }
905
BeginConfig(napi_env env,napi_callback_info info)906 napi_value CameraSessionNapi::BeginConfig(napi_env env, napi_callback_info info)
907 {
908 MEDIA_INFO_LOG("BeginConfig is called");
909 napi_status status;
910 napi_value result = nullptr;
911 size_t argc = ARGS_ZERO;
912 napi_value argv[ARGS_ZERO];
913 napi_value thisVar = nullptr;
914 napi_get_undefined(env, &result);
915 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
916
917 CameraSessionNapi* cameraSessionNapi = nullptr;
918 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
919 if (status == napi_ok && cameraSessionNapi != nullptr) {
920 int32_t ret = cameraSessionNapi->cameraSession_->BeginConfig();
921 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, ret), nullptr);
922 } else {
923 MEDIA_ERR_LOG("BeginConfig call Failed!");
924 }
925 return result;
926 }
927
CommitConfig(napi_env env,napi_callback_info info)928 napi_value CameraSessionNapi::CommitConfig(napi_env env, napi_callback_info info)
929 {
930 MEDIA_INFO_LOG("CommitConfig is called");
931 std::unique_ptr<CameraSessionAsyncContext> asyncContext = std::make_unique<CameraSessionAsyncContext>(
932 "CameraSessionNapi::CommitConfig", CameraNapiUtils::IncrementAndGet(cameraSessionTaskId));
933 auto asyncFunction = std::make_shared<CameraNapiAsyncFunction>(
934 env, "CommitConfig", asyncContext->callbackRef, asyncContext->deferred);
935 CameraNapiParamParser jsParamParser(env, info, asyncContext->objectInfo, asyncFunction);
936 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "invalid argument"), nullptr,
937 "CameraSessionNapi::CommitConfig invalid argument");
938 asyncContext->HoldNapiValue(env, jsParamParser.GetThisVar());
939 napi_status status = napi_create_async_work(
940 env, nullptr, asyncFunction->GetResourceName(),
941 [](napi_env env, void* data) {
942 MEDIA_INFO_LOG("CameraSessionNapi::CommitConfig running on worker");
943 auto context = static_cast<CameraSessionAsyncContext*>(data);
944 CHECK_ERROR_RETURN_LOG(
945 context->objectInfo == nullptr, "CameraSessionNapi::CommitConfig async info is nullptr");
946 CAMERA_START_ASYNC_TRACE(context->funcName, context->taskId);
947 CameraNapiWorkerQueueKeeper::GetInstance()->ConsumeWorkerQueueTask(context->queueTask, [&context]() {
948 context->errorCode = context->objectInfo->cameraSession_->CommitConfig();
949 context->status = context->errorCode == CameraErrorCode::SUCCESS;
950 MEDIA_INFO_LOG("CameraSessionNapi::CommitConfig errorCode:%{public}d", context->errorCode);
951 });
952 },
953 AsyncCompleteCallback, static_cast<void*>(asyncContext.get()), &asyncContext->work);
954 if (status != napi_ok) {
955 MEDIA_ERR_LOG("Failed to create napi_create_async_work for CameraSessionNapi::CommitConfig");
956 asyncFunction->Reset();
957 } else {
958 asyncContext->queueTask =
959 CameraNapiWorkerQueueKeeper::GetInstance()->AcquireWorkerQueueTask("CameraSessionNapi::CommitConfig");
960 napi_queue_async_work_with_qos(env, asyncContext->work, napi_qos_user_initiated);
961 asyncContext.release();
962 }
963 CHECK_ERROR_RETURN_RET(asyncFunction->GetAsyncFunctionType() == ASYNC_FUN_TYPE_PROMISE,
964 asyncFunction->GetPromise());
965 return CameraNapiUtils::GetUndefinedValue(env);
966 }
967
LockForControl(napi_env env,napi_callback_info info)968 napi_value CameraSessionNapi::LockForControl(napi_env env, napi_callback_info info)
969 {
970 MEDIA_DEBUG_LOG("LockForControl is called");
971 napi_status status;
972 napi_value result = nullptr;
973 size_t argc = ARGS_ZERO;
974 napi_value argv[ARGS_ZERO];
975 napi_value thisVar = nullptr;
976
977 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
978
979 napi_get_undefined(env, &result);
980 CameraSessionNapi* cameraSessionNapi = nullptr;
981 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
982 if (status == napi_ok && cameraSessionNapi != nullptr) {
983 cameraSessionNapi->cameraSession_->LockForControl();
984 } else {
985 MEDIA_ERR_LOG("LockForControl call Failed!");
986 }
987 return result;
988 }
989
UnlockForControl(napi_env env,napi_callback_info info)990 napi_value CameraSessionNapi::UnlockForControl(napi_env env, napi_callback_info info)
991 {
992 MEDIA_DEBUG_LOG("UnlockForControl is called");
993 napi_status status;
994 napi_value result = nullptr;
995 size_t argc = ARGS_ZERO;
996 napi_value argv[ARGS_ZERO];
997 napi_value thisVar = nullptr;
998
999 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1000
1001 napi_get_undefined(env, &result);
1002 CameraSessionNapi* cameraSessionNapi = nullptr;
1003 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1004 if (status == napi_ok && cameraSessionNapi != nullptr) {
1005 cameraSessionNapi->cameraSession_->UnlockForControl();
1006 } else {
1007 MEDIA_ERR_LOG("UnlockForControl call Failed!");
1008 }
1009 return result;
1010 }
1011
GetJSArgsForCameraInput(napi_env env,size_t argc,const napi_value argv[],sptr<CaptureInput> & cameraInput)1012 napi_value GetJSArgsForCameraInput(napi_env env, size_t argc, const napi_value argv[],
1013 sptr<CaptureInput> &cameraInput)
1014 {
1015 MEDIA_DEBUG_LOG("GetJSArgsForCameraInput is called");
1016 napi_value result = nullptr;
1017 CameraInputNapi* cameraInputNapiObj = nullptr;
1018
1019 NAPI_ASSERT(env, argv != nullptr, "Argument list is empty");
1020
1021 for (size_t i = PARAM0; i < argc; i++) {
1022 napi_valuetype valueType = napi_undefined;
1023 napi_typeof(env, argv[i], &valueType);
1024 if (i == PARAM0 && valueType == napi_object) {
1025 napi_unwrap(env, argv[i], reinterpret_cast<void**>(&cameraInputNapiObj));
1026 if (cameraInputNapiObj != nullptr) {
1027 cameraInput = cameraInputNapiObj->GetCameraInput();
1028 } else {
1029 NAPI_ASSERT(env, false, "type mismatch");
1030 }
1031 } else {
1032 NAPI_ASSERT(env, false, "type mismatch");
1033 }
1034 }
1035 napi_get_boolean(env, true, &result);
1036 return result;
1037 }
1038
AddInput(napi_env env,napi_callback_info info)1039 napi_value CameraSessionNapi::AddInput(napi_env env, napi_callback_info info)
1040 {
1041 MEDIA_INFO_LOG("AddInput is called");
1042 napi_status status;
1043 napi_value result = nullptr;
1044 size_t argc = ARGS_ONE;
1045 napi_value argv[ARGS_ONE] = {0};
1046 napi_value thisVar = nullptr;
1047
1048 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1049 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckInvalidArgument(env, argc, ARGS_ONE, argv, ADD_INPUT), result);
1050
1051 napi_get_undefined(env, &result);
1052 CameraSessionNapi* cameraSessionNapi = nullptr;
1053 sptr<CaptureInput> cameraInput = nullptr;
1054 GetJSArgsForCameraInput(env, argc, argv, cameraInput);
1055 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1056 if (status == napi_ok && cameraSessionNapi != nullptr) {
1057 int32_t ret = cameraSessionNapi->cameraSession_->AddInput(cameraInput);
1058 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, ret), nullptr);
1059 } else {
1060 MEDIA_ERR_LOG("AddInput call Failed!");
1061 }
1062 return result;
1063 }
1064
CanAddInput(napi_env env,napi_callback_info info)1065 napi_value CameraSessionNapi::CanAddInput(napi_env env, napi_callback_info info)
1066 {
1067 MEDIA_DEBUG_LOG("CanAddInput is called");
1068 napi_status status;
1069 napi_value result = nullptr;
1070 size_t argc = ARGS_ONE;
1071 napi_value argv[ARGS_ONE] = {0};
1072 napi_value thisVar = nullptr;
1073
1074 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1075
1076 napi_get_undefined(env, &result);
1077 CameraSessionNapi* cameraSessionNapi = nullptr;
1078 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1079 if (status == napi_ok && cameraSessionNapi != nullptr) {
1080 sptr<CaptureInput> cameraInput = nullptr;
1081 GetJSArgsForCameraInput(env, argc, argv, cameraInput);
1082 bool isSupported = cameraSessionNapi->cameraSession_->CanAddInput(cameraInput);
1083 napi_get_boolean(env, isSupported, &result);
1084 } else {
1085 MEDIA_ERR_LOG("CanAddInput call Failed!");
1086 }
1087 return result;
1088 }
1089
RemoveInput(napi_env env,napi_callback_info info)1090 napi_value CameraSessionNapi::RemoveInput(napi_env env, napi_callback_info info)
1091 {
1092 MEDIA_DEBUG_LOG("RemoveInput is called");
1093 napi_status status;
1094 napi_value result = nullptr;
1095 size_t argc = ARGS_ONE;
1096 napi_value argv[ARGS_ONE] = {0};
1097 napi_value thisVar = nullptr;
1098
1099 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1100 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckInvalidArgument(env, argc, ARGS_ONE, argv, REMOVE_INPUT), result);
1101
1102 napi_get_undefined(env, &result);
1103 CameraSessionNapi* cameraSessionNapi = nullptr;
1104 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1105 if (status == napi_ok && cameraSessionNapi != nullptr) {
1106 sptr<CaptureInput> cameraInput = nullptr;
1107 GetJSArgsForCameraInput(env, argc, argv, cameraInput);
1108 int32_t ret = cameraSessionNapi->cameraSession_->RemoveInput(cameraInput);
1109 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, ret), nullptr);
1110 return result;
1111 } else {
1112 MEDIA_ERR_LOG("RemoveInput call Failed!");
1113 }
1114 return result;
1115 }
1116
GetJSArgsForCameraOutput(napi_env env,size_t argc,const napi_value argv[],sptr<CaptureOutput> & cameraOutput)1117 napi_value CameraSessionNapi::GetJSArgsForCameraOutput(napi_env env, size_t argc, const napi_value argv[],
1118 sptr<CaptureOutput> &cameraOutput)
1119 {
1120 MEDIA_DEBUG_LOG("GetJSArgsForCameraOutput is called");
1121 napi_value result = nullptr;
1122 PreviewOutputNapi* previewOutputNapiObj = nullptr;
1123 PhotoOutputNapi* photoOutputNapiObj = nullptr;
1124 VideoOutputNapi* videoOutputNapiObj = nullptr;
1125 MetadataOutputNapi* metadataOutputNapiObj = nullptr;
1126 DepthDataOutputNapi* depthDataOutputNapiObj = nullptr;
1127
1128 NAPI_ASSERT(env, argv != nullptr, "Argument list is empty");
1129
1130 for (size_t i = PARAM0; i < argc; i++) {
1131 napi_valuetype valueType = napi_undefined;
1132 napi_typeof(env, argv[i], &valueType);
1133
1134 if (i == PARAM0 && valueType == napi_object) {
1135 if (PreviewOutputNapi::IsPreviewOutput(env, argv[i])) {
1136 MEDIA_DEBUG_LOG("preview output adding..");
1137 napi_unwrap(env, argv[i], reinterpret_cast<void**>(&previewOutputNapiObj));
1138 cameraOutput = previewOutputNapiObj->GetPreviewOutput();
1139 } else if (PhotoOutputNapi::IsPhotoOutput(env, argv[i])) {
1140 MEDIA_DEBUG_LOG("photo output adding..");
1141 napi_unwrap(env, argv[i], reinterpret_cast<void**>(&photoOutputNapiObj));
1142 cameraOutput = photoOutputNapiObj->GetPhotoOutput();
1143 } else if (VideoOutputNapi::IsVideoOutput(env, argv[i])) {
1144 MEDIA_DEBUG_LOG("video output adding..");
1145 napi_unwrap(env, argv[i], reinterpret_cast<void**>(&videoOutputNapiObj));
1146 cameraOutput = videoOutputNapiObj->GetVideoOutput();
1147 } else if (MetadataOutputNapi::IsMetadataOutput(env, argv[i])) {
1148 MEDIA_DEBUG_LOG("metadata output adding..");
1149 napi_unwrap(env, argv[i], reinterpret_cast<void**>(&metadataOutputNapiObj));
1150 cameraOutput = metadataOutputNapiObj->GetMetadataOutput();
1151 } else if (DepthDataOutputNapi::IsDepthDataOutput(env, argv[i])) {
1152 MEDIA_DEBUG_LOG("depth data output adding..");
1153 napi_unwrap(env, argv[i], reinterpret_cast<void**>(&depthDataOutputNapiObj));
1154 cameraOutput = depthDataOutputNapiObj->GetDepthDataOutput();
1155 } else {
1156 MEDIA_INFO_LOG("invalid output ..");
1157 NAPI_ASSERT(env, false, "type mismatch");
1158 }
1159 } else {
1160 NAPI_ASSERT(env, false, "type mismatch");
1161 }
1162 }
1163 // Return true napi_value if params are successfully obtained
1164 napi_get_boolean(env, true, &result);
1165 return result;
1166 }
1167
AddOutput(napi_env env,napi_callback_info info)1168 napi_value CameraSessionNapi::AddOutput(napi_env env, napi_callback_info info)
1169 {
1170 MEDIA_INFO_LOG("AddOutput is called");
1171 napi_status status;
1172 napi_value result = nullptr;
1173 size_t argc = ARGS_ONE;
1174 napi_value argv[ARGS_ONE] = {0};
1175 napi_value thisVar = nullptr;
1176
1177 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1178 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckInvalidArgument(env, argc, ARGS_ONE, argv, ADD_OUTPUT), result);
1179
1180 napi_get_undefined(env, &result);
1181 CameraSessionNapi* cameraSessionNapi = nullptr;
1182 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1183 if (status == napi_ok && cameraSessionNapi != nullptr) {
1184 sptr<CaptureOutput> cameraOutput = nullptr;
1185 result = GetJSArgsForCameraOutput(env, argc, argv, cameraOutput);
1186 int32_t ret = cameraSessionNapi->cameraSession_->AddOutput(cameraOutput);
1187 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, ret), nullptr);
1188 } else {
1189 MEDIA_ERR_LOG("AddOutput call Failed!");
1190 }
1191 return result;
1192 }
1193
CanAddOutput(napi_env env,napi_callback_info info)1194 napi_value CameraSessionNapi::CanAddOutput(napi_env env, napi_callback_info info)
1195 {
1196 MEDIA_DEBUG_LOG("CanAddOutput is called");
1197 napi_status status;
1198 napi_value result = nullptr;
1199 size_t argc = ARGS_ONE;
1200 napi_value argv[ARGS_ONE] = {0};
1201 napi_value thisVar = nullptr;
1202
1203 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1204
1205 napi_get_undefined(env, &result);
1206 CameraSessionNapi* cameraSessionNapi = nullptr;
1207 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1208 if (status == napi_ok && cameraSessionNapi != nullptr) {
1209 sptr<CaptureOutput> cameraOutput = nullptr;
1210 result = GetJSArgsForCameraOutput(env, argc, argv, cameraOutput);
1211 bool isSupported = cameraSessionNapi->cameraSession_->CanAddOutput(cameraOutput);
1212 napi_get_boolean(env, isSupported, &result);
1213 } else {
1214 MEDIA_ERR_LOG("CanAddOutput call Failed!");
1215 }
1216 return result;
1217 }
1218
RemoveOutput(napi_env env,napi_callback_info info)1219 napi_value CameraSessionNapi::RemoveOutput(napi_env env, napi_callback_info info)
1220 {
1221 MEDIA_INFO_LOG("RemoveOutput is called");
1222 napi_status status;
1223 napi_value result = nullptr;
1224 size_t argc = ARGS_ONE;
1225 napi_value argv[ARGS_ONE] = {0};
1226 napi_value thisVar = nullptr;
1227
1228 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1229 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckInvalidArgument(env, argc, ARGS_ONE, argv, REMOVE_OUTPUT), result);
1230
1231 napi_get_undefined(env, &result);
1232 CameraSessionNapi* cameraSessionNapi = nullptr;
1233 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1234 if (status == napi_ok && cameraSessionNapi != nullptr) {
1235 sptr<CaptureOutput> cameraOutput = nullptr;
1236 result = GetJSArgsForCameraOutput(env, argc, argv, cameraOutput);
1237 int32_t ret = cameraSessionNapi->cameraSession_->RemoveOutput(cameraOutput);
1238 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, ret), nullptr);
1239 } else {
1240 MEDIA_ERR_LOG("RemoveOutput call Failed!");
1241 }
1242 return result;
1243 }
1244
Start(napi_env env,napi_callback_info info)1245 napi_value CameraSessionNapi::Start(napi_env env, napi_callback_info info)
1246 {
1247 MEDIA_INFO_LOG("Start is called");
1248 std::unique_ptr<CameraSessionAsyncContext> asyncContext = std::make_unique<CameraSessionAsyncContext>(
1249 "CameraSessionNapi::Start", CameraNapiUtils::IncrementAndGet(cameraSessionTaskId));
1250 auto asyncFunction =
1251 std::make_shared<CameraNapiAsyncFunction>(env, "Start", asyncContext->callbackRef, asyncContext->deferred);
1252 CameraNapiParamParser jsParamParser(env, info, asyncContext->objectInfo, asyncFunction);
1253 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "invalid argument"),
1254 nullptr, "CameraSessionNapi::Start invalid argument");
1255 asyncContext->HoldNapiValue(env, jsParamParser.GetThisVar());
1256 napi_status status = napi_create_async_work(
1257 env, nullptr, asyncFunction->GetResourceName(),
1258 [](napi_env env, void* data) {
1259 MEDIA_INFO_LOG("CameraSessionNapi::Start running on worker");
1260 auto context = static_cast<CameraSessionAsyncContext*>(data);
1261 CHECK_ERROR_RETURN_LOG(context->objectInfo == nullptr, "CameraSessionNapi::Start async info is nullptr");
1262 CAMERA_START_ASYNC_TRACE(context->funcName, context->taskId);
1263 CameraNapiWorkerQueueKeeper::GetInstance()->ConsumeWorkerQueueTask(context->queueTask, [&context]() {
1264 context->errorCode = context->objectInfo->cameraSession_->Start();
1265 context->status = context->errorCode == CameraErrorCode::SUCCESS;
1266 MEDIA_INFO_LOG("CameraSessionNapi::Start errorCode:%{public}d", context->errorCode);
1267 });
1268 },
1269 AsyncCompleteCallback, static_cast<void*>(asyncContext.get()), &asyncContext->work);
1270 if (status != napi_ok) {
1271 MEDIA_ERR_LOG("Failed to create napi_create_async_work for CameraSessionNapi::Start");
1272 asyncFunction->Reset();
1273 } else {
1274 asyncContext->queueTask =
1275 CameraNapiWorkerQueueKeeper::GetInstance()->AcquireWorkerQueueTask("CameraSessionNapi::Start");
1276 napi_queue_async_work_with_qos(env, asyncContext->work, napi_qos_user_initiated);
1277 asyncContext.release();
1278 }
1279 CHECK_ERROR_RETURN_RET(asyncFunction->GetAsyncFunctionType() == ASYNC_FUN_TYPE_PROMISE,
1280 asyncFunction->GetPromise());
1281 return CameraNapiUtils::GetUndefinedValue(env);
1282 }
1283
Stop(napi_env env,napi_callback_info info)1284 napi_value CameraSessionNapi::Stop(napi_env env, napi_callback_info info)
1285 {
1286 MEDIA_INFO_LOG("Stop is called");
1287 std::unique_ptr<CameraSessionAsyncContext> asyncContext = std::make_unique<CameraSessionAsyncContext>(
1288 "CameraSessionNapi::Stop", CameraNapiUtils::IncrementAndGet(cameraSessionTaskId));
1289 auto asyncFunction =
1290 std::make_shared<CameraNapiAsyncFunction>(env, "Stop", asyncContext->callbackRef, asyncContext->deferred);
1291 CameraNapiParamParser jsParamParser(env, info, asyncContext->objectInfo, asyncFunction);
1292 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "invalid argument"), nullptr,
1293 "CameraSessionNapi::Stop invalid argument");
1294 asyncContext->HoldNapiValue(env, jsParamParser.GetThisVar());
1295 napi_status status = napi_create_async_work(
1296 env, nullptr, asyncFunction->GetResourceName(),
1297 [](napi_env env, void* data) {
1298 MEDIA_INFO_LOG("CameraSessionNapi::Stop running on worker");
1299 auto context = static_cast<CameraSessionAsyncContext*>(data);
1300 CHECK_ERROR_RETURN_LOG(context->objectInfo == nullptr, "CameraSessionNapi::Stop async info is nullptr");
1301 CAMERA_START_ASYNC_TRACE(context->funcName, context->taskId);
1302 CameraNapiWorkerQueueKeeper::GetInstance()->ConsumeWorkerQueueTask(context->queueTask, [&context]() {
1303 context->errorCode = context->objectInfo->cameraSession_->Stop();
1304 context->status = context->errorCode == CameraErrorCode::SUCCESS;
1305 MEDIA_INFO_LOG("CameraSessionNapi::Stop errorCode:%{public}d", context->errorCode);
1306 });
1307 },
1308 AsyncCompleteCallback, static_cast<void*>(asyncContext.get()), &asyncContext->work);
1309 if (status != napi_ok) {
1310 MEDIA_ERR_LOG("Failed to create napi_create_async_work for CameraSessionNapi::Stop");
1311 asyncFunction->Reset();
1312 } else {
1313 asyncContext->queueTask =
1314 CameraNapiWorkerQueueKeeper::GetInstance()->AcquireWorkerQueueTask("CameraSessionNapi::Stop");
1315 napi_queue_async_work_with_qos(env, asyncContext->work, napi_qos_user_initiated);
1316 asyncContext.release();
1317 }
1318 CHECK_ERROR_RETURN_RET(asyncFunction->GetAsyncFunctionType() == ASYNC_FUN_TYPE_PROMISE,
1319 asyncFunction->GetPromise());
1320 return CameraNapiUtils::GetUndefinedValue(env);
1321 }
1322
Release(napi_env env,napi_callback_info info)1323 napi_value CameraSessionNapi::Release(napi_env env, napi_callback_info info)
1324 {
1325 MEDIA_INFO_LOG("Release is called");
1326 std::unique_ptr<CameraSessionAsyncContext> asyncContext = std::make_unique<CameraSessionAsyncContext>(
1327 "CameraSessionNapi::Release", CameraNapiUtils::IncrementAndGet(cameraSessionTaskId));
1328 auto asyncFunction =
1329 std::make_shared<CameraNapiAsyncFunction>(env, "Release", asyncContext->callbackRef, asyncContext->deferred);
1330 CameraNapiParamParser jsParamParser(env, info, asyncContext->objectInfo, asyncFunction);
1331 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "invalid argument"), nullptr,
1332 "CameraSessionNapi::Release invalid argument");
1333 asyncContext->HoldNapiValue(env, jsParamParser.GetThisVar());
1334 napi_status status = napi_create_async_work(
1335 env, nullptr, asyncFunction->GetResourceName(),
1336 [](napi_env env, void* data) {
1337 MEDIA_INFO_LOG("CameraSessionNapi::Release running on worker");
1338 auto context = static_cast<CameraSessionAsyncContext*>(data);
1339 CHECK_ERROR_RETURN_LOG(context->objectInfo == nullptr, "CameraSessionNapi::Release async info is nullptr");
1340 CAMERA_START_ASYNC_TRACE(context->funcName, context->taskId);
1341 CameraNapiWorkerQueueKeeper::GetInstance()->ConsumeWorkerQueueTask(context->queueTask, [&context]() {
1342 context->errorCode = context->objectInfo->cameraSession_->Release();
1343 context->status = context->errorCode == CameraErrorCode::SUCCESS;
1344 MEDIA_INFO_LOG("CameraSessionNapi::Release errorCode:%{public}d", context->errorCode);
1345 });
1346 },
1347 AsyncCompleteCallback, static_cast<void*>(asyncContext.get()), &asyncContext->work);
1348 if (status != napi_ok) {
1349 MEDIA_ERR_LOG("Failed to create napi_create_async_work for CameraSessionNapi::Release");
1350 asyncFunction->Reset();
1351 } else {
1352 asyncContext->queueTask =
1353 CameraNapiWorkerQueueKeeper::GetInstance()->AcquireWorkerQueueTask("CameraSessionNapi::Release");
1354 napi_queue_async_work_with_qos(env, asyncContext->work, napi_qos_user_initiated);
1355 asyncContext.release();
1356 }
1357 CHECK_ERROR_RETURN_RET(asyncFunction->GetAsyncFunctionType() == ASYNC_FUN_TYPE_PROMISE,
1358 asyncFunction->GetPromise());
1359 return CameraNapiUtils::GetUndefinedValue(env);
1360 }
1361
IsVideoStabilizationModeSupported(napi_env env,napi_callback_info info)1362 napi_value CameraSessionNapi::IsVideoStabilizationModeSupported(napi_env env, napi_callback_info info)
1363 {
1364 MEDIA_DEBUG_LOG("IsVideoStabilizationModeSupported is called");
1365 napi_status status;
1366 napi_value result = nullptr;
1367 size_t argc = ARGS_ONE;
1368 napi_value argv[ARGS_ONE] = {0};
1369 napi_value thisVar = nullptr;
1370
1371 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1372
1373 napi_get_undefined(env, &result);
1374 CameraSessionNapi* cameraSessionNapi = nullptr;
1375 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1376 if (status == napi_ok && cameraSessionNapi != nullptr) {
1377 int32_t value;
1378 napi_get_value_int32(env, argv[PARAM0], &value);
1379 VideoStabilizationMode videoStabilizationMode = (VideoStabilizationMode)value;
1380 bool isSupported;
1381 int32_t retCode = cameraSessionNapi->cameraSession_->
1382 IsVideoStabilizationModeSupported(videoStabilizationMode, isSupported);
1383 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
1384 napi_get_boolean(env, isSupported, &result);
1385 } else {
1386 MEDIA_ERR_LOG("IsVideoStabilizationModeSupported call Failed!");
1387 }
1388 return result;
1389 }
1390
GetActiveVideoStabilizationMode(napi_env env,napi_callback_info info)1391 napi_value CameraSessionNapi::GetActiveVideoStabilizationMode(napi_env env, napi_callback_info info)
1392 {
1393 MEDIA_DEBUG_LOG("GetActiveVideoStabilizationMode is called");
1394 napi_status status;
1395 napi_value result = nullptr;
1396 size_t argc = ARGS_ZERO;
1397 napi_value argv[ARGS_ZERO];
1398 napi_value thisVar = nullptr;
1399
1400 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1401
1402 napi_get_undefined(env, &result);
1403 CameraSessionNapi* cameraSessionNapi = nullptr;
1404 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1405 if (status == napi_ok && cameraSessionNapi != nullptr) {
1406 VideoStabilizationMode videoStabilizationMode;
1407 int32_t retCode = cameraSessionNapi->cameraSession_->
1408 GetActiveVideoStabilizationMode(videoStabilizationMode);
1409 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
1410 napi_create_int32(env, videoStabilizationMode, &result);
1411 } else {
1412 MEDIA_ERR_LOG("GetActiveVideoStabilizationMode call Failed!");
1413 }
1414 return result;
1415 }
1416
SetVideoStabilizationMode(napi_env env,napi_callback_info info)1417 napi_value CameraSessionNapi::SetVideoStabilizationMode(napi_env env, napi_callback_info info)
1418 {
1419 MEDIA_DEBUG_LOG("SetVideoStabilizationMode is called");
1420 napi_status status;
1421 napi_value result = nullptr;
1422 size_t argc = ARGS_ONE;
1423 napi_value argv[ARGS_ONE] = {0};
1424 napi_value thisVar = nullptr;
1425
1426 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1427
1428 napi_get_undefined(env, &result);
1429 CameraSessionNapi* cameraSessionNapi = nullptr;
1430 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1431 if (status == napi_ok && cameraSessionNapi != nullptr) {
1432 int32_t value;
1433 napi_get_value_int32(env, argv[PARAM0], &value);
1434 VideoStabilizationMode videoStabilizationMode = (VideoStabilizationMode)value;
1435 int retCode = cameraSessionNapi->cameraSession_->SetVideoStabilizationMode(videoStabilizationMode);
1436 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
1437 } else {
1438 MEDIA_ERR_LOG("SetVideoStabilizationMode call Failed!");
1439 }
1440 return result;
1441 }
1442
HasFlash(napi_env env,napi_callback_info info)1443 napi_value CameraSessionNapi::HasFlash(napi_env env, napi_callback_info info)
1444 {
1445 MEDIA_DEBUG_LOG("HasFlash is called");
1446 napi_status status;
1447 napi_value result = nullptr;
1448 size_t argc = ARGS_ZERO;
1449 napi_value argv[ARGS_ZERO];
1450 napi_value thisVar = nullptr;
1451
1452 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1453
1454 napi_get_undefined(env, &result);
1455 CameraSessionNapi* cameraSessionNapi = nullptr;
1456 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1457 if (status == napi_ok && cameraSessionNapi != nullptr) {
1458 bool isSupported = false;
1459 int retCode = cameraSessionNapi->cameraSession_->HasFlash(isSupported);
1460 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
1461 napi_get_boolean(env, isSupported, &result);
1462 } else {
1463 MEDIA_ERR_LOG("HasFlash call Failed!");
1464 }
1465 return result;
1466 }
1467
IsFlashModeSupported(napi_env env,napi_callback_info info)1468 napi_value CameraSessionNapi::IsFlashModeSupported(napi_env env, napi_callback_info info)
1469 {
1470 MEDIA_DEBUG_LOG("IsFlashModeSupported is called");
1471 napi_status status;
1472 napi_value result = nullptr;
1473 size_t argc = ARGS_ONE;
1474 napi_value argv[ARGS_ONE] = {0};
1475 napi_value thisVar = nullptr;
1476
1477 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1478
1479 napi_get_undefined(env, &result);
1480 CameraSessionNapi* cameraSessionNapi = nullptr;
1481 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1482 if (status == napi_ok && cameraSessionNapi != nullptr) {
1483 int32_t value;
1484 napi_get_value_int32(env, argv[PARAM0], &value);
1485 FlashMode flashMode = (FlashMode)value;
1486 bool isSupported;
1487 int32_t retCode = cameraSessionNapi->cameraSession_->IsFlashModeSupported(flashMode, isSupported);
1488 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
1489 napi_get_boolean(env, isSupported, &result);
1490 } else {
1491 MEDIA_ERR_LOG("IsFlashModeSupported call Failed!");
1492 }
1493 return result;
1494 }
1495
SetFlashMode(napi_env env,napi_callback_info info)1496 napi_value CameraSessionNapi::SetFlashMode(napi_env env, napi_callback_info info)
1497 {
1498 MEDIA_DEBUG_LOG("SetFlashMode is called");
1499 CAMERA_SYNC_TRACE;
1500 napi_status status;
1501 napi_value result = nullptr;
1502 size_t argc = ARGS_ONE;
1503 napi_value argv[ARGS_ONE] = {0};
1504 napi_value thisVar = nullptr;
1505
1506 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1507
1508 napi_get_undefined(env, &result);
1509 CameraSessionNapi* cameraSessionNapi = nullptr;
1510 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1511 if (status == napi_ok && cameraSessionNapi != nullptr) {
1512 int32_t value;
1513 napi_get_value_int32(env, argv[PARAM0], &value);
1514 MEDIA_INFO_LOG("CameraSessionNapi::SetFlashMode mode:%{public}d", value);
1515 FlashMode flashMode = (FlashMode)value;
1516 cameraSessionNapi->cameraSession_->LockForControl();
1517 int retCode = cameraSessionNapi->cameraSession_->SetFlashMode(flashMode);
1518 cameraSessionNapi->cameraSession_->UnlockForControl();
1519 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
1520 } else {
1521 MEDIA_ERR_LOG("SetFlashMode call Failed!");
1522 }
1523 return result;
1524 }
1525
GetFlashMode(napi_env env,napi_callback_info info)1526 napi_value CameraSessionNapi::GetFlashMode(napi_env env, napi_callback_info info)
1527 {
1528 MEDIA_DEBUG_LOG("GetFlashMode is called");
1529 napi_status status;
1530 napi_value result = nullptr;
1531 size_t argc = ARGS_ZERO;
1532 napi_value argv[ARGS_ZERO];
1533 napi_value thisVar = nullptr;
1534
1535 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1536 napi_get_undefined(env, &result);
1537 CameraSessionNapi* cameraSessionNapi = nullptr;
1538 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1539 if (status == napi_ok && cameraSessionNapi != nullptr) {
1540 FlashMode flashMode;
1541 int32_t retCode = cameraSessionNapi->cameraSession_->GetFlashMode(flashMode);
1542 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
1543 napi_create_int32(env, flashMode, &result);
1544 } else {
1545 MEDIA_ERR_LOG("GetFlashMode call Failed!");
1546 }
1547 return result;
1548 }
1549
IsLcdFlashSupported(napi_env env,napi_callback_info info)1550 napi_value CameraSessionNapi::IsLcdFlashSupported(napi_env env, napi_callback_info info)
1551 {
1552 MEDIA_DEBUG_LOG("IsLcdFlashSupported is called");
1553 CAMERA_SYNC_TRACE;
1554 napi_value result = CameraNapiUtils::GetUndefinedValue(env);
1555 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), result,
1556 "SystemApi isLcdFlashSupported is called!");
1557 CameraSessionNapi* cameraSessionNapi = nullptr;
1558 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi);
1559 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"),
1560 result, "IsLcdFlashSupported parse parameter occur error");
1561 if (cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
1562 bool isSupported = cameraSessionNapi->cameraSession_->IsLcdFlashSupported();
1563 napi_get_boolean(env, isSupported, &result);
1564 } else {
1565 MEDIA_ERR_LOG("IsLcdFlashSupported call Failed!");
1566 }
1567 return result;
1568 }
1569
EnableLcdFlash(napi_env env,napi_callback_info info)1570 napi_value CameraSessionNapi::EnableLcdFlash(napi_env env, napi_callback_info info)
1571 {
1572 MEDIA_DEBUG_LOG("EnableLcdFlash is called");
1573 napi_value result = CameraNapiUtils::GetUndefinedValue(env);
1574 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), result, "SystemApi enableLcdFlash is called!");
1575 bool isEnable;
1576 CameraSessionNapi* cameraSessionNapi = nullptr;
1577 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi, isEnable);
1578 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"), result,
1579 "EnableLcdFlash parse parameter occur error");
1580
1581 if (cameraSessionNapi->cameraSession_ != nullptr) {
1582 MEDIA_INFO_LOG("EnableLcdFlash:%{public}d", isEnable);
1583 cameraSessionNapi->cameraSession_->LockForControl();
1584 int32_t retCode = cameraSessionNapi->cameraSession_->EnableLcdFlash(isEnable);
1585 cameraSessionNapi->cameraSession_->UnlockForControl();
1586 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiUtils::CheckError(env, retCode), result,
1587 "EnableLcdFlash fail %{public}d", retCode);
1588 } else {
1589 MEDIA_ERR_LOG("EnableLcdFlash get native object fail");
1590 CameraNapiUtils::ThrowError(env, INVALID_ARGUMENT, "get native object fail");
1591 return result;
1592 }
1593 return result;
1594 }
1595
IsExposureModeSupported(napi_env env,napi_callback_info info)1596 napi_value CameraSessionNapi::IsExposureModeSupported(napi_env env, napi_callback_info info)
1597 {
1598 MEDIA_DEBUG_LOG("IsExposureModeSupported is called");
1599 napi_status status;
1600 napi_value result = nullptr;
1601 size_t argc = ARGS_ONE;
1602 napi_value argv[ARGS_ONE] = {0};
1603 napi_value thisVar = nullptr;
1604
1605 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1606
1607 napi_get_undefined(env, &result);
1608 CameraSessionNapi* cameraSessionNapi = nullptr;
1609 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1610 if (status == napi_ok && cameraSessionNapi != nullptr) {
1611 int32_t value;
1612 napi_get_value_int32(env, argv[PARAM0], &value);
1613 ExposureMode exposureMode = (ExposureMode)value;
1614 bool isSupported;
1615 int32_t retCode = cameraSessionNapi->cameraSession_->
1616 IsExposureModeSupported(static_cast<ExposureMode>(exposureMode), isSupported);
1617 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
1618 napi_get_boolean(env, isSupported, &result);
1619 } else {
1620 MEDIA_ERR_LOG("IsExposureModeSupported call Failed!");
1621 }
1622 return result;
1623 }
1624
GetExposureMode(napi_env env,napi_callback_info info)1625 napi_value CameraSessionNapi::GetExposureMode(napi_env env, napi_callback_info info)
1626 {
1627 MEDIA_DEBUG_LOG("GetExposureMode is called");
1628 napi_status status;
1629 napi_value result = nullptr;
1630 size_t argc = ARGS_ZERO;
1631 napi_value argv[ARGS_ZERO];
1632 napi_value thisVar = nullptr;
1633
1634 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1635
1636 napi_get_undefined(env, &result);
1637 CameraSessionNapi* cameraSessionNapi = nullptr;
1638 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1639 if (status == napi_ok && cameraSessionNapi != nullptr) {
1640 ExposureMode exposureMode;
1641 int32_t retCode = cameraSessionNapi->cameraSession_->GetExposureMode(exposureMode);
1642 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
1643 napi_create_int32(env, exposureMode, &result);
1644 } else {
1645 MEDIA_ERR_LOG("GetExposureMode call Failed!");
1646 }
1647 return result;
1648 }
1649
SetExposureMode(napi_env env,napi_callback_info info)1650 napi_value CameraSessionNapi::SetExposureMode(napi_env env, napi_callback_info info)
1651 {
1652 MEDIA_DEBUG_LOG("SetExposureMode is called");
1653 CAMERA_SYNC_TRACE;
1654 napi_status status;
1655 napi_value result = nullptr;
1656 size_t argc = ARGS_ONE;
1657 napi_value argv[ARGS_ONE] = {0};
1658 napi_value thisVar = nullptr;
1659
1660 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1661
1662 napi_get_undefined(env, &result);
1663 CameraSessionNapi* cameraSessionNapi = nullptr;
1664 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1665 if (status == napi_ok && cameraSessionNapi != nullptr) {
1666 int32_t value;
1667 napi_get_value_int32(env, argv[PARAM0], &value);
1668 ExposureMode exposureMode = (ExposureMode)value;
1669 cameraSessionNapi->cameraSession_->LockForControl();
1670 int retCode = cameraSessionNapi->cameraSession_->SetExposureMode(exposureMode);
1671 cameraSessionNapi->cameraSession_->UnlockForControl();
1672 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
1673 } else {
1674 MEDIA_ERR_LOG("SetExposureMode call Failed!");
1675 }
1676 return result;
1677 }
1678
SetMeteringPoint(napi_env env,napi_callback_info info)1679 napi_value CameraSessionNapi::SetMeteringPoint(napi_env env, napi_callback_info info)
1680 {
1681 MEDIA_DEBUG_LOG("SetMeteringPoint is called");
1682 CAMERA_SYNC_TRACE;
1683 napi_status status;
1684 napi_value result = nullptr;
1685 size_t argc = ARGS_ONE;
1686 napi_value argv[ARGS_ONE] = {0};
1687 napi_value thisVar = nullptr;
1688
1689 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1690
1691 napi_get_undefined(env, &result);
1692 CameraSessionNapi* cameraSessionNapi = nullptr;
1693 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1694 if (status == napi_ok && cameraSessionNapi != nullptr) {
1695 Point exposurePoint;
1696 if (GetPointProperties(env, argv[PARAM0], exposurePoint) == 0) {
1697 cameraSessionNapi->cameraSession_->LockForControl();
1698 int32_t retCode = cameraSessionNapi->cameraSession_->SetMeteringPoint(exposurePoint);
1699 cameraSessionNapi->cameraSession_->UnlockForControl();
1700 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
1701 } else {
1702 MEDIA_ERR_LOG("get point failed");
1703 }
1704 } else {
1705 MEDIA_ERR_LOG("SetMeteringPoint call Failed!");
1706 }
1707 return result;
1708 }
1709
GetMeteringPoint(napi_env env,napi_callback_info info)1710 napi_value CameraSessionNapi::GetMeteringPoint(napi_env env, napi_callback_info info)
1711 {
1712 MEDIA_DEBUG_LOG("GetMeteringPoint is called");
1713 napi_status status;
1714 napi_value result = nullptr;
1715 size_t argc = ARGS_ZERO;
1716 napi_value argv[ARGS_ZERO];
1717 napi_value thisVar = nullptr;
1718
1719 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1720 napi_get_undefined(env, &result);
1721 CameraSessionNapi* cameraSessionNapi = nullptr;
1722 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1723 if (status == napi_ok && cameraSessionNapi != nullptr) {
1724 Point exposurePoint;
1725 int32_t retCode = cameraSessionNapi->cameraSession_->GetMeteringPoint(exposurePoint);
1726 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
1727 return GetPointNapiValue(env, exposurePoint);
1728 } else {
1729 MEDIA_ERR_LOG("GetMeteringPoint call Failed!");
1730 }
1731 return result;
1732 }
1733
GetExposureBiasRange(napi_env env,napi_callback_info info)1734 napi_value CameraSessionNapi::GetExposureBiasRange(napi_env env, napi_callback_info info)
1735 {
1736 MEDIA_DEBUG_LOG("GetExposureBiasRange is called");
1737 napi_status status;
1738 napi_value result = nullptr;
1739 size_t argc = ARGS_ZERO;
1740 napi_value argv[ARGS_ZERO];
1741 napi_value thisVar = nullptr;
1742
1743 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1744
1745 napi_get_undefined(env, &result);
1746 CameraSessionNapi* cameraSessionNapi = nullptr;
1747 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1748 if (status == napi_ok && cameraSessionNapi != nullptr) {
1749 std::vector<float> vecExposureBiasList;
1750 int32_t retCode = cameraSessionNapi->cameraSession_->GetExposureBiasRange(vecExposureBiasList);
1751 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
1752 CHECK_ERROR_RETURN_RET(vecExposureBiasList.empty() || napi_create_array(env, &result) != napi_ok, result);
1753 size_t len = vecExposureBiasList.size();
1754 for (size_t i = 0; i < len; i++) {
1755 float exposureBias = vecExposureBiasList[i];
1756 MEDIA_DEBUG_LOG("EXPOSURE_BIAS_RANGE : exposureBias = %{public}f", vecExposureBiasList[i]);
1757 napi_value value;
1758 napi_create_double(env, CameraNapiUtils::FloatToDouble(exposureBias), &value);
1759 napi_set_element(env, result, i, value);
1760 }
1761 MEDIA_DEBUG_LOG("EXPOSURE_BIAS_RANGE ExposureBiasList size : %{public}zu", vecExposureBiasList.size());
1762 } else {
1763 MEDIA_ERR_LOG("GetExposureBiasRange call Failed!");
1764 }
1765 return result;
1766 }
1767
GetExposureValue(napi_env env,napi_callback_info info)1768 napi_value CameraSessionNapi::GetExposureValue(napi_env env, napi_callback_info info)
1769 {
1770 MEDIA_DEBUG_LOG("GetExposureValue is called");
1771 napi_status status;
1772 napi_value result = nullptr;
1773 size_t argc = ARGS_ZERO;
1774 napi_value argv[ARGS_ZERO];
1775 napi_value thisVar = nullptr;
1776
1777 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1778
1779 napi_get_undefined(env, &result);
1780 CameraSessionNapi* cameraSessionNapi = nullptr;
1781 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1782 if (status == napi_ok && cameraSessionNapi!= nullptr) {
1783 float exposureValue;
1784 int32_t retCode = cameraSessionNapi->cameraSession_->GetExposureValue(exposureValue);
1785 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
1786 napi_create_double(env, CameraNapiUtils::FloatToDouble(exposureValue), &result);
1787 } else {
1788 MEDIA_ERR_LOG("GetExposureValue call Failed!");
1789 }
1790 return result;
1791 }
1792
SetExposureBias(napi_env env,napi_callback_info info)1793 napi_value CameraSessionNapi::SetExposureBias(napi_env env, napi_callback_info info)
1794 {
1795 MEDIA_DEBUG_LOG("SetExposureBias is called");
1796 CAMERA_SYNC_TRACE;
1797 napi_status status;
1798 napi_value result = nullptr;
1799 size_t argc = ARGS_ONE;
1800 napi_value argv[ARGS_ONE] = {0};
1801 napi_value thisVar = nullptr;
1802
1803 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1804
1805 napi_get_undefined(env, &result);
1806 CameraSessionNapi* cameraSessionNapi = nullptr;
1807 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1808 if (status == napi_ok && cameraSessionNapi != nullptr) {
1809 double exposureValue;
1810 napi_get_value_double(env, argv[PARAM0], &exposureValue);
1811 cameraSessionNapi->cameraSession_->LockForControl();
1812 int32_t retCode = cameraSessionNapi->cameraSession_->SetExposureBias((float)exposureValue);
1813 cameraSessionNapi->cameraSession_->UnlockForControl();
1814 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
1815 } else {
1816 MEDIA_ERR_LOG("SetExposureBias call Failed!");
1817 }
1818 return result;
1819 }
1820
IsFocusModeSupported(napi_env env,napi_callback_info info)1821 napi_value CameraSessionNapi::IsFocusModeSupported(napi_env env, napi_callback_info info)
1822 {
1823 MEDIA_DEBUG_LOG("IsFocusModeSupported is called");
1824 napi_status status;
1825 napi_value result = nullptr;
1826 size_t argc = ARGS_ONE;
1827 napi_value argv[ARGS_ONE] = {0};
1828 napi_value thisVar = nullptr;
1829
1830 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1831
1832 napi_get_undefined(env, &result);
1833 CameraSessionNapi* cameraSessionNapi = nullptr;
1834 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1835 if (status == napi_ok && cameraSessionNapi != nullptr) {
1836 int32_t value;
1837 napi_get_value_int32(env, argv[PARAM0], &value);
1838 FocusMode focusMode = (FocusMode)value;
1839 bool isSupported;
1840 int32_t retCode = cameraSessionNapi->cameraSession_->IsFocusModeSupported(focusMode,
1841 isSupported);
1842 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
1843 napi_get_boolean(env, isSupported, &result);
1844 } else {
1845 MEDIA_ERR_LOG("IsFocusModeSupported call Failed!");
1846 }
1847 return result;
1848 }
1849
GetFocalLength(napi_env env,napi_callback_info info)1850 napi_value CameraSessionNapi::GetFocalLength(napi_env env, napi_callback_info info)
1851 {
1852 MEDIA_DEBUG_LOG("GetFocalLength is called");
1853 napi_status status;
1854 napi_value result = nullptr;
1855 size_t argc = ARGS_ZERO;
1856 napi_value argv[ARGS_ZERO];
1857 napi_value thisVar = nullptr;
1858
1859 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1860
1861 napi_get_undefined(env, &result);
1862 CameraSessionNapi* cameraSessionNapi = nullptr;
1863 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1864 if (status == napi_ok && cameraSessionNapi != nullptr) {
1865 float focalLength;
1866 int32_t retCode = cameraSessionNapi->cameraSession_->GetFocalLength(focalLength);
1867 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
1868 napi_create_double(env, CameraNapiUtils::FloatToDouble(focalLength), &result);
1869 } else {
1870 MEDIA_ERR_LOG("GetFocalLength call Failed!");
1871 }
1872 return result;
1873 }
1874
SetFocusPoint(napi_env env,napi_callback_info info)1875 napi_value CameraSessionNapi::SetFocusPoint(napi_env env, napi_callback_info info)
1876 {
1877 MEDIA_DEBUG_LOG("SetFocusPoint is called");
1878 CAMERA_SYNC_TRACE;
1879 napi_status status;
1880 napi_value result = nullptr;
1881 size_t argc = ARGS_ONE;
1882 napi_value argv[ARGS_ONE] = {0};
1883 napi_value thisVar = nullptr;
1884
1885 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1886
1887 napi_get_undefined(env, &result);
1888 CameraSessionNapi* cameraSessionNapi = nullptr;
1889 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1890 if (status == napi_ok && cameraSessionNapi != nullptr) {
1891 Point focusPoint;
1892 if (GetPointProperties(env, argv[PARAM0], focusPoint) == 0) {
1893 cameraSessionNapi->cameraSession_->LockForControl();
1894 int32_t retCode = cameraSessionNapi->cameraSession_->SetFocusPoint(focusPoint);
1895 cameraSessionNapi->cameraSession_->UnlockForControl();
1896 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
1897 } else {
1898 MEDIA_ERR_LOG("get point failed");
1899 }
1900 } else {
1901 MEDIA_ERR_LOG("SetFocusPoint call Failed!");
1902 }
1903 return result;
1904 }
1905
GetFocusPoint(napi_env env,napi_callback_info info)1906 napi_value CameraSessionNapi::GetFocusPoint(napi_env env, napi_callback_info info)
1907 {
1908 MEDIA_DEBUG_LOG("GetFocusPoint is called");
1909 napi_status status;
1910 napi_value result = nullptr;
1911 size_t argc = ARGS_ZERO;
1912 napi_value argv[ARGS_ZERO];
1913 napi_value thisVar = nullptr;
1914
1915 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1916
1917 napi_get_undefined(env, &result);
1918 CameraSessionNapi* cameraSessionNapi = nullptr;
1919 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1920 if (status == napi_ok && cameraSessionNapi != nullptr) {
1921 Point focusPoint;
1922 int32_t retCode = cameraSessionNapi->cameraSession_->GetFocusPoint(focusPoint);
1923 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
1924 return GetPointNapiValue(env, focusPoint);
1925 } else {
1926 MEDIA_ERR_LOG("GetFocusPoint call Failed!");
1927 }
1928 return result;
1929 }
1930
GetFocusMode(napi_env env,napi_callback_info info)1931 napi_value CameraSessionNapi::GetFocusMode(napi_env env, napi_callback_info info)
1932 {
1933 MEDIA_DEBUG_LOG("GetFocusMode is called");
1934 napi_status status;
1935 napi_value result = nullptr;
1936 size_t argc = ARGS_ZERO;
1937 napi_value argv[ARGS_ZERO];
1938 napi_value thisVar = nullptr;
1939
1940 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1941
1942 napi_get_undefined(env, &result);
1943 CameraSessionNapi* cameraSessionNapi = nullptr;
1944 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1945 if (status == napi_ok && cameraSessionNapi != nullptr) {
1946 FocusMode focusMode;
1947 int32_t retCode = cameraSessionNapi->cameraSession_->GetFocusMode(focusMode);
1948 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
1949 napi_create_int32(env, focusMode, &result);
1950 } else {
1951 MEDIA_ERR_LOG("GetFocusMode call Failed!");
1952 }
1953 return result;
1954 }
1955
SetFocusMode(napi_env env,napi_callback_info info)1956 napi_value CameraSessionNapi::SetFocusMode(napi_env env, napi_callback_info info)
1957 {
1958 MEDIA_DEBUG_LOG("SetFocusMode is called");
1959 CAMERA_SYNC_TRACE;
1960 napi_status status;
1961 napi_value result = nullptr;
1962 size_t argc = ARGS_ONE;
1963 napi_value argv[ARGS_ONE] = {0};
1964 napi_value thisVar = nullptr;
1965
1966 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
1967
1968 napi_get_undefined(env, &result);
1969 CameraSessionNapi* cameraSessionNapi = nullptr;
1970 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
1971 if (status == napi_ok && cameraSessionNapi != nullptr) {
1972 int32_t value;
1973 napi_get_value_int32(env, argv[PARAM0], &value);
1974 FocusMode focusMode = (FocusMode)value;
1975 cameraSessionNapi->cameraSession_->LockForControl();
1976 int retCode = cameraSessionNapi->cameraSession_->
1977 SetFocusMode(static_cast<FocusMode>(focusMode));
1978 cameraSessionNapi->cameraSession_->UnlockForControl();
1979 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
1980 } else {
1981 MEDIA_ERR_LOG("SetFocusMode call Failed!");
1982 }
1983 return result;
1984 }
1985
IsFocusRangeTypeSupported(napi_env env,napi_callback_info info)1986 napi_value CameraSessionNapi::IsFocusRangeTypeSupported(napi_env env, napi_callback_info info)
1987 {
1988 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
1989 "SystemApi IsFocusRangeTypeSupported is called!");
1990 MEDIA_DEBUG_LOG("IsFocusRangeTypeSupported is called");
1991 int32_t focusRangeType = 0;
1992 CameraSessionNapi* cameraSessionNapi = nullptr;
1993 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi, focusRangeType);
1994 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(PARAMETER_ERROR, "parse parameter occur error"), nullptr,
1995 "CameraSessionNapi::IsFocusRangeTypeSupported parse parameter occur error");
1996
1997 auto result = CameraNapiUtils::GetUndefinedValue(env);
1998 if (cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
1999 bool isSupported = false;
2000 int32_t retCode = cameraSessionNapi->cameraSession_->IsFocusRangeTypeSupported(
2001 static_cast<FocusRangeType>(focusRangeType), isSupported);
2002 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
2003 napi_get_boolean(env, isSupported, &result);
2004 } else {
2005 MEDIA_ERR_LOG("IsFocusRangeTypeSupported get native object fail");
2006 CameraNapiUtils::ThrowError(env, PARAMETER_ERROR, "get native object fail");
2007 return nullptr;
2008 }
2009 return result;
2010 }
2011
GetFocusRange(napi_env env,napi_callback_info info)2012 napi_value CameraSessionNapi::GetFocusRange(napi_env env, napi_callback_info info)
2013 {
2014 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
2015 "SystemApi GetFocusRange is called!");
2016 MEDIA_DEBUG_LOG("GetFocusRange is called");
2017 CameraSessionNapi* cameraSessionNapi = nullptr;
2018 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi);
2019 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(PARAMETER_ERROR, "parse parameter occur error"), nullptr,
2020 "CameraSessionNapi::GetFocusRange parse parameter occur error");
2021
2022 auto result = CameraNapiUtils::GetUndefinedValue(env);
2023 if (cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
2024 FocusRangeType focusRangeType = FocusRangeType::FOCUS_RANGE_TYPE_AUTO;
2025 int32_t retCode = cameraSessionNapi->cameraSession_->GetFocusRange(focusRangeType);
2026 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
2027 napi_create_int32(env, focusRangeType, &result);
2028 } else {
2029 MEDIA_ERR_LOG("GetFocusRange get native object fail");
2030 CameraNapiUtils::ThrowError(env, PARAMETER_ERROR, "get native object fail");
2031 return nullptr;
2032 }
2033 return result;
2034 }
2035
SetFocusRange(napi_env env,napi_callback_info info)2036 napi_value CameraSessionNapi::SetFocusRange(napi_env env, napi_callback_info info)
2037 {
2038 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
2039 "SystemApi SetFocusRange is called!");
2040 MEDIA_DEBUG_LOG("SetFocusRange is called");
2041 int32_t focusRangeType = 0;
2042 CameraSessionNapi* cameraSessionNapi = nullptr;
2043 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi, focusRangeType);
2044 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(PARAMETER_ERROR, "parse parameter occur error"), nullptr,
2045 "CameraSessionNapi::SetFocusRange parse parameter occur error");
2046 if (cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
2047 cameraSessionNapi->cameraSession_->LockForControl();
2048 int retCode = cameraSessionNapi->cameraSession_->SetFocusRange(static_cast<FocusRangeType>(focusRangeType));
2049 cameraSessionNapi->cameraSession_->UnlockForControl();
2050 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
2051 } else {
2052 MEDIA_ERR_LOG("SetFocusRange get native object fail");
2053 CameraNapiUtils::ThrowError(env, PARAMETER_ERROR, "get native object fail");
2054 return nullptr;
2055 }
2056 return CameraNapiUtils::GetUndefinedValue(env);
2057 }
2058
IsFocusDrivenTypeSupported(napi_env env,napi_callback_info info)2059 napi_value CameraSessionNapi::IsFocusDrivenTypeSupported(napi_env env, napi_callback_info info)
2060 {
2061 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
2062 "SystemApi IsFocusDrivenTypeSupported is called!");
2063 MEDIA_DEBUG_LOG("IsFocusDrivenTypeSupported is called");
2064 int32_t focusDrivenType = 0;
2065 CameraSessionNapi* cameraSessionNapi = nullptr;
2066 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi, focusDrivenType);
2067 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(PARAMETER_ERROR, "parse parameter occur error"), nullptr,
2068 "CameraSessionNapi::IsFocusDrivenTypeSupported parse parameter occur error");
2069
2070 auto result = CameraNapiUtils::GetUndefinedValue(env);
2071 if (cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
2072 bool isSupported = false;
2073 int32_t retCode = cameraSessionNapi->cameraSession_->IsFocusDrivenTypeSupported(
2074 static_cast<FocusDrivenType>(focusDrivenType), isSupported);
2075 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
2076 napi_get_boolean(env, isSupported, &result);
2077 } else {
2078 MEDIA_ERR_LOG("IsFocusDrivenTypeSupported get native object fail");
2079 CameraNapiUtils::ThrowError(env, PARAMETER_ERROR, "get native object fail");
2080 return nullptr;
2081 }
2082 return result;
2083 }
2084
GetFocusDriven(napi_env env,napi_callback_info info)2085 napi_value CameraSessionNapi::GetFocusDriven(napi_env env, napi_callback_info info)
2086 {
2087 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
2088 "SystemApi GetFocusDriven is called!");
2089 MEDIA_DEBUG_LOG("GetFocusDriven is called");
2090 CameraSessionNapi* cameraSessionNapi = nullptr;
2091 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi);
2092 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(PARAMETER_ERROR, "parse parameter occur error"), nullptr,
2093 "CameraSessionNapi::GetFocusDriven parse parameter occur error");
2094
2095 auto result = CameraNapiUtils::GetUndefinedValue(env);
2096 if (cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
2097 FocusDrivenType focusDrivenType = FocusDrivenType::FOCUS_DRIVEN_TYPE_AUTO;
2098 int32_t retCode = cameraSessionNapi->cameraSession_->GetFocusDriven(focusDrivenType);
2099 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
2100 napi_create_int32(env, focusDrivenType, &result);
2101 } else {
2102 MEDIA_ERR_LOG("GetFocusDriven get native object fail");
2103 CameraNapiUtils::ThrowError(env, PARAMETER_ERROR, "get native object fail");
2104 return nullptr;
2105 }
2106 return result;
2107 }
2108
SetFocusDriven(napi_env env,napi_callback_info info)2109 napi_value CameraSessionNapi::SetFocusDriven(napi_env env, napi_callback_info info)
2110 {
2111 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
2112 "SystemApi SetFocusDriven is called!");
2113 MEDIA_DEBUG_LOG("SetFocusDriven is called");
2114 int32_t focusDrivenType = 0;
2115 CameraSessionNapi* cameraSessionNapi = nullptr;
2116 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi, focusDrivenType);
2117 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(PARAMETER_ERROR, "parse parameter occur error"), nullptr,
2118 "CameraSessionNapi::SetFocusDriven parse parameter occur error");
2119 if (cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
2120 cameraSessionNapi->cameraSession_->LockForControl();
2121 int retCode = cameraSessionNapi->cameraSession_->SetFocusDriven(static_cast<FocusDrivenType>(focusDrivenType));
2122 cameraSessionNapi->cameraSession_->UnlockForControl();
2123 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
2124 } else {
2125 MEDIA_ERR_LOG("SetFocusDriven get native object fail");
2126 CameraNapiUtils::ThrowError(env, PARAMETER_ERROR, "get native object fail");
2127 return nullptr;
2128 }
2129 return CameraNapiUtils::GetUndefinedValue(env);
2130 }
2131
GetSupportedColorReservationTypes(napi_env env,napi_callback_info info)2132 napi_value CameraSessionNapi::GetSupportedColorReservationTypes(napi_env env, napi_callback_info info)
2133 {
2134 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
2135 "SystemApi GetSupportedColorReservationTypes is called!");
2136 MEDIA_DEBUG_LOG("GetSupportedColorReservationTypes is called");
2137 CameraSessionNapi* cameraSessionNapi = nullptr;
2138 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi);
2139 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(PARAMETER_ERROR, "parse parameter occur error"), nullptr,
2140 "CameraSessionNapi::GetSupportedColorReservationTypes parse parameter occur error");
2141
2142 napi_value result = nullptr;
2143 napi_status status = napi_create_array(env, &result);
2144 if (status != napi_ok) {
2145 MEDIA_ERR_LOG("GetSupportedColorReservationTypes napi_create_array call Failed!");
2146 CameraNapiUtils::ThrowError(env, PARAMETER_ERROR, "napi_create_array call Failed!");
2147 return nullptr;
2148 }
2149 if (cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
2150 std::vector<ColorReservationType> colorReservationTypes;
2151 int32_t retCode = cameraSessionNapi->cameraSession_->GetSupportedColorReservationTypes(colorReservationTypes);
2152 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
2153
2154 MEDIA_INFO_LOG("CameraSessionNapi::GetSupportedColorReservationTypes len = %{public}zu",
2155 colorReservationTypes.size());
2156 if (!colorReservationTypes.empty()) {
2157 for (size_t i = 0; i < colorReservationTypes.size(); i++) {
2158 ColorReservationType colorReservationType = colorReservationTypes[i];
2159 napi_value value;
2160 napi_create_int32(env, colorReservationType, &value);
2161 napi_set_element(env, result, i, value);
2162 }
2163 }
2164 } else {
2165 MEDIA_ERR_LOG("GetSupportedColorReservationTypes get native object fail");
2166 CameraNapiUtils::ThrowError(env, PARAMETER_ERROR, "get native object fail");
2167 return nullptr;
2168 }
2169 return result;
2170 }
2171
GetColorReservation(napi_env env,napi_callback_info info)2172 napi_value CameraSessionNapi::GetColorReservation(napi_env env, napi_callback_info info)
2173 {
2174 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
2175 "SystemApi GetColorReservation is called!");
2176 MEDIA_DEBUG_LOG("GetColorReservation is called");
2177 CameraSessionNapi* cameraSessionNapi = nullptr;
2178 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi);
2179 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(PARAMETER_ERROR, "parse parameter occur error"), nullptr,
2180 "CameraSessionNapi::GetColorReservation parse parameter occur error");
2181
2182 auto result = CameraNapiUtils::GetUndefinedValue(env);
2183 if (cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
2184 ColorReservationType colorReservationType = ColorReservationType::COLOR_RESERVATION_TYPE_NONE;
2185 int32_t retCode = cameraSessionNapi->cameraSession_->GetColorReservation(colorReservationType);
2186 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
2187 napi_create_int32(env, colorReservationType, &result);
2188 } else {
2189 MEDIA_ERR_LOG("GetColorReservation get native object fail");
2190 CameraNapiUtils::ThrowError(env, PARAMETER_ERROR, "get native object fail");
2191 return nullptr;
2192 }
2193 return result;
2194 }
2195
SetColorReservation(napi_env env,napi_callback_info info)2196 napi_value CameraSessionNapi::SetColorReservation(napi_env env, napi_callback_info info)
2197 {
2198 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
2199 "SystemApi SetColorReservation is called!");
2200 MEDIA_DEBUG_LOG("SetColorReservation is called");
2201 int32_t colorReservationType = 0;
2202 CameraSessionNapi* cameraSessionNapi = nullptr;
2203 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi, colorReservationType);
2204 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(PARAMETER_ERROR, "parse parameter occur error"), nullptr,
2205 "CameraSessionNapi::SetColorReservation parse parameter occur error");
2206 if (cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
2207 cameraSessionNapi->cameraSession_->LockForControl();
2208 int retCode = cameraSessionNapi->cameraSession_->SetColorReservation(
2209 static_cast<ColorReservationType>(colorReservationType));
2210 cameraSessionNapi->cameraSession_->UnlockForControl();
2211 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
2212 } else {
2213 MEDIA_ERR_LOG("SetColorReservation get native object fail");
2214 CameraNapiUtils::ThrowError(env, PARAMETER_ERROR, "get native object fail");
2215 return nullptr;
2216 }
2217 return CameraNapiUtils::GetUndefinedValue(env);
2218 }
2219
SetQualityPrioritization(napi_env env,napi_callback_info info)2220 napi_value CameraSessionNapi::SetQualityPrioritization(napi_env env, napi_callback_info info)
2221 {
2222 MEDIA_DEBUG_LOG("SetQualityPrioritization is called");
2223 CAMERA_SYNC_TRACE;
2224 napi_status status;
2225 napi_value result = nullptr;
2226 size_t argc = ARGS_ONE;
2227 napi_value argv[ARGS_ONE] = { 0 };
2228 napi_value thisVar = nullptr;
2229
2230 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
2231
2232 napi_get_undefined(env, &result);
2233 CameraSessionNapi* cameraSessionNapi = nullptr;
2234 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
2235 if (status == napi_ok && cameraSessionNapi != nullptr) {
2236 int32_t value;
2237 napi_get_value_int32(env, argv[PARAM0], &value);
2238 QualityPrioritization qualityPrioritization = (QualityPrioritization)value;
2239 cameraSessionNapi->cameraSession_->LockForControl();
2240 int retCode = cameraSessionNapi->cameraSession_->SetQualityPrioritization(
2241 static_cast<QualityPrioritization>(qualityPrioritization));
2242 cameraSessionNapi->cameraSession_->UnlockForControl();
2243 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
2244 } else {
2245 MEDIA_ERR_LOG("SetQualityPrioritization call Failed!");
2246 }
2247 return result;
2248 }
2249
GetZoomRatioRange(napi_env env,napi_callback_info info)2250 napi_value CameraSessionNapi::GetZoomRatioRange(napi_env env, napi_callback_info info)
2251 {
2252 MEDIA_DEBUG_LOG("GetZoomRatioRange is called");
2253 napi_status status;
2254 napi_value result = nullptr;
2255 size_t argc = ARGS_ZERO;
2256 napi_value argv[ARGS_ZERO];
2257 napi_value thisVar = nullptr;
2258
2259 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
2260
2261 napi_get_undefined(env, &result);
2262
2263 CameraSessionNapi* cameraSessionNapi = nullptr;
2264 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
2265 if (status == napi_ok && cameraSessionNapi != nullptr) {
2266 std::vector<float> vecZoomRatioList;
2267 int32_t retCode = cameraSessionNapi->cameraSession_->GetZoomRatioRange(vecZoomRatioList);
2268 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
2269 MEDIA_INFO_LOG("CameraSessionNapi::GetZoomRatioRange len = %{public}zu",
2270 vecZoomRatioList.size());
2271
2272 if (!vecZoomRatioList.empty() && napi_create_array(env, &result) == napi_ok) {
2273 for (size_t i = 0; i < vecZoomRatioList.size(); i++) {
2274 float zoomRatio = vecZoomRatioList[i];
2275 napi_value value;
2276 napi_create_double(env, CameraNapiUtils::FloatToDouble(zoomRatio), &value);
2277 napi_set_element(env, result, i, value);
2278 }
2279 } else {
2280 MEDIA_ERR_LOG("vecSupportedZoomRatioList is empty or failed to create array!");
2281 }
2282 } else {
2283 MEDIA_ERR_LOG("GetZoomRatioRange call Failed!");
2284 }
2285 return result;
2286 }
2287
GetZoomRatio(napi_env env,napi_callback_info info)2288 napi_value CameraSessionNapi::GetZoomRatio(napi_env env, napi_callback_info info)
2289 {
2290 MEDIA_DEBUG_LOG("GetZoomRatio is called");
2291 napi_status status;
2292 napi_value result = nullptr;
2293 size_t argc = ARGS_ZERO;
2294 napi_value argv[ARGS_ZERO];
2295 napi_value thisVar = nullptr;
2296
2297 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
2298
2299 napi_get_undefined(env, &result);
2300 CameraSessionNapi* cameraSessionNapi = nullptr;
2301 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
2302 if (status == napi_ok && cameraSessionNapi != nullptr) {
2303 float zoomRatio;
2304 int32_t retCode = cameraSessionNapi->cameraSession_->GetZoomRatio(zoomRatio);
2305 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
2306 napi_create_double(env, CameraNapiUtils::FloatToDouble(zoomRatio), &result);
2307 } else {
2308 MEDIA_ERR_LOG("GetZoomRatio call Failed!");
2309 }
2310 return result;
2311 }
2312
SetZoomRatio(napi_env env,napi_callback_info info)2313 napi_value CameraSessionNapi::SetZoomRatio(napi_env env, napi_callback_info info)
2314 {
2315 MEDIA_DEBUG_LOG("SetZoomRatio is called");
2316 CAMERA_SYNC_TRACE;
2317 napi_status status;
2318 napi_value result = nullptr;
2319
2320 size_t argc = ARGS_ONE;
2321 napi_value argv[ARGS_ONE];
2322 napi_value thisVar = nullptr;
2323
2324 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
2325
2326 napi_get_undefined(env, &result);
2327 CameraSessionNapi* cameraSessionNapi = nullptr;
2328 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
2329 if (status == napi_ok && cameraSessionNapi != nullptr) {
2330 double zoomRatio;
2331 napi_get_value_double(env, argv[PARAM0], &zoomRatio);
2332 cameraSessionNapi->cameraSession_->LockForControl();
2333 int32_t retCode = cameraSessionNapi->cameraSession_->SetZoomRatio((float)zoomRatio);
2334 cameraSessionNapi->cameraSession_->UnlockForControl();
2335 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
2336 } else {
2337 MEDIA_ERR_LOG("SetZoomRatio call Failed!");
2338 }
2339 return result;
2340 }
2341
PrepareZoom(napi_env env,napi_callback_info info)2342 napi_value CameraSessionNapi::PrepareZoom(napi_env env, napi_callback_info info)
2343 {
2344 MEDIA_DEBUG_LOG("PrepareZoom is called");
2345 CAMERA_SYNC_TRACE;
2346 napi_status status;
2347 napi_value result = nullptr;
2348
2349 size_t argc = ARGS_ZERO;
2350 napi_value argv[ARGS_ZERO];
2351 napi_value thisVar = nullptr;
2352
2353 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
2354
2355 napi_get_undefined(env, &result);
2356 CameraSessionNapi* cameraSessionNapi = nullptr;
2357 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
2358 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
2359 cameraSessionNapi->cameraSession_->LockForControl();
2360 int32_t retCode = cameraSessionNapi->cameraSession_->PrepareZoom();
2361 cameraSessionNapi->cameraSession_->UnlockForControl();
2362 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
2363 } else {
2364 MEDIA_ERR_LOG("PrepareZoom call Failed!");
2365 }
2366 return result;
2367 }
2368
UnPrepareZoom(napi_env env,napi_callback_info info)2369 napi_value CameraSessionNapi::UnPrepareZoom(napi_env env, napi_callback_info info)
2370 {
2371 MEDIA_DEBUG_LOG("PrepareZoom is called");
2372 CAMERA_SYNC_TRACE;
2373 napi_status status;
2374 napi_value result = nullptr;
2375
2376 size_t argc = ARGS_ZERO;
2377 napi_value argv[ARGS_ZERO];
2378 napi_value thisVar = nullptr;
2379
2380 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
2381
2382 napi_get_undefined(env, &result);
2383 CameraSessionNapi* cameraSessionNapi = nullptr;
2384 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
2385 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
2386 cameraSessionNapi->cameraSession_->LockForControl();
2387 int32_t retCode = cameraSessionNapi->cameraSession_->UnPrepareZoom();
2388 cameraSessionNapi->cameraSession_->UnlockForControl();
2389 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
2390 } else {
2391 MEDIA_ERR_LOG("PrepareZoom call Failed!");
2392 }
2393 return result;
2394 }
2395
SetSmoothZoom(napi_env env,napi_callback_info info)2396 napi_value CameraSessionNapi::SetSmoothZoom(napi_env env, napi_callback_info info)
2397 {
2398 MEDIA_DEBUG_LOG("SetSmoothZoom is called");
2399 CAMERA_SYNC_TRACE;
2400 napi_status status;
2401 napi_value result = nullptr;
2402
2403 size_t argc = ARGS_TWO;
2404 napi_value argv[ARGS_TWO];
2405 napi_value thisVar = nullptr;
2406
2407 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
2408
2409 napi_get_undefined(env, &result);
2410 CameraSessionNapi* cameraSessionNapi = nullptr;
2411 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
2412 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
2413 double targetZoomRatio;
2414 int32_t smoothZoomType;
2415 napi_get_value_double(env, argv[PARAM0], &targetZoomRatio);
2416 napi_get_value_int32(env, argv[PARAM1], &smoothZoomType);
2417 int32_t retCode = cameraSessionNapi->cameraSession_->SetSmoothZoom((float)targetZoomRatio, smoothZoomType);
2418 if (!CameraNapiUtils::CheckError(env, retCode)) {
2419 return nullptr;
2420 }
2421 } else {
2422 MEDIA_ERR_LOG("SetSmoothZoom call Failed!");
2423 }
2424 return result;
2425 }
2426
GetZoomPointInfos(napi_env env,napi_callback_info info)2427 napi_value CameraSessionNapi::GetZoomPointInfos(napi_env env, napi_callback_info info)
2428 {
2429 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
2430 "SystemApi GetZoomPointInfos is called!");
2431 MEDIA_DEBUG_LOG("GetZoomPointInfos is called");
2432 napi_status status;
2433 napi_value result = nullptr;
2434 size_t argc = ARGS_ZERO;
2435 napi_value argv[ARGS_ZERO];
2436 napi_value thisVar = nullptr;
2437
2438 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
2439
2440 napi_get_undefined(env, &result);
2441
2442 CameraSessionNapi* cameraSessionNapi = nullptr;
2443 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
2444 if (status == napi_ok && cameraSessionNapi != nullptr) {
2445 std::vector<ZoomPointInfo> vecZoomPointInfoList;
2446 int32_t retCode = cameraSessionNapi->cameraSession_->GetZoomPointInfos(vecZoomPointInfoList);
2447 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
2448 MEDIA_INFO_LOG("CameraSessionNapi::GetZoomPointInfos len = %{public}zu",
2449 vecZoomPointInfoList.size());
2450
2451 if (!vecZoomPointInfoList.empty() && napi_create_array(env, &result) == napi_ok) {
2452 for (size_t i = 0; i < vecZoomPointInfoList.size(); i++) {
2453 ZoomPointInfo zoomPointInfo = vecZoomPointInfoList[i];
2454 napi_value value;
2455 napi_value zoomRatio;
2456 napi_value equivalentFocus;
2457 napi_create_object(env, &value);
2458 napi_create_double(env, CameraNapiUtils::FloatToDouble(zoomPointInfo.zoomRatio), &zoomRatio);
2459 napi_set_named_property(env, value, "zoomRatio", zoomRatio);
2460 napi_create_double(env, zoomPointInfo.equivalentFocalLength, &equivalentFocus);
2461 napi_set_named_property(env, value, "equivalentFocalLength", equivalentFocus);
2462 napi_set_element(env, result, i, value);
2463 }
2464 } else {
2465 MEDIA_ERR_LOG("vecSupportedZoomRatioList is empty or failed to create array!");
2466 }
2467 } else {
2468 MEDIA_ERR_LOG("GetZoomPointInfos call Failed!");
2469 }
2470 return result;
2471 }
2472
GetSupportedFilters(napi_env env,napi_callback_info info)2473 napi_value CameraSessionNapi::GetSupportedFilters(napi_env env, napi_callback_info info)
2474 {
2475 MEDIA_DEBUG_LOG("getSupportedFilters is called");
2476 napi_status status;
2477 napi_value result = nullptr;
2478 size_t argc = ARGS_ZERO;
2479 napi_value argv[ARGS_ZERO];
2480 napi_value thisVar = nullptr;
2481
2482 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
2483
2484 napi_get_undefined(env, &result);
2485 status = napi_create_array(env, &result);
2486 CHECK_ERROR_RETURN_RET_LOG(status != napi_ok, result, "napi_create_array call Failed!");
2487 CameraSessionNapi* cameraSessionNapi = nullptr;
2488 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
2489 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
2490 std::vector<FilterType> filterTypes = cameraSessionNapi->cameraSession_->GetSupportedFilters();
2491 MEDIA_INFO_LOG("CameraSessionNapi::GetSupportedFilters len = %{public}zu",
2492 filterTypes.size());
2493 if (!filterTypes.empty()) {
2494 for (size_t i = 0; i < filterTypes.size(); i++) {
2495 FilterType filterType = filterTypes[i];
2496 napi_value value;
2497 napi_create_int32(env, filterType, &value);
2498 napi_set_element(env, result, i, value);
2499 }
2500 }
2501 } else {
2502 MEDIA_ERR_LOG("GetSupportedFilters call Failed!");
2503 }
2504 return result;
2505 }
GetFilter(napi_env env,napi_callback_info info)2506 napi_value CameraSessionNapi::GetFilter(napi_env env, napi_callback_info info)
2507 {
2508 MEDIA_DEBUG_LOG("GetFilter is called");
2509 napi_status status;
2510 napi_value result = nullptr;
2511 size_t argc = ARGS_ZERO;
2512 napi_value argv[ARGS_ZERO];
2513 napi_value thisVar = nullptr;
2514
2515 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
2516
2517 napi_get_undefined(env, &result);
2518 CameraSessionNapi* cameraSessionNapi = nullptr;
2519 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
2520 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
2521 FilterType filterType = cameraSessionNapi->cameraSession_->GetFilter();
2522 napi_create_int32(env, filterType, &result);
2523 } else {
2524 MEDIA_ERR_LOG("GetFilter call Failed!");
2525 }
2526 return result;
2527 }
SetFilter(napi_env env,napi_callback_info info)2528 napi_value CameraSessionNapi::SetFilter(napi_env env, napi_callback_info info)
2529 {
2530 MEDIA_DEBUG_LOG("setFilter is called");
2531 CAMERA_SYNC_TRACE;
2532 napi_status status;
2533 napi_value result = nullptr;
2534 size_t argc = ARGS_ONE;
2535 napi_value argv[ARGS_ONE] = {0};
2536 napi_value thisVar = nullptr;
2537
2538 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
2539
2540 napi_get_undefined(env, &result);
2541 CameraSessionNapi* cameraSessionNapi = nullptr;
2542 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
2543 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
2544 int32_t value;
2545 napi_get_value_int32(env, argv[PARAM0], &value);
2546 FilterType filterType = (FilterType)value;
2547 cameraSessionNapi->cameraSession_->LockForControl();
2548 cameraSessionNapi->cameraSession_->
2549 SetFilter(static_cast<FilterType>(filterType));
2550 cameraSessionNapi->cameraSession_->UnlockForControl();
2551 } else {
2552 MEDIA_ERR_LOG("SetFilter call Failed!");
2553 }
2554 return result;
2555 }
2556
GetSupportedBeautyTypes(napi_env env,napi_callback_info info)2557 napi_value CameraSessionNapi::GetSupportedBeautyTypes(napi_env env, napi_callback_info info)
2558 {
2559 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
2560 "SystemApi GetSupportedBeautyTypes is called!");
2561 MEDIA_DEBUG_LOG("GetSupportedBeautyTypes is called");
2562 napi_status status;
2563 napi_value result = nullptr;
2564 size_t argc = ARGS_ZERO;
2565 napi_value argv[ARGS_ZERO];
2566 napi_value thisVar = nullptr;
2567
2568 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
2569
2570 napi_get_undefined(env, &result);
2571 status = napi_create_array(env, &result);
2572 CHECK_ERROR_RETURN_RET_LOG(status != napi_ok, result, "napi_create_array call Failed!");
2573 CameraSessionNapi* cameraSessionNapi = nullptr;
2574 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
2575 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
2576 std::vector<BeautyType> beautyTypes = cameraSessionNapi->cameraSession_->GetSupportedBeautyTypes();
2577 MEDIA_INFO_LOG("CameraSessionNapi::GetSupportedBeautyTypes len = %{public}zu",
2578 beautyTypes.size());
2579 if (!beautyTypes.empty() && status == napi_ok) {
2580 for (size_t i = 0; i < beautyTypes.size(); i++) {
2581 BeautyType beautyType = beautyTypes[i];
2582 napi_value value;
2583 napi_create_int32(env, beautyType, &value);
2584 napi_set_element(env, result, i, value);
2585 }
2586 }
2587 } else {
2588 MEDIA_ERR_LOG("GetSupportedBeautyTypes call Failed!");
2589 }
2590 return result;
2591 }
2592
GetSupportedBeautyRange(napi_env env,napi_callback_info info)2593 napi_value CameraSessionNapi::GetSupportedBeautyRange(napi_env env, napi_callback_info info)
2594 {
2595 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
2596 "SystemApi GetSupportedBeautyRange is called!");
2597 MEDIA_DEBUG_LOG("GetSupportedBeautyRange is called");
2598 napi_status status;
2599 napi_value result = nullptr;
2600 size_t argc = ARGS_ONE;
2601 napi_value argv[ARGS_ONE];
2602 napi_value thisVar = nullptr;
2603
2604 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
2605
2606 napi_get_undefined(env, &result);
2607 status = napi_create_array(env, &result);
2608 CHECK_ERROR_RETURN_RET_LOG(status != napi_ok, result, "napi_create_array call Failed!");
2609 CameraSessionNapi* cameraSessionNapi = nullptr;
2610 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
2611 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
2612 int32_t beautyType;
2613 napi_get_value_int32(env, argv[PARAM0], &beautyType);
2614 std::vector<int32_t> beautyRanges =
2615 cameraSessionNapi->cameraSession_->GetSupportedBeautyRange(static_cast<BeautyType>(beautyType));
2616 MEDIA_INFO_LOG("CameraSessionNapi::GetSupportedBeautyRange beautyType = %{public}d, len = %{public}zu",
2617 beautyType, beautyRanges.size());
2618 if (!beautyRanges.empty()) {
2619 for (size_t i = 0; i < beautyRanges.size(); i++) {
2620 int beautyRange = beautyRanges[i];
2621 napi_value value;
2622 napi_create_int32(env, beautyRange, &value);
2623 napi_set_element(env, result, i, value);
2624 }
2625 }
2626 } else {
2627 MEDIA_ERR_LOG("GetSupportedBeautyRange call Failed!");
2628 }
2629 return result;
2630 }
2631
GetBeauty(napi_env env,napi_callback_info info)2632 napi_value CameraSessionNapi::GetBeauty(napi_env env, napi_callback_info info)
2633 {
2634 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr, "SystemApi GetBeauty is called!");
2635 MEDIA_DEBUG_LOG("GetBeauty is called");
2636 napi_status status;
2637 napi_value result = nullptr;
2638 size_t argc = ARGS_ONE;
2639 napi_value argv[ARGS_ONE];
2640 napi_value thisVar = nullptr;
2641
2642 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
2643
2644 napi_get_undefined(env, &result);
2645 CameraSessionNapi* cameraSessionNapi = nullptr;
2646 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
2647 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
2648 int32_t beautyType;
2649 napi_get_value_int32(env, argv[PARAM0], &beautyType);
2650 int32_t beautyStrength = cameraSessionNapi->cameraSession_->GetBeauty(static_cast<BeautyType>(beautyType));
2651 napi_create_int32(env, beautyStrength, &result);
2652 } else {
2653 MEDIA_ERR_LOG("GetBeauty call Failed!");
2654 }
2655 return result;
2656 }
2657
SetBeauty(napi_env env,napi_callback_info info)2658 napi_value CameraSessionNapi::SetBeauty(napi_env env, napi_callback_info info)
2659 {
2660 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr, "SystemApi SetBeauty is called!");
2661 MEDIA_DEBUG_LOG("SetBeauty is called");
2662 napi_status status;
2663 napi_value result = nullptr;
2664 size_t argc = ARGS_TWO;
2665 napi_value argv[ARGS_TWO];
2666 napi_value thisVar = nullptr;
2667
2668 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
2669
2670 napi_get_undefined(env, &result);
2671 CameraSessionNapi* cameraSessionNapi = nullptr;
2672 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
2673 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
2674 int32_t beautyType;
2675 napi_get_value_int32(env, argv[PARAM0], &beautyType);
2676 int32_t beautyStrength;
2677 napi_get_value_int32(env, argv[PARAM1], &beautyStrength);
2678 cameraSessionNapi->cameraSession_->LockForControl();
2679 cameraSessionNapi->cameraSession_->SetBeauty(static_cast<BeautyType>(beautyType), beautyStrength);
2680 cameraSessionNapi->cameraSession_->UnlockForControl();
2681 } else {
2682 MEDIA_ERR_LOG("SetBeauty call Failed!");
2683 }
2684 return result;
2685 }
2686
GetSupportedPortraitThemeTypes(napi_env env,napi_callback_info info)2687 napi_value CameraSessionNapi::GetSupportedPortraitThemeTypes(napi_env env, napi_callback_info info)
2688 {
2689 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
2690 "SystemApi GetSupportedPortraitThemeTypes is called!");
2691 MEDIA_DEBUG_LOG("GetSupportedPortraitThemeTypes is called");
2692 CameraSessionNapi* cameraSessionNapi = nullptr;
2693 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi);
2694 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"), nullptr,
2695 "CameraSessionNapi::GetSupportedPortraitThemeTypes parse parameter occur error");
2696
2697 napi_status status;
2698 napi_value result = nullptr;
2699 status = napi_create_array(env, &result);
2700 CHECK_ERROR_RETURN_RET_LOG(status != napi_ok, nullptr, "napi_create_array call Failed!");
2701
2702 if (cameraSessionNapi->cameraSession_ != nullptr) {
2703 std::vector<PortraitThemeType> themeTypes;
2704 int32_t retCode = cameraSessionNapi->cameraSession_->GetSupportedPortraitThemeTypes(themeTypes);
2705 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
2706 MEDIA_INFO_LOG("CameraSessionNapi::GetSupportedPortraitThemeTypes len = %{public}zu", themeTypes.size());
2707 if (!themeTypes.empty()) {
2708 for (size_t i = 0; i < themeTypes.size(); i++) {
2709 napi_value value;
2710 napi_create_int32(env, static_cast<int32_t>(themeTypes[i]), &value);
2711 napi_set_element(env, result, i, value);
2712 }
2713 }
2714 } else {
2715 MEDIA_ERR_LOG("GetSupportedPortraitThemeTypes call Failed!");
2716 }
2717 return result;
2718 }
2719
SetPortraitThemeType(napi_env env,napi_callback_info info)2720 napi_value CameraSessionNapi::SetPortraitThemeType(napi_env env, napi_callback_info info)
2721 {
2722 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
2723 "SystemApi SetPortraitThemeType is called!");
2724 MEDIA_DEBUG_LOG("CameraSessionNapi::SetPortraitThemeType is called");
2725 int32_t type = 0;
2726 CameraSessionNapi* cameraSessionNapi = nullptr;
2727 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi, type);
2728 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"), nullptr,
2729 "CameraSessionNapi::SetPortraitThemeType parse parameter occur error");
2730
2731 if (cameraSessionNapi->cameraSession_ != nullptr) {
2732 PortraitThemeType portraitThemeType = static_cast<PortraitThemeType>(type);
2733 MEDIA_INFO_LOG("CameraSessionNapi::SetPortraitThemeType:%{public}d", portraitThemeType);
2734 cameraSessionNapi->cameraSession_->LockForControl();
2735 int32_t retCode = cameraSessionNapi->cameraSession_->SetPortraitThemeType(portraitThemeType);
2736 cameraSessionNapi->cameraSession_->UnlockForControl();
2737 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiUtils::CheckError(env, retCode), nullptr,
2738 "CameraSessionNapi::SetPortraitThemeType fail %{public}d", retCode);
2739 } else {
2740 MEDIA_ERR_LOG("CameraSessionNapi::SetPortraitThemeType get native object fail");
2741 CameraNapiUtils::ThrowError(env, INVALID_ARGUMENT, "get native object fail");
2742 return nullptr;
2743 }
2744 return CameraNapiUtils::GetUndefinedValue(env);
2745 }
2746
IsPortraitThemeSupported(napi_env env,napi_callback_info info)2747 napi_value CameraSessionNapi::IsPortraitThemeSupported(napi_env env, napi_callback_info info)
2748 {
2749 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
2750 "SystemApi IsPortraitThemeSupported is called!");
2751 MEDIA_DEBUG_LOG("CameraSessionNapi::IsPortraitThemeSupported is called");
2752 CameraSessionNapi* cameraSessionNapi = nullptr;
2753 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi);
2754 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"), nullptr,
2755 "CameraSessionNapi::IsPortraitThemeSupported parse parameter occur error");
2756 auto result = CameraNapiUtils::GetUndefinedValue(env);
2757 if (cameraSessionNapi->cameraSession_ != nullptr) {
2758 bool isSupported;
2759 int32_t retCode = cameraSessionNapi->cameraSession_->IsPortraitThemeSupported(isSupported);
2760 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
2761 napi_get_boolean(env, isSupported, &result);
2762 } else {
2763 MEDIA_ERR_LOG("CameraSessionNapi::IsPortraitThemeSupported get native object fail");
2764 CameraNapiUtils::ThrowError(env, INVALID_ARGUMENT, "get native object fail");
2765 return nullptr;
2766 }
2767 return result;
2768 }
2769
GetSupportedColorSpaces(napi_env env,napi_callback_info info)2770 napi_value CameraSessionNapi::GetSupportedColorSpaces(napi_env env, napi_callback_info info)
2771 {
2772 MEDIA_DEBUG_LOG("GetSupportedColorSpaces is called.");
2773 napi_status status;
2774 napi_value result = nullptr;
2775 size_t argc = ARGS_ZERO;
2776 napi_value argv[ARGS_ZERO];
2777 napi_value thisVar = nullptr;
2778
2779 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
2780
2781 napi_get_undefined(env, &result);
2782 status = napi_create_array(env, &result);
2783 CHECK_ERROR_RETURN_RET_LOG(status != napi_ok, result, "napi_create_array call Failed!");
2784 CameraSessionNapi* cameraSessionNapi = nullptr;
2785 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
2786 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
2787 std::vector<ColorSpace> colorSpaces = cameraSessionNapi->cameraSession_->GetSupportedColorSpaces();
2788 if (!colorSpaces.empty()) {
2789 for (size_t i = 0; i < colorSpaces.size(); i++) {
2790 int colorSpace = colorSpaces[i];
2791 napi_value value;
2792 napi_create_int32(env, colorSpace, &value);
2793 napi_set_element(env, result, i, value);
2794 }
2795 }
2796 } else {
2797 MEDIA_ERR_LOG("GetSupportedColorSpaces call Failed!");
2798 }
2799 return result;
2800 }
2801
GetActiveColorSpace(napi_env env,napi_callback_info info)2802 napi_value CameraSessionNapi::GetActiveColorSpace(napi_env env, napi_callback_info info)
2803 {
2804 MEDIA_DEBUG_LOG("GetActiveColorSpace is called");
2805 napi_status status;
2806 napi_value result = nullptr;
2807 size_t argc = ARGS_ZERO;
2808 napi_value argv[ARGS_ZERO];
2809 napi_value thisVar = nullptr;
2810
2811 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
2812
2813 napi_get_undefined(env, &result);
2814 CameraSessionNapi* cameraSessionNapi = nullptr;
2815 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
2816 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
2817 ColorSpace colorSpace;
2818 int32_t retCode = cameraSessionNapi->cameraSession_->GetActiveColorSpace(colorSpace);
2819 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), result);
2820 napi_create_int32(env, colorSpace, &result);
2821 } else {
2822 MEDIA_ERR_LOG("GetActiveColorSpace call Failed!");
2823 }
2824 return result;
2825 }
2826
SetColorSpace(napi_env env,napi_callback_info info)2827 napi_value CameraSessionNapi::SetColorSpace(napi_env env, napi_callback_info info)
2828 {
2829 MEDIA_DEBUG_LOG("SetColorSpace is called");
2830 CAMERA_SYNC_TRACE;
2831 napi_status status;
2832 napi_value result = nullptr;
2833 size_t argc = ARGS_ONE;
2834 napi_value argv[ARGS_ONE] = {0};
2835 napi_value thisVar = nullptr;
2836
2837 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
2838
2839 napi_get_undefined(env, &result);
2840 CameraSessionNapi* cameraSessionNapi = nullptr;
2841 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
2842 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
2843 int32_t colorSpaceNumber;
2844 napi_get_value_int32(env, argv[PARAM0], &colorSpaceNumber);
2845 ColorSpace colorSpace = (ColorSpace)colorSpaceNumber;
2846 int32_t retCode = cameraSessionNapi->cameraSession_->SetColorSpace(colorSpace);
2847 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), result);
2848 } else {
2849 MEDIA_ERR_LOG("SetColorSpace call Failed!");
2850 }
2851 return result;
2852 }
2853
GetSupportedColorEffects(napi_env env,napi_callback_info info)2854 napi_value CameraSessionNapi::GetSupportedColorEffects(napi_env env, napi_callback_info info)
2855 {
2856 MEDIA_DEBUG_LOG("GetSupportedColorEffects is called");
2857 napi_status status;
2858 napi_value result = nullptr;
2859 size_t argc = ARGS_ZERO;
2860 napi_value argv[ARGS_ZERO];
2861 napi_value thisVar = nullptr;
2862
2863 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
2864
2865 napi_get_undefined(env, &result);
2866 status = napi_create_array(env, &result);
2867 CHECK_ERROR_RETURN_RET_LOG(status != napi_ok, result, "napi_create_array call Failed!");
2868 CameraSessionNapi* cameraSessionNapi = nullptr;
2869 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
2870 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
2871 std::vector<ColorEffect> colorEffects = cameraSessionNapi->cameraSession_->GetSupportedColorEffects();
2872 if (!colorEffects.empty()) {
2873 for (size_t i = 0; i < colorEffects.size(); i++) {
2874 int colorEffect = colorEffects[i];
2875 napi_value value;
2876 napi_create_int32(env, colorEffect, &value);
2877 napi_set_element(env, result, i, value);
2878 }
2879 }
2880 } else {
2881 MEDIA_ERR_LOG("GetSupportedColorEffects call Failed!");
2882 }
2883 return result;
2884 }
2885
GetColorEffect(napi_env env,napi_callback_info info)2886 napi_value CameraSessionNapi::GetColorEffect(napi_env env, napi_callback_info info)
2887 {
2888 MEDIA_DEBUG_LOG("GetColorEffect is called");
2889 napi_status status;
2890 napi_value result = nullptr;
2891 size_t argc = ARGS_ZERO;
2892 napi_value argv[ARGS_ZERO];
2893 napi_value thisVar = nullptr;
2894
2895 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
2896
2897 napi_get_undefined(env, &result);
2898 CameraSessionNapi* cameraSessionNapi = nullptr;
2899 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
2900 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
2901 ColorEffect colorEffect = cameraSessionNapi->cameraSession_->GetColorEffect();
2902 napi_create_int32(env, colorEffect, &result);
2903 } else {
2904 MEDIA_ERR_LOG("GetColorEffect call Failed!");
2905 }
2906 return result;
2907 }
2908
SetColorEffect(napi_env env,napi_callback_info info)2909 napi_value CameraSessionNapi::SetColorEffect(napi_env env, napi_callback_info info)
2910 {
2911 MEDIA_DEBUG_LOG("SetColorEffect is called");
2912 CAMERA_SYNC_TRACE;
2913 napi_status status;
2914 napi_value result = nullptr;
2915 size_t argc = ARGS_ONE;
2916 napi_value argv[ARGS_ONE] = {0};
2917 napi_value thisVar = nullptr;
2918
2919 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
2920
2921 napi_get_undefined(env, &result);
2922 CameraSessionNapi* cameraSessionNapi = nullptr;
2923 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
2924 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
2925 int32_t colorEffectNumber;
2926 napi_get_value_int32(env, argv[PARAM0], &colorEffectNumber);
2927 ColorEffect colorEffect = (ColorEffect)colorEffectNumber;
2928 cameraSessionNapi->cameraSession_->LockForControl();
2929 cameraSessionNapi->cameraSession_->SetColorEffect(static_cast<ColorEffect>(colorEffect));
2930 cameraSessionNapi->cameraSession_->UnlockForControl();
2931 } else {
2932 MEDIA_ERR_LOG("SetColorEffect call Failed!");
2933 }
2934 return result;
2935 }
2936
GetFocusDistance(napi_env env,napi_callback_info info)2937 napi_value CameraSessionNapi::GetFocusDistance(napi_env env, napi_callback_info info)
2938 {
2939 MEDIA_DEBUG_LOG("GetFocusDistance is called");
2940 napi_status status;
2941 napi_value result = nullptr;
2942 size_t argc = ARGS_ZERO;
2943 napi_value argv[ARGS_ZERO];
2944 napi_value thisVar = nullptr;
2945
2946 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
2947
2948 napi_get_undefined(env, &result);
2949 CameraSessionNapi* cameraSessionNapi = nullptr;
2950 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
2951 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
2952 float distance;
2953 int32_t retCode = cameraSessionNapi->cameraSession_->GetFocusDistance(distance);
2954 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
2955 napi_create_double(env, distance, &result);
2956 } else {
2957 MEDIA_ERR_LOG("GetFocusDistance call Failed!");
2958 }
2959 return result;
2960 }
2961
SetFocusDistance(napi_env env,napi_callback_info info)2962 napi_value CameraSessionNapi::SetFocusDistance(napi_env env, napi_callback_info info)
2963 {
2964 MEDIA_DEBUG_LOG("SetFocusDistance is called");
2965 CAMERA_SYNC_TRACE;
2966 napi_status status;
2967 napi_value result = nullptr;
2968 size_t argc = ARGS_ONE;
2969 napi_value argv[ARGS_ONE] = {0};
2970 napi_value thisVar = nullptr;
2971
2972 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
2973
2974 napi_get_undefined(env, &result);
2975 CameraSessionNapi* cameraSessionNapi = nullptr;
2976 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
2977 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
2978 double value;
2979 napi_get_value_double(env, argv[PARAM0], &value);
2980 float distance = static_cast<float>(value);
2981 cameraSessionNapi->cameraSession_->LockForControl();
2982 cameraSessionNapi->cameraSession_->SetFocusDistance(distance);
2983 MEDIA_INFO_LOG("CameraSessionNapi::SetFocusDistance set focusDistance:%{public}f!", distance);
2984 cameraSessionNapi->cameraSession_->UnlockForControl();
2985 } else {
2986 MEDIA_ERR_LOG("SetFocusDistance call Failed!");
2987 }
2988 return result;
2989 }
2990
IsMacroSupported(napi_env env,napi_callback_info info)2991 napi_value CameraSessionNapi::IsMacroSupported(napi_env env, napi_callback_info info)
2992 {
2993 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
2994 "SystemApi IsMacroSupported is called!");
2995 MEDIA_DEBUG_LOG("CameraSessionNapi::IsMacroSupported is called");
2996 CameraSessionNapi* cameraSessionNapi = nullptr;
2997 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi);
2998 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"), nullptr,
2999 "CameraSessionNapi::IsMacroSupported parse parameter occur error");
3000 auto result = CameraNapiUtils::GetUndefinedValue(env);
3001 if (cameraSessionNapi->cameraSession_ != nullptr) {
3002 bool isSupported = cameraSessionNapi->cameraSession_->IsMacroSupported();
3003 napi_get_boolean(env, isSupported, &result);
3004 } else {
3005 MEDIA_ERR_LOG("CameraSessionNapi::IsMacroSupported get native object fail");
3006 CameraNapiUtils::ThrowError(env, INVALID_ARGUMENT, "get native object fail");
3007 return nullptr;
3008 }
3009 return result;
3010 }
3011
EnableMacro(napi_env env,napi_callback_info info)3012 napi_value CameraSessionNapi::EnableMacro(napi_env env, napi_callback_info info)
3013 {
3014 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr, "SystemApi EnableMacro is called!");
3015 MEDIA_DEBUG_LOG("CameraSessionNapi::EnableMacro is called");
3016 bool isEnableMacro;
3017 CameraSessionNapi* cameraSessionNapi = nullptr;
3018 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi, isEnableMacro);
3019 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"), nullptr,
3020 "CameraSessionNapi::EnableMacro parse parameter occur error");
3021
3022 if (cameraSessionNapi->cameraSession_ != nullptr) {
3023 MEDIA_INFO_LOG("CameraSessionNapi::EnableMacro:%{public}d", isEnableMacro);
3024 cameraSessionNapi->cameraSession_->LockForControl();
3025 int32_t retCode = cameraSessionNapi->cameraSession_->EnableMacro(isEnableMacro);
3026 cameraSessionNapi->cameraSession_->UnlockForControl();
3027 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiUtils::CheckError(env, retCode), nullptr,
3028 "CameraSessionNapi::EnableMacro fail %{public}d", retCode);
3029 } else {
3030 MEDIA_ERR_LOG("CameraSessionNapi::EnableMacro get native object fail");
3031 CameraNapiUtils::ThrowError(env, INVALID_ARGUMENT, "get native object fail");
3032 return nullptr;
3033 }
3034 return CameraNapiUtils::GetUndefinedValue(env);
3035 }
3036
IsDepthFusionSupported(napi_env env,napi_callback_info info)3037 napi_value CameraSessionNapi::IsDepthFusionSupported(napi_env env, napi_callback_info info)
3038 {
3039 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
3040 "SystemApi GetDepthFusionThreshold is called!");
3041 MEDIA_DEBUG_LOG("CameraSessionNapi::IsDepthFusionSupported is called");
3042 CameraSessionNapi* cameraSessionNapi = nullptr;
3043 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi);
3044 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"), nullptr,
3045 "CameraSessionNapi::IsDepthFusionSupported parse parameter occur error");
3046 auto result = CameraNapiUtils::GetUndefinedValue(env);
3047 if (cameraSessionNapi->cameraSession_ != nullptr) {
3048 bool isSupported = cameraSessionNapi->cameraSession_->IsDepthFusionSupported();
3049 napi_get_boolean(env, isSupported, &result);
3050 return result;
3051 } else {
3052 MEDIA_ERR_LOG("CameraSessionNapi::IsDepthFusionSupported call Failed!");
3053 CameraNapiUtils::ThrowError(env, INVALID_ARGUMENT, "get native object fail");
3054 return nullptr;
3055 }
3056 return result;
3057 }
3058
GetDepthFusionThreshold(napi_env env,napi_callback_info info)3059 napi_value CameraSessionNapi::GetDepthFusionThreshold(napi_env env, napi_callback_info info)
3060 {
3061 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
3062 "SystemApi GetDepthFusionThreshold is called!");
3063 MEDIA_DEBUG_LOG("CameraSessionNapi::GetDepthFusionThreshold is called");
3064 CameraSessionNapi* cameraSessionNapi = nullptr;
3065 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi);
3066 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"), nullptr,
3067 "CameraSessionNapi::IsDepthFusionSupported parse parameter occur error");
3068 napi_value result = nullptr;
3069 if (cameraSessionNapi->cameraSession_ != nullptr) {
3070 std::vector<float> vecDepthFusionThreshold;
3071 int32_t retCode = cameraSessionNapi->cameraSession_->GetDepthFusionThreshold(vecDepthFusionThreshold);
3072 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
3073 MEDIA_INFO_LOG("CameraSessionNapi::GetDepthFusionThreshold len = %{public}zu",
3074 vecDepthFusionThreshold.size());
3075
3076 if (!vecDepthFusionThreshold.empty() && napi_create_array(env, &result) == napi_ok) {
3077 for (size_t i = 0; i < vecDepthFusionThreshold.size(); i++) {
3078 float depthFusion = vecDepthFusionThreshold[i];
3079 napi_value value;
3080 napi_create_double(env, CameraNapiUtils::FloatToDouble(depthFusion), &value);
3081 napi_set_element(env, result, i, value);
3082 }
3083 } else {
3084 MEDIA_ERR_LOG("vecDepthFusionThreshold is empty or failed to create array!");
3085 }
3086 } else {
3087 MEDIA_ERR_LOG("CameraSessionNapi::GetDepthFusionThreshold call Failed!");
3088 return nullptr;
3089 }
3090 return result;
3091 }
3092
IsDepthFusionEnabled(napi_env env,napi_callback_info info)3093 napi_value CameraSessionNapi::IsDepthFusionEnabled(napi_env env, napi_callback_info info)
3094 {
3095 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
3096 "SystemApi IsDepthFusionEnabled is called!");
3097 MEDIA_DEBUG_LOG("CameraSessionNapi::IsDepthFusionEnabled is called");
3098 CameraSessionNapi* cameraSessionNapi = nullptr;
3099 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi);
3100 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"), nullptr,
3101 "CameraSessionNapi::IsDepthFusionEnabled parse parameter occur error");
3102 auto result = CameraNapiUtils::GetUndefinedValue(env);
3103 if (cameraSessionNapi->cameraSession_ != nullptr) {
3104 bool isEnabled = cameraSessionNapi->cameraSession_->IsDepthFusionEnabled();
3105 napi_get_boolean(env, isEnabled, &result);
3106 MEDIA_INFO_LOG("CameraSessionNapi::IsDepthFusionEnabled:%{public}d", isEnabled);
3107 } else {
3108 MEDIA_ERR_LOG("CameraSessionNapi::IsDepthFusionEnabled get native object fail");
3109 CameraNapiUtils::ThrowError(env, INVALID_ARGUMENT, "get native object fail");
3110 return nullptr;
3111 }
3112 return result;
3113 }
3114
EnableDepthFusion(napi_env env,napi_callback_info info)3115 napi_value CameraSessionNapi::EnableDepthFusion(napi_env env, napi_callback_info info)
3116 {
3117 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
3118 "SystemApi EnableDepthFusion is called!");
3119 MEDIA_DEBUG_LOG("CameraSessionNapi::EnableDepthFusion is called");
3120 bool isEnabledDepthFusion;
3121 CameraSessionNapi* cameraSessionNapi = nullptr;
3122 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi, isEnabledDepthFusion);
3123 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"), nullptr,
3124 "CameraSessionNapi::EnabledDepthFusion parse parameter occur error");
3125
3126 if (cameraSessionNapi->cameraSession_ != nullptr) {
3127 MEDIA_INFO_LOG("CameraSessionNapi::EnableDepthFusion:%{public}d", isEnabledDepthFusion);
3128 cameraSessionNapi->cameraSession_->LockForControl();
3129 int32_t retCode = cameraSessionNapi->cameraSession_->EnableDepthFusion(isEnabledDepthFusion);
3130 cameraSessionNapi->cameraSession_->UnlockForControl();
3131 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiUtils::CheckError(env, retCode), nullptr,
3132 "CameraSessionNapi::EnableDepthFusion fail %{public}d", retCode);
3133 MEDIA_INFO_LOG("CameraSessionNapi::EnableDepthFusion success");
3134 } else {
3135 MEDIA_ERR_LOG("CameraSessionNapi::EnableDepthFusion get native object fail");
3136 CameraNapiUtils::ThrowError(env, INVALID_ARGUMENT, "get native object fail");
3137 return nullptr;
3138 }
3139 return CameraNapiUtils::GetUndefinedValue(env);
3140 }
3141
IsMoonCaptureBoostSupported(napi_env env,napi_callback_info info)3142 napi_value CameraSessionNapi::IsMoonCaptureBoostSupported(napi_env env, napi_callback_info info)
3143 {
3144 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
3145 "SystemApi IsMoonCaptureBoostSupported is called!");
3146 MEDIA_DEBUG_LOG("IsMoonCaptureBoostSupported is called");
3147 napi_status status;
3148 napi_value result = nullptr;
3149 size_t argc = ARGS_ZERO;
3150 napi_value argv[ARGS_ZERO];
3151 napi_value thisVar = nullptr;
3152
3153 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
3154
3155 napi_get_undefined(env, &result);
3156 CameraSessionNapi* cameraSessionNapi = nullptr;
3157 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
3158 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
3159 bool isSupported = cameraSessionNapi->cameraSession_->IsMoonCaptureBoostSupported();
3160 napi_get_boolean(env, isSupported, &result);
3161 } else {
3162 MEDIA_ERR_LOG("IsMoonCaptureBoostSupported call Failed!");
3163 }
3164 return result;
3165 }
3166
EnableMoonCaptureBoost(napi_env env,napi_callback_info info)3167 napi_value CameraSessionNapi::EnableMoonCaptureBoost(napi_env env, napi_callback_info info)
3168 {
3169 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
3170 "SystemApi EnableMoonCaptureBoost is called!");
3171 MEDIA_DEBUG_LOG("EnableMoonCaptureBoost is called");
3172 napi_status status;
3173 napi_value result = nullptr;
3174 size_t argc = ARGS_ONE;
3175 napi_value argv[ARGS_ONE] = { 0 };
3176 napi_value thisVar = nullptr;
3177 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
3178 NAPI_ASSERT(env, argc == ARGS_ONE, "requires one parameter");
3179 napi_valuetype valueType = napi_undefined;
3180 napi_typeof(env, argv[0], &valueType);
3181 CHECK_ERROR_RETURN_RET(valueType != napi_boolean && !CameraNapiUtils::CheckError(env, INVALID_ARGUMENT), result);
3182 napi_get_undefined(env, &result);
3183 CameraSessionNapi* cameraSessionNapi = nullptr;
3184 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
3185 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
3186 bool isEnableMoonCaptureBoost;
3187 napi_get_value_bool(env, argv[PARAM0], &isEnableMoonCaptureBoost);
3188 MEDIA_INFO_LOG("CameraSessionNapi::EnableMoonCaptureBoost:%{public}d", isEnableMoonCaptureBoost);
3189 cameraSessionNapi->cameraSession_->LockForControl();
3190 int32_t retCode = cameraSessionNapi->cameraSession_->EnableMoonCaptureBoost(isEnableMoonCaptureBoost);
3191 cameraSessionNapi->cameraSession_->UnlockForControl();
3192 CHECK_ERROR_RETURN_RET(retCode != 0 && !CameraNapiUtils::CheckError(env, retCode), result);
3193 }
3194 return result;
3195 }
3196
IsFeatureSupported(napi_env env,napi_callback_info info)3197 napi_value CameraSessionNapi::IsFeatureSupported(napi_env env, napi_callback_info info)
3198 {
3199 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
3200 "SystemApi IsFeatureSupported is called!");
3201 MEDIA_DEBUG_LOG("IsFeatureSupported is called");
3202 int32_t sceneFeature;
3203 CameraSessionNapi* cameraSessionNapi = nullptr;
3204 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi, sceneFeature);
3205 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"), nullptr,
3206 "CameraSessionNapi::IsFeatureSupported parse parameter occur error");
3207
3208 napi_value result = nullptr;
3209 napi_get_boolean(
3210 env, cameraSessionNapi->cameraSession_->IsFeatureSupported(static_cast<SceneFeature>(sceneFeature)), &result);
3211 return result;
3212 }
3213
EnableFeature(napi_env env,napi_callback_info info)3214 napi_value CameraSessionNapi::EnableFeature(napi_env env, napi_callback_info info)
3215 {
3216 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr, "SystemApi EnableFeature is called!");
3217 MEDIA_DEBUG_LOG("EnableFeature is called");
3218 int32_t sceneFeature;
3219 bool isEnable;
3220 CameraSessionNapi* cameraSessionNapi = nullptr;
3221 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi, sceneFeature, isEnable);
3222 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"), nullptr,
3223 "CameraSessionNapi::EnableFeature parse parameter occur error");
3224
3225 MEDIA_INFO_LOG("CameraSessionNapi::EnableFeature:%{public}d", isEnable);
3226 int32_t retCode =
3227 cameraSessionNapi->cameraSession_->EnableFeature(static_cast<SceneFeature>(sceneFeature), isEnable);
3228 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
3229
3230 return CameraNapiUtils::GetUndefinedValue(env);
3231 }
3232
CanPreconfig(napi_env env,napi_callback_info info)3233 napi_value CameraSessionNapi::CanPreconfig(napi_env env, napi_callback_info info)
3234 {
3235 MEDIA_DEBUG_LOG("CanPreconfig is called");
3236 size_t argSize = CameraNapiUtils::GetNapiArgs(env, info);
3237 int32_t configType;
3238 int32_t profileSizeRatio = ProfileSizeRatio::UNSPECIFIED;
3239 CameraSessionNapi* cameraSessionNapi = nullptr;
3240 if (argSize == ARGS_ONE) {
3241 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi, configType);
3242 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"),
3243 nullptr, "CameraSessionNapi::CanPreconfig parse parameter occur error");
3244 } else {
3245 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi, configType, profileSizeRatio);
3246 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"),
3247 nullptr, "CameraSessionNapi::CanPreconfig parse 2 parameter occur error");
3248 }
3249
3250 MEDIA_INFO_LOG("CameraSessionNapi::CanPreconfig: %{public}d, ratioType:%{public}d", configType, profileSizeRatio);
3251 bool result = cameraSessionNapi->cameraSession_->CanPreconfig(
3252 static_cast<PreconfigType>(configType), static_cast<ProfileSizeRatio>(profileSizeRatio));
3253 return CameraNapiUtils::GetBooleanValue(env, result);
3254 }
3255
Preconfig(napi_env env,napi_callback_info info)3256 napi_value CameraSessionNapi::Preconfig(napi_env env, napi_callback_info info)
3257 {
3258 MEDIA_DEBUG_LOG("Preconfig is called");
3259 size_t argSize = CameraNapiUtils::GetNapiArgs(env, info);
3260 int32_t configType;
3261 int32_t profileSizeRatio = ProfileSizeRatio::UNSPECIFIED;
3262 CameraSessionNapi* cameraSessionNapi = nullptr;
3263 if (argSize == ARGS_ONE) {
3264 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi, configType);
3265 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"),
3266 nullptr, "CameraSessionNapi::Preconfig parse parameter occur error");
3267 } else {
3268 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi, configType, profileSizeRatio);
3269 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"),
3270 nullptr, "CameraSessionNapi::Preconfig parse 2 parameter occur error");
3271 }
3272 int32_t retCode = cameraSessionNapi->cameraSession_->Preconfig(
3273 static_cast<PreconfigType>(configType), static_cast<ProfileSizeRatio>(profileSizeRatio));
3274 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
3275 return CameraNapiUtils::GetUndefinedValue(env);
3276 }
3277
GetCameraOutputCapabilities(napi_env env,napi_callback_info info)3278 napi_value CameraSessionNapi::GetCameraOutputCapabilities(napi_env env, napi_callback_info info)
3279 {
3280 MEDIA_INFO_LOG("GetCameraOutputCapabilities is called");
3281
3282 size_t argSize = CameraNapiUtils::GetNapiArgs(env, info);
3283 if (argSize != ARGS_ONE) {
3284 CameraNapiUtils::ThrowError(env, INVALID_ARGUMENT, "Invalid argument.");
3285 return nullptr;
3286 }
3287
3288 std::string cameraId;
3289 CameraNapiObject cameraInfoObj { { { "cameraId", &cameraId } } };
3290 CameraSessionNapi* cameraSessionNapi = nullptr;
3291 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi, cameraInfoObj);
3292
3293 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "Create cameraInput invalid argument!"),
3294 nullptr, "CameraSessionNapi::GetCameraOutputCapabilities invalid argument");
3295
3296 sptr<CameraDevice> cameraInfo = CameraManager::GetInstance()->GetCameraDeviceFromId(cameraId);
3297 if (cameraInfo == nullptr) {
3298 MEDIA_ERR_LOG("cameraInfo is null");
3299 CameraNapiUtils::ThrowError(env, SERVICE_FATL_ERROR, "cameraInfo is null.");
3300 return nullptr;
3301 }
3302
3303 std::vector<sptr<CameraOutputCapability>> caplist =
3304 cameraSessionNapi->cameraSession_->GetCameraOutputCapabilities(cameraInfo);
3305 CHECK_ERROR_RETURN_RET_LOG(caplist.empty(), nullptr, "caplist is empty");
3306
3307 napi_value capArray;
3308 napi_status status = napi_create_array(env, &capArray);
3309 CHECK_ERROR_RETURN_RET_LOG(status != napi_ok, nullptr, "Failed to create napi array");
3310
3311 for (size_t i = 0; i < caplist.size(); i++) {
3312 if (caplist[i] == nullptr) {
3313 continue;
3314 }
3315 caplist[i]->RemoveDuplicatesProfiles();
3316 napi_value cap = CameraNapiObjCameraOutputCapability(*caplist[i]).GenerateNapiValue(env);
3317 CHECK_ERROR_RETURN_RET_LOG(cap == nullptr || napi_set_element(env, capArray, i, cap) != napi_ok, nullptr,
3318 "Failed to create camera napi wrapper object");
3319 }
3320
3321 return capArray;
3322 }
3323
ParseSize(napi_env env,napi_value root,Size & size)3324 void ParseSize(napi_env env, napi_value root, Size& size)
3325 {
3326 MEDIA_DEBUG_LOG("ParseSize is called");
3327 napi_value res = nullptr;
3328 CHECK_EXECUTE(napi_get_named_property(env, root, "width", &res) == napi_ok,
3329 napi_get_value_uint32(env, res, &size.width));
3330
3331 CHECK_EXECUTE(napi_get_named_property(env, root, "height", &res) == napi_ok,
3332 napi_get_value_uint32(env, res, &size.height));
3333 }
3334
ParseProfile(napi_env env,napi_value root,Profile & profile)3335 void ParseProfile(napi_env env, napi_value root, Profile& profile)
3336 {
3337 MEDIA_DEBUG_LOG("ParseProfile is called");
3338 napi_value res = nullptr;
3339
3340 CHECK_EXECUTE(napi_get_named_property(env, root, "size", &res) == napi_ok, ParseSize(env, res, profile.size_));
3341
3342 int32_t intValue = 0;
3343 if (napi_get_named_property(env, root, "format", &res) == napi_ok) {
3344 napi_get_value_int32(env, res, &intValue);
3345 profile.format_ = static_cast<CameraFormat>(intValue);
3346 }
3347 }
3348
ParseVideoProfile(napi_env env,napi_value root,VideoProfile & profile)3349 void ParseVideoProfile(napi_env env, napi_value root, VideoProfile& profile)
3350 {
3351 MEDIA_DEBUG_LOG("ParseVideoProfile is called");
3352 napi_value res = nullptr;
3353
3354 CHECK_EXECUTE(napi_get_named_property(env, root, "size", &res) == napi_ok, ParseSize(env, res, profile.size_));
3355
3356 int32_t intValue = 0;
3357 if (napi_get_named_property(env, root, "format", &res) == napi_ok) {
3358 napi_get_value_int32(env, res, &intValue);
3359 profile.format_ = static_cast<CameraFormat>(intValue);
3360 }
3361
3362 if (napi_get_named_property(env, root, "frameRateRange", &res) == napi_ok) {
3363 const int32_t LENGTH = 2;
3364 std::vector<int32_t> rateRanges(LENGTH);
3365 napi_value value;
3366
3367 CHECK_EXECUTE(napi_get_named_property(env, res, "min", &value) == napi_ok,
3368 napi_get_value_int32(env, value, &rateRanges[0]));
3369 CHECK_EXECUTE(napi_get_named_property(env, res, "max", &value) == napi_ok,
3370 napi_get_value_int32(env, value, &rateRanges[1]));
3371 profile.framerates_ = rateRanges;
3372 }
3373 }
3374
3375
ParseProfileList(napi_env env,napi_value arrayParam,std::vector<Profile> & profiles)3376 void ParseProfileList(napi_env env, napi_value arrayParam, std::vector<Profile> &profiles)
3377 {
3378 uint32_t length = 0;
3379 napi_get_array_length(env, arrayParam, &length);
3380 for (uint32_t i = 0; i < length; ++i) {
3381 napi_value value;
3382 napi_get_element(env, arrayParam, i, &value);
3383 Profile profile; // 在栈上创建 Profile 对象
3384 ParseProfile(env, value, profile);
3385 profiles.push_back(profile);
3386 }
3387 }
3388
ParseVideoProfileList(napi_env env,napi_value arrayParam,std::vector<VideoProfile> & profiles)3389 void ParseVideoProfileList(napi_env env, napi_value arrayParam, std::vector<VideoProfile> &profiles)
3390 {
3391 uint32_t length = 0;
3392 napi_get_array_length(env, arrayParam, &length);
3393 for (uint32_t i = 0; i < length; ++i) {
3394 napi_value value;
3395 napi_get_element(env, arrayParam, i, &value);
3396 VideoProfile profile;
3397 ParseVideoProfile(env, value, profile);
3398 profiles.push_back(profile);
3399 }
3400 }
3401
ParseCameraOutputCapability(napi_env env,napi_value root,std::vector<Profile> & previewProfiles,std::vector<Profile> & photoProfiles,std::vector<VideoProfile> & videoProfiles)3402 void ParseCameraOutputCapability(napi_env env, napi_value root,
3403 std::vector<Profile>& previewProfiles,
3404 std::vector<Profile>& photoProfiles,
3405 std::vector<VideoProfile>& videoProfiles)
3406 {
3407 previewProfiles.clear();
3408 photoProfiles.clear();
3409 videoProfiles.clear();
3410 napi_value res = nullptr;
3411
3412 CHECK_EXECUTE(napi_get_named_property(env, root, "previewProfiles", &res) == napi_ok,
3413 ParseProfileList(env, res, previewProfiles));
3414 CHECK_EXECUTE(napi_get_named_property(env, root, "photoProfiles", &res) == napi_ok,
3415 ParseProfileList(env, res, photoProfiles));
3416 CHECK_EXECUTE(napi_get_named_property(env, root, "videoProfiles", &res) == napi_ok,
3417 ParseVideoProfileList(env, res, videoProfiles));
3418 }
3419
GetSessionFunctions(napi_env env,napi_callback_info info)3420 napi_value CameraSessionNapi::GetSessionFunctions(napi_env env, napi_callback_info info)
3421 {
3422 MEDIA_INFO_LOG("GetSessionFunctions is called");
3423 napi_status status;
3424 napi_value result = nullptr;
3425 size_t argc = ARGS_ONE;
3426 napi_value argv[ARGS_ONE] = {0};
3427 napi_value thisVar = nullptr;
3428
3429 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
3430
3431 std::vector<Profile> previewProfiles;
3432 std::vector<Profile> photoProfiles;
3433 std::vector<VideoProfile> videoProfiles;
3434 ParseCameraOutputCapability(env, argv[PARAM0], previewProfiles, photoProfiles, videoProfiles);
3435 CameraSessionNapi* cameraSessionNapi = nullptr;
3436 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
3437 CHECK_ERROR_RETURN_RET_LOG(status != napi_ok || cameraSessionNapi == nullptr, nullptr, "napi_unwrap failure!");
3438
3439 auto session = cameraSessionNapi->cameraSession_;
3440 SceneMode mode = session->GetMode();
3441 auto cameraFunctionsList = session->GetSessionFunctions(previewProfiles, photoProfiles, videoProfiles);
3442 auto it = modeToFunctionTypeMap_.find(mode);
3443 if (it != modeToFunctionTypeMap_.end()) {
3444 result = CreateFunctionsJSArray(env, cameraFunctionsList, it->second);
3445 } else {
3446 MEDIA_ERR_LOG("GetSessionFunctions failed due to unsupported mode: %{public}d", mode);
3447 }
3448 return result;
3449 }
3450
GetSessionConflictFunctions(napi_env env,napi_callback_info info)3451 napi_value CameraSessionNapi::GetSessionConflictFunctions(napi_env env, napi_callback_info info)
3452 {
3453 MEDIA_INFO_LOG("GetSessionConflictFunctions is called");
3454 napi_status status;
3455 napi_value result = nullptr;
3456 size_t argc = ARGS_ONE;
3457 napi_value argv[ARGS_ONE];
3458 napi_value thisVar = nullptr;
3459
3460 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
3461
3462 napi_get_undefined(env, &result);
3463
3464 CameraSessionNapi* cameraSessionNapi = nullptr;
3465 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
3466 CHECK_ERROR_RETURN_RET_LOG(status != napi_ok || cameraSessionNapi == nullptr, nullptr, "napi_unwrap failure!");
3467
3468 auto session = cameraSessionNapi->cameraSession_;
3469 SceneMode mode = session->GetMode();
3470 auto conflictFunctionsList = session->GetSessionConflictFunctions();
3471 auto it = modeToConflictFunctionTypeMap_.find(mode);
3472 if (it != modeToConflictFunctionTypeMap_.end()) {
3473 result = CreateFunctionsJSArray(env, conflictFunctionsList, it->second);
3474 } else {
3475 MEDIA_ERR_LOG("GetSessionConflictFunctions failed due to unsupported mode: %{public}d", mode);
3476 }
3477 return result;
3478 }
3479
CreateFunctionsJSArray(napi_env env,std::vector<sptr<CameraAbility>> functionsList,FunctionsType type)3480 napi_value CameraSessionNapi::CreateFunctionsJSArray(
3481 napi_env env, std::vector<sptr<CameraAbility>> functionsList, FunctionsType type)
3482 {
3483 MEDIA_DEBUG_LOG("CreateFunctionsJSArray is called");
3484 napi_value functionsArray = nullptr;
3485 napi_value functions = nullptr;
3486 napi_status status;
3487
3488 CHECK_ERROR_PRINT_LOG(functionsList.empty(), "functionsList is empty");
3489
3490 status = napi_create_array(env, &functionsArray);
3491 CHECK_ERROR_RETURN_RET_LOG(status != napi_ok, functionsArray, "napi_create_array failed");
3492
3493 size_t j = 0;
3494 for (size_t i = 0; i < functionsList.size(); i++) {
3495 functions = CameraFunctionsNapi::CreateCameraFunctions(env, functionsList[i], type);
3496 CHECK_ERROR_RETURN_RET_LOG((functions == nullptr) ||
3497 napi_set_element(env, functionsArray, j++, functions) != napi_ok, nullptr,
3498 "failed to create functions object napi wrapper object");
3499 }
3500 MEDIA_INFO_LOG("create functions count = %{public}zu", j);
3501 return functionsArray;
3502 }
3503
IsEffectSuggestionSupported(napi_env env,napi_callback_info info)3504 napi_value CameraSessionNapi::IsEffectSuggestionSupported(napi_env env, napi_callback_info info)
3505 {
3506 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env, false), nullptr,
3507 "SystemApi IsEffectSuggestionSupported is called!");
3508 MEDIA_DEBUG_LOG("IsEffectSuggestionSupported is called");
3509 napi_status status;
3510 napi_value result = nullptr;
3511 size_t argc = ARGS_ZERO;
3512 napi_value argv[ARGS_ZERO];
3513 napi_value thisVar = nullptr;
3514
3515 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
3516
3517 napi_get_undefined(env, &result);
3518 CameraSessionNapi* cameraSessionNapi = nullptr;
3519 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
3520 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
3521 bool isEffectSuggestionSupported = cameraSessionNapi->cameraSession_->IsEffectSuggestionSupported();
3522 napi_get_boolean(env, isEffectSuggestionSupported, &result);
3523 } else {
3524 MEDIA_ERR_LOG("IsEffectSuggestionSupported call Failed!");
3525 }
3526 return result;
3527 }
3528
EnableEffectSuggestion(napi_env env,napi_callback_info info)3529 napi_value CameraSessionNapi::EnableEffectSuggestion(napi_env env, napi_callback_info info)
3530 {
3531 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env, false), nullptr,
3532 "SystemApi EnableEffectSuggestion is called!");
3533 MEDIA_DEBUG_LOG("EnableEffectSuggestion is called");
3534 napi_status status;
3535 napi_value result = nullptr;
3536 size_t argc = ARGS_ONE;
3537 napi_value argv[ARGS_ONE] = { 0 };
3538 napi_value thisVar = nullptr;
3539 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
3540 NAPI_ASSERT(env, argc == ARGS_ONE, "requires one parameter");
3541 napi_valuetype valueType = napi_undefined;
3542 napi_typeof(env, argv[0], &valueType);
3543 CHECK_ERROR_RETURN_RET(valueType != napi_boolean && !CameraNapiUtils::CheckError(env, INVALID_ARGUMENT), result);
3544 napi_get_undefined(env, &result);
3545 CameraSessionNapi* cameraSessionNapi = nullptr;
3546 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
3547 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
3548 bool enabled;
3549 napi_get_value_bool(env, argv[PARAM0], &enabled);
3550 MEDIA_INFO_LOG("CameraSessionNapi::EnableEffectSuggestion:%{public}d", enabled);
3551 cameraSessionNapi->cameraSession_->LockForControl();
3552 int32_t retCode = cameraSessionNapi->cameraSession_->EnableEffectSuggestion(enabled);
3553 cameraSessionNapi->cameraSession_->UnlockForControl();
3554 CHECK_ERROR_RETURN_RET(retCode != 0 && !CameraNapiUtils::CheckError(env, retCode), result);
3555 }
3556 return result;
3557 }
3558
GetSupportedEffectSuggestionType(napi_env env,napi_callback_info info)3559 napi_value CameraSessionNapi::GetSupportedEffectSuggestionType(napi_env env, napi_callback_info info)
3560 {
3561 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env, false), nullptr,
3562 "SystemApi GetSupportedEffectSuggestionType is called!");
3563 MEDIA_DEBUG_LOG("GetSupportedEffectSuggestionType is called");
3564 napi_status status;
3565 napi_value result = nullptr;
3566 size_t argc = ARGS_ZERO;
3567 napi_value argv[ARGS_ZERO];
3568 napi_value thisVar = nullptr;
3569
3570 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
3571
3572 napi_get_undefined(env, &result);
3573 status = napi_create_array(env, &result);
3574 CHECK_ERROR_RETURN_RET_LOG(status != napi_ok, result, "napi_create_array call Failed!");
3575 CameraSessionNapi* cameraSessionNapi = nullptr;
3576 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
3577 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
3578 std::vector<EffectSuggestionType> effectSuggestionTypeList =
3579 cameraSessionNapi->cameraSession_->GetSupportedEffectSuggestionType();
3580 if (!effectSuggestionTypeList.empty()) {
3581 for (size_t i = 0; i < effectSuggestionTypeList.size(); i++) {
3582 int type = effectSuggestionTypeList[i];
3583 napi_value value;
3584 napi_create_int32(env, type, &value);
3585 napi_set_element(env, result, i, value);
3586 }
3587 }
3588 } else {
3589 MEDIA_ERR_LOG("GetSupportedEffectSuggestionType call Failed!");
3590 }
3591 return result;
3592 }
3593
ParseEffectSuggestionStatus(napi_env env,napi_value arrayParam,std::vector<EffectSuggestionStatus> & effectSuggestionStatusList)3594 static void ParseEffectSuggestionStatus(napi_env env, napi_value arrayParam,
3595 std::vector<EffectSuggestionStatus> &effectSuggestionStatusList)
3596 {
3597 MEDIA_DEBUG_LOG("ParseEffectSuggestionStatus is called");
3598 uint32_t length = 0;
3599 napi_value value;
3600 napi_get_array_length(env, arrayParam, &length);
3601 for (uint32_t i = 0; i < length; i++) {
3602 napi_get_element(env, arrayParam, i, &value);
3603 napi_value res = nullptr;
3604 EffectSuggestionStatus effectSuggestionStatus;
3605 int32_t intValue = 0;
3606 if (napi_get_named_property(env, value, "type", &res) == napi_ok) {
3607 napi_get_value_int32(env, res, &intValue);
3608 effectSuggestionStatus.type = static_cast<EffectSuggestionType>(intValue);
3609 }
3610 bool enabled = false;
3611 if (napi_get_named_property(env, value, "status", &res) == napi_ok) {
3612 napi_get_value_bool(env, res, &enabled);
3613 effectSuggestionStatus.status = enabled;
3614 }
3615 effectSuggestionStatusList.push_back(effectSuggestionStatus);
3616 }
3617 }
3618
SetEffectSuggestionStatus(napi_env env,napi_callback_info info)3619 napi_value CameraSessionNapi::SetEffectSuggestionStatus(napi_env env, napi_callback_info info)
3620 {
3621 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env, false), nullptr,
3622 "SystemApi SetEffectSuggestionStatus is called!");
3623 MEDIA_INFO_LOG("SetEffectSuggestionStatus is called");
3624 napi_status status;
3625 napi_value result = nullptr;
3626 size_t argc = ARGS_ONE;
3627 napi_value argv[ARGS_ONE] = {0};
3628 napi_value thisVar = nullptr;
3629
3630 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
3631
3632 std::vector<EffectSuggestionStatus> effectSuggestionStatusList;
3633 ParseEffectSuggestionStatus(env, argv[PARAM0], effectSuggestionStatusList);
3634
3635 napi_get_undefined(env, &result);
3636 CameraSessionNapi* cameraSessionNapi = nullptr;
3637 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
3638 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
3639 cameraSessionNapi->cameraSession_->LockForControl();
3640 int32_t retCode = cameraSessionNapi->cameraSession_->SetEffectSuggestionStatus(effectSuggestionStatusList);
3641 cameraSessionNapi->cameraSession_->UnlockForControl();
3642 CHECK_ERROR_RETURN_RET(retCode != 0 && !CameraNapiUtils::CheckError(env, retCode), result);
3643 }
3644 return result;
3645 }
3646
UpdateEffectSuggestion(napi_env env,napi_callback_info info)3647 napi_value CameraSessionNapi::UpdateEffectSuggestion(napi_env env, napi_callback_info info)
3648 {
3649 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env, false), nullptr,
3650 "SystemApi UpdateEffectSuggestion is called!");
3651 MEDIA_DEBUG_LOG("UpdateEffectSuggestion is called");
3652 napi_status status;
3653 napi_value result = nullptr;
3654 size_t argc = ARGS_TWO;
3655 napi_value argv[ARGS_TWO] = { 0, 0 };
3656 napi_value thisVar = nullptr;
3657 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
3658 NAPI_ASSERT(env, argc == ARGS_TWO, "requires two parameter");
3659 napi_valuetype valueType = napi_undefined;
3660 napi_typeof(env, argv[PARAM0], &valueType);
3661 CHECK_ERROR_RETURN_RET(valueType != napi_number && !CameraNapiUtils::CheckError(env, INVALID_ARGUMENT), result);
3662 napi_typeof(env, argv[PARAM1], &valueType);
3663 CHECK_ERROR_RETURN_RET(valueType != napi_boolean && !CameraNapiUtils::CheckError(env, INVALID_ARGUMENT), result);
3664
3665 napi_get_undefined(env, &result);
3666 CameraSessionNapi* cameraSessionNapi = nullptr;
3667 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
3668 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
3669 int32_t value;
3670 napi_get_value_int32(env, argv[PARAM0], &value);
3671 auto effectSuggestionType = (EffectSuggestionType)value;
3672 bool enabled;
3673 napi_get_value_bool(env, argv[PARAM1], &enabled);
3674 MEDIA_INFO_LOG("CameraSessionNapi::UpdateEffectSuggestion:%{public}d enabled:%{public}d",
3675 effectSuggestionType, enabled);
3676 cameraSessionNapi->cameraSession_->LockForControl();
3677 int32_t retCode = cameraSessionNapi->cameraSession_->UpdateEffectSuggestion(effectSuggestionType, enabled);
3678 cameraSessionNapi->cameraSession_->UnlockForControl();
3679 CHECK_ERROR_RETURN_RET(retCode != 0 && !CameraNapiUtils::CheckError(env, retCode), result);
3680 }
3681 return result;
3682 }
3683
3684 // ------------------------------------------------auto_awb_props-------------------------------------------------------
GetSupportedWhiteBalanceModes(napi_env env,napi_callback_info info)3685 napi_value CameraSessionNapi::GetSupportedWhiteBalanceModes(napi_env env, napi_callback_info info)
3686 {
3687 MEDIA_DEBUG_LOG("GetSupportedWhiteBalanceModes is called");
3688 napi_status status;
3689 napi_value result = nullptr;
3690 size_t argc = ARGS_ZERO;
3691 napi_value argv[ARGS_ZERO];
3692 napi_value thisVar = nullptr;
3693
3694 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
3695
3696 napi_get_undefined(env, &result);
3697 status = napi_create_array(env, &result);
3698 CHECK_ERROR_RETURN_RET_LOG(status != napi_ok, result, "napi_create_array call Failed!");
3699 CameraSessionNapi* cameraSessionNapi = nullptr;
3700 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
3701 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
3702 std::vector<WhiteBalanceMode> whiteBalanceModes;
3703 int32_t retCode = cameraSessionNapi->cameraSession_->GetSupportedWhiteBalanceModes(whiteBalanceModes);
3704 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
3705
3706 MEDIA_INFO_LOG("ProfessionSessionNapi::GetSupportedWhiteBalanceModes len = %{public}zu",
3707 whiteBalanceModes.size());
3708 if (!whiteBalanceModes.empty()) {
3709 for (size_t i = 0; i < whiteBalanceModes.size(); i++) {
3710 WhiteBalanceMode whiteBalanceMode = whiteBalanceModes[i];
3711 napi_value value;
3712 napi_create_int32(env, whiteBalanceMode, &value);
3713 napi_set_element(env, result, i, value);
3714 }
3715 }
3716 } else {
3717 MEDIA_ERR_LOG("GetSupportedWhiteBalanceModes call Failed!");
3718 }
3719 return result;
3720 }
3721
IsWhiteBalanceModeSupported(napi_env env,napi_callback_info info)3722 napi_value CameraSessionNapi::IsWhiteBalanceModeSupported(napi_env env, napi_callback_info info)
3723 {
3724 MEDIA_DEBUG_LOG("IsWhiteBalanceModeSupported is called");
3725 napi_status status;
3726 napi_value result = nullptr;
3727 size_t argc = ARGS_ONE;
3728 napi_value argv[ARGS_ONE] = {0};
3729 napi_value thisVar = nullptr;
3730
3731 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
3732
3733 napi_get_undefined(env, &result);
3734 CameraSessionNapi* cameraSessionNapi = nullptr;
3735 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
3736 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
3737 int32_t value;
3738 napi_get_value_int32(env, argv[PARAM0], &value);
3739 WhiteBalanceMode mode = (WhiteBalanceMode)value;
3740 bool isSupported;
3741 int32_t retCode = cameraSessionNapi->cameraSession_->IsWhiteBalanceModeSupported(mode, isSupported);
3742 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
3743 napi_get_boolean(env, isSupported, &result);
3744 } else {
3745 MEDIA_ERR_LOG("IsWhiteBalanceModeSupported call Failed!");
3746 }
3747 return result;
3748 }
3749
GetWhiteBalanceMode(napi_env env,napi_callback_info info)3750 napi_value CameraSessionNapi::GetWhiteBalanceMode(napi_env env, napi_callback_info info)
3751 {
3752 MEDIA_DEBUG_LOG("GetWhiteBalanceMode is called");
3753 napi_status status;
3754 napi_value result = nullptr;
3755 size_t argc = ARGS_ZERO;
3756 napi_value argv[ARGS_ZERO];
3757 napi_value thisVar = nullptr;
3758
3759 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
3760
3761 napi_get_undefined(env, &result);
3762 CameraSessionNapi* cameraSessionNapi = nullptr;
3763 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
3764 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
3765 WhiteBalanceMode whiteBalanceMode;
3766 int32_t retCode = cameraSessionNapi->cameraSession_->GetWhiteBalanceMode(whiteBalanceMode);
3767 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
3768 napi_create_int32(env, whiteBalanceMode, &result);
3769 } else {
3770 MEDIA_ERR_LOG("GetWhiteBalanceMode call Failed!");
3771 }
3772 return result;
3773 }
3774
SetWhiteBalanceMode(napi_env env,napi_callback_info info)3775 napi_value CameraSessionNapi::SetWhiteBalanceMode(napi_env env, napi_callback_info info)
3776 {
3777 MEDIA_DEBUG_LOG("SetWhiteBalanceMode is called");
3778 CAMERA_SYNC_TRACE;
3779 napi_status status;
3780 napi_value result = nullptr;
3781 size_t argc = ARGS_ONE;
3782 napi_value argv[ARGS_ONE] = {0};
3783 napi_value thisVar = nullptr;
3784
3785 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
3786
3787 napi_get_undefined(env, &result);
3788 CameraSessionNapi* cameraSessionNapi = nullptr;
3789 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
3790 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
3791 int32_t value;
3792 napi_get_value_int32(env, argv[PARAM0], &value);
3793 WhiteBalanceMode mode = (WhiteBalanceMode)value;
3794 cameraSessionNapi->cameraSession_->LockForControl();
3795 cameraSessionNapi->cameraSession_->SetWhiteBalanceMode(mode);
3796 MEDIA_INFO_LOG("ProfessionSessionNapi::SetWhiteBalanceMode set mode:%{public}d", value);
3797 cameraSessionNapi->cameraSession_->UnlockForControl();
3798 } else {
3799 MEDIA_ERR_LOG("SetWhiteBalanceMode call Failed!");
3800 }
3801 return result;
3802 }
3803
3804 // -----------------------------------------------manual_awb_props------------------------------------------------------
GetManualWhiteBalanceRange(napi_env env,napi_callback_info info)3805 napi_value CameraSessionNapi::GetManualWhiteBalanceRange(napi_env env, napi_callback_info info)
3806 {
3807 MEDIA_DEBUG_LOG("GetManualWhiteBalanceRange is called");
3808 napi_status status;
3809 napi_value result = nullptr;
3810 size_t argc = ARGS_ZERO;
3811 napi_value argv[ARGS_ZERO];
3812 napi_value thisVar = nullptr;
3813
3814 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
3815
3816 napi_get_undefined(env, &result);
3817
3818 CameraSessionNapi* cameraSessionNapi = nullptr;
3819 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
3820 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
3821 std::vector<int32_t> whiteBalanceRange = {};
3822 int32_t retCode = cameraSessionNapi->cameraSession_->GetManualWhiteBalanceRange(whiteBalanceRange);
3823 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
3824 MEDIA_INFO_LOG("ProfessionSessionNapi::GetManualWhiteBalanceRange len = %{public}zu", whiteBalanceRange.size());
3825
3826 if (!whiteBalanceRange.empty() && napi_create_array(env, &result) == napi_ok) {
3827 for (size_t i = 0; i < whiteBalanceRange.size(); i++) {
3828 int32_t iso = whiteBalanceRange[i];
3829 napi_value value;
3830 napi_create_int32(env, iso, &value);
3831 napi_set_element(env, result, i, value);
3832 }
3833 } else {
3834 MEDIA_ERR_LOG("whiteBalanceRange is empty or failed to create array!");
3835 }
3836 } else {
3837 MEDIA_ERR_LOG("GetManualWhiteBalanceRange call Failed!");
3838 }
3839 return result;
3840 }
3841
IsManualWhiteBalanceSupported(napi_env env,napi_callback_info info)3842 napi_value CameraSessionNapi::IsManualWhiteBalanceSupported(napi_env env, napi_callback_info info)
3843 {
3844 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
3845 "SystemApi IsManualIsoSupported is called!");
3846 MEDIA_DEBUG_LOG("IsManualIsoSupported is called");
3847 napi_status status;
3848 napi_value result = nullptr;
3849 size_t argc = ARGS_ZERO;
3850 napi_value argv[ARGS_ZERO];
3851 napi_value thisVar = nullptr;
3852
3853 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
3854
3855 napi_get_undefined(env, &result);
3856 CameraSessionNapi* cameraSessionNapi = nullptr;
3857 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
3858 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
3859 bool isSupported;
3860 int32_t retCode = cameraSessionNapi->cameraSession_->IsManualWhiteBalanceSupported(isSupported);
3861 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
3862 napi_get_boolean(env, isSupported, &result);
3863 } else {
3864 MEDIA_ERR_LOG("IsManualIsoSupported call Failed!");
3865 }
3866 return result;
3867 }
3868
GetManualWhiteBalance(napi_env env,napi_callback_info info)3869 napi_value CameraSessionNapi::GetManualWhiteBalance(napi_env env, napi_callback_info info)
3870 {
3871 MEDIA_DEBUG_LOG("GetISO is called");
3872 napi_status status;
3873 napi_value result = nullptr;
3874 size_t argc = ARGS_ZERO;
3875 napi_value argv[ARGS_ZERO];
3876 napi_value thisVar = nullptr;
3877
3878 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
3879
3880 napi_get_undefined(env, &result);
3881 CameraSessionNapi* cameraSessionNapi = nullptr;
3882 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
3883 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
3884 int32_t wbValue;
3885 int32_t retCode = cameraSessionNapi->cameraSession_->GetManualWhiteBalance(wbValue);
3886 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
3887 napi_create_int32(env, wbValue, &result);
3888 } else {
3889 MEDIA_ERR_LOG("GetISO call Failed!");
3890 }
3891 return result;
3892 }
3893
SetManualWhiteBalance(napi_env env,napi_callback_info info)3894 napi_value CameraSessionNapi::SetManualWhiteBalance(napi_env env, napi_callback_info info)
3895 {
3896 MEDIA_DEBUG_LOG("SetManualWhiteBalance is called");
3897 CAMERA_SYNC_TRACE;
3898 napi_status status;
3899 napi_value result = nullptr;
3900 size_t argc = ARGS_ONE;
3901 napi_value argv[ARGS_ONE] = {0};
3902 napi_value thisVar = nullptr;
3903
3904 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
3905
3906 napi_get_undefined(env, &result);
3907 CameraSessionNapi* cameraSessionNapi = nullptr;
3908 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraSessionNapi));
3909 if (status == napi_ok && cameraSessionNapi != nullptr && cameraSessionNapi->cameraSession_ != nullptr) {
3910 int32_t wbValue;
3911 napi_get_value_int32(env, argv[PARAM0], &wbValue);
3912 cameraSessionNapi->cameraSession_->LockForControl();
3913 cameraSessionNapi->cameraSession_->SetManualWhiteBalance(wbValue);
3914 MEDIA_INFO_LOG("ProfessionSessionNapi::SetManualWhiteBalance set wbValue:%{public}d", wbValue);
3915 cameraSessionNapi->cameraSession_->UnlockForControl();
3916 } else {
3917 MEDIA_ERR_LOG("SetManualWhiteBalance call Failed!");
3918 }
3919 return result;
3920 }
3921
GetSupportedVirtualApertures(napi_env env,napi_callback_info info)3922 napi_value CameraSessionNapi::GetSupportedVirtualApertures(napi_env env, napi_callback_info info)
3923 {
3924 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
3925 "SystemApi GetSupportedVirtualApertures is called!");
3926 MEDIA_DEBUG_LOG("GetSupportedVirtualApertures is called");
3927 CameraSessionNapi* cameraSessionNapi = nullptr;
3928 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi);
3929 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"), nullptr,
3930 "CameraSessionNapi::GetSupportedVirtualApertures parse parameter occur error");
3931
3932 napi_status status;
3933 napi_value result = nullptr;
3934 status = napi_create_array(env, &result);
3935 CHECK_ERROR_RETURN_RET_LOG(status != napi_ok, nullptr, "napi_create_array call Failed!");
3936
3937 if (cameraSessionNapi->cameraSession_ != nullptr) {
3938 std::vector<float> virtualApertures = {};
3939 int32_t retCode = cameraSessionNapi->cameraSession_->GetSupportedVirtualApertures(virtualApertures);
3940 MEDIA_INFO_LOG("GetSupportedVirtualApertures virtualApertures len = %{public}zu", virtualApertures.size());
3941 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
3942 if (!virtualApertures.empty()) {
3943 for (size_t i = 0; i < virtualApertures.size(); i++) {
3944 float virtualAperture = virtualApertures[i];
3945 napi_value value;
3946 napi_create_double(env, CameraNapiUtils::FloatToDouble(virtualAperture), &value);
3947 napi_set_element(env, result, i, value);
3948 }
3949 }
3950 } else {
3951 MEDIA_ERR_LOG("GetSupportedVirtualApertures call Failed!");
3952 }
3953 return result;
3954 }
3955
GetVirtualAperture(napi_env env,napi_callback_info info)3956 napi_value CameraSessionNapi::GetVirtualAperture(napi_env env, napi_callback_info info)
3957 {
3958 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
3959 "SystemApi GetVirtualAperture is called!");
3960 MEDIA_DEBUG_LOG("GetVirtualAperture is called");
3961 CameraSessionNapi* cameraSessionNapi = nullptr;
3962 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi);
3963 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"), nullptr,
3964 "CameraSessionNapi::GetVirtualAperture parse parameter occur error");
3965 if (cameraSessionNapi->cameraSession_ != nullptr) {
3966 float virtualAperture;
3967 int32_t retCode = cameraSessionNapi->cameraSession_->GetVirtualAperture(virtualAperture);
3968 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
3969 napi_value result;
3970 napi_create_double(env, CameraNapiUtils::FloatToDouble(virtualAperture), &result);
3971 return result;
3972 } else {
3973 MEDIA_ERR_LOG("GetVirtualAperture call Failed!");
3974 }
3975 return CameraNapiUtils::GetUndefinedValue(env);
3976 }
3977
SetVirtualAperture(napi_env env,napi_callback_info info)3978 napi_value CameraSessionNapi::SetVirtualAperture(napi_env env, napi_callback_info info)
3979 {
3980 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
3981 "SystemApi SetVirtualAperture is called!");
3982 MEDIA_DEBUG_LOG("SetVirtualAperture is called");
3983 double virtualAperture;
3984 CameraSessionNapi* cameraSessionNapi = nullptr;
3985 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi, virtualAperture);
3986 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"), nullptr,
3987 "CameraSessionNapi::SetVirtualAperture parse parameter occur error");
3988 if (cameraSessionNapi->cameraSession_ != nullptr) {
3989 cameraSessionNapi->cameraSession_->LockForControl();
3990 int32_t retCode = cameraSessionNapi->cameraSession_->SetVirtualAperture((float)virtualAperture);
3991 MEDIA_INFO_LOG("SetVirtualAperture set virtualAperture %{public}f!", virtualAperture);
3992 cameraSessionNapi->cameraSession_->UnlockForControl();
3993 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
3994 } else {
3995 MEDIA_ERR_LOG("SetVirtualAperture call Failed!");
3996 }
3997 return CameraNapiUtils::GetUndefinedValue(env);
3998 }
3999
GetSupportedPhysicalApertures(napi_env env,napi_callback_info info)4000 napi_value CameraSessionNapi::GetSupportedPhysicalApertures(napi_env env, napi_callback_info info)
4001 {
4002 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
4003 "SystemApi GetSupportedPhysicalApertures is called!");
4004 MEDIA_DEBUG_LOG("GetSupportedPhysicalApertures is called");
4005 CameraSessionNapi* cameraSessionNapi = nullptr;
4006 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi);
4007 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"), nullptr,
4008 "CameraSessionNapi::GetSupportedPhysicalApertures parse parameter occur error");
4009
4010 napi_status status;
4011 napi_value result = nullptr;
4012 status = napi_create_array(env, &result);
4013 CHECK_ERROR_RETURN_RET_LOG(status != napi_ok, nullptr, "napi_create_array call Failed!");
4014
4015 if (status == napi_ok && cameraSessionNapi->cameraSession_ != nullptr) {
4016 std::vector<std::vector<float>> physicalApertures = {};
4017 int32_t retCode = cameraSessionNapi->cameraSession_->GetSupportedPhysicalApertures(physicalApertures);
4018 MEDIA_INFO_LOG("GetSupportedPhysicalApertures len = %{public}zu", physicalApertures.size());
4019 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
4020 if (!physicalApertures.empty()) {
4021 result = CameraNapiUtils::ProcessingPhysicalApertures(env, physicalApertures);
4022 }
4023 } else {
4024 MEDIA_ERR_LOG("GetSupportedPhysicalApertures call Failed!");
4025 }
4026 return result;
4027 }
4028
GetPhysicalAperture(napi_env env,napi_callback_info info)4029 napi_value CameraSessionNapi::GetPhysicalAperture(napi_env env, napi_callback_info info)
4030 {
4031 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
4032 "SystemApi GetPhysicalAperture is called!");
4033 MEDIA_DEBUG_LOG("GetPhysicalAperture is called");
4034 CameraSessionNapi* cameraSessionNapi = nullptr;
4035 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi);
4036 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"), nullptr,
4037 "CameraSessionNapi::GetPhysicalAperture parse parameter occur error");
4038
4039 if (cameraSessionNapi->cameraSession_ != nullptr) {
4040 float physicalAperture = 0.0;
4041 int32_t retCode = cameraSessionNapi->cameraSession_->GetPhysicalAperture(physicalAperture);
4042 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
4043 napi_value result = nullptr;
4044 napi_create_double(env, CameraNapiUtils::FloatToDouble(physicalAperture), &result);
4045 return result;
4046 } else {
4047 MEDIA_ERR_LOG("GetPhysicalAperture call Failed!");
4048 }
4049 return CameraNapiUtils::GetUndefinedValue(env);
4050 }
4051
SetPhysicalAperture(napi_env env,napi_callback_info info)4052 napi_value CameraSessionNapi::SetPhysicalAperture(napi_env env, napi_callback_info info)
4053 {
4054 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr,
4055 "SystemApi SetPhysicalAperture is called!");
4056 MEDIA_DEBUG_LOG("SetPhysicalAperture is called");
4057 double physicalAperture;
4058 CameraSessionNapi* cameraSessionNapi = nullptr;
4059 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi, physicalAperture);
4060 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"), nullptr,
4061 "CameraSessionNapi::SetPhysicalAperture parse parameter occur error");
4062
4063 if (cameraSessionNapi->cameraSession_ != nullptr) {
4064 cameraSessionNapi->cameraSession_->LockForControl();
4065 int32_t retCode = cameraSessionNapi->cameraSession_->SetPhysicalAperture((float)physicalAperture);
4066 MEDIA_INFO_LOG("SetPhysicalAperture set physicalAperture %{public}f!", ConfusingNumber(physicalAperture));
4067 cameraSessionNapi->cameraSession_->UnlockForControl();
4068 CHECK_ERROR_RETURN_RET(!CameraNapiUtils::CheckError(env, retCode), nullptr);
4069 } else {
4070 MEDIA_ERR_LOG("SetPhysicalAperture call Failed!");
4071 }
4072 return CameraNapiUtils::GetUndefinedValue(env);
4073 }
4074
SetUsage(napi_env env,napi_callback_info info)4075 napi_value CameraSessionNapi::SetUsage(napi_env env, napi_callback_info info)
4076 {
4077 MEDIA_DEBUG_LOG("SetUsage is called");
4078 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env), nullptr, "SystemApi SetUsage is called!");
4079
4080 uint32_t usageType;
4081 bool enabled;
4082 CameraSessionNapi* cameraSessionNapi = nullptr;
4083 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi, usageType, enabled);
4084 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"), nullptr,
4085 "CameraSessionNapi::SetUsage parse parameter occur error");
4086
4087 cameraSessionNapi->cameraSession_->LockForControl();
4088 cameraSessionNapi->cameraSession_->SetUsage(static_cast<UsageType>(usageType), enabled);
4089 cameraSessionNapi->cameraSession_->UnlockForControl();
4090
4091 MEDIA_DEBUG_LOG("CameraSessionNapi::SetUsage success");
4092
4093 return CameraNapiUtils::GetUndefinedValue(env);
4094 }
4095
RegisterExposureCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args,bool isOnce)4096 void CameraSessionNapi::RegisterExposureCallbackListener(
4097 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args, bool isOnce)
4098 {
4099 if (exposureCallback_ == nullptr) {
4100 exposureCallback_ = std::make_shared<ExposureCallbackListener>(env);
4101 cameraSession_->SetExposureCallback(exposureCallback_);
4102 }
4103 exposureCallback_->SaveCallbackReference(eventName, callback, isOnce);
4104 }
4105
UnregisterExposureCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args)4106 void CameraSessionNapi::UnregisterExposureCallbackListener(
4107 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args)
4108 {
4109 CHECK_ERROR_RETURN_LOG(exposureCallback_ == nullptr, "exposureCallback is null");
4110 exposureCallback_->RemoveCallbackRef(eventName, callback);
4111 }
4112
RegisterFocusCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args,bool isOnce)4113 void CameraSessionNapi::RegisterFocusCallbackListener(
4114 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args, bool isOnce)
4115 {
4116 if (focusCallback_ == nullptr) {
4117 focusCallback_ = make_shared<FocusCallbackListener>(env);
4118 cameraSession_->SetFocusCallback(focusCallback_);
4119 }
4120 focusCallback_->SaveCallbackReference(eventName, callback, isOnce);
4121 }
4122
UnregisterFocusCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args)4123 void CameraSessionNapi::UnregisterFocusCallbackListener(
4124 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args)
4125 {
4126 CHECK_ERROR_RETURN_LOG(focusCallback_ == nullptr, "focusCallback is null");
4127 focusCallback_->RemoveCallbackRef(eventName, callback);
4128 }
4129
RegisterMacroStatusCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args,bool isOnce)4130 void CameraSessionNapi::RegisterMacroStatusCallbackListener(
4131 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args, bool isOnce)
4132 {
4133 CHECK_ERROR_RETURN_LOG(!CameraNapiSecurity::CheckSystemApp(env), "SystemApi on macroStatusChanged is called!");
4134 if (macroStatusCallback_ == nullptr) {
4135 macroStatusCallback_ = std::make_shared<MacroStatusCallbackListener>(env);
4136 cameraSession_->SetMacroStatusCallback(macroStatusCallback_);
4137 }
4138 macroStatusCallback_->SaveCallbackReference(eventName, callback, isOnce);
4139 }
4140
UnregisterMacroStatusCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args)4141 void CameraSessionNapi::UnregisterMacroStatusCallbackListener(
4142 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args)
4143 {
4144 CHECK_ERROR_RETURN_LOG(!CameraNapiSecurity::CheckSystemApp(env), "SystemApi off macroStatusChanged is called!");
4145 CHECK_ERROR_RETURN_LOG(macroStatusCallback_ == nullptr, "macroStatusCallback is null");
4146 macroStatusCallback_->RemoveCallbackRef(eventName, callback);
4147 }
4148
RegisterMoonCaptureBoostCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args,bool isOnce)4149 void CameraSessionNapi::RegisterMoonCaptureBoostCallbackListener(
4150 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args, bool isOnce)
4151 {
4152 CHECK_ERROR_RETURN_LOG(!CameraNapiSecurity::CheckSystemApp(env), "SystemApi on moonCaptureBoostStatus is called!");
4153 if (moonCaptureBoostCallback_ == nullptr) {
4154 moonCaptureBoostCallback_ = std::make_shared<MoonCaptureBoostCallbackListener>(env);
4155 cameraSession_->SetMoonCaptureBoostStatusCallback(moonCaptureBoostCallback_);
4156 }
4157 moonCaptureBoostCallback_->SaveCallbackReference(eventName, callback, isOnce);
4158 }
4159
UnregisterMoonCaptureBoostCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args)4160 void CameraSessionNapi::UnregisterMoonCaptureBoostCallbackListener(
4161 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args)
4162 {
4163 CHECK_ERROR_RETURN_LOG(!CameraNapiSecurity::CheckSystemApp(env), "SystemApi off moonCaptureBoostStatus is called!");
4164 CHECK_ERROR_RETURN_LOG(moonCaptureBoostCallback_ == nullptr, "macroStatusCallback is null");
4165 moonCaptureBoostCallback_->RemoveCallbackRef(eventName, callback);
4166 }
4167
RegisterFeatureDetectionStatusListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args,bool isOnce)4168 void CameraSessionNapi::RegisterFeatureDetectionStatusListener(
4169 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args, bool isOnce)
4170 {
4171 CHECK_ERROR_RETURN_LOG(!CameraNapiSecurity::CheckSystemApp(env), "SystemApi on featureDetectionStatus is called!");
4172 int32_t featureType = SceneFeature::FEATURE_ENUM_MAX;
4173 CameraNapiParamParser jsParamParser(env, args, featureType);
4174 CHECK_ERROR_RETURN_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "Invalid feature type"),
4175 "CameraSessionNapi::RegisterFeatureDetectionStatusListener Invalid feature type");
4176 if (featureType < SceneFeature::FEATURE_ENUM_MIN || featureType >= SceneFeature::FEATURE_ENUM_MAX) {
4177 CameraNapiUtils::ThrowError(env, INVALID_ARGUMENT, "scene feature invalid");
4178 MEDIA_ERR_LOG("CameraSessionNapi::RegisterFeatureDetectionStatusListener scene feature invalid");
4179 return;
4180 }
4181
4182 if (featureDetectionStatusCallback_ == nullptr) {
4183 featureDetectionStatusCallback_ = std::make_shared<FeatureDetectionStatusCallbackListener>(env);
4184 cameraSession_->SetFeatureDetectionStatusCallback(featureDetectionStatusCallback_);
4185 }
4186
4187 if (featureType == SceneFeature::FEATURE_LOW_LIGHT_BOOST) {
4188 cameraSession_->LockForControl();
4189 cameraSession_->EnableLowLightDetection(true);
4190 cameraSession_->UnlockForControl();
4191 }
4192 if (featureType == SceneFeature::FEATURE_TRIPOD_DETECTION) {
4193 cameraSession_->LockForControl();
4194 cameraSession_->EnableTripodDetection(true);
4195 cameraSession_->UnlockForControl();
4196 }
4197 featureDetectionStatusCallback_->SaveCallbackReference(eventName + std::to_string(featureType), callback, isOnce);
4198 }
4199
UnregisterFeatureDetectionStatusListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args)4200 void CameraSessionNapi::UnregisterFeatureDetectionStatusListener(
4201 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args)
4202 {
4203 CHECK_ERROR_RETURN_LOG(!CameraNapiSecurity::CheckSystemApp(env), "SystemApi off featureDetectionStatus is called!");
4204 CHECK_ERROR_RETURN_LOG(featureDetectionStatusCallback_ == nullptr, "featureDetectionStatusCallback_ is null");
4205 int32_t featureType = SceneFeature::FEATURE_ENUM_MAX;
4206 CameraNapiParamParser jsParamParser(env, args, featureType);
4207 CHECK_ERROR_RETURN_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "Invalid feature type"),
4208 "CameraSessionNapi::RegisterFeatureDetectionStatusListener Invalid feature type");
4209 if (featureType < SceneFeature::FEATURE_ENUM_MIN || featureType >= SceneFeature::FEATURE_ENUM_MAX) {
4210 CameraNapiUtils::ThrowError(env, INVALID_ARGUMENT, "scene feature invalid");
4211 MEDIA_ERR_LOG("CameraSessionNapi::RegisterFeatureDetectionStatusListener scene feature invalid");
4212 return;
4213 }
4214
4215 featureDetectionStatusCallback_->RemoveCallbackRef(eventName + std::to_string(featureType), callback);
4216
4217 if (featureType == SceneFeature::FEATURE_LOW_LIGHT_BOOST &&
4218 !featureDetectionStatusCallback_->IsFeatureSubscribed(SceneFeature::FEATURE_LOW_LIGHT_BOOST)) {
4219 cameraSession_->LockForControl();
4220 cameraSession_->EnableLowLightDetection(false);
4221 cameraSession_->UnlockForControl();
4222 }
4223 if (featureType == SceneFeature::FEATURE_TRIPOD_DETECTION &&
4224 !featureDetectionStatusCallback_->IsFeatureSubscribed(SceneFeature::FEATURE_TRIPOD_DETECTION)) {
4225 cameraSession_->LockForControl();
4226 cameraSession_->EnableTripodDetection(false);
4227 cameraSession_->UnlockForControl();
4228 }
4229 }
4230
RegisterSessionErrorCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args,bool isOnce)4231 void CameraSessionNapi::RegisterSessionErrorCallbackListener(
4232 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args, bool isOnce)
4233 {
4234 if (sessionCallback_ == nullptr) {
4235 sessionCallback_ = std::make_shared<SessionCallbackListener>(env);
4236 cameraSession_->SetCallback(sessionCallback_);
4237 }
4238 sessionCallback_->SaveCallbackReference(eventName, callback, isOnce);
4239 }
4240
UnregisterSessionErrorCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args)4241 void CameraSessionNapi::UnregisterSessionErrorCallbackListener(
4242 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args)
4243 {
4244 if (sessionCallback_ == nullptr) {
4245 MEDIA_DEBUG_LOG("sessionCallback is null");
4246 return;
4247 }
4248 sessionCallback_->RemoveCallbackRef(eventName, callback);
4249 }
4250
RegisterEffectSuggestionCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args,bool isOnce)4251 void CameraSessionNapi::RegisterEffectSuggestionCallbackListener(
4252 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args, bool isOnce)
4253 {
4254 if (effectSuggestionCallback_ == nullptr) {
4255 auto effectSuggestionCallback = std::make_shared<EffectSuggestionCallbackListener>(env);
4256 effectSuggestionCallback_ = effectSuggestionCallback;
4257 cameraSession_->SetEffectSuggestionCallback(effectSuggestionCallback);
4258 }
4259 effectSuggestionCallback_->SaveCallbackReference(eventName, callback, isOnce);
4260 }
4261
UnregisterEffectSuggestionCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args)4262 void CameraSessionNapi::UnregisterEffectSuggestionCallbackListener(
4263 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args)
4264 {
4265 if (effectSuggestionCallback_ == nullptr) {
4266 MEDIA_ERR_LOG("effectSuggestionCallback is null");
4267 } else {
4268 effectSuggestionCallback_->RemoveCallbackRef(eventName, callback);
4269 }
4270 }
4271
RegisterAbilityChangeCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args,bool isOnce)4272 void CameraSessionNapi::RegisterAbilityChangeCallbackListener(
4273 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args, bool isOnce)
4274 {
4275 if (abilityCallback_ == nullptr) {
4276 auto abilityCallback = std::make_shared<AbilityCallbackListener>(env);
4277 abilityCallback_ = abilityCallback;
4278 cameraSession_->SetAbilityCallback(abilityCallback);
4279 }
4280 abilityCallback_->SaveCallbackReference(eventName, callback, isOnce);
4281 }
4282
UnregisterAbilityChangeCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args)4283 void CameraSessionNapi::UnregisterAbilityChangeCallbackListener(
4284 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args)
4285 {
4286 if (abilityCallback_ == nullptr) {
4287 MEDIA_ERR_LOG("abilityCallback is null");
4288 } else {
4289 abilityCallback_->RemoveCallbackRef(eventName, callback);
4290 }
4291 }
4292
RegisterSmoothZoomCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args,bool isOnce)4293 void CameraSessionNapi::RegisterSmoothZoomCallbackListener(
4294 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args, bool isOnce)
4295 {
4296 if (smoothZoomCallback_ == nullptr) {
4297 smoothZoomCallback_ = std::make_shared<SmoothZoomCallbackListener>(env);
4298 cameraSession_->SetSmoothZoomCallback(smoothZoomCallback_);
4299 }
4300 smoothZoomCallback_->SaveCallbackReference(eventName, callback, isOnce);
4301 }
4302
UnregisterSmoothZoomCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args)4303 void CameraSessionNapi::UnregisterSmoothZoomCallbackListener(
4304 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args)
4305 {
4306 CHECK_ERROR_RETURN_LOG(smoothZoomCallback_ == nullptr, "smoothZoomCallback is null");
4307 smoothZoomCallback_->RemoveCallbackRef(eventName, callback);
4308 }
4309
RegisterExposureInfoCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args,bool isOnce)4310 void CameraSessionNapi::RegisterExposureInfoCallbackListener(
4311 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args, bool isOnce)
4312 {
4313 CameraNapiUtils::ThrowError(
4314 env, CameraErrorCode::OPERATION_NOT_ALLOWED, "this type callback can not be registered in current session!");
4315 }
4316
UnregisterExposureInfoCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args)4317 void CameraSessionNapi::UnregisterExposureInfoCallbackListener(
4318 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args)
4319 {
4320 CameraNapiUtils::ThrowError(
4321 env, CameraErrorCode::OPERATION_NOT_ALLOWED, "this type callback can not be unregistered in current session!");
4322 }
4323
RegisterIsoInfoCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args,bool isOnce)4324 void CameraSessionNapi::RegisterIsoInfoCallbackListener(
4325 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args, bool isOnce)
4326 {
4327 CameraNapiUtils::ThrowError(
4328 env, CameraErrorCode::OPERATION_NOT_ALLOWED, "this type callback can not be registered in current session!");
4329 }
4330
UnregisterIsoInfoCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args)4331 void CameraSessionNapi::UnregisterIsoInfoCallbackListener(
4332 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args)
4333 {
4334 CameraNapiUtils::ThrowError(
4335 env, CameraErrorCode::OPERATION_NOT_ALLOWED, "this type callback can not be unregistered in current session!");
4336 }
4337
RegisterApertureInfoCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args,bool isOnce)4338 void CameraSessionNapi::RegisterApertureInfoCallbackListener(
4339 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args, bool isOnce)
4340 {
4341 CameraNapiUtils::ThrowError(
4342 env, CameraErrorCode::OPERATION_NOT_ALLOWED, "this type callback can not be registered in current session!");
4343 }
4344
UnregisterApertureInfoCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args)4345 void CameraSessionNapi::UnregisterApertureInfoCallbackListener(
4346 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args)
4347 {
4348 CameraNapiUtils::ThrowError(
4349 env, CameraErrorCode::OPERATION_NOT_ALLOWED, "this type callback can not be unregistered in current session!");
4350 }
4351
RegisterLuminationInfoCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args,bool isOnce)4352 void CameraSessionNapi::RegisterLuminationInfoCallbackListener(
4353 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args, bool isOnce)
4354 {
4355 CameraNapiUtils::ThrowError(
4356 env, CameraErrorCode::OPERATION_NOT_ALLOWED, "this type callback can not be registered in current session!");
4357 }
4358
UnregisterLuminationInfoCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args)4359 void CameraSessionNapi::UnregisterLuminationInfoCallbackListener(
4360 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args)
4361 {
4362 CameraNapiUtils::ThrowError(
4363 env, CameraErrorCode::OPERATION_NOT_ALLOWED, "this type callback can not be unregistered in current session!");
4364 }
4365
RegisterSlowMotionStateCb(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args,bool isOnce)4366 void CameraSessionNapi::RegisterSlowMotionStateCb(
4367 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args, bool isOnce)
4368 {
4369 CameraNapiUtils::ThrowError(
4370 env, CameraErrorCode::OPERATION_NOT_ALLOWED, "this type callback can not be unregistered in current session!");
4371 }
4372
UnregisterSlowMotionStateCb(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args)4373 void CameraSessionNapi::UnregisterSlowMotionStateCb(
4374 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args)
4375 {
4376 CameraNapiUtils::ThrowError(
4377 env, CameraErrorCode::OPERATION_NOT_ALLOWED, "this type callback can not be unregistered in current session!");
4378 }
4379
RegisterTryAEInfoCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args,bool isOnce)4380 void CameraSessionNapi::RegisterTryAEInfoCallbackListener(
4381 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args, bool isOnce)
4382 {
4383 CameraNapiUtils::ThrowError(env, CameraErrorCode::OPERATION_NOT_ALLOWED,
4384 "this type callback can not be registered in current session!");
4385 }
4386
UnregisterTryAEInfoCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args)4387 void CameraSessionNapi::UnregisterTryAEInfoCallbackListener(
4388 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args)
4389 {
4390 CameraNapiUtils::ThrowError(env, CameraErrorCode::OPERATION_NOT_ALLOWED,
4391 "this type callback can not be unregistered in current session!");
4392 }
4393
RegisterFocusTrackingInfoCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args,bool isOnce)4394 void CameraSessionNapi::RegisterFocusTrackingInfoCallbackListener(const std::string& eventName,
4395 napi_env env, napi_value callback, const std::vector<napi_value>& args, bool isOnce)
4396 {
4397 CHECK_ERROR_RETURN_LOG(!CameraNapiSecurity::CheckSystemApp(env),
4398 "SystemApi on focusTrackingInfoAvailable is called");
4399 CameraNapiUtils::ThrowError(env, CameraErrorCode::OPERATION_NOT_ALLOWED,
4400 "this type callback can not be registered in current session!");
4401 }
4402
UnregisterFocusTrackingInfoCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args)4403 void CameraSessionNapi::UnregisterFocusTrackingInfoCallbackListener(const std::string& eventName,
4404 napi_env env, napi_value callback, const std::vector<napi_value>& args)
4405 {
4406 CHECK_ERROR_RETURN_LOG(!CameraNapiSecurity::CheckSystemApp(env),
4407 "SystemApi off focusTrackingInfoAvailable is called");
4408 CameraNapiUtils::ThrowError(env, CameraErrorCode::OPERATION_NOT_ALLOWED,
4409 "this type callback can not be unregistered in current session!");
4410 }
4411
RegisterLightStatusCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args,bool isOnce)4412 void CameraSessionNapi::RegisterLightStatusCallbackListener(const std::string& eventName,
4413 napi_env env, napi_value callback, const std::vector<napi_value>& args, bool isOnce)
4414 {
4415 CHECK_ERROR_RETURN_LOG(!CameraNapiSecurity::CheckSystemApp(env),
4416 "SystemApi on lightStatusChange is called");
4417 CameraNapiUtils::ThrowError(env, CameraErrorCode::OPERATION_NOT_ALLOWED,
4418 "this type callback can not be registered in current session!");
4419 }
4420
UnregisterLightStatusCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args)4421 void CameraSessionNapi::UnregisterLightStatusCallbackListener(const std::string& eventName,
4422 napi_env env, napi_value callback, const std::vector<napi_value>& args)
4423 {
4424 CHECK_ERROR_RETURN_LOG(!CameraNapiSecurity::CheckSystemApp(env),
4425 "SystemApi off lightStatusChange is called");
4426 CameraNapiUtils::ThrowError(env, CameraErrorCode::OPERATION_NOT_ALLOWED,
4427 "this type callback can not be unregistered in current session!");
4428 }
4429
4430 const CameraSessionNapi::EmitterFunctions CameraSessionNapi::fun_map_ = {
4431 { "exposureStateChange", {
4432 &CameraSessionNapi::RegisterExposureCallbackListener,
4433 &CameraSessionNapi::UnregisterExposureCallbackListener} },
4434 { "focusStateChange", {
4435 &CameraSessionNapi::RegisterFocusCallbackListener,
4436 &CameraSessionNapi::UnregisterFocusCallbackListener } },
4437 { "macroStatusChanged", {
4438 &CameraSessionNapi::RegisterMacroStatusCallbackListener,
4439 &CameraSessionNapi::UnregisterMacroStatusCallbackListener } },
4440 { "moonCaptureBoostStatus", {
4441 &CameraSessionNapi::RegisterMoonCaptureBoostCallbackListener,
4442 &CameraSessionNapi::UnregisterMoonCaptureBoostCallbackListener } },
4443 { "featureDetection", {
4444 &CameraSessionNapi::RegisterFeatureDetectionStatusListener,
4445 &CameraSessionNapi::UnregisterFeatureDetectionStatusListener } },
4446 { "featureDetectionStatus", {
4447 &CameraSessionNapi::RegisterFeatureDetectionStatusListener,
4448 &CameraSessionNapi::UnregisterFeatureDetectionStatusListener } },
4449 { "error", {
4450 &CameraSessionNapi::RegisterSessionErrorCallbackListener,
4451 &CameraSessionNapi::UnregisterSessionErrorCallbackListener } },
4452 { "smoothZoomInfoAvailable", {
4453 &CameraSessionNapi::RegisterSmoothZoomCallbackListener,
4454 &CameraSessionNapi::UnregisterSmoothZoomCallbackListener } },
4455 { "slowMotionStatus", {
4456 &CameraSessionNapi::RegisterSlowMotionStateCb,
4457 &CameraSessionNapi::UnregisterSlowMotionStateCb } },
4458 { "exposureInfoChange", {
4459 &CameraSessionNapi::RegisterExposureInfoCallbackListener,
4460 &CameraSessionNapi::UnregisterExposureInfoCallbackListener} },
4461 { "isoInfoChange", {
4462 &CameraSessionNapi::RegisterIsoInfoCallbackListener,
4463 &CameraSessionNapi::UnregisterIsoInfoCallbackListener } },
4464 { "apertureInfoChange", {
4465 &CameraSessionNapi::RegisterApertureInfoCallbackListener,
4466 &CameraSessionNapi::UnregisterApertureInfoCallbackListener } },
4467 { "luminationInfoChange", {
4468 &CameraSessionNapi::RegisterLuminationInfoCallbackListener,
4469 &CameraSessionNapi::UnregisterLuminationInfoCallbackListener } },
4470 { "abilityChange", {
4471 &CameraSessionNapi::RegisterAbilityChangeCallbackListener,
4472 &CameraSessionNapi::UnregisterAbilityChangeCallbackListener } },
4473 { "effectSuggestionChange", {
4474 &CameraSessionNapi::RegisterEffectSuggestionCallbackListener,
4475 &CameraSessionNapi::UnregisterEffectSuggestionCallbackListener } },
4476 { "tryAEInfoChange", {
4477 &CameraSessionNapi::RegisterTryAEInfoCallbackListener,
4478 &CameraSessionNapi::UnregisterTryAEInfoCallbackListener } },
4479 { "lcdFlashStatus", {
4480 &CameraSessionNapi::RegisterLcdFlashStatusCallbackListener,
4481 &CameraSessionNapi::UnregisterLcdFlashStatusCallbackListener } },
4482 { "autoDeviceSwitchStatusChange", {
4483 &CameraSessionNapi::RegisterAutoDeviceSwitchCallbackListener,
4484 &CameraSessionNapi::UnregisterAutoDeviceSwitchCallbackListener } },
4485 { "focusTrackingInfoAvailable", {
4486 &CameraSessionNapi::RegisterFocusTrackingInfoCallbackListener,
4487 &CameraSessionNapi::UnregisterFocusTrackingInfoCallbackListener } },
4488 { "lightStatusChange", {
4489 &CameraSessionNapi::RegisterLightStatusCallbackListener,
4490 &CameraSessionNapi::UnregisterLightStatusCallbackListener } },
4491 };
4492
GetEmitterFunctions()4493 const CameraSessionNapi::EmitterFunctions& CameraSessionNapi::GetEmitterFunctions()
4494 {
4495 return fun_map_;
4496 }
4497
On(napi_env env,napi_callback_info info)4498 napi_value CameraSessionNapi::On(napi_env env, napi_callback_info info)
4499 {
4500 return ListenerTemplate<CameraSessionNapi>::On(env, info);
4501 }
4502
Once(napi_env env,napi_callback_info info)4503 napi_value CameraSessionNapi::Once(napi_env env, napi_callback_info info)
4504 {
4505 return ListenerTemplate<CameraSessionNapi>::Once(env, info);
4506 }
4507
Off(napi_env env,napi_callback_info info)4508 napi_value CameraSessionNapi::Off(napi_env env, napi_callback_info info)
4509 {
4510 return ListenerTemplate<CameraSessionNapi>::Off(env, info);
4511 }
4512
RegisterLcdFlashStatusCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args,bool isOnce)4513 void CameraSessionNapi::RegisterLcdFlashStatusCallbackListener(
4514 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args, bool isOnce)
4515 {
4516 CHECK_ERROR_RETURN_LOG(!CameraNapiSecurity::CheckSystemApp(env), "SystemApi on LcdFlashStatus is called!");
4517 CHECK_ERROR_RETURN_LOG(cameraSession_ == nullptr, "cameraSession is null!");
4518 if (lcdFlashStatusCallback_ == nullptr) {
4519 lcdFlashStatusCallback_ = std::make_shared<LcdFlashStatusCallbackListener>(env);
4520 cameraSession_->SetLcdFlashStatusCallback(lcdFlashStatusCallback_);
4521 }
4522 lcdFlashStatusCallback_->SaveCallbackReference(eventName, callback, isOnce);
4523 cameraSession_->LockForControl();
4524 cameraSession_->EnableLcdFlashDetection(true);
4525 cameraSession_->UnlockForControl();
4526 }
4527
UnregisterLcdFlashStatusCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args)4528 void CameraSessionNapi::UnregisterLcdFlashStatusCallbackListener(
4529 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args)
4530 {
4531 CHECK_ERROR_RETURN_LOG(lcdFlashStatusCallback_ == nullptr, "lcdFlashStatusCallback is null");
4532 lcdFlashStatusCallback_->RemoveCallbackRef(eventName, callback);
4533 if (lcdFlashStatusCallback_->IsEmpty("lcdFlashStatus")) {
4534 cameraSession_->LockForControl();
4535 cameraSession_->EnableLcdFlashDetection(false);
4536 cameraSession_->UnlockForControl();
4537 }
4538 }
4539
IsAutoDeviceSwitchSupported(napi_env env,napi_callback_info info)4540 napi_value CameraSessionNapi::IsAutoDeviceSwitchSupported(napi_env env, napi_callback_info info)
4541 {
4542 MEDIA_INFO_LOG("IsAutoDeviceSwitchSupported is called");
4543 CameraSessionNapi* cameraSessionNapi = nullptr;
4544 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi);
4545 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"), nullptr,
4546 "CameraSessionNapi::IsAutoDeviceSwitchSupported parse parameter occur error");
4547 auto result = CameraNapiUtils::GetUndefinedValue(env);
4548 if (cameraSessionNapi->cameraSession_ != nullptr) {
4549 bool isSupported = cameraSessionNapi->cameraSession_->IsAutoDeviceSwitchSupported();
4550 napi_get_boolean(env, isSupported, &result);
4551 } else {
4552 MEDIA_ERR_LOG("CameraSessionNapi::IsAutoDeviceSwitchSupported get native object fail");
4553 CameraNapiUtils::ThrowError(env, INVALID_ARGUMENT, "get native object fail");
4554 return nullptr;
4555 }
4556 return result;
4557 }
4558
EnableAutoDeviceSwitch(napi_env env,napi_callback_info info)4559 napi_value CameraSessionNapi::EnableAutoDeviceSwitch(napi_env env, napi_callback_info info)
4560 {
4561 MEDIA_DEBUG_LOG("CameraSessionNapi::EnableAutoDeviceSwitch is called");
4562 bool isEnable;
4563 CameraSessionNapi* cameraSessionNapi = nullptr;
4564 CameraNapiParamParser jsParamParser(env, info, cameraSessionNapi, isEnable);
4565 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"), nullptr,
4566 "CameraSessionNapi::EnableAutoDeviceSwitch parse parameter occur error");
4567
4568 if (cameraSessionNapi->cameraSession_ != nullptr) {
4569 MEDIA_INFO_LOG("CameraSessionNapi::EnableAutoDeviceSwitch:%{public}d", isEnable);
4570 cameraSessionNapi->cameraSession_->LockForControl();
4571 int32_t retCode = cameraSessionNapi->cameraSession_->EnableAutoDeviceSwitch(isEnable);
4572 cameraSessionNapi->cameraSession_->UnlockForControl();
4573 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiUtils::CheckError(env, retCode), nullptr,
4574 "CameraSessionNapi::EnableAutoSwitchDevice fail %{public}d", retCode);
4575 } else {
4576 MEDIA_ERR_LOG("CameraSessionNapi::EnableAutoDeviceSwitch get native object fail");
4577 CameraNapiUtils::ThrowError(env, INVALID_ARGUMENT, "get native object fail");
4578 return nullptr;
4579 }
4580 return CameraNapiUtils::GetUndefinedValue(env);
4581 }
4582
RegisterAutoDeviceSwitchCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args,bool isOnce)4583 void CameraSessionNapi::RegisterAutoDeviceSwitchCallbackListener(
4584 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args, bool isOnce)
4585 {
4586 CHECK_ERROR_RETURN_LOG(cameraSession_ == nullptr, "cameraSession is null!");
4587 if (autoDeviceSwitchCallback_ == nullptr) {
4588 autoDeviceSwitchCallback_ = std::make_shared<AutoDeviceSwitchCallbackListener>(env);
4589 cameraSession_->SetAutoDeviceSwitchCallback(autoDeviceSwitchCallback_);
4590 }
4591 autoDeviceSwitchCallback_->SaveCallbackReference(eventName, callback, isOnce);
4592 }
4593
UnregisterAutoDeviceSwitchCallbackListener(const std::string & eventName,napi_env env,napi_value callback,const std::vector<napi_value> & args)4594 void CameraSessionNapi::UnregisterAutoDeviceSwitchCallbackListener(
4595 const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args)
4596 {
4597 CHECK_ERROR_RETURN_LOG(autoDeviceSwitchCallback_ == nullptr, "autoDeviceSwitchCallback is nullptr.");
4598 autoDeviceSwitchCallback_->RemoveCallbackRef(eventName, callback);
4599 }
4600 } // namespace CameraStandard
4601 } // namespace OHOS
4602