📄 headset_audio.c
字号:
/****************************************************************************Copyright (C) Cambridge Silicon Radio Ltd. 2005-2006Part of BlueLab 3.6.2-releaseFILE NAME headset_audio.cDESCRIPTION This file handles all Synchrounous connection messagesNOTES*//**************************************************************************** Header files*/#include "headset_private.h"#include "headset_audio.h"#include "headset_statemanager.h"#include "headset_LEDmanager.h"#include "headset_soundmanager.h"#include <connection.h>#include <hfp.h>#include <pcm.h>#ifdef DEBUG_AUDIO#define AUD_DEBUG(x) DEBUG(x)#else#define AUD_DEBUG(x) #endif /****************************************************************************NAME audioHandleSyncConnectInd DESCRIPTION Handle HFP_AUDIO_CONNECT_IND. This indicates that an incoming sychronous connection is being requestedRETURNS */void audioHandleSyncConnectInd ( hsTaskData *pApp , const HFP_AUDIO_CONNECT_IND_T *ind){ HFP *lHfp = 0 ; hfp_audio_params * lParamsPtr = 0 ; hfp_audio_params lParams; AUD_DEBUG(("AUD: Synchronous Connect Ind:\n")) ; /* Respond to the HFP with our acceptable parameters*/ /* Accept audio if its for a task we own */ if ((ind->hfp == pApp->hfp) || (ind->hfp == pApp->hsp)) { lHfp = ind->hfp; } if ( pApp->HFP_1_5_supp_features.HFP_1_5_Is_Enabled ) { if (pApp->HFP_1_5_supp_features.Additional_Parameters_Enabled ) { lParamsPtr = &lParams; lParamsPtr->bandwidth = pApp->HFP_1_5_supp_features.bandwidth ; lParamsPtr->max_latency = pApp->HFP_1_5_supp_features.max_latency ; lParamsPtr->voice_settings = pApp->HFP_1_5_supp_features.voice_settings ; lParamsPtr->retx_effort = pApp->HFP_1_5_supp_features.retx_effort ; DEBUG(("AUD : [%x][%x][%x][%x]\n" , (int)lParamsPtr->bandwidth , lParamsPtr->max_latency , lParamsPtr->voice_settings , (int)lParamsPtr->retx_effort )) ; } } /* Accept or reject the incoming audio connection */ if (lHfp) { HfpAudioConnectResponse(lHfp, TRUE, audioGetSupportedPacketTypes( pApp ), lParamsPtr); } else { HfpAudioConnectResponse(lHfp, FALSE, 0, 0); }}/* this is the format of the required const hfp_audio_params *typedef struct{ uint32 bandwidth; uint16 max_latency; uint16 voice_settings; sync_retx_effort retx_effort; //dont car = 0xFF} hfp_audio_params;*//****************************************************************************NAME audioHandleSyncConnectCfm DESCRIPTION Handle HFP_AUDIO_CONNECT_CFM. This indicates that an incoming sychronous connection has been establishedRETURNS */void audioHandleSyncConnectCfm ( hsTaskData * pApp , const HFP_AUDIO_CONNECT_CFM_T * pInd){ AUD_DEBUG(("Synchronous Connect Cfm:\n")) ; /* A SCO connection has been opened to this device */ AUD_DEBUG(("AUD : ->Sco\n")); if (pInd->status == hfp_success) { /* Store the sink associated with the SCO */ pApp->sco_sink = pInd->audio_sink; audioConnectScoToPcm ( pApp , 0 ) ; /* If this is a headset instance, enter the active call state This is necessary as the opening of a SCO connection is the only way to know that a call is active */ if (pApp->profile_connected == hfp_headset_profile) { stateManagerEnterActiveCallState (pApp) ; } switch (pInd->link_type) { case (sync_link_unknown): DEBUG(("AUD: Link = ?")) ; break ; case (sync_link_sco) : DEBUG(("AUD: Link = SCO")) ; break; case sync_link_esco: DEBUG(("AUD: Link = eSCO")) ; break ; } } AUD_DEBUG(("AUD : Sco->\n")) ;}/****************************************************************************NAME audioHandleSyncDisconnectInd DESCRIPTION Handle HFP_AUDIO_DISCONNECT_IND. This indicates that an incoming sychronous connection has been disconnectedRETURNS */void audioHandleSyncDisconnectInd ( hsTaskData * pApp , const HFP_AUDIO_DISCONNECT_IND_T * pInd){ AUD_DEBUG(("AUD: Synchronous Disconnect Ind:\n")) ; /* Reset the SCO sink as it is no longer valid */ pApp->sco_sink = 0; MessageSend ( &pApp->task , EventSCOLinkClose , 0 ) ; if (pApp->PIO.HeadsetActivePIOEnabled ) { LedManagerSetPIO ( pApp->PIO.HeadsetActivePIO , FALSE) ; } /*if this is a headset instance, end the call*/ if (pApp->profile_connected == hfp_headset_profile ) { if(stateManagerIsConnected()) { stateManagerEnterConnectedState ( pApp ) ; } } /*if we are muted - then un mute at disconnection*/ if (pApp->theSoundTask.gMuted) { MessageSend(&pApp->task , EventMuteOff , 0) ; }}/****************************************************************************NAME audioConnectScoToPcm DESCRIPTION This function connects the synchronous connection to the PCMRETURNS */void audioConnectScoToPcm ( hsTaskData *pApp, uint16 pPcmPort ){ bool lResult = FALSE ; /* Set up SCO routing to the PCM (for now). Depending on the hardware, test if we can route internally (ie. BC3-MM). If this fails then route externally (ie. BC2-external) */ if (!PcmRateAndRoute(pPcmPort, PCM_NO_SYNC, 8000, 8000, VM_PCM_INTERNAL_A)) { AUD_DEBUG(("AUD : 1[%d]\n",lResult)) ; PcmRateAndRoute(pPcmPort, PCM_NO_SYNC, 8000, 8000, VM_PCM_EXTERNAL_PCM); } else { AUD_DEBUG(("AUD : 2[%d]\n",lResult)) ; } AUD_DEBUG(("AUD: Sink [%x][%x]", (int)pApp->sco_sink, pPcmPort)) ; lResult = StreamConnect(StreamSourceFromSink(pApp->sco_sink), StreamPcmSink(pPcmPort)); /* Only reconnect the mic path if we are not muted */ if (pApp->theSoundTask.gMuted == VOL_NOT_MUTED) { lResult = StreamConnect(StreamPcmSource(pPcmPort), pApp->sco_sink); } /* Send an event to indicate that a SCO has been opened */ MessageSend ( &pApp->task , EventSCOLinkOpen , 0 ) ; /* Headset active PIO is assered if configured */ if (pApp->PIO.HeadsetActivePIOEnabled ) { LedManagerSetPIO ( pApp->PIO.HeadsetActivePIO , TRUE) ; } } static const char * const gScoPacketStrings [ 10 ]= { "hv1", "hv2", "hv3", "ev3", "ev4", "ev5", "2ev3", "3ev3", "2ev5", "3ev5" }; #ifdef AUD_DEBUG#ifdef DEBUG_PRINT_ENABLED#endif#endif/****************************************************************************NAME audioGetSupportedPacketTypes DESCRIPTION Gets the Headset supported packet types - exposed for the call manager transfer toggleRETURNS */uint16 audioGetSupportedPacketTypes ( hsTaskData* pApp ) { uint16 lPacketTypes = pApp->HFP_1_5_supp_features.supportedSyncPacketTypes; uint16 i = 0 ; DEBUG(("AUD: Sco/Esco Pkts Supported [%d] :\n" , lPacketTypes)) ; for ( i=0 ; i<10 ; i++) { if ( lPacketTypes & (1<<i) ) { DEBUG(("[%s]" , gScoPacketStrings[i] )) ; } else { DEBUG(("[-]")) ; } DEBUG(("\n")) ; } return lPacketTypes ; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -