1 /* 2 * Copyright (C) 2021 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 RECORDER_H 17 #define RECORDER_H 18 19 #include <cstdint> 20 #include <string> 21 #include <map> 22 #include <set> 23 #include <parcel.h> 24 #include "meta/format.h" 25 #include "meta/meta.h" 26 #include "buffer/avbuffer.h" 27 #include "surface.h" 28 #include "av_common.h" 29 #include "codec_capability.h" 30 #include "media_core.h" 31 32 namespace OHOS { 33 namespace Media { 34 using ConfigMap = std::map<std::string, int32_t>; 35 constexpr size_t DEVICE_INFO_SIZE_LIMIT = 30; // 30 from audioCapture 36 37 enum FileGenerationMode : int32_t { 38 APP_CREATE = 0, 39 AUTO_CREATE_CAMERA_SCENE = 1, 40 }; 41 42 /** 43 * @brief Enumerates video source types. 44 * 45 * @since 1.0 46 * @version 1.0 47 */ 48 enum VideoSourceType : int32_t { 49 /** Unsupported App Usage. */ 50 /** YUV video data provided through {@link Surface} */ 51 VIDEO_SOURCE_SURFACE_YUV = 0, 52 /** Raw encoded data provided through {@link Surface} */ 53 VIDEO_SOURCE_SURFACE_ES, 54 /** RGBA video data provided through {@link Surface} */ 55 VIDEO_SOURCE_SURFACE_RGBA, 56 /** Invalid value */ 57 VIDEO_SOURCE_BUTT 58 }; 59 60 /** 61 * @brief Enumerates meta source types. 62 * 63 * @since 4.2 64 * @version 4.2 65 */ 66 enum MetaSourceType : int32_t { 67 /** Invalid metadata source */ 68 VIDEO_META_SOURCE_INVALID = -1, 69 /** Video Maker info */ 70 VIDEO_META_MAKER_INFO, 71 /** max enum */ 72 VIDEO_META_SOURCE_BUTT 73 }; 74 75 /** 76 * @brief Enumerates audio source types. 77 * 78 * @since 1.0 79 * @version 1.0 80 */ 81 enum AudioSourceType : int32_t { 82 /** Invalid audio source */ 83 AUDIO_SOURCE_INVALID = -1, 84 /** Default audio source */ 85 AUDIO_SOURCE_DEFAULT = 0, 86 /** Microphone */ 87 AUDIO_MIC = 1, 88 /** Voice recognition */ 89 AUDIO_SOURCE_VOICE_RECOGNITION = 2, 90 /** Voice call */ 91 AUDIO_SOURCE_VOICE_CALL = 4, 92 /** Voice communication */ 93 AUDIO_SOURCE_VOICE_COMMUNICATION = 7, 94 /** Voice message */ 95 AUDIO_SOURCE_VOICE_MESSAGE = 10, 96 /** Camcorder */ 97 AUDIO_SOURCE_CAMCORDER = 13, 98 /** Inner audio */ 99 AUDIO_INNER = 20, 100 }; 101 102 /** 103 * Unsupported app usage. 104 * @brief Enumerates data source types. 105 * 106 * @since 1.0 107 * @version 1.0 108 */ 109 enum DataSourceType : int32_t { 110 /** meta data source */ 111 METADATA = 0 112 }; 113 114 /** 115 * @brief Enumerates output format types. 116 * 117 * @since 3.1 118 * @version 3.1 119 */ 120 enum OutputFormatType : int32_t { 121 /** Default format */ 122 FORMAT_DEFAULT = 0, 123 /** MPEG4 format */ 124 FORMAT_MPEG_4 = 2, 125 /** M4A format */ 126 FORMAT_M4A = 6, 127 /** AMR format */ 128 FORMAT_AMR = 8, 129 /** mp3 format */ 130 FORMAT_MP3 = 9, 131 /** WAV format */ 132 FORMAT_WAV = 10, 133 /** BUTT */ 134 FORMAT_BUTT, 135 }; 136 137 /** 138 * @brief Enumerates video codec formats. 139 * 140 * @since 3.1 141 * @version 3.1 142 */ 143 enum VideoCodecFormat : int32_t { 144 /** Default format */ 145 VIDEO_DEFAULT = 0, 146 /** H.264 */ 147 H264 = 2, 148 /** MPEG4 */ 149 MPEG4 = 6, 150 /** H.265 */ 151 H265 = 8, 152 VIDEO_CODEC_FORMAT_BUTT, 153 }; 154 155 /** 156 * @brief Enumerates audio codec formats. 157 * 158 * @since 3.1 159 * @version 3.1 160 */ 161 enum AudioCodecFormat : int32_t { 162 /** Default format */ 163 AUDIO_DEFAULT = 0, 164 /** Advanced Audio Coding Low Complexity (AAC-LC) */ 165 AAC_LC = 3, 166 /** mp3 format */ 167 AUDIO_MPEG = 4, 168 /** G711-mulaw format */ 169 AUDIO_G711MU = 5, 170 /** AUDIO_AMR_NB format */ 171 AUDIO_AMR_NB = 9, 172 /** AUDIO_AMR_WB format */ 173 AUDIO_AMR_WB = 10, 174 /** Invalid value */ 175 AUDIO_CODEC_FORMAT_BUTT, 176 }; 177 178 /** 179 * Unsupported App Usage. 180 * @brief Enumerates file split types. 181 * 182 * @since 1.0 183 * @version 1.0 184 */ 185 enum FileSplitType : int32_t { 186 /** Delayed/Backward split */ 187 FILE_SPLIT_POST = 0, 188 /** Advanced/Forward split */ 189 FILE_SPLIT_PRE, 190 /** Normal split */ 191 FILE_SPLIT_NORMAL, 192 /** Invalid value */ 193 FILE_SPLIT_BUTT, 194 }; 195 196 /** 197 * @brief Enumerates recording information types. 198 * 199 * @since 1.0 200 * @version 1.0 201 */ 202 enum RecorderInfoType : int32_t { 203 /** 204 * The recording duration is reaching the threshold specified by {@link SetMaxDuration}. This type of 205 * information is reported when only one second or 10% is left to reach the allowed duration. 206 */ 207 RECORDER_INFO_MAX_DURATION_APPROACHING = 0, 208 /** 209 * The recorded file size is reaching the threshold specified by {@link SetMaxFileSize}. This type of 210 * information is reported when only 100 KB or 10% is left to reach the allowed size. 211 */ 212 RECORDER_INFO_MAX_FILESIZE_APPROACHING, 213 /** 214 * The threshold specified by {@link SetMaxDuration} is reached, and the recording ends. 215 * Before calling {@link SetNextOutputFile}, you must close the file. 216 */ 217 RECORDER_INFO_MAX_DURATION_REACHED, 218 /** 219 * The threshold specified by {@link SetMaxFileSize} is reached, and the recording ends. 220 * Before calling {@link SetNextOutputFile}, you must close the file. 221 */ 222 RECORDER_INFO_MAX_FILESIZE_REACHED, 223 /** Recording started for the next output file. */ 224 RECORDER_INFO_NEXT_OUTPUT_FILE_STARTED, 225 /** Manual file split completed. */ 226 RECORDER_INFO_FILE_SPLIT_FINISHED, 227 /** The start time position of the recording file is not supported. */ 228 RECORDER_INFO_FILE_START_TIME_MS, 229 /** Next file fd is needed but not set. */ 230 RECORDER_INFO_NEXT_FILE_FD_NOT_SET, 231 232 /** warnings, and the err code passed by the 'extra' argument, the code see "MediaServiceErrCode". */ 233 RECORDER_INFO_INTERNEL_WARNING, 234 235 /** extend info start,The extension information code agreed upon by the plug-in and 236 the application will be transparently transmitted by the service. */ 237 RECORDER_INFO_EXTEND_START = 0X10000, 238 }; 239 240 /** 241 * @brief Enumerates recording error types. 242 * 243 * @since 1.0 244 * @version 1.0 245 */ 246 enum RecorderErrorType : int32_t { 247 /* internal errors, error code passed by the errorCode, and definition see "MediaServiceErrCode" */ 248 RECORDER_ERROR_INTERNAL, 249 250 /** extend error start,The extension error code agreed upon by the plug-in and 251 the application will be transparently transmitted by the service. */ 252 RECORDER_ERROR_EXTEND_START = 0X10000, 253 }; 254 255 struct AudioCapturerInfo { 256 int32_t sourceType; 257 int32_t capturerFlags; 258 259 AudioCapturerInfo() = default; 260 ~AudioCapturerInfo()= default; MarshallingAudioCapturerInfo261 bool Marshalling(Parcel &parcel) const 262 { 263 return parcel.WriteInt32(sourceType) 264 && parcel.WriteInt32(capturerFlags); 265 } UnmarshallingAudioCapturerInfo266 void Unmarshalling(Parcel &parcel) 267 { 268 sourceType = parcel.ReadInt32(); 269 capturerFlags = parcel.ReadInt32(); 270 } 271 }; 272 273 struct DeviceStreamInfo { 274 int32_t encoding; 275 int32_t format; 276 std::set<int32_t> samplingRate; 277 std::set<int32_t> channels; 278 279 DeviceStreamInfo() = default; 280 MarshallingDeviceStreamInfo281 bool Marshalling(Parcel &parcel) const 282 { 283 if (!parcel.WriteInt32(encoding)) { 284 return false; 285 } 286 if (!parcel.WriteInt32(format)) { 287 return false; 288 } 289 size_t size = samplingRate.size(); 290 if (!parcel.WriteUint64(size)) { 291 return false; 292 } 293 for (const auto &i : samplingRate) { 294 if (!parcel.WriteInt32(i)) { 295 return false; 296 } 297 } 298 size = channels.size(); 299 if (!parcel.WriteUint64(size)) { 300 return false; 301 } 302 for (const auto &i : channels) { 303 if (!parcel.WriteInt32(i)) { 304 return false; 305 } 306 } 307 return true; 308 } UnmarshallingDeviceStreamInfo309 void Unmarshalling(Parcel &parcel) 310 { 311 encoding = parcel.ReadInt32(); 312 format = parcel.ReadInt32(); 313 size_t size = parcel.ReadUint64(); 314 // it may change in the future, Restricted by security requirements 315 if (size > DEVICE_INFO_SIZE_LIMIT) { 316 return; 317 } 318 for (size_t i = 0; i < size; i++) { 319 samplingRate.insert(parcel.ReadInt32()); 320 } 321 size = parcel.ReadUint64(); 322 if (size > DEVICE_INFO_SIZE_LIMIT) { 323 return; 324 } 325 for (size_t i = 0; i < size; i++) { 326 channels.insert(parcel.ReadInt32()); 327 } 328 } 329 }; 330 331 struct DeviceInfo { 332 int32_t deviceType; 333 int32_t deviceRole; 334 int32_t deviceId; 335 int32_t channelMasks; 336 int32_t channelIndexMasks; 337 std::string deviceName; 338 std::string macAddress; 339 DeviceStreamInfo audioStreamInfo; 340 std::string networkId; 341 std::string displayName; 342 int32_t interruptGroupId; 343 int32_t volumeGroupId; 344 bool isLowLatencyDevice; 345 346 DeviceInfo() = default; 347 ~DeviceInfo() = default; MarshallingDeviceInfo348 bool Marshalling(Parcel &parcel) const 349 { 350 return parcel.WriteInt32(deviceType) 351 && parcel.WriteInt32(deviceRole) 352 && parcel.WriteInt32(deviceId) 353 && parcel.WriteInt32(channelMasks) 354 && parcel.WriteInt32(channelIndexMasks) 355 && parcel.WriteString(deviceName) 356 && parcel.WriteString(macAddress) 357 && audioStreamInfo.Marshalling(parcel) 358 && parcel.WriteString(networkId) 359 && parcel.WriteString(displayName) 360 && parcel.WriteInt32(interruptGroupId) 361 && parcel.WriteInt32(volumeGroupId) 362 && parcel.WriteBool(isLowLatencyDevice); 363 } UnmarshallingDeviceInfo364 void Unmarshalling(Parcel &parcel) 365 { 366 deviceType = parcel.ReadInt32(); 367 deviceRole = parcel.ReadInt32(); 368 deviceId = parcel.ReadInt32(); 369 channelMasks = parcel.ReadInt32(); 370 channelIndexMasks = parcel.ReadInt32(); 371 deviceName = parcel.ReadString(); 372 macAddress = parcel.ReadString(); 373 audioStreamInfo.Unmarshalling(parcel); 374 networkId = parcel.ReadString(); 375 displayName = parcel.ReadString(); 376 interruptGroupId = parcel.ReadInt32(); 377 volumeGroupId = parcel.ReadInt32(); 378 isLowLatencyDevice = parcel.ReadBool(); 379 } 380 }; 381 /** 382 * same as AudioCapturerChangeInfo in audio_info.h 383 */ 384 class AudioRecorderChangeInfo { 385 public: 386 int32_t createrUID; 387 int32_t clientUID; 388 int32_t sessionId; 389 int32_t clientPid; 390 AudioCapturerInfo capturerInfo; 391 int32_t capturerState; 392 DeviceInfo inputDeviceInfo; 393 bool muted; 394 AudioRecorderChangeInfo(const AudioRecorderChangeInfo & audioRecorderChangeInfo)395 AudioRecorderChangeInfo(const AudioRecorderChangeInfo &audioRecorderChangeInfo) 396 { 397 *this = audioRecorderChangeInfo; 398 } 399 AudioRecorderChangeInfo() = default; 400 ~AudioRecorderChangeInfo() = default; Marshalling(Parcel & parcel)401 bool Marshalling(Parcel &parcel) const 402 { 403 return parcel.WriteInt32(createrUID) 404 && parcel.WriteInt32(clientUID) 405 && parcel.WriteInt32(sessionId) 406 && parcel.WriteInt32(clientPid) 407 && capturerInfo.Marshalling(parcel) 408 && parcel.WriteInt32(capturerState) 409 && inputDeviceInfo.Marshalling(parcel) 410 && parcel.WriteBool(muted); 411 } Unmarshalling(Parcel & parcel)412 void Unmarshalling(Parcel &parcel) 413 { 414 createrUID = parcel.ReadInt32(); 415 clientUID = parcel.ReadInt32(); 416 sessionId = parcel.ReadInt32(); 417 clientPid = parcel.ReadInt32(); 418 capturerInfo.Unmarshalling(parcel); 419 capturerState = parcel.ReadInt32(); 420 inputDeviceInfo.Unmarshalling(parcel); 421 muted = parcel.ReadBool(); 422 } 423 }; 424 425 struct userLocation { 426 float latitude = 0.0f; 427 float longitude = 0.0f; 428 }; 429 430 /** 431 * @brief same as AVMetadata 432 * 433 * @param videoOrientation {0, 90, 180, 270} default 0 default orientation is 0, same as AVRecorderConfig.rotation 434 * @param genre the metadata to retrieve the content type or genre of the data 435 * @param location geo location information from user 436 * @param customInfo Custom parameter key-value map from user 437 */ 438 struct AVMetadata { 439 std::string videoOrientation; 440 std::string genre; 441 userLocation location; 442 Meta customInfo; 443 }; 444 445 /** 446 * @brief Provides listeners for recording errors and information events. 447 * 448 * @since 1.0 449 * @version 1.0 450 */ 451 class RecorderCallback { 452 public: 453 virtual ~RecorderCallback() = default; 454 455 /** 456 * @brief Called when an error occurs during recording. This callback is used to report recording errors. 457 * 458 * @param errorType Indicates the error type. For details, see {@link RecorderErrorType}. 459 * @param errorCode Indicates the error code. 460 * @since 1.0 461 * @version 1.0 462 */ 463 virtual void OnError(RecorderErrorType errorType, int32_t errorCode) = 0; 464 465 /** 466 * @brief Called when an information event occurs during recording. This callback is used to report recording 467 * information. 468 * 469 * @param type Indicates the information type. For details, see {@link RecorderInfoType}. 470 * @param extra Indicates other information, for example, the start time position of a recording file. 471 * @since 1.0 472 * @version 1.0 473 */ 474 virtual void OnInfo(int32_t type, int32_t extra) = 0; 475 /** 476 * @brief Called when the recording configuration changes. This callback is used to report all information 477 * after recording configuration changes 478 * 479 * @param audioCaptureChangeInfo audio Capture Change information. 480 * @since 1.0 481 * @version 1.0 482 */ OnAudioCaptureChange(const AudioRecorderChangeInfo & audioRecorderChangeInfo)483 virtual void OnAudioCaptureChange(const AudioRecorderChangeInfo &audioRecorderChangeInfo) 484 { 485 (void)audioRecorderChangeInfo; 486 } 487 OnPhotoAssertAvailable(const std::string & uri)488 virtual void OnPhotoAssertAvailable(const std::string &uri) 489 { 490 (void)uri; 491 } 492 }; 493 494 /** 495 * @brief Provides functions for audio and video recording. 496 * 497 * @since 1.0 498 * @version 1.0 499 */ 500 class Recorder { 501 public: 502 virtual ~Recorder() = default; 503 504 /** 505 * @brief Sets a video source for recording. 506 * 507 * If this function is not called, the output file does not contain the video track. 508 * 509 * @param source Indicates the video source type. For details, see {@link VideoSourceType}. 510 * @param sourceId Indicates the video source ID. The value <b>-1</b> indicates an invalid ID and the setting fails. 511 * 512 * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. 513 * @since 1.0 514 * @version 1.0 515 */ 516 virtual int32_t SetVideoSource(VideoSourceType source, int32_t &sourceId) = 0; 517 518 /** 519 * @brief Sets the audio source for recording. 520 * 521 * If this function is not called, the output file does not contain the audio track. 522 * 523 * @param source Indicates the audio source type. For details, see {@link AudioSourceType}. 524 * @param sourceId Indicates the audio source ID. The value <b>-1</b> indicates an invalid ID and the setting fails. 525 * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. 526 * @since 1.0 527 * @version 1.0 528 */ 529 virtual int32_t SetAudioSource(AudioSourceType source, int32_t &sourceId) = 0; 530 531 /** 532 * Unsupported App Usage. 533 * @brief Sets a data source for recording. 534 * 535 * If this function is not called, the output file does not contain the data track. 536 * 537 * @param sourceId Indicates the data source ID. The value <b>-1</b> indicates an invalid ID and the setting fails. 538 * 539 * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. 540 * @since 1.0 541 * @version 1.0 542 */ 543 virtual int32_t SetDataSource(DataSourceType dataType, int32_t &sourceId) = 0; 544 545 /** 546 * @brief Sets a meta source for recording. 547 * 548 * If this function is not called, the output file does not contain the meta track. 549 * 550 * @param source Indicates the meta source type. For details, see {@link MetaSourceType}. 551 * @param sourceId Indicates the meta source ID. The value <b>-1</b> indicates an invalid ID and the setting fails. 552 * 553 * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. 554 * @since 1.0 555 * @version 1.0 556 */ 557 virtual int32_t SetMetaSource(MetaSourceType source, int32_t &sourceId) = 0; 558 559 /** 560 * @brief Sets a meta track configurations for recording. 561 * 562 * If this function is not called, the output file does not contain the meta track. 563 * 564 * @param sourceId Indicates the data source ID. The value <b>-1</b> indicates an invalid ID and the setting fails. 565 * 566 * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. 567 * @since 1.0 568 * @version 1.0 569 */ 570 virtual int32_t SetMetaConfigs(int32_t sourceId) = 0; 571 572 /** 573 * @brief Sets the output file format. 574 * 575 * This function must be called before {@link Prepare} and after after all required sources have been set. After 576 * this function called, no more source settings allowed. 577 * 578 * @param format Indicates the output file format. For details, see {@link OutputFormatType}. 579 * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. 580 * @since 1.0 581 * @version 1.0 582 */ 583 virtual int32_t SetOutputFormat(OutputFormatType format) = 0; 584 585 /** 586 * @brief Sets a video encoder for recording. 587 * 588 * If this function is not called, the output file does not contain the video track when the video source is 589 * YUV or RGB. 590 * This function must be called after {@link SetOutputFormat} but before {@link Prepare}. 591 * 592 * @param sourceId Indicates the video source ID, which can be obtained from {@link SetVideoSource}. 593 * @param encoder Indicates the video encoder to set. For details, see {@link VideoCodecFormat}. 594 * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. 595 * @since 1.0 596 * @version 1.0 597 */ 598 virtual int32_t SetVideoEncoder(int32_t sourceId, VideoCodecFormat encoder) = 0; 599 600 /** 601 * @brief Sets the status of the video to record. 602 * 603 * This function must be called after {@link SetOutputFormat} 604 * 605 * @param sourceId Indicates the video source ID, which can be obtained from {@link SetVideoSource}. 606 * @param isHdr Indicates the HDR status to set. 607 * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. 608 * @since 1.0 609 * @version 1.0 610 */ 611 virtual int32_t SetVideoIsHdr(int32_t sourceId, bool isHdr) = 0; 612 613 /** 614 * @brief Sets the status of the video whether to encode the video in temporal scale mode. 615 * 616 * @param sourceId Indicates the video source ID, which can be obtained from {@link SetVideoSource}. 617 * @param enableTemporalScale Indicates the temporal scale mode to set. 618 * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. 619 * @since 1.0 620 * @version 1.0 621 */ 622 virtual int32_t SetVideoEnableTemporalScale(int32_t sourceId, bool enableTemporalScale) = 0; 623 624 /** 625 * @brief SetVideoEnableStableQualityMode. 626 * 627 * @param sourceId Indicates the video source ID, which can be obtained from {@link SetVideoSource}. 628 * @param enableStableQualityMode Indicates the stable quality mode to set. 629 * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. 630 * @since 1.0 631 * @version 1.0 632 */ 633 virtual int32_t SetVideoEnableStableQualityMode(int32_t sourceId, bool enableStableQualityMode) = 0; 634 635 /** 636 * @brief Sets the width and height of the video to record. 637 * 638 * This function must be called after {@link SetOutputFormat} but before {@link Prepare}. 639 * 640 * @param sourceId Indicates the video source ID, which can be obtained from {@link SetVideoSource}. 641 * @param width Indicates the video width to set. 642 * @param height Indicates the video height to set. 643 * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. 644 * @since 1.0 645 * @version 1.0 646 */ 647 virtual int32_t SetVideoSize(int32_t sourceId, int32_t width, int32_t height) = 0; 648 649 /** 650 * Unsupported App Usage. 651 * @brief Sets the frame rate of the video to record. 652 * 653 * This function must be called after {@link SetOutputFormat} but before {@link Prepare}. 654 * 655 * @param sourceId Indicates the video source ID, which can be obtained from {@link SetVideoSource}. 656 * @param frameRate Indicates the frame rate to set. 657 * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. 658 * @since 1.0 659 * @version 1.0 660 */ 661 virtual int32_t SetVideoFrameRate(int32_t sourceId, int32_t frameRate) = 0; 662 663 /** 664 * @brief Sets the encoding bit rate of the video to record. 665 * 666 * This function must be called after {@link SetOutputFormat} but before {@link Prepare}. 667 * 668 * @param sourceId Indicates the video source ID, which can be obtained from {@link SetVideoSource}. 669 * @param rate Indicates the encoding bit rate to set. 670 * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. 671 * @since 1.0 672 * @version 1.0 673 */ 674 virtual int32_t SetVideoEncodingBitRate(int32_t sourceId, int32_t rate) = 0; 675 676 /** 677 * Unsupported App Usage. 678 * @brief Sets the video capture rate. 679 * 680 * This function must be called after {@link SetOutputFormat} but before {@link Prepare}. It is valid when the 681 * video source is YUV or RGB. 682 * 683 * @param sourceId Indicates the video source ID, which can be obtained from {@link SetVideoSource}. 684 * @param fps Indicates the rate at which frames are captured per second. 685 * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. 686 * @since 1.0 687 * @version 1.0 688 */ 689 virtual int32_t SetCaptureRate(int32_t sourceId, double fps) = 0; 690 691 /** 692 * @brief Obtains the surface of the video source. This function can only be called after {@link Prepare} and 693 * before {@link Stop}. 694 * 695 * @param sourceId Indicates the video source ID, which can be obtained from {@link SetVideoSource}. 696 * @return Returns the pointer to the surface. 697 * @since 1.0 698 * @version 1.0 699 */ 700 virtual sptr<OHOS::Surface> GetSurface(int32_t sourceId) = 0; 701 702 /** 703 * @brief Obtains the surface of the video source. This function can only be called after {@link Prepare} and 704 * before {@link Stop}. 705 * 706 * @param sourceId Indicates the meta source ID, which can be obtained from {@link SetMetaSource}. 707 * @return Returns the pointer to the surface. 708 * @since 1.0 709 * @version 1.0 710 */ 711 virtual sptr<OHOS::Surface> GetMetaSurface(int32_t sourceId) = 0; 712 713 /** 714 * @brief Sets an audio encoder for recording. 715 * 716 * If this function is not called, the output file does not contain the audio track. 717 * This function must be called after {@link SetOutputFormat} but before {@link Prepare}. 718 * 719 * @param sourceId Indicates the audio source ID, which can be obtained from {@link SetAudioSource}. 720 * @param encoder Indicates the audio encoder to set. 721 * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. 722 * @since 1.0 723 * @version 1.0 724 */ 725 virtual int32_t SetAudioEncoder(int32_t sourceId, AudioCodecFormat encoder) = 0; 726 727 /** 728 * @brief Sets the audio sampling rate for recording. 729 * 730 * This function must be called after {@link SetOutputFormat} but before {@link Prepare}. 731 * 732 * @param sourceId Indicates the audio source ID, which can be obtained from {@link SetAudioSource}. 733 * @param rate Indicates the sampling rate of the audio per second. 734 * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. 735 * @since 1.0 736 * @version 1.0 737 */ 738 virtual int32_t SetAudioSampleRate(int32_t sourceId, int32_t rate) = 0; 739 740 /** 741 * @brief Sets the number of audio channels to record. 742 * 743 * This function must be called after {@link SetOutputFormat} but before {@link Prepare}. 744 * 745 * @param sourceId Indicates the audio source ID, which can be obtained from {@link SetAudioSource}. 746 * @param num Indicates the number of audio channels to set. 747 * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. 748 * @since 1.0 749 * @version 1.0 750 */ 751 virtual int32_t SetAudioChannels(int32_t sourceId, int32_t num) = 0; 752 753 /** 754 * @brief Sets the encoding bit rate of the audio to record. 755 * 756 * This function must be called after {@link SetOutputFormat} but before {@link Prepare}. 757 * 758 * @param sourceId Indicates the audio source ID, which can be obtained from {@link SetAudioSource}. 759 * @param bitRate Indicates the audio encoding bit rate, in bit/s. 760 * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. 761 * @since 1.0 762 * @version 1.0 763 */ 764 virtual int32_t SetAudioEncodingBitRate(int32_t sourceId, int32_t bitRate) = 0; 765 766 /** 767 * Unsupported App Usage. 768 * @brief Sets the maximum duration of a recorded file, in seconds. 769 * 770 * This function must be called after {@link SetOutputFormat} but before {@link Prepare}. If the setting is valid, 771 * {@link RECORDER_INFO_MAX_DURATION_APPROACHING} is reported through {@link OnInfo} in the {@link RecorderCallback} 772 * class when only one second or 10% is left to reach the allowed duration. 773 * If the recording output file is set by calling {@link SetOutputFile}, call {@link SetNextOutputFile} to set the 774 * next output file. Otherwise, the current file will be overwritten when the allowed duration is reached. 775 * 776 * @param duration Indicates the maximum recording duration to set. If the value is <b>0</b> or a negative number, 777 * a failure message is returned. The default duration is 60s. 778 * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. 779 * @since 1.0 780 * @version 1.0 781 */ 782 virtual int32_t SetMaxDuration(int32_t duration) = 0; 783 784 /** 785 * Unsupported App Usage. 786 * @brief Sets the maximum size of a recorded file, in bytes. 787 * 788 * This function must be called after {@link SetOutputFormat} but before {@link Prepare}. If the setting is valid, 789 * {@link RECORDER_INFO_MAX_DURATION_APPROACHING} is reported through {@link OnInfo} in the {@link RecorderCallback} 790 * class when only 100 KB or 10% is left to reach the allowed size. 791 * If the recording output file is set by calling {@link SetOutputFile}, call {@link SetNextOutputFile} to set the 792 * next output file. Otherwise, when the allowed size is reached, the current file will be overwritten. If 793 * <b>MaxDuration</b> is also set by calling {@link SetMaxDuration}, <b>MaxDuration</b> or <b>MaxFileSize</b> 794 * prevails depending on which of them is first satisfied. 795 * 796 * @param size Indicates the maximum file size to set. If the value is <b>0</b> or a negative number, a failure 797 * message is returned. 798 * By default, the maximum size of a single file supported by the current file system is used as the limit. 799 * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. 800 * @since 1.0 801 * @version 1.0 802 */ 803 virtual int32_t SetMaxFileSize(int64_t size) = 0; 804 805 /** 806 * @brief Sets the file descriptor (FD) of the output file. 807 * 808 * This function must be called after {@link SetOutputFormat} but before {@link Prepare} 809 * 810 * @param fd Indicates the FD of the file. 811 * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. 812 * @since 1.0 813 * @version 1.0 814 */ 815 virtual int32_t SetOutputFile(int32_t fd) = 0; 816 817 /** 818 * @brief Sets the FileGenerationMode. 819 * 820 * This function must be called after {@link SetOutputFormat} but before {@link Prepare} 821 * 822 * @param FileGenerationMode. 823 * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. 824 * @since 1.0 825 * @version 1.0 826 */ 827 virtual int32_t SetFileGenerationMode(FileGenerationMode mode) = 0; 828 829 /** 830 * Unsupported App Usage. 831 * @brief Sets the FD of the next output file. 832 * 833 * If {@link SetOutputFile} is successful, call this function to set the FD of the next output file after 834 * {@link RECORDER_INFO_MAX_DURATION_APPROACHING} or {@link RECORDER_INFO_MAX_FILESIZE_APPROACHING} is received. 835 * 836 * @param fd Indicates the FD of the next output file. 837 * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. 838 * @since 1.0 839 * @version 1.0 840 */ 841 virtual int32_t SetNextOutputFile(int32_t fd) = 0; 842 843 /** 844 * @brief Set and store the geodata (latitude and longitude) in the output file. 845 * This method should be called before prepare(). The geodata is stored in udta box if 846 * the output format is OutputFormat.THREE_GPP or OutputFormat.MPEG_4, 847 * and is ignored for other output formats. 848 * 849 * @param latitude float: latitude in degrees. Its value must be in the range [-90, 90]. 850 * @param longitude float: longitude in degrees. Its value must be in the range [-180, 180]. 851 * @since openharmony 3.1 852 * @version 1.0 853 */ 854 virtual void SetLocation(float latitude, float longitude) = 0; 855 856 /** 857 * @brief set the orientation hint in output file, and for the file to playback. mp4 support. 858 * the range of orientation should be {0, 90, 180, 270}, default is 0. 859 * 860 * @param rotation int32_t: should be {0, 90, 180, 270}, default is 0. 861 * @since openharmony 3.1 862 * @version 1.0 863 */ 864 virtual void SetOrientationHint(int32_t rotation) = 0; 865 866 /** 867 * @brief Registers a recording listener. 868 * 869 * This function must be called after {@link SetOutputFormat} but before {@link Prepare} 870 * 871 * @param callback Indicates the recording listener to register. For details, see {@link RecorderCallback}. 872 * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. 873 * @since 1.0 874 * @version 1.0 875 */ 876 virtual int32_t SetRecorderCallback(const std::shared_ptr<RecorderCallback> &callback) = 0; 877 878 /** 879 * @brief Custom parameter 880 * 881 * @param userMeta The user Custom Parameters 882 * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined 883 * in {@link media_errors.h} otherwise. 884 */ 885 virtual int32_t SetUserCustomInfo(Meta &userCustomInfo) = 0; 886 887 /** 888 * @brief Genre 889 */ 890 virtual int32_t SetGenre(std::string &genre) = 0; 891 892 /** 893 * @brief Prepares for recording. 894 * 895 * This function must be called before {@link Start}. 896 * 897 * @return Returns {@link MSERR_OK} if the preparation is successful; returns an error code otherwise. 898 * @since 1.0 899 * @version 1.0 900 */ 901 virtual int32_t Prepare() = 0; 902 903 /** 904 * @brief Starts recording. 905 * 906 * This function must be called after {@link Prepare}. 907 * 908 * @return Returns {@link MSERR_OK} if the recording is started; returns an error code otherwise. 909 * @since 1.0 910 * @version 1.0 911 */ 912 virtual int32_t Start() = 0; 913 914 /** 915 * @brief Pauses recording. 916 * 917 * After {@link Start} is called, you can call this function to pause recording. 918 * 919 * @return Returns {@link MSERR_OK} if the recording is paused; returns an error code otherwise. 920 * @since 1.0 921 * @version 1.0 922 */ 923 virtual int32_t Pause() = 0; 924 925 /** 926 * @brief Resumes recording. 927 * 928 * You can call this function to resume recording after {@link Pause} is called. 929 * 930 * @return Returns {@link MSERR_OK} if the recording is resumed; returns an error code otherwise. 931 * @since 1.0 932 * @version 1.0 933 */ 934 virtual int32_t Resume() = 0; 935 936 /** 937 * @brief Stops recording. 938 * 939 * @param block Indicates the stop mode. The value <b>true</b> indicates that the processing stops after all caches 940 * are processed, and <b>false</b> indicates that the processing stops immediately and all caches are discarded. 941 * After the recording stopped, all sources and parameters must be set again to restore recording. The function is 942 * like to {@link Reset}, except that the block parameter is allowed to be specified. 943 * @return Returns {@link MSERR_OK} if the recording is stopped; returns an error code otherwise. 944 * @since 1.0 945 * @version 1.0 946 */ 947 virtual int32_t Stop(bool block) = 0; 948 949 /** 950 * @brief Resets the recording. 951 * 952 * After the function is called, add a recording source by calling {@link SetVideoSource} or {@link SetAudioSource}, 953 * set related parameters, and call {@link Start} to start recording again after {@link Prepare} is called. 954 * 955 * @return Returns {@link MSERR_OK} if the recording is stopped; returns an error code otherwise. 956 * @since 1.0 957 * @version 1.0 958 */ 959 virtual int32_t Reset() = 0; 960 961 /** 962 * @brief Releases recording resources. After this function called, none of interfaces of {@link Recorder} 963 * can be used. 964 * 965 * @return Returns {@link MSERR_OK} if the recording is stopped; returns an error code otherwise. 966 * @since 1.0 967 * @version 1.0 968 */ 969 virtual int32_t Release() = 0; 970 971 /** 972 * Unsupported App Usage. 973 * @brief Manually splits a video. 974 * 975 * This function must be called after {@link Start}. After this function is called, the file is split based on the 976 * manual split type. After the manual split is complete, the initial split type is used. This function can be 977 * called again only after {@link RECORDER_INFO_FILE_SPLIT_FINISHED} is reported. 978 * 979 * @param type Indicates the file split type. For details, see {@link FileSplitType}. 980 * @param timestamp Indicates the file split timestamp. This parameter is not supported currently and can be set to 981 * <b>-1</b>. The recording module splits a file based on the call time. 982 * @param duration Indicates the duration for splitting the file. 983 * @return Returns {@link MSERR_OK} if the recording is stopped; returns an error code otherwise. 984 * @since 1.0 985 * @version 1.0 986 */ 987 virtual int32_t SetFileSplitDuration(FileSplitType type, int64_t timestamp, uint32_t duration) = 0; 988 989 /** 990 * @brief Sets an extended parameter for recording, for example, {@link RECORDER_PRE_CACHE_DURATION}. 991 * 992 * This function must be called after {@link Prepare}. 993 * 994 * @param sourceId Indicates the data source ID. The value <b>-1</b> indicates all sources. 995 * @param format Indicates the string key and value. For details, see {@link Format} and 996 * {@link RECORDER_PRE_CACHE_DURATION}. 997 * @return Returns {@link MSERR_OK} if the recording is stopped; returns an error code otherwise. 998 * @since 1.0 999 * @version 1.0 1000 */ 1001 virtual int32_t SetParameter(int32_t sourceId, const Format &format) = 0; 1002 1003 virtual int32_t GetAVRecorderConfig(ConfigMap &configMap) = 0; 1004 1005 virtual int32_t GetLocation(Location &location) = 0; 1006 1007 virtual int32_t GetCurrentCapturerChangeInfo(AudioRecorderChangeInfo &changeInfo) = 0; 1008 1009 virtual int32_t GetAvailableEncoder(std::vector<EncoderCapabilityData> &encoderInfo) = 0; 1010 1011 virtual int32_t GetMaxAmplitude() = 0; 1012 /** 1013 * @brief Check if the avrecorder has watermark capability. 1014 * 1015 * @param isWatermarkSupported isWatermarkSupported true or false. 1016 * @return Returns {@link MSERR_OK} If the query succeeds; returns an error code otherwise. 1017 * @since 1.0 1018 * @version 1.0 1019 */ 1020 virtual int32_t IsWatermarkSupported(bool &isWatermarkSupported) = 0; 1021 /** 1022 * @brief Set watermarkBuffer to avrecorder. 1023 * 1024 * @param waterMarkBuffer watermark image and config 1025 * @return Returns {@link MSERR_OK} If the SetWatermark succeeds; returns an error code otherwise. 1026 * @since 1.0 1027 * @version 1.0 1028 */ 1029 virtual int32_t SetWatermark(std::shared_ptr<AVBuffer> &waterMarkBuffer) = 0; 1030 }; 1031 1032 class __attribute__((visibility("default"))) RecorderFactory { 1033 public: 1034 #ifdef UNSUPPORT_RECORDER CreateRecorder()1035 static std::shared_ptr<Recorder> CreateRecorder() 1036 { 1037 return nullptr; 1038 } 1039 #else 1040 static std::shared_ptr<Recorder> CreateRecorder(); 1041 #endif 1042 private: 1043 RecorderFactory() = default; 1044 ~RecorderFactory() = default; 1045 }; 1046 } // namespace Media 1047 } // namespace OHOS 1048 #endif // RECORDER_H 1049