1# OH_AudioCapturer_Callbacks_Struct
2
3
4## Overview
5
6The **OH_AudioCapturer_Callbacks_Struct** struct defines a pointer to the callback functions related to an audio capturer.
7
8To avoid unexpected behavior, ensure that every member variable of the struct is initialized by a custom callback method or a null pointer when setting the audio callback functions. For details, see [Using OHAudio for Audio Recording](../../media/audio/using-ohaudio-for-recording.md).
9
10**System capability**: SystemCapability.Multimedia.Audio.Core
11
12**Since**: 10
13
14**Related module**: [OHAudio](_o_h_audio.md)
15
16
17## Summary
18
19
20### Member Variables
21
22| Name| Description|
23| -------- | -------- |
24| int32_t (\*[OH_AudioCapturer_OnReadData](#oh_audiocapturer_onreaddata))([OH_AudioCapturer](_o_h_audio.md#oh_audiocapturer) \*capturer, void \*userData, void \*buffer, int32_t length) | Defines a function pointer to the callback function used to read audio data. |
25| int32_t (\*[OH_AudioCapturer_OnStreamEvent](#oh_audiocapturer_onstreamevent))([OH_AudioCapturer](_o_h_audio.md#oh_audiocapturer) \*capturer, void \*userData, [OH_AudioStream_Event](_o_h_audio.md#oh_audiostream_event) event) | Defines a function pointer to the callback function used to process audio recording stream events. |
26| int32_t (\*[OH_AudioCapturer_OnInterruptEvent](#oh_audiocapturer_oninterruptevent))([OH_AudioCapturer](_o_h_audio.md#oh_audiocapturer) \*capturer, void \*userData, [OH_AudioInterrupt_ForceType](_o_h_audio.md#oh_audiointerrupt_forcetype) type, [OH_AudioInterrupt_Hint](_o_h_audio.md#oh_audiointerrupt_hint) hint) | Defines a function pointer to the callback function used to process audio recording interruption events. |
27| int32_t (\*[OH_AudioCapturer_OnError](#oh_audiocapturer_onerror))([OH_AudioCapturer](_o_h_audio.md#oh_audiocapturer) \*capturer, void \*userData, [OH_AudioStream_Result](_o_h_audio.md#oh_audiostream_result) error) | Defines a function pointer to the callback function used to process audio recording errors. |
28
29
30## Member Variable Description
31
32> **NOTE**
33>
34> No enumerated values are defined as the return values of the following callbacks. In the current version, no processing specific to the return value is provided. To support expansion in later versions, the default value **0** is used.
35
36
37### OH_AudioCapturer_OnError
38
39```
40int32_t (*OH_AudioCapturer_Callbacks_Struct::OH_AudioCapturer_OnError)(OH_AudioCapturer *capturer, void *userData, OH_AudioStream_Result error)
41```
42
43**Description**
44
45Defines a function pointer to the callback function used to process audio recording errors.
46**Parameters**
47
48| Name| Description|
49| -------- | -------- |
50| capturer | Pointer to an audio capturer instance, which is created by calling [OH_AudioStreamBuilder_GenerateCapturer](_o_h_audio.md#oh_audiostreambuilder_generatecapturer).|
51| userData | Pointer to the data storage area customized by the application.|
52| error | Audio recording error result defined by [OH_AudioStream_Result](_o_h_audio.md#oh_audiostream_result), which can be **AUDIOSTREAM_ERROR_INVALID_PARAM**, **AUDIOSTREAM_ERROR_ILLEGAL_STATE**, or **AUDIOSTREAM_ERROR_SYSTEM**.|
53
54
55### OH_AudioCapturer_OnInterruptEvent
56
57```
58int32_t (*OH_AudioCapturer_Callbacks_Struct::OH_AudioCapturer_OnInterruptEvent)(OH_AudioCapturer *capturer, void *userData, OH_AudioInterrupt_ForceType type, OH_AudioInterrupt_Hint hint)
59```
60
61**Description**
62
63Defines a function pointer to the callback function used to process audio recording interruption events.
64
65**Parameters**
66
67| Name| Description|
68| -------- | -------- |
69| capturer | Pointer to an audio capturer instance, which is created by calling [OH_AudioStreamBuilder_GenerateCapturer](_o_h_audio.md#oh_audiostreambuilder_generatecapturer).|
70| userData | Pointer to the data storage area customized by the application.|
71| type | Type of force that causes audio interruption. For details about the available options, see [OH_AudioInterrupt_ForceType](_o_h_audio.md#oh_audiointerrupt_forcetype).|
72| hint | Hint provided along with audio interruption. For details about the available options, see [OH_AudioInterrupt_Hint](_o_h_audio.md#oh_audiointerrupt_hint).|
73
74
75### OH_AudioCapturer_OnReadData
76
77```
78int32_t (*OH_AudioCapturer_Callbacks_Struct::OH_AudioCapturer_OnReadData)(OH_AudioCapturer *capturer, void *userData, void *buffer, int32_t length)
79```
80
81**Description**
82
83Defines a function pointer to the callback function used to read audio data.
84
85The callback function is used only to read audio data. Do not call AudioCapturer APIs in it.
86
87**Parameters**
88
89| Name| Description|
90| -------- | -------- |
91| capturer | Pointer to an audio capturer instance, which is created by calling [OH_AudioStreamBuilder_GenerateCapturer](_o_h_audio.md#oh_audiostreambuilder_generatecapturer).|
92| userData | Pointer to the data storage area customized by the application.|
93| buffer | Pointer to the captured data storage area, which is used by the application to fill in captured data.|
94| length | Length of the buffer.|
95
96
97### OH_AudioCapturer_OnStreamEvent
98
99```
100int32_t (*OH_AudioCapturer_Callbacks_Struct::OH_AudioCapturer_OnStreamEvent)(OH_AudioCapturer *capturer, void *userData, OH_AudioStream_Event event)
101```
102
103**Description**
104
105Defines a function pointer to the callback function used to process audio recording stream events.
106
107**Parameters**
108
109| Name| Description|
110| -------- | -------- |
111| capturer | Pointer to an audio capturer instance, which is created by calling [OH_AudioStreamBuilder_GenerateCapturer](_o_h_audio.md#oh_audiostreambuilder_generatecapturer).|
112| userData | Pointer to the data storage area customized by the application.|
113| event | Audio event defined in [OH_AudioStream_Event](_o_h_audio.md#oh_audiostream_event).|
114