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