• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# OHAudio
2
3
4## Overview
5
6The **OHAudio** module provides C APIs of the audio module.
7
8**System capability**: SystemCapability.Multimedia.Audio.Core
9
10**Since**: 10
11
12
13## Summary
14
15
16### Files
17
18| Name| Description|
19| -------- | -------- |
20| [native_audiocapturer.h](native__audiocapturer_8h.md) | Declares the functions related to an audio capturer.<br>**File to include**: &lt;ohaudio/native_audiocapturer.h&gt;<br>**Library**: libohaudio.so|
21| [native_audiorenderer.h](native__audiorenderer_8h.md) | Declares the functions related to an audio renderer.<br>**File to include**: &lt;ohaudio/native_audiorenderer.h&gt;<br>**Library**: libohaudio.so|
22| [native_audiostream_base.h](native__audiostream__base_8h.md) | Declares the basic data structure of **OHAudio**.<br>**File to include**: &lt;ohaudio/native_audiostream_base.h&gt;<br>**Library**: libohaudio.so|
23| [native_audiostreambuilder.h](native__audiostreambuilder_8h.md) | Declares the functions related to the audio stream builder.<br>**File to include**: &lt;ohaudio/native_audiostreambuilder.h&gt;<br>**Library**: libohaudio.so|
24
25
26### Structs
27
28| Name| Description|
29| -------- | -------- |
30| struct&nbsp;&nbsp;[OH_AudioRenderer_Callbacks_Struct](_o_h___audio_renderer___callbacks___struct.md) | Defines a pointer to the callback functions related to an audio renderer.|
31| struct&nbsp;&nbsp;[OH_AudioCapturer_Callbacks_Struct](_o_h___audio_capturer___callbacks___struct.md) | Defines a pointer to the callback functions related to an audio capturer.|
32
33
34### Types
35
36| Name| Description|
37| -------- | -------- |
38| typedef struct OH_AudioStreamBuilderStruct [OH_AudioStreamBuilder](#oh_audiostreambuilder) | Defines an audio stream builder.|
39| typedef struct OH_AudioRendererStruct [OH_AudioRenderer](#oh_audiorenderer) | Defines an audio renderer.|
40| typedef struct OH_AudioCapturerStruct [OH_AudioCapturer](#oh_audiocapturer) | Defines an audio capturer.|
41| typedef struct [OH_AudioRenderer_Callbacks_Struct](_o_h___audio_renderer___callbacks___struct.md)[OH_AudioRenderer_Callbacks](#oh_audiorenderer_callbacks) | Defines a pointer to the callback functions related to an audio renderer.|
42| typedef struct [OH_AudioCapturer_Callbacks_Struct](_o_h___audio_capturer___callbacks___struct.md)[OH_AudioCapturer_Callbacks](#oh_audiocapturer_callbacks) | Defines a pointer to the callback functions related to an audio capturer.|
43
44
45### Enums
46
47| Name| Description|
48| -------- | -------- |
49| [OH_AudioStream_Result](#oh_audiostream_result) {<br>AUDIOSTREAM_SUCCESS = 0,<br>AUDIOSTREAM_ERROR_INVALID_PARAM = 1,<br>AUDIOSTREAM_ERROR_ILLEGAL_STATE = 2,<br>AUDIOSTREAM_ERROR_SYSTEM = 3<br>} | Enumerates the audio stream operation results.|
50| [OH_AudioStream_Type](#oh_audiostream_type) {<br>AUDIOSTREAM_TYPE_RERNDERER = 1,<br>AUDIOSTREAM_TYPE_CAPTURER = 2<br>} | Enumerates the audio stream types.|
51| [OH_AudioStream_SampleFormat](#oh_audiostream_sampleformat) {<br>AUDIOSTREAM_SAMPLE_U8 = 0,<br>AUDIOSTREAM_SAMPLE_S16LE = 1,<br>AUDIOSTREAM_SAMPLE_S24LE = 2,<br>AUDIOSTREAM_SAMPLE_S32LE = 3<br>} | Enumerates the sampling formats of audio streams.|
52| [OH_AudioStream_EncodingType](#oh_audiostream_encodingtype) {<br>AUDIOSTREAM_ENCODING_TYPE_RAW = 0<br>} | Enumerates the encoding types of audio streams.|
53| [OH_AudioStream_Usage](#oh_audiostream_usage) {<br>AUDIOSTREAM_USAGE_UNKNOWN = 0,<br>AUDIOSTREAM_USAGE_MUSIC = 1,<br>AUDIOSTREAM_USAGE_COMMUNICATION = 2,<br>AUDIOSTREAM_USAGE_VOICE_ASSISTANT = 3,<br>AUDIOSTREAM_USAGE_ALARM = 4,<br>AUDIOSTREAM_USAGE_VOICE_MESSAGE = 5,<br>AUDIOSTREAM_USAGE_RINGTONE = 6,<br>AUDIOSTREAM_USAGE_NOTIFICATION = 7,<br>AUDIOSTREAM_USAGE_ACCESSIBILITY = 8,<br>AUDIOSTREAM_USAGE_MOVIE = 10,<br>AUDIOSTREAM_USAGE_GAME = 11,<br>AUDIOSTREAM_USAGE_AUDIOBOOK = 12,<br>AUDIOSTREAM_USAGE_NAVIGATION = 13<br>} | Enumerates the usage scenarios of audio streams.|
54| [OH_AudioStream_LatencyMode](#oh_audiostream_latencymode) {<br>AUDIOSTREAM_LATENCY_MODE_NORMAL = 0,<br>AUDIOSTREAM_LATENCY_MODE_FAST = 1<br>} | Enumerates the latency modes of audio streams.|
55| [OH_AudioStream_State](#oh_audiostream_state) {<br>AUDIOSTREAM_STATE_INVALID = -1,<br>AUDIOSTREAM_STATE_NEW = 0,<br>AUDIOSTREAM_STATE_PREPARED = 1,<br>AUDIOSTREAM_STATE_RUNNING = 2,<br>AUDIOSTREAM_STATE_STOPPED = 3,<br>AUDIOSTREAM_STATE_RELEASED = 4,<br>AUDIOSTREAM_STATE_PAUSED = 5<br>} | Enumerates the audio stream states.|
56| [OH_AudioStream_SourceType](#oh_audiostream_sourcetype) {<br>AUDIOSTREAM_SOURCE_TYPE_INVALID = -1,<br>AUDIOSTREAM_SOURCE_TYPE_MIC = 0,<br>AUDIOSTREAM_SOURCE_TYPE_VOICE_RECOGNITION = 1,<br>AUDIOSTREAM_SOURCE_TYPE_PLAYBACK_CAPTURE = 2,<br>AUDIOSTREAM_SOURCE_TYPE_VOICE_COMMUNICATION = 7<br>} | Enumerates the usage scenarios of audio streams.|
57| [OH_AudioStream_Event](#oh_audiostream_event) {<br>AUDIOSTREAM_EVENT_ROUTING_CHANGED = 0<br>} | Enumerates the audio stream events.|
58| [OH_AudioInterrupt_ForceType](#oh_audiointerrupt_forcetype) {<br>AUDIOSTREAM_INTERRUPT_FORCE = 0,<br>AUDIOSTREAM_INTERRUPT_SHAR = 1<br>} | Enumerates the types of force that causes audio interruption.|
59| [OH_AudioInterrupt_Hint](#oh_audiointerrupt_hint) {<br>AUDIOSTREAM_INTERRUPT_HINT_NONE = 0,<br>AUDIOSTREAM_INTERRUPT_HINT_RESUME = 1,<br>AUDIOSTREAM_INTERRUPT_HINT_PAUSE = 2,<br>AUDIOSTREAM_INTERRUPT_HINT_STOP = 3,<br>AUDIOSTREAM_INTERRUPT_HINT_DUCK = 4,<br>AUDIOSTREAM_INTERRUPT_HINT_UNDUCK = 5<br>} | Enumerates the hints provided along with audio interruption.|
60
61
62### Functions
63
64| Name| Description|
65| -------- | -------- |
66| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioCapturer_Release](#oh_audiocapturer_release) ([OH_AudioCapturer](#oh_audiocapturer) \*capturer) | Releases an audio capturer.|
67| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioCapturer_Start](#oh_audiocapturer_start) ([OH_AudioCapturer](#oh_audiocapturer) \*capturer) | Starts an audio capturer.|
68| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioCapturer_Pause](#oh_audiocapturer_pause) ([OH_AudioCapturer](#oh_audiocapturer) \*capturer) | Pauses an audio capturer.|
69| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioCapturer_Stop](#oh_audiocapturer_stop) ([OH_AudioCapturer](#oh_audiocapturer) \*capturer) | Stops an audio capturer.|
70| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioCapturer_Flush](#oh_audiocapturer_flush) ([OH_AudioCapturer](#oh_audiocapturer) \*capturer) | Flushes obtained audio data.|
71| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioCapturer_GetCurrentState](#oh_audiocapturer_getcurrentstate) ([OH_AudioCapturer](#oh_audiocapturer) \*capturer, [OH_AudioStream_State](#oh_audiostream_state) \*state) | Obtains the state of an audio capturer.|
72| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioCapturer_GetLatencyMode](#oh_audiocapturer_getlatencymode) ([OH_AudioCapturer](#oh_audiocapturer) \*capturer, [OH_AudioStream_LatencyMode](#oh_audiostream_latencymode) \*latencyMode) | Obtains the latency mode of an audio capturer.|
73| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioCapturer_GetStreamId](#oh_audiocapturer_getstreamid) ([OH_AudioCapturer](#oh_audiocapturer) \*capturer, uint32_t \*streamId) | Obtains the stream ID of an audio capturer.|
74| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioCapturer_GetSamplingRate](#oh_audiocapturer_getsamplingrate) ([OH_AudioCapturer](#oh_audiocapturer) \*capturer, int32_t \*rate) | Obtains the sampling rate of an audio capturer.|
75| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioCapturer_GetChannelCount](#oh_audiocapturer_getchannelcount) ([OH_AudioCapturer](#oh_audiocapturer) \*capturer, int32_t \*channelCount) | Obtains the number of channels for an audio capturer.|
76| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioCapturer_GetSampleFormat](#oh_audiocapturer_getsampleformat) ([OH_AudioCapturer](#oh_audiocapturer) \*capturer, [OH_AudioStream_SampleFormat](#oh_audiostream_sampleformat) \*sampleFormat) | Obtains the sampling format of an audio capturer.|
77| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioCapturer_GetEncodingType](#oh_audiocapturer_getencodingtype) ([OH_AudioCapturer](#oh_audiocapturer) \*capturer, [OH_AudioStream_EncodingType](#oh_audiostream_encodingtype) \*encodingType) | Obtains the encoding type of an audio capturer.|
78| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioCapturer_GetCapturerInfo](#oh_audiocapturer_getcapturerinfo) ([OH_AudioCapturer](#oh_audiocapturer) \*capturer, [OH_AudioStream_SourceType](#oh_audiostream_sourcetype) \*sourceType) | Obtains the usage scenario of an audio capturer.|
79| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioCapturer_GetFrameSizeInCallback](#oh_audiocapturer_getframesizeincallback) ([OH_AudioCapturer](#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.|
80| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioCapturer_GetTimestamp](#oh_audiocapturer_gettimestamp) ([OH_AudioCapturer](#oh_audiocapturer) \*capturer, clockid_t clockId, int64_t \*framePosition, int64_t \*timestamp) | Obtains the timestamp and position information of an audio input stream.|
81| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioCapturer_GetFramesRead](#oh_audiocapturer_getframesread) ([OH_AudioCapturer](#oh_audiocapturer) \*capturer, int64_t \*frames) | Obtains the number of frames that have been read since the stream was created.|
82| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioRenderer_Release](#oh_audiorenderer_release) ([OH_AudioRenderer](#oh_audiorenderer) \*renderer) | Releases an audio renderer.|
83| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioRenderer_Start](#oh_audiorenderer_start) ([OH_AudioRenderer](#oh_audiorenderer) \*renderer) | Starts an audio renderer.|
84| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioRenderer_Pause](#oh_audiorenderer_pause) ([OH_AudioRenderer](#oh_audiorenderer) \*renderer) | Pauses an audio renderer.|
85| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioRenderer_Stop](#oh_audiorenderer_stop) ([OH_AudioRenderer](#oh_audiorenderer) \*renderer) | Stops an audio renderer.|
86| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioRenderer_Flush](#oh_audiorenderer_flush) ([OH_AudioRenderer](#oh_audiorenderer) \*renderer) | Flushes written audio data.|
87| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioRenderer_GetCurrentState](#oh_audiorenderer_getcurrentstate) ([OH_AudioRenderer](#oh_audiorenderer) \*renderer, [OH_AudioStream_State](#oh_audiostream_state) \*state) | Obtains the state of an audio renderer.|
88| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioRenderer_GetSamplingRate](#oh_audiorenderer_getsamplingrate) ([OH_AudioRenderer](#oh_audiorenderer) \*renderer, int32_t \*rate) | Obtains the sampling rate of an audio renderer.|
89| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioRenderer_GetStreamId](#oh_audiorenderer_getstreamid) ([OH_AudioRenderer](#oh_audiorenderer) \*renderer, uint32_t \*streamId) | Obtains the stream ID of an audio renderer.|
90| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioRenderer_GetChannelCount](#oh_audiorenderer_getchannelcount) ([OH_AudioRenderer](#oh_audiorenderer) \*renderer, int32_t \*channelCount) | Obtains the number of channels for an audio renderer.|
91| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioRenderer_GetSampleFormat](#oh_audiorenderer_getsampleformat) ([OH_AudioRenderer](#oh_audiorenderer) \*renderer, [OH_AudioStream_SampleFormat](#oh_audiostream_sampleformat) \*sampleFormat) | Obtains the sampling format of an audio renderer.|
92| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioRenderer_GetLatencyMode](#oh_audiorenderer_getlatencymode) ([OH_AudioRenderer](#oh_audiorenderer) \*renderer, [OH_AudioStream_LatencyMode](#oh_audiostream_latencymode) \*latencyMode) | Obtains the latency mode of an audio renderer.|
93| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioRenderer_GetRendererInfo](#oh_audiorenderer_getrendererinfo) ([OH_AudioRenderer](#oh_audiorenderer) \*renderer, [OH_AudioStream_Usage](#oh_audiostream_usage) \*usage) | Obtains the usage scenario of an audio renderer.|
94| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioRenderer_GetEncodingType](#oh_audiorenderer_getencodingtype) ([OH_AudioRenderer](#oh_audiorenderer) \*renderer, [OH_AudioStream_EncodingType](#oh_audiostream_encodingtype) \*encodingType) | Obtains the encoding type of an audio renderer.|
95| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioRenderer_GetFramesWritten](#oh_audiorenderer_getframeswritten) ([OH_AudioRenderer](#oh_audiorenderer) \*renderer, int64_t \*frames) | Obtains the number of frames that have been written since the stream was created.|
96| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioRenderer_GetTimestamp](#oh_audiorenderer_gettimestamp) ([OH_AudioRenderer](#oh_audiorenderer) \*renderer, clockid_t clockId, int64_t \*framePosition, int64_t \*timestamp) | Obtains the timestamp and position information of an audio output stream.|
97| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioRenderer_GetFrameSizeInCallback](#oh_audiorenderer_getframesizeincallback) ([OH_AudioRenderer](#oh_audiorenderer) \*renderer, int32_t \*frameSize) | Obtains the frame size in the callback.|
98| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioStreamBuilder_Create](#oh_audiostreambuilder_create) ([OH_AudioStreamBuilder](#oh_audiostreambuilder) \*\*builder, [OH_AudioStream_Type](#oh_audiostream_type) type) | Creates an audio stream builder, which can be an audio renderer or capturer.|
99| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioStreamBuilder_Destroy](#oh_audiostreambuilder_destroy) ([OH_AudioStreamBuilder](#oh_audiostreambuilder) \*builder) | Destroys an audio stream builder.|
100| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioStreamBuilder_SetSamplingRate](#oh_audiostreambuilder_setsamplingrate) ([OH_AudioStreamBuilder](#oh_audiostreambuilder) \*builder, int32_t rate) | Sets the sampling rate of an audio stream.|
101| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioStreamBuilder_SetChannelCount](#oh_audiostreambuilder_setchannelcount) ([OH_AudioStreamBuilder](#oh_audiostreambuilder) \*builder, int32_t channelCount) | Sets the number of channels for an audio stream.|
102| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioStreamBuilder_SetSampleFormat](#oh_audiostreambuilder_setsampleformat) ([OH_AudioStreamBuilder](#oh_audiostreambuilder) \*builder, [OH_AudioStream_SampleFormat](#oh_audiostream_sampleformat) format) | Sets the sampling format of an audio stream.|
103| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioStreamBuilder_SetEncodingType](#oh_audiostreambuilder_setencodingtype) ([OH_AudioStreamBuilder](#oh_audiostreambuilder) \*builder, [OH_AudioStream_EncodingType](#oh_audiostream_encodingtype) encodingType) | Sets the encoding type of an audio stream.|
104| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioStreamBuilder_SetLatencyMode](#oh_audiostreambuilder_setlatencymode) ([OH_AudioStreamBuilder](#oh_audiostreambuilder) \*builder, [OH_AudioStream_LatencyMode](#oh_audiostream_latencymode) latencyMode) | Sets the latency mode of an audio stream.|
105| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioStreamBuilder_SetRendererInfo](#oh_audiostreambuilder_setrendererinfo) ([OH_AudioStreamBuilder](#oh_audiostreambuilder) \*builder, [OH_AudioStream_Usage](#oh_audiostream_usage) usage) | Sets the usage scenario of an audio renderer.|
106| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioStreamBuilder_SetCapturerInfo](#oh_audiostreambuilder_setcapturerinfo) ([OH_AudioStreamBuilder](#oh_audiostreambuilder) \*builder, [OH_AudioStream_SourceType](#oh_audiostream_sourcetype) sourceType) | Sets the usage scenario of an audio capturer.|
107| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioStreamBuilder_SetRendererCallback](#oh_audiostreambuilder_setrenderercallback) ([OH_AudioStreamBuilder](#oh_audiostreambuilder) \*builder, [OH_AudioRenderer_Callbacks](#oh_audiorenderer_callbacks) callbacks, void \*userData) | Sets callbacks for an audio renderer.|
108| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioStreamBuilder_SetCapturerCallback](#oh_audiostreambuilder_setcapturercallback) ([OH_AudioStreamBuilder](#oh_audiostreambuilder) \*builder, [OH_AudioCapturer_Callbacks](#oh_audiocapturer_callbacks) callbacks, void \*userData) | Sets callbacks for an audio capturer.|
109| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioStreamBuilder_GenerateRenderer](#oh_audiostreambuilder_generaterenderer) ([OH_AudioStreamBuilder](#oh_audiostreambuilder) \*builder, [OH_AudioRenderer](#oh_audiorenderer) \*\*audioRenderer) | Creates an audio renderer instance.|
110| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioStreamBuilder_GenerateCapturer](#oh_audiostreambuilder_generatecapturer) ([OH_AudioStreamBuilder](#oh_audiostreambuilder) \*builder, [OH_AudioCapturer](#oh_audiocapturer) \*\*audioCapturer) | Creates an audio capturer instance.|
111| [OH_AudioStream_Result](#oh_audiostream_result)[OH_AudioStreamBuilder_SetFrameSizeInCallback](#oh_audiostreambuilder_setframesizeincallback) ([OH_AudioStreamBuilder](#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.|
112
113
114## Type Description
115
116
117### OH_AudioCapturer
118
119```
120typedef struct OH_AudioCapturerStruct OH_AudioCapturer
121```
122
123**Description**
124
125Defines an audio capturer.
126
127An audio capturer instance is used to capture audio data.
128
129**System capability**: SystemCapability.Multimedia.Audio.Core
130
131**Since**: 10
132
133
134### OH_AudioCapturer_Callbacks
135
136```
137typedef struct OH_AudioCapturer_Callbacks_Struct OH_AudioCapturer_Callbacks
138```
139
140**Description**
141
142Defines a pointer to the callback functions related to an audio capturer.
143
144**System capability**: SystemCapability.Multimedia.Audio.Core
145
146**Since**: 10
147
148
149### OH_AudioRenderer
150
151```
152typedef struct OH_AudioRendererStruct OH_AudioRenderer
153```
154
155**Description**
156
157Defines an audio renderer.
158
159An audio renderer instance is used to render audio data.
160
161**System capability**: SystemCapability.Multimedia.Audio.Core
162
163**Since**: 10
164
165
166### OH_AudioRenderer_Callbacks
167
168```
169typedef struct OH_AudioRenderer_Callbacks_Struct OH_AudioRenderer_Callbacks
170```
171
172**Description**
173
174Defines a pointer to the callback functions related to an audio renderer.
175
176**System capability**: SystemCapability.Multimedia.Audio.Core
177
178**Since**: 10
179
180
181### OH_AudioStreamBuilder
182
183```
184typedef struct OH_AudioStreamBuilderStruct OH_AudioStreamBuilder
185```
186
187**Description**
188
189Defines an audio stream builder.
190
191An audio stream builder instance is often used to create an audio stream and set its attributes.
192
193**System capability**: SystemCapability.Multimedia.Audio.Core
194
195**Since**: 10
196
197
198## Enum Description
199
200
201### OH_AudioInterrupt_ForceType
202
203```
204enum OH_AudioInterrupt_ForceType
205```
206
207**Description**
208
209Enumerates the types of force that causes audio interruption.
210
211This enum is used to describe audio interruption events.
212
213**System capability**: SystemCapability.Multimedia.Audio.Core
214
215**Since**: 10
216
217| Value| Description|
218| -------- | -------- |
219| AUDIOSTREAM_INTERRUPT_FORCE | The system changes the audio status.|
220| AUDIOSTREAM_INTERRUPT_SHAR | The application changes the audio status.|
221
222
223### OH_AudioInterrupt_Hint
224
225```
226enum OH_AudioInterrupt_Hint
227```
228
229**Description**
230
231Enumerates the types of force that causes audio interruption.
232
233This enum is used to describe audio interruption events.
234
235**System capability**: SystemCapability.Multimedia.Audio.Core
236
237**Since**: 10
238
239| Value| Description|
240| -------- | -------- |
241| AUDIOSTREAM_INTERRUPT_HINT_NONE | None.|
242| AUDIOSTREAM_INTERRUPT_HINT_RESUME | Resume the playback.|
243| AUDIOSTREAM_INTERRUPT_HINT_PAUSE | Paused/Pause the playback.|
244| AUDIOSTREAM_INTERRUPT_HINT_STOP | Stopped/Stop the playback.|
245| AUDIOSTREAM_INTERRUPT_HINT_DUCK | Ducked the playback.|
246| AUDIOSTREAM_INTERRUPT_HINT_UNDUCK | Unducked the playback.|
247
248
249### OH_AudioStream_EncodingType
250
251```
252enum OH_AudioStream_EncodingType
253```
254
255**Description**
256
257Enumerates the encoding types of audio streams.
258
259**System capability**: SystemCapability.Multimedia.Audio.Core
260
261**Since**: 10
262
263| Value| Description|
264| -------- | -------- |
265| AUDIOSTREAM_ENCODING_TYPE_RAW | PCM encoding.|
266
267
268### OH_AudioStream_Event
269
270```
271enum OH_AudioStream_Event
272```
273
274**Description**
275
276Enumerates the audio stream events.
277
278This enum is used to describe audio events.
279
280**System capability**: SystemCapability.Multimedia.Audio.Core
281
282**Since**: 10
283
284| Value| Description|
285| -------- | -------- |
286| AUDIOSTREAM_EVENT_ROUTING_CHANGED | The audio route has been changed.|
287
288
289### OH_AudioStream_LatencyMode
290
291```
292enum OH_AudioStream_LatencyMode
293```
294
295**Description**
296
297Enumerates the latency modes of audio streams.
298
299**System capability**: SystemCapability.Multimedia.Audio.Core
300
301**Since**: 10
302
303| Value| Description|
304| -------- | -------- |
305| AUDIOSTREAM_LATENCY_MODE_NORMAL | Normal latency mode.|
306| AUDIOSTREAM_LATENCY_MODE_FAST | Low latency mode.|
307
308
309### OH_AudioStream_Result
310
311```
312enum OH_AudioStream_Result
313```
314
315**Description**
316
317Enumerates the audio stream operation results.
318
319**System capability**: SystemCapability.Multimedia.Audio.Core
320
321**Since**: 10
322
323| Value| Description|
324| -------- | -------- |
325| AUDIOSTREAM_SUCCESS | The operation is successful.|
326| AUDIOSTREAM_ERROR_INVALID_PARAM | Invalid input parameter.|
327| AUDIOSTREAM_ERROR_ILLEGAL_STATE | Invalid state.|
328| AUDIOSTREAM_ERROR_SYSTEM | System error.|
329
330
331### OH_AudioStream_SampleFormat
332
333```
334enum OH_AudioStream_SampleFormat
335```
336
337**Description**
338
339Enumerates the sampling formats of audio streams.
340
341**System capability**: SystemCapability.Multimedia.Audio.Core
342
343**Since**: 10
344
345| Value| Description|
346| -------- | -------- |
347| AUDIOSTREAM_SAMPLE_U8 | Unsigned 8-bit.|
348| AUDIOSTREAM_SAMPLE_S16LE | Short 16-bit little-endian.|
349| AUDIOSTREAM_SAMPLE_S24LE | Short 24-bit little-endian.|
350| AUDIOSTREAM_SAMPLE_S32LE | Short 32-bit little-endian.|
351
352
353### OH_AudioStream_SourceType
354
355```
356enum OH_AudioStream_SourceType
357```
358
359**Description**
360
361Enumerates the usage scenarios of an audio capturer, that is, the usage scenarios of audio input streams.
362
363**System capability**: SystemCapability.Multimedia.Audio.Core
364
365**Since**: 10
366
367| Value| Description|
368| -------- | -------- |
369| AUDIOSTREAM_SOURCE_TYPE_INVALID | Invalid state.|
370| AUDIOSTREAM_SOURCE_TYPE_MIC | Audio recording.|
371| AUDIOSTREAM_SOURCE_TYPE_VOICE_RECOGNITION | Voice recognition.|
372| AUDIOSTREAM_SOURCE_TYPE_PLAYBACK_CAPTURE | Audio playback.|
373| AUDIOSTREAM_SOURCE_TYPE_VOICE_COMMUNICATION | Voice communication.|
374
375
376### OH_AudioStream_State
377
378```
379enum OH_AudioStream_State
380```
381
382**Description**
383
384Enumerates the audio stream states.
385
386**System capability**: SystemCapability.Multimedia.Audio.Core
387
388**Since**: 10
389
390| Value| Description|
391| -------- | -------- |
392| AUDIOSTREAM_STATE_INVALID | Invalid state.|
393| AUDIOSTREAM_STATE_NEW | Newly created.|
394| AUDIOSTREAM_STATE_PREPARED | Prepared.|
395| AUDIOSTREAM_STATE_RUNNING | Running.|
396| AUDIOSTREAM_STATE_STOPPED | Stopped.|
397| AUDIOSTREAM_STATE_RELEASED | Released.|
398| AUDIOSTREAM_STATE_PAUSED | Paused.|
399
400
401### OH_AudioStream_Type
402
403```
404enum OH_AudioStream_Type
405```
406
407**Description**
408
409Enumerates the audio stream types.
410
411**System capability**: SystemCapability.Multimedia.Audio.Core
412
413**Since**: 10
414
415| Value| Description|
416| -------- | -------- |
417| AUDIOSTREAM_TYPE_RERNDERER | The audio stream is an output stream.|
418| AUDIOSTREAM_TYPE_CAPTURER | The audio stream is an input stream.|
419
420
421### OH_AudioStream_Usage
422
423```
424enum OH_AudioStream_Usage
425```
426
427**Description**
428
429Enumerates the usage scenarios of an audio renderer, that is, the usage scenarios of audio output streams.
430
431**System capability**: SystemCapability.Multimedia.Audio.Core
432
433**Since**: 10
434
435| Value| Description|
436| -------- | -------- |
437| AUDIOSTREAM_USAGE_UNKNOWN | Undefined.|
438| AUDIOSTREAM_USAGE_MUSIC | Music.|
439| AUDIOSTREAM_USAGE_COMMUNICATION | Voice communication.|
440| AUDIOSTREAM_USAGE_VOICE_ASSISTANT | Voice assistant.|
441| AUDIOSTREAM_USAGE_ALARM | Alarming.|
442| AUDIOSTREAM_USAGE_VOICE_MESSAGE | Voice message.|
443| AUDIOSTREAM_USAGE_RINGTONE | Ringtone.|
444| AUDIOSTREAM_USAGE_NOTIFICATION | Notification.|
445| AUDIOSTREAM_USAGE_ACCESSIBILITY | Accessibility.|
446| AUDIOSTREAM_USAGE_MOVIE | Video.|
447| AUDIOSTREAM_USAGE_GAME | Gaming.|
448| AUDIOSTREAM_USAGE_AUDIOBOOK | Audiobook.|
449| AUDIOSTREAM_USAGE_NAVIGATION | Navigation.|
450
451
452## Function Description
453
454
455### OH_AudioCapturer_Flush()
456
457```
458OH_AudioStream_Result OH_AudioCapturer_Flush (OH_AudioCapturer * capturer)
459```
460
461**Description**
462
463Flushes obtained audio data.
464
465**Since**: 10
466
467**System capability**: SystemCapability.Multimedia.Audio.Core
468
469**Parameters**
470
471| Name| Description|
472| -------- | -------- |
473| capturer | Pointer to an audio capturer instance created by [OH_AudioStreamBuilder_GenerateCapturer](#oh_audiostreambuilder_generatecapturer).|
474
475**Returns**
476
477Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
478
479
480### OH_AudioCapturer_GetCapturerInfo()
481
482```
483OH_AudioStream_Result OH_AudioCapturer_GetCapturerInfo (OH_AudioCapturer * capturer, OH_AudioStream_SourceType * sourceType )
484```
485
486**Description**
487
488Obtains the usage scenario of an audio capturer.
489
490**Since**: 10
491
492**System capability**: SystemCapability.Multimedia.Audio.Core
493
494**Parameters**
495
496| Name| Description|
497| -------- | -------- |
498| capturer | Pointer to an audio capturer instance created by [OH_AudioStreamBuilder_GenerateCapturer](#oh_audiostreambuilder_generatecapturer).|
499| sourceType | Pointer to a variable used to receive the usage scenario.|
500
501**Returns**
502
503Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
504
505
506### OH_AudioCapturer_GetChannelCount()
507
508```
509OH_AudioStream_Result OH_AudioCapturer_GetChannelCount (OH_AudioCapturer * capturer, int32_t * channelCount )
510```
511
512**Description**
513
514Obtains the number of channels for an audio capturer.
515
516**Since**: 10
517
518**System capability**: SystemCapability.Multimedia.Audio.Core
519
520**Parameters**
521
522| Name| Description|
523| -------- | -------- |
524| capturer | Pointer to an audio capturer instance created by [OH_AudioStreamBuilder_GenerateCapturer](#oh_audiostreambuilder_generatecapturer).|
525| channelCount | Pointer to a variable used to receive the number of channels.|
526
527**Returns**
528
529Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
530
531
532### OH_AudioCapturer_GetCurrentState()
533
534```
535OH_AudioStream_Result OH_AudioCapturer_GetCurrentState (OH_AudioCapturer * capturer, OH_AudioStream_State * state )
536```
537
538**Description**
539
540Obtains the state of an audio capturer.
541
542**Since**: 10
543
544**System capability**: SystemCapability.Multimedia.Audio.Core
545
546**Parameters**
547
548| Name| Description|
549| -------- | -------- |
550| capturer | Pointer to an audio capturer instance created by [OH_AudioStreamBuilder_GenerateCapturer](#oh_audiostreambuilder_generatecapturer).|
551| state | Pointer to a variable used to receive the state.|
552
553**Returns**
554
555Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
556
557
558### OH_AudioCapturer_GetEncodingType()
559
560```
561OH_AudioStream_Result OH_AudioCapturer_GetEncodingType (OH_AudioCapturer * capturer, OH_AudioStream_EncodingType * encodingType )
562```
563
564**Description**
565
566Obtains the encoding type of an audio capturer.
567
568**Since**: 10
569
570**System capability**: SystemCapability.Multimedia.Audio.Core
571
572**Parameters**
573
574| Name| Description|
575| -------- | -------- |
576| capturer | Pointer to an audio capturer instance created by [OH_AudioStreamBuilder_GenerateCapturer](#oh_audiostreambuilder_generatecapturer).|
577| encodingType | Pointer to a variable used to receive the encoding type.|
578
579**Returns**
580
581Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
582
583
584### OH_AudioCapturer_GetFrameSizeInCallback()
585
586```
587OH_AudioStream_Result OH_AudioCapturer_GetFrameSizeInCallback (OH_AudioCapturer * capturer, int32_t * frameSize )
588```
589
590**Description**
591
592Obtains the frame size in the callback. The frame size is the fixed length of the buffer returned by each callback.
593
594**Since**: 10
595
596**System capability**: SystemCapability.Multimedia.Audio.Core
597
598**Parameters**
599
600| Name| Description|
601| -------- | -------- |
602| capturer | Pointer to an audio capturer instance created by [OH_AudioStreamBuilder_GenerateCapturer](#oh_audiostreambuilder_generatecapturer).|
603| frameSize | Pointer to the variable that holds the frame size.|
604
605**Returns**
606
607Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
608
609
610### OH_AudioCapturer_GetFramesRead()
611
612```
613OH_AudioStream_Result OH_AudioCapturer_GetFramesRead (OH_AudioCapturer * capturer, int64_t * frames )
614```
615
616**Description**
617
618Obtains the number of frames that have been read since the stream was created.
619
620**Since**: 10
621
622**System capability**: SystemCapability.Multimedia.Audio.Core
623
624**Parameters**
625
626| Name| Description|
627| -------- | -------- |
628| capturer | Pointer to an audio capturer instance created by [OH_AudioStreamBuilder_GenerateCapturer](#oh_audiostreambuilder_generatecapturer).|
629| frames | Pointer to the variable that holds the frame count.|
630
631**Returns**
632
633Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
634
635
636### OH_AudioCapturer_GetLatencyMode()
637
638```
639OH_AudioStream_Result OH_AudioCapturer_GetLatencyMode (OH_AudioCapturer * capturer, OH_AudioStream_LatencyMode * latencyMode )
640```
641
642**Description**
643
644Obtains the latency mode of an audio capturer.
645
646**Since**: 10
647
648**System capability**: SystemCapability.Multimedia.Audio.Core
649
650**Parameters**
651
652| Name| Description|
653| -------- | -------- |
654| capturer | Pointer to an audio capturer instance created by [OH_AudioStreamBuilder_GenerateCapturer](#oh_audiostreambuilder_generatecapturer).|
655| latencyMode | Pointer to a variable used to receive the latency mode.|
656
657**Returns**
658
659Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
660
661
662### OH_AudioCapturer_GetSampleFormat()
663
664```
665OH_AudioStream_Result OH_AudioCapturer_GetSampleFormat (OH_AudioCapturer * capturer, OH_AudioStream_SampleFormat * sampleFormat )
666```
667
668**Description**
669
670Obtains the sampling format of an audio capturer.
671
672**Since**: 10
673
674**System capability**: SystemCapability.Multimedia.Audio.Core
675
676**Parameters**
677
678| Name| Description|
679| -------- | -------- |
680| capturer | Pointer to an audio capturer instance created by [OH_AudioStreamBuilder_GenerateCapturer](#oh_audiostreambuilder_generatecapturer).|
681| sampleFormat | Pointer to a variable used to receive the sampling format.|
682
683**Returns**
684
685Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
686
687
688### OH_AudioCapturer_GetSamplingRate()
689
690```
691OH_AudioStream_Result OH_AudioCapturer_GetSamplingRate (OH_AudioCapturer * capturer, int32_t * rate )
692```
693
694**Description**
695
696Obtains the sampling rate of an audio capturer.
697
698**Since**: 10
699
700**System capability**: SystemCapability.Multimedia.Audio.Core
701
702**Parameters**
703
704| Name| Description|
705| -------- | -------- |
706| capturer | Pointer to an audio capturer instance created by [OH_AudioStreamBuilder_GenerateCapturer](#oh_audiostreambuilder_generatecapturer).|
707| rate | Pointer to a variable used to receive the sampling rate.|
708
709**Returns**
710
711Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
712
713
714### OH_AudioCapturer_GetStreamId()
715
716```
717OH_AudioStream_Result OH_AudioCapturer_GetStreamId (OH_AudioCapturer * capturer, uint32_t * streamId )
718```
719
720**Description**
721
722Obtains the stream ID of an audio capturer.
723
724**Since**: 10
725
726**System capability**: SystemCapability.Multimedia.Audio.Core
727
728**Parameters**
729
730| Name| Description|
731| -------- | -------- |
732| capturer | Pointer to an audio capturer instance created by [OH_AudioStreamBuilder_GenerateCapturer](#oh_audiostreambuilder_generatecapturer).|
733| streamId | Pointer to a variable used to receive the stream ID.|
734
735**Returns**
736
737Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
738
739
740### OH_AudioCapturer_GetTimestamp()
741
742```
743OH_AudioStream_Result OH_AudioCapturer_GetTimestamp (OH_AudioCapturer * capturer, clockid_t clockId, int64_t * framePosition, int64_t * timestamp )
744```
745
746**Description**
747
748Obtains the timestamp and position information of an audio input stream.
749
750**Since**: 10
751
752**System capability**: SystemCapability.Multimedia.Audio.Core
753
754**Parameters**
755
756| Name| Description|
757| -------- | -------- |
758| capturer | Pointer to an audio capturer instance created by [OH_AudioStreamBuilder_GenerateCapturer](#oh_audiostreambuilder_generatecapturer).|
759| clockId | CLOCK_MONOTONIC.|
760| framePosition | Pointer to the variable that holds the position information.|
761| timestamp | Pointer to the variable that holds the timestamp.|
762
763**Returns**
764
765Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
766
767
768### OH_AudioCapturer_Pause()
769
770```
771OH_AudioStream_Result OH_AudioCapturer_Pause (OH_AudioCapturer * capturer)
772```
773
774**Description**
775
776Pauses an audio capturer.
777
778**Since**: 10
779
780**System capability**: SystemCapability.Multimedia.Audio.Core
781
782**Parameters**
783
784| Name| Description|
785| -------- | -------- |
786| capturer | Pointer to an audio capturer instance created by [OH_AudioStreamBuilder_GenerateCapturer](#oh_audiostreambuilder_generatecapturer).|
787
788**Required permissions**
789
790ohos.permission.MICROPHONE
791
792**Returns**
793
794Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
795
796
797### OH_AudioCapturer_Release()
798
799```
800OH_AudioStream_Result OH_AudioCapturer_Release (OH_AudioCapturer * capturer)
801```
802
803**Description**
804
805Releases an audio capturer.
806
807**Since**: 10
808
809**System capability**: SystemCapability.Multimedia.Audio.Core
810
811**Parameters**
812
813| Name| Description|
814| -------- | -------- |
815| capturer | Pointer to an audio capturer instance created by [OH_AudioStreamBuilder_GenerateCapturer](#oh_audiostreambuilder_generatecapturer).|
816
817**Required permissions**
818
819ohos.permission.MICROPHONE
820
821**Returns**
822
823Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
824
825
826### OH_AudioCapturer_Start()
827
828```
829OH_AudioStream_Result OH_AudioCapturer_Start (OH_AudioCapturer * capturer)
830```
831
832**Description**
833
834Starts an audio capturer.
835
836**Since**: 10
837
838**System capability**: SystemCapability.Multimedia.Audio.Core
839
840**Parameters**
841
842| Name| Description|
843| -------- | -------- |
844| capturer | Pointer to an audio capturer instance created by [OH_AudioStreamBuilder_GenerateCapturer](#oh_audiostreambuilder_generatecapturer).|
845
846**Required permissions**
847
848ohos.permission.MICROPHONE
849
850**Returns**
851
852Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
853
854
855### OH_AudioCapturer_Stop()
856
857```
858OH_AudioStream_Result OH_AudioCapturer_Stop (OH_AudioCapturer * capturer)
859```
860
861**Description**
862
863Stops an audio capturer.
864
865**Since**: 10
866
867**System capability**: SystemCapability.Multimedia.Audio.Core
868
869**Parameters**
870
871| Name| Description|
872| -------- | -------- |
873| capturer | Pointer to an audio capturer instance created by [OH_AudioStreamBuilder_GenerateCapturer](#oh_audiostreambuilder_generatecapturer).|
874
875**Required permissions**
876
877ohos.permission.MICROPHONE
878
879**Returns**
880
881Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
882
883
884### OH_AudioRenderer_Flush()
885
886```
887OH_AudioStream_Result OH_AudioRenderer_Flush (OH_AudioRenderer * renderer)
888```
889
890**Description**
891
892Flushes written audio data.
893
894**Since**: 10
895
896**System capability**: SystemCapability.Multimedia.Audio.Core
897
898**Parameters**
899
900| Name| Description|
901| -------- | -------- |
902| renderer | Pointer to an audio renderer instance created by [OH_AudioStreamBuilder_GenerateRenderer](#oh_audiostreambuilder_generaterenderer).|
903
904**Returns**
905
906Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
907
908
909### OH_AudioRenderer_GetChannelCount()
910
911```
912OH_AudioStream_Result OH_AudioRenderer_GetChannelCount (OH_AudioRenderer * renderer, int32_t * channelCount )
913```
914
915**Description**
916
917Obtains the number of channels for an audio renderer.
918
919**Since**: 10
920
921**System capability**: SystemCapability.Multimedia.Audio.Core
922
923**Parameters**
924
925| Name| Description|
926| -------- | -------- |
927| renderer | Pointer to an audio renderer instance created by [OH_AudioStreamBuilder_GenerateRenderer](#oh_audiostreambuilder_generaterenderer).|
928| channelCount | Pointer to a variable used to receive the number of channels.|
929
930**Returns**
931
932Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
933
934
935### OH_AudioRenderer_GetCurrentState()
936
937```
938OH_AudioStream_Result OH_AudioRenderer_GetCurrentState (OH_AudioRenderer * renderer, OH_AudioStream_State * state )
939```
940
941**Description**
942
943Obtains the state of an audio renderer.
944
945**Since**: 10
946
947**System capability**: SystemCapability.Multimedia.Audio.Core
948
949**Parameters**
950
951| Name| Description|
952| -------- | -------- |
953| renderer | Pointer to an audio renderer instance created by [OH_AudioStreamBuilder_GenerateRenderer](#oh_audiostreambuilder_generaterenderer).|
954| state | Pointer to a variable used to receive the state.|
955
956**Returns**
957
958Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
959
960
961### OH_AudioRenderer_GetEncodingType()
962
963```
964OH_AudioStream_Result OH_AudioRenderer_GetEncodingType (OH_AudioRenderer * renderer, OH_AudioStream_EncodingType * encodingType )
965```
966
967**Description**
968
969Obtains the encoding type of an audio renderer.
970
971**Since**: 10
972
973**System capability**: SystemCapability.Multimedia.Audio.Core
974
975**Parameters**
976
977| Name| Description|
978| -------- | -------- |
979| renderer | Pointer to an audio renderer instance created by [OH_AudioStreamBuilder_GenerateRenderer](#oh_audiostreambuilder_generaterenderer).|
980| encodingType | Pointer to a variable used to receive the encoding type.|
981
982**Returns**
983
984Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
985
986
987### OH_AudioRenderer_GetFrameSizeInCallback()
988
989```
990OH_AudioStream_Result OH_AudioRenderer_GetFrameSizeInCallback (OH_AudioRenderer * renderer, int32_t * frameSize )
991```
992
993**Description**
994
995Obtains the frame size in the callback. The frame size is the fixed length of the buffer returned by each callback.
996
997**Since**: 10
998
999**System capability**: SystemCapability.Multimedia.Audio.Core
1000
1001**Parameters**
1002
1003| Name| Description|
1004| -------- | -------- |
1005| renderer | Pointer to an audio renderer instance created by [OH_AudioStreamBuilder_GenerateRenderer](#oh_audiostreambuilder_generaterenderer).|
1006| frameSize | Pointer to the variable that holds the frame size.|
1007
1008**Returns**
1009
1010Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
1011
1012
1013### OH_AudioRenderer_GetFramesWritten()
1014
1015```
1016OH_AudioStream_Result OH_AudioRenderer_GetFramesWritten (OH_AudioRenderer * renderer, int64_t * frames )
1017```
1018
1019**Description**
1020
1021Obtains the number of frames that have been written since the stream was created.
1022
1023**Since**: 10
1024
1025**System capability**: SystemCapability.Multimedia.Audio.Core
1026
1027**Parameters**
1028
1029| Name| Description|
1030| -------- | -------- |
1031| renderer | Pointer to an audio renderer instance created by [OH_AudioStreamBuilder_GenerateRenderer](#oh_audiostreambuilder_generaterenderer).|
1032| frames | Pointer to the variable that holds the frame count.|
1033
1034**Returns**
1035
1036Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
1037
1038
1039### OH_AudioRenderer_GetLatencyMode()
1040
1041```
1042OH_AudioStream_Result OH_AudioRenderer_GetLatencyMode (OH_AudioRenderer * renderer, OH_AudioStream_LatencyMode * latencyMode )
1043```
1044
1045**Description**
1046
1047Obtains the latency mode of an audio renderer.
1048
1049**Since**: 10
1050
1051**System capability**: SystemCapability.Multimedia.Audio.Core
1052
1053**Parameters**
1054
1055| Name| Description|
1056| -------- | -------- |
1057| renderer | Pointer to an audio renderer instance created by [OH_AudioStreamBuilder_GenerateRenderer](#oh_audiostreambuilder_generaterenderer).|
1058| latencyMode | Pointer to a variable used to receive the latency mode.|
1059
1060**Returns**
1061
1062Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
1063
1064
1065### OH_AudioRenderer_GetRendererInfo()
1066
1067```
1068OH_AudioStream_Result OH_AudioRenderer_GetRendererInfo (OH_AudioRenderer * renderer, OH_AudioStream_Usage * usage )
1069```
1070
1071**Description**
1072
1073Obtains the usage scenario of an audio renderer.
1074
1075**Since**: 10
1076
1077**System capability**: SystemCapability.Multimedia.Audio.Core
1078
1079**Parameters**
1080
1081| Name| Description|
1082| -------- | -------- |
1083| renderer | Pointer to an audio renderer instance created by [OH_AudioStreamBuilder_GenerateRenderer](#oh_audiostreambuilder_generaterenderer).|
1084| usage | Pointer to a variable used to receive the usage scenario.|
1085
1086**Returns**
1087
1088Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
1089
1090
1091### OH_AudioRenderer_GetSampleFormat()
1092
1093```
1094OH_AudioStream_Result OH_AudioRenderer_GetSampleFormat (OH_AudioRenderer * renderer, OH_AudioStream_SampleFormat * sampleFormat )
1095```
1096
1097**Description**
1098
1099Obtains the sampling format of an audio renderer.
1100
1101**Since**: 10
1102
1103**System capability**: SystemCapability.Multimedia.Audio.Core
1104
1105**Parameters**
1106
1107| Name| Description|
1108| -------- | -------- |
1109| renderer | Pointer to an audio renderer instance created by [OH_AudioStreamBuilder_GenerateRenderer](#oh_audiostreambuilder_generaterenderer).|
1110| sampleFormat | Pointer to a variable used to receive the sampling format.|
1111
1112**Returns**
1113
1114Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
1115
1116
1117### OH_AudioRenderer_GetSamplingRate()
1118
1119```
1120OH_AudioStream_Result OH_AudioRenderer_GetSamplingRate (OH_AudioRenderer * renderer, int32_t * rate )
1121```
1122
1123**Description**
1124
1125Obtains the sampling rate of an audio renderer.
1126
1127**Since**: 10
1128
1129**System capability**: SystemCapability.Multimedia.Audio.Core
1130
1131**Parameters**
1132
1133| Name| Description|
1134| -------- | -------- |
1135| renderer | Pointer to an audio renderer instance created by [OH_AudioStreamBuilder_GenerateRenderer](#oh_audiostreambuilder_generaterenderer).|
1136| rate | Pointer to a variable used to receive the sampling rate.|
1137
1138**Returns**
1139
1140Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
1141
1142
1143### OH_AudioRenderer_GetStreamId()
1144
1145```
1146OH_AudioStream_Result OH_AudioRenderer_GetStreamId (OH_AudioRenderer * renderer, uint32_t * streamId )
1147```
1148
1149**Description**
1150
1151Obtains the stream ID of an audio renderer.
1152
1153**Since**: 10
1154
1155**System capability**: SystemCapability.Multimedia.Audio.Core
1156
1157**Parameters**
1158
1159| Name| Description|
1160| -------- | -------- |
1161| renderer | Pointer to an audio renderer instance created by [OH_AudioStreamBuilder_GenerateRenderer](#oh_audiostreambuilder_generaterenderer).|
1162| streamId | Pointer to a variable used to receive the stream ID.|
1163
1164**Returns**
1165
1166Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
1167
1168
1169### OH_AudioRenderer_GetTimestamp()
1170
1171```
1172OH_AudioStream_Result OH_AudioRenderer_GetTimestamp (OH_AudioRenderer * renderer, clockid_t clockId, int64_t * framePosition, int64_t * timestamp )
1173```
1174
1175**Description**
1176
1177Obtains the timestamp and position information of an audio output stream.
1178
1179**Since**: 10
1180
1181**System capability**: SystemCapability.Multimedia.Audio.Core
1182
1183**Parameters**
1184
1185| Name| Description|
1186| -------- | -------- |
1187| renderer | Pointer to an audio renderer instance created by [OH_AudioStreamBuilder_GenerateRenderer](#oh_audiostreambuilder_generaterenderer).|
1188| clockId | CLOCK_MONOTONIC |
1189| framePosition | Pointer to the variable that holds the position information.|
1190| timestamp | Pointer to the variable that holds the timestamp.|
1191
1192**Returns**
1193
1194Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
1195
1196
1197### OH_AudioRenderer_Pause()
1198
1199```
1200OH_AudioStream_Result OH_AudioRenderer_Pause (OH_AudioRenderer * renderer)
1201```
1202
1203**Description**
1204
1205Pauses an audio renderer.
1206
1207**Since**: 10
1208
1209**System capability**: SystemCapability.Multimedia.Audio.Core
1210
1211**Parameters**
1212
1213| Name| Description|
1214| -------- | -------- |
1215| renderer | Pointer to an audio renderer instance created by [OH_AudioStreamBuilder_GenerateRenderer](#oh_audiostreambuilder_generaterenderer).|
1216
1217**Returns**
1218
1219Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
1220
1221
1222### OH_AudioRenderer_Release()
1223
1224```
1225OH_AudioStream_Result OH_AudioRenderer_Release (OH_AudioRenderer * renderer)
1226```
1227
1228**Description**
1229
1230Releases an audio renderer.
1231
1232**Since**: 10
1233
1234**System capability**: SystemCapability.Multimedia.Audio.Core
1235
1236**Parameters**
1237
1238| Name| Description|
1239| -------- | -------- |
1240| renderer | Pointer to an audio renderer instance created by [OH_AudioStreamBuilder_GenerateRenderer](#oh_audiostreambuilder_generaterenderer).|
1241
1242**Returns**
1243
1244Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
1245
1246
1247### OH_AudioRenderer_Start()
1248
1249```
1250OH_AudioStream_Result OH_AudioRenderer_Start (OH_AudioRenderer * renderer)
1251```
1252
1253**Description**
1254
1255Starts an audio renderer.
1256
1257**Since**: 10
1258
1259**System capability**: SystemCapability.Multimedia.Audio.Core
1260
1261**Parameters**
1262
1263| Name| Description|
1264| -------- | -------- |
1265| renderer | Pointer to an audio renderer instance created by [OH_AudioStreamBuilder_GenerateRenderer](#oh_audiostreambuilder_generaterenderer).|
1266
1267**Returns**
1268
1269Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
1270
1271
1272### OH_AudioRenderer_Stop()
1273
1274```
1275OH_AudioStream_Result OH_AudioRenderer_Stop (OH_AudioRenderer * renderer)
1276```
1277
1278**Description**
1279
1280Stops an audio renderer.
1281
1282**Since**: 10
1283
1284**System capability**: SystemCapability.Multimedia.Audio.Core
1285
1286**Parameters**
1287
1288| Name| Description|
1289| -------- | -------- |
1290| renderer | Pointer to an audio renderer instance created by [OH_AudioStreamBuilder_GenerateRenderer](#oh_audiostreambuilder_generaterenderer).|
1291
1292**Returns**
1293
1294Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
1295
1296
1297### OH_AudioStreamBuilder_Create()
1298
1299```
1300OH_AudioStream_Result OH_AudioStreamBuilder_Create (OH_AudioStreamBuilder ** builder, OH_AudioStream_Type type )
1301```
1302
1303**Description**
1304
1305Creates an audio stream builder, which can be an audio renderer or capturer.
1306
1307You need to call **OH_AudioStreamBuilder_Destroy()** to destroy the builder when it is no longer required.
1308
1309**Since**: 10
1310
1311**System capability**: SystemCapability.Multimedia.Audio.Core
1312
1313**Parameters**
1314
1315| Name| Description|
1316| -------- | -------- |
1317| builder | Double pointer to the audio stream builder created.|
1318| type | Type of the audio stream builder, which can be **AUDIOSTREAM_TYPE_RERNDERER** or **AUDIOSTREAM_TYPE_CAPTURER**.|
1319
1320**Returns**
1321
1322Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
1323
1324
1325### OH_AudioStreamBuilder_Destroy()
1326
1327```
1328OH_AudioStream_Result OH_AudioStreamBuilder_Destroy (OH_AudioStreamBuilder * builder)
1329```
1330
1331**Description**
1332
1333Destroys an audio stream builder when it is no longer required.
1334
1335**Since**: 10
1336
1337**System capability**: SystemCapability.Multimedia.Audio.Core
1338
1339**Parameters**
1340
1341| Name| Description|
1342| -------- | -------- |
1343| builder | Pointer to an audio stream builder instance created by **OH_AudioStreamBuilder_Create()**.|
1344
1345**Returns**
1346
1347Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
1348
1349
1350### OH_AudioStreamBuilder_GenerateCapturer()
1351
1352```
1353OH_AudioStream_Result OH_AudioStreamBuilder_GenerateCapturer (OH_AudioStreamBuilder * builder, OH_AudioCapturer ** audioCapturer )
1354```
1355
1356**Description**
1357
1358Creates an audio capturer instance.
1359
1360**Since**: 10
1361
1362**System capability**: SystemCapability.Multimedia.Audio.Core
1363
1364**Parameters**
1365
1366| Name| Description|
1367| -------- | -------- |
1368| builder | Pointer to an audio stream builder instance created by **OH_AudioStreamBuilder_Create()**.|
1369| audioCapturer | Double pointer to the audio capturer instance created.|
1370
1371**Returns**
1372
1373Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
1374
1375
1376### OH_AudioStreamBuilder_GenerateRenderer()
1377
1378```
1379OH_AudioStream_Result OH_AudioStreamBuilder_GenerateRenderer (OH_AudioStreamBuilder * builder, OH_AudioRenderer ** audioRenderer )
1380```
1381
1382**Description**
1383
1384Creates an audio renderer instance.
1385
1386**Since**: 10
1387
1388**System capability**: SystemCapability.Multimedia.Audio.Core
1389
1390**Parameters**
1391
1392| Name| Description|
1393| -------- | -------- |
1394| builder | Pointer to an audio stream builder instance created by **OH_AudioStreamBuilder_Create()**.|
1395| audioRenderer | Double pointer to the audio renderer instance created.|
1396
1397**Returns**
1398
1399Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
1400
1401
1402### OH_AudioStreamBuilder_SetCapturerCallback()
1403
1404```
1405OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerCallback (OH_AudioStreamBuilder * builder, OH_AudioCapturer_Callbacks callbacks, void * userData )
1406```
1407
1408**Description**
1409
1410Sets callbacks for an audio capturer.
1411
1412**Since**: 10
1413
1414**System capability**: SystemCapability.Multimedia.Audio.Core
1415
1416**Parameters**
1417
1418| Name| Description|
1419| -------- | -------- |
1420| builder | Pointer to an audio stream builder instance created by **OH_AudioStreamBuilder_Create()**.|
1421| callbacks | Callback functions that will be used to process events related to audio input streams.|
1422| userData | Pointer to the application data passed through the callback functions.|
1423
1424**Returns**
1425
1426Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
1427
1428
1429### OH_AudioStreamBuilder_SetCapturerInfo()
1430
1431```
1432OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerInfo (OH_AudioStreamBuilder * builder, OH_AudioStream_SourceType sourceType )
1433```
1434
1435**Description**
1436
1437Sets the usage scenario of an audio capturer.
1438
1439**Since**: 10
1440
1441**System capability**: SystemCapability.Multimedia.Audio.Core
1442
1443**Parameters**
1444
1445| Name| Description|
1446| -------- | -------- |
1447| builder | Pointer to an audio stream builder instance created by **OH_AudioStreamBuilder_Create()**.|
1448| sourceType | Usage scenario of the audio capturer.|
1449
1450**Returns**
1451
1452Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
1453
1454
1455### OH_AudioStreamBuilder_SetChannelCount()
1456
1457```
1458OH_AudioStream_Result OH_AudioStreamBuilder_SetChannelCount (OH_AudioStreamBuilder * builder, int32_t channelCount )
1459```
1460
1461**Description**
1462
1463Sets the number of channels for an audio stream.
1464
1465**Since**: 10
1466
1467**System capability**: SystemCapability.Multimedia.Audio.Core
1468
1469**Parameters**
1470
1471| Name| Description|
1472| -------- | -------- |
1473| builder | Pointer to an audio stream builder instance created by **OH_AudioStreamBuilder_Create()**.|
1474| channelCount | Number of channels.|
1475
1476**Returns**
1477
1478Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
1479
1480
1481### OH_AudioStreamBuilder_SetEncodingType()
1482
1483```
1484OH_AudioStream_Result OH_AudioStreamBuilder_SetEncodingType (OH_AudioStreamBuilder * builder, OH_AudioStream_EncodingType encodingType )
1485```
1486
1487**Description**
1488
1489Sets the encoding type of an audio stream.
1490
1491**Since**: 10
1492
1493**System capability**: SystemCapability.Multimedia.Audio.Core
1494
1495**Parameters**
1496
1497| Name| Description|
1498| -------- | -------- |
1499| builder | Pointer to an audio stream builder instance created by **OH_AudioStreamBuilder_Create()**.|
1500| encodingType | Encoding type, which can be **AUDIOSTREAM_ENCODING_PCM**.|
1501
1502**Returns**
1503
1504Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
1505
1506
1507### OH_AudioStreamBuilder_SetFrameSizeInCallback()
1508
1509```
1510OH_AudioStream_Result OH_AudioStreamBuilder_SetFrameSizeInCallback (OH_AudioStreamBuilder * builder, int32_t frameSize )
1511```
1512
1513**Description**
1514
1515Sets 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.
1516
1517**Since**: 11
1518
1519**System capability**: SystemCapability.Multimedia.Audio.Core
1520
1521**Parameters**
1522
1523| Name| Description|
1524| -------- | -------- |
1525| builder | Pointer to an audio stream builder instance created by **OH_AudioStreamBuilder_Create()**.|
1526| frameSize | Frame size.|
1527
1528**Returns**
1529
1530Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
1531
1532
1533### OH_AudioStreamBuilder_SetLatencyMode()
1534
1535```
1536OH_AudioStream_Result OH_AudioStreamBuilder_SetLatencyMode (OH_AudioStreamBuilder * builder, OH_AudioStream_LatencyMode latencyMode )
1537```
1538
1539**Description**
1540
1541Sets the latency mode of an audio stream.
1542
1543**Since**: 10
1544
1545**System capability**: SystemCapability.Multimedia.Audio.Core
1546
1547**Parameters**
1548
1549| Name| Description|
1550| -------- | -------- |
1551| builder | Pointer to an audio stream builder instance created by **OH_AudioStreamBuilder_Create()**.|
1552| latencyMode | Latency mode.|
1553
1554**Returns**
1555
1556Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
1557
1558
1559### OH_AudioStreamBuilder_SetRendererCallback()
1560
1561```
1562OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererCallback (OH_AudioStreamBuilder * builder, OH_AudioRenderer_Callbacks callbacks, void * userData )
1563```
1564
1565**Description**
1566
1567Sets callbacks for an audio renderer.
1568
1569**Since**: 10
1570
1571**System capability**: SystemCapability.Multimedia.Audio.Core
1572
1573**Parameters**
1574
1575| Name| Description|
1576| -------- | -------- |
1577| builder | Pointer to an audio stream builder instance created by **OH_AudioStreamBuilder_Create()**.|
1578| callbacks | Callback functions that will be used to process events related to audio output streams.|
1579| userData | Pointer to the application data passed through the callback functions.|
1580
1581**Returns**
1582
1583Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
1584
1585
1586### OH_AudioStreamBuilder_SetRendererInfo()
1587
1588```
1589OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererInfo (OH_AudioStreamBuilder * builder, OH_AudioStream_Usage usage )
1590```
1591
1592**Description**
1593
1594Sets the usage scenario of an audio renderer.
1595
1596**Since**: 10
1597
1598**System capability**: SystemCapability.Multimedia.Audio.Core
1599
1600**Parameters**
1601
1602| Name| Description|
1603| -------- | -------- |
1604| builder | Pointer to an audio stream builder instance created by **OH_AudioStreamBuilder_Create()**.|
1605| usage | Usage scenario of the audio renderer.|
1606
1607**Returns**
1608
1609Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
1610
1611
1612### OH_AudioStreamBuilder_SetSampleFormat()
1613
1614```
1615OH_AudioStream_Result OH_AudioStreamBuilder_SetSampleFormat (OH_AudioStreamBuilder * builder, OH_AudioStream_SampleFormat format )
1616```
1617
1618**Description**
1619
1620Sets the sampling format of an audio stream.
1621
1622**Since**: 10
1623
1624**System capability**: SystemCapability.Multimedia.Audio.Core
1625
1626**Parameters**
1627
1628| Name| Description|
1629| -------- | -------- |
1630| builder | Pointer to an audio stream builder instance created by **OH_AudioStreamBuilder_Create()**.|
1631| format | Sampling format.|
1632
1633**Returns**
1634
1635Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
1636
1637
1638### OH_AudioStreamBuilder_SetSamplingRate()
1639
1640```
1641OH_AudioStream_Result OH_AudioStreamBuilder_SetSamplingRate (OH_AudioStreamBuilder * builder, int32_t rate )
1642```
1643
1644**Description**
1645
1646Sets the sampling rate of an audio stream.
1647
1648**Since**: 10
1649
1650**System capability**: SystemCapability.Multimedia.Audio.Core
1651
1652**Parameters**
1653
1654| Name| Description|
1655| -------- | -------- |
1656| builder | Pointer to an audio stream builder instance created by **OH_AudioStreamBuilder_Create()**.|
1657| channelCount | Sampling rate.|
1658
1659**Returns**
1660
1661Returns **AUDIOSTREAM_SUCCESS** if the operation is successful; returns an error code otherwise.
1662