vtengines/videoteleng/Src/Audio/CVtEngAudioHandler.cpp
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 implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    "CVtEngAudioHandler.h"
       
    21 #include    "CVtEngSettings.h"
       
    22 #include    "CVtEngEventManager.h"
       
    23 #include    "VtEngUtils.h"
       
    24 #include    <cvtlogger.h>
       
    25 #include    <featmgr.h>
       
    26 #include    <mmf/server/sounddevice.h>
       
    27 #include    <audiopreference.h>
       
    28 #include    "VtEngUtils.h"
       
    29 #include    "CVtEngStateManager.h"
       
    30 #include    "MVtEngSessionInfo.h"
       
    31 #include    "CVtEngHandlerContainer.h"
       
    32 
       
    33 // CONSTANTS
       
    34 
       
    35 // For DevSound initialization
       
    36 const TInt KVtEngUidControlHwDevice = 0x10206593;
       
    37 
       
    38 // ============================ MEMBER FUNCTIONS ===============================
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CVtEngAudioHandler::CVtEngAudioHandler
       
    42 // C++ default constructor can NOT contain any code, that
       
    43 // might leave.
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CVtEngAudioHandler::CVtEngAudioHandler()
       
    47     {
       
    48     __VTPRINT( DEBUG_CONSTRUCT | DEBUG_AUDIO, "AH.c++" )
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CVtEngAudioHandler::ConstructL
       
    53 // Symbian 2nd phase constructor can leave.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 void CVtEngAudioHandler::ConstructL()
       
    57     {
       
    58     __VTPRINT( DEBUG_CONSTRUCT | DEBUG_AUDIO, "AH.ConstructL" )
       
    59 
       
    60     iAccHandler = &CVtEngUtility::AccessoryHandler();
       
    61     iAccHandler->RegisterObserverL( this );
       
    62     iTelephonyAudioRouting = CTelephonyAudioRouting::NewL( *this );
       
    63     iCurrentAudioOutput = iTelephonyAudioRouting->Output();
       
    64 
       
    65     // Fetch the mode.
       
    66     User::LeaveIfError( iAccHandler->AccessoryMode( iAccMode ) );
       
    67     __VTPRINT2( DEBUG_AUDIO, "AH.iAccMode %d", ( TInt )iAccMode.iAccessoryMode )
       
    68 
       
    69     UpdateCurrentVolume();
       
    70     __VTPRINT( DEBUG_CONSTRUCT | DEBUG_AUDIO, "AH.ConstructL<")
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CVtEngAudioHandler::NewL
       
    75 // Two-phased constructor.
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 CVtEngAudioHandler* CVtEngAudioHandler::NewL()
       
    79     {
       
    80     CVtEngAudioHandler* self = new( ELeave ) CVtEngAudioHandler;
       
    81     CleanupStack::PushL( self );
       
    82     self->ConstructL();
       
    83     CleanupStack::Pop();
       
    84     return self;
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CVtEngAudioHandler::~CVtEngAudioHandler
       
    89 // Destructor.
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 CVtEngAudioHandler::~CVtEngAudioHandler()
       
    93     {
       
    94     __VTPRINT( DEBUG_AUDIO, "AH.~<" )
       
    95     delete iRoutingEnabler;
       
    96 
       
    97     delete iTelephonyAudioRouting;
       
    98     if ( iAccHandler )
       
    99     	{
       
   100     	iAccHandler->RemoveObserver( this );
       
   101     	}
       
   102     __VTPRINT( DEBUG_AUDIO, "AH.~>" )
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CVtEngAudioHandler::HandleL
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 void CVtEngAudioHandler::HandleL( CVtEngOperation& aOperation )
       
   110     {
       
   111     __VTPRINT2( DEBUG_AUDIO, "AH.HandleL op=%d", ( TInt )iOperation )
       
   112     if ( iOperation )
       
   113         {
       
   114         // While operation is ongoing, another call should not be made.
       
   115         User::Leave( KErrArgument );
       
   116         }
       
   117 
       
   118     MVtEngAudio::TVtEngRoutingSetting routeSetting;
       
   119     TVtEngOpParamUtil<MVtEngAudio::TVtEngRoutingSetting>::Set(
       
   120         routeSetting, aOperation );
       
   121 
       
   122     switch( routeSetting )
       
   123         {
       
   124         case EActivateHandsfree:
       
   125             SetLoudspeakerL( ETrue, ETrue );
       
   126             break;
       
   127 
       
   128         case EDeactivateHansfree:
       
   129             SetLoudspeakerL( EFalse, ETrue );
       
   130             break;
       
   131 
       
   132         case EActivateBT:
       
   133             SetBluetoothL( ETrue ); // asynchronous
       
   134             break;
       
   135 
       
   136         case EDeactivateBT:
       
   137             SetBluetoothL( EFalse );
       
   138             break;
       
   139         }
       
   140 
       
   141     iOperation = &aOperation;
       
   142     __VTPRINT( DEBUG_AUDIO | DEBUG_RETURN, "AH.HandleL" )
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CVtEngAudioHandler::SetRoutingEnablerL
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 void CVtEngAudioHandler::SetRoutingEnablerL( const TBool aEnable )
       
   150     {
       
   151     __VTPRINTENTER( "AHRout.SetRoutingEnablerL" )
       
   152 
       
   153     if ( aEnable && !iRoutingEnabler )
       
   154         {
       
   155         // Before connected state audio routing can be changed by the user
       
   156         // only in MO calls. Create temporary devsound only if call is such.
       
   157         const CVtEngHandlerContainer& handlers =
       
   158             CVtEngUtility::StateManager()->Handlers();
       
   159         const MVtEngSessionInfo& session = handlers.Session();
       
   160         MVtEngSessionInfo::TDirection direction =
       
   161             MVtEngSessionInfo::EDirectionNone; // init to MO, if
       
   162         const TInt err( session.GetDirection( direction ) );
       
   163         if ( err == KErrNone && direction == MVtEngSessionInfo::EDirectionMO )
       
   164             {
       
   165             iRoutingEnabler = CRoutingEnabler::NewL();
       
   166             }
       
   167         }
       
   168     else if ( !aEnable )
       
   169         {
       
   170         delete iRoutingEnabler;
       
   171         iRoutingEnabler = NULL;
       
   172         }
       
   173     __VTPRINTEXIT( "AHRout.ReleaseRoutingEnablerL" )
       
   174     }
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // CVtEngAudioHandler::IncreaseVolume
       
   178 // -----------------------------------------------------------------------------
       
   179 //
       
   180 TBool CVtEngAudioHandler::IncreaseVolume()
       
   181     {
       
   182     __VTPRINTENTER( "AH.IncreaseVolume" )
       
   183     TBool adjustOk( AdjustVolume( 1 ) );
       
   184     if ( !adjustOk )
       
   185         {
       
   186         // only reason for AdjustVolume to fail is that volume is max already
       
   187         CVtEngEventManager::NotifyEvent( KVtEngAudioVolumeMax );
       
   188         }
       
   189     __VTPRINTEXITR( "AH.IncreaseVolume %d", adjustOk )
       
   190     return adjustOk;
       
   191     }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // CVtEngAudioHandler::DecreaseVolume
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 TBool CVtEngAudioHandler::DecreaseVolume()
       
   198     {
       
   199     __VTPRINTENTER( "AH.DecreaseVolume" )
       
   200     TBool adjustOk( AdjustVolume( -1 ) );
       
   201     if ( !adjustOk )
       
   202         {
       
   203         // only reason for AdjustVolume to fail is that volume is min already
       
   204         CVtEngEventManager::NotifyEvent( KVtEngAudioVolumeMin );
       
   205         }
       
   206     __VTPRINTEXITR( "AH.DecreaseVolume %d", adjustOk )
       
   207     return adjustOk;
       
   208     }
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // CVtEngAudioHandler::AdjustVolume
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 TBool CVtEngAudioHandler::AdjustVolume( const TInt aDelta )
       
   215     {
       
   216     __VTPRINTENTER( "AH.AdjustVolume" )
       
   217     __VTPRINT2( DEBUG_AUDIO, "AH.AdjustVolume aDelta = %d", aDelta )
       
   218     TBool result( EFalse );
       
   219     CVtEngSettings& settings( CVtEngUtility::Settings() );
       
   220     TVtEngOutputVolume volume;
       
   221     settings.GetVolume( volume.iHandsetVolume, EFalse, EFalse );
       
   222     settings.GetVolume( volume.iHandsfreeVolume, ETrue, EFalse );
       
   223     TAudioRoutingState routingState;
       
   224     GetRoutingState( routingState );
       
   225     TInt& value( ( routingState == EAudioLoudspeaker ) ?
       
   226         volume.iHandsfreeVolume : volume.iHandsetVolume );
       
   227     value += aDelta;
       
   228     TInt validValue( settings.ValidVolume( value ) );
       
   229     if ( validValue == value )
       
   230         {
       
   231         settings.SetVolume(
       
   232             volume.iHandsetVolume,
       
   233             volume.iHandsfreeVolume,
       
   234             ETrue );
       
   235         settings.SetVolume(
       
   236             volume.iHandsetVolume,
       
   237             volume.iHandsfreeVolume,
       
   238             EFalse );
       
   239         result = ETrue;
       
   240         }
       
   241     __VTPRINTEXITR( "AH.AdjustVolume %d", result )
       
   242     return result;
       
   243     }
       
   244 
       
   245 // -----------------------------------------------------------------------------
       
   246 // CVtEngAudioHandler::GetRoutingState
       
   247 // -----------------------------------------------------------------------------
       
   248 //
       
   249 TInt CVtEngAudioHandler::GetRoutingState(
       
   250         TAudioRoutingState& aAudioRoutingState )
       
   251     {
       
   252     switch ( iCurrentAudioOutput )
       
   253         {
       
   254         // Wired headset has the highest priority.
       
   255         case CTelephonyAudioRouting::EWiredAudioAccessory:
       
   256             __VTPRINT( DEBUG_CONSTRUCT | DEBUG_AUDIO, "AH.GRS.wired" )
       
   257             aAudioRoutingState = EAudioWiredHeadset;
       
   258             break;
       
   259 
       
   260         // Then bluetooth handsfree.
       
   261         case CTelephonyAudioRouting::EBTAudioAccessory:
       
   262             __VTPRINT( DEBUG_CONSTRUCT | DEBUG_AUDIO, "AH.GRS.bt" )
       
   263             aAudioRoutingState = EAudioBT;
       
   264             break;
       
   265 
       
   266         // Loudspeaker.
       
   267         case CTelephonyAudioRouting::ELoudspeaker:
       
   268             __VTPRINT( DEBUG_CONSTRUCT | DEBUG_AUDIO, "AH.GRS.IHF" )
       
   269             aAudioRoutingState = EAudioLoudspeaker;
       
   270             break;
       
   271 
       
   272         // Handset as fallback.
       
   273         default:
       
   274             __VTPRINT( DEBUG_CONSTRUCT | DEBUG_AUDIO, "AH.GRS.Handset" )
       
   275             aAudioRoutingState = EAudioHandset;
       
   276             break;
       
   277         }
       
   278 
       
   279     return KErrNone;
       
   280     }
       
   281 
       
   282 // -----------------------------------------------------------------------------
       
   283 // CVtEngAudioHandler::GetRoutingAvailability
       
   284 // -----------------------------------------------------------------------------
       
   285 //
       
   286 TInt CVtEngAudioHandler::GetRoutingAvailability(
       
   287         const TAudioRoutingState aAudioRoutingState,
       
   288         TBool& aAvailable )
       
   289     {
       
   290     TAudioRoutingState currentRouting;
       
   291     GetRoutingState( currentRouting ); // always succeeds
       
   292 
       
   293     if ( currentRouting == aAudioRoutingState )
       
   294         {
       
   295         // It is possible to route to itself, although it does not make
       
   296         // much sense.
       
   297         aAvailable = ETrue;
       
   298         }
       
   299     else if ( currentRouting == EAudioWiredHeadset )
       
   300         {
       
   301         // For wired headset, audio routings are not possible.
       
   302         aAvailable = EFalse;
       
   303         }
       
   304     else
       
   305         {
       
   306         switch ( aAudioRoutingState )
       
   307             {
       
   308             case EAudioHandset:
       
   309             case EAudioLoudspeaker:
       
   310                 // Handset & loudspeaker are always available.
       
   311                 aAvailable = ETrue;
       
   312                 break;
       
   313 
       
   314             case EAudioBT:
       
   315                 aAvailable = IsOutputAvailable( CTelephonyAudioRouting::EBTAudioAccessory );
       
   316                 break;
       
   317 
       
   318             case EAudioWiredHeadset:
       
   319                 // Wired headset can not be routed to. When headset is
       
   320                 // attached, routing happens automatically.
       
   321                 aAvailable = EFalse;
       
   322                 break;
       
   323             }
       
   324         }
       
   325 
       
   326     __VTPRINT3( DEBUG_AUDIO, "AH.GRA state %d availability=%d",
       
   327         aAudioRoutingState, aAvailable )
       
   328     return KErrNone;
       
   329     }
       
   330 
       
   331 // -----------------------------------------------------------------------------
       
   332 // CVtEngAudioHandler::GetHeadsetType
       
   333 // -----------------------------------------------------------------------------
       
   334 //
       
   335 TInt CVtEngAudioHandler::GetHeadsetType(
       
   336         TWiredHeadsetType& aHeadsetType )
       
   337     {
       
   338     switch ( iAccMode.iAccessoryMode )
       
   339         {
       
   340         case EAccModeWiredHeadset:
       
   341         case EAccModeWiredCarKit:
       
   342         case EAccModeMusicStand:
       
   343             aHeadsetType = EWiredHeadset;
       
   344             break;
       
   345 
       
   346         case EAccModeLoopset:
       
   347             aHeadsetType = EWiredLoopset;
       
   348             break;
       
   349 
       
   350         case EAccModeTextDevice:
       
   351             aHeadsetType = EWiredTty;
       
   352             break;
       
   353 
       
   354         case EAccModeHandPortable:
       
   355         case EAccModeWirelessHeadset:
       
   356         case EAccModeWirelessCarKit:
       
   357         default:
       
   358             // Not wired headset.
       
   359             aHeadsetType = EWiredNone;
       
   360             break;
       
   361         }
       
   362 
       
   363     __VTPRINT2( DEBUG_AUDIO, "AH.HeadsetType=%d", aHeadsetType )
       
   364     return KErrNone;
       
   365     }
       
   366 
       
   367 // -----------------------------------------------------------------------------
       
   368 // CVtEngAudioHandler::OutputVolume
       
   369 // -----------------------------------------------------------------------------
       
   370 //
       
   371 TInt CVtEngAudioHandler::OutputVolume(
       
   372         const TBool aHandsetVolume ) const
       
   373     {
       
   374     __VTPRINT2( DEBUG_AUDIO, "AH.OutputVolume isHandset=%d", aHandsetVolume )
       
   375     TInt vol = 0;
       
   376     CVtEngSettings& setting = CVtEngUtility::Settings();
       
   377     TInt err( setting.GetVolume( vol, !aHandsetVolume, EFalse ) );
       
   378     if ( err != KErrNone )
       
   379         {
       
   380         vol = err;
       
   381         }
       
   382     __VTPRINT2( DEBUG_AUDIO, "AH.OutputVolume vol=%d",vol )
       
   383     return vol;
       
   384     }
       
   385 
       
   386 // -----------------------------------------------------------------------------
       
   387 // CVtEngAudioHandler::SetLoudspeakerL
       
   388 // -----------------------------------------------------------------------------
       
   389 //
       
   390 void CVtEngAudioHandler::SetLoudspeakerL( TBool aTurnOn, TBool /*aShowNote*/ )
       
   391     {
       
   392     __VTPRINTENTER(	"AH.SetLoudspeakerL" )
       
   393     __VTPRINT2( DEBUG_AUDIO, "AH.SetLoudspeakerL %d", aTurnOn )
       
   394     TBool available( EFalse );
       
   395     GetRoutingAvailability( EAudioLoudspeaker, available );
       
   396     if ( !available )
       
   397         {
       
   398         User::Leave( KErrNotSupported );
       
   399         }
       
   400     // Set shownote flag up in telephony audiorouting, before calling SetOutputL.
       
   401     User::LeaveIfError( iTelephonyAudioRouting->SetShowNote( ETrue ) );
       
   402 
       
   403     if( aTurnOn )
       
   404         {
       
   405         iTelephonyAudioRouting->SetOutputL( CTelephonyAudioRouting::ELoudspeaker );
       
   406         }
       
   407     else
       
   408         {
       
   409         iTelephonyAudioRouting->SetOutputL( CTelephonyAudioRouting::EHandset );
       
   410         }
       
   411     __VTPRINTEXIT( "AH.SetLoudspeakerL" )
       
   412     }
       
   413 
       
   414 // -----------------------------------------------------------------------------
       
   415 // CVtEngAudioHandler::SetBluetoothL
       
   416 // -----------------------------------------------------------------------------
       
   417 //
       
   418 void CVtEngAudioHandler::SetBluetoothL( TBool aTurnOn )
       
   419     {
       
   420     __VTPRINTENTER( "AH.SetBluetoothL" )
       
   421     TBool available( EFalse );
       
   422     GetRoutingAvailability( EAudioBT, available );
       
   423     if ( !available )
       
   424         {
       
   425         User::Leave( KErrNotSupported );
       
   426         }
       
   427     // Set shownote flag up in telephony audiorouting, before calling SetOutputL.
       
   428     User::LeaveIfError( iTelephonyAudioRouting->SetShowNote( ETrue ) );
       
   429 
       
   430     if( aTurnOn )
       
   431         {
       
   432         iTelephonyAudioRouting->SetOutputL( CTelephonyAudioRouting::EBTAudioAccessory );
       
   433         }
       
   434     else
       
   435         {
       
   436         iTelephonyAudioRouting->SetOutputL( CTelephonyAudioRouting::EHandset );
       
   437         }
       
   438     __VTPRINTEXIT( "AH.SetBluetoothL" )
       
   439     }
       
   440 
       
   441 // -----------------------------------------------------------------------------
       
   442 // CVtEngAudioHandler::AvailableOutputsChanged
       
   443 // -----------------------------------------------------------------------------
       
   444 //
       
   445 void CVtEngAudioHandler::AvailableOutputsChanged(
       
   446     CTelephonyAudioRouting& /*aTelephonyAudioRouting*/ )
       
   447     {
       
   448     __VTPRINTENTER( "AH.AvailableOutputsChanged" )
       
   449     CVtEngEventManager::NotifyEvent( KVtEngAudioRoutingAvailabilityChanged );
       
   450     __VTPRINTEXIT( "AH.AvailableOutputsChanged" )
       
   451     }
       
   452 
       
   453 // -----------------------------------------------------------------------------
       
   454 // CVtEngAudioHandler::OutputChanged
       
   455 // -----------------------------------------------------------------------------
       
   456 //
       
   457 void CVtEngAudioHandler::OutputChanged(
       
   458     CTelephonyAudioRouting& aTelephonyAudioRouting )
       
   459     {
       
   460     __VTPRINTENTER( "AH.OutputChanged" )
       
   461     CTelephonyAudioRouting::TAudioOutput
       
   462         previousAudioOutput( iCurrentAudioOutput );
       
   463     iCurrentAudioOutput = aTelephonyAudioRouting.Output();
       
   464     CVtEngEventManager::NotifyEvent( KVtEngAudioRoutingChanged );
       
   465     // HandSet -> IHF
       
   466     if( ( previousAudioOutput == CTelephonyAudioRouting::EHandset ) &&
       
   467         ( iCurrentAudioOutput == CTelephonyAudioRouting::ELoudspeaker ) )
       
   468         {
       
   469         __VTPRINT( DEBUG_AUDIO, "AH.OutputChanged signalling HandSet to IHF" )
       
   470         }
       
   471     // IHF -> HandSet
       
   472     else if( ( previousAudioOutput == CTelephonyAudioRouting::ELoudspeaker ) &&
       
   473         ( iCurrentAudioOutput == CTelephonyAudioRouting::EHandset ) )
       
   474         {
       
   475         __VTPRINT( DEBUG_AUDIO, "AH.OutputChanged signalling IHF to HandSet" )
       
   476         }
       
   477     UpdateCurrentVolume();
       
   478     __VTPRINTEXITR( "AH.OutputChanged %d", iCurrentAudioOutput )
       
   479     }
       
   480 
       
   481 // -----------------------------------------------------------------------------
       
   482 // CVtEngAudioHandler::SetOutputComplete
       
   483 // -----------------------------------------------------------------------------
       
   484 //
       
   485 void CVtEngAudioHandler::SetOutputComplete(
       
   486     CTelephonyAudioRouting& aTelephonyAudioRouting,
       
   487     TInt aError )
       
   488     {
       
   489     __VTPRINTENTER( "AH.SetOutputComplete" )
       
   490     if ( aError == KErrNone )
       
   491         {
       
   492         OutputChanged( aTelephonyAudioRouting );
       
   493         }
       
   494     CompleteOperation( aError );
       
   495     __VTPRINTEXIT( "AH.SetOutputComplete" )
       
   496     }
       
   497 
       
   498 // -----------------------------------------------------------------------------
       
   499 // CVtEngAudioHandler::CompleteOperation
       
   500 // -----------------------------------------------------------------------------
       
   501 //
       
   502 void CVtEngAudioHandler::CompleteOperation( TInt aResult )
       
   503     {
       
   504     __VTPRINT3( DEBUG_AUDIO, "AH.CompleteOperation op=%d,res=%d" ,
       
   505         ( TInt )iOperation, aResult )
       
   506     if ( iOperation )
       
   507         {
       
   508         iOperation->HandleOpComplete( aResult );
       
   509         iOperation = NULL;
       
   510         }
       
   511     }
       
   512 
       
   513 // -----------------------------------------------------------------------------
       
   514 // CVtEngAudioHandler::UpdateCurrentVolume
       
   515 // -----------------------------------------------------------------------------
       
   516 //
       
   517 void CVtEngAudioHandler::UpdateCurrentVolume()
       
   518     {
       
   519     __VTPRINTENTER( "AH.UpdateCurrentVolume" )
       
   520     TAudioRoutingState currentRouting = EAudioHandset;
       
   521     GetRoutingState( currentRouting );
       
   522 
       
   523     const TBool currentVolume = ( currentRouting == EAudioLoudspeaker );
       
   524     CVtEngSettings& setting = CVtEngUtility::Settings();
       
   525     setting.SetCurrentVolume( currentVolume );
       
   526 
       
   527     __VTPRINTEXITR( "AH.UpdateCurrentVolume output is IHF=%d", currentVolume )
       
   528     }
       
   529 
       
   530 // -----------------------------------------------------------------------------
       
   531 // CVtEngAudioHandler::AccessoryModeChanged
       
   532 // -----------------------------------------------------------------------------
       
   533 //
       
   534 void CVtEngAudioHandler::AccessoryModeChanged(
       
   535     const TAccMode& aMode, const TBool /* aActivated */ )
       
   536     {
       
   537     iAccMode.iAccessoryMode = aMode;
       
   538     }
       
   539 
       
   540 
       
   541 // -----------------------------------------------------------------------------
       
   542 // CVtEngAudioHandler::IsOutputAvailable
       
   543 // -----------------------------------------------------------------------------
       
   544 //
       
   545 TBool CVtEngAudioHandler::IsOutputAvailable(
       
   546     const CTelephonyAudioRouting::TAudioOutput aOutput )
       
   547     {
       
   548     const TArray< CTelephonyAudioRouting::TAudioOutput > outputs =
       
   549         iTelephonyAudioRouting->AvailableOutputs();
       
   550 
       
   551     for ( TInt i = 0; i < outputs.Count(); i++ )
       
   552         {
       
   553         if ( outputs[ i ] == aOutput )
       
   554             {
       
   555             return ETrue;
       
   556             }
       
   557         }
       
   558     return EFalse;
       
   559     }
       
   560 // -----------------------------------------------------------------------------
       
   561 // CRoutingEnabler::NewL
       
   562 // -----------------------------------------------------------------------------
       
   563 //
       
   564 CRoutingEnabler* CRoutingEnabler::NewL()
       
   565     {
       
   566     CRoutingEnabler* enabler =
       
   567         new ( ELeave ) CRoutingEnabler();
       
   568     CleanupStack::PushL( enabler );
       
   569     enabler->StartL();
       
   570     CleanupStack::Pop( enabler );
       
   571     return enabler;
       
   572     }
       
   573 
       
   574 // Destructor
       
   575 CRoutingEnabler::~CRoutingEnabler()
       
   576     {
       
   577     if ( iDevSound )
       
   578     	{
       
   579         // If initialization ahs been successfull, Devsound Play has started
       
   580         // and need to be stopped.
       
   581         if( !iDevsoundInitializeFailure )
       
   582             {
       
   583             __VTPRINT( DEBUG_MEDIA, "AHRout.~ Stopping audio" )
       
   584     	    iDevSound->Stop();
       
   585             }
       
   586         delete iDevSound;
       
   587     	iDevSound = NULL;
       
   588         }
       
   589     }
       
   590 
       
   591 // c++ constructor
       
   592 CRoutingEnabler::CRoutingEnabler()
       
   593     {
       
   594     }
       
   595 
       
   596 // -----------------------------------------------------------------------------
       
   597 // CRoutingEnabler::StartL
       
   598 // -----------------------------------------------------------------------------
       
   599 //
       
   600 void CRoutingEnabler::StartL()
       
   601     {
       
   602     __VTPRINTENTER( "AHRout.StartL" )
       
   603     iDevSound = CMMFDevSound::NewL();
       
   604 
       
   605     iDevSound->InitializeL(
       
   606         *( this ),
       
   607         EMMFStatePlaying );
       
   608     __VTPRINTEXIT( "AHRout.StartL" )
       
   609     }
       
   610 
       
   611 // -----------------------------------------------------------------------------
       
   612 // CRoutingEnabler::InitializeComplete
       
   613 // -----------------------------------------------------------------------------
       
   614 //
       
   615 void CRoutingEnabler::InitializeComplete( TInt aError )
       
   616     {
       
   617     __VTPRINTENTER( "AHRout.InitializeComplete" )
       
   618     if ( aError == KErrNone )
       
   619         {
       
   620         TMMFPrioritySettings prioritySettings;
       
   621         prioritySettings.iPriority = KAudioPriorityCSCallDownlink;
       
   622         prioritySettings.iPref =
       
   623             ( TMdaPriorityPreference ) KAudioPrefCSCallDownlink;
       
   624         prioritySettings.iState = EMMFStatePlaying;
       
   625         if ( iDevSound )
       
   626             {
       
   627             iDevSound->SetPrioritySettings( prioritySettings );
       
   628 
       
   629             TRAPD( err, iDevSound->PlayInitL() );
       
   630             if ( err != KErrNone )
       
   631             	{
       
   632             	__VTPRINT2( DEBUG_AUDIO, "AHRout.InitializeComplete PlayInitL err=%d", err )
       
   633 
       
   634                 // Devsound PlayInitL leave error happened.
       
   635                 iDevsoundInitializeFailure = ETrue;
       
   636             	}
       
   637             }
       
   638         }
       
   639     else
       
   640         {
       
   641         __VTPRINT2( DEBUG_AUDIO, "AHRout.InitializeComplete err=%d", aError )
       
   642 
       
   643         // Devsound initialization failed
       
   644         iDevsoundInitializeFailure = ETrue;
       
   645         }
       
   646     __VTPRINTEXIT( "AHRout.InitializeComplete" )
       
   647     }
       
   648 
       
   649 // -----------------------------------------------------------------------------
       
   650 // CRoutingEnabler::ToneFinished
       
   651 // -----------------------------------------------------------------------------
       
   652 //
       
   653 void CRoutingEnabler::ToneFinished( TInt /*aError*/)
       
   654     {
       
   655     }
       
   656 
       
   657 // -----------------------------------------------------------------------------
       
   658 // CRoutingEnabler::BufferToBeFilled
       
   659 // -----------------------------------------------------------------------------
       
   660 //
       
   661 void CRoutingEnabler::BufferToBeFilled(
       
   662     CMMFBuffer* /*aBuffer*/)
       
   663     {
       
   664     }
       
   665 
       
   666 // -----------------------------------------------------------------------------
       
   667 // CRoutingEnabler::PlayError
       
   668 // -----------------------------------------------------------------------------
       
   669 //
       
   670 void CRoutingEnabler::PlayError( TInt /*aError*/)
       
   671     {
       
   672     }
       
   673 
       
   674 // -----------------------------------------------------------------------------
       
   675 // CRoutingEnabler::BufferToBeEmptied
       
   676 // -----------------------------------------------------------------------------
       
   677 //
       
   678 void CRoutingEnabler::BufferToBeEmptied(
       
   679     CMMFBuffer* /*aBuffer*/ )
       
   680     {
       
   681     }
       
   682 
       
   683 // -----------------------------------------------------------------------------
       
   684 // CRoutingEnabler::RecordError
       
   685 // -----------------------------------------------------------------------------
       
   686 //
       
   687 void CRoutingEnabler::RecordError(
       
   688     TInt /*aError*/ )
       
   689     {
       
   690     }
       
   691 
       
   692 // -----------------------------------------------------------------------------
       
   693 // CRoutingEnabler::ConvertError
       
   694 // -----------------------------------------------------------------------------
       
   695 //
       
   696 void CRoutingEnabler::ConvertError( TInt /*aError*/ )
       
   697     {
       
   698     }
       
   699 
       
   700 // -----------------------------------------------------------------------------
       
   701 // CRoutingEnabler::DeviceMessage
       
   702 // -----------------------------------------------------------------------------
       
   703 //
       
   704 void CRoutingEnabler::DeviceMessage(
       
   705     TUid /*aMessageType*/, const TDesC8& /*aMsg*/ )
       
   706     {
       
   707     }
       
   708 
       
   709 //  End of File