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