1 /*
2  * Copyright (C) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
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 "napi/native_api.h"
17 #include "camera_manager_ndk.h"
18 #include <js_native_api.h>
19 #include "camera.h"
20 #include <string.h>
21 #include "hilog/log.h"
22 
23 static NDKCamera* ndkCamera_ = nullptr;
24 const static int NUMBER_2 = 2;
25 struct Capture_Setting {
26     int32_t quality;
27     int32_t rotation;
28     int32_t location;
29     bool mirror;
30     int32_t latitude;
31     int32_t longitude;
32     int32_t altitude;
33 };
34 
InitCamera(napi_env env, napi_callback_info info)35 static napi_value InitCamera(napi_env env, napi_callback_info info)
36 {
37     size_t argc = 2;
38     napi_value args[2] = {nullptr};
39     napi_value result;
40 
41     size_t typeLen = 0;
42     char* surfaceId = nullptr;
43 
44     napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
45 
46     napi_get_value_string_utf8(env, args[0], nullptr, 0, &typeLen);
47     surfaceId = new char[typeLen + 1];
48     napi_get_value_string_utf8(env, args[0], surfaceId, typeLen + 1, &typeLen);
49 
50     int32_t  cameraDeviceIndex;
51     napi_get_value_int32(env, args[1], &cameraDeviceIndex);
52 
53     ndkCamera_ = new NDKCamera(surfaceId);
54     napi_create_int32(env, CAMERA_OK, &result);
55     return result;
56 }
57 
VideoOutputStart(napi_env env, napi_callback_info info)58 static napi_value VideoOutputStart(napi_env env, napi_callback_info info)
59 {
60     napi_value result;
61 
62     Camera_ErrorCode ret = ndkCamera_->VideoOutputStart();
63     napi_create_int32(env, ret, &result);
64     return result;
65 }
66 
GetSupportedCameras(napi_env env, napi_callback_info info)67 static napi_value GetSupportedCameras(napi_env env, napi_callback_info info)
68 {
69     ndkCamera_->GetSupportedCameras();
70 
71     napi_value cameraInfo = nullptr;
72     napi_create_object(env, &cameraInfo);
73 
74     napi_value jsValue = nullptr;
75 
76     napi_create_int32(env, ndkCamera_->cameras_->cameraPosition, &jsValue);
77     napi_set_named_property(env, cameraInfo, "cameraPosition", jsValue);
78 
79     napi_create_int32(env, ndkCamera_->cameras_->cameraType, &jsValue);
80     napi_set_named_property(env, cameraInfo, "cameraType", jsValue);
81 
82     napi_create_int32(env, ndkCamera_->cameras_->connectionType, &jsValue);
83     napi_set_named_property(env, cameraInfo, "connectionType", jsValue);
84 
85     napi_create_string_utf8(env, ndkCamera_->cameras_->cameraId, sizeof(ndkCamera_->cameras_->cameraId) + 1 , &jsValue);
86     napi_set_named_property(env, cameraInfo, "cameraId", jsValue);
87 
88     return cameraInfo;
89 }
90 
GetCameraOrientation(napi_env env, napi_callback_info info)91 static napi_value GetCameraOrientation(napi_env env, napi_callback_info info)
92 {
93     ndkCamera_->GetCameraOrientation();
94 
95     napi_value jsValue = nullptr;
96 
97     napi_create_int32(env, ndkCamera_->GetCameraOrientation(), &jsValue);
98 
99     return jsValue;
100 }
101 
102 
CreateCameraInput(napi_env env, napi_callback_info info)103 static napi_value CreateCameraInput(napi_env env, napi_callback_info info)
104 {
105     napi_value result;
106     Camera_ErrorCode ret = ndkCamera_->CreateCameraInput();
107     napi_create_int32(env, ret, &result);
108     return result;
109 }
110 
GetPosition(int position)111 static Camera_Position GetPosition(int position)
112 {
113     switch (position) {
114         case 1:
115             return Camera_Position::CAMERA_POSITION_BACK;
116         case 2: // 2:Camera_Position::CAMERA_POSITION_FRONT
117             return Camera_Position::CAMERA_POSITION_FRONT;
118         default:
119             return Camera_Position::CAMERA_POSITION_UNSPECIFIED;
120     }
121 }
122 
GetType(int type)123 static Camera_Type GetType(int type)
124 {
125     switch (type) {
126         case 1:
127             return Camera_Type::CAMERA_TYPE_WIDE_ANGLE;
128         case 2: // 2:Camera_Type::CAMERA_TYPE_ULTRA_WIDE
129             return Camera_Type::CAMERA_TYPE_ULTRA_WIDE;
130         case 3: // 3:Camera_Type::CAMERA_TYPE_TELEPHOTO
131             return Camera_Type::CAMERA_TYPE_TELEPHOTO;
132         case 4: // 4:Camera_Type::CAMERA_TYPE_TRUE_DEPTH
133             return Camera_Type::CAMERA_TYPE_TRUE_DEPTH;
134         default:
135             return Camera_Type::CAMERA_TYPE_DEFAULT;
136     }
137 }
138 
CreateCameraInputWithPositionAndType(napi_env env, napi_callback_info info)139 static napi_value CreateCameraInputWithPositionAndType(napi_env env, napi_callback_info info)
140 {
141     size_t argc = 2;
142     napi_value args[2] = {nullptr};
143     napi_value result;
144 
145     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
146 
147     napi_valuetype valuetype0;
148     napi_typeof(env, args[0], &valuetype0);
149     int x;
150     napi_get_value_int32(env, args[0], &x);
151 
152     napi_valuetype valuetype1;
153     napi_typeof(env, args[0], &valuetype1);
154     int y;
155     napi_get_value_int32(env, args[1], &y);
156 
157     Camera_Position position = GetPosition(x);
158     Camera_Type type = GetType(y);
159     Camera_ErrorCode ret = ndkCamera_->CreateCameraInputWithPositionAndType(position, type);
160     napi_create_int32(env, ret, &result);
161     return result;
162 }
163 
GetSupportedOutputCapability(napi_env env, napi_callback_info info)164 static napi_value GetSupportedOutputCapability(napi_env env, napi_callback_info info)
165 {
166     ndkCamera_->GetSupportedOutputCapability();
167 
168     napi_value cameraOutputCapability = nullptr;
169     napi_create_object(env, &cameraOutputCapability);
170 
171     napi_value jsValue = nullptr;
172 
173     napi_create_int32(env, ndkCamera_->cameraOutputCapability_->previewProfilesSize, &jsValue);
174     napi_set_named_property(env, cameraOutputCapability, "previewProfilesSize", jsValue);
175 
176     napi_create_int32(env, ndkCamera_->cameraOutputCapability_->photoProfilesSize, &jsValue);
177     napi_set_named_property(env, cameraOutputCapability, "photoProfilesSize", jsValue);
178 
179     napi_create_int32(env, ndkCamera_->cameraOutputCapability_->videoProfilesSize, &jsValue);
180     napi_set_named_property(env, cameraOutputCapability, "videoProfilesSize", jsValue);
181 
182     napi_create_int32(env, ndkCamera_->cameraOutputCapability_->metadataProfilesSize, &jsValue);
183     napi_set_named_property(env, cameraOutputCapability, "metadataProfilesSize", jsValue);
184 
185     return cameraOutputCapability;
186 }
187 
CreatePreviewOutput(napi_env env, napi_callback_info info)188 static napi_value CreatePreviewOutput(napi_env env, napi_callback_info info)
189 {
190     napi_value result;
191 
192     Camera_ErrorCode ret = ndkCamera_->CreatePreviewOutput();
193     napi_create_int32(env, ret, &result);
194     return result;
195 }
196 
CreatePhotoOutput(napi_env env, napi_callback_info info)197 static napi_value CreatePhotoOutput(napi_env env, napi_callback_info info)
198 {
199     napi_value result;
200 
201     size_t argc = 2;
202     napi_value args[2] = {nullptr};
203     size_t typeLen = 0;
204     char* surfaceId = nullptr;
205 
206     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
207 
208     napi_get_value_string_utf8(env, args[0], nullptr, 0, &typeLen);
209     surfaceId = new char[typeLen + 1];
210     napi_get_value_string_utf8(env, args[0], surfaceId, typeLen + 1, &typeLen);
211     Camera_ErrorCode ret = ndkCamera_->CreatePhotoOutput(surfaceId);
212     napi_create_int32(env, ret, &result);
213     return result;
214 }
215 
CreateVideoOutput(napi_env env, napi_callback_info info)216 static napi_value CreateVideoOutput(napi_env env, napi_callback_info info)
217 {
218     size_t argc = 2;
219     napi_value args[2] = {nullptr};
220     napi_value result;
221 
222     size_t videoIdLen = 0;
223     char* videoId = nullptr;
224     napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
225     napi_get_value_string_utf8(env, args[0], nullptr, 0, &videoIdLen);
226     videoId = new char[videoIdLen + 1];
227     napi_get_value_string_utf8(env, args[0], videoId, videoIdLen + 1, &videoIdLen);
228     Camera_ErrorCode ret = ndkCamera_->CreateVideoOutput(videoId);
229     napi_create_int32(env, ret, &result);
230     return result;
231 }
232 
CreateMetadataOutput(napi_env env, napi_callback_info info)233 static napi_value CreateMetadataOutput(napi_env env, napi_callback_info info)
234 {
235     napi_value result;
236 
237     Camera_ErrorCode ret = ndkCamera_->CreateMetadataOutput();
238     napi_create_int32(env, ret, &result);
239     return result;
240 }
241 
IsCameraMuted(napi_env env, napi_callback_info info)242 static napi_value IsCameraMuted(napi_env env, napi_callback_info info)
243 {
244     napi_value result;
245 
246     Camera_ErrorCode ret = ndkCamera_->IsCameraMuted();
247     napi_create_int32(env, ret, &result);
248     return result;
249 }
250 
CameraInputOpen(napi_env env, napi_callback_info info)251 static napi_value CameraInputOpen(napi_env env, napi_callback_info info)
252 {
253     napi_value result;
254 
255     Camera_ErrorCode ret = ndkCamera_->CameraInputOpen();
256     napi_create_int32(env, ret, &result);
257     return result;
258 }
259 
CameraInputClose(napi_env env, napi_callback_info info)260 static napi_value CameraInputClose(napi_env env, napi_callback_info info)
261 {
262     napi_value result;
263 
264     Camera_ErrorCode ret = ndkCamera_->CameraInputClose();
265     napi_create_int32(env, ret, &result);
266     return result;
267 }
268 
CameraInputRelease(napi_env env, napi_callback_info info)269 static napi_value CameraInputRelease(napi_env env, napi_callback_info info)
270 {
271     napi_value result;
272 
273     Camera_ErrorCode ret = ndkCamera_->CameraInputRelease();
274     napi_create_int32(env, ret, &result);
275     return result;
276 }
277 
PreviewOutputStart(napi_env env, napi_callback_info info)278 static napi_value PreviewOutputStart(napi_env env, napi_callback_info info)
279 {
280     napi_value result;
281 
282     Camera_ErrorCode ret = ndkCamera_->PreviewOutputStart();
283     napi_create_int32(env, ret, &result);
284     return result;
285 }
286 
PreviewOutputStop(napi_env env, napi_callback_info info)287 static napi_value PreviewOutputStop(napi_env env, napi_callback_info info)
288 {
289     napi_value result;
290 
291     Camera_ErrorCode ret = ndkCamera_->PreviewOutputStop();
292     napi_create_int32(env, ret, &result);
293     return result;
294 }
295 
PreviewOutputRelease(napi_env env, napi_callback_info info)296 static napi_value PreviewOutputRelease(napi_env env, napi_callback_info info)
297 {
298     napi_value result;
299 
300     Camera_ErrorCode ret = ndkCamera_->PreviewOutputRelease();
301     napi_create_int32(env, ret, &result);
302     return result;
303 }
304 
PhotoOutputCapture(napi_env env, napi_callback_info info)305 static napi_value PhotoOutputCapture(napi_env env, napi_callback_info info)
306 {
307     napi_value result;
308 
309     Camera_ErrorCode ret = ndkCamera_->PhotoOutputCapture();
310     napi_create_int32(env, ret, &result);
311     return result;
312 }
313 
PhotoOutputRelease(napi_env env, napi_callback_info info)314 static napi_value PhotoOutputRelease(napi_env env, napi_callback_info info)
315 {
316     napi_value result;
317 
318     Camera_ErrorCode ret = ndkCamera_->PhotoOutputRelease();
319     napi_create_int32(env, ret, &result);
320     return result;
321 }
322 
IsMirrorSupported(napi_env env, napi_callback_info info)323 static napi_value IsMirrorSupported(napi_env env, napi_callback_info info)
324 {
325     napi_value result;
326 
327     ndkCamera_->IsMirrorSupported();
328     napi_get_boolean(env, ndkCamera_->IsMirror_, &result);
329     return result;
330 }
331 
VideoOutputStop(napi_env env, napi_callback_info info)332 static napi_value VideoOutputStop(napi_env env, napi_callback_info info)
333 {
334     napi_value result;
335 
336     Camera_ErrorCode ret = ndkCamera_->VideoOutputStop();
337     napi_create_int32(env, ret, &result);
338     return result;
339 }
340 
VideoOutputRelease(napi_env env, napi_callback_info info)341 static napi_value VideoOutputRelease(napi_env env, napi_callback_info info)
342 {
343     napi_value result;
344 
345     Camera_ErrorCode ret = ndkCamera_->VideoOutputRelease();
346     napi_create_int32(env, ret, &result);
347     return result;
348 }
349 
MetadataOutputStart(napi_env env, napi_callback_info info)350 static napi_value MetadataOutputStart(napi_env env, napi_callback_info info)
351 {
352     napi_value result;
353 
354     Camera_ErrorCode ret = ndkCamera_->MetadataOutputStart();
355     napi_create_int32(env, ret, &result);
356     return result;
357 }
358 
MetadataOutputStop(napi_env env, napi_callback_info info)359 static napi_value MetadataOutputStop(napi_env env, napi_callback_info info)
360 {
361     napi_value result;
362 
363     Camera_ErrorCode ret = ndkCamera_->MetadataOutputStop();
364     napi_create_int32(env, ret, &result);
365     return result;
366 }
367 
MetadataOutputRelease(napi_env env, napi_callback_info info)368 static napi_value MetadataOutputRelease(napi_env env, napi_callback_info info)
369 {
370     napi_value result;
371 
372     Camera_ErrorCode ret = ndkCamera_->MetadataOutputRelease();
373     napi_create_int32(env, ret, &result);
374     return result;
375 }
376 
SessionAddInput(napi_env env, napi_callback_info info)377 static napi_value SessionAddInput(napi_env env, napi_callback_info info)
378 {
379     napi_value result;
380 
381     Camera_ErrorCode ret = ndkCamera_->SessionAddInput();
382     napi_create_int32(env, ret, &result);
383     return result;
384 }
385 
SessionRemoveInput(napi_env env, napi_callback_info info)386 static napi_value SessionRemoveInput(napi_env env, napi_callback_info info)
387 {
388     napi_value result;
389 
390     Camera_ErrorCode ret = ndkCamera_->SessionRemoveInput();
391     napi_create_int32(env, ret, &result);
392     return result;
393 }
394 
SessionAddPreviewOutput(napi_env env, napi_callback_info info)395 static napi_value SessionAddPreviewOutput(napi_env env, napi_callback_info info)
396 {
397     napi_value result;
398 
399     Camera_ErrorCode ret = ndkCamera_->SessionAddPreviewOutput();
400     napi_create_int32(env, ret, &result);
401     return result;
402 }
403 
SessionAddPhotoOutput(napi_env env, napi_callback_info info)404 static napi_value SessionAddPhotoOutput(napi_env env, napi_callback_info info)
405 {
406     napi_value result;
407 
408     Camera_ErrorCode ret = ndkCamera_->SessionAddPhotoOutput();
409     napi_create_int32(env, ret, &result);
410     return result;
411 }
412 
SessionAddVideoOutput(napi_env env, napi_callback_info info)413 static napi_value SessionAddVideoOutput(napi_env env, napi_callback_info info)
414 {
415     napi_value result;
416 
417     Camera_ErrorCode ret = ndkCamera_->SessionAddVideoOutput();
418     napi_create_int32(env, ret, &result);
419     return result;
420 }
421 
SessionAddMetadataOutput(napi_env env, napi_callback_info info)422 static napi_value SessionAddMetadataOutput(napi_env env, napi_callback_info info)
423 {
424     napi_value result;
425 
426     Camera_ErrorCode ret = ndkCamera_->SessionAddMetadataOutput();
427     napi_create_int32(env, ret, &result);
428     return result;
429 }
430 
SessionRemovePreviewOutput(napi_env env, napi_callback_info info)431 static napi_value SessionRemovePreviewOutput(napi_env env, napi_callback_info info)
432 {
433     napi_value result;
434 
435     Camera_ErrorCode ret = ndkCamera_->SessionRemovePreviewOutput();
436     napi_create_int32(env, ret, &result);
437     return result;
438 }
439 
SessionRemovePhotoOutput(napi_env env, napi_callback_info info)440 static napi_value SessionRemovePhotoOutput(napi_env env, napi_callback_info info)
441 {
442     napi_value result;
443 
444     Camera_ErrorCode ret = ndkCamera_->SessionRemovePhotoOutput();
445     napi_create_int32(env, ret, &result);
446     return result;
447 }
448 
SessionRemoveVideoOutput(napi_env env, napi_callback_info info)449 static napi_value SessionRemoveVideoOutput(napi_env env, napi_callback_info info)
450 {
451     napi_value result;
452 
453     Camera_ErrorCode ret = ndkCamera_->SessionRemoveVideoOutput();
454     napi_create_int32(env, ret, &result);
455     return result;
456 }
457 
SessionRemoveMetadataOutput(napi_env env, napi_callback_info info)458 static napi_value SessionRemoveMetadataOutput(napi_env env, napi_callback_info info)
459 {
460     napi_value result;
461 
462     Camera_ErrorCode ret = ndkCamera_->SessionRemoveMetadataOutput();
463     napi_create_int32(env, ret, &result);
464     return result;
465 }
466 
SessionStart(napi_env env, napi_callback_info info)467 static napi_value SessionStart(napi_env env, napi_callback_info info)
468 {
469     napi_value result;
470 
471     Camera_ErrorCode ret = ndkCamera_->SessionStart();
472     napi_create_int32(env, ret, &result);
473     return result;
474 }
475 
SessionStop(napi_env env, napi_callback_info info)476 static napi_value SessionStop(napi_env env, napi_callback_info info)
477 {
478     napi_value result;
479 
480     Camera_ErrorCode ret = ndkCamera_->SessionStop();
481     napi_create_int32(env, ret, &result);
482     return result;
483 }
484 
SessionBegin(napi_env env, napi_callback_info info)485 static napi_value SessionBegin(napi_env env, napi_callback_info info)
486 {
487     napi_value result;
488 
489     Camera_ErrorCode ret = ndkCamera_->SessionBegin();
490     napi_create_int32(env, ret, &result);
491     return result;
492 }
493 
SessionCommitConfig(napi_env env, napi_callback_info info)494 static napi_value SessionCommitConfig(napi_env env, napi_callback_info info)
495 {
496     napi_value result;
497 
498     Camera_ErrorCode ret = ndkCamera_->SessionCommitConfig();
499     napi_create_int32(env, ret, &result);
500     return result;
501 }
502 
SessionRelease(napi_env env, napi_callback_info info)503 static napi_value SessionRelease(napi_env env, napi_callback_info info)
504 {
505     napi_value result;
506 
507     Camera_ErrorCode ret = ndkCamera_->SessionRelease();
508     napi_create_int32(env, ret, &result);
509     return result;
510 }
511 
CreateSession(napi_env env, napi_callback_info info)512 static napi_value CreateSession(napi_env env, napi_callback_info info)
513 {
514     napi_value result;
515 
516     Camera_ErrorCode ret = ndkCamera_->CreateSession();
517     napi_create_int32(env, ret, &result);
518     return result;
519 }
520 
SessionHasFlash(napi_env env, napi_callback_info info)521 static napi_value SessionHasFlash(napi_env env, napi_callback_info info)
522 {
523     napi_value result;
524 
525     ndkCamera_->SessionHasFlash();
526     napi_get_boolean(env, ndkCamera_->HasFlash_, &result);
527     return result;
528 }
529 
SessionIsFlashModeSupported(napi_env env, napi_callback_info info)530 static napi_value SessionIsFlashModeSupported(napi_env env, napi_callback_info info)
531 {
532     size_t argc = 2;
533     napi_value args[2] = {nullptr};
534     napi_value result;
535 
536     napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
537 
538     int32_t flashMode;
539     napi_get_value_int32(env, args[0], &flashMode);
540 
541     ndkCamera_->SessionIsFlashModeSupported(flashMode);
542     napi_get_boolean(env, ndkCamera_->IsFlashMode_, &result);
543     return result;
544 }
545 
SessionGetFlashMode(napi_env env, napi_callback_info info)546 static napi_value SessionGetFlashMode(napi_env env, napi_callback_info info)
547 {
548     napi_value result;
549 
550     ndkCamera_->SessionGetFlashMode();
551     Camera_FlashMode flashMode = ndkCamera_->flashMode_;
552     napi_create_int32(env, flashMode, &result);
553     return result;
554 }
555 
SessionGetPhotoRotation(napi_env env, napi_callback_info info)556 static napi_value SessionGetPhotoRotation(napi_env env, napi_callback_info info)
557 {
558     size_t argc = 2;
559     napi_value args[2] = {nullptr};
560     napi_value result;
561 
562     napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
563 
564     int32_t rotation;
565     napi_get_value_int32(env, args[0], &rotation);
566     Camera_ErrorCode ret = ndkCamera_->SessionGetPhotoRotation(rotation);
567     napi_create_int32(env, ret, &result);
568     return result;
569 }
570 
SessionGetVideoRotation(napi_env env, napi_callback_info info)571 static napi_value SessionGetVideoRotation(napi_env env, napi_callback_info info)
572 {
573     size_t argc = 2;
574     napi_value args[2] = {nullptr};
575     napi_value result;
576 
577     napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
578 
579     int32_t rotation;
580     napi_get_value_int32(env, args[0], &rotation);
581     Camera_ErrorCode ret = ndkCamera_->SessionGetVideoRotation(rotation);
582     napi_create_int32(env, ret, &result);
583     return result;
584 }
585 
SessionGetPreviewRotation(napi_env env, napi_callback_info info)586 static napi_value SessionGetPreviewRotation(napi_env env, napi_callback_info info)
587 {
588     size_t argc = 2;
589     napi_value args[2] = {nullptr};
590     napi_value result;
591 
592     napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
593 
594     int32_t rotation;
595     napi_get_value_int32(env, args[0], &rotation);
596     Camera_ErrorCode ret = ndkCamera_->SessionGetPreviewRotation(rotation);
597     napi_create_int32(env, ret, &result);
598     return result;
599 }
600 
SessionSetPreviewRotation(napi_env env, napi_callback_info info)601 static napi_value SessionSetPreviewRotation(napi_env env, napi_callback_info info)
602 {
603     size_t argc = 2;
604     napi_value args[2] = {nullptr};
605     napi_value result;
606 
607     napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
608 
609     int32_t rotation;
610     napi_get_value_int32(env, args[0], &rotation);
611     bool isDisplayLocked;
612     napi_get_value_bool(env, args[1], &isDisplayLocked);
613     Camera_ErrorCode ret = ndkCamera_->SessionSetPreviewRotation(rotation, isDisplayLocked);
614     napi_create_int32(env, ret, &result);
615     return result;
616 }
617 
SessionSetFlashMode(napi_env env, napi_callback_info info)618 static napi_value SessionSetFlashMode(napi_env env, napi_callback_info info)
619 {
620     size_t argc = 2;
621     napi_value args[2] = {nullptr};
622     napi_value result;
623 
624     napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
625 
626     int32_t flashMode;
627     napi_get_value_int32(env, args[0], &flashMode);
628     Camera_ErrorCode ret = ndkCamera_->SessionSetFlashMode(flashMode);
629     napi_create_int32(env, ret, &result);
630     return result;
631 }
632 
SessionIsExposureModeSupported(napi_env env, napi_callback_info info)633 static napi_value SessionIsExposureModeSupported(napi_env env, napi_callback_info info)
634 {
635     size_t argc = 2;
636     napi_value args[2] = {nullptr};
637     napi_value result;
638 
639     napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
640 
641     int32_t exposureMode;
642     napi_get_value_int32(env, args[0], &exposureMode);
643 
644     ndkCamera_->SessionIsExposureModeSupported(exposureMode);
645     napi_get_boolean(env, ndkCamera_->IsExposureMode_, &result);
646     return result;
647 }
648 
SessionGetExposureMode(napi_env env, napi_callback_info info)649 static napi_value SessionGetExposureMode(napi_env env, napi_callback_info info)
650 {
651     napi_value result;
652 
653     ndkCamera_->SessionGetExposureMode();
654     Camera_ExposureMode exposureMode = ndkCamera_->exposureMode_;
655     napi_create_int32(env, exposureMode, &result);
656     return result;
657 }
658 
SessionSetExposureMode(napi_env env, napi_callback_info info)659 static napi_value SessionSetExposureMode(napi_env env, napi_callback_info info)
660 {
661     size_t argc = 2;
662     napi_value args[2] = {nullptr};
663     napi_value result;
664     napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
665     int32_t exposureMode;
666     napi_get_value_int32(env, args[0], &exposureMode);
667     Camera_ErrorCode ret = ndkCamera_->SessionSetExposureMode(exposureMode);
668     napi_create_int32(env, ret, &result);
669     return result;
670 }
671 
SessionGetMeteringPoint(napi_env env, napi_callback_info info)672 static napi_value SessionGetMeteringPoint(napi_env env, napi_callback_info info)
673 {
674     ndkCamera_->SessionGetMeteringPoint();
675     Camera_Point point = ndkCamera_->point_;
676     napi_value Point = nullptr;
677     napi_create_object(env, &Point);
678 
679     napi_value jsValue = nullptr;
680     napi_create_double(env, point.x, &jsValue);
681     napi_set_named_property(env, Point, "x", jsValue);
682 
683     napi_create_double(env, point.y, &jsValue);
684     napi_set_named_property(env, Point, "y", jsValue);
685 
686     return Point;
687 }
688 
SessionSetMeteringPoint(napi_env env, napi_callback_info info)689 static napi_value SessionSetMeteringPoint(napi_env env, napi_callback_info info)
690 {
691     size_t argc = 2;
692     napi_value args[2] = {nullptr};
693     napi_value result;
694 
695     napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
696 
697     napi_value value = nullptr;
698     napi_get_named_property(env, args[0], "x", &value);
699     double x;
700     napi_get_value_double(env, value, &x);
701 
702     napi_get_named_property(env, args[0], "y", &value);
703     double y;
704     napi_get_value_double(env, value, &y);
705 
706     Camera_ErrorCode ret = ndkCamera_->SessionSetMeteringPoint(x,y);
707     napi_create_int32(env, ret, &result);
708     return result;
709 }
710 
SessionGetExposureBiasRange(napi_env env, napi_callback_info info)711 static napi_value SessionGetExposureBiasRange(napi_env env, napi_callback_info info)
712 {
713     ndkCamera_->SessionGetExposureBiasRange();
714     napi_value exposureBias = nullptr;
715     napi_create_object(env, &exposureBias);
716 
717     napi_value jsValue = nullptr;
718 
719     napi_create_double(env, ndkCamera_->minExposureBias_, &jsValue);
720     napi_set_named_property(env, exposureBias, "minExposureBias", jsValue);
721 
722     napi_create_double(env, ndkCamera_->maxExposureBias_, &jsValue);
723     napi_set_named_property(env, exposureBias, "maxExposureBias", jsValue);
724 
725     return exposureBias;
726 }
727 
SessionSetExposureBias(napi_env env, napi_callback_info info)728 static napi_value SessionSetExposureBias(napi_env env, napi_callback_info info)
729 {
730     size_t argc = 2;
731     napi_value args[2] = {nullptr};
732     napi_value result;
733 
734     napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
735 
736     double exposureBias;
737     napi_get_value_double(env, args[0], &exposureBias);
738     Camera_ErrorCode ret = ndkCamera_->SessionSetExposureBias(exposureBias);
739     napi_create_int32(env, ret, &result);
740     return result;
741 }
742 
SessionGetExposureBias(napi_env env, napi_callback_info info)743 static napi_value SessionGetExposureBias(napi_env env, napi_callback_info info)
744 {
745     napi_value result;
746 
747     ndkCamera_->SessionGetExposureBias();
748     double exposureBias = ndkCamera_->exposureBias_;
749     napi_create_double(env, exposureBias, &result);
750     return result;
751 }
752 
SessionIsFocusModeSupported(napi_env env, napi_callback_info info)753 static napi_value SessionIsFocusModeSupported(napi_env env, napi_callback_info info)
754 {
755     size_t argc = 2;
756     napi_value args[2] = {nullptr};
757     napi_value result;
758 
759     napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
760 
761     int32_t focusMode;
762     napi_get_value_int32(env, args[0], &focusMode);
763 
764     ndkCamera_->SessionIsFocusModeSupported(focusMode);
765     napi_get_boolean(env, ndkCamera_->isFocusSupported_, &result);
766     return result;
767 }
768 
SessionGetFocusMode(napi_env env, napi_callback_info info)769 static napi_value SessionGetFocusMode(napi_env env, napi_callback_info info)
770 {
771     napi_value result;
772 
773     ndkCamera_->SessionGetFocusMode();
774     Camera_FocusMode focusMode = ndkCamera_->focusMode_;
775     napi_create_int32(env, focusMode, &result);
776     return result;
777 }
778 
SessionSetFocusMode(napi_env env, napi_callback_info info)779 static napi_value SessionSetFocusMode(napi_env env, napi_callback_info info)
780 {
781     size_t argc = 2;
782     napi_value args[2] = {nullptr};
783     napi_value result;
784 
785     napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
786 
787     int32_t focusMode;
788     napi_get_value_int32(env, args[0], &focusMode);
789     Camera_ErrorCode ret = ndkCamera_->SessionSetFocusMode(focusMode);
790     napi_create_int32(env, ret, &result);
791     return result;
792 }
793 
SessionSetFocusPoint(napi_env env, napi_callback_info info)794 static napi_value SessionSetFocusPoint(napi_env env, napi_callback_info info)
795 {
796     size_t argc = 2;
797     napi_value args[2] = {nullptr};
798     napi_value result;
799 
800     napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
801 
802     napi_value value = nullptr;
803     napi_get_named_property(env, args[0], "x", &value);
804     double x;
805     napi_get_value_double(env, value, &x);
806 
807     napi_get_named_property(env, args[0], "y", &value);
808     double y;
809     napi_get_value_double(env, value, &y);
810 
811     Camera_ErrorCode ret = ndkCamera_->SessionSetFocusPoint(x,y);
812     napi_create_int32(env, ret, &result);
813     return result;
814 }
815 
SessionGetFocusPoint(napi_env env, napi_callback_info info)816 static napi_value SessionGetFocusPoint(napi_env env, napi_callback_info info)
817 {
818     ndkCamera_->SessionGetFocusPoint();
819     Camera_Point point = ndkCamera_->focusPoint_;
820     napi_value Point = nullptr;
821     napi_create_object(env, &Point);
822 
823     napi_value jsValue = nullptr;
824     napi_create_double(env, point.x, &jsValue);
825     napi_set_named_property(env, Point, "x", jsValue);
826 
827     napi_create_double(env, point.y, &jsValue);
828     napi_set_named_property(env, Point, "y", jsValue);
829 
830     return Point;
831 }
832 
SessionGetZoomRatioRange(napi_env env, napi_callback_info info)833 static napi_value SessionGetZoomRatioRange(napi_env env, napi_callback_info info)
834 {
835     ndkCamera_->SessionGetZoomRatioRange();
836 
837     napi_value zoomRatio = nullptr;
838     napi_create_object(env, &zoomRatio);
839 
840     napi_value jsValue = nullptr;
841 
842     napi_create_double(env, ndkCamera_->minZoom_, &jsValue);
843     napi_set_named_property(env, zoomRatio, "minZoom", jsValue);
844 
845     napi_create_double(env, ndkCamera_->maxZoom_, &jsValue);
846     napi_set_named_property(env, zoomRatio, "maxZoom", jsValue);
847 
848     return zoomRatio;
849 }
850 
SessionGetZoomRatio(napi_env env, napi_callback_info info)851 static napi_value SessionGetZoomRatio(napi_env env, napi_callback_info info)
852 {
853     napi_value result;
854 
855     ndkCamera_->SessionGetZoomRatio();
856     napi_create_double(env, ndkCamera_->zoom_, &result);
857     return result;
858 }
859 
SessionSetZoomRatio(napi_env env, napi_callback_info info)860 static napi_value SessionSetZoomRatio(napi_env env, napi_callback_info info)
861 {
862     size_t argc = 2;
863     napi_value args[2] = {nullptr};
864     napi_value result;
865 
866     napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
867 
868     double zoomRatio;
869     napi_get_value_double(env, args[0], &zoomRatio);
870     Camera_ErrorCode ret = ndkCamera_->SessionSetZoomRatio(zoomRatio);
871     napi_create_int32(env, ret, &result);
872     return result;
873 }
874 
SessionIsVideoStabilizationModeSupported(napi_env env, napi_callback_info info)875 static napi_value SessionIsVideoStabilizationModeSupported(napi_env env, napi_callback_info info)
876 {
877     size_t argc = 2;
878     napi_value args[2] = {nullptr};
879     napi_value result;
880 
881     napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
882     int32_t videoStabilizationMode;
883     napi_get_value_int32(env, args[0], &videoStabilizationMode);
884     ndkCamera_->SessionIsVideoStabilizationModeSupported(videoStabilizationMode);
885     napi_get_boolean(env, ndkCamera_->isVideoSupported_, &result);
886     return result;
887 }
888 
SessionGetVideoStabilizationMode(napi_env env, napi_callback_info info)889 static napi_value SessionGetVideoStabilizationMode(napi_env env, napi_callback_info info)
890 {
891     napi_value result;
892 
893     ndkCamera_->SessionGetVideoStabilizationMode();
894     Camera_VideoStabilizationMode videoMode = ndkCamera_->videoMode_;
895     napi_create_int32(env, videoMode, &result);
896     return result;
897 }
898 
SessionSetVideoStabilizationMode(napi_env env, napi_callback_info info)899 static napi_value SessionSetVideoStabilizationMode(napi_env env, napi_callback_info info)
900 {
901     size_t argc = 2;
902     napi_value args[2] = {nullptr};
903     napi_value result;
904 
905     napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
906 
907     int32_t videoStabilizationMode;
908     napi_get_value_int32(env, args[0], &videoStabilizationMode);
909     Camera_ErrorCode ret = ndkCamera_->SessionSetVideoStabilizationMode(videoStabilizationMode);
910     napi_create_int32(env, ret, &result);
911     return result;
912 }
913 
GetCameraCallbackCode(napi_env env, napi_callback_info info)914 static napi_value GetCameraCallbackCode(napi_env env, napi_callback_info info)
915 {
916     napi_value result;
917 
918     CameraCallbackCode status  = ndkCamera_->cameraCallbackCode_;
919     napi_create_int32(env, status, &result);
920     return result;
921 }
922 
GetCaptureParam(napi_env env, napi_value captureConfigValue, Capture_Setting *config)923 static napi_value GetCaptureParam(napi_env env, napi_value captureConfigValue, Capture_Setting *config)
924 {
925     napi_value value = nullptr;
926     napi_get_named_property(env, captureConfigValue, "quality", &value);
927     napi_get_value_int32(env, value, &config->quality);
928 
929     napi_get_named_property(env, captureConfigValue, "rotation", &value);
930     napi_get_value_int32(env, value, &config->rotation);
931 
932     napi_get_named_property(env, captureConfigValue, "mirror", &value);
933     napi_get_value_bool(env, value, &config->mirror);
934 
935     napi_get_named_property(env, captureConfigValue, "latitude", &value);
936     napi_get_value_int32(env, value, &config->latitude);
937 
938     napi_get_named_property(env, captureConfigValue, "longitude", &value);
939     napi_get_value_int32(env, value, &config->longitude);
940 
941     napi_get_named_property(env, captureConfigValue, "altitude", &value);
942     napi_get_value_int32(env, value, &config->altitude);
943 
944     return 0;
945 }
946 
SetConfig(Capture_Setting settings, Camera_PhotoCaptureSetting* photoSetting, Camera_Location* location)947 static void SetConfig(Capture_Setting settings, Camera_PhotoCaptureSetting* photoSetting, Camera_Location* location)
948 {
949     if (photoSetting == nullptr || location == nullptr) {
950         return;
951     }
952     photoSetting->quality = static_cast<Camera_QualityLevel>(settings.quality);
953     photoSetting->rotation = static_cast<Camera_ImageRotation>(settings.rotation);
954     photoSetting->mirror = settings.mirror;
955     location->altitude = settings.altitude;
956     location->latitude = settings.latitude;
957     location->longitude = settings.longitude;
958     photoSetting->location = location;
959 }
960 
TakePictureWithSettings(napi_env env, napi_callback_info info)961 static napi_value TakePictureWithSettings(napi_env env, napi_callback_info info)
962 {
963     size_t argc = 1;
964     napi_value args[1] = {nullptr};
965     Camera_PhotoCaptureSetting photoSetting;
966     Capture_Setting setting_inner;
967     Camera_Location* location = new Camera_Location;
968 
969     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
970     GetCaptureParam(env, args[0], &setting_inner);
971     SetConfig(setting_inner, &photoSetting, location);
972 
973     napi_value result;
974     Camera_ErrorCode ret = ndkCamera_->TakePictureWithPhotoSettings(photoSetting);
975     napi_create_int32(env, ret, &result);
976     return result;
977 }
OHCaptureSessionRegisterCallback(napi_env env, napi_callback_info info)978 static napi_value OHCaptureSessionRegisterCallback(napi_env env, napi_callback_info info)
979 {
980     size_t argc = 1;
981     napi_value args[1] = {nullptr};
982     napi_value result;
983 
984     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
985 
986     int32_t index;
987     napi_get_value_int32(env, args[0], &index);
988 
989     Camera_ErrorCode code = ndkCamera_->CaptureSessionRegisterCallback(index);
990 
991     napi_create_int32(env, code, &result);
992     return result;
993 }
OHCaptureSessionUnregisterCallback(napi_env env, napi_callback_info info)994 static napi_value OHCaptureSessionUnregisterCallback(napi_env env, napi_callback_info info)
995 {
996     size_t argc = 1;
997     napi_value args[1] = {nullptr};
998     napi_value result;
999 
1000     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1001 
1002     int32_t index;
1003     napi_get_value_int32(env, args[0], &index);
1004 
1005     Camera_ErrorCode code = ndkCamera_->CaptureSessionUnRegisterCallback(index);
1006 
1007     napi_create_int32(env, code, &result);
1008     return result;
1009 }
OHCameraManagerGetSupportedSceneModes(napi_env env, napi_callback_info info)1010 static napi_value OHCameraManagerGetSupportedSceneModes(napi_env env, napi_callback_info info)
1011 {
1012     size_t argc = 1;
1013     napi_value args[1] = {nullptr};
1014 
1015     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1016 
1017     int32_t index;
1018     napi_get_value_int32(env, args[0], &index);
1019 
1020     Camera_ErrorCode code = ndkCamera_->GetSupportedSceneModes(index);
1021 
1022     napi_value supportedSceneModes = nullptr;
1023     napi_create_object(env, &supportedSceneModes);
1024     napi_value jsValue = nullptr;
1025 
1026     napi_create_int32(env, ndkCamera_->sceneModesSize_, &jsValue);
1027     napi_set_named_property(env, supportedSceneModes, "sceneModesSize", jsValue);
1028 
1029     napi_create_int32(env, code, &jsValue);
1030     napi_set_named_property(env, supportedSceneModes, "errorCode", jsValue);
1031 
1032     bool normalPhoto = ndkCamera_->isNormalPhoto_;
1033     napi_get_boolean(env, normalPhoto, &jsValue);
1034     napi_set_named_property(env, supportedSceneModes, "isNormalPhoto", jsValue);
1035 
1036     bool normalVideo = ndkCamera_->isNormalVideo_;
1037     napi_get_boolean(env, normalVideo, &jsValue);
1038     napi_set_named_property(env, supportedSceneModes, "isNormalVideo", jsValue);
1039 
1040     bool securePhoto = ndkCamera_->isSecurePhoto_;
1041     napi_get_boolean(env, securePhoto, &jsValue);
1042     napi_set_named_property(env, supportedSceneModes, "isSecurePhoto", jsValue);
1043 
1044     return supportedSceneModes;
1045 }
OHCameraManagerDeleteSceneModes(napi_env env, napi_callback_info info)1046 static napi_value OHCameraManagerDeleteSceneModes(napi_env env, napi_callback_info info)
1047 {
1048     size_t argc = 1;
1049     napi_value args[1] = {nullptr};
1050     napi_value result;
1051 
1052     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1053 
1054     int32_t index;
1055     napi_get_value_int32(env, args[0], &index);
1056 
1057     Camera_ErrorCode code = ndkCamera_->DeleteSceneModes(index);
1058 
1059     napi_create_int32(env, code, &result);
1060     return result;
1061 }
OHCameraManagerGetSupportedCameraOutputCapabilityWithSceneMode(napi_env env, napi_callback_info info)1062 static napi_value OHCameraManagerGetSupportedCameraOutputCapabilityWithSceneMode(napi_env env,
1063     napi_callback_info info)
1064 {
1065     size_t argc = 1;
1066     napi_value args[1] = {nullptr};
1067     napi_value result;
1068 
1069     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1070 
1071     int32_t index;
1072     napi_get_value_int32(env, args[0], &index);
1073 
1074     Camera_ErrorCode code = ndkCamera_->GetSupportedCameraOutputCapabilityWithSceneMode(index);
1075 
1076     napi_create_int32(env, code, &result);
1077     return result;
1078 }
OHCaptureSessionSetSessionMode(napi_env env, napi_callback_info info)1079 static napi_value OHCaptureSessionSetSessionMode(napi_env env, napi_callback_info info)
1080 {
1081     size_t argc = 1;
1082     napi_value args[1] = {nullptr};
1083     napi_value result;
1084 
1085     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1086 
1087     int32_t index;
1088     napi_get_value_int32(env, args[0], &index);
1089 
1090     Camera_ErrorCode code = ndkCamera_->SetSessionMode(index);
1091 
1092     napi_create_int32(env, code, &result);
1093     return result;
1094 }
OHCaptureSessionCanAddInput(napi_env env, napi_callback_info info)1095 static napi_value OHCaptureSessionCanAddInput(napi_env env, napi_callback_info info)
1096 {
1097     size_t argc = 1;
1098     napi_value args[1] = {nullptr};
1099 
1100     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1101 
1102     int32_t index;
1103     napi_get_value_int32(env, args[0], &index);
1104 
1105     Camera_ErrorCode code = ndkCamera_->CanAddInput(index);
1106 
1107     napi_value canAddInput = nullptr;
1108     napi_create_object(env, &canAddInput);
1109     napi_value jsValue = nullptr;
1110 
1111     bool result = ndkCamera_->isAddInput_;
1112     napi_get_boolean(env, result, &jsValue);
1113     napi_set_named_property(env, canAddInput, "isAddInput", jsValue);
1114 
1115     napi_create_int32(env, code, &jsValue);
1116     napi_set_named_property(env, canAddInput, "errorCode", jsValue);
1117 
1118     return canAddInput;
1119 }
OHCaptureSessionCanAddPreviewOutput(napi_env env, napi_callback_info info)1120 static napi_value OHCaptureSessionCanAddPreviewOutput(napi_env env, napi_callback_info info)
1121 {
1122     size_t argc = 1;
1123     napi_value args[1] = {nullptr};
1124 
1125     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1126 
1127     int32_t index;
1128     napi_get_value_int32(env, args[0], &index);
1129 
1130     Camera_ErrorCode code = ndkCamera_->CanAddPreviewOutput(index);
1131 
1132     napi_value canAddPreviewOutput = nullptr;
1133     napi_create_object(env, &canAddPreviewOutput);
1134     napi_value jsValue = nullptr;
1135 
1136     bool result = ndkCamera_->isAddInput_;
1137     napi_get_boolean(env, result, &jsValue);
1138     napi_set_named_property(env, canAddPreviewOutput, "isAddPreviewOutput", jsValue);
1139 
1140     napi_create_int32(env, code, &jsValue);
1141     napi_set_named_property(env, canAddPreviewOutput, "errorCode", jsValue);
1142 
1143     return canAddPreviewOutput;
1144 }
OHCaptureSessionCanAddPhotoOutput(napi_env env, napi_callback_info info)1145 static napi_value OHCaptureSessionCanAddPhotoOutput(napi_env env, napi_callback_info info)
1146 {
1147     size_t argc = 1;
1148     napi_value args[1] = {nullptr};
1149 
1150     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1151 
1152     int32_t index;
1153     napi_get_value_int32(env, args[0], &index);
1154 
1155     Camera_ErrorCode code = ndkCamera_->CanAddPhotoOutput(index);
1156 
1157     napi_value canAddPhotoOutput = nullptr;
1158     napi_create_object(env, &canAddPhotoOutput);
1159     napi_value jsValue = nullptr;
1160 
1161     bool result = ndkCamera_->isAddInput_;
1162     napi_get_boolean(env, result, &jsValue);
1163     napi_set_named_property(env, canAddPhotoOutput, "isAddPhotoOutput", jsValue);
1164 
1165     napi_create_int32(env, code, &jsValue);
1166     napi_set_named_property(env, canAddPhotoOutput, "errorCode", jsValue);
1167 
1168     return canAddPhotoOutput;
1169 }
OHCaptureSessionCanAddVideoOutput(napi_env env, napi_callback_info info)1170 static napi_value OHCaptureSessionCanAddVideoOutput(napi_env env, napi_callback_info info)
1171 {
1172     size_t argc = 1;
1173     napi_value args[1] = {nullptr};
1174 
1175     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1176 
1177     int32_t index;
1178     napi_get_value_int32(env, args[0], &index);
1179 
1180     Camera_ErrorCode code = ndkCamera_->CanAddVideoOutput(index);
1181 
1182     napi_value canAddVideoOutput = nullptr;
1183     napi_create_object(env, &canAddVideoOutput);
1184     napi_value jsValue = nullptr;
1185 
1186     bool result = ndkCamera_->isAddInput_;
1187     napi_get_boolean(env, result, &jsValue);
1188     napi_set_named_property(env, canAddVideoOutput, "isAddVideoOutput", jsValue);
1189 
1190     napi_create_int32(env, code, &jsValue);
1191     napi_set_named_property(env, canAddVideoOutput, "errorCode", jsValue);
1192 
1193     return canAddVideoOutput;
1194 }
OHCaptureSessionAddSecureOutput(napi_env env, napi_callback_info info)1195 static napi_value OHCaptureSessionAddSecureOutput(napi_env env, napi_callback_info info)
1196 {
1197     size_t argc = 1;
1198     napi_value args[1] = {nullptr};
1199     napi_value result;
1200 
1201     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1202 
1203     int32_t index;
1204     napi_get_value_int32(env, args[0], &index);
1205 
1206     Camera_ErrorCode code = ndkCamera_->AddSecureOutput(index);
1207 
1208     napi_create_int32(env, code, &result);
1209     return result;
1210 }
OHCameraInputOpenSecureCamera(napi_env env, napi_callback_info info)1211 static napi_value OHCameraInputOpenSecureCamera(napi_env env, napi_callback_info info)
1212 {
1213     size_t argc = 1;
1214     napi_value args[1] = {nullptr};
1215     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1216 
1217     int32_t index;
1218     napi_get_value_int32(env, args[0], &index);
1219 
1220     Camera_ErrorCode code = ndkCamera_->OpenSecureCamera(index);
1221 
1222     napi_value secureCamera = nullptr;
1223     napi_create_object(env, &secureCamera);
1224     napi_value jsValue = nullptr;
1225 
1226     napi_create_bigint_uint64(env, ndkCamera_->secureSeqId_, &jsValue);
1227     napi_set_named_property(env, secureCamera, "secureSeqId", jsValue);
1228 
1229     napi_create_int32(env, code, &jsValue);
1230     napi_set_named_property(env, secureCamera, "errorCode", jsValue);
1231 
1232     return secureCamera;
1233 }
OHCameraManagerSetSceneMode(napi_env env, napi_callback_info info)1234 static napi_value OHCameraManagerSetSceneMode(napi_env env, napi_callback_info info)
1235 {
1236     size_t argc = 1;
1237     napi_value args[1] = {nullptr};
1238     napi_value result;
1239 
1240     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1241 
1242     int32_t index;
1243     napi_get_value_int32(env, args[0], &index);
1244 
1245     Camera_ErrorCode code = ndkCamera_->SetSceneMode(index);
1246 
1247     napi_create_int32(env, code, &result);
1248     return result;
1249 }
OHCameraManagerCreatePreviewOutputUsedInPreconfig(napi_env env, napi_callback_info info)1250 static napi_value OHCameraManagerCreatePreviewOutputUsedInPreconfig(napi_env env, napi_callback_info info)
1251 {
1252     size_t argc = 1;
1253     napi_value args[1] = {nullptr};
1254     napi_value result;
1255 
1256     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1257 
1258     int32_t index;
1259     napi_get_value_int32(env, args[0], &index);
1260 
1261     Camera_ErrorCode code = ndkCamera_->CreatePreviewOutputUsedInPreconfig(index);
1262 
1263     napi_create_int32(env, code, &result);
1264     return result;
1265 }
OHCameraManagerCreatePhotoOutputUsedInPreconfig(napi_env env, napi_callback_info info)1266 static napi_value OHCameraManagerCreatePhotoOutputUsedInPreconfig(napi_env env, napi_callback_info info)
1267 {
1268     napi_value result;
1269 
1270     size_t argc = 2;
1271     napi_value args[2] = {nullptr};
1272     size_t typeLen = 0;
1273     char *surfaceId = nullptr;
1274 
1275     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1276 
1277     napi_get_value_string_utf8(env, args[0], nullptr, 0, &typeLen);
1278     surfaceId = new char[typeLen + 1];
1279     napi_get_value_string_utf8(env, args[0], surfaceId, typeLen + 1, &typeLen);
1280 
1281     int32_t index;
1282     napi_get_value_int32(env, args[1], &index);
1283     Camera_ErrorCode ret = ndkCamera_->CreatePhotoOutputUsedInPreconfig(surfaceId, index);
1284     napi_create_int32(env, ret, &result);
1285     return result;
1286 }
OHCaptureSessionCanPreconfig(napi_env env, napi_callback_info info)1287 static napi_value OHCaptureSessionCanPreconfig(napi_env env, napi_callback_info info)
1288 {
1289     size_t argc = 2;
1290     napi_value args[2] = {nullptr};
1291 
1292     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1293 
1294     int32_t mode;
1295     napi_get_value_int32(env, args[0], &mode);
1296     int32_t index;
1297     napi_get_value_int32(env, args[1], &index);
1298 
1299     Camera_ErrorCode code = ndkCamera_->SessionCanPreconfig(mode, index);
1300     napi_value sessionCanPreconfig = nullptr;
1301     napi_create_object(env, &sessionCanPreconfig);
1302     napi_value jsValue = nullptr;
1303 
1304     bool result = ndkCamera_->canPreconfig_;
1305     napi_get_boolean(env, result, &jsValue);
1306     napi_set_named_property(env, sessionCanPreconfig, "canPreconfig", jsValue);
1307 
1308     napi_create_int32(env, code, &jsValue);
1309     napi_set_named_property(env, sessionCanPreconfig, "errorCode", jsValue);
1310 
1311     return sessionCanPreconfig;
1312 }
OHCaptureSessionCanPreconfigWithRatio(napi_env env, napi_callback_info info)1313 static napi_value OHCaptureSessionCanPreconfigWithRatio(napi_env env, napi_callback_info info)
1314 {
1315     size_t argc = 3;
1316     napi_value args[3] = {nullptr};
1317 
1318     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1319 
1320     int32_t preconfigTypeValue;
1321     napi_get_value_int32(env, args[0], &preconfigTypeValue);
1322     int32_t preconfigRatioValue;
1323     napi_get_value_int32(env, args[1], &preconfigRatioValue);
1324     int32_t index;
1325     napi_get_value_int32(env, args[NUMBER_2], &index);
1326 
1327     Camera_ErrorCode code = ndkCamera_->SessionCanPreconfigWithRatio(preconfigTypeValue, preconfigRatioValue, index);
1328     napi_value sessionCanPreconfig = nullptr;
1329     napi_create_object(env, &sessionCanPreconfig);
1330     napi_value jsValue = nullptr;
1331 
1332     bool result = ndkCamera_->canPreconfig_;
1333     napi_get_boolean(env, result, &jsValue);
1334     napi_set_named_property(env, sessionCanPreconfig, "canPreconfig", jsValue);
1335 
1336     napi_create_int32(env, code, &jsValue);
1337     napi_set_named_property(env, sessionCanPreconfig, "errorCode", jsValue);
1338 
1339     return sessionCanPreconfig;
1340 }
1341 
OHCaptureSessionPreconfig(napi_env env, napi_callback_info info)1342 static napi_value OHCaptureSessionPreconfig(napi_env env, napi_callback_info info)
1343 {
1344     size_t argc = 2;
1345     napi_value args[2] = {nullptr};
1346     napi_value result;
1347 
1348     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1349 
1350     int32_t mode;
1351     napi_get_value_int32(env, args[0], &mode);
1352     int32_t index;
1353     napi_get_value_int32(env, args[1], &index);
1354 
1355     Camera_ErrorCode code = ndkCamera_->SessionPreconfig(mode, index);
1356     napi_create_int32(env, code, &result);
1357     return result;
1358 }
OHCaptureSessionPreconfigWithRatio(napi_env env, napi_callback_info info)1359 static napi_value OHCaptureSessionPreconfigWithRatio(napi_env env, napi_callback_info info)
1360 {
1361     size_t argc = 3;
1362     napi_value args[3] = {nullptr};
1363     napi_value result;
1364 
1365     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1366 
1367     int32_t preconfigTypeValue;
1368     napi_get_value_int32(env, args[0], &preconfigTypeValue);
1369     int32_t preconfigRatioValue;
1370     napi_get_value_int32(env, args[1], &preconfigRatioValue);
1371     int32_t index;
1372     napi_get_value_int32(env, args[NUMBER_2], &index);
1373 
1374     Camera_ErrorCode code = ndkCamera_->SessionPreconfigWithRatio(preconfigTypeValue, preconfigRatioValue, index);
1375     napi_create_int32(env, code, &result);
1376     return result;
1377 }
OHCameraManagerCreateVideoOutputUsedInPreconfig(napi_env env, napi_callback_info info)1378 static napi_value OHCameraManagerCreateVideoOutputUsedInPreconfig(napi_env env, napi_callback_info info)
1379 {
1380     size_t argc = 2;
1381     napi_value args[2] = {nullptr};
1382     napi_value result;
1383 
1384     size_t videoIdLen = 0;
1385     char *videoId = nullptr;
1386     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1387     napi_get_value_string_utf8(env, args[0], nullptr, 0, &videoIdLen);
1388     videoId = new char[videoIdLen + 1];
1389     napi_get_value_string_utf8(env, args[0], videoId, videoIdLen + 1, &videoIdLen);
1390 
1391     int32_t index;
1392     napi_get_value_int32(env, args[1], &index);
1393 
1394     Camera_ErrorCode ret = ndkCamera_->CreateVideoOutputUsedInPreconfig(videoId, index);
1395     napi_create_int32(env, ret, &result);
1396     return result;
1397 }
OHVideoOutputGetActiveProfile(napi_env env, napi_callback_info info)1398 static napi_value OHVideoOutputGetActiveProfile(napi_env env, napi_callback_info info)
1399 {
1400     size_t argc = 1;
1401     napi_value args[1] = {nullptr};
1402     napi_value result;
1403 
1404     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1405 
1406     int32_t index;
1407     napi_get_value_int32(env, args[0], &index);
1408 
1409     Camera_ErrorCode code = ndkCamera_->VideoOutputGetActiveProfile(index);
1410 
1411     napi_create_int32(env, code, &result);
1412     return result;
1413 }
OHVideoOutputDeleteProfile(napi_env env, napi_callback_info info)1414 static napi_value OHVideoOutputDeleteProfile(napi_env env, napi_callback_info info)
1415 {
1416     size_t argc = 1;
1417     napi_value args[1] = {nullptr};
1418     napi_value result;
1419 
1420     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1421 
1422     int32_t index;
1423     napi_get_value_int32(env, args[0], &index);
1424 
1425     Camera_ErrorCode code = ndkCamera_->VideoOutputDeleteProfile(index);
1426 
1427     napi_create_int32(env, code, &result);
1428     return result;
1429 }
OHPreviewOutputGetActiveProfile(napi_env env, napi_callback_info info)1430 static napi_value OHPreviewOutputGetActiveProfile(napi_env env, napi_callback_info info)
1431 {
1432     size_t argc = 1;
1433     napi_value args[1] = {nullptr};
1434     napi_value result;
1435 
1436     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1437 
1438     int32_t index;
1439     napi_get_value_int32(env, args[0], &index);
1440 
1441     Camera_ErrorCode code = ndkCamera_->PreviewOutputGetActiveProfile(index);
1442 
1443     napi_create_int32(env, code, &result);
1444     return result;
1445 }
OHPreviewOutputDeleteProfile(napi_env env, napi_callback_info info)1446 static napi_value OHPreviewOutputDeleteProfile(napi_env env, napi_callback_info info)
1447 {
1448     size_t argc = 1;
1449     napi_value args[1] = {nullptr};
1450     napi_value result;
1451 
1452     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1453 
1454     int32_t index;
1455     napi_get_value_int32(env, args[0], &index);
1456 
1457     Camera_ErrorCode code = ndkCamera_->PreviewOutputDeleteProfile(index);
1458 
1459     napi_create_int32(env, code, &result);
1460     return result;
1461 }
OHPhotoOutputGetActiveProfile(napi_env env, napi_callback_info info)1462 static napi_value OHPhotoOutputGetActiveProfile(napi_env env, napi_callback_info info)
1463 {
1464     size_t argc = 1;
1465     napi_value args[1] = {nullptr};
1466     napi_value result;
1467 
1468     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1469 
1470     int32_t index;
1471     napi_get_value_int32(env, args[0], &index);
1472 
1473     Camera_ErrorCode code = ndkCamera_->PhotoOutputGetActiveProfile(index);
1474 
1475     napi_create_int32(env, code, &result);
1476     return result;
1477 }
OHPhotoOutputDeleteProfile(napi_env env, napi_callback_info info)1478 static napi_value OHPhotoOutputDeleteProfile(napi_env env, napi_callback_info info)
1479 {
1480     size_t argc = 1;
1481     napi_value args[1] = {nullptr};
1482     napi_value result;
1483 
1484     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1485 
1486     int32_t index;
1487     napi_get_value_int32(env, args[0], &index);
1488 
1489     Camera_ErrorCode code = ndkCamera_->PhotoOutputDeleteProfile(index);
1490 
1491     napi_create_int32(env, code, &result);
1492     return result;
1493 }
OHCaptureSessionRegisterCallbackOn(napi_env env, napi_callback_info info)1494 static napi_value OHCaptureSessionRegisterCallbackOn(napi_env env, napi_callback_info info)
1495 {
1496     size_t argc = 1;
1497     napi_value args[1] = {nullptr};
1498     napi_value result;
1499 
1500     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1501 
1502     int32_t index;
1503     napi_get_value_int32(env, args[0], &index);
1504 
1505     Camera_ErrorCode code = ndkCamera_->CaptureSessionRegisterCallbackOn(index);
1506 
1507     napi_create_int32(env, code, &result);
1508     return result;
1509 }
OHCaptureSessionUnregisterCallbackOff(napi_env env, napi_callback_info info)1510 static napi_value OHCaptureSessionUnregisterCallbackOff(napi_env env, napi_callback_info info)
1511 {
1512     size_t argc = 1;
1513     napi_value args[1] = {nullptr};
1514     napi_value result;
1515 
1516     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1517 
1518     int32_t index;
1519     napi_get_value_int32(env, args[0], &index);
1520 
1521     Camera_ErrorCode code = ndkCamera_->CaptureSessionUnregisterCallbackOff(index);
1522 
1523     napi_create_int32(env, code, &result);
1524     return result;
1525 }
OHPhotoOutputRegisterPhotoAvailableCallback(napi_env env, napi_callback_info info)1526 static napi_value OHPhotoOutputRegisterPhotoAvailableCallback(napi_env env, napi_callback_info info)
1527 {
1528     size_t argc = 1;
1529     napi_value args[1] = {nullptr};
1530     napi_value result;
1531 
1532     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1533 
1534     int32_t index;
1535     napi_get_value_int32(env, args[0], &index);
1536 
1537     Camera_ErrorCode code = ndkCamera_->RegisterPhotoAvailableCallback(index);
1538 
1539     napi_create_int32(env, code, &result);
1540     return result;
1541 }
OHPhotoOutputUnregisterPhotoAvailableCallback(napi_env env, napi_callback_info info)1542 static napi_value OHPhotoOutputUnregisterPhotoAvailableCallback(napi_env env, napi_callback_info info)
1543 {
1544     size_t argc = 1;
1545     napi_value args[1] = {nullptr};
1546     napi_value result;
1547 
1548     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1549 
1550     int32_t index;
1551     napi_get_value_int32(env, args[0], &index);
1552 
1553     Camera_ErrorCode code = ndkCamera_->UnregisterPhotoAvailableCallback(index);
1554 
1555     napi_create_int32(env, code, &result);
1556     return result;
1557 }
OHPhotoOutputRegisterPhotoAssetAvailableCallback(napi_env env, napi_callback_info info)1558 static napi_value OHPhotoOutputRegisterPhotoAssetAvailableCallback(napi_env env, napi_callback_info info)
1559 {
1560     size_t argc = 1;
1561     napi_value args[1] = {nullptr};
1562     napi_value result;
1563 
1564     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1565 
1566     int32_t index;
1567     napi_get_value_int32(env, args[0], &index);
1568 
1569     Camera_ErrorCode code = ndkCamera_->RegisterPhotoAssetAvailableCallback(index);
1570 
1571     napi_create_int32(env, code, &result);
1572     return result;
1573 }
OHPhotoOutputUnregisterPhotoAssetAvailableCallback(napi_env env, napi_callback_info info)1574 static napi_value OHPhotoOutputUnregisterPhotoAssetAvailableCallback(napi_env env, napi_callback_info info)
1575 {
1576     size_t argc = 1;
1577     napi_value args[1] = {nullptr};
1578     napi_value result;
1579 
1580     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1581 
1582     int32_t index;
1583     napi_get_value_int32(env, args[0], &index);
1584 
1585     Camera_ErrorCode code = ndkCamera_->UnregisterPhotoAssetAvailableCallback(index);
1586 
1587     napi_create_int32(env, code, &result);
1588     return result;
1589 }
OHPhotoOutputIsMovingPhotoSupported(napi_env env, napi_callback_info info)1590 static napi_value OHPhotoOutputIsMovingPhotoSupported(napi_env env, napi_callback_info info)
1591 {
1592     size_t argc = 1;
1593     napi_value args[1] = {nullptr};
1594 
1595     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1596 
1597     int32_t index;
1598     napi_get_value_int32(env, args[0], &index);
1599 
1600     Camera_ErrorCode code = ndkCamera_->IsMovingPhotoSupported(index);
1601 
1602     napi_value movingPhoto = nullptr;
1603     napi_create_object(env, &movingPhoto);
1604     napi_value jsValue = nullptr;
1605 
1606     bool isMovingPhoto = ndkCamera_->isMovingPhotoSupported_;
1607     napi_get_boolean(env, isMovingPhoto, &jsValue);
1608     napi_set_named_property(env, movingPhoto, "isMovingPhotoSupported", jsValue);
1609 
1610     napi_create_int32(env, code, &jsValue);
1611     napi_set_named_property(env, movingPhoto, "errorCode", jsValue);
1612 
1613     return movingPhoto;
1614 }
OHPhotoOutputEnableMovingPhoto(napi_env env, napi_callback_info info)1615 static napi_value OHPhotoOutputEnableMovingPhoto(napi_env env, napi_callback_info info)
1616 {
1617     size_t argc = 2;
1618     napi_value args[NUMBER_2] = {nullptr};
1619     napi_value result;
1620 
1621     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1622 
1623     int32_t index;
1624     napi_get_value_int32(env, args[0], &index);
1625 
1626     bool enable;
1627     napi_get_value_bool(env, args[1], &enable);
1628 
1629     Camera_ErrorCode code = ndkCamera_->EnableMovingPhoto(index, enable);
1630 
1631     napi_create_int32(env, code, &result);
1632     return result;
1633 }
OHPhotoNativeGetMainImage(napi_env env, napi_callback_info info)1634 static napi_value OHPhotoNativeGetMainImage(napi_env env, napi_callback_info info)
1635 {
1636     size_t argc = 1;
1637     napi_value args[1] = {nullptr};
1638     napi_value result;
1639 
1640     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1641 
1642     int32_t index;
1643     napi_get_value_int32(env, args[0], &index);
1644 
1645     Camera_ErrorCode code = ndkCamera_->GetMainImage(index);
1646 
1647     napi_create_int32(env, code, &result);
1648     return result;
1649 }
OHPhotoNativeRelease(napi_env env, napi_callback_info info)1650 static napi_value OHPhotoNativeRelease(napi_env env, napi_callback_info info)
1651 {
1652     size_t argc = 1;
1653     napi_value args[1] = {nullptr};
1654     napi_value result;
1655 
1656     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1657 
1658     int32_t index;
1659     napi_get_value_int32(env, args[0], &index);
1660 
1661     Camera_ErrorCode code = ndkCamera_->PhotoNativeRelease(index);
1662 
1663     napi_create_int32(env, code, &result);
1664     return result;
1665 }
OHCameraManagerCreatePhotoOutputWithoutSurface(napi_env env, napi_callback_info info)1666 static napi_value OHCameraManagerCreatePhotoOutputWithoutSurface(napi_env env, napi_callback_info info)
1667 {
1668     size_t argc = 1;
1669     napi_value args[1] = {nullptr};
1670     napi_value result;
1671 
1672     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1673 
1674     int32_t index;
1675     napi_get_value_int32(env, args[0], &index);
1676 
1677     Camera_ErrorCode code = ndkCamera_->CreatePhotoOutputWithoutSurface(index);
1678 
1679     napi_create_int32(env, code, &result);
1680     return result;
1681 }
ReleaseCamera(napi_env env, napi_callback_info info)1682 static napi_value ReleaseCamera(napi_env env, napi_callback_info info)
1683 {
1684     napi_value result;
1685     Camera_ErrorCode code = ndkCamera_->ReleaseCamera();
1686 
1687     napi_create_int32(env, code, &result);
1688     return result;
1689 }
OHCameraManagerIsTorchSupported(napi_env env, napi_callback_info info)1690 static napi_value OHCameraManagerIsTorchSupported(napi_env env, napi_callback_info info)
1691 {
1692     size_t argc = 1;
1693     napi_value args[1] = {nullptr};
1694 
1695     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1696 
1697     int32_t index;
1698     napi_get_value_int32(env, args[0], &index);
1699 
1700     Camera_ErrorCode code = ndkCamera_->IsTorchSupported(index);
1701 
1702     napi_value isTorchSupported = nullptr;
1703     napi_create_object(env, &isTorchSupported);
1704     napi_value jsValue = nullptr;
1705 
1706     napi_get_boolean(env, ndkCamera_->isTorchSupported_, &jsValue);
1707     napi_set_named_property(env, isTorchSupported, "isTorchSupported", jsValue);
1708 
1709     napi_create_int32(env, code, &jsValue);
1710     napi_set_named_property(env, isTorchSupported, "errorCode", jsValue);
1711 
1712     return isTorchSupported;
1713 }
1714 
OHCameraManagerIsTorchSupportedByTorchMode(napi_env env, napi_callback_info info)1715 static napi_value OHCameraManagerIsTorchSupportedByTorchMode(napi_env env, napi_callback_info info)
1716 {
1717     size_t argc = 1;
1718     napi_value args[1] = {nullptr};
1719 
1720     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1721 
1722     int32_t index;
1723     napi_get_value_int32(env, args[0], &index);
1724 
1725     Camera_ErrorCode code = ndkCamera_->IsTorchSupportedByTorchMode(index);
1726 
1727     napi_value isTorchSupportedByTorchMode = nullptr;
1728     napi_create_object(env, &isTorchSupportedByTorchMode);
1729     napi_value jsValue = nullptr;
1730 
1731     napi_get_boolean(env, ndkCamera_->isTorchSupportedByTorchMode_, &jsValue);
1732     napi_set_named_property(env, isTorchSupportedByTorchMode, "isTorchSupportedByTorchMode", jsValue);
1733 
1734     napi_create_int32(env, code, &jsValue);
1735     napi_set_named_property(env, isTorchSupportedByTorchMode, "errorCode", jsValue);
1736 
1737     return isTorchSupportedByTorchMode;
1738 }
1739 
OHCameraManagerSetTorchMode(napi_env env, napi_callback_info info)1740 static napi_value OHCameraManagerSetTorchMode(napi_env env, napi_callback_info info)
1741 {
1742     size_t argc = 1;
1743     napi_value args[1] = {nullptr};
1744     napi_value result;
1745 
1746     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1747 
1748     int32_t index;
1749     napi_get_value_int32(env, args[0], &index);
1750 
1751     Camera_ErrorCode code = ndkCamera_->SetTorchMode(index);
1752 
1753     napi_create_int32(env, code, &result);
1754     return result;
1755 }
1756 
OHCaptureSessionGetExposureValue(napi_env env, napi_callback_info info)1757 static napi_value OHCaptureSessionGetExposureValue(napi_env env, napi_callback_info info)
1758 {
1759     size_t argc = 1;
1760     napi_value args[1] = {nullptr};
1761     napi_value result;
1762 
1763     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1764 
1765     int32_t index;
1766     napi_get_value_int32(env, args[0], &index);
1767 
1768     Camera_ErrorCode code = ndkCamera_->GetExposureValue(index);
1769 
1770     napi_create_int32(env, code, &result);
1771     return result;
1772 }
1773 
OHCaptureSessionGetFocalLength(napi_env env, napi_callback_info info)1774 static napi_value OHCaptureSessionGetFocalLength(napi_env env, napi_callback_info info)
1775 {
1776     size_t argc = 1;
1777     napi_value args[1] = {nullptr};
1778     napi_value result;
1779 
1780     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1781 
1782     int32_t index;
1783     napi_get_value_int32(env, args[0], &index);
1784 
1785     Camera_ErrorCode code = ndkCamera_->GetFocalLength(index);
1786 
1787     napi_create_int32(env, code, &result);
1788     return result;
1789 }
1790 
OHCaptureSessionSetSmoothZoom(napi_env env, napi_callback_info info)1791 static napi_value OHCaptureSessionSetSmoothZoom(napi_env env, napi_callback_info info)
1792 {
1793     size_t argc = 1;
1794     napi_value args[1] = {nullptr};
1795     napi_value result;
1796 
1797     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1798 
1799     int32_t index;
1800     napi_get_value_int32(env, args[0], &index);
1801 
1802     Camera_ErrorCode code = ndkCamera_->SetSmoothZoom(index);
1803 
1804     napi_create_int32(env, code, &result);
1805     return result;
1806 }
1807 
OHCaptureSessionGetSupportedColorSpaces(napi_env env, napi_callback_info info)1808 static napi_value OHCaptureSessionGetSupportedColorSpaces(napi_env env, napi_callback_info info)
1809 {
1810     size_t argc = 1;
1811     napi_value args[1] = {nullptr};
1812 
1813     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1814 
1815     int32_t index;
1816     napi_get_value_int32(env, args[0], &index);
1817 
1818     Camera_ErrorCode code = ndkCamera_->GetSupportedColorSpaces(index);
1819 
1820     napi_value colorSpacesSize = nullptr;
1821     napi_create_object(env, &colorSpacesSize);
1822     napi_value jsValue = nullptr;
1823 
1824     napi_create_int32(env, ndkCamera_->colorSpacesSize_, &jsValue);
1825     napi_set_named_property(env, colorSpacesSize, "colorSpacesSize", jsValue);
1826 
1827     napi_create_int32(env, code, &jsValue);
1828     napi_set_named_property(env, colorSpacesSize, "errorCode", jsValue);
1829     return colorSpacesSize;
1830 }
1831 
OHCaptureSessionDeleteColorSpaces(napi_env env, napi_callback_info info)1832 static napi_value OHCaptureSessionDeleteColorSpaces(napi_env env, napi_callback_info info)
1833 {
1834     size_t argc = 1;
1835     napi_value args[1] = {nullptr};
1836     napi_value result;
1837 
1838     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1839 
1840     int32_t index;
1841     napi_get_value_int32(env, args[0], &index);
1842 
1843     Camera_ErrorCode code = ndkCamera_->DeleteColorSpaces(index);
1844 
1845     napi_create_int32(env, code, &result);
1846     return result;
1847 }
1848 
OHCaptureSessionGetActiveColorSpace(napi_env env, napi_callback_info info)1849 static napi_value OHCaptureSessionGetActiveColorSpace(napi_env env, napi_callback_info info)
1850 {
1851     size_t argc = 1;
1852     napi_value args[1] = {nullptr};
1853 
1854     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1855 
1856     int32_t index;
1857     napi_get_value_int32(env, args[0], &index);
1858 
1859     Camera_ErrorCode code = ndkCamera_->GetActiveColorSpace(index);
1860 
1861     napi_value activeColorSpace = nullptr;
1862     napi_create_object(env, &activeColorSpace);
1863     napi_value jsValue = nullptr;
1864 
1865     napi_create_int32(env, ndkCamera_->activeColorSpace_, &jsValue);
1866     napi_set_named_property(env, activeColorSpace, "activeColorSpace", jsValue);
1867 
1868     napi_create_int32(env, code, &jsValue);
1869     napi_set_named_property(env, activeColorSpace, "errorCode", jsValue);
1870 
1871     return activeColorSpace;
1872 }
1873 
OHNativeBufferColorSpace(napi_env env, napi_callback_info info)1874 static napi_value OHNativeBufferColorSpace(napi_env env, napi_callback_info info)
1875 {
1876     napi_value colorSpace = nullptr;
1877     napi_create_object(env, &colorSpace);
1878     napi_value jsValue = nullptr;
1879 
1880     napi_create_int32(env, ndkCamera_->ColorSpace(), &jsValue);
1881     napi_set_named_property(env, colorSpace, "colorSpaceSupportSize", jsValue);
1882 
1883     napi_create_int32(env, ndkCamera_->setcolorSpace_, &jsValue);
1884     napi_set_named_property(env, colorSpace, "setcolorSpace", jsValue);
1885 
1886     napi_create_int32(env, ndkCamera_->colorSpacesSize_, &jsValue);
1887     napi_set_named_property(env, colorSpace, "colorSpacesSize", jsValue);
1888 
1889     return colorSpace;
1890 }
1891 
1892 
OHCaptureSessionSetActiveColorSpace(napi_env env, napi_callback_info info)1893 static napi_value OHCaptureSessionSetActiveColorSpace(napi_env env, napi_callback_info info)
1894 {
1895     size_t argc = 1;
1896     napi_value args[1] = {nullptr};
1897     napi_value result;
1898 
1899     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1900 
1901     int32_t index;
1902     napi_get_value_int32(env, args[0], &index);
1903 
1904     Camera_ErrorCode code = ndkCamera_->SetColorSpace(index);
1905 
1906     napi_create_int32(env, code, &result);
1907     return result;
1908 }
1909 
OHPreviewOutputGetSupportedFrameRates(napi_env env, napi_callback_info info)1910 static napi_value OHPreviewOutputGetSupportedFrameRates(napi_env env, napi_callback_info info)
1911 {
1912     size_t argc = 1;
1913     napi_value args[1] = {nullptr};
1914 
1915     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1916 
1917     int32_t index;
1918     napi_get_value_int32(env, args[0], &index);
1919 
1920     Camera_ErrorCode code = ndkCamera_->GetSupportedFrameRates(index);
1921 
1922     napi_value frameRatesSize = nullptr;
1923     napi_create_object(env, &frameRatesSize);
1924     napi_value jsValue = nullptr;
1925 
1926     napi_create_int32(env, ndkCamera_->frameRatesSize_, &jsValue);
1927     napi_set_named_property(env, frameRatesSize, "frameRatesSize", jsValue);
1928 
1929     napi_create_int32(env, code, &jsValue);
1930     napi_set_named_property(env, frameRatesSize, "errorCode", jsValue);
1931 
1932     return frameRatesSize;
1933 }
1934 
OHPreviewOutputSetFrameRate(napi_env env, napi_callback_info info)1935 static napi_value OHPreviewOutputSetFrameRate(napi_env env, napi_callback_info info)
1936 {
1937     size_t argc = 1;
1938     napi_value args[1] = {nullptr};
1939     napi_value result;
1940 
1941     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1942 
1943     int32_t index;
1944     napi_get_value_int32(env, args[0], &index);
1945 
1946     Camera_ErrorCode code = ndkCamera_->SetFrameRate(index);
1947 
1948     napi_create_int32(env, code, &result);
1949     return result;
1950 }
1951 
OHPreviewOutputGetActiveFrameRate(napi_env env, napi_callback_info info)1952 static napi_value OHPreviewOutputGetActiveFrameRate(napi_env env, napi_callback_info info)
1953 {
1954     size_t argc = 1;
1955     napi_value args[1] = {nullptr};
1956 
1957     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1958 
1959     int32_t index;
1960     napi_get_value_int32(env, args[0], &index);
1961 
1962     Camera_ErrorCode code = ndkCamera_->GetActiveFrameRate(index);
1963 
1964     napi_value activeFrameRateRange = nullptr;
1965     napi_create_object(env, &activeFrameRateRange);
1966     napi_value jsValue = nullptr;
1967 
1968     napi_create_int32(env, ndkCamera_->activeFrameRateRange_.min, &jsValue);
1969     napi_set_named_property(env, activeFrameRateRange, "min", jsValue);
1970 
1971     napi_create_int32(env, ndkCamera_->activeFrameRateRange_.max, &jsValue);
1972     napi_set_named_property(env, activeFrameRateRange, "max", jsValue);
1973 
1974     napi_create_int32(env, code, &jsValue);
1975     napi_set_named_property(env, activeFrameRateRange, "errorCode", jsValue);
1976     return activeFrameRateRange;
1977 }
1978 
OHVideoOutputGetSupportedFrameRates(napi_env env, napi_callback_info info)1979 static napi_value OHVideoOutputGetSupportedFrameRates(napi_env env, napi_callback_info info)
1980 {
1981     size_t argc = 1;
1982     napi_value args[1] = {nullptr};
1983 
1984     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1985 
1986     int32_t index;
1987     napi_get_value_int32(env, args[0], &index);
1988 
1989     Camera_ErrorCode code = ndkCamera_->VideoOutputGetSupportedFrameRates(index);
1990 
1991     napi_value videoFrameRatesSize = nullptr;
1992     napi_create_object(env, &videoFrameRatesSize);
1993     napi_value jsValue = nullptr;
1994 
1995     napi_create_int32(env, ndkCamera_->videoFrameRatesSize_, &jsValue);
1996     napi_set_named_property(env, videoFrameRatesSize, "videoFrameRatesSize", jsValue);
1997 
1998     napi_create_int32(env, code, &jsValue);
1999     napi_set_named_property(env, videoFrameRatesSize, "errorCode", jsValue);
2000     return videoFrameRatesSize;
2001 }
2002 
OHVideoOutputSetFrameRate(napi_env env, napi_callback_info info)2003 static napi_value OHVideoOutputSetFrameRate(napi_env env, napi_callback_info info)
2004 {
2005     size_t argc = 1;
2006     napi_value args[1] = {nullptr};
2007     napi_value result;
2008 
2009     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
2010 
2011     int32_t index;
2012     napi_get_value_int32(env, args[0], &index);
2013 
2014     Camera_ErrorCode code = ndkCamera_->VideoOutputSetFrameRate(index);
2015 
2016     napi_create_int32(env, code, &result);
2017     return result;
2018 }
2019 
OHVideoOutputGetActiveFrameRate(napi_env env, napi_callback_info info)2020 static napi_value OHVideoOutputGetActiveFrameRate(napi_env env, napi_callback_info info)
2021 {
2022     size_t argc = 1;
2023     napi_value args[1] = {nullptr};
2024 
2025     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
2026 
2027     int32_t index;
2028     napi_get_value_int32(env, args[0], &index);
2029 
2030     Camera_ErrorCode code = ndkCamera_->VideoOutputGetActiveFrameRate(index);
2031 
2032     napi_value videoActiveFrameRateRange = nullptr;
2033     napi_create_object(env, &videoActiveFrameRateRange);
2034     napi_value jsValue = nullptr;
2035 
2036     napi_create_int32(env, ndkCamera_->videoActiveFrameRateRange_.min, &jsValue);
2037     napi_set_named_property(env, videoActiveFrameRateRange, "min", jsValue);
2038 
2039     napi_create_int32(env, ndkCamera_->videoActiveFrameRateRange_.max, &jsValue);
2040     napi_set_named_property(env, videoActiveFrameRateRange, "max", jsValue);
2041 
2042     napi_create_int32(env, code, &jsValue);
2043     napi_set_named_property(env, videoActiveFrameRateRange, "errorCode", jsValue);
2044     return videoActiveFrameRateRange;
2045 }
2046 
OHVideoOutputDeleteFrameRates(napi_env env, napi_callback_info info)2047 static napi_value OHVideoOutputDeleteFrameRates(napi_env env, napi_callback_info info)
2048 {
2049     size_t argc = 1;
2050     napi_value args[1] = {nullptr};
2051     napi_value result;
2052 
2053     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
2054 
2055     int32_t index;
2056     napi_get_value_int32(env, args[0], &index);
2057 
2058     Camera_ErrorCode code = ndkCamera_->VideoOutputDeleteFrameRates(index);
2059 
2060     napi_create_int32(env, code, &result);
2061     return result;
2062 }
2063 
OHPreviewOutputDeleteFrameRates(napi_env env, napi_callback_info info)2064 static napi_value OHPreviewOutputDeleteFrameRates(napi_env env, napi_callback_info info)
2065 {
2066     size_t argc = 1;
2067     napi_value args[1] = {nullptr};
2068     napi_value result;
2069 
2070     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
2071 
2072     int32_t index;
2073     napi_get_value_int32(env, args[0], &index);
2074 
2075     Camera_ErrorCode code = ndkCamera_->DeleteFrameRates(index);
2076 
2077     napi_create_int32(env, code, &result);
2078     return result;
2079 }
2080 
OHCameraManagerRegisterTorchStatusCallback(napi_env env, napi_callback_info info)2081 static napi_value OHCameraManagerRegisterTorchStatusCallback(napi_env env, napi_callback_info info)
2082 {
2083     size_t argc = 1;
2084     napi_value args[1] = {nullptr};
2085     napi_value result;
2086 
2087     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
2088 
2089     int32_t index;
2090     napi_get_value_int32(env, args[0], &index);
2091 
2092     Camera_ErrorCode code = ndkCamera_->CameraManagerRegisterTorchStatusCallback(index);
2093 
2094     napi_create_int32(env, code, &result);
2095     return result;
2096 }
2097 
OHCameraManagerUnregisterTorchStatusCallback(napi_env env, napi_callback_info info)2098 static napi_value OHCameraManagerUnregisterTorchStatusCallback(napi_env env, napi_callback_info info)
2099 {
2100     size_t argc = 1;
2101     napi_value args[1] = {nullptr};
2102     napi_value result;
2103 
2104     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
2105 
2106     int32_t index;
2107     napi_get_value_int32(env, args[0], &index);
2108 
2109     Camera_ErrorCode code = ndkCamera_->CameraManagerUnregisterTorchStatusCallback(index);
2110 
2111     napi_create_int32(env, code, &result);
2112     return result;
2113 }
2114 
OHCaptureSessionRegisterSmoothZoomInfoCallback(napi_env env, napi_callback_info info)2115 static napi_value OHCaptureSessionRegisterSmoothZoomInfoCallback(napi_env env, napi_callback_info info)
2116 {
2117     size_t argc = 1;
2118     napi_value args[1] = {nullptr};
2119     napi_value result;
2120 
2121     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
2122 
2123     int32_t index;
2124     napi_get_value_int32(env, args[0], &index);
2125 
2126     Camera_ErrorCode code = ndkCamera_->CaptureSessionRegisterSmoothZoomInfoCallback(index);
2127 
2128     napi_create_int32(env, code, &result);
2129     return result;
2130 }
2131 
OHCaptureSessionUnregisterSmoothZoomInfoCallback(napi_env env, napi_callback_info info)2132 static napi_value OHCaptureSessionUnregisterSmoothZoomInfoCallback(napi_env env, napi_callback_info info)
2133 {
2134     size_t argc = 1;
2135     napi_value args[1] = {nullptr};
2136     napi_value result;
2137 
2138     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
2139 
2140     int32_t index;
2141     napi_get_value_int32(env, args[0], &index);
2142 
2143     Camera_ErrorCode code = ndkCamera_->CaptureSessionUnregisterSmoothZoomInfoCallback(index);
2144 
2145     napi_create_int32(env, code, &result);
2146     return result;
2147 }
2148 
OHPhotoOutputRegisterCaptureStartWithInfoCallback(napi_env env, napi_callback_info info)2149 static napi_value OHPhotoOutputRegisterCaptureStartWithInfoCallback(napi_env env, napi_callback_info info)
2150 {
2151     size_t argc = 1;
2152     napi_value args[1] = {nullptr};
2153     napi_value result;
2154 
2155     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
2156 
2157     int32_t index;
2158     napi_get_value_int32(env, args[0], &index);
2159 
2160     Camera_ErrorCode code = ndkCamera_->PhotoOutputRegisterCaptureStartWithInfoCallback(index);
2161 
2162     napi_create_int32(env, code, &result);
2163     return result;
2164 }
2165 
OHPhotoOutputUnregisterCaptureStartWithInfoCallback(napi_env env, napi_callback_info info)2166 static napi_value OHPhotoOutputUnregisterCaptureStartWithInfoCallback(napi_env env, napi_callback_info info)
2167 {
2168     size_t argc = 1;
2169     napi_value args[1] = {nullptr};
2170     napi_value result;
2171 
2172     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
2173 
2174     int32_t index;
2175     napi_get_value_int32(env, args[0], &index);
2176 
2177     Camera_ErrorCode code = ndkCamera_->PhotoOutputUnregisterCaptureStartWithInfoCallback(index);
2178 
2179     napi_create_int32(env, code, &result);
2180     return result;
2181 }
2182 
OHPhotoOutputRegisterCaptureEndCallback(napi_env env, napi_callback_info info)2183 static napi_value OHPhotoOutputRegisterCaptureEndCallback(napi_env env, napi_callback_info info)
2184 {
2185     size_t argc = 1;
2186     napi_value args[1] = {nullptr};
2187     napi_value result;
2188 
2189     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
2190 
2191     int32_t index;
2192     napi_get_value_int32(env, args[0], &index);
2193 
2194     Camera_ErrorCode code = ndkCamera_->PhotoOutputRegisterCaptureEndCallback(index);
2195 
2196     napi_create_int32(env, code, &result);
2197     return result;
2198 }
2199 
OHPhotoOutputUnregisterCaptureEndCallback(napi_env env, napi_callback_info info)2200 static napi_value OHPhotoOutputUnregisterCaptureEndCallback(napi_env env, napi_callback_info info)
2201 {
2202     size_t argc = 1;
2203     napi_value args[1] = {nullptr};
2204     napi_value result;
2205 
2206     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
2207 
2208     int32_t index;
2209     napi_get_value_int32(env, args[0], &index);
2210 
2211     Camera_ErrorCode code = ndkCamera_->PhotoOutputUnregisterCaptureEndCallback(index);
2212 
2213     napi_create_int32(env, code, &result);
2214     return result;
2215 }
2216 
OHPhotoOutputRegisterFrameShutterEndCallback(napi_env env, napi_callback_info info)2217 static napi_value OHPhotoOutputRegisterFrameShutterEndCallback(napi_env env, napi_callback_info info)
2218 {
2219     size_t argc = 1;
2220     napi_value args[1] = {nullptr};
2221     napi_value result;
2222 
2223     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
2224 
2225     int32_t index;
2226     napi_get_value_int32(env, args[0], &index);
2227 
2228     Camera_ErrorCode code = ndkCamera_->PhotoOutputRegisterFrameShutterEndCallback(index);
2229 
2230     napi_create_int32(env, code, &result);
2231     return result;
2232 }
2233 
OHPhotoOutputUnregisterFrameShutterEndCallback(napi_env env, napi_callback_info info)2234 static napi_value OHPhotoOutputUnregisterFrameShutterEndCallback(napi_env env, napi_callback_info info)
2235 {
2236     size_t argc = 1;
2237     napi_value args[1] = {nullptr};
2238     napi_value result;
2239 
2240     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
2241 
2242     int32_t index;
2243     napi_get_value_int32(env, args[0], &index);
2244 
2245     Camera_ErrorCode code = ndkCamera_->PhotoOutputUnregisterFrameShutterEndCallback(index);
2246 
2247     napi_create_int32(env, code, &result);
2248     return result;
2249 }
2250 
OHPhotoOutputRegisterCaptureReadyCallback(napi_env env, napi_callback_info info)2251 static napi_value OHPhotoOutputRegisterCaptureReadyCallback(napi_env env, napi_callback_info info)
2252 {
2253     size_t argc = 1;
2254     napi_value args[1] = {nullptr};
2255     napi_value result;
2256 
2257     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
2258 
2259     int32_t index;
2260     napi_get_value_int32(env, args[0], &index);
2261 
2262     Camera_ErrorCode code = ndkCamera_->PhotoOutputRegisterCaptureReadyCallback(index);
2263 
2264     napi_create_int32(env, code, &result);
2265     return result;
2266 }
2267 
OHPhotoOutputUnregisterCaptureReadyCallback(napi_env env, napi_callback_info info)2268 static napi_value OHPhotoOutputUnregisterCaptureReadyCallback(napi_env env, napi_callback_info info)
2269 {
2270     size_t argc = 1;
2271     napi_value args[1] = {nullptr};
2272     napi_value result;
2273 
2274     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
2275 
2276     int32_t index;
2277     napi_get_value_int32(env, args[0], &index);
2278 
2279     Camera_ErrorCode code = ndkCamera_->PhotoOutputUnregisterCaptureReadyCallback(index);
2280 
2281     napi_create_int32(env, code, &result);
2282     return result;
2283 }
2284 
OHPhotoOutputRegisterEstimatedCaptureDurationCallback(napi_env env, napi_callback_info info)2285 static napi_value OHPhotoOutputRegisterEstimatedCaptureDurationCallback(napi_env env, napi_callback_info info)
2286 {
2287     size_t argc = 1;
2288     napi_value args[1] = {nullptr};
2289     napi_value result;
2290 
2291     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
2292 
2293     int32_t index;
2294     napi_get_value_int32(env, args[0], &index);
2295 
2296     Camera_ErrorCode code = ndkCamera_->PhotoOutputRegisterEstimatedCaptureDurationCallback(index);
2297 
2298     napi_create_int32(env, code, &result);
2299     return result;
2300 }
2301 
OHPhotoOutputUnregisterEstimatedCaptureDurationCallback(napi_env env, napi_callback_info info)2302 static napi_value OHPhotoOutputUnregisterEstimatedCaptureDurationCallback(napi_env env, napi_callback_info info)
2303 {
2304     size_t argc = 1;
2305     napi_value args[1] = {nullptr};
2306     napi_value result;
2307 
2308     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
2309 
2310     int32_t index;
2311     napi_get_value_int32(env, args[0], &index);
2312 
2313     Camera_ErrorCode code = ndkCamera_->PhotoOutputUnregisterEstimatedCaptureDurationCallback(index);
2314 
2315     napi_create_int32(env, code, &result);
2316     return result;
2317 }
2318 
OHCameraManagerTorchMode(napi_env env, napi_callback_info info)2319 static napi_value OHCameraManagerTorchMode(napi_env env, napi_callback_info info)
2320 {
2321     size_t argc = 1;
2322     napi_value args[1] = {nullptr};
2323     napi_value result;
2324 
2325     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
2326 
2327     int32_t index;
2328     napi_get_value_int32(env, args[0], &index);
2329 
2330     Camera_ErrorCode code = ndkCamera_->TorchMode(index);
2331 
2332     napi_create_int32(env, code, &result);
2333     return result;
2334 }
ReadyCreatePhotoOutputWithoutSurface(napi_env env, napi_callback_info info)2335 static napi_value ReadyCreatePhotoOutputWithoutSurface(napi_env env, napi_callback_info info)
2336 {
2337     napi_value result;
2338 
2339     Camera_ErrorCode code = ndkCamera_->ReadyCreatePhotoOutputWithoutSurface();
2340 
2341     napi_create_int32(env, code, &result);
2342     return result;
2343 }
2344 EXTERN_C_START
Init(napi_env env, napi_value exports)2345 static napi_value Init(napi_env env, napi_value exports)
2346 {
2347     napi_property_descriptor desc[] = {
2348         { "initCamera", nullptr, InitCamera, nullptr, nullptr, nullptr, napi_default, nullptr },
2349         { "getSupportedCameras", nullptr, GetSupportedCameras, nullptr, nullptr, nullptr, napi_default, nullptr },
2350         { "getCameraOrientation", nullptr, GetCameraOrientation, nullptr, nullptr, nullptr, napi_default, nullptr },
2351         { "createCameraInput", nullptr, CreateCameraInput, nullptr, nullptr, nullptr, napi_default, nullptr },
2352         { "createCameraInputWithPositionAndType", nullptr, CreateCameraInputWithPositionAndType, nullptr, nullptr,
2353             nullptr, napi_default, nullptr },
2354         { "getSupportedOutputCapability", nullptr, GetSupportedOutputCapability, nullptr, nullptr, nullptr,
2355             napi_default, nullptr },
2356         { "createPreviewOutput", nullptr, CreatePreviewOutput, nullptr, nullptr, nullptr, napi_default, nullptr },
2357         { "createPhotoOutput", nullptr, CreatePhotoOutput, nullptr, nullptr, nullptr, napi_default, nullptr },
2358         { "createVideoOutput", nullptr, CreateVideoOutput, nullptr, nullptr, nullptr, napi_default, nullptr },
2359         { "createMetadataOutput", nullptr, CreateMetadataOutput, nullptr, nullptr, nullptr, napi_default, nullptr },
2360         { "createSession", nullptr, CreateSession, nullptr, nullptr, nullptr, napi_default, nullptr },
2361         { "isCameraMuted", nullptr, IsCameraMuted, nullptr, nullptr, nullptr, napi_default, nullptr },
2362         { "cameraInputOpen", nullptr, CameraInputOpen, nullptr, nullptr, nullptr, napi_default, nullptr },
2363         { "cameraInputClose", nullptr, CameraInputClose, nullptr, nullptr, nullptr, napi_default, nullptr },
2364         { "cameraInputRelease", nullptr, CameraInputRelease, nullptr, nullptr, nullptr, napi_default, nullptr },
2365         { "previewOutputStart", nullptr, PreviewOutputStart, nullptr, nullptr, nullptr, napi_default, nullptr },
2366         { "previewOutputStop", nullptr, PreviewOutputStop, nullptr, nullptr, nullptr, napi_default, nullptr },
2367         { "previewOutputRelease", nullptr, PreviewOutputRelease, nullptr, nullptr, nullptr, napi_default, nullptr },
2368         { "photoOutputCapture", nullptr, PhotoOutputCapture, nullptr, nullptr, nullptr, napi_default, nullptr },
2369         { "photoOutputRelease", nullptr, PhotoOutputRelease, nullptr, nullptr, nullptr, napi_default, nullptr },
2370         { "isMirrorSupported", nullptr, IsMirrorSupported, nullptr, nullptr, nullptr, napi_default, nullptr },
2371         { "videoOutputStart", nullptr, VideoOutputStart, nullptr, nullptr, nullptr, napi_default, nullptr },
2372         { "videoOutputStop", nullptr, VideoOutputStop, nullptr, nullptr, nullptr, napi_default, nullptr },
2373         { "videoOutputRelease", nullptr, VideoOutputRelease, nullptr, nullptr, nullptr, napi_default, nullptr },
2374         { "metadataOutputStart", nullptr, MetadataOutputStart, nullptr, nullptr, nullptr, napi_default, nullptr },
2375         { "metadataOutputStop", nullptr, MetadataOutputStop, nullptr, nullptr, nullptr, napi_default, nullptr },
2376         { "metadataOutputRelease", nullptr, MetadataOutputRelease, nullptr, nullptr, nullptr, napi_default, nullptr },
2377         { "previewOutputStop", nullptr, PreviewOutputStop, nullptr, nullptr, nullptr, napi_default, nullptr },
2378         { "sessionAddInput", nullptr, SessionAddInput, nullptr, nullptr, nullptr, napi_default, nullptr },
2379         { "sessionRemoveInput", nullptr, SessionRemoveInput, nullptr, nullptr, nullptr, napi_default, nullptr },
2380         { "sessionAddPreviewOutput", nullptr, SessionAddPreviewOutput, nullptr, nullptr, nullptr,
2381             napi_default, nullptr },
2382         { "sessionAddPhotoOutput", nullptr, SessionAddPhotoOutput, nullptr, nullptr, nullptr, napi_default, nullptr },
2383         { "sessionAddVideoOutput", nullptr, SessionAddVideoOutput, nullptr, nullptr, nullptr, napi_default, nullptr },
2384         { "sessionAddMetadataOutput", nullptr, SessionAddMetadataOutput, nullptr, nullptr, nullptr,
2385             napi_default, nullptr },
2386         { "sessionRemovePreviewOutput", nullptr, SessionRemovePreviewOutput, nullptr, nullptr, nullptr,
2387             napi_default, nullptr },
2388         { "sessionRemovePhotoOutput", nullptr, SessionRemovePhotoOutput, nullptr, nullptr, nullptr,
2389             napi_default, nullptr },
2390         { "sessionRemoveVideoOutput", nullptr, SessionRemoveVideoOutput, nullptr, nullptr, nullptr,
2391             napi_default, nullptr },
2392         { "sessionRemoveMetadataOutput", nullptr, SessionRemoveMetadataOutput, nullptr, nullptr, nullptr,
2393             napi_default, nullptr },
2394         { "sessionStart", nullptr, SessionStart, nullptr, nullptr, nullptr, napi_default, nullptr },
2395         { "sessionStop", nullptr, SessionStop, nullptr, nullptr, nullptr, napi_default, nullptr },
2396         { "sessionBegin", nullptr, SessionBegin, nullptr, nullptr, nullptr, napi_default, nullptr },
2397         { "sessionCommitConfig", nullptr, SessionCommitConfig, nullptr, nullptr, nullptr,
2398             napi_default, nullptr },
2399         { "sessionRelease", nullptr, SessionRelease, nullptr, nullptr, nullptr, napi_default, nullptr },
2400         { "sessionHasFlash", nullptr, SessionHasFlash, nullptr, nullptr, nullptr, napi_default, nullptr },
2401         { "sessionIsFlashModeSupported", nullptr, SessionIsFlashModeSupported, nullptr, nullptr, nullptr,
2402             napi_default, nullptr },
2403         { "sessionGetFlashMode", nullptr, SessionGetFlashMode, nullptr, nullptr, nullptr, napi_default, nullptr },
2404         { "sessionSetFlashMode", nullptr, SessionSetFlashMode, nullptr, nullptr, nullptr, napi_default, nullptr },
2405         { "sessionIsExposureModeSupported", nullptr, SessionIsExposureModeSupported, nullptr, nullptr, nullptr,
2406             napi_default, nullptr },
2407         { "sessionGetExposureMode", nullptr, SessionGetExposureMode, nullptr, nullptr, nullptr,
2408             napi_default, nullptr },
2409         { "sessionSetExposureMode", nullptr, SessionSetExposureMode, nullptr, nullptr, nullptr,
2410             napi_default, nullptr },
2411         { "sessionGetMeteringPoint", nullptr, SessionGetMeteringPoint, nullptr, nullptr, nullptr,
2412             napi_default, nullptr },
2413         { "sessionSetMeteringPoint", nullptr, SessionSetMeteringPoint, nullptr, nullptr, nullptr,
2414             napi_default, nullptr },
2415         { "sessionGetExposureBiasRange", nullptr, SessionGetExposureBiasRange, nullptr, nullptr, nullptr,
2416             napi_default, nullptr },
2417         { "sessionSetExposureBias", nullptr, SessionSetExposureBias, nullptr, nullptr, nullptr, napi_default, nullptr },
2418         { "sessionGetExposureBias", nullptr, SessionGetExposureBias, nullptr, nullptr, nullptr, napi_default, nullptr },
2419         { "sessionIsFocusModeSupported", nullptr, SessionIsFocusModeSupported, nullptr, nullptr, nullptr,
2420             napi_default, nullptr },
2421         { "sessionGetFocusMode", nullptr, SessionGetFocusMode, nullptr, nullptr, nullptr, napi_default, nullptr },
2422         { "sessionSetFocusMode", nullptr, SessionSetFocusMode, nullptr, nullptr, nullptr, napi_default, nullptr },
2423         { "sessionSetFocusPoint", nullptr, SessionSetFocusPoint, nullptr, nullptr, nullptr, napi_default, nullptr },
2424         { "sessionGetFocusPoint", nullptr, SessionGetFocusPoint, nullptr, nullptr, nullptr, napi_default, nullptr },
2425         { "sessionGetZoomRatioRange", nullptr, SessionGetZoomRatioRange, nullptr, nullptr, nullptr,
2426             napi_default, nullptr },
2427         { "sessionGetZoomRatio", nullptr, SessionGetZoomRatio, nullptr, nullptr, nullptr, napi_default, nullptr },
2428         { "sessionSetZoomRatio", nullptr, SessionSetZoomRatio, nullptr, nullptr, nullptr, napi_default, nullptr },
2429         { "sessionIsVideoStabilizationModeSupported", nullptr, SessionIsVideoStabilizationModeSupported,
2430             nullptr, nullptr, nullptr, napi_default, nullptr },
2431         { "sessionGetVideoStabilizationMode", nullptr, SessionGetVideoStabilizationMode, nullptr, nullptr, nullptr,
2432             napi_default, nullptr },
2433         { "sessionSetVideoStabilizationMode", nullptr, SessionSetVideoStabilizationMode, nullptr, nullptr, nullptr,
2434             napi_default, nullptr },
2435         { "getCameraCallbackCode", nullptr, GetCameraCallbackCode, nullptr, nullptr, nullptr, napi_default, nullptr },
2436         { "takePictureWithSettings", nullptr, TakePictureWithSettings, nullptr, nullptr, nullptr,
2437             napi_default, nullptr },
2438         { "sessionGetPhotoRotation", nullptr, SessionGetPhotoRotation, nullptr, nullptr, nullptr,
2439             napi_default, nullptr },
2440         { "sessionGetVideoRotation", nullptr, SessionGetVideoRotation, nullptr, nullptr, nullptr,
2441             napi_default, nullptr },
2442         { "sessionGetPreviewRotation", nullptr, SessionGetPreviewRotation, nullptr, nullptr, nullptr,
2443             napi_default, nullptr },
2444         { "sessionSetPreviewRotation", nullptr, SessionSetPreviewRotation, nullptr, nullptr, nullptr,
2445             napi_default, nullptr },
2446     };
2447     napi_property_descriptor desc1[] = {
2448         {"oHCaptureSessionRegisterCallback", nullptr, OHCaptureSessionRegisterCallback, nullptr, nullptr, nullptr,
2449             napi_default, nullptr},
2450         {"oHCaptureSessionUnregisterCallback", nullptr, OHCaptureSessionUnregisterCallback, nullptr, nullptr, nullptr,
2451             napi_default, nullptr},
2452         {"oHCameraManagerGetSupportedSceneModes", nullptr, OHCameraManagerGetSupportedSceneModes, nullptr, nullptr,
2453             nullptr, napi_default, nullptr},
2454         {"oHCameraManagerDeleteSceneModes", nullptr, OHCameraManagerDeleteSceneModes, nullptr, nullptr, nullptr,
2455             napi_default, nullptr},
2456         {"oHCameraManagerGetSupportedCameraOutputCapabilityWithSceneMode", nullptr,
2457             OHCameraManagerGetSupportedCameraOutputCapabilityWithSceneMode, nullptr, nullptr, nullptr, napi_default,
2458             nullptr},
2459         {"oHCaptureSessionSetSessionMode", nullptr, OHCaptureSessionSetSessionMode, nullptr, nullptr, nullptr,
2460             napi_default, nullptr},
2461         {"oHCaptureSessionCanAddInput", nullptr, OHCaptureSessionCanAddInput, nullptr, nullptr, nullptr, napi_default,
2462             nullptr},
2463         {"oHCaptureSessionCanAddPreviewOutput", nullptr, OHCaptureSessionCanAddPreviewOutput, nullptr, nullptr, nullptr,
2464             napi_default, nullptr},
2465         {"oHCaptureSessionCanAddPhotoOutput", nullptr, OHCaptureSessionCanAddPhotoOutput, nullptr, nullptr, nullptr,
2466             napi_default, nullptr},
2467         {"oHCaptureSessionCanAddVideoOutput", nullptr, OHCaptureSessionCanAddVideoOutput, nullptr, nullptr, nullptr,
2468             napi_default, nullptr},
2469         {"oHCaptureSessionAddSecureOutput", nullptr, OHCaptureSessionAddSecureOutput, nullptr, nullptr, nullptr,
2470             napi_default, nullptr},
2471         {"oHCameraInputOpenSecureCamera", nullptr, OHCameraInputOpenSecureCamera, nullptr, nullptr, nullptr,
2472             napi_default, nullptr},
2473         {"oHCaptureSessionRegisterCallbackOn", nullptr, OHCaptureSessionRegisterCallbackOn, nullptr, nullptr, nullptr,
2474             napi_default, nullptr},
2475         {"oHCaptureSessionUnregisterCallbackOff", nullptr, OHCaptureSessionUnregisterCallbackOff, nullptr, nullptr,
2476             nullptr, napi_default, nullptr},
2477         {"oHCameraManagerSetSceneMode", nullptr, OHCameraManagerSetSceneMode, nullptr, nullptr, nullptr, napi_default,
2478             nullptr},
2479     };
2480     napi_property_descriptor desc2[] = {
2481         {"oHCameraManagerCreatePreviewOutputUsedInPreconfig", nullptr,
2482             OHCameraManagerCreatePreviewOutputUsedInPreconfig, nullptr, nullptr, nullptr, napi_default, nullptr},
2483         {"oHCameraManagerCreatePhotoOutputUsedInPreconfig", nullptr, OHCameraManagerCreatePhotoOutputUsedInPreconfig,
2484             nullptr, nullptr, nullptr, napi_default, nullptr},
2485         {"oHCaptureSessionCanPreconfig", nullptr, OHCaptureSessionCanPreconfig, nullptr, nullptr, nullptr, napi_default,
2486             nullptr},
2487         {"oHCaptureSessionCanPreconfigWithRatio", nullptr, OHCaptureSessionCanPreconfigWithRatio, nullptr, nullptr,
2488             nullptr, napi_default, nullptr},
2489         {"oHCaptureSessionPreconfig", nullptr, OHCaptureSessionPreconfig, nullptr, nullptr, nullptr, napi_default,
2490             nullptr},
2491         {"oHCaptureSessionPreconfigWithRatio", nullptr, OHCaptureSessionPreconfigWithRatio, nullptr, nullptr, nullptr,
2492             napi_default, nullptr},
2493         {"oHCameraManagerCreateVideoOutputUsedInPreconfig", nullptr, OHCameraManagerCreateVideoOutputUsedInPreconfig,
2494             nullptr, nullptr, nullptr, napi_default, nullptr},
2495         {"oHVideoOutputGetActiveProfile", nullptr, OHVideoOutputGetActiveProfile, nullptr, nullptr, nullptr,
2496             napi_default, nullptr},
2497         {"oHVideoOutputDeleteProfile", nullptr, OHVideoOutputDeleteProfile, nullptr, nullptr, nullptr, napi_default,
2498             nullptr},
2499         {"oHPreviewOutputGetActiveProfile", nullptr, OHPreviewOutputGetActiveProfile, nullptr, nullptr, nullptr,
2500             napi_default, nullptr},
2501         {"oHPreviewOutputDeleteProfile", nullptr, OHPreviewOutputDeleteProfile, nullptr, nullptr, nullptr, napi_default,
2502             nullptr},
2503         {"oHPhotoOutputGetActiveProfile", nullptr, OHPhotoOutputGetActiveProfile, nullptr, nullptr, nullptr,
2504             napi_default, nullptr},
2505         {"oHPhotoOutputDeleteProfile", nullptr, OHPhotoOutputDeleteProfile, nullptr, nullptr, nullptr, napi_default,
2506             nullptr},
2507     };
2508     napi_property_descriptor desc3[] = {
2509         {"oHCameraManagerTorchMode", nullptr, OHCameraManagerTorchMode, nullptr, nullptr, nullptr,
2510          napi_default, nullptr},
2511         {"oHCameraManagerIsTorchSupported", nullptr, OHCameraManagerIsTorchSupported, nullptr, nullptr, nullptr,
2512          napi_default, nullptr},
2513         {"oHCameraManagerIsTorchSupportedByTorchMode", nullptr, OHCameraManagerIsTorchSupportedByTorchMode, nullptr,
2514          nullptr, nullptr, napi_default, nullptr},
2515         {"oHCameraManagerSetTorchMode", nullptr, OHCameraManagerSetTorchMode, nullptr, nullptr, nullptr,
2516          napi_default, nullptr},
2517         {"oHCaptureSessionGetExposureValue", nullptr, OHCaptureSessionGetExposureValue, nullptr, nullptr, nullptr,
2518          napi_default, nullptr},
2519         {"oHCaptureSessionGetFocalLength", nullptr, OHCaptureSessionGetFocalLength, nullptr, nullptr, nullptr,
2520          napi_default, nullptr},
2521         {"oHCaptureSessionSetSmoothZoom", nullptr, OHCaptureSessionSetSmoothZoom, nullptr, nullptr, nullptr,
2522          napi_default, nullptr},
2523         {"oHCaptureSessionGetSupportedColorSpaces", nullptr, OHCaptureSessionGetSupportedColorSpaces, nullptr,
2524          nullptr, nullptr, napi_default, nullptr},
2525         {"oHCaptureSessionDeleteColorSpaces", nullptr, OHCaptureSessionDeleteColorSpaces, nullptr,
2526          nullptr, nullptr, napi_default, nullptr},
2527         {"oHCaptureSessionGetActiveColorSpace", nullptr, OHCaptureSessionGetActiveColorSpace, nullptr, nullptr,
2528          nullptr, napi_default, nullptr},
2529         {"oHNativeBufferColorSpace", nullptr, OHNativeBufferColorSpace, nullptr, nullptr, nullptr, napi_default,
2530          nullptr},
2531         {"oHCaptureSessionSetActiveColorSpace", nullptr, OHCaptureSessionSetActiveColorSpace, nullptr, nullptr,
2532          nullptr, napi_default, nullptr},
2533         {"oHPreviewOutputGetSupportedFrameRates", nullptr, OHPreviewOutputGetSupportedFrameRates, nullptr, nullptr,
2534          nullptr, napi_default, nullptr},
2535         {"oHPreviewOutputSetFrameRate", nullptr, OHPreviewOutputSetFrameRate, nullptr, nullptr, nullptr,
2536          napi_default, nullptr},
2537         {"oHPreviewOutputGetActiveFrameRate", nullptr, OHPreviewOutputGetActiveFrameRate, nullptr, nullptr, nullptr,
2538          napi_default, nullptr},
2539         {"oHVideoOutputGetSupportedFrameRates", nullptr, OHVideoOutputGetSupportedFrameRates, nullptr, nullptr,
2540          nullptr, napi_default, nullptr},
2541         {"oHVideoOutputSetFrameRate", nullptr, OHVideoOutputSetFrameRate, nullptr, nullptr, nullptr, napi_default,
2542          nullptr},
2543         {"oHVideoOutputGetActiveFrameRate", nullptr, OHVideoOutputGetActiveFrameRate, nullptr, nullptr, nullptr,
2544          napi_default, nullptr},
2545         {"oHVideoOutputDeleteFrameRates", nullptr, OHVideoOutputDeleteFrameRates, nullptr, nullptr, nullptr,
2546          napi_default, nullptr},
2547         {"oHPreviewOutputDeleteFrameRates", nullptr, OHPreviewOutputDeleteFrameRates, nullptr, nullptr, nullptr,
2548          napi_default, nullptr},
2549         {"oHCameraManagerRegisterTorchStatusCallback", nullptr, OHCameraManagerRegisterTorchStatusCallback, nullptr,
2550          nullptr, nullptr, napi_default, nullptr},
2551         {"oHCameraManagerUnregisterTorchStatusCallback", nullptr, OHCameraManagerUnregisterTorchStatusCallback,
2552          nullptr, nullptr, nullptr, napi_default, nullptr},
2553         {"oHCaptureSessionRegisterSmoothZoomInfoCallback", nullptr, OHCaptureSessionRegisterSmoothZoomInfoCallback,
2554          nullptr, nullptr, nullptr, napi_default, nullptr},
2555         {"oHCaptureSessionUnregisterSmoothZoomInfoCallback", nullptr,
2556          OHCaptureSessionUnregisterSmoothZoomInfoCallback, nullptr, nullptr, nullptr, napi_default, nullptr},
2557         {"oHPhotoOutputRegisterCaptureStartWithInfoCallback", nullptr,
2558          OHPhotoOutputRegisterCaptureStartWithInfoCallback, nullptr, nullptr, nullptr, napi_default, nullptr},
2559         {"oHPhotoOutputUnregisterCaptureStartWithInfoCallback", nullptr,
2560          OHPhotoOutputUnregisterCaptureStartWithInfoCallback, nullptr, nullptr, nullptr, napi_default, nullptr},
2561         {"oHPhotoOutputRegisterCaptureEndCallback", nullptr, OHPhotoOutputRegisterCaptureEndCallback, nullptr,
2562          nullptr, nullptr, napi_default, nullptr},
2563         {"oHPhotoOutputUnregisterCaptureEndCallback", nullptr, OHPhotoOutputUnregisterCaptureEndCallback, nullptr,
2564          nullptr, nullptr, napi_default, nullptr},
2565         {"oHPhotoOutputRegisterFrameShutterEndCallback", nullptr, OHPhotoOutputRegisterFrameShutterEndCallback,
2566          nullptr, nullptr, nullptr, napi_default, nullptr},
2567         {"oHPhotoOutputUnregisterFrameShutterEndCallback", nullptr, OHPhotoOutputUnregisterFrameShutterEndCallback,
2568          nullptr, nullptr, nullptr, napi_default, nullptr},
2569         {"oHPhotoOutputRegisterCaptureReadyCallback", nullptr, OHPhotoOutputRegisterCaptureReadyCallback, nullptr,
2570          nullptr, nullptr, napi_default, nullptr},
2571         {"oHPhotoOutputUnregisterCaptureReadyCallback", nullptr, OHPhotoOutputUnregisterCaptureReadyCallback, nullptr,
2572          nullptr, nullptr, napi_default, nullptr},
2573         {"oHPhotoOutputRegisterEstimatedCaptureDurationCallback", nullptr,
2574          OHPhotoOutputRegisterEstimatedCaptureDurationCallback, nullptr, nullptr, nullptr, napi_default, nullptr},
2575         {"oHPhotoOutputUnregisterEstimatedCaptureDurationCallback", nullptr,
2576          OHPhotoOutputUnregisterEstimatedCaptureDurationCallback, nullptr, nullptr, nullptr, napi_default, nullptr},
2577     };
2578     napi_property_descriptor desc4[] = {
2579         {"oHPhotoOutputRegisterPhotoAvailableCallback", nullptr, OHPhotoOutputRegisterPhotoAvailableCallback,
2580             nullptr, nullptr, nullptr, napi_default, nullptr},
2581         {"oHPhotoOutputUnregisterPhotoAvailableCallback", nullptr, OHPhotoOutputUnregisterPhotoAvailableCallback,
2582             nullptr, nullptr, nullptr, napi_default, nullptr},
2583         {"oHPhotoOutputRegisterPhotoAssetAvailableCallback", nullptr, OHPhotoOutputRegisterPhotoAssetAvailableCallback,
2584             nullptr, nullptr, nullptr, napi_default, nullptr},
2585         {"oHPhotoOutputUnregisterPhotoAssetAvailableCallback", nullptr,
2586             OHPhotoOutputUnregisterPhotoAssetAvailableCallback, nullptr, nullptr, nullptr, napi_default, nullptr},
2587         {"oHPhotoOutputIsMovingPhotoSupported", nullptr, OHPhotoOutputIsMovingPhotoSupported, nullptr, nullptr, nullptr,
2588             napi_default, nullptr},
2589         {"oHPhotoOutputEnableMovingPhoto", nullptr, OHPhotoOutputEnableMovingPhoto, nullptr, nullptr, nullptr,
2590             napi_default, nullptr},
2591         {"oHPhotoNativeGetMainImage", nullptr, OHPhotoNativeGetMainImage, nullptr, nullptr, nullptr, napi_default,
2592             nullptr},
2593         {"oHPhotoNativeRelease", nullptr, OHPhotoNativeRelease, nullptr, nullptr, nullptr, napi_default,
2594             nullptr},
2595         {"oHCameraManagerCreatePhotoOutputWithoutSurface", nullptr, OHCameraManagerCreatePhotoOutputWithoutSurface,
2596             nullptr, nullptr, nullptr, napi_default, nullptr},
2597         {"releaseCamera", nullptr, ReleaseCamera, nullptr, nullptr, nullptr, napi_default, nullptr},
2598         {"readyCreatePhotoOutputWithoutSurface", nullptr, ReadyCreatePhotoOutputWithoutSurface, nullptr, nullptr,
2599             nullptr, napi_default, nullptr},
2600     };
2601     size_t mergedLength = sizeof(desc) / sizeof(desc[0]) +
2602                           sizeof(desc1) / sizeof(desc1[0]) +
2603                           sizeof(desc2) / sizeof(desc2[0]) +
2604                           sizeof(desc3) / sizeof(desc3[0]) +
2605                           sizeof(desc4) / sizeof(desc4[0]);
2606     napi_property_descriptor mergedArray[mergedLength];
2607     for (size_t i = 0; i < sizeof(desc) / sizeof(desc[0]); ++i) {
2608         mergedArray[i] = desc[i];
2609     }
2610     for (size_t i = 0; i < sizeof(desc1) / sizeof(desc1[0]); ++i) {
2611         mergedArray[sizeof(desc) / sizeof(desc[0]) + i] = desc1[i];
2612     }
2613     for (size_t i = 0; i < sizeof(desc2) / sizeof(desc2[0]); ++i) {
2614         mergedArray[sizeof(desc) / sizeof(desc[0]) + sizeof(desc1) / sizeof(desc1[0]) + i] = desc2[i];
2615     }
2616     for (size_t i = 0; i < sizeof(desc3) / sizeof(desc3[0]); ++i) {
2617         mergedArray[sizeof(desc) / sizeof(desc[0]) + sizeof(desc1) / sizeof(desc1[0]) +
2618             sizeof(desc2) / sizeof(desc2[0]) + i] = desc3[i];
2619     }
2620     for (size_t i = 0; i < sizeof(desc4) / sizeof(desc4[0]); ++i) {
2621         mergedArray[sizeof(desc) / sizeof(desc[0]) + sizeof(desc1) / sizeof(desc1[0]) +
2622         sizeof(desc2) / sizeof(desc2[0]) + sizeof(desc3) / sizeof(desc3[0]) + i] = desc4[i];
2623     }
2624     napi_define_properties(env, exports, mergedLength, mergedArray);
2625     return exports;
2626 };
2627 EXTERN_C_END
2628 
2629 static napi_module demoModule = {
2630     .nm_version =1,
2631     .nm_flags = 0,
2632     .nm_filename = nullptr,
2633     .nm_register_func = Init,
2634     .nm_modname = "entry",
2635     .nm_priv = ((void*)0),
2636     .reserved = { 0 },
2637 };
2638 
RegisterEntryModule(void)2639 extern "C" __attribute__((constructor)) void RegisterEntryModule(void)
2640 {
2641     napi_module_register(&demoModule);
2642 }
2643