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 audioSampleRate = 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 bool enableStableQualityMode = false; 164 VideoCodecFormat videoCodecFormat = VideoCodecFormat::VIDEO_DEFAULT; 165 166 OutputFormatType fileFormat = OutputFormatType::FORMAT_DEFAULT; 167 }; 168 169 struct AVRecorderConfig { 170 AudioSourceType audioSourceType; // source type; 171 VideoSourceType videoSourceType; 172 std::vector<MetaSourceType> metaSourceTypeVec; 173 AVRecorderProfile profile; 174 std::string url; 175 int32_t rotation = 0; // Optional 176 int32_t maxDuration = INT32_MAX; // Optional 177 Location location; // Optional 178 AVMetadata metadata; // Optional 179 FileGenerationMode fileGenerationMode = FileGenerationMode::APP_CREATE; 180 bool withVideo = false; 181 bool withAudio = false; 182 bool withLocation = false; 183 }; 184 185 struct WatermarkConfig { 186 int32_t top = -1; // offset of the watermark to the top line of pixel 187 int32_t left = -1; // offset of the watermark to the left line if pixel 188 }; 189 190 using RetInfo = std::pair<int32_t, std::string>; 191 192 class AVRecorderNapi { 193 public: 194 __attribute__((visibility("default"))) static napi_value Init(napi_env env, napi_value exports); 195 196 using AvRecorderTaskqFunc = RetInfo (AVRecorderNapi::*)(); 197 198 private: 199 static napi_value Constructor(napi_env env, napi_callback_info info); 200 static void Destructor(napi_env env, void *nativeObject, void *finalize); 201 /** 202 * createAVRecorder(callback: AsyncCallback<VideoPlayer>): void 203 * createAVRecorder(): Promise<VideoPlayer> 204 */ 205 static napi_value JsCreateAVRecorder(napi_env env, napi_callback_info info); 206 /** 207 * prepare(config: AVRecorderConfig, callback: AsyncCallback<void>): void; 208 * prepare(config: AVRecorderConfig): Promise<void>; 209 */ 210 static napi_value JsPrepare(napi_env env, napi_callback_info info); 211 /** 212 * setOrientationHint(config: AVRecorderConfig, callback: AsyncCallback<void>): void; 213 * setOrientationHint(config: AVRecorderConfig): Promise<void>; 214 */ 215 static napi_value JsSetOrientationHint(napi_env env, napi_callback_info info); 216 /** 217 * setWatermark(watermark: image.PixelMap, config: WatermarkConfig): promise<void>; 218 */ 219 static napi_value JsSetWatermark(napi_env env, napi_callback_info info); 220 /** 221 * getInputSurface(callback: AsyncCallback<string>): void 222 * getInputSurface(): Promise<string> 223 */ 224 static napi_value JsGetInputSurface(napi_env env, napi_callback_info info); 225 /** 226 * getInputMetaSurface(callback: AsyncCallback<string>): void 227 * getInputMetaSurface(): Promise<string> 228 */ 229 static napi_value JsGetInputMetaSurface(napi_env env, napi_callback_info info); 230 /** 231 * start(callback: AsyncCallback<void>): void; 232 * start(): Promise<void>; 233 */ 234 static napi_value JsStart(napi_env env, napi_callback_info info); 235 /** 236 * pause(callback: AsyncCallback<void>): void; 237 * pause(): Promise<void>; 238 */ 239 static napi_value JsPause(napi_env env, napi_callback_info info); 240 /** 241 * resume(callback: AsyncCallback<void>): void; 242 * resume(): Promise<void>; 243 */ 244 static napi_value JsResume(napi_env env, napi_callback_info info); 245 /** 246 * stop(callback: AsyncCallback<void>): void; 247 * stop(): Promise<void>; 248 */ 249 static napi_value JsStop(napi_env env, napi_callback_info info); 250 /** 251 * reset(callback: AsyncCallback<void>): void 252 * reset(): Promise<void> 253 */ 254 static napi_value JsReset(napi_env env, napi_callback_info info); 255 /** 256 * release(callback: AsyncCallback<void>): void 257 * release(): Promise<void> 258 */ 259 static napi_value JsRelease(napi_env env, napi_callback_info info); 260 /** 261 * on(type: 'stateChange', callback: (state: AVPlayerState, reason: StateChangeReason) => void): void 262 * on(type: 'error', callback: ErrorCallback): void 263 * on(type: 'audioCaptureChange', callback: Callback<AudioCaptureChangeInfo>): void 264 * on(type: 'photoAssetAvailable', callback: Callback<photoAccessHelper.PhotoAsset>): void 265 */ 266 static napi_value JsSetEventCallback(napi_env env, napi_callback_info info); 267 /** 268 * off(type: 'stateChange'): void; 269 * off(type: 'error'): void; 270 * off(type: 'audioCaptureChange'): void 271 * off(type: 'photoAssetAvailable'): void 272 */ 273 static napi_value JsCancelEventCallback(napi_env env, napi_callback_info info); 274 /** 275 * readonly state: AVRecorderState; 276 */ 277 static napi_value JsGetState(napi_env env, napi_callback_info info); 278 /** 279 * getVideoRecorderProfile(sourceId: number, qualityLevel: VideoRecorderQualityLevel, 280 * callback: AsyncCallback<AVRecorderProfile>); 281 * getVideoRecorderProfile(sourceId: number, qualityLevel: VideoRecorderQualityLevel): Promise<AVRecorderProfile>; 282 */ 283 static napi_value JsGetAVRecorderProfile(napi_env env, napi_callback_info info); 284 /** 285 * setAVRecorderConfig(config: AVRecorderConfig, callback: AsyncCallback<void>): void; 286 * setAVRecorderConfig(config: AVRecorderConfig): Promise<void>; 287 */ 288 static napi_value JsSetAVRecorderConfig(napi_env env, napi_callback_info info); 289 /** 290 * getAVRecorderConfig(callback: AsyncCallback<AVRecorderConfig>); 291 * getAVRecorderConfig(): Promise<AVRecorderConfig>; 292 */ 293 static napi_value JsGetAVRecorderConfig(napi_env env, napi_callback_info info); 294 /** 295 * getCurrentAudioCapturerInfo(callback: AsyncCallback<audio.AudioCapturerChangeInfo>): void; 296 * getCurrentAudioCapturerInfo(): Promise<audio.AudioCapturerChangeInfo>; 297 */ 298 static napi_value JsGetCurrentAudioCapturerInfo(napi_env env, napi_callback_info info); 299 /** 300 * getAudioCapturerMaxAmplitude(callback: AsyncCallback<number>): void; 301 * getAudioCapturerMaxAmplitude(): Promise<number>; 302 */ 303 static napi_value JsGetAudioCapturerMaxAmplitude(napi_env env, napi_callback_info info); 304 /** 305 * getAvailableEncoder(callback: AsyncCallback<Array<EncoderInfo>>): void; 306 * getAvailableEncoder(): Promise<Array<EncoderInfo>>; 307 */ 308 static napi_value JsGetAvailableEncoder(napi_env env, napi_callback_info info); 309 /** 310 * isWatermarkSupported(): promise<boolean>; 311 */ 312 static napi_value JsIsWatermarkSupported(napi_env env, napi_callback_info info); 313 314 static AVRecorderNapi* GetJsInstanceAndArgs(napi_env env, napi_callback_info info, 315 size_t &argCount, napi_value *args); 316 static std::shared_ptr<TaskHandler<RetInfo>> GetPrepareTask(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx); 317 static std::shared_ptr<TaskHandler<RetInfo>> GetSetOrientationHintTask( 318 const std::unique_ptr<AVRecorderAsyncContext> &asyncCtx); 319 static std::shared_ptr<TaskHandler<RetInfo>> GetInputMetaSurface( 320 const std::unique_ptr<AVRecorderAsyncContext> &asyncCtx); 321 static std::shared_ptr<TaskHandler<RetInfo>> GetPromiseTask(AVRecorderNapi *avnapi, const std::string &opt); 322 static std::shared_ptr<TaskHandler<RetInfo>> GetAVRecorderProfileTask( 323 const std::unique_ptr<AVRecorderAsyncContext> &asyncCtx); 324 static std::shared_ptr<TaskHandler<RetInfo>> SetAVRecorderConfigTask( 325 std::unique_ptr<AVRecorderAsyncContext> &asyncCtx); 326 static napi_value ExecuteByPromise(napi_env env, napi_callback_info info, const std::string &opt); 327 static std::shared_ptr<TaskHandler<RetInfo>> GetAVRecorderConfigTask( 328 const std::unique_ptr<AVRecorderAsyncContext> &asyncCtx); 329 static std::shared_ptr<TaskHandler<RetInfo>> GetCurrentCapturerChangeInfoTask( 330 const std::unique_ptr<AVRecorderAsyncContext> &asyncCtx); 331 static std::shared_ptr<TaskHandler<RetInfo>> GetMaxAmplitudeTask( 332 const std::unique_ptr<AVRecorderAsyncContext> &asyncCtx); 333 static std::shared_ptr<TaskHandler<RetInfo>> GetEncoderInfoTask( 334 const std::unique_ptr<AVRecorderAsyncContext> &asyncCtx); 335 static std::shared_ptr<TaskHandler<RetInfo>> IsWatermarkSupportedTask( 336 const std::unique_ptr<AVRecorderAsyncContext> &asyncCtx); 337 static std::shared_ptr<TaskHandler<RetInfo>> SetWatermarkTask( 338 const std::unique_ptr<AVRecorderAsyncContext> &asyncCtx); 339 static int32_t GetAudioCodecFormat(const std::string &mime, AudioCodecFormat &codecFormat); 340 static int32_t GetVideoCodecFormat(const std::string &mime, VideoCodecFormat &codecFormat); 341 static int32_t GetOutputFormat(const std::string &extension, OutputFormatType &type); 342 343 static int32_t GetPropertyInt32(napi_env env, napi_value configObj, const std::string &type, int32_t &result, 344 bool &getValue); 345 static int32_t GetPropertyInt32Vec(napi_env env, napi_value configObj, const std::string &type, 346 std::vector<int32_t> &result, bool &getValue); 347 348 static int32_t GetAVRecorderProfile(std::shared_ptr<AVRecorderProfile> &profile, 349 const int32_t sourceId, const int32_t qualityLevel); 350 static void MediaProfileLog(bool isVideo, AVRecorderProfile &profile); 351 352 AVRecorderNapi(); 353 ~AVRecorderNapi(); 354 355 RetInfo GetInputSurface(); 356 RetInfo Start(); 357 RetInfo Pause(); 358 RetInfo Resume(); 359 RetInfo Stop(); 360 RetInfo Reset(); 361 RetInfo Release(); 362 RetInfo GetVideoRecorderProfile(); 363 364 int32_t GetAVRecorderConfig(std::shared_ptr<AVRecorderConfig> &config); 365 int32_t GetCurrentCapturerChangeInfo(AudioRecorderChangeInfo &changeInfo); 366 int32_t GetMaxAmplitude(int32_t &maxAmplitude); 367 int32_t GetEncoderInfo(std::vector<EncoderCapabilityData> &encoderInfo); 368 int32_t IsWatermarkSupported(bool &isWatermarkSupported); 369 int32_t SetWatermark(std::shared_ptr<PixelMap> &pixelMap, std::shared_ptr<WatermarkConfig> &watermarkConfig); 370 371 void ErrorCallback(int32_t errCode, const std::string &operate, const std::string &add = ""); 372 void StateCallback(const std::string &state); 373 void SetCallbackReference(const std::string &callbackName, std::shared_ptr<AutoRef> ref); 374 void CancelCallbackReference(const std::string &callbackName); 375 void CancelCallback(); 376 void RemoveSurface(); 377 378 int32_t CheckStateMachine(const std::string &opt); 379 int32_t CheckRepeatOperation(const std::string &opt); 380 int32_t GetSourceType(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env, napi_value args); 381 int32_t GetAudioProfile(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env, napi_value item, 382 AVRecorderProfile &profile); 383 int32_t GetVideoProfile(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env, napi_value item, 384 AVRecorderProfile &profile); 385 int32_t GetProfile(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env, napi_value args); 386 int32_t GetModeAndUrl(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env, napi_value args); 387 int32_t GetConfig(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env, napi_value args); 388 int32_t GetRotation(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env, napi_value args); 389 int32_t GetMetaType(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env, napi_value args); 390 int32_t GetAVMetaData(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env, napi_value args); 391 int32_t GetWatermarkParameter(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env, 392 napi_value watermark, napi_value watermarkConfig); 393 int32_t GetWatermark(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env, napi_value args); 394 int32_t GetWatermarkConfig(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env, napi_value args); 395 396 bool GetLocation(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env, napi_value args); 397 int32_t GetSourceIdAndQuality(std::unique_ptr<AVRecorderAsyncContext> &asyncCtx, napi_env env, 398 napi_value sourceIdArgs, napi_value qualityArgs, const std::string &opt); 399 RetInfo SetProfile(std::shared_ptr<AVRecorderConfig> config); 400 RetInfo Configure(std::shared_ptr<AVRecorderConfig> config); 401 RetInfo ConfigureUrl(std::shared_ptr<AVRecorderConfig> config); 402 int32_t ConfigAVBufferMeta(std::shared_ptr<PixelMap> &pixelMap, std::shared_ptr<WatermarkConfig> &watermarkConfig, 403 std::shared_ptr<Meta> &meta); 404 405 static thread_local napi_ref constructor_; 406 napi_env env_ = nullptr; 407 std::shared_ptr<Recorder> recorder_ = nullptr; 408 std::shared_ptr<RecorderCallback> recorderCb_ = nullptr; 409 std::map<std::string, std::shared_ptr<AutoRef>> eventCbMap_; 410 std::unique_ptr<TaskQueue> taskQue_; 411 static std::map<std::string, AvRecorderTaskqFunc> taskQFuncs_; 412 std::map<MetaSourceType, int32_t> metaSourceIDMap_; 413 sptr<Surface> surface_ = nullptr; 414 sptr<Surface> metaSurface_ = nullptr; 415 int32_t videoSourceID_ = -1; 416 int32_t audioSourceID_ = -1; 417 int32_t metaSourceID_ = -1; 418 bool withVideo_ = false; 419 bool getVideoInputSurface_ = false; 420 bool getMetaInputSurface_ = false; 421 int32_t sourceId_ = -1; 422 int32_t qualityLevel_ = -1; 423 bool hasConfiged_ = false; 424 int32_t videoFrameWidth_ = -1; // Required for watermarking. Synchronize the modification if any. 425 int32_t videoFrameHeight_ = -1; // Required for watermarking. Synchronize the modification if any. 426 int32_t rotation_ = 0; // Required for watermarking. Synchronize the modification if any. 427 }; 428 429 struct AVRecorderAsyncContext : public MediaAsyncContext { AVRecorderAsyncContextAVRecorderAsyncContext430 explicit AVRecorderAsyncContext(napi_env env) : MediaAsyncContext(env) {} 431 ~AVRecorderAsyncContext() = default; 432 433 void AVRecorderSignError(int32_t errCode, const std::string &operate, 434 const std::string ¶m, const std::string &add = ""); 435 436 AVRecorderNapi *napi = nullptr; 437 std::shared_ptr<AVRecorderConfig> config_ = nullptr; 438 std::string opt_ = ""; 439 std::shared_ptr<TaskHandler<RetInfo>> task_ = nullptr; 440 std::shared_ptr<AVRecorderProfile> profile_ = nullptr; 441 AudioRecorderChangeInfo changeInfo_; 442 int32_t maxAmplitude_ = 0; 443 std::vector<EncoderCapabilityData> encoderInfo_; 444 MetaSourceType metaType_ = MetaSourceType::VIDEO_META_SOURCE_INVALID; 445 std::shared_ptr<PixelMap> pixelMap_ = nullptr; 446 std::shared_ptr<WatermarkConfig> watermarkConfig_ = nullptr; 447 bool isWatermarkSupported_ = false; 448 }; 449 450 class MediaJsResultExtensionMethod { 451 public: 452 static int32_t SetAudioCodecFormat(AudioCodecFormat &codecFormat, std::string &mime); 453 static int32_t SetVideoCodecFormat(VideoCodecFormat &codecFormat, std::string &mime); 454 static int32_t SetFileFormat(OutputFormatType &type, std::string &extension); 455 }; 456 class MediaJsAVRecorderProfile : public MediaJsResult { 457 public: MediaJsAVRecorderProfile(std::shared_ptr<AVRecorderProfile> value)458 explicit MediaJsAVRecorderProfile(std::shared_ptr<AVRecorderProfile> value) 459 : value_(value) 460 { 461 } 462 ~MediaJsAVRecorderProfile() = default; 463 napi_status GetJsResult(napi_env env, napi_value &result) override; 464 465 private: 466 std::shared_ptr<AVRecorderProfile> value_ = nullptr; 467 }; 468 class MediaJsAVRecorderConfig : public MediaJsResult { 469 public: MediaJsAVRecorderConfig(std::shared_ptr<AVRecorderConfig> value)470 explicit MediaJsAVRecorderConfig(std::shared_ptr<AVRecorderConfig> value) 471 : value_(value) 472 { 473 } 474 ~MediaJsAVRecorderConfig() = default; 475 napi_status GetJsResult(napi_env env, napi_value &result) override; 476 napi_status audioToSet(napi_env env, napi_value &profile, napi_value &result); 477 napi_status videoToSet(napi_env env, napi_value &profile, napi_value &result); 478 napi_status locationToSet(napi_env env, napi_value &location, napi_value &result); 479 480 private: 481 std::shared_ptr<AVRecorderConfig> value_ = nullptr; 482 }; 483 class MediaJsEncoderInfo : public MediaJsResult { 484 public: MediaJsEncoderInfo(const std::vector<EncoderCapabilityData> encoderInfo)485 explicit MediaJsEncoderInfo(const std::vector<EncoderCapabilityData> encoderInfo) 486 : encoderInfo_(encoderInfo) 487 { 488 } 489 ~MediaJsEncoderInfo() = default; 490 napi_status GetJsResult(napi_env env, napi_value &result) override; 491 napi_status GetAudioEncoderInfo( 492 napi_env env, EncoderCapabilityData encoderCapData, napi_value &result, uint32_t position); 493 napi_status GetVideoEncoderInfo( 494 napi_env env, EncoderCapabilityData encoderCapData, napi_value &result, uint32_t position); 495 private: 496 std::vector<EncoderCapabilityData> encoderInfo_; 497 }; 498 } // namespace Media 499 } // namespace OHOS 500 #endif // AV_RECORDER_NAPI_H