1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @addtogroup OHAudio
18  * @{
19  *
20  * @brief Provide the definition of the C interface for the audio module.
21  *
22  * @syscap SystemCapability.Multimedia.Audio.Core
23  *
24  * @since 10
25  * @version 1.0
26  */
27 
28 /**
29  * @file native_audiocapturer.h
30  *
31  * @brief Declare audio stream related interfaces for input type.
32  *
33  * @library libohaudio.so
34  * @syscap SystemCapability.Multimedia.Audio.Core
35  * @kit AudioKit
36  * @since 10
37  * @version 1.0
38  */
39 
40 #ifndef NATIVE_AUDIOCAPTURER_H
41 #define NATIVE_AUDIOCAPTURER_H
42 
43 #include <time.h>
44 #include "native_audiostream_base.h"
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 /*
49  * Request to release the capturer stream.
50  *
51  * @since 10
52  * @permission ohos.permission.MICROPHONE
53  *
54  * @param capturer reference created by OH_AudioStreamBuilder_GenerateCapturer()
55  * @return Function result code:
56  *         {@link AUDIOSTREAM_SUCCESS} If the execution is successful.
57  *         {@link AUDIOSTREAM_ERROR_INVALID_PARAM} The param of capturer is nullptr.
58  *         {@link AUDIOSTREAM_ERROR_ILLEGAL_STATE} Execution status exception.
59  */
60 OH_AudioStream_Result OH_AudioCapturer_Release(OH_AudioCapturer* capturer);
61 
62 /*
63  * Request to start the capturer stream.
64  *
65  * @since 10
66  * @permission ohos.permission.MICROPHONE
67  *
68  * @param capturer reference created by OH_AudioStreamBuilder_GenerateCapturer()
69  * @return Function result code:
70  *         {@link AUDIOSTREAM_SUCCESS} If the execution is successful.
71  *         {@link AUDIOSTREAM_ERROR_INVALID_PARAM} The param of capturer is nullptr.
72  *         {@link AUDIOSTREAM_ERROR_ILLEGAL_STATE} Execution status exception.
73  */
74 OH_AudioStream_Result OH_AudioCapturer_Start(OH_AudioCapturer* capturer);
75 
76 /*
77  * Request to pause the capturer stream.
78  *
79  * @since 10
80  * @permission ohos.permission.MICROPHONE
81  *
82  * @param capturer reference created by OH_AudioStreamBuilder_GenerateCapturer()
83  * @return Function result code:
84  *         {@link AUDIOSTREAM_SUCCESS} If the execution is successful.
85  *         {@link AUDIOSTREAM_ERROR_INVALID_PARAM} The param of capturer is nullptr.
86  *         {@link AUDIOSTREAM_ERROR_ILLEGAL_STATE} Execution status exception.
87  */
88 OH_AudioStream_Result OH_AudioCapturer_Pause(OH_AudioCapturer* capturer);
89 
90 /*
91  * Request to stop the capturer stream.
92  *
93  * @since 10
94  * @permission ohos.permission.MICROPHONE
95  *
96  * @param capturer reference created by OH_AudioStreamBuilder_GenerateCapturer()
97  * @return Function result code:
98  *         {@link AUDIOSTREAM_SUCCESS} If the execution is successful.
99  *         {@link AUDIOSTREAM_ERROR_INVALID_PARAM} The param of capturer is nullptr.
100  *         {@link AUDIOSTREAM_ERROR_ILLEGAL_STATE} Execution status exception.
101  */
102 OH_AudioStream_Result OH_AudioCapturer_Stop(OH_AudioCapturer* capturer);
103 
104 /*
105  * Request to flush the capturer stream.
106  *
107  * @since 10
108  *
109  * @param capturer reference created by OH_AudioStreamBuilder_GenerateCapturer()
110  * @return Function result code:
111  *         {@link AUDIOSTREAM_SUCCESS} If the execution is successful.
112  *         {@link AUDIOSTREAM_ERROR_INVALID_PARAM} The param of capturer is nullptr.
113  *         {@link AUDIOSTREAM_ERROR_ILLEGAL_STATE} Execution status exception.
114  */
115 OH_AudioStream_Result OH_AudioCapturer_Flush(OH_AudioCapturer* capturer);
116 
117 /*
118  * Query the current state of the capturer client.
119  *
120  * This function will return the capturer state without updating the state.
121  *
122  * @since 10
123  *
124  * @param capturer Reference created by OH_AudioStreamBuilder_GenerateCapturer()
125  * @param state Pointer to a variable that will be set for the state value.
126  * @return Function result code:
127  *         {@link AUDIOSTREAM_SUCCESS} If the execution is successful.
128  *         {@link AUDIOSTREAM_ERROR_INVALID_PARAM} The param of capturer is nullptr.
129  */
130 OH_AudioStream_Result OH_AudioCapturer_GetCurrentState(OH_AudioCapturer* capturer, OH_AudioStream_State* state);
131 
132 /*
133  * Query the latency mode of the capturer client.
134  *
135  * @since 10
136  *
137  * @param capturer Reference created by OH_AudioStreamBuilder_GenerateCapturer()
138  * @param latencyMode Pointer to a variable that will be set for the latency mode.
139  * @return Function result code:
140  *         {@link AUDIOSTREAM_SUCCESS} If the execution is successful.
141  *         {@link AUDIOSTREAM_ERROR_INVALID_PARAM} The param of capturer is nullptr.
142  */
143 OH_AudioStream_Result OH_AudioCapturer_GetLatencyMode(OH_AudioCapturer* capturer,
144     OH_AudioStream_LatencyMode* latencyMode);
145 
146 /*
147  * Query the stream id of the capturer client.
148  *
149  * @since 10
150  *
151  * @param capturer Reference created by OH_AudioStreamBuilder_GenerateCapturer()
152  * @param stramId Pointer to a variable that will be set for the stream id.
153  * @return Function result code:
154  *         {@link AUDIOSTREAM_SUCCESS} If the execution is successful.
155  *         {@link AUDIOSTREAM_ERROR_INVALID_PARAM} The param of capturer is nullptr.
156  */
157 OH_AudioStream_Result OH_AudioCapturer_GetStreamId(OH_AudioCapturer* capturer, uint32_t* streamId);
158 
159 /*
160  * Query the sample rate value of the capturer client.
161  *
162  * This function will return the capturer sample rate value without updating the state.
163  *
164  * @since 10
165  *
166  * @param capturer Reference created by OH_AudioStreamBuilder_GenerateCapturer()
167  * @param rate The state value to be updated
168  * @return Function result code:
169  *         {@link AUDIOSTREAM_SUCCESS} If the execution is successful.
170  *         {@link AUDIOSTREAM_ERROR_INVALID_PARAM} The param of capturer is nullptr.
171  */
172 OH_AudioStream_Result OH_AudioCapturer_GetSamplingRate(OH_AudioCapturer* capturer, int32_t* rate);
173 
174 /*
175  * Query the channel count of the capturer client.
176  *
177  * @since 10
178  *
179  * @param capturer Reference created by OH_AudioStreamBuilder_GenerateCapturer()
180  * @param channelCount Pointer to a variable that will be set for the channel count.
181  * @return Function result code:
182  *         {@link AUDIOSTREAM_SUCCESS} If the execution is successful.
183  *         {@link AUDIOSTREAM_ERROR_INVALID_PARAM} The param of capturer is nullptr.
184  */
185 OH_AudioStream_Result OH_AudioCapturer_GetChannelCount(OH_AudioCapturer* capturer, int32_t* channelCount);
186 
187 /*
188  * Query the sample format of the capturer client.
189  *
190  * @since 10
191  *
192  * @param capturer Reference created by OH_AudioStreamBuilder_GenerateCapturer()
193  * @param sampleFormat Pointer to a variable that will be set for the sample format.
194  * @return Function result code:
195  *         {@link AUDIOSTREAM_SUCCESS} If the execution is successful.
196  *         {@link AUDIOSTREAM_ERROR_INVALID_PARAM} The param of capturer is nullptr.
197  */
198 OH_AudioStream_Result OH_AudioCapturer_GetSampleFormat(OH_AudioCapturer* capturer,
199     OH_AudioStream_SampleFormat* sampleFormat);
200 
201 /*
202  * Query the encoding type of the capturer client.
203  *
204  * @since 10
205  *
206  * @param capturer Reference created by OH_AudioStreamBuilder_GenerateCapturer()
207  * @param encodingType Pointer to a variable that will be set for the encoding type.
208  * @return Function result code:
209  *         {@link AUDIOSTREAM_SUCCESS} If the execution is successful.
210  *         {@link AUDIOSTREAM_ERROR_INVALID_PARAM} The param of capturer is nullptr.
211  */
212 OH_AudioStream_Result OH_AudioCapturer_GetEncodingType(OH_AudioCapturer* capturer,
213     OH_AudioStream_EncodingType* encodingType);
214 
215 /*
216  * Query the capturer info of the capturer client.
217  *
218  * @since 10
219  *
220  * @param capturer Reference created by OH_AudioStreamBuilder_GenerateCapturer()
221  * @param sourceType Pointer to a variable that will be set for the stream sourceType.
222  * @return Function result code:
223  *         {@link AUDIOSTREAM_SUCCESS} If the execution is successful.
224  *         {@link AUDIOSTREAM_ERROR_INVALID_PARAM} The param of capturer is nullptr.
225  */
226 OH_AudioStream_Result OH_AudioCapturer_GetCapturerInfo(OH_AudioCapturer* capturer,
227     OH_AudioStream_SourceType* sourceType);
228 
229 /*
230  * Query the frame size in callback, it is a fixed length of the buffer returned by each callback.
231  *
232  * @since 10
233  *
234  * @param capturer Reference created by OH_AudioStreamBuilder_GenerateCapturer()
235  * @param frameSize Pointer to a variable that will be set for the frame size.
236  * @return Function result code:
237  *         {@link AUDIOSTREAM_SUCCESS} If the execution is successful.
238  *         {@link AUDIOSTREAM_ERROR_INVALID_PARAM} The param of capturer is nullptr.
239  *         {@link AUDIOSTREAM_ERROR_ILLEGAL_STATE} Execution status exception.
240  */
241 OH_AudioStream_Result OH_AudioCapturer_GetFrameSizeInCallback(OH_AudioCapturer* capturer, int32_t* frameSize);
242 
243 /*
244  * Query the the time at which a particular frame was presented
245  *
246  * @since 10
247  *
248  * @param capturer Reference created by OH_AudioStreamBuilder_GenerateCapturer()
249  * @param clockId {@link #CLOCK_MONOTONIC}
250  * @param framePosition Pointer to a variable to receive the position
251  * @param timestamp Pointer to a variable to receive the timestamp
252  * @return Function result code:
253  *         {@link AUDIOSTREAM_SUCCESS} If the execution is successful.
254  *         {@link AUDIOSTREAM_ERROR_INVALID_PARAM}:
255  *                                                 1.The param of capturer is nullptr;
256  *                                                 2.The param of clockId invalid.
257  *         {@link AUDIOSTREAM_ERROR_ILLEGAL_STATE} Execution status exception.
258  */
259 OH_AudioStream_Result OH_AudioCapturer_GetTimestamp(OH_AudioCapturer* capturer,
260     clockid_t clockId, int64_t* framePosition, int64_t* timestamp);
261 
262 /*
263  * Query the the number of frames that have been read since the stream was created.
264  *
265  * @since 10
266  *
267  * @param capturer Reference created by OH_AudioStreamBuilder_GenerateCapturer()
268  * @param frames Pointer to a variable that will be set for the frame count number.
269  * @return Function result code:
270  *         {@link AUDIOSTREAM_SUCCESS} If the execution is successful.
271  *         {@link AUDIOSTREAM_ERROR_INVALID_PARAM} The param of capturer is nullptr.
272  */
273 OH_AudioStream_Result OH_AudioCapturer_GetFramesRead(OH_AudioCapturer* capturer, int64_t* frames);
274 
275 /**
276  * @brief Gets the overflow count on this stream.
277  *
278  * @since 12
279  *
280  * @param capturer Capturer generated by OH_AudioStreamBuilder_GenerateCapturer()
281  * @param count Pointer to a variable that will be set for the overflow count number.
282  * @return Function result code:
283  *         {@link AUDIOSTREAM_SUCCESS} If the execution is successful.
284  *         {@link AUDIOSTREAM_ERROR_INVALID_PARAM} The param of capturer is nullptr.
285  */
286 OH_AudioStream_Result OH_AudioCapturer_GetOverflowCount(OH_AudioCapturer* capturer, uint32_t* count);
287 
288 #ifdef __cplusplus
289 }
290 #endif
291 #endif // NATIVE_AUDIOCAPTURER_H
292