b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 1 | /*-----------------------------------------------------------------------------------------------*/ |
| 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 |
| 22 | extern "C" { |
| 23 | #endif |
| 24 | |
| 25 | #include <stdint.h> |
| 26 | |
| 27 | |
| 28 | typedef int ql_audio_handle_t; |
| 29 | |
| 30 | |
| 31 | typedef enum QL_AUDIO_STREAM_FORMAT_ENUM |
| 32 | { |
| 33 | QL_AUDIO_STREAM_FORMAT_PCM = 1, /**< PCM*/ |
| 34 | QL_AUDIO_STREAM_FORMAT_MP3, /**< MP3*/ |
| 35 | QL_AUDIO_STREAM_FORMAT_AMR, /**< AMR*/ |
| 36 | QL_AUDIO_STREAM_FORMAT_AMRNB, /**< AMR-NB*/ |
| 37 | QL_AUDIO_STREAM_FORMAT_AMRWB, /**< AMR-WB*/ |
| 38 | }QL_AUDIO_STREAM_FORMAT_E; |
| 39 | |
| 40 | |
| 41 | /**The structure of PCM configuration parameters*/ |
| 42 | typedef struct ql_audio_pcm_config_struct |
| 43 | { |
| 44 | /** Each sound card maintains a hardware buffer to store audio data. The hardware |
| 45 | * buffer is divided into several periods. The sound card uses period as a unit to transmit data, |
| 46 | * and one period stores some data frames.period_size sets the size of periods in hardware buffer. |
| 47 | * When period_size is set to 0,it means that the period size is calculated by the bottom layer to |
| 48 | * obtain a default value. If period_size is not 0, the recommended value is 128–960. The larger the |
| 49 | * perod_size is, the larger the kernel overhead is |
| 50 | */ |
| 51 | uint32_t period_size; |
| 52 | /** period_count indicates the count of period that the data occupies, when the application reads data |
| 53 | * from or writes data to the hardware buffer.The size of the data that the application reads from or |
| 54 | * writes to the hardware buffer every time equals period_count multiplied by period_size. The hardware |
| 55 | * buffer has a maximum of 8 periods by default. The recommended value of period_count is 1–3. |
| 56 | */ |
| 57 | uint32_t period_count; |
| 58 | uint32_t num_channels; /**< Number of channels. 1 Mono 2 Stereo*/ |
| 59 | uint32_t sample_rate; /**< Sampling rate. A PCM interface supports 8000 and 16000,and an I2s interface supports 48000.Unit:Hz*/ |
| 60 | uint32_t pcm_format; /**< PCM data format.Presently supports 2 only,which means 16-bit little endian format*/ |
| 61 | } ql_audio_pcm_config_t; |
| 62 | |
| 63 | #define QL_AUDIO_INVALID_HANDLE ((ql_audio_handle_t)(void *)NULL) |
| 64 | |
| 65 | typedef enum |
| 66 | { |
| 67 | QL_AUDIO_STREAM_DIRECTION_PLAYBACK = 0, |
| 68 | QL_AUDIO_STREAM_DIRECTION_CAPTURE, |
| 69 | QL_AUDIO_STREAM_DIRECTION_MAX |
| 70 | }QL_AUDIO_STREAM_DIRECTION_E; |
| 71 | |
| 72 | |
| 73 | /**The enumeration of the front end PCM device types*/ |
| 74 | typedef enum QL_AUDIO_FE_PCM_DEV_ENUM |
| 75 | { |
| 76 | QL_AUDIO_FE_PCM_DEV_MIN = -1, |
| 77 | QL_AUDIO_FE_PCM_DEV_MULTIMEDIA1 = 0, /**< The first PCM device available for general-purpose audio playback and capturing.*/ |
| 78 | QL_AUDIO_FE_PCM_DEV_MULTIMEDIA2 = 1, /**< The sencond PCM device available for general-purpose audio playback and capturing.*/ |
| 79 | QL_AUDIO_FE_PCM_DEV_MULTIMEDIA3 = 2, /**< The third PCM device available for general-purpose audio playback and capturing.*/ |
| 80 | QL_AUDIO_FE_PCM_DEV_MAX |
| 81 | } QL_AUDIO_FE_PCM_DEV_E; |
| 82 | |
| 83 | |
| 84 | |
| 85 | typedef enum QL_AUDIO_BE_DAI_ENUM |
| 86 | { |
| 87 | QL_AUDIO_BE_DAI_MIN = -1, |
| 88 | QL_AUDIO_BE_DAI_PLAYBACK_PRI_PCM = 0, /**< Play back audio to the first PCM interface.*/ |
| 89 | QL_AUDIO_BE_DAI_PLAYBACK_VOICE_TX, /**< play back audio to the voice call uplink*/ |
| 90 | QL_AUDIO_BE_DAI_CAPTURE_PRI_PCM, /**< Capture audio from the first PCM interface*/ |
| 91 | QL_AUDIO_BE_DAI_CAPTURE_VOICE_UL, /**< Capture voice stream from voice call uplink*/ |
| 92 | QL_AUDIO_BE_DAI_CAPTURE_VOICE_DL, /**< Capture voice stream from voice call downlink*/ |
| 93 | QL_AUDIO_BE_DAI_MAX |
| 94 | }QL_AUDIO_BE_DAI_E; |
| 95 | |
| 96 | #define QL_AUDIO_BE_DAI_MASK_PLAYBACK_PRI_PCM (1 << QL_AUDIO_BE_DAI_PLAYBACK_PRI_PCM) |
| 97 | #define QL_AUDIO_BE_DAI_MASK_PLAYBACK_VOICE_TX (1 << QL_AUDIO_BE_DAI_PLAYBACK_VOICE_TX) |
| 98 | #define QL_AUDIO_BE_DAI_MASK_CAPTURE_PRI_PCM (1 << QL_AUDIO_BE_DAI_CAPTURE_PRI_PCM) |
| 99 | #define QL_AUDIO_BE_DAI_MASK_CAPTURE_VOICE_UL (1 << QL_AUDIO_BE_DAI_CAPTURE_VOICE_UL) |
| 100 | #define QL_AUDIO_BE_DAI_MASK_CAPTURE_VOICE_DL (1 << QL_AUDIO_BE_DAI_CAPTURE_VOICE_DL) |
| 101 | |
| 102 | /**The enumeration of audio playback state*/ |
| 103 | typedef enum QL_AUDIO_PLAYBACK_STATE_ENUM |
| 104 | { |
| 105 | QL_AUDIO_PLAYBACK_STATE_CLOSE = 0, /**< Close*/ |
| 106 | QL_AUDIO_PLAYBACK_STATE_OPEN, /**< Open*/ |
| 107 | QL_AUDIO_PLAYBACK_STATE_PREPARE, /**< Ready*/ |
| 108 | QL_AUDIO_PLAYBACK_STATE_PLAYING, /**< Playing*/ |
| 109 | QL_AUDIO_PLAYBACK_STATE_FINISHED, /**< Finished*/ |
| 110 | QL_AUDIO_PLAYBACK_STATE_PAUSE, /**< Pause*/ |
| 111 | QL_AUDIO_PLAYBACK_STATE_ERROR, /**< Error*/ |
| 112 | } QL_AUDIO_PLAYBACK_STATE_E; |
| 113 | |
| 114 | /**The enumeration of audio capture state*/ |
| 115 | typedef enum QL_AUDIO_CAPTURE_STATE_ENUM |
| 116 | { |
| 117 | QL_AUDIO_CAPTURE_STATE_CLOSE = 0, /**< Close*/ |
| 118 | QL_AUDIO_CAPTURE_STATE_OPEN, /**< Open*/ |
| 119 | QL_AUDIO_CAPTURE_STATE_PREPARE, /**< Prepare*/ |
| 120 | QL_AUDIO_CAPTURE_STATE_CAPTURING, /**< Capturing*/ |
| 121 | QL_AUDIO_CAPTURE_STATE_FINISHED, /**< Finished*/ |
| 122 | QL_AUDIO_CAPTURE_STATE_PAUSE, /**< Pause*/ |
| 123 | QL_AUDIO_CAPTURE_STATE_ERROR, /**< Error*/ |
| 124 | } QL_AUDIO_CAPTURE_STATE_E; |
| 125 | |
| 126 | |
| 127 | #define QL_AUDIO_PLAYBACK_NONBLOCK 0 |
| 128 | #define QL_AUDIO_PLAYBACK_BLOCK 1 |
| 129 | |
| 130 | |
| 131 | /** |
| 132 | @brief The audio capturing state callback function |
| 133 | @param handle Recording handle,which is the return value of ql_audio_capture_open(). |
| 134 | @param params Parameters carried by the callback function |
| 135 | @param state The current audio capturing state. |
| 136 | */ |
| 137 | typedef int (*ql_audio_capture_state_cb_f)(ql_audio_handle_t handle, void *params, QL_AUDIO_CAPTURE_STATE_E state); |
| 138 | |
| 139 | /** |
| 140 | @brief The playback state callback function |
| 141 | @param handle Playback handle, which is the return value of ql_audio_playback_open(). |
| 142 | @param params Parameters carried by the callback function. |
| 143 | @param state The current playback state. |
| 144 | */ |
| 145 | typedef int (*ql_audio_playback_state_cb_f)(ql_audio_handle_t handle, void *params, QL_AUDIO_PLAYBACK_STATE_E state); |
| 146 | |
| 147 | /*-----------------------------------------------------------------------------------------------*/ |
| 148 | /** |
| 149 | @brief This function opens the audio context for playback. |
| 150 | |
| 151 | @param[in] fe_pcm_dev Front end PCM device type. defined by QL_AUDIO_FE_PCM_DEV_E |
| 152 | @param[in] be_dai_mask Backend digit audio interface mask, support follow: |
| 153 | QL_AUDIO_BE_DAI_MASK_PLAYBACK_PRI_PCM Play back audio to the 1 st PCM interface |
| 154 | QL_AUDIO_BE_DAI_MASK_PLAYBACK_SEC_PCM Play back audio to the 2 nd PCM interface |
| 155 | QL_AUDIO_BE_DAI_MASK_PLAYBACK_PRI_I2S Play back audio to the 1 st I2S interface |
| 156 | QL_AUDIO_BE_DAI_MASK_PLAYBACK_SEC_I2S Play back audio to the 2 nd I2S interface |
| 157 | QL_AUDIO_BE_DAI_MASK_PLAYBACK_VOICE_TX Play back audio to the voice call uplink |
| 158 | |
| 159 | @retval A_valid_handle Successful execution. |
| 160 | @retval QL_AUDIO_INVALID_HANDLE Failed execution.Invalid handle |
| 161 | */ |
| 162 | /*-----------------------------------------------------------------------------------------------*/ |
| 163 | ql_audio_handle_t ql_audio_playback_open(QL_AUDIO_FE_PCM_DEV_E fe_pcm_dev, uint32_t be_dai_mask); |
| 164 | |
| 165 | /*-----------------------------------------------------------------------------------------------*/ |
| 166 | /** |
| 167 | @brief This function prepares for audio file playback. |
| 168 | |
| 169 | @param[in] handle The handle returned by ql_audio_playback_open(). |
| 170 | @param[in] file_name The name of the file to be played back. |
| 171 | @param[in] pcm_config Pcm config, including sample rate, channel nums, |
| 172 | defined by ql_audio_pcm_config_t. Generally, it is NULL. |
| 173 | @param[in] playback_state_cb Callback function to report the current playback state |
| 174 | The states defined by QL_AUDIO_PLAYBACK_STATE_E |
| 175 | @param[in] params Parameters carried by the callback function. |
| 176 | |
| 177 | @retval QL_ERR_OK Successful execution. |
| 178 | @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle. |
| 179 | @retval QL_ERR_INVALID_STATE Failed execution. Invalid state. |
| 180 | @retval Others Failed execution. See ql_type.h for error codes. |
| 181 | |
| 182 | @note Before calling this function, call ql_audio_playback_open() first to obtain a handle. |
| 183 | If an audio file is expected to be played back, call this function first to prepare for |
| 184 | the playback and then ql_audio_playback_play() to start playback. |
| 185 | */ |
| 186 | /*-----------------------------------------------------------------------------------------------*/ |
| 187 | int ql_audio_playback_file_prepare(ql_audio_handle_t handle, |
| 188 | const char *file_name, |
| 189 | ql_audio_pcm_config_t *pcm_config, |
| 190 | ql_audio_playback_state_cb_f playback_state_cb, |
| 191 | void *params); |
| 192 | |
| 193 | /*-----------------------------------------------------------------------------------------------*/ |
| 194 | /** |
| 195 | @brief This function prepares for audio stream playback. |
| 196 | |
| 197 | @param[in] handle The API ql_audio_playback_open return results |
| 198 | @param[in] pcm_config Pcm config, including sample rate, channel nums, |
| 199 | defined by ql_audio_pcm_config_t. If it is NULL, the API use defaule value. |
| 200 | @param[in] playback_state_cb Callback function to report the current playback state. |
| 201 | @param[in] params Parameters carried by the callback function. |
| 202 | |
| 203 | @retval QL_ERR_OK Successful execution. |
| 204 | @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle. |
| 205 | @retval QL_ERR_INVALID_STATE Failed execution. Invalid state. |
| 206 | @retval Others Failed execution. See ql_type.h for error codes. |
| 207 | |
| 208 | @note Before calling this function, call ql_audio_playback_open() first to obtain a handle. |
| 209 | If an audio stream is expected to be played back, call this function first to prepare |
| 210 | for the audio stream playback and then ql_audio_playback_push_stream() to start playback. |
| 211 | */ |
| 212 | /*-----------------------------------------------------------------------------------------------*/ |
| 213 | int ql_audio_playback_stream_prepare(ql_audio_handle_t handle, |
| 214 | ql_audio_pcm_config_t *pcm_config, |
| 215 | ql_audio_playback_state_cb_f playback_state_cb, |
| 216 | void *params); |
| 217 | |
| 218 | /*-----------------------------------------------------------------------------------------------*/ |
| 219 | /** |
| 220 | @brief This function starts playback of the audio data. |
| 221 | |
| 222 | @param[in] handle The handle returned by ql_audio_playback_open(). |
| 223 | |
| 224 | @retval QL_ERR_OK Successful execution. |
| 225 | @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle. |
| 226 | @retval QL_ERR_INVALID_STATE Failed execution. Invalid state. |
| 227 | @retval Others Failed execution. See ql_type.h for error codes. |
| 228 | |
| 229 | @note Before calling this function, call ql_audio_playback_file_prepare() first to prepare the audio file |
| 230 | to be played back, otherwise the audio data cannot be played back successfully.This function also supports |
| 231 | playback of audio stream data. In this case, call ql_audio_playback_stream_prepare() first to prepare |
| 232 | the audio stream to be played back, then this function to start playback, and finally |
| 233 | ql_audio_playback_push_stream() to play back the audio stream in buffer. |
| 234 | */ |
| 235 | /*-----------------------------------------------------------------------------------------------*/ |
| 236 | int ql_audio_playback_play(ql_audio_handle_t handle); |
| 237 | |
| 238 | /*-----------------------------------------------------------------------------------------------*/ |
| 239 | /** |
| 240 | @brief This function plays back the audio stream in buffer. |
| 241 | |
| 242 | @param[in] handle The handle returned by ql_audio_playback_open(). |
| 243 | @param[in] stream_buf The buffer that stores the audio stream to be played back. |
| 244 | @param[in] buf_size The size of the audio stream to be played back. Unit: Byte. |
| 245 | |
| 246 | @retval QL_ERR_OK Successful execution. |
| 247 | @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle. |
| 248 | @retval QL_ERR_INVALID_STATE Failed execution. Invalid state. |
| 249 | @retval Others Failed execution. See ql_type.h for error codes. |
| 250 | |
| 251 | */ |
| 252 | /*-----------------------------------------------------------------------------------------------*/ |
| 253 | int ql_audio_playback_push_stream(ql_audio_handle_t handle, void *stream_buf, uint32_t buf_size); |
| 254 | |
| 255 | /*-----------------------------------------------------------------------------------------------*/ |
| 256 | /** |
| 257 | @brief This function pauses the audio playback. |
| 258 | |
| 259 | @param[in] handle The handle returned by ql_audio_playback_open(). |
| 260 | |
| 261 | @retval QL_ERR_OK Successful execution. |
| 262 | @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle. |
| 263 | @retval Others Failed execution. See ql_type.h for error codes. |
| 264 | */ |
| 265 | /*-----------------------------------------------------------------------------------------------*/ |
| 266 | int ql_audio_playback_pause(ql_audio_handle_t handle); |
| 267 | |
| 268 | /*-----------------------------------------------------------------------------------------------*/ |
| 269 | /** |
| 270 | @brief This function resumes the audio playback. |
| 271 | |
| 272 | @param[in] handle The handle returned by ql_audio_playback_open(). |
| 273 | |
| 274 | @retval QL_ERR_OK Successful execution. |
| 275 | @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle. |
| 276 | @retval Others Failed execution. See ql_type.h for error codes. |
| 277 | */ |
| 278 | /*-----------------------------------------------------------------------------------------------*/ |
| 279 | int ql_audio_playback_resume(ql_audio_handle_t handle); |
| 280 | |
| 281 | /*-----------------------------------------------------------------------------------------------*/ |
| 282 | /** |
| 283 | @brief This function stops the audio playback. |
| 284 | |
| 285 | @param[in] handle The handle returned by ql_audio_playback_open(). |
| 286 | |
| 287 | @retval QL_ERR_OK Successful execution. |
| 288 | @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle. |
| 289 | @retval Others Failed execution. See ql_type.h for error codes. |
| 290 | */ |
| 291 | /*-----------------------------------------------------------------------------------------------*/ |
| 292 | int ql_audio_playback_stop(ql_audio_handle_t handle); |
| 293 | |
| 294 | /*-----------------------------------------------------------------------------------------------*/ |
| 295 | /** |
| 296 | @brief This function closes the audio context for playback. |
| 297 | |
| 298 | @param[in] handle The handle returned by ql_audio_playback_open(). |
| 299 | |
| 300 | @retval QL_ERR_OK Successful execution. |
| 301 | @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle. |
| 302 | @retval Others Failed execution. See ql_type.h for error codes. |
| 303 | |
| 304 | @Note After an audio playback ends, you must call this function to close the audio context, |
| 305 | otherwise subsequent call of ql_audio_playback_open() will fail. |
| 306 | */ |
| 307 | /*-----------------------------------------------------------------------------------------------*/ |
| 308 | int ql_audio_playback_close(ql_audio_handle_t handle); |
| 309 | |
| 310 | /*-----------------------------------------------------------------------------------------------*/ |
| 311 | /** |
| 312 | @brief This function gets the audio playback state. |
| 313 | |
| 314 | @param[in] handle The handle returned by ql_audio_playback_open(). |
| 315 | @param[out] playback_state the current audio playback state, defined by QL_AUDIO_PLAYBACK_STATE_E |
| 316 | */ |
| 317 | /*-----------------------------------------------------------------------------------------------*/ |
| 318 | int ql_audio_playback_get_state(ql_audio_handle_t handle, QL_AUDIO_PLAYBACK_STATE_E *playback_state); |
| 319 | |
| 320 | /*-----------------------------------------------------------------------------------------------*/ |
| 321 | /** |
| 322 | @brief This function sets the block flag for audio playback. |
| 323 | |
| 324 | @param[in] handle The handle returned by ql_audio_playback_open(). |
| 325 | @param[in] flags block flag, including QL_AUDIO_PLAYBACK_NONBLOCK and QL_AUDIO_PLAYBACK_BLOCK |
| 326 | |
| 327 | @retval QL_ERR_OK Successful execution. |
| 328 | @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle. |
| 329 | @retval QL_ERR_INVALID_ARG Illegal argument. |
| 330 | @retval QL_ERR_INVALID_STATE Failed execution. Invalid state. |
| 331 | @retval Others Failed execution. See ql_type.h for error codes. |
| 332 | |
| 333 | @note Call this function as per the function call sequence below, to make sure the audio playback can be blocked successfully. |
| 334 | 1) ql_audio_playback_open() |
| 335 | 2) ql_audio_playback_set_block_flag() |
| 336 | 3) ql_audio_playback_file_prepare() |
| 337 | 4) ql_audio_playback_play() |
| 338 | If the audio playback is blocked successfully by calling ql_audio_playback_set_block_flag(), then |
| 339 | 1) If you dial a call or there is an incoming call during the audio playback, the playback will pause; |
| 340 | after the call is hung up, the playback resumes automatically. |
| 341 | 2) During a voice call, no function can be used to realize audio playback. In this case, |
| 342 | the call of ql_auido_palyback_file_prepare() will fail, which means audio files cannot be played back. |
| 343 | */ |
| 344 | /*-----------------------------------------------------------------------------------------------*/ |
| 345 | int ql_audio_playback_set_block_flag(ql_audio_handle_t handle, uint8_t flags); |
| 346 | |
| 347 | /*-----------------------------------------------------------------------------------------------*/ |
| 348 | /** |
| 349 | @brief This function opens the audio context for capturing. |
| 350 | |
| 351 | @param[in] fe_pcm_dev Front end PCM device type. |
| 352 | @param[in] be_dai_mask Back end DAI mask,support follow: |
| 353 | QL_AUDIO_BE_DAI_MASK_CAPTURE_PRI_PCM |
| 354 | QL_AUDIO_BE_DAI_MASK_CAPTURE_VOICE_UL |
| 355 | QL_AUDIO_BE_DAI_MASK_CAPTURE_VOICE_DL |
| 356 | |
| 357 | @retval A_valid_handle Successful execution |
| 358 | @retval QL_AUDIO_INVALID_HANDLE Failed execution.Invalid handle |
| 359 | */ |
| 360 | /*-----------------------------------------------------------------------------------------------*/ |
| 361 | ql_audio_handle_t ql_audio_capture_open(QL_AUDIO_FE_PCM_DEV_E fe_pcm_dev, uint32_t be_dai_mask); |
| 362 | |
| 363 | /*-----------------------------------------------------------------------------------------------*/ |
| 364 | /** |
| 365 | @brief This function prepares for audio file capturing. |
| 366 | |
| 367 | @param[in] handle The handle returned by ql_audio_capture_open(). |
| 368 | @param[in] file_name The name of the audio file to be captured. |
| 369 | @param[in] type The format of the audio data in the audio file. |
| 370 | @param[in] pcm_config Pcm config, including sample rate, channel nums, |
| 371 | defined by ql_audio_pcm_config_t, If it is NULL, the API use defaule value |
| 372 | @param[in] capture_state_cb Callback function to report the current audio capturing state. |
| 373 | @param[in] params Parameters carried by the callback function. |
| 374 | |
| 375 | @retval QL_ERR_OK Successful execution. |
| 376 | @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle. |
| 377 | @retval QL_ERR_INVALID_STATE Failed execution. Invalid state. |
| 378 | @retval Others Failed execution. See ql_type.h for error codes. |
| 379 | |
| 380 | @note Before calling this function, call ql_audio_capture_open() first to obtain a handle. |
| 381 | If an audio file is expected to be captured, call this function first to prepare for the audio file |
| 382 | capturing and then ql_audio_capture_record() to start capturing. |
| 383 | */ |
| 384 | /*-----------------------------------------------------------------------------------------------*/ |
| 385 | int ql_audio_capture_file_prepare(ql_audio_handle_t handle, |
| 386 | const char *file_name, |
| 387 | QL_AUDIO_STREAM_FORMAT_E type, |
| 388 | ql_audio_pcm_config_t *pcm_config, |
| 389 | ql_audio_capture_state_cb_f capture_state_cb, |
| 390 | void *params); |
| 391 | |
| 392 | /*-----------------------------------------------------------------------------------------------*/ |
| 393 | /** |
| 394 | @brief This function prepares for audio stream capturing. |
| 395 | |
| 396 | @param[in] handle This function prepares for audio stream capturing. |
| 397 | @param[in] pcm_config PCM configuration parameters. |
| 398 | @param[in] capture_state_cb Callback function to report the current audio capturing state. |
| 399 | @param[in] params Parameters carried by the callback function. |
| 400 | |
| 401 | @retval QL_ERR_OK Successful execution. |
| 402 | @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle. |
| 403 | @retval QL_ERR_INVALID_STATE Failed execution. Invalid state. |
| 404 | @retval Others Failed execution. See ql_type.h for error codes. |
| 405 | |
| 406 | @note Before calling this function, call ql_audio_capture_open() first to obtain a handle. |
| 407 | If an audio stream is expected to be captured, call this function first to prepare for |
| 408 | the audio stream capturing and then ql_audio_capture_push_stream() to start capturing. |
| 409 | */ |
| 410 | /*-----------------------------------------------------------------------------------------------*/ |
| 411 | int ql_audio_capture_stream_prepare(ql_audio_handle_t handle, |
| 412 | ql_audio_pcm_config_t *pcm_config, |
| 413 | ql_audio_capture_state_cb_f capture_state_cb, |
| 414 | void *params); |
| 415 | |
| 416 | /*-----------------------------------------------------------------------------------------------*/ |
| 417 | /** |
| 418 | @brief This function starts to capture the audio data. |
| 419 | |
| 420 | @param[in] handle The handle returned by ql_audio_capture_open(). |
| 421 | |
| 422 | @retval QL_ERR_OK Successful execution. |
| 423 | @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle. |
| 424 | @retval QL_ERR_INVALID_STATE Failed execution. Invalid state. |
| 425 | @retval Others Failed execution. See ql_type.h for error codes. |
| 426 | |
| 427 | @note Before calling this function, call ql_audio_capture_file_prepare() first to prepare the audio |
| 428 | file to be captured, otherwise the audio data cannot be captured successfully.This function also |
| 429 | supports capturing of audio stream data. In this case, call ql_audio_capture_stream_prepare() |
| 430 | first to prepare the audio stream to be captured, then this function to start capturing, |
| 431 | and finally ql_audio_capture_pull_stream() to capture the audio stream in buffer. |
| 432 | */ |
| 433 | /*-----------------------------------------------------------------------------------------------*/ |
| 434 | int ql_audio_capture_record(ql_audio_handle_t handle); |
| 435 | |
| 436 | /*-----------------------------------------------------------------------------------------------*/ |
| 437 | /** |
| 438 | @brief This function captures the audio stream data to the buffer. |
| 439 | |
| 440 | @param[in] handle The handle returned by ql_audio_capture_open(). |
| 441 | @param[out] stream_buf The buffer that stores the audio stream data to be captured. |
| 442 | @param[in] buf_size Buffer size. Unit: Byte. |
| 443 | |
| 444 | @retval QL_ERR_OK Successful execution. |
| 445 | @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle. |
| 446 | @retval Others Failed execution. See ql_type.h for error codes. |
| 447 | |
| 448 | */ |
| 449 | /*-----------------------------------------------------------------------------------------------*/ |
| 450 | int ql_audio_capture_pull_stream(ql_audio_handle_t handle, void *stream_buf, uint32_t buf_size); |
| 451 | |
| 452 | /*-----------------------------------------------------------------------------------------------*/ |
| 453 | /** |
| 454 | @brief This function pauses the audio capturing. |
| 455 | |
| 456 | @param[in] handle The handle returned by ql_audio_capture_open(). |
| 457 | |
| 458 | @retval QL_ERR_OK Successful execution. |
| 459 | @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle. |
| 460 | @retval Others Failed execution. See ql_type.h for error codes. |
| 461 | */ |
| 462 | /*-----------------------------------------------------------------------------------------------*/ |
| 463 | int ql_audio_capture_pause(ql_audio_handle_t handle); |
| 464 | |
| 465 | /*-----------------------------------------------------------------------------------------------*/ |
| 466 | /** |
| 467 | @brief This function resumes the audio capturing. |
| 468 | |
| 469 | @param[in] handle The handle returned by ql_audio_capture_open(). |
| 470 | |
| 471 | @retval QL_ERR_OK Successful execution. |
| 472 | @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle. |
| 473 | @retval Others Failed execution. See ql_type.h for error codes. |
| 474 | */ |
| 475 | /*-----------------------------------------------------------------------------------------------*/ |
| 476 | int ql_audio_capture_resume(ql_audio_handle_t handle); |
| 477 | |
| 478 | /*-----------------------------------------------------------------------------------------------*/ |
| 479 | /** |
| 480 | @brief This function stops the audio capturing. |
| 481 | |
| 482 | @param[in] handle The handle returned by ql_audio_capture_open(). |
| 483 | |
| 484 | @retval QL_ERR_OK Successful execution. |
| 485 | @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle. |
| 486 | @retval Others Failed execution. See ql_type.h for error codes. |
| 487 | |
| 488 | @note Calling this function will stop audio capturing regardless of whether the capturing is in |
| 489 | progress or paused,and the capturing cannot be resumed after it is stopped. |
| 490 | */ |
| 491 | /*-----------------------------------------------------------------------------------------------*/ |
| 492 | int ql_audio_capture_stop(ql_audio_handle_t handle); |
| 493 | |
| 494 | /*-----------------------------------------------------------------------------------------------*/ |
| 495 | /** |
| 496 | @brief This function closes the audio context for capturing. |
| 497 | |
| 498 | @param[in] handle The handle returned by ql_audio_capture_open(). |
| 499 | |
| 500 | @retval QL_ERR_OK Successful execution. |
| 501 | @retval QL_ERR_INVALID_HANDLE Failed execution. Invalid handle. |
| 502 | @retval Others Failed execution. See ql_type.h for error codes. |
| 503 | @note After audio capturing ends, you must call this function to close the audio context, |
| 504 | otherwise subsequent call of ql_audio_capture_open() will fail. |
| 505 | */ |
| 506 | /*-----------------------------------------------------------------------------------------------*/ |
| 507 | int ql_audio_capture_close(ql_audio_handle_t handle); |
| 508 | |
| 509 | /*-----------------------------------------------------------------------------------------------*/ |
| 510 | /** |
| 511 | @brief This function gets the current audio capturing state. |
| 512 | |
| 513 | @param[in] handle The handle returned by ql_audio_capture_open(). |
| 514 | @param[out] capture_state The current audio capturing state. |
| 515 | */ |
| 516 | /*-----------------------------------------------------------------------------------------------*/ |
| 517 | void ql_audio_capture_get_state(ql_audio_handle_t handle, QL_AUDIO_CAPTURE_STATE_E *capture_state); |
| 518 | |
| 519 | #ifdef __cplusplus |
| 520 | } |
| 521 | #endif |
| 522 | |
| 523 | |
| 524 | #endif |
| 525 | |