MT2523 API Reference  LinkIt SDK v4
bt_codec.h
1 /* Copyright Statement:
2  *
3  * (C) 2005-2016 MediaTek Inc. All rights reserved.
4  *
5  * This software/firmware and related documentation ("MediaTek Software") are
6  * protected under relevant copyright laws. The information contained herein
7  * is confidential and proprietary to MediaTek Inc. ("MediaTek") and/or its licensors.
8  * Without the prior written permission of MediaTek and/or its licensors,
9  * any reproduction, modification, use or disclosure of MediaTek Software,
10  * and information contained herein, in whole or in part, shall be strictly prohibited.
11  * You may only use, reproduce, modify, or distribute (as applicable) MediaTek Software
12  * if you have agreed to and been bound by the applicable license agreement with
13  * MediaTek ("License Agreement") and been granted explicit permission to do so within
14  * the License Agreement ("Permitted User"). If you are not a Permitted User,
15  * please cease any access or use of MediaTek Software immediately.
16  * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
17  * THAT MEDIATEK SOFTWARE RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES
18  * ARE PROVIDED TO RECEIVER ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL
19  * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
21  * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
22  * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
23  * SUPPLIED WITH MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
24  * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
25  * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
26  * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
27  * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
28  * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
29  * CUMULATIVE LIABILITY WITH RESPECT TO MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
30  * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE MEDIATEK SOFTWARE AT ISSUE,
31  * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
32  * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
33  */
34 
35 #ifndef __BT_CODEC_H__
36 #define __BT_CODEC_H__
37 
191 #ifdef __cplusplus
192 extern "C" {
193 #endif
194 
195 #include <stdint.h>
196 #include <stdbool.h>
197 #include "bt_hfp.h"
198 #include "bt_a2dp.h"
199 
206 #define BT_CODEC_MEDIA_EVENT_START (120)
209 typedef enum {
216 
217 
219 typedef enum {
229 
230 
232 typedef enum {
239 
241 typedef enum {
245 
246 
247 typedef enum {
252 
253 
264 typedef enum {
269 
280 typedef struct {
281  uint8_t *buffer_base;
282  int32_t buffer_size;
283  int32_t write;
284  int32_t read;
285  void *param;
287 
289 typedef int32_t (*bt_codec_get_data)(volatile uint16_t *buf, uint32_t len);
290 
292 typedef int32_t (*bt_codec_get_data_count)(void);
293 
294 
296 typedef struct _bt_media_handle_t {
299  bool underflow;
300  bool waiting;
301  uint16_t audio_id;
303  void (*handler)(struct _bt_media_handle_t *handle, bt_codec_media_event_t event_id);
304  void (*set_buffer)(struct _bt_media_handle_t *handle, uint8_t *buffer, uint32_t length);
307  void (*get_write_buffer)(struct _bt_media_handle_t *handle, uint8_t **buffer, uint32_t *length);
308  void (*get_read_buffer)(struct _bt_media_handle_t *handle, uint8_t **buffer, uint32_t *length);
309  void (*write_data_done)(struct _bt_media_handle_t *handle, uint32_t length);
310  void (*finish_write_data)(struct _bt_media_handle_t *handle);
311  void (*reset_share_buffer)(struct _bt_media_handle_t *handle);
312  void (*read_data_done)(struct _bt_media_handle_t *handle, uint32_t length);
313  int32_t (*get_free_space)(struct _bt_media_handle_t *handle);
314  int32_t (*get_data_count)(struct _bt_media_handle_t *handle);
322 
323 
327 typedef struct {
328  uint8_t min_bit_pool;
329  uint8_t max_bit_pool;
330  uint8_t block_length;
331  uint8_t subband_num;
332  uint8_t alloc_method;
333  uint8_t sample_rate;
334  uint8_t channel_mode;
336 
340 typedef struct {
341  bool vbr;
342  uint8_t object_type;
343  uint8_t channels;
344  uint16_t sample_rate;
345  uint32_t bit_rate;
347 
351 typedef union {
354 } bt_codec_t;
355 
359 typedef struct {
363 
364 
366 typedef struct {
370 
372 typedef struct {
375 
377 typedef struct {
378  uint32_t sample_count;
379  uint32_t sampling_rate;
381 
383 typedef struct {
384  uint32_t sample_count;
385  uint32_t byte_count;
387 
389 typedef struct {
390  uint8_t *buffer;
391  uint32_t byte_count;
393 
400 
401 
409 
410 
418 
425 
437 
444 
445 
446 
456 
457 
466 
467 
468 
474 
475 
483 
484 
485 
493 bt_codec_media_status_t bt_codec_hfp_read_stream_in(void *buffer, uint32_t sample_count);
494 
495 
504 
510 
518 
525 
533 
540 
548 
555 
563 
571 
580 
589 
597 
605 
613 bt_codec_media_status_t bt_codec_a2dp_aws_get_audio_latency(bt_media_handle_t *handle, uint32_t sampling_rate, uint32_t *latency_us);
614 
615 
622 
628 
629 #ifdef __cplusplus
630 }
631 #endif
632 
639 #endif /* __BT_CODEC_H__ */
640 
bt_codec_aac_t aac
AAC codec.
Definition: bt_codec.h:353
bt_codec_media_status_t bt_codec_hfp_unregister_mix_stream_out_data_callback(void)
Unregister the callback function for mix stream out data.
Invalid parameters.
Definition: bt_codec.h:236
uint8_t channel_mode
b0: joint stereo, b1: stereo, b2: dual channel, b3: mono.
Definition: bt_codec.h:334
void(* bt_codec_a2dp_callback_t)(bt_media_handle_t *handle, bt_codec_media_event_t event_id)
This defines the A2DP codec callback function prototype.
Definition: bt_codec.h:399
The stream out and stream in path of HFP is to/from internal ABB.
Definition: bt_codec.h:265
void(* set_buffer)(struct _bt_media_handle_t *handle, uint8_t *buffer, uint32_t length)
Set the shared buffer for bitstream.
Definition: bt_codec.h:304
The Bluetooth codec is terminated.
Definition: bt_codec.h:225
bt_codec_media_status_t bt_codec_a2dp_close(bt_media_handle_t *handle)
This function closes the A2DP audio codec.
uint8_t bt_a2dp_role_t
The type of A2DP role.
Definition: bt_a2dp.h:229
Maintain origin stream out.
Definition: bt_codec.h:248
void * param
Extended parameter or information.
Definition: bt_codec.h:285
bt_codec_media_status_t bt_codec_hfp_register_mix_stream_out_data_callback(bt_codec_hfp_mix_stream_out_data_callback_t callback, void *user_data)
Register the callback function for mixing stream out data.
uint8_t * buffer
Buffer pointer.
Definition: bt_codec.h:390
bt_codec_get_data directly_access_dsp_function
Set function to access DSP buffer directly.
Definition: bt_codec.h:315
uint8_t subband_num
b0: 8, b1: 4.
Definition: bt_codec.h:331
int32_t(* bt_codec_get_data)(volatile uint16_t *buf, uint32_t len)
A2DP direct access to DSP buffer function type.
Definition: bt_codec.h:289
bt_codec_media_status_t bt_codec_hfp_get_mix_stream_out_sample_count(uint32_t *sample_count)
Query the sample_count of mix stream out buffer.
uint8_t bt_hfp_audio_codec_type_t
This structure defines the HFP codec type.
Definition: bt_hfp.h:257
Successful.
Definition: bt_codec.h:234
int32_t buffer_size
Size of the ring buffer.
Definition: bt_codec.h:282
uint8_t channels
b0: 2, b1: 1.
Definition: bt_codec.h:343
uint8_t max_bit_pool
The maximum bit pool.
Definition: bt_codec.h:329
bt_codec_media_status_t(* process)(struct _bt_media_handle_t *handle, bt_codec_media_event_t event_id)
The Bluetooth codec process function.
Definition: bt_codec.h:319
The Bluetooth codec is ready to play the media.
Definition: bt_codec.h:211
The A2DP audio codec bitstream information structure.
Definition: bt_codec.h:383
void(* handler)(struct _bt_media_handle_t *handle, bt_codec_media_event_t event_id)
The Bluetooth codec handler.
Definition: bt_codec.h:303
Successful.
Definition: bt_codec.h:221
bt_codec_media_status_t bt_codec_hfp_unregister_get_stream_in_data_callback(void)
Unregister the callback function for getting stream in data.
int32_t(* get_data_count)(struct _bt_media_handle_t *handle)
Get the available data amount of the shared buffer.
Definition: bt_codec.h:314
void(* write_data_done)(struct _bt_media_handle_t *handle, uint32_t length)
Update the write pointer to the shared buffer.
Definition: bt_codec.h:309
bt_media_handle_t * bt_codec_hfp_open(bt_codec_hfp_callback_t callback, const bt_codec_hfp_audio_t *param)
This function opens the HFP audio codec.
The base of the status.
Definition: bt_codec.h:233
bt_hfp_audio_codec_type_t type
1: CVSD, 2: mSBC
Definition: bt_codec.h:373
bt_codec_hfp_device_path_t
bt codec hfp device path enum
Definition: bt_codec.h:264
bt_codec_media_status_t bt_codec_a2dp_aws_set_flag(bt_media_handle_t *handle, bool flag)
This function sets the advanced wireless stereo flag.
bool vbr
Indicates if VBR is supported or not.
Definition: bt_codec.h:341
bt_codec_state_t
Bluetooth codec state.
Definition: bt_codec.h:209
bt_codec_media_status_t bt_codec_hfp_get_stream_in_sample_count(uint32_t *sample_count)
Query the sample_count of stream in buffer.
bt_codec_media_status_t bt_codec_a2dp_aws_fill_silence_frame(bt_media_handle_t *handle, bt_codec_a2dp_buffer_t *data, uint32_t frame_count)
This function fills the advanced wireless stereo silence frames to target data buffer.
void(* get_write_buffer)(struct _bt_media_handle_t *handle, uint8_t **buffer, uint32_t *length)
Get the available length to write into a shared buffer and a pointer to the shared buffer...
Definition: bt_codec.h:307
bt_codec_sbc_t sbc
SBC codec.
Definition: bt_codec.h:352
uint8_t sample_rate
b0: 48000, b1: 44100, b2: 32000, b3: 16000.
Definition: bt_codec.h:333
bt_codec_capability_t codec_cap
The capabilities of Bluetooth codec.
Definition: bt_codec.h:367
This structure defines the A2DP codec capability.
Definition: bt_codec.h:359
uint8_t min_bit_pool
The minimum bit pool.
Definition: bt_codec.h:328
bt_a2dp_codec_type_t type
Codec type.
Definition: bt_codec.h:360
The Bluetooth codec AWS clock skew is compensating.
Definition: bt_codec.h:243
uint32_t sample_count
One pair of L / R counts as one sample.
Definition: bt_codec.h:378
bt_codec_media_status_t(* stop)(struct _bt_media_handle_t *handle)
The Bluetooth codec stop function.
Definition: bt_codec.h:320
#define BT_CODEC_MEDIA_EVENT_START
Defines the codec media event.
Definition: bt_codec.h:206
The Bluetooth codec reported an error.
Definition: bt_codec.h:213
This structure defines the AAC codec details.
Definition: bt_codec.h:340
bool waiting
The Bluetooth codec is waiting to fill data.
Definition: bt_codec.h:300
int32_t write
Index of the ring buffer to write the data.
Definition: bt_codec.h:283
void(* get_read_buffer)(struct _bt_media_handle_t *handle, uint8_t **buffer, uint32_t *length)
Get the available length to read from a shared buffer and a pointer to the shared buffer...
Definition: bt_codec.h:308
uint8_t bt_a2dp_codec_type_t
The type of A2DP codec.
Definition: bt_a2dp.h:219
bt_codec_media_hfp_mix_stream_out_method_t
Definition: bt_codec.h:247
This structure defines the A2DP codec.
Definition: bt_codec.h:366
uint32_t sampling_rate
Sampling rate, unit: Hz.
Definition: bt_codec.h:379
Advanced wireless stereo underflow-checking mechanism is triggered.
Definition: bt_codec.h:226
bt_codec_media_status_t
This structure defines the Bluetooth codec API return status.
Definition: bt_codec.h:232
Advanced wireless stereo clock-skew-checking mechanism is triggered.
Definition: bt_codec.h:227
uint32_t bit_rate
Constant/peak bits per second in 23 bit UiMsbf.
Definition: bt_codec.h:345
bt_codec_media_status_t(* play)(struct _bt_media_handle_t *handle)
The Bluetooth codec play function.
Definition: bt_codec.h:318
The Bluetooth codec AWS clock skew is inactive.
Definition: bt_codec.h:242
void(* set_get_data_function)(struct _bt_media_handle_t *handle, bt_codec_get_data func)
Set the callback function for bitstream.
Definition: bt_codec.h:305
uint8_t alloc_method
b0: loudness, b1: SNR.
Definition: bt_codec.h:332
uint8_t object_type
b4: M4-scalable, b5: M4-LTP, b6: M4-LC, b7: M2-LC.
Definition: bt_codec.h:342
The end of the status.
Definition: bt_codec.h:237
A2DP audio handle structure type.
Definition: bt_codec.h:296
bt_codec_t codec
Codec information.
Definition: bt_codec.h:361
bt_a2dp_role_t role
The Bluetooth codec roles.
Definition: bt_codec.h:368
Bitstreaming request from the user.
Definition: bt_codec.h:223
int32_t(* bt_codec_get_data_count)(void)
A2DP get data count function type.
Definition: bt_codec.h:292
The stream out and stream in path of HFP is from MASTER I2S.Note stream out also can to internal ABB...
Definition: bt_codec.h:266
bt_codec_media_status_t bt_codec_hfp_mix_stream_out(bt_codec_media_hfp_mix_stream_out_method_t mix_method, void *buffer, uint32_t sample_count)
Mix a tone to the stream out tone.
Not support now.
Definition: bt_codec.h:267
Weighted mean.
Definition: bt_codec.h:250
struct _bt_media_handle_t bt_media_handle_t
A2DP audio handle structure type.
bt_codec_media_status_t bt_codec_a2dp_set_sw_aac_flag(bool flag)
This function sets the SW AAC DECODER for BT A2DP.
uint16_t audio_id
The audio ID of the Bluetooth codec.
Definition: bt_codec.h:301
bt_codec_get_data_count get_data_count_function
Set function to get available data amount of the uplayer total buffer size.
Definition: bt_codec.h:316
int32_t(* get_free_space)(struct _bt_media_handle_t *handle)
Get the free space length available in the shared buffer.
Definition: bt_codec.h:313
void(* bt_codec_hfp_get_stream_in_data_callback_t)(bt_codec_media_event_t event, void *user_data)
This defines the HFP codec hfp mix stream in callback function prototype.
Definition: bt_codec.h:417
The bitstreaming is underflow and the codec output is on silent.
Definition: bt_codec.h:222
void(* bt_codec_hfp_mix_stream_out_data_callback_t)(bt_codec_media_event_t event, void *user_data)
This defines the HFP codec hfp mix stream out callback function prototype.
Definition: bt_codec.h:408
void(* reset_share_buffer)(struct _bt_media_handle_t *handle)
Reset the shared buffer&#39;s information.
Definition: bt_codec.h:311
bt_codec_media_status_t bt_codec_a2dp_aws_get_silence_frame_information(bt_media_handle_t *handle, bt_codec_a2dp_bitstream_t *information)
This function gets the advanced wireless stereo silence frame information for one silence frame...
bt_audio_buffer_t buffer_info
The shared buffer information for the Bluetooth codec.
Definition: bt_codec.h:298
bt_codec_media_status_t bt_codec_a2dp_aws_set_clock_skew_compensation_value(bt_media_handle_t *handle, int32_t sample_count)
This function sets the advanced wireless stereo clock skew compensation value.
int32_t read
Index of the ring buffer to read the data.
Definition: bt_codec.h:284
bt_codec_media_status_t bt_codec_a2dp_aws_get_consumed_data_count(bt_media_handle_t *handle, bt_codec_a2dp_data_count_t *information)
This function gets the advanced wireless stereo consumed data count.
The Bluetooth codec is inactive.
Definition: bt_codec.h:210
bt_codec_media_event_t
This structure defines the Bluetooth codec media events.
Definition: bt_codec.h:219
bt_codec_media_status_t bt_codec_hfp_set_device_path(bt_codec_hfp_device_path_t device_path)
This function sets the HFP device path.
bool bt_codec_a2dp_get_sw_aac_flag(void)
This function gets the SW AAC DECODER for BT A2DP.
The start of the Media events.
Definition: bt_codec.h:220
This union defines the A2DP codec.
Definition: bt_codec.h:351
uint8_t * buffer_base
Pointer to the ring buffer.
Definition: bt_codec.h:281
bt_codec_media_status_t bt_codec_hfp_close(bt_media_handle_t *handle)
This function closes the HFP codec.
This structure defines the SBC codec details.
Definition: bt_codec.h:327
bt_codec_media_status_t bt_codec_a2dp_aws_parse_data_information(bt_media_handle_t *handle, bt_codec_a2dp_buffer_t *data, bt_codec_a2dp_bitstream_t *information)
This function parses the advanced wireless stereo packet data information.
bt_codec_aws_clock_skew_status_t
Bluetooth codec AWS clock skew status.
Definition: bt_codec.h:241
bt_codec_media_status_t bt_codec_hfp_register_get_stream_in_data_callback(bt_codec_hfp_get_stream_in_data_callback_t callback, void *user_data)
Register the callback function for get stream in data.
The A2DP audio codec buffer information structure.
Definition: bt_codec.h:389
This structure defines the HFP codec.
Definition: bt_codec.h:372
Replace origin stream out.
Definition: bt_codec.h:249
The Bluetooth codec is in a playing state.
Definition: bt_codec.h:212
Bitstreaming notification to the user.
Definition: bt_codec.h:224
bt_media_handle_t * bt_codec_a2dp_open(bt_codec_a2dp_callback_t callback, const bt_codec_a2dp_audio_t *param)
This function opens the A2DP audio codec.
bool underflow
The Bluetooth codec data underflow occurred.
Definition: bt_codec.h:299
void(* finish_write_data)(struct _bt_media_handle_t *handle)
Indicate the last data transfer.
Definition: bt_codec.h:310
void(* read_data_done)(struct _bt_media_handle_t *handle, uint32_t length)
Update the read pointer to the shared buffer.
Definition: bt_codec.h:312
uint32_t sample_count
One pair of L / R counts as one sample.
Definition: bt_codec.h:384
uint16_t sample_rate
b0~b11: 96000,88200,64000,48000,44100,32000,24000,22050,16000,12000,11025,8000.
Definition: bt_codec.h:344
void(* set_get_data_count_function)(struct _bt_media_handle_t *handle, bt_codec_get_data_count func)
Set the callback function for bitstream.
Definition: bt_codec.h:306
Error.
Definition: bt_codec.h:235
uint32_t byte_count
Byte count.
Definition: bt_codec.h:385
uint8_t block_length
b0: 16, b1: 12, b2: 8, b3: 4.
Definition: bt_codec.h:330
The Bluetooth codec has stopped.
Definition: bt_codec.h:214
void(* bt_codec_hfp_callback_t)(bt_media_handle_t *handle, bt_codec_media_event_t event_id)
This defines the HFP codec callback function prototype.
Definition: bt_codec.h:424
bt_codec_media_status_t bt_codec_a2dp_aws_set_initial_sync(bt_media_handle_t *handle)
This function sets the advanced wireless stereo initial synchronization.
This structure defines the shared buffer structure.
Definition: bt_codec.h:280
uint32_t byte_count
Buffer byte count.
Definition: bt_codec.h:391
bt_codec_media_status_t bt_codec_hfp_read_stream_in(void *buffer, uint32_t sample_count)
Recieve data from stream in.
The A2DP audio codec data count structure.
Definition: bt_codec.h:377
bt_codec_state_t state
The Bluetooth codec state.
Definition: bt_codec.h:297
bt_codec_media_status_t bt_codec_a2dp_aws_get_clock_skew_status(bt_media_handle_t *handle, bt_codec_aws_clock_skew_status_t *status)
This function gets the advanced wireless stereo clock skew status.
bt_codec_media_status_t bt_codec_a2dp_aws_get_audio_latency(bt_media_handle_t *handle, uint32_t sampling_rate, uint32_t *latency_us)
This function gets the advanced wireless stereo audio latency.