1 /*
2  * Copyright (C) 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 AV_RECORDER_NAPI_H
17 #define AV_RECORDER_NAPI_H
18 
19 #include "recorder.h"
20 #include "av_common.h"
21 #include "media_errors.h"
22 #include "napi/native_api.h"
23 #include "napi/native_node_api.h"
24 #include "common_napi.h"
25 #include "task_queue.h"
26 #include "recorder_profiles.h"
27 #include "pixel_map_napi.h"
28 #include "buffer/avbuffer.h"
29 
30 namespace OHOS {
31 namespace Media {
32 /* type AVRecorderState = 'idle' | 'prepared' | 'started' | 'paused' | 'stopped' | 'released' | 'error'; */
33 namespace AVRecorderState {
34 const std::string STATE_IDLE = "idle";
35 const std::string STATE_PREPARED = "prepared";
36 const std::string STATE_STARTED = "started";
37 const std::string STATE_PAUSED = "paused";
38 const std::string STATE_STOPPED = "stopped";
39 const std::string STATE_RELEASED = "released";
40 const std::string STATE_ERROR = "error";
41 }
42 
43 namespace AVRecordergOpt {
44 const std::string PREPARE = "Prepare";
45 const std::string SET_ORIENTATION_HINT = "SetOrientationHint";
46 const std::string GETINPUTSURFACE = "GetInputSurface";
47 const std::string GETINPUTMETASURFACE = "GetInputMetaSurface";
48 const std::string START = "Start";
49 const std::string PAUSE = "Pause";
50 const std::string RESUME = "Resume";
51 const std::string STOP = "Stop";
52 const std::string RESET = "Reset";
53 const std::string RELEASE = "Release";
54 const std::string GET_AV_RECORDER_PROFILE = "GetAVRecorderProfile";
55 const std::string SET_AV_RECORDER_CONFIG = "SetAVRecorderConfig";
56 const std::string GET_AV_RECORDER_CONFIG = "GetAVRecorderConfig";
57 const std::string GET_CURRENT_AUDIO_CAPTURER_INFO = "GetCurrentAudioCapturerInfo";
58 const std::string GET_MAX_AMPLITUDE = "GetMaxAmplitude";
59 const std::string GET_ENCODER_INFO = "GetEncoderInfo";
60 const std::string IS_WATERMARK_SUPPORTED = "IsWatermarkSupported";
61 const std::string SET_WATERMARK = "SetWatermark";
62 }
63 
64 constexpr int32_t AVRECORDER_DEFAULT_AUDIO_BIT_RATE = 48000;
65 constexpr int32_t AVRECORDER_DEFAULT_AUDIO_CHANNELS = 2;
66 constexpr int32_t AVRECORDER_DEFAULT_AUDIO_SAMPLE_RATE = 48000;
67 constexpr int32_t AVRECORDER_DEFAULT_VIDEO_BIT_RATE = 48000;
68 constexpr int32_t AVRECORDER_DEFAULT_FRAME_HEIGHT = -1;
69 constexpr int32_t AVRECORDER_DEFAULT_FRAME_WIDTH = -1;
70 constexpr int32_t AVRECORDER_DEFAULT_FRAME_RATE = 30;
71 
72 const std::map<std::string, std::vector<std::string>> stateCtrlList = {
73     {AVRecorderState::STATE_IDLE, {
74         AVRecordergOpt::PREPARE,
75         AVRecordergOpt::RESET,
76         AVRecordergOpt::RELEASE,
77         AVRecordergOpt::GET_AV_RECORDER_PROFILE,
78         AVRecordergOpt::SET_AV_RECORDER_CONFIG,
79         AVRecordergOpt::GET_ENCODER_INFO
80     }},
81     {AVRecorderState::STATE_PREPARED, {
82         AVRecordergOpt::SET_ORIENTATION_HINT,
83         AVRecordergOpt::GETINPUTSURFACE,
84         AVRecordergOpt::GETINPUTMETASURFACE,
85         AVRecordergOpt::START,
86         AVRecordergOpt::RESET,
87         AVRecordergOpt::RELEASE,
88         AVRecordergOpt::GET_CURRENT_AUDIO_CAPTURER_INFO,
89         AVRecordergOpt::GET_MAX_AMPLITUDE,
90         AVRecordergOpt::GET_ENCODER_INFO,
91         AVRecordergOpt::GET_AV_RECORDER_CONFIG,
92         AVRecordergOpt::IS_WATERMARK_SUPPORTED,
93         AVRecordergOpt::SET_WATERMARK
94     }},
95     {AVRecorderState::STATE_STARTED, {
96         AVRecordergOpt::START,
97         AVRecordergOpt::RESUME,
98         AVRecordergOpt::PAUSE,
99         AVRecordergOpt::STOP,
100         AVRecordergOpt::RESET,
101         AVRecordergOpt::RELEASE,
102         AVRecordergOpt::GET_CURRENT_AUDIO_CAPTURER_INFO,
103         AVRecordergOpt::GET_MAX_AMPLITUDE,
104         AVRecordergOpt::GET_ENCODER_INFO,
105         AVRecordergOpt::GET_AV_RECORDER_CONFIG,
106         AVRecordergOpt::IS_WATERMARK_SUPPORTED
107     }},
108     {AVRecorderState::STATE_PAUSED, {
109         AVRecordergOpt::PAUSE,
110         AVRecordergOpt::RESUME,
111         AVRecordergOpt::STOP,
112         AVRecordergOpt::RESET,
113         AVRecordergOpt::RELEASE,
114         AVRecordergOpt::GET_CURRENT_AUDIO_CAPTURER_INFO,
115         AVRecordergOpt::GET_MAX_AMPLITUDE,
116         AVRecordergOpt::GET_ENCODER_INFO,
117         AVRecordergOpt::GET_AV_RECORDER_CONFIG,
118         AVRecordergOpt::IS_WATERMARK_SUPPORTED
119     }},
120     {AVRecorderState::STATE_STOPPED, {
121         AVRecordergOpt::STOP,
122         AVRecordergOpt::PREPARE,
123         AVRecordergOpt::RESET,
124         AVRecordergOpt::RELEASE,
125         AVRecordergOpt::GET_ENCODER_INFO,
126         AVRecordergOpt::GET_AV_RECORDER_CONFIG
127     }},
128     {AVRecorderState::STATE_RELEASED, {
129         AVRecordergOpt::RELEASE
130     }},
131     {AVRecorderState::STATE_ERROR, {
132         AVRecordergOpt::RESET,
133         AVRecordergOpt::RELEASE
134     }},
135 };
136 
137 /**
138  * on(type: 'stateChange', callback: (state: AVPlayerState, reason: StateChangeReason) => void): void
139  * on(type: 'error', callback: ErrorCallback): void
140  * on(type: 'audioCaptureChange', callback: Callback<AudioCaptureChangeInfo>): void
141  * on(type: 'photoAssetAvailable', callback: Callback<photoAccessHelper.PhotoAsset>): void
142  */
143 namespace AVRecorderEvent {
144 const std::string EVENT_STATE_CHANGE = "stateChange";
145 const std::string EVENT_ERROR = "error";
146 const std::string EVENT_AUDIO_CAPTURE_CHANGE = "audioCapturerChange";
147 const std::string EVENT_PHOTO_ASSET_AVAILABLE = "photoAssetAvailable";
148 }
149 
150 struct AVRecorderAsyncContext;
151 struct AVRecorderProfile {
152     int32_t audioBitrate = AVRECORDER_DEFAULT_AUDIO_BIT_RATE;
153     int32_t audioChannels = AVRECORDER_DEFAULT_AUDIO_CHANNELS;
154     int32_t auidoSampleRate = AVRECORDER_DEFAULT_AUDIO_SAMPLE_RATE;
155     AudioCodecFormat audioCodecFormat = AudioCodecFormat::AUDIO_DEFAULT;
156 
157     int32_t videoBitrate = AVRECORDER_DEFAULT_VIDEO_BIT_RATE;
158     int32_t videoFrameWidth = AVRECORDER_DEFAULT_FRAME_HEIGHT;
159     int32_t videoFrameHeight = AVRECORDER_DEFAULT_FRAME_WIDTH;
160     int32_t videoFrameRate = AVRECORDER_DEFAULT_FRAME_RATE;
161     bool isHdr = false;
162     bool enableTemporalScale = false;
163     VideoCodecFormat videoCodecFormat = VideoCodecFormat::VIDEO_DEFAULT;
164 
165     OutputFormatType fileFormat = OutputFormatType::FORMAT_DEFAULT;
166 };
167 
168 struct AVRecorderConfig {
169     AudioSourceType audioSourceType; // source type;
170     VideoSourceType videoSourceType;
171     std::vector<MetaSourceType> metaSourceTypeVec;
172     AVRecorderProfile profile;
173     std::string url;
174     int32_t rotation = 0; // Optional
175     Location location; // Optional
176     AVMetadata metadata; // Optional
177     FileGenerationMode fileGenerationMode = FileGenerationMode::APP_CREATE;
178     bool withVideo = false;
179     bool withAudio = false;
180     bool withLocation = false;
181 };
182 
183 struct WatermarkConfig {
184     int32_t top = -1; // offset of the watermark to the top line of pixel
185     int32_t left = -1; // offset of the watermark to the left line if pixel
186 };
187 
188 using RetInfo = std::pair<int32_t, std::string>;
189 
190 class AVRecorderNapi {
191 public:
192     __attribute__((visibility("default"))) static napi_value Init(napi_env env, napi_value exports);
193 
194     using AvRecorderTaskqFunc = RetInfo (AVRecorderNapi::*)();
195 
196 private:
197     static napi_value Constructor(napi_env env, napi_callback_info info);
198     static void Destructor(napi_env env, void *nativeObject, void *finalize);
199     /**
200      * createAVRecorder(callback: AsyncCallback<VideoPlayer>): void
201      * createAVRecorder(): Promise<VideoPlayer>
202      */
203     static napi_value JsCreateAVRecorder(napi_env env, napi_callback_info info);
204     /**
205      * prepare(config: AVRecorderConfig, callback: AsyncCallback<void>): void;
206      * prepare(config: AVRecorderConfig): Promise<void>;
207      */
208     static napi_value JsPrepare(napi_env env, napi_callback_info info);
209     /**
210      * setOrientationHint(config: AVRecorderConfig, callback: AsyncCallback<void>): void;
211      * setOrientationHint(config: AVRecorderConfig): Promise<void>;
212      */
213     static napi_value JsSetOrientationHint(napi_env env, napi_callback_info info);
214     /**
215      * setWatermark(watermark: image.PixelMap, config: WatermarkConfig): promise<void>;
216     */
217     static napi_value JsSetWatermark(napi_env env, napi_callback_info info);
218     /**
219      * getInputSurface(callback: AsyncCallback<string>): void
220      * getInputSurface(): Promise<string>
221      */
222     static napi_value JsGetInputSurface(napi_env env, napi_callback_info info);
223     /**
224      * getInputMetaSurface(callback: AsyncCallback<string>): void
225      * getInputMetaSurface(): Promise<string>
226      */
227     static napi_value JsGetInputMetaSurface(napi_env env, napi_callback_info info);
228     /**
229      * start(callback: AsyncCallback<void>): void;
230      * start(): Promise<void>;
231      */
232     static napi_value JsStart(napi_env env, napi_callback_info info);
233     /**
234      * pause(callback: AsyncCallback<void>): void;
235      * pause(): Promise<void>;
236      */
237     static napi_value JsPause(napi_env env, napi_callback_info info);
238     /**
239      * resume(callback: AsyncCallback<void>): void;
240      * resume(): Promise<void>;
241      */
242     static napi_value JsResume(napi_env env, napi_callback_info info);
243     /**
244      * stop(callback: AsyncCallback<void>): void;
245      * stop(): Promise<void>;
246      */
247     static napi_value JsStop(napi_env env, napi_callback_info info);
248     /**
249      * reset(callback: AsyncCallback<void>): void
250      * reset(): Promise<void>
251      */
252     static napi_value JsReset(napi_env env, napi_callback_info info);
253     /**
254      * release(callback: AsyncCallback<void>): void
255      * release(): Promise<void>
256      */
257     static napi_value JsRelease(napi_env env, napi_callback_info info);
258     /**
259      * on(type: 'stateChange', callback: (state: AVPlayerState, reason: StateChangeReason) => void): void
260      * on(type: 'error', callback: ErrorCallback): void
261      * on(type: 'audioCaptureChange', callback: Callback<AudioCaptureChangeInfo>): void
262      * on(type: 'photoAssetAvailable', callback: Callback<photoAccessHelper.PhotoAsset>): void
263      */
264     static napi_value JsSetEventCallback(napi_env env, napi_callback_info info);
265     /**
266      * off(type: 'stateChange'): void;
267      * off(type: 'error'): void;
268      * off(type: 'audioCaptureChange'): void
269      * off(type: 'photoAssetAvailable'): void
270      */
271     static napi_value JsCancelEventCallback(napi_env env, napi_callback_info info);
272     /**
273      * readonly state: AVRecorderState;
274      */
275     static napi_value JsGetState(napi_env env, napi_callback_info info);
276     /**
277      * getVideoRecorderProfile(sourceId: number, qualityLevel: VideoRecorderQualityLevel,
278      *     callback: AsyncCallback<AVRecorderProfile>);
279      * getVideoRecorderProfile(sourceId: number, qualityLevel: VideoRecorderQualityLevel): Promise<AVRecorderProfile>;
280     */
281     static napi_value JsGetAVRecorderProfile(napi_env env, napi_callback_info info);
282     /**
283      * setAVRecorderConfig(config: AVRecorderConfig, callback: AsyncCallback<void>): void;
284      * setAVRecorderConfig(config: AVRecorderConfig): Promise<void>;
285     */
286     static napi_value JsSetAVRecorderConfig(napi_env env, napi_callback_info info);
287     /**
288      * getAVRecorderConfig(callback: AsyncCallback<AVRecorderConfig>);
289      * getAVRecorderConfig(): Promise<AVRecorderConfig>;
290     */
291     static napi_value JsGetAVRecorderConfig(napi_env env, napi_callback_info info);
292     /**
293      * getCurrentAudioCapturerInfo(callback: AsyncCallback<audio.AudioCapturerChangeInfo>): void;
294      * getCurrentAudioCapturerInfo(): Promise<audio.AudioCapturerChangeInfo>;
295     */
296     static napi_value JsGetCurrentAudioCapturerInfo(napi_env env, napi_callback_info info);
297     /**
298      * getAudioCapturerMaxAmplitude(callback: AsyncCallback<number>): void;
299      * getAudioCapturerMaxAmplitude(): Promise<number>;
300     */
301     static napi_value JsGetAudioCapturerMaxAmplitude(napi_env env,  napi_callback_info info);
302     /**
303      * getAvailableEncoder(callback: AsyncCallback<Array<EncoderInfo>>): void;
304      * getAvailableEncoder(): Promise<Array<EncoderInfo>>;
305     */
306     static napi_value JsGetAvailableEncoder(napi_env env,  napi_callback_info info);
307     /**
308      * isWatermarkSupported(): promise<boolean>;
309     */
310     static napi_value JsIsWatermarkSupported(napi_env env, napi_callback_info info);
311 
312     static AVRecorderNapi* GetJsInstanceAndArgs(napi_env env, napi_callback_info info,
313         size_t &argCount, napi_value *args);
314     static std::shared_ptr<TaskHandler<RetInfo>> GetPrepareTask(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx);
315     static std::shared_ptr<TaskHandler<RetInfo>> GetSetOrientationHintTask(
316         const std::unique_ptr<AVRecorderAsyncContext> &asyncCtx);
317     static std::shared_ptr<TaskHandler<RetInfo>> GetInputMetaSurface(
318         const std::unique_ptr<AVRecorderAsyncContext> &asyncCtx);
319     static std::shared_ptr<TaskHandler<RetInfo>> GetPromiseTask(AVRecorderNapi *avnapi, const std::string &opt);
320     static std::shared_ptr<TaskHandler<RetInfo>> GetAVRecorderProfileTask(
321         const std::unique_ptr<AVRecorderAsyncContext> &asyncCtx);
322     static std::shared_ptr<TaskHandler<RetInfo>> SetAVRecorderConfigTask(
323         std::unique_ptr<AVRecorderAsyncContext> &asyncCtx);
324     static napi_value ExecuteByPromise(napi_env env, napi_callback_info info, const std::string &opt);
325     static std::shared_ptr<TaskHandler<RetInfo>> GetAVRecorderConfigTask(
326         const std::unique_ptr<AVRecorderAsyncContext> &asyncCtx);
327     static std::shared_ptr<TaskHandler<RetInfo>> GetCurrentCapturerChangeInfoTask(
328         const std::unique_ptr<AVRecorderAsyncContext> &asyncCtx);
329     static std::shared_ptr<TaskHandler<RetInfo>> GetMaxAmplitudeTask(
330         const std::unique_ptr<AVRecorderAsyncContext> &asyncCtx);
331     static std::shared_ptr<TaskHandler<RetInfo>> GetEncoderInfoTask(
332         const std::unique_ptr<AVRecorderAsyncContext> &asyncCtx);
333     static std::shared_ptr<TaskHandler<RetInfo>> IsWatermarkSupportedTask(
334         const std::unique_ptr<AVRecorderAsyncContext> &asyncCtx);
335     static std::shared_ptr<TaskHandler<RetInfo>> SetWatermarkTask(
336         const std::unique_ptr<AVRecorderAsyncContext> &asyncCtx);
337     static int32_t GetAudioCodecFormat(const std::string &mime, AudioCodecFormat &codecFormat);
338     static int32_t GetVideoCodecFormat(const std::string &mime, VideoCodecFormat &codecFormat);
339     static int32_t GetOutputFormat(const std::string &extension, OutputFormatType &type);
340 
341     static int32_t GetPropertyInt32(napi_env env, napi_value configObj, const std::string &type, int32_t &result,
342         bool &getValue);
343     static int32_t GetPropertyInt32Vec(napi_env env, napi_value configObj, const std::string &type,
344     std::vector<int32_t> &result, bool &getValue);
345 
346     static int32_t GetAVRecorderProfile(std::shared_ptr<AVRecorderProfile> &profile,
347         const int32_t sourceId, const int32_t qualityLevel);
348     static void MediaProfileLog(bool isVideo, AVRecorderProfile &profile);
349 
350     AVRecorderNapi();
351     ~AVRecorderNapi();
352 
353     RetInfo GetInputSurface();
354     RetInfo Start();
355     RetInfo Pause();
356     RetInfo Resume();
357     RetInfo Stop();
358     RetInfo Reset();
359     RetInfo Release();
360     RetInfo GetVideoRecorderProfile();
361 
362     int32_t GetAVRecorderConfig(std::shared_ptr<AVRecorderConfig> &config);
363     int32_t GetCurrentCapturerChangeInfo(AudioRecorderChangeInfo &changeInfo);
364     int32_t GetMaxAmplitude(int32_t &maxAmplitude);
365     int32_t GetEncoderInfo(std::vector<EncoderCapabilityData> &encoderInfo);
366     int32_t IsWatermarkSupported(bool &isWatermarkSupported);
367     int32_t SetWatermark(std::shared_ptr<PixelMap> &pixelMap, std::shared_ptr<WatermarkConfig> &watermarkConfig);
368 
369     void ErrorCallback(int32_t errCode, const std::string &operate, const std::string &add = "");
370     void StateCallback(const std::string &state);
371     void SetCallbackReference(const std::string &callbackName, std::shared_ptr<AutoRef> ref);
372     void CancelCallbackReference(const std::string &callbackName);
373     void CancelCallback();
374     void RemoveSurface();
375 
376     int32_t CheckStateMachine(const std::string &opt);
377     int32_t CheckRepeatOperation(const std::string &opt);
378     int32_t GetSourceType(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env, napi_value args);
379     int32_t GetAudioProfile(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env, napi_value item,
380         AVRecorderProfile &profile);
381     int32_t GetVideoProfile(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env, napi_value item,
382         AVRecorderProfile &profile);
383     int32_t GetProfile(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env, napi_value args);
384     int32_t GetModeAndUrl(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env, napi_value args);
385     int32_t GetConfig(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env, napi_value args);
386     int32_t GetRotation(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env, napi_value args);
387     int32_t GetMetaType(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env, napi_value args);
388     int32_t GetAVMetaData(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env, napi_value args);
389     int32_t GetWatermarkParameter(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env,
390         napi_value watermark, napi_value watermarkConfig);
391     int32_t GetWatermark(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env, napi_value args);
392     int32_t GetWatermarkConfig(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env, napi_value args);
393 
394     bool GetLocation(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env, napi_value args);
395     int32_t GetSourceIdAndQuality(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env,
396         napi_value sourceIdArgs, napi_value qualityArgs, const std::string &opt);
397     RetInfo SetProfile(std::shared_ptr<AVRecorderConfig> config);
398     RetInfo Configure(std::shared_ptr<AVRecorderConfig> config);
399     RetInfo ConfigureUrl(std::shared_ptr<AVRecorderConfig> config);
400     int32_t ConfigAVBufferMeta(std::shared_ptr<PixelMap> &pixelMap, std::shared_ptr<WatermarkConfig> &watermarkConfig,
401         std::shared_ptr<Meta> &meta);
402 
403     static thread_local napi_ref constructor_;
404     napi_env env_ = nullptr;
405     std::shared_ptr<Recorder> recorder_ = nullptr;
406     std::shared_ptr<RecorderCallback> recorderCb_ = nullptr;
407     std::map<std::string, std::shared_ptr<AutoRef>> eventCbMap_;
408     std::unique_ptr<TaskQueue> taskQue_;
409     static std::map<std::string, AvRecorderTaskqFunc> taskQFuncs_;
410     std::map<MetaSourceType, int32_t> metaSourceIDMap_;
411     sptr<Surface> surface_ = nullptr;
412     sptr<Surface> metaSurface_ = nullptr;
413     int32_t videoSourceID_ = -1;
414     int32_t audioSourceID_ = -1;
415     int32_t metaSourceID_ = -1;
416     bool withVideo_ = false;
417     bool getVideoInputSurface_ = false;
418     bool getMetaInputSurface_ = false;
419     int32_t sourceId_ = -1;
420     int32_t qualityLevel_ = -1;
421     bool hasConfiged_ = false;
422     int32_t videoFrameWidth_ = -1; // Required for watermarking. Synchronize the modification if any.
423     int32_t videoFrameHeight_ = -1; // Required for watermarking. Synchronize the modification if any.
424     int32_t rotation_ = 0; // Required for watermarking. Synchronize the modification if any.
425 };
426 
427 struct AVRecorderAsyncContext : public MediaAsyncContext {
AVRecorderAsyncContextAVRecorderAsyncContext428     explicit AVRecorderAsyncContext(napi_env env) : MediaAsyncContext(env) {}
429     ~AVRecorderAsyncContext() = default;
430 
431     void AVRecorderSignError(int32_t errCode, const std::string &operate,
432         const std::string &param, const std::string &add = "");
433 
434     AVRecorderNapi *napi = nullptr;
435     std::shared_ptr<AVRecorderConfig> config_ = nullptr;
436     std::string opt_ = "";
437     std::shared_ptr<TaskHandler<RetInfo>> task_ = nullptr;
438     std::shared_ptr<AVRecorderProfile> profile_ = nullptr;
439     AudioRecorderChangeInfo changeInfo_;
440     int32_t maxAmplitude_ = 0;
441     std::vector<EncoderCapabilityData> encoderInfo_;
442     MetaSourceType metaType_ = MetaSourceType::VIDEO_META_SOURCE_INVALID;
443     std::shared_ptr<PixelMap> pixelMap_ = nullptr;
444     std::shared_ptr<WatermarkConfig> watermarkConfig_ = nullptr;
445     bool isWatermarkSupported_ = false;
446 };
447 
448 class MediaJsResultExtensionMethod {
449 public:
450     static int32_t SetAudioCodecFormat(AudioCodecFormat &codecFormat, std::string &mime);
451     static int32_t SetVideoCodecFormat(VideoCodecFormat &codecFormat, std::string &mime);
452     static int32_t SetFileFormat(OutputFormatType &type, std::string &extension);
453 };
454 class MediaJsAVRecorderProfile : public MediaJsResult {
455 public:
MediaJsAVRecorderProfile(std::shared_ptr<AVRecorderProfile> value)456     explicit MediaJsAVRecorderProfile(std::shared_ptr<AVRecorderProfile> value)
457         : value_(value)
458     {
459     }
460     ~MediaJsAVRecorderProfile() = default;
461     napi_status GetJsResult(napi_env env, napi_value &result) override;
462 
463 private:
464     std::shared_ptr<AVRecorderProfile> value_ = nullptr;
465 };
466 class MediaJsAVRecorderConfig : public MediaJsResult {
467 public:
MediaJsAVRecorderConfig(std::shared_ptr<AVRecorderConfig> value)468     explicit MediaJsAVRecorderConfig(std::shared_ptr<AVRecorderConfig> value)
469         : value_(value)
470     {
471     }
472     ~MediaJsAVRecorderConfig() = default;
473     napi_status GetJsResult(napi_env env, napi_value &result) override;
474     napi_status audioToSet(napi_env env, napi_value &profile, napi_value &result);
475     napi_status videoToSet(napi_env env, napi_value &profile, napi_value &result);
476     napi_status locationToSet(napi_env env, napi_value &location, napi_value &result);
477 
478 private:
479     std::shared_ptr<AVRecorderConfig> value_ = nullptr;
480 };
481 class MediaJsEncoderInfo : public MediaJsResult {
482 public:
MediaJsEncoderInfo(const std::vector<EncoderCapabilityData> encoderInfo)483     explicit MediaJsEncoderInfo(const std::vector<EncoderCapabilityData> encoderInfo)
484         : encoderInfo_(encoderInfo)
485     {
486     }
487     ~MediaJsEncoderInfo() = default;
488     napi_status GetJsResult(napi_env env, napi_value &result) override;
489     napi_status GetAudioEncoderInfo(
490         napi_env env, EncoderCapabilityData encoderCapData, napi_value &result, uint32_t position);
491     napi_status GetVideoEncoderInfo(
492         napi_env env, EncoderCapabilityData encoderCapData, napi_value &result, uint32_t position);
493 private:
494     std::vector<EncoderCapabilityData> encoderInfo_;
495 };
496 } // namespace Media
497 } // namespace OHOS
498 #endif // AV_RECORDER_NAPI_H