blob: c98a335cca89da83d3227e010bee7aaaa31cd0b0 [file] [log] [blame]
b.liud440f9f2025-04-18 10:44:31 +08001/*-----------------------------------------------------------------------------------------------*/
2/**
3 @file ql_audio_pcm.h
4 @brief playback or capture API
5*/
6/*-----------------------------------------------------------------------------------------------*/
7
8/*-------------------------------------------------------------------------------------------------
9 EDIT HISTORY
10 This section contains comments describing changes made to the file.
11 Notice that changes are listed in reverse chronological order.
12 $Header: $
13 when who what, where, why
14 -------- --- ----------------------------------------------------------
15 2021-11-03 dameng.lin Created .
16-------------------------------------------------------------------------------------------------*/
17
18#ifndef __QL_AUDIO_PCM_H
19#define __QL_AUDIO_PCM_H
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25#include <stdint.h>
26#include "mbtk_log.h"
27#include "mbtk_audio2.h"
28#include "ql_v2/ql_type.h"
29#include "mbtk_ril_api.h"
30#include "ql_v2/ql_audio_cfg.h"
31
32typedef int ql_audio_handle_t;
33
34static const char *g_wav_file_name = NULL;
35static mbtk_ril_handle* call_info_handle = NULL;
36
37
38typedef enum QL_AUDIO_STREAM_FORMAT_ENUM
39{
40 QL_AUDIO_STREAM_FORMAT_PCM = 1, /**< PCM*/
41 QL_AUDIO_STREAM_FORMAT_MP3, /**< MP3*/
42 QL_AUDIO_STREAM_FORMAT_AMR, /**< AMR*/
43 QL_AUDIO_STREAM_FORMAT_AMRNB, /**< AMR-NB*/
44 QL_AUDIO_STREAM_FORMAT_AMRWB, /**< AMR-WB*/
45}QL_AUDIO_STREAM_FORMAT_E;
46
47
48/**The structure of PCM configuration parameters*/
49typedef struct ql_audio_pcm_config_struct
50{
51 /** Each sound card maintains a hardware buffer to store audio data. The hardware
52 * buffer is divided into several periods. The sound card uses period as a unit to transmit data,
53 * and one period stores some data frames.period_size sets the size of periods in hardware buffer.
54 * When period_size is set to 0,it means that the period size is calculated by the bottom layer to
55 * obtain a default value. If period_size is not 0, the recommended value is 128–960. The larger the
56 * perod_size is, the larger the kernel overhead is
57 */
58 uint32_t period_size;
59 /** period_count indicates the count of period that the data occupies, when the application reads data
60 * from or writes data to the hardware buffer.The size of the data that the application reads from or
61 * writes to the hardware buffer every time equals period_count multiplied by period_size. The hardware
62 * buffer has a maximum of 8 periods by default. The recommended value of period_count is 1–3.
63 */
64 uint32_t period_count;
65 uint32_t num_channels; /**< Number of channels. 1 Mono 2 Stereo*/
66 uint32_t sample_rate; /**< Sampling rate. A PCM interface supports 8000 and 16000,and an I2s interface supports 48000.Unit:Hz*/
67 uint32_t pcm_format; /**< PCM data format.Presently supports 2 only,which means 16-bit little endian format*/
68} ql_audio_pcm_config_t;
69
70#define QL_AUDIO_INVALID_HANDLE ((ql_audio_handle_t)(void *)NULL)
71
72typedef enum
73{
74 QL_AUDIO_STREAM_DIRECTION_PLAYBACK = 0,
75 QL_AUDIO_STREAM_DIRECTION_CAPTURE,
76 QL_AUDIO_STREAM_DIRECTION_MAX
77}QL_AUDIO_STREAM_DIRECTION_E;
78
79
80/**The enumeration of the front end PCM device types*/
81typedef enum QL_AUDIO_FE_PCM_DEV_ENUM
82{
83 QL_AUDIO_FE_PCM_DEV_MIN = -1,
84 QL_AUDIO_FE_PCM_DEV_MULTIMEDIA1 = 0, /**< The first PCM device available for general-purpose audio playback and capturing.*/
85 QL_AUDIO_FE_PCM_DEV_MULTIMEDIA2 = 1, /**< The sencond PCM device available for general-purpose audio playback and capturing.*/
86 QL_AUDIO_FE_PCM_DEV_MULTIMEDIA3 = 2, /**< The third PCM device available for general-purpose audio playback and capturing.*/
87 QL_AUDIO_FE_PCM_DEV_MAX
88} QL_AUDIO_FE_PCM_DEV_E;
89
90
91
92typedef enum QL_AUDIO_BE_DAI_ENUM
93{
94 QL_AUDIO_BE_DAI_MIN = -1,
95 QL_AUDIO_BE_DAI_PLAYBACK_PRI_PCM = 0, /**< Play back audio to the first PCM interface.*/
96 QL_AUDIO_BE_DAI_PLAYBACK_VOICE_TX, /**< play back audio to the voice call uplink*/
97 QL_AUDIO_BE_DAI_CAPTURE_PRI_PCM, /**< Capture audio from the first PCM interface*/
98 QL_AUDIO_BE_DAI_CAPTURE_VOICE_UL, /**< Capture voice stream from voice call uplink*/
99 QL_AUDIO_BE_DAI_CAPTURE_VOICE_DL, /**< Capture voice stream from voice call downlink*/
100 QL_AUDIO_BE_DAI_MAX
101}QL_AUDIO_BE_DAI_E;
102
103#define QL_AUDIO_BE_DAI_MASK_PLAYBACK_PRI_PCM (1 << QL_AUDIO_BE_DAI_PLAYBACK_PRI_PCM)
104#define QL_AUDIO_BE_DAI_MASK_PLAYBACK_VOICE_TX (1 << QL_AUDIO_BE_DAI_PLAYBACK_VOICE_TX)
105#define QL_AUDIO_BE_DAI_MASK_CAPTURE_PRI_PCM (1 << QL_AUDIO_BE_DAI_CAPTURE_PRI_PCM)
106#define QL_AUDIO_BE_DAI_MASK_CAPTURE_VOICE_UL (1 << QL_AUDIO_BE_DAI_CAPTURE_VOICE_UL)
107#define QL_AUDIO_BE_DAI_MASK_CAPTURE_VOICE_DL (1 << QL_AUDIO_BE_DAI_CAPTURE_VOICE_DL)
108
109/**The enumeration of audio playback state*/
110typedef enum QL_AUDIO_PLAYBACK_STATE_ENUM
111{
112 QL_AUDIO_PLAYBACK_STATE_CLOSE = 0, /**< Close*/
113 QL_AUDIO_PLAYBACK_STATE_OPEN, /**< Open*/
114 QL_AUDIO_PLAYBACK_STATE_PREPARE, /**< Ready*/
115 QL_AUDIO_PLAYBACK_STATE_PLAYING, /**< Playing*/
116 QL_AUDIO_PLAYBACK_STATE_FINISHED, /**< Finished*/
117 QL_AUDIO_PLAYBACK_STATE_PAUSE, /**< Pause*/
118 QL_AUDIO_PLAYBACK_STATE_ERROR, /**< Error*/
119} QL_AUDIO_PLAYBACK_STATE_E;
120
121/**The enumeration of audio capture state*/
122typedef enum QL_AUDIO_CAPTURE_STATE_ENUM
123{
124 QL_AUDIO_CAPTURE_STATE_CLOSE = 0, /**< Close*/
125 QL_AUDIO_CAPTURE_STATE_OPEN, /**< Open*/
126 QL_AUDIO_CAPTURE_STATE_PREPARE, /**< Prepare*/
127 QL_AUDIO_CAPTURE_STATE_CAPTURING, /**< Capturing*/
128 QL_AUDIO_CAPTURE_STATE_FINISHED, /**< Finished*/
129 QL_AUDIO_CAPTURE_STATE_PAUSE, /**< Pause*/
130 QL_AUDIO_CAPTURE_STATE_ERROR, /**< Error*/
131} QL_AUDIO_CAPTURE_STATE_E;
132
133
134#define QL_AUDIO_PLAYBACK_NONBLOCK 0
135#define QL_AUDIO_PLAYBACK_BLOCK 1
136
137
138/**
139 @brief The audio capturing state callback function
140 @param handle Recording handle,which is the return value of ql_audio_capture_open().
141 @param params Parameters carried by the callback function
142 @param state The current audio capturing state.
143*/
144typedef int (*ql_audio_capture_state_cb_f)(ql_audio_handle_t handle, void *params, QL_AUDIO_CAPTURE_STATE_E state);
145
146/**
147 @brief The playback state callback function
148 @param handle Playback handle, which is the return value of ql_audio_playback_open().
149 @param params Parameters carried by the callback function.
150 @param state The current playback state.
151*/
152typedef int (*ql_audio_playback_state_cb_f)(ql_audio_handle_t handle, void *params, QL_AUDIO_PLAYBACK_STATE_E state);
153/*-----------------------------------------------------------------------------------------------*/
154/**
155 @brief This function opens the audio context for playback.
156
157 @param[in] fe_pcm_dev Front end PCM device type. defined by QL_AUDIO_FE_PCM_DEV_E
158 @param[in] be_dai_mask Backend digit audio interface mask, support follow:
159 QL_AUDIO_BE_DAI_MASK_PLAYBACK_PRI_PCM Play back audio to the 1 st PCM interface
160 QL_AUDIO_BE_DAI_MASK_PLAYBACK_SEC_PCM Play back audio to the 2 nd PCM interface
161 QL_AUDIO_BE_DAI_MASK_PLAYBACK_PRI_I2S Play back audio to the 1 st I2S interface
162 QL_AUDIO_BE_DAI_MASK_PLAYBACK_SEC_I2S Play back audio to the 2 nd I2S interface
163 QL_AUDIO_BE_DAI_MASK_PLAYBACK_VOICE_TX Play back audio to the voice call uplink
164
165 @retval A_valid_handle Successful execution.
166 @retval QL_AUDIO_INVALID_HANDLE Failed execution.Invalid handle
167 */
168/*-----------------------------------------------------------------------------------------------*/
169ql_audio_handle_t ql_audio_playback_open(QL_AUDIO_FE_PCM_DEV_E fe_pcm_dev, uint32_t be_dai_mask)
170{
171 if (fe_pcm_dev == QL_AUDIO_FE_PCM_DEV_MULTIMEDIA1 && be_dai_mask == QL_AUDIO_BE_DAI_MASK_PLAYBACK_PRI_PCM)
172 {
173 int init_result = mbtk_audio_pcm_init();
174
175 if (init_result != 0) {
176 LOGE("Error: mbtk_audio_pcm_init failed with error code %d\n", init_result);
177 if (audio_error_callback) {
178 audio_error_callback(init_result);
179 }
180 return QL_AUDIO_INVALID_HANDLE;
181 }
182 } else {
183 printf("Error: Unsupported PCM device or DAI mask\n");
184 return QL_AUDIO_INVALID_HANDLE;
185 }
186
187 return (ql_audio_handle_t)1;
188}
189
190/*-----------------------------------------------------------------------------------------------*/
191/**
192 @brief This function prepares for audio file playback.
193
194 @param[in] handle The handle returned by ql_audio_playback_open().
195 @param[in] file_name The name of the file to be played back.
196 @param[in] pcm_config Pcm config, including sample rate, channel nums,
197 defined by ql_audio_pcm_config_t. Generally, it is NULL.
198 @param[in] playback_state_cb Callback function to report the current playback state
199 The states defined by QL_AUDIO_PLAYBACK_STATE_E
200 @param[in] params Parameters carried by the callback function.
201
202 @retval QL_ERR_OK Successful execution.
203 @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle.
204 @retval QL_ERR_INVALID_STATE Failed execution. Invalid state.
205 @retval Others Failed execution. See ql_type.h for error codes.
206
207 @note Before calling this function, call ql_audio_playback_open() first to obtain a handle.
208 If an audio file is expected to be played back, call this function first to prepare for
209 the playback and then ql_audio_playback_play() to start playback.
210 */
211/*-----------------------------------------------------------------------------------------------*/
212int ql_audio_playback_file_prepare(ql_audio_handle_t handle,
213 const char *file_name,
214 ql_audio_pcm_config_t *pcm_config,
215 ql_audio_playback_state_cb_f playback_state_cb,
216 void *params)
217{
218 if (handle == QL_AUDIO_INVALID_HANDLE) {
219 LOGE("Error: Invalid handle\n");
220 if (audio_error_callback) {
221 audio_error_callback(-1);
222 }
223 return QL_ERR_SERVICE_NOT_READY;
224 }
225
226 if (file_name == NULL) {
227 LOGE("Error: File name is NULL\n");
228 if (audio_error_callback) {
229 audio_error_callback(-1);
230 }
231 return QL_ERR_SERVICE_NOT_READY;
232 }
233
234 g_wav_file_name = file_name;
235
236 if (pcm_config != NULL) {
237 printf("Warning: PCM configuration provided but not supported\n");
238 } else {
239 LOGD("No PCM configuration provided\n");
240 }
241
242 if (playback_state_cb != NULL) {
243 printf("Warning: Playback state callback provided but not supported\n");
244 } else {
245 LOGD("No playback state callback provided\n");
246 }
247
248 LOGD("Audio file prepared for playback: %s\n", file_name);
249 return QL_ERR_OK;
250}
251/*-----------------------------------------------------------------------------------------------*/
252/**
253 @brief This function prepares for audio stream playback.
254
255 @param[in] handle The API ql_audio_playback_open return results
256 @param[in] pcm_config Pcm config, including sample rate, channel nums,
257 defined by ql_audio_pcm_config_t. If it is NULL, the API use defaule value.
258 @param[in] playback_state_cb Callback function to report the current playback state.
259 @param[in] params Parameters carried by the callback function.
260
261 @retval QL_ERR_OK Successful execution.
262 @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle.
263 @retval QL_ERR_INVALID_STATE Failed execution. Invalid state.
264 @retval Others Failed execution. See ql_type.h for error codes.
265
266 @note Before calling this function, call ql_audio_playback_open() first to obtain a handle.
267 If an audio stream is expected to be played back, call this function first to prepare
268 for the audio stream playback and then ql_audio_playback_push_stream() to start playback.
269 */
270/*-----------------------------------------------------------------------------------------------*/
271int ql_audio_playback_stream_prepare(ql_audio_handle_t handle,
272 ql_audio_pcm_config_t *pcm_config,
273 ql_audio_playback_state_cb_f playback_state_cb,
274 void *params);
275
276/*-----------------------------------------------------------------------------------------------*/
277/**
278 @brief This function starts playback of the audio data.
279
280 @param[in] handle The handle returned by ql_audio_playback_open().
281
282 @retval QL_ERR_OK Successful execution.
283 @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle.
284 @retval QL_ERR_INVALID_STATE Failed execution. Invalid state.
285 @retval Others Failed execution. See ql_type.h for error codes.
286
287 @note Before calling this function, call ql_audio_playback_file_prepare() first to prepare the audio file
288 to be played back, otherwise the audio data cannot be played back successfully.This function also supports
289 playback of audio stream data. In this case, call ql_audio_playback_stream_prepare() first to prepare
290 the audio stream to be played back, then this function to start playback, and finally
291 ql_audio_playback_push_stream() to play back the audio stream in buffer.
292 */
293/*-----------------------------------------------------------------------------------------------*/
294int ql_audio_playback_play(ql_audio_handle_t handle)
295{
296 if (handle == QL_AUDIO_INVALID_HANDLE) {
297 LOGE("Error: Invalid handle\n");
298 if (audio_error_callback) {
299 audio_error_callback(-1);
300 }
301 return QL_ERR_SERVICE_NOT_READY;
302 }
303
304 if (g_wav_file_name == NULL) {
305 LOGE("Error: No audio file prepared for playback\n");
306 if (audio_error_callback) {
307 audio_error_callback(-1);
308 }
309 return QL_ERR_SERVICE_NOT_READY;
310 }
311
312 int err = mbtk_audio_wav_play_start(g_wav_file_name);
313 if (err != 0) {
314 LOGE("Error playing audio file: %d\n", err);
315 if (audio_error_callback) {
316 audio_error_callback(err);
317 }
318 return QL_ERR_SERVICE_NOT_READY;
319 } else {
320 LOGD("Audio file playback started successfully\n");
321 }
322
323 return QL_ERR_OK;
324}
325
326/*-----------------------------------------------------------------------------------------------*/
327/**
328 @brief This function plays back the audio stream in buffer.
329
330 @param[in] handle The handle returned by ql_audio_playback_open().
331 @param[in] stream_buf The buffer that stores the audio stream to be played back.
332 @param[in] buf_size The size of the audio stream to be played back. Unit: Byte.
333
334 @retval QL_ERR_OK Successful execution.
335 @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle.
336 @retval QL_ERR_INVALID_STATE Failed execution. Invalid state.
337 @retval Others Failed execution. See ql_type.h for error codes.
338
339 */
340/*-----------------------------------------------------------------------------------------------*/
341int ql_audio_playback_push_stream(ql_audio_handle_t handle, void *stream_buf, uint32_t buf_size);
342
343/*-----------------------------------------------------------------------------------------------*/
344/**
345 @brief This function pauses the audio playback.
346
347 @param[in] handle The handle returned by ql_audio_playback_open().
348
349 @retval QL_ERR_OK Successful execution.
350 @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle.
351 @retval Others Failed execution. See ql_type.h for error codes.
352 */
353/*-----------------------------------------------------------------------------------------------*/
354int ql_audio_playback_pause(ql_audio_handle_t handle);
355
356/*-----------------------------------------------------------------------------------------------*/
357/**
358 @brief This function resumes the audio playback.
359
360 @param[in] handle The handle returned by ql_audio_playback_open().
361
362 @retval QL_ERR_OK Successful execution.
363 @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle.
364 @retval Others Failed execution. See ql_type.h for error codes.
365 */
366/*-----------------------------------------------------------------------------------------------*/
367int ql_audio_playback_resume(ql_audio_handle_t handle);
368
369/*-----------------------------------------------------------------------------------------------*/
370/**
371 @brief This function stops the audio playback.
372
373 @param[in] handle The handle returned by ql_audio_playback_open().
374
375 @retval QL_ERR_OK Successful execution.
376 @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle.
377 @retval Others Failed execution. See ql_type.h for error codes.
378 */
379/*-----------------------------------------------------------------------------------------------*/
380int ql_audio_playback_stop(ql_audio_handle_t handle);
381
382/*-----------------------------------------------------------------------------------------------*/
383/**
384 @brief This function closes the audio context for playback.
385
386 @param[in] handle The handle returned by ql_audio_playback_open().
387
388 @retval QL_ERR_OK Successful execution.
389 @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle.
390 @retval Others Failed execution. See ql_type.h for error codes.
391
392 @Note After an audio playback ends, you must call this function to close the audio context,
393 otherwise subsequent call of ql_audio_playback_open() will fail.
394 */
395/*-----------------------------------------------------------------------------------------------*/
396int ql_audio_playback_close(ql_audio_handle_t handle)
397{
398 if (handle == QL_AUDIO_INVALID_HANDLE) {
399 LOGE("Error: Invalid handle\n");
400 if (audio_error_callback) {
401 audio_error_callback(-1);
402 }
403 return QL_ERR_SERVICE_NOT_READY;
404 }
405
406 int deinit_result = mbtk_audio_wav_deinit();
407 if (deinit_result != 0) {
408 LOGE("Error: mbtk_audio_wav_deinit failed with error code %d\n", deinit_result);
409 if (audio_error_callback) {
410 audio_error_callback(deinit_result);
411 }
412 return QL_ERR_SERVICE_NOT_READY;
413 }
414
415 LOGD("Audio playback context closed successfully\n");
416 return QL_ERR_OK;
417}
418/*-----------------------------------------------------------------------------------------------*/
419/**
420 @brief This function gets the audio playback state.
421
422 @param[in] handle The handle returned by ql_audio_playback_open().
423 @param[out] playback_state the current audio playback state, defined by QL_AUDIO_PLAYBACK_STATE_E
424 */
425/*-----------------------------------------------------------------------------------------------*/
426int ql_audio_playback_get_state(ql_audio_handle_t handle, QL_AUDIO_PLAYBACK_STATE_E *playback_state);
427
428/*-----------------------------------------------------------------------------------------------*/
429/**
430 @brief This function handles the call state changes.
431
432 @param[in] data Pointer to the call information data.
433 @param[in] data_len Length of the call information data.
434
435 This function is a callback that processes different call states. When a call is waiting (MBTK_CLCC),
436 it pauses the audio playback. When a call is disconnected (MBTK_DISCONNECTED), it resumes the audio playback.
437 For other states, it logs the current call wait state.
438
439 @note The function uses mbtk_audio_wav_play_pause() and mbtk_audio_wav_play_resume() to control audio playback.
440 Error handling is performed by logging errors if the playback control functions fail.
441*/
442/*-----------------------------------------------------------------------------------------------*/
443static void call_state_handler(const void* data, int data_len)
444{
445 mbtk_call_info_t *reg = (mbtk_call_info_t *)data;
446 switch (reg->call_wait)
447 {
448 case MBTK_CLCC:
449 {
450 int result = mbtk_audio_wav_play_pause();
451 if (result != 0) {
452 LOGE("Error: mbtk_audio_wav_play_pause failed with error code %d\n", result);
453 if (audio_error_callback) {
454 audio_error_callback(result);
455 }
456 return;
457 }
458 LOGD("Incoming call!\n");
459 }
460 break;
461 case MBTK_DISCONNECTED:
462 {
463 int result = mbtk_audio_wav_play_resume();
464 if (result != 0) {
465 LOGE("Error: mbtk_audio_wav_play_resume failed with error code %d\n", result);
466 if (audio_error_callback) {
467 audio_error_callback(result);
468 }
469 return;
470 }
471 LOGD("Call disconnected!\n");
472 }
473 break;
474 default:
475 LOGD("RING: None call_wait = %d", reg->call_wait);
476 break;
477 }
478}
479/*-----------------------------------------------------------------------------------------------*/
480/**
481 @brief This function sets the block flag for audio playback.
482
483 @param[in] handle The handle returned by ql_audio_playback_open().
484 @param[in] flags block flag, including QL_AUDIO_PLAYBACK_NONBLOCK and QL_AUDIO_PLAYBACK_BLOCK
485
486 @retval QL_ERR_OK Successful execution.
487 @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle.
488 @retval QL_ERR_INVALID_ARG Illegal argument.
489 @retval QL_ERR_INVALID_STATE Failed execution. Invalid state.
490 @retval Others Failed execution. See ql_type.h for error codes.
491
492 @note Call this function as per the function call sequence below, to make sure the audio playback can be blocked successfully.
493 1) ql_audio_playback_open()
494 2) ql_audio_playback_set_block_flag()
495 3) ql_audio_playback_file_prepare()
496 4) ql_audio_playback_play()
497 If the audio playback is blocked successfully by calling ql_audio_playback_set_block_flag(), then
498 1) If you dial a call or there is an incoming call during the audio playback, the playback will pause;
499 after the call is hung up, the playback resumes automatically.
500 2) During a voice call, no function can be used to realize audio playback. In this case,
501 the call of ql_auido_palyback_file_prepare() will fail, which means audio files cannot be played back.
502 */
503/*-----------------------------------------------------------------------------------------------*/
504int ql_audio_playback_set_block_flag(ql_audio_handle_t handle, uint8_t flags)
505{
506 if (handle == QL_AUDIO_INVALID_HANDLE) {
507 LOGE("Error: Invalid handle\n");
508 if (audio_error_callback) {
509 audio_error_callback(-1);
510 }
511 return QL_ERR_SERVICE_NOT_READY;
512 }
513
514 if (flags == QL_AUDIO_PLAYBACK_BLOCK) {
515 LOGD("Set to blocking mode\n");
516
517 if (call_info_handle == NULL) {
518 call_info_handle = mbtk_ril_open(MBTK_AT_PORT_DEF);
519 if (call_info_handle) {
520 LOGD("Successfully created qser_voice_call_client_init\n");
521 } else {
522 LOGE("Failed to create qser_voice_call_client_init\n");
523 if (audio_error_callback) {
524 audio_error_callback(-1);
525 }
526 return QL_ERR_SERVICE_NOT_READY;
527 }
528 }
529
530 int err = mbtk_call_state_change_cb_reg(call_state_handler);
531 if (err) {
532 LOGE("Error registering call state change callback: %d\n", err);
533 if (audio_error_callback) {
534 audio_error_callback(err);
535 }
536 return QL_ERR_SERVICE_NOT_READY;
537 }
538
539 } else if (flags == QL_AUDIO_PLAYBACK_NONBLOCK) {
540 LOGD("Set to non-blocking mode\n");
541 } else {
542 LOGE("Invalid flags parameter: %d\n", flags);
543 if (audio_error_callback) {
544 audio_error_callback(-1);
545 }
546 return QL_ERR_SERVICE_NOT_READY;
547 }
548
549 return QL_ERR_OK;
550}
551/*-----------------------------------------------------------------------------------------------*/
552/**
553 @brief This function opens the audio context for capturing.
554
555 @param[in] fe_pcm_dev Front end PCM device type.
556 @param[in] be_dai_mask Back end DAI mask,support follow:
557 QL_AUDIO_BE_DAI_MASK_CAPTURE_PRI_PCM
558 QL_AUDIO_BE_DAI_MASK_CAPTURE_VOICE_UL
559 QL_AUDIO_BE_DAI_MASK_CAPTURE_VOICE_DL
560
561@retval A_valid_handle Successful execution
562@retval QL_AUDIO_INVALID_HANDLE Failed execution.Invalid handle
563 */
564/*-----------------------------------------------------------------------------------------------*/
565ql_audio_handle_t ql_audio_capture_open(QL_AUDIO_FE_PCM_DEV_E fe_pcm_dev, uint32_t be_dai_mask);
566
567/*-----------------------------------------------------------------------------------------------*/
568/**
569 @brief This function prepares for audio file capturing.
570
571 @param[in] handle The handle returned by ql_audio_capture_open().
572 @param[in] file_name The name of the audio file to be captured.
573 @param[in] type The format of the audio data in the audio file.
574 @param[in] pcm_config Pcm config, including sample rate, channel nums,
575 defined by ql_audio_pcm_config_t, If it is NULL, the API use defaule value
576 @param[in] capture_state_cb Callback function to report the current audio capturing state.
577 @param[in] params Parameters carried by the callback function.
578
579 @retval QL_ERR_OK Successful execution.
580 @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle.
581 @retval QL_ERR_INVALID_STATE Failed execution. Invalid state.
582 @retval Others Failed execution. See ql_type.h for error codes.
583
584 @note Before calling this function, call ql_audio_capture_open() first to obtain a handle.
585 If an audio file is expected to be captured, call this function first to prepare for the audio file
586 capturing and then ql_audio_capture_record() to start capturing.
587 */
588/*-----------------------------------------------------------------------------------------------*/
589int ql_audio_capture_file_prepare(ql_audio_handle_t handle,
590 const char *file_name,
591 QL_AUDIO_STREAM_FORMAT_E type,
592 ql_audio_pcm_config_t *pcm_config,
593 ql_audio_capture_state_cb_f capture_state_cb,
594 void *params);
595
596/*-----------------------------------------------------------------------------------------------*/
597/**
598 @brief This function prepares for audio stream capturing.
599
600 @param[in] handle This function prepares for audio stream capturing.
601 @param[in] pcm_config PCM configuration parameters.
602 @param[in] capture_state_cb Callback function to report the current audio capturing state.
603 @param[in] params Parameters carried by the callback function.
604
605 @retval QL_ERR_OK Successful execution.
606 @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle.
607 @retval QL_ERR_INVALID_STATE Failed execution. Invalid state.
608 @retval Others Failed execution. See ql_type.h for error codes.
609
610 @note Before calling this function, call ql_audio_capture_open() first to obtain a handle.
611 If an audio stream is expected to be captured, call this function first to prepare for
612 the audio stream capturing and then ql_audio_capture_push_stream() to start capturing.
613 */
614/*-----------------------------------------------------------------------------------------------*/
615int ql_audio_capture_stream_prepare(ql_audio_handle_t handle,
616 ql_audio_pcm_config_t *pcm_config,
617 ql_audio_capture_state_cb_f capture_state_cb,
618 void *params);
619
620/*-----------------------------------------------------------------------------------------------*/
621/**
622 @brief This function starts to capture the audio data.
623
624 @param[in] handle The handle returned by ql_audio_capture_open().
625
626 @retval QL_ERR_OK Successful execution.
627 @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle.
628 @retval QL_ERR_INVALID_STATE Failed execution. Invalid state.
629 @retval Others Failed execution. See ql_type.h for error codes.
630
631 @note Before calling this function, call ql_audio_capture_file_prepare() first to prepare the audio
632 file to be captured, otherwise the audio data cannot be captured successfully.This function also
633 supports capturing of audio stream data. In this case, call ql_audio_capture_stream_prepare()
634 first to prepare the audio stream to be captured, then this function to start capturing,
635 and finally ql_audio_capture_pull_stream() to capture the audio stream in buffer.
636 */
637/*-----------------------------------------------------------------------------------------------*/
638int ql_audio_capture_record(ql_audio_handle_t handle);
639
640/*-----------------------------------------------------------------------------------------------*/
641/**
642 @brief This function captures the audio stream data to the buffer.
643
644 @param[in] handle The handle returned by ql_audio_capture_open().
645 @param[out] stream_buf The buffer that stores the audio stream data to be captured.
646 @param[in] buf_size Buffer size. Unit: Byte.
647
648 @retval QL_ERR_OK Successful execution.
649 @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle.
650 @retval Others Failed execution. See ql_type.h for error codes.
651
652 */
653/*-----------------------------------------------------------------------------------------------*/
654int ql_audio_capture_pull_stream(ql_audio_handle_t handle, void *stream_buf, uint32_t buf_size);
655
656/*-----------------------------------------------------------------------------------------------*/
657/**
658 @brief This function pauses the audio capturing.
659
660 @param[in] handle The handle returned by ql_audio_capture_open().
661
662 @retval QL_ERR_OK Successful execution.
663 @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle.
664 @retval Others Failed execution. See ql_type.h for error codes.
665 */
666/*-----------------------------------------------------------------------------------------------*/
667int ql_audio_capture_pause(ql_audio_handle_t handle);
668
669/*-----------------------------------------------------------------------------------------------*/
670/**
671 @brief This function resumes the audio capturing.
672
673 @param[in] handle The handle returned by ql_audio_capture_open().
674
675 @retval QL_ERR_OK Successful execution.
676 @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle.
677 @retval Others Failed execution. See ql_type.h for error codes.
678 */
679/*-----------------------------------------------------------------------------------------------*/
680int ql_audio_capture_resume(ql_audio_handle_t handle);
681
682/*-----------------------------------------------------------------------------------------------*/
683/**
684 @brief This function stops the audio capturing.
685
686 @param[in] handle The handle returned by ql_audio_capture_open().
687
688 @retval QL_ERR_OK Successful execution.
689 @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle.
690 @retval Others Failed execution. See ql_type.h for error codes.
691
692 @note Calling this function will stop audio capturing regardless of whether the capturing is in
693 progress or paused,and the capturing cannot be resumed after it is stopped.
694 */
695/*-----------------------------------------------------------------------------------------------*/
696int ql_audio_capture_stop(ql_audio_handle_t handle);
697
698/*-----------------------------------------------------------------------------------------------*/
699/**
700 @brief This function closes the audio context for capturing.
701
702 @param[in] handle The handle returned by ql_audio_capture_open().
703
704 @retval QL_ERR_OK Successful execution.
705 @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle.
706 @retval Others Failed execution. See ql_type.h for error codes.
707 @note After audio capturing ends, you must call this function to close the audio context,
708 otherwise subsequent call of ql_audio_capture_open() will fail.
709 */
710/*-----------------------------------------------------------------------------------------------*/
711int ql_audio_capture_close(ql_audio_handle_t handle);
712
713/*-----------------------------------------------------------------------------------------------*/
714/**
715 @brief This function gets the current audio capturing state.
716
717 @param[in] handle The handle returned by ql_audio_capture_open().
718 @param[out] capture_state The current audio capturing state.
719 */
720/*-----------------------------------------------------------------------------------------------*/
721void ql_audio_capture_get_state(ql_audio_handle_t handle, QL_AUDIO_CAPTURE_STATE_E *capture_state);
722
723#ifdef __cplusplus
724}
725#endif
726
727
728#endif
729