radioengine/engine/src/cradioengineimp.cpp
branchRCL_3
changeset 19 cce62ebc198e
equal deleted inserted replaced
18:1a6714c53019 19:cce62ebc198e
       
     1 /*
       
     2 * Copyright (c) 2009 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:
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <AudioOutput.h>
       
    20 #include <eikdef.h>
       
    21 #include <coemain.h>
       
    22 #include <badesca.h>
       
    23 #include <tzlocalizer.h>
       
    24 
       
    25 // User includes
       
    26 #include "cradioenginelogger.h"
       
    27 #include "radiointernalcrkeys.h"
       
    28 #include "cradioaudiorouter.h"
       
    29 #include "cradioengineimp.h"
       
    30 #include "mradioengineobserver.h"
       
    31 #include "cradioregion.h"
       
    32 #include "cradiosettings.h"
       
    33 #include "mradioenginesettings.h"
       
    34 #include "mradiosettingssetter.h"
       
    35 #include "cradiordsreceiver.h"
       
    36 #include "cradiosystemeventcollector.h"
       
    37 #include "cradionetworkinfolistener.h"
       
    38 #include "radioengine.hrh"
       
    39 #include "cradioenginelogger.h"
       
    40 
       
    41 // This has to be the last include.
       
    42 #ifdef STUB_CONSTELLATION
       
    43 #   include <RadioStubManager.h>
       
    44 #endif //STUB_CONSTELLATION
       
    45 
       
    46 // Constants
       
    47 
       
    48 /** The limit of volume steps that must not be divided */
       
    49 const TInt KRadioVolumeStepsDividinglimit = 20;
       
    50 /** If CMMTunerUtility has 200 volume steps, AknVolume control has 20 steps */
       
    51 const TInt KRadioVolumeStepsDivider = 500;
       
    52 /** amount of volume steps used previously */
       
    53 #if defined __WINS__
       
    54 const TInt KRadioVolumeStepsWins = 20;
       
    55 #endif // defined __WINS__
       
    56 
       
    57 /** KRadioRadioSwitchDelay value must not be too small, otherwise problems with
       
    58  radioserver will occur, when swithing between valid and invalid presets */
       
    59 const TInt KRadioRadioSwitchDelay = 300; // In milliseconds
       
    60 
       
    61 const TInt KRadioThousand = 1000;
       
    62 const TInt KRadioMillion = KRadioThousand * KRadioThousand;
       
    63 
       
    64 // Country order from timezones.rss. Default = 0, Japan = 1, America = 2.
       
    65 const TUint KCityGroupRegions[] =
       
    66     {0,0,0,0,0,0,2,0,0,0,0,2,0,2,0,2,0,2,0,2,2,0,2,0,0,2,2,2,0,2,0,0, //32
       
    67      0,0,0,0,0,0,0,2,2,0,0,0,0,0,0,0,0,0,0,2,1,0,0,0,0,0,0,0,0,0,0,0, //64
       
    68      0,0,0,0,0,2,0,0,0,2,0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //96
       
    69      0,0,0,2,0,0,0,0,2,2,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //128
       
    70      0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //160
       
    71      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,2,2,0,0,0,0,0,0,0,0,0,0, //192
       
    72      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0, //224
       
    73      2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
       
    74 
       
    75 
       
    76 
       
    77 // ================= MEMBER FUNCTIONS =======================
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 CRadioEngineImp::CRadioEngineImp( CRadioAudioRouter* aAudioRouter )
       
    84     : CRadioEngine( aAudioRouter )
       
    85     , iAntennaAttached( ETrue )
       
    86     , iFreqEventReason( RadioEngine::ERadioFrequencyEventReasonUnknown )
       
    87     {
       
    88     LEVEL3( LOG_METHOD_AUTO );
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 void CRadioEngineImp::ConstructL()
       
    96     {
       
    97     LOG_METHOD_AUTO;
       
    98 
       
    99     if ( !iAudioRouter || !iSystemEventCollector || !iSettings )
       
   100         {
       
   101         User::Leave( KErrNotReady );
       
   102         }
       
   103 
       
   104     iSystemEventCollector->AddObserverL( this );
       
   105 
       
   106     // Initial default values to be over by init
       
   107     User::LeaveIfError( iSettings->RadioSetter().SetPowerOn( EFalse ) );
       
   108 
       
   109     // The output source needs to be in headset when starting the radio.
       
   110     // But if the headset is not connected, audio cannot be heard if it is routed
       
   111     // to headset
       
   112     RadioEngine::TRadioAudioRoute route = iSystemEventCollector->IsHeadsetConnectedL() ?
       
   113                                 RadioEngine::ERadioHeadset : RadioEngine::ERadioSpeaker;
       
   114     User::LeaveIfError( iSettings->RadioSetter().SetAudioRoute( route ) );
       
   115 
       
   116     iRdsReceiver = CRadioRdsReceiver::NewL( iSettings->EngineSettings() );
       
   117     iNetworkInfoListener = CRadioNetworkInfoListener::NewL( iSettings->RadioSetter(), NULL );
       
   118 
       
   119     iRdsReceiver->AddObserverL( this );
       
   120 
       
   121     // Create timer that is used when polling for radio restart.
       
   122     iRadioTimer = CPeriodic::NewL( CActive::EPriorityHigh );
       
   123     }
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 CRadioEngineImp::~CRadioEngineImp()
       
   130     {
       
   131     LEVEL3( LOG_METHOD_AUTO );
       
   132 
       
   133     delete iNetworkInfoListener;
       
   134 
       
   135     PowerOff();
       
   136 
       
   137     delete iRadioTimer;
       
   138 
       
   139     DeleteAudioOutput();
       
   140 
       
   141     if ( iTunerUtility )
       
   142         {
       
   143         iTunerUtility->Close();
       
   144         }
       
   145 
       
   146     if ( iPlayerUtility )
       
   147         {
       
   148         iPlayerUtility->Close();
       
   149         }
       
   150 
       
   151     if ( iRdsReceiver )
       
   152         {
       
   153         iRdsReceiver->RemoveObserver( this );
       
   154         }
       
   155 
       
   156     delete iRdsReceiver;
       
   157     delete iRadioUtility;
       
   158 
       
   159     iObservers.Close();
       
   160 
       
   161     if ( iSystemEventCollector )
       
   162         {
       
   163         iSystemEventCollector->RemoveObserver( this );
       
   164         }
       
   165     delete iSystemEventCollector;
       
   166 
       
   167     if ( iSettings )
       
   168         {
       
   169         iSettings->RadioSetter().SetObserver( NULL );
       
   170         }
       
   171     delete iSettings;
       
   172 
       
   173     }
       
   174 
       
   175 // ---------------------------------------------------------------------------
       
   176 //
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 void CRadioEngineImp::SetSystemEventCollector( CRadioSystemEventCollector* aCollector )
       
   180     {
       
   181     LEVEL3( LOG_METHOD_AUTO );
       
   182     iSystemEventCollector = aCollector;
       
   183     }
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 //
       
   187 // ---------------------------------------------------------------------------
       
   188 //
       
   189 void CRadioEngineImp::SetRadioSettings( CRadioSettings* aSettings )
       
   190     {
       
   191     LEVEL3( LOG_METHOD_AUTO );
       
   192     iSettings = aSettings;
       
   193     iSettings->RadioSetter().SetObserver( this );
       
   194     }
       
   195 
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 // ---------------------------------------------------------------------------
       
   199 //
       
   200 CRadioAudioRouter& CRadioEngineImp::AudioRouter() const
       
   201     {
       
   202     LEVEL3( LOG_METHOD_AUTO );
       
   203     return *iAudioRouter;
       
   204     }
       
   205 
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 // ---------------------------------------------------------------------------
       
   209 //
       
   210 CRadioSystemEventCollector& CRadioEngineImp::SystemEventCollector() const
       
   211     {
       
   212     LEVEL3( LOG_METHOD_AUTO );
       
   213     return *iSystemEventCollector;
       
   214     }
       
   215 
       
   216 // ---------------------------------------------------------------------------
       
   217 //
       
   218 // ---------------------------------------------------------------------------
       
   219 //
       
   220 CRadioSettings& CRadioEngineImp::Settings() const
       
   221     {
       
   222     LEVEL3( LOG_METHOD_AUTO );
       
   223     return *iSettings;
       
   224     }
       
   225 
       
   226 // ---------------------------------------------------------------------------
       
   227 // Determines radio region
       
   228 // ---------------------------------------------------------------------------
       
   229 //
       
   230 TRadioRegion CRadioEngineImp::DetermineRegion()
       
   231     {
       
   232     LEVEL3( LOG_METHOD_AUTO );
       
   233     TRadioRegion region = ERadioRegionNone;
       
   234 
       
   235     //TODO: Reimplement in QT side and remove the mobile network functionality
       
   236     MRadioEngineSettings& engineSettings = iSettings->EngineSettings();
       
   237     if ( iSystemEventCollector->IsMobileNetworkCoverage() )
       
   238         {
       
   239         region = RegionFromMobileNetwork();
       
   240         }
       
   241     else
       
   242         {
       
   243         region = RegionFromTimezone();
       
   244         }
       
   245 
       
   246     if ( !iSettings->IsRegionAllowed( region ) )
       
   247         {
       
   248         region = ERadioRegionNone;
       
   249         }
       
   250 
       
   251     // Region not found, try to use the previously set region
       
   252     if ( region == ERadioRegionNone && engineSettings.RegionId() != ERadioRegionNone )
       
   253         {
       
   254         region = engineSettings.RegionId();
       
   255         }
       
   256 
       
   257     // All regions have been searched and no direct match found, use default one
       
   258     if ( region == ERadioRegionNone )
       
   259         {
       
   260         region = engineSettings.DefaultRegion();
       
   261         }
       
   262 
       
   263     return region;
       
   264     }
       
   265 
       
   266 // ---------------------------------------------------------------------------
       
   267 // Initializes / reinitializes the radio. If this is not called
       
   268 // the radio is not functional
       
   269 // ---------------------------------------------------------------------------
       
   270 //
       
   271 void CRadioEngineImp::InitRadioL( TInt aRegionId )
       
   272     {
       
   273     LOG_METHOD_AUTO;
       
   274     LOG_FORMAT( "Region: %d", aRegionId );
       
   275 
       
   276     iRadioInitializationState = ERadioNotInitialized;
       
   277 
       
   278     iFreqEventReason = RadioEngine::ERadioFrequencyEventReasonUnknown;
       
   279     if ( iSettings->EngineSettings().RegionId() != aRegionId )
       
   280         {
       
   281         // Change only when necessary as it changes also the default tuned frequency
       
   282         User::LeaveIfError( iSettings->RadioSetter().SetRegionId( aRegionId ) );
       
   283         }
       
   284 
       
   285     if ( !iRadioUtility )
       
   286         {
       
   287         iRadioUtility = CRadioUtility::NewL( ETrue );
       
   288         }
       
   289 
       
   290     if ( !iPlayerUtility )
       
   291         {
       
   292         iPlayerUtility = &iRadioUtility->RadioPlayerUtilityL( *this );
       
   293         SetAudioOutput( CAudioOutput::NewL( *iPlayerUtility ) );
       
   294         }
       
   295 
       
   296     if ( !iTunerUtility )
       
   297         {
       
   298         iTunerUtility = &iRadioUtility->RadioFmTunerUtilityL( *this );
       
   299         }
       
   300 
       
   301     // Utilities have been created now
       
   302     iRadioInitializationState = ERadioUtilitiesConstructed;
       
   303 
       
   304     RequestTunerControl();
       
   305     }
       
   306 
       
   307 // ---------------------------------------------------------------------------
       
   308 //
       
   309 // ---------------------------------------------------------------------------
       
   310 //
       
   311 TBool CRadioEngineImp::RadioInitialized() const
       
   312     {
       
   313     LEVEL3( LOG_METHOD_AUTO );
       
   314     return iRadioInitializationState == ERadioTunerControlGranted;
       
   315     }
       
   316 
       
   317 // ---------------------------------------------------------------------------
       
   318 // Sets the state for radio audio
       
   319 // ---------------------------------------------------------------------------
       
   320 //
       
   321 void CRadioEngineImp::EnableAudio( TBool aEnable, TBool aDelay )
       
   322     {
       
   323     LOG_METHOD_AUTO;
       
   324     LOG_FORMAT( "aEnable %d ", aEnable );
       
   325     iRadioEnabled = aEnable;
       
   326     if ( aDelay )
       
   327         {
       
   328         SwitchPower( iRadioEnabled );
       
   329         }
       
   330     else if ( aEnable )
       
   331         {
       
   332         if ( !RadioInitialized() &&
       
   333              iRadioInitializationState == ERadioUtilitiesConstructed &&
       
   334              iRadioEnabled &&
       
   335              OkToPlay( iSettings->EngineSettings().TunedFrequency() ) )
       
   336             {
       
   337             RequestTunerControl();
       
   338             }
       
   339         else
       
   340             {
       
   341             PowerOn();
       
   342             }
       
   343         }
       
   344     else
       
   345         {
       
   346         PowerOff();
       
   347         }
       
   348     }
       
   349 
       
   350 // ---------------------------------------------------------------------------
       
   351 // Gets the state for radio audio.
       
   352 // ---------------------------------------------------------------------------
       
   353 //
       
   354 TBool CRadioEngineImp::RadioAudioEnabled() const
       
   355     {
       
   356     LEVEL3( LOG_METHOD_AUTO );
       
   357     return iRadioEnabled;
       
   358     }
       
   359 
       
   360 // ---------------------------------------------------------------------------
       
   361 // Sets the state for audio overriding
       
   362 // ---------------------------------------------------------------------------
       
   363 //
       
   364 void CRadioEngineImp::SetAudioOverride( TBool aOverride )
       
   365     {
       
   366     LEVEL3( LOG_METHOD_AUTO );
       
   367     LEVEL3( LOG_FORMAT( "aOverride %d ", aOverride ) );
       
   368     iOverrideAudioResources = aOverride;
       
   369     }
       
   370 
       
   371 // ---------------------------------------------------------------------------
       
   372 // Adds an observer for the radio state changes notifications.
       
   373 // ---------------------------------------------------------------------------
       
   374 //
       
   375 void CRadioEngineImp::AddObserverL( MRadioEngineObserver* aObserver )
       
   376     {
       
   377     LEVEL3( LOG_METHOD_AUTO );
       
   378     TInt index = iObservers.FindInAddressOrder( aObserver );
       
   379     if ( index == KErrNotFound )
       
   380         {
       
   381         iObservers.InsertInAddressOrderL( aObserver );
       
   382         }
       
   383     }
       
   384 
       
   385 // ---------------------------------------------------------------------------
       
   386 // Removes an observer from the list of obsevers
       
   387 // ---------------------------------------------------------------------------
       
   388 //
       
   389 void CRadioEngineImp::RemoveObserver( MRadioEngineObserver* aObserver )
       
   390     {
       
   391     LEVEL3( LOG_METHOD_AUTO );
       
   392     TInt index = iObservers.FindInAddressOrder( aObserver );
       
   393 
       
   394     if ( index >= 0 )
       
   395         {
       
   396         iObservers.Remove( index );
       
   397         }
       
   398     }
       
   399 
       
   400 // ---------------------------------------------------------------------------
       
   401 //
       
   402 // ---------------------------------------------------------------------------
       
   403 //
       
   404 TFmRadioFrequencyRange CRadioEngineImp::TunerFrequencyRangeForRegionId( TInt aRegionId ) const
       
   405     {
       
   406     LEVEL3( LOG_METHOD_AUTO );
       
   407     TFmRadioFrequencyRange result = EFmRangeEuroAmerica;
       
   408     switch ( aRegionId )
       
   409         {
       
   410         case ERadioRegionDefault:
       
   411             {
       
   412             result = EFmRangeEuroAmerica;
       
   413             break;
       
   414             }
       
   415         case ERadioRegionJapan:
       
   416             {
       
   417             result = EFmRangeJapan;
       
   418             break;
       
   419             }
       
   420         case ERadioRegionAmerica:
       
   421             {
       
   422             result = EFmRangeEuroAmerica;
       
   423             break;
       
   424             }
       
   425         default:
       
   426             break;
       
   427         }
       
   428     return result;
       
   429     }
       
   430 
       
   431 // ---------------------------------------------------------------------------
       
   432 // Sets radio mode ERadioStereo or ERadioMono
       
   433 // ---------------------------------------------------------------------------
       
   434 
       
   435 void CRadioEngineImp::SetAudioMode( TInt aAudioMode )
       
   436     {
       
   437     LEVEL3( LOG_METHOD_AUTO );
       
   438     LOG_FORMAT( "aAudioMode: %d", aAudioMode );
       
   439     TInt err = KErrNone;
       
   440     if ( !RadioInitialized() )
       
   441         {
       
   442         TInt err = iSettings->RadioSetter().SetOutputMode( aAudioMode );
       
   443         NotifyRadioEvent( ERadioEventAudioMode, err );
       
   444         }
       
   445     else
       
   446         {
       
   447         err = iTunerUtility->ForceMonoReception( aAudioMode == RadioEngine::ERadioMono );
       
   448 
       
   449         if ( err )
       
   450             {
       
   451             NotifyRadioEvent( ERadioEventAudioMode, err );
       
   452             }
       
   453         }
       
   454     }
       
   455 
       
   456 // ---------------------------------------------------------------------------
       
   457 // Switches power on/off after a delay
       
   458 // ---------------------------------------------------------------------------
       
   459 //
       
   460 void CRadioEngineImp::SwitchPower( TBool aPowerOn )
       
   461     {
       
   462     LEVEL3( LOG_METHOD_AUTO );
       
   463     LOG_FORMAT( "aPowerOn %d", aPowerOn );
       
   464     if ( RadioInitialized() )
       
   465         {
       
   466         if ( !aPowerOn || OkToPlay( iSettings->EngineSettings().TunedFrequency() ) )
       
   467             {
       
   468             iRadioTimer->Cancel();
       
   469             if ( aPowerOn )
       
   470                 {
       
   471                 iRadioTimer->Start( TTimeIntervalMicroSeconds32( KRadioRadioSwitchDelay * KRadioThousand ),
       
   472                         TTimeIntervalMicroSeconds32( 0 ),
       
   473                         TCallBack( StaticPowerOnCallback, this ) );
       
   474                 }
       
   475             else
       
   476                 {
       
   477                 iRadioTimer->Start( TTimeIntervalMicroSeconds32( KRadioRadioSwitchDelay * KRadioThousand ),
       
   478                         TTimeIntervalMicroSeconds32( 0 ),
       
   479                         TCallBack( StaticPowerOffCallback, this ) );
       
   480                 }
       
   481             }
       
   482         }
       
   483     else if ( aPowerOn &&
       
   484             iRadioInitializationState == ERadioUtilitiesConstructed &&
       
   485             iRadioEnabled &&
       
   486             OkToPlay( iSettings->EngineSettings().TunedFrequency() ) )
       
   487         {
       
   488         RequestTunerControl();
       
   489         }
       
   490     else
       
   491         {
       
   492         LOG( "CRadioEngineImp::SwitchPower - Unhandled case" );
       
   493         LOG_FORMAT( "PowerOn: %d, InitializationState: %d, Enabled: %d, Frequency: %d",
       
   494                 aPowerOn, iRadioInitializationState, iRadioEnabled, iSettings->EngineSettings().TunedFrequency() );
       
   495         }
       
   496     }
       
   497 
       
   498 // ---------------------------------------------------------------------------
       
   499 // Executes the power switch
       
   500 // ---------------------------------------------------------------------------
       
   501 //
       
   502 TInt CRadioEngineImp::StaticPowerOnCallback( TAny* aSelfPtr )
       
   503     {
       
   504     LEVEL3( LOG_METHOD_AUTO );
       
   505     CRadioEngineImp* self = reinterpret_cast<CRadioEngineImp*>( aSelfPtr );
       
   506 
       
   507     if ( self )
       
   508         {
       
   509         self->iRadioTimer->Cancel(); // prevents the further calls.
       
   510 
       
   511         if ( !self->iSettings->EngineSettings().IsPowerOn() )
       
   512             {
       
   513             self->PowerOn();
       
   514             }
       
   515         }
       
   516 
       
   517     return KErrNone;
       
   518     }
       
   519 
       
   520 // ---------------------------------------------------------------------------
       
   521 // Executes the power switch
       
   522 // ---------------------------------------------------------------------------
       
   523 //
       
   524 TInt CRadioEngineImp::StaticPowerOffCallback( TAny* aSelfPtr )
       
   525     {
       
   526     LEVEL3( LOG_METHOD_AUTO );
       
   527     CRadioEngineImp* self = reinterpret_cast<CRadioEngineImp*>( aSelfPtr );
       
   528 
       
   529     if ( self )
       
   530         {
       
   531         self->iRadioTimer->Cancel(); // prevents the further calls.
       
   532 
       
   533         if ( self->iSettings->EngineSettings().IsPowerOn() )
       
   534             {
       
   535             self->PowerOff();
       
   536             }
       
   537         }
       
   538 
       
   539     return KErrNone;
       
   540     }
       
   541 
       
   542 // ---------------------------------------------------------------------------
       
   543 //
       
   544 // ---------------------------------------------------------------------------
       
   545 //
       
   546 void CRadioEngineImp::PowerOn()
       
   547     {
       
   548     LOG_METHOD_AUTO;
       
   549 
       
   550     if ( RadioInitialized() &&
       
   551         iRadioEnabled &&
       
   552         OkToPlay( iSettings->EngineSettings().TunedFrequency() ) )
       
   553         {
       
   554         SetAudioMode( iSettings->EngineSettings().OutputMode() );
       
   555         iPlayerUtility->SetVolumeRamp( TTimeIntervalMicroSeconds( MAKE_TINT64( 0, KRadioMillion ) ) );
       
   556         iPlayerUtility->SetVolume( TunerVolumeForUiVolume( iSettings->EngineSettings().Volume() ) );
       
   557 
       
   558         iPlayerUtility->Mute( iSettings->EngineSettings().IsVolMuted() );
       
   559         iTunerUtility->SetFrequency( iSettings->EngineSettings().TunedFrequency() );
       
   560         iFreqEventReason = RadioEngine::ERadioFrequencyEventReasonImplicit;
       
   561 
       
   562         TRAP_IGNORE( iAudioRouter->SetAudioRouteL(
       
   563                 RadioEngine::TRadioAudioRoute( iSettings->EngineSettings().AudioRoute() ) ) )
       
   564 
       
   565         iPlayerUtility->Play();
       
   566         }
       
   567     else
       
   568         {
       
   569         HandlePowerEvent( EFalse, KErrGeneral );
       
   570         }
       
   571     }
       
   572 
       
   573 // ---------------------------------------------------------------------------
       
   574 // Radio power off
       
   575 // ---------------------------------------------------------------------------
       
   576 //
       
   577 void CRadioEngineImp::PowerOff()
       
   578     {
       
   579     LOG_METHOD_AUTO;
       
   580 
       
   581     if ( iSettings->EngineSettings().IsPowerOn() )
       
   582         {
       
   583         if ( RadioInitialized() )
       
   584             {
       
   585             iPlayerUtility->Stop();
       
   586             }
       
   587         else // This shouldn't occur normally, just a recovery action
       
   588             {
       
   589             HandlePowerEvent( EFalse, KErrNone );
       
   590             }
       
   591         }
       
   592     }
       
   593 
       
   594 // ---------------------------------------------------------------------------
       
   595 // Requests tuner control from tuner utility
       
   596 // ---------------------------------------------------------------------------
       
   597 //
       
   598 void CRadioEngineImp::RequestTunerControl()
       
   599     {
       
   600     LOG_METHOD_AUTO;
       
   601 
       
   602     if ( iRadioInitializationState < ERadioTunerControlRequested )
       
   603         {
       
   604         LOG( "Requesting tuner control" );
       
   605         // Before first RequestTunerControl() say that it is ok to enable offline mode without checking capabilities
       
   606         iTunerUtility->EnableTunerInOfflineMode( ETrue );
       
   607         iTunerUtility->RequestTunerControl();
       
   608 
       
   609         iRadioInitializationState = ERadioTunerControlRequested;
       
   610         }
       
   611     else
       
   612         {
       
   613         LOG( "Tuner control already requested" );
       
   614         }
       
   615     }
       
   616 
       
   617 // ---------------------------------------------------------------------------
       
   618 //
       
   619 // ---------------------------------------------------------------------------
       
   620 //
       
   621 TBool CRadioEngineImp::OkToPlay( TUint32 aFrequency ) const
       
   622     {
       
   623     LEVEL3( LOG_METHOD_AUTO );
       
   624     TBool audioResourcesAvailable = iSystemEventCollector->IsAudioResourcesAvailable();
       
   625     TBool okToPlay = iAntennaAttached &&
       
   626                      !iFmTransmitterActive &&
       
   627                      ( audioResourcesAvailable || iOverrideAudioResources ) &&
       
   628 #ifdef COMPILE_IN_IVALO
       
   629                      IsFrequencyValid( aFrequency )
       
   630                      && !iSystemEventCollector->IsCallActive();
       
   631 #else
       
   632                      IsFrequencyValid( aFrequency );
       
   633 #endif //COMPILE_IN_IVALO
       
   634 
       
   635     LEVEL2( LOG_FORMAT( "returning okToPlay %d ", okToPlay ) );
       
   636     return okToPlay;
       
   637     }
       
   638 
       
   639 // ---------------------------------------------------------------------------
       
   640 //
       
   641 // ---------------------------------------------------------------------------
       
   642 //
       
   643 TBool CRadioEngineImp::IsFrequencyValid( TUint32 aFrequency ) const
       
   644     {
       
   645     LEVEL3( LOG_METHOD_AUTO );
       
   646     TBool ret( EFalse );
       
   647     if ( !aFrequency )
       
   648         {
       
   649         aFrequency = iSettings->EngineSettings().TunedFrequency();
       
   650         }
       
   651     if ( aFrequency >= iSettings->EngineSettings().MinFrequency() && aFrequency <= iSettings->EngineSettings().MaxFrequency() )
       
   652         {
       
   653         ret = ETrue;
       
   654         }
       
   655     return ret;
       
   656     }
       
   657 
       
   658 // ---------------------------------------------------------------------------
       
   659 //
       
   660 // ---------------------------------------------------------------------------
       
   661 //
       
   662 void CRadioEngineImp::SetManualSeekMode( TBool aManualSeekActive )
       
   663     {
       
   664     iManualSeekMode = aManualSeekActive;
       
   665     if ( iManualSeekMode )
       
   666         {
       
   667         CancelSeek();
       
   668         iRdsReceiver->StopReceiver();
       
   669         }
       
   670     else
       
   671         {
       
   672         iRdsReceiver->StartReceiver();
       
   673         TInt frequency = 0;
       
   674         iTunerUtility->GetFrequency( frequency );
       
   675         HandleFrequencyEvent( frequency );
       
   676         }
       
   677     }
       
   678 
       
   679 // ---------------------------------------------------------------------------
       
   680 //
       
   681 // ---------------------------------------------------------------------------
       
   682 //
       
   683 TBool CRadioEngineImp::IsInManualSeekMode() const
       
   684     {
       
   685     return iManualSeekMode;
       
   686     }
       
   687 
       
   688 // ---------------------------------------------------------------------------
       
   689 // Radio tuning
       
   690 // ---------------------------------------------------------------------------
       
   691 //
       
   692 void CRadioEngineImp::SetFrequency( TUint32 aFrequency, RadioEngine::TRadioFrequencyEventReason aReason )
       
   693     {
       
   694     LEVEL3( LOG_METHOD_AUTO );
       
   695     LEVEL2( LOG_FORMAT( "freq: %u, Initialized: %d, Enabled: %d",
       
   696             aFrequency, RadioInitialized(), iRadioEnabled ) );
       
   697 
       
   698     iFreqEventReason = aReason;
       
   699     if ( iManualSeekMode )
       
   700         {
       
   701         iTunerUtility->SetFrequency( aFrequency );
       
   702         }
       
   703     else
       
   704         {
       
   705         iFrequencySetByRdsAf = EFalse;
       
   706 
       
   707         TInt frequency = 0;
       
   708         if ( iTunerUtility )
       
   709             {
       
   710             iTunerUtility->GetFrequency( frequency );
       
   711             }
       
   712         CancelSeek();
       
   713 
       
   714         if ( aFrequency == frequency ) //radio has already the frequency to be set.
       
   715             {
       
   716             LOG( "CRadioEngineImp::SetFrequency: Already at the requested frequency" );
       
   717             HandleFrequencyEvent( aFrequency );
       
   718             }
       
   719         else
       
   720             {
       
   721             iRadioTimer->Cancel();
       
   722             if ( RadioInitialized() && iRadioEnabled && OkToPlay( aFrequency ) )
       
   723                 {
       
   724                 LOG( "CRadioEngineImp::SetFrequency: Tuning to frequency" );
       
   725                 iTunerUtility->SetFrequency( aFrequency );
       
   726                 }
       
   727             else
       
   728                 {
       
   729                 HandleFrequencyEvent( aFrequency );
       
   730                 }
       
   731             }
       
   732         }
       
   733     }
       
   734 
       
   735 // ---------------------------------------------------------------------------
       
   736 // Radio seek
       
   737 // ---------------------------------------------------------------------------
       
   738 //
       
   739 void CRadioEngineImp::Seek( RadioEngine::TRadioTuneDirection aDirection )
       
   740     {
       
   741     LOG_METHOD_AUTO;
       
   742     LOG_FORMAT( "aDirection: %d",aDirection );
       
   743 
       
   744     iFrequencySetByRdsAf = EFalse;
       
   745 
       
   746     // Check if audio playing parameters ( other than frequency ) are OK
       
   747     if ( iRadioEnabled &&
       
   748         OkToPlay( iSettings->EngineSettings().MinFrequency() ) &&
       
   749         iSeekingState == RadioEngine::ERadioNotSeeking )
       
   750         {
       
   751         if ( aDirection == RadioEngine::ERadioDown )
       
   752             {
       
   753             iSeekingState = RadioEngine::ERadioSeekingDown;
       
   754             iFreqEventReason = RadioEngine::ERadioFrequencyEventReasonSeekDown;
       
   755             }
       
   756         else
       
   757             {
       
   758             iSeekingState = RadioEngine::ERadioSeekingUp;
       
   759             iFreqEventReason = RadioEngine::ERadioFrequencyEventReasonSeekUp;
       
   760             }
       
   761 
       
   762         NotifyRadioEvent( ERadioEventSeeking );
       
   763 
       
   764         if ( IsFrequencyValid() )
       
   765             {
       
   766             if ( iSettings->EngineSettings().IsPowerOn() )
       
   767                 {
       
   768                 iTunerUtility->StationSeek( aDirection == RadioEngine::ERadioUp ? ETrue : EFalse );
       
   769                 }
       
   770             else
       
   771                 {
       
   772                 // Try to switch power on ( reinitialization )
       
   773                 SwitchPower( ETrue );
       
   774                 }
       
   775             }
       
   776         else
       
   777             {
       
   778             // Tune first to valid frequency, start seeking after radio power is on
       
   779             SetFrequency( iSettings->EngineSettings().MinFrequency(), RadioEngine::ERadioFrequencyEventReasonImplicit );
       
   780             }
       
   781         }
       
   782     else
       
   783         {
       
   784         NotifyRadioEvent( ERadioEventSeeking, KErrGeneral );
       
   785         }
       
   786     }
       
   787 
       
   788 // ---------------------------------------------------------------------------
       
   789 // Cancels seek up/down request
       
   790 // ---------------------------------------------------------------------------
       
   791 //
       
   792 void CRadioEngineImp::CancelSeek()
       
   793     {
       
   794     LOG_METHOD_AUTO;
       
   795     LOG_FORMAT( "seeking state was:%d", iSeekingState );
       
   796 
       
   797     if ( iSeekingState != RadioEngine::ERadioNotSeeking )
       
   798         {
       
   799         iSeekingState = RadioEngine::ERadioNotSeeking;
       
   800         iTunerUtility->CancelStationSeek();
       
   801         iFreqEventReason = RadioEngine::ERadioFrequencyEventReasonImplicit;
       
   802         NotifyRadioEvent( ERadioEventSeeking, KErrCancel );
       
   803         NotifyRadioEvent( ERadioEventFrequency, KErrNone ); // Notify the observers even if the frequency remains the same.
       
   804         }
       
   805     }
       
   806 
       
   807 // ---------------------------------------------------------------------------
       
   808 //
       
   809 // ---------------------------------------------------------------------------
       
   810 //
       
   811 RadioEngine::TRadioSeeking CRadioEngineImp::Seeking() const
       
   812     {
       
   813     LEVEL3( LOG_METHOD_AUTO );
       
   814     return iSeekingState;
       
   815     }
       
   816 
       
   817 // ---------------------------------------------------------------------------
       
   818 // Sets volume level up/down one step.
       
   819 // ---------------------------------------------------------------------------
       
   820 //
       
   821 void CRadioEngineImp::AdjustVolume( RadioEngine::TRadioVolumeSetDirection aDirection )
       
   822     {
       
   823     LOG_METHOD_AUTO;
       
   824     LOG_FORMAT( "aDirection: %d ", aDirection );
       
   825 
       
   826     if ( iSettings->EngineSettings().IsPowerOn() )
       
   827         {
       
   828         TInt volume = iSettings->EngineSettings().Volume();
       
   829         LOG_FORMAT( "volume = ( %d )", volume );
       
   830 
       
   831         if ( aDirection == RadioEngine::ERadioDecVolume )
       
   832             {
       
   833             TInt min = iSettings->EngineSettings().DefaultMinVolumeLevel();
       
   834             if ( --volume < min )
       
   835                 {
       
   836                 volume = 0;
       
   837                 }
       
   838             }
       
   839         else if ( aDirection == RadioEngine::ERadioIncVolume )
       
   840             {
       
   841             TInt max = MaxVolumeLevel();
       
   842 
       
   843             if ( ++volume > max )
       
   844                 {
       
   845                 volume = max;
       
   846                 }
       
   847             }
       
   848         else
       
   849             {
       
   850             LOG( "Unhandled case" );
       
   851             }
       
   852         SetVolume( volume );
       
   853         }
       
   854     }
       
   855 
       
   856 // ---------------------------------------------------------------------------
       
   857 // Sets audio volume level
       
   858 // ---------------------------------------------------------------------------
       
   859 //
       
   860 void CRadioEngineImp::SetVolume( TInt aVolume )
       
   861     {
       
   862     LOG_METHOD_AUTO;
       
   863     LOG_FORMAT( "aVolume: %d", aVolume );
       
   864 
       
   865     if ( iSettings->EngineSettings().IsPowerOn() && RadioInitialized() )
       
   866         {
       
   867         LOG( "Setting volume to player utility" );
       
   868 
       
   869         if ( aVolume == 0 )
       
   870             {
       
   871             iSettings->RadioSetter().SetVolume( aVolume );
       
   872             NotifyRadioEvent( ERadioEventVolume, KErrNone );
       
   873             SetVolumeMuted( ETrue );
       
   874             }
       
   875         else
       
   876             {
       
   877             if ( iPlayerUtility->SetVolume( TunerVolumeForUiVolume( aVolume ) ) == KErrNone )
       
   878                 {
       
   879                 iSettings->RadioSetter().SetVolume( aVolume );
       
   880                 NotifyRadioEvent( ERadioEventVolume, KErrNone );
       
   881                 SetVolumeMuted( EFalse );
       
   882                 }
       
   883             }
       
   884         }
       
   885     }
       
   886 
       
   887 // ---------------------------------------------------------------------------
       
   888 // Set radio audio muted/unmuted
       
   889 // ---------------------------------------------------------------------------
       
   890 //
       
   891 void CRadioEngineImp::SetVolumeMuted( TBool aMuteState, TBool aUpdateSettings )
       
   892     {
       
   893     LOG_METHOD_AUTO;
       
   894     LOG_FORMAT( "MuteState = %d", aMuteState );
       
   895 
       
   896     if ( iSettings->EngineSettings().IsPowerOn() )
       
   897         {
       
   898         TInt err = KErrNone;
       
   899         if ( RadioInitialized() )
       
   900             {
       
   901             err = iPlayerUtility->Mute( aMuteState );
       
   902             }
       
   903 
       
   904         if ( aUpdateSettings )
       
   905             {
       
   906             err = iSettings->RadioSetter().SetVolMuted( aMuteState );
       
   907             }
       
   908         NotifyRadioEvent( ERadioEventMute, err );
       
   909         }
       
   910     }
       
   911 
       
   912 // ---------------------------------------------------------------------------
       
   913 //
       
   914 // ---------------------------------------------------------------------------
       
   915 //
       
   916 TBool CRadioEngineImp::IsAntennaAttached()
       
   917     {
       
   918     LEVEL3( LOG_METHOD_AUTO );
       
   919     LEVEL3( LOG_FORMAT( "returning iAntennaAttached: %d", iAntennaAttached ) );
       
   920     return iAntennaAttached;
       
   921     }
       
   922 
       
   923 // ---------------------------------------------------------------------------
       
   924 //
       
   925 // ---------------------------------------------------------------------------
       
   926 //
       
   927 TBool CRadioEngineImp::IsFmTransmitterActive() const
       
   928     {
       
   929     LEVEL3( LOG_METHOD_AUTO );
       
   930     LEVEL3( LOG_FORMAT( "returning iFmTransmitterActive: %d", iFmTransmitterActive ) );
       
   931     return iFmTransmitterActive;
       
   932     }
       
   933 
       
   934 // ---------------------------------------------------------------------------
       
   935 // This function is usable only in WINS emulator.
       
   936 // ---------------------------------------------------------------------------
       
   937 //
       
   938 void CRadioEngineImp::SetAntennaAttached( TBool aAntennaAttached )
       
   939     {
       
   940     LOG_METHOD_AUTO;
       
   941 #ifdef __WINS__
       
   942     MrftoAntennaStatusChange( aAntennaAttached );
       
   943 #endif
       
   944     }
       
   945 
       
   946 // ---------------------------------------------------------------------------
       
   947 // Determine the meximum volume level by dividing the maximum volume setting
       
   948 // received from player utility to get the desired 20 volume steps
       
   949 // ---------------------------------------------------------------------------
       
   950 //
       
   951 TInt CRadioEngineImp::MaxVolumeLevel() const
       
   952     {
       
   953     LEVEL3( LOG_METHOD_AUTO );
       
   954     TInt maxLevel = 0;
       
   955 
       
   956 #if defined __WINS__
       
   957     maxLevel = KRadioVolumeStepsWins;
       
   958 #else
       
   959     if ( RadioInitialized() )
       
   960         {
       
   961         iPlayerUtility->GetMaxVolume( maxLevel );
       
   962         }
       
   963 #endif //defined __WINS__
       
   964 
       
   965     if ( maxLevel > KRadioVolumeStepsDividinglimit )
       
   966         {
       
   967         maxLevel = maxLevel / KRadioVolumeStepsDivider;
       
   968         }
       
   969 
       
   970     return maxLevel;
       
   971     }
       
   972 
       
   973 // ---------------------------------------------------------------------------
       
   974 //
       
   975 // ---------------------------------------------------------------------------
       
   976 //
       
   977 TBool CRadioEngineImp::FrequencySetByRdsAf() const
       
   978     {
       
   979     LEVEL3( LOG_METHOD_AUTO );
       
   980     return iFrequencySetByRdsAf;
       
   981     }
       
   982 
       
   983 // ---------------------------------------------------------------------------
       
   984 //
       
   985 // ---------------------------------------------------------------------------
       
   986 //
       
   987 MRadioRdsReceiver& CRadioEngineImp::RdsReceiver()
       
   988     {
       
   989     LEVEL3( LOG_METHOD_AUTO );
       
   990     return *iRdsReceiver;
       
   991     }
       
   992 
       
   993 // ---------------------------------------------------------------------------
       
   994 //
       
   995 // ---------------------------------------------------------------------------
       
   996 //
       
   997 TInt CRadioEngineImp::TunerVolumeForUiVolume( TInt aUiVolume )
       
   998     {
       
   999     LEVEL3( LOG_METHOD_AUTO );
       
  1000     TInt vol = aUiVolume * KRadioVolumeStepsDivider;
       
  1001 
       
  1002     return vol;
       
  1003     }
       
  1004 
       
  1005 // ---------------------------------------------------------------------------
       
  1006 //
       
  1007 // ---------------------------------------------------------------------------
       
  1008 //
       
  1009 void CRadioEngineImp::NotifyRadioEvent( TInt aRadioEvent, TInt aErrorCode )
       
  1010     {
       
  1011     LEVEL3( LOG_METHOD_AUTO );
       
  1012     TRAP_IGNORE( DoNotifyRadioEventL( aRadioEvent, aErrorCode ) )
       
  1013     }
       
  1014 
       
  1015 // ---------------------------------------------------------------------------
       
  1016 // Notifies all the registered observers of radio events
       
  1017 // by sending notifications to observers.
       
  1018 // ---------------------------------------------------------------------------
       
  1019 //
       
  1020 void CRadioEngineImp::DoNotifyRadioEventL( TInt aRadioEvent, TInt aErrorCode )
       
  1021     {
       
  1022     LOG_METHOD_AUTO;
       
  1023     TInt count = iObservers.Count();
       
  1024 
       
  1025     for ( TInt i = 0; i < count; ++i )
       
  1026         {
       
  1027         MRadioEngineObserver* observer = iObservers[i];
       
  1028 
       
  1029         switch ( aRadioEvent )
       
  1030             {
       
  1031             case ERadioEventPower:
       
  1032                 {
       
  1033                 observer->PowerEventL( iSettings->EngineSettings().IsPowerOn(), aErrorCode );
       
  1034                 break;
       
  1035                 }
       
  1036             case ERadioEventFrequency:
       
  1037                 {
       
  1038                 observer->FrequencyEventL( iSettings->EngineSettings().TunedFrequency(),
       
  1039                                            iFreqEventReason, aErrorCode );
       
  1040                 break;
       
  1041                 }
       
  1042             case ERadioEventVolume:
       
  1043                 {
       
  1044                 observer->VolumeEventL( iSettings->EngineSettings().Volume(), aErrorCode );
       
  1045                 break;
       
  1046                 }
       
  1047             case ERadioEventMute:
       
  1048                 {
       
  1049                 observer->MuteEventL( iSettings->EngineSettings().IsVolMuted(), aErrorCode );
       
  1050                 break;
       
  1051                 }
       
  1052             case ERadioEventAudioMode:
       
  1053                 {
       
  1054                 observer->AudioModeEventL( iSettings->EngineSettings().OutputMode(), aErrorCode );
       
  1055                 break;
       
  1056                 }
       
  1057             case ERadioEventAntenna:
       
  1058                 {
       
  1059                 observer->AntennaEventL( iAntennaAttached, aErrorCode );
       
  1060                 break;
       
  1061                 }
       
  1062             case ERadioEventAudioRouting:
       
  1063                 {
       
  1064                 observer->AudioRoutingEventL( iSettings->EngineSettings().AudioRoute(), aErrorCode );
       
  1065                 break;
       
  1066                 }
       
  1067             case ERadioEventSeeking:
       
  1068                 {
       
  1069                 observer->SeekingEventL( iSeekingState, aErrorCode );
       
  1070                 break;
       
  1071                 }
       
  1072             case ERadioEventRegion:
       
  1073                 {
       
  1074                 observer->RegionEventL( iSettings->EngineSettings().RegionId(), aErrorCode );
       
  1075                 break;
       
  1076                 }
       
  1077             case ERadioEventFmTransmitter:
       
  1078                 {
       
  1079                 observer->FmTransmitterEventL( iFmTransmitterActive );
       
  1080                 break;
       
  1081                 }
       
  1082             default:
       
  1083                 {
       
  1084                 break;
       
  1085                 }
       
  1086             }
       
  1087         }
       
  1088     }
       
  1089 
       
  1090 // ---------------------------------------------------------------------------
       
  1091 // Handles some system events
       
  1092 // ---------------------------------------------------------------------------
       
  1093 //
       
  1094 void CRadioEngineImp::HandleSystemEventL( TRadioSystemEventType aEventType )
       
  1095     {
       
  1096     LOG_METHOD_AUTO;
       
  1097     LOG_FORMAT( "aEventType = %d", aEventType );
       
  1098 
       
  1099     switch ( aEventType )
       
  1100         {
       
  1101         case ERadioAudioResourcesAvailable:
       
  1102             {
       
  1103             LOG( "CRadioEngineImp::HandleSystemEventL, Audio resources available" );
       
  1104             SwitchPower( ETrue );
       
  1105             }
       
  1106             break;
       
  1107 
       
  1108         case ERadioAudioAutoResumeForbidden:
       
  1109             {
       
  1110             EnableAudio( EFalse );
       
  1111             }
       
  1112             break;
       
  1113 
       
  1114         case ERadioAudioRouteHeadset:
       
  1115             {
       
  1116             HandleAudioRoutingEvent( RadioEngine::ERadioHeadset );
       
  1117             }
       
  1118             break;
       
  1119 
       
  1120         case ERadioAudioRouteSpeaker:
       
  1121             {
       
  1122             HandleAudioRoutingEvent( RadioEngine::ERadioSpeaker );
       
  1123             }
       
  1124             break;
       
  1125 
       
  1126         case ERadioCallActivated:
       
  1127             {
       
  1128             CancelSeek();
       
  1129             }
       
  1130             break;
       
  1131 
       
  1132         case ERadioCallDeactivated:
       
  1133             {
       
  1134             iPlayerUtility->Play();
       
  1135             SwitchPower( ETrue );
       
  1136             }
       
  1137             break;
       
  1138 
       
  1139         case ERadioHeadsetConnected:
       
  1140             {
       
  1141             // Explicitly set the audio routing to headset. Because system
       
  1142             // forces the routing to headset anyway, and without our knowledge.
       
  1143             MRadioSettingsSetter& setter = iSettings->RadioSetter();
       
  1144             setter.SetAudioRoute( RadioEngine::ERadioHeadset );
       
  1145             iAudioRouter->SetAudioRouteL( RadioEngine::ERadioHeadset );
       
  1146             }
       
  1147             break;
       
  1148 
       
  1149         case ERadioHeadsetDisconnected:
       
  1150             {
       
  1151             // Explicitly set the audio routing to speaker. Because system
       
  1152             // forces the routing to speaker anyway, if radio stays on.
       
  1153             MRadioSettingsSetter& setter = iSettings->RadioSetter();
       
  1154             setter.SetAudioRoute( RadioEngine::ERadioSpeaker );
       
  1155             iAudioRouter->SetAudioRouteL( RadioEngine::ERadioSpeaker );
       
  1156             }
       
  1157             break;
       
  1158         default:
       
  1159             {
       
  1160             break;
       
  1161             }
       
  1162         }
       
  1163     }
       
  1164 
       
  1165 // ---------------------------------------------------------------------------
       
  1166 //
       
  1167 // ---------------------------------------------------------------------------
       
  1168 //
       
  1169 void CRadioEngineImp::MrftoRequestTunerControlComplete( TInt aError )
       
  1170     {
       
  1171     LOG_METHOD_AUTO;
       
  1172     LOG_FORMAT( "aError: %d", aError );
       
  1173 
       
  1174     if ( aError == KErrNone || aError == KErrAlreadyExists ) // Tuner activated now or was already active
       
  1175         {
       
  1176         iRadioInitializationState = ERadioTunerControlGranted;
       
  1177 
       
  1178         TFmTunerCapabilities tunerCaps;
       
  1179         tunerCaps.iTunerBands = 0;
       
  1180         tunerCaps.iTunerFunctions = 0;
       
  1181         tunerCaps.iAdditionalFunctions1 = 0;
       
  1182         tunerCaps.iAdditionalFunctions2 = 0;
       
  1183         iTunerUtility->GetCapabilities( tunerCaps );
       
  1184 
       
  1185 #ifdef LOGGING_ENABLED
       
  1186         TBuf<50> tunerCapsBuf;
       
  1187         if ( tunerCaps.ETunerAvailableInOfflineMode )
       
  1188             {
       
  1189             tunerCapsBuf.Append( _L("OfflineMode ") );
       
  1190             }
       
  1191         if ( tunerCaps.ETunerRdsSupport )
       
  1192             {
       
  1193             tunerCapsBuf.Append( _L("RDS ") );
       
  1194             }
       
  1195         if ( tunerCaps.ETunerDualTunerSupport )
       
  1196             {
       
  1197             tunerCapsBuf.Append( _L("DualTuner ") );
       
  1198             }
       
  1199         LOG_FORMAT( "Radio tuner capabilities: %S", &tunerCapsBuf );
       
  1200 
       
  1201 #endif // LOGGING_ENABLED
       
  1202 
       
  1203         TBool offlineAvailable( tunerCaps.iTunerFunctions &
       
  1204                                 TFmTunerCapabilities::ETunerAvailableInOfflineMode );
       
  1205         iTunerUtility->EnableTunerInOfflineMode( offlineAvailable );
       
  1206 
       
  1207         if ( tunerCaps.iTunerFunctions & TFmTunerCapabilities::ETunerRdsSupport )
       
  1208             {
       
  1209             TRAP_IGNORE( iRdsReceiver->InitL( *iRadioUtility ) )
       
  1210             }
       
  1211 
       
  1212         iTunerUtility->SetFrequencyRange( TunerFrequencyRangeForRegionId(
       
  1213                                           iSettings->EngineSettings().RegionId() ) );
       
  1214         // To prevent false frequency changes
       
  1215         iTunerUtility->SetFrequency( iSettings->EngineSettings().TunedFrequency() );
       
  1216         SwitchPower( ETrue );
       
  1217         }
       
  1218     }
       
  1219 
       
  1220 // ---------------------------------------------------------------------------
       
  1221 //
       
  1222 // ---------------------------------------------------------------------------
       
  1223 //
       
  1224 void CRadioEngineImp::MrftoSetFrequencyRangeComplete( TInt aError )
       
  1225     {
       
  1226     LEVEL3( LOG_METHOD_AUTO );
       
  1227     LEVEL3( LOG_FORMAT( "aError: %d", aError ) );
       
  1228     if ( aError )
       
  1229         {
       
  1230         NotifyRadioEvent( ERadioEventRegion, aError );
       
  1231         }
       
  1232     }
       
  1233 
       
  1234 // ---------------------------------------------------------------------------
       
  1235 //
       
  1236 // ---------------------------------------------------------------------------
       
  1237 //
       
  1238 void CRadioEngineImp::MrftoSetFrequencyComplete( TInt aError )
       
  1239     {
       
  1240     LOG_METHOD_AUTO;
       
  1241     LOG_FORMAT( "aError: %d", aError );
       
  1242 
       
  1243     if ( aError && !iManualSeekMode )
       
  1244         {
       
  1245         if ( aError == KErrNotReady )
       
  1246             {
       
  1247             iRadioInitializationState = ERadioUtilitiesConstructed;
       
  1248             }
       
  1249         HandleFrequencyEvent( iSettings->EngineSettings().TunedFrequency(), aError );
       
  1250         }
       
  1251     }
       
  1252 
       
  1253 // ---------------------------------------------------------------------------
       
  1254 //
       
  1255 // ---------------------------------------------------------------------------
       
  1256 //
       
  1257 void CRadioEngineImp::MrftoStationSeekComplete( TInt aError, TInt aFrequency )
       
  1258     {
       
  1259     LOG_METHOD_AUTO;
       
  1260     LOG_FORMAT( "aError = %d, aFrequency = %d", aError, aFrequency );
       
  1261     // Seeking has ended, error code tells if it was successful
       
  1262 
       
  1263     if ( aError == KFmRadioErrAntennaNotConnected )
       
  1264         {
       
  1265         iAntennaAttached = EFalse;
       
  1266         }
       
  1267     else if ( aError == KErrNotReady )
       
  1268         {
       
  1269         iRadioInitializationState = ERadioUtilitiesConstructed;
       
  1270         }
       
  1271 
       
  1272     iSeekingState = RadioEngine::ERadioNotSeeking;
       
  1273 
       
  1274     if ( aFrequency == 0 )
       
  1275         {
       
  1276         NotifyRadioEvent( ERadioEventFrequency, aError );
       
  1277         }
       
  1278     }
       
  1279 
       
  1280 // ---------------------------------------------------------------------------
       
  1281 //
       
  1282 // ---------------------------------------------------------------------------
       
  1283 //
       
  1284 void CRadioEngineImp::MrftoFmTransmitterStatusChange( TBool aActive )
       
  1285     {
       
  1286     LOG_METHOD_AUTO;
       
  1287     LOG_FORMAT( "aActive: %d", aActive );
       
  1288     iFmTransmitterActive = aActive;
       
  1289 
       
  1290     if ( !iFmTransmitterActive )
       
  1291         {
       
  1292         SwitchPower( ETrue );
       
  1293         }
       
  1294 
       
  1295     NotifyRadioEvent( ERadioEventFmTransmitter );
       
  1296     }
       
  1297 
       
  1298 // ---------------------------------------------------------------------------
       
  1299 //
       
  1300 // ---------------------------------------------------------------------------
       
  1301 //
       
  1302 void CRadioEngineImp::MrftoAntennaStatusChange( TBool aAttached )
       
  1303     {
       
  1304     LOG_METHOD_AUTO;
       
  1305     LOG_FORMAT( "aAttached: %d", aAttached );
       
  1306     iAntennaAttached = aAttached;
       
  1307     if ( iAntennaAttached )
       
  1308         {
       
  1309         SwitchPower( ETrue );
       
  1310         NotifyRadioEvent( ERadioEventAntenna );
       
  1311         }
       
  1312     else
       
  1313         {
       
  1314         NotifyRadioEvent( ERadioEventAntenna, KErrDisconnected );
       
  1315         }
       
  1316     }
       
  1317 
       
  1318 // ---------------------------------------------------------------------------
       
  1319 //
       
  1320 // ---------------------------------------------------------------------------
       
  1321 
       
  1322 //
       
  1323 void CRadioEngineImp::MrftoOfflineModeStatusChange( TBool DEBUGVAR3( aOfflineMode ) )
       
  1324     {
       
  1325     LEVEL3( LOG_METHOD_AUTO );
       
  1326     LEVEL3( LOG_FORMAT( "aOfflineMode: %d", aOfflineMode ) );
       
  1327     }
       
  1328 
       
  1329 // ---------------------------------------------------------------------------
       
  1330 //
       
  1331 // ---------------------------------------------------------------------------
       
  1332 //
       
  1333 void CRadioEngineImp::MrftoFrequencyRangeChange( TFmRadioFrequencyRange DEBUGVAR3( aBand ) )
       
  1334     {
       
  1335     LEVEL3( LOG_METHOD_AUTO );
       
  1336     LEVEL3( LOG_FORMAT( "aBand: %d", aBand ) );
       
  1337     if ( RadioInitialized() )
       
  1338         {
       
  1339         iTunerUtility->SetFrequency( iSettings->EngineSettings().TunedFrequency() );
       
  1340         iFreqEventReason = RadioEngine::ERadioFrequencyEventReasonImplicit;
       
  1341         }
       
  1342     NotifyRadioEvent( ERadioEventRegion );
       
  1343     }
       
  1344 
       
  1345 // ---------------------------------------------------------------------------
       
  1346 //
       
  1347 // ---------------------------------------------------------------------------
       
  1348 //
       
  1349 void CRadioEngineImp::MrftoFrequencyChange( TInt aNewFrequency )
       
  1350     {
       
  1351     LEVEL3( LOG_METHOD_AUTO );
       
  1352     LEVEL3( LOG_FORMAT( "aNewFrequency = %u", aNewFrequency ) );
       
  1353 
       
  1354     // There may be frequency changed events when radio is not initialized ( because
       
  1355     // of SetFrequency or Seek returns with KErrNotReady ).
       
  1356     if ( !iManualSeekMode && RadioInitialized() )
       
  1357         {
       
  1358         HandleFrequencyEvent( aNewFrequency );
       
  1359         }
       
  1360     }
       
  1361 
       
  1362 // ---------------------------------------------------------------------------
       
  1363 //
       
  1364 // ---------------------------------------------------------------------------
       
  1365 //
       
  1366 void CRadioEngineImp::MrftoForcedMonoChange( TBool aForcedMono )
       
  1367     {
       
  1368     LEVEL3( LOG_METHOD_AUTO );
       
  1369     LEVEL3( LOG_FORMAT( "aForcedMono = %d", aForcedMono ) );
       
  1370 
       
  1371     iSettings->RadioSetter().SetOutputMode( aForcedMono ? RadioEngine::ERadioMono : RadioEngine::ERadioStereo );
       
  1372     NotifyRadioEvent( ERadioEventAudioMode );
       
  1373     }
       
  1374 
       
  1375 // ---------------------------------------------------------------------------
       
  1376 //
       
  1377 // ---------------------------------------------------------------------------
       
  1378 //
       
  1379 void CRadioEngineImp::MrftoSquelchChange( TBool /*aSquelch*/ )
       
  1380     {
       
  1381     LEVEL3( LOG_METHOD_AUTO );
       
  1382     }
       
  1383 
       
  1384 // ---------------------------------------------------------------------------
       
  1385 //
       
  1386 // ---------------------------------------------------------------------------
       
  1387 //
       
  1388 void CRadioEngineImp::MrpoStateChange( TPlayerState aState, TInt aError )
       
  1389     {
       
  1390     LEVEL3( LOG_METHOD_AUTO );
       
  1391     LEVEL3( LOG_FORMAT( "aState = %d, aError = %d", aState, aError ) );
       
  1392 
       
  1393     if ( aError == KFmRadioErrAntennaNotConnected )
       
  1394         {
       
  1395         iAntennaAttached = EFalse;
       
  1396         }
       
  1397     HandlePowerEvent( aState == ERadioPlayerPlaying, aError );
       
  1398     }
       
  1399 
       
  1400 // ---------------------------------------------------------------------------
       
  1401 //
       
  1402 // ---------------------------------------------------------------------------
       
  1403 //
       
  1404 void CRadioEngineImp::MrpoVolumeChange( TInt aVolume )
       
  1405     {
       
  1406     LEVEL3( LOG_METHOD_AUTO );
       
  1407 	aVolume = aVolume / KRadioVolumeStepsDivider;
       
  1408     if ( aVolume != iSettings->EngineSettings().Volume() )
       
  1409         {
       
  1410         iSettings->RadioSetter().SetVolume( aVolume );
       
  1411         NotifyRadioEvent( ERadioEventVolume );
       
  1412         }
       
  1413     }
       
  1414 
       
  1415 // ---------------------------------------------------------------------------
       
  1416 //
       
  1417 // ---------------------------------------------------------------------------
       
  1418 //
       
  1419 void CRadioEngineImp::MrpoMuteChange( TBool aMute )
       
  1420     {
       
  1421     LEVEL3( LOG_METHOD_AUTO );
       
  1422     LOG_FORMAT( "CRadioEngineImp::MrpoMuteChange muted: %d", aMute );
       
  1423 
       
  1424 //    TBool muted = iSettings->EngineSettings().IsVolMuted();
       
  1425 //    if ( !aMute != !muted )
       
  1426 //        {
       
  1427 //        iSettings->RadioSetter().SetVolMuted( aMute );
       
  1428 //        NotifyRadioEvent( ERadioEventMute );
       
  1429 //        }
       
  1430     }
       
  1431 
       
  1432 // ---------------------------------------------------------------------------
       
  1433 //
       
  1434 // ---------------------------------------------------------------------------
       
  1435 //
       
  1436 void CRadioEngineImp::MrpoBalanceChange( TInt /*aLeftPercentage*/, TInt /*aRightPercentage*/ )
       
  1437     {
       
  1438     LEVEL3( LOG_METHOD_AUTO );
       
  1439     }
       
  1440 
       
  1441 // ---------------------------------------------------------------------------
       
  1442 //
       
  1443 // ---------------------------------------------------------------------------
       
  1444 //
       
  1445 void CRadioEngineImp::RdsAfSearchSettingChangedL( TBool aEnabled )
       
  1446     {
       
  1447     LEVEL3( LOG_METHOD_AUTO );
       
  1448     LEVEL3( LOG_FORMAT( "aEnabled: %d", aEnabled ) );
       
  1449     iRdsReceiver->SetAutomaticSwitchingL( aEnabled );
       
  1450     }
       
  1451 
       
  1452 // ---------------------------------------------------------------------------
       
  1453 //
       
  1454 // ---------------------------------------------------------------------------
       
  1455 //
       
  1456 //TODO: Check if this can be removed. Radio doesn't currently support changing regions on the fly
       
  1457 void CRadioEngineImp::RegionSettingChangedL( TInt DEBUGVAR3( aRegion ) )
       
  1458     {
       
  1459     LEVEL3( LOG_METHOD_AUTO );
       
  1460     LEVEL3( LOG_FORMAT( "aRegion: %d", aRegion ) );
       
  1461 
       
  1462     if ( RadioInitialized() )
       
  1463         {
       
  1464         iTunerUtility->SetFrequencyRange( TunerFrequencyRangeForRegionId( iSettings->EngineSettings().RegionId() ) );
       
  1465         iTunerUtility->SetFrequency( iSettings->EngineSettings().TunedFrequency() );
       
  1466         iFreqEventReason = RadioEngine::ERadioFrequencyEventReasonImplicit;
       
  1467         }
       
  1468     }
       
  1469 
       
  1470 // ---------------------------------------------------------------------------
       
  1471 //
       
  1472 // ---------------------------------------------------------------------------
       
  1473 //
       
  1474 void CRadioEngineImp::RdsAfSearchBegin()
       
  1475     {
       
  1476     LEVEL3( LOG_METHOD_AUTO );
       
  1477     iFrequencySetByRdsAf = ETrue;
       
  1478     }
       
  1479 
       
  1480 // ---------------------------------------------------------------------------
       
  1481 //
       
  1482 // ---------------------------------------------------------------------------
       
  1483 //
       
  1484 void CRadioEngineImp::RdsAfSearchEnd( TUint32 DEBUGVAR3( aFrequency ), TInt aError )
       
  1485     {
       
  1486     LEVEL3( LOG_METHOD_AUTO );
       
  1487     LEVEL3( LOG_FORMAT( "aFrequency: %d, aError: %d )", aFrequency, aError ) );
       
  1488     if ( aError != KErrNone )
       
  1489         {
       
  1490         iFrequencySetByRdsAf = EFalse;
       
  1491         }
       
  1492     }
       
  1493 
       
  1494 // ---------------------------------------------------------------------------
       
  1495 // Tries to figure the region out based on current mobile network id
       
  1496 // ---------------------------------------------------------------------------
       
  1497 //
       
  1498 TRadioRegion CRadioEngineImp::RegionFromMobileNetwork() const
       
  1499     {
       
  1500     LEVEL3( LOG_METHOD_AUTO );
       
  1501     TRadioRegion region = ERadioRegionNone;
       
  1502 
       
  1503     // Choose the frequency range according to country code
       
  1504     MRadioEngineSettings& engineSettings = iSettings->EngineSettings();
       
  1505     TPtrC countryCode = engineSettings.CountryCode();
       
  1506     const TInt regionCount = engineSettings.CountRegions();
       
  1507     TBool matchFound = EFalse;
       
  1508     for ( TInt i = 0; i < regionCount && !matchFound; ++i )
       
  1509         {
       
  1510         const RRadioCountryCodeArray& regionCountryCodes =
       
  1511                 engineSettings.Region( i ).CountryCodes();
       
  1512 
       
  1513         const TInt countryCodeCount = regionCountryCodes.Count();
       
  1514         for ( TInt j = 0; j < countryCodeCount && !matchFound; ++j )
       
  1515             {
       
  1516             if ( countryCode == *regionCountryCodes[j] )
       
  1517                 {
       
  1518                 // We have a match
       
  1519                 matchFound = ETrue;
       
  1520                 region = engineSettings.Region( i ).Id();
       
  1521                 }
       
  1522             }
       
  1523         }
       
  1524 
       
  1525     return region;
       
  1526     }
       
  1527 
       
  1528 // ---------------------------------------------------------------------------
       
  1529 // Tries to figure the region out based on timezone selection
       
  1530 // ---------------------------------------------------------------------------
       
  1531 //
       
  1532 TRadioRegion CRadioEngineImp::RegionFromTimezone() const
       
  1533     {
       
  1534     LEVEL3( LOG_METHOD_AUTO );
       
  1535     TRadioRegion region = ERadioRegionNone;
       
  1536     TRAP_IGNORE( region = DoRegionFromTimezoneL() );
       
  1537     return region;
       
  1538     }
       
  1539 
       
  1540 // ---------------------------------------------------------------------------
       
  1541 // Performs the timezone-based check
       
  1542 // ---------------------------------------------------------------------------
       
  1543 //
       
  1544 TRadioRegion CRadioEngineImp::DoRegionFromTimezoneL() const
       
  1545     {
       
  1546     LOG_METHOD_AUTO;
       
  1547     CTzLocalizer* timezoneLocalizer = CTzLocalizer::NewL();
       
  1548     CleanupStack::PushL( timezoneLocalizer );
       
  1549 
       
  1550     CTzLocalizedCityGroupArray* cityGroups = timezoneLocalizer->GetAllCityGroupsL(
       
  1551                                             CTzLocalizer::ETzAlphaNameAscending );
       
  1552     CleanupStack::PushL( cityGroups );
       
  1553 
       
  1554     // We get the ownership so we must delete
       
  1555     CTzLocalizedCity* city = timezoneLocalizer->GetFrequentlyUsedZoneCityL( CTzLocalizedTimeZone::ECurrentZone );
       
  1556     const TUint8 cityId = city->GroupId();
       
  1557     delete city;
       
  1558     city = NULL;
       
  1559     LOG_FORMAT( "group id: %d", cityId );
       
  1560 
       
  1561     TRadioRegion region = ERadioRegionNone;
       
  1562     const TInt cityGroupCount = cityGroups->Count();
       
  1563     TBool found = EFalse;
       
  1564     for ( TInt i = 0; i < cityGroupCount && !found; ++i )
       
  1565         {
       
  1566         if ( cityId == cityGroups->At( i ).Id() )
       
  1567             {
       
  1568             region = static_cast<TRadioRegion>( KCityGroupRegions[ cityId - 1 ] );
       
  1569             found = ETrue;
       
  1570             }
       
  1571         }
       
  1572 
       
  1573     CleanupStack::PopAndDestroy( cityGroups );
       
  1574     CleanupStack::PopAndDestroy( timezoneLocalizer );
       
  1575 
       
  1576     LOG_ASSERT( found, LOG_FORMAT( "City not found: %d", cityId ) );
       
  1577 
       
  1578     return region;
       
  1579     }
       
  1580 
       
  1581 // ---------------------------------------------------------------------------
       
  1582 //
       
  1583 // ---------------------------------------------------------------------------
       
  1584 //
       
  1585 void CRadioEngineImp::HandleAudioRoutingEvent( RadioEngine::TRadioAudioRoute aDestination )
       
  1586     {
       
  1587     LOG_METHOD_AUTO;
       
  1588     LOG_FORMAT( "aDestination: %d", aDestination );
       
  1589 
       
  1590     // Make modifications to volume ONLY if new audio source state
       
  1591     // differs from settings. If they don't differ, this state
       
  1592     // change is a part of the radio initialization.
       
  1593     MRadioSettingsSetter& setter = iSettings->RadioSetter();
       
  1594     if ( aDestination != iSettings->EngineSettings().AudioRoute() )
       
  1595         {
       
  1596         setter.SetAudioRoute( aDestination );
       
  1597 
       
  1598         // If audio muted, change it to minimum volume
       
  1599         MRadioEngineSettings& engineSettings = iSettings->EngineSettings();
       
  1600         TInt vol = engineSettings.IsVolMuted() ? engineSettings.DefaultMinVolumeLevel()
       
  1601                                                : engineSettings.Volume();
       
  1602 
       
  1603         if ( RadioInitialized() )
       
  1604             {
       
  1605             TInt err = iPlayerUtility->Mute( EFalse );
       
  1606             if ( !err )
       
  1607                 {
       
  1608                 setter.SetVolMuted( EFalse );
       
  1609                 err = iPlayerUtility->SetVolume( TunerVolumeForUiVolume( vol ));
       
  1610 
       
  1611                 if ( !err )
       
  1612                     {
       
  1613                     setter.SetVolume( vol );
       
  1614                     }
       
  1615                 }
       
  1616             }
       
  1617         else
       
  1618             {
       
  1619             setter.SetVolMuted( EFalse );
       
  1620             setter.SetVolume( vol );
       
  1621             }
       
  1622         NotifyRadioEvent( ERadioEventAudioRouting );
       
  1623         }
       
  1624     }
       
  1625 
       
  1626 // ---------------------------------------------------------------------------
       
  1627 //
       
  1628 // ---------------------------------------------------------------------------
       
  1629 //
       
  1630 void CRadioEngineImp::HandlePowerEvent( TBool aPowerOn, TInt aErrorCode )
       
  1631     {
       
  1632     LOG_METHOD_AUTO;
       
  1633     LOG_FORMAT( "aPowerOn: %d, aErrorCode: %d )", aPowerOn, aErrorCode );
       
  1634 
       
  1635     const TBool powerState = iSettings->EngineSettings().IsPowerOn();
       
  1636     if ( !powerState != !aPowerOn )
       
  1637         {
       
  1638         iSettings->RadioSetter().SetPowerOn( aPowerOn );
       
  1639 
       
  1640         if ( aPowerOn )
       
  1641             {
       
  1642             iRdsReceiver->StartReceiver();
       
  1643             }
       
  1644         else
       
  1645             {
       
  1646             iRdsReceiver->StopReceiver();
       
  1647             }
       
  1648         }
       
  1649 
       
  1650     if ( !aPowerOn )
       
  1651         {
       
  1652         CancelSeek();
       
  1653         }
       
  1654 
       
  1655     // If we are seeking, power event starts seeking
       
  1656     if ( iSeekingState != RadioEngine::ERadioNotSeeking && aPowerOn )
       
  1657         {
       
  1658         // Reset seeking state to enable seeking start
       
  1659         LOG( "PowerOn event in seekingstate. Restart seeking" );
       
  1660         RadioEngine::TRadioSeeking oldSeeking = iSeekingState;
       
  1661         iSeekingState = RadioEngine::ERadioNotSeeking;
       
  1662         Seek( oldSeeking == RadioEngine::ERadioSeekingUp ? RadioEngine::ERadioUp : RadioEngine::ERadioDown );
       
  1663         }
       
  1664 
       
  1665     if ( !powerState != !aPowerOn || aErrorCode )
       
  1666         {
       
  1667         NotifyRadioEvent( ERadioEventPower, aErrorCode );
       
  1668         }
       
  1669     }
       
  1670 
       
  1671 // ---------------------------------------------------------------------------
       
  1672 //
       
  1673 // ---------------------------------------------------------------------------
       
  1674 //
       
  1675 void CRadioEngineImp::HandleFrequencyEvent( TUint32 aFrequency, TInt aErrorCode )
       
  1676     {
       
  1677     LOG_METHOD_AUTO;
       
  1678     LOG_FORMAT( "aFrequency:  %d, aErrorCode: %d )", aFrequency, aErrorCode );
       
  1679 
       
  1680     if ( iSettings->EngineSettings().TunedFrequency() != aFrequency )
       
  1681         {
       
  1682         if ( iSettings->EngineSettings().IsPowerOn() )
       
  1683             {
       
  1684             if ( !OkToPlay( aFrequency ) )
       
  1685                 {
       
  1686                 // Radio is going to be powered off, stop rds receiver immediately because
       
  1687                 // some rds data from previous channel might come before power off event.
       
  1688                 iRdsReceiver->StopReceiver();
       
  1689                 }
       
  1690             else
       
  1691                 {
       
  1692                 // Normal frequency change, make sure that rds receiver is started
       
  1693                 iRdsReceiver->StartReceiver();
       
  1694                 }
       
  1695             }
       
  1696         if ( !iFrequencySetByRdsAf )
       
  1697             {
       
  1698             iRdsReceiver->ClearRdsInformation();
       
  1699             }
       
  1700         }
       
  1701     else if ( iFrequencySetByRdsAf )
       
  1702         {
       
  1703         // frequency didn't change, so AF search didn't complete successfully
       
  1704         iFrequencySetByRdsAf = EFalse;
       
  1705         }
       
  1706 
       
  1707     iSettings->RadioSetter().SetTunedFrequency( aFrequency );
       
  1708 
       
  1709     NotifyRadioEvent( ERadioEventFrequency, aErrorCode );
       
  1710     iFreqEventReason = RadioEngine::ERadioFrequencyEventReasonUnknown;
       
  1711 
       
  1712     if ( aErrorCode == KErrNone )
       
  1713         {
       
  1714         SwitchPower( iRadioEnabled && OkToPlay( aFrequency ) );
       
  1715         }
       
  1716     }
       
  1717 
       
  1718 // ---------------------------------------------------------------------------
       
  1719 // Routing is not possible when headset is not available, power is off or
       
  1720 // audio routing is not supported.
       
  1721 // ---------------------------------------------------------------------------
       
  1722 //
       
  1723 TBool CRadioEngineImp::IsAudioRoutingPossible() const
       
  1724     {
       
  1725     LEVEL3( LOG_METHOD_AUTO );
       
  1726     TBool headsetConnected = EFalse;
       
  1727     TRAP_IGNORE( ( headsetConnected = iSystemEventCollector->IsHeadsetConnectedL() ) )
       
  1728 
       
  1729     TBool powerOn = iSettings->EngineSettings().IsPowerOn();
       
  1730 
       
  1731     TBool isAudioRoutingPossible = EFalse;
       
  1732     if ( headsetConnected && powerOn && AudioRoutingSupported() )
       
  1733         {
       
  1734         isAudioRoutingPossible = ETrue;
       
  1735         }
       
  1736 
       
  1737     return isAudioRoutingPossible;
       
  1738     }
       
  1739