2016-11-02 11:40:46 +00:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004-2012 Broadcom Corporation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* This file contains action functions for advanced audio/video stream
|
|
|
|
* state machine. these functions are shared by both audio and video
|
|
|
|
* streams.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
2018-04-08 04:10:50 +00:00
|
|
|
#include "common/bt_target.h"
|
2016-11-02 11:40:46 +00:00
|
|
|
#if defined(BTA_AV_INCLUDED) && (BTA_AV_INCLUDED == TRUE)
|
|
|
|
|
|
|
|
// #include <assert.h>
|
2018-04-08 04:10:50 +00:00
|
|
|
#include "common/bt_trace.h"
|
2016-11-02 11:40:46 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2018-04-08 04:10:50 +00:00
|
|
|
#include "osi/allocator.h"
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
#include "bta_av_int.h"
|
2018-04-08 04:10:50 +00:00
|
|
|
#include "stack/avdt_api.h"
|
|
|
|
#include "bta/utl.h"
|
|
|
|
#include "stack/l2c_api.h"
|
|
|
|
#include "stack/l2cdefs.h"
|
2016-11-02 11:40:46 +00:00
|
|
|
#if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE)
|
2018-04-08 04:10:50 +00:00
|
|
|
#include "bta/bta_ar_api.h"
|
2016-11-02 11:40:46 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
** Constants
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/* the delay time in milliseconds to start service discovery on AVRCP */
|
|
|
|
#ifndef BTA_AV_RC_DISC_TIME_VAL
|
|
|
|
#define BTA_AV_RC_DISC_TIME_VAL 3500
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* the timer in milliseconds to guard against link busy and AVDT_CloseReq failed to be sent */
|
|
|
|
#ifndef BTA_AV_CLOSE_REQ_TIME_VAL
|
|
|
|
#define BTA_AV_CLOSE_REQ_TIME_VAL 4000
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* number to retry on reconfigure failure - some headsets requirs this number to be more than 1 */
|
|
|
|
#ifndef BTA_AV_RECONFIG_RETRY
|
|
|
|
#define BTA_AV_RECONFIG_RETRY 6
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void bta_av_st_rc_timer(tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
|
|
|
|
|
|
|
|
/* state machine states */
|
2017-03-17 14:46:49 +00:00
|
|
|
enum {
|
2016-11-02 11:40:46 +00:00
|
|
|
BTA_AV_INIT_SST,
|
|
|
|
BTA_AV_INCOMING_SST,
|
|
|
|
BTA_AV_OPENING_SST,
|
|
|
|
BTA_AV_OPEN_SST,
|
|
|
|
BTA_AV_RCFG_SST,
|
|
|
|
BTA_AV_CLOSING_SST
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* the call out functions for audio stream */
|
2016-11-04 10:33:57 +00:00
|
|
|
/* const tBTA_AV_CO_FUNCTS bta_av_a2d_cos =
|
2016-11-02 11:40:46 +00:00
|
|
|
{
|
|
|
|
bta_av_co_audio_init,
|
|
|
|
bta_av_co_audio_disc_res,
|
|
|
|
bta_av_co_audio_getconfig,
|
|
|
|
bta_av_co_audio_setconfig,
|
|
|
|
bta_av_co_audio_open,
|
|
|
|
bta_av_co_audio_close,
|
|
|
|
bta_av_co_audio_start,
|
|
|
|
bta_av_co_audio_stop,
|
|
|
|
bta_av_co_audio_src_data_path,
|
|
|
|
bta_av_co_audio_delay
|
|
|
|
};
|
2016-11-04 10:33:57 +00:00
|
|
|
*/
|
|
|
|
tBTA_AV_CO_FUNCTS *p_bta_av_a2d_cos = NULL;
|
|
|
|
|
|
|
|
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
/* ssm action functions for audio stream */
|
2017-03-17 14:46:49 +00:00
|
|
|
const tBTA_AV_SACT bta_av_a2d_action[] = {
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_av_do_disc_a2d, /* BTA_AV_DO_DISC */
|
|
|
|
bta_av_cleanup, /* BTA_AV_CLEANUP */
|
|
|
|
bta_av_free_sdb, /* BTA_AV_FREE_SDB */
|
|
|
|
bta_av_config_ind, /* BTA_AV_CONFIG_IND */
|
|
|
|
bta_av_disconnect_req, /* BTA_AV_DISCONNECT_REQ */
|
|
|
|
bta_av_security_req, /* BTA_AV_SECURITY_REQ */
|
|
|
|
bta_av_security_rsp, /* BTA_AV_SECURITY_RSP */
|
|
|
|
bta_av_setconfig_rsp, /* BTA_AV_SETCONFIG_RSP */
|
|
|
|
bta_av_st_rc_timer, /* BTA_AV_ST_RC_TIMER */
|
|
|
|
bta_av_str_opened, /* BTA_AV_STR_OPENED */
|
|
|
|
bta_av_security_ind, /* BTA_AV_SECURITY_IND */
|
|
|
|
bta_av_security_cfm, /* BTA_AV_SECURITY_CFM */
|
|
|
|
bta_av_do_close, /* BTA_AV_DO_CLOSE */
|
|
|
|
bta_av_connect_req, /* BTA_AV_CONNECT_REQ */
|
|
|
|
bta_av_sdp_failed, /* BTA_AV_SDP_FAILED */
|
|
|
|
bta_av_disc_results, /* BTA_AV_DISC_RESULTS */
|
|
|
|
bta_av_disc_res_as_acp, /* BTA_AV_DISC_RES_AS_ACP */
|
|
|
|
bta_av_open_failed, /* BTA_AV_OPEN_FAILED */
|
|
|
|
bta_av_getcap_results, /* BTA_AV_GETCAP_RESULTS */
|
|
|
|
bta_av_setconfig_rej, /* BTA_AV_SETCONFIG_REJ */
|
|
|
|
bta_av_discover_req, /* BTA_AV_DISCOVER_REQ */
|
|
|
|
bta_av_conn_failed, /* BTA_AV_CONN_FAILED */
|
|
|
|
bta_av_do_start, /* BTA_AV_DO_START */
|
|
|
|
bta_av_str_stopped, /* BTA_AV_STR_STOPPED */
|
|
|
|
bta_av_reconfig, /* BTA_AV_RECONFIG */
|
|
|
|
bta_av_data_path, /* BTA_AV_DATA_PATH */
|
|
|
|
bta_av_start_ok, /* BTA_AV_START_OK */
|
|
|
|
bta_av_start_failed, /* BTA_AV_START_FAILED */
|
|
|
|
bta_av_str_closed, /* BTA_AV_STR_CLOSED */
|
|
|
|
bta_av_clr_cong, /* BTA_AV_CLR_CONG */
|
|
|
|
bta_av_suspend_cfm, /* BTA_AV_SUSPEND_CFM */
|
|
|
|
bta_av_rcfg_str_ok, /* BTA_AV_RCFG_STR_OK */
|
|
|
|
bta_av_rcfg_failed, /* BTA_AV_RCFG_FAILED */
|
|
|
|
bta_av_rcfg_connect, /* BTA_AV_RCFG_CONNECT */
|
|
|
|
bta_av_rcfg_discntd, /* BTA_AV_RCFG_DISCNTD */
|
|
|
|
bta_av_suspend_cont, /* BTA_AV_SUSPEND_CONT */
|
|
|
|
bta_av_rcfg_cfm, /* BTA_AV_RCFG_CFM */
|
|
|
|
bta_av_rcfg_open, /* BTA_AV_RCFG_OPEN */
|
|
|
|
bta_av_security_rej, /* BTA_AV_SECURITY_REJ */
|
|
|
|
bta_av_open_rc, /* BTA_AV_OPEN_RC */
|
|
|
|
bta_av_chk_2nd_start, /* BTA_AV_CHK_2ND_START */
|
|
|
|
bta_av_save_caps, /* BTA_AV_SAVE_CAPS */
|
|
|
|
bta_av_set_use_rc, /* BTA_AV_SET_USE_RC */
|
|
|
|
bta_av_cco_close, /* BTA_AV_CCO_CLOSE */
|
|
|
|
bta_av_switch_role, /* BTA_AV_SWITCH_ROLE */
|
|
|
|
bta_av_role_res, /* BTA_AV_ROLE_RES */
|
|
|
|
bta_av_delay_co, /* BTA_AV_DELAY_CO */
|
|
|
|
bta_av_open_at_inc, /* BTA_AV_OPEN_AT_INC */
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* these tables translate AVDT events to SSM events */
|
|
|
|
static const UINT16 bta_av_stream_evt_ok[] = {
|
|
|
|
BTA_AV_STR_DISC_OK_EVT, /* AVDT_DISCOVER_CFM_EVT */
|
|
|
|
BTA_AV_STR_GETCAP_OK_EVT, /* AVDT_GETCAP_CFM_EVT */
|
|
|
|
BTA_AV_STR_OPEN_OK_EVT, /* AVDT_OPEN_CFM_EVT */
|
|
|
|
BTA_AV_STR_OPEN_OK_EVT, /* AVDT_OPEN_IND_EVT */
|
|
|
|
BTA_AV_STR_CONFIG_IND_EVT, /* AVDT_CONFIG_IND_EVT */
|
|
|
|
BTA_AV_STR_START_OK_EVT, /* AVDT_START_CFM_EVT */
|
|
|
|
BTA_AV_STR_START_OK_EVT, /* AVDT_START_IND_EVT */
|
|
|
|
BTA_AV_STR_SUSPEND_CFM_EVT, /* AVDT_SUSPEND_CFM_EVT */
|
|
|
|
BTA_AV_STR_SUSPEND_CFM_EVT, /* AVDT_SUSPEND_IND_EVT */
|
|
|
|
BTA_AV_STR_CLOSE_EVT, /* AVDT_CLOSE_CFM_EVT */
|
|
|
|
BTA_AV_STR_CLOSE_EVT, /* AVDT_CLOSE_IND_EVT */
|
|
|
|
BTA_AV_STR_RECONFIG_CFM_EVT, /* AVDT_RECONFIG_CFM_EVT */
|
|
|
|
0, /* AVDT_RECONFIG_IND_EVT */
|
|
|
|
BTA_AV_STR_SECURITY_CFM_EVT, /* AVDT_SECURITY_CFM_EVT */
|
|
|
|
BTA_AV_STR_SECURITY_IND_EVT, /* AVDT_SECURITY_IND_EVT */
|
|
|
|
BTA_AV_STR_WRITE_CFM_EVT, /* AVDT_WRITE_CFM_EVT */
|
|
|
|
BTA_AV_AVDT_CONNECT_EVT, /* AVDT_CONNECT_IND_EVT */
|
|
|
|
BTA_AV_AVDT_DISCONNECT_EVT, /* AVDT_DISCONNECT_IND_EVT */
|
|
|
|
#if (AVDT_REPORTING == TRUE)
|
|
|
|
BTA_AV_AVDT_RPT_CONN_EVT, /* AVDT_REPORT_CONN_EVT */
|
|
|
|
BTA_AV_AVDT_RPT_CONN_EVT, /* AVDT_REPORT_DISCONN_EVT */
|
|
|
|
#endif
|
|
|
|
BTA_AV_AVDT_DELAY_RPT_EVT, /* AVDT_DELAY_REPORT_EVT */
|
|
|
|
0 /* AVDT_DELAY_REPORT_CFM_EVT */
|
|
|
|
};
|
|
|
|
|
|
|
|
static const UINT16 bta_av_stream_evt_fail[] = {
|
|
|
|
BTA_AV_STR_DISC_FAIL_EVT, /* AVDT_DISCOVER_CFM_EVT */
|
|
|
|
BTA_AV_STR_GETCAP_FAIL_EVT, /* AVDT_GETCAP_CFM_EVT */
|
|
|
|
BTA_AV_STR_OPEN_FAIL_EVT, /* AVDT_OPEN_CFM_EVT */
|
|
|
|
BTA_AV_STR_OPEN_OK_EVT, /* AVDT_OPEN_IND_EVT */
|
|
|
|
BTA_AV_STR_CONFIG_IND_EVT, /* AVDT_CONFIG_IND_EVT */
|
|
|
|
BTA_AV_STR_START_FAIL_EVT, /* AVDT_START_CFM_EVT */
|
|
|
|
BTA_AV_STR_START_OK_EVT, /* AVDT_START_IND_EVT */
|
|
|
|
BTA_AV_STR_SUSPEND_CFM_EVT, /* AVDT_SUSPEND_CFM_EVT */
|
|
|
|
BTA_AV_STR_SUSPEND_CFM_EVT, /* AVDT_SUSPEND_IND_EVT */
|
|
|
|
BTA_AV_STR_CLOSE_EVT, /* AVDT_CLOSE_CFM_EVT */
|
|
|
|
BTA_AV_STR_CLOSE_EVT, /* AVDT_CLOSE_IND_EVT */
|
|
|
|
BTA_AV_STR_RECONFIG_CFM_EVT, /* AVDT_RECONFIG_CFM_EVT */
|
|
|
|
0, /* AVDT_RECONFIG_IND_EVT */
|
|
|
|
BTA_AV_STR_SECURITY_CFM_EVT, /* AVDT_SECURITY_CFM_EVT */
|
|
|
|
BTA_AV_STR_SECURITY_IND_EVT, /* AVDT_SECURITY_IND_EVT */
|
|
|
|
BTA_AV_STR_WRITE_CFM_EVT, /* AVDT_WRITE_CFM_EVT */
|
|
|
|
BTA_AV_AVDT_CONNECT_EVT, /* AVDT_CONNECT_IND_EVT */
|
|
|
|
BTA_AV_AVDT_DISCONNECT_EVT, /* AVDT_DISCONNECT_IND_EVT */
|
|
|
|
#if (AVDT_REPORTING == TRUE)
|
|
|
|
BTA_AV_AVDT_RPT_CONN_EVT, /* AVDT_REPORT_CONN_EVT */
|
|
|
|
BTA_AV_AVDT_RPT_CONN_EVT, /* AVDT_REPORT_DISCONN_EVT */
|
|
|
|
#endif
|
|
|
|
BTA_AV_AVDT_DELAY_RPT_EVT, /* AVDT_DELAY_REPORT_EVT */
|
|
|
|
0 /* AVDT_DELAY_REPORT_CFM_EVT */
|
|
|
|
};
|
|
|
|
|
|
|
|
void bta_av_stream_data_cback(UINT8 handle, BT_HDR *p_pkt, UINT32 time_stamp, UINT8 m_pt);
|
|
|
|
static void bta_av_stream0_cback(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDT_CTRL *p_data);
|
|
|
|
static void bta_av_stream1_cback(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDT_CTRL *p_data);
|
|
|
|
#if BTA_AV_NUM_STRS > 2
|
|
|
|
static void bta_av_stream2_cback(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDT_CTRL *p_data);
|
|
|
|
#endif
|
|
|
|
#if BTA_AV_NUM_STRS > 3
|
|
|
|
static void bta_av_stream3_cback(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDT_CTRL *p_data);
|
|
|
|
#endif
|
|
|
|
#if BTA_AV_NUM_STRS > 4
|
|
|
|
static void bta_av_stream4_cback(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDT_CTRL *p_data);
|
|
|
|
#endif
|
|
|
|
#if BTA_AV_NUM_STRS > 5
|
|
|
|
static void bta_av_stream5_cback(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDT_CTRL *p_data);
|
|
|
|
#endif
|
|
|
|
/* the array of callback functions to receive events from AVDT control channel */
|
2017-03-17 14:46:49 +00:00
|
|
|
tAVDT_CTRL_CBACK *const bta_av_dt_cback[] = {
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_av_stream0_cback
|
2017-03-17 14:46:49 +00:00
|
|
|
, bta_av_stream1_cback
|
2016-11-02 11:40:46 +00:00
|
|
|
#if BTA_AV_NUM_STRS > 2
|
2017-03-17 14:46:49 +00:00
|
|
|
, bta_av_stream2_cback
|
2016-11-02 11:40:46 +00:00
|
|
|
#endif
|
|
|
|
#if BTA_AV_NUM_STRS > 3
|
2017-03-17 14:46:49 +00:00
|
|
|
, bta_av_stream3_cback
|
2016-11-02 11:40:46 +00:00
|
|
|
#endif
|
|
|
|
#if BTA_AV_NUM_STRS > 4
|
2017-03-17 14:46:49 +00:00
|
|
|
, bta_av_stream4_cback
|
2016-11-02 11:40:46 +00:00
|
|
|
#endif
|
|
|
|
#if BTA_AV_NUM_STRS > 5
|
2017-03-17 14:46:49 +00:00
|
|
|
, bta_av_stream5_cback
|
2016-11-02 11:40:46 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
/***********************************************
|
|
|
|
**
|
|
|
|
** Function bta_get_scb_handle
|
|
|
|
**
|
|
|
|
** Description gives the registered AVDT handle.by checking with sep_type.
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
***********************************************/
|
|
|
|
static UINT8 bta_av_get_scb_handle(tBTA_AV_SCB *p_scb, UINT8 local_sep)
|
|
|
|
{
|
2017-03-17 14:46:49 +00:00
|
|
|
UINT8 xx = 0;
|
|
|
|
for (xx = 0; xx < BTA_AV_MAX_SEPS; xx++) {
|
2016-11-02 11:40:46 +00:00
|
|
|
if ((p_scb->seps[xx].tsep == local_sep) &&
|
2017-03-17 14:46:49 +00:00
|
|
|
(p_scb->seps[xx].codec_type == p_scb->codec_type)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
return (p_scb->seps[xx].av_handle);
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
}
|
|
|
|
APPL_TRACE_DEBUG(" bta_av_get_scb_handle appropiate sep_type not found")
|
|
|
|
return 0; /* return invalid handle */
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_get_scb_sep_type
|
|
|
|
**
|
|
|
|
** Description gives the sep type by cross-checking with AVDT handle
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
***********************************************/
|
|
|
|
static UINT8 bta_av_get_scb_sep_type(tBTA_AV_SCB *p_scb, UINT8 tavdt_handle)
|
|
|
|
{
|
2017-03-17 14:46:49 +00:00
|
|
|
UINT8 xx = 0;
|
|
|
|
for (xx = 0; xx < BTA_AV_MAX_SEPS; xx++) {
|
|
|
|
if (p_scb->seps[xx].av_handle == tavdt_handle) {
|
2016-11-02 11:40:46 +00:00
|
|
|
return (p_scb->seps[xx].tsep);
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
}
|
|
|
|
APPL_TRACE_DEBUG(" bta_av_get_scb_sep_type appropiate handle not found")
|
|
|
|
return 3; /* return invalid sep type */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_save_addr
|
|
|
|
**
|
|
|
|
** Description copy the bd_addr and maybe reset the supported flags
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static void bta_av_save_addr(tBTA_AV_SCB *p_scb, const BD_ADDR b)
|
|
|
|
{
|
|
|
|
APPL_TRACE_DEBUG("bta_av_save_addr r:%d, s:%d",
|
2017-03-17 14:46:49 +00:00
|
|
|
p_scb->recfg_sup, p_scb->suspend_sup);
|
|
|
|
if (bdcmp(p_scb->peer_addr, b) != 0) {
|
2016-11-02 11:40:46 +00:00
|
|
|
APPL_TRACE_ERROR("reset flags");
|
|
|
|
/* a new addr, reset the supported flags */
|
|
|
|
p_scb->recfg_sup = TRUE;
|
|
|
|
p_scb->suspend_sup = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do this copy anyway, just in case the first addr matches
|
|
|
|
* the control block one by accident */
|
|
|
|
bdcpy(p_scb->peer_addr, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function notify_start_failed
|
|
|
|
**
|
|
|
|
** Description notify up-layer AV start failed
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static void notify_start_failed(tBTA_AV_SCB *p_scb)
|
|
|
|
{
|
|
|
|
tBTA_AV_START start;
|
|
|
|
/* if start failed, clear role */
|
|
|
|
p_scb->role &= ~BTA_AV_ROLE_START_INT;
|
|
|
|
start.chnl = p_scb->chnl;
|
|
|
|
start.status = BTA_AV_FAIL;
|
|
|
|
start.initiator = TRUE;
|
|
|
|
start.hndl = p_scb->hndl;
|
|
|
|
(*bta_av_cb.p_cback)(BTA_AV_START_EVT, (tBTA_AV *) &start);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_st_rc_timer
|
|
|
|
**
|
|
|
|
** Description start the AVRC timer if no RC connection & CT is supported &
|
|
|
|
** RC is used or
|
|
|
|
** as ACP (we do not really know if we want AVRC)
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static void bta_av_st_rc_timer(tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
UNUSED(p_data);
|
|
|
|
|
|
|
|
APPL_TRACE_DEBUG("bta_av_st_rc_timer rc_handle:%d, use_rc: %d",
|
2017-03-17 14:46:49 +00:00
|
|
|
p_scb->rc_handle, p_scb->use_rc);
|
2016-11-02 11:40:46 +00:00
|
|
|
/* for outgoing RC connection as INT/CT */
|
2017-03-17 14:46:49 +00:00
|
|
|
if ( (p_scb->rc_handle == BTA_AV_RC_HANDLE_NONE) &&
|
|
|
|
/*(bta_av_cb.features & BTA_AV_FEAT_RCCT) &&*/
|
|
|
|
(p_scb->use_rc == TRUE || (p_scb->role & BTA_AV_ROLE_AD_ACP)) ) {
|
|
|
|
if ((p_scb->wait & BTA_AV_WAIT_ROLE_SW_BITS) == 0) {
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_sys_start_timer(&p_scb->timer, BTA_AV_AVRC_TIMER_EVT, BTA_AV_RC_DISC_TIME_VAL);
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->wait |= BTA_AV_WAIT_CHECK_RC;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_next_getcap
|
|
|
|
**
|
|
|
|
** Description The function gets the capabilities of the next available
|
|
|
|
** stream found in the discovery results.
|
|
|
|
**
|
|
|
|
** Returns TRUE if we sent request to AVDT, FALSE otherwise.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static BOOLEAN bta_av_next_getcap(tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
tAVDT_GETCAP_REQ *p_req;
|
|
|
|
BOOLEAN sent_cmd = FALSE;
|
|
|
|
UINT16 uuid_int = p_scb->uuid_int;
|
|
|
|
UINT8 sep_requested = 0;
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (uuid_int == UUID_SERVCLASS_AUDIO_SOURCE) {
|
|
|
|
sep_requested = AVDT_TSEP_SNK;
|
|
|
|
} else if (uuid_int == UUID_SERVCLASS_AUDIO_SINK) {
|
|
|
|
sep_requested = AVDT_TSEP_SRC;
|
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
for (i = p_scb->sep_info_idx; i < p_scb->num_seps; i++) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* steam not in use, is a sink, and is the right media type (audio/video) */
|
|
|
|
if ((p_scb->sep_info[i].in_use == FALSE) &&
|
2017-03-17 14:46:49 +00:00
|
|
|
(p_scb->sep_info[i].tsep == sep_requested) &&
|
|
|
|
(p_scb->sep_info[i].media_type == p_scb->media_type)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->sep_info_idx = i;
|
|
|
|
|
|
|
|
/* we got a stream; get its capabilities */
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->p_cap == NULL) {
|
2017-08-17 13:13:45 +00:00
|
|
|
p_scb->p_cap = (tAVDT_CFG *) osi_malloc(sizeof(tAVDT_CFG));
|
2016-11-02 11:40:46 +00:00
|
|
|
}
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->p_cap == NULL) {
|
2016-11-02 11:40:46 +00:00
|
|
|
i = p_scb->num_seps;
|
|
|
|
break;
|
|
|
|
}
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->avdt_version >= AVDT_VERSION_SYNC) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_req = AVDT_GetAllCapReq;
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_req = AVDT_GetCapReq;
|
|
|
|
}
|
|
|
|
(*p_req)(p_scb->peer_addr,
|
2017-03-17 14:46:49 +00:00
|
|
|
p_scb->sep_info[i].seid,
|
|
|
|
p_scb->p_cap, bta_av_dt_cback[p_scb->hdi]);
|
2016-11-02 11:40:46 +00:00
|
|
|
sent_cmd = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if no streams available then stream open fails */
|
2017-03-17 14:46:49 +00:00
|
|
|
if (!sent_cmd) {
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_av_ssm_execute(p_scb, BTA_AV_STR_GETCAP_FAIL_EVT, p_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return sent_cmd;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_proc_stream_evt
|
|
|
|
**
|
|
|
|
** Description Utility function to compose stream events.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static void bta_av_proc_stream_evt(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDT_CTRL *p_data, int index)
|
|
|
|
{
|
|
|
|
tBTA_AV_STR_MSG *p_msg;
|
|
|
|
UINT16 sec_len = 0;
|
|
|
|
tBTA_AV_SCB *p_scb = bta_av_cb.p_scb[index];
|
|
|
|
int xx;
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_data) {
|
|
|
|
if (event == AVDT_SECURITY_IND_EVT) {
|
2016-11-02 11:40:46 +00:00
|
|
|
sec_len = (p_data->security_ind.len < BTA_AV_SECURITY_MAX_LEN) ?
|
2017-03-17 14:46:49 +00:00
|
|
|
p_data->security_ind.len : BTA_AV_SECURITY_MAX_LEN;
|
|
|
|
} else if (event == AVDT_SECURITY_CFM_EVT && p_data->hdr.err_code == 0) {
|
2016-11-02 11:40:46 +00:00
|
|
|
sec_len = (p_data->security_cfm.len < BTA_AV_SECURITY_MAX_LEN) ?
|
2017-03-17 14:46:49 +00:00
|
|
|
p_data->security_cfm.len : BTA_AV_SECURITY_MAX_LEN;
|
2016-11-02 11:40:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
if (p_scb && (p_msg = (tBTA_AV_STR_MSG *) osi_malloc((UINT16) (sizeof(tBTA_AV_STR_MSG) + sec_len))) != NULL) {
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
/* copy event data, bd addr, and handle to event message buffer */
|
|
|
|
p_msg->hdr.offset = 0;
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (bd_addr != NULL) {
|
2016-11-02 11:40:46 +00:00
|
|
|
bdcpy(p_msg->bd_addr, bd_addr);
|
|
|
|
APPL_TRACE_DEBUG(" bd_addr:%02x-%02x-%02x-%02x-%02x-%02x",
|
2017-03-17 14:46:49 +00:00
|
|
|
bd_addr[0], bd_addr[1],
|
|
|
|
bd_addr[2], bd_addr[3],
|
|
|
|
bd_addr[4], bd_addr[5]);
|
2016-11-02 11:40:46 +00:00
|
|
|
}
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_data != NULL) {
|
2016-11-02 11:40:46 +00:00
|
|
|
memcpy(&p_msg->msg, p_data, sizeof (tAVDT_CTRL));
|
|
|
|
/* copy config params to event message buffer */
|
2017-03-17 14:46:49 +00:00
|
|
|
switch (event) {
|
2016-11-02 11:40:46 +00:00
|
|
|
case AVDT_RECONFIG_CFM_EVT:
|
2017-03-17 14:46:49 +00:00
|
|
|
APPL_TRACE_DEBUG("reconfig cfm event codec info = 0x%06x-%06x-%06x-%02x",
|
|
|
|
(p_msg->msg.reconfig_cfm.p_cfg->codec_info[0] << 16) + (p_msg->msg.reconfig_cfm.p_cfg->codec_info[1] << 8) + p_msg->msg.reconfig_cfm.p_cfg->codec_info[2],
|
|
|
|
(p_msg->msg.reconfig_cfm.p_cfg->codec_info[3] << 16) + (p_msg->msg.reconfig_cfm.p_cfg->codec_info[4] << 8) + p_msg->msg.reconfig_cfm.p_cfg->codec_info[5],
|
|
|
|
(p_msg->msg.reconfig_cfm.p_cfg->codec_info[6] << 16) + (p_msg->msg.reconfig_cfm.p_cfg->codec_info[7] << 8) + p_msg->msg.reconfig_cfm.p_cfg->codec_info[8],
|
|
|
|
p_msg->msg.reconfig_cfm.p_cfg->codec_info[9]);
|
|
|
|
break;
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case AVDT_CONFIG_IND_EVT:
|
2017-03-17 14:46:49 +00:00
|
|
|
/* We might have 2 SEP signallings(A2DP + VDP) with one peer device on one L2CAP.
|
|
|
|
* If we already have a signalling connection with the bd_addr and the streaming
|
|
|
|
* SST is at INIT state, change it to INCOMING state to handle the signalling
|
|
|
|
* from the 2nd SEP. */
|
|
|
|
if ((bta_av_find_lcb(bd_addr, BTA_AV_LCB_FIND) != NULL) && (bta_av_is_scb_init(p_scb))) {
|
|
|
|
bta_av_set_scb_sst_incoming (p_scb);
|
|
|
|
|
|
|
|
/* When ACP_CONNECT_EVT was received, we put first available scb to incoming state.
|
|
|
|
* Later when we receive AVDT_CONFIG_IND_EVT, we use a new p_scb and set its state to
|
|
|
|
* incoming which we do it above.
|
|
|
|
* We also have to set the old p_scb state to init to be used later */
|
|
|
|
for (xx = 0; xx < BTA_AV_NUM_STRS; xx++) {
|
|
|
|
if ((bta_av_cb.p_scb[xx]) && (xx != index)) {
|
|
|
|
if (bta_av_cb.p_scb[xx]->state == BTA_AV_INCOMING_SST) {
|
|
|
|
bta_av_cb.p_scb[xx]->state = BTA_AV_INIT_SST;
|
|
|
|
bta_av_cb.p_scb[xx]->coll_mask = 0;
|
|
|
|
break;
|
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
memcpy(&p_msg->cfg, p_data->config_ind.p_cfg, sizeof(tAVDT_CFG));
|
|
|
|
break;
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
case AVDT_SECURITY_IND_EVT:
|
|
|
|
p_msg->msg.security_ind.p_data = (UINT8 *) (p_msg + 1);
|
|
|
|
memcpy(p_msg->msg.security_ind.p_data, p_data->security_ind.p_data, sec_len);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AVDT_SECURITY_CFM_EVT:
|
|
|
|
p_msg->msg.security_cfm.p_data = (UINT8 *) (p_msg + 1);
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_data->hdr.err_code == 0) {
|
2016-11-02 11:40:46 +00:00
|
|
|
memcpy(p_msg->msg.security_cfm.p_data, p_data->security_cfm.p_data, sec_len);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AVDT_SUSPEND_IND_EVT:
|
2017-02-23 06:30:08 +00:00
|
|
|
p_msg->msg.hdr.err_code = 0;
|
2016-11-02 11:40:46 +00:00
|
|
|
break;
|
2017-03-17 14:46:49 +00:00
|
|
|
/*
|
2017-02-23 06:30:08 +00:00
|
|
|
case AVDT_CLOSE_CFM_EVT:
|
|
|
|
case AVDT_CLOSE_IND_EVT:
|
2017-03-17 14:46:49 +00:00
|
|
|
p_msg->disc_rsn = p_data->hdr.err_param;
|
|
|
|
break;
|
|
|
|
*/
|
2018-03-06 06:11:28 +00:00
|
|
|
case AVDT_DISCONNECT_IND_EVT:
|
|
|
|
p_msg->hdr.offset = p_data->hdr.err_param;
|
|
|
|
break;
|
2016-11-02 11:40:46 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_msg->msg.hdr.err_code = 0;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
/* look up application event */
|
2017-03-17 14:46:49 +00:00
|
|
|
if ((p_data == NULL) || (p_data->hdr.err_code == 0)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_msg->hdr.event = bta_av_stream_evt_ok[event];
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_msg->hdr.event = bta_av_stream_evt_fail[event];
|
|
|
|
}
|
|
|
|
|
|
|
|
p_msg->initiator = FALSE;
|
2017-03-17 14:46:49 +00:00
|
|
|
if (event == AVDT_SUSPEND_CFM_EVT) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_msg->initiator = TRUE;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
APPL_TRACE_VERBOSE("hndl:x%x", p_scb->hndl);
|
|
|
|
p_msg->hdr.layer_specific = p_scb->hndl;
|
|
|
|
p_msg->handle = handle;
|
|
|
|
p_msg->avdt_event = event;
|
|
|
|
bta_sys_sendmsg(p_msg);
|
|
|
|
}
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
/* coverity[var_deref_model] */
|
|
|
|
/* false-positive: bta_av_conn_cback only processes AVDT_CONNECT_IND_EVT and AVDT_DISCONNECT_IND_EVT event
|
|
|
|
* these 2 events always have associated p_data */
|
|
|
|
if (p_data) {
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_av_conn_cback(handle, bd_addr, event, p_data);
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2018-01-17 11:23:41 +00:00
|
|
|
APPL_TRACE_EVENT("%s: p_data is null", __func__);
|
2016-11-02 11:40:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_stream_data_cback
|
|
|
|
**
|
|
|
|
** Description This is the AVDTP callback function for stream events.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_stream_data_cback(UINT8 handle, BT_HDR *p_pkt, UINT32 time_stamp, UINT8 m_pt)
|
|
|
|
{
|
|
|
|
int index = 0;
|
|
|
|
tBTA_AV_SCB *p_scb ;
|
2017-03-17 14:46:49 +00:00
|
|
|
APPL_TRACE_DEBUG("bta_av_stream_data_cback avdt_handle: %d pkt_len=0x%x ofst = 0x%x", handle, p_pkt->len, p_pkt->offset);
|
|
|
|
APPL_TRACE_DEBUG(" Number of frames 0x%x", *((UINT8 *)(p_pkt + 1) + p_pkt->offset));
|
|
|
|
APPL_TRACE_DEBUG("Sequence Number 0x%x", p_pkt->layer_specific);
|
2016-11-02 11:40:46 +00:00
|
|
|
/* Get SCB and correct sep type*/
|
2017-03-17 14:46:49 +00:00
|
|
|
for (index = 0; index < BTA_AV_NUM_STRS; index ++ ) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb = bta_av_cb.p_scb[index];
|
2017-03-17 14:46:49 +00:00
|
|
|
if ((p_scb->avdt_handle == handle) && (p_scb->seps[p_scb->sep_idx].tsep == AVDT_TSEP_SNK)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
break;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
}
|
2017-03-17 14:46:49 +00:00
|
|
|
if (index == BTA_AV_NUM_STRS) { /* cannot find correct handler */
|
2017-08-17 13:13:45 +00:00
|
|
|
osi_free(p_pkt);
|
2016-11-02 11:40:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
p_pkt->event = BTA_AV_MEDIA_DATA_EVT;
|
2017-03-17 14:46:49 +00:00
|
|
|
p_scb->seps[p_scb->sep_idx].p_app_data_cback(BTA_AV_MEDIA_DATA_EVT, (tBTA_AV_MEDIA *)p_pkt);
|
2017-08-17 13:13:45 +00:00
|
|
|
osi_free(p_pkt); /* a copy of packet had been delivered, we free this buffer */
|
2016-11-02 11:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_stream0_cback
|
|
|
|
**
|
|
|
|
** Description This is the AVDTP callback function for stream events.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static void bta_av_stream0_cback(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDT_CTRL *p_data)
|
|
|
|
{
|
|
|
|
APPL_TRACE_VERBOSE("bta_av_stream0_cback avdt_handle: %d event=0x%x", handle, event);
|
|
|
|
bta_av_proc_stream_evt(handle, bd_addr, event, p_data, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_stream1_cback
|
|
|
|
**
|
|
|
|
** Description This is the AVDTP callback function for stream events.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static void bta_av_stream1_cback(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDT_CTRL *p_data)
|
|
|
|
{
|
|
|
|
APPL_TRACE_EVENT("bta_av_stream1_cback avdt_handle: %d event=0x%x", handle, event);
|
|
|
|
bta_av_proc_stream_evt(handle, bd_addr, event, p_data, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if BTA_AV_NUM_STRS > 2
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_stream2_cback
|
|
|
|
**
|
|
|
|
** Description This is the AVDTP callback function for stream events.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static void bta_av_stream2_cback(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDT_CTRL *p_data)
|
|
|
|
{
|
|
|
|
APPL_TRACE_EVENT("bta_av_stream2_cback avdt_handle: %d event=0x%x", handle, event);
|
|
|
|
bta_av_proc_stream_evt(handle, bd_addr, event, p_data, 2);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if BTA_AV_NUM_STRS > 3
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_stream3_cback
|
|
|
|
**
|
|
|
|
** Description This is the AVDTP callback function for stream events.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static void bta_av_stream3_cback(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDT_CTRL *p_data)
|
|
|
|
{
|
|
|
|
APPL_TRACE_EVENT("bta_av_stream3_cback avdt_handle: %d event=0x%x", handle, event);
|
|
|
|
bta_av_proc_stream_evt(handle, bd_addr, event, p_data, 3);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_stream4_cback
|
|
|
|
**
|
|
|
|
** Description This is the AVDTP callback function for stream events.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
#if BTA_AV_NUM_STRS > 4
|
|
|
|
static void bta_av_stream4_cback(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDT_CTRL *p_data)
|
|
|
|
{
|
|
|
|
APPL_TRACE_EVENT("bta_av_stream4_cback avdt_handle: %d event=0x%x", handle, event);
|
|
|
|
bta_av_proc_stream_evt(handle, bd_addr, event, p_data, 4);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_stream5_cback
|
|
|
|
**
|
|
|
|
** Description This is the AVDTP callback function for stream events.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
#if BTA_AV_NUM_STRS > 5
|
|
|
|
static void bta_av_stream5_cback(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDT_CTRL *p_data)
|
|
|
|
{
|
|
|
|
APPL_TRACE_EVENT("bta_av_stream5_cback avdt_handle: %d event=0x%x", handle, event);
|
|
|
|
bta_av_proc_stream_evt(handle, bd_addr, event, p_data, 5);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_a2d_sdp_cback
|
|
|
|
**
|
|
|
|
** Description A2DP service discovery callback.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static void bta_av_a2d_sdp_cback(BOOLEAN found, tA2D_Service *p_service)
|
|
|
|
{
|
|
|
|
tBTA_AV_SDP_RES *p_msg;
|
|
|
|
tBTA_AV_SCB *p_scb;
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
if ((p_msg = (tBTA_AV_SDP_RES *) osi_malloc(sizeof(tBTA_AV_SDP_RES))) != NULL) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_msg->hdr.event = (found) ? BTA_AV_SDP_DISC_OK_EVT : BTA_AV_SDP_DISC_FAIL_EVT;
|
|
|
|
|
|
|
|
p_scb = bta_av_hndl_to_scb(bta_av_cb.handle);
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb) {
|
|
|
|
if (found && (p_service != NULL)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->avdt_version = p_service->avdt_version;
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->avdt_version = 0x00;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
p_msg->hdr.layer_specific = bta_av_cb.handle;
|
|
|
|
bta_sys_sendmsg(p_msg);
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
APPL_TRACE_ERROR ("bta_av_a2d_sdp_cback, no scb found for handle(0x%x)", bta_av_cb.handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_adjust_seps_idx
|
|
|
|
**
|
|
|
|
** Description adjust the sep_idx
|
|
|
|
**
|
|
|
|
** Returns
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static void bta_av_adjust_seps_idx(tBTA_AV_SCB *p_scb, UINT8 avdt_handle)
|
|
|
|
{
|
|
|
|
int xx;
|
|
|
|
APPL_TRACE_DEBUG("bta_av_adjust_seps_idx codec_type: %d", p_scb->codec_type);
|
2017-03-17 14:46:49 +00:00
|
|
|
for (xx = 0; xx < BTA_AV_MAX_SEPS; xx++) {
|
2016-11-02 11:40:46 +00:00
|
|
|
APPL_TRACE_DEBUG("av_handle: %d codec_type: %d",
|
2017-03-17 14:46:49 +00:00
|
|
|
p_scb->seps[xx].av_handle, p_scb->seps[xx].codec_type);
|
|
|
|
if ((p_scb->seps[xx].av_handle && p_scb->codec_type == p_scb->seps[xx].codec_type)
|
|
|
|
&& (p_scb->seps[xx].av_handle == avdt_handle)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->sep_idx = xx;
|
|
|
|
p_scb->avdt_handle = p_scb->seps[xx].av_handle;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_switch_role
|
|
|
|
**
|
|
|
|
** Description Switch role was not started and a timer was started.
|
|
|
|
** another attempt to switch role now - still opening.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_switch_role (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
tBTA_AV_RS_RES switch_res = BTA_AV_RS_NONE;
|
|
|
|
tBTA_AV_API_OPEN *p_buf = &p_scb->q_info.open;
|
|
|
|
UNUSED(p_data);
|
|
|
|
|
|
|
|
APPL_TRACE_DEBUG("bta_av_switch_role wait:x%x", p_scb->wait);
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->wait & BTA_AV_WAIT_ROLE_SW_RES_START) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->wait |= BTA_AV_WAIT_ROLE_SW_RETRY;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
/* clear the masks set when the timer is started */
|
2017-03-17 14:46:49 +00:00
|
|
|
p_scb->wait &= ~(BTA_AV_WAIT_ROLE_SW_RES_OPEN | BTA_AV_WAIT_ROLE_SW_RES_START);
|
2016-11-02 11:40:46 +00:00
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->q_tag == BTA_AV_Q_TAG_OPEN) {
|
|
|
|
if (bta_av_switch_if_needed(p_scb) || !bta_av_link_role_ok(p_scb, A2D_SET_MULTL_BIT)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->wait |= BTA_AV_WAIT_ROLE_SW_RES_OPEN;
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* this should not happen in theory. Just in case...
|
|
|
|
* continue to do_disc_a2d */
|
|
|
|
switch_res = BTA_AV_RS_DONE;
|
|
|
|
}
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* report failure on OPEN */
|
|
|
|
switch_res = BTA_AV_RS_FAIL;
|
|
|
|
}
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (switch_res != BTA_AV_RS_NONE) {
|
|
|
|
if (bta_av_cb.rs_idx == (p_scb->hdi + 1)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_av_cb.rs_idx = 0;
|
|
|
|
}
|
|
|
|
p_scb->wait &= ~BTA_AV_WAIT_ROLE_SW_RETRY;
|
|
|
|
p_scb->q_tag = 0;
|
|
|
|
p_buf->switch_res = switch_res;
|
|
|
|
bta_av_do_disc_a2d(p_scb, (tBTA_AV_DATA *)p_buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_role_res
|
|
|
|
**
|
|
|
|
** Description Handle the role changed event
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_role_res (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
BOOLEAN initiator = FALSE;
|
|
|
|
tBTA_AV_START start;
|
|
|
|
tBTA_AV_OPEN av_open;
|
|
|
|
|
|
|
|
APPL_TRACE_DEBUG("bta_av_role_res q_tag:%d, wait:x%x, role:x%x", p_scb->q_tag, p_scb->wait, p_scb->role);
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->role & BTA_AV_ROLE_START_INT) {
|
2016-11-02 11:40:46 +00:00
|
|
|
initiator = TRUE;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->q_tag == BTA_AV_Q_TAG_START) {
|
|
|
|
if (p_scb->wait & BTA_AV_WAIT_ROLE_SW_STARTED) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->wait &= ~BTA_AV_WAIT_ROLE_SW_BITS;
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_data->role_res.hci_status != HCI_SUCCESS) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->role &= ~BTA_AV_ROLE_START_INT;
|
|
|
|
bta_sys_idle(BTA_ID_AV, bta_av_cb.audio_open_cnt, p_scb->peer_addr);
|
|
|
|
/* start failed because of role switch. */
|
|
|
|
start.chnl = p_scb->chnl;
|
|
|
|
start.status = BTA_AV_FAIL_ROLE;
|
|
|
|
start.hndl = p_scb->hndl;
|
|
|
|
start.initiator = initiator;
|
|
|
|
(*bta_av_cb.p_cback)(BTA_AV_START_EVT, (tBTA_AV *) &start);
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_av_start_ok(p_scb, p_data);
|
|
|
|
}
|
2017-03-17 14:46:49 +00:00
|
|
|
} else if (p_scb->wait & BTA_AV_WAIT_ROLE_SW_RES_START) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->wait |= BTA_AV_WAIT_ROLE_SW_FAILED;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
|
|
|
} else if (p_scb->q_tag == BTA_AV_Q_TAG_OPEN) {
|
|
|
|
if (p_scb->wait & BTA_AV_WAIT_ROLE_SW_RES_OPEN) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->role &= ~BTA_AV_ROLE_START_INT;
|
|
|
|
p_scb->wait &= ~BTA_AV_WAIT_ROLE_SW_BITS;
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_data->role_res.hci_status != HCI_SUCCESS) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* Open failed because of role switch. */
|
|
|
|
bdcpy(av_open.bd_addr, p_scb->peer_addr);
|
|
|
|
av_open.chnl = p_scb->chnl;
|
|
|
|
av_open.hndl = p_scb->hndl;
|
|
|
|
start.status = BTA_AV_FAIL_ROLE;
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->seps[p_scb->sep_idx].tsep == AVDT_TSEP_SRC ) {
|
2016-11-02 11:40:46 +00:00
|
|
|
av_open.sep = AVDT_TSEP_SNK;
|
2017-03-17 14:46:49 +00:00
|
|
|
} else if (p_scb->seps[p_scb->sep_idx].tsep == AVDT_TSEP_SNK ) {
|
2016-11-02 11:40:46 +00:00
|
|
|
av_open.sep = AVDT_TSEP_SRC;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
(*bta_av_cb.p_cback)(BTA_AV_OPEN_EVT, (tBTA_AV *)&av_open);
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* Continue av open process */
|
|
|
|
p_scb->q_info.open.switch_res = BTA_AV_RS_DONE;
|
2017-03-17 14:46:49 +00:00
|
|
|
bta_av_do_disc_a2d (p_scb, (tBTA_AV_DATA *) & (p_scb->q_info.open));
|
2016-11-02 11:40:46 +00:00
|
|
|
}
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
APPL_TRACE_WARNING ("Unexpected role switch event: q_tag = %d wait = %d", p_scb->q_tag, p_scb->wait);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
APPL_TRACE_DEBUG("wait:x%x, role:x%x", p_scb->wait, p_scb->role);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_delay_co
|
|
|
|
**
|
|
|
|
** Description Call the delay call-out function to report the delay report
|
|
|
|
** from SNK
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_delay_co (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
p_scb->p_cos->delay(p_scb->hndl, p_data->str_msg.msg.delay_rpt_cmd.delay);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_do_disc_a2d
|
|
|
|
**
|
|
|
|
** Description Do service discovery for A2DP.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_do_disc_a2d (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
BOOLEAN ok_continue = FALSE;
|
|
|
|
tA2D_SDP_DB_PARAMS db_params;
|
|
|
|
UINT16 attr_list[] = {ATTR_ID_SERVICE_CLASS_ID_LIST,
|
|
|
|
ATTR_ID_PROTOCOL_DESC_LIST,
|
2017-03-17 14:46:49 +00:00
|
|
|
ATTR_ID_BT_PROFILE_DESC_LIST
|
|
|
|
};
|
2016-11-02 11:40:46 +00:00
|
|
|
UINT16 sdp_uuid = 0; /* UUID for which SDP has to be done */
|
|
|
|
|
|
|
|
APPL_TRACE_DEBUG("bta_av_do_disc_a2d use_rc: %d rs:%d, oc:%d",
|
2017-03-17 14:46:49 +00:00
|
|
|
p_data->api_open.use_rc, p_data->api_open.switch_res, bta_av_cb.audio_open_cnt);
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
memcpy (&(p_scb->open_api), &(p_data->api_open), sizeof(tBTA_AV_API_OPEN));
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
switch (p_data->api_open.switch_res) {
|
2016-11-02 11:40:46 +00:00
|
|
|
case BTA_AV_RS_NONE:
|
2017-03-17 14:46:49 +00:00
|
|
|
if (bta_av_switch_if_needed(p_scb) || !bta_av_link_role_ok(p_scb, A2D_SET_MULTL_BIT)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* waiting for role switch result. save the api to control block */
|
|
|
|
memcpy(&p_scb->q_info.open, &p_data->api_open, sizeof(tBTA_AV_API_OPEN));
|
|
|
|
p_scb->wait |= BTA_AV_WAIT_ROLE_SW_RES_OPEN;
|
|
|
|
p_scb->q_tag = BTA_AV_Q_TAG_OPEN;
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
ok_continue = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BTA_AV_RS_FAIL:
|
|
|
|
/* report a new failure event */
|
|
|
|
p_scb->open_status = BTA_AV_FAIL_ROLE;
|
|
|
|
bta_av_ssm_execute(p_scb, BTA_AV_SDP_DISC_FAIL_EVT, NULL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BTA_AV_RS_OK:
|
|
|
|
p_data = (tBTA_AV_DATA *)&p_scb->q_info.open;
|
|
|
|
/* continue to open if link role is ok */
|
2017-03-17 14:46:49 +00:00
|
|
|
if (bta_av_link_role_ok(p_scb, A2D_SET_MULTL_BIT)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
ok_continue = TRUE;
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->wait |= BTA_AV_WAIT_ROLE_SW_RES_OPEN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BTA_AV_RS_DONE:
|
|
|
|
ok_continue = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
APPL_TRACE_DEBUG("ok_continue: %d wait:x%x, q_tag: %d", ok_continue, p_scb->wait, p_scb->q_tag);
|
2017-03-17 14:46:49 +00:00
|
|
|
if (!ok_continue) {
|
2016-11-02 11:40:46 +00:00
|
|
|
return;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
/* clear the role switch bits */
|
|
|
|
p_scb->wait &= ~BTA_AV_WAIT_ROLE_SW_BITS;
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->wait & BTA_AV_WAIT_CHECK_RC) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->wait &= ~BTA_AV_WAIT_CHECK_RC;
|
|
|
|
bta_sys_start_timer(&p_scb->timer, BTA_AV_AVRC_TIMER_EVT, BTA_AV_RC_DISC_TIME_VAL);
|
|
|
|
}
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (bta_av_cb.features & BTA_AV_FEAT_MASTER) {
|
2016-11-02 11:40:46 +00:00
|
|
|
L2CA_SetDesireRole(L2CAP_ROLE_DISALLOW_SWITCH);
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (bta_av_cb.audio_open_cnt == 1) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* there's already an A2DP connection. do not allow switch */
|
|
|
|
bta_sys_clear_default_policy(BTA_ID_AV, HCI_ENABLE_MASTER_SLAVE_SWITCH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* store peer addr other parameters */
|
|
|
|
bta_av_save_addr(p_scb, p_data->api_open.bd_addr);
|
|
|
|
p_scb->sec_mask = p_data->api_open.sec_mask;
|
|
|
|
p_scb->use_rc = p_data->api_open.use_rc;
|
|
|
|
|
|
|
|
bta_sys_app_open(BTA_ID_AV, p_scb->app_id, p_scb->peer_addr);
|
|
|
|
|
|
|
|
/* allocate discovery database */
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->p_disc_db == NULL) {
|
2017-08-17 13:13:45 +00:00
|
|
|
p_scb->p_disc_db = (tSDP_DISCOVERY_DB *) osi_malloc(BTA_AV_DISC_BUF_SIZE);
|
2016-11-02 11:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* only one A2D find service is active at a time */
|
|
|
|
bta_av_cb.handle = p_scb->hndl;
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->p_disc_db) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* set up parameters */
|
|
|
|
db_params.db_len = BTA_AV_DISC_BUF_SIZE;
|
|
|
|
db_params.num_attr = 3;
|
|
|
|
db_params.p_db = p_scb->p_disc_db;
|
|
|
|
db_params.p_attrs = attr_list;
|
|
|
|
p_scb->uuid_int = p_data->api_open.uuid;
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->uuid_int == UUID_SERVCLASS_AUDIO_SINK) {
|
2016-11-02 11:40:46 +00:00
|
|
|
sdp_uuid = UUID_SERVCLASS_AUDIO_SOURCE;
|
2017-03-17 14:46:49 +00:00
|
|
|
} else if (p_scb->uuid_int == UUID_SERVCLASS_AUDIO_SOURCE) {
|
2016-11-02 11:40:46 +00:00
|
|
|
sdp_uuid = UUID_SERVCLASS_AUDIO_SINK;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
APPL_TRACE_DEBUG("uuid_int 0x%x, Doing SDP For 0x%x", p_scb->uuid_int, sdp_uuid);
|
2017-03-17 14:46:49 +00:00
|
|
|
if (A2D_FindService(sdp_uuid, p_scb->peer_addr, &db_params,
|
|
|
|
bta_av_a2d_sdp_cback) == A2D_SUCCESS) {
|
2016-11-02 11:40:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* when the code reaches here, either the DB is NULL
|
|
|
|
* or A2D_FindService is not successful */
|
|
|
|
bta_av_a2d_sdp_cback(FALSE, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_cleanup
|
|
|
|
**
|
|
|
|
** Description cleanup AV stream control block.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_cleanup(tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
tBTA_AV_CONN_CHG msg;
|
|
|
|
int xx;
|
|
|
|
UINT8 role = BTA_AV_ROLE_AD_INT;
|
|
|
|
UNUSED(p_data);
|
|
|
|
|
|
|
|
APPL_TRACE_DEBUG("bta_av_cleanup");
|
|
|
|
|
|
|
|
/* free any buffers */
|
|
|
|
utl_freebuf((void **) &p_scb->p_cap);
|
|
|
|
utl_freebuf((void **) &p_scb->p_disc_db);
|
|
|
|
p_scb->avdt_version = 0;
|
|
|
|
|
|
|
|
/* initialize some control block variables */
|
|
|
|
p_scb->open_status = BTA_AV_SUCCESS;
|
|
|
|
|
|
|
|
/* if de-registering shut everything down */
|
|
|
|
msg.hdr.layer_specific = p_scb->hndl;
|
|
|
|
p_scb->started = FALSE;
|
|
|
|
p_scb->cong = FALSE;
|
|
|
|
p_scb->role = role;
|
|
|
|
p_scb->cur_psc_mask = 0;
|
|
|
|
p_scb->wait = 0;
|
|
|
|
p_scb->num_disc_snks = 0;
|
2017-02-23 06:30:08 +00:00
|
|
|
p_scb->disc_rsn = 0;
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_sys_stop_timer(&p_scb->timer);
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->deregistring) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* remove stream */
|
2017-03-17 14:46:49 +00:00
|
|
|
for (xx = 0; xx < BTA_AV_MAX_SEPS; xx++) {
|
|
|
|
if (p_scb->seps[xx].av_handle) {
|
2016-11-02 11:40:46 +00:00
|
|
|
AVDT_RemoveStream(p_scb->seps[xx].av_handle);
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->seps[xx].av_handle = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bta_av_dereg_comp((tBTA_AV_DATA *) &msg);
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* report stream closed to main SM */
|
|
|
|
msg.is_up = FALSE;
|
|
|
|
bdcpy(msg.peer_addr, p_scb->peer_addr);
|
|
|
|
bta_av_conn_chg((tBTA_AV_DATA *) &msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_free_sdb
|
|
|
|
**
|
|
|
|
** Description Free service discovery db buffer.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_free_sdb(tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
UNUSED(p_data);
|
|
|
|
utl_freebuf((void **) &p_scb->p_disc_db);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_config_ind
|
|
|
|
**
|
|
|
|
** Description Handle a stream configuration indication from the peer.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_config_ind (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
tBTA_AV_CI_SETCONFIG setconfig;
|
|
|
|
tAVDT_SEP_INFO *p_info;
|
|
|
|
tAVDT_CFG *p_evt_cfg = &p_data->str_msg.cfg;
|
|
|
|
UINT8 psc_mask = (p_evt_cfg->psc_mask | p_scb->cfg.psc_mask);
|
|
|
|
UINT8 local_sep; /* sep type of local handle on which connection was received */
|
|
|
|
tBTA_AV_STR_MSG *p_msg = (tBTA_AV_STR_MSG *)p_data;
|
|
|
|
UNUSED(p_data);
|
|
|
|
|
|
|
|
local_sep = bta_av_get_scb_sep_type(p_scb, p_msg->handle);
|
|
|
|
p_scb->avdt_label = p_data->str_msg.msg.hdr.label;
|
|
|
|
memcpy(p_scb->cfg.codec_info, p_evt_cfg->codec_info, AVDT_CODEC_SIZE);
|
|
|
|
p_scb->codec_type = p_evt_cfg->codec_info[BTA_AV_CODEC_TYPE_IDX];
|
|
|
|
bta_av_save_addr(p_scb, p_data->str_msg.bd_addr);
|
|
|
|
|
|
|
|
/* Clear collision mask */
|
|
|
|
p_scb->coll_mask = 0;
|
|
|
|
bta_sys_stop_timer(&bta_av_cb.acp_sig_tmr);
|
|
|
|
|
|
|
|
/* if no codec parameters in configuration, fail */
|
|
|
|
if ((p_evt_cfg->num_codec == 0) ||
|
2017-03-17 14:46:49 +00:00
|
|
|
/* or the peer requests for a service we do not support */
|
|
|
|
((psc_mask != p_scb->cfg.psc_mask) &&
|
|
|
|
(psc_mask != (p_scb->cfg.psc_mask & ~AVDT_PSC_DELAY_RPT))) ) {
|
2016-11-02 11:40:46 +00:00
|
|
|
setconfig.hndl = p_scb->hndl; /* we may not need this */
|
|
|
|
setconfig.err_code = AVDT_ERR_UNSUP_CFG;
|
|
|
|
bta_av_ssm_execute(p_scb, BTA_AV_CI_SETCONFIG_FAIL_EVT, (tBTA_AV_DATA *) &setconfig);
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_info = &p_scb->sep_info[0];
|
|
|
|
p_info->in_use = 0;
|
|
|
|
p_info->media_type = p_scb->media_type;
|
|
|
|
p_info->seid = p_data->str_msg.msg.config_ind.int_seid;
|
|
|
|
|
|
|
|
/* Sep type of Peer will be oppsite role to our local sep */
|
2017-03-17 14:46:49 +00:00
|
|
|
if (local_sep == AVDT_TSEP_SRC) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_info->tsep = AVDT_TSEP_SNK;
|
2017-03-17 14:46:49 +00:00
|
|
|
} else if (local_sep == AVDT_TSEP_SNK) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_info->tsep = AVDT_TSEP_SRC;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
p_scb->role |= BTA_AV_ROLE_AD_ACP;
|
|
|
|
p_scb->cur_psc_mask = p_evt_cfg->psc_mask;
|
2017-03-17 14:46:49 +00:00
|
|
|
if (bta_av_cb.features & BTA_AV_FEAT_RCTG) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->use_rc = TRUE;
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->use_rc = FALSE;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
p_scb->num_seps = 1;
|
|
|
|
p_scb->sep_info_idx = 0;
|
|
|
|
APPL_TRACE_DEBUG("bta_av_config_ind: SEID: %d use_rc: %d cur_psc_mask:0x%x", p_info->seid, p_scb->use_rc, p_scb->cur_psc_mask);
|
|
|
|
/* in case of A2DP SINK this is the first time peer data is being sent to co functions */
|
2017-03-17 14:46:49 +00:00
|
|
|
if (local_sep == AVDT_TSEP_SNK) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->p_cos->setcfg(p_scb->hndl, p_scb->codec_type,
|
2017-03-17 14:46:49 +00:00
|
|
|
p_evt_cfg->codec_info,
|
|
|
|
p_info->seid,
|
|
|
|
p_scb->peer_addr,
|
|
|
|
p_evt_cfg->num_protect,
|
|
|
|
p_evt_cfg->protect_info,
|
|
|
|
AVDT_TSEP_SNK,
|
|
|
|
p_msg->handle);
|
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->p_cos->setcfg(p_scb->hndl, p_scb->codec_type,
|
2017-03-17 14:46:49 +00:00
|
|
|
p_evt_cfg->codec_info,
|
|
|
|
p_info->seid,
|
|
|
|
p_scb->peer_addr,
|
|
|
|
p_evt_cfg->num_protect,
|
|
|
|
p_evt_cfg->protect_info,
|
|
|
|
AVDT_TSEP_SRC,
|
|
|
|
p_msg->handle);
|
2016-11-02 11:40:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_disconnect_req
|
|
|
|
**
|
|
|
|
** Description Disconnect AVDTP connection.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_disconnect_req (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
tBTA_AV_RCB *p_rcb;
|
|
|
|
UNUSED(p_data);
|
|
|
|
|
|
|
|
APPL_TRACE_DEBUG("bta_av_disconnect_req conn_lcb: 0x%x", bta_av_cb.conn_lcb);
|
|
|
|
|
|
|
|
bta_sys_stop_timer(&bta_av_cb.sig_tmr);
|
|
|
|
bta_sys_stop_timer(&p_scb->timer);
|
2017-03-17 14:46:49 +00:00
|
|
|
if (bta_av_cb.conn_lcb) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_rcb = bta_av_get_rcb_by_shdl((UINT8)(p_scb->hdi + 1));
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_rcb) {
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_av_del_rc(p_rcb);
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
AVDT_DisconnectReq(p_scb->peer_addr, bta_av_dt_cback[p_scb->hdi]);
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_av_ssm_execute(p_scb, BTA_AV_AVDT_DISCONNECT_EVT, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_security_req
|
|
|
|
**
|
|
|
|
** Description Send an AVDTP security request.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_security_req (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
2017-03-17 14:46:49 +00:00
|
|
|
if (bta_av_cb.features & BTA_AV_FEAT_PROTECT) {
|
2016-11-02 11:40:46 +00:00
|
|
|
AVDT_SecurityReq(p_scb->avdt_handle, p_data->api_protect_req.p_data,
|
|
|
|
p_data->api_protect_req.len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_security_rsp
|
|
|
|
**
|
|
|
|
** Description Send an AVDTP security response.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_security_rsp (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
2017-03-17 14:46:49 +00:00
|
|
|
if (bta_av_cb.features & BTA_AV_FEAT_PROTECT) {
|
2016-11-02 11:40:46 +00:00
|
|
|
AVDT_SecurityRsp(p_scb->avdt_handle, p_scb->avdt_label, p_data->api_protect_rsp.error_code,
|
|
|
|
p_data->api_protect_rsp.p_data, p_data->api_protect_rsp.len);
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
AVDT_SecurityRsp(p_scb->avdt_handle, p_scb->avdt_label, AVDT_ERR_NSC,
|
2017-03-17 14:46:49 +00:00
|
|
|
NULL, 0);
|
2016-11-02 11:40:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_setconfig_rsp
|
|
|
|
**
|
|
|
|
** Description setconfig is OK
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_setconfig_rsp (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
UINT8 num = p_data->ci_setconfig.num_seid + 1;
|
|
|
|
UINT8 avdt_handle = p_data->ci_setconfig.avdt_handle;
|
|
|
|
UINT8 *p_seid = p_data->ci_setconfig.p_seid;
|
|
|
|
int i;
|
|
|
|
UINT8 local_sep;
|
|
|
|
|
|
|
|
/* we like this codec_type. find the sep_idx */
|
2017-03-17 14:46:49 +00:00
|
|
|
local_sep = bta_av_get_scb_sep_type(p_scb, avdt_handle);
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_av_adjust_seps_idx(p_scb, avdt_handle);
|
|
|
|
APPL_TRACE_DEBUG("bta_av_setconfig_rsp: sep_idx: %d cur_psc_mask:0x%x", p_scb->sep_idx, p_scb->cur_psc_mask);
|
|
|
|
|
|
|
|
if ((AVDT_TSEP_SNK == local_sep) && (p_data->ci_setconfig.err_code == AVDT_SUCCESS) &&
|
2017-03-17 14:46:49 +00:00
|
|
|
(p_scb->seps[p_scb->sep_idx].p_app_data_cback != NULL))
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->seps[p_scb->sep_idx].p_app_data_cback(BTA_AV_MEDIA_SINK_CFG_EVT,
|
2017-03-17 14:46:49 +00:00
|
|
|
(tBTA_AV_MEDIA *)p_scb->cfg.codec_info);
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
AVDT_ConfigRsp(p_scb->avdt_handle, p_scb->avdt_label, p_data->ci_setconfig.err_code,
|
|
|
|
p_data->ci_setconfig.category);
|
|
|
|
|
|
|
|
bta_sys_stop_timer(&bta_av_cb.sig_tmr);
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_data->ci_setconfig.err_code == AVDT_SUCCESS) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->wait = BTA_AV_WAIT_ACP_CAPS_ON;
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_data->ci_setconfig.recfg_needed) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->role |= BTA_AV_ROLE_SUSPEND_OPT;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
APPL_TRACE_DEBUG("bta_av_setconfig_rsp recfg_needed:%d role:x%x num:%d",
|
2017-03-17 14:46:49 +00:00
|
|
|
p_data->ci_setconfig.recfg_needed, p_scb->role, num);
|
2016-11-02 11:40:46 +00:00
|
|
|
/* callout module tells BTA the number of "good" SEPs and their SEIDs.
|
|
|
|
* getcap on these SEID */
|
|
|
|
p_scb->num_seps = num;
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->cur_psc_mask & AVDT_PSC_DELAY_RPT) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->avdt_version = AVDT_VERSION_SYNC;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->codec_type == BTA_AV_CODEC_SBC || num > 1) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* if SBC is used by the SNK as INT, discover req is not sent in bta_av_config_ind.
|
|
|
|
* call disc_res now */
|
2017-03-17 14:46:49 +00:00
|
|
|
/* this is called in A2DP SRC path only, In case of SINK we don't need it */
|
2016-11-02 11:40:46 +00:00
|
|
|
if (local_sep == AVDT_TSEP_SRC)
|
|
|
|
p_scb->p_cos->disc_res(p_scb->hndl, num, num, 0, p_scb->peer_addr,
|
2017-03-17 14:46:49 +00:00
|
|
|
UUID_SERVCLASS_AUDIO_SOURCE);
|
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* we do not know the peer device and it is using non-SBC codec
|
|
|
|
* we need to know all the SEPs on SNK */
|
|
|
|
bta_av_discover_req(p_scb, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
for (i = 1; i < num; i++) {
|
|
|
|
APPL_TRACE_DEBUG("sep_info[%d] SEID: %d", i, p_seid[i - 1]);
|
2016-11-02 11:40:46 +00:00
|
|
|
/* initialize the sep_info[] to get capabilities */
|
|
|
|
p_scb->sep_info[i].in_use = FALSE;
|
|
|
|
p_scb->sep_info[i].tsep = AVDT_TSEP_SNK;
|
|
|
|
p_scb->sep_info[i].media_type = p_scb->media_type;
|
2017-03-17 14:46:49 +00:00
|
|
|
p_scb->sep_info[i].seid = p_seid[i - 1];
|
2016-11-02 11:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* only in case of local sep as SRC we need to look for other SEPs, In case of SINK we don't */
|
2017-03-17 14:46:49 +00:00
|
|
|
if (local_sep == AVDT_TSEP_SRC) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* Make sure UUID has been initialized... */
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->uuid_int == 0) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->uuid_int = p_scb->open_api.uuid;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_av_next_getcap(p_scb, p_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_str_opened
|
|
|
|
**
|
|
|
|
** Description Stream opened OK (incoming/outgoing).
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_str_opened (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
tBTA_AV_CONN_CHG msg;
|
|
|
|
tBTA_AV_OPEN open;
|
|
|
|
UINT8 *p;
|
|
|
|
UINT16 mtu;
|
|
|
|
|
|
|
|
msg.hdr.layer_specific = p_scb->hndl;
|
|
|
|
msg.is_up = TRUE;
|
|
|
|
bdcpy(msg.peer_addr, p_scb->peer_addr);
|
|
|
|
p_scb->l2c_cid = AVDT_GetL2CapChannel(p_scb->avdt_handle);
|
|
|
|
bta_av_conn_chg((tBTA_AV_DATA *) &msg);
|
|
|
|
/* set the congestion flag, so AV would not send media packets by accident */
|
|
|
|
p_scb->cong = TRUE;
|
|
|
|
|
|
|
|
|
|
|
|
p_scb->stream_mtu = p_data->str_msg.msg.open_ind.peer_mtu - AVDT_MEDIA_HDR_SIZE;
|
|
|
|
mtu = bta_av_chk_mtu(p_scb, p_scb->stream_mtu);
|
|
|
|
APPL_TRACE_DEBUG("bta_av_str_opened l2c_cid: 0x%x stream_mtu: %d mtu: %d",
|
2017-03-17 14:46:49 +00:00
|
|
|
p_scb->l2c_cid, p_scb->stream_mtu, mtu);
|
|
|
|
if (mtu == 0 || mtu > p_scb->stream_mtu) {
|
2016-11-02 11:40:46 +00:00
|
|
|
mtu = p_scb->stream_mtu;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
/* Set the media channel as medium priority */
|
|
|
|
L2CA_SetTxPriority(p_scb->l2c_cid, L2CAP_CHNL_PRIORITY_MEDIUM);
|
|
|
|
L2CA_SetChnlFlushability (p_scb->l2c_cid, TRUE);
|
|
|
|
|
|
|
|
bta_sys_conn_open(BTA_ID_AV, p_scb->app_id, p_scb->peer_addr);
|
|
|
|
memset(&p_scb->q_info, 0, sizeof(tBTA_AV_Q_INFO));
|
|
|
|
|
|
|
|
p_scb->l2c_bufs = 0;
|
|
|
|
p_scb->p_cos->open(p_scb->hndl,
|
2017-03-17 14:46:49 +00:00
|
|
|
p_scb->codec_type, p_scb->cfg.codec_info, mtu);
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
/* TODO check if other audio channel is open.
|
|
|
|
* If yes, check if reconfig is needed
|
|
|
|
* Rigt now we do not do this kind of checking.
|
|
|
|
* BTA-AV is INT for 2nd audio connection.
|
|
|
|
* The application needs to make sure the current codec_info is proper.
|
|
|
|
* If one audio connection is open and another SNK attempts to connect to AV,
|
|
|
|
* the connection will be rejected.
|
|
|
|
*/
|
|
|
|
/* check if other audio channel is started. If yes, start */
|
|
|
|
bdcpy(open.bd_addr, p_scb->peer_addr);
|
|
|
|
open.chnl = p_scb->chnl;
|
|
|
|
open.hndl = p_scb->hndl;
|
|
|
|
open.status = BTA_AV_SUCCESS;
|
|
|
|
open.starting = bta_av_chk_start(p_scb);
|
|
|
|
open.edr = 0;
|
2017-03-17 14:46:49 +00:00
|
|
|
if ( NULL != (p = BTM_ReadRemoteFeatures(p_scb->peer_addr))) {
|
|
|
|
if (HCI_EDR_ACL_2MPS_SUPPORTED(p)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
open.edr |= BTA_AV_EDR_2MBPS;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
|
|
|
if (HCI_EDR_ACL_3MPS_SUPPORTED(p)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
open.edr |= BTA_AV_EDR_3MBPS;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
}
|
|
|
|
#if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE)
|
|
|
|
bta_ar_avdt_conn(BTA_ID_AV, open.bd_addr);
|
|
|
|
#endif
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->seps[p_scb->sep_idx].tsep == AVDT_TSEP_SRC ) {
|
2016-11-02 11:40:46 +00:00
|
|
|
open.sep = AVDT_TSEP_SNK;
|
2017-03-17 14:46:49 +00:00
|
|
|
} else if (p_scb->seps[p_scb->sep_idx].tsep == AVDT_TSEP_SNK ) {
|
2016-11-02 11:40:46 +00:00
|
|
|
open.sep = AVDT_TSEP_SRC;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
(*bta_av_cb.p_cback)(BTA_AV_OPEN_EVT, (tBTA_AV *) &open);
|
2017-03-17 14:46:49 +00:00
|
|
|
if (open.starting) {
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_av_ssm_execute(p_scb, BTA_AV_AP_START_EVT, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
#if 0 /* TODO: implement the property enable/disable */
|
2016-11-02 11:40:46 +00:00
|
|
|
// This code is used to pass PTS TC for AVDTP ABORT
|
|
|
|
char value[PROPERTY_VALUE_MAX] = {0};
|
|
|
|
if ((property_get("bluetooth.pts.force_a2dp_abort", value, "false"))
|
2017-03-17 14:46:49 +00:00
|
|
|
&& (!strcmp(value, "true"))) {
|
2016-11-02 11:40:46 +00:00
|
|
|
APPL_TRACE_ERROR ("%s: Calling AVDT_AbortReq", __func__);
|
|
|
|
AVDT_AbortReq(p_scb->avdt_handle);
|
|
|
|
}
|
|
|
|
#endif /* #if 0*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_security_ind
|
|
|
|
**
|
|
|
|
** Description Handle an AVDTP security indication.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_security_ind (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
tBTA_AV_PROTECT_REQ protect_req;
|
|
|
|
|
|
|
|
p_scb->avdt_label = p_data->str_msg.msg.hdr.label;
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (bta_av_cb.features & BTA_AV_FEAT_PROTECT) {
|
2016-11-02 11:40:46 +00:00
|
|
|
protect_req.chnl = p_scb->chnl;
|
|
|
|
protect_req.hndl = p_scb->hndl;
|
|
|
|
/*
|
|
|
|
APPL_TRACE_EVENT("sec ind handle: x%x", protect_req.hndl);
|
|
|
|
*/
|
|
|
|
protect_req.p_data = p_data->str_msg.msg.security_ind.p_data;
|
|
|
|
protect_req.len = p_data->str_msg.msg.security_ind.len;
|
|
|
|
|
|
|
|
(*bta_av_cb.p_cback)(BTA_AV_PROTECT_REQ_EVT, (tBTA_AV *) &protect_req);
|
|
|
|
}
|
|
|
|
/* app doesn't support security indication; respond with failure */
|
2017-03-17 14:46:49 +00:00
|
|
|
else {
|
2016-11-02 11:40:46 +00:00
|
|
|
AVDT_SecurityRsp(p_scb->avdt_handle, p_scb->avdt_label, AVDT_ERR_NSC, NULL, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_security_cfm
|
|
|
|
**
|
|
|
|
** Description Handle an AVDTP security confirm.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_security_cfm (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
tBTA_AV_PROTECT_RSP protect_rsp;
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (bta_av_cb.features & BTA_AV_FEAT_PROTECT) {
|
2016-11-02 11:40:46 +00:00
|
|
|
protect_rsp.chnl = p_scb->chnl;
|
|
|
|
protect_rsp.hndl = p_scb->hndl;
|
|
|
|
protect_rsp.p_data = p_data->str_msg.msg.security_cfm.p_data;
|
|
|
|
protect_rsp.len = p_data->str_msg.msg.security_cfm.len;
|
2017-03-17 14:46:49 +00:00
|
|
|
protect_rsp.err_code = p_data->str_msg.msg.hdr.err_code;
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
(*bta_av_cb.p_cback)(BTA_AV_PROTECT_RSP_EVT, (tBTA_AV *) &protect_rsp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_do_close
|
|
|
|
**
|
|
|
|
** Description Close stream.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_do_close (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
UNUSED(p_data);
|
|
|
|
|
|
|
|
/* stop stream if started */
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->co_started) {
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_av_str_stopped(p_scb, NULL);
|
|
|
|
}
|
|
|
|
bta_sys_stop_timer(&bta_av_cb.sig_tmr);
|
|
|
|
|
|
|
|
/* close stream */
|
|
|
|
p_scb->started = FALSE;
|
|
|
|
|
|
|
|
/* drop the buffers queued in L2CAP */
|
|
|
|
L2CA_FlushChannel (p_scb->l2c_cid, L2CAP_FLUSH_CHANS_ALL);
|
|
|
|
|
|
|
|
AVDT_CloseReq(p_scb->avdt_handle);
|
|
|
|
/* just in case that the link is congested, link is flow controled by peer or
|
|
|
|
* for whatever reason the the close request can not be sent in time.
|
|
|
|
* when this timer expires, AVDT_DisconnectReq will be called to disconnect the link
|
|
|
|
*/
|
|
|
|
bta_sys_start_timer(&p_scb->timer,
|
|
|
|
(UINT16)BTA_AV_API_CLOSE_EVT,
|
|
|
|
BTA_AV_CLOSE_REQ_TIME_VAL);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_connect_req
|
|
|
|
**
|
|
|
|
** Description Connect AVDTP connection.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_connect_req (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
UNUSED(p_data);
|
|
|
|
|
|
|
|
utl_freebuf((void **) &p_scb->p_disc_db);
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->coll_mask & BTA_AV_COLL_INC_TMR) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* SNK initiated L2C connection while SRC was doing SDP. */
|
|
|
|
/* Wait until timeout to check if SNK starts signalling. */
|
|
|
|
APPL_TRACE_EVENT("bta_av_connect_req: coll_mask = 0x%2X", p_scb->coll_mask);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AVDT_ConnectReq(p_scb->peer_addr, p_scb->sec_mask, bta_av_dt_cback[p_scb->hdi]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_sdp_failed
|
|
|
|
**
|
|
|
|
** Description Service discovery failed.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_sdp_failed (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
2017-03-17 14:46:49 +00:00
|
|
|
if (!p_scb->open_status) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->open_status = BTA_AV_FAIL_SDP;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
utl_freebuf((void **) &p_scb->p_disc_db);
|
|
|
|
bta_av_str_closed(p_scb, p_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_disc_results
|
|
|
|
**
|
|
|
|
** Description Handle the AVDTP discover results. Search through the
|
|
|
|
** results and find the first available stream, and get
|
|
|
|
** its capabilities.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_disc_results (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
2017-03-17 14:46:49 +00:00
|
|
|
UINT8 num_snks = 0, num_srcs = 0, i;
|
2016-11-02 11:40:46 +00:00
|
|
|
/* our uuid in case we initiate connection */
|
|
|
|
UINT16 uuid_int = p_scb->uuid_int;
|
|
|
|
|
|
|
|
APPL_TRACE_DEBUG(" initiator UUID 0x%x", uuid_int);
|
|
|
|
/* store number of stream endpoints returned */
|
|
|
|
p_scb->num_seps = p_data->str_msg.msg.discover_cfm.num_seps;
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
for (i = 0; i < p_scb->num_seps; i++) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* steam not in use, is a sink, and is audio */
|
|
|
|
if ((p_scb->sep_info[i].in_use == FALSE) &&
|
2017-03-17 14:46:49 +00:00
|
|
|
(p_scb->sep_info[i].media_type == p_scb->media_type)) {
|
|
|
|
if ((p_scb->sep_info[i].tsep == AVDT_TSEP_SNK) &&
|
|
|
|
(uuid_int == UUID_SERVCLASS_AUDIO_SOURCE)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
num_snks++;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if ((p_scb->sep_info[i].tsep == AVDT_TSEP_SRC) &&
|
|
|
|
(uuid_int == UUID_SERVCLASS_AUDIO_SINK)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
num_srcs++;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p_scb->p_cos->disc_res(p_scb->hndl, p_scb->num_seps, num_snks, num_srcs, p_scb->peer_addr,
|
2017-03-17 14:46:49 +00:00
|
|
|
uuid_int);
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->num_disc_snks = num_snks;
|
|
|
|
p_scb->num_disc_srcs = num_srcs;
|
|
|
|
|
|
|
|
/* if we got any */
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->num_seps > 0) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* initialize index into discovery results */
|
|
|
|
p_scb->sep_info_idx = 0;
|
|
|
|
|
|
|
|
/* get the capabilities of the first available stream */
|
|
|
|
bta_av_next_getcap(p_scb, p_data);
|
|
|
|
}
|
|
|
|
/* else we got discover response but with no streams; we're done */
|
2017-03-17 14:46:49 +00:00
|
|
|
else {
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_av_ssm_execute(p_scb, BTA_AV_STR_DISC_FAIL_EVT, p_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_disc_res_as_acp
|
|
|
|
**
|
|
|
|
** Description Handle the AVDTP discover results. Search through the
|
|
|
|
** results and find the first available stream, and get
|
|
|
|
** its capabilities.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_disc_res_as_acp (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
UINT8 num_snks = 0, i;
|
|
|
|
|
|
|
|
/* store number of stream endpoints returned */
|
|
|
|
p_scb->num_seps = p_data->str_msg.msg.discover_cfm.num_seps;
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
for (i = 0; i < p_scb->num_seps; i++) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* steam is a sink, and is audio */
|
|
|
|
if ((p_scb->sep_info[i].tsep == AVDT_TSEP_SNK) &&
|
2017-03-17 14:46:49 +00:00
|
|
|
(p_scb->sep_info[i].media_type == p_scb->media_type)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->sep_info[i].in_use = FALSE;
|
|
|
|
num_snks++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p_scb->p_cos->disc_res(p_scb->hndl, p_scb->num_seps, num_snks, 0, p_scb->peer_addr,
|
2017-03-17 14:46:49 +00:00
|
|
|
UUID_SERVCLASS_AUDIO_SOURCE);
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->num_disc_snks = num_snks;
|
|
|
|
p_scb->num_disc_srcs = 0;
|
|
|
|
|
|
|
|
/* if we got any */
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->num_seps > 0) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* initialize index into discovery results */
|
|
|
|
p_scb->sep_info_idx = 0;
|
|
|
|
|
|
|
|
/* get the capabilities of the first available stream */
|
|
|
|
bta_av_next_getcap(p_scb, p_data);
|
|
|
|
}
|
|
|
|
/* else we got discover response but with no streams; we're done */
|
2017-03-17 14:46:49 +00:00
|
|
|
else {
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_av_ssm_execute(p_scb, BTA_AV_STR_DISC_FAIL_EVT, p_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_save_caps
|
|
|
|
**
|
|
|
|
** Description report the SNK SEP capabilities to application
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_save_caps(tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
tAVDT_CFG cfg;
|
|
|
|
tAVDT_SEP_INFO *p_info = &p_scb->sep_info[p_scb->sep_info_idx];
|
|
|
|
UINT8 old_wait = p_scb->wait;
|
|
|
|
BOOLEAN getcap_done = FALSE;
|
|
|
|
|
|
|
|
APPL_TRACE_DEBUG("bta_av_save_caps num_seps:%d sep_info_idx:%d wait:x%x",
|
2017-03-17 14:46:49 +00:00
|
|
|
p_scb->num_seps, p_scb->sep_info_idx, p_scb->wait);
|
2016-11-02 11:40:46 +00:00
|
|
|
memcpy(&cfg, p_scb->p_cap, sizeof(tAVDT_CFG));
|
|
|
|
/* let application know the capability of the SNK */
|
|
|
|
p_scb->p_cos->getcfg(p_scb->hndl, cfg.codec_info[BTA_AV_CODEC_TYPE_IDX],
|
2017-03-17 14:46:49 +00:00
|
|
|
cfg.codec_info, &p_scb->sep_info_idx, p_info->seid,
|
|
|
|
&cfg.num_protect, cfg.protect_info);
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
p_scb->sep_info_idx++;
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->num_seps > p_scb->sep_info_idx) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* Some devices have seps at the end of the discover list, which is not */
|
|
|
|
/* matching media type(video not audio). */
|
|
|
|
/* In this case, we are done with getcap without sending another */
|
|
|
|
/* request to AVDT. */
|
2017-03-17 14:46:49 +00:00
|
|
|
if (!bta_av_next_getcap(p_scb, p_data)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
getcap_done = TRUE;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
getcap_done = TRUE;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (getcap_done) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* we are done getting capabilities. restore the p_cb->sep_info_idx */
|
|
|
|
p_scb->sep_info_idx = 0;
|
2017-03-17 14:46:49 +00:00
|
|
|
p_scb->wait &= ~(BTA_AV_WAIT_ACP_CAPS_ON | BTA_AV_WAIT_ACP_CAPS_STARTED);
|
|
|
|
if (old_wait & BTA_AV_WAIT_ACP_CAPS_STARTED) {
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_av_start_ok (p_scb, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_set_use_rc
|
|
|
|
**
|
|
|
|
** Description set to use AVRC for this stream control block.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_set_use_rc (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
UNUSED(p_data);
|
|
|
|
|
|
|
|
p_scb->use_rc = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_cco_close
|
|
|
|
**
|
|
|
|
** Description call close call-out function.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_cco_close (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
UINT16 mtu;
|
|
|
|
UNUSED(p_data);
|
|
|
|
|
|
|
|
mtu = bta_av_chk_mtu(p_scb, BTA_AV_MAX_A2DP_MTU);
|
|
|
|
|
|
|
|
p_scb->p_cos->close(p_scb->hndl, p_scb->codec_type, mtu);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_open_failed
|
|
|
|
**
|
|
|
|
** Description Failed to open an AVDT stream
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_open_failed (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
|
|
|
|
BOOLEAN is_av_opened = FALSE;
|
2017-03-17 14:46:49 +00:00
|
|
|
tBTA_AV_SCB *p_opened_scb = NULL;
|
2016-11-02 11:40:46 +00:00
|
|
|
UINT8 idx;
|
|
|
|
tBTA_AV_OPEN open;
|
|
|
|
|
|
|
|
APPL_TRACE_DEBUG("bta_av_open_failed");
|
|
|
|
p_scb->open_status = BTA_AV_FAIL_STREAM;
|
|
|
|
bta_av_cco_close(p_scb, p_data);
|
|
|
|
|
|
|
|
/* check whether there is already an opened audio or video connection with the same device */
|
2017-03-17 14:46:49 +00:00
|
|
|
for (idx = 0; (idx < BTA_AV_NUM_STRS) && (is_av_opened == FALSE); idx++ ) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_opened_scb = bta_av_cb.p_scb[idx];
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_opened_scb && (p_opened_scb->state == BTA_AV_OPEN_SST) && (!bdcmp(p_opened_scb->peer_addr, p_scb->peer_addr )) ) {
|
2016-11-02 11:40:46 +00:00
|
|
|
is_av_opened = TRUE;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if there is already an active AV connnection with the same bd_addr,
|
|
|
|
don't send disconnect req, just report the open event with BTA_AV_FAIL_GET_CAP status */
|
2017-03-17 14:46:49 +00:00
|
|
|
if (is_av_opened == TRUE) {
|
2016-11-02 11:40:46 +00:00
|
|
|
bdcpy(open.bd_addr, p_scb->peer_addr);
|
|
|
|
open.chnl = p_scb->chnl;
|
|
|
|
open.hndl = p_scb->hndl;
|
|
|
|
open.status = BTA_AV_FAIL_GET_CAP;
|
|
|
|
open.starting = bta_av_chk_start(p_scb);
|
|
|
|
open.edr = 0;
|
|
|
|
/* set the state back to initial state */
|
|
|
|
bta_av_set_scb_sst_init(p_scb);
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->seps[p_scb->sep_idx].tsep == AVDT_TSEP_SRC ) {
|
2016-11-02 11:40:46 +00:00
|
|
|
open.sep = AVDT_TSEP_SNK;
|
2017-03-17 14:46:49 +00:00
|
|
|
} else if (p_scb->seps[p_scb->sep_idx].tsep == AVDT_TSEP_SNK ) {
|
2016-11-02 11:40:46 +00:00
|
|
|
open.sep = AVDT_TSEP_SRC;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
(*bta_av_cb.p_cback)(BTA_AV_OPEN_EVT, (tBTA_AV *) &open);
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
AVDT_DisconnectReq(p_scb->peer_addr, bta_av_dt_cback[p_scb->hdi]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_getcap_results
|
|
|
|
**
|
|
|
|
** Description Handle the AVDTP get capabilities results. Check the codec
|
|
|
|
** type and see if it matches ours. If it does not, get the
|
|
|
|
** capabilities of the next stream, if any.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_getcap_results (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
tAVDT_CFG cfg;
|
|
|
|
UINT8 media_type;
|
|
|
|
tAVDT_SEP_INFO *p_info = &p_scb->sep_info[p_scb->sep_info_idx];
|
|
|
|
UINT16 uuid_int; /* UUID for which connection was initiatied */
|
|
|
|
|
|
|
|
memcpy(&cfg, &p_scb->cfg, sizeof(tAVDT_CFG));
|
|
|
|
cfg.num_codec = 1;
|
|
|
|
cfg.num_protect = p_scb->p_cap->num_protect;
|
|
|
|
memcpy(cfg.codec_info, p_scb->p_cap->codec_info, AVDT_CODEC_SIZE);
|
|
|
|
memcpy(cfg.protect_info, p_scb->p_cap->protect_info, AVDT_PROTECT_SIZE);
|
|
|
|
media_type = p_scb->p_cap->codec_info[BTA_AV_MEDIA_TYPE_IDX] >> 4;
|
|
|
|
|
|
|
|
APPL_TRACE_DEBUG("num_codec %d", p_scb->p_cap->num_codec);
|
|
|
|
APPL_TRACE_DEBUG("media type x%x, x%x", media_type, p_scb->media_type);
|
|
|
|
#if AVDT_MULTIPLEXING == TRUE
|
|
|
|
APPL_TRACE_DEBUG("mux x%x, x%x", cfg.mux_mask, p_scb->p_cap->mux_mask);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* if codec present and we get a codec configuration */
|
|
|
|
if ((p_scb->p_cap->num_codec != 0) &&
|
2017-03-17 14:46:49 +00:00
|
|
|
(media_type == p_scb->media_type) &&
|
|
|
|
(p_scb->p_cos->getcfg(p_scb->hndl, p_scb->p_cap->codec_info[BTA_AV_CODEC_TYPE_IDX],
|
|
|
|
cfg.codec_info, &p_scb->sep_info_idx, p_info->seid,
|
|
|
|
&cfg.num_protect, cfg.protect_info) == 0)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
#if AVDT_MULTIPLEXING == TRUE
|
|
|
|
cfg.mux_mask &= p_scb->p_cap->mux_mask;
|
|
|
|
APPL_TRACE_DEBUG("mux_mask used x%x", cfg.mux_mask);
|
|
|
|
#endif
|
|
|
|
/* save copy of codec type and configuration */
|
|
|
|
p_scb->codec_type = cfg.codec_info[BTA_AV_CODEC_TYPE_IDX];
|
|
|
|
memcpy(&p_scb->cfg, &cfg, sizeof(tAVDT_CFG));
|
|
|
|
|
|
|
|
uuid_int = p_scb->uuid_int;
|
|
|
|
APPL_TRACE_DEBUG(" initiator UUID = 0x%x ", uuid_int);
|
2017-03-17 14:46:49 +00:00
|
|
|
if (uuid_int == UUID_SERVCLASS_AUDIO_SOURCE) {
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_av_adjust_seps_idx(p_scb, bta_av_get_scb_handle(p_scb, AVDT_TSEP_SRC));
|
2017-03-17 14:46:49 +00:00
|
|
|
} else if (uuid_int == UUID_SERVCLASS_AUDIO_SINK) {
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_av_adjust_seps_idx(p_scb, bta_av_get_scb_handle(p_scb, AVDT_TSEP_SNK));
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
/* use only the services peer supports */
|
|
|
|
cfg.psc_mask &= p_scb->p_cap->psc_mask;
|
|
|
|
p_scb->cur_psc_mask = cfg.psc_mask;
|
|
|
|
|
|
|
|
if ((uuid_int == UUID_SERVCLASS_AUDIO_SINK) &&
|
2017-03-17 14:46:49 +00:00
|
|
|
(p_scb->seps[p_scb->sep_idx].p_app_data_cback != NULL)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
APPL_TRACE_DEBUG(" Configure Deoder for Sink Connection ");
|
|
|
|
p_scb->seps[p_scb->sep_idx].p_app_data_cback(BTA_AV_MEDIA_SINK_CFG_EVT,
|
2017-03-17 14:46:49 +00:00
|
|
|
(tBTA_AV_MEDIA *)p_scb->cfg.codec_info);
|
2016-11-02 11:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* open the stream */
|
|
|
|
AVDT_OpenReq(p_scb->seps[p_scb->sep_idx].av_handle, p_scb->peer_addr,
|
|
|
|
p_scb->sep_info[p_scb->sep_info_idx].seid, &cfg);
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (!bta_av_is_rcfg_sst(p_scb)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* free capabilities buffer */
|
|
|
|
utl_freebuf((void **) &p_scb->p_cap);
|
|
|
|
}
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* try the next stream, if any */
|
|
|
|
p_scb->sep_info_idx++;
|
|
|
|
bta_av_next_getcap(p_scb, p_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_setconfig_rej
|
|
|
|
**
|
|
|
|
** Description Send AVDTP set config reject.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_setconfig_rej (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
tBTA_AV_REJECT reject;
|
|
|
|
UINT8 avdt_handle = p_data->ci_setconfig.avdt_handle;
|
|
|
|
|
|
|
|
bta_av_adjust_seps_idx(p_scb, avdt_handle);
|
2017-03-17 14:46:49 +00:00
|
|
|
APPL_TRACE_DEBUG("bta_av_setconfig_rej: sep_idx: %d", p_scb->sep_idx);
|
2016-11-02 11:40:46 +00:00
|
|
|
AVDT_ConfigRsp(p_scb->avdt_handle, p_scb->avdt_label, AVDT_ERR_UNSUP_CFG, 0);
|
|
|
|
|
|
|
|
bdcpy(reject.bd_addr, p_data->str_msg.bd_addr);
|
|
|
|
reject.hndl = p_scb->hndl;
|
|
|
|
(*bta_av_cb.p_cback)(BTA_AV_REJECT_EVT, (tBTA_AV *) &reject);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_discover_req
|
|
|
|
**
|
|
|
|
** Description Send an AVDTP discover request to the peer.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_discover_req (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
UNUSED(p_data);
|
|
|
|
|
|
|
|
/* send avdtp discover request */
|
|
|
|
|
|
|
|
AVDT_DiscoverReq(p_scb->peer_addr, p_scb->sep_info, BTA_AV_NUM_SEPS, bta_av_dt_cback[p_scb->hdi]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_conn_failed
|
|
|
|
**
|
|
|
|
** Description AVDTP connection failed.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_conn_failed (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
p_scb->open_status = BTA_AV_FAIL_STREAM;
|
|
|
|
bta_av_str_closed(p_scb, p_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_do_start
|
|
|
|
**
|
|
|
|
** Description Start stream.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_do_start (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
UINT8 policy = HCI_ENABLE_SNIFF_MODE;
|
|
|
|
UINT8 cur_role;
|
|
|
|
|
|
|
|
APPL_TRACE_DEBUG("bta_av_do_start sco_occupied:%d, role:x%x, started:%d", bta_av_cb.sco_occupied, p_scb->role, p_scb->started);
|
2017-03-17 14:46:49 +00:00
|
|
|
if (bta_av_cb.sco_occupied) {
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_av_start_failed(p_scb, p_data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* disallow role switch during streaming, only if we are the master role
|
|
|
|
* i.e. allow role switch, if we are slave.
|
|
|
|
* It would not hurt us, if the peer device wants us to be master */
|
|
|
|
if ((BTM_GetRole (p_scb->peer_addr, &cur_role) == BTM_SUCCESS) &&
|
2017-03-17 14:46:49 +00:00
|
|
|
(cur_role == BTM_ROLE_MASTER) ) {
|
2016-11-02 11:40:46 +00:00
|
|
|
policy |= HCI_ENABLE_MASTER_SLAVE_SWITCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
bta_sys_clear_policy(BTA_ID_AV, policy, p_scb->peer_addr);
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if ((p_scb->started == FALSE) && ((p_scb->role & BTA_AV_ROLE_START_INT) == 0)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->role |= BTA_AV_ROLE_START_INT;
|
|
|
|
bta_sys_busy(BTA_ID_AV, bta_av_cb.audio_open_cnt, p_scb->peer_addr);
|
|
|
|
|
|
|
|
AVDT_StartReq(&p_scb->avdt_handle, 1);
|
2017-03-17 14:46:49 +00:00
|
|
|
} else if (p_scb->started) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->role |= BTA_AV_ROLE_START_INT;
|
|
|
|
if ( p_scb->wait == 0 ) {
|
|
|
|
if (p_scb->role & BTA_AV_ROLE_SUSPEND) {
|
|
|
|
notify_start_failed(p_scb);
|
|
|
|
} else {
|
|
|
|
bta_av_start_ok(p_scb, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
APPL_TRACE_DEBUG("started %d role:x%x", p_scb->started, p_scb->role);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_str_stopped
|
|
|
|
**
|
|
|
|
** Description Stream stopped.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_str_stopped (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
tBTA_AV_SUSPEND suspend_rsp;
|
|
|
|
UINT8 start = p_scb->started;
|
|
|
|
BOOLEAN sus_evt = TRUE;
|
|
|
|
BT_HDR *p_buf;
|
|
|
|
UINT8 policy = HCI_ENABLE_SNIFF_MODE;
|
|
|
|
|
2016-12-26 12:35:28 +00:00
|
|
|
APPL_TRACE_ERROR("bta_av_str_stopped:audio_open_cnt=%d, p_data %p",
|
2017-03-17 14:46:49 +00:00
|
|
|
bta_av_cb.audio_open_cnt, p_data);
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
bta_sys_idle(BTA_ID_AV, bta_av_cb.audio_open_cnt, p_scb->peer_addr);
|
2017-03-17 14:46:49 +00:00
|
|
|
if ((bta_av_cb.features & BTA_AV_FEAT_MASTER) == 0 || bta_av_cb.audio_open_cnt == 1) {
|
2016-11-02 11:40:46 +00:00
|
|
|
policy |= HCI_ENABLE_MASTER_SLAVE_SWITCH;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_sys_set_policy(BTA_ID_AV, policy, p_scb->peer_addr);
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->co_started) {
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_av_stream_chg(p_scb, FALSE);
|
|
|
|
p_scb->co_started = FALSE;
|
|
|
|
|
|
|
|
p_scb->p_cos->stop(p_scb->hndl, p_scb->codec_type);
|
|
|
|
L2CA_SetFlushTimeout(p_scb->peer_addr, L2CAP_DEFAULT_FLUSH_TO);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if q_info.a2d_list is not empty, drop it now */
|
|
|
|
if (BTA_AV_CHNL_AUDIO == p_scb->chnl) {
|
2017-03-17 14:46:49 +00:00
|
|
|
while (!list_is_empty(p_scb->a2d_list)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_buf = (BT_HDR *)list_front(p_scb->a2d_list);
|
|
|
|
list_remove(p_scb->a2d_list, p_buf);
|
2017-08-17 13:13:45 +00:00
|
|
|
osi_free(p_buf);
|
2016-11-02 11:40:46 +00:00
|
|
|
}
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
/* drop the audio buffers queued in L2CAP */
|
|
|
|
if (p_data && p_data->api_stop.flush) {
|
2016-11-02 11:40:46 +00:00
|
|
|
L2CA_FlushChannel (p_scb->l2c_cid, L2CAP_FLUSH_CHANS_ALL);
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
suspend_rsp.chnl = p_scb->chnl;
|
|
|
|
suspend_rsp.hndl = p_scb->hndl;
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_data && p_data->api_stop.suspend) {
|
2016-11-02 11:40:46 +00:00
|
|
|
APPL_TRACE_DEBUG("suspending: %d, sup:%d", start, p_scb->suspend_sup);
|
2017-03-17 14:46:49 +00:00
|
|
|
if ((start) && (p_scb->suspend_sup)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
sus_evt = FALSE;
|
|
|
|
p_scb->l2c_bufs = 0;
|
|
|
|
AVDT_SuspendReq(&p_scb->avdt_handle, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send SUSPEND_EVT event only if not in reconfiguring state and sus_evt is TRUE*/
|
2017-03-17 14:46:49 +00:00
|
|
|
if ((sus_evt) && (p_scb->state != BTA_AV_RCFG_SST)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
suspend_rsp.status = BTA_AV_SUCCESS;
|
|
|
|
suspend_rsp.initiator = TRUE;
|
|
|
|
(*bta_av_cb.p_cback)(BTA_AV_SUSPEND_EVT, (tBTA_AV *) &suspend_rsp);
|
|
|
|
}
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
suspend_rsp.status = BTA_AV_SUCCESS;
|
|
|
|
suspend_rsp.initiator = TRUE;
|
|
|
|
APPL_TRACE_EVENT("bta_av_str_stopped status %d", suspend_rsp.status);
|
|
|
|
|
|
|
|
/* send STOP_EVT event only if not in reconfiguring state */
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->state != BTA_AV_RCFG_SST) {
|
2016-11-02 11:40:46 +00:00
|
|
|
(*bta_av_cb.p_cback)(BTA_AV_STOP_EVT, (tBTA_AV *) &suspend_rsp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_reconfig
|
|
|
|
**
|
|
|
|
** Description process the reconfigure request.
|
|
|
|
** save the parameter in control block and
|
|
|
|
** suspend, reconfigure or close the stream
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_reconfig (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
tAVDT_CFG *p_cfg;
|
|
|
|
tBTA_AV_API_STOP stop;
|
|
|
|
tBTA_AV_RECONFIG evt;
|
|
|
|
tBTA_AV_API_RCFG *p_rcfg = &p_data->api_reconfig;
|
|
|
|
|
|
|
|
APPL_TRACE_DEBUG("bta_av_reconfig r:%d, s:%d idx: %d (o:%d)",
|
2017-03-17 14:46:49 +00:00
|
|
|
p_scb->recfg_sup, p_scb->suspend_sup,
|
|
|
|
p_scb->rcfg_idx, p_scb->sep_info_idx);
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
p_scb->num_recfg = 0;
|
|
|
|
/* store the new configuration in control block */
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->p_cap == NULL) {
|
2017-08-17 13:13:45 +00:00
|
|
|
p_scb->p_cap = (tAVDT_CFG *) osi_malloc(sizeof(tAVDT_CFG));
|
2016-11-02 11:40:46 +00:00
|
|
|
}
|
2017-03-17 14:46:49 +00:00
|
|
|
if ((p_cfg = p_scb->p_cap) == NULL) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* report failure */
|
|
|
|
evt.status = BTA_AV_FAIL_RESOURCES;
|
|
|
|
evt.chnl = p_scb->chnl;
|
|
|
|
evt.hndl = p_scb->hndl;
|
|
|
|
(*bta_av_cb.p_cback)(BTA_AV_RECONFIG_EVT, (tBTA_AV *)&evt);
|
|
|
|
|
|
|
|
/* this event is not possible in this state.
|
|
|
|
* use it to bring the SSM back to open state */
|
|
|
|
bta_av_ssm_execute(p_scb, BTA_AV_SDP_DISC_OK_EVT, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*if(bta_av_cb.features & BTA_AV_FEAT_RCCT)*/
|
2017-03-17 14:46:49 +00:00
|
|
|
bta_sys_stop_timer(&p_scb->timer);
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
memcpy(p_cfg, &p_scb->cfg, sizeof(tAVDT_CFG));
|
|
|
|
p_cfg->num_protect = p_rcfg->num_protect;
|
|
|
|
memcpy(p_cfg->codec_info, p_rcfg->codec_info, AVDT_CODEC_SIZE);
|
|
|
|
memcpy(p_cfg->protect_info, p_rcfg->p_protect_info, p_rcfg->num_protect);
|
|
|
|
p_scb->rcfg_idx = p_rcfg->sep_info_idx;
|
|
|
|
p_scb->p_cap->psc_mask = p_scb->cur_psc_mask;
|
|
|
|
|
|
|
|
/* if the requested index differs from the current one, we can only close/open */
|
|
|
|
if ((p_scb->rcfg_idx == p_scb->sep_info_idx) &&
|
2017-03-17 14:46:49 +00:00
|
|
|
(p_rcfg->suspend) && (p_scb->recfg_sup) && (p_scb->suspend_sup)) {
|
|
|
|
if (p_scb->started) {
|
2016-11-02 11:40:46 +00:00
|
|
|
stop.flush = FALSE;
|
|
|
|
stop.suspend = TRUE;
|
|
|
|
bta_av_str_stopped(p_scb, (tBTA_AV_DATA *)&stop);
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
APPL_TRACE_DEBUG("Reconfig");
|
|
|
|
AVDT_ReconfigReq(p_scb->avdt_handle, p_scb->p_cap);
|
|
|
|
p_scb->p_cap->psc_mask = p_scb->cur_psc_mask;
|
|
|
|
}
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* close the stream */
|
|
|
|
APPL_TRACE_DEBUG("close/open num_protect: %d", p_cfg->num_protect);
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->started) {
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_av_str_stopped(p_scb, NULL);
|
|
|
|
p_scb->started = FALSE;
|
|
|
|
|
|
|
|
/* drop the buffers queued in L2CAP */
|
|
|
|
L2CA_FlushChannel (p_scb->l2c_cid, L2CAP_FLUSH_CHANS_ALL);
|
|
|
|
|
|
|
|
AVDT_CloseReq(p_scb->avdt_handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_data_path
|
|
|
|
**
|
|
|
|
** Description Handle stream data path.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_data_path (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
BT_HDR *p_buf = NULL;
|
|
|
|
UINT32 data_len;
|
|
|
|
UINT32 timestamp;
|
|
|
|
BOOLEAN new_buf = FALSE;
|
|
|
|
UINT8 m_pt = 0x60 | p_scb->codec_type;
|
|
|
|
tAVDT_DATA_OPT_MASK opt;
|
|
|
|
UNUSED(p_data);
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->cong) {
|
2016-11-02 11:40:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
APPL_TRACE_ERROR("q: %d", p_scb->l2c_bufs);
|
|
|
|
*/
|
|
|
|
//Always get the current number of bufs que'd up
|
|
|
|
p_scb->l2c_bufs = (UINT8)L2CA_FlushChannel (p_scb->l2c_cid, L2CAP_FLUSH_CHANS_GET);
|
|
|
|
|
|
|
|
if (!list_is_empty(p_scb->a2d_list)) {
|
|
|
|
p_buf = (BT_HDR *)list_front(p_scb->a2d_list);
|
|
|
|
list_remove(p_scb->a2d_list, p_buf);
|
2017-03-17 14:46:49 +00:00
|
|
|
/* use q_info.a2d data, read the timestamp */
|
2016-11-02 11:40:46 +00:00
|
|
|
timestamp = *(UINT32 *)(p_buf + 1);
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
new_buf = TRUE;
|
|
|
|
/* a2d_list empty, call co_data, dup data to other channels */
|
|
|
|
p_buf = (BT_HDR *)p_scb->p_cos->data(p_scb->codec_type, &data_len,
|
2017-03-17 14:46:49 +00:00
|
|
|
×tamp);
|
2016-11-02 11:40:46 +00:00
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_buf) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* use the offset area for the time stamp */
|
|
|
|
*(UINT32 *)(p_buf + 1) = timestamp;
|
|
|
|
|
|
|
|
/* dup the data to other channels */
|
|
|
|
bta_av_dup_audio_buf(p_scb, p_buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_buf) {
|
|
|
|
if (p_scb->l2c_bufs < (BTA_AV_QUEUE_DATA_CHK_NUM)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* there's a buffer, just queue it to L2CAP */
|
|
|
|
/* There's no need to increment it here, it is always read from L2CAP see above */
|
|
|
|
/* p_scb->l2c_bufs++; */
|
|
|
|
/*
|
|
|
|
APPL_TRACE_ERROR("qw: %d", p_scb->l2c_bufs);
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* opt is a bit mask, it could have several options set */
|
|
|
|
opt = AVDT_DATA_OPT_NONE;
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->no_rtp_hdr) {
|
2016-11-02 11:40:46 +00:00
|
|
|
opt |= AVDT_DATA_OPT_NO_RTP;
|
|
|
|
}
|
|
|
|
|
|
|
|
AVDT_WriteReqOpt(p_scb->avdt_handle, p_buf, timestamp, m_pt, opt);
|
|
|
|
p_scb->cong = TRUE;
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* there's a buffer, but L2CAP does not seem to be moving data */
|
2017-03-17 14:46:49 +00:00
|
|
|
if (new_buf) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* just got this buffer from co_data,
|
|
|
|
* put it in queue */
|
|
|
|
list_append(p_scb->a2d_list, p_buf);
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* just dequeue it from the a2d_list */
|
|
|
|
if (list_length(p_scb->a2d_list) < 3) {
|
|
|
|
/* put it back to the queue */
|
|
|
|
list_prepend(p_scb->a2d_list, p_buf);
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* too many buffers in a2d_list, drop it. */
|
|
|
|
bta_av_co_audio_drop(p_scb->hndl);
|
2017-08-17 13:13:45 +00:00
|
|
|
osi_free(p_buf);
|
2016-11-02 11:40:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_start_ok
|
|
|
|
**
|
|
|
|
** Description Stream started.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_start_ok (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
tBTA_AV_START start;
|
|
|
|
tBTA_AV_API_STOP stop;
|
|
|
|
BOOLEAN initiator = FALSE;
|
|
|
|
BOOLEAN suspend = FALSE;
|
|
|
|
UINT16 flush_to;
|
|
|
|
UINT8 new_role = p_scb->role;
|
|
|
|
BT_HDR hdr;
|
|
|
|
UINT8 policy = HCI_ENABLE_SNIFF_MODE;
|
|
|
|
UINT8 cur_role;
|
|
|
|
|
|
|
|
APPL_TRACE_DEBUG("bta_av_start_ok wait:x%x, role:x%x", p_scb->wait, p_scb->role);
|
|
|
|
|
|
|
|
p_scb->started = TRUE;
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->sco_suspend) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->sco_suspend = FALSE;
|
|
|
|
}
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (new_role & BTA_AV_ROLE_START_INT) {
|
2016-11-02 11:40:46 +00:00
|
|
|
initiator = TRUE;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
/* for A2DP SINK we do not send get_caps */
|
|
|
|
if ((p_scb->avdt_handle == p_scb->seps[p_scb->sep_idx].av_handle)
|
2017-03-17 14:46:49 +00:00
|
|
|
&& (p_scb->seps[p_scb->sep_idx].tsep == AVDT_TSEP_SNK)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->wait &= ~(BTA_AV_WAIT_ACP_CAPS_ON);
|
2017-03-17 14:46:49 +00:00
|
|
|
APPL_TRACE_DEBUG(" Local SEP type is SNK new wait is 0x%x", p_scb->wait);
|
2016-11-02 11:40:46 +00:00
|
|
|
}
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->wait & BTA_AV_WAIT_ROLE_SW_FAILED) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* role switch has failed */
|
|
|
|
p_scb->wait &= ~BTA_AV_WAIT_ROLE_SW_FAILED;
|
|
|
|
p_data = (tBTA_AV_DATA *)&hdr;
|
|
|
|
hdr.offset = BTA_AV_RS_FAIL;
|
|
|
|
}
|
|
|
|
APPL_TRACE_DEBUG("wait:x%x", p_scb->wait);
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_data && (p_data->hdr.offset != BTA_AV_RS_NONE)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->wait &= ~BTA_AV_WAIT_ROLE_SW_BITS;
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_data->hdr.offset == BTA_AV_RS_FAIL) {
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_sys_idle(BTA_ID_AV, bta_av_cb.audio_open_cnt, p_scb->peer_addr);
|
|
|
|
start.chnl = p_scb->chnl;
|
|
|
|
start.status = BTA_AV_FAIL_ROLE;
|
|
|
|
start.hndl = p_scb->hndl;
|
|
|
|
start.initiator = initiator;
|
|
|
|
(*bta_av_cb.p_cback)(BTA_AV_START_EVT, (tBTA_AV *) &start);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (!bta_av_link_role_ok(p_scb, A2D_SET_ONE_BIT)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->q_tag = BTA_AV_Q_TAG_START;
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* The wait flag may be set here while we are already master on the link */
|
|
|
|
/* this could happen if a role switch complete event occurred during reconfig */
|
|
|
|
/* if we are now master on the link, there is no need to wait for the role switch, */
|
|
|
|
/* complete anymore so we can clear the wait for role switch flag */
|
|
|
|
p_scb->wait &= ~BTA_AV_WAIT_ROLE_SW_BITS;
|
|
|
|
}
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->wait & (BTA_AV_WAIT_ROLE_SW_RES_OPEN | BTA_AV_WAIT_ROLE_SW_RES_START)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->wait |= BTA_AV_WAIT_ROLE_SW_STARTED;
|
|
|
|
p_scb->q_tag = BTA_AV_Q_TAG_START;
|
|
|
|
}
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->wait) {
|
2016-11-02 11:40:46 +00:00
|
|
|
APPL_TRACE_ERROR("wait:x%x q_tag:%d- not started", p_scb->wait, p_scb->q_tag);
|
|
|
|
/* Clear first bit of p_scb->wait and not to return from this point else
|
|
|
|
* HAL layer gets blocked. And if there is delay in Get Capability response as
|
|
|
|
* first bit of p_scb->wait is cleared hence it ensures bt_av_start_ok is not called
|
|
|
|
* again from bta_av_save_caps.
|
|
|
|
*/
|
|
|
|
p_scb->wait &= ~BTA_AV_WAIT_ACP_CAPS_ON;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* tell role manager to check M/S role */
|
|
|
|
bta_sys_conn_open(BTA_ID_AV, p_scb->app_id, p_scb->peer_addr);
|
|
|
|
|
|
|
|
bta_sys_busy(BTA_ID_AV, bta_av_cb.audio_open_cnt, p_scb->peer_addr);
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->media_type == AVDT_MEDIA_AUDIO) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* in normal logic, conns should be bta_av_cb.audio_count - 1,
|
|
|
|
* However, bta_av_stream_chg is not called to increase bta_av_cb.audio_count yet.
|
|
|
|
* If the code were to be re-arranged for some reasons, this number may need to be changed
|
|
|
|
*/
|
|
|
|
p_scb->co_started = bta_av_cb.audio_open_cnt;
|
|
|
|
flush_to = p_bta_av_cfg->p_audio_flush_to[p_scb->co_started - 1];
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
flush_to = p_bta_av_cfg->video_flush_to;
|
|
|
|
}
|
|
|
|
L2CA_SetFlushTimeout(p_scb->peer_addr, flush_to );
|
|
|
|
|
|
|
|
/* clear the congestion flag */
|
|
|
|
p_scb->cong = FALSE;
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (new_role & BTA_AV_ROLE_START_INT) {
|
2016-11-02 11:40:46 +00:00
|
|
|
new_role &= ~BTA_AV_ROLE_START_INT;
|
2017-03-17 14:46:49 +00:00
|
|
|
} else if ((new_role & BTA_AV_ROLE_AD_ACP) && (new_role & BTA_AV_ROLE_SUSPEND_OPT)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
suspend = TRUE;
|
|
|
|
}
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (!suspend) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->q_tag = BTA_AV_Q_TAG_STREAM;
|
|
|
|
bta_av_stream_chg(p_scb, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
/* If sink starts stream, disable sniff mode here */
|
2017-03-17 14:46:49 +00:00
|
|
|
if (!initiator) {
|
|
|
|
/* If souce is the master role, disable role switch during streaming.
|
|
|
|
* Otherwise allow role switch, if source is slave.
|
|
|
|
* Because it would not hurt source, if the peer device wants source to be master */
|
2016-11-02 11:40:46 +00:00
|
|
|
if ((BTM_GetRole (p_scb->peer_addr, &cur_role) == BTM_SUCCESS) &&
|
2017-03-17 14:46:49 +00:00
|
|
|
(cur_role == BTM_ROLE_MASTER) ) {
|
2016-11-02 11:40:46 +00:00
|
|
|
policy |= HCI_ENABLE_MASTER_SLAVE_SWITCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
bta_sys_clear_policy(BTA_ID_AV, policy, p_scb->peer_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
p_scb->role = new_role;
|
|
|
|
p_scb->role &= ~BTA_AV_ROLE_AD_ACP;
|
|
|
|
p_scb->role &= ~BTA_AV_ROLE_SUSPEND_OPT;
|
|
|
|
|
|
|
|
p_scb->no_rtp_hdr = FALSE;
|
|
|
|
p_scb->p_cos->start(p_scb->hndl, p_scb->codec_type, p_scb->cfg.codec_info, &p_scb->no_rtp_hdr);
|
|
|
|
p_scb->co_started = TRUE;
|
|
|
|
|
|
|
|
APPL_TRACE_DEBUG("bta_av_start_ok suspending: %d, role:x%x, init %d",
|
2017-03-17 14:46:49 +00:00
|
|
|
suspend, p_scb->role, initiator);
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
start.suspending = suspend;
|
|
|
|
start.initiator = initiator;
|
|
|
|
start.chnl = p_scb->chnl;
|
|
|
|
start.status = BTA_AV_SUCCESS;
|
|
|
|
start.hndl = p_scb->hndl;
|
|
|
|
(*bta_av_cb.p_cback)(BTA_AV_START_EVT, (tBTA_AV *) &start);
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (suspend) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->role |= BTA_AV_ROLE_SUSPEND;
|
|
|
|
p_scb->cong = TRUE; /* do not allow the media data to go through */
|
|
|
|
/* do not duplicate the media packets to this channel */
|
|
|
|
p_scb->p_cos->stop(p_scb->hndl, p_scb->codec_type);
|
|
|
|
p_scb->co_started = FALSE;
|
|
|
|
stop.flush = FALSE;
|
|
|
|
stop.suspend = TRUE;
|
|
|
|
bta_av_ssm_execute(p_scb, BTA_AV_AP_STOP_EVT, (tBTA_AV_DATA *)&stop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_start_failed
|
|
|
|
**
|
|
|
|
** Description Stream start failed.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_start_failed (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
UNUSED(p_data);
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->started == FALSE && p_scb->co_started == FALSE) {
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_sys_idle(BTA_ID_AV, bta_av_cb.audio_open_cnt, p_scb->peer_addr);
|
|
|
|
notify_start_failed(p_scb);
|
|
|
|
}
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
bta_sys_set_policy(BTA_ID_AV, (HCI_ENABLE_SNIFF_MODE | HCI_ENABLE_MASTER_SLAVE_SWITCH), p_scb->peer_addr);
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->sco_suspend = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_str_closed
|
|
|
|
**
|
|
|
|
** Description Stream closed.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_str_closed (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
tBTA_AV data;
|
|
|
|
tBTA_AV_EVT event;
|
|
|
|
UINT16 mtu;
|
|
|
|
UINT8 policy = HCI_ENABLE_SNIFF_MODE;
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if ((bta_av_cb.features & BTA_AV_FEAT_MASTER) == 0 || bta_av_cb.audio_open_cnt == 1) {
|
2016-11-02 11:40:46 +00:00
|
|
|
policy |= HCI_ENABLE_MASTER_SLAVE_SWITCH;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_sys_set_policy(BTA_ID_AV, policy, p_scb->peer_addr);
|
2017-03-17 14:46:49 +00:00
|
|
|
if (bta_av_cb.audio_open_cnt <= 1) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* last connection - restore the allow switch flag */
|
|
|
|
L2CA_SetDesireRole(L2CAP_ROLE_ALLOW_SWITCH);
|
|
|
|
}
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->open_status) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* must be failure when opening the stream */
|
|
|
|
bdcpy(data.open.bd_addr, p_scb->peer_addr);
|
|
|
|
data.open.status = p_scb->open_status;
|
|
|
|
data.open.chnl = p_scb->chnl;
|
|
|
|
data.open.hndl = p_scb->hndl;
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->seps[p_scb->sep_idx].tsep == AVDT_TSEP_SRC ) {
|
2016-11-02 11:40:46 +00:00
|
|
|
data.open.sep = AVDT_TSEP_SNK;
|
2017-03-17 14:46:49 +00:00
|
|
|
} else if (p_scb->seps[p_scb->sep_idx].tsep == AVDT_TSEP_SNK ) {
|
2016-11-02 11:40:46 +00:00
|
|
|
data.open.sep = AVDT_TSEP_SRC;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
|
|
|
|
event = BTA_AV_OPEN_EVT;
|
|
|
|
p_scb->open_status = BTA_AV_SUCCESS;
|
|
|
|
|
|
|
|
bta_sys_conn_close(BTA_ID_AV, p_scb->app_id, p_scb->peer_addr);
|
|
|
|
bta_av_cleanup(p_scb, p_data);
|
|
|
|
(*bta_av_cb.p_cback)(event, &data);
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* do stop if we were started */
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->co_started) {
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_av_str_stopped(p_scb, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update common mtu shared by remaining connectons */
|
|
|
|
mtu = bta_av_chk_mtu(p_scb, BTA_AV_MAX_A2DP_MTU);
|
|
|
|
|
|
|
|
{
|
|
|
|
p_scb->p_cos->close(p_scb->hndl, p_scb->codec_type, mtu);
|
|
|
|
data.close.chnl = p_scb->chnl;
|
|
|
|
data.close.hndl = p_scb->hndl;
|
2017-02-23 06:30:08 +00:00
|
|
|
data.close.disc_rsn = p_scb->disc_rsn;
|
2016-11-02 11:40:46 +00:00
|
|
|
event = BTA_AV_CLOSE_EVT;
|
|
|
|
|
|
|
|
bta_sys_conn_close(BTA_ID_AV, p_scb->app_id, p_scb->peer_addr);
|
|
|
|
bta_av_cleanup(p_scb, p_data);
|
|
|
|
(*bta_av_cb.p_cback)(event, &data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_clr_cong
|
|
|
|
**
|
|
|
|
** Description Clear stream congestion flag.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_clr_cong (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
UNUSED(p_data);
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->co_started) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->cong = FALSE;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_suspend_cfm
|
|
|
|
**
|
|
|
|
** Description process the suspend response
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_suspend_cfm (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
tBTA_AV_SUSPEND suspend_rsp;
|
|
|
|
UINT8 err_code = p_data->str_msg.msg.hdr.err_code;
|
|
|
|
UINT8 policy = HCI_ENABLE_SNIFF_MODE;
|
|
|
|
|
|
|
|
APPL_TRACE_DEBUG ("bta_av_suspend_cfm:audio_open_cnt = %d, err_code = %d",
|
2017-03-17 14:46:49 +00:00
|
|
|
bta_av_cb.audio_open_cnt, err_code);
|
2016-11-02 11:40:46 +00:00
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->started == FALSE) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* handle the condition where there is a collision of SUSPEND req from either side
|
|
|
|
** Second SUSPEND req could be rejected. Do not treat this as a failure
|
|
|
|
*/
|
|
|
|
APPL_TRACE_WARNING("bta_av_suspend_cfm: already suspended, ignore, err_code %d",
|
2017-03-17 14:46:49 +00:00
|
|
|
err_code);
|
2016-11-02 11:40:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
suspend_rsp.status = BTA_AV_SUCCESS;
|
2017-03-17 14:46:49 +00:00
|
|
|
if (err_code && (err_code != AVDT_ERR_BAD_STATE)) {
|
|
|
|
/* Disable suspend feature only with explicit rejection(not with timeout) */
|
|
|
|
if (err_code != AVDT_ERR_TIMEOUT) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->suspend_sup = FALSE;
|
|
|
|
}
|
|
|
|
suspend_rsp.status = BTA_AV_FAIL;
|
|
|
|
|
|
|
|
APPL_TRACE_ERROR ("bta_av_suspend_cfm: suspend failed, closing connection");
|
|
|
|
|
|
|
|
/* SUSPEND failed. Close connection. */
|
|
|
|
bta_av_ssm_execute(p_scb, BTA_AV_API_CLOSE_EVT, NULL);
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* only set started to FALSE when suspend is successful */
|
|
|
|
p_scb->started = FALSE;
|
|
|
|
}
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->role & BTA_AV_ROLE_SUSPEND) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->role &= ~BTA_AV_ROLE_SUSPEND;
|
|
|
|
p_scb->cong = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bta_sys_idle(BTA_ID_AV, bta_av_cb.audio_open_cnt, p_scb->peer_addr);
|
2017-03-17 14:46:49 +00:00
|
|
|
if ((bta_av_cb.features & BTA_AV_FEAT_MASTER) == 0 || bta_av_cb.audio_open_cnt == 1) {
|
2016-11-02 11:40:46 +00:00
|
|
|
policy |= HCI_ENABLE_MASTER_SLAVE_SWITCH;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_sys_set_policy(BTA_ID_AV, policy, p_scb->peer_addr);
|
|
|
|
|
|
|
|
/* in case that we received suspend_ind, we may need to call co_stop here */
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->co_started) {
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_av_stream_chg(p_scb, FALSE);
|
|
|
|
|
|
|
|
{
|
|
|
|
p_scb->co_started = FALSE;
|
|
|
|
p_scb->p_cos->stop(p_scb->hndl, p_scb->codec_type);
|
|
|
|
}
|
|
|
|
L2CA_SetFlushTimeout(p_scb->peer_addr, L2CAP_DEFAULT_FLUSH_TO);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
suspend_rsp.chnl = p_scb->chnl;
|
|
|
|
suspend_rsp.hndl = p_scb->hndl;
|
|
|
|
suspend_rsp.initiator = p_data->str_msg.initiator;
|
|
|
|
(*bta_av_cb.p_cback)(BTA_AV_SUSPEND_EVT, (tBTA_AV *) &suspend_rsp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_rcfg_str_ok
|
|
|
|
**
|
|
|
|
** Description report reconfigure successful
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_rcfg_str_ok (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
tBTA_AV_RECONFIG evt;
|
|
|
|
UNUSED(p_data);
|
|
|
|
|
|
|
|
p_scb->l2c_cid = AVDT_GetL2CapChannel(p_scb->avdt_handle);
|
|
|
|
APPL_TRACE_DEBUG("bta_av_rcfg_str_ok: l2c_cid: %d", p_scb->l2c_cid);
|
|
|
|
|
|
|
|
/* rc listen */
|
|
|
|
bta_av_st_rc_timer(p_scb, NULL);
|
|
|
|
utl_freebuf((void **)&p_scb->p_cap);
|
|
|
|
|
|
|
|
/* No need to keep the role bits once reconfig is done. */
|
|
|
|
p_scb->role &= ~BTA_AV_ROLE_AD_ACP;
|
|
|
|
p_scb->role &= ~BTA_AV_ROLE_SUSPEND_OPT;
|
|
|
|
p_scb->role &= ~BTA_AV_ROLE_START_INT;
|
|
|
|
|
|
|
|
{
|
|
|
|
/* reconfigure success */
|
|
|
|
evt.status = BTA_AV_SUCCESS;
|
|
|
|
evt.chnl = p_scb->chnl;
|
|
|
|
evt.hndl = p_scb->hndl;
|
|
|
|
(*bta_av_cb.p_cback)(BTA_AV_RECONFIG_EVT, (tBTA_AV *)&evt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_rcfg_failed
|
|
|
|
**
|
|
|
|
** Description process reconfigure failed
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_rcfg_failed (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
tBTA_AV_RECONFIG evt;
|
|
|
|
|
|
|
|
APPL_TRACE_DEBUG("bta_av_rcfg_failed num_recfg: %d, conn_lcb:0x%x",
|
2017-03-17 14:46:49 +00:00
|
|
|
p_scb->num_recfg, bta_av_cb.conn_lcb);
|
|
|
|
if (p_scb->num_recfg > BTA_AV_RECONFIG_RETRY) {
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_av_cco_close(p_scb, p_data);
|
|
|
|
/* report failure */
|
|
|
|
evt.status = BTA_AV_FAIL_STREAM;
|
|
|
|
evt.chnl = p_scb->chnl;
|
|
|
|
evt.hndl = p_scb->hndl;
|
|
|
|
(*bta_av_cb.p_cback)(BTA_AV_RECONFIG_EVT, (tBTA_AV *)&evt);
|
|
|
|
/* go to closing state */
|
|
|
|
bta_av_ssm_execute(p_scb, BTA_AV_API_CLOSE_EVT, NULL);
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* open failed. try again */
|
|
|
|
p_scb->num_recfg++;
|
2017-03-17 14:46:49 +00:00
|
|
|
if (bta_av_cb.conn_lcb) {
|
2016-11-02 11:40:46 +00:00
|
|
|
AVDT_DisconnectReq(p_scb->peer_addr, bta_av_dt_cback[p_scb->hdi]);
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_av_connect_req(p_scb, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_rcfg_connect
|
|
|
|
**
|
|
|
|
** Description stream closed. reconnect the stream
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_rcfg_connect (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
UNUSED(p_data);
|
|
|
|
|
|
|
|
p_scb->cong = FALSE;
|
|
|
|
p_scb->num_recfg++;
|
|
|
|
APPL_TRACE_DEBUG("bta_av_rcfg_connect num_recfg: %d", p_scb->num_recfg);
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->num_recfg > BTA_AV_RECONFIG_RETRY) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* let bta_av_rcfg_failed report fail */
|
|
|
|
bta_av_rcfg_failed(p_scb, NULL);
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
AVDT_ConnectReq(p_scb->peer_addr, p_scb->sec_mask, bta_av_dt_cback[p_scb->hdi]);
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_rcfg_discntd
|
|
|
|
**
|
|
|
|
** Description AVDT disconnected. reconnect the stream
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_rcfg_discntd (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
tBTA_AV_RECONFIG evt;
|
|
|
|
UNUSED(p_data);
|
|
|
|
|
|
|
|
APPL_TRACE_DEBUG("bta_av_rcfg_discntd num_recfg: %d", p_scb->num_recfg);
|
|
|
|
p_scb->num_recfg++;
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->num_recfg > BTA_AV_RECONFIG_RETRY) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* report failure */
|
|
|
|
evt.status = BTA_AV_FAIL_STREAM;
|
|
|
|
evt.chnl = p_scb->chnl;
|
|
|
|
evt.hndl = p_scb->hndl;
|
|
|
|
(*bta_av_cb.p_cback)(BTA_AV_RECONFIG_EVT, (tBTA_AV *)&evt);
|
|
|
|
/* report close event & go to init state */
|
|
|
|
bta_av_ssm_execute(p_scb, BTA_AV_STR_DISC_FAIL_EVT, NULL);
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
AVDT_ConnectReq(p_scb->peer_addr, p_scb->sec_mask, bta_av_dt_cback[p_scb->hdi]);
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_suspend_cont
|
|
|
|
**
|
|
|
|
** Description received the suspend response.
|
|
|
|
** continue to reconfigure the stream
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_suspend_cont (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
UINT8 err_code = p_data->str_msg.msg.hdr.err_code;
|
|
|
|
tBTA_AV_RECONFIG evt;
|
|
|
|
|
|
|
|
p_scb->started = FALSE;
|
|
|
|
p_scb->cong = FALSE;
|
2017-03-17 14:46:49 +00:00
|
|
|
if (err_code) {
|
|
|
|
if (AVDT_ERR_CONNECT == err_code) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* report failure */
|
|
|
|
evt.status = BTA_AV_FAIL;
|
|
|
|
(*bta_av_cb.p_cback)(BTA_AV_RECONFIG_EVT, (tBTA_AV *)&evt);
|
|
|
|
bta_av_ssm_execute(p_scb, BTA_AV_STR_DISC_FAIL_EVT, NULL);
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
APPL_TRACE_ERROR("suspend rejected, try close");
|
2017-03-17 14:46:49 +00:00
|
|
|
/* Disable suspend feature only with explicit rejection(not with timeout) */
|
|
|
|
if (err_code != AVDT_ERR_TIMEOUT) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->suspend_sup = FALSE;
|
|
|
|
}
|
|
|
|
/* drop the buffers queued in L2CAP */
|
|
|
|
L2CA_FlushChannel (p_scb->l2c_cid, L2CAP_FLUSH_CHANS_ALL);
|
|
|
|
|
|
|
|
AVDT_CloseReq(p_scb->avdt_handle);
|
|
|
|
}
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
APPL_TRACE_DEBUG("bta_av_suspend_cont calling AVDT_ReconfigReq");
|
|
|
|
/* reconfig the stream */
|
|
|
|
|
|
|
|
AVDT_ReconfigReq(p_scb->avdt_handle, p_scb->p_cap);
|
|
|
|
p_scb->p_cap->psc_mask = p_scb->cur_psc_mask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_rcfg_cfm
|
|
|
|
**
|
|
|
|
** Description if reconfigure is successful, report the event
|
|
|
|
** otherwise, close the stream.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_rcfg_cfm (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
UINT8 err_code = p_data->str_msg.msg.hdr.err_code;
|
|
|
|
|
|
|
|
/*
|
|
|
|
APPL_TRACE_DEBUG("bta_av_rcfg_cfm");
|
|
|
|
*/
|
2017-03-17 14:46:49 +00:00
|
|
|
if (err_code) {
|
2016-11-02 11:40:46 +00:00
|
|
|
APPL_TRACE_ERROR("reconfig rejected, try close");
|
2017-03-17 14:46:49 +00:00
|
|
|
/* Disable reconfiguration feature only with explicit rejection(not with timeout) */
|
|
|
|
if (err_code != AVDT_ERR_TIMEOUT) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->recfg_sup = FALSE;
|
|
|
|
}
|
|
|
|
/* started flag is FALSE when reconfigure command is sent */
|
|
|
|
/* drop the buffers queued in L2CAP */
|
|
|
|
L2CA_FlushChannel (p_scb->l2c_cid, L2CAP_FLUSH_CHANS_ALL);
|
|
|
|
AVDT_CloseReq(p_scb->avdt_handle);
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* update the codec info after rcfg cfm */
|
2017-03-17 14:46:49 +00:00
|
|
|
memcpy(p_scb->cfg.codec_info, p_data->str_msg.msg.reconfig_cfm.p_cfg->codec_info, AVDT_CODEC_SIZE);
|
2016-11-02 11:40:46 +00:00
|
|
|
/* take the SSM back to OPEN state */
|
|
|
|
bta_av_ssm_execute(p_scb, BTA_AV_STR_OPEN_OK_EVT, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_rcfg_open
|
|
|
|
**
|
|
|
|
** Description AVDT is connected. open the stream with the new configuration
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_rcfg_open (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
UNUSED(p_data);
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
APPL_TRACE_DEBUG("bta_av_rcfg_open, num_disc_snks = %d", p_scb->num_disc_snks);
|
2016-11-02 11:40:46 +00:00
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->num_disc_snks == 0) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* Need to update call-out module so that it will be ready for discover */
|
|
|
|
p_scb->p_cos->stop(p_scb->hndl, p_scb->codec_type);
|
|
|
|
|
|
|
|
/* send avdtp discover request */
|
|
|
|
AVDT_DiscoverReq(p_scb->peer_addr, p_scb->sep_info, BTA_AV_NUM_SEPS, bta_av_dt_cback[p_scb->hdi]);
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->codec_type = p_scb->p_cap->codec_info[BTA_AV_CODEC_TYPE_IDX];
|
|
|
|
memcpy(p_scb->cfg.codec_info, p_scb->p_cap->codec_info, AVDT_CODEC_SIZE);
|
|
|
|
/* we may choose to use a different SEP at reconfig.
|
|
|
|
* adjust the sep_idx now */
|
|
|
|
bta_av_adjust_seps_idx(p_scb, bta_av_get_scb_handle(p_scb, AVDT_TSEP_SRC));
|
|
|
|
|
|
|
|
/* open the stream with the new config */
|
|
|
|
p_scb->sep_info_idx = p_scb->rcfg_idx;
|
|
|
|
AVDT_OpenReq(p_scb->avdt_handle, p_scb->peer_addr,
|
|
|
|
p_scb->sep_info[p_scb->sep_info_idx].seid, p_scb->p_cap);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_security_rej
|
|
|
|
**
|
|
|
|
** Description Send an AVDTP security reject.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_security_rej (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
UNUSED(p_data);
|
|
|
|
|
|
|
|
AVDT_SecurityRsp(p_scb->avdt_handle, p_scb->avdt_label, AVDT_ERR_BAD_STATE,
|
|
|
|
NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_chk_2nd_start
|
|
|
|
**
|
|
|
|
** Description check if this is 2nd stream and if it needs to be started.
|
|
|
|
** This function needs to be kept very similar to bta_av_chk_start
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_chk_2nd_start (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
tBTA_AV_SCB *p_scbi;
|
|
|
|
int i;
|
|
|
|
BOOLEAN new_started = FALSE;
|
|
|
|
UNUSED(p_data);
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if ((p_scb->chnl == BTA_AV_CHNL_AUDIO) && (bta_av_cb.audio_open_cnt >= 2)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* more than one audio channel is connected */
|
2017-03-17 14:46:49 +00:00
|
|
|
if (!(p_scb->role & BTA_AV_ROLE_SUSPEND_OPT)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* this channel does not need to be reconfigured.
|
|
|
|
* if there is other channel streaming, start the stream now */
|
2017-03-17 14:46:49 +00:00
|
|
|
for (i = 0; i < BTA_AV_NUM_STRS; i++) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scbi = bta_av_cb.p_scb[i];
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scbi && p_scbi->chnl == BTA_AV_CHNL_AUDIO && p_scbi->co_started) {
|
|
|
|
if (!new_started) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* start the new stream */
|
|
|
|
new_started = TRUE;
|
|
|
|
bta_av_ssm_execute(p_scb, BTA_AV_AP_START_EVT, NULL);
|
|
|
|
}
|
|
|
|
/* may need to update the flush timeout of this already started stream */
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scbi->co_started != bta_av_cb.audio_open_cnt) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scbi->co_started = bta_av_cb.audio_open_cnt;
|
|
|
|
L2CA_SetFlushTimeout(p_scbi->peer_addr, p_bta_av_cfg->p_audio_flush_to[p_scbi->co_started - 1] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_open_rc
|
|
|
|
**
|
|
|
|
** Description Send a message to main SM to open RC channel.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_open_rc (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
tBTA_AV_START start;
|
|
|
|
|
|
|
|
APPL_TRACE_DEBUG("bta_av_open_rc use_rc: %d, wait: x%x role:x%x", p_scb->use_rc, p_scb->wait, p_scb->role);
|
2017-03-17 14:46:49 +00:00
|
|
|
if ((p_scb->wait & BTA_AV_WAIT_ROLE_SW_BITS) && (p_scb->q_tag == BTA_AV_Q_TAG_START)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* waiting for role switch for some reason & the timer expires */
|
2017-03-17 14:46:49 +00:00
|
|
|
if (!bta_av_link_role_ok(p_scb, A2D_SET_ONE_BIT)) {
|
2016-11-02 11:40:46 +00:00
|
|
|
APPL_TRACE_ERROR ("failed to start streaming for role management reasons!!");
|
|
|
|
bta_sys_stop_timer(&p_scb->timer);
|
|
|
|
start.chnl = p_scb->chnl;
|
|
|
|
start.status = BTA_AV_FAIL_ROLE;
|
|
|
|
start.initiator = TRUE;
|
|
|
|
start.hndl = p_scb->hndl;
|
|
|
|
p_scb->wait &= ~BTA_AV_WAIT_ROLE_SW_BITS;
|
|
|
|
bta_av_cb.rs_idx = 0;
|
|
|
|
(*bta_av_cb.p_cback)(BTA_AV_START_EVT, (tBTA_AV *) &start);
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* role switch is done. continue to start streaming */
|
|
|
|
bta_av_cb.rs_idx = 0;
|
|
|
|
p_data->hdr.offset = BTA_AV_RS_OK;
|
|
|
|
bta_av_start_ok (p_scb, p_data);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->use_rc == TRUE || (p_scb->role & BTA_AV_ROLE_AD_ACP) ) {
|
|
|
|
if (bta_av_cb.disc) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* AVRC discover db is in use */
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->rc_handle == BTA_AV_RC_HANDLE_NONE) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* AVRC channel is not connected. delay a little bit */
|
2017-03-17 14:46:49 +00:00
|
|
|
if ((p_scb->wait & BTA_AV_WAIT_ROLE_SW_BITS) == 0) {
|
2016-11-02 11:40:46 +00:00
|
|
|
bta_sys_start_timer(&p_scb->timer, BTA_AV_AVRC_TIMER_EVT, BTA_AV_RC_DISC_TIME_VAL);
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->wait |= BTA_AV_WAIT_CHECK_RC;
|
2017-03-17 14:46:49 +00:00
|
|
|
}
|
2016-11-02 11:40:46 +00:00
|
|
|
}
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* use main SM for AVRC SDP activities */
|
|
|
|
bta_av_rc_disc((UINT8)(p_scb->hdi + 1));
|
|
|
|
}
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
|
|
|
if (BTA_AV_RC_HANDLE_NONE != p_scb->rc_handle) {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* the open API said that this handle does not want a RC connection.
|
|
|
|
* disconnect it now */
|
|
|
|
AVRC_Close(p_scb->rc_handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_av_open_at_inc
|
|
|
|
**
|
|
|
|
** Description This function is called if API open is called by application
|
|
|
|
** while state-machine is at incoming state.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_av_open_at_inc (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
|
|
|
|
{
|
|
|
|
tBTA_AV_API_OPEN *p_buf;
|
|
|
|
|
|
|
|
memcpy (&(p_scb->open_api), &(p_data->api_open), sizeof(tBTA_AV_API_OPEN));
|
|
|
|
|
2017-03-17 14:46:49 +00:00
|
|
|
if (p_scb->coll_mask & BTA_AV_COLL_INC_TMR) {
|
2016-11-02 11:40:46 +00:00
|
|
|
p_scb->coll_mask |= BTA_AV_COLL_API_CALLED;
|
|
|
|
|
|
|
|
/* API open will be handled at timeout if SNK did not start signalling. */
|
|
|
|
/* API open will be ignored if SNK starts signalling. */
|
2017-03-17 14:46:49 +00:00
|
|
|
} else {
|
2016-11-02 11:40:46 +00:00
|
|
|
/* SNK did not start signalling, API was called N seconds timeout. */
|
|
|
|
/* We need to switch to INIT state and start opening connection. */
|
|
|
|
p_scb->coll_mask = 0;
|
|
|
|
bta_av_set_scb_sst_init (p_scb);
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
if ((p_buf = (tBTA_AV_API_OPEN *) osi_malloc(sizeof(tBTA_AV_API_OPEN))) != NULL) {
|
2016-11-02 11:40:46 +00:00
|
|
|
memcpy(p_buf, &(p_scb->open_api), sizeof(tBTA_AV_API_OPEN));
|
|
|
|
bta_sys_sendmsg(p_buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* BTA_AV_INCLUDED */
|