phoneengine/audiohandling/src/cpecallaudioroutinghandler.cpp
changeset 0 5f000ab63145
child 21 92ab7f8d0eab
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     1 /*
       
     2 * Copyright (c) 2006-2008 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 CPECallAudioRoutingHandler class 
       
    15 *                member functions
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDES
       
    21 #include <talogger.h>
       
    22 #include "cpecallaudioroutinghandler.h"
       
    23 #include "cpeaudiodata.h"
       
    24 
       
    25 // EXTERNAL DATA STRUCTURES
       
    26 // None.
       
    27 
       
    28 // EXTERNAL FUNCTION PROTOTYPES  
       
    29 // None.
       
    30 
       
    31 // CONSTANTS
       
    32 // None
       
    33 
       
    34 // MACROS
       
    35 // None.
       
    36 
       
    37 // LOCAL CONSTANTS AND MACROS
       
    38 // None.
       
    39 
       
    40 // MODULE DATA STRUCTURES
       
    41 // None.
       
    42 
       
    43 // LOCAL FUNCTION PROTOTYPES
       
    44 // None.
       
    45 
       
    46 // ==================== LOCAL FUNCTIONS =====================================
       
    47 //None.
       
    48 
       
    49 // ================= MEMBER FUNCTIONS =======================================
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CPECallAudioRoutingHandler::CPECallAudioRoutingHandler
       
    53 // C++ default constructor can NOT contain any code, that
       
    54 // might leave.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CPECallAudioRoutingHandler::CPECallAudioRoutingHandler( 
       
    58     CPEAudioData& aOwner )
       
    59     : iOwner( aOwner )
       
    60     { 
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CPEAudioRoutingMonitor::NewL
       
    65 // Two-phased constructor.
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CPECallAudioRoutingHandler* CPECallAudioRoutingHandler::NewL( 
       
    69     CPEAudioData& aOwner )
       
    70     {
       
    71     CPECallAudioRoutingHandler* self = 
       
    72         new ( ELeave ) CPECallAudioRoutingHandler( aOwner );
       
    73     
       
    74     return self;
       
    75     }
       
    76 
       
    77 CPECallAudioRoutingHandler::~CPECallAudioRoutingHandler()
       
    78     {
       
    79     }
       
    80  
       
    81  
       
    82 // -----------------------------------------------------------------------------
       
    83 // CPECallAudioRoutingHandler::HandleAudioRoutingCallInit
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 TInt CPECallAudioRoutingHandler::HandleAudioRoutingCallInit( TBool aVideoCall )
       
    87     {
       
    88   
       
    89     TInt error = KErrNone;
       
    90     CTelephonyAudioRouting::TAudioOutput curOutput = iOwner.Output();
       
    91     CTelephonyAudioRouting::TAudioOutput newOutput = curOutput;
       
    92 
       
    93     TEFLOGSTRING2( KTAINT, 
       
    94         "AUD CPECallAudioRoutingHandler::HandleAudioRoutingCallInit > : isVideo = %d", aVideoCall );
       
    95     iAnyVideoCall = aVideoCall;
       
    96     
       
    97     // Wired headset has top priority
       
    98     if ( iOwner.IsWiredAvailable() )
       
    99         {
       
   100         newOutput = CTelephonyAudioRouting::EWiredAudioAccessory;
       
   101         }
       
   102     else if ( iOwner.IsBTAvailable() ) 
       
   103         {
       
   104         if ( iAnswerToHandset )  
       
   105             {
       
   106             newOutput = iOwner.RoutePreference();
       
   107             }
       
   108         else
       
   109             {
       
   110             newOutput = CTelephonyAudioRouting::EBTAudioAccessory;
       
   111             }            
       
   112         }
       
   113     else if ( iOwner.IsTTYAvailable() )
       
   114         {
       
   115         newOutput = CTelephonyAudioRouting::ETTY;
       
   116         }
       
   117     else
       
   118         {
       
   119         if ( iAnyVideoCall )
       
   120         	{
       
   121         	if ( iAnswerToHandset )
       
   122         	    {
       
   123         	    newOutput = CTelephonyAudioRouting::EHandset;
       
   124         	    }
       
   125             else
       
   126                 {
       
   127                 newOutput = CTelephonyAudioRouting::ELoudspeaker;        
       
   128                 }        	    
       
   129             }
       
   130         else
       
   131         	{
       
   132             newOutput = iOwner.RoutePreference();
       
   133             } 
       
   134         }
       
   135     SetAnswerToHandset( EFalse );
       
   136     
       
   137     if ( newOutput != curOutput )
       
   138         {
       
   139         iOwner.SetTAROutput( newOutput, EFalse );    
       
   140         TEFLOGSTRING2( KTAINT, 
       
   141         "AUD CPECallAudioRoutingHandler::HandleAudioRoutingCallInit: new output = %d", newOutput );
       
   142         }
       
   143     else
       
   144         {
       
   145         TEFLOGSTRING2( KTAINT, 
       
   146         "AUD CPECallAudioRoutingHandler::HandleAudioRoutingCallInit: Already output = %d", curOutput );
       
   147         }        
       
   148  
       
   149     return error;
       
   150     }
       
   151     
       
   152 // -----------------------------------------------------------------------------
       
   153 // CPECallAudioRoutingHandler::HandleAudioRoutingAvailableChanged
       
   154 // Handles accessory mode changed message from AudioHandling subsystem.
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 TInt CPECallAudioRoutingHandler::HandleAudioRoutingAvailableChanged()
       
   158     {
       
   159     TInt error = KErrNone;
       
   160        
       
   161     CTelephonyAudioRouting::TAudioOutput curOutput = iOwner.Output();
       
   162     CTelephonyAudioRouting::TAudioOutput newOutput = curOutput;
       
   163     
       
   164     
       
   165     switch ( curOutput )
       
   166         {
       
   167         case CTelephonyAudioRouting::ENotActive:
       
   168    			// None
       
   169              break;
       
   170  		case CTelephonyAudioRouting::EHandset:
       
   171  		case CTelephonyAudioRouting::ELoudspeaker:
       
   172  			// Wired audio accessory connected during call
       
   173  			if ( iOwner.IsWiredAvailable() )
       
   174  				{
       
   175  				newOutput = CTelephonyAudioRouting::EWiredAudioAccessory;
       
   176   				}
       
   177  			// BT comes available during call	
       
   178  			else if ( iOwner.IsBTAvailable() )
       
   179  				{
       
   180  		        newOutput = CTelephonyAudioRouting::EBTAudioAccessory;
       
   181   				}
       
   182 			else if ( iOwner.IsTTYAvailable() ) 				
       
   183 				{
       
   184  				newOutput = CTelephonyAudioRouting::ETTY;
       
   185   				}
       
   186   			else
       
   187   			    {
       
   188   			    // No changes
       
   189   			    }	
       
   190  		    break;
       
   191  		case CTelephonyAudioRouting::EWiredAudioAccessory:
       
   192  			if ( iOwner.IsBTAvailable() )
       
   193   			    {
       
   194  				// Not allowed direct from wired to BTA
       
   195  				// or BTA comes available during wired, No changes
       
   196  				}
       
   197  			if ( iOwner.IsWiredAvailable() )
       
   198 				{
       
   199  			    // No changes
       
   200 				}
       
   201 		    else if ( iAnyVideoCall )
       
   202  			    {
       
   203  			    newOutput = CTelephonyAudioRouting::ELoudspeaker;
       
   204  			    }
       
   205             else 			    
       
   206 				{
       
   207 				// Wired detach
       
   208             	newOutput = iOwner.RoutePreference();
       
   209 				}	
       
   210          	break;
       
   211 		case CTelephonyAudioRouting::EBTAudioAccessory:
       
   212  			if ( iOwner.IsWiredAvailable() )
       
   213  				{
       
   214  				newOutput = CTelephonyAudioRouting::EWiredAudioAccessory;
       
   215    				}
       
   216   			else if ( iOwner.IsBTAvailable() )	
       
   217   				{
       
   218   			    // No changes
       
   219   				}
       
   220 			else
       
   221 				{
       
   222  				newOutput = iOwner.RoutePreference();
       
   223  				}		    
       
   224    		    break;
       
   225         case CTelephonyAudioRouting::ETTY:
       
   226         	if ( iOwner.IsTTYAvailable()  )
       
   227  				{
       
   228   			    // No changes
       
   229    				}
       
   230  			else
       
   231 				{
       
   232  				newOutput = iOwner.RoutePreference();
       
   233  				}
       
   234         	break;
       
   235        default:
       
   236             break;     
       
   237         }
       
   238     
       
   239    if ( newOutput != curOutput )
       
   240         {
       
   241         iOwner.SetTAROutput( newOutput, ETrue );    
       
   242         TEFLOGSTRING2( KTAINT, 
       
   243         "PE CPECallAudioRoutingHandler::HandleAudioRoutingAvailableChanged: new output = %d", newOutput );
       
   244         }
       
   245     else
       
   246         {
       
   247         TEFLOGSTRING2( KTAINT, 
       
   248         "PE CPECallAudioRoutingHandler::HandleAudioRoutingAvailableChanged: Already output = %d", curOutput );
       
   249         }     
       
   250       
       
   251     return error;
       
   252     }    
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // CPECallAudioRoutingHandler::HandleAudioRoutePreferenceChanged
       
   256 // Handles route preference mode changed message from AudioHandling subsystem.
       
   257 // -----------------------------------------------------------------------------
       
   258 //
       
   259 TInt CPECallAudioRoutingHandler::HandleAudioRoutePreferenceChanged()
       
   260     {
       
   261     TInt error = KErrNone;
       
   262     CTelephonyAudioRouting::TAudioOutput curOutput = iOwner.Output();
       
   263     CTelephonyAudioRouting::TAudioOutput newOutput = curOutput;
       
   264     
       
   265     if ( !iAnyVideoCall &&
       
   266        	 curOutput != CTelephonyAudioRouting::EWiredAudioAccessory &&
       
   267        	 curOutput != CTelephonyAudioRouting::EBTAudioAccessory )
       
   268         {
       
   269         newOutput = iOwner.RoutePreference();
       
   270         }
       
   271     if ( newOutput != curOutput )
       
   272         {
       
   273         iOwner.SetTAROutput( newOutput, ETrue );    
       
   274         TEFLOGSTRING2( KTAINT, 
       
   275         "PE CPECallAudioRoutingHandler::HandleAudioRoutePreferenceChanged: new output = %d", newOutput );
       
   276         }
       
   277     else
       
   278         {
       
   279         TEFLOGSTRING2( KTAINT, 
       
   280         "PE CPECallAudioRoutingHandler::HandleAudioRoutePreferenceChanged: Already output = %d", curOutput );
       
   281         }        
       
   282     return error;
       
   283     }
       
   284 // -----------------------------------------------------------------------------
       
   285 // CPECallAudioRoutingHandler::SetAnswerToHandset
       
   286 //  
       
   287 // -----------------------------------------------------------------------------
       
   288 //
       
   289 void  CPECallAudioRoutingHandler::SetAnswerToHandset( TBool aStatus )
       
   290     {
       
   291     iAnswerToHandset = aStatus;
       
   292     }
       
   293  
       
   294  
       
   295 // ================= OTHER EXPORTED FUNCTIONS ===============================
       
   296 //None
       
   297 
       
   298 //  End of File