phoneengine/audiohandling/src/cpeaudiodata.cpp
changeset 0 5f000ab63145
child 21 92ab7f8d0eab
child 61 41a7f70b3818
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     1 /*
       
     2 * Copyright (c) 2002-2007 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:  This module contains the implementation of AudioData class 
       
    15 *                member functions
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "cpeaudiodata.h"
       
    22 
       
    23 #include <AudioPreference.h>
       
    24 #include <mpephonemodelinternal.h>
       
    25 #include <mpedatastore.h>
       
    26 #include <mpeexternaldatahandler.h>
       
    27 #include <talogger.h>
       
    28 #include <telmicmutestatuspskeys.h>
       
    29 #include <PSVariables.h>
       
    30 
       
    31 #include "pepanic.pan"
       
    32 #include "cpeaudiodtmftoneplayer.h"
       
    33 #include "cpeaudioroutingmonitor.h"
       
    34 #include "cpecallaudioroutinghandler.h"
       
    35 #include "cpeaudiofactory.h"	
       
    36 #include <telinternalpskeys.h>
       
    37 // CONSTANTS
       
    38 //Mute Value for volume
       
    39 const TInt KPEDefaultVolume = 4;
       
    40 const TInt KPEMaxVolume = 10;
       
    41 
       
    42 // ================= MEMBER FUNCTIONS =======================
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CPEAudioData::CPEAudioData
       
    46 // C++ default constructor can NOT contain any code, that
       
    47 // might leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 CPEAudioData::CPEAudioData( 
       
    51         MPEPhoneModelInternal& aPhoneModel
       
    52         ) : iPhoneModel( aPhoneModel )
       
    53     {
       
    54     iRouteInitialized = EFalse;
       
    55     iAudioOutputChanged = EFalse; 
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CPEAudioData::ConstructL
       
    60 // Symbian 2nd phase constructor can leave
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 void CPEAudioData::ConstructL( CPEAudioFactory& aAudioFactory )
       
    64     {
       
    65     TEFLOGSTRING( KTAOBJECT, "AUD CPEAudioData::ConstructL start" );
       
    66     iAudioRoutingMonitor = CPEAudioRoutingMonitor::NewL( *this );
       
    67     iAudioRouting = aAudioFactory.CreateTelephonyAudioRoutingL(*iAudioRoutingMonitor);
       
    68     iAudioRoutingHandler = CPECallAudioRoutingHandler::NewL( *this );
       
    69  
       
    70     //Gets audio volumes from repository
       
    71     InitializeAudioVolumes();
       
    72     
       
    73     RProperty::TType type( RProperty::EInt );
       
    74     TSecurityPolicy readPolicy( ECapability_None );
       
    75     TSecurityPolicy writePolicy( ECapabilityWriteDeviceData );
       
    76     	
       
    77     RProperty::Define( KPSUidTelMicrophoneMuteStatus, 
       
    78         KTelMicrophoneMuteState,
       
    79         type,
       
    80         readPolicy,
       
    81         writePolicy );
       
    82                 
       
    83     TEFLOGSTRING( KTAINT, "AUD CPEAudioData::ConstructL  complete" );               
       
    84     }
       
    85 
       
    86 // Destructor
       
    87 EXPORT_C CPEAudioData::~CPEAudioData()
       
    88     {
       
    89     TEFLOGSTRING( KTAOBJECT, "AUD CPEAudioData::~CPEAudioData" );
       
    90  
       
    91     delete iAudioRouting;
       
    92     delete iAudioRoutingMonitor;
       
    93     delete iAudioRoutingHandler;
       
    94     
       
    95     iPEavailableOutputs.Close();
       
    96 
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CPEAudioData::InitializeAudioVolumes
       
   101 // Gets audio volume values from reporitory
       
   102 // -----------------------------------------------------------------------------
       
   103 //   
       
   104 void CPEAudioData::InitializeAudioVolumes()
       
   105     {
       
   106 // Connect to CPEGsmExternalDataHandler missing from TEPhoneEngineTestUtils wrapper !!!
       
   107     TInt volume;
       
   108    
       
   109     iPhoneModel.DataStoreExt()->Get( 
       
   110         EPEIncallLoudspeakerVolumeSetting, volume ); 
       
   111     iLoudspeakerVolume = volume;
       
   112     TEFLOGSTRING2( KTAINT, 
       
   113         "AUD CPEAudioData::CPEAudioData, DataStoreExt()->Get, iLoudspeakerVolume = %d",
       
   114          iLoudspeakerVolume );
       
   115          
       
   116     iPhoneModel.DataStoreExt()->Get( 
       
   117         EPEIncallEarVolumeSetting, volume ); 
       
   118     iHeadSetVolume = volume;
       
   119     TEFLOGSTRING2( KTAINT, 
       
   120         "AUD CPEAudioData::CPEAudioData, DataStoreExt()->Get, iLoudspeakerVolume = %d",
       
   121          iHeadSetVolume );
       
   122 
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CPEAudioData::GetAudioMuteSync
       
   127 // Creates synchronous request to get Audio Mute value.
       
   128 // (other items were commented in a header).
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 EXPORT_C void CPEAudioData::GetAudioMuteSync(
       
   132         TBool& aAudioMute ) const 
       
   133     {
       
   134     TEFLOGSTRING( KTAINT, "AUD CPEAudioData::GetAudioMuteSync" );     
       
   135     if ( IsMuted() ) 
       
   136         {
       
   137         //mute is on
       
   138         aAudioMute = ETrue;
       
   139         }
       
   140     else
       
   141         {
       
   142         aAudioMute = EFalse;
       
   143         }
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CPEAudioData::GetAudioVolumeSync
       
   148 // Creates synchronous request to get audio volume.
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 EXPORT_C void CPEAudioData::GetAudioVolumeSync(
       
   152         TInt& aAudioVolume ) const
       
   153     {
       
   154     TEFLOGSTRING( KTAINT, "AUD CPEAudioData::GetAudioVolumeSync" );
       
   155 
       
   156     if ( iPhoneModel.DataStore()->AudioOutput() == EPELoudspeaker )
       
   157         {
       
   158         iPhoneModel.DataStoreExt()->Get( 
       
   159             EPEIncallLoudspeakerVolumeSetting, aAudioVolume );
       
   160         TEFLOGSTRING( KTAINT, 
       
   161             "AUD CPEAudioData::GetAudioVolumeSync: EPEIncallLoudspeakerVolumeSetting");
       
   162         }
       
   163     else 
       
   164         {
       
   165         iPhoneModel.DataStoreExt()->Get( 
       
   166             EPEIncallEarVolumeSetting, aAudioVolume );
       
   167         TEFLOGSTRING( KTAINT, 
       
   168             "AUD CPEAudioData::GetAudioVolumeSync: EPEIncallEarVolumeSetting");            
       
   169         }
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CPEAudioData::SendErrorMessage
       
   174 // Saves errorcode to member variable and sends error notification to PhoneEngine.
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 void CPEAudioData::SendErrorMessage( 
       
   178         const TInt aErrorCode )
       
   179     {
       
   180     iPhoneModel.DataStore()->SetErrorCode( aErrorCode );
       
   181     TEFLOGSTRING( 
       
   182         KTAREQOUT, 
       
   183         "AUD CPEAudioData::SendErrorMessage: iPhoneModel.SendMessage( MEngineMonitor::EPEMessageAudioHandlingError )" );
       
   184     iPhoneModel.SendMessage( MEngineMonitor::EPEMessageAudioHandlingError );
       
   185     }
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // CPEAudioData::SendMessage
       
   189 // Forwards message to PhoneEngine.
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 void CPEAudioData::SendMessage( 
       
   193         const MEngineMonitor::TPEMessagesFromPhoneEngine aMessage )
       
   194     {
       
   195     TEFLOGSTRING2( KTAREQIN, 
       
   196         "AUD CPEAudioData::SendMessage: aMessage = %d", aMessage );
       
   197    
       
   198    if ( aMessage == MEngineMonitor::EPEMessageAudioVolumeChanged )
       
   199 	   {
       
   200 	    // update volume
       
   201 	    if ( iPhoneModel.DataStore()->AudioOutput() == EPELoudspeaker )
       
   202 	        {
       
   203 	        iLoudspeakerVolume = iPhoneModel.DataStore()->AudioVolume();
       
   204 	        TEFLOGSTRING2( KTAINT, 
       
   205 	            "AUD CPEAudioData::SendMessage: iLoudspeakerVolume = %d", 
       
   206 	            iLoudspeakerVolume );
       
   207 	        }
       
   208 	    else 
       
   209 	        {
       
   210 	        iHeadSetVolume = iPhoneModel.DataStore()->AudioVolume();
       
   211 	        TEFLOGSTRING2( KTAINT, 
       
   212 	            "AUD CPEAudioData::SendMessage: iHeadSetVolume = %d", 
       
   213 	            iHeadSetVolume );
       
   214 	        }	
       
   215     	   	
       
   216        	if ( !iAudioOutputChanged )
       
   217             {
       
   218             // EPEMessageAudioVolumeChanged message must not be sent 
       
   219             // while audio output change is being processed
       
   220             iPhoneModel.SendMessage( aMessage );	
       
   221             }
       
   222 	   }
       
   223     else 
       
   224         {
       
   225         iPhoneModel.SendMessage( aMessage );	
       
   226         }        
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // CPEAudioData::SendMessage
       
   231 // Forwards message to PhoneEngine. Output mode is saved.
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 void CPEAudioData::SendMessage( 
       
   235         const MEngineMonitor::TPEMessagesFromPhoneEngine aMessage,
       
   236         const CTelephonyAudioRouting::TAudioOutput aOutput )
       
   237     {
       
   238     TEFLOGSTRING3( 
       
   239          KTAREQIN, 
       
   240         "AUD CPEAudioData::SendMessage: aMessage = %d, aOutput = %d", 
       
   241         aMessage, aOutput );
       
   242         
       
   243     // BT long key press requires manual re-route to handset or loudspeaker
       
   244     if ( aOutput == CTelephonyAudioRouting::ENone &&
       
   245          iAudioRouting->PreviousOutput() == CTelephonyAudioRouting::EBTAudioAccessory )
       
   246         {
       
   247         SetRoutePreference( ETrue );
       
   248         }
       
   249     else
       
   250         {
       
   251         // store the old audio path volume
       
   252         if ( iPhoneModel.DataStore()->AudioOutput() == EPELoudspeaker )
       
   253             {
       
   254             iLoudspeakerVolume = iPhoneModel.DataStore()->AudioVolume();
       
   255             TEFLOGSTRING2( KTAINT, 
       
   256                 "AUD CPEAudioData::SendMessage: iLoudspeakerVolume = %d", 
       
   257                 iLoudspeakerVolume );
       
   258             }
       
   259         else 
       
   260             {
       
   261             iHeadSetVolume = iPhoneModel.DataStore()->AudioVolume();
       
   262             TEFLOGSTRING2( KTAINT, 
       
   263                 "AUD CPEAudioData::SendMessage: iHeadSetVolume = %d", 
       
   264                 iHeadSetVolume );
       
   265             }
       
   266         
       
   267         // update the audio values in engineinfo
       
   268         TBool status;
       
   269         iAudioRouting->GetShowNote( status );
       
   270         iPhoneModel.DataStore()->SetAudioOutput( ConvertToPE( aOutput ), ConvertToPE( PreviousOutput() ), status );
       
   271 
       
   272         // Set audio output change flag 
       
   273         iAudioOutputChanged = ( MEngineMonitor::EPEMessageAudioOutputChanged == aMessage );
       
   274           
       
   275         // restore the stored volume for the new path
       
   276         if ( aOutput == CTelephonyAudioRouting::ELoudspeaker )
       
   277             {
       
   278             // restore the stored volume for the new path
       
   279             SetAudioVolumeSync( iLoudspeakerVolume );
       
   280             iPhoneModel.DataStore()->SetAudioVolume( iLoudspeakerVolume );   
       
   281             TEFLOGSTRING2( KTAINT, 
       
   282                 "AUD CPEAudioData::SendMessage: DataStoreExt()->Set, iLoudspeakerVolume = %d", 
       
   283                 iLoudspeakerVolume );
       
   284             iPhoneModel.DataStoreExt()->Set( EPEIncallLoudspeakerVolumeSetting,
       
   285                 iLoudspeakerVolume );
       
   286             }
       
   287         else 
       
   288             {
       
   289             // restore the stored volume for the new path
       
   290             SetAudioVolumeSync( iHeadSetVolume );
       
   291             iPhoneModel.DataStore()->SetAudioVolume( iHeadSetVolume );   
       
   292             TEFLOGSTRING2( KTAINT, 
       
   293                 "AUD CPEAudioData::SendMessage: DataStoreExt()->Set, iHeadSetVolume  = %d", 
       
   294                 iHeadSetVolume );
       
   295             iPhoneModel.DataStoreExt()->Set( EPEIncallEarVolumeSetting,
       
   296                 iHeadSetVolume );
       
   297             }
       
   298         
       
   299         // Reset audio output change flag 
       
   300         iAudioOutputChanged = EFalse;                                                
       
   301                      
       
   302         iPhoneModel.SendMessage( aMessage );
       
   303         }
       
   304     }
       
   305 
       
   306 // -----------------------------------------------------------------------------
       
   307 // CPEAudioData::SendMessage
       
   308 // Forwards message to PhoneEngine.
       
   309 // -----------------------------------------------------------------------------
       
   310 //   
       
   311 void CPEAudioData::SendMessage( 
       
   312         const MEngineMonitor::TPEMessagesFromPhoneEngine aMessage, 
       
   313         CTelephonyAudioRouting& aTelephonyAudioRouting )
       
   314     {
       
   315     TEFLOGSTRING2( 
       
   316          KTAREQIN, 
       
   317         "AUD CPEAudioData::SendMessage: aMessage = %d, available outputs changed ", aMessage );
       
   318     iPhoneModel.DataStore()->SetAvailableAudioOutputs( 
       
   319         GetAvailableOutputs( aTelephonyAudioRouting ) );
       
   320     
       
   321     if ( iRouteInitialized &&
       
   322          aMessage == MEngineMonitor::EPEMessageAvailableAudioOutputsChanged )
       
   323         {
       
   324         iAudioRoutingHandler->HandleAudioRoutingAvailableChanged();
       
   325         }
       
   326  
       
   327     iPhoneModel.SendMessage( aMessage );
       
   328     }
       
   329 
       
   330 // -----------------------------------------------------------------------------
       
   331 // CPEAudioData::SetAudioMuteSync
       
   332 // Creates synchronous request to set audio mute.
       
   333 // EPEMessageAudioMuteChanged message is sent when gain is changed
       
   334 // -----------------------------------------------------------------------------
       
   335 //
       
   336 EXPORT_C void CPEAudioData::SetAudioMuteSync( 
       
   337         const TBool aAudioMute ) // Mute value to be set
       
   338     {
       
   339     TEFLOGSTRING( KTAINT, "AUD CPEAudioData::SetAudioMuteSync" );
       
   340     
       
   341     if ( aAudioMute )
       
   342         {
       
   343         iPhoneModel.DataStore()->SetAudioMute( aAudioMute );
       
   344         SendMessage( MEngineMonitor::EPEMessageAudioMuteChanged );
       
   345         // Inform VoIP/PE Videocallmanager mute state. Error code not handled.
       
   346         TInt err = RProperty::Set( 
       
   347             KPSUidTelMicrophoneMuteStatus, 
       
   348             KTelMicrophoneMuteState,
       
   349             EPSTelMicMuteOn );
       
   350             TEFLOGSTRING2( 
       
   351                 KTAREQOUT, 
       
   352                 "AUD CPEAudioData::SetAudioMuteSync: EPSTelephonyMicMuteOn , error = %d", 
       
   353                 err );            
       
   354         }
       
   355     else
       
   356         {
       
   357         iPhoneModel.DataStore()->SetAudioMute( aAudioMute );
       
   358         SendMessage( MEngineMonitor::EPEMessageAudioMuteChanged );
       
   359         TInt err = RProperty::Set( 
       
   360             KPSUidTelMicrophoneMuteStatus, 
       
   361             KTelMicrophoneMuteState,
       
   362             EPSTelMicMuteOff );
       
   363         TEFLOGSTRING2( 
       
   364             KTAREQOUT, 
       
   365             "AUD CPEAudioData::SetAudioMuteSync: EPSTelephonyMicMuteOff, error = %d", 
       
   366             err );                
       
   367         }
       
   368     }
       
   369 
       
   370 // -----------------------------------------------------------------------------
       
   371 // CPEAudioData::SetAudioVolumeSync
       
   372 // Creates synchronous request to set audio volume.
       
   373 // -----------------------------------------------------------------------------
       
   374 //
       
   375 EXPORT_C void CPEAudioData::SetAudioVolumeSync( 
       
   376         const TInt aAudioVolume ) // Volume to be set
       
   377     {
       
   378     TEFLOGSTRING2( 
       
   379         KTAREQIN, 
       
   380         "AUD CPEAudioData::SetAudioVolumeSync, aAudioVolume = %d", 
       
   381         aAudioVolume );
       
   382  
       
   383     if ( aAudioVolume <= KPEMaxVolume ) 
       
   384         {
       
   385         TEFLOGSTRING2( KTAINT, 
       
   386             "AUD CPEAudioData::SetAudioVolumeSync, aAudioVolume = %d",
       
   387             aAudioVolume );
       
   388         
       
   389         if ( iPhoneModel.DataStore()->AudioOutput() == EPELoudspeaker )
       
   390             {
       
   391             iPhoneModel.DataStoreExt()->Set( 
       
   392                 EPEIncallLoudspeakerVolumeSetting, 
       
   393                 aAudioVolume );
       
   394             TEFLOGSTRING( KTAINT, 
       
   395                 "AUD CPEAudioData::SetAudioVolumeSync: EPEIncallLoudspeakerVolumeSetting");
       
   396             }
       
   397         else 
       
   398             {
       
   399             iPhoneModel.DataStoreExt()->Set( 
       
   400                 EPEIncallEarVolumeSetting, 
       
   401                 aAudioVolume );
       
   402             TEFLOGSTRING( KTAINT, 
       
   403                 "AUD CPEAudioData::SetAudioVolumeSync: EPEIncallEarVolumeSetting");
       
   404             }
       
   405 		}            
       
   406  
       
   407     iPhoneModel.DataStore()->SetAudioVolume( aAudioVolume );
       
   408 
       
   409     DoHandleVolumeChange( aAudioVolume );
       
   410 
       
   411     SendMessage( MEngineMonitor::EPEMessageAudioVolumeChanged );
       
   412     }
       
   413 
       
   414 // -----------------------------------------------------------------------------
       
   415 // CPEAudioData::SetAudioOutput
       
   416 // Makes request to Telephony Audio Routing to set audio output path
       
   417 // -----------------------------------------------------------------------------
       
   418 //
       
   419 EXPORT_C TInt CPEAudioData::SetAudioOutput( 
       
   420         const TPEAudioOutput aOutput,
       
   421         TBool aShowNote )
       
   422     {
       
   423     TEFLOGSTRING2( 
       
   424         KTAREQIN, 
       
   425         "AUD CPEAudioData::SetAudioOutput: aOutput = %d", 
       
   426         aOutput );
       
   427         
       
   428     TInt error( KErrNone );
       
   429     
       
   430     TEFLOGSTRING2( KTAERROR, 
       
   431         "AUD CPEAudioData::SetAudioOutput: iRouteInitialized (%d)"
       
   432         , iRouteInitialized );
       
   433 
       
   434     if ( iRouteInitialized  && iPhoneModel.DataStore()->AudioOutputAvailable( aOutput ) )
       
   435         {
       
   436         SetTAROutput( ConvertToTAR( aOutput), aShowNote  );
       
   437         }
       
   438     else
       
   439         {
       
   440         if ( aOutput == EPEHandset )
       
   441             {
       
   442             iAudioRoutingHandler->SetAnswerToHandset( ETrue );
       
   443             }
       
   444         else
       
   445             {
       
   446             TEFLOGSTRING2( KTAERROR,
       
   447                  "AUD CPEAudioData::SetAudioOutput: Requested audio path not available (%d)"
       
   448                  , aOutput );
       
   449             error = KErrArgument;            
       
   450             }
       
   451         }
       
   452  
       
   453     return error;
       
   454     }
       
   455 
       
   456 
       
   457 // -----------------------------------------------------------------------------
       
   458 // CPEAudioData::SetTAROutput
       
   459 // -----------------------------------------------------------------------------
       
   460 //
       
   461 void CPEAudioData::SetTAROutput( 
       
   462     CTelephonyAudioRouting::TAudioOutput aOutput,
       
   463     TBool aShowNote ) 
       
   464     {
       
   465     TEFLOGSTRING2( 
       
   466         KTAREQIN, 
       
   467         "AUD CPEAudioData::SetTAROutput: aOutput = %d", 
       
   468         aOutput );
       
   469 
       
   470 #if defined(__WINSCW__ ) && !defined(UNIT_TESTING)
       
   471     iAudioRouting->SetShowNote( aShowNote );
       
   472     SendMessage( MEngineMonitor::EPEMessageAudioOutputChanged, aOutput);
       
   473 #else   	
       
   474     CTelephonyAudioRouting::TAudioOutput output = iAudioRouting->Output();    	
       
   475      
       
   476     if ( output == aOutput ) 
       
   477     	{
       
   478     	// audio routing cannot changed
       
   479     	TEFLOGSTRING2( KTAERROR, 
       
   480     	    "AUD CPEAudioData::SetTAROutput: audio path already (%d)"
       
   481     	    , aOutput );
       
   482   		return;
       
   483      	}
       
   484     iAudioRouting->SetShowNote( aShowNote );     	    
       
   485    	TRAPD( err, iAudioRouting->SetOutputL( aOutput ) );
       
   486     
       
   487 	if( err )
       
   488 		{
       
   489 		TEFLOGSTRING2( KTAERROR, 
       
   490 		    "AUD CPEAudioData::SetTAROutput:Leave.1 (%d)", err );
       
   491  	    switch ( aOutput )
       
   492 		    {
       
   493 			case CTelephonyAudioRouting::ELoudspeaker:
       
   494 			case CTelephonyAudioRouting::EWiredAudioAccessory:   		    
       
   495 			case CTelephonyAudioRouting::EBTAudioAccessory:
       
   496 				// if leave try handset
       
   497 				TRAPD( err2, iAudioRouting->SetOutputL( CTelephonyAudioRouting::EHandset ) );
       
   498 				if( err2 )
       
   499 					{
       
   500 					TEFLOGSTRING2( KTAERROR, 
       
   501 					    "AUD CPEAudioData::SetTAROutput:Leave.2 (%d)", err );
       
   502  					}				
       
   503 				break;
       
   504 		  	default:
       
   505 		        // None
       
   506 		    	break;     
       
   507 		    }
       
   508         }
       
   509 #endif        
       
   510     }
       
   511 
       
   512 // -----------------------------------------------------------------------------
       
   513 // CPEAudioData::StartUp
       
   514 // Gets initial values and inializes TAR
       
   515 // StartUpL methods.
       
   516 // -----------------------------------------------------------------------------
       
   517 //
       
   518 EXPORT_C void CPEAudioData::StartUp()
       
   519     {
       
   520     TEFLOGSTRING( KTAREQIN, "AUD CPEAudioData::StartUp" );
       
   521     // get available audio output paths and current audio output
       
   522     iPhoneModel.DataStore()->SetAvailableAudioOutputs( GetAvailableOutputs( *iAudioRouting ) );
       
   523     iPhoneModel.DataStore()->SetAudioOutput( ConvertToPE( iAudioRouting->Output() ), ConvertToPE( iAudioRouting->PreviousOutput() ), EFalse );    
       
   524     }
       
   525 
       
   526 // -----------------------------------------------------------------------------
       
   527 // CPEAudioData::GetAvailableOutputs
       
   528 // Gets Available Outputs from Audio routing framework
       
   529 // Return list of available outputs
       
   530 // -----------------------------------------------------------------------------
       
   531 //
       
   532 TArray<TPEAudioOutput> CPEAudioData::GetAvailableOutputs( 
       
   533         CTelephonyAudioRouting& aTelephonyAudioRouting )
       
   534     {
       
   535     TEFLOGSTRING( KTAREQOUT, 
       
   536         "AUD CPEAudioData::GetAvailableOutputs > CTelephonyAudioRouting::AvailableOutputs()" );
       
   537     TArray<CTelephonyAudioRouting::TAudioOutput> availableOutputs = 
       
   538         aTelephonyAudioRouting.AvailableOutputs();
       
   539     
       
   540     iPEavailableOutputs.Reset();
       
   541 
       
   542     for ( TInt j = 0; j < availableOutputs.Count(); j++ )
       
   543         {
       
   544         iPEavailableOutputs.Append( ConvertToPE( availableOutputs[j] ) );
       
   545         TEFLOGSTRING3( KTAINT, 
       
   546             "AUD CPEAudioData::GetAvailableOutputs, index: %d, available: %d", 
       
   547             j, 
       
   548             availableOutputs[j] );
       
   549         }     
       
   550  
       
   551     return iPEavailableOutputs.Array();  
       
   552     }
       
   553  
       
   554 // -----------------------------------------------------------------------------
       
   555 // CPEAudioData::SetDefaultVolume
       
   556 // -----------------------------------------------------------------------------
       
   557 //
       
   558 EXPORT_C void CPEAudioData::SetDefaultVolume()
       
   559     {
       
   560     TEFLOGSTRING( KTAREQIN, "AUD CPEAudioData::SetDefaultVolume" );
       
   561     if ( !iLoudspeakerVolume )
       
   562         {
       
   563         TEFLOGSTRING( KTAREQIN, "AUD CPEAudioData->SetDefaultLoudspeakerVolume" );
       
   564         iLoudspeakerVolume = KPEDefaultVolume;
       
   565         iPhoneModel.DataStore()->SetAudioVolume( iLoudspeakerVolume );
       
   566         iPhoneModel.DataStoreExt()->Set( EPEIncallLoudspeakerVolumeSetting,
       
   567                 iLoudspeakerVolume );
       
   568         }
       
   569     if ( !iHeadSetVolume )
       
   570         {
       
   571         TEFLOGSTRING( KTAREQIN, "AUD CPEAudioData->SetDefaultHeadSetVolume" );
       
   572         iHeadSetVolume = KPEDefaultVolume;
       
   573         iPhoneModel.DataStore()->SetAudioVolume( iHeadSetVolume );
       
   574         iPhoneModel.DataStoreExt()->Set( EPEIncallEarVolumeSetting, 
       
   575                 iHeadSetVolume );            
       
   576         }
       
   577 
       
   578     DoHandleVolumeChange( KPEDefaultVolume );
       
   579     }    
       
   580   
       
   581 // -----------------------------------------------------------------------------
       
   582 // CPEAudioData::HandleCallStarting  
       
   583 // -----------------------------------------------------------------------------
       
   584 //    
       
   585 EXPORT_C TInt CPEAudioData::HandleCallStarting( TBool aVideoCall )
       
   586     {
       
   587     TEFLOGSTRING( KTAMESINT, "AUD CPEAudioData::HandleCallStarting()" );
       
   588     TInt ret( KErrNone );
       
   589     
       
   590     if ( !iRouteInitialized )  // if route not already initialized
       
   591         {                      // Not new route init for multi calls
       
   592         iRouteInitialized = ETrue;
       
   593         ret  = iAudioRoutingHandler->HandleAudioRoutingCallInit( aVideoCall );
       
   594         }
       
   595     
       
   596     return ret;        
       
   597     }
       
   598 
       
   599 // -----------------------------------------------------------------------------
       
   600 // CPEAudioData::HandleEnergencyCallStarting
       
   601 // Can be called, if new call is created before previous call is idle state
       
   602 // One used situation is that emergency call is dialed during the video call or 
       
   603 // voice call. Audio routing have to initialized when emergency is dialing state
       
   604 // even previous call(voice or video) haven't got idle yet.
       
   605 // -----------------------------------------------------------------------------
       
   606 //    
       
   607 EXPORT_C TInt CPEAudioData::HandleEnergencyCallStarting()
       
   608     {
       
   609     TEFLOGSTRING( KTAMESINT, "AUD CPEAudioData::HandleCallSwitching()" );
       
   610     TInt ret( KErrNone );
       
   611     
       
   612     // Always new route init
       
   613     ret = iAudioRoutingHandler->HandleAudioRoutingCallInit( EFalse );
       
   614     iRouteInitialized = ETrue;
       
   615   
       
   616     return ret;        
       
   617     }
       
   618 
       
   619 // -----------------------------------------------------------------------------
       
   620 // CPEAudioData::HandleCallEnding()
       
   621 // -----------------------------------------------------------------------------
       
   622 //    
       
   623 EXPORT_C void CPEAudioData::HandleCallEnding()
       
   624     {
       
   625     TEFLOGSTRING( KTAMESINT, "AUD CPEAudioData::HandleCallEnding()" );
       
   626     
       
   627     if ( iRouteInitialized )
       
   628         {
       
   629         iRouteInitialized = EFalse;
       
   630         TEFLOGSTRING( KTAMESINT, 
       
   631             "AUD CPEAudioData::HandleCallEnding() > CTelephonyAudioRouting::ENotActive" );
       
   632         SetTAROutput( CTelephonyAudioRouting::ENotActive, EFalse  );        
       
   633         }
       
   634     }
       
   635      
       
   636 // -----------------------------------------------------------------------------
       
   637 // CPEAudioData::CallAudioRoutePreferenceChanged()
       
   638 //  
       
   639 // -----------------------------------------------------------------------------
       
   640 //    
       
   641 EXPORT_C TInt CPEAudioData::CallAudioRoutePreferenceChanged()
       
   642     {
       
   643     TEFLOGSTRING( KTAMESINT, "AUD CPEAudioData::CallAudioRoutePreferenceChanged()" );
       
   644     if ( iRouteInitialized )
       
   645         {
       
   646         return iAudioRoutingHandler->HandleAudioRoutePreferenceChanged();         
       
   647         }
       
   648     return KErrNotReady;
       
   649     }    
       
   650         
       
   651 // -----------------------------------------------------------------------------
       
   652 // CPEAudioData::PreviousOutput
       
   653 // -----------------------------------------------------------------------------
       
   654 //
       
   655 CTelephonyAudioRouting::TAudioOutput CPEAudioData::PreviousOutput()
       
   656     {
       
   657     return iAudioRouting->PreviousOutput();
       
   658     }
       
   659         
       
   660 // -----------------------------------------------------------------------------
       
   661 // CPEAudioData::Output
       
   662 // -----------------------------------------------------------------------------
       
   663 //
       
   664 CTelephonyAudioRouting::TAudioOutput CPEAudioData::Output()
       
   665     {
       
   666     return iAudioRouting->Output();
       
   667     }
       
   668  
       
   669 // -----------------------------------------------------------------------------
       
   670 // CPEAudioData::SetRoutePreference
       
   671 // -----------------------------------------------------------------------------
       
   672 //    
       
   673 void CPEAudioData::SetRoutePreference( TBool aShowNote )
       
   674     {
       
   675     TEFLOGSTRING( KTAMESINT, "AUD CPEAudioData::SetRoutePreference()" );
       
   676     CTelephonyAudioRouting::TAudioOutput output = CTelephonyAudioRouting::EHandset;
       
   677      
       
   678     const TInt outputPreference = iPhoneModel.DataStore()->AudioOutputPreference();
       
   679     if ( outputPreference == EPSAudioPublic )
       
   680         {
       
   681         output = CTelephonyAudioRouting::ELoudspeaker;
       
   682         }
       
   683     TInt error;
       
   684     iAudioRouting->SetShowNote( aShowNote );
       
   685     TRAP( error, iAudioRouting->SetOutputL( output ) );
       
   686     TEFLOGSTRING2( KTAMESINT, "AUD CPEAudioData::SetRoutePreference() err %d", error );
       
   687     }    
       
   688     
       
   689 // -----------------------------------------------------------------------------
       
   690 // CPEAudioData::RoutePreference
       
   691 // -----------------------------------------------------------------------------
       
   692 //    
       
   693 CTelephonyAudioRouting::TAudioOutput CPEAudioData::RoutePreference()
       
   694     {
       
   695     CTelephonyAudioRouting::TAudioOutput output = CTelephonyAudioRouting::EHandset;
       
   696      
       
   697     const TInt outputPreference = iPhoneModel.DataStore()->AudioOutputPreference();
       
   698     if ( outputPreference == EPSAudioPublic )
       
   699         {
       
   700         output = CTelephonyAudioRouting::ELoudspeaker;
       
   701         }
       
   702     TEFLOGSTRING2( KTAMESINT, "AUD CPEAudioData::RoutePreference() output %d", output );
       
   703     return output;
       
   704     }    
       
   705 // -----------------------------------------------------------------------------
       
   706 // CPEAudioData::IsWiredAvailable
       
   707 // -----------------------------------------------------------------------------
       
   708 //
       
   709 TBool CPEAudioData::IsWiredAvailable()
       
   710     {
       
   711     return iPhoneModel.DataStore()->AudioOutputAvailable( 
       
   712          EPEWiredAudioAccessory );
       
   713     }
       
   714 
       
   715     
       
   716 // -----------------------------------------------------------------------------
       
   717 // CPEAudioData::IsBTAvailable
       
   718 // -----------------------------------------------------------------------------
       
   719 //
       
   720 TBool CPEAudioData::IsBTAvailable()
       
   721     {
       
   722     return iPhoneModel.DataStore()->AudioOutputAvailable( 
       
   723          EPEBTAudioAccessory );
       
   724     }
       
   725 
       
   726 // -----------------------------------------------------------------------------
       
   727 // CPEAudioData::IsTTYAvailable
       
   728 // -----------------------------------------------------------------------------
       
   729 //
       
   730 TBool CPEAudioData::IsTTYAvailable()
       
   731     {
       
   732     return iPhoneModel.DataStore()->AudioOutputAvailable( 
       
   733          EPETTY );
       
   734     }
       
   735  // -----------------------------------------------------------------------------
       
   736 // CPEAudioData::IsMuted
       
   737 // -----------------------------------------------------------------------------
       
   738 //
       
   739 TBool CPEAudioData::IsMuted() const
       
   740     {
       
   741     TInt value;
       
   742     TInt err = RProperty::Get( 
       
   743         KPSUidTelMicrophoneMuteStatus, 
       
   744         KTelMicrophoneMuteState,
       
   745         value );
       
   746  
       
   747     TEFLOGSTRING3( 
       
   748          KTAREQIN, 
       
   749         "AUD CPEAudioData::IsMuted: value = %d, error = %d", 
       
   750         value, err );        
       
   751     return ( value == EPSTelMicMuteOn ) ? ETrue : EFalse;
       
   752     }   
       
   753    
       
   754 
       
   755 // -----------------------------------------------------------------------------
       
   756 // CPEAudioData::ConvertToPE
       
   757 // -----------------------------------------------------------------------------
       
   758 //
       
   759 TPEAudioOutput CPEAudioData::ConvertToPE( CTelephonyAudioRouting::TAudioOutput aOutput )
       
   760     {
       
   761     TEFLOGSTRING2( KTAMESINT, "AUD CPEAudioData::ConvertToPE, aOutput %d", aOutput );
       
   762     TPEAudioOutput newOutput( EPENotActive );
       
   763     
       
   764     switch( aOutput )
       
   765         {
       
   766         case CTelephonyAudioRouting::ENotActive:
       
   767             newOutput = EPENotActive;
       
   768             break;
       
   769         case CTelephonyAudioRouting::EHandset:
       
   770             newOutput = EPEHandset;
       
   771             break;
       
   772         case CTelephonyAudioRouting::ELoudspeaker:
       
   773             newOutput = EPELoudspeaker;
       
   774             break;
       
   775         case CTelephonyAudioRouting::EWiredAudioAccessory:
       
   776             newOutput = EPEWiredAudioAccessory;
       
   777             break;
       
   778         case CTelephonyAudioRouting::EBTAudioAccessory:
       
   779             newOutput = EPEBTAudioAccessory;
       
   780             break;
       
   781         case CTelephonyAudioRouting::ETTY:
       
   782             newOutput = EPETTY;
       
   783             break;
       
   784         default:
       
   785             break;    
       
   786         }
       
   787     
       
   788     return newOutput;
       
   789     }
       
   790 
       
   791 // -----------------------------------------------------------------------------
       
   792 // CPEAudioData::ConvertToTAR
       
   793 // -----------------------------------------------------------------------------
       
   794 //
       
   795 CTelephonyAudioRouting::TAudioOutput CPEAudioData::ConvertToTAR( TPEAudioOutput aOutput )
       
   796     {
       
   797     TEFLOGSTRING2( KTAMESINT, "AUD CPEAudioData::ConvertToTAR, aOutput %d", aOutput );
       
   798     
       
   799     CTelephonyAudioRouting::TAudioOutput newOutput ( CTelephonyAudioRouting::ENotActive );
       
   800     
       
   801     switch( aOutput )
       
   802         {
       
   803         case EPENotActive:
       
   804             newOutput = CTelephonyAudioRouting::ENotActive;
       
   805             break;
       
   806         case EPEHandset:
       
   807             newOutput = CTelephonyAudioRouting::EHandset;
       
   808             break;
       
   809         case EPELoudspeaker:
       
   810             newOutput = CTelephonyAudioRouting::ELoudspeaker;
       
   811             break;
       
   812         case EPEWiredAudioAccessory:
       
   813             newOutput = CTelephonyAudioRouting::EWiredAudioAccessory;
       
   814             break;
       
   815         case EPEBTAudioAccessory:
       
   816             newOutput = CTelephonyAudioRouting::EBTAudioAccessory;
       
   817             break;
       
   818         case EPETTY:
       
   819             newOutput = CTelephonyAudioRouting::ETTY;
       
   820             break;
       
   821         default:
       
   822             break;    
       
   823         }
       
   824     return newOutput;
       
   825     }
       
   826 
       
   827 // -----------------------------------------------------------------------------
       
   828 // CPEAudioData::DoHandleVolumeChange
       
   829 // -----------------------------------------------------------------------------
       
   830 //
       
   831 void CPEAudioData::DoHandleVolumeChange( TInt /*aVolume*/ )
       
   832     {
       
   833     
       
   834     }
       
   835 
       
   836 // End of File