convergedcallengine/csplugin/src/cspspeaker.cpp
branchRCL_3
changeset 20 987c9837762f
parent 0 ff3b6d0fd310
equal deleted inserted replaced
19:7d48bed6ce0c 20:987c9837762f
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Provides speaker functionality
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <AudioPreference.h>
       
    20 
       
    21 #include "cspspeaker.h"
       
    22 #include "csplogger.h"
       
    23 #include "mcspdevsoundobserver.h"
       
    24 
       
    25 //Audio levels
       
    26 //Max volume level
       
    27 const TInt KMaxVolumeLevel = 10;
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // Static constructor
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 CSPSpeaker* CSPSpeaker::NewL(
       
    34     MCSPDevSoundObserver& aObserver )
       
    35     {
       
    36     CSPSpeaker* self = new( ELeave ) CSPSpeaker( aObserver );
       
    37     CleanupStack::PushL( self );
       
    38     self->ConstructL();
       
    39     CleanupStack::Pop( self );
       
    40     return self;
       
    41     }
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // Destructor.
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 CSPSpeaker::~CSPSpeaker()
       
    48     {
       
    49     }
       
    50    
       
    51 // ---------------------------------------------------------------------------
       
    52 // Sets volume
       
    53 // Volume needs to be converted from 0-10 scale to the volume scale used by 
       
    54 // DevSound 0 - MaxVolume().
       
    55 // No need to check aVolume value, because devsound takes care
       
    56 // than illegal value are converted to legal, ie <0 are 0 and >MaxVolume
       
    57 // are set to MaxVolume.
       
    58 // ---------------------------------------------------------------------------
       
    59 //    
       
    60 void CSPSpeaker::SetVolume( TInt aVolume )
       
    61     {
       
    62     TInt vol( 0 );    
       
    63     vol = iDevSound->MaxVolume() * aVolume / KMaxVolumeLevel;
       
    64     iDevSound->SetVolume( vol );
       
    65     CSPLOGSTRING2(CSPINT, "CSPSpeaker::SetVolume() \
       
    66                 vol=%d", vol ); 
       
    67     CSPLOGSTRING2(CSPINT, "CSPSpeaker::SetVolume() \
       
    68                 maxVol=%d", iDevSound->MaxVolume() );
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // Gives volume
       
    73 // ---------------------------------------------------------------------------
       
    74 //    
       
    75 TInt CSPSpeaker::Volume()
       
    76     {
       
    77     TInt devVol = iDevSound->Volume();
       
    78     CSPLOGSTRING2(CSPINT, "CSPSpeaker::Volume \
       
    79                     vol from DevSound =%d", devVol );
       
    80     TInt vol = devVol * KMaxVolumeLevel / iDevSound->MaxVolume();
       
    81     
       
    82     CSPLOGSTRING2(CSPINT, "CSPSpeaker::Volume() \
       
    83                        vol=%d", vol );
       
    84        
       
    85     return vol;
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // From class MDevSoundObserver
       
    90 // Speaker stream has been activated successfully.
       
    91 // ---------------------------------------------------------------------------
       
    92 //    
       
    93 void CSPSpeaker::BufferToBeFilled( CMMFBuffer* /*aBuffer*/ )
       
    94     {
       
    95     CSPLOGSTRING( CSPINT, "CSPSpeaker::BufferToBeFilled activated" );
       
    96     // We dont react to devsound messages unless we are activating.
       
    97     if( IsActivationOngoing() )
       
    98         {
       
    99         iActive = ETrue;
       
   100         iActivationOngoing = EFalse;
       
   101         iObserver.SpeakerActivatedSuccessfully();
       
   102         }
       
   103     }
       
   104     
       
   105 // ---------------------------------------------------------------------------
       
   106 // From class MDevSoundObserver
       
   107 // Speaker stream activation failed
       
   108 // ---------------------------------------------------------------------------
       
   109 //    
       
   110 void CSPSpeaker::PlayError( TInt aError )   
       
   111     {
       
   112     CSPLOGSTRING( CSPINT, "CSPSpeaker::PlayError" );
       
   113     
       
   114     // We dont react to devsound messages unless we are activating.
       
   115     if( IsActivationOngoing() )
       
   116         {
       
   117         CSPLOGSTRING( CSPINT, "CSPSpeaker::PlayError activation failed" );
       
   118         if( aError == KErrAccessDenied ) 
       
   119             {
       
   120             iActivationOngoing = EFalse;
       
   121             iObserver.SpeakerActivationFailed();
       
   122             }
       
   123         }
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // From class CSPDevsound
       
   128 // Tries to activate speaker stream.
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 void CSPSpeaker::DoActivateL()
       
   132     {
       
   133     iDevSound->PlayInitL();
       
   134     }  
       
   135     
       
   136 // ---------------------------------------------------------------------------
       
   137 // Constructor
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 CSPSpeaker::CSPSpeaker( 
       
   141     MCSPDevSoundObserver& aObserver ) :
       
   142     CSPDevSound( aObserver )
       
   143     {
       
   144     }
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // Second phase constructor
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 void CSPSpeaker::ConstructL()
       
   151     {
       
   152     CSPDevSound::ConstructL( 
       
   153         EMMFStatePlaying, 
       
   154         KAudioPrefCSCallDownlink,
       
   155         KAudioPriorityCSCallDownlink );
       
   156     }
       
   157 
       
   158 //  End of File