ohaudio-sys 0.1.0

Raw Bindings to the audio module of OpenHarmony
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
// automatically generated by rust-bindgen 0.71.1

#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#[cfg(feature = "api-20")]
use crate::audio_device_base::OH_AudioDeviceDescriptorArray;
use crate::audiostream_base::*;
use libc::clockid_t;

/// Called when audio data is available to read. This function is similar to
/// OH_AudioCapturer_Callbacks_Struct.OH_AudioCapturer_OnReadData.
///
/// # Arguments
///
/// * `capturer` - Pointer to the AudioCapturer instance that triggers the callback.
///
/// * `userData` - Pointer to the user data passed when setting the callback via
/// OH_AudioStreamBuilder_SetCapturerReadDataCallback.
///
/// * `audioData` - Pointer to the available audio data.
///
/// * `audioDataSize` - Size of the available audio data.
/// [`OH_AudioCapturer_Callbacks_Struct.OH_AudioCapturer_OnReadData`]
/// Available since API-level: 20
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
pub type OH_AudioCapturer_OnReadDataCallback = ::core::option::Option<
    unsafe extern "C" fn(
        capturer: *mut OH_AudioCapturer,
        userData: *mut ::core::ffi::c_void,
        audioData: *mut ::core::ffi::c_void,
        audioDataSize: i32,
    ),
>;
/// Called when the input device of an AudioCapturer instance changes.
/// This function is similar to OH_AudioCapturer_Callbacks_Struct.OH_AudioCapturer_OnStreamEvent.
///
/// # Arguments
///
/// * `capturer` - Pointer to the AudioCapturer instance that triggers the callback.
///
/// * `userData` - Pointer to the user data passed when setting the callback via
/// OH_AudioStreamBuilder_SetCapturerDeviceChangeCallback.
///
/// * `deviceArray` - Pointer to an array of the new input devices.
/// [`OH_AudioCapturer_Callbacks_Struct.OH_AudioCapturer_OnStreamEvent`]
/// Available since API-level: 20
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
pub type OH_AudioCapturer_OnDeviceChangeCallback = ::core::option::Option<
    unsafe extern "C" fn(
        capturer: *mut OH_AudioCapturer,
        userData: *mut ::core::ffi::c_void,
        deviceArray: *mut OH_AudioDeviceDescriptorArray,
    ),
>;
/// Called when an interrupt event occurs in an AudioCapturer instance.
/// This function is similar to OH_AudioCapturer_Callbacks_Struct.OH_AudioCapturer_OnInterruptEvent.
///
/// # Arguments
///
/// * `capturer` - Pointer to the AudioCapturer instance that triggers the callback.
///
/// * `userData` - Pointer to the user data passed when setting the callback via
/// OH_AudioStreamBuilder_SetCapturerInterruptCallback.
///
/// * `type` - Type of force that causes the interrupt event.
///
/// * `hint` - Hint provided along with the interrupt event.
/// [`OH_AudioCapturer_Callbacks_Struct.OH_AudioCapturer_OnInterruptEvent.`]
/// Available since API-level: 20
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
pub type OH_AudioCapturer_OnInterruptCallback = ::core::option::Option<
    unsafe extern "C" fn(
        capturer: *mut OH_AudioCapturer,
        userData: *mut ::core::ffi::c_void,
        type_: OH_AudioInterrupt_ForceType,
        hint: OH_AudioInterrupt_Hint,
    ),
>;
/// Called when an error event occurs in an AudioCapturer instance.
/// This function is similar to OH_AudioCapturer_Callbacks_Struct.OH_AudioCapturer_OnError.
///
/// # Arguments
///
/// * `capturer` - Pointer to the AudioCapturer instance that triggers the callback.
///
/// * `userData` - Pointer to the user data passed when setting the callback via
/// OH_AudioStreamBuilder_SetCapturerErrorCallback.
///
/// * `error` - Specific error information.
/// [`OH_AudioCapturer_Callbacks_Struct.OH_AudioCapturer_OnError`]
/// Available since API-level: 20
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
pub type OH_AudioCapturer_OnErrorCallback = ::core::option::Option<
    unsafe extern "C" fn(
        capturer: *mut OH_AudioCapturer,
        userData: *mut ::core::ffi::c_void,
        error: OH_AudioStream_Result,
    ),
>;
/// Callback function of fast status change event for audio capturer.
///
/// # Arguments
///
/// * `capturer` - Pointer to an audio capturer instance for which this callback occurs.
///
/// * `userData` - Userdata which is passed by register.
///
/// * `status` - Current fast status.
///
/// Available since API-level: 20
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
pub type OH_AudioCapturer_OnFastStatusChange = ::core::option::Option<
    unsafe extern "C" fn(
        capturer: *mut OH_AudioCapturer,
        userData: *mut ::core::ffi::c_void,
        status: OH_AudioStream_FastStatus,
    ),
>;
/// Callback function to get playback capture start result.
///
/// # Arguments
///
/// * `capturer` - Pointer to the AudioCapturer instance that triggers the callback.
///
/// * `userData` - Pointer to the user data passed when setting the callback via
/// [`#OH_AudioCapturer_RequestPlaybackCaptureStart`].
///
/// * `state` - The final state to describe whether start request is successful.
///
/// Available since API-level: 23
#[cfg(feature = "api-23")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-23")))]
pub type OH_AudioCapturer_OnPlaybackCaptureStartCallback = ::core::option::Option<
    unsafe extern "C" fn(
        capturer: *mut OH_AudioCapturer,
        userData: *mut ::core::ffi::c_void,
        state: OH_AudioStream_PlaybackCaptureStartState,
    ),
>;
extern "C" {
    /// Request to release the capturer stream.
    ///
    ///
    /// Available since API-level: 10
    /// ohos.permission.MICROPHONE
    ///
    /// # Arguments
    ///
    /// * `capturer` - reference created by OH_AudioStreamBuilder_GenerateCapturer()
    ///
    /// # Returns
    ///
    /// * Function result code:
    /// [`AUDIOSTREAM_SUCCESS`] If the execution is successful.
    /// [`AUDIOSTREAM_ERROR_INVALID_PARAM`] The param of capturer is nullptr.
    /// [`AUDIOSTREAM_ERROR_ILLEGAL_STATE`] Execution status exception.
    pub fn OH_AudioCapturer_Release(capturer: *mut OH_AudioCapturer) -> OH_AudioStream_Result;
    /// Request to start the capturer stream.
    ///
    ///
    /// Available since API-level: 10
    /// ohos.permission.MICROPHONE
    ///
    /// # Arguments
    ///
    /// * `capturer` - reference created by OH_AudioStreamBuilder_GenerateCapturer()
    ///
    /// # Returns
    ///
    /// * Function result code:
    /// [`AUDIOSTREAM_SUCCESS`] If the execution is successful.
    /// [`AUDIOSTREAM_ERROR_INVALID_PARAM`] The param of capturer is nullptr.
    /// [`AUDIOSTREAM_ERROR_ILLEGAL_STATE`] Execution status exception.
    pub fn OH_AudioCapturer_Start(capturer: *mut OH_AudioCapturer) -> OH_AudioStream_Result;
    /// Request to pause the capturer stream.
    ///
    ///
    /// Available since API-level: 10
    /// ohos.permission.MICROPHONE
    ///
    /// # Arguments
    ///
    /// * `capturer` - reference created by OH_AudioStreamBuilder_GenerateCapturer()
    ///
    /// # Returns
    ///
    /// * Function result code:
    /// [`AUDIOSTREAM_SUCCESS`] If the execution is successful.
    /// [`AUDIOSTREAM_ERROR_INVALID_PARAM`] The param of capturer is nullptr.
    /// [`AUDIOSTREAM_ERROR_ILLEGAL_STATE`] Execution status exception.
    pub fn OH_AudioCapturer_Pause(capturer: *mut OH_AudioCapturer) -> OH_AudioStream_Result;
    /// Request to stop the capturer stream.
    ///
    ///
    /// Available since API-level: 10
    /// ohos.permission.MICROPHONE
    ///
    /// # Arguments
    ///
    /// * `capturer` - reference created by OH_AudioStreamBuilder_GenerateCapturer()
    ///
    /// # Returns
    ///
    /// * Function result code:
    /// [`AUDIOSTREAM_SUCCESS`] If the execution is successful.
    /// [`AUDIOSTREAM_ERROR_INVALID_PARAM`] The param of capturer is nullptr.
    /// [`AUDIOSTREAM_ERROR_ILLEGAL_STATE`] Execution status exception.
    pub fn OH_AudioCapturer_Stop(capturer: *mut OH_AudioCapturer) -> OH_AudioStream_Result;
    /// Request to flush the capturer stream.
    ///
    ///
    /// Available since API-level: 10
    ///
    /// # Arguments
    ///
    /// * `capturer` - reference created by OH_AudioStreamBuilder_GenerateCapturer()
    ///
    /// # Returns
    ///
    /// * Function result code:
    /// [`AUDIOSTREAM_SUCCESS`] If the execution is successful.
    /// [`AUDIOSTREAM_ERROR_INVALID_PARAM`] The param of capturer is nullptr.
    /// [`AUDIOSTREAM_ERROR_ILLEGAL_STATE`] Execution status exception.
    pub fn OH_AudioCapturer_Flush(capturer: *mut OH_AudioCapturer) -> OH_AudioStream_Result;
    /// Query the current state of the capturer client.
    ///
    /// This function will return the capturer state without updating the state.
    ///
    ///
    /// Available since API-level: 10
    ///
    /// # Arguments
    ///
    /// * `capturer` - Reference created by OH_AudioStreamBuilder_GenerateCapturer()
    ///
    /// * `state` - Pointer to a variable that will be set for the state value.
    ///
    /// # Returns
    ///
    /// * Function result code:
    /// [`AUDIOSTREAM_SUCCESS`] If the execution is successful.
    /// [`AUDIOSTREAM_ERROR_INVALID_PARAM`] The param of capturer is nullptr.
    pub fn OH_AudioCapturer_GetCurrentState(
        capturer: *mut OH_AudioCapturer,
        state: *mut OH_AudioStream_State,
    ) -> OH_AudioStream_Result;
    /// Query the latency mode of the capturer client.
    ///
    ///
    /// Available since API-level: 10
    ///
    /// # Arguments
    ///
    /// * `capturer` - Reference created by OH_AudioStreamBuilder_GenerateCapturer()
    ///
    /// * `latencyMode` - Pointer to a variable that will be set for the latency mode.
    ///
    /// # Returns
    ///
    /// * Function result code:
    /// [`AUDIOSTREAM_SUCCESS`] If the execution is successful.
    /// [`AUDIOSTREAM_ERROR_INVALID_PARAM`] The param of capturer is nullptr.
    pub fn OH_AudioCapturer_GetLatencyMode(
        capturer: *mut OH_AudioCapturer,
        latencyMode: *mut OH_AudioStream_LatencyMode,
    ) -> OH_AudioStream_Result;
    /// Query the stream id of the capturer client.
    ///
    ///
    /// Available since API-level: 10
    ///
    /// # Arguments
    ///
    /// * `capturer` - Reference created by OH_AudioStreamBuilder_GenerateCapturer()
    ///
    /// * `streamId` - Pointer to a variable that will be set for the stream id.
    ///
    /// # Returns
    ///
    /// * Function result code:
    /// [`AUDIOSTREAM_SUCCESS`] If the execution is successful.
    /// [`AUDIOSTREAM_ERROR_INVALID_PARAM`] The param of capturer is nullptr.
    pub fn OH_AudioCapturer_GetStreamId(
        capturer: *mut OH_AudioCapturer,
        streamId: *mut u32,
    ) -> OH_AudioStream_Result;
    /// Query the sample rate value of the capturer client.
    ///
    /// This function will return the capturer sample rate value without updating the state.
    ///
    ///
    /// Available since API-level: 10
    ///
    /// # Arguments
    ///
    /// * `capturer` - Reference created by OH_AudioStreamBuilder_GenerateCapturer()
    ///
    /// * `rate` - The state value to be updated
    ///
    /// # Returns
    ///
    /// * Function result code:
    /// [`AUDIOSTREAM_SUCCESS`] If the execution is successful.
    /// [`AUDIOSTREAM_ERROR_INVALID_PARAM`] The param of capturer is nullptr.
    pub fn OH_AudioCapturer_GetSamplingRate(
        capturer: *mut OH_AudioCapturer,
        rate: *mut i32,
    ) -> OH_AudioStream_Result;
    /// Query the channel count of the capturer client.
    ///
    ///
    /// Available since API-level: 10
    ///
    /// # Arguments
    ///
    /// * `capturer` - Reference created by OH_AudioStreamBuilder_GenerateCapturer()
    ///
    /// * `channelCount` - Pointer to a variable that will be set for the channel count.
    ///
    /// # Returns
    ///
    /// * Function result code:
    /// [`AUDIOSTREAM_SUCCESS`] If the execution is successful.
    /// [`AUDIOSTREAM_ERROR_INVALID_PARAM`] The param of capturer is nullptr.
    pub fn OH_AudioCapturer_GetChannelCount(
        capturer: *mut OH_AudioCapturer,
        channelCount: *mut i32,
    ) -> OH_AudioStream_Result;
    /// Query the sample format of the capturer client.
    ///
    ///
    /// Available since API-level: 10
    ///
    /// # Arguments
    ///
    /// * `capturer` - Reference created by OH_AudioStreamBuilder_GenerateCapturer()
    ///
    /// * `sampleFormat` - Pointer to a variable that will be set for the sample format.
    ///
    /// # Returns
    ///
    /// * Function result code:
    /// [`AUDIOSTREAM_SUCCESS`] If the execution is successful.
    /// [`AUDIOSTREAM_ERROR_INVALID_PARAM`] The param of capturer is nullptr.
    pub fn OH_AudioCapturer_GetSampleFormat(
        capturer: *mut OH_AudioCapturer,
        sampleFormat: *mut OH_AudioStream_SampleFormat,
    ) -> OH_AudioStream_Result;
    /// Query the encoding type of the capturer client.
    ///
    ///
    /// Available since API-level: 10
    ///
    /// # Arguments
    ///
    /// * `capturer` - Reference created by OH_AudioStreamBuilder_GenerateCapturer()
    ///
    /// * `encodingType` - Pointer to a variable that will be set for the encoding type.
    ///
    /// # Returns
    ///
    /// * Function result code:
    /// [`AUDIOSTREAM_SUCCESS`] If the execution is successful.
    /// [`AUDIOSTREAM_ERROR_INVALID_PARAM`] The param of capturer is nullptr.
    pub fn OH_AudioCapturer_GetEncodingType(
        capturer: *mut OH_AudioCapturer,
        encodingType: *mut OH_AudioStream_EncodingType,
    ) -> OH_AudioStream_Result;
    /// Query the capturer info of the capturer client.
    ///
    ///
    /// Available since API-level: 10
    ///
    /// # Arguments
    ///
    /// * `capturer` - Reference created by OH_AudioStreamBuilder_GenerateCapturer()
    ///
    /// * `sourceType` - Pointer to a variable that will be set for the stream sourceType.
    ///
    /// # Returns
    ///
    /// * Function result code:
    /// [`AUDIOSTREAM_SUCCESS`] If the execution is successful.
    /// [`AUDIOSTREAM_ERROR_INVALID_PARAM`] The param of capturer is nullptr.
    pub fn OH_AudioCapturer_GetCapturerInfo(
        capturer: *mut OH_AudioCapturer,
        sourceType: *mut OH_AudioStream_SourceType,
    ) -> OH_AudioStream_Result;
    /// Query the frame size in callback, it is a fixed length of the buffer returned by each callback.
    ///
    ///
    /// Available since API-level: 10
    ///
    /// # Arguments
    ///
    /// * `capturer` - Reference created by OH_AudioStreamBuilder_GenerateCapturer()
    ///
    /// * `frameSize` - Pointer to a variable that will be set for the frame size.
    ///
    /// # Returns
    ///
    /// * Function result code:
    /// [`AUDIOSTREAM_SUCCESS`] If the execution is successful.
    /// [`AUDIOSTREAM_ERROR_INVALID_PARAM`] The param of capturer is nullptr.
    /// [`AUDIOSTREAM_ERROR_ILLEGAL_STATE`] Execution status exception.
    pub fn OH_AudioCapturer_GetFrameSizeInCallback(
        capturer: *mut OH_AudioCapturer,
        frameSize: *mut i32,
    ) -> OH_AudioStream_Result;
    /// Query the the time at which a particular frame was presented
    ///
    ///
    /// Available since API-level: 10
    ///
    /// # Arguments
    ///
    /// * `capturer` - Reference created by OH_AudioStreamBuilder_GenerateCapturer()
    ///
    /// * `clockId` - [`#CLOCK_MONOTONIC`]
    ///
    /// * `framePosition` - Pointer to a variable to receive the position
    ///
    /// * `timestamp` - Pointer to a variable to receive the timestamp
    ///
    /// # Returns
    ///
    /// * Function result code:
    /// [`AUDIOSTREAM_SUCCESS`] If the execution is successful.
    /// [`AUDIOSTREAM_ERROR_INVALID_PARAM`]:
    /// 1.The param of capturer is nullptr;
    /// 2.The param of clockId invalid.
    /// [`AUDIOSTREAM_ERROR_ILLEGAL_STATE`] Execution status exception.
    pub fn OH_AudioCapturer_GetTimestamp(
        capturer: *mut OH_AudioCapturer,
        clockId: clockid_t,
        framePosition: *mut i64,
        timestamp: *mut i64,
    ) -> OH_AudioStream_Result;
    /// Query the the number of frames that have been read since the stream was created.
    ///
    ///
    /// Available since API-level: 10
    ///
    /// # Arguments
    ///
    /// * `capturer` - Reference created by OH_AudioStreamBuilder_GenerateCapturer()
    ///
    /// * `frames` - Pointer to a variable that will be set for the frame count number.
    ///
    /// # Returns
    ///
    /// * Function result code:
    /// [`AUDIOSTREAM_SUCCESS`] If the execution is successful.
    /// [`AUDIOSTREAM_ERROR_INVALID_PARAM`] The param of capturer is nullptr.
    pub fn OH_AudioCapturer_GetFramesRead(
        capturer: *mut OH_AudioCapturer,
        frames: *mut i64,
    ) -> OH_AudioStream_Result;
    /// Gets the overflow count on this stream.
    ///
    ///
    /// Available since API-level: 12
    ///
    /// # Arguments
    ///
    /// * `capturer` - Capturer generated by OH_AudioStreamBuilder_GenerateCapturer()
    ///
    /// * `count` - Pointer to a variable that will be set for the overflow count number.
    ///
    /// # Returns
    ///
    /// * Function result code:
    /// [`AUDIOSTREAM_SUCCESS`] If the execution is successful.
    /// [`AUDIOSTREAM_ERROR_INVALID_PARAM`] The param of capturer is nullptr.
    #[cfg(feature = "api-12")]
    #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
    pub fn OH_AudioCapturer_GetOverflowCount(
        capturer: *mut OH_AudioCapturer,
        count: *mut u32,
    ) -> OH_AudioStream_Result;
    /// Gets audio capturer running status, check if it works in fast status.
    ///
    /// # Arguments
    ///
    /// * `capturer` - Reference created by OH_AudioStreamBuilder_GenerateCapturer.
    ///
    /// * `status` - Pointer to a variable to receive the status.
    ///
    /// # Returns
    ///
    /// * [`AUDIOSTREAM_SUCCESS`] if the execution is successful.
    /// [`AUDIOSTREAM_ERROR_INVALID_PARAM`] the param of capturer is nullptr.
    /// [`AUDIOSTREAM_ERROR_ILLEGAL_STATE`] function called in invalid state, only available before release state.
    ///
    /// Available since API-level: 20
    #[cfg(feature = "api-20")]
    #[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
    pub fn OH_AudioCapturer_GetFastStatus(
        capturer: *mut OH_AudioCapturer,
        status: *mut OH_AudioStream_FastStatus,
    ) -> OH_AudioStream_Result;
    /// Asynchronously request to start the playback capture stream.
    /// This function is non-blocking, which means system will continue to process user authorization and
    /// stream starting when receiving the start request. And the final result will be returned by callback.
    /// # Arguments
    ///
    /// * `capturer` - reference created by [`#OH_AudioStreamBuilder_GenerateCapturer`]
    ///
    /// * `callback` - Callback function used to receive the final result of start request.
    ///
    /// * `userData` - Pointer to an application data structure that will be passed to the callback functions.
    ///
    /// # Returns
    ///
    /// * Function result code:
    /// [`#AUDIOSTREAM_SUCCESS`] If the execution is successful.
    /// [`#AUDIOSTREAM_ERROR_INVALID_PARAM`] The param of capturer is nullptr or callback is invalid.
    /// [`#AUDIOSTREAM_ERROR_ILLEGAL_STATE`] Running and released are illegal states.
    /// [`#AUDIOSTREAM_ERROR_SYSTEM`] System internal error, like audio service error.
    ///
    /// Available since API-level: 23
    #[cfg(feature = "api-23")]
    #[cfg_attr(docsrs, doc(cfg(feature = "api-23")))]
    pub fn OH_AudioCapturer_RequestPlaybackCaptureStart(
        capturer: *mut OH_AudioCapturer,
        callback: OH_AudioCapturer_OnPlaybackCaptureStartCallback,
        userData: *mut ::core::ffi::c_void,
    ) -> OH_AudioStream_Result;
}