mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
bt-a2dp: BT A2DP sink and source selection is now runtime
Earlier they have to be selected at the compile time through sdkconfig. A2DP sink and source application tested with this change. Signed-off-by: Amey Inamdar <amey@espressif.com>
This commit is contained in:
parent
f502e195aa
commit
ae8ed8dad8
@ -120,24 +120,14 @@ config A2DP_ENABLE
|
||||
help
|
||||
Advanced Audio Distrubution Profile
|
||||
|
||||
choice A2DP_ROLE
|
||||
prompt "A2DP ROLE config"
|
||||
depends on A2DP_ENABLE
|
||||
|
||||
config A2DP_SINK_ENABLE
|
||||
bool "SINK"
|
||||
config A2DP_SRC_ENABLE
|
||||
bool "SOURCE"
|
||||
endchoice
|
||||
|
||||
config A2DP_SINK_TASK_STACK_SIZE
|
||||
int "A2DP sink (audio stream decoding) task stack size"
|
||||
depends on A2DP_ENABLE && A2DP_SINK_ENABLE
|
||||
depends on A2DP_ENABLE
|
||||
default 2048
|
||||
|
||||
config A2DP_SOURCE_TASK_STACK_SIZE
|
||||
int "A2DP source (audio stream encoding) task stack size"
|
||||
depends on A2DP_ENABLE && A2DP_SRC_ENABLE
|
||||
depends on A2DP_ENABLE
|
||||
default 2048
|
||||
|
||||
config BT_SPP_ENABLED
|
||||
|
@ -49,9 +49,10 @@ void btc_a2dp_on_init(void)
|
||||
|
||||
void btc_a2dp_on_idle(void)
|
||||
{
|
||||
APPL_TRACE_EVENT("## ON A2DP IDLE ## peer_sep = %d", btc_av_get_peer_sep());
|
||||
APPL_TRACE_EVENT("## ON A2DP IDLE ## peer_sep = %d, service id = %d", btc_av_get_peer_sep(),
|
||||
btc_av_get_service_id());
|
||||
#if BTC_AV_SRC_INCLUDED
|
||||
if (btc_av_get_peer_sep() == AVDT_TSEP_SNK) {
|
||||
if (btc_av_get_peer_sep() == AVDT_TSEP_SNK && btc_av_get_service_id() == BTA_A2DP_SOURCE_SERVICE_ID) {
|
||||
btc_a2dp_source_on_idle();
|
||||
}
|
||||
#endif // BTC_AV_SRC_INCLUDED
|
||||
@ -59,7 +60,7 @@ void btc_a2dp_on_idle(void)
|
||||
bta_av_co_init();
|
||||
|
||||
#if BTC_AV_SINK_INCLUDED
|
||||
if (btc_av_get_peer_sep() == AVDT_TSEP_SRC) {
|
||||
if (btc_av_get_peer_sep() == AVDT_TSEP_SRC && btc_av_get_service_id() == BTA_A2DP_SINK_SERVICE_ID) {
|
||||
btc_a2dp_sink_on_idle();
|
||||
}
|
||||
#endif // BTC_AV_SINK_INCLUDED
|
||||
@ -120,7 +121,7 @@ void btc_a2dp_on_stopped(tBTA_AV_SUSPEND *p_av)
|
||||
{
|
||||
APPL_TRACE_EVENT("## ON A2DP STOPPED ##");
|
||||
#if BTC_AV_SINK_INCLUDED
|
||||
if (btc_av_get_peer_sep() == AVDT_TSEP_SRC) {
|
||||
if (btc_av_get_peer_sep() == AVDT_TSEP_SRC && btc_av_get_service_id() == BTA_A2DP_SINK_SERVICE_ID) {
|
||||
btc_a2dp_sink_on_stopped(p_av);
|
||||
return;
|
||||
}
|
||||
@ -140,7 +141,7 @@ void btc_a2dp_on_suspended(tBTA_AV_SUSPEND *p_av)
|
||||
{
|
||||
APPL_TRACE_EVENT("## ON A2DP SUSPENDED ##");
|
||||
#if BTC_AV_SINK_INCLUDED
|
||||
if (btc_av_get_peer_sep() == AVDT_TSEP_SRC) {
|
||||
if (btc_av_get_peer_sep() == AVDT_TSEP_SRC && btc_av_get_service_id() == BTA_A2DP_SINK_SERVICE_ID) {
|
||||
btc_a2dp_sink_on_suspended(p_av);
|
||||
return;
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ void btc_a2dp_control_command_ack(int status)
|
||||
static void btc_a2dp_datapath_open(void)
|
||||
{
|
||||
#if BTC_AV_SRC_INCLUDED
|
||||
if (btc_av_get_peer_sep() == AVDT_TSEP_SNK) {
|
||||
if (btc_av_get_peer_sep() == AVDT_TSEP_SNK && btc_av_get_service_id() == BTA_A2DP_SOURCE_SERVICE_ID) {
|
||||
/* Start the media task to encode SBC */
|
||||
btc_a2dp_source_start_audio_req();
|
||||
|
||||
@ -147,7 +147,7 @@ void btc_a2dp_control_media_ctrl(esp_a2d_media_ctrl_t ctrl)
|
||||
|
||||
btc_a2dp_dispatch_datapath_evt(BTC_AV_DATAPATH_OPEN_EVT);
|
||||
#if (BTC_AV_SINK_INCLUDED == TRUE)
|
||||
if (btc_av_get_peer_sep() == AVDT_TSEP_SRC) {
|
||||
if (btc_av_get_peer_sep() == AVDT_TSEP_SRC && btc_av_get_service_id() == BTA_A2DP_SINK_SERVICE_ID) {
|
||||
btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_SUCCESS);
|
||||
}
|
||||
#endif
|
||||
@ -160,7 +160,8 @@ void btc_a2dp_control_media_ctrl(esp_a2d_media_ctrl_t ctrl)
|
||||
break;
|
||||
case ESP_A2D_MEDIA_CTRL_STOP:
|
||||
#if BTC_AV_SRC_INCLUDED
|
||||
if (btc_av_get_peer_sep() == AVDT_TSEP_SNK && !btc_a2dp_source_is_streaming()) {
|
||||
if (btc_av_get_peer_sep() == AVDT_TSEP_SNK && !btc_a2dp_source_is_streaming() &&
|
||||
btc_av_get_service_id() == BTA_A2DP_SOURCE_SERVICE_ID) {
|
||||
/* we are already stopped, just ack back*/
|
||||
btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_SUCCESS);
|
||||
break;
|
||||
@ -168,7 +169,7 @@ void btc_a2dp_control_media_ctrl(esp_a2d_media_ctrl_t ctrl)
|
||||
#endif /* BTC_AV_SRC_INCLUDED */
|
||||
btc_dispatch_sm_event(BTC_AV_STOP_STREAM_REQ_EVT, NULL, 0);
|
||||
#if (BTC_AV_SINK_INCLUDED == TRUE)
|
||||
if (btc_av_get_peer_sep() == AVDT_TSEP_SRC) {
|
||||
if (btc_av_get_peer_sep() == AVDT_TSEP_SRC && btc_av_get_service_id() == BTA_A2DP_SINK_SERVICE_ID) {
|
||||
btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_SUCCESS);
|
||||
}
|
||||
#endif
|
||||
|
@ -588,6 +588,7 @@ static void btc_a2dp_sink_handle_inc_media(tBT_SBC_HDR *p_msg)
|
||||
UINT32 sbc_frame_len = p_msg->len - 1;
|
||||
availPcmBytes = 2 * sizeof(pcmData);
|
||||
|
||||
/* XXX: Check if the below check is correct, we are checking for peer to be sink when we are sink */
|
||||
if (btc_av_get_peer_sep() == AVDT_TSEP_SNK || (btc_aa_snk_cb.rx_flush)) {
|
||||
APPL_TRACE_DEBUG(" State Changed happened in this tick ");
|
||||
return;
|
||||
|
@ -72,6 +72,7 @@ typedef enum {
|
||||
******************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
int service_id;
|
||||
tBTA_AV_HNDL bta_handle;
|
||||
bt_bdaddr_t peer_bda;
|
||||
btc_sm_handle_t sm_handle;
|
||||
@ -957,6 +958,7 @@ static void btc_av_event_free_data(btc_sm_event_t event, void *p_data)
|
||||
static bt_status_t btc_av_init(int service_id)
|
||||
{
|
||||
if (btc_av_cb.sm_handle == NULL) {
|
||||
btc_av_cb.service_id = service_id;
|
||||
bool stat = false;
|
||||
if (service_id == BTA_A2DP_SOURCE_SERVICE_ID) {
|
||||
#if BTC_AV_SRC_INCLUDED
|
||||
@ -1265,6 +1267,21 @@ BOOLEAN btc_av_is_connected(void)
|
||||
return ((state == BTC_AV_STATE_OPENED) || (state == BTC_AV_STATE_STARTED));
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Function btc_av_get_service_id
|
||||
*
|
||||
* Description Get the current AV service ID.
|
||||
*
|
||||
* Returns The stream endpoint type: either BTA_A2DP_SOURCE_SERVICE_ID or
|
||||
* BTA_A2DP_SINK_SERVICE_ID.
|
||||
*
|
||||
******************************************************************************/
|
||||
uint8_t btc_av_get_service_id(void)
|
||||
{
|
||||
return btc_av_cb.service_id;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Function btc_av_get_peer_sep
|
||||
|
@ -203,6 +203,18 @@ BOOLEAN btc_av_is_peer_edr(void);
|
||||
********************************************************************************/
|
||||
void btc_av_clear_remote_suspend_flag(void);
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Function btc_av_get_service_id
|
||||
*
|
||||
* Description Get the current AV service ID.
|
||||
*
|
||||
* Returns The stream endpoint type: either BTA_A2DP_SOURCE_SERVICE_ID or
|
||||
* BTA_A2DP_SINK_SERVICE_ID.
|
||||
*
|
||||
******************************************************************************/
|
||||
uint8_t btc_av_get_service_id(void);
|
||||
|
||||
#endif ///BTC_AV_INCLUDED == TRUE
|
||||
|
||||
#endif /* __BTC_AV_H__ */
|
||||
|
@ -60,18 +60,12 @@
|
||||
#define AVCT_INCLUDED TRUE
|
||||
#define AVRC_INCLUDED TRUE
|
||||
#define BTC_AV_INCLUDED TRUE
|
||||
#endif /* CONFIG_A2DP_ENABLE */
|
||||
|
||||
#if CONFIG_A2DP_SINK_ENABLE
|
||||
#define BTA_AV_SINK_INCLUDED TRUE
|
||||
#define BTC_AV_SINK_INCLUDED TRUE
|
||||
#define SBC_DEC_INCLUDED TRUE
|
||||
#endif /* CONFIG_A2DP_SINK_ENABLE */
|
||||
|
||||
#if CONFIG_A2DP_SRC_ENABLE
|
||||
#define BTC_AV_SRC_INCLUDED TRUE
|
||||
#define SBC_ENC_INCLUDED TRUE
|
||||
#endif /* CONFIG_A2DP_SRC_ENABLE */
|
||||
#endif /* CONFIG_A2DP_ENABLE */
|
||||
|
||||
#if CONFIG_BT_SPP_ENABLED
|
||||
#define RFCOMM_INCLUDED TRUE
|
||||
|
@ -4,8 +4,6 @@ CONFIG_BT_ENABLED=y
|
||||
CONFIG_BLUEDROID_ENABLED=y
|
||||
CONFIG_CLASSIC_BT_ENABLED=y
|
||||
CONFIG_A2DP_ENABLE=y
|
||||
CONFIG_A2DP_SINK_ENABLE=y
|
||||
CONFIG_A2DP_SRC_ENABLE=
|
||||
CONFIG_BT_SPP_ENABLED=
|
||||
CONFIG_GATTS_ENABLE=
|
||||
CONFIG_GATTC_ENABLE=
|
||||
|
@ -4,8 +4,6 @@ CONFIG_BT_ENABLED=y
|
||||
CONFIG_BLUEDROID_ENABLED=y
|
||||
CONFIG_CLASSIC_BT_ENABLED=y
|
||||
CONFIG_A2DP_ENABLE=y
|
||||
CONFIG_A2DP_SINK_ENABLE=
|
||||
CONFIG_A2DP_SRC_ENABLE=y
|
||||
CONFIG_BT_SPP_ENABLED=
|
||||
CONFIG_GATTS_ENABLE=
|
||||
CONFIG_GATTC_ENABLE=
|
||||
|
Loading…
Reference in New Issue
Block a user