⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 headset_a2dp_connection.c

📁 bc5_stereo:bluetooth stereo Headset CODE 支持A2DP HSP 和 HSP 。可作为车载免提。BlueLab 2007环境下编译
💻 C
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004-2007

FILE NAME
    headset_a2dp_connection.c
    
DESCRIPTION
    Handles a2dp connection.
    
*/


#include "headset_a2dp_connection.h"
#include "headset_a2dp_stream_control.h"
#include "headset_avrcp_event_handler.h"
#include "headset_configmanager.h"
#include "headset_hfp_slc.h"

#include <bdaddr.h>
#include <ps.h>


#ifdef DEBUG_A2DP_CONNECTION
#define A2DP_CONNECTION_DEBUG(x) DEBUG(x)
#else
#define A2DP_CONNECTION_DEBUG(x) 
#endif


/****************************************************************************
  FUNCTIONS
*/
bool a2dpGetLastUsedSource(bdaddr *addr, a2dp_sep_type *sep_type)
{
	bool ret = TRUE;
	
    if (!PsRetrieve(PSKEY_LAST_USED_AV_SOURCE, addr, sizeof(bdaddr)))
    {
		if (!PsRetrieve(PSKEY_LAST_PAIRED_DEVICE, addr, sizeof(bdaddr)))
		{
		    ret = FALSE;
	    }
	}
	
	if ((ret) && (!PsRetrieve(PSKEY_LAST_USED_AV_SOURCE_SEP, sep_type, sizeof(a2dp_sep_type))))
	{
		*sep_type = a2dp_sbc;
	}
	
	return ret;
}


/****************************************************************************/
void a2dpReconnectProcedure(hsTaskData *app)
{
	bdaddr a2dp_addr, ag_addr;	
	a2dp_sep_type sep_type;
	
	/* 	
		If this A2DP source is also an AG then only connect signalling channel. 
		If the A2DP source and AG are different devices then connect signalling and media channels.	   
	*/
	if (!a2dpGetLastUsedSource(&a2dp_addr, &sep_type))
		return;
	
	if (!hfpSlcGetLastConnectedAG(&ag_addr))
	{
		a2dpConnectRequest(app, TRUE);
		return;	
	}
	
	if (BdaddrIsSame(&a2dp_addr, &ag_addr) && app->slcConnectFromPowerOn)
	{
		if (!app->a2dp.sig_sink)
			a2dpConnectRequest(app, FALSE);			
	}
	else
	{
		a2dpConnectRequest(app, TRUE);
	}
}


/****************************************************************************/
void a2dpConnectRequest(hsTaskData *app, bool connect_media)
{
    bdaddr addr;
	a2dp_sep_type sep_type = a2dp_sbc;
    
	if (!a2dpGetLastUsedSource(&addr, &sep_type))
	{
		MessageSend(&app->task, EventA2dpReconnectFailed, 0);
		return;
	}
				
    app->a2dpConnecting = TRUE;
	
	/* Send an avrcp_play once media has connected and entered
	   the correct state. This is so A2DP sources (standalone and AGs)
	   will start playing music straight away.
	*/
	if (connect_media)
		app->sendPlayOnConnection = TRUE;

	if (!app->a2dpMP3Enabled)
	{
		sep_type = a2dp_sbc;
	}

    A2dpOpen(app->a2dp.a2dp, sep_type, &addr, connect_media);
}


/****************************************************************************/
void a2dpDisconnectRequest(hsTaskData *app)
{
	/* Don't resume A2DP streaming */
	streamControlCancelResumeA2dpStreaming( app );
	
	/* Disconnect AVRCP first. */
	avrcpDisconnectReq(app);
	
	/* Close all A2DP signalling and media channels */
	A2dpCloseAll(app->a2dp.a2dp);
}


/****************************************************************************/
bool a2dpIsConnecting ( hsTaskData * pApp )
{
	return pApp->a2dpConnecting;	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -