OHAudio

Overview

The OHAudio module provides C APIs of the audio module.

System capability: SystemCapability.Multimedia.Audio.Core

Since: 10

Summary

Files

Name Description
native_audiocapturer.h Declares the functions related to an audio capturer.
File to include: <ohaudio/native_audiocapturer.h>
Library: libohaudio.so
native_audiorenderer.h Declares the functions related to an audio renderer.
File to include: <ohaudio/native_audiorenderer.h>
Library: libohaudio.so
native_audiostream_base.h Declares the basic data structure of OHAudio.
File to include: <ohaudio/native_audiostream_base.h>
Library: libohaudio.so
native_audiostreambuilder.h Declares the functions related to the audio stream builder.
File to include: <ohaudio/native_audiostreambuilder.h>
Library: libohaudio.so

Structs

Name Description
struct  OH_AudioRenderer_Callbacks_Struct Defines a pointer to the callback functions related to an audio renderer.
struct  OH_AudioCapturer_Callbacks_Struct Defines a pointer to the callback functions related to an audio capturer.

Types

Name Description
typedef struct OH_AudioStreamBuilderStruct OH_AudioStreamBuilder Defines an audio stream builder.
typedef struct OH_AudioRendererStruct OH_AudioRenderer Defines an audio renderer.
typedef struct OH_AudioCapturerStruct OH_AudioCapturer Defines an audio capturer.
typedef struct OH_AudioRenderer_Callbacks_Struct OH_AudioRenderer_Callbacks Defines a pointer to the callback functions related to an audio renderer.
typedef struct OH_AudioCapturer_Callbacks_Struct OH_AudioCapturer_Callbacks Defines a pointer to the callback functions related to an audio capturer.

Enums

Name Description
OH_AudioStream_Result {
AUDIOSTREAM_SUCCESS = 0,
AUDIOSTREAM_ERROR_INVALID_PARAM = 1,
AUDIOSTREAM_ERROR_ILLEGAL_STATE = 2,
AUDIOSTREAM_ERROR_SYSTEM = 3
}
Enumerates the audio stream operation results.
OH_AudioStream_Type {
AUDIOSTREAM_TYPE_RERNDERER = 1,
AUDIOSTREAM_TYPE_CAPTURER = 2
}
Enumerates the audio stream types.
OH_AudioStream_SampleFormat {
AUDIOSTREAM_SAMPLE_U8 = 0,
AUDIOSTREAM_SAMPLE_S16LE = 1,
AUDIOSTREAM_SAMPLE_S24LE = 2,
AUDIOSTREAM_SAMPLE_S32LE = 3
}
Enumerates the sampling formats of audio streams.
OH_AudioStream_EncodingType {
AUDIOSTREAM_ENCODING_TYPE_RAW = 0
}
Enumerates the encoding types of audio streams.
OH_AudioStream_Usage {
AUDIOSTREAM_USAGE_UNKNOWN = 0,
AUDIOSTREAM_USAGE_MUSIC = 1,
AUDIOSTREAM_USAGE_COMMUNICATION = 2,
AUDIOSTREAM_USAGE_VOICE_ASSISTANT = 3,
AUDIOSTREAM_USAGE_ALARM = 4,
AUDIOSTREAM_USAGE_VOICE_MESSAGE = 5,
AUDIOSTREAM_USAGE_RINGTONE = 6,
AUDIOSTREAM_USAGE_NOTIFICATION = 7,
AUDIOSTREAM_USAGE_ACCESSIBILITY = 8,
AUDIOSTREAM_USAGE_MOVIE = 10,
AUDIOSTREAM_USAGE_GAME = 11,
AUDIOSTREAM_USAGE_AUDIOBOOK = 12,
AUDIOSTREAM_USAGE_NAVIGATION = 13
}
Enumerates the usage scenarios of audio streams.
OH_AudioStream_LatencyMode {
AUDIOSTREAM_LATENCY_MODE_NORMAL = 0,
AUDIOSTREAM_LATENCY_MODE_FAST = 1
}
Enumerates the latency modes of audio streams.
OH_AudioStream_State {
AUDIOSTREAM_STATE_INVALID = -1,
AUDIOSTREAM_STATE_NEW = 0,
AUDIOSTREAM_STATE_PREPARED = 1,
AUDIOSTREAM_STATE_RUNNING = 2,
AUDIOSTREAM_STATE_STOPPED = 3,
AUDIOSTREAM_STATE_RELEASED = 4,
AUDIOSTREAM_STATE_PAUSED = 5
}
Enumerates the audio stream states.
OH_AudioStream_SourceType {
AUDIOSTREAM_SOURCE_TYPE_INVALID = -1,
AUDIOSTREAM_SOURCE_TYPE_MIC = 0,
AUDIOSTREAM_SOURCE_TYPE_VOICE_RECOGNITION = 1,
AUDIOSTREAM_SOURCE_TYPE_PLAYBACK_CAPTURE = 2,
AUDIOSTREAM_SOURCE_TYPE_VOICE_COMMUNICATION = 7
}
Enumerates the usage scenarios of audio streams.
OH_AudioStream_Event {
AUDIOSTREAM_EVENT_ROUTING_CHANGED = 0
}
Enumerates the audio stream events.
OH_AudioInterrupt_ForceType {
AUDIOSTREAM_INTERRUPT_FORCE = 0,
AUDIOSTREAM_INTERRUPT_SHAR = 1
}
Enumerates the types of force that causes audio interruption.
OH_AudioInterrupt_Hint {
AUDIOSTREAM_INTERRUPT_HINT_NONE = 0,
AUDIOSTREAM_INTERRUPT_HINT_RESUME = 1,
AUDIOSTREAM_INTERRUPT_HINT_PAUSE = 2,
AUDIOSTREAM_INTERRUPT_HINT_STOP = 3,
AUDIOSTREAM_INTERRUPT_HINT_DUCK = 4,
AUDIOSTREAM_INTERRUPT_HINT_UNDUCK = 5
}
Enumerates the hints provided along with audio interruption.

Functions

Name Description
OH_AudioStream_Result OH_AudioCapturer_Release(OH_AudioCapturer *capturer) Releases an audio capturer.
OH_AudioStream_Result OH_AudioCapturer_Start(OH_AudioCapturer *capturer) Starts an audio capturer.
OH_AudioStream_Result OH_AudioCapturer_Pause(OH_AudioCapturer *capturer) Pauses an audio capturer.
OH_AudioStream_Result OH_AudioCapturer_Stop(OH_AudioCapturer *capturer) Stops an audio capturer.
OH_AudioStream_Result OH_AudioCapturer_Flush(OH_AudioCapturer *capturer) Flushes obtained audio data.
OH_AudioStream_Result OH_AudioCapturer_GetCurrentState(OH_AudioCapturer *capturer, OH_AudioStream_State *state) Obtains the state of an audio capturer.
OH_AudioStream_Result OH_AudioCapturer_GetLatencyMode(OH_AudioCapturer *capturer, OH_AudioStream_LatencyMode *latencyMode) Obtains the latency mode of an audio capturer.
OH_AudioStream_Result OH_AudioCapturer_GetStreamId(OH_AudioCapturer *capturer, uint32_t *streamId) Obtains the stream ID of an audio capturer.
OH_AudioStream_Result OH_AudioCapturer_GetSamplingRate(OH_AudioCapturer *capturer, int32_t *rate) Obtains the sampling rate of an audio capturer.
OH_AudioStream_Result OH_AudioCapturer_GetChannelCount(OH_AudioCapturer *capturer, int32_t *channelCount) Obtains the number of channels for an audio capturer.
OH_AudioStream_Result OH_AudioCapturer_GetSampleFormat(OH_AudioCapturer *capturer, OH_AudioStream_SampleFormat *sampleFormat) Obtains the sampling format of an audio capturer.
OH_AudioStream_Result OH_AudioCapturer_GetEncodingType(OH_AudioCapturer *capturer, OH_AudioStream_EncodingType *encodingType) Obtains the encoding type of an audio capturer.
OH_AudioStream_Result OH_AudioCapturer_GetCapturerInfo(OH_AudioCapturer *capturer, OH_AudioStream_SourceType *sourceType) Obtains the usage scenario of an audio capturer.
OH_AudioStream_Result OH_AudioCapturer_GetFrameSizeInCallback(OH_AudioCapturer *capturer, int32_t *frameSize) Obtains the frame size in the callback. The frame size is the fixed length of the buffer returned by each callback.
OH_AudioStream_Result OH_AudioCapturer_GetTimestamp(OH_AudioCapturer *capturer, clockid_t clockId, int64_t *framePosition, int64_t *timestamp) Obtains the timestamp and position information of an audio input stream.
OH_AudioStream_Result OH_AudioCapturer_GetFramesRead(OH_AudioCapturer *capturer, int64_t *frames) Obtains the number of frames that have been read since the stream was created.
OH_AudioStream_Result OH_AudioRenderer_Release(OH_AudioRenderer *renderer) Releases an audio renderer.
OH_AudioStream_Result OH_AudioRenderer_Start(OH_AudioRenderer *renderer) Starts an audio renderer.
OH_AudioStream_Result OH_AudioRenderer_Pause(OH_AudioRenderer *renderer) Pauses an audio renderer.
OH_AudioStream_Result OH_AudioRenderer_Stop(OH_AudioRenderer *renderer) Stops an audio renderer.
OH_AudioStream_Result OH_AudioRenderer_Flush(OH_AudioRenderer *renderer) Flushes written audio data.
OH_AudioStream_Result OH_AudioRenderer_GetCurrentState(OH_AudioRenderer *renderer, OH_AudioStream_State *state) Obtains the state of an audio renderer.
OH_AudioStream_Result OH_AudioRenderer_GetSamplingRate(OH_AudioRenderer *renderer, int32_t *rate) Obtains the sampling rate of an audio renderer.
OH_AudioStream_Result OH_AudioRenderer_GetStreamId(OH_AudioRenderer *renderer, uint32_t *streamId) Obtains the stream ID of an audio renderer.
OH_AudioStream_Result OH_AudioRenderer_GetChannelCount(OH_AudioRenderer *renderer, int32_t *channelCount) Obtains the number of channels for an audio renderer.
OH_AudioStream_Result OH_AudioRenderer_GetSampleFormat(OH_AudioRenderer *renderer, OH_AudioStream_SampleFormat *sampleFormat) Obtains the sampling format of an audio renderer.
OH_AudioStream_Result OH_AudioRenderer_GetLatencyMode(OH_AudioRenderer *renderer, OH_AudioStream_LatencyMode *latencyMode) Obtains the latency mode of an audio renderer.
OH_AudioStream_Result OH_AudioRenderer_GetRendererInfo(OH_AudioRenderer *renderer, OH_AudioStream_Usage *usage) Obtains the usage scenario of an audio renderer.
OH_AudioStream_Result OH_AudioRenderer_GetEncodingType(OH_AudioRenderer *renderer, OH_AudioStream_EncodingType *encodingType) Obtains the encoding type of an audio renderer.
OH_AudioStream_Result OH_AudioRenderer_GetFramesWritten(OH_AudioRenderer *renderer, int64_t *frames) Obtains the number of frames that have been written since the stream was created.
OH_AudioStream_Result OH_AudioRenderer_GetTimestamp(OH_AudioRenderer *renderer, clockid_t clockId, int64_t *framePosition, int64_t *timestamp) Obtains the timestamp and position information of an audio output stream.
OH_AudioStream_Result OH_AudioRenderer_GetFrameSizeInCallback(OH_AudioRenderer *renderer, int32_t *frameSize) Obtains the frame size in the callback.
OH_AudioStream_Result OH_AudioStreamBuilder_Create(OH_AudioStreamBuilder **builder, OH_AudioStream_Type type) Creates an audio stream builder, which can be an audio renderer or capturer.
OH_AudioStream_Result OH_AudioStreamBuilder_Destroy(OH_AudioStreamBuilder *builder) Destroys an audio stream builder.
OH_AudioStream_Result OH_AudioStreamBuilder_SetSamplingRate(OH_AudioStreamBuilder *builder, int32_t rate) Sets the sampling rate of an audio stream.
OH_AudioStream_Result OH_AudioStreamBuilder_SetChannelCount(OH_AudioStreamBuilder *builder, int32_t channelCount) Sets the number of channels for an audio stream.
OH_AudioStream_Result OH_AudioStreamBuilder_SetSampleFormat(OH_AudioStreamBuilder *builder, OH_AudioStream_SampleFormat format) Sets the sampling format of an audio stream.
OH_AudioStream_Result OH_AudioStreamBuilder_SetEncodingType(OH_AudioStreamBuilder *builder, OH_AudioStream_EncodingType encodingType) Sets the encoding type of an audio stream.
OH_AudioStream_Result OH_AudioStreamBuilder_SetLatencyMode(OH_AudioStreamBuilder *builder, OH_AudioStream_LatencyMode latencyMode) Sets the latency mode of an audio stream.
OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererInfo(OH_AudioStreamBuilder *builder, OH_AudioStream_Usage usage) Sets the usage scenario of an audio renderer.
OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerInfo(OH_AudioStreamBuilder *builder, OH_AudioStream_SourceType sourceType) Sets the usage scenario of an audio capturer.
OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererCallback(OH_AudioStreamBuilder *builder, OH_AudioRenderer_Callbacks callbacks, void *userData) Sets callbacks for an audio renderer.
OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerCallback(OH_AudioStreamBuilder *builder, OH_AudioCapturer_Callbacks callbacks, void *userData) Sets callbacks for an audio capturer.
OH_AudioStream_Result OH_AudioStreamBuilder_GenerateRenderer(OH_AudioStreamBuilder *builder, OH_AudioRenderer **audioRenderer) Creates an audio renderer instance.
OH_AudioStream_Result OH_AudioStreamBuilder_GenerateCapturer(OH_AudioStreamBuilder *builder, OH_AudioCapturer **audioCapturer) Creates an audio capturer instance.
OH_AudioStream_Result OH_AudioStreamBuilder_SetFrameSizeInCallback(OH_AudioStreamBuilder *builder, int32_t frameSize) Sets the frame size for each callback. The frame size must be at least equal to the size of the data processed by the audio hardware at a time and less than half of the internal buffer capacity.

Type Description

OH_AudioCapturer

typedef struct OH_AudioCapturerStruct OH_AudioCapturer

Description

Defines an audio capturer.

An audio capturer instance is used to capture audio data.

System capability: SystemCapability.Multimedia.Audio.Core

Since: 10

OH_AudioCapturer_Callbacks

typedef struct OH_AudioCapturer_Callbacks_Struct OH_AudioCapturer_Callbacks

Description

Defines a pointer to the callback functions related to an audio capturer.

System capability: SystemCapability.Multimedia.Audio.Core

Since: 10

OH_AudioRenderer

typedef struct OH_AudioRendererStruct OH_AudioRenderer

Description

Defines an audio renderer.

An audio renderer instance is used to render audio data.

System capability: SystemCapability.Multimedia.Audio.Core

Since: 10

OH_AudioRenderer_Callbacks

typedef struct OH_AudioRenderer_Callbacks_Struct OH_AudioRenderer_Callbacks

Description

Defines a pointer to the callback functions related to an audio renderer.

System capability: SystemCapability.Multimedia.Audio.Core

Since: 10

OH_AudioStreamBuilder

typedef struct OH_AudioStreamBuilderStruct OH_AudioStreamBuilder

Description

Defines an audio stream builder.

An audio stream builder instance is often used to create an audio stream and set its attributes.

System capability: SystemCapability.Multimedia.Audio.Core

Since: 10

Enum Description

OH_AudioInterrupt_ForceType

enum OH_AudioInterrupt_ForceType

Description

Enumerates the types of force that causes audio interruption.

This enum is used to describe audio interruption events.

System capability: SystemCapability.Multimedia.Audio.Core

Since: 10

Value Description
AUDIOSTREAM_INTERRUPT_FORCE The system changes the audio status.
AUDIOSTREAM_INTERRUPT_SHAR The application changes the audio status.

OH_AudioInterrupt_Hint

enum OH_AudioInterrupt_Hint

Description

Enumerates the types of force that causes audio interruption.

This enum is used to describe audio interruption events.

System capability: SystemCapability.Multimedia.Audio.Core

Since: 10

Value Description
AUDIOSTREAM_INTERRUPT_HINT_NONE None.
AUDIOSTREAM_INTERRUPT_HINT_RESUME Resume the playback.
AUDIOSTREAM_INTERRUPT_HINT_PAUSE Paused/Pause the playback.
AUDIOSTREAM_INTERRUPT_HINT_STOP Stopped/Stop the playback.
AUDIOSTREAM_INTERRUPT_HINT_DUCK Ducked the playback.
AUDIOSTREAM_INTERRUPT_HINT_UNDUCK Unducked the playback.

OH_AudioStream_EncodingType

enum OH_AudioStream_EncodingType

Description

Enumerates the encoding types of audio streams.

System capability: SystemCapability.Multimedia.Audio.Core

Since: 10

Value Description
AUDIOSTREAM_ENCODING_TYPE_RAW PCM encoding.

OH_AudioStream_Event

enum OH_AudioStream_Event

Description

Enumerates the audio stream events.

This enum is used to describe audio events.

System capability: SystemCapability.Multimedia.Audio.Core

Since: 10

Value Description
AUDIOSTREAM_EVENT_ROUTING_CHANGED The audio route has been changed.

OH_AudioStream_LatencyMode

enum OH_AudioStream_LatencyMode

Description

Enumerates the latency modes of audio streams.

System capability: SystemCapability.Multimedia.Audio.Core

Since: 10

Value Description
AUDIOSTREAM_LATENCY_MODE_NORMAL Normal latency mode.
AUDIOSTREAM_LATENCY_MODE_FAST Low latency mode.

OH_AudioStream_Result

enum OH_AudioStream_Result

Description

Enumerates the audio stream operation results.

System capability: SystemCapability.Multimedia.Audio.Core

Since: 10

Value Description
AUDIOSTREAM_SUCCESS The operation is successful.
AUDIOSTREAM_ERROR_INVALID_PARAM Invalid input parameter.
AUDIOSTREAM_ERROR_ILLEGAL_STATE Invalid state.
AUDIOSTREAM_ERROR_SYSTEM System error.

OH_AudioStream_SampleFormat

enum OH_AudioStream_SampleFormat

Description

Enumerates the sampling formats of audio streams.

System capability: SystemCapability.Multimedia.Audio.Core

Since: 10

Value Description
AUDIOSTREAM_SAMPLE_U8 Unsigned 8-bit.
AUDIOSTREAM_SAMPLE_S16LE Short 16-bit little-endian.
AUDIOSTREAM_SAMPLE_S24LE Short 24-bit little-endian.
AUDIOSTREAM_SAMPLE_S32LE Short 32-bit little-endian.

OH_AudioStream_SourceType

enum OH_AudioStream_SourceType

Description

Enumerates the usage scenarios of an audio capturer, that is, the usage scenarios of audio input streams.

System capability: SystemCapability.Multimedia.Audio.Core

Since: 10

Value Description
AUDIOSTREAM_SOURCE_TYPE_INVALID Invalid state.
AUDIOSTREAM_SOURCE_TYPE_MIC Audio recording.
AUDIOSTREAM_SOURCE_TYPE_VOICE_RECOGNITION Voice recognition.
AUDIOSTREAM_SOURCE_TYPE_PLAYBACK_CAPTURE Audio playback.
AUDIOSTREAM_SOURCE_TYPE_VOICE_COMMUNICATION Voice communication.

OH_AudioStream_State

enum OH_AudioStream_State

Description

Enumerates the audio stream states.

System capability: SystemCapability.Multimedia.Audio.Core

Since: 10

Value Description
AUDIOSTREAM_STATE_INVALID Invalid state.
AUDIOSTREAM_STATE_NEW Newly created.
AUDIOSTREAM_STATE_PREPARED Prepared.
AUDIOSTREAM_STATE_RUNNING Running.
AUDIOSTREAM_STATE_STOPPED Stopped.
AUDIOSTREAM_STATE_RELEASED Released.
AUDIOSTREAM_STATE_PAUSED Paused.

OH_AudioStream_Type

enum OH_AudioStream_Type

Description

Enumerates the audio stream types.

System capability: SystemCapability.Multimedia.Audio.Core

Since: 10

Value Description
AUDIOSTREAM_TYPE_RERNDERER The audio stream is an output stream.
AUDIOSTREAM_TYPE_CAPTURER The audio stream is an input stream.

OH_AudioStream_Usage

enum OH_AudioStream_Usage

Description

Enumerates the usage scenarios of an audio renderer, that is, the usage scenarios of audio output streams.

System capability: SystemCapability.Multimedia.Audio.Core

Since: 10

Value Description
AUDIOSTREAM_USAGE_UNKNOWN Undefined.
AUDIOSTREAM_USAGE_MUSIC Music.
AUDIOSTREAM_USAGE_COMMUNICATION Voice communication.
AUDIOSTREAM_USAGE_VOICE_ASSISTANT Voice assistant.
AUDIOSTREAM_USAGE_ALARM Alarming.
AUDIOSTREAM_USAGE_VOICE_MESSAGE Voice message.
AUDIOSTREAM_USAGE_RINGTONE Ringtone.
AUDIOSTREAM_USAGE_NOTIFICATION Notification.
AUDIOSTREAM_USAGE_ACCESSIBILITY Accessibility.
AUDIOSTREAM_USAGE_MOVIE Video.
AUDIOSTREAM_USAGE_GAME Gaming.
AUDIOSTREAM_USAGE_AUDIOBOOK Audiobook.
AUDIOSTREAM_USAGE_NAVIGATION Navigation.

Function Description

OH_AudioCapturer_Flush()

OH_AudioStream_Result OH_AudioCapturer_Flush (OH_AudioCapturer * capturer)

Description

Flushes obtained audio data.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
capturer Pointer to an audio capturer instance created by OH_AudioStreamBuilder_GenerateCapturer.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

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

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
capturer Pointer to an audio capturer instance created by OH_AudioStreamBuilder_GenerateCapturer.
sourceType Pointer to a variable used to receive the usage scenario.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

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

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
capturer Pointer to an audio capturer instance created by OH_AudioStreamBuilder_GenerateCapturer.
channelCount Pointer to a variable used to receive the number of channels.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

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

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
capturer Pointer to an audio capturer instance created by OH_AudioStreamBuilder_GenerateCapturer.
state Pointer to a variable used to receive the state.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

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

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
capturer Pointer to an audio capturer instance created by OH_AudioStreamBuilder_GenerateCapturer.
encodingType Pointer to a variable used to receive the encoding type.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

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

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
capturer Pointer to an audio capturer instance created by OH_AudioStreamBuilder_GenerateCapturer.
frameSize Pointer to the variable that holds the frame size.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

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

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
capturer Pointer to an audio capturer instance created by OH_AudioStreamBuilder_GenerateCapturer.
frames Pointer to the variable that holds the frame count.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

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

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
capturer Pointer to an audio capturer instance created by OH_AudioStreamBuilder_GenerateCapturer.
latencyMode Pointer to a variable used to receive the latency mode.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

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

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
capturer Pointer to an audio capturer instance created by OH_AudioStreamBuilder_GenerateCapturer.
sampleFormat Pointer to a variable used to receive the sampling format.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

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

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
capturer Pointer to an audio capturer instance created by OH_AudioStreamBuilder_GenerateCapturer.
rate Pointer to a variable used to receive the sampling rate.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

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

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
capturer Pointer to an audio capturer instance created by OH_AudioStreamBuilder_GenerateCapturer.
streamId Pointer to a variable used to receive the stream ID.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioCapturer_GetTimestamp()

OH_AudioStream_Result OH_AudioCapturer_GetTimestamp(OH_AudioCapturer *capturer, clockid_t clockId, int64_t *framePosition, int64_t *timestamp)

Description

Obtains the timestamp and position information of an audio input stream.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
capturer Pointer to an audio capturer instance created by OH_AudioStreamBuilder_GenerateCapturer.
clockId CLOCK_MONOTONIC.
framePosition Pointer to the variable that holds the position information.
timestamp Pointer to the variable that holds the timestamp.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioCapturer_Pause()

OH_AudioStream_Result OH_AudioCapturer_Pause(OH_AudioCapturer *capturer)

Description

Pauses an audio capturer.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
capturer Pointer to an audio capturer instance created by OH_AudioStreamBuilder_GenerateCapturer.

Required permissions

ohos.permission.MICROPHONE

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioCapturer_Release()

OH_AudioStream_Result OH_AudioCapturer_Release(OH_AudioCapturer *capturer)

Description

Releases an audio capturer.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
capturer Pointer to an audio capturer instance created by OH_AudioStreamBuilder_GenerateCapturer.

Required permissions

ohos.permission.MICROPHONE

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioCapturer_Start()

OH_AudioStream_Result OH_AudioCapturer_Start(OH_AudioCapturer *capturer)

Description

Starts an audio capturer.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
capturer Pointer to an audio capturer instance created by OH_AudioStreamBuilder_GenerateCapturer.

Required permissions

ohos.permission.MICROPHONE

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioCapturer_Stop()

OH_AudioStream_Result OH_AudioCapturer_Stop(OH_AudioCapturer *capturer)

Description

Stops an audio capturer.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
capturer Pointer to an audio capturer instance created by OH_AudioStreamBuilder_GenerateCapturer.

Required permissions

ohos.permission.MICROPHONE

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioRenderer_Flush()

OH_AudioStream_Result OH_AudioRenderer_Flush(OH_AudioRenderer *renderer)

Description

Flushes written audio data.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
renderer Pointer to an audio renderer instance created by OH_AudioStreamBuilder_GenerateRenderer.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioRenderer_GetChannelCount()

OH_AudioStream_Result OH_AudioRenderer_GetChannelCount(OH_AudioRenderer *renderer, int32_t *channelCount)

Description

Obtains the number of channels for an audio renderer.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
renderer Pointer to an audio renderer instance created by OH_AudioStreamBuilder_GenerateRenderer.
channelCount Pointer to a variable used to receive the number of channels.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioRenderer_GetCurrentState()

OH_AudioStream_Result OH_AudioRenderer_GetCurrentState(OH_AudioRenderer *renderer, OH_AudioStream_State *state)

Description

Obtains the state of an audio renderer.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
renderer Pointer to an audio renderer instance created by OH_AudioStreamBuilder_GenerateRenderer.
state Pointer to a variable used to receive the state.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioRenderer_GetEncodingType()

OH_AudioStream_Result OH_AudioRenderer_GetEncodingType(OH_AudioRenderer *renderer, OH_AudioStream_EncodingType *encodingType)

Description

Obtains the encoding type of an audio renderer.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
renderer Pointer to an audio renderer instance created by OH_AudioStreamBuilder_GenerateRenderer.
encodingType Pointer to a variable used to receive the encoding type.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioRenderer_GetFrameSizeInCallback()

OH_AudioStream_Result OH_AudioRenderer_GetFrameSizeInCallback(OH_AudioRenderer *renderer, 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

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
renderer Pointer to an audio renderer instance created by OH_AudioStreamBuilder_GenerateRenderer.
frameSize Pointer to the variable that holds the frame size.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioRenderer_GetFramesWritten()

OH_AudioStream_Result OH_AudioRenderer_GetFramesWritten(OH_AudioRenderer *renderer, int64_t *frames)

Description

Obtains the number of frames that have been written since the stream was created.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
renderer Pointer to an audio renderer instance created by OH_AudioStreamBuilder_GenerateRenderer.
frames Pointer to the variable that holds the frame count.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioRenderer_GetLatencyMode()

OH_AudioStream_Result OH_AudioRenderer_GetLatencyMode(OH_AudioRenderer *renderer, OH_AudioStream_LatencyMode *latencyMode)

Description

Obtains the latency mode of an audio renderer.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
renderer Pointer to an audio renderer instance created by OH_AudioStreamBuilder_GenerateRenderer.
latencyMode Pointer to a variable used to receive the latency mode.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioRenderer_GetRendererInfo()

OH_AudioStream_Result OH_AudioRenderer_GetRendererInfo(OH_AudioRenderer *renderer, OH_AudioStream_Usage *usage)

Description

Obtains the usage scenario of an audio renderer.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
renderer Pointer to an audio renderer instance created by OH_AudioStreamBuilder_GenerateRenderer.
usage Pointer to a variable used to receive the usage scenario.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioRenderer_GetSampleFormat()

OH_AudioStream_Result OH_AudioRenderer_GetSampleFormat(OH_AudioRenderer *renderer, OH_AudioStream_SampleFormat *sampleFormat)

Description

Obtains the sampling format of an audio renderer.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
renderer Pointer to an audio renderer instance created by OH_AudioStreamBuilder_GenerateRenderer.
sampleFormat Pointer to a variable used to receive the sampling format.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioRenderer_GetSamplingRate()

OH_AudioStream_Result OH_AudioRenderer_GetSamplingRate(OH_AudioRenderer *renderer, int32_t *rate)

Description

Obtains the sampling rate of an audio renderer.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
renderer Pointer to an audio renderer instance created by OH_AudioStreamBuilder_GenerateRenderer.
rate Pointer to a variable used to receive the sampling rate.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioRenderer_GetStreamId()

OH_AudioStream_Result OH_AudioRenderer_GetStreamId(OH_AudioRenderer *renderer, uint32_t *streamId)

Description

Obtains the stream ID of an audio renderer.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
renderer Pointer to an audio renderer instance created by OH_AudioStreamBuilder_GenerateRenderer.
streamId Pointer to a variable used to receive the stream ID.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioRenderer_GetTimestamp()

OH_AudioStream_Result OH_AudioRenderer_GetTimestamp(OH_AudioRenderer *renderer, clockid_t clockId, int64_t *framePosition, int64_t *timestamp)

Description

Obtains the timestamp and position information of an audio output stream.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
renderer Pointer to an audio renderer instance created by OH_AudioStreamBuilder_GenerateRenderer.
clockId CLOCK_MONOTONIC
framePosition Pointer to the variable that holds the position information.
timestamp Pointer to the variable that holds the timestamp.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioRenderer_Pause()

OH_AudioStream_Result OH_AudioRenderer_Pause(OH_AudioRenderer *renderer)

Description

Pauses an audio renderer.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
renderer Pointer to an audio renderer instance created by OH_AudioStreamBuilder_GenerateRenderer.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioRenderer_Release()

OH_AudioStream_Result OH_AudioRenderer_Release(OH_AudioRenderer *renderer)

Description

Releases an audio renderer.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
renderer Pointer to an audio renderer instance created by OH_AudioStreamBuilder_GenerateRenderer.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioRenderer_Start()

OH_AudioStream_Result OH_AudioRenderer_Start(OH_AudioRenderer *renderer)

Description

Starts an audio renderer.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
renderer Pointer to an audio renderer instance created by OH_AudioStreamBuilder_GenerateRenderer.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioRenderer_Stop()

OH_AudioStream_Result OH_AudioRenderer_Stop(OH_AudioRenderer *renderer)

Description

Stops an audio renderer.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
renderer Pointer to an audio renderer instance created by OH_AudioStreamBuilder_GenerateRenderer.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioStreamBuilder_Create()

OH_AudioStream_Result OH_AudioStreamBuilder_Create(OH_AudioStreamBuilder **builder, OH_AudioStream_Type type)

Description

Creates an audio stream builder, which can be an audio renderer or capturer.

You need to call OH_AudioStreamBuilder_Destroy() to destroy the builder when it is no longer required.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
builder Double pointer to the audio stream builder created.
type Type of the audio stream builder, which can be AUDIOSTREAM_TYPE_RERNDERER or AUDIOSTREAM_TYPE_CAPTURER.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioStreamBuilder_Destroy()

OH_AudioStream_Result OH_AudioStreamBuilder_Destroy(OH_AudioStreamBuilder *builder)

Description

Destroys an audio stream builder when it is no longer required.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
builder Pointer to an audio stream builder instance created by OH_AudioStreamBuilder_Create().

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioStreamBuilder_GenerateCapturer()

OH_AudioStream_Result OH_AudioStreamBuilder_GenerateCapturer(OH_AudioStreamBuilder *builder, OH_AudioCapturer **audioCapturer)

Description

Creates an audio capturer instance.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
builder Pointer to an audio stream builder instance created by OH_AudioStreamBuilder_Create().
audioCapturer Double pointer to the audio capturer instance created.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioStreamBuilder_GenerateRenderer()

OH_AudioStream_Result OH_AudioStreamBuilder_GenerateRenderer(OH_AudioStreamBuilder *builder, OH_AudioRenderer **audioRenderer)

Description

Creates an audio renderer instance.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
builder Pointer to an audio stream builder instance created by OH_AudioStreamBuilder_Create().
audioRenderer Double pointer to the audio renderer instance created.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioStreamBuilder_SetCapturerCallback()

OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerCallback(OH_AudioStreamBuilder *builder, OH_AudioCapturer_Callbacks callbacks, void *userData)

Description

Sets callbacks for an audio capturer.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
builder Pointer to an audio stream builder instance created by OH_AudioStreamBuilder_Create().
callbacks Callback functions that will be used to process events related to audio input streams.
userData Pointer to the application data passed through the callback functions.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioStreamBuilder_SetCapturerInfo()

OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerInfo(OH_AudioStreamBuilder *builder, OH_AudioStream_SourceType sourceType)

Description

Sets the usage scenario of an audio capturer.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
builder Pointer to an audio stream builder instance created by OH_AudioStreamBuilder_Create().
sourceType Usage scenario of the audio capturer.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioStreamBuilder_SetChannelCount()

OH_AudioStream_Result OH_AudioStreamBuilder_SetChannelCount(OH_AudioStreamBuilder *builder, int32_t channelCount)

Description

Sets the number of channels for an audio stream.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
builder Pointer to an audio stream builder instance created by OH_AudioStreamBuilder_Create().
channelCount Number of channels.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioStreamBuilder_SetEncodingType()

OH_AudioStream_Result OH_AudioStreamBuilder_SetEncodingType(OH_AudioStreamBuilder *builder, OH_AudioStream_EncodingType encodingType)

Description

Sets the encoding type of an audio stream.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
builder Pointer to an audio stream builder instance created by OH_AudioStreamBuilder_Create().
encodingType Encoding type, which can be AUDIOSTREAM_ENCODING_PCM.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioStreamBuilder_SetFrameSizeInCallback()

OH_AudioStream_Result OH_AudioStreamBuilder_SetFrameSizeInCallback(OH_AudioStreamBuilder *builder, int32_t frameSize)

Description

Sets the frame size for each callback. The frame size must be at least equal to the size of the data processed by the audio hardware at a time and less than half of the internal buffer capacity.

Since: 11

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
builder Pointer to an audio stream builder instance created by OH_AudioStreamBuilder_Create().
frameSize Frame size.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioStreamBuilder_SetLatencyMode()

OH_AudioStream_Result OH_AudioStreamBuilder_SetLatencyMode(OH_AudioStreamBuilder *builder, OH_AudioStream_LatencyMode latencyMode)

Description

Sets the latency mode of an audio stream.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
builder Pointer to an audio stream builder instance created by OH_AudioStreamBuilder_Create().
latencyMode Latency mode.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioStreamBuilder_SetRendererCallback()

OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererCallback(OH_AudioStreamBuilder *builder, OH_AudioRenderer_Callbacks callbacks, void *userData)

Description

Sets callbacks for an audio renderer.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
builder Pointer to an audio stream builder instance created by OH_AudioStreamBuilder_Create().
callbacks Callback functions that will be used to process events related to audio output streams.
userData Pointer to the application data passed through the callback functions.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioStreamBuilder_SetRendererInfo()

OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererInfo(OH_AudioStreamBuilder *builder, OH_AudioStream_Usage usage)

Description

Sets the usage scenario of an audio renderer.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
builder Pointer to an audio stream builder instance created by OH_AudioStreamBuilder_Create().
usage Usage scenario of the audio renderer.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioStreamBuilder_SetSampleFormat()

OH_AudioStream_Result OH_AudioStreamBuilder_SetSampleFormat(OH_AudioStreamBuilder *builder, OH_AudioStream_SampleFormat format)

Description

Sets the sampling format of an audio stream.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
builder Pointer to an audio stream builder instance created by OH_AudioStreamBuilder_Create().
format Sampling format.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.

OH_AudioStreamBuilder_SetSamplingRate()

OH_AudioStream_Result OH_AudioStreamBuilder_SetSamplingRate(OH_AudioStreamBuilder *builder, int32_t rate)

Description

Sets the sampling rate of an audio stream.

Since: 10

System capability: SystemCapability.Multimedia.Audio.Core

Parameters

Name Description
builder Pointer to an audio stream builder instance created by OH_AudioStreamBuilder_Create().
channelCount Sampling rate.

Returns

Returns AUDIOSTREAM_SUCCESS if the operation is successful; returns an error code otherwise.