• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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 PHOTO_OUTPUT_NAPI_H_
17 #define PHOTO_OUTPUT_NAPI_H_
18 
19 #include <cstdint>
20 #include <memory>
21 #include <mutex>
22 
23 #include "camera_napi_event_emitter.h"
24 #include "camera_napi_template_utils.h"
25 #include "input/camera_device.h"
26 #include "input/camera_manager.h"
27 #include "listener_base.h"
28 #include "native_image.h"
29 #include "output/camera_output_capability.h"
30 #include "output/photo_output.h"
31 #include "pixel_map.h"
32 
33 namespace OHOS::Media {
34     class PixelMap;
35 }
36 namespace OHOS {
37 namespace CameraStandard {
38 class PictureIntf;
39 const std::string dataWidth = "dataWidth";
40 const std::string dataHeight = "dataHeight";
41 static const std::string CONST_CAPTURE_START = "captureStart";
42 static const std::string CONST_CAPTURE_END = "captureEnd";
43 static const std::string CONST_CAPTURE_FRAME_SHUTTER = "frameShutter";
44 static const std::string CONST_CAPTURE_ERROR = "error";
45 static const std::string CONST_CAPTURE_PHOTO_AVAILABLE = "photoAvailable";
46 static const std::string CONST_CAPTURE_DEFERRED_PHOTO_AVAILABLE = "deferredPhotoProxyAvailable";
47 static const std::string CONST_CAPTURE_PHOTO_ASSET_AVAILABLE = "photoAssetAvailable";
48 static const std::string CONST_CAPTURE_FRAME_SHUTTER_END = "frameShutterEnd";
49 static const std::string CONST_CAPTURE_READY = "captureReady";
50 static const std::string CONST_CAPTURE_ESTIMATED_CAPTURE_DURATION = "estimatedCaptureDuration";
51 static const std::string CONST_CAPTURE_START_WITH_INFO = "captureStartWithInfo";
52 
53 static const std::string CONST_CAPTURE_QUICK_THUMBNAIL = "quickThumbnail";
54 static const char CAMERA_PHOTO_OUTPUT_NAPI_CLASS_NAME[] = "PhotoOutput";
55 
56 static const std::string CONST_GAINMAP_SURFACE = "gainmap";
57 static const std::string CONST_DEEP_SURFACE = "deep";
58 static const std::string CONST_EXIF_SURFACE = "exif";
59 static const std::string CONST_DEBUG_SURFACE = "debug";
60 static const std::string CONST_CAPTURE_OFFLINE_DELIVERY_FINISHED = "offlineDeliveryFinished";
61 
62 struct CallbackInfo {
63     int32_t captureID;
64     uint64_t timestamp = 0;
65     int32_t frameCount = 0;
66     int32_t errorCode;
67     int32_t duration;
68 };
69 
70 enum PhotoOutputEventType {
71     CAPTURE_START,
72     CAPTURE_END,
73     CAPTURE_FRAME_SHUTTER,
74     CAPTURE_FRAME_SHUTTER_END,
75     CAPTURE_READY,
76     CAPTURE_ERROR,
77     CAPTURE_INVALID_TYPE,
78     CAPTURE_PHOTO_AVAILABLE,
79     CAPTURE_DEFERRED_PHOTO_AVAILABLE,
80     CAPTURE_PHOTO_ASSET_AVAILABLE,
81     CAPTURE_ESTIMATED_CAPTURE_DURATION,
82     CAPTURE_START_WITH_INFO,
83     CAPTURE_OFFLINE_DELIVERY_FINISHED
84 };
85 
86 static EnumHelper<PhotoOutputEventType> PhotoOutputEventTypeHelper({
87         {CAPTURE_START, CONST_CAPTURE_START},
88         {CAPTURE_END, CONST_CAPTURE_END},
89         {CAPTURE_FRAME_SHUTTER, CONST_CAPTURE_FRAME_SHUTTER},
90         {CAPTURE_ERROR, CONST_CAPTURE_ERROR},
91         {CAPTURE_PHOTO_AVAILABLE, CONST_CAPTURE_PHOTO_AVAILABLE},
92         {CAPTURE_DEFERRED_PHOTO_AVAILABLE, CONST_CAPTURE_DEFERRED_PHOTO_AVAILABLE},
93         {CAPTURE_PHOTO_ASSET_AVAILABLE, CONST_CAPTURE_PHOTO_ASSET_AVAILABLE},
94         {CAPTURE_FRAME_SHUTTER_END, CONST_CAPTURE_FRAME_SHUTTER_END},
95         {CAPTURE_READY, CONST_CAPTURE_READY},
96         {CAPTURE_ESTIMATED_CAPTURE_DURATION, CONST_CAPTURE_ESTIMATED_CAPTURE_DURATION},
97         {CAPTURE_START_WITH_INFO, CONST_CAPTURE_START_WITH_INFO},
98         {CAPTURE_OFFLINE_DELIVERY_FINISHED, CONST_CAPTURE_OFFLINE_DELIVERY_FINISHED}
99     },
100     PhotoOutputEventType::CAPTURE_INVALID_TYPE
101 );
102 enum SurfaceType {
103     GAINMAP_SURFACE = 0,
104     DEEP_SURFACE = 1,
105     EXIF_SURFACE = 2,
106     DEBUG_SURFACE = 3,
107     INVALID_SURFACE = -1,
108 };
109 
110 static EnumHelper<SurfaceType> SurfaceTypeHelper({
111         {GAINMAP_SURFACE, CONST_GAINMAP_SURFACE},
112         {DEEP_SURFACE, CONST_DEEP_SURFACE},
113         {EXIF_SURFACE, CONST_EXIF_SURFACE},
114         {DEBUG_SURFACE, CONST_DEBUG_SURFACE},
115     },
116     SurfaceType::INVALID_SURFACE
117 );
118 
119 class PhotoBufferProcessor : public Media::IBufferProcessor {
120 public:
PhotoBufferProcessor(sptr<Surface> photoSurface)121     explicit PhotoBufferProcessor(sptr<Surface> photoSurface) : photoSurface_(photoSurface) {}
~PhotoBufferProcessor()122     ~PhotoBufferProcessor()
123     {
124         photoSurface_ = nullptr;
125     }
BufferRelease(sptr<SurfaceBuffer> & buffer)126     void BufferRelease(sptr<SurfaceBuffer>& buffer) override
127     {
128         if (photoSurface_ != nullptr) {
129             photoSurface_->ReleaseBuffer(buffer, -1);
130         }
131     }
132 
133 private:
134     sptr<Surface> photoSurface_ = nullptr;
135 };
136 
137 class PhotoListener : public IBufferConsumerListener,
138                       public ListenerBase,
139                       public std::enable_shared_from_this<PhotoListener> {
140 public:
141     explicit PhotoListener(napi_env env, const sptr<Surface> photoSurface, wptr<PhotoOutput> photoOutput);
142     virtual ~PhotoListener();
143     void OnBufferAvailable() override;
144     void SaveCallback(const std::string eventName, napi_value callback);
145     void RemoveCallback(const std::string eventName, napi_value callback);
146     void ExecuteDeepCopySurfaceBuffer();
147 
148     void ClearTaskManager();
149     std::shared_ptr<DeferredProcessing::TaskManager> GetDefaultTaskManager();
150 
151 private:
152 
153     void UpdateJSCallback(sptr<Surface> photoSurface) const;
154     void UpdateJSCallbackAsync(sptr<Surface> photoSurface) const;
155     void UpdatePictureJSCallback(int32_t captureId, const string uri, int32_t cameraShotType,
156         const std::string burstKey) const;
157     void UpdateMainPictureStageOneJSCallback(sptr<SurfaceBuffer> surfaceBuffer, int64_t timestamp) const;
158     void ExecutePhoto(sptr<SurfaceBuffer> surfaceBfuffer, int64_t timestamp) const;
159     void ExecuteDeferredPhoto(sptr<SurfaceBuffer> surfaceBuffer) const;
160     void DeepCopyBuffer(sptr<SurfaceBuffer> newSurfaceBuffer, sptr<SurfaceBuffer> surfaceBuffer,
161         int32_t captureId) const;
162     void ExecutePhotoAsset(sptr<SurfaceBuffer> surfaceBuffer, bool isHighQuality, int64_t timestamp) const;
163     void CreateMediaLibrary(sptr<SurfaceBuffer> surfaceBuffer, BufferHandle* bufferHandle, bool isHighQuality,
164         std::string& uri, int32_t& cameraShotType, std::string &burstKey, int64_t timestamp) const;
165     void AssembleAuxiliaryPhoto(int64_t timestamp, int32_t captureId);
166     int32_t GetAuxiliaryPhotoCount(sptr<SurfaceBuffer> surfaceBuffer);
167     sptr<Surface> photoSurface_;
168     wptr<PhotoOutput> photoOutput_;
169     shared_ptr<PhotoBufferProcessor> bufferProcessor_;
170     uint8_t callbackFlag_ = 0;
171     std::mutex taskManagerMutex_;
172     std::shared_ptr<DeferredProcessing::TaskManager> taskManager_ = nullptr;
173 };
174 
175 class RawPhotoListener : public IBufferConsumerListener, public ListenerBase,
176     public std::enable_shared_from_this<RawPhotoListener> {
177 public:
178     explicit RawPhotoListener(napi_env env, const sptr<Surface> rawPhotoSurface);
179     ~RawPhotoListener() = default;
180     void OnBufferAvailable() override;
181 
182 private:
183     sptr<Surface> rawPhotoSurface_;
184     shared_ptr<PhotoBufferProcessor> bufferProcessor_;
185     void UpdateJSCallback(sptr<Surface> rawPhotoSurface) const;
186     void UpdateJSCallbackAsync(sptr<Surface> rawPhotoSurface) const;
187     void ExecuteRawPhoto(sptr<SurfaceBuffer> rawPhotoSurface) const;
188 };
189 
190 class AuxiliaryPhotoListener : public IBufferConsumerListener {
191 public:
192     explicit AuxiliaryPhotoListener(const std::string surfaceName, const sptr<Surface> surface,
193         wptr<PhotoOutput> photoOutput);
194     ~AuxiliaryPhotoListener() = default;
195     void OnBufferAvailable() override;
196     void ExecuteDeepCopySurfaceBuffer();
197 private:
198     void DeepCopyBuffer(sptr<SurfaceBuffer> newSurfaceBuffer, sptr<SurfaceBuffer> surfaceBuffer, int32_t) const;
199     std::string surfaceName_;
200     sptr<Surface> surface_;
201     wptr<PhotoOutput> photoOutput_;
202     shared_ptr<PhotoBufferProcessor> bufferProcessor_;
203 };
204 
205 class PictureListener : public RefBase {
206 public:
207     explicit PictureListener() = default;
208     ~PictureListener() = default;
209     void InitPictureListeners(napi_env env, wptr<PhotoOutput> photoOutput);
210     sptr<AuxiliaryPhotoListener> gainmapImageListener;
211     sptr<AuxiliaryPhotoListener> deepImageListener;
212     sptr<AuxiliaryPhotoListener> exifImageListener;
213     sptr<AuxiliaryPhotoListener> debugImageListener;
214 };
215 
216 class PhotoOutputCallback : public PhotoStateCallback,
217                             public ListenerBase,
218                             public std::enable_shared_from_this<PhotoOutputCallback> {
219 public:
220     explicit PhotoOutputCallback(napi_env env);
221     ~PhotoOutputCallback() = default;
222 
223     void OnCaptureStarted(const int32_t captureID) const override;
224     void OnCaptureStarted(const int32_t captureID, uint32_t exposureTime) const override;
225     void OnCaptureEnded(const int32_t captureID, const int32_t frameCount) const override;
226     void OnFrameShutter(const int32_t captureId, const uint64_t timestamp) const override;
227     void OnFrameShutterEnd(const int32_t captureId, const uint64_t timestamp) const override;
228     void OnCaptureReady(const int32_t captureId, const uint64_t timestamp) const override;
229     void OnCaptureError(const int32_t captureId, const int32_t errorCode) const override;
230     void OnEstimatedCaptureDuration(const int32_t duration) const override;
231     void OnOfflineDeliveryFinished(const int32_t captureId) const override;
232 
233 private:
234     void UpdateJSCallback(PhotoOutputEventType eventType, const CallbackInfo& info) const;
235     void UpdateJSCallbackAsync(PhotoOutputEventType eventType, const CallbackInfo& info) const;
236     void ExecuteCaptureStartCb(const CallbackInfo& info) const;
237     void ExecuteCaptureStartWithInfoCb(const CallbackInfo& info) const;
238     void ExecuteCaptureEndCb(const CallbackInfo& info) const;
239     void ExecuteFrameShutterCb(const CallbackInfo& info) const;
240     void ExecuteCaptureErrorCb(const CallbackInfo& info) const;
241     void ExecuteFrameShutterEndCb(const CallbackInfo& info) const;
242     void ExecuteCaptureReadyCb(const CallbackInfo& info) const;
243     void ExecuteEstimatedCaptureDurationCb(const CallbackInfo& info) const;
244     void ExecuteOfflineDeliveryFinishedCb(const CallbackInfo& info) const;
245 };
246 
247 struct PhotoOutputCallbackInfo {
248     PhotoOutputEventType eventType_;
249     CallbackInfo info_;
250     weak_ptr<const PhotoOutputCallback> listener_;
PhotoOutputCallbackInfoPhotoOutputCallbackInfo251     PhotoOutputCallbackInfo(
252         PhotoOutputEventType eventType, CallbackInfo info, shared_ptr<const PhotoOutputCallback> listener)
253         : eventType_(eventType), info_(info), listener_(listener)
254     {}
255 };
256 
257 class ThumbnailListener : public IBufferConsumerListener, public ListenerBase {
258 public:
259     explicit ThumbnailListener(napi_env env, const sptr<PhotoOutput> photoOutput);
260     virtual ~ThumbnailListener();
261     void OnBufferAvailable() override;
262     std::shared_ptr<DeferredProcessing::TaskManager> taskManager_ = nullptr;
263     void ClearTaskManager();
264     std::mutex taskManagerMutex_;
265 private:
266     wptr<PhotoOutput> photoOutput_;
267     void UpdateJSCallback() const;
268     void UpdateJSCallbackAsync();
269     void UpdateJSCallback(int32_t captureId, int64_t timestamp, unique_ptr<Media::PixelMap>) const;
270     void UpdateJSCallbackAsync(int32_t captureId, int64_t timestamp, unique_ptr<Media::PixelMap>);
271     void ExecuteDeepCopySurfaceBuffer();
272 
273     unique_ptr<Media::PixelMap> CreatePixelMapFromSurfaceBuffer(sptr<SurfaceBuffer> &surfaceBuffer,
274         int32_t width, int32_t height, bool isHdr);
275     unique_ptr<Media::PixelMap> SetPixelMapYuvInfo(sptr<SurfaceBuffer> &surfaceBuffer,
276         unique_ptr<Media::PixelMap> pixelMap, bool isHdr);
277     void DeepCopyBuffer(sptr<SurfaceBuffer> newSurfaceBuffer, sptr<SurfaceBuffer> surfaceBuffer,
278         int32_t thumbnailWidth, int32_t thumbnailHeight, bool isHdr) const;
279 
280     static constexpr int32_t PLANE_Y = 0;
281     static constexpr int32_t PLANE_U = 1;
282     static constexpr uint8_t PIXEL_SIZE_HDR_YUV = 3;
283     static constexpr uint8_t  HDR_PIXEL_SIZE = 2;
284     static constexpr uint8_t SDR_PIXEL_SIZE = 1;
285 };
286 
287 struct ThumbnailListenerInfo {
288     wptr<ThumbnailListener> listener_;
289     int32_t captureId_;
290     int64_t timestamp_;
291     unique_ptr<Media::PixelMap> pixelMap_;
ThumbnailListenerInfoThumbnailListenerInfo292     ThumbnailListenerInfo(sptr<ThumbnailListener> listener, int32_t captureId,
293         int64_t timestamp, unique_ptr<Media::PixelMap> pixelMap)
294         : listener_(listener), captureId_(captureId), timestamp_(timestamp), pixelMap_(std::move(pixelMap))
295     {}
296 };
297 
298 struct PhotoListenerInfo {
299     sptr<Surface> photoSurface_;
300     weak_ptr<const PhotoListener> listener_;
PhotoListenerInfoPhotoListenerInfo301     PhotoListenerInfo(sptr<Surface> photoSurface, shared_ptr<const PhotoListener> listener)
302         : photoSurface_(photoSurface), listener_(listener)
303     {}
304     int32_t captureId = 0;
305     std::string uri = "";
306     int32_t cameraShotType = 0;
307     std::string burstKey = "";
308     sptr<SurfaceBuffer> surfaceBuffer = nullptr;
309     int64_t timestamp = 0;
310 };
311 
312 struct RawPhotoListenerInfo {
313     sptr<Surface> rawPhotoSurface_;
314     weak_ptr<const RawPhotoListener> listener_;
RawPhotoListenerInfoRawPhotoListenerInfo315     RawPhotoListenerInfo(sptr<Surface> rawPhotoSurface, shared_ptr<const RawPhotoListener> listener)
316         : rawPhotoSurface_(rawPhotoSurface), listener_(listener)
317     {}
318 };
319 
320 struct PhotoOutputAsyncContext;
321 class PhotoOutputNapi : public CameraNapiEventEmitter<PhotoOutputNapi> {
322 public:
323     static napi_value Init(napi_env env, napi_value exports);
324     static napi_value CreatePhotoOutput(napi_env env, Profile& profile, std::string surfaceId);
325     static napi_value CreatePhotoOutput(napi_env env, std::string surfaceId);
326 
327     static napi_value Capture(napi_env env, napi_callback_info info);
328     static napi_value BurstCapture(napi_env env, napi_callback_info info);
329     static napi_value ConfirmCapture(napi_env env, napi_callback_info info);
330     static napi_value Release(napi_env env, napi_callback_info info);
331     static napi_value IsMirrorSupported(napi_env env, napi_callback_info info);
332     static napi_value EnableMirror(napi_env env, napi_callback_info info);
333     static napi_value EnableQuickThumbnail(napi_env env, napi_callback_info info);
334     static napi_value IsQuickThumbnailSupported(napi_env env, napi_callback_info info);
335     static napi_value EnableRawDelivery(napi_env env, napi_callback_info info);
336     static napi_value IsRawDeliverySupported(napi_env env, napi_callback_info info);
337     static napi_value DeferImageDeliveryFor(napi_env env, napi_callback_info info);
338     static napi_value IsDeferredImageDeliverySupported(napi_env env, napi_callback_info info);
339     static napi_value IsDeferredImageDeliveryEnabled(napi_env env, napi_callback_info info);
340     static napi_value GetSupportedMovingPhotoVideoCodecTypes(napi_env env, napi_callback_info info);
341     static napi_value SetMovingPhotoVideoCodecType(napi_env env, napi_callback_info info);
342     static napi_value IsDepthDataDeliverySupported(napi_env env, napi_callback_info info);
343     static napi_value EnableDepthDataDelivery(napi_env env, napi_callback_info info);
344     static bool IsPhotoOutput(napi_env env, napi_value obj);
345     static napi_value GetActiveProfile(napi_env env, napi_callback_info info);
346     static napi_value On(napi_env env, napi_callback_info info);
347     static napi_value Once(napi_env env, napi_callback_info info);
348     static napi_value Off(napi_env env, napi_callback_info info);
349     static napi_value IsAutoHighQualityPhotoSupported(napi_env env, napi_callback_info info);
350     static napi_value EnableAutoHighQualityPhoto(napi_env env, napi_callback_info info);
351     static napi_value IsAutoCloudImageEnhancementSupported(napi_env env, napi_callback_info info);
352     static napi_value EnableAutoCloudImageEnhancement(napi_env env, napi_callback_info info);
353     static napi_value IsMovingPhotoSupported(napi_env env, napi_callback_info info);
354     static napi_value EnableMovingPhoto(napi_env env, napi_callback_info info);
355     static napi_value GetPhotoRotation(napi_env env, napi_callback_info info);
356     static napi_value IsAutoAigcPhotoSupported(napi_env env, napi_callback_info info);
357     static napi_value EnableAutoAigcPhoto(napi_env env, napi_callback_info info);
358     static napi_value IsOfflineSupported(napi_env env, napi_callback_info info);
359     static napi_value EnableOfflinePhoto(napi_env env, napi_callback_info info);
360 
361     PhotoOutputNapi();
362     ~PhotoOutputNapi() override;
363 
364     sptr<PhotoOutput> GetPhotoOutput();
365     bool GetEnableMirror();
366 
367     const EmitterFunctions& GetEmitterFunctions() override;
368 
369 private:
370     static void PhotoOutputNapiDestructor(napi_env env, void* nativeObject, void* finalize_hint);
371     static napi_value PhotoOutputNapiConstructor(napi_env env, napi_callback_info info);
372 
373     void CreateMultiChannelPictureLisenter(napi_env env);
374     void CreateSingleChannelPhotoLisenter(napi_env env);
375     void RegisterQuickThumbnailCallbackListener(const std::string& eventName, napi_env env, napi_value callback,
376         const std::vector<napi_value>& args, bool isOnce);
377     void UnregisterQuickThumbnailCallbackListener(
378         const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args);
379     void RegisterPhotoAvailableCallbackListener(const std::string& eventName, napi_env env, napi_value callback,
380         const std::vector<napi_value>& args, bool isOnce);
381     void UnregisterPhotoAvailableCallbackListener(
382         const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args);
383     void RegisterDeferredPhotoProxyAvailableCallbackListener(const std::string& eventName, napi_env env,
384         napi_value callback, const std::vector<napi_value>& args, bool isOnce);
385     void UnregisterDeferredPhotoProxyAvailableCallbackListener(
386         const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args);
387     void RegisterPhotoAssetAvailableCallbackListener(const std::string& eventName, napi_env env, napi_value callback,
388         const std::vector<napi_value>& args, bool isOnce);
389     void UnregisterPhotoAssetAvailableCallbackListener(
390         const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args);
391     void RegisterCaptureStartCallbackListener(const std::string& eventName, napi_env env, napi_value callback,
392         const std::vector<napi_value>& args, bool isOnce);
393     void UnregisterCaptureStartCallbackListener(
394         const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args);
395     void RegisterCaptureEndCallbackListener(const std::string& eventName, napi_env env, napi_value callback,
396         const std::vector<napi_value>& args, bool isOnce);
397     void UnregisterCaptureEndCallbackListener(
398         const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args);
399     void RegisterFrameShutterCallbackListener(const std::string& eventName, napi_env env, napi_value callback,
400         const std::vector<napi_value>& args, bool isOnce);
401     void UnregisterFrameShutterCallbackListener(
402         const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args);
403     void RegisterErrorCallbackListener(const std::string& eventName, napi_env env, napi_value callback,
404         const std::vector<napi_value>& args, bool isOnce);
405     void UnregisterErrorCallbackListener(
406         const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args);
407     void RegisterFrameShutterEndCallbackListener(const std::string& eventName, napi_env env, napi_value callback,
408         const std::vector<napi_value>& args, bool isOnce);
409     void UnregisterFrameShutterEndCallbackListener(
410         const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args);
411     void RegisterReadyCallbackListener(const std::string& eventName, napi_env env, napi_value callback,
412         const std::vector<napi_value>& args, bool isOnce);
413     void UnregisterReadyCallbackListener(
414         const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args);
415     void RegisterEstimatedCaptureDurationCallbackListener(const std::string& eventName, napi_env env,
416         napi_value callback, const std::vector<napi_value>& args, bool isOnce);
417     void UnregisterEstimatedCaptureDurationCallbackListener(
418         const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args);
419     void RegisterCaptureStartWithInfoCallbackListener(const std::string& eventName, napi_env env, napi_value callback,
420         const std::vector<napi_value>& args, bool isOnce);
421     void UnregisterCaptureStartWithInfoCallbackListener(
422         const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args);
423     void RegisterOfflineDeliveryFinishedCallbackListener(
424         const std::string& eventName, napi_env env, napi_value callback,
425         const std::vector<napi_value>& args, bool isOnce);
426     void UnregisterOfflineDeliveryFinishedCallbackListener(
427         const std::string& eventName, napi_env env, napi_value callback, const std::vector<napi_value>& args);
428 
429     static thread_local napi_ref sConstructor_;
430     static thread_local sptr<PhotoOutput> sPhotoOutput_;
431 
432     sptr<PhotoOutput> photoOutput_;
433     std::shared_ptr<Profile> profile_;
434     bool isQuickThumbnailEnabled_ = false;
435     bool isDeferredPhotoEnabled_ = false;
436     bool isMirrorEnabled_ = false;
437     sptr<ThumbnailListener> thumbnailListener_;
438     sptr<PhotoListener> photoListener_;
439     sptr<RawPhotoListener> rawPhotoListener_;
440     sptr<PictureListener> pictureListener_;
441     std::shared_ptr<PhotoOutputCallback> photoOutputCallback_;
442     static thread_local uint32_t photoOutputTaskId;
443     static thread_local napi_ref rawCallback_;
444 };
445 
446 struct PhotoOutputNapiCaptureSetting {
447     int32_t quality = -1;
448 };
449 
450 struct PhotoOutputAsyncContext : public AsyncContext {
PhotoOutputAsyncContextPhotoOutputAsyncContext451     PhotoOutputAsyncContext(std::string funcName, int32_t taskId) : AsyncContext(funcName, taskId) {};
452     int32_t quality = -1;
453     int32_t rotation = -1;
454     bool isMirror = false;
455     bool isMirrorSettedByUser = false;
456     bool hasPhotoSettings = false;
457     bool isSupported = false;
458     shared_ptr<Location> location;
459     PhotoOutputNapi* objectInfo = nullptr;
460     std::string surfaceId;
461 };
462 } // namespace CameraStandard
463 } // namespace OHOS
464 #endif /* PHOTO_OUTPUT_NAPI_H_ */