MultiMedia_Recorder
Since:
1.0
Version:
1.0
Summary
Files
Data Structures
Provides listeners for recording errors and information events. |
|
Enumerations
: int32_t { OHOS::Media::VIDEO_SOURCE_SURFACE_YUV = 0, , OHOS::Media::VIDEO_SOURCE_SURFACE_ES, } |
|
OHOS::Media::DataSourceType : int32_t { = 0 } |
|
OHOS::Media::OutputFormatType : int32_t { = 0, OHOS::Media::FORMAT_MPEG_4, } |
|
OHOS::Media::FileSplitType : int32_t { = 0, OHOS::Media::FILE_SPLIT_PRE, } |
|
OHOS::Media::RecorderCallback::RecorderInfoType : int32_t { = 0, OHOS::Media::RecorderCallback::RECORDER_INFO_MAX_FILESIZE_APPROACHING, , OHOS::Media::RecorderCallback::RECORDER_INFO_MAX_FILESIZE_REACHED, , OHOS::Media::RecorderCallback::RECORDER_INFO_FILE_SPLIT_FINISHED, } |
|
OHOS::Media::RecorderCallback::RecorderErrorType : int32_t { = 0 } |
Functions
OHOS::Media::RecorderCallback::OnError (int32_t errorType, int32_t errorCode)=0 |
Called when an error occurs during recording. This callback is used to report recording errors. |
Called when an information event occurs during recording. This callback is used to report recording information. |
|
OHOS::Media::Recorder::SetVideoSource ( source, int32_t &sourceId) |
|
OHOS::Media::Recorder::SetVideoEncoder (int32_t sourceId, encoder) |
|
OHOS::Media::Recorder::SetVideoSize (int32_t sourceId, int32_t width, int32_t height) |
|
OHOS::Media::Recorder::SetVideoEncodingBitRate (int32_t sourceId, int32_t rate) |
|
OHOS::Media::Recorder::GetSurface (int32_t sourceId) |
|
OHOS::Media::Recorder::SetAudioSource ( source, int32_t &sourceId) |
|
OHOS::Media::Recorder::SetAudioEncoder (int32_t sourceId, encoder) |
|
OHOS::Media::Recorder::SetAudioSampleRate (int32_t sourceId, int32_t rate) |
|
OHOS::Media::Recorder::SetAudioEncodingBitRate (int32_t sourceId, int32_t bitRate) |
|
OHOS::Media::Recorder::SetOutputFormat ( format) |
|
OHOS::Media::Recorder::SetOutputPath (const string &path) |
|
OHOS::Media::Recorder::SetNextOutputFile (int32_t fd) |
|
OHOS::Media::Recorder::SetRecorderCallback (const std::shared_ptr< > &callback) |
|
OHOS::Media::Recorder::Stop (bool block) |
|
(FileSplitType type, int64_t timestamp, uint32_t duration) |
|
(int32_t sourceId, const Format &format) |
Sets an extended parameter for recording, for example, RCORDER_PRE_CACHE_DURATION. |
Details
Enumeration Type Documentation
DataSourceType
Description:
Enumerates data source types.
IMAGE |
FileSplitType
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 | |
VIDEO_SOURCE_SURFACE_ES | Raw encoded data provided through Surface |
VIDEO_SOURCE_BUTT |
Function Documentation
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 . |
Returns:
Returns the pointer to the surface.
OnError()
Description:
Called when an error occurs during recording. This callback is used to report recording errors.
Parameters:
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 otherwise.
Prepare()
int32_t OHOS::Media::Recorder::Prepare ()
Description:
Prepares for recording.
This function must be called before .
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()
Description:
Resets the recording.
After the function is called, add a recording source by calling SetVideoSource or , set related parameters, and call Start to start recording again after is called.
Returns:
Returns SUCCESS if the recording is reset; returns an error code defined in media_errors.h otherwise.
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 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 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 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 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 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 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 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 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 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 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 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 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.
Parameters:
Returns:
Returns SUCCESS if the video is manually split; returns an error code defined in media_errors.h otherwise.
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 . 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 , 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 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 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:
Returns:
Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.
SetOutputFile()
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()
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 must be set.
Parameters:
path | Indicates the output file path. |
Returns:
Returns SUCCESS if the setting is successful; returns an error code defined in 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 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 .
Parameters:
callback | Indicates the recording listener to register. For details, see . |
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 .
Parameters:
sourceId | Indicates the video source ID, which can be obtained from . |
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 .
Parameters:
sourceId | Indicates the video source ID, which can be obtained from . |
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 .
Parameters:
sourceId | Indicates the video source ID, which can be obtained from . |
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 .
Parameters:
sourceId | Indicates the video source ID, which can be obtained from . |
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 otherwise.
Start()
int32_t OHOS::Media::Recorder::Start ()
Description:
Starts recording.
This function must be called after .
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 otherwise.
RCORDER_PRE_CACHE_DURATION
Description: