- MultiMedia_AudioCapturer
- Overview
- Summary
- Files
- Data Structures
- Enumerations
- Functions
- Details
- Enumeration Type Documentation
- State
- Timebase
- Function Documentation
- GetAudioTime()
- GetCapturerInfo()
- GetFrameCount()
- GetMinFrameCount()
- GetStatus()
- Read()
- Release()
- SetCapturerInfo()
- Start()
- Stop()
- Variable Documentation
- audioFormat
- bitRate
- bitWidth
- channelCount
- inputSource
- sampleRate
- streamType
MultiMedia_AudioCapturer
Overview
Declares APIs in the AudioCapturer class for audio capture.
Since:
1.0
Version:
1.0
Summary
Files
Provides the AudioCapturer class to implement operations related to audio capture. |
Data Structures
Enumerations
OHOS::Audio::Timestamp::Timebase : int32_t { OHOS::Audio::Timestamp::Timebase::MONOTONIC = 0, OHOS::Audio::Timestamp::Timebase::BOOTTIME = 1 } |
Enumerates the time base of this Timestamp. Different timing methods are supported. |
OHOS::Audio::State : uint32_t { OHOS::Audio::PREPPARED, OHOS::Audio::RECORDING, OHOS::Audio::STOPPED, OHOS::Audio::RELEASED } |
Functions
OHOS::Audio::AudioCapturer::GetMinFrameCount (int32_t sampleRate, int32_t channelCount, AudioCodecFormat audioFormat, size_t &frameCount) |
Obtains the minimum number of frames required in a specified condition, in bytes per sample. |
Obtains the number of frames required in the current condition, in bytes per sample. |
|
OHOS::Audio::AudioCapturer::SetCapturerInfo (const AudioCapturerInfo info) |
|
OHOS::Audio::AudioCapturer::GetCapturerInfo (AudioCapturerInfo &info) |
|
OHOS::Audio::AudioCapturer::Read (uint8_t *buffer, size_t userSize, bool isBlockingRead) |
|
OHOS::Audio::AudioCapturer::GetAudioTime (Timestamp ×tamp, Timestamp::Timebase base) |
|
Releases a local AudioCapturer object. |
Details
Enumeration Type Documentation
State
enum [OHOS::Audio::State]($api-api-SmartVision-Devices-MultiMedia_AudioCapturer.md#ga3d8d6798a2346e57e241d16da673d508) : uint32_t
Description:
Enumerates the recording states of the current device.
PREPPARED | |
RECORDING | |
STOPPED | |
RELEASED |
Timebase
enum [OHOS::Audio::Timestamp::Timebase]($api-api-SmartVision-Devices-MultiMedia_AudioCapturer.md#gacdafb362a7da91799fa96163bca2a619) : int32_t
Description:
Enumerates the time base of this Timestamp. Different timing methods are supported.
MONOTONIC | Monotonically increasing time, excluding the system sleep time |
BOOTTIME | Monotonically increasing time, including the system sleep time |
Function Documentation
GetAudioTime()
bool OHOS::Audio::AudioCapturer::GetAudioTime ([Timestamp]($api-api-SmartVision-Devices-OHOS-Audio-Timestamp.md) & timestamp, [Timestamp::Timebase]($api-api-SmartVision-Devices-MultiMedia_AudioCapturer.md#gacdafb362a7da91799fa96163bca2a619) base )
Description:
Obtains the timestamp.
Parameters:
timestamp | Indicates a Timestamp instance reference provided by the caller. |
base | Indicates the time base, which can be Timestamp.Timebase.BOOTTIME or Timestamp.Timebase.MONOTONIC. |
Returns:
Returns true if the timestamp is successfully obtained; returns false otherwise.
GetCapturerInfo()
int32_t OHOS::Audio::AudioCapturer::GetCapturerInfo ([AudioCapturerInfo]($api-api-SmartVision-Devices-OHOS-Audio-AudioCapturerInfo.md) & info)
Description:
Obtains audio capture parameters.
This function can be called after SetCapturerInfo is successful.
Parameters:
info | Indicates information about audio capture parameters. For details, see AudioCapturerInfo. |
Returns:
Returns SUCCESS if the parameter information is successfully obtained; returns an error code defined in media_errors.h otherwise.
GetFrameCount()
uint64_t OHOS::Audio::AudioCapturer::GetFrameCount ()
Description:
Obtains the number of frames required in the current condition, in bytes per sample.
Returns:
Returns the number of frames (in bytes per sample) if the operation is successful; returns -1 if an exception occurs.
GetMinFrameCount()
static bool OHOS::Audio::AudioCapturer::GetMinFrameCount (int32_t sampleRate, int32_t channelCount, [AudioCodecFormat]($api-api-SmartVision-Devices-MultiMedia_MediaCommon.md#gaa4ea6f314644ed287e0704be26c768b7) audioFormat, size_t & frameCount )
Description:
Obtains the minimum number of frames required in a specified condition, in bytes per sample.
Parameters:
sampleRate | Indicates the audio sampling rate, in Hz. |
channelCount | Indicates the number of audio recording channels. |
audioFormat | Indicates the audio data format. |
frameCount | Indicates the minimum number of frames, in bytes per sample. |
Returns:
Returns true if the minimum number of frames is successfully obtained; returns false otherwise.
GetStatus()
[State]($api-api-SmartVision-Devices-MultiMedia_AudioCapturer.md#ga3d8d6798a2346e57e241d16da673d508) OHOS::Audio::AudioCapturer::GetStatus ()
Description:
Obtains the audio capture state.
Returns:
Returns the audio capture state defined in State.
Read()
int32_t OHOS::Audio::AudioCapturer::Read (uint8_t * buffer, size_t userSize, bool isBlockingRead )
Description:
Reads audio data.
Parameters:
buffer | Indicates the pointer to the buffer into which the audio data is to be written. |
userSize | Indicates the size of the buffer into which the audio data is to be written, in bytes. userSize >= frameCount channelCount BytesPerSample must evaluate to true. You can call GetFrameCount to obtain the frameCount value. |
isBlockingRead | Specifies whether data reading will be blocked. |
Returns:
Returns the size of the audio data read from the device. The value ranges from 0 to userSize. If the reading fails, one of the following error codes is returned: ERR_INVALID_PARAM: The input parameter is incorrect. ERR_ILLEGAL_STATE: The AudioCapturer instance is not initialized. ERR_SOURCE_NOT_SET: The state of hardware device instance is abnormal.
Release()
bool OHOS::Audio::AudioCapturer::Release ()
Description:
Releases a local AudioCapturer object.
Returns:
Returns true if the object is successfully released; returns false otherwise.
SetCapturerInfo()
int32_t OHOS::Audio::AudioCapturer::SetCapturerInfo (const [AudioCapturerInfo]($api-api-SmartVision-Devices-OHOS-Audio-AudioCapturerInfo.md) info)
Description:
Sets audio capture parameters.
Parameters:
info | Indicates information about audio capture parameters to set. For details, see AudioCapturerInfo. |
Returns:
Returns SUCCESS if the setting is successful; returns an error code defined in media_errors.h otherwise.
Start()
bool OHOS::Audio::AudioCapturer::Start ()
Description:
Starts audio recording.
Returns:
Returns true if the recording is successfully started; returns false otherwise.
Stop()
bool OHOS::Audio::AudioCapturer::Stop ()
Description:
Stops audio recording.
Returns:
Returns true if the recording is successfully stopped; returns false otherwise.
Variable Documentation
audioFormat
[AudioCodecFormat]($api-api-SmartVision-Devices-MultiMedia_MediaCommon.md#gaa4ea6f314644ed287e0704be26c768b7) OHOS::Audio::AudioCapturerInfo::audioFormat = [AUDIO_DEFAULT](MultiMedia_MediaCommon.md#ggaa4ea6f314644ed287e0704be26c768b7a4c4c5829b054bc468274700c56d65546)
Description:
Audio codec format
bitRate
int32_t OHOS::Audio::AudioCapturerInfo::bitRate = 0
Description:
Bit rate
bitWidth
[AudioBitWidth](MultiMedia_MediaCommon.md#gae3e35ee2a2222a667fdebbc5b793ca7c) OHOS::Audio::AudioCapturerInfo::bitWidth = [BIT_WIDTH_16](MultiMedia_MediaCommon.md#ggae3e35ee2a2222a667fdebbc5b793ca7ca036f0b45813f96cb6b0f90de1722a780)
Description:
Bit width
channelCount
int32_t OHOS::Audio::AudioCapturerInfo::channelCount = 0
Description:
Number of audio channels
inputSource
[AudioSourceType](MultiMedia_MediaCommon.md#gadc3158e093b995ca7b9b6aa32388ccdd) OHOS::Audio::AudioCapturerInfo::inputSource = [AUDIO_MIC](MultiMedia_MediaCommon.md#ggadc3158e093b995ca7b9b6aa32388ccdda732604b3a24d137429e2b83b31849bce)
Description:
Audio source type
sampleRate
int32_t OHOS::Audio::AudioCapturerInfo::sampleRate = 0
Description:
Sampling rate
streamType
[AudioStreamType](MultiMedia_MediaCommon.md#gae7077e4211e48131ae544adb20fc494a) OHOS::Audio::AudioCapturerInfo::streamType = [TYPE_MEDIA](MultiMedia_MediaCommon.md#ggae7077e4211e48131ae544adb20fc494aa431e273affaa22e18ec5a2a548b70e90)
Description:
Audio stream type