• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef METADATA_OUTPUT_NAPI_H_
17 #define METADATA_OUTPUT_NAPI_H_
18 
19 #include <cinttypes>
20 #include <securec.h>
21 
22 #include "camera_log.h"
23 #include "napi/native_api.h"
24 #include "napi/native_node_api.h"
25 
26 #include "input/camera_manager.h"
27 #include "input/camera_info.h"
28 
29 #include "hilog/log.h"
30 #include "camera_napi_utils.h"
31 
32 #include <fstream>
33 #include <iostream>
34 #include <sstream>
35 #include <vector>
36 
37 #include <fcntl.h>
38 #include <sys/stat.h>
39 #include <sys/time.h>
40 #include <sys/types.h>
41 
42 namespace OHOS {
43 namespace CameraStandard {
44 static const char CAMERA_METADATA_OUTPUT_NAPI_CLASS_NAME[] = "MetadataOutput";
45 
46 class MetadataOutputCallback : public MetadataObjectCallback {
47 public:
48     explicit MetadataOutputCallback(napi_env env);
49     ~MetadataOutputCallback() = default;
50 
51     void OnMetadataObjectsAvailable(std::vector<sptr<MetadataObject>> metaObjects) const override;
52     void SetCallbackRef(const std::string &eventType, const napi_ref &callbackRef);
53 
54 private:
55     void OnMetadataObjectsAvailableCallback(const std::vector<sptr<MetadataObject>> metadataObjList) const;
56     napi_env env_;
57     napi_ref metadataObjectsAvailableCallbackRef_ = nullptr;
58 };
59 
60 struct  MetadataOutputCallbackInfo {
61     const std::vector<sptr<MetadataObject>> info_;
62     const MetadataOutputCallback* listener_;
MetadataOutputCallbackInfoMetadataOutputCallbackInfo63     MetadataOutputCallbackInfo(std::vector<sptr<MetadataObject>> metadataObjList,
64         const MetadataOutputCallback* listener)
65         : info_(metadataObjList), listener_(listener) {}
66 };
67 
68 class MetadataOutputNapi {
69 public:
70     static napi_value Init(napi_env env, napi_value exports);
71     static napi_value CreateMetadataOutput(napi_env env);
72     MetadataOutputNapi();
73     ~MetadataOutputNapi();
74     sptr<MetadataOutput> GetMetadataOutput();
75     static bool IsMetadataOutput(napi_env env, napi_value obj);
76 
77 private:
78     static void MetadataOutputNapiDestructor(napi_env env, void* nativeObject, void* finalize_hint);
79     static napi_value MetadataOutputNapiConstructor(napi_env env, napi_callback_info info);
80 
81     static napi_value GetSupportedMetadataObjectTypes(napi_env env, napi_callback_info info);
82     static napi_value SetCapturingMetadataObjectTypes(napi_env env, napi_callback_info info);
83     static napi_value Start(napi_env env, napi_callback_info info);
84     static napi_value Stop(napi_env env, napi_callback_info info);
85     static napi_value On(napi_env env, napi_callback_info info);
86 
87     static thread_local napi_ref sConstructor_;
88     static thread_local sptr<MetadataOutput> sMetadataOutput_;
89 
90     napi_env env_;
91     napi_ref wrapper_;
92     sptr<MetadataOutput> metadataOutput_;
93     std::shared_ptr<MetadataOutputCallback> metadataCallback_ = nullptr;
94 };
95 
96 struct MetadataOutputAsyncContext : public AsyncContext {
97     MetadataOutputNapi* objectInfo;
98     bool bRetBool;
99     bool isSupported = false;
100     std::string errorMsg;
101     std::vector<MetadataObjectType> SupportedMetadataObjectTypes;
102     std::vector<MetadataObjectType> setSupportedMetadataObjectTypes;
~MetadataOutputAsyncContextMetadataOutputAsyncContext103     ~MetadataOutputAsyncContext()
104     {
105         objectInfo = nullptr;
106     }
107 };
108 } // namespace CameraStandard
109 } // namespace OHOS
110 #endif /* METADATA_OUTPUT_NAPI_H_ */
111