os/mm/devsound/sounddevbt/src/A2dpBlueTooth/headsetaudioif/GavdpStateMachine.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #ifndef __GAVDPSTATEMACHINE_H__
    17 #define __GAVDPSTATEMACHINE_H__
    18 
    19 #include <e32base.h>
    20 #include <bttypes.h> //TBTDevAddr
    21 #include <es_sock.h> //RSocketServer, RSocket
    22 #include <gavdp.h> //MGavdpUser, RGavdp
    23 #include <bluetoothav.h> //TAvdtpSEPInfo, TSEID
    24 #include <mmf/common/mmfutilities.h> //TFourCC
    25 #include <mmf/server/sounddevice.h> //TMMFStereoSupport
    26 #include "GavdpStates.h"
    27 
    28 
    29 const TUint KGAVDPCallbackTimeout = 30000000;
    30 
    31 class CGavdpTimeout; //fwd ref
    32 class CA2dpAudioCodecConfiguration;
    33 
    34 using namespace SymbianSBC;
    35 using namespace SymbianBluetoothAV;	
    36 
    37 /**
    38 structure used internally in the GAVDP state machine to keep
    39 track of seps than can be used on the headset to send audio and 
    40 the local symbian device SEPs
    41 */
    42 struct TUsableSEP
    43 	{
    44 	TSEID iSEID;
    45 	TFourCC iDataType;
    46 	};
    47 	
    48 /**
    49 Callback class implemented by CA2dpBTHeadsetAudioInterface to get events
    50 back from CGAVDPStateMachine
    51 */	
    52 class MGAVDPStateChangeObserver
    53 	{
    54 public:
    55 /**
    56 Callback when the CGAVDPStateMachine has completed a state change
    57 initiated by a call to ChangeState
    58 
    59 @internalComponent
    60 @param aInitialState The state the CGAVDPStateMachine prior to calling ChangeState
    61 @param standard SymbianOS error
    62 */
    63 	void virtual GAVDPStateChangeComplete(const TGAVDPState& aInitialState, TInt aError) = 0;
    64 	
    65 /**
    66 Callback when the GAVDPStateMachine detects an error condition
    67 event while no state change is in progress
    68 
    69 @internalComponent
    70 @param aError standard SymbianOS error
    71 */
    72 	void virtual GAVDPStateMachineEvent(TInt aError) = 0;
    73 	
    74 /**
    75 Callback when the headset suspends the streaming
    76 
    77 @internalComponent
    78 */
    79 	void virtual GAVDPStateMachineStreamSuspendedByRemoteHeadset() = 0;
    80 	
    81 /**
    82 Callback when the headset requested a reconfiguration of the settings
    83 
    84 @internalComponent
    85 @return an error code indicating whether it was possible to perform the reconfiguration
    86 */
    87 	TInt virtual GAVDPStateMachineReconfigureByRemoteHeadset() = 0;
    88 	
    89 /**
    90 Callback when the headset starts (or restarts) the streaming
    91 
    92 @internalComponent
    93 */
    94 	void virtual GAVDPStateMachineStreamResumedByRemoteHeadset() = 0;
    95 	};
    96 
    97 
    98 /**
    99 GAVDP state machine used by the CA2dpBTHeadsetAudioInterface.
   100 This class is used by the CA2dpBTHeadsetAudioInterface to
   101 initialize and open the headset, which involved finding SEPs,
   102 configuring , getting a bearer and streaming.  The CGAVDPStateMachine
   103 uses the MGAVDPStateChangeObserver callback to inform the CA2dpBTHeadsetAudioInterface
   104 of when the state change is complete, error conditions, and state changes
   105 initiated by the headset itself
   106  
   107 @internalComponent
   108 */
   109 NONSHARABLE_CLASS(CGAVDPStateMachine) : public CActive, public MGavdpUser  
   110 	{
   111 	friend class CGavdpTimeout;
   112 public:
   113 	static CGAVDPStateMachine* NewL(MGAVDPStateChangeObserver& aGAVDPStateChangeObserver, CA2dpAudioCodecConfiguration& aA2dpCodecSettings, RSocketServ& aSocketServer);
   114 	~CGAVDPStateMachine();
   115 	void SetBTAddress(const TBTDevAddr& aRemoteAddress);
   116 	TInt Reconfigure(TBool aSettingsHaveChanged);
   117 	TInt ChangeState(const TGAVDPState& aNewState);
   118 	void CancelChangeState(); //external request to cancel state change
   119 	TGAVDPState State() const;
   120 	RArray<TUsableSEP>& UsableSEPs() const;
   121 	RSocket& BearerSocket() const;
   122 	TBTDevAddr& BTAddress() const;
   123 	TInt CodecCaps(TAvdtpMediaCodecCapabilities*& aCodecCaps) const;
   124 	
   125 	//used by a2dp instead of CodecCaps
   126 	TAvdtpMediaCodecCapabilities* RemoteCodecConfiguration();
   127 private:
   128 	CGAVDPStateMachine(MGAVDPStateChangeObserver& aGAVDPStateChangeObserver, CA2dpAudioCodecConfiguration& aA2dpCodecSettings, RSocketServ& aSocketServer); 
   129 	void ConstructL();
   130 	TInt RegisterLocalSEP();
   131 	void ConnectToGAVDP();
   132 	void DiscoverRemoteSEPs();
   133 	void GetRemoteSEPCapability();
   134 	void GetRemoteSEPCapabilities();
   135 	void ConfigureSEP();
   136 	TInt ConfigureLocalSEP();
   137 	TInt ConfigureRemoteSEP();
   138 	void CreateBearerSocket();
   139 	void StartStream();
   140 	void SuspendStream();
   141 	
   142 	void NextState();
   143 	void StateChangeComplete();
   144 	void CancelChangeState(TInt aReason); //internal request to cancel state change eg due to an error condition
   145 	void Reset(); //utility to reset state to idle and all variables
   146  	
   147 	//MGavdpUser
   148 	virtual void GAVDP_ConnectConfirm(const TBTDevAddr& aDevice);
   149 	virtual void GAVDP_SEPDiscovered(const TAvdtpSEPInfo& aSEP);
   150 	virtual void GAVDP_SEPDiscoveryComplete();	
   151 	virtual void GAVDP_SEPCapability(TAvdtpServiceCapability* aCapability);
   152 	virtual void GAVDP_SEPCapabilityComplete();		
   153 	virtual void GAVDP_AbortStreamConfirm();
   154 	virtual void GAVDP_StartStreamsConfirm();	
   155 	virtual void GAVDP_SuspendStreamsConfirm();
   156 	virtual void GAVDP_SecurityControlConfirm(const TDesC8& /*aResponseData*/) {};	
   157 	virtual void GAVDP_ConfigurationConfirm();
   158 	virtual void GAVDP_ConfigurationStartIndication(TSEID aLocalSEID, TSEID aRemoteSEID);
   159 	virtual TInt	GAVDP_ConfigurationIndication(TAvdtpServiceCapability* aCapability);
   160 	virtual TInt	GAVDP_ConfigurationEndIndication();
   161 	virtual TInt	GAVDP_StartIndication(TSEID aSEID);
   162 	virtual TInt	GAVDP_SuspendIndication(TSEID aSEID);
   163 	virtual TInt	GAVDP_SecurityControlIndication(TSEID /*aSEID*/, TDes8& /*aSecurityData*/) {return KErrNotSupported;};
   164 	virtual void GAVDP_AbortIndication(TSEID aSEID);
   165 	virtual void GAVDP_ReleaseIndication(TSEID aSEID);
   166 	virtual void GAVDP_BearerReady(RSocket aSocket, const TAvdtpSockAddr& aAddress);
   167 	virtual void GAVDP_Error(TInt aError, const TDesC8& aErrorData);
   168 
   169 	//CActive
   170 	void RunL();
   171 	void DoCancel();
   172 private:
   173 	MGAVDPStateChangeObserver& iGAVDPStateChangeObserver;
   174 	TGAVDPState iInitialState;
   175 	TGAVDPState iCurrentState;
   176 	TGAVDPState iNextState;
   177 	TGAVDPState	iTargetState;
   178 	TConfigurationByRemoteHeadsetState iConfigurationByRemoteHeadsetState;
   179 	CA2dpAudioCodecConfiguration& iA2dpCodecSettings;
   180 	TBool iLocalSEPConfigured;
   181 	TBool iChangeOfSelectedHeadsetSEP;
   182 	TBTDevAddr iBTDevAddr;
   183 	TBool iStateChangeInProgress;
   184 	RSocketServ& iSocketServer;
   185 	RSocket iBearerSocket;
   186 	RGavdp		iGavdp;
   187 	TSEID		iSymbianDeviceSEID;
   188 	TSEID		iHeadsetSEID;
   189 	RArray<TSEID> iPotentialSEPs;
   190 	RArray<TUsableSEP> iSymbianDeviceSEPs;
   191 	RArray<TUsableSEP> iUsableSEPs; //SEPs that can actually be used to stream audio
   192 	RPointerArray<TAvdtpServiceCapability> iSEPCapabilities;
   193 	TUint iSEPIterator; //used to iterate through potential SEPs when getting caps
   194 	TUint iSEPCapabilityEntry;
   195 	
   196 	//heap members owned by CGAVDPStateMachine
   197 	CGavdpTimeout* iSignallingTransactionTimeout;
   198 	};
   199 	
   200 /**
   201 The SEP discovery and GetCapabilities do not have built in timeouts,
   202 so a timeout is required
   203 
   204 @internalComponent
   205 */
   206 NONSHARABLE_CLASS(CGavdpTimeout) : public CTimer
   207 	{
   208 public:
   209 	static CGavdpTimeout* NewL(CGAVDPStateMachine& aGAVDPStateMachine);
   210 	void StartTimer(TTimeIntervalMicroSeconds32 aTimeInterval);
   211 private:
   212 	CGavdpTimeout();
   213 	void ConstructL(CGAVDPStateMachine& aGAVDPStateMachine);
   214 	virtual void RunL();
   215 private:
   216 	CGAVDPStateMachine* iGAVDPStateMachine;
   217 	};
   218 	
   219 
   220 #endif
   221