📄 av_headset_sep.c
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004
FILE NAME
av_headset_sep.c
DESCRIPTION
NOTES
*/
/****************************************************************************
Header files
*/
#include "headset_private.h"
#include "headset_scan.h"
#include "av_headset_sep.h"
#include "av_headset_sep.h"
#include "av_headset_kalimba.h"
#include <codec.h>
#include <kalimba.h>
#include <panic.h>
#include <ps.h>
#include <stdlib.h>
/*************************************************************************
NAME
avHeadsetRegisterSep
DESCRIPTION
This function is called to register the required Stream Endpoints
into the GAVDP SEP database
RETURNS
*/
void avHeadsetRegisterSep(const headsetTaskData *app, a2dp_sep_type sep)
{
a2dp_sep_config config;
config.sep_type = sep;
config.params = 0;
A2dpAddSep(app->a2dp, &config);
}
/*************************************************************************
NAME
avHeadsetHandleA2dpAddSepCfm
DESCRIPTION
This function is called to when confirmation that the stream endpoints have been
registered
RETURNS
*/
void avHeadsetHandleA2dpAddSepCfm(headsetTaskData* app, const A2DP_ADD_SEP_CFM_T* cfm)
{
if(cfm->status == a2dp_success)
{
/* SBC is registered last, so wait for it.*/
if (cfm->sep_type == a2dp_sbc)
{
avrcp_init_params config;
config.device_type = avrcp_controller;
config.priority = 50;
/* Go ahead and Initialise the AVRCP library */
AvrcpInit(&app->task, &config);
/* Permit browsing of SDP service records without pairing */
ConnectionSmSetSdpSecurityIn(TRUE);
/* Change to Ready state */
avHeadsetSetA2dpState(avHeadsetA2dpReady);
}
}
else
{
DEBUG(("Unable to register SEPs\n"));
Panic();
}
}
/*************************************************************************
NAME
avHeadsetHandleA2dpOpenInd
DESCRIPTION
This function is called on receipt of an A2DP_OPEN_IND message indicating
that the SEP has opened
RETURNS
*/
void avHeadsetHandleA2dpOpenInd(headsetTaskData* app, const A2DP_OPEN_IND_T* ind)
{
bdaddr bdaddr_ind;
if (app->a2dp_state != avHeadsetA2dpReady)
return;
(void) SinkGetBdAddr(ind->media_sink, &bdaddr_ind);
DEBUG(("Bdaddr from Sink: 0x%lx / 0x%x / 0x%x\n",bdaddr_ind.lap,bdaddr_ind.uap,bdaddr_ind.nap));
/* We are now connected */
app->a2dp_state = avHeadsetA2dpConnected;
headsetTestForConnectablilty(app);
app->remote_bdaddr = bdaddr_ind;
(void)PsStore(LAST_USED_AV_SOURCE,&app->remote_bdaddr,sizeof(bdaddr));
DEBUG(("Stored PSKey of 0x%lx / 0x%x / 0x%x\n",bdaddr_ind.lap,bdaddr_ind.uap,bdaddr_ind.nap));
/* Establish an AVRCP connection if required */
if (app->avrcp_state == avHeadsetAvrcpReady)
{
/* Establish AVRCP connection */
/* Change to connecting state */
avHeadsetSetAvrcpState(avHeadsetAvrcpConnecting);
AvrcpConnect(app->avrcp, &app->remote_bdaddr);
}
/* Store the media sink and source id*/
app->media_sink = ind->media_sink;
}
/*************************************************************************
NAME
avHeadsetHandleA2dpOpenCfm
DESCRIPTION
This function is called on receipt of an A2DP_OPEN_CFM message indicating
that the SEP has opened
RETURNS
*/
void avHeadsetHandleA2dpOpenCfm(headsetTaskData* app, const A2DP_OPEN_CFM_T* cfm)
{
if (cfm->result == a2dp_success)
{
A2dpStart(app->a2dp, cfm->media_sink);
app->a2dp_state = avHeadsetA2dpConnected;
headsetTestForConnectablilty(app);
/* Store the media sink and source id*/
app->media_sink = cfm->media_sink;
}
else
{
app->a2dp_state = avHeadsetA2dpReady;
}
}
/*************************************************************************
NAME
avHeadsetHandleA2dpStartInd
DESCRIPTION
This function is called on receipt of an A2DP_START_IND message
indicating that we are about to start streaming
RETURNS
*/
void avHeadsetHandleA2dpStartInd(headsetTaskData* app, const A2DP_START_IND_T* ind)
{
if (!app->media_sink || (app->a2dp_state == avHeadsetA2dpStreaming))
return;
if (app->sco_sink)
/* SCO is active so don't start AV */
A2dpSuspend(app->a2dp, ind->media_sink);
else
avHeadsetAvStreamStart(app);
/* Change to streaming state */
app->a2dp_state = avHeadsetA2dpStreaming;
/* Cancel pairing mode */
(void) MessageCancelAll(getAppTask(), APP_PAIR_MODE_END_IND);
MessageSend(getAppTask(), APP_PAIR_MODE_END_IND, 0);
}
/*************************************************************************
NAME
avHeadsetHandleA2dpStartCfm
DESCRIPTION
This function is called on receipt of an A2DP_START_CFM message indicating
the result of our request to start streaming
RETURNS
*/
void avHeadsetHandleA2dpStartCfm(headsetTaskData* app, const A2DP_START_CFM_T* cfm)
{
if (cfm->result == a2dp_success)
{
/* Cancel pairing mode */
(void) MessageCancelAll(getAppTask(), APP_PAIR_MODE_END_IND);
MessageSend(getAppTask(), APP_PAIR_MODE_END_IND, 0);
/* start Kalimba decoding if it isn't already */
if (app->av_stream_stopped)
{
if (app->sco_sink)
{
/* SCO has become active while we were waiting for a START_CFM.
AV doesn't want to be streaming now, so we must try to
suspend the source again.
*/
A2dpSuspend(app->a2dp, cfm->media_sink);
return;
}
else
{
avHeadsetAvStreamStart(app);
}
}
app->a2dp_state = avHeadsetA2dpStreaming;
}
else
{
/* failed to start, close the connection */
A2dpClose(app->a2dp, cfm->media_sink);
if (app->avrcp_state == avHeadsetAvrcpConnected)
AvrcpDisconnect(app->avrcp);
}
}
/*************************************************************************
NAME
avHeadsetHandleA2dpSuspendInd
DESCRIPTION
This function is called on receipt of an A2DP_SUSPEND_IND message
RETURNS
*/
void avHeadsetHandleA2dpSuspendInd(headsetTaskData *app)
{
/* Change to connected state */
app->a2dp_state = avHeadsetA2dpConnected;
avHeadsetAvStreamStop(app, FALSE);
}
/*************************************************************************
NAME
avHeadsetHandleA2dpSuspendCfm
DESCRIPTION
This function is called on receipt of an A2DP_SUSPEND_CFM message
RETURNS
*/
void avHeadsetHandleA2dpSuspendCfm(headsetTaskData* app, const A2DP_SUSPEND_CFM_T* ind)
{
if (ind->result == a2dp_success)
{
app->a2dp_state = avHeadsetA2dpConnected;
if (!app->av_stream_stopped)
{
/* We must have had a stream restart at this end occuring so restart AV source */
A2dpStart(app->a2dp, app->media_sink);
}
else
{
/* We have suspended the AV source. */
app->sent_suspend = TRUE;
}
}
}
/*************************************************************************
NAME
avHeadsetHandleA2dpCloseInd
DESCRIPTION
This function is called on receipt of an A2DP_CLOSE_IND message
RETURNS
*/
void avHeadsetHandleA2dpCloseInd(headsetTaskData *app)
{
/* Stop the media stream */
avHeadsetAvStreamStop(app,FALSE);
/* Power down the codec */
CodecPowerDown(app->codec_task);
/* Change to ready state */
app->a2dp_state = avHeadsetA2dpReady;
headsetTestForConnectablilty(app);
/* Switch to hfp mode */
app->active_profile = hfp_active;
if (app->avrcp_state == avHeadsetAvrcpConnected)
{
/* Change avrcp to disconnecting state */
avHeadsetSetAvrcpState(avHeadsetAvrcpDisconnecting);
/* Disconnect the AVRCP connection */
AvrcpDisconnect(app->avrcp);
}
}
/*************************************************************************
NAME
avHeadsetHandleA2dpCloseCfm
DESCRIPTION
This function is called on receipt of an A2DP_CLOSE_CFM message
RETURNS
*/
void avHeadsetHandleA2dpCloseCfm(headsetTaskData* app)
{
/* Stop the media stream */
avHeadsetAvStreamStop(app,FALSE);
/* Switch to hfp mode */
app->active_profile = hfp_active;
/* Change to ready state */
app->a2dp_state = avHeadsetA2dpReady;
headsetTestForConnectablilty(app);
}
/*************************************************************************
NAME
avHeadsetHandleA2dpCodecSettingsInd
DESCRIPTION
Handle the receipt of new codec settings.
RETURNS
*/
void avHeadsetHandleA2dpCodecSettingsInd(headsetTaskData *theAvApp, const A2DP_CODEC_SETTINGS_IND_T *ind)
{
/* Store the codec config settings */
theAvApp->channel_mode = ind->channel_mode;
theAvApp->rate = ind->rate;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -