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