• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "format.h"
22 #include "surface.h"
23 #include "av_common.h"
24 
25 namespace OHOS {
26 namespace Media {
27 /**
28  * @brief Enumerates video source types.
29  *
30  * @since 1.0
31  * @version 1.0
32  */
33 enum VideoSourceType : int32_t {
34     /** Unsupported App Usage. */
35     /** YUV video data provided through {@link Surface} */
36     VIDEO_SOURCE_SURFACE_YUV = 0,
37     /** Raw encoded data provided through {@link Surface} */
38     VIDEO_SOURCE_SURFACE_ES,
39     /** RGBA video data provided through {@link Surface} */
40     VIDEO_SOURCE_SURFACE_RGBA,
41     /** Invalid value */
42     VIDEO_SOURCE_BUTT
43 };
44 
45 /**
46  * @brief Enumerates audio source types.
47  *
48  * @since 1.0
49  * @version 1.0
50  */
51 enum AudioSourceType : int32_t {
52     /** Invalid audio source */
53     AUDIO_SOURCE_INVALID = -1,
54     /** Default audio source */
55     AUDIO_SOURCE_DEFAULT = 0,
56     /** Microphone */
57     AUDIO_MIC = 1,
58 };
59 
60 /**
61  * Unsupported app usage.
62  * @brief Enumerates data source types.
63  *
64  * @since 1.0
65  * @version 1.0
66  */
67 enum DataSourceType : int32_t {
68     /** meta data source */
69     METADATA = 0
70 };
71 
72 /**
73  * @brief Enumerates output format types.
74  *
75  * @since 3.1
76  * @version 3.1
77  */
78 enum OutputFormatType : int32_t {
79     /** Default format */
80     FORMAT_DEFAULT = 0,
81     /** MPEG4 format */
82     FORMAT_MPEG_4 = 2,
83     /** M4A format */
84     FORMAT_M4A = 6,
85     /** BUTT */
86     FORMAT_BUTT,
87 };
88 
89 /**
90  * @brief Enumerates video codec formats.
91  *
92  * @since 3.1
93  * @version 3.1
94  */
95 enum VideoCodecFormat : int32_t {
96     /** Default format */
97     VIDEO_DEFAULT = 0,
98     /** H.264 */
99     H264 = 2,
100     /** MPEG4 */
101     MPEG4 = 6,
102     VIDEO_CODEC_FORMAT_BUTT,
103 };
104 
105 /**
106  * @brief Enumerates audio codec formats.
107  *
108  * @since 3.1
109  * @version 3.1
110  */
111 enum AudioCodecFormat : int32_t {
112     /** Default format */
113     AUDIO_DEFAULT = 0,
114     /** Advanced Audio Coding Low Complexity (AAC-LC) */
115     AAC_LC = 3,
116     /** Invalid value */
117     AUDIO_CODEC_FORMAT_BUTT,
118 };
119 
120 /**
121  * Unsupported App Usage.
122  * @brief Enumerates file split types.
123  *
124  * @since 1.0
125  * @version 1.0
126  */
127 enum FileSplitType : int32_t {
128     /** Delayed/Backward split */
129     FILE_SPLIT_POST = 0,
130     /** Advanced/Forward split */
131     FILE_SPLIT_PRE,
132     /** Normal split */
133     FILE_SPLIT_NORMAL,
134     /** Invalid value */
135     FILE_SPLIT_BUTT,
136 };
137 
138 /**
139  * @brief Enumerates recording information types.
140  *
141  * @since 1.0
142  * @version 1.0
143  */
144 enum RecorderInfoType : int32_t {
145     /**
146      * The recording duration is reaching the threshold specified by {@link SetMaxDuration}. This type of
147      * information is reported when only one second or 10% is left to reach the allowed duration.
148      */
149     RECORDER_INFO_MAX_DURATION_APPROACHING = 0,
150     /**
151      * The recorded file size is reaching the threshold specified by {@link SetMaxFileSize}. This type of
152      * information is reported when only 100 KB or 10% is left to reach the allowed size.
153      */
154     RECORDER_INFO_MAX_FILESIZE_APPROACHING,
155     /**
156      * The threshold specified by {@link SetMaxDuration} is reached, and the recording ends.
157      * Before calling {@link SetNextOutputFile}, you must close the file.
158      */
159     RECORDER_INFO_MAX_DURATION_REACHED,
160     /**
161      * The threshold specified by {@link SetMaxFileSize} is reached, and the recording ends.
162      * Before calling {@link SetNextOutputFile}, you must close the file.
163      */
164     RECORDER_INFO_MAX_FILESIZE_REACHED,
165     /** Recording started for the next output file. */
166     RECORDER_INFO_NEXT_OUTPUT_FILE_STARTED,
167     /** Manual file split completed. */
168     RECORDER_INFO_FILE_SPLIT_FINISHED,
169     /** The start time position of the recording file is not supported. */
170     RECORDER_INFO_FILE_START_TIME_MS,
171     /** Next file fd is needed but not set. */
172     RECORDER_INFO_NEXT_FILE_FD_NOT_SET,
173 
174     /** warnings, and the err code passed by the 'extra' argument, the code see "MediaServiceErrCode". */
175     RECORDER_INFO_INTERNEL_WARNING,
176 
177      /** extend info start,The extension information code agreed upon by the plug-in and
178          the application will be transparently transmitted by the service. */
179     RECORDER_INFO_EXTEND_START = 0X10000,
180 };
181 
182 /**
183  * @brief Enumerates recording error types.
184  *
185  * @since 1.0
186  * @version 1.0
187  */
188 enum RecorderErrorType : int32_t {
189     /* internal errors, error code passed by the errorCode, and definition see "MediaServiceErrCode" */
190     RECORDER_ERROR_INTERNAL,
191 
192      /** extend error start,The extension error code agreed upon by the plug-in and
193          the application will be transparently transmitted by the service. */
194     RECORDER_ERROR_EXTEND_START = 0X10000,
195 };
196 
197 /**
198  * @brief Enumerates the container format types.
199  */
200 class ContainerFormatType {
201 public:
202     static constexpr std::string_view CFT_MPEG_4A = "m4a";
203     static constexpr std::string_view CFT_MPEG_4 = "mp4";
204 };
205 
206 /**
207  * @brief the struct of geolocation
208  *
209  * @param latitude float: latitude in degrees. Its value must be in the range [-90, 90].
210  * @param longitude float: longitude in degrees. Its value must be in the range [-180, 180].
211  * @since  3.1
212  * @version 3.1
213  */
214 struct Location {
215     float latitude = 0;
216     float longitude = 0;
217 };
218 
219 /**
220  * @brief Provides listeners for recording errors and information events.
221  *
222  * @since 1.0
223  * @version 1.0
224  */
225 class RecorderCallback {
226 public:
227     virtual ~RecorderCallback() = default;
228 
229     /**
230      * @brief Called when an error occurs during recording. This callback is used to report recording errors.
231      *
232      * @param errorType Indicates the error type. For details, see {@link RecorderErrorType}.
233      * @param errorCode Indicates the error code.
234      * @since 1.0
235      * @version 1.0
236      */
237     virtual void OnError(RecorderErrorType errorType, int32_t errorCode) = 0;
238 
239     /**
240      * @brief Called when an information event occurs during recording. This callback is used to report recording
241      * information.
242      *
243      * @param type Indicates the information type. For details, see {@link RecorderInfoType}.
244      * @param extra Indicates other information, for example, the start time position of a recording file.
245      * @since 1.0
246      * @version 1.0
247      */
248     virtual void OnInfo(int32_t type, int32_t extra) = 0;
249 };
250 
251 /**
252  * @brief Provides functions for audio and video recording.
253  *
254  * @since 1.0
255  * @version 1.0
256  */
257 class Recorder {
258 public:
259     virtual ~Recorder() = default;
260 
261     /**
262      * @brief Sets a video source for recording.
263      *
264      * If this function is not called, the output file does not contain the video track.
265      *
266      * @param source Indicates the video source type. For details, see {@link VideoSourceType}.
267      * @param sourceId Indicates the video source ID. The value <b>-1</b> indicates an invalid ID and the setting fails.
268      *
269      * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise.
270      * @since 1.0
271      * @version 1.0
272      */
273     virtual int32_t SetVideoSource(VideoSourceType source, int32_t &sourceId) = 0;
274 
275     /**
276      * @brief Sets the audio source for recording.
277      *
278      * If this function is not called, the output file does not contain the audio track.
279      *
280      * @param source Indicates the audio source type. For details, see {@link AudioSourceType}.
281      * @param sourceId Indicates the audio source ID. The value <b>-1</b> indicates an invalid ID and the setting fails.
282      * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise.
283      * @since 1.0
284      * @version 1.0
285      */
286     virtual int32_t SetAudioSource(AudioSourceType source, int32_t &sourceId) = 0;
287 
288     /**
289      * Unsupported App Usage.
290      * @brief Sets a data source for recording.
291      *
292      * If this function is not called, the output file does not contain the data track.
293      *
294      * @param sourceId Indicates the data source ID. The value <b>-1</b> indicates an invalid ID and the setting fails.
295      *
296      * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise.
297      * @since 1.0
298      * @version 1.0
299      */
300     virtual int32_t SetDataSource(DataSourceType dataType, int32_t &sourceId) = 0;
301 
302     /**
303      * @brief Sets the output file format.
304      *
305      * This function must be called before {@link Prepare} and after after all required sources have been set. After
306      * this function called, no more source settings allowed.
307      *
308      * @param format Indicates the output file format. For details, see {@link OutputFormatType}.
309      * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise.
310      * @since 1.0
311      * @version 1.0
312      */
313     virtual int32_t SetOutputFormat(OutputFormatType format) = 0;
314 
315     /**
316      * @brief Sets a video encoder for recording.
317      *
318      * If this function is not called, the output file does not contain the video track when the video source is
319      * YUV or RGB.
320      * This function must be called after {@link SetOutputFormat} but before {@link Prepare}.
321      *
322      * @param sourceId Indicates the video source ID, which can be obtained from {@link SetVideoSource}.
323      * @param encoder Indicates the video encoder to set. For details, see {@link VideoCodecFormat}.
324      * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise.
325      * @since 1.0
326      * @version 1.0
327      */
328     virtual int32_t SetVideoEncoder(int32_t sourceId, VideoCodecFormat encoder) = 0;
329 
330     /**
331      * @brief Sets the width and height of the video to record.
332      *
333      * This function must be called after {@link SetOutputFormat} but before {@link Prepare}.
334      *
335      * @param sourceId Indicates the video source ID, which can be obtained from {@link SetVideoSource}.
336      * @param width Indicates the video width to set.
337      * @param height Indicates the video height to set.
338      * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise.
339      * @since 1.0
340      * @version 1.0
341      */
342     virtual int32_t SetVideoSize(int32_t sourceId, int32_t width, int32_t height) = 0;
343 
344     /**
345      * Unsupported App Usage.
346      * @brief Sets the frame rate of the video to record.
347      *
348      * This function must be called after {@link SetOutputFormat} but before {@link Prepare}.
349      *
350      * @param sourceId Indicates the video source ID, which can be obtained from {@link SetVideoSource}.
351      * @param frameRate Indicates the frame rate to set.
352      * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise.
353      * @since 1.0
354      * @version 1.0
355      */
356     virtual int32_t SetVideoFrameRate(int32_t sourceId, int32_t frameRate) = 0;
357 
358     /**
359      * @brief Sets the encoding bit rate of the video to record.
360      *
361      * This function must be called after {@link SetOutputFormat} but before {@link Prepare}.
362      *
363      * @param sourceId Indicates the video source ID, which can be obtained from {@link SetVideoSource}.
364      * @param rate Indicates the encoding bit rate to set.
365      * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise.
366      * @since 1.0
367      * @version 1.0
368      */
369     virtual int32_t SetVideoEncodingBitRate(int32_t sourceId, int32_t rate) = 0;
370 
371     /**
372      * Unsupported App Usage.
373      * @brief Sets the video capture rate.
374      *
375      * This function must be called after {@link SetOutputFormat} but before {@link Prepare}. It is valid when the
376      * video source is YUV or RGB.
377      *
378      * @param sourceId Indicates the video source ID, which can be obtained from {@link SetVideoSource}.
379      * @param fps Indicates the rate at which frames are captured per second.
380      * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise.
381      * @since 1.0
382      * @version 1.0
383      */
384     virtual int32_t SetCaptureRate(int32_t sourceId, double fps) = 0;
385 
386     /**
387      * @brief Obtains the surface of the video source. This function can only be called after {@link Prepare} and
388      * before {@link Stop}.
389      *
390      * @param sourceId Indicates the video source ID, which can be obtained from {@link SetVideoSource}.
391      * @return Returns the pointer to the surface.
392      * @since 1.0
393      * @version 1.0
394      */
395     virtual sptr<OHOS::Surface> GetSurface(int32_t sourceId) = 0;
396 
397     /**
398      * @brief Sets an audio encoder for recording.
399      *
400      * If this function is not called, the output file does not contain the audio track.
401      * This function must be called after {@link SetOutputFormat} but before {@link Prepare}.
402      *
403      * @param sourceId Indicates the audio source ID, which can be obtained from {@link SetAudioSource}.
404      * @param encoder Indicates the audio encoder to set.
405      * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise.
406      * @since 1.0
407      * @version 1.0
408      */
409     virtual int32_t SetAudioEncoder(int32_t sourceId, AudioCodecFormat encoder) = 0;
410 
411     /**
412      * @brief Sets the audio sampling rate for recording.
413      *
414      * This function must be called after {@link SetOutputFormat} but before {@link Prepare}.
415      *
416      * @param sourceId Indicates the audio source ID, which can be obtained from {@link SetAudioSource}.
417      * @param rate Indicates the sampling rate of the audio per second.
418      * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise.
419      * @since 1.0
420      * @version 1.0
421      */
422     virtual int32_t SetAudioSampleRate(int32_t sourceId, int32_t rate) = 0;
423 
424     /**
425      * @brief Sets the number of audio channels to record.
426      *
427      * This function must be called after {@link SetOutputFormat} but before {@link Prepare}.
428      *
429      * @param sourceId Indicates the audio source ID, which can be obtained from {@link SetAudioSource}.
430      * @param num Indicates the number of audio channels to set.
431      * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise.
432      * @since 1.0
433      * @version 1.0
434      */
435     virtual int32_t SetAudioChannels(int32_t sourceId, int32_t num) = 0;
436 
437     /**
438      * @brief Sets the encoding bit rate of the audio to record.
439      *
440      * This function must be called after {@link SetOutputFormat} but before {@link Prepare}.
441      *
442      * @param sourceId Indicates the audio source ID, which can be obtained from {@link SetAudioSource}.
443      * @param bitRate Indicates the audio encoding bit rate, in bit/s.
444      * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise.
445      * @since 1.0
446      * @version 1.0
447      */
448     virtual int32_t SetAudioEncodingBitRate(int32_t sourceId, int32_t bitRate) = 0;
449 
450     /**
451      * Unsupported App Usage.
452      * @brief Sets the maximum duration of a recorded file, in seconds.
453      *
454      * This function must be called after {@link SetOutputFormat} but before {@link Prepare}. If the setting is valid,
455      * {@link RECORDER_INFO_MAX_DURATION_APPROACHING} is reported through {@link OnInfo} in the {@link RecorderCallback}
456      * class when only one second or 10% is left to reach the allowed duration.
457      * If the recording output file is set by calling {@link SetOutputFile}, call {@link SetNextOutputFile} to set the
458      * next output file. Otherwise, the current file will be overwritten when the allowed duration is reached.
459      *
460      * @param duration Indicates the maximum recording duration to set. If the value is <b>0</b> or a negative number,
461      * a failure message is returned. The default duration is 60s.
462      * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise.
463      * @since 1.0
464      * @version 1.0
465      */
466     virtual int32_t SetMaxDuration(int32_t duration) = 0;
467 
468     /**
469      * Unsupported App Usage.
470      * @brief Sets the maximum size of a recorded file, in bytes.
471      *
472      * This function must be called after {@link SetOutputFormat} but before {@link Prepare}. If the setting is valid,
473      * {@link RECORDER_INFO_MAX_DURATION_APPROACHING} is reported through {@link OnInfo} in the {@link RecorderCallback}
474      * class when only 100 KB or 10% is left to reach the allowed size.
475      * If the recording output file is set by calling {@link SetOutputFile}, call {@link SetNextOutputFile} to set the
476      * next output file. Otherwise, when the allowed size is reached, the current file will be overwritten. If
477      * <b>MaxDuration</b> is also set by calling {@link SetMaxDuration}, <b>MaxDuration</b> or <b>MaxFileSize</b>
478      * prevails depending on which of them is first satisfied.
479      *
480      * @param size Indicates the maximum file size to set. If the value is <b>0</b> or a negative number, a failure
481      * message is returned.
482      * By default, the maximum size of a single file supported by the current file system is used as the limit.
483      * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise.
484      * @since 1.0
485      * @version 1.0
486      */
487     virtual int32_t SetMaxFileSize(int64_t size) = 0;
488 
489     /**
490      * @brief Sets the file descriptor (FD) of the output file.
491      *
492      * This function must be called after {@link SetOutputFormat} but before {@link Prepare}
493      *
494      * @param fd Indicates the FD of the file.
495      * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise.
496      * @since 1.0
497      * @version 1.0
498      */
499     virtual int32_t SetOutputFile(int32_t fd) = 0;
500 
501     /**
502      * Unsupported App Usage.
503      * @brief Sets the FD of the next output file.
504      *
505      * If {@link SetOutputFile} is successful, call this function to set the FD of the next output file after
506      * {@link RECORDER_INFO_MAX_DURATION_APPROACHING} or {@link RECORDER_INFO_MAX_FILESIZE_APPROACHING} is received.
507      *
508      * @param fd Indicates the FD of the next output file.
509      * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise.
510      * @since 1.0
511      * @version 1.0
512      */
513     virtual int32_t SetNextOutputFile(int32_t fd) = 0;
514 
515     /**
516      * @brief Set and store the geodata (latitude and longitude) in the output file.
517      * This method should be called before prepare(). The geodata is stored in udta box if
518      * the output format is OutputFormat.THREE_GPP or OutputFormat.MPEG_4,
519      * and is ignored for other output formats.
520      *
521      * @param latitude float: latitude in degrees. Its value must be in the range [-90, 90].
522      * @param longitude float: longitude in degrees. Its value must be in the range [-180, 180].
523      * @since openharmony 3.1
524      * @version 1.0
525      */
526     virtual void SetLocation(float latitude, float longitude) = 0;
527 
528     /**
529      * @brief set the orientation hint in output file, and for the file to playback. mp4 support.
530      * the range of orientation should be {0, 90, 180, 270}, default is 0.
531      *
532      * @param rotation int32_t: should be {0, 90, 180, 270}, default is 0.
533      * @since openharmony 3.1
534      * @version 1.0
535      */
536     virtual void SetOrientationHint(int32_t rotation) = 0;
537 
538     /**
539      * @brief Registers a recording listener.
540      *
541      * This function must be called after {@link SetOutputFormat} but before {@link Prepare}
542      *
543      * @param callback Indicates the recording listener to register. For details, see {@link RecorderCallback}.
544      * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise.
545      * @since 1.0
546      * @version 1.0
547      */
548     virtual int32_t SetRecorderCallback(const std::shared_ptr<RecorderCallback> &callback) = 0;
549 
550     /**
551      * @brief Prepares for recording.
552      *
553      * This function must be called before {@link Start}.
554      *
555      * @return Returns {@link MSERR_OK} if the preparation is successful; returns an error code otherwise.
556      * @since 1.0
557      * @version 1.0
558      */
559     virtual int32_t Prepare() = 0;
560 
561     /**
562      * @brief Starts recording.
563      *
564      * This function must be called after {@link Prepare}.
565      *
566      * @return Returns {@link MSERR_OK} if the recording is started; returns an error code otherwise.
567      * @since 1.0
568      * @version 1.0
569      */
570     virtual int32_t Start() = 0;
571 
572     /**
573      * @brief Pauses recording.
574      *
575      * After {@link Start} is called, you can call this function to pause recording.
576      *
577      * @return Returns {@link MSERR_OK} if the recording is paused; returns an error code otherwise.
578      * @since 1.0
579      * @version 1.0
580      */
581     virtual int32_t Pause() = 0;
582 
583     /**
584     * @brief Resumes recording.
585     *
586     * You can call this function to resume recording after {@link Pause} is called.
587      *
588      * @return Returns {@link MSERR_OK} if the recording is resumed; returns an error code otherwise.
589      * @since 1.0
590      * @version 1.0
591      */
592     virtual int32_t Resume() = 0;
593 
594     /**
595      * @brief Stops recording.
596      *
597      * @param block Indicates the stop mode. The value <b>true</b> indicates that the processing stops after all caches
598      * are processed, and <b>false</b> indicates that the processing stops immediately and all caches are discarded.
599      * After the recording stopped, all sources and parameters must be set again to restore recording. The function is
600      * like to {@link Reset}, except that the block parameter is allowed to be specified.
601      * @return Returns {@link MSERR_OK} if the recording is stopped; returns an error code otherwise.
602      * @since 1.0
603      * @version 1.0
604      */
605     virtual int32_t Stop(bool block) = 0;
606 
607     /**
608      * @brief Resets the recording.
609      *
610      * After the function is called, add a recording source by calling {@link SetVideoSource} or {@link SetAudioSource},
611      * set related parameters, and call {@link Start} to start recording again after {@link Prepare} is called.
612      *
613      * @return Returns {@link MSERR_OK} if the recording is stopped; returns an error code otherwise.
614      * @since 1.0
615      * @version 1.0
616      */
617     virtual int32_t Reset() = 0;
618 
619     /**
620      * @brief Releases recording resources. After this function called, none of interfaces of {@link Recorder}
621      * can be used.
622      *
623      * @return Returns {@link MSERR_OK} if the recording is stopped; returns an error code otherwise.
624      * @since 1.0
625      * @version 1.0
626      */
627     virtual int32_t Release() = 0;
628 
629     /**
630      * Unsupported App Usage.
631      * @brief Manually splits a video.
632      *
633      * This function must be called after {@link Start}. After this function is called, the file is split based on the
634      * manual split type. After the manual split is complete, the initial split type is used. This function can be
635      * called again only after {@link RECORDER_INFO_FILE_SPLIT_FINISHED} is reported.
636      *
637      * @param type Indicates the file split type. For details, see {@link FileSplitType}.
638      * @param timestamp Indicates the file split timestamp. This parameter is not supported currently and can be set to
639      * <b>-1</b>. The recording module splits a file based on the call time.
640      * @param duration Indicates the duration for splitting the file.
641      * @return Returns {@link MSERR_OK} if the recording is stopped; returns an error code otherwise.
642      * @since 1.0
643      * @version 1.0
644      */
645     virtual int32_t SetFileSplitDuration(FileSplitType type, int64_t timestamp, uint32_t duration) = 0;
646 
647     /**
648      * @brief Sets an extended parameter for recording, for example, {@link RECORDER_PRE_CACHE_DURATION}.
649      *
650      * This function must be called after {@link Prepare}.
651      *
652      * @param sourceId Indicates the data source ID. The value <b>-1</b> indicates all sources.
653      * @param format Indicates the string key and value. For details, see {@link Format} and
654      * {@link RECORDER_PRE_CACHE_DURATION}.
655      * @return Returns {@link MSERR_OK} if the recording is stopped; returns an error code otherwise.
656      * @since 1.0
657      * @version 1.0
658      */
659     virtual int32_t SetParameter(int32_t sourceId, const Format &format) = 0;
660 };
661 
662 class __attribute__((visibility("default"))) RecorderFactory {
663 public:
664 #ifdef UNSUPPORT_RECORDER
CreateRecorder()665     static std::shared_ptr<Recorder> CreateRecorder()
666     {
667         return nullptr;
668     }
669 #else
670     static std::shared_ptr<Recorder> CreateRecorder();
671 #endif
672 private:
673     RecorderFactory() = default;
674     ~RecorderFactory() = default;
675 };
676 } // namespace Media
677 } // namespace OHOS
678 #endif // RECORDER_H
679