MultiMedia_AudioCapturer

Overview

Declares APIs in the AudioCapturer class for audio capture.

Since:

1.0

Version:

1.0

Summary

Files

File Name

Description

audio_capturer.h

Provides the AudioCapturer class to implement operations related to audio capture.

Data Structures

Data Structure Name

Description

OHOS::Audio::AudioCapturerInfo

Defines information about audio capture parameters, including the input source, audio codec format,sampling rate (Hz), number of audio channels, bit rate, and bit width.

OHOS::Audio::Timestamp

Represents timestamp information, including the frame position information and high-resolution time source.

OHOS::Audio::AudioCapturer

Provides functions for applications to implement audio capturing.

Enumerations

Enumeration Name

Description

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 }

Enumerates the recording states of the current device.

Functions

Function Name

Description

OHOS::Audio::AudioCapturer::GetMinFrameCount (int32_t sampleRate, int32_t channelCount, AudioCodecFormat audioFormat, size_t &frameCount)

static bool 

Obtains the minimum number of frames required in a specified condition, in bytes per sample.

OHOS::Audio::AudioCapturer::GetFrameCount ()

uint64_t 

Obtains the number of frames required in the current condition, in bytes per sample.

OHOS::Audio::AudioCapturer::SetCapturerInfo (const AudioCapturerInfo info)

int32_t 

Sets audio capture parameters.

OHOS::Audio::AudioCapturer::GetCapturerInfo (AudioCapturerInfo &info)

int32_t 

Obtains audio capture parameters.

OHOS::Audio::AudioCapturer::Start ()

bool 

Starts audio recording.

OHOS::Audio::AudioCapturer::Read (uint8_t *buffer, size_t userSize, bool isBlockingRead)

int32_t 

Reads audio data.

OHOS::Audio::AudioCapturer::GetStatus ()

State 

Obtains the audio capture state.

OHOS::Audio::AudioCapturer::GetAudioTime (Timestamp &timestamp, Timestamp::Timebase base)

bool 

Obtains the timestamp.

OHOS::Audio::AudioCapturer::Stop ()

bool 

Stops audio recording.

OHOS::Audio::AudioCapturer::Release ()

bool 

Releases a local AudioCapturer object.

Details

Enumeration Type Documentation

State

  1. enum[OHOS::Audio::State]($api-api-SmartVision-Devices-MultiMedia_AudioCapturer.md#ga3d8d6798a2346e57e241d16da673d508) : uint32_t

Description:

Enumerates the recording states of the current device.

Enumerator

Description

PREPPARED 

Prepared

RECORDING 

Recording

STOPPED 

Stopped

RELEASED 

Released

Timebase

  1. 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.

Enumerator

Description

MONOTONIC 

Monotonically increasing time, excluding the system sleep time

BOOTTIME 

Monotonically increasing time, including the system sleep time

Function Documentation

GetAudioTime()

  1. 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:

Name

Description

timestampIndicates a Timestamp instance reference provided by the caller.
baseIndicates 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()

  1. 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:

Name

Description

infoIndicates 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()

  1. 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()

  1. staticbool 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:

Name

Description

sampleRateIndicates the audio sampling rate, in Hz.
channelCountIndicates the number of audio recording channels.
audioFormatIndicates the audio data format.
frameCountIndicates 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()

  1. [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()

  1. int32_t OHOS::Audio::AudioCapturer::Read(uint8_t* buffer,size_t userSize,bool isBlockingRead )

Description:

Reads audio data.

Parameters:

Name

Description

bufferIndicates the pointer to the buffer into which the audio data is to be written.
userSizeIndicates 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.
isBlockingReadSpecifies 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()

  1. bool OHOS::Audio::AudioCapturer::Release()

Description:

Releases a local AudioCapturer object.

Returns:

Returns true if the object is successfully released; returns false otherwise.

SetCapturerInfo()

  1. int32_t OHOS::Audio::AudioCapturer::SetCapturerInfo(const[AudioCapturerInfo]($api-api-SmartVision-Devices-OHOS-Audio-AudioCapturerInfo.md) info)

Description:

Sets audio capture parameters.

Parameters:

Name

Description

infoIndicates 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()

  1. bool OHOS::Audio::AudioCapturer::Start()

Description:

Starts audio recording.

Returns:

Returns true if the recording is successfully started; returns false otherwise.

Stop()

  1. bool OHOS::Audio::AudioCapturer::Stop()

Description:

Stops audio recording.

Returns:

Returns true if the recording is successfully stopped; returns false otherwise.

Variable Documentation

audioFormat

  1. [AudioCodecFormat]($api-api-SmartVision-Devices-MultiMedia_MediaCommon.md#gaa4ea6f314644ed287e0704be26c768b7) OHOS::Audio::AudioCapturerInfo::audioFormat = [AUDIO_DEFAULT](MultiMedia_MediaCommon.md#ggaa4ea6f314644ed287e0704be26c768b7a4c4c5829b054bc468274700c56d65546)

Description:

Audio codec format

bitRate

  1. int32_t OHOS::Audio::AudioCapturerInfo::bitRate =0

Description:

Bit rate

bitWidth

  1. [AudioBitWidth](MultiMedia_MediaCommon.md#gae3e35ee2a2222a667fdebbc5b793ca7c) OHOS::Audio::AudioCapturerInfo::bitWidth = [BIT_WIDTH_16](MultiMedia_MediaCommon.md#ggae3e35ee2a2222a667fdebbc5b793ca7ca036f0b45813f96cb6b0f90de1722a780)

Description:

Bit width

channelCount

  1. int32_t OHOS::Audio::AudioCapturerInfo::channelCount =0

Description:

Number of audio channels

inputSource

  1. [AudioSourceType](MultiMedia_MediaCommon.md#gadc3158e093b995ca7b9b6aa32388ccdd) OHOS::Audio::AudioCapturerInfo::inputSource = [AUDIO_MIC](MultiMedia_MediaCommon.md#ggadc3158e093b995ca7b9b6aa32388ccdda732604b3a24d137429e2b83b31849bce)

Description:

Audio source type

sampleRate

  1. int32_t OHOS::Audio::AudioCapturerInfo::sampleRate =0

Description:

Sampling rate

streamType

  1. [AudioStreamType](MultiMedia_MediaCommon.md#gae7077e4211e48131ae544adb20fc494a) OHOS::Audio::AudioCapturerInfo::streamType = [TYPE_MEDIA](MultiMedia_MediaCommon.md#ggae7077e4211e48131ae544adb20fc494aa431e273affaa22e18ec5a2a548b70e90)

Description:

Audio stream type