native_audiocapturer.h
Overview
The file declares the functions related to an audio capturer.
File to include: <ohaudio/native_audiocapturer.h>
Library: libohaudio.so
System capability: SystemCapability.Multimedia.Audio.Core
Since: 10
Related module: OHAudio
Summary
Functions
Function Description
OH_AudioCapturer_Release()
OH_AudioStream_Result OH_AudioCapturer_Release(OH_AudioCapturer* capturer)
Description
Releases an audio capturer.
Required permissions: ohos.permission.MICROPHONE
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioCapturer* capturer | Pointer to an audio capturer instance, which is created by calling OH_AudioStreamBuilder_GenerateCapturer. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: The capturer parameter is nullptr. AUDIOSTREAM_ERROR_ILLEGAL_STATE: The execution status is abnormal. |
OH_AudioCapturer_Start()
OH_AudioStream_Result OH_AudioCapturer_Start(OH_AudioCapturer* capturer)
Description
Starts an audio capturer to start capturing audio data.
Required permissions: ohos.permission.MICROPHONE
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioCapturer* capturer | Pointer to an audio capturer instance, which is created by calling OH_AudioStreamBuilder_GenerateCapturer. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: The capturer parameter is nullptr. AUDIOSTREAM_ERROR_ILLEGAL_STATE: The execution status is abnormal. |
OH_AudioCapturer_Pause()
OH_AudioStream_Result OH_AudioCapturer_Pause(OH_AudioCapturer* capturer)
Description
Pauses an audio capturer. You are advised to use the pause function if you need to resume audio recording later.
Required permissions: ohos.permission.MICROPHONE
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioCapturer* capturer | Pointer to an audio capturer instance, which is created by calling OH_AudioStreamBuilder_GenerateCapturer. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: The capturer parameter is nullptr. AUDIOSTREAM_ERROR_ILLEGAL_STATE: The execution status is abnormal. |
OH_AudioCapturer_Stop()
OH_AudioStream_Result OH_AudioCapturer_Stop(OH_AudioCapturer* capturer)
Description
Stops an audio capturer, ceasing the input audio stream. You are advised to use the stop function if you need to terminate recording completely.
Required permissions: ohos.permission.MICROPHONE
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioCapturer* capturer | Pointer to an audio capturer instance, which is created by calling OH_AudioStreamBuilder_GenerateCapturer. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: The capturer parameter is nullptr. AUDIOSTREAM_ERROR_ILLEGAL_STATE: The execution status is abnormal. |
OH_AudioCapturer_Flush()
OH_AudioStream_Result OH_AudioCapturer_Flush(OH_AudioCapturer* capturer)
Description
Flushes audio data captured by an audio capturer.
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioCapturer* capturer | Pointer to an audio capturer instance, which is created by calling OH_AudioStreamBuilder_GenerateCapturer. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: The capturer parameter is nullptr. AUDIOSTREAM_ERROR_ILLEGAL_STATE: The execution status is abnormal. |
OH_AudioCapturer_GetCurrentState()
OH_AudioStream_Result OH_AudioCapturer_GetCurrentState(OH_AudioCapturer* capturer, OH_AudioStream_State* state)
Description
Obtains the state of an audio capturer.
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioCapturer* capturer | Pointer to an audio capturer instance, which is created by calling OH_AudioStreamBuilder_GenerateCapturer. |
| OH_AudioStream_State* state | Pointer to a variable used to receive the state. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: The capturer parameter is nullptr. |
OH_AudioCapturer_GetLatencyMode()
OH_AudioStream_Result OH_AudioCapturer_GetLatencyMode(OH_AudioCapturer* capturer,OH_AudioStream_LatencyMode* latencyMode)
Description
Obtains the latency mode of an audio capturer.
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioCapturer* capturer | Pointer to an audio capturer instance, which is created by calling OH_AudioStreamBuilder_GenerateCapturer. |
| OH_AudioStream_LatencyMode* latencyMode | Pointer to a variable used to receive the latency mode. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: The capturer parameter is nullptr. |
OH_AudioCapturer_GetStreamId()
OH_AudioStream_Result OH_AudioCapturer_GetStreamId(OH_AudioCapturer* capturer, uint32_t* streamId)
Description
Obtains the stream ID of an audio capturer.
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioCapturer* capturer | Pointer to an audio capturer instance, which is created by calling OH_AudioStreamBuilder_GenerateCapturer. |
| uint32_t* streamId | Pointer to a variable used to receive the stream ID. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: The capturer parameter is nullptr. |
OH_AudioCapturer_GetSamplingRate()
OH_AudioStream_Result OH_AudioCapturer_GetSamplingRate(OH_AudioCapturer* capturer, int32_t* rate)
Description
Obtains the sampling rate of an audio capturer.
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioCapturer* capturer | Pointer to an audio capturer instance, which is created by calling OH_AudioStreamBuilder_GenerateCapturer. |
| int32_t* rate | Pointer to a variable used to receive the sampling rate. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: The capturer parameter is nullptr. |
OH_AudioCapturer_GetChannelCount()
OH_AudioStream_Result OH_AudioCapturer_GetChannelCount(OH_AudioCapturer* capturer, int32_t* channelCount)
Description
Obtains the number of channels for an audio capturer.
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioCapturer* capturer | Pointer to an audio capturer instance, which is created by calling OH_AudioStreamBuilder_GenerateCapturer. |
| int32_t* channelCount | Pointer to a variable used to receive the channel count. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: The capturer parameter is nullptr. |
OH_AudioCapturer_GetSampleFormat()
OH_AudioStream_Result OH_AudioCapturer_GetSampleFormat(OH_AudioCapturer* capturer,OH_AudioStream_SampleFormat* sampleFormat)
Description
Obtains the sampling format of an audio capturer.
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioCapturer* capturer | Pointer to an audio capturer instance, which is created by calling OH_AudioStreamBuilder_GenerateCapturer. |
| OH_AudioStream_SampleFormat* sampleFormat | Pointer to a variable used to receive the sampling format. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: The capturer parameter is nullptr. |
OH_AudioCapturer_GetEncodingType()
OH_AudioStream_Result OH_AudioCapturer_GetEncodingType(OH_AudioCapturer* capturer,OH_AudioStream_EncodingType* encodingType)
Description
Obtains the encoding type of an audio capturer.
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioCapturer* capturer | Pointer to an audio capturer instance, which is created by calling OH_AudioStreamBuilder_GenerateCapturer. |
| OH_AudioStream_EncodingType* encodingType | Pointer to a variable used to receive the encoding type. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: The capturer parameter is nullptr. |
OH_AudioCapturer_GetCapturerInfo()
OH_AudioStream_Result OH_AudioCapturer_GetCapturerInfo(OH_AudioCapturer* capturer,OH_AudioStream_SourceType* sourceType)
Description
Obtains the usage scenario of an audio capturer.
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioCapturer* capturer | Pointer to an audio capturer instance, which is created by calling OH_AudioStreamBuilder_GenerateCapturer. |
| OH_AudioStream_SourceType* sourceType | Pointer to a variable used to receive the usage scenario. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: The capturer parameter is nullptr. |
OH_AudioCapturer_GetFrameSizeInCallback()
OH_AudioStream_Result OH_AudioCapturer_GetFrameSizeInCallback(OH_AudioCapturer* capturer,int32_t* frameSize)
Description
Obtains the frame size in the callback. The frame size is the fixed length of the buffer returned by each callback.
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioCapturer* capturer | Pointer to an audio capturer instance, which is created by calling OH_AudioStreamBuilder_GenerateCapturer. |
| int32_t* frameSize | Pointer to a variable used to receive the frame size. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: The capturer parameter is nullptr. AUDIOSTREAM_ERROR_ILLEGAL_STATE: The execution status is abnormal. |
OH_AudioCapturer_GetTimestamp()
OH_AudioStream_Result OH_AudioCapturer_GetTimestamp(OH_AudioCapturer* capturer, clockid_t clockId,int64_t* framePosition, int64_t* timestamp)
Description
Obtains the information about the input audio stream timestamp and the current data frame position.
This function obtains the actual recording position (specified by framePosition) of the audio channel and the timestamp when recording to that position (specified by timestamp, in nanoseconds).
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioCapturer* capturer | Pointer to an audio capturer instance, which is created by calling OH_AudioStreamBuilder_GenerateCapturer. |
| clockid_t clockId | Clock identifier. Use CLOCK_MONOTONIC. |
| int64_t* framePosition | Pointer to a variable used to receive the position information. |
| int64_t* timestamp | Pointer to a variable used to receive the timestamp, in nanoseconds. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: 1. The capturer parameter is nullptr. 2. The clockId parameter is invalid. AUDIOSTREAM_ERROR_ILLEGAL_STATE: The execution status is abnormal. |
OH_AudioCapturer_GetFramesRead()
OH_AudioStream_Result OH_AudioCapturer_GetFramesRead(OH_AudioCapturer* capturer, int64_t* frames)
Description
Obtains the number of frames that have been read since the stream was created.
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioCapturer* capturer | Pointer to an audio capturer instance, which is created by calling OH_AudioStreamBuilder_GenerateCapturer. |
| int64_t* frames | Pointer to a variable used to receive the frame count. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: The capturer parameter is nullptr. |
OH_AudioCapturer_GetOverflowCount()
OH_AudioStream_Result OH_AudioCapturer_GetOverflowCount(OH_AudioCapturer* capturer, uint32_t* count)
Description
Obtains the number of overloaded audio streams of an audio capturer.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_AudioCapturer* capturer | Pointer to an audio capturer instance, which is created by calling OH_AudioStreamBuilder_GenerateCapturer. |
| uint32_t* count | Pointer to a variable used to receive the number of overloaded audio streams. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: The capturer parameter is nullptr. |
OH_AudioCapturer_OnReadDataCallback()
typedef void (*OH_AudioCapturer_OnReadDataCallback)(OH_AudioCapturer* capturer, void* userData, void* audioData,int32_t audioDataSize)
Description
Defines the callback used to read audio data. To eliminate power-on noise caused by the microphone hardware design, the first 100 ms of data after recording starts is typically muted.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_AudioCapturer* capturer | Pointer to an audio capturer instance, which is created by calling OH_AudioStreamBuilder_GenerateCapturer. |
| void* userData | Pointer to the data storage region customized by an application, allowing the application to transfer data to itself. |
| void* audioData | Pointer to the captured data storage area, which is used by the application to read captured data. |
| int32_t audioDataSize | Length of the captured data, in bytes. |
OH_AudioCapturer_OnDeviceChangeCallback()
typedef void (*OH_AudioCapturer_OnDeviceChangeCallback)(OH_AudioCapturer* capturer, void* userData,OH_AudioDeviceDescriptorArray* deviceArray)
Description
Defines the callback for audio capturer device change events.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_AudioCapturer* capturer | Pointer to an audio capturer instance, which is created by calling OH_AudioStreamBuilder_GenerateCapturer. |
| void* userData | Pointer to the data storage area customized by the application. |
| OH_AudioDeviceDescriptorArray* deviceArray | Pointer to the audio device descriptors in the array. |
OH_AudioCapturer_OnInterruptCallback()
typedef void (*OH_AudioCapturer_OnInterruptCallback)(OH_AudioCapturer* capturer, void* userData,OH_AudioInterrupt_ForceType type, OH_AudioInterrupt_Hint hint)
Description
Defines the callback for interruption events of an audio capturer.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_AudioCapturer* capturer | Pointer to an audio capturer instance, which is created by calling OH_AudioStreamBuilder_GenerateCapturer. |
| void* userData | Pointer to the data storage area customized by the application. |
| OH_AudioInterrupt_ForceType type | Type of force that causes audio interruption. |
| OH_AudioInterrupt_Hint hint | Hint provided along with audio interruption. |
OH_AudioCapturer_OnErrorCallback()
typedef void (*OH_AudioCapturer_OnErrorCallback)(OH_AudioCapturer* capturer, void* userData,OH_AudioStream_Result error)
Description
Defines the callback for error events of an audio capturer.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_AudioCapturer* capturer | Pointer to an audio capturer instance, which is created by calling OH_AudioStreamBuilder_GenerateCapturer. |
| void* userData | Pointer to the data storage area customized by the application. |
| OH_AudioStream_Result error | Audio capturer error. |
OH_AudioCapturer_GetFastStatus()
OH_AudioStream_Result OH_AudioCapturer_GetFastStatus(OH_AudioCapturer* capturer,OH_AudioStream_FastStatus* status)
Description
Obtains the running status of an audio capturer to determine whether it is running in low-latency mode.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_AudioCapturer* capturer | Pointer to an audio capturer instance, which is created by calling OH_AudioStreamBuilder_GenerateCapturer. |
| OH_AudioStream_FastStatus* status | Pointer to the running status. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: The capturer parameter is nullptr. AUDIOSTREAM_ERROR_ILLEGAL_STATE: The function is called in an incorrect state. |
OH_AudioCapturer_OnFastStatusChange()
typedef void (*OH_AudioCapturer_OnFastStatusChange)(OH_AudioCapturer* capturer,void* userData,OH_AudioStream_FastStatus status)
Description
Defines a callback function for low-latency status changes during audio recording.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_AudioCapturer* capturer | Pointer to an audio capturer instance, which is created by calling OH_AudioStreamBuilder_GenerateCapturer. |
| void* userData | Pointer to the data storage area customized by the application. |
| OH_AudioStream_FastStatus status | Low-latency status. |
OH_AudioCapturer_OnPlaybackCaptureStartCallback()
typedef void (*OH_AudioCapturer_OnPlaybackCaptureStartCallback)(OH_AudioCapturer* capturer, void* userData, OH_AudioStream_PlaybackCaptureStartState state)
Description
Defines the callback function for the starting result of internal audio recording (capturing sound from the applications on the device) during audio recording. This API is currently not available for public use.
Since: 23
Parameters
| Name | Description |
|---|---|
| OH_AudioCapturer* capturer | Pointer to an audio capturer instance, which is created by calling OH_AudioStreamBuilder_GenerateCapturer. |
| void* userData | Pointer to the custom data storage region of an application via OH_AudioCapturer_RequestPlaybackCaptureStart. |
| OH_AudioStream_PlaybackCaptureStartState state | Whether the internal recording request is successful. |
OH_AudioCapturer_RequestPlaybackCaptureStart()
OH_AudioStream_Result OH_AudioCapturer_RequestPlaybackCaptureStart(OH_AudioCapturer* capturer, OH_AudioCapturer_OnPlaybackCaptureStartCallback callback, void* userData)
Description
Asynchronously requests to start the internal recording stream. This API works in non-blocking mode, which means that the system continues to process user authorization and start the internal recording stream after receiving a start request.
The final result is returned through a callback. This API is currently not available for public use.
Since: 23
Parameters
| Name | Description |
|---|---|
| OH_AudioCapturer* capturer | Pointer to an audio capturer instance, which is created by calling OH_AudioStreamBuilder_GenerateCapturer. |
| OH_AudioCapturer_OnPlaybackCaptureStartCallback callback | Callback function used to receive the final result of the start request. |
| void* userData | Pointer to the data storage region customized by an application. This struct will be passed to the callback function. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: Invalid capturer or callback. AUDIOSTREAM_ERROR_ILLEGAL_STATE: The stream is either active or has been released. AUDIOSTREAM_ERROR_SYSTEM: Internal system error, for example, abnormal audio error. |
OH_AudioCapturer_SetIndependentAudioSessionStrategy()
OH_AudioStream_Result OH_AudioCapturer_SetIndependentAudioSessionStrategy(OH_AudioCapturer* capturer, const OH_AudioSession_Strategy* strategy, uint32_t behavior)
Description
Sets the independent audio session policy and behavior parameters. If this API is called while an audio capturer is running, you must call the OH_AudioCapturer_Start API again for the settings to take effect.
Since: 24
Parameters
| Name | Description |
|---|---|
| OH_AudioCapturer* capturer | Pointer to an audio capturer instance, which is created by calling OH_AudioStreamBuilder_GenerateCapturer. |
| const OH_AudioSession_Strategy* strategy | Pointer to the independent audio session policy. |
| uint32_t behavior | Audio session behavior flag. This can be a single flag or a bitwise OR combination of multiple flags. For details about the supported audio session behaviors, see OH_AudioSession_BehaviorFlags. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: The parameter value is a null pointer or out of range. AUDIOSTREAM_ERROR_ILLEGAL_STATE: The execution status is abnormal. |
你可能感兴趣的鸿蒙文章
openharmony 鸿蒙 capi-native-audiostreambuilder-h
openharmony 鸿蒙 capi-ohaudiosuite
openharmony 鸿蒙 js-apis-inner-multimedia-systemSoundPlayer
openharmony 鸿蒙 arkts-apis-audio-i
openharmony 鸿蒙 arkts-apis-audio-AudioManager
openharmony 鸿蒙 capi-ohaudiosuite-oh-audiosuite-spacerenderpositionparams