|
1 /* |
|
2 * Copyright (c) 2002-2007 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: EikSrv keysound server. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32svr.h> |
|
19 #include <coemain.h> |
|
20 #include <barsread.h> |
|
21 #include <eiksrvui.rsg> |
|
22 #include <s32mem.h> |
|
23 #include "eikkeysoundserver.h" |
|
24 #include <aknanimdllstd.h> |
|
25 #include "AknEikAudioToneObserver.h" |
|
26 #include <avkon.hrh> |
|
27 #include <centralrepository.h> |
|
28 #include <ProfileEngineSDKCRKeys.h> // KProEngActiveKeypadVolume |
|
29 #include <ataudioeventapi.h> |
|
30 #include <e32uid.h> |
|
31 |
|
32 // Declare thread entry point |
|
33 GLDEF_C TInt KeySoundServerThreadStartFunction(TAny* aPtr); |
|
34 |
|
35 _LIT(KKeySoundServerThreadName,"KeySoundServerThread"); |
|
36 _LIT(KKeySoundServerSemaphoreName,"KeySoundServerSemaphore"); |
|
37 _LIT(KKeySoundServerDll,"AtSoundServerClient.dll"); |
|
38 |
|
39 const TInt KKeySoundServerStackSize = 1024*4; // 4K |
|
40 const TInt KAknSoundInfoMapGranularity = 16; |
|
41 const TInt KKeyClickPreference = 0x00140001; |
|
42 const TInt KKeySoundServerBufExpandSize = 1024*1; // 1K |
|
43 const TInt KKeysoundServerDllUid = 0x10281C86; |
|
44 |
|
45 typedef CATAudioEventAPI* (*PFUNC)(MATEventCompleteObserver& aCient); |
|
46 |
|
47 // ======================================= |
|
48 // CAknAnimKeySoundControl implementation. |
|
49 // ======================================= |
|
50 |
|
51 CAknAnimKeySoundControl::CAknAnimKeySoundControl() |
|
52 { |
|
53 } |
|
54 |
|
55 void CAknAnimKeySoundControl::ConstructL(RWindowGroup* aParent) |
|
56 { |
|
57 CreateWindowL(aParent); |
|
58 SetExtent(TPoint(0,0),TSize(0,0)); |
|
59 Window().SetShadowDisabled(ETrue); |
|
60 Window().Activate(); |
|
61 } |
|
62 |
|
63 // ================================ |
|
64 // RAknAnimKeySound implementation. |
|
65 // ================================ |
|
66 |
|
67 RAknAnimKeySound::RAknAnimKeySound(RAnimDll& aAnimDll) |
|
68 :RAnim(aAnimDll) |
|
69 { |
|
70 } |
|
71 |
|
72 void RAknAnimKeySound::ConstructL(RWindowGroup* aParent) |
|
73 { |
|
74 iKeySoundControl = new(ELeave)CAknAnimKeySoundControl(); |
|
75 iKeySoundControl->ConstructL(aParent); |
|
76 RAnim::Construct(*(iKeySoundControl->DrawableWindow()), EAnimKeySound, TPtrC8()); |
|
77 } |
|
78 |
|
79 void RAknAnimKeySound::Close() |
|
80 { |
|
81 delete iKeySoundControl; |
|
82 iKeySoundControl = NULL; |
|
83 } |
|
84 |
|
85 // ================================== |
|
86 // CEikKeySoundServer implementation. |
|
87 // ================================== |
|
88 |
|
89 TInt CEikKeySoundServer::LaunchServer(TThreadId& aThreadId) |
|
90 { |
|
91 // First, check that ther server isn't already running. |
|
92 TFindServer findServer(__KEYSOUND_SERVER_NAME); |
|
93 TFullName name; |
|
94 if (findServer.Next(name) == KErrNone) |
|
95 { |
|
96 return KErrAlreadyExists; |
|
97 } |
|
98 |
|
99 // Create a semaphore. |
|
100 RSemaphore globStartSignal; |
|
101 TInt err = globStartSignal.CreateGlobal(KKeySoundServerSemaphoreName, EOwnerProcess); |
|
102 if (err != KErrNone) |
|
103 { |
|
104 err=globStartSignal.OpenGlobal(KKeySoundServerSemaphoreName, EOwnerProcess); |
|
105 if (err != KErrNone) |
|
106 { |
|
107 return err; |
|
108 } |
|
109 } |
|
110 RThread keySoundServerThread; |
|
111 |
|
112 err = keySoundServerThread.Create( |
|
113 KKeySoundServerThreadName, |
|
114 KeySoundServerThreadStartFunction, |
|
115 KKeySoundServerStackSize, |
|
116 NULL, // uses caller thread's heap |
|
117 NULL, |
|
118 EOwnerThread); |
|
119 |
|
120 aThreadId = keySoundServerThread.Id(); |
|
121 keySoundServerThread.Resume(); |
|
122 keySoundServerThread.Close(); |
|
123 globStartSignal.Wait(); |
|
124 return err; |
|
125 } |
|
126 |
|
127 // Construct the server object |
|
128 LOCAL_C void DoKeySoundServerThreadStartFunctionL() |
|
129 { |
|
130 CEikKeySoundServer::NewLC(); |
|
131 |
|
132 RSemaphore globStartSignal; |
|
133 CleanupClosePushL(globStartSignal); |
|
134 User::LeaveIfError(globStartSignal.OpenGlobal(KKeySoundServerSemaphoreName)); |
|
135 globStartSignal.Signal(); |
|
136 CleanupStack::PopAndDestroy(); // globStartSignal.Close() |
|
137 |
|
138 CActiveScheduler::Start(); |
|
139 CleanupStack::PopAndDestroy(); // keySoundServer |
|
140 } |
|
141 |
|
142 // Entry point into the new thread |
|
143 GLDEF_C TInt KeySoundServerThreadStartFunction(TAny* /*aPtr*/) |
|
144 { |
|
145 __UHEAP_MARK; |
|
146 RThread thread; |
|
147 |
|
148 TInt err = User::RenameThread(KKeySoundServerThreadName); |
|
149 if (err == KErrNone) |
|
150 { |
|
151 thread.SetPriority(EPriorityAbsoluteForeground); |
|
152 thread.Close(); |
|
153 |
|
154 // Set up scheduler and cleanup stack for this thread |
|
155 CActiveScheduler* scheduler = new CActiveScheduler; |
|
156 if (!scheduler) |
|
157 { |
|
158 return KErrNoMemory; |
|
159 } |
|
160 CActiveScheduler::Install(scheduler); |
|
161 CTrapCleanup* trapCleanup = CTrapCleanup::New(); |
|
162 if (!trapCleanup) |
|
163 { |
|
164 return KErrNoMemory; |
|
165 } |
|
166 |
|
167 // Set initial trap harness, and construct server object |
|
168 TRAP(err,DoKeySoundServerThreadStartFunctionL()); |
|
169 |
|
170 delete CActiveScheduler::Current(); |
|
171 delete trapCleanup; |
|
172 } |
|
173 __UHEAP_MARKEND; |
|
174 return err; |
|
175 } |
|
176 |
|
177 CEikKeySoundServer* CEikKeySoundServer::NewLC() |
|
178 { |
|
179 CEikKeySoundServer* self = new(ELeave)CEikKeySoundServer(); |
|
180 CleanupStack::PushL(self); |
|
181 self->ConstructL(); |
|
182 self->StartL(__KEYSOUND_SERVER_NAME); |
|
183 return self; |
|
184 } |
|
185 |
|
186 CEikKeySoundServer::CEikKeySoundServer() |
|
187 :CServer2(EActivePriorityDefault), |
|
188 iDisabledScanCode( -1 ) |
|
189 { |
|
190 // construct all system SID objects |
|
191 } |
|
192 |
|
193 void CEikKeySoundServer::ConstructL() |
|
194 { |
|
195 iInit = EFalse; |
|
196 iSidList = new(ELeave)CArrayFixFlat<TAknSoundID>(KAknSoundInfoMapGranularity); |
|
197 iSoundList = new(ELeave)CArrayPtrFlat<CEikSoundInfo>(KAknSoundInfoMapGranularity); |
|
198 |
|
199 // Default to loudest volume |
|
200 iKeypadVolume = CEikSoundInfo::EKeypadVolumeLoud; |
|
201 |
|
202 TRAPD(err, iProfilesRepository = CRepository::NewL(KCRUidProfileEngine)); |
|
203 if (err == KErrNone) |
|
204 { |
|
205 iProfilesNotifyHandler = CCenRepNotifyHandler::NewL(*this, |
|
206 *iProfilesRepository, |
|
207 CCenRepNotifyHandler::EIntKey, |
|
208 KProEngActiveKeypadVolume); |
|
209 |
|
210 iWarningToneEnableHandler = CCenRepNotifyHandler::NewL( *this, |
|
211 *iProfilesRepository, |
|
212 CCenRepNotifyHandler::EIntKey, |
|
213 KProEngActiveWarningTones); |
|
214 |
|
215 iProfilesNotifyHandler->StartListeningL(); |
|
216 iWarningToneEnableHandler->StartListeningL(); |
|
217 |
|
218 iProfilesRepository->Get(KProEngActiveKeypadVolume, (TInt&)iKeypadVolume); |
|
219 iProfilesRepository->Get(KProEngActiveWarningTones, iWarningToneEnabled); |
|
220 } |
|
221 |
|
222 iATSoundServerAPI = NULL; |
|
223 |
|
224 RLibrary lib; |
|
225 TUidType uidType( KDynamicLibraryUid, KSharedLibraryUid, TUid::Uid( KKeysoundServerDllUid ) ); |
|
226 |
|
227 if(lib.Load(KKeySoundServerDll, uidType) == KErrNone) |
|
228 { |
|
229 PFUNC func = (PFUNC)lib.Lookup(1); /* NewL */ |
|
230 |
|
231 TRAPD(error, iATSoundServerAPI = (CATAudioEventAPI*) func(*this)); |
|
232 if( error ) |
|
233 { |
|
234 iATSoundServerAPI = NULL; |
|
235 } |
|
236 } |
|
237 |
|
238 #ifdef _DEBUG |
|
239 RDebug::Print(_L("cenrep CEikKeySoundServer::ConstructL %d"), (TInt)iKeypadVolume); |
|
240 #endif |
|
241 } |
|
242 |
|
243 CEikKeySoundServer::~CEikKeySoundServer() |
|
244 { |
|
245 if (iProfilesNotifyHandler) |
|
246 { |
|
247 iProfilesNotifyHandler->StopListening(); |
|
248 delete iProfilesNotifyHandler; |
|
249 } |
|
250 |
|
251 if (iWarningToneEnableHandler) |
|
252 { |
|
253 iWarningToneEnableHandler->StopListening(); |
|
254 delete iWarningToneEnableHandler; |
|
255 } |
|
256 |
|
257 delete iProfilesRepository; |
|
258 delete iDefaultSoundMap; |
|
259 delete iSoundList; |
|
260 delete iSidList; |
|
261 delete iATSoundServerAPI; |
|
262 } |
|
263 |
|
264 CSession2* CEikKeySoundServer::NewSessionL(const TVersion& aVersion, |
|
265 const RMessage2& /*aMessage*/) const |
|
266 { |
|
267 TVersion ver(KKeySoundServMajorVN, KKeySoundServMinorVN, KKeySoundServBuildVN); |
|
268 if (!User::QueryVersionSupported(ver, aVersion)) |
|
269 { |
|
270 User::Leave(KErrNotSupported); |
|
271 } |
|
272 return CEikKeySoundSession::NewL(CONST_CAST(CEikKeySoundServer*,this)); |
|
273 } |
|
274 |
|
275 void CEikKeySoundServer::InitL(const RMessage2& aMessage) |
|
276 { |
|
277 TPckg<TInt> pckgBuf(iInit); |
|
278 aMessage.WriteL(0, pckgBuf); |
|
279 iInit = ETrue; |
|
280 } |
|
281 |
|
282 void CEikKeySoundServer::Complete(TInt aError, TAudioThemeEvent aEvent) |
|
283 { |
|
284 if( aError != KErrNone && aError != ESilencedError |
|
285 && aError != EEventCurrentlyPlaying ) |
|
286 { |
|
287 PlaySid(aEvent, ETrue); |
|
288 } |
|
289 } |
|
290 |
|
291 void CEikKeySoundServer::PlaySid(TInt aSid, TBool aPlaySelf) |
|
292 { |
|
293 if (aSid == EAvkonSIDWarningTone && iWarningToneEnabled == 0) |
|
294 { |
|
295 // Don't play warning tone, when the warning tone is disabled in setting. |
|
296 return; |
|
297 } |
|
298 |
|
299 TInt error(KErrNone); |
|
300 |
|
301 // special cases when the sound is always played in the key sound server |
|
302 if (aSid <= 1000 || aSid == EAvkonSIDStandardKeyClick || |
|
303 aSid == EAvkonSIDReadialCompleteTone || aSid == EAvkonSIDPowerOffTone || |
|
304 aSid == EAvkonSIDPowerOnTone || aSid == EAvkonSIDVoiceRecordingTone || |
|
305 aSid == EAvkonSIDVoiceRecordingStartTone || |
|
306 aSid == EAvkonSIDVoiceRecordingStopTone || aSid == EAvkonSIDNetBusy || |
|
307 aSid == EAvkonSIDNetCallWaiting || aSid == EAvkonSIDNetReorder || |
|
308 aSid == EAvkonSIDNetCongestion || aSid == EAvkonSIDNetSpecialInformation || |
|
309 aSid == EAvkonSIDNetRadioNotAvailable || aSid == EAvkonSIDIHFActive || |
|
310 aSid == EAvkonSIDRadioPathAcknowledge || aSid == EAvkonSIDDial || |
|
311 aSid == EAvkonSIDRingGoing || aSid == EAvkonSIDLocationRequest || |
|
312 aSid == EAvkonSIDInformationTone || aSid == EAvkonSIDConfirmationTone ) |
|
313 { |
|
314 aPlaySelf = ETrue; |
|
315 } |
|
316 |
|
317 if(!aPlaySelf && iATSoundServerAPI) |
|
318 { |
|
319 TAudioThemeEvent event = static_cast<TAudioThemeEvent>(aSid); |
|
320 TRAP(error, iATSoundServerAPI->SendAudioEventL(event, EFalse)); |
|
321 } |
|
322 |
|
323 if (aPlaySelf || error) |
|
324 { |
|
325 TKeyArrayFix sidKey(_FOFF(TAknSoundID, iSid), ECmpTUint); |
|
326 TAknSoundID soundId; |
|
327 soundId.iSid = aSid; |
|
328 TInt index; |
|
329 if (iSidList->FindIsq(soundId, sidKey, index) == 0) |
|
330 { |
|
331 CEikSoundInfo* info = ((*iSidList)[index]).iSoundInfo; |
|
332 if (info && info->Volume() != CEikSoundInfo::EKeypadVolumeOff ) |
|
333 { |
|
334 TRAP_IGNORE(info->PlayL()); |
|
335 #if defined(EIKKSS_DEBUGSOUNDID) |
|
336 RDebug::Print(_L("Playing SoundID:%d"), aSid & 0xffff); |
|
337 #endif |
|
338 LOGTEXT2(_L(" PlaySid(): Index:%d, pointer:%d"), index, (TInt)info); |
|
339 } |
|
340 } |
|
341 } |
|
342 } |
|
343 |
|
344 void CEikKeySoundServer::StopSid(TInt aSid) |
|
345 { |
|
346 TKeyArrayFix sidKey(_FOFF(TAknSoundID, iSid), ECmpTUint); |
|
347 TAknSoundID soundId; |
|
348 soundId.iSid = aSid; |
|
349 TInt index; |
|
350 if (iSidList->FindIsq(soundId, sidKey, index) == 0) |
|
351 { |
|
352 CEikSoundInfo* info = ((*iSidList)[index]).iSoundInfo; |
|
353 if (info) |
|
354 { |
|
355 info->Stop(); |
|
356 #if defined(EIKKSS_DEBUGSOUNDID) |
|
357 RDebug::Print(_L("Force Stopping SoundID:%d"), aSid & 0xffff); |
|
358 #endif |
|
359 } |
|
360 } |
|
361 } |
|
362 |
|
363 void CEikKeySoundServer::SetVolumeForPreferenceType(TInt aPreference, |
|
364 CEikSoundInfo::TVolumeSetting aVolume) |
|
365 { |
|
366 TInt count = iSoundList->Count(); |
|
367 for (TInt ii = 0; ii < count; ii++) |
|
368 { |
|
369 CEikSoundInfo* info = (*iSoundList)[ii]; |
|
370 if (info) |
|
371 { |
|
372 if (info->Preference() == aPreference) |
|
373 { |
|
374 info->SetVolume(aVolume); |
|
375 } |
|
376 } |
|
377 } |
|
378 } |
|
379 |
|
380 void CEikKeySoundServer::SetDisabledScanCode( TInt aScanCode ) |
|
381 { |
|
382 iDisabledScanCode = aScanCode; |
|
383 } |
|
384 |
|
385 TInt CEikKeySoundServer::DisabledScanCode() |
|
386 { |
|
387 return iDisabledScanCode; |
|
388 } |
|
389 |
|
390 |
|
391 void CEikKeySoundServer::HandleNotifyInt(TUint32 aId, TInt aNewValue) |
|
392 { |
|
393 if (aId == KProEngActiveKeypadVolume) |
|
394 { |
|
395 iKeypadVolume = (CEikSoundInfo::TVolumeSetting)aNewValue; |
|
396 SetVolumeForPreferenceType( KKeyClickPreference, iKeypadVolume ); |
|
397 } |
|
398 else if (aId == KProEngActiveWarningTones) |
|
399 { |
|
400 iWarningToneEnabled = aNewValue; |
|
401 } |
|
402 } |
|
403 |
|
404 // =================================== |
|
405 // CEikKeySoundSession implementation. |
|
406 // =================================== |
|
407 |
|
408 CEikKeySoundSession* CEikKeySoundSession::NewL(CEikKeySoundServer* aServer) |
|
409 { |
|
410 CEikKeySoundSession* self = new(ELeave)CEikKeySoundSession(aServer); |
|
411 CleanupStack::PushL(self); |
|
412 self->ConstructL(); |
|
413 CleanupStack::Pop(); |
|
414 return self; |
|
415 } |
|
416 |
|
417 |
|
418 CEikKeySoundSession::CEikKeySoundSession(CEikKeySoundServer* aServer) |
|
419 :CSession2(), iServer(aServer) |
|
420 { |
|
421 } |
|
422 |
|
423 CEikKeySoundSession::~CEikKeySoundSession() |
|
424 { |
|
425 RemoveSids(iClientUid); |
|
426 if (iHasLockedContext) |
|
427 { |
|
428 iServer->SetContextLocked(EFalse); |
|
429 } |
|
430 if (iOwnsDefaultSounds) |
|
431 { |
|
432 RemoveSids(0); |
|
433 iServer->iInit = EFalse; |
|
434 } |
|
435 if (iSoundStack) |
|
436 { |
|
437 if (iSoundStack->Count() > 0) |
|
438 { |
|
439 // Bottom entry is owned by server, so remove before deleting other sound maps |
|
440 iSoundStack->Delete(0); |
|
441 iSoundStack->ResetAndDestroy(); |
|
442 } |
|
443 // Make sure server isn't using this soundstack |
|
444 if (iServer->iCurrentSoundStack == iSoundStack) |
|
445 { |
|
446 iServer->iCurrentSoundStack = NULL; |
|
447 } |
|
448 delete iSoundStack; |
|
449 } |
|
450 } |
|
451 |
|
452 |
|
453 void CEikKeySoundSession::ConstructL() |
|
454 { |
|
455 iSoundStack = CEikKeySoundStack::NewL(); |
|
456 if (iServer->iDefaultSoundMap) |
|
457 { |
|
458 iSoundStack->AppendL(iServer->iDefaultSoundMap); |
|
459 } |
|
460 } |
|
461 |
|
462 |
|
463 void CEikKeySoundSession::ServiceL(const RMessage2& aMessage) |
|
464 { |
|
465 if (aMessage.Function() == EKeySoundServerPlayKey) |
|
466 { |
|
467 TInt scancode = aMessage.Int0() & 0xff; |
|
468 TBool repeat = aMessage.Int1(); |
|
469 aMessage.Complete(KErrNone); |
|
470 TInt sid; |
|
471 if (iServer->iCurrentSoundStack) |
|
472 { |
|
473 if (iServer->iCurrentSoundStack->Find(scancode, repeat, sid)) |
|
474 { |
|
475 if ( scancode != iServer->DisabledScanCode() ) |
|
476 { |
|
477 iServer->PlaySid(sid, EFalse); |
|
478 } |
|
479 else |
|
480 { |
|
481 iServer->SetDisabledScanCode( -1 ); |
|
482 } |
|
483 } |
|
484 } |
|
485 } |
|
486 else |
|
487 { |
|
488 TRAPD(err, DispatchMessageL(aMessage)); |
|
489 aMessage.Complete(err); |
|
490 } |
|
491 } |
|
492 |
|
493 |
|
494 void CEikKeySoundSession::DispatchMessageL(const RMessage2& aMessage) |
|
495 { |
|
496 switch (aMessage.Function()) |
|
497 { |
|
498 case EKeySoundServerInit: |
|
499 iClientUid = aMessage.Int1(); |
|
500 iServer->InitL(aMessage); |
|
501 break; |
|
502 case EKeySoundServerPlaySID: |
|
503 iServer->PlaySid(aMessage.Int0(), EFalse); |
|
504 break; |
|
505 case EKeySoundServerAddSIDS: |
|
506 AddSoundIdBufferL(aMessage); |
|
507 break; |
|
508 case EKeySoundServerPushContext: |
|
509 PushContextL(aMessage); |
|
510 break; |
|
511 case EKeySoundServerPopContext: |
|
512 PopContext(); |
|
513 break; |
|
514 case EKeySoundServerTopContext: |
|
515 { |
|
516 TInt id = 0; |
|
517 if (iServer->iCurrentSoundStack && iServer->iCurrentSoundStack->Count()) |
|
518 { |
|
519 CEikKeySoundMap* map = iServer->iCurrentSoundStack->At( |
|
520 iServer->iCurrentSoundStack->Count() - 1); |
|
521 |
|
522 id = map->ContextResourceId(); |
|
523 } |
|
524 TPckg<TInt> pckg(id); |
|
525 aMessage.WriteL(0, pckg); |
|
526 break; |
|
527 } |
|
528 case EKeySoundServerBringToForeground: |
|
529 if ( !iServer->ContextLocked() ) |
|
530 { |
|
531 iServer->iCurrentSoundStack = iSoundStack; |
|
532 } |
|
533 break; |
|
534 case EKeySoundServerStopCurrentTone: |
|
535 iServer->StopSid(aMessage.Int0()); |
|
536 break; |
|
537 case EKeySoundServerLockContext: |
|
538 // We do not want lock twice and we do not want lock other's context. |
|
539 if ( !iServer->ContextLocked() && iServer->iCurrentSoundStack == iSoundStack ) |
|
540 { |
|
541 iServer->SetContextLocked( ETrue ); |
|
542 iHasLockedContext = ETrue; |
|
543 } |
|
544 break; |
|
545 case EKeySoundServerReleaseContext: |
|
546 iServer->SetContextLocked( EFalse ); |
|
547 iHasLockedContext = EFalse; |
|
548 break; |
|
549 case EKeySoundServerCloseServer: |
|
550 { |
|
551 RProcess myProcess; |
|
552 TUid myUid = myProcess.SecureId(); |
|
553 |
|
554 // This server command is not allowed to be called outside eiksrvs process. |
|
555 if (aMessage.SecureId() != myProcess.SecureId()) |
|
556 { |
|
557 User::Leave(KErrPermissionDenied); |
|
558 } |
|
559 |
|
560 CActiveScheduler::Stop(); |
|
561 break; |
|
562 } |
|
563 |
|
564 case EKeySoundServerDisableNextKeySound: |
|
565 iServer->SetDisabledScanCode( aMessage.Int0() ); |
|
566 break; |
|
567 |
|
568 default: |
|
569 User::Leave(KErrNotSupported); |
|
570 break; |
|
571 } |
|
572 } |
|
573 |
|
574 void CEikKeySoundSession::AddSoundIdBufferL(const RMessage2& aMessage) |
|
575 { |
|
576 TInt uid = aMessage.Int0(); |
|
577 TInt size = aMessage.Int1(); |
|
578 |
|
579 // CBufFlat requires that size must be positive and not larger than KMaxTInt / 2. |
|
580 // Without this check the KeySoundServer could panic. |
|
581 if (size <= 0 || size >= ((KMaxTInt / 2) - KKeySoundServerBufExpandSize)) |
|
582 { |
|
583 User::Leave(KErrArgument); |
|
584 } |
|
585 |
|
586 if (uid == 0) |
|
587 { |
|
588 // Remember if this session is loading the default sounds, |
|
589 // so they can be restored if this session goes down. |
|
590 iOwnsDefaultSounds = ETrue; |
|
591 } |
|
592 |
|
593 CBufFlat* buffer = CBufFlat::NewL(KKeySoundServerBufExpandSize); |
|
594 CleanupStack::PushL(buffer); |
|
595 |
|
596 buffer->ExpandL(0,size); |
|
597 TPtr8 buf(buffer->Ptr(0)); |
|
598 aMessage.ReadL(2,buf); |
|
599 |
|
600 // Internalize the data from the stream |
|
601 RBufReadStream readStream; |
|
602 readStream.Open(*buffer); |
|
603 |
|
604 CleanupClosePushL(readStream); |
|
605 |
|
606 TInt count = readStream.ReadUint16L(); |
|
607 |
|
608 for (TInt ii = 0; ii < count; ii++) |
|
609 { |
|
610 TAknSoundID soundId; |
|
611 soundId.iSid = readStream.ReadUint32L(); |
|
612 soundId.iAppUid = uid; |
|
613 |
|
614 TInt priority = readStream.ReadUint16L(); |
|
615 TInt preference = readStream.ReadUint32L(); |
|
616 |
|
617 TInt type = readStream.ReadInt8L(); |
|
618 switch (type) |
|
619 { |
|
620 case 0: // File |
|
621 { |
|
622 CAknFileSoundInfo* soundInfo = new(ELeave)CAknFileSoundInfo(priority, preference); |
|
623 CleanupStack::PushL(soundInfo); |
|
624 soundId.iSoundInfo = soundInfo; |
|
625 TFileName file; |
|
626 readStream >> file; |
|
627 |
|
628 TInt volume = readStream.ReadInt8L(); |
|
629 |
|
630 if ( volume >= CEikSoundInfo::ESoundVolume0 |
|
631 && volume <= CEikSoundInfo::ESoundVolume9 ) |
|
632 { |
|
633 soundInfo->SetVolume((CEikSoundInfo::TVolumeSetting)volume); |
|
634 } |
|
635 // No need to use else, because sound infos default to the loudest. |
|
636 |
|
637 AddFileSidL(soundId, soundInfo, file); |
|
638 CleanupStack::Pop(); // soundInfo |
|
639 break; |
|
640 } |
|
641 case 1: // tone |
|
642 { |
|
643 CAknToneSoundInfo* soundInfo = new(ELeave)CAknToneSoundInfo(priority, preference); |
|
644 CleanupStack::PushL(soundInfo); |
|
645 soundId.iSoundInfo = soundInfo; |
|
646 soundInfo->iFrequency = readStream.ReadUint16L(); |
|
647 TInt64 ms(STATIC_CAST(TUint,readStream.ReadUint32L())); |
|
648 soundInfo->iMs = TTimeIntervalMicroSeconds(ms); |
|
649 |
|
650 TInt volume = readStream.ReadInt8L(); |
|
651 |
|
652 if ( volume >= CEikSoundInfo::ESoundVolume0 |
|
653 && volume <= CEikSoundInfo::ESoundVolume9 ) |
|
654 { |
|
655 soundInfo->SetVolume((CEikSoundInfo::TVolumeSetting)volume); |
|
656 } |
|
657 // No need to use else, because sound infos default to the loudest. |
|
658 |
|
659 AddToneSidL(soundId, soundInfo); |
|
660 CleanupStack::Pop(); // soundInfo |
|
661 break; |
|
662 } |
|
663 case 2: // sequence |
|
664 { |
|
665 CAknSequenceSoundInfo* soundInfo = new(ELeave)CAknSequenceSoundInfo(priority, |
|
666 preference); |
|
667 |
|
668 CleanupStack::PushL(soundInfo); |
|
669 soundInfo->ReadSequenceL(readStream); |
|
670 soundId.iSoundInfo = soundInfo; |
|
671 |
|
672 TInt volume = readStream.ReadInt8L(); |
|
673 |
|
674 if ( volume >= CEikSoundInfo::ESoundVolume0 |
|
675 && volume <= CEikSoundInfo::ESoundVolume9 ) |
|
676 { |
|
677 soundInfo->SetVolume((CEikSoundInfo::TVolumeSetting)volume); |
|
678 } |
|
679 // No need to use else, because sound infos default to the loudest. |
|
680 |
|
681 AddSequenceSidL(soundId, soundInfo); |
|
682 CleanupStack::Pop(); // soundinfo |
|
683 break; |
|
684 } |
|
685 } // end of switch |
|
686 } |
|
687 |
|
688 CleanupStack::PopAndDestroy(2); // readstream close, buffer |
|
689 // Set default volumes. |
|
690 iServer->SetVolumeForPreferenceType(KKeyClickPreference, iServer->iKeypadVolume); |
|
691 } |
|
692 |
|
693 void CEikKeySoundSession::RemoveSids(TInt aUid) |
|
694 { |
|
695 TUint uid = aUid << 16; |
|
696 if (!iServer->iSidList) |
|
697 { |
|
698 return; |
|
699 } |
|
700 TInt count = iServer->iSidList->Count(); |
|
701 for (TInt ii=0; ii<count; ii++) |
|
702 { |
|
703 TAknSoundID& id = iServer->iSidList->At(ii); |
|
704 if ( (id.iSid & 0xffff0000) == uid) |
|
705 { |
|
706 // Check first for possible duplicate sid. It is possible to have duplicates |
|
707 // in some cases when 2 instances of same application (uid) are running |
|
708 // simultaneusly, e.g. the real application and an embedded instance of |
|
709 // the application. |
|
710 TBool duplicateFound = EFalse; |
|
711 for (TInt jj = ii + 1; jj < count; jj++) |
|
712 { |
|
713 TAknSoundID& possibleDuplicateId = iServer->iSidList->At(jj); |
|
714 if (possibleDuplicateId.iSid == id.iSid) |
|
715 { |
|
716 duplicateFound = ETrue; |
|
717 break; |
|
718 } |
|
719 } |
|
720 // If no duplicate found, sid is deleted. Else duplicate will be |
|
721 // deleted when the for-loop reaches it (unless there is even more duplicates). |
|
722 if (!duplicateFound) |
|
723 { |
|
724 // Remove sound at this position |
|
725 delete id.iSoundInfo; |
|
726 if (iServer->iSoundList) |
|
727 { |
|
728 iServer->iSoundList->Delete(ii); |
|
729 } |
|
730 iServer->iSidList->Delete(ii); |
|
731 ii--; |
|
732 count--; |
|
733 } |
|
734 } |
|
735 } |
|
736 } |
|
737 |
|
738 void CEikKeySoundSession::PushContextL(const RMessage2& aMessage) |
|
739 { |
|
740 TInt items = aMessage.Int0(); |
|
741 TInt uid = aMessage.Int2(); |
|
742 TInt resSize = (items * 5); |
|
743 TInt contextResId = aMessage.Int3(); |
|
744 |
|
745 // CBufFlat requires that resSize must be positive and not larger than KMaxTInt / 2. |
|
746 // Without this check the KeySoundServer could panic. |
|
747 if (resSize <= 0 || resSize >= ((KMaxTInt / 2) - KKeySoundServerBufExpandSize)) |
|
748 { |
|
749 User::Leave(KErrArgument); |
|
750 } |
|
751 |
|
752 CBufFlat* buffer = CBufFlat::NewL(KKeySoundServerBufExpandSize); |
|
753 CleanupStack::PushL(buffer); |
|
754 |
|
755 buffer->ExpandL(0,resSize); |
|
756 TPtr8 buf(buffer->Ptr(0)); |
|
757 aMessage.ReadL(1,buf); |
|
758 |
|
759 // Internalize the data from the stream |
|
760 RBufReadStream readStream; |
|
761 readStream.Open(*buffer); |
|
762 |
|
763 CleanupClosePushL(readStream); |
|
764 |
|
765 CEikKeySoundMap* soundMap = CEikKeySoundMap::NewL(); |
|
766 CleanupStack::PushL(soundMap); |
|
767 soundMap->SetContextResourceId(contextResId); |
|
768 soundMap->InternalizeL(readStream, items, uid); |
|
769 iSoundStack->AppendL(soundMap); |
|
770 CleanupStack::Pop(); // soundMap |
|
771 |
|
772 if (iServer->iDefaultSoundMap == NULL) |
|
773 { |
|
774 iServer->iDefaultSoundMap = soundMap; |
|
775 } |
|
776 |
|
777 CleanupStack::PopAndDestroy(2); // readstream close, buffer |
|
778 } |
|
779 |
|
780 void CEikKeySoundSession::PopContext() |
|
781 { |
|
782 if (iSoundStack) |
|
783 { |
|
784 TInt count = iSoundStack->Count(); |
|
785 if (count > 1) |
|
786 { |
|
787 delete iSoundStack->At(count-1); |
|
788 iSoundStack->Delete(count-1); |
|
789 } |
|
790 } |
|
791 } |
|
792 |
|
793 void CEikKeySoundSession::AddToneSidL(const TAknSoundID& aSoundID, CAknToneSoundInfo* aSoundInfo) |
|
794 { |
|
795 aSoundInfo->InitL(); |
|
796 |
|
797 TKeyArrayFix sidKey(_FOFF(TAknSoundID, iSid), ECmpTUint); |
|
798 if (iServer->iSidList && iServer->iSoundList) |
|
799 { |
|
800 TInt position = iServer->iSidList->InsertIsqAllowDuplicatesL(aSoundID, sidKey); |
|
801 TRAPD(err, |
|
802 iServer->iSoundList->AppendL(aSoundInfo)); |
|
803 if (err != KErrNone) |
|
804 { |
|
805 iServer->iSidList->Delete(position); |
|
806 } |
|
807 } |
|
808 } |
|
809 |
|
810 void CEikKeySoundSession::AddSequenceSidL(const TAknSoundID& aSoundID, |
|
811 CAknSequenceSoundInfo* aSoundInfo) |
|
812 { |
|
813 aSoundInfo->InitL(); |
|
814 |
|
815 TKeyArrayFix sidKey(_FOFF(TAknSoundID, iSid), ECmpTUint); |
|
816 |
|
817 if (iServer->iSidList && iServer->iSoundList) |
|
818 { |
|
819 TInt position = iServer->iSidList->InsertIsqAllowDuplicatesL(aSoundID, sidKey); |
|
820 TRAPD(err, |
|
821 iServer->iSoundList->AppendL(aSoundInfo)); |
|
822 if (err != KErrNone) |
|
823 { |
|
824 iServer->iSidList->Delete(position); |
|
825 } |
|
826 } |
|
827 } |
|
828 |
|
829 void CEikKeySoundSession::AddFileSidL(const TAknSoundID& aSoundID, CAknFileSoundInfo* aSoundInfo, |
|
830 const TDesC& aFileName) |
|
831 { |
|
832 aSoundInfo->InitL(aFileName, NULL); |
|
833 |
|
834 TKeyArrayFix sidKey(_FOFF(TAknSoundID, iSid), ECmpTUint); |
|
835 if (iServer->iSidList && iServer->iSoundList) |
|
836 { |
|
837 TInt position = iServer->iSidList->InsertIsqAllowDuplicatesL(aSoundID, sidKey); |
|
838 TRAPD(err, |
|
839 iServer->iSoundList->AppendL(aSoundInfo)); |
|
840 if (err != KErrNone) |
|
841 { |
|
842 iServer->iSidList->Delete(position); |
|
843 } |
|
844 } |
|
845 } |
|
846 |
|
847 // ============================= |
|
848 // CEikSoundInfo implementation. |
|
849 // ============================= |
|
850 |
|
851 CEikSoundInfo::CEikSoundInfo(TInt aPriority, TInt aPreference) |
|
852 { |
|
853 iPriority = aPriority; |
|
854 iPreference = aPreference; |
|
855 iVolume = ESoundVolume9; // default to loudest |
|
856 } |
|
857 |
|
858 CEikSoundInfo::~CEikSoundInfo() |
|
859 { |
|
860 LOGTEXT(_L("CEikSoundInfo::~CEikSoundInfo(). Destructor.")); |
|
861 // Empty implementation. |
|
862 } |
|
863 |
|
864 TInt CEikSoundInfo::Preference() |
|
865 { |
|
866 return iPreference; |
|
867 } |
|
868 |
|
869 CEikSoundInfo::TVolumeSetting CEikSoundInfo::Volume() |
|
870 { |
|
871 return iVolume; |
|
872 } |
|
873 |
|
874 // ================================== |
|
875 // CAknSynthSoundInfo implementation. |
|
876 // ================================== |
|
877 |
|
878 CAknSynthSoundInfo::CAknSynthSoundInfo(TInt aPriority, TInt aPreference) |
|
879 : CEikSoundInfo(aPriority, aPreference), iPlayedStatically(EFalse) |
|
880 { |
|
881 } |
|
882 |
|
883 CAknSynthSoundInfo::~CAknSynthSoundInfo() |
|
884 { |
|
885 LOGTEXT(_L("CAknSynthSoundInfo::~CAknSynthSoundInfo(). Destructor.")); |
|
886 |
|
887 // Stops playing and deletes instances if they exist. |
|
888 Stop(); |
|
889 |
|
890 delete iToneObserver; |
|
891 delete iTonePlayer; |
|
892 } |
|
893 |
|
894 void CAknSynthSoundInfo::Prepare() |
|
895 { |
|
896 LOGTEXT(_L("CAknSynthSoundInfo::Prepare().")); |
|
897 // This base class method should never be called. |
|
898 } |
|
899 |
|
900 void CAknSynthSoundInfo::InitL() |
|
901 { |
|
902 // Keyclicks are played with a statically reserved CMdaAudioToneUtility. |
|
903 // Same concerns also error tones (this is a hack to avoid an endless error dialog |
|
904 // loop because of audio server crash). |
|
905 if ((iPriority == EAvkonKeyClickPriority && iPreference == KKeyClickPreference) || |
|
906 (iPriority == EAvkonErrorNotePriority && iPreference == EAvkonErrorNotePreference)) |
|
907 { |
|
908 LOGTEXT(_L("CAknSynthSoundInfo::InitL(). Static init.")); |
|
909 |
|
910 iPlayedStatically = ETrue; |
|
911 iToneObserver = CAknEikAudioToneObserver::NewL(*this); |
|
912 iTonePlayer = CMdaAudioToneUtility::NewL(*iToneObserver, NULL); // Synchronous |
|
913 } |
|
914 } |
|
915 |
|
916 void CAknSynthSoundInfo::PlayL() |
|
917 { |
|
918 LOGTEXT(_L("CAknSynthSoundInfo::PlayL().")); |
|
919 LOGTEXT3(_L(" This:%d, iPriority:%d, iPreference:%d"), (TInt)this, iPriority, iPreference); |
|
920 |
|
921 // Stops playing and deletes instances if they exist. |
|
922 Stop(); |
|
923 |
|
924 if (!iPlayedStatically) |
|
925 { |
|
926 // Create new tone player and observer. |
|
927 iToneObserver = CAknEikAudioToneObserver::NewL(*this); |
|
928 iTonePlayer = CMdaAudioToneUtility::NewL(*iToneObserver, NULL); // Synchronous |
|
929 } |
|
930 |
|
931 // Prepare to play either a tone or a sequence depending on subclass. |
|
932 Prepare(); |
|
933 } |
|
934 |
|
935 void CAknSynthSoundInfo::DoPlay() |
|
936 { |
|
937 LOGTEXT(_L("CAknSynthSoundInfo::DoPlay().")); |
|
938 LOGTEXT3(_L(" This:%d, iPriority:%d, iPreference:%d"), (TInt)this, iPriority, iPreference); |
|
939 |
|
940 if (iTonePlayer->State() == EMdaAudioToneUtilityPrepared) |
|
941 { |
|
942 LOGTEXT(_L(" CAknSynthSoundInfo::DoPlay(). Prepare successful, play.")); |
|
943 |
|
944 iTonePlayer->SetPriority(iPriority,(TMdaPriorityPreference)iPreference); |
|
945 DoSetVolume(iTonePlayer); |
|
946 |
|
947 LOGTEXT1(_L(" iVolume just before calling play: %d"), iVolume); |
|
948 LOGTEXT1(_L(" Volume from iTonePlayer: %d"), iTonePlayer->Volume()); |
|
949 |
|
950 iTonePlayer->Play(); |
|
951 } |
|
952 else |
|
953 { |
|
954 LOGTEXT(_L(" CAknSynthSoundInfo::DoPlay(). Prepare failed, delete!")); |
|
955 |
|
956 if (!iPlayedStatically) |
|
957 { |
|
958 LOGTEXT(_L(" CAknSynthSoundInfo::DoPlay(). Deleting iTonePlayer and iToneObserver.")); |
|
959 |
|
960 delete iTonePlayer; |
|
961 iTonePlayer = NULL; |
|
962 delete iToneObserver; |
|
963 iToneObserver = NULL; |
|
964 } |
|
965 } |
|
966 } |
|
967 |
|
968 void CAknSynthSoundInfo::Stop() |
|
969 { |
|
970 LOGTEXT(_L("CAknSynthSoundInfo::Stop().")); |
|
971 LOGTEXT3(_L(" This:%d, iPriority:%d, iPreference:%d"), (TInt)this, iPriority, iPreference); |
|
972 |
|
973 // Stop playing and delete tone player if it exists. |
|
974 if (iTonePlayer) |
|
975 { |
|
976 LOGTEXT(_L(" CAknSynthSoundInfo::Stop(). iTonePlayer exists.")); |
|
977 |
|
978 if (iTonePlayer->State() == EMdaAudioToneUtilityPlaying) |
|
979 { |
|
980 LOGTEXT(_L(" CAknSynthSoundInfo::Stop(). Playing, call CancelPlay().")); |
|
981 |
|
982 iTonePlayer->CancelPlay(); |
|
983 } |
|
984 |
|
985 if (!iPlayedStatically) |
|
986 { |
|
987 LOGTEXT(_L(" CAknSynthSoundInfo::Stop(). Dynamic playing. Deleting iTonePlayer.")); |
|
988 |
|
989 delete iTonePlayer; |
|
990 iTonePlayer = NULL; |
|
991 } |
|
992 } |
|
993 |
|
994 // Delete also tone observer if it exists. |
|
995 if (iToneObserver) |
|
996 { |
|
997 LOGTEXT(_L(" CAknSynthSoundInfo::Stop(). iToneObserver exists.")); |
|
998 |
|
999 if (!iPlayedStatically) |
|
1000 { |
|
1001 LOGTEXT(_L(" CAknSynthSoundInfo::Stop(). Dynamic playing. Deleting iToneObserver.")); |
|
1002 |
|
1003 delete iToneObserver; |
|
1004 iToneObserver = NULL; |
|
1005 } |
|
1006 } |
|
1007 } |
|
1008 |
|
1009 void CAknSynthSoundInfo::SetVolume(TVolumeSetting aVolume) |
|
1010 { |
|
1011 iVolume = aVolume; |
|
1012 } |
|
1013 |
|
1014 void CAknSynthSoundInfo::DoSetVolume(CMdaAudioToneUtility* aTonePlayer) |
|
1015 { |
|
1016 TInt max = aTonePlayer->MaxVolume(); |
|
1017 |
|
1018 if ( max == 0x0000ffff ) // 16bit -1 i.e. not set |
|
1019 { |
|
1020 max = (TInt)ESoundVolume9; // Set it to our max |
|
1021 } |
|
1022 |
|
1023 TInt volume = 0; |
|
1024 |
|
1025 if ( Preference() != KKeyClickPreference ) // Other sounds than key click |
|
1026 { |
|
1027 aTonePlayer->SetVolume( ((TInt)iVolume * max )/(TInt)ESoundVolume9); |
|
1028 return; |
|
1029 } |
|
1030 |
|
1031 switch (iVolume) |
|
1032 { |
|
1033 case EKeypadVolumeOff: |
|
1034 break; |
|
1035 case EKeypadVolumeQuiet: |
|
1036 volume = max / 3; |
|
1037 break; |
|
1038 case EKeypadVolumeMedium: |
|
1039 volume = (max * 2) / 3; |
|
1040 break; |
|
1041 default: //case EKeypadVolumeLoud: |
|
1042 volume = max; |
|
1043 break; |
|
1044 } |
|
1045 aTonePlayer->SetVolume(volume); |
|
1046 } |
|
1047 |
|
1048 |
|
1049 // ================================= |
|
1050 // CAknToneSoundInfo implementation. |
|
1051 // ================================= |
|
1052 |
|
1053 CAknToneSoundInfo::CAknToneSoundInfo(TInt aPriority, TInt aPreference) |
|
1054 : CAknSynthSoundInfo(aPriority, aPreference) |
|
1055 { |
|
1056 } |
|
1057 |
|
1058 CAknToneSoundInfo::~CAknToneSoundInfo() |
|
1059 { |
|
1060 LOGTEXT(_L("CAknToneSoundInfo::~CAknToneSoundInfo(). Destructor.")); |
|
1061 // Empty implementation. |
|
1062 } |
|
1063 |
|
1064 void CAknToneSoundInfo::Prepare() |
|
1065 { |
|
1066 LOGTEXT(_L("CAknToneSoundInfo::Prepare().")); |
|
1067 |
|
1068 // Prepare |
|
1069 iTonePlayer->PrepareToPlayTone(iFrequency, iMs); |
|
1070 } |
|
1071 |
|
1072 |
|
1073 // ===================================== |
|
1074 // CAknSequenceSoundInfo implementation. |
|
1075 // ===================================== |
|
1076 |
|
1077 CAknSequenceSoundInfo::CAknSequenceSoundInfo(TInt aPriority, TInt aPreference) |
|
1078 : CAknSynthSoundInfo(aPriority, aPreference) |
|
1079 { |
|
1080 } |
|
1081 |
|
1082 CAknSequenceSoundInfo::~CAknSequenceSoundInfo() |
|
1083 { |
|
1084 LOGTEXT(_L("CAknSequenceSoundInfo::~CAknSequenceSoundInfo(). Destructor.")); |
|
1085 |
|
1086 delete iSequence; |
|
1087 } |
|
1088 |
|
1089 void CAknSequenceSoundInfo::Prepare() |
|
1090 { |
|
1091 LOGTEXT(_L("CAknSequenceSoundInfo::Prepare().")); |
|
1092 |
|
1093 // Prepare |
|
1094 iTonePlayer->PrepareToPlayDesSequence(*iSequence); |
|
1095 } |
|
1096 |
|
1097 void CAknSequenceSoundInfo::ReadSequenceL(RReadStream& aStream) |
|
1098 { |
|
1099 delete iSequence; |
|
1100 iSequence = NULL; |
|
1101 |
|
1102 TInt length = aStream.ReadInt16L(); |
|
1103 iSequence = HBufC8::NewMaxL(length); |
|
1104 TPtr8 ptr = iSequence->Des(); |
|
1105 for (TInt ii = 0; ii < length; ii++) |
|
1106 { |
|
1107 ptr[ii] = aStream.ReadUint8L(); |
|
1108 } |
|
1109 } |
|
1110 |
|
1111 // ================================= |
|
1112 // CAknFileSoundInfo implementation. |
|
1113 // ================================= |
|
1114 |
|
1115 CAknFileSoundInfo::CAknFileSoundInfo(TInt aPriority, TInt aPreference) |
|
1116 : CEikSoundInfo(aPriority, aPreference) |
|
1117 { |
|
1118 } |
|
1119 |
|
1120 CAknFileSoundInfo::~CAknFileSoundInfo() |
|
1121 { |
|
1122 delete iAudioPlayer; |
|
1123 delete iAudioData; |
|
1124 } |
|
1125 |
|
1126 void CAknFileSoundInfo::InitL(const TDesC& aFileName, CMdaServer* aMdaServer) |
|
1127 { |
|
1128 LOGTEXT(_L("CAknFileSoundInfo::InitL() - Filename:")); |
|
1129 LOGTEXT(aFileName); |
|
1130 |
|
1131 iMdaServer = aMdaServer; |
|
1132 |
|
1133 delete iAudioData; |
|
1134 iAudioData = NULL; |
|
1135 |
|
1136 RFs fsSession; |
|
1137 User::LeaveIfError( fsSession.Connect() ); |
|
1138 CleanupClosePushL(fsSession); |
|
1139 |
|
1140 TEntry entry; |
|
1141 User::LeaveIfError(fsSession.Entry(aFileName, entry)); |
|
1142 TInt fileSize = entry.iSize; |
|
1143 |
|
1144 LOGTEXT1(_L(" CAknFileSoundInfo::InitL() - File size:%d"), fileSize); |
|
1145 |
|
1146 iAudioData = HBufC8::NewMaxL(fileSize); |
|
1147 |
|
1148 TPtr8 dataPtr = iAudioData->Des(); |
|
1149 LoadAudioDataL(fsSession, aFileName, dataPtr); |
|
1150 |
|
1151 CleanupStack::PopAndDestroy(); // fsSession |
|
1152 |
|
1153 LOGTEXT(_L(" CAknFileSoundInfo::InitL() - Exit")); |
|
1154 } |
|
1155 |
|
1156 |
|
1157 void CAknFileSoundInfo::LoadAudioDataL(RFs& aFs, const TDesC& aFileName, TDes8& aDes) |
|
1158 { |
|
1159 RDebug::Print(_L("CAknFileSoundInfo::LoadAudioDataL().")); |
|
1160 |
|
1161 RFile file; |
|
1162 User::LeaveIfError( file.Open(aFs, aFileName,EFileRead|EFileShareAny) ); |
|
1163 CleanupClosePushL(file); |
|
1164 TInt error = file.Read(aDes, aDes.Length()); |
|
1165 file.Close(); |
|
1166 CleanupStack::Pop(); //file |
|
1167 User::LeaveIfError(error); |
|
1168 |
|
1169 LOGTEXT(_L(" CAknFileSoundInfo::LoadAudioDataL() - Exit")); |
|
1170 } |
|
1171 |
|
1172 |
|
1173 void CAknFileSoundInfo::PlayL() |
|
1174 { |
|
1175 LOGTEXT(_L("CAknFileSoundInfo::PlayL().")); |
|
1176 LOGTEXT3(_L(" This:%d, iPriority:%d, iPreference:%d"), (TInt)this, iPriority, iPreference); |
|
1177 |
|
1178 // Stops playing and deletes audio player instance if it exist. |
|
1179 Stop(); |
|
1180 |
|
1181 // Create audio player. DoPlay() will be called in all circumstances. |
|
1182 iAudioPlayer = CMdaAudioPlayerUtility::NewDesPlayerReadOnlyL( |
|
1183 *iAudioData, *this, iPriority, (TMdaPriorityPreference)iPreference, iMdaServer); |
|
1184 |
|
1185 LOGTEXT(_L(" CAknFileSoundInfo::PlayL() - Exit")); |
|
1186 } |
|
1187 |
|
1188 |
|
1189 void CAknFileSoundInfo::DoPlay() |
|
1190 { |
|
1191 LOGTEXT(_L("CAknFileSoundInfo::DoPlay().")); |
|
1192 |
|
1193 if (iPrepared) |
|
1194 { |
|
1195 LOGTEXT(_L(" CAknFileSoundInfo::DoPlay(). Prepared succesfull, play.")); |
|
1196 |
|
1197 // No need to set priority. It is already set in NewDesPlayerReadOnlyL(). |
|
1198 |
|
1199 // Set volume. |
|
1200 DoSetVolume(iAudioPlayer); |
|
1201 |
|
1202 LOGTEXT1(_L(" iVolume just before calling play: %d"), iVolume); |
|
1203 |
|
1204 iAudioPlayer->Play(); |
|
1205 iPlaying = ETrue; |
|
1206 } |
|
1207 else |
|
1208 { |
|
1209 LOGTEXT(_L(" CAknFileSoundInfo::DoPlay(). Prepare failed, delete!")); |
|
1210 LOGTEXT(_L(" CAknFileSoundInfo::DoPlay(). Deleting iAudioPlayer.")); |
|
1211 |
|
1212 delete iAudioPlayer; |
|
1213 iAudioPlayer = NULL; |
|
1214 } |
|
1215 } |
|
1216 |
|
1217 |
|
1218 void CAknFileSoundInfo::Stop() |
|
1219 { |
|
1220 LOGTEXT(_L("CAknFileSoundInfo::Stop().")); |
|
1221 |
|
1222 // Stop playing and delete audio player if it exists. |
|
1223 if (iAudioPlayer) |
|
1224 { |
|
1225 LOGTEXT(_L(" CAknFileSoundInfo::Stop(). iAudioPlayer exists.")); |
|
1226 |
|
1227 if (iPlaying) |
|
1228 { |
|
1229 LOGTEXT(_L(" CAknFileSoundInfo::Stop(). Playing, call CancelPlay().")); |
|
1230 |
|
1231 iAudioPlayer->Stop(); |
|
1232 iPlaying = EFalse; |
|
1233 } |
|
1234 |
|
1235 LOGTEXT(_L(" CAknFileSoundInfo::Stop(). Deleting iAudioPlayer.")); |
|
1236 |
|
1237 delete iAudioPlayer; |
|
1238 iAudioPlayer = NULL; |
|
1239 iPrepared = EFalse; |
|
1240 } |
|
1241 } |
|
1242 |
|
1243 void CAknFileSoundInfo::MoscoStateChangeEvent(CBase* /*aObject*/, TInt /*aPreviousState*/, |
|
1244 TInt /*aCurrentState*/, TInt /*aErrorCode*/) |
|
1245 { |
|
1246 } |
|
1247 |
|
1248 void CAknFileSoundInfo::SetVolume(TVolumeSetting aVolume) |
|
1249 { |
|
1250 iVolume = aVolume; |
|
1251 } |
|
1252 |
|
1253 void CAknFileSoundInfo::DoSetVolume(CMdaAudioPlayerUtility* aAudioPlayer) |
|
1254 { |
|
1255 TInt max = aAudioPlayer->MaxVolume(); |
|
1256 |
|
1257 if ( max == 0x0000ffff ) // 16bit -1 i.e. not set |
|
1258 { |
|
1259 max = (TInt)ESoundVolume9; // Set it to our max |
|
1260 } |
|
1261 |
|
1262 TInt volume = 0; |
|
1263 |
|
1264 if ( Preference() != KKeyClickPreference ) // Other sounds than key click |
|
1265 { |
|
1266 aAudioPlayer->SetVolume( ((TInt)iVolume * max )/(TInt)ESoundVolume9); |
|
1267 return; |
|
1268 } |
|
1269 |
|
1270 switch (iVolume) |
|
1271 { |
|
1272 case EKeypadVolumeOff: |
|
1273 break; |
|
1274 case EKeypadVolumeQuiet: |
|
1275 volume = max / 3; |
|
1276 break; |
|
1277 case EKeypadVolumeMedium: |
|
1278 volume = (max * 2) / 3; |
|
1279 break; |
|
1280 default: //case EKeypadVolumeLoud: |
|
1281 volume = max; |
|
1282 break; |
|
1283 } |
|
1284 aAudioPlayer->SetVolume(volume); |
|
1285 } |
|
1286 |
|
1287 void CAknFileSoundInfo::MapcInitComplete(TInt aError, |
|
1288 const TTimeIntervalMicroSeconds& /*aDuration*/) |
|
1289 { |
|
1290 LOGTEXT(_L("CAknFileSoundInfo::MapcInitComplete().")); |
|
1291 LOGTEXT1(_L(" aError:%d"), aError); |
|
1292 |
|
1293 if (aError == KErrNone) |
|
1294 { |
|
1295 iPrepared = ETrue; |
|
1296 SetVolume(iVolume); |
|
1297 } |
|
1298 |
|
1299 DoPlay(); |
|
1300 } |
|
1301 |
|
1302 void CAknFileSoundInfo::MapcPlayComplete(TInt /*aError*/) |
|
1303 { |
|
1304 LOGTEXT(_L("CAknFileSoundInfo::MapcPlayComplete()")); |
|
1305 |
|
1306 iPlaying = EFalse; |
|
1307 |
|
1308 delete iAudioPlayer; |
|
1309 iAudioPlayer = NULL; |
|
1310 iPrepared = EFalse; |
|
1311 } |
|
1312 |
|
1313 // End of file |