- MultiMedia_Recorder
- Overview
- Summary
- Files
- Data Structures
- Enumerations
- Functions
- Details
- Enumeration Type Documentation
- DataSourceType
- FileSplitType
- OutputFormatType
- RecorderErrorType
- RecorderInfoType
- VideoSourceType
- Function Documentation
- GetSurface()
- OnError()
- OnInfo()
- Pause()
- Prepare()
- Release()
- Reset()
- Resume()
- SetAudioChannels()
- SetAudioEncoder()
- SetAudioEncodingBitRate()
- SetAudioSampleRate()
- SetAudioSource()
- SetCaptureRate()
- SetFileSplitDuration()
- SetMaxDuration()
- SetMaxFileSize()
- SetNextOutputFile()
- SetOutputFile()
- SetOutputFormat()
- SetOutputPath()
- SetParameter()
- SetRecorderCallback()
- SetVideoEncoder()
- SetVideoEncodingBitRate()
- SetVideoFrameRate()
- SetVideoSize()
- SetVideoSource()
- Start()
- Stop()
- Variable Documentation
- RCORDER_PRE_CACHE_DURATION
MultiMedia_Recorder
Overview
Defines the Recorder class and provides functions for audio and video recording.
Since:
1.0
Version:
1.0
Summary
Files
Data Structures
Provides listeners for recording errors and information events. |
|
Enumerations
Functions
Details
Enumeration Type Documentation
DataSourceType
enum [OHOS::Media::DataSourceType]($api-api-SmartVision-Devices-MultiMedia_Recorder.md#gaccc05bb178cecd760369ea096dceae4c) : int32_t
Description:
Enumerates data source types.
IMAGE | Image data source |
FileSplitType
enum [OHOS::Media::FileSplitType]($api-api-SmartVision-Devices-MultiMedia_Recorder.md#ga8759c7e5a74964a584a716f4ec0b7edb) : int32_t
Description:
Enumerates file split types.
FILE_SPLIT_POST | |
FILE_SPLIT_PRE | |
FILE_SPLIT_NORMAL |
OutputFormatType
enum [OHOS::Media::OutputFormatType]($api-api-SmartVision-Devices-MultiMedia_Recorder.md#ga3dfe2e61369bf1c081ce569e235354df) : int32_t
Description:
Enumerates output file formats.
FORMAT_DEFAULT | |
FORMAT_MPEG_4 | |
FORMAT_TS |
RecorderErrorType
enum [OHOS::Media::RecorderCallback::RecorderErrorType]($api-api-SmartVision-Devices-MultiMedia_Recorder.md#ga5132172c298fc1497d12040b6bd511cf) : int32_t
Description:
Enumerates recording error types.
RECORDER_ERROR_UNKNOWN |
RecorderInfoType
enum [OHOS::Media::RecorderCallback::RecorderInfoType]($api-api-SmartVision-Devices-MultiMedia_Recorder.md#ga0db5cf9cc68d4b468e921a563248ffe0) : int32_t
Description:
Enumerates recording information types.
VideoSourceType
enum [OHOS::Media::VideoSourceType]($api-api-SmartVision-Devices-MultiMedia_Recorder.md#gad252d27f9ce4b6ae0756bfeaa5f34490) : int32_t
Description:
Enumerates video source types.
VIDEO_SOURCE_SURFACE_YUV | YUV video data provided through Surface |
VIDEO_SOURCE_SURFACE_RGB | RGB video data provided through Surface |
VIDEO_SOURCE_SURFACE_ES | Raw encoded data provided through Surface |
VIDEO_SOURCE_BUTT |
Function Documentation
GetSurface()
std::shared_ptr<[OHOS::Surface]($api-api-SmartVision-Devices-OHOS-Surface.md)> OHOS::Media::Recorder::GetSurface (int32_t sourceId)
Description:
Obtains the surface of the video source.
Parameters:
sourceId | Indicates the video source ID, which can be obtained from SetVideoSource. |
Returns:
Returns the pointer to the surface.
OnError()
virtual void OHOS::Media::RecorderCallback::OnError (int32_t errorType, int32_t errorCode )
Description:
Called when an error occurs during recording. This callback is used to report recording errors.
Parameters:
errorType | Indicates the error type. For details, see RecorderErrorType. |
errorCode | Indicates the error code. |
OnInfo()
virtual void OHOS::Media::RecorderCallback::OnInfo (int32_t type, int32_t extra )
Description:
Called when an information event occurs during recording. This callback is used to report recording information.
Parameters:
type | Indicates the information type. For details, see RecorderInfoType. |
extra | Indicates other information, for example, the start time position of a recording file. |
Pause()
int32_t OHOS::Media::Recorder::Pause ()
Description:
Pauses recording.
After Start is called, you can call this function to pause recording. The audio and video source streams are not paused, and source data is discarded.
Returns:
Returns SUCCESS if the recording is paused; returns an error code defined in media_errors.h otherwise.
Prepare()
int32_t OHOS::Media::Recorder::Prepare ()
Description:
Prepares for recording.
This function must be called before Start.
Returns:
Returns SUCCESS if the preparation is successful; returns an error code defined in media_errors.h otherwise.
Release()
int32_t OHOS::Media::Recorder::Release ()
Description:
Releases recording resources.
Returns:
Returns SUCCESS if recording resources are released; returns an error code defined in media_errors.h otherwise.
Reset()
int32_t OHOS::Media::Recorder::Reset ()
Description:
Resets the recording.
After the function is called, add a recording source by calling SetVideoSource or SetAudioSource, set related parameters, and call Start to start recording again after Prepare is called.
Returns:
Returns SUCCESS if the recording is reset; returns an error code defined in media_errors.h otherwise.
Resume()
int32_t OHOS::Media::Recorder::Resume ()
Description:
Resumes recording.
You can call this function to resume recording after Pause is called.
Returns:
Returns SUCCESS if the recording is resumed; returns an error code defined in media_errors.h otherwise.
SetAudioChannels()
int32_t OHOS::Media::Recorder::SetAudioChannels (int32_t sourceId, int32_t num )
Description:
Sets the number of audio channels to record.
This function must be called after SetAudioSource but before Prepare.
Parameters:
sourceId | Indicates the audio source ID, which can be obtained from SetAudioSource. |
num | Indicates the number of audio channels to set. |
Returns:
Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.
SetAudioEncoder()
int32_t OHOS::Media::Recorder::SetAudioEncoder (int32_t sourceId, [AudioCodecFormat]($api-api-SmartVision-Devices-MultiMedia_MediaCommon.md#gaa4ea6f314644ed287e0704be26c768b7) encoder )
Description:
Sets an audio encoder for recording.
If this function is not called, the output file does not contain the audio track. This function must be called after SetAudioSource but before Prepare.
Parameters:
sourceId | Indicates the audio source ID, which can be obtained from SetAudioSource. |
encoder | Indicates the audio encoder to set. |
Returns:
Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.
SetAudioEncodingBitRate()
int32_t OHOS::Media::Recorder::SetAudioEncodingBitRate (int32_t sourceId, int32_t bitRate )
Description:
Sets the encoding bit rate of the audio to record.
This function must be called after SetAudioSource but before Prepare.
Parameters:
sourceId | Indicates the audio source ID, which can be obtained from SetAudioSource. |
bitRate | Indicates the audio encoding bit rate, in bit/s. |
Returns:
Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.
SetAudioSampleRate()
int32_t OHOS::Media::Recorder::SetAudioSampleRate (int32_t sourceId, int32_t rate )
Description:
Sets the audio sampling rate for recording.
This function must be called after SetAudioSource but before Prepare.
Parameters:
sourceId | Indicates the audio source ID, which can be obtained from SetAudioSource. |
rate | Indicates the sampling rate of the audio per second. |
Returns:
Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.
SetAudioSource()
int32_t OHOS::Media::Recorder::SetAudioSource ([AudioSourceType]($api-api-SmartVision-Devices-MultiMedia_MediaCommon.md#gadc3158e093b995ca7b9b6aa32388ccdd) source, int32_t & sourceId )
Description:
Sets the audio source for recording.
If this function is not called, the output file does not contain the audio track.
Parameters:
source | Indicates the audio source type. For details, see AudioSourceType. |
sourceId | Indicates the audio source ID. The value -1 indicates an invalid ID and the setting fails. |
Returns:
Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.
SetCaptureRate()
int32_t OHOS::Media::Recorder::SetCaptureRate (int32_t sourceId, double fps )
Description:
Sets the video capture rate.
This function must be called after SetVideoSource but before Prepare. It is valid when the video source is YUV or RGB.
Parameters:
sourceId | Indicates the video source ID, which can be obtained from SetVideoSource. |
fps | Indicates the rate at which frames are captured per second. |
Returns:
Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.
SetFileSplitDuration()
int32_t OHOS::Media::Recorder::SetFileSplitDuration ([FileSplitType]($api-api-SmartVision-Devices-MultiMedia_Recorder.md#ga8759c7e5a74964a584a716f4ec0b7edb) type, int64_t timestamp, uint32_t duration )
Description:
Manually splits a video.
This function must be called after Start. After this function is called, the file is split based on the manual split type. After the manual split is complete, the initial split type is used. This function can be called again only after RECORDER_INFO_FILE_SPLIT_FINISHED is reported.
Parameters:
Returns:
Returns SUCCESS if the video is manually split; returns an error code defined in media_errors.h otherwise.
SetMaxDuration()
int32_t OHOS::Media::Recorder::SetMaxDuration (int32_t duration)
Description:
Sets the maximum duration of a recorded file, in seconds.
This method must be called before Prepare. If the setting is valid, RECORDER_INFO_MAX_DURATION_APPROACHING is reported through OnInfo in the RecorderCallback class when only one second or 10% is left to reach the allowed duration. If the recording output file is set by calling SetOutputFile, call SetNextOutputFile to set the next output file. Otherwise, the current file will be overwritten when the allowed duration is reached.
Parameters:
duration | Indicates the maximum recording duration to set. If the value is 0 or a negative number, a failure message is returned. The default duration is 60s. |
Returns:
Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.
SetMaxFileSize()
int32_t OHOS::Media::Recorder::SetMaxFileSize (int64_t size)
Description:
Sets the maximum size of a recorded file, in bytes.
This function must be called before Prepare. If the setting is valid, RECORDER_INFO_MAX_DURATION_APPROACHING is reported through OnInfo in the RecorderCallback class when only 100 KB or 10% is left to reach the allowed size. If the recording output file is set by calling SetOutputFile, call SetNextOutputFile to set the next output file. Otherwise, when the allowed size is reached, the current file will be overwritten. If MaxDuration is also set by calling SetMaxDuration, MaxDuration or MaxFileSize prevails depending on which of them is first satisfied.
Parameters:
Returns:
Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.
SetNextOutputFile()
int32_t OHOS::Media::Recorder::SetNextOutputFile (int32_t fd)
Description:
Sets the FD of the next output file.
If SetOutputFile is successful, call this function to set the FD of the next output file after RECORDER_INFO_MAX_DURATION_APPROACHING or RECORDER_INFO_MAX_FILESIZE_APPROACHING is received.
Parameters:
fd | Indicates the FD of the next output file. |
Returns:
Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.
SetOutputFile()
int32_t OHOS::Media::Recorder::SetOutputFile (int32_t fd)
Description:
Sets the file descriptor (FD) of the output file.
This function must be called before Prepare.
Parameters:
fd | Indicates the FD of the file. |
Returns:
Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.
SetOutputFormat()
int32_t OHOS::Media::Recorder::SetOutputFormat ([OutputFormatType]($api-api-SmartVision-Devices-MultiMedia_Recorder.md#ga3dfe2e61369bf1c081ce569e235354df) format)
Description:
Sets the output file format.
This function must be called before Prepare.
Parameters:
format | Indicates the output file format. For details, see OutputFormatType. |
Returns:
Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.
SetOutputPath()
int32_t OHOS::Media::Recorder::SetOutputPath (const string & path)
Description:
Sets the output file path.
This function must be called before Prepare and One of them SetOutputFile must be set.
Parameters:
path | Indicates the output file path. |
Returns:
Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.
SetParameter()
int32_t OHOS::Media::Recorder::SetParameter (int32_t sourceId, const [Format]($api-api-SmartVision-Devices-OHOS-Media-Format.md) & format )
Description:
Sets an extended parameter for recording, for example, RCORDER_PRE_CACHE_DURATION.
Parameters:
sourceId | Indicates the data source ID. The value -1 indicates all sources. |
format | Indicates the string key and value. For details, see Format and RCORDER_PRE_CACHE_DURATION. |
Returns:
Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.
SetRecorderCallback()
int32_t OHOS::Media::Recorder::SetRecorderCallback (const std::shared_ptr< [RecorderCallback]($api-api-SmartVision-Devices-OHOS-Media-RecorderCallback.md) > & callback)
Description:
Registers a recording listener.
This function must be called before Prepare.
Parameters:
callback | Indicates the recording listener to register. For details, see RecorderCallback. |
Returns:
Returns SUCCESS if the listener is registered; returns an error code defined in media_errors.h otherwise.
SetVideoEncoder()
int32_t OHOS::Media::Recorder::SetVideoEncoder (int32_t sourceId, [VideoCodecFormat]($api-api-SmartVision-Devices-MultiMedia_MediaCommon.md#ga797e6c5e38e23e730eff5bcc41427d7e) encoder )
Description:
Sets a video encoder for recording.
If this function is not called, the output file does not contain the video track. This function must be called after SetVideoSource but before Prepare.
Parameters:
sourceId | Indicates the video source ID, which can be obtained from SetVideoSource. |
encoder | Indicates the video encoder to set. |
Returns:
Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.
SetVideoEncodingBitRate()
int32_t OHOS::Media::Recorder::SetVideoEncodingBitRate (int32_t sourceId, int32_t rate )
Description:
Sets the encoding bit rate of the video to record.
This function must be called after SetVideoSource but before Prepare.
Parameters:
sourceId | Indicates the video source ID, which can be obtained from SetVideoSource. |
rate | Indicates the encoding bit rate to set. |
Returns:
Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.
SetVideoFrameRate()
int32_t OHOS::Media::Recorder::SetVideoFrameRate (int32_t sourceId, int32_t frameRate )
Description:
Sets the frame rate of the video to record.
This function must be called after SetVideoSource but before Prepare.
Parameters:
sourceId | Indicates the video source ID, which can be obtained from SetVideoSource. |
frameRate | Indicates the frame rate to set. |
Returns:
Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.
SetVideoSize()
int32_t OHOS::Media::Recorder::SetVideoSize (int32_t sourceId, int32_t width, int32_t height )
Description:
Sets the width and height of the video to record.
This function must be called after SetVideoSource but before Prepare.
Parameters:
sourceId | Indicates the video source ID, which can be obtained from SetVideoSource. |
width | Indicates the video width to set. |
height | Indicates the video height to set. |
Returns:
Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.
SetVideoSource()
int32_t OHOS::Media::Recorder::SetVideoSource ([VideoSourceType]($api-api-SmartVision-Devices-MultiMedia_Recorder.md#gad252d27f9ce4b6ae0756bfeaa5f34490) source, int32_t & sourceId )
Description:
Sets a video source for recording.
If this function is not called, the output file does not contain the video track.
Parameters:
source | Indicates the video source type. For details, see VideoSourceType. |
sourceId | Indicates the video source ID. The value -1 indicates an invalid ID and the setting fails. |
Returns:
Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.
Start()
int32_t OHOS::Media::Recorder::Start ()
Description:
Starts recording.
This function must be called after Prepare.
Returns:
Returns SUCCESS if the recording is started; returns an error code defined in media_errors.h otherwise.
Stop()
int32_t OHOS::Media::Recorder::Stop (bool block)
Description:
Stops recording.
Parameters:
Returns:
Returns SUCCESS if the recording is stopped; returns an error code defined in media_errors.h otherwise.
Variable Documentation
RCORDER_PRE_CACHE_DURATION
const string OHOS::Media::RCORDER_PRE_CACHE_DURATION = "pre-cache-duration"
Description:
This constant can be used as the value of Format in SetParameter to configure the duration for storing recorded data in the cache.