1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/devsound/sounddevbt/src/A2dpBlueTooth/headsetaudioif/GavdpStateMachine.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,221 @@
1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#ifndef __GAVDPSTATEMACHINE_H__
1.20 +#define __GAVDPSTATEMACHINE_H__
1.21 +
1.22 +#include <e32base.h>
1.23 +#include <bttypes.h> //TBTDevAddr
1.24 +#include <es_sock.h> //RSocketServer, RSocket
1.25 +#include <gavdp.h> //MGavdpUser, RGavdp
1.26 +#include <bluetoothav.h> //TAvdtpSEPInfo, TSEID
1.27 +#include <mmf/common/mmfutilities.h> //TFourCC
1.28 +#include <mmf/server/sounddevice.h> //TMMFStereoSupport
1.29 +#include "GavdpStates.h"
1.30 +
1.31 +
1.32 +const TUint KGAVDPCallbackTimeout = 30000000;
1.33 +
1.34 +class CGavdpTimeout; //fwd ref
1.35 +class CA2dpAudioCodecConfiguration;
1.36 +
1.37 +using namespace SymbianSBC;
1.38 +using namespace SymbianBluetoothAV;
1.39 +
1.40 +/**
1.41 +structure used internally in the GAVDP state machine to keep
1.42 +track of seps than can be used on the headset to send audio and
1.43 +the local symbian device SEPs
1.44 +*/
1.45 +struct TUsableSEP
1.46 + {
1.47 + TSEID iSEID;
1.48 + TFourCC iDataType;
1.49 + };
1.50 +
1.51 +/**
1.52 +Callback class implemented by CA2dpBTHeadsetAudioInterface to get events
1.53 +back from CGAVDPStateMachine
1.54 +*/
1.55 +class MGAVDPStateChangeObserver
1.56 + {
1.57 +public:
1.58 +/**
1.59 +Callback when the CGAVDPStateMachine has completed a state change
1.60 +initiated by a call to ChangeState
1.61 +
1.62 +@internalComponent
1.63 +@param aInitialState The state the CGAVDPStateMachine prior to calling ChangeState
1.64 +@param standard SymbianOS error
1.65 +*/
1.66 + void virtual GAVDPStateChangeComplete(const TGAVDPState& aInitialState, TInt aError) = 0;
1.67 +
1.68 +/**
1.69 +Callback when the GAVDPStateMachine detects an error condition
1.70 +event while no state change is in progress
1.71 +
1.72 +@internalComponent
1.73 +@param aError standard SymbianOS error
1.74 +*/
1.75 + void virtual GAVDPStateMachineEvent(TInt aError) = 0;
1.76 +
1.77 +/**
1.78 +Callback when the headset suspends the streaming
1.79 +
1.80 +@internalComponent
1.81 +*/
1.82 + void virtual GAVDPStateMachineStreamSuspendedByRemoteHeadset() = 0;
1.83 +
1.84 +/**
1.85 +Callback when the headset requested a reconfiguration of the settings
1.86 +
1.87 +@internalComponent
1.88 +@return an error code indicating whether it was possible to perform the reconfiguration
1.89 +*/
1.90 + TInt virtual GAVDPStateMachineReconfigureByRemoteHeadset() = 0;
1.91 +
1.92 +/**
1.93 +Callback when the headset starts (or restarts) the streaming
1.94 +
1.95 +@internalComponent
1.96 +*/
1.97 + void virtual GAVDPStateMachineStreamResumedByRemoteHeadset() = 0;
1.98 + };
1.99 +
1.100 +
1.101 +/**
1.102 +GAVDP state machine used by the CA2dpBTHeadsetAudioInterface.
1.103 +This class is used by the CA2dpBTHeadsetAudioInterface to
1.104 +initialize and open the headset, which involved finding SEPs,
1.105 +configuring , getting a bearer and streaming. The CGAVDPStateMachine
1.106 +uses the MGAVDPStateChangeObserver callback to inform the CA2dpBTHeadsetAudioInterface
1.107 +of when the state change is complete, error conditions, and state changes
1.108 +initiated by the headset itself
1.109 +
1.110 +@internalComponent
1.111 +*/
1.112 +NONSHARABLE_CLASS(CGAVDPStateMachine) : public CActive, public MGavdpUser
1.113 + {
1.114 + friend class CGavdpTimeout;
1.115 +public:
1.116 + static CGAVDPStateMachine* NewL(MGAVDPStateChangeObserver& aGAVDPStateChangeObserver, CA2dpAudioCodecConfiguration& aA2dpCodecSettings, RSocketServ& aSocketServer);
1.117 + ~CGAVDPStateMachine();
1.118 + void SetBTAddress(const TBTDevAddr& aRemoteAddress);
1.119 + TInt Reconfigure(TBool aSettingsHaveChanged);
1.120 + TInt ChangeState(const TGAVDPState& aNewState);
1.121 + void CancelChangeState(); //external request to cancel state change
1.122 + TGAVDPState State() const;
1.123 + RArray<TUsableSEP>& UsableSEPs() const;
1.124 + RSocket& BearerSocket() const;
1.125 + TBTDevAddr& BTAddress() const;
1.126 + TInt CodecCaps(TAvdtpMediaCodecCapabilities*& aCodecCaps) const;
1.127 +
1.128 + //used by a2dp instead of CodecCaps
1.129 + TAvdtpMediaCodecCapabilities* RemoteCodecConfiguration();
1.130 +private:
1.131 + CGAVDPStateMachine(MGAVDPStateChangeObserver& aGAVDPStateChangeObserver, CA2dpAudioCodecConfiguration& aA2dpCodecSettings, RSocketServ& aSocketServer);
1.132 + void ConstructL();
1.133 + TInt RegisterLocalSEP();
1.134 + void ConnectToGAVDP();
1.135 + void DiscoverRemoteSEPs();
1.136 + void GetRemoteSEPCapability();
1.137 + void GetRemoteSEPCapabilities();
1.138 + void ConfigureSEP();
1.139 + TInt ConfigureLocalSEP();
1.140 + TInt ConfigureRemoteSEP();
1.141 + void CreateBearerSocket();
1.142 + void StartStream();
1.143 + void SuspendStream();
1.144 +
1.145 + void NextState();
1.146 + void StateChangeComplete();
1.147 + void CancelChangeState(TInt aReason); //internal request to cancel state change eg due to an error condition
1.148 + void Reset(); //utility to reset state to idle and all variables
1.149 +
1.150 + //MGavdpUser
1.151 + virtual void GAVDP_ConnectConfirm(const TBTDevAddr& aDevice);
1.152 + virtual void GAVDP_SEPDiscovered(const TAvdtpSEPInfo& aSEP);
1.153 + virtual void GAVDP_SEPDiscoveryComplete();
1.154 + virtual void GAVDP_SEPCapability(TAvdtpServiceCapability* aCapability);
1.155 + virtual void GAVDP_SEPCapabilityComplete();
1.156 + virtual void GAVDP_AbortStreamConfirm();
1.157 + virtual void GAVDP_StartStreamsConfirm();
1.158 + virtual void GAVDP_SuspendStreamsConfirm();
1.159 + virtual void GAVDP_SecurityControlConfirm(const TDesC8& /*aResponseData*/) {};
1.160 + virtual void GAVDP_ConfigurationConfirm();
1.161 + virtual void GAVDP_ConfigurationStartIndication(TSEID aLocalSEID, TSEID aRemoteSEID);
1.162 + virtual TInt GAVDP_ConfigurationIndication(TAvdtpServiceCapability* aCapability);
1.163 + virtual TInt GAVDP_ConfigurationEndIndication();
1.164 + virtual TInt GAVDP_StartIndication(TSEID aSEID);
1.165 + virtual TInt GAVDP_SuspendIndication(TSEID aSEID);
1.166 + virtual TInt GAVDP_SecurityControlIndication(TSEID /*aSEID*/, TDes8& /*aSecurityData*/) {return KErrNotSupported;};
1.167 + virtual void GAVDP_AbortIndication(TSEID aSEID);
1.168 + virtual void GAVDP_ReleaseIndication(TSEID aSEID);
1.169 + virtual void GAVDP_BearerReady(RSocket aSocket, const TAvdtpSockAddr& aAddress);
1.170 + virtual void GAVDP_Error(TInt aError, const TDesC8& aErrorData);
1.171 +
1.172 + //CActive
1.173 + void RunL();
1.174 + void DoCancel();
1.175 +private:
1.176 + MGAVDPStateChangeObserver& iGAVDPStateChangeObserver;
1.177 + TGAVDPState iInitialState;
1.178 + TGAVDPState iCurrentState;
1.179 + TGAVDPState iNextState;
1.180 + TGAVDPState iTargetState;
1.181 + TConfigurationByRemoteHeadsetState iConfigurationByRemoteHeadsetState;
1.182 + CA2dpAudioCodecConfiguration& iA2dpCodecSettings;
1.183 + TBool iLocalSEPConfigured;
1.184 + TBool iChangeOfSelectedHeadsetSEP;
1.185 + TBTDevAddr iBTDevAddr;
1.186 + TBool iStateChangeInProgress;
1.187 + RSocketServ& iSocketServer;
1.188 + RSocket iBearerSocket;
1.189 + RGavdp iGavdp;
1.190 + TSEID iSymbianDeviceSEID;
1.191 + TSEID iHeadsetSEID;
1.192 + RArray<TSEID> iPotentialSEPs;
1.193 + RArray<TUsableSEP> iSymbianDeviceSEPs;
1.194 + RArray<TUsableSEP> iUsableSEPs; //SEPs that can actually be used to stream audio
1.195 + RPointerArray<TAvdtpServiceCapability> iSEPCapabilities;
1.196 + TUint iSEPIterator; //used to iterate through potential SEPs when getting caps
1.197 + TUint iSEPCapabilityEntry;
1.198 +
1.199 + //heap members owned by CGAVDPStateMachine
1.200 + CGavdpTimeout* iSignallingTransactionTimeout;
1.201 + };
1.202 +
1.203 +/**
1.204 +The SEP discovery and GetCapabilities do not have built in timeouts,
1.205 +so a timeout is required
1.206 +
1.207 +@internalComponent
1.208 +*/
1.209 +NONSHARABLE_CLASS(CGavdpTimeout) : public CTimer
1.210 + {
1.211 +public:
1.212 + static CGavdpTimeout* NewL(CGAVDPStateMachine& aGAVDPStateMachine);
1.213 + void StartTimer(TTimeIntervalMicroSeconds32 aTimeInterval);
1.214 +private:
1.215 + CGavdpTimeout();
1.216 + void ConstructL(CGAVDPStateMachine& aGAVDPStateMachine);
1.217 + virtual void RunL();
1.218 +private:
1.219 + CGAVDPStateMachine* iGAVDPStateMachine;
1.220 + };
1.221 +
1.222 +
1.223 +#endif
1.224 +