bluetoothengine/btsac/inc/btsacStreamerController.h
changeset 0 f63038272f30
child 1 6a1fe72036e3
equal deleted inserted replaced
-1:000000000000 0:f63038272f30
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Declaration for CBTSACStreamerController class. This class constructs and
       
    15 *				 communicates with 'BT Audio Streamer' component to do RTP streaming.
       
    16 
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #ifndef BTSAC_STREAMER_H
       
    22 #define BTSAC_STREAMER_H
       
    23 
       
    24 //  INCLUDES
       
    25 
       
    26 #include <btaudiostreamer.h>  
       
    27 #include <btaudiostreaminputbase.h> 
       
    28 #include <bluetoothav.h>		// Protocol definitions, e.g., TSBCCodecCapabilities
       
    29 #include "btsacActivePacketDropIoctl.h" 
       
    30 #include <SbcEncoderIntfc.h>  // uuid of SBC Encoder
       
    31 
       
    32 
       
    33 class MBTAudioAdaptationObserver
       
    34     {
       
    35     public:
       
    36     virtual void NotifyError(TInt aError) = 0; 
       
    37     };
       
    38 
       
    39 // CONSTANTS
       
    40 
       
    41 // DATA TYPES
       
    42 
       
    43 // FORWARD DECLARATIONS
       
    44 
       
    45 // CLASS DECLARATION
       
    46 
       
    47 /**
       
    48 *  
       
    49 *  
       
    50 *  
       
    51 */
       
    52 
       
    53 class TBitpoolData
       
    54 	{
       
    55 public:
       
    56 	TInt iMaxBitpoolValue;
       
    57 	TInt iMaxDeviation;
       
    58 	//TInt iUpgradeDelay;
       
    59 	TInt iIndex;
       
    60 	TInt iDownBitpoolIndex;
       
    61 	TInt iUpBitpoolIndex;
       
    62 	TBool iMinimumMaxBitpool;
       
    63 	};
       
    64 
       
    65 NONSHARABLE_CLASS(CBTSACStreamerController) : public CActive, MBTAudioErrorObserver, MActivePacketDropIoctlObserver
       
    66     {
       
    67  public:  // Constructors and destructor
       
    68         
       
    69         /**
       
    70         * Two-phased constructor.
       
    71         * 
       
    72         * 
       
    73         * 
       
    74         */
       
    75         static CBTSACStreamerController* NewL(MBTAudioAdaptationObserver& aObserver);
       
    76         
       
    77         /**
       
    78         * Destructor.
       
    79         * 
       
    80         * 
       
    81         */
       
    82         virtual ~CBTSACStreamerController();
       
    83         
       
    84   public:
       
    85 		// From MBTAudioErrorObserver
       
    86 		virtual TInt Error(const TInt aError); 
       
    87 
       
    88 		// From MActivePacketDropIoctlObserver
       
    89     	virtual void PacketsDropped(TInt aPacketCount);
       
    90 
       
    91   
       
    92   public: // New functions
       
    93         
       
    94         /**
       
    95         * 
       
    96         * 
       
    97         * @param aStatus            
       
    98         * @return                   None.
       
    99         */
       
   100         TInt StartStream(RSocket& aSocket, TInt aFrameLength);
       
   101         
       
   102         /**
       
   103         * 
       
   104         * 
       
   105         * @param aStatus            
       
   106         * @return                   None.
       
   107         */
       
   108         TInt StopStream();
       
   109         
       
   110         /**
       
   111         * 
       
   112         * 
       
   113         * @param aStatus            
       
   114         * @return                   None.
       
   115         */
       
   116         void ResetAudioInput();
       
   117         
       
   118         /**
       
   119         * 
       
   120         * 
       
   121         * @param aStatus            
       
   122         * @return                   None.
       
   123         */
       
   124         TInt FillCapabilities( TSBCCodecCapabilities& aSbc );
       
   125         
       
   126         /**
       
   127         * 
       
   128         * 
       
   129         * @param aStatus            
       
   130         * @return                   None.
       
   131         */
       
   132         TInt ConfigureSEP( TSBCCodecCapabilities& aDec );
       
   133         
       
   134         /**
       
   135         * 
       
   136         * 
       
   137         * @param aStatus            
       
   138         * @return                   None.
       
   139         */
       
   140         TInt FrameLength() const;
       
   141         
       
   142         /**
       
   143         * 
       
   144         * 
       
   145         * @param none
       
   146         * @return                   TSBCCodecCapabilities.
       
   147         */
       
   148         TSBCCodecCapabilities &GetCaps();
       
   149         
       
   150     protected:  // Functions from CActive
       
   151     
       
   152         /**
       
   153         * RunL is called by framework after request is being completed.
       
   154         * @param nones
       
   155         * @return none 
       
   156         */    
       
   157     	void RunL();
       
   158     	
       
   159         /**
       
   160         * DoCancel() has to be implemented by all the classes deriving CActive.
       
   161         * Request cancellation routine.
       
   162         * @param none
       
   163         * @return none 
       
   164         */
       
   165     	void DoCancel();
       
   166 
       
   167     	/**
       
   168     	* RunError is called if RunL() leaves
       
   169     	*/
       
   170         TInt RunError(TInt aError);
       
   171 
       
   172                                  
       
   173 	private: // Data definitions
       
   174 
       
   175         enum TBTSACStreamingState
       
   176         	{
       
   177         		EStateStreaming,
       
   178         		EStateIdle,
       
   179         		EStateError
       
   180         	};
       
   181  		
       
   182  		typedef enum EOngoingAction
       
   183 			{
       
   184 			ENone,
       
   185 			EErrorSending,
       
   186 			EDowngradeBitrate,
       
   187 			EUpgradeBitrate,
       
   188 			EStartStabilizingTimer,
       
   189 			EStabilize
       
   190 			};
       
   191 			
       
   192      private:
       
   193 
       
   194         /**
       
   195         * C++ default constructor.
       
   196         */
       
   197         CBTSACStreamerController(MBTAudioAdaptationObserver& aObserver);
       
   198 
       
   199         /**
       
   200         * Symbian 2nd phase constructor.
       
   201         * 
       
   202         * 
       
   203         * 
       
   204         * 
       
   205         */
       
   206         void ConstructL();
       
   207 		
       
   208 		void CheckAndAdjustBitpool(TSBCCodecCapabilities& aDec);
       
   209 		TInt GetMatchingCaps(TSBCCodecCapabilities& aCaps);
       
   210 		TInt ConfigureSEPBitpool(EOngoingAction aAction);
       
   211 		void DoSelfComplete(EOngoingAction aAction, TInt aError);
       
   212 		
       
   213 		void SetBlockLen(TSBCCodecCapabilities& aCap, TUint8 aBlockLen);
       
   214 		TInt GetBlockLen(TSBCCodecCapabilities& aCap) const;
       
   215 		void SetSamplingFrequency(TSBCCodecCapabilities& aCap, TUint8 aFrequency);
       
   216 		TInt GetSamplingFrequency(TSBCCodecCapabilities& aCap) const;
       
   217 		TInt FrameLengthFormula(TSBCCodecCapabilities& aCap) const;
       
   218 		TInt GetNumOfChannels(TSBCCodecCapabilities& aCap) const;
       
   219 		void SetNumOfSubbands(TSBCCodecCapabilities& aCap, TUint8 aNumOfSubbands);
       
   220 		TInt GetNumOfSubbands(TSBCCodecCapabilities& aCap) const;		
       
   221 		void SetBitpoolValues(TSBCCodecCapabilities& aCap);
       
   222 		void SetAllocationMethod(TSBCCodecCapabilities& aCap, TUint8 aAllocationMethod);
       
   223 		void SetChannelMode(TSBCCodecCapabilities& aCap, TUint8 aChannelMode);
       
   224 		
       
   225 		TInt SetCurrentBitpoolData(TInt aBitpool);
       
   226 		void InitializeBitpoolDataL();
       
   227 		void ReorganizeBitpoolTable(TInt aNegotiatedMaxBitpool);
       
   228 		TBitpoolData* GetBitpoolData(TInt aIndex);
       
   229 		TInt GetIndex(TInt aBitpool);
       
   230 		TBool IndexValid(TInt aIndex);
       
   231         
       
   232 	private:    // Data
       
   233         
       
   234 		CBTAudioStreamer* iBTStreamer;  // Bluetooth Audio Streamer component
       
   235 		CBTAudioStreamInputBase* iAudioInput;
       
   236     	TBTSACStreamingState iState;
       
   237     	EOngoingAction iOngoingAction;
       
   238     	TSBCCodecCapabilities iLocalCap; // local copy of Audio Adapatation capabilities
       
   239     	TSBCCodecCapabilities iMatchCap; // local copy of capabilites used to configure accessory
       
   240     	RLibrary iLib;  // for loading BTAudioStreamer and BTAudioAdaptation dll
       
   241     	TInt iCurrentBitrate; 
       
   242     	TInt iCurrentFrameLength;
       
   243 		RTimer iTimer;
       
   244 		CActivePacketDropIoctl* iPacketDropIoctl; 
       
   245 		RThread iThread;
       
   246 		CSbcEncoderIntfc *iEncoderCI;
       
   247 		MBTAudioAdaptationObserver& iObserver;
       
   248 		TInt iTotalNbrOfDroppedPackets;
       
   249 		TTime iFirstPacketDropTime; 
       
   250 		TInt iPacketDropDeviation;
       
   251 		RArray<TBitpoolData> iBitpoolData;
       
   252 		TBitpoolData* iCurrentBitpoolData;
       
   253     };
       
   254 
       
   255 
       
   256 #endif      // BTSAC_STREAMER_H
       
   257             
       
   258 // End of File