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 |
#ifndef CRADIOENGINEIMP_H
|
|
18 |
#define CRADIOENGINEIMP_H
|
|
19 |
|
|
20 |
// System includes
|
|
21 |
#include <RadioFmTunerUtility.h>
|
|
22 |
#include <RadioPlayerUtility.h>
|
|
23 |
#include <RadioUtility.h>
|
|
24 |
|
|
25 |
// User includes
|
|
26 |
#include "cradioengine.h"
|
|
27 |
#include "mradiosettingsobserver.h"
|
|
28 |
#include "mradiordsdataobserver.h"
|
|
29 |
#include "mradiosystemeventobserver.h"
|
|
30 |
#include "radioenginedef.h"
|
|
31 |
|
|
32 |
// Forward declarations
|
|
33 |
class CRadioPubSub;
|
|
34 |
class CRadioRdsReceiverBase;
|
|
35 |
class CRadioNetworkInfoListener;
|
|
36 |
class MRadioEngineSettings;
|
|
37 |
class MRadioSettingsSetter;
|
|
38 |
class MRadioEngineObserver;
|
|
39 |
class MRadioScanObserver;
|
|
40 |
|
|
41 |
/**
|
|
42 |
* Radio class takes care of the FM-radio side.
|
|
43 |
*/
|
|
44 |
NONSHARABLE_CLASS( CRadioEngineImp ) : public CRadioEngine
|
|
45 |
, public MRadioSystemEventObserver
|
|
46 |
, public MRadioFmTunerObserver
|
|
47 |
, public MRadioPlayerObserver
|
|
48 |
, public MRadioSettingsObserver
|
|
49 |
, public MRadioRdsDataObserver
|
|
50 |
{
|
|
51 |
friend class CRadioEngine;
|
|
52 |
|
|
53 |
public:
|
|
54 |
|
|
55 |
~CRadioEngineImp();
|
|
56 |
|
|
57 |
void SetSystemEventCollector( CRadioSystemEventCollector* aCollector );
|
|
58 |
void SetRadioSettings( CRadioSettings* aSettings );
|
|
59 |
void SetRadioPubSub( CRadioPubSub* aPubSub );
|
|
60 |
|
|
61 |
private:
|
|
62 |
|
|
63 |
CRadioEngineImp( CRadioAudioRouter* aAudioRouter );
|
|
64 |
|
|
65 |
// from base class CRadioEngine
|
|
66 |
|
|
67 |
CRadioAudioRouter& AudioRouter() const;
|
|
68 |
CRadioSystemEventCollector& SystemEventCollector() const;
|
|
69 |
CRadioSettings& Settings() const;
|
|
70 |
CRadioPubSub* PubSub() const;
|
|
71 |
TRadioRegion DetermineRegion();
|
|
72 |
void InitRadioL( TInt aRegionId, CRadioPubSub* aPubSub = 0 );
|
|
73 |
TBool RadioInitialized() const;
|
|
74 |
void EnableAudio( TBool aEnable, TBool aDelay = ETrue );
|
|
75 |
TBool RadioAudioEnabled() const;
|
|
76 |
void SetAudioOverride( TBool aOverride );
|
|
77 |
void AddObserverL( MRadioEngineObserver* aObserver );
|
|
78 |
void RemoveObserver( MRadioEngineObserver* aObserver );
|
|
79 |
void SetAudioMode( TInt aAudioMode );
|
|
80 |
TBool IsFrequencyValid( TUint32 aFrequency = 0 ) const;
|
|
81 |
void SetFrequency( TUint32 aFrequency,
|
|
82 |
RadioEngine::TRadioFrequencyEventReason aReason = RadioEngine::ERadioFrequencyEventReasonUnknown );
|
|
83 |
void SetFrequencyFast( TUint32 aFrequency,
|
|
84 |
RadioEngine::TRadioFrequencyEventReason aReason = RadioEngine::ERadioFrequencyEventReasonUnknown );
|
|
85 |
void StepToFrequency( RadioEngine::TRadioTuneDirection aDirection );
|
|
86 |
void Seek( RadioEngine::TRadioTuneDirection aDirection );
|
|
87 |
void CancelSeek();
|
|
88 |
RadioEngine::TRadioSeeking Seeking() const;
|
|
89 |
void StartScan( MRadioScanObserver& aObserver );
|
|
90 |
void StopScan( TInt aError = KErrCancel );
|
|
91 |
void AdjustVolume( RadioEngine::TRadioVolumeSetDirection aDirection );
|
|
92 |
void SetVolume( TInt aVolume );
|
|
93 |
void SetVolumeMuted( TBool aMute );
|
|
94 |
TBool IsAntennaAttached();
|
|
95 |
TBool IsFmTransmitterActive() const;
|
|
96 |
void SetAntennaAttached( TBool aAntennaAttached );
|
|
97 |
TInt MaxVolumeLevel() const;
|
|
98 |
TBool FrequencySetByRdsAf() const;
|
|
99 |
MRadioRdsReceiver& RdsReceiver();
|
|
100 |
TBool IsAudioRoutingPossible() const;
|
|
101 |
TBool OkToPlay( TUint32 aFrequency ) const;
|
|
102 |
|
|
103 |
private:
|
|
104 |
|
|
105 |
/** Radio event notifications */
|
|
106 |
enum TRadioEventNotification
|
|
107 |
{
|
|
108 |
ERadioEventPower = 1,
|
|
109 |
ERadioEventFrequency,
|
|
110 |
ERadioEventVolume,
|
|
111 |
ERadioEventMute,
|
|
112 |
ERadioEventAudioMode,
|
|
113 |
ERadioEventAntenna,
|
|
114 |
ERadioEventAudioRouting,
|
|
115 |
ERadioEventSeeking,
|
|
116 |
ERadioEventRegion,
|
|
117 |
ERadioEventFmTransmitter
|
|
118 |
};
|
|
119 |
|
|
120 |
/**
|
|
121 |
* Possible radio scan events.
|
|
122 |
*/
|
|
123 |
enum TRadioScanEvent
|
|
124 |
{
|
|
125 |
/**
|
|
126 |
* Scanning found a valid frequency.
|
|
127 |
*/
|
|
128 |
ERadioEventFrequencyScanned,
|
|
129 |
|
|
130 |
/**
|
|
131 |
* Scanning is completed.
|
|
132 |
*/
|
|
133 |
ERadioEventScanCompleted
|
|
134 |
|
|
135 |
};
|
|
136 |
|
|
137 |
enum TRadioInitialisationState
|
|
138 |
{
|
|
139 |
ERadioNotInitialized,
|
|
140 |
ERadioUtilitiesConstructed,
|
|
141 |
ERadioTunerControlGranted
|
|
142 |
};
|
|
143 |
|
|
144 |
void ConstructL();
|
|
145 |
|
|
146 |
/**
|
|
147 |
* Switches power on/off after a delay
|
|
148 |
*
|
|
149 |
* @param aPowerOn ETrue if power is to be switched on,
|
|
150 |
* EFalse if power is to be switched off
|
|
151 |
*/
|
|
152 |
void SwitchPower( TBool aPowerOn );
|
|
153 |
|
|
154 |
/**
|
|
155 |
* Callback for switching the radio power on
|
|
156 |
*
|
|
157 |
* @param aSelfPtr A pointer to CRadioEngineImp instance
|
|
158 |
* @return KErrNone
|
|
159 |
*/
|
|
160 |
static TInt StaticPowerOnCallback( TAny* aSelfPtr );
|
|
161 |
|
|
162 |
/**
|
|
163 |
* Callback for switching the radio power off
|
|
164 |
*
|
|
165 |
* @param aSelfPtr A pointer to CRadioEngineImp instance
|
|
166 |
* @return KErrNone
|
|
167 |
*/
|
|
168 |
static TInt StaticPowerOffCallback( TAny* aSelfPtr );
|
|
169 |
|
|
170 |
/**
|
|
171 |
* Switches radio power ON.
|
|
172 |
*/
|
|
173 |
void PowerOn();
|
|
174 |
|
|
175 |
/**
|
|
176 |
* Switches radio power OFF.
|
|
177 |
*/
|
|
178 |
void PowerOff();
|
|
179 |
|
|
180 |
/**
|
|
181 |
* Converts region code used internally by Visual Radio
|
|
182 |
* in to a frequency range by tuner ( TFmRadioFrequencyRange )
|
|
183 |
*
|
|
184 |
* @param aRegionId VR region ID
|
|
185 |
* @return Frequency range
|
|
186 |
*/
|
|
187 |
TFmRadioFrequencyRange TunerFrequencyRangeForRegionId( TInt aRegionId ) const;
|
|
188 |
|
|
189 |
/**
|
|
190 |
* Non-leaving version of DoNotifyRadioEventL.
|
|
191 |
* @param aRadioEvent event notification ( identification )
|
|
192 |
* @param aErrorCode error code related to state change
|
|
193 |
*/
|
|
194 |
void NotifyRadioEvent( TInt aRadioEvent, TInt aErrorCode = KErrNone );
|
|
195 |
|
|
196 |
/**
|
|
197 |
* Leaving version of DoNotifyRadioEvent.
|
|
198 |
* @param aRadioEvent event notification ( identification )
|
|
199 |
* @param aErrorCode error code related to state change
|
|
200 |
*/
|
|
201 |
void DoNotifyRadioEventL( TInt aRadioEvent, TInt aErrorCode = KErrNone );
|
|
202 |
|
|
203 |
/**
|
|
204 |
* Notifies the observer of a radio scan event.
|
|
205 |
*
|
|
206 |
* @param aEvent Event to notify.
|
|
207 |
* @param aObserver Scan observer.
|
|
208 |
* @param aError Error code the event completed with.
|
|
209 |
*/
|
|
210 |
void NotifyRadioScanEvent( TRadioScanEvent aEvent, MRadioScanObserver& aObserver,
|
|
211 |
TInt aError = KErrNone );
|
|
212 |
|
|
213 |
/**
|
|
214 |
* Notifies the observer of a radio scan event.
|
|
215 |
*
|
|
216 |
* @param aEvent Event to notify.
|
|
217 |
* @param aObserver Scan observer.
|
|
218 |
* @param aError Error code the event completed with.
|
|
219 |
*/
|
|
220 |
void DoNotifyRadioScanEventL( TRadioScanEvent aEvent, MRadioScanObserver& aObserver,
|
|
221 |
TInt aError );
|
|
222 |
|
|
223 |
/**
|
|
224 |
* Handles the change in audio routing
|
|
225 |
*
|
|
226 |
* @param aDestination The new routing destination
|
|
227 |
*/
|
|
228 |
void HandleAudioRoutingEvent( RadioEngine::TRadioAudioRoute aDestination );
|
|
229 |
|
|
230 |
/**
|
|
231 |
* Handles the change in power state
|
|
232 |
*
|
|
233 |
* @param aPowerOn The power state
|
|
234 |
* @param aErrorCode Error code related to state change
|
|
235 |
*/
|
|
236 |
void HandlePowerEvent( TBool aPowerOn, TInt aErrorCode = KErrNone );
|
|
237 |
|
|
238 |
/**
|
|
239 |
* Handles the change in power state
|
|
240 |
*
|
|
241 |
* @param aFrequency The current frequency
|
|
242 |
* @param aErrorCode Error code related to state change
|
|
243 |
*/
|
|
244 |
void HandleFrequencyEvent( TUint32 aFrequency, TInt aErrorCode = KErrNone );
|
|
245 |
|
|
246 |
/**
|
|
247 |
* Converts the volume used by Visual Radio to volume used by Radio Utility
|
|
248 |
*
|
|
249 |
* @param aUiVolume The Volume used by Visual Radio
|
|
250 |
* @return The volume used by Radio Utility
|
|
251 |
*/
|
|
252 |
TInt TunerVolumeForUiVolume( TInt aUiVolume );
|
|
253 |
|
|
254 |
// from base class MRadioSystemEventObserver
|
|
255 |
|
|
256 |
void HandleSystemEventL( TRadioSystemEventType aEventType );
|
|
257 |
|
|
258 |
// from base class MRadioFmTunerObserver
|
|
259 |
|
|
260 |
void MrftoRequestTunerControlComplete( TInt aError );
|
|
261 |
void MrftoSetFrequencyRangeComplete( TInt aError );
|
|
262 |
void MrftoSetFrequencyComplete( TInt aError );
|
|
263 |
void MrftoStationSeekComplete( TInt aError, TInt aFrequency );
|
|
264 |
void MrftoFmTransmitterStatusChange( TBool aActive );
|
|
265 |
void MrftoAntennaStatusChange( TBool aAttached );
|
|
266 |
void MrftoOfflineModeStatusChange( TBool aOfflineMode );
|
|
267 |
void MrftoFrequencyRangeChange( TFmRadioFrequencyRange aBand );
|
|
268 |
void MrftoFrequencyChange( TInt aNewFrequency );
|
|
269 |
void MrftoForcedMonoChange( TBool aForcedMono );
|
|
270 |
void MrftoSquelchChange( TBool aSquelch );
|
|
271 |
|
|
272 |
// from base class MRadioPlayerObserver
|
|
273 |
|
|
274 |
void MrpoStateChange( TPlayerState aState, TInt aError );
|
|
275 |
void MrpoVolumeChange( TInt aVolume );
|
|
276 |
void MrpoMuteChange( TBool aMute );
|
|
277 |
void MrpoBalanceChange( TInt aLeftPercentage, TInt aRightPercentage );
|
|
278 |
|
|
279 |
// from base class MRadioSettingsObserver
|
|
280 |
|
|
281 |
void RdsAfSearchSettingChangedL( TBool aEnabled );
|
|
282 |
void RegionSettingChangedL( TInt aRegion );
|
|
283 |
|
|
284 |
// from base class MRadioRdsDataObserver
|
|
285 |
|
|
286 |
void RdsAvailable( TUint32 /*aFrequency*/, TBool /*aAvailable*/ ) {}
|
|
287 |
void RdsAfSearchBegin();
|
|
288 |
void RdsAfSearchEnd( TUint32 aFrequency, TInt aError );
|
|
289 |
void RdsAfSearchStateChange( TBool /*aEnabled*/ ) {}
|
|
290 |
void RdsDataProgrammeService( TUint32 /*aFrequency*/, const TDesC& /*aProgramService*/ ) {}
|
|
291 |
void RdsDataRadioText( TUint32 /*aFrequency*/, const TDesC& /*aRadioText*/ ) {}
|
|
292 |
void RdsDataRadioTextPlus( TUint32 /*aFrequency*/, const TInt /*aRadioTextPlusClass*/, const TDesC& /*aRadioText*/ ) {}
|
|
293 |
void RdsDataGenre( TUint32 /*aFrequency*/, const TInt /*aGenre*/ ) {}
|
|
294 |
void RdsDataPiCode( TUint32 /*aFrequency*/, const TInt /*aPiCode*/ ) {}
|
|
295 |
|
|
296 |
// New functions
|
|
297 |
|
|
298 |
/**
|
|
299 |
* Tries to figure the region out based on current mobile network id
|
|
300 |
*/
|
|
301 |
TRadioRegion RegionFromMobileNetwork() const;
|
|
302 |
|
|
303 |
/**
|
|
304 |
* Tries to figure the region out based on timezone selection
|
|
305 |
*/
|
|
306 |
TRadioRegion RegionFromTimezone() const;
|
|
307 |
|
|
308 |
/**
|
|
309 |
* Performs the timezone-based check
|
|
310 |
*/
|
|
311 |
TRadioRegion DoRegionFromTimezoneL() const;
|
|
312 |
|
|
313 |
private: // data
|
|
314 |
|
|
315 |
/**
|
|
316 |
* Array of state change observers.
|
|
317 |
*/
|
|
318 |
RPointerArray<MRadioEngineObserver> iObservers;
|
|
319 |
|
|
320 |
/**
|
|
321 |
* A pointer to system event collector
|
|
322 |
* Own.
|
|
323 |
*/
|
|
324 |
CRadioSystemEventCollector* iSystemEventCollector;
|
|
325 |
|
|
326 |
/**
|
|
327 |
* Radio settings
|
|
328 |
* Own.
|
|
329 |
*/
|
|
330 |
CRadioSettings* iSettings;
|
|
331 |
|
|
332 |
/**
|
|
333 |
* Network info listener
|
|
334 |
* Own.
|
|
335 |
*/
|
|
336 |
CRadioNetworkInfoListener* iNetworkInfoListener;
|
|
337 |
|
|
338 |
/**
|
|
339 |
* Controls the radio hardware
|
|
340 |
*/
|
|
341 |
CRadioUtility* iRadioUtility;
|
|
342 |
|
|
343 |
/**
|
|
344 |
* Controls FM radio tuner. Not owned.
|
|
345 |
*/
|
|
346 |
CRadioFmTunerUtility* iTunerUtility;
|
|
347 |
|
|
348 |
/**
|
|
349 |
* Controls the radio player. Not owned.
|
|
350 |
*/
|
|
351 |
CRadioPlayerUtility* iPlayerUtility;
|
|
352 |
|
|
353 |
/**
|
|
354 |
* Receives and notifies of the RDS data
|
|
355 |
*/
|
|
356 |
CRadioRdsReceiverBase* iRdsReceiver;
|
|
357 |
|
|
358 |
/**
|
|
359 |
* State for radio initialization
|
|
360 |
*/
|
|
361 |
TRadioInitialisationState iRadioInitializationState;
|
|
362 |
|
|
363 |
/**
|
|
364 |
* Radio on/off timer.
|
|
365 |
*/
|
|
366 |
CPeriodic* iRadioTimer;
|
|
367 |
|
|
368 |
/**
|
|
369 |
* If this is true, audio resource availability is ignored on next radio power on
|
|
370 |
*/
|
|
371 |
TBool iOverrideAudioResources;
|
|
372 |
|
|
373 |
/**
|
|
374 |
* Direction of the previous seek request, needed for canceling
|
|
375 |
*/
|
|
376 |
RadioEngine::TRadioSeeking iSeekingState;
|
|
377 |
|
|
378 |
/**
|
|
379 |
* Antenna state.
|
|
380 |
*/
|
|
381 |
TBool iAntennaAttached;
|
|
382 |
|
|
383 |
/**
|
|
384 |
* Radio enabling state
|
|
385 |
*/
|
|
386 |
TBool iRadioEnabled;
|
|
387 |
|
|
388 |
/**
|
|
389 |
* ETrue if frequency was set by RDS AF
|
|
390 |
*/
|
|
391 |
TBool iFrequencySetByRdsAf;
|
|
392 |
|
|
393 |
/**
|
|
394 |
* The state of the fm transmitter
|
|
395 |
*/
|
|
396 |
TBool iFmTransmitterActive;
|
|
397 |
|
|
398 |
/**
|
|
399 |
* Cause for the ongoing frequency change operation.
|
|
400 |
*/
|
|
401 |
RadioEngine::TRadioFrequencyEventReason iFreqEventReason;
|
|
402 |
|
|
403 |
/**
|
|
404 |
* Publish&Subscribe object. Can be NULL.
|
|
405 |
* Owned if set
|
|
406 |
*/
|
|
407 |
CRadioPubSub* iPubSub;
|
|
408 |
|
|
409 |
/**
|
|
410 |
* Radio scan observer. NULL when scanning is not ongoing
|
|
411 |
* Not owned.
|
|
412 |
*/
|
|
413 |
MRadioScanObserver* iScanObserver;
|
|
414 |
|
|
415 |
/**
|
|
416 |
* The previously scanned frequency, or <code>KErrNotFound</code> if none.
|
|
417 |
*/
|
|
418 |
TUint32 iPreviousScannedFrequency;
|
|
419 |
|
|
420 |
/**
|
|
421 |
* The state of mute before scan has been started.
|
|
422 |
*/
|
|
423 |
TBool iPreviousMuteState;
|
|
424 |
|
|
425 |
};
|
|
426 |
|
|
427 |
#endif // CRADIOENGINEIMP_H
|
|
428 |
|