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