phoneengine/audiohandling/src/cpeaudiodata.cpp
branchRCL_3
changeset 62 5266b1f337bd
parent 61 41a7f70b3818
--- a/phoneengine/audiohandling/src/cpeaudiodata.cpp	Tue Aug 31 15:14:29 2010 +0300
+++ b/phoneengine/audiohandling/src/cpeaudiodata.cpp	Wed Sep 01 12:30:10 2010 +0100
@@ -1,20 +1,21 @@
 /*
- * Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
- * All rights reserved.
- * This component and the accompanying materials are made available
- * under the terms of "Eclipse Public License v1.0"
- * which accompanies this distribution, and is available
- * at the URL "http://www.eclipse.org/legal/epl-v10.html".
- *
- * Initial Contributors:
- * Nokia Corporation - initial contribution.
- *
- * Contributors:
- *
- * Description: This module contains the implementation of AudioData class
- *              member functions
- *
- */
+* Copyright (c) 2002-2007 Nokia Corporation and/or its subsidiary(-ies). 
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:  This module contains the implementation of AudioData class 
+*                member functions
+*
+*/
+
 
 // INCLUDE FILES
 #include "cpeaudiodata.h"
@@ -26,21 +27,16 @@
 #include <talogger.h>
 #include <telmicmutestatuspskeys.h>
 #include <PSVariables.h>
-#include <tms.h>
-#include <tmseffectobsrvr.h>
-#include <tmsglobalvoleffect.h>
-#include <telinformationpskeys.h>
+
 #include "pepanic.pan"
 #include "cpeaudiodtmftoneplayer.h"
 #include "cpeaudioroutingmonitor.h"
 #include "cpecallaudioroutinghandler.h"
-#include "cpeaudiofactory.h"
-#include "cpeaudioeffect.h"
-
+#include "cpeaudiofactory.h"	
 #include <telinternalpskeys.h>
-
 // CONSTANTS
 //Mute Value for volume
+const TInt KPEDefaultVolume = 4;
 const TInt KPEMaxVolume = 10;
 
 // ================= MEMBER FUNCTIONS =======================
@@ -51,10 +47,12 @@
 // might leave.
 // -----------------------------------------------------------------------------
 //
-CPEAudioData::CPEAudioData(MPEPhoneModelInternal& aPhoneModel) :
-    iPhoneModel(aPhoneModel)
+CPEAudioData::CPEAudioData( 
+        MPEPhoneModelInternal& aPhoneModel
+        ) : iPhoneModel( aPhoneModel )
     {
     iRouteInitialized = EFalse;
+    iAudioOutputChanged = EFalse; 
     }
 
 // -----------------------------------------------------------------------------
@@ -62,47 +60,66 @@
 // Symbian 2nd phase constructor can leave
 // -----------------------------------------------------------------------------
 //
-void CPEAudioData::ConstructL(CPEAudioFactory& aAudioFactory)
+void CPEAudioData::ConstructL( CPEAudioFactory& aAudioFactory )
     {
     TEFLOGSTRING( KTAOBJECT, "AUD CPEAudioData::ConstructL start" );
-    iAudioRoutingMonitor = CPEAudioRoutingMonitor::NewL(*this);
-    iAudioRouting = aAudioFactory.CreateTelephonyAudioRoutingL(
-            *iAudioRoutingMonitor);
-    iAudioRoutingHandler = CPECallAudioRoutingHandler::NewL(*this);
-    iAudioEffect = CPEAudioEffect::NewL(*this);
-
-    InitializeAudioVolume();
-
-    TEFLOGSTRING( KTAINT, "AUD CPEAudioData::ConstructL  complete" );
+    iAudioRoutingMonitor = CPEAudioRoutingMonitor::NewL( *this );
+    iAudioRouting = aAudioFactory.CreateTelephonyAudioRoutingL(*iAudioRoutingMonitor);
+    iAudioRoutingHandler = CPECallAudioRoutingHandler::NewL( *this );
+ 
+    //Gets audio volumes from repository
+    InitializeAudioVolumes();
+    
+    RProperty::TType type( RProperty::EInt );
+    TSecurityPolicy readPolicy( ECapability_None );
+    TSecurityPolicy writePolicy( ECapabilityWriteDeviceData );
+    	
+    RProperty::Define( KPSUidTelMicrophoneMuteStatus, 
+        KTelMicrophoneMuteState,
+        type,
+        readPolicy,
+        writePolicy );
+                
+    TEFLOGSTRING( KTAINT, "AUD CPEAudioData::ConstructL  complete" );               
     }
 
 // Destructor
 EXPORT_C CPEAudioData::~CPEAudioData()
     {
     TEFLOGSTRING( KTAOBJECT, "AUD CPEAudioData::~CPEAudioData" );
-
+ 
     delete iAudioRouting;
     delete iAudioRoutingMonitor;
     delete iAudioRoutingHandler;
-
+    
     iPEavailableOutputs.Close();
 
-    delete iAudioEffect;
     }
 
 // -----------------------------------------------------------------------------
-// CPEAudioData::InitializeAudioVolume
-// Gets audio volume value
+// CPEAudioData::InitializeAudioVolumes
+// Gets audio volume values from reporitory
 // -----------------------------------------------------------------------------
-//
-void CPEAudioData::InitializeAudioVolume()
+//   
+void CPEAudioData::InitializeAudioVolumes()
     {
-    TInt volume = iAudioEffect->Volume();
-    iPhoneModel.DataStore()->SetAudioVolume(volume);
+// Connect to CPEGsmExternalDataHandler missing from TEPhoneEngineTestUtils wrapper !!!
+    TInt volume;
+   
+    iPhoneModel.DataStoreExt()->Get( 
+        EPEIncallLoudspeakerVolumeSetting, volume ); 
+    iLoudspeakerVolume = volume;
+    TEFLOGSTRING2( KTAINT, 
+        "AUD CPEAudioData::CPEAudioData, DataStoreExt()->Get, iLoudspeakerVolume = %d",
+         iLoudspeakerVolume );
+         
+    iPhoneModel.DataStoreExt()->Get( 
+        EPEIncallEarVolumeSetting, volume ); 
+    iHeadSetVolume = volume;
+    TEFLOGSTRING2( KTAINT, 
+        "AUD CPEAudioData::CPEAudioData, DataStoreExt()->Get, iLoudspeakerVolume = %d",
+         iHeadSetVolume );
 
-    TEFLOGSTRING2( KTAINT,
-            "AUD CPEAudioData::InitializeAudioVolumes, volume = %d",
-            volume );
     }
 
 // -----------------------------------------------------------------------------
@@ -111,14 +128,19 @@
 // (other items were commented in a header).
 // -----------------------------------------------------------------------------
 //
-EXPORT_C void CPEAudioData::GetAudioMuteSync(TBool& aAudioMute) const
+EXPORT_C void CPEAudioData::GetAudioMuteSync(
+        TBool& aAudioMute ) const 
     {
-    aAudioMute = iAudioEffect->MuteState();
-    TEFLOGSTRING2(
-            KTAREQIN,
-            "AUD CPEAudioData::GetAudioMuteSync: value = %d",
-            aAudioMute);
-
+    TEFLOGSTRING( KTAINT, "AUD CPEAudioData::GetAudioMuteSync" );     
+    if ( IsMuted() ) 
+        {
+        //mute is on
+        aAudioMute = ETrue;
+        }
+    else
+        {
+        aAudioMute = EFalse;
+        }
     }
 
 // -----------------------------------------------------------------------------
@@ -126,10 +148,25 @@
 // Creates synchronous request to get audio volume.
 // -----------------------------------------------------------------------------
 //
-EXPORT_C void CPEAudioData::GetAudioVolumeSync(TInt& aAudioVolume) const
+EXPORT_C void CPEAudioData::GetAudioVolumeSync(
+        TInt& aAudioVolume ) const
     {
     TEFLOGSTRING( KTAINT, "AUD CPEAudioData::GetAudioVolumeSync" );
-    aAudioVolume = iAudioEffect->Volume();
+
+    if ( iPhoneModel.DataStore()->AudioOutput() == EPELoudspeaker )
+        {
+        iPhoneModel.DataStoreExt()->Get( 
+            EPEIncallLoudspeakerVolumeSetting, aAudioVolume );
+        TEFLOGSTRING( KTAINT, 
+            "AUD CPEAudioData::GetAudioVolumeSync: EPEIncallLoudspeakerVolumeSetting");
+        }
+    else 
+        {
+        iPhoneModel.DataStoreExt()->Get( 
+            EPEIncallEarVolumeSetting, aAudioVolume );
+        TEFLOGSTRING( KTAINT, 
+            "AUD CPEAudioData::GetAudioVolumeSync: EPEIncallEarVolumeSetting");            
+        }
     }
 
 // -----------------------------------------------------------------------------
@@ -137,13 +174,14 @@
 // Saves errorcode to member variable and sends error notification to PhoneEngine.
 // -----------------------------------------------------------------------------
 //
-void CPEAudioData::SendErrorMessage(const TInt aErrorCode)
+void CPEAudioData::SendErrorMessage( 
+        const TInt aErrorCode )
     {
-    iPhoneModel.DataStore()->SetErrorCode(aErrorCode);
-    TEFLOGSTRING(
-            KTAREQOUT,
-            "AUD CPEAudioData::SendErrorMessage: iPhoneModel.SendMessage( MEngineMonitor::EPEMessageAudioHandlingError )" );
-    iPhoneModel.SendMessage(MEngineMonitor::EPEMessageAudioHandlingError);
+    iPhoneModel.DataStore()->SetErrorCode( aErrorCode );
+    TEFLOGSTRING( 
+        KTAREQOUT, 
+        "AUD CPEAudioData::SendErrorMessage: iPhoneModel.SendMessage( MEngineMonitor::EPEMessageAudioHandlingError )" );
+    iPhoneModel.SendMessage( MEngineMonitor::EPEMessageAudioHandlingError );
     }
 
 // -----------------------------------------------------------------------------
@@ -151,22 +189,41 @@
 // Forwards message to PhoneEngine.
 // -----------------------------------------------------------------------------
 //
-void CPEAudioData::SendMessage(
-        const MEngineMonitor::TPEMessagesFromPhoneEngine aMessage)
+void CPEAudioData::SendMessage( 
+        const MEngineMonitor::TPEMessagesFromPhoneEngine aMessage )
     {
-    TEFLOGSTRING2( KTAREQIN,
-            "AUD CPEAudioData::SendMessage: aMessage = %d", aMessage );
-
-    if (aMessage == MEngineMonitor::EPEMessageAudioVolumeChanged)
+    TEFLOGSTRING2( KTAREQIN, 
+        "AUD CPEAudioData::SendMessage: aMessage = %d", aMessage );
+   
+   if ( aMessage == MEngineMonitor::EPEMessageAudioVolumeChanged )
+	   {
+	    // update volume
+	    if ( iPhoneModel.DataStore()->AudioOutput() == EPELoudspeaker )
+	        {
+	        iLoudspeakerVolume = iPhoneModel.DataStore()->AudioVolume();
+	        TEFLOGSTRING2( KTAINT, 
+	            "AUD CPEAudioData::SendMessage: iLoudspeakerVolume = %d", 
+	            iLoudspeakerVolume );
+	        }
+	    else 
+	        {
+	        iHeadSetVolume = iPhoneModel.DataStore()->AudioVolume();
+	        TEFLOGSTRING2( KTAINT, 
+	            "AUD CPEAudioData::SendMessage: iHeadSetVolume = %d", 
+	            iHeadSetVolume );
+	        }	
+    	   	
+       	if ( !iAudioOutputChanged )
+            {
+            // EPEMessageAudioVolumeChanged message must not be sent 
+            // while audio output change is being processed
+            iPhoneModel.SendMessage( aMessage );	
+            }
+	   }
+    else 
         {
-        // update volume
-        TInt volume = iPhoneModel.DataStore()->AudioVolume();
-        TEFLOGSTRING2( KTAINT,
-                "AUD CPEAudioData::SendMessage: volume = %d",
-                volume );
-        }
-
-    iPhoneModel.SendMessage(aMessage);
+        iPhoneModel.SendMessage( aMessage );	
+        }        
     }
 
 // -----------------------------------------------------------------------------
@@ -174,30 +231,75 @@
 // Forwards message to PhoneEngine. Output mode is saved.
 // -----------------------------------------------------------------------------
 //
-void CPEAudioData::SendMessage(
+void CPEAudioData::SendMessage( 
         const MEngineMonitor::TPEMessagesFromPhoneEngine aMessage,
-        const CTelephonyAudioRouting::TAudioOutput aOutput)
+        const CTelephonyAudioRouting::TAudioOutput aOutput )
     {
-    TEFLOGSTRING3(
-            KTAREQIN,
-            "AUD CPEAudioData::SendMessage: aMessage = %d, aOutput = %d",
-            aMessage, aOutput );
-
+    TEFLOGSTRING3( 
+         KTAREQIN, 
+        "AUD CPEAudioData::SendMessage: aMessage = %d, aOutput = %d", 
+        aMessage, aOutput );
+        
     // BT long key press requires manual re-route to handset or loudspeaker
-    if (aOutput == CTelephonyAudioRouting::ENone
-            && iAudioRouting->PreviousOutput()
-                    == CTelephonyAudioRouting::EBTAudioAccessory)
+    if ( aOutput == CTelephonyAudioRouting::ENone &&
+         iAudioRouting->PreviousOutput() == CTelephonyAudioRouting::EBTAudioAccessory )
         {
-        SetRoutePreference(ETrue);
+        SetRoutePreference( ETrue );
         }
     else
         {
+        // store the old audio path volume
+        if ( iPhoneModel.DataStore()->AudioOutput() == EPELoudspeaker )
+            {
+            iLoudspeakerVolume = iPhoneModel.DataStore()->AudioVolume();
+            TEFLOGSTRING2( KTAINT, 
+                "AUD CPEAudioData::SendMessage: iLoudspeakerVolume = %d", 
+                iLoudspeakerVolume );
+            }
+        else 
+            {
+            iHeadSetVolume = iPhoneModel.DataStore()->AudioVolume();
+            TEFLOGSTRING2( KTAINT, 
+                "AUD CPEAudioData::SendMessage: iHeadSetVolume = %d", 
+                iHeadSetVolume );
+            }
+        
         // update the audio values in engineinfo
         TBool status;
-        iAudioRouting->GetShowNote(status);
-        iPhoneModel.DataStore()->SetAudioOutput(ConvertToPE(aOutput),
-                ConvertToPE(PreviousOutput()), status);
-        iPhoneModel.SendMessage(aMessage);
+        iAudioRouting->GetShowNote( status );
+        iPhoneModel.DataStore()->SetAudioOutput( ConvertToPE( aOutput ), ConvertToPE( PreviousOutput() ), status );
+
+        // Set audio output change flag 
+        iAudioOutputChanged = ( MEngineMonitor::EPEMessageAudioOutputChanged == aMessage );
+          
+        // restore the stored volume for the new path
+        if ( aOutput == CTelephonyAudioRouting::ELoudspeaker )
+            {
+            // restore the stored volume for the new path
+            SetAudioVolumeSync( iLoudspeakerVolume );
+            iPhoneModel.DataStore()->SetAudioVolume( iLoudspeakerVolume );   
+            TEFLOGSTRING2( KTAINT, 
+                "AUD CPEAudioData::SendMessage: DataStoreExt()->Set, iLoudspeakerVolume = %d", 
+                iLoudspeakerVolume );
+            iPhoneModel.DataStoreExt()->Set( EPEIncallLoudspeakerVolumeSetting,
+                iLoudspeakerVolume );
+            }
+        else 
+            {
+            // restore the stored volume for the new path
+            SetAudioVolumeSync( iHeadSetVolume );
+            iPhoneModel.DataStore()->SetAudioVolume( iHeadSetVolume );   
+            TEFLOGSTRING2( KTAINT, 
+                "AUD CPEAudioData::SendMessage: DataStoreExt()->Set, iHeadSetVolume  = %d", 
+                iHeadSetVolume );
+            iPhoneModel.DataStoreExt()->Set( EPEIncallEarVolumeSetting,
+                iHeadSetVolume );
+            }
+        
+        // Reset audio output change flag 
+        iAudioOutputChanged = EFalse;                                                
+                     
+        iPhoneModel.SendMessage( aMessage );
         }
     }
 
@@ -205,24 +307,24 @@
 // CPEAudioData::SendMessage
 // Forwards message to PhoneEngine.
 // -----------------------------------------------------------------------------
-//
-void CPEAudioData::SendMessage(
-        const MEngineMonitor::TPEMessagesFromPhoneEngine aMessage,
-        CTelephonyAudioRouting& aTelephonyAudioRouting)
+//   
+void CPEAudioData::SendMessage( 
+        const MEngineMonitor::TPEMessagesFromPhoneEngine aMessage, 
+        CTelephonyAudioRouting& aTelephonyAudioRouting )
     {
-    TEFLOGSTRING2(
-            KTAREQIN,
-            "AUD CPEAudioData::SendMessage: aMessage = %d, available outputs changed ", aMessage );
-    iPhoneModel.DataStore()->SetAvailableAudioOutputs(GetAvailableOutputs(
-            aTelephonyAudioRouting));
-
-    if (iRouteInitialized && aMessage
-            == MEngineMonitor::EPEMessageAvailableAudioOutputsChanged)
+    TEFLOGSTRING2( 
+         KTAREQIN, 
+        "AUD CPEAudioData::SendMessage: aMessage = %d, available outputs changed ", aMessage );
+    iPhoneModel.DataStore()->SetAvailableAudioOutputs( 
+        GetAvailableOutputs( aTelephonyAudioRouting ) );
+    
+    if ( iRouteInitialized &&
+         aMessage == MEngineMonitor::EPEMessageAvailableAudioOutputsChanged )
         {
         iAudioRoutingHandler->HandleAudioRoutingAvailableChanged();
         }
-
-    iPhoneModel.SendMessage(aMessage);
+ 
+    iPhoneModel.SendMessage( aMessage );
     }
 
 // -----------------------------------------------------------------------------
@@ -231,29 +333,37 @@
 // EPEMessageAudioMuteChanged message is sent when gain is changed
 // -----------------------------------------------------------------------------
 //
-EXPORT_C void CPEAudioData::SetAudioMuteSync(const TBool aAudioMute) // Mute value to be set
+EXPORT_C void CPEAudioData::SetAudioMuteSync( 
+        const TBool aAudioMute ) // Mute value to be set
     {
     TEFLOGSTRING( KTAINT, "AUD CPEAudioData::SetAudioMuteSync" );
-
-    if (aAudioMute)
+    
+    if ( aAudioMute )
         {
-        iPhoneModel.DataStore()->SetAudioMute(aAudioMute);
-        SendMessage(MEngineMonitor::EPEMessageAudioMuteChanged);
-        TInt err = iAudioEffect->SetMuteState(ETrue);
-        TEFLOGSTRING2(
-                KTAREQOUT,
-                "AUD CPEAudioData::SetAudioMuteSync: error = %d",
-                err );
+        iPhoneModel.DataStore()->SetAudioMute( aAudioMute );
+        SendMessage( MEngineMonitor::EPEMessageAudioMuteChanged );
+        // Inform VoIP/PE Videocallmanager mute state. Error code not handled.
+        TInt err = RProperty::Set( 
+            KPSUidTelMicrophoneMuteStatus, 
+            KTelMicrophoneMuteState,
+            EPSTelMicMuteOn );
+            TEFLOGSTRING2( 
+                KTAREQOUT, 
+                "AUD CPEAudioData::SetAudioMuteSync: EPSTelephonyMicMuteOn , error = %d", 
+                err );            
         }
     else
         {
-        iPhoneModel.DataStore()->SetAudioMute(aAudioMute);
-        SendMessage(MEngineMonitor::EPEMessageAudioMuteChanged);
-        TInt err = iAudioEffect->SetMuteState(EFalse);
-        TEFLOGSTRING2(
-                KTAREQOUT,
-                "AUD CPEAudioData::SetAudioMuteSync: error = %d",
-                err );
+        iPhoneModel.DataStore()->SetAudioMute( aAudioMute );
+        SendMessage( MEngineMonitor::EPEMessageAudioMuteChanged );
+        TInt err = RProperty::Set( 
+            KPSUidTelMicrophoneMuteStatus, 
+            KTelMicrophoneMuteState,
+            EPSTelMicMuteOff );
+        TEFLOGSTRING2( 
+            KTAREQOUT, 
+            "AUD CPEAudioData::SetAudioMuteSync: EPSTelephonyMicMuteOff, error = %d", 
+            err );                
         }
     }
 
@@ -262,22 +372,43 @@
 // Creates synchronous request to set audio volume.
 // -----------------------------------------------------------------------------
 //
-EXPORT_C void CPEAudioData::SetAudioVolumeSync(const TInt aAudioVolume) // Volume to be set
+EXPORT_C void CPEAudioData::SetAudioVolumeSync( 
+        const TInt aAudioVolume ) // Volume to be set
     {
-    TEFLOGSTRING2(
-            KTAREQIN,
+    TEFLOGSTRING2( 
+        KTAREQIN, 
+        "AUD CPEAudioData::SetAudioVolumeSync, aAudioVolume = %d", 
+        aAudioVolume );
+ 
+    if ( aAudioVolume <= KPEMaxVolume ) 
+        {
+        TEFLOGSTRING2( KTAINT, 
             "AUD CPEAudioData::SetAudioVolumeSync, aAudioVolume = %d",
             aAudioVolume );
+        
+        if ( iPhoneModel.DataStore()->AudioOutput() == EPELoudspeaker )
+            {
+            iPhoneModel.DataStoreExt()->Set( 
+                EPEIncallLoudspeakerVolumeSetting, 
+                aAudioVolume );
+            TEFLOGSTRING( KTAINT, 
+                "AUD CPEAudioData::SetAudioVolumeSync: EPEIncallLoudspeakerVolumeSetting");
+            }
+        else 
+            {
+            iPhoneModel.DataStoreExt()->Set( 
+                EPEIncallEarVolumeSetting, 
+                aAudioVolume );
+            TEFLOGSTRING( KTAINT, 
+                "AUD CPEAudioData::SetAudioVolumeSync: EPEIncallEarVolumeSetting");
+            }
+		}            
+ 
+    iPhoneModel.DataStore()->SetAudioVolume( aAudioVolume );
 
-    if (aAudioVolume <= KPEMaxVolume)
-        {
-        TEFLOGSTRING2( KTAINT,
-                "AUD CPEAudioData::SetAudioVolumeSync, aAudioVolume = %d",
-                aAudioVolume );
+    DoHandleVolumeChange( aAudioVolume );
 
-        iAudioEffect->SetVolume(aAudioVolume);
-        }
-    DoHandleVolumeChange(aAudioVolume, ETrue);
+    SendMessage( MEngineMonitor::EPEMessageAudioVolumeChanged );
     }
 
 // -----------------------------------------------------------------------------
@@ -285,95 +416,97 @@
 // Makes request to Telephony Audio Routing to set audio output path
 // -----------------------------------------------------------------------------
 //
-EXPORT_C TInt CPEAudioData::SetAudioOutput(const TPEAudioOutput aOutput,
-        TBool aShowNote)
+EXPORT_C TInt CPEAudioData::SetAudioOutput( 
+        const TPEAudioOutput aOutput,
+        TBool aShowNote )
     {
-    TEFLOGSTRING2(
-            KTAREQIN,
-            "AUD CPEAudioData::SetAudioOutput: aOutput = %d",
-            aOutput );
+    TEFLOGSTRING2( 
+        KTAREQIN, 
+        "AUD CPEAudioData::SetAudioOutput: aOutput = %d", 
+        aOutput );
+        
+    TInt error( KErrNone );
+    
+    TEFLOGSTRING2( KTAERROR, 
+        "AUD CPEAudioData::SetAudioOutput: iRouteInitialized (%d)"
+        , iRouteInitialized );
 
-    TInt error(KErrNone);
-
-    TEFLOGSTRING2( KTAERROR,
-            "AUD CPEAudioData::SetAudioOutput: iRouteInitialized (%d)"
-            , iRouteInitialized );
-
-    if (iRouteInitialized && iPhoneModel.DataStore()->AudioOutputAvailable(
-            aOutput))
+    if ( iRouteInitialized  && iPhoneModel.DataStore()->AudioOutputAvailable( aOutput ) )
         {
-        SetTAROutput(ConvertToTAR(aOutput), aShowNote);
+        SetTAROutput( ConvertToTAR( aOutput), aShowNote  );
         }
     else
         {
-        if (aOutput == EPEHandset)
+        if ( aOutput == EPEHandset )
             {
-            iAudioRoutingHandler->SetAnswerToHandset(ETrue);
+            iAudioRoutingHandler->SetAnswerToHandset( ETrue );
             }
         else
             {
             TEFLOGSTRING2( KTAERROR,
-                    "AUD CPEAudioData::SetAudioOutput: Requested audio path not available (%d)"
-                    , aOutput );
-            error = KErrArgument;
+                 "AUD CPEAudioData::SetAudioOutput: Requested audio path not available (%d)"
+                 , aOutput );
+            error = KErrArgument;            
             }
         }
-
+ 
     return error;
     }
 
+
 // -----------------------------------------------------------------------------
 // CPEAudioData::SetTAROutput
 // -----------------------------------------------------------------------------
 //
-void CPEAudioData::SetTAROutput(CTelephonyAudioRouting::TAudioOutput aOutput,
-        TBool aShowNote)
+void CPEAudioData::SetTAROutput( 
+    CTelephonyAudioRouting::TAudioOutput aOutput,
+    TBool aShowNote ) 
     {
-    TEFLOGSTRING2(
-            KTAREQIN,
-            "AUD CPEAudioData::SetTAROutput: aOutput = %d",
-            aOutput );
+    TEFLOGSTRING2( 
+        KTAREQIN, 
+        "AUD CPEAudioData::SetTAROutput: aOutput = %d", 
+        aOutput );
 
 #if defined(__WINSCW__ ) && !defined(UNIT_TESTING)
-    iAudioRouting->SetShowNote(aShowNote);
-    SendMessage(MEngineMonitor::EPEMessageAudioOutputChanged, aOutput);
-#else
-    CTelephonyAudioRouting::TAudioOutput output = iAudioRouting->Output();
-
-    if ( output == aOutput )
-        {
-        // audio routing cannot changed
-        TEFLOGSTRING2( KTAERROR,
-                "AUD CPEAudioData::SetTAROutput: audio path already (%d)"
-                , aOutput );
-        return;
+    iAudioRouting->SetShowNote( aShowNote );
+    SendMessage( MEngineMonitor::EPEMessageAudioOutputChanged, aOutput);
+#else   	
+    CTelephonyAudioRouting::TAudioOutput output = iAudioRouting->Output();    	
+     
+    if ( output == aOutput ) 
+    	{
+    	// audio routing cannot changed
+    	TEFLOGSTRING2( KTAERROR, 
+    	    "AUD CPEAudioData::SetTAROutput: audio path already (%d)"
+    	    , aOutput );
+  		return;
+     	}
+    iAudioRouting->SetShowNote( aShowNote );     	    
+   	TRAPD( err, iAudioRouting->SetOutputL( aOutput ) );
+    
+	if( err )
+		{
+		TEFLOGSTRING2( KTAERROR, 
+		    "AUD CPEAudioData::SetTAROutput:Leave.1 (%d)", err );
+ 	    switch ( aOutput )
+		    {
+			case CTelephonyAudioRouting::ELoudspeaker:
+			case CTelephonyAudioRouting::EWiredAudioAccessory:   		    
+			case CTelephonyAudioRouting::EBTAudioAccessory:
+				// if leave try handset
+				TRAPD( err2, iAudioRouting->SetOutputL( CTelephonyAudioRouting::EHandset ) );
+				if( err2 )
+					{
+					TEFLOGSTRING2( KTAERROR, 
+					    "AUD CPEAudioData::SetTAROutput:Leave.2 (%d)", err );
+ 					}				
+				break;
+		  	default:
+		        // None
+		    	break;     
+		    }
         }
-    iAudioRouting->SetShowNote( aShowNote );
-    TRAPD( err, iAudioRouting->SetOutputL( aOutput ) );
-
-    if( err )
-        {
-        TEFLOGSTRING2( KTAERROR,
-                "AUD CPEAudioData::SetTAROutput:Leave.1 (%d)", err );
-        switch ( aOutput )
-            {
-            case CTelephonyAudioRouting::ELoudspeaker:
-            case CTelephonyAudioRouting::EWiredAudioAccessory:
-            case CTelephonyAudioRouting::EBTAudioAccessory:
-                // if leave try handset
-                TRAPD( err2, iAudioRouting->SetOutputL( CTelephonyAudioRouting::EHandset ) );
-                if( err2 )
-                    {
-                    TEFLOGSTRING2( KTAERROR,
-                            "AUD CPEAudioData::SetTAROutput:Leave.2 (%d)", err );
-                    }
-                break;
-            default:
-                // None
-                break;
-            }
-        }
-#endif
+#endif        
     }
 
 // -----------------------------------------------------------------------------
@@ -386,11 +519,8 @@
     {
     TEFLOGSTRING( KTAREQIN, "AUD CPEAudioData::StartUp" );
     // get available audio output paths and current audio output
-    iPhoneModel.DataStore()->SetAvailableAudioOutputs(GetAvailableOutputs(
-            *iAudioRouting));
-    iPhoneModel.DataStore()->SetAudioOutput(ConvertToPE(
-            iAudioRouting->Output()), ConvertToPE(
-            iAudioRouting->PreviousOutput()), EFalse);
+    iPhoneModel.DataStore()->SetAvailableAudioOutputs( GetAvailableOutputs( *iAudioRouting ) );
+    iPhoneModel.DataStore()->SetAudioOutput( ConvertToPE( iAudioRouting->Output() ), ConvertToPE( iAudioRouting->PreviousOutput() ), EFalse );    
     }
 
 // -----------------------------------------------------------------------------
@@ -399,103 +529,125 @@
 // Return list of available outputs
 // -----------------------------------------------------------------------------
 //
-TArray<TPEAudioOutput> CPEAudioData::GetAvailableOutputs(
-        CTelephonyAudioRouting& aTelephonyAudioRouting)
+TArray<TPEAudioOutput> CPEAudioData::GetAvailableOutputs( 
+        CTelephonyAudioRouting& aTelephonyAudioRouting )
     {
-    TEFLOGSTRING( KTAREQOUT,
-            "AUD CPEAudioData::GetAvailableOutputs > CTelephonyAudioRouting::AvailableOutputs()" );
-    TArray<CTelephonyAudioRouting::TAudioOutput> availableOutputs =
-            aTelephonyAudioRouting.AvailableOutputs();
-
+    TEFLOGSTRING( KTAREQOUT, 
+        "AUD CPEAudioData::GetAvailableOutputs > CTelephonyAudioRouting::AvailableOutputs()" );
+    TArray<CTelephonyAudioRouting::TAudioOutput> availableOutputs = 
+        aTelephonyAudioRouting.AvailableOutputs();
+    
     iPEavailableOutputs.Reset();
 
-    for (TInt j = 0; j < availableOutputs.Count(); j++)
+    for ( TInt j = 0; j < availableOutputs.Count(); j++ )
         {
-        TInt err = iPEavailableOutputs.Append(ConvertToPE(availableOutputs[j]));
-        TEFLOGSTRING4( KTAINT,
-                "AUD CPEAudioData::GetAvailableOutputs, index: %d, available: %d, err: %d",
-                j,
-                availableOutputs[j],
-                err );
-        if(err != KErrNone)
-            {
-            // Do nothing. Here for just to suppress the compile warning.
-            }
+        iPEavailableOutputs.Append( ConvertToPE( availableOutputs[j] ) );
+        TEFLOGSTRING3( KTAINT, 
+            "AUD CPEAudioData::GetAvailableOutputs, index: %d, available: %d", 
+            j, 
+            availableOutputs[j] );
+        }     
+ 
+    return iPEavailableOutputs.Array();  
+    }
+ 
+// -----------------------------------------------------------------------------
+// CPEAudioData::SetDefaultVolume
+// -----------------------------------------------------------------------------
+//
+EXPORT_C void CPEAudioData::SetDefaultVolume()
+    {
+    TEFLOGSTRING( KTAREQIN, "AUD CPEAudioData::SetDefaultVolume" );
+    if ( !iLoudspeakerVolume )
+        {
+        TEFLOGSTRING( KTAREQIN, "AUD CPEAudioData->SetDefaultLoudspeakerVolume" );
+        iLoudspeakerVolume = KPEDefaultVolume;
+        iPhoneModel.DataStore()->SetAudioVolume( iLoudspeakerVolume );
+        iPhoneModel.DataStoreExt()->Set( EPEIncallLoudspeakerVolumeSetting,
+                iLoudspeakerVolume );
+        }
+    if ( !iHeadSetVolume )
+        {
+        TEFLOGSTRING( KTAREQIN, "AUD CPEAudioData->SetDefaultHeadSetVolume" );
+        iHeadSetVolume = KPEDefaultVolume;
+        iPhoneModel.DataStore()->SetAudioVolume( iHeadSetVolume );
+        iPhoneModel.DataStoreExt()->Set( EPEIncallEarVolumeSetting, 
+                iHeadSetVolume );            
         }
 
-    return iPEavailableOutputs.Array();
-    }
-
+    DoHandleVolumeChange( KPEDefaultVolume );
+    }    
+  
 // -----------------------------------------------------------------------------
-// CPEAudioData::HandleCallStarting
+// CPEAudioData::HandleCallStarting  
 // -----------------------------------------------------------------------------
-//
-EXPORT_C TInt CPEAudioData::HandleCallStarting(TBool aVideoCall)
+//    
+EXPORT_C TInt CPEAudioData::HandleCallStarting( TBool aVideoCall )
     {
     TEFLOGSTRING( KTAMESINT, "AUD CPEAudioData::HandleCallStarting()" );
-    TInt ret(KErrNone);
-
-    if (!iRouteInitialized) // if route not already initialized
-        { // Not new route init for multi calls
+    TInt ret( KErrNone );
+    
+    if ( !iRouteInitialized )  // if route not already initialized
+        {                      // Not new route init for multi calls
         iRouteInitialized = ETrue;
-        ret = iAudioRoutingHandler->HandleAudioRoutingCallInit(aVideoCall);
+        ret  = iAudioRoutingHandler->HandleAudioRoutingCallInit( aVideoCall );
         }
-
-    return ret;
+    
+    return ret;        
     }
 
 // -----------------------------------------------------------------------------
 // CPEAudioData::HandleEnergencyCallStarting
 // Can be called, if new call is created before previous call is idle state
-// One used situation is that emergency call is dialed during the video call or
+// One used situation is that emergency call is dialed during the video call or 
 // voice call. Audio routing have to initialized when emergency is dialing state
 // even previous call(voice or video) haven't got idle yet.
 // -----------------------------------------------------------------------------
-//
+//    
 EXPORT_C TInt CPEAudioData::HandleEnergencyCallStarting()
     {
     TEFLOGSTRING( KTAMESINT, "AUD CPEAudioData::HandleCallSwitching()" );
-    TInt ret(KErrNone);
-
+    TInt ret( KErrNone );
+    
     // Always new route init
-    ret = iAudioRoutingHandler->HandleAudioRoutingCallInit(EFalse);
+    ret = iAudioRoutingHandler->HandleAudioRoutingCallInit( EFalse );
     iRouteInitialized = ETrue;
-
-    return ret;
+  
+    return ret;        
     }
 
 // -----------------------------------------------------------------------------
 // CPEAudioData::HandleCallEnding()
 // -----------------------------------------------------------------------------
-//
+//    
 EXPORT_C void CPEAudioData::HandleCallEnding()
     {
     TEFLOGSTRING( KTAMESINT, "AUD CPEAudioData::HandleCallEnding()" );
-
-    if (iRouteInitialized)
+    
+    if ( iRouteInitialized )
         {
         iRouteInitialized = EFalse;
-        TEFLOGSTRING( KTAMESINT,
-                "AUD CPEAudioData::HandleCallEnding() > CTelephonyAudioRouting::ENotActive" );
-        SetTAROutput(CTelephonyAudioRouting::ENotActive, EFalse);
+        TEFLOGSTRING( KTAMESINT, 
+            "AUD CPEAudioData::HandleCallEnding() > CTelephonyAudioRouting::ENotActive" );
+        SetTAROutput( CTelephonyAudioRouting::ENotActive, EFalse  );        
         }
     }
-
+     
 // -----------------------------------------------------------------------------
 // CPEAudioData::CallAudioRoutePreferenceChanged()
-//
+//  
 // -----------------------------------------------------------------------------
-//
+//    
 EXPORT_C TInt CPEAudioData::CallAudioRoutePreferenceChanged()
     {
     TEFLOGSTRING( KTAMESINT, "AUD CPEAudioData::CallAudioRoutePreferenceChanged()" );
-    if (iRouteInitialized)
+    if ( iRouteInitialized )
         {
-        return iAudioRoutingHandler->HandleAudioRoutePreferenceChanged();
+        return iAudioRoutingHandler->HandleAudioRoutePreferenceChanged();         
         }
     return KErrNotReady;
-    }
-
+    }    
+        
 // -----------------------------------------------------------------------------
 // CPEAudioData::PreviousOutput
 // -----------------------------------------------------------------------------
@@ -504,7 +656,7 @@
     {
     return iAudioRouting->PreviousOutput();
     }
-
+        
 // -----------------------------------------------------------------------------
 // CPEAudioData::Output
 // -----------------------------------------------------------------------------
@@ -513,74 +665,62 @@
     {
     return iAudioRouting->Output();
     }
-
+ 
 // -----------------------------------------------------------------------------
 // CPEAudioData::SetRoutePreference
 // -----------------------------------------------------------------------------
-//
-void CPEAudioData::SetRoutePreference(TBool aShowNote)
+//    
+void CPEAudioData::SetRoutePreference( TBool aShowNote )
     {
     TEFLOGSTRING( KTAMESINT, "AUD CPEAudioData::SetRoutePreference()" );
-    CTelephonyAudioRouting::TAudioOutput output =
-            CTelephonyAudioRouting::EHandset;
-
-    const TInt outputPreference =
-            iPhoneModel.DataStore()->AudioOutputPreference();
-    if (outputPreference == EPSAudioPublic)
+    CTelephonyAudioRouting::TAudioOutput output = CTelephonyAudioRouting::EHandset;
+     
+    const TInt outputPreference = iPhoneModel.DataStore()->AudioOutputPreference();
+    if ( outputPreference == EPSAudioPublic )
         {
         output = CTelephonyAudioRouting::ELoudspeaker;
         }
     TInt error;
-    iAudioRouting->SetShowNote(aShowNote);
+    iAudioRouting->SetShowNote( aShowNote );
     TRAP( error, iAudioRouting->SetOutputL( output ) );
     TEFLOGSTRING2( KTAMESINT, "AUD CPEAudioData::SetRoutePreference() err %d", error );
-    }
-
+    }    
+    
 // -----------------------------------------------------------------------------
 // CPEAudioData::RoutePreference
 // -----------------------------------------------------------------------------
-//
+//    
 CTelephonyAudioRouting::TAudioOutput CPEAudioData::RoutePreference()
     {
-    CTelephonyAudioRouting::TAudioOutput output =
-            CTelephonyAudioRouting::EHandset;
-
-    const TInt outputPreference =
-            iPhoneModel.DataStore()->AudioOutputPreference();
-    if (outputPreference == EPSAudioPublic)
+    CTelephonyAudioRouting::TAudioOutput output = CTelephonyAudioRouting::EHandset;
+     
+    const TInt outputPreference = iPhoneModel.DataStore()->AudioOutputPreference();
+    if ( outputPreference == EPSAudioPublic )
         {
         output = CTelephonyAudioRouting::ELoudspeaker;
         }
-    else
-        {
-        TInt value; 
-        const TInt err = RProperty::Get( KPSUidTelCarMode, KTelCarMode, value );
-        if ( !err && value == EPSCarModeOn )
-            {
-            output = CTelephonyAudioRouting::ELoudspeaker;
-            }
-        }
-        
     TEFLOGSTRING2( KTAMESINT, "AUD CPEAudioData::RoutePreference() output %d", output );
     return output;
-    }
+    }    
 // -----------------------------------------------------------------------------
 // CPEAudioData::IsWiredAvailable
 // -----------------------------------------------------------------------------
 //
 TBool CPEAudioData::IsWiredAvailable()
     {
-    return iPhoneModel.DataStore()->AudioOutputAvailable(
-            EPEWiredAudioAccessory);
+    return iPhoneModel.DataStore()->AudioOutputAvailable( 
+         EPEWiredAudioAccessory );
     }
 
+    
 // -----------------------------------------------------------------------------
 // CPEAudioData::IsBTAvailable
 // -----------------------------------------------------------------------------
 //
 TBool CPEAudioData::IsBTAvailable()
     {
-    return iPhoneModel.DataStore()->AudioOutputAvailable(EPEBTAudioAccessory);
+    return iPhoneModel.DataStore()->AudioOutputAvailable( 
+         EPEBTAudioAccessory );
     }
 
 // -----------------------------------------------------------------------------
@@ -589,20 +729,39 @@
 //
 TBool CPEAudioData::IsTTYAvailable()
     {
-    return iPhoneModel.DataStore()->AudioOutputAvailable(EPETTY);
+    return iPhoneModel.DataStore()->AudioOutputAvailable( 
+         EPETTY );
     }
+ // -----------------------------------------------------------------------------
+// CPEAudioData::IsMuted
+// -----------------------------------------------------------------------------
+//
+TBool CPEAudioData::IsMuted() const
+    {
+    TInt value;
+    TInt err = RProperty::Get( 
+        KPSUidTelMicrophoneMuteStatus, 
+        KTelMicrophoneMuteState,
+        value );
+ 
+    TEFLOGSTRING3( 
+         KTAREQIN, 
+        "AUD CPEAudioData::IsMuted: value = %d, error = %d", 
+        value, err );        
+    return ( value == EPSTelMicMuteOn ) ? ETrue : EFalse;
+    }   
+   
 
 // -----------------------------------------------------------------------------
 // CPEAudioData::ConvertToPE
 // -----------------------------------------------------------------------------
 //
-TPEAudioOutput CPEAudioData::ConvertToPE(
-        CTelephonyAudioRouting::TAudioOutput aOutput)
+TPEAudioOutput CPEAudioData::ConvertToPE( CTelephonyAudioRouting::TAudioOutput aOutput )
     {
     TEFLOGSTRING2( KTAMESINT, "AUD CPEAudioData::ConvertToPE, aOutput %d", aOutput );
-    TPEAudioOutput newOutput(EPENotActive);
-
-    switch (aOutput)
+    TPEAudioOutput newOutput( EPENotActive );
+    
+    switch( aOutput )
         {
         case CTelephonyAudioRouting::ENotActive:
             newOutput = EPENotActive;
@@ -623,9 +782,9 @@
             newOutput = EPETTY;
             break;
         default:
-            break;
+            break;    
         }
-
+    
     return newOutput;
     }
 
@@ -633,15 +792,13 @@
 // CPEAudioData::ConvertToTAR
 // -----------------------------------------------------------------------------
 //
-CTelephonyAudioRouting::TAudioOutput CPEAudioData::ConvertToTAR(
-        TPEAudioOutput aOutput)
+CTelephonyAudioRouting::TAudioOutput CPEAudioData::ConvertToTAR( TPEAudioOutput aOutput )
     {
     TEFLOGSTRING2( KTAMESINT, "AUD CPEAudioData::ConvertToTAR, aOutput %d", aOutput );
-
-    CTelephonyAudioRouting::TAudioOutput newOutput(
-            CTelephonyAudioRouting::ENotActive);
-
-    switch (aOutput)
+    
+    CTelephonyAudioRouting::TAudioOutput newOutput ( CTelephonyAudioRouting::ENotActive );
+    
+    switch( aOutput )
         {
         case EPENotActive:
             newOutput = CTelephonyAudioRouting::ENotActive;
@@ -662,7 +819,7 @@
             newOutput = CTelephonyAudioRouting::ETTY;
             break;
         default:
-            break;
+            break;    
         }
     return newOutput;
     }
@@ -671,43 +828,9 @@
 // CPEAudioData::DoHandleVolumeChange
 // -----------------------------------------------------------------------------
 //
-void CPEAudioData::DoHandleVolumeChange(TInt aVolume, TBool aSendMsg)
+void CPEAudioData::DoHandleVolumeChange( TInt /*aVolume*/ )
     {
-    iPhoneModel.DataStore()->SetAudioVolume(aVolume);
-
-    if (aSendMsg)
-        {
-        SendMessage(MEngineMonitor::EPEMessageAudioVolumeChanged);
-        }
+    
     }
 
-// -----------------------------------------------------------------------------
-// CPEAudioData::EffectsEvent
-// -----------------------------------------------------------------------------
-//
-void CPEAudioData::EffectsEvent(const TMSEffect& tmseffect,
-        TMSSignalEvent event)
-    {
-    TMSEffectType effecttype;
-    const_cast<TMSEffect&>(tmseffect).GetType(effecttype);
-
-    if (effecttype == TMS_EFFECT_GLOBAL_VOL &&
-            event.type == TMS_EVENT_EFFECT_VOL_CHANGED)
-        {
-        TMSVolumeEventChangeData* vd;
-        vd = static_cast<TMSVolumeEventChangeData*>(event.event_data);
-
-        // If volume change event has been triggered by routing change, we
-        // do not want to send EPEMessageAudioVolumeChanged message.
-        if (!vd->output_changed)
-            {
-            DoHandleVolumeChange(iAudioEffect->Volume(), ETrue);
-            }
-        else
-            {
-            DoHandleVolumeChange(iAudioEffect->Volume(), EFalse);
-            }
-        }
-    }
-
-// End of File
+// End of File