vtengines/videoteleng/Inc/Audio/CVtEngAudioHandler.h
changeset 0 ed9695c8bcbe
child 8 07d1685f0cd4
equal deleted inserted replaced
-1:000000000000 0:ed9695c8bcbe
       
     1 /*
       
     2 * Copyright (c) 2004-2006 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:  Audio handler class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef CVTENGAUDIOHANDLER_H
       
    21 #define CVTENGAUDIOHANDLER_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include    <e32base.h>
       
    25 #include    "MVtEngAudio.h"
       
    26 #include    "CVtEngOperation.h"
       
    27 #include    "MVtEngSettingPSObserver.h"
       
    28 #include    "CVTEngPubSubsListener.h"
       
    29 #include    "CVtEngAccessoryHandler.h"
       
    30 #include    "MVtEngAccessoryObserver.h"
       
    31 // new audio routing
       
    32 #include    "telephonyaudiorouting.h"
       
    33 #include    "mtelephonyaudioroutingobserver.h"
       
    34 #include    <rphcltserver.h>
       
    35 #include    <mmf/server/sounddevice.h>
       
    36 
       
    37 // FORWARD DECLARATIONS
       
    38 class CVtEngStateManager;
       
    39 class CRoutingEnabler;
       
    40 
       
    41 /**
       
    42 *  Class for audio handling.
       
    43 *
       
    44 *  @lib videoteleng.lib
       
    45 *  @since Series 60 2.6
       
    46 */
       
    47 NONSHARABLE_CLASS( CVtEngAudioHandler )
       
    48     : public CBase,
       
    49       public MVtEngAudio,
       
    50       private MVtEngAccessoryObserver,
       
    51       private MTelephonyAudioRoutingObserver
       
    52     {
       
    53     public: // Constructors and destructor
       
    54 
       
    55         /**
       
    56         * Two-phased constructor.
       
    57         */
       
    58         static CVtEngAudioHandler* NewL();
       
    59 
       
    60         /**
       
    61         * Destructor.
       
    62         */
       
    63         virtual ~CVtEngAudioHandler();
       
    64 
       
    65     public: // New functions.
       
    66 
       
    67         /**
       
    68         * Performs on operation in the handler.
       
    69         * @param operation to be performed on the handler
       
    70         */
       
    71         void HandleL( CVtEngOperation& aOperation );
       
    72 
       
    73         /**
       
    74         * Creates/releases temporary DevSound instance.
       
    75         * @param aEnable
       
    76         *   ETrue creates devSound
       
    77         *   EFalse destructs devSound
       
    78         */
       
    79         void SetRoutingEnablerL( const TBool aEnable );
       
    80 
       
    81         /**
       
    82         * Increases audio volume
       
    83         */
       
    84         TBool IncreaseVolume();
       
    85 
       
    86         /**
       
    87         * Decreases audio volume
       
    88         */
       
    89         TBool DecreaseVolume();
       
    90 
       
    91     private: // Functions from base classes.
       
    92 
       
    93         // from MVtEngAccessoryObserver
       
    94 
       
    95         /** @see MVtEngAccessoryObserver */
       
    96         virtual void AccessoryModeChanged( const TAccMode& aMode,
       
    97             const TBool aActivated );
       
    98 
       
    99         // from MTelephonyAudioRoutingObserver
       
   100 
       
   101         /** @see MTelephonyAudioRoutingObserver::AvailableOutputsChanged */
       
   102 		virtual void AvailableOutputsChanged( CTelephonyAudioRouting& aTelephonyAudioRouting );
       
   103 
       
   104         /** @see MTelephonyAudioRoutingObserver::OutputChanged */
       
   105 		virtual void OutputChanged( CTelephonyAudioRouting& aTelephonyAudioRouting );
       
   106 
       
   107         /** @see MTelephonyAudioRoutingObserver::SetOutputComplete */
       
   108 		virtual void SetOutputComplete( CTelephonyAudioRouting& aTelephonyAudioRouting,
       
   109 		    TInt aError );
       
   110 
       
   111     public: // Functions from base classes.
       
   112 
       
   113         /** @see MVtEngAudio::GetRoutingState. */
       
   114         virtual TInt GetRoutingState( TAudioRoutingState& aAudioRoutingState );
       
   115 
       
   116         /** @see MVtEngAudio::GetRoutingAvailability. */
       
   117         virtual TInt GetRoutingAvailability(
       
   118             const TAudioRoutingState aAudioRoutingState,
       
   119             TBool& aAvailable );
       
   120 
       
   121         /** @see MVtEngAudio::GetHeadsetType. */
       
   122         virtual TInt GetHeadsetType( TWiredHeadsetType& aHeadsetType );
       
   123 
       
   124         /** @see MVtEngAudio::OutputVolume. */
       
   125         virtual TInt OutputVolume( const TBool aHandsetVolume ) const;
       
   126 
       
   127     private:
       
   128 
       
   129         /**
       
   130         * C++ default constructor.
       
   131         */
       
   132         CVtEngAudioHandler();
       
   133 
       
   134         /**
       
   135         * By default Symbian 2nd phase constructor is private.
       
   136         */
       
   137         void ConstructL();
       
   138 
       
   139         /**
       
   140         * Completes operation.
       
   141         * @param aResult error code
       
   142         */
       
   143         void CompleteOperation( TInt aResult );
       
   144 
       
   145         /**
       
   146         * Sets loudspeaker on / off.
       
   147         * @param aTurnOn ETrue if on, EFalse if off
       
   148         * @param aShowNote ETrue if note is allowed to be shown, EFalse if not
       
   149         */
       
   150         void SetLoudspeakerL( TBool aTurnOn, TBool aShowNote );
       
   151 
       
   152         /**
       
   153         * Sets Bluetooth on / off.
       
   154         * @param aTurnOn ETrue if on, EFalse if off
       
   155         */
       
   156         void SetBluetoothL( TBool aTurnOn );
       
   157 
       
   158         /**
       
   159         * Updates current volume that should be used.
       
   160         */
       
   161         void UpdateCurrentVolume();
       
   162 
       
   163         /**
       
   164         * Checks if given audio output route is available.
       
   165         * @return ETrue if given audio output route is available
       
   166         */
       
   167         TBool IsOutputAvailable( const CTelephonyAudioRouting::TAudioOutput aOutput );
       
   168 
       
   169         /**
       
   170         * Modifies the volume by aDelta.
       
   171         */
       
   172         TBool AdjustVolume( const TInt aDelta );
       
   173 
       
   174     private: // Data
       
   175 
       
   176         // Enumeration flags used in the implementation.
       
   177         enum
       
   178             {
       
   179             // Handset
       
   180             EFlagHandset = 1,
       
   181             // Loudspeaker
       
   182             EFlagLoudspeaker = 2,
       
   183             // Bluetooth handsfree
       
   184             EFlagBT = 4,
       
   185             // Wired headset
       
   186             EFlagWiredHeadset = 8
       
   187             };
       
   188 
       
   189         // Accessory mode listener class.
       
   190         CVtEngAccessoryHandler* iAccHandler;
       
   191 
       
   192         // Contains the current accessory and it's audio mode.
       
   193         TAccPolAccessoryMode iAccMode;
       
   194 
       
   195         // Pointer to telephony audio routing instance
       
   196         CTelephonyAudioRouting* iTelephonyAudioRouting;
       
   197 
       
   198         // Current audio routing state
       
   199         CTelephonyAudioRouting::TAudioOutput iCurrentAudioOutput;
       
   200 
       
   201         // Holds old routing state.
       
   202         TAudioRoutingState iOldAudioRoutingState;
       
   203 
       
   204         // Pointer to an operation.
       
   205         CVtEngOperation* iOperation;
       
   206 
       
   207         /**
       
   208         * For enabling audio routing before actual
       
   209         * DevSound for play is created.
       
   210         */
       
   211         CRoutingEnabler*    iRoutingEnabler;
       
   212     };
       
   213 
       
   214 /**
       
   215 * Class for handling dummy DevSound. It enables audio routing
       
   216 * before video call is connected. Proper devSound instance
       
   217 * must exist in order to control audio routing. Actual instance
       
   218 * is created in protocol in later phase of the stack
       
   219 * initialization and one in here is deleted.
       
   220 */
       
   221 NONSHARABLE_CLASS( CRoutingEnabler ) :
       
   222     public CBase,
       
   223     private MDevSoundObserver
       
   224     {
       
   225     public: // constructor and destructor
       
   226 
       
   227         // Constructor
       
   228         static CRoutingEnabler* NewL();
       
   229 
       
   230         // Destructor
       
   231         ~CRoutingEnabler();
       
   232 
       
   233     private: // constructors
       
   234 
       
   235         // c++ constructor
       
   236         CRoutingEnabler();
       
   237 
       
   238         /**
       
   239         * Creates and starts devSound.
       
   240         */
       
   241         void StartL();
       
   242 
       
   243     public: // new functions
       
   244 
       
   245         public: // from MDevSoundObserver
       
   246 
       
   247         /**
       
   248         * @see MDevSoundObserver
       
   249         */
       
   250         virtual void InitializeComplete( TInt aError );
       
   251 
       
   252         /**
       
   253         * @see MDevSoundObserver
       
   254         */
       
   255         virtual void ToneFinished( TInt aError );
       
   256 
       
   257         /**
       
   258         * @see MDevSoundObserver
       
   259         */
       
   260         virtual void BufferToBeFilled( CMMFBuffer* aBuffer );
       
   261 
       
   262         /**
       
   263         * @see MDevSoundObserver
       
   264         */
       
   265         virtual void PlayError( TInt aError );
       
   266 
       
   267         /**
       
   268         * @see MDevSoundObserver
       
   269         */
       
   270         virtual void BufferToBeEmptied( CMMFBuffer* aBuffer );
       
   271 
       
   272         /**
       
   273         * @see MDevSoundObserver
       
   274         */
       
   275         virtual void RecordError( TInt aError );
       
   276 
       
   277         /**
       
   278         * @see MDevSoundObserver
       
   279         */
       
   280         virtual void ConvertError( TInt aError );
       
   281 
       
   282         /**
       
   283         * @see MDevSoundObserver
       
   284         */
       
   285         virtual void DeviceMessage(
       
   286             TUid aMessageType,
       
   287             const TDesC8& aMsg );
       
   288 
       
   289     private:
       
   290         // Temporary DevSound instance to enable audio routing
       
   291         // before actual instance in protocol is ready.
       
   292         // Routing can be changed already when MO call is alerting.
       
   293         CMMFDevSound* iDevSound;
       
   294 
       
   295         // Variable to detect failure in Devsound initialization or PlayInitL().
       
   296         // If failure happens, Devsound instance is deleted outside callback
       
   297         // in desctructor. ETrue; failure happened, EFalse; all OK
       
   298         TBool iDevsoundInitializeFailure;
       
   299     };
       
   300 
       
   301 
       
   302 #endif      // CVTENGAUDIOHANDLER_H
       
   303 
       
   304 // End of File