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

📄 headset_audio.c

📁 bluelab的一个很好的例程
💻 C
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2005

FILE NAME
    headset_audio.c

DESCRIPTION
    This file handles all Synchrounous connection messages

NOTES

*/


/****************************************************************************
    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 requested

RETURNS
    
*/
void audioHandleSyncConnectInd ( hsTaskData *pApp , const HFP_AUDIO_CONNECT_IND_T *ind)
{
    HFP *lHfp = 0 ;
    
    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;    
    }
    
    /* Accept or reject the incoming audio connection */
    if (lHfp)
    {
        HfpAudioConnectResponse(lHfp, TRUE, audioGetSupportedPacketTypes( pApp ), 0);
    }    
    else
    {
        HfpAudioConnectResponse(lHfp, FALSE, 0, 0);
    }
}


/****************************************************************************
NAME    
    audioHandleSyncConnectCfm
    
DESCRIPTION
	Handle HFP_AUDIO_CONNECT_CFM.  This indicates that an incoming sychronous 
	connection has been established

RETURNS
    
*/
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) ;
        }
    }
    AUD_DEBUG(("AUD : Sco->\n")) ;
}


/****************************************************************************
NAME    
    audioHandleSyncDisconnectInd
    
DESCRIPTION
	Handle HFP_AUDIO_DISCONNECT_IND.  This indicates that an incoming sychronous 
	connection has been disconnected

RETURNS
    
*/
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 PCM

RETURNS
    
*/
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) ;
    }          
}


#ifdef AUD_DEBUG
#ifdef DEBUG_PRINT_ENABLED
    static const char * const gScoPacketStrings [ 10 ]= {
                        "hv1",
                        "hv2",
                        "hv3",
                        "ev3",
                        "ev4",
                        "ev5",
                        "2ev3",
                        "3ev3",
                        "2ev5",
                        "3ev5"
                        };
    
#endif
#endif

/****************************************************************************
NAME    
    audioGetSupportedPacketTypes
    
DESCRIPTION
    Gets the Headset supported packet types - exposed for the call manager transfer toggle
RETURNS
    
*/
uint16 audioGetSupportedPacketTypes ( hsTaskData* pApp ) 
{
    uint16 lPacketTypes =  pApp->HFP_1_5_supp_features.supportedSyncPacketTypes;
    uint16 i = 0 ;
    
    AUD_DEBUG(("AUD: Sco/Esco Pkts Supported [%d] :\n" , lPacketTypes)) ;
    
    for ( i=0 ; i<10 ; i++)
    {
        if ( lPacketTypes & (1<<i) )
        {
            AUD_DEBUG(("[%s]" , gScoPacketStrings[i] )) ;
        }
        else
        {
            AUD_DEBUG(("[-]")) ;
        }
        AUD_DEBUG(("\n")) ;
    }
    

    return lPacketTypes ;
    
}

⌨️ 快捷键说明

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