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