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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #ifndef __GAVDPSTATEMACHINE_H__
17 #define __GAVDPSTATEMACHINE_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"
29 const TUint KGAVDPCallbackTimeout = 30000000;
31 class CGavdpTimeout; //fwd ref
32 class CA2dpAudioCodecConfiguration;
34 using namespace SymbianSBC;
35 using namespace SymbianBluetoothAV;
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
49 Callback class implemented by CA2dpBTHeadsetAudioInterface to get events
50 back from CGAVDPStateMachine
52 class MGAVDPStateChangeObserver
56 Callback when the CGAVDPStateMachine has completed a state change
57 initiated by a call to ChangeState
60 @param aInitialState The state the CGAVDPStateMachine prior to calling ChangeState
61 @param standard SymbianOS error
63 void virtual GAVDPStateChangeComplete(const TGAVDPState& aInitialState, TInt aError) = 0;
66 Callback when the GAVDPStateMachine detects an error condition
67 event while no state change is in progress
70 @param aError standard SymbianOS error
72 void virtual GAVDPStateMachineEvent(TInt aError) = 0;
75 Callback when the headset suspends the streaming
79 void virtual GAVDPStateMachineStreamSuspendedByRemoteHeadset() = 0;
82 Callback when the headset requested a reconfiguration of the settings
85 @return an error code indicating whether it was possible to perform the reconfiguration
87 TInt virtual GAVDPStateMachineReconfigureByRemoteHeadset() = 0;
90 Callback when the headset starts (or restarts) the streaming
94 void virtual GAVDPStateMachineStreamResumedByRemoteHeadset() = 0;
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
109 NONSHARABLE_CLASS(CGAVDPStateMachine) : public CActive, public MGavdpUser
111 friend class CGavdpTimeout;
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;
125 //used by a2dp instead of CodecCaps
126 TAvdtpMediaCodecCapabilities* RemoteCodecConfiguration();
128 CGAVDPStateMachine(MGAVDPStateChangeObserver& aGAVDPStateChangeObserver, CA2dpAudioCodecConfiguration& aA2dpCodecSettings, RSocketServ& aSocketServer);
130 TInt RegisterLocalSEP();
131 void ConnectToGAVDP();
132 void DiscoverRemoteSEPs();
133 void GetRemoteSEPCapability();
134 void GetRemoteSEPCapabilities();
136 TInt ConfigureLocalSEP();
137 TInt ConfigureRemoteSEP();
138 void CreateBearerSocket();
140 void SuspendStream();
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
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);
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;
187 TSEID iSymbianDeviceSEID;
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;
196 //heap members owned by CGAVDPStateMachine
197 CGavdpTimeout* iSignallingTransactionTimeout;
201 The SEP discovery and GetCapabilities do not have built in timeouts,
202 so a timeout is required
206 NONSHARABLE_CLASS(CGavdpTimeout) : public CTimer
209 static CGavdpTimeout* NewL(CGAVDPStateMachine& aGAVDPStateMachine);
210 void StartTimer(TTimeIntervalMicroSeconds32 aTimeInterval);
213 void ConstructL(CGAVDPStateMachine& aGAVDPStateMachine);
216 CGAVDPStateMachine* iGAVDPStateMachine;