|
1 /* |
|
2 * Copyright (c) 2002 - 2006 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 * This class acts as a high level wrapper around the media server |
|
16 * playback and recording functionalities. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include "CVRSystemEventHandler.h" |
|
23 #include <ctsydomainpskeys.h> |
|
24 |
|
25 #include <e32svr.h> |
|
26 #include <bautils.h> |
|
27 #include <eikenv.h> |
|
28 #include <aknappui.h> |
|
29 #include <e32property.h> |
|
30 #include <AudioPreference.h> |
|
31 #include <aknsoundsystem.h> |
|
32 #include <ScreensaverInternalPSKeys.h> |
|
33 #include <AknGlobalNote.h> |
|
34 #include <StringLoader.h> |
|
35 #include <ErrorUI.h> |
|
36 #include <sysutil.h> |
|
37 |
|
38 #include <featmgr.h> // Feature manager |
|
39 |
|
40 #include <voicerecorder.rsg> |
|
41 #include <VoiceRecorderUID.h> |
|
42 #include "VoiceRecorderPrivatePSKeys.h" |
|
43 #include "CVRMemo.h" |
|
44 #include "MVRObserver.h" |
|
45 #include "VRConsts.h" |
|
46 #include "VRUtils.h" |
|
47 #include "CVRTonePlayer.h" |
|
48 #include "CVRMdaRecorder.h" |
|
49 #include "CVRDiskSpaceWatcher.h" |
|
50 #include "CVRRecViewModel.h" |
|
51 #include <AudioInput.h> |
|
52 |
|
53 |
|
54 // MACROS |
|
55 #ifdef _DEBUG |
|
56 #define DEB_PRN_0(str) RDebug::Print(str) |
|
57 #else |
|
58 #define DEB_PRN_0(str) |
|
59 #endif |
|
60 |
|
61 // CONSTANTS |
|
62 const TInt KVRMdaRecorderDefaultStep( 5 ); |
|
63 const TInt KVRObserverArrayGranularity( 2 ); |
|
64 const TInt KVRMaxNoteLabelLength( 256 ); |
|
65 |
|
66 |
|
67 // ================= MEMBER FUNCTIONS ======================================== |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // CVRMdaRecorder::CVRMdaRecorder |
|
71 // |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 CVRMdaRecorder::CVRMdaRecorder() : |
|
75 iObservers( KVRObserverArrayGranularity ), |
|
76 iIsAttachedToMemo( EFalse ), |
|
77 iMediaServerError( KErrNone ), |
|
78 iDimLight (EFalse), |
|
79 iAttachingToMemo(EFalse), |
|
80 ifInRecording(EFalse), |
|
81 ifStopCalled(EFalse) |
|
82 { |
|
83 } |
|
84 |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // CVRMdaRecorder::~CVRMdaRecorder |
|
88 // |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 CVRMdaRecorder::~CVRMdaRecorder() |
|
92 { |
|
93 |
|
94 delete iGlobalNote; |
|
95 delete iAudioInput; |
|
96 delete iAudioRecorder; |
|
97 delete iErrorUI; |
|
98 delete iTimer; |
|
99 delete iTonePlayer; |
|
100 delete iLight; |
|
101 delete iDiskSpaceWatcher; |
|
102 iObservers.Close(); |
|
103 |
|
104 if (iCurrentCallHandler) |
|
105 { |
|
106 delete iCurrentCallHandler; |
|
107 } |
|
108 } |
|
109 |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // CVRMdaRecorder::ConstructL |
|
113 // |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 void CVRMdaRecorder::ConstructL() |
|
117 { |
|
118 _LIT_SECURITY_POLICY_S0( KVRWritePolicy, KVoiceRecorderAppUID3 ); |
|
119 _LIT_SECURITY_POLICY_PASS( KVRReadPolicy ); |
|
120 // Connect to Pub&Sub: |
|
121 // Error ignored, key may be already defined which is ok for us |
|
122 iPropVRState.Define( KPSUidVoiceRecorder, KVoiceRecorderMode, 0, |
|
123 KVRReadPolicy, KVRWritePolicy ); |
|
124 |
|
125 User::LeaveIfError( |
|
126 iPropVRState.Attach( |
|
127 KPSUidVoiceRecorder, KVoiceRecorderMode ) ); |
|
128 |
|
129 // To allow/don't allow screensaver |
|
130 // Errors ignored, no actions needed if API is not available |
|
131 iPropScreenSaver.Attach( KPSUidScreenSaver, |
|
132 KScreenSaverAllowScreenSaver ); |
|
133 iAudioRecorder = CMdaAudioRecorderUtility::NewL( *this, NULL, |
|
134 KAudioPriorityRecording, TMdaPriorityPreference( |
|
135 KAudioPrefRealOneLocalPlayback ) ); |
|
136 |
|
137 iGlobalNote = CAknGlobalNote::NewL(); |
|
138 |
|
139 iErrorUI = CErrorUI::NewL(); |
|
140 |
|
141 iTonePlayer = CVRTonePlayer::NewL(); |
|
142 iTonePlayer->PrepareToneL( EAvkonSIDVoiceRecordingStartTone ); |
|
143 |
|
144 iLight = CHWRMLight::NewL(this); |
|
145 |
|
146 // start observe diskdrive |
|
147 RFs& fs( CEikonEnv::Static()->FsSession() ); |
|
148 |
|
149 iDiskSpaceWatcher = CVRDiskSpaceWatcher::NewL(*this, fs); |
|
150 |
|
151 } |
|
152 |
|
153 |
|
154 // --------------------------------------------------------------------------- |
|
155 // CVRMdaRecorder::MoscoStateChangeEvent |
|
156 // |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 void CVRMdaRecorder::MoscoStateChangeEvent( CBase* /*aObject*/, |
|
160 TInt aPreviousState, |
|
161 TInt aCurrentState, |
|
162 TInt aErrorCode ) |
|
163 { |
|
164 #ifdef _DEBUG |
|
165 RDebug::Print( _L( "VoiceRecorder: MoscoStateChangeEvent() prev: %d, current: %d, error: %d" ), |
|
166 aPreviousState, aCurrentState, aErrorCode ); |
|
167 #endif |
|
168 iMediaServerError = aErrorCode; |
|
169 |
|
170 TRAP_IGNORE(CreateAudioInputL()); |
|
171 |
|
172 |
|
173 // Stop the active scheduler wait (if present) |
|
174 if ( iActiveWait.IsStarted() ) |
|
175 { |
|
176 iActiveWait.AsyncStop(); |
|
177 } |
|
178 |
|
179 if (iMediaServerError != KErrNone ) |
|
180 { |
|
181 |
|
182 // when mmc card is used and unpluged, this error returned |
|
183 if (iMediaServerError == KErrCorrupt || iMediaServerError == KErrNotReady) |
|
184 { |
|
185 CVRRecViewModel* iViewModel = NULL; |
|
186 //iAudioRecorder->Close(); |
|
187 iViewModel = dynamic_cast <CVRRecViewModel*>(iAutoStopObserver); |
|
188 if(iViewModel != NULL) |
|
189 { |
|
190 TRAP_IGNORE( iViewModel->HandleCommandL(EEikCmdExit) ); |
|
191 } |
|
192 else |
|
193 { |
|
194 TRAP_IGNORE( CEikonEnv::Static()->EikAppUi()->HandleCommandL( EAknSoftkeyExit) ); |
|
195 } |
|
196 } |
|
197 |
|
198 // Media server reports KErrDied if the playing was interrupted |
|
199 // by some other system sound triggered by for example incoming SMS |
|
200 |
|
201 if (aPreviousState == CMdaAudioClipUtility::ERecording || aPreviousState == CMdaAudioClipUtility::EPlaying ) |
|
202 { |
|
203 |
|
204 //if ( iMediaServerError != KErrDied && iMediaServerError != KErrAccessDenied ) |
|
205 if ( iMediaServerError != KErrDied && |
|
206 iMediaServerError != KErrAccessDenied && |
|
207 iMediaServerError != KErrInUse ) |
|
208 { |
|
209 TBuf< KVRMaxNoteLabelLength > label; |
|
210 |
|
211 // If showing of error note fails, then.. well it fails |
|
212 if ( iMediaServerError == KErrNotSupported ) |
|
213 { |
|
214 CCoeEnv::Static()-> |
|
215 ReadResourceAsDes16( label, R_VR_UNSUPPORTED_INFONOTE_LABEL ); |
|
216 |
|
217 TRAP_IGNORE( iGlobalNote-> |
|
218 ShowNoteL( EAknGlobalErrorNote, label ) ); |
|
219 |
|
220 } |
|
221 else if ( iMediaServerError == KErrCorrupt ) |
|
222 { |
|
223 CCoeEnv::Static()-> |
|
224 ReadResourceAsDes16( label, R_VR_CORRUPT_INFONOTE_LABEL ); |
|
225 |
|
226 TRAP_IGNORE( iGlobalNote->ShowNoteL( EAknGlobalErrorNote, |
|
227 label ) ); |
|
228 } |
|
229 |
|
230 else |
|
231 { |
|
232 TRAP_IGNORE( iErrorUI->ShowGlobalErrorNoteL( iMediaServerError ) ); |
|
233 } |
|
234 |
|
235 } |
|
236 if(iMediaServerError == KErrInUse && aPreviousState == CMdaAudioClipUtility::EPlaying) |
|
237 { |
|
238 CVRRecViewModel* iViewModel = NULL; |
|
239 iViewModel = dynamic_cast <CVRRecViewModel*>(iAutoStopObserver); |
|
240 if(iViewModel != NULL) |
|
241 { |
|
242 iViewModel->HandleCommandL(ECmdPause); |
|
243 } |
|
244 return; |
|
245 } |
|
246 else |
|
247 { |
|
248 StopAndNotify(); |
|
249 } |
|
250 } |
|
251 |
|
252 //it will happen when the openfile fails |
|
253 if (aPreviousState == CMdaAudioClipUtility::ENotReady && aCurrentState == CMdaAudioClipUtility::ENotReady ) |
|
254 { |
|
255 #ifdef _DEBUG |
|
256 RDebug::Print( _L( "VoiceRecorder: callback stop called" ) ); |
|
257 #endif |
|
258 iAudioRecorder->Close(); |
|
259 } |
|
260 |
|
261 #ifdef _DEBUG |
|
262 if ( aCurrentState == CMdaAudioClipUtility::ERecording) |
|
263 { |
|
264 RDebug::Print( _L( "VoiceRecorder: ERecording" ) ); |
|
265 } |
|
266 #endif |
|
267 |
|
268 } // if ( iMediaServerError != KErrNone ) |
|
269 |
|
270 if ( aCurrentState == CMdaAudioClipUtility::ERecording || |
|
271 aCurrentState == CMdaAudioClipUtility::EPlaying ) |
|
272 { |
|
273 // Do not allow screen saver while playing |
|
274 // Errors ignored, no actions needed if API is not available |
|
275 iPropScreenSaver.Set( KPSUidScreenSaver, |
|
276 KScreenSaverAllowScreenSaver, EVRScreenSaverNotAllowed ); |
|
277 } |
|
278 |
|
279 if ( aCurrentState == CMdaAudioClipUtility::EOpen ) |
|
280 { |
|
281 switch ( aPreviousState ) |
|
282 { |
|
283 case CMdaAudioClipUtility::ENotReady: |
|
284 { |
|
285 iMemo->UpdateModifiedDate(); |
|
286 if ( iAttachingToMemo ) |
|
287 { |
|
288 iAttachingToMemo = EFalse; |
|
289 TRAP_IGNORE( ConfigureMemoL()); |
|
290 } |
|
291 break; |
|
292 } |
|
293 default: |
|
294 { |
|
295 StopAndNotify(); |
|
296 break; |
|
297 } |
|
298 } |
|
299 } |
|
300 DEB_PRN_0( _L( "CVRMdaRecorder::MoscoStateChangeEvent::Exit")); |
|
301 } |
|
302 |
|
303 |
|
304 // --------------------------------------------------------------------------- |
|
305 // CVRMdaRecorder::RegisterObserver |
|
306 // |
|
307 // --------------------------------------------------------------------------- |
|
308 // |
|
309 void CVRMdaRecorder::RegisterObserver( MVRObserver* aObserver ) |
|
310 { |
|
311 if ( aObserver && iObservers.Find( aObserver ) == KErrNotFound ) |
|
312 { |
|
313 iObservers.Append( aObserver ); |
|
314 } |
|
315 } |
|
316 |
|
317 |
|
318 // --------------------------------------------------------------------------- |
|
319 // CVRMdaRecorder::UnregisterObserver |
|
320 // |
|
321 // --------------------------------------------------------------------------- |
|
322 // |
|
323 void CVRMdaRecorder::UnregisterObserver( MVRObserver* aObserver ) |
|
324 { |
|
325 if ( !aObserver ) |
|
326 { |
|
327 return; |
|
328 } |
|
329 |
|
330 TInt index( iObservers.Find( aObserver ) ); |
|
331 if ( index != KErrNotFound ) |
|
332 { |
|
333 iObservers.Remove( index ); |
|
334 } |
|
335 } |
|
336 |
|
337 |
|
338 // --------------------------------------------------------------------------- |
|
339 // CVRMdaRecorder::SetAutoStopObserver |
|
340 // |
|
341 // --------------------------------------------------------------------------- |
|
342 // |
|
343 void CVRMdaRecorder::SetAutoStopObserver( MVRObserver* aObserver ) |
|
344 { |
|
345 iAutoStopObserver = aObserver; |
|
346 } |
|
347 |
|
348 |
|
349 // --------------------------------------------------------------------------- |
|
350 // CVRMdaRecorder::AttachToMemoL |
|
351 // Opens a memo file. |
|
352 // If the specified file does not exist (yet), it is created. |
|
353 // --------------------------------------------------------------------------- |
|
354 // |
|
355 void CVRMdaRecorder::AttachToMemoL( CVRMemo* aMemo ) |
|
356 { |
|
357 #ifdef _DEBUG |
|
358 RDebug::Print( _L( "CVRMdaRecorder::AttachToMemoL -enter" )); |
|
359 #endif |
|
360 |
|
361 // if error happen, attach will fail |
|
362 |
|
363 if( iIsAttachedToMemo ) |
|
364 { |
|
365 User::Panic( KVRPanic,EPanicAlreadyAttached ); |
|
366 } |
|
367 |
|
368 if( !aMemo ) |
|
369 { |
|
370 User::Panic( KVRPanic, KErrNotFound ); |
|
371 } |
|
372 |
|
373 iMemo = aMemo; |
|
374 |
|
375 // if the mmc card is full, should not attach to it |
|
376 |
|
377 RFs& fs( CEikonEnv::Static()->FsSession() ); |
|
378 |
|
379 |
|
380 // old storage system |
|
381 #ifndef RD_MULTIPLE_DRIVE |
|
382 if ( iMemo->MemoStore() == EMemoStorePhoneMemory ) |
|
383 { |
|
384 #ifdef __AAC_ENCODER_PLUGIN |
|
385 if (((iMemo->Quality() != EQualityHigh) && SysUtil::FFSSpaceBelowCriticalLevelL( &fs, KVRRecStartMemBuf )) || |
|
386 ((iMemo->Quality() == EQualityHigh) && SysUtil::FFSSpaceBelowCriticalLevelL( &fs, KVRAACCriticalMemoryLevel ))) |
|
387 #else |
|
388 // now AAC format is not enabled |
|
389 if (SysUtil::FFSSpaceBelowCriticalLevelL( &fs, KVRRecStartMemBuf )) |
|
390 #endif |
|
391 { |
|
392 VRUtils::ShowMemoryFullConfirmationQuery(); |
|
393 if(GetInRecordingFlag()) |
|
394 { |
|
395 SetInRecordingFlag(EFalse); |
|
396 } |
|
397 } |
|
398 |
|
399 } |
|
400 |
|
401 // MMC card |
|
402 else |
|
403 { |
|
404 #ifdef __AAC_ENCODER_PLUGIN |
|
405 if (((iMemo->Quality() != EQualityHigh) && SysUtil::MMCSpaceBelowCriticalLevelL( &fs, KVRRecStartMemBuf )) || |
|
406 ((iMemo->Quality() == EQualityHigh) && SysUtil::MMCSpaceBelowCriticalLevelL( &fs, KVRAACCriticalMemoryLevel ))) |
|
407 #else |
|
408 // now AAC format is not enabled |
|
409 if (SysUtil::FFSSpaceBelowCriticalLevelL( &fs, KVRRecStartMemBuf )) |
|
410 #endif |
|
411 { |
|
412 VRUtils::ShowMemoryFullConfirmationQuery(ETrue); |
|
413 |
|
414 if(GetInRecordingFlag()) |
|
415 { |
|
416 SetInRecordingFlag(EFalse); |
|
417 } |
|
418 } |
|
419 } |
|
420 |
|
421 // now multiple drives |
|
422 #else |
|
423 |
|
424 #ifdef __AAC_ENCODER_PLUGIN |
|
425 if (((iMemo->Quality() != EQualityHigh) && SysUtil::DiskSpaceBelowCriticalLevelL( &fs, KVRRecStartMemBuf, iMemo->StorageDrive())) || |
|
426 ((iMemo->Quality() == EQualityHigh) && SysUtil::DiskSpaceBelowCriticalLevelL( &fs, KVRAACCriticalMemoryLevel, iMemo->StorageDrive()))) |
|
427 #else |
|
428 // now AAC format is not enabled |
|
429 if (SysUtil::DiskSpaceBelowCriticalLevelL( &fs, KVRRecStartMemBuf, iMemo->StorageDrive())) |
|
430 #endif |
|
431 |
|
432 { |
|
433 //mmc card |
|
434 if ( iMemo->StorageDrive() == VRUtils::GetRemovableMassStorageL()) |
|
435 { |
|
436 VRUtils::ShowMemoryFullConfirmationQuery(ETrue); |
|
437 } |
|
438 else |
|
439 { |
|
440 VRUtils::ShowMemoryFullConfirmationQuery(); |
|
441 } |
|
442 if(GetInRecordingFlag()) |
|
443 { |
|
444 SetInRecordingFlag(EFalse); |
|
445 } |
|
446 } |
|
447 |
|
448 |
|
449 #endif |
|
450 |
|
451 // opens an existing file or creates new |
|
452 iAudioRecorder->OpenFileL( iMemo->File() ); |
|
453 |
|
454 iAttachingToMemo = ETrue; |
|
455 |
|
456 if( !iActiveWait.IsStarted() ) |
|
457 { |
|
458 #ifdef _DEBUG |
|
459 RDebug::Print( _L( "CVRMdaRecorder::AttachToMemoL::AWaitStarting...")); |
|
460 #endif |
|
461 iActiveWait.Start(); // CSI: 10 # |
|
462 |
|
463 #ifdef _DEBUG |
|
464 RDebug::Print( _L( "CVRMdaRecorder::AttachToMemoL::AWResuming...[%d]"), iMediaServerError); |
|
465 #endif |
|
466 } |
|
467 |
|
468 User::LeaveIfError( iMediaServerError ); |
|
469 |
|
470 |
|
471 |
|
472 /* |
|
473 if( !iActiveWait.IsStarted() ) |
|
474 { |
|
475 RDebug::Print( _L( "CVRMdaRecorder::AttachToMemoL::AWaitStarting...")); |
|
476 iActiveWait.Start(); // CSI: 10 # |
|
477 RDebug::Print( _L( "CVRMdaRecorder::AttachToMemoL::AWResuming...[%d]"), iMediaServerError); |
|
478 } |
|
479 |
|
480 User::LeaveIfError( iMediaServerError ); |
|
481 |
|
482 // Configure bitrate if recording an AMR clip. |
|
483 // Default bitrate is 12200 and it's used if codec doesn't support |
|
484 // the bitrate that is retrieved from Central Repository. |
|
485 if (iMemo->Quality() == EQualityMMSOptimized ) |
|
486 { |
|
487 TUint configuredAmrBitrate( VRUtils::AMRBitrateL() ); |
|
488 TUint amrBitrate( KVRDefaultAmrBitrate ); |
|
489 |
|
490 // Fetch supported bitrates and find out if configured bitrate |
|
491 // is supported |
|
492 RArray<TUint> rates; |
|
493 iAudioRecorder->GetSupportedBitRatesL( rates ); |
|
494 TInt num = rates.Count(); |
|
495 if(num > 0) |
|
496 { |
|
497 rates.Sort(); |
|
498 TInt found = rates.Find(configuredAmrBitrate); |
|
499 if (found == KErrNotFound) |
|
500 { |
|
501 amrBitrate = rates[num-1]; |
|
502 } |
|
503 } |
|
504 rates.Reset(); // Clear array |
|
505 iAudioRecorder->SetDestinationBitRateL( amrBitrate ); |
|
506 } |
|
507 |
|
508 |
|
509 // added for supporting mp4 format |
|
510 #ifdef __AAC_ENCODER_PLUGIN |
|
511 else if (iMemo->Quality() == EQualityHigh) |
|
512 { |
|
513 |
|
514 TInt configuredAacSamplerate( VRUtils::AACSamplerateL() ); |
|
515 TInt aacSampleRate( KVRDefaultSamplerateAac ); |
|
516 |
|
517 TInt configuredAacBitrate( VRUtils::AACBitrateL() ); |
|
518 TInt aacBitrate( KVRDefaultBitrateAac ); |
|
519 |
|
520 TInt configuredAudioMode( VRUtils::AACAudioModeL() ); |
|
521 |
|
522 // Sample rate |
|
523 RArray<TUint> supportedSampleRates; |
|
524 #ifdef _DEBUG |
|
525 RDebug::Print( _L( "CVRMdaRecorder::AttachToMemoL-GetSupportedSampleRatesL -before" )); |
|
526 #endif |
|
527 iAudioRecorder->GetSupportedSampleRatesL(supportedSampleRates); |
|
528 |
|
529 #ifdef _DEBUG |
|
530 RDebug::Print( _L( "CVRMdaRecorder::AttachToMemoL-GetSupportedSampleRatesL -after" )); |
|
531 #endif |
|
532 |
|
533 TInt num1 = supportedSampleRates.Count(); |
|
534 if(num1 > 0) |
|
535 { |
|
536 supportedSampleRates.Sort(); |
|
537 TInt found1 = supportedSampleRates.Find(configuredAacSamplerate); |
|
538 if (found1 == KErrNotFound) |
|
539 { |
|
540 aacSampleRate = supportedSampleRates[num1-1]; |
|
541 } |
|
542 } |
|
543 |
|
544 supportedSampleRates.Reset(); |
|
545 #ifdef _DEBUG |
|
546 RDebug::Print( _L( "CVRMdaRecorder::AttachToMemoL-SetDestinationSampleRateL -before, sampleRate is %d"), aacSampleRate); |
|
547 #endif |
|
548 iAudioRecorder->SetDestinationSampleRateL(aacSampleRate); |
|
549 |
|
550 #ifdef _DEBUG |
|
551 RDebug::Print( _L( "CVRMdaRecorder::AttachToMemoL-SetDestinationSampleRateL -after" )); |
|
552 #endif |
|
553 |
|
554 |
|
555 // Bit reate |
|
556 RArray<TUint> supportedBitRates; |
|
557 |
|
558 #ifdef _DEBUG |
|
559 RDebug::Print( _L( "CVRMdaRecorder::AttachToMemoL-GetSupportedBitRatesL -before" )); |
|
560 #endif |
|
561 iAudioRecorder->GetSupportedBitRatesL(supportedBitRates); |
|
562 |
|
563 #ifdef _DEBUG |
|
564 RDebug::Print( _L( "CVRMdaRecorder::AttachToMemoL-GetSupportedBitRatesL -after" )); |
|
565 #endif |
|
566 |
|
567 TInt num2 = supportedBitRates.Count(); |
|
568 if(num2 > 0) |
|
569 { |
|
570 supportedBitRates.Sort(); |
|
571 TInt found2 = supportedBitRates.Find(configuredAacBitrate); |
|
572 if (found2 == KErrNotFound) |
|
573 { |
|
574 aacBitrate = supportedBitRates[num2-1]; |
|
575 } |
|
576 } |
|
577 |
|
578 supportedBitRates.Reset(); |
|
579 |
|
580 #ifdef _DEBUG |
|
581 RDebug::Print( _L( "CVRMdaRecorder::AttachToMemoL-SetDestinationBitRateL -before, bitrate is %d"), aacBitrate); |
|
582 #endif |
|
583 iAudioRecorder->SetDestinationBitRateL(aacBitrate); |
|
584 |
|
585 #ifdef _DEBUG |
|
586 RDebug::Print( _L( "CVRMdaRecorder::AttachToMemoL-SetDestinationBitRateL -after" )); |
|
587 #endif |
|
588 |
|
589 // the audio mode flag |
|
590 |
|
591 #ifdef _DEBUG |
|
592 RDebug::Print( _L( "CVRMdaRecorder::AttachToMemoL-GetSupportedNumberOfChannelsL -before" )); |
|
593 #endif |
|
594 RArray<TUint> supportedNumberOfChannels; |
|
595 iAudioRecorder->GetSupportedNumberOfChannelsL(supportedNumberOfChannels); |
|
596 TInt num3 = supportedNumberOfChannels.Count(); |
|
597 if (num3 > 0) |
|
598 { |
|
599 supportedNumberOfChannels.Sort(); |
|
600 TInt ifFound = supportedNumberOfChannels.Find(configuredAudioMode); |
|
601 if (ifFound == KErrNotFound) |
|
602 { |
|
603 configuredAudioMode = supportedNumberOfChannels [0]; |
|
604 } |
|
605 } |
|
606 supportedNumberOfChannels.Reset(); |
|
607 iAudioRecorder->SetDestinationNumberOfChannelsL(configuredAudioMode); |
|
608 |
|
609 } |
|
610 #endif |
|
611 iIsAttachedToMemo = ETrue; |
|
612 ResetPosition(); |
|
613 */ |
|
614 |
|
615 #ifdef _DEBUG |
|
616 RDebug::Print( _L( "CVRMdaRecorder::AttachToMemoL -exit" )); |
|
617 #endif |
|
618 } |
|
619 |
|
620 |
|
621 // --------------------------------------------------------------------------- |
|
622 // CVRMdaRecorder::CreateNewMemoL |
|
623 // |
|
624 // --------------------------------------------------------------------------- |
|
625 // |
|
626 void CVRMdaRecorder::CreateNewMemoL( CVRMemo* aMemo ) |
|
627 { |
|
628 iMemo = aMemo; |
|
629 iAudioRecorder->OpenFileL( aMemo->File() ); |
|
630 if ( !iActiveWait.IsStarted() ) |
|
631 { |
|
632 iActiveWait.Start(); // CSI: 10 # |
|
633 } |
|
634 User::LeaveIfError( iMediaServerError ); |
|
635 } |
|
636 |
|
637 |
|
638 // --------------------------------------------------------------------------- |
|
639 // CVRMdaRecorder::DetachMemo |
|
640 // |
|
641 // --------------------------------------------------------------------------- |
|
642 // |
|
643 void CVRMdaRecorder::DetachMemo() |
|
644 { |
|
645 if ( iIsAttachedToMemo ) |
|
646 { |
|
647 Stop(); |
|
648 //Need to delete iAudioInput before close!!! |
|
649 DeleteAudioInput(); |
|
650 |
|
651 iAudioRecorder->Close(); |
|
652 |
|
653 iMemo = NULL; |
|
654 iIsAttachedToMemo = EFalse; |
|
655 } |
|
656 } |
|
657 |
|
658 |
|
659 // --------------------------------------------------------------------------- |
|
660 // CVRMdaRecorder::SetVolume |
|
661 // |
|
662 // --------------------------------------------------------------------------- |
|
663 // |
|
664 void CVRMdaRecorder::SetVolume( TInt aStep, TInt aMaxSteps ) |
|
665 { |
|
666 if ( iIsAttachedToMemo ) |
|
667 { |
|
668 // On device, MaxVolume() typically returns 9. |
|
669 TInt maxVolume( iAudioRecorder->MaxVolume() ); |
|
670 TInt volume = maxVolume * aStep / aMaxSteps; |
|
671 |
|
672 // Just to make sure that volume is between 0 .. MaxVolume |
|
673 if ( volume < 0) |
|
674 { |
|
675 volume = 0; |
|
676 } |
|
677 else if ( volume > maxVolume ) |
|
678 { |
|
679 volume = maxVolume; |
|
680 } |
|
681 |
|
682 #ifdef _DEBUG |
|
683 RDebug::Print( _L( "VoiceRecorder: Set volume: %d, max volume: %d" ), |
|
684 volume, maxVolume ); |
|
685 #endif |
|
686 iAudioRecorder->SetVolume( volume ); |
|
687 } |
|
688 } |
|
689 |
|
690 |
|
691 // --------------------------------------------------------------------------- |
|
692 // CVRMdaRecorder::PlayL |
|
693 // |
|
694 // --------------------------------------------------------------------------- |
|
695 // |
|
696 TInt CVRMdaRecorder::PlayL() |
|
697 { |
|
698 __ASSERT_DEBUG( iIsAttachedToMemo, User::Panic( KVRPanic, |
|
699 EPanicNotAttached ) ); |
|
700 |
|
701 if( iPause ) |
|
702 { |
|
703 iAudioRecorder->SetPosition( iPosition ); |
|
704 iPosition = 0; |
|
705 iPause = EFalse; |
|
706 } |
|
707 |
|
708 // This line was added to prevent MMF crash, remove it when play works |
|
709 // without this |
|
710 iAudioRecorder->SetPlaybackBalance( KMMFBalanceCenter ); |
|
711 |
|
712 SetIfStopCalled(EFalse); |
|
713 iAudioRecorder->PlayL(); |
|
714 |
|
715 User::LeaveIfError( iPropVRState.Set( KPSUidVoiceRecorder, |
|
716 KVoiceRecorderMode, EVRPlaying ) ); |
|
717 |
|
718 // Do not allow screen saver while playing |
|
719 // Errors ignored, no actions needed if API is not available |
|
720 iPropScreenSaver.Set( KPSUidScreenSaver, |
|
721 KScreenSaverAllowScreenSaver, EVRScreenSaverNotAllowed ); |
|
722 |
|
723 if( !iActiveWait.IsStarted() ) |
|
724 { |
|
725 iActiveWait.Start(); // CSI: 10 # |
|
726 } |
|
727 StartTimerL(); |
|
728 return iMediaServerError; |
|
729 } |
|
730 |
|
731 // --------------------------------------------------------------------------- |
|
732 // CVRMdaRecorder::RecordL |
|
733 // Starts the recording of a sound clip. Checks the memory space situation |
|
734 // and plays start tone before starting recording. |
|
735 // --------------------------------------------------------------------------- |
|
736 // |
|
737 TInt CVRMdaRecorder::RecordL() |
|
738 { |
|
739 // If we receive record command and file is not opened yet. wait for file |
|
740 // to be opened and then resume. |
|
741 if ( !iIsAttachedToMemo && iAttachingToMemo && !iActiveWait.IsStarted() ) |
|
742 { |
|
743 iActiveWait.Start(); |
|
744 User::LeaveIfError( iMediaServerError ); |
|
745 } |
|
746 |
|
747 __ASSERT_DEBUG( iIsAttachedToMemo, User::Panic( KVRPanic, |
|
748 EPanicNotAttached ) ); |
|
749 TBool wasPaused( iPause ); |
|
750 iPause = EFalse; |
|
751 |
|
752 // Check if available memory is/goes below critical level |
|
753 // in that case record is not performed |
|
754 // KVRRecStartMemBuf should be size of 60 sec AMR and 5 sec WAV |
|
755 // New max time estimation for WAV is calculated after 5 secs |
|
756 RFs& fs( CEikonEnv::Static()->FsSession() ); |
|
757 |
|
758 TBool critical( EFalse ); |
|
759 |
|
760 // the current storage system (phone memory and mmc card) |
|
761 #ifndef RD_MULTIPLE_DRIVE |
|
762 if ( iMemo->MemoStore() == EMemoStorePhoneMemory ) |
|
763 { |
|
764 #ifdef __AAC_ENCODER_PLUGIN |
|
765 if (((iMemo->Quality() != EQualityHigh) && SysUtil::FFSSpaceBelowCriticalLevelL( &fs, KVRRecStartMemBuf )) || |
|
766 ((iMemo->Quality() == EQualityHigh) && SysUtil::FFSSpaceBelowCriticalLevelL( &fs, KVRAACCriticalMemoryLevel ))) |
|
767 #else |
|
768 // now AAC format is not enabled |
|
769 if (SysUtil::FFSSpaceBelowCriticalLevelL( &fs, KVRRecStartMemBuf )) |
|
770 #endif |
|
771 { |
|
772 VRUtils::ShowMemoryFullConfirmationQuery(); |
|
773 critical = ETrue; |
|
774 } |
|
775 } |
|
776 |
|
777 // MMC card |
|
778 else |
|
779 { |
|
780 #ifdef __AAC_ENCODER_PLUGIN |
|
781 if (((iMemo->Quality() != EQualityHigh) && SysUtil::MMCSpaceBelowCriticalLevelL( &fs, KVRRecStartMemBuf )) || |
|
782 ((iMemo->Quality() == EQualityHigh) && SysUtil::MMCSpaceBelowCriticalLevelL( &fs, KVRAACCriticalMemoryLevel ))) |
|
783 #else |
|
784 // now AAC format is not enabled |
|
785 if (SysUtil::MMCSpaceBelowCriticalLevelL( &fs, KVRRecStartMemBuf )) |
|
786 #endif |
|
787 { |
|
788 VRUtils::ShowMemoryFullConfirmationQuery( ETrue ); |
|
789 critical = ETrue; |
|
790 } |
|
791 |
|
792 } |
|
793 |
|
794 // now for multiple drives |
|
795 #else |
|
796 #ifdef __AAC_ENCODER_PLUGIN |
|
797 if (((iMemo->Quality() != EQualityHigh) && SysUtil::DiskSpaceBelowCriticalLevelL( &fs, KVRRecStartMemBuf, iMemo->StorageDrive())) || |
|
798 ((iMemo->Quality() == EQualityHigh) && SysUtil::DiskSpaceBelowCriticalLevelL( &fs, KVRAACCriticalMemoryLevel, iMemo->StorageDrive()))) |
|
799 #else |
|
800 // now AAC format is not enabled |
|
801 if (SysUtil::DiskSpaceBelowCriticalLevelL( &fs, KVRRecStartMemBuf, iMemo->StorageDrive())) |
|
802 #endif |
|
803 { |
|
804 if ( iMemo->StorageDrive() == VRUtils::GetRemovableMassStorageL()) |
|
805 { |
|
806 VRUtils::ShowMemoryFullConfirmationQuery(ETrue); |
|
807 } |
|
808 else |
|
809 { |
|
810 VRUtils::ShowMemoryFullConfirmationQuery(); |
|
811 } |
|
812 critical = ETrue; |
|
813 } |
|
814 |
|
815 |
|
816 #endif |
|
817 |
|
818 if( critical ) |
|
819 { |
|
820 User::Leave( KErrDiskFull ); |
|
821 } |
|
822 |
|
823 |
|
824 if ( !wasPaused ) |
|
825 { |
|
826 iTonePlayer->PlayTone( EAvkonSIDVoiceRecordingStartTone ); |
|
827 iTonePlayer->PrepareToneL( EAvkonSIDVoiceRecordingStopTone ); |
|
828 } |
|
829 |
|
830 // start monitor disk space |
|
831 #ifdef __AAC_ENCODER_PLUGIN |
|
832 if (iMemo->Quality() == EQualityHigh) |
|
833 { |
|
834 TInt drive (0); |
|
835 #ifndef RD_MULTIPLE_DRIVE |
|
836 if ( iMemo->MemoStore() == EMemoStorePhoneMemory ) |
|
837 { |
|
838 drive = EDriveC; |
|
839 } |
|
840 else |
|
841 { |
|
842 drive = EDriveE; |
|
843 } |
|
844 // multiple drives |
|
845 #else |
|
846 drive = iMemo->StorageDrive(); |
|
847 #endif |
|
848 |
|
849 iDiskSpaceWatcher->RequestNotification(KVRAACCriticalMemoryLevel,drive); |
|
850 } |
|
851 #endif |
|
852 |
|
853 // Set recording preference |
|
854 iAudioRecorder->SetPriority( KAudioPriorityRecording, |
|
855 TMdaPriorityPreference( KAudioPrefVoiceRec ) ); |
|
856 iAudioRecorder->SetGain( iAudioRecorder->MaxGain() ); |
|
857 |
|
858 SetIfStopCalled(EFalse); |
|
859 |
|
860 iAudioRecorder->RecordL(); |
|
861 |
|
862 // Sets the indication that recording has started -> |
|
863 // Current file's handle can't be reused for next file |
|
864 iMemo->SetRecorded( ETrue ); |
|
865 |
|
866 |
|
867 User::LeaveIfError( iPropVRState.Set( KPSUidVoiceRecorder, |
|
868 KVoiceRecorderMode, EVRRecording ) ); |
|
869 |
|
870 // Do not allow screen saver while recording |
|
871 // Errors ignored, no actions needed if API is not available |
|
872 iPropScreenSaver.Set( KPSUidScreenSaver, KScreenSaverAllowScreenSaver, |
|
873 EVRScreenSaverNotAllowed ); |
|
874 |
|
875 if( !iActiveWait.IsStarted() ) |
|
876 { |
|
877 iActiveWait.Start(); // CSI: 10 # |
|
878 } |
|
879 StartTimerL(); |
|
880 |
|
881 return iMediaServerError; |
|
882 } |
|
883 |
|
884 |
|
885 // --------------------------------------------------------------------------- |
|
886 // CVRMdaRecorder::Stop |
|
887 // |
|
888 // --------------------------------------------------------------------------- |
|
889 // |
|
890 void CVRMdaRecorder::Stop() |
|
891 { |
|
892 if ( iIsAttachedToMemo ) |
|
893 { |
|
894 TBool reallyStopping( iPause ); |
|
895 #ifdef _DEBUG |
|
896 RDebug::Print( _L( "VoiceRecorder: Stop error: %d" ), |
|
897 iMediaServerError ); |
|
898 #endif |
|
899 iPause = EFalse; |
|
900 |
|
901 if( iAudioRecorder->State() == CMdaAudioRecorderUtility::ERecording ) |
|
902 { |
|
903 reallyStopping = ETrue; |
|
904 |
|
905 // if the dim light is on, turn off it. |
|
906 if(iDimLight) |
|
907 { |
|
908 |
|
909 iLight->ReleaseLight (CHWRMLight::EPrimaryDisplay); |
|
910 User::ResetInactivityTime(); |
|
911 iDimLight = EFalse; |
|
912 } |
|
913 |
|
914 } |
|
915 // it will tell VRecorder not pause because it has been stopped. |
|
916 SetIfStopCalled(ETrue); |
|
917 iAudioRecorder->Stop(); |
|
918 |
|
919 // if error does not happen in recording, change the file to visible |
|
920 iMemo->File().SetAtt( KEntryAttNormal, KEntryAttHidden); |
|
921 |
|
922 iTonePlayer->PlayTone( EAvkonSIDVoiceRecordingStopTone ); |
|
923 iTonePlayer->PrepareTone( EAvkonSIDVoiceRecordingStartTone ); |
|
924 |
|
925 if( ( iAudioRecorder->State() == CMdaAudioRecorderUtility::EOpen ) || |
|
926 reallyStopping ) |
|
927 { |
|
928 // Set lower preference to ensure other sounds will |
|
929 // be played correctly |
|
930 iAudioRecorder->SetPriority( KAudioPriorityRecording, |
|
931 TMdaPriorityPreference( KAudioPrefRealOneLocalPlayback ) ); |
|
932 } |
|
933 |
|
934 // Error value ignored if PS key is not available |
|
935 iPropVRState.Set( KPSUidVoiceRecorder, KVoiceRecorderMode, EVRIdle ); |
|
936 // Used to check the state of a phone call if any |
|
937 |
|
938 if ( iCurrentCallHandler ) |
|
939 { |
|
940 delete iCurrentCallHandler; |
|
941 iCurrentCallHandler = NULL; |
|
942 } |
|
943 |
|
944 TRAP_IGNORE( iCurrentCallHandler = CVRSystemEventHandler::NewL() ); |
|
945 TInt currentState( 0 ); |
|
946 TRAP_IGNORE( currentState = iCurrentCallHandler->StateL( KPSUidCtsyCallInformation, KCTsyCallState ) ); |
|
947 |
|
948 // Do not allow screen saver if there is an active phone call |
|
949 if(currentState == EPSCTsyCallStateRinging) |
|
950 { |
|
951 // Do not allow screen saver |
|
952 // Errors ignored, no actions needed if API is not available |
|
953 iPropScreenSaver.Set( KPSUidScreenSaver, |
|
954 KScreenSaverAllowScreenSaver, EVRScreenSaverNotAllowed ); |
|
955 } |
|
956 else |
|
957 { |
|
958 // Allow screen saver |
|
959 // Errors ignored, no actions needed if API is not available |
|
960 iPropScreenSaver.Set( KPSUidScreenSaver, |
|
961 KScreenSaverAllowScreenSaver, EVRScreenSaverAllowed ); |
|
962 } |
|
963 |
|
964 StopTimer(); |
|
965 ResetPosition(); |
|
966 iMemo->UpdateModifiedDate(); |
|
967 } |
|
968 } |
|
969 |
|
970 |
|
971 // --------------------------------------------------------------------------- |
|
972 // CVRMdaRecorder::StopAndNotify |
|
973 // |
|
974 // --------------------------------------------------------------------------- |
|
975 // |
|
976 void CVRMdaRecorder::StopAndNotify() |
|
977 { |
|
978 Stop(); |
|
979 if ( iAutoStopObserver ) |
|
980 { |
|
981 #ifdef _DEBUG |
|
982 RDebug::Print( _L( "VoiceRecorder: StopAndNotify AutoStopObserver: %d" ), |
|
983 iMediaServerError ); |
|
984 #endif |
|
985 iAutoStopObserver->Update(); |
|
986 #ifdef _DEBUG |
|
987 RDebug::Print( _L( "VoiceRecorder: StopAndNotify AutoStopObserver: %d" ), |
|
988 iMediaServerError ); |
|
989 #endif |
|
990 } |
|
991 } |
|
992 |
|
993 |
|
994 // --------------------------------------------------------------------------- |
|
995 // CVRMdaRecorder::Pause |
|
996 // |
|
997 // --------------------------------------------------------------------------- |
|
998 void CVRMdaRecorder::Pause() |
|
999 { |
|
1000 __ASSERT_DEBUG( iIsAttachedToMemo, User::Panic( KVRPanic, |
|
1001 EPanicNotAttached ) ); |
|
1002 |
|
1003 iPause = ETrue; |
|
1004 |
|
1005 #ifdef _DEBUG |
|
1006 RDebug::Print( _L("VoiceRecorder: Pause called. Position: %d:%d"), |
|
1007 I64HIGH( iPosition.Int64() ), I64LOW( iPosition.Int64() ) ); |
|
1008 #endif |
|
1009 |
|
1010 iAudioRecorder->Stop(); |
|
1011 |
|
1012 // Error value ignored if PS key is not available |
|
1013 iPropVRState.Set( KPSUidVoiceRecorder, KVoiceRecorderMode, EVRIdle ); |
|
1014 |
|
1015 // Don't allow screen saver |
|
1016 // Errors ignored, no actions needed if API is not available |
|
1017 iPropScreenSaver.Set( KPSUidScreenSaver, |
|
1018 KScreenSaverAllowScreenSaver, EVRScreenSaverAllowed ); |
|
1019 |
|
1020 StopTimer(); |
|
1021 SyncAndNotify(); |
|
1022 } |
|
1023 |
|
1024 |
|
1025 // --------------------------------------------------------------------------- |
|
1026 // CVRMdaRecorder::ForwardL |
|
1027 // |
|
1028 // --------------------------------------------------------------------------- |
|
1029 // |
|
1030 TInt CVRMdaRecorder::ForwardL() |
|
1031 { |
|
1032 if ( !MovePositionL( KVRMdaRecorderDefaultStep ) ) |
|
1033 { |
|
1034 return KErrOverflow; |
|
1035 } |
|
1036 return iMediaServerError; |
|
1037 } |
|
1038 |
|
1039 |
|
1040 // --------------------------------------------------------------------------- |
|
1041 // CVRMdaRecorder::RewindL |
|
1042 // |
|
1043 // --------------------------------------------------------------------------- |
|
1044 // |
|
1045 TInt CVRMdaRecorder::RewindL() |
|
1046 { |
|
1047 MovePositionL( -KVRMdaRecorderDefaultStep ); |
|
1048 return iMediaServerError; |
|
1049 } |
|
1050 |
|
1051 |
|
1052 // --------------------------------------------------------------------------- |
|
1053 // CVRMdaRecorder::CanAcceptCommands |
|
1054 // |
|
1055 // --------------------------------------------------------------------------- |
|
1056 // |
|
1057 TBool CVRMdaRecorder::CanAcceptCommands() const |
|
1058 { |
|
1059 return !iActiveWait.IsStarted(); |
|
1060 } |
|
1061 |
|
1062 |
|
1063 // --------------------------------------------------------------------------- |
|
1064 // CVRMdaRecorder::MovePositionL |
|
1065 // |
|
1066 // --------------------------------------------------------------------------- |
|
1067 // |
|
1068 TBool CVRMdaRecorder::MovePositionL( TInt aSeconds ) |
|
1069 { |
|
1070 __ASSERT_DEBUG( iIsAttachedToMemo, User::Panic( KVRPanic, |
|
1071 EPanicNotAttached ) ); |
|
1072 |
|
1073 #ifdef _DEBUG |
|
1074 RDebug::Print( _L("VoiceRecorder: MovePosition called. Base position: %d:%d"), |
|
1075 I64HIGH( iAudioRecorder->Position().Int64() ), |
|
1076 I64LOW( iAudioRecorder->Position().Int64() ) ); |
|
1077 #endif |
|
1078 |
|
1079 TInt64 interval; |
|
1080 if (iPause) |
|
1081 { |
|
1082 interval = iPosition.Int64() + aSeconds * KVRSecondAsMicroSeconds; |
|
1083 } |
|
1084 // Not sure if iPosition value is valid other than when paused, so do as |
|
1085 // previous for all other states: |
|
1086 else |
|
1087 { |
|
1088 interval = iAudioRecorder->Position().Int64() + |
|
1089 aSeconds * |
|
1090 KVRSecondAsMicroSeconds; |
|
1091 } |
|
1092 |
|
1093 // Truncated to integer values |
|
1094 TInt integerInterval( interval / KVRSecondAsMicroSeconds ); |
|
1095 TInt integerDuration( iAudioRecorder->Duration().Int64() / |
|
1096 KVRSecondAsMicroSeconds ); |
|
1097 if ( interval < 0 ) |
|
1098 { |
|
1099 interval = 0; |
|
1100 } |
|
1101 // if gone past the end or integer values are the same |
|
1102 // in duration and position |
|
1103 else if ( interval > iAudioRecorder->Duration().Int64() || |
|
1104 integerInterval == integerDuration ) |
|
1105 { |
|
1106 interval = iAudioRecorder->Duration().Int64(); |
|
1107 } |
|
1108 |
|
1109 #ifdef _DEBUG |
|
1110 RDebug::Print( _L("VoiceRecorder: MovePosition called. Interval: %d:%d"), |
|
1111 I64HIGH( interval ), I64LOW( interval ) ); |
|
1112 #endif |
|
1113 |
|
1114 TTimeIntervalMicroSeconds newPosition( interval ); |
|
1115 |
|
1116 if (iPause) |
|
1117 { |
|
1118 iPosition = newPosition; |
|
1119 } |
|
1120 else if ( iAudioRecorder->State() == CMdaAudioClipUtility::EOpen ) |
|
1121 { |
|
1122 // not playing, recording or paused. |
|
1123 #ifdef _DEBUG |
|
1124 RDebug::Print( _L("VoiceRecorder. Idle.: MovePosition called. New Position: %d:%d"), |
|
1125 I64HIGH( newPosition.Int64() ), I64LOW( newPosition.Int64() ) ); |
|
1126 #endif |
|
1127 iAudioRecorder->SetPosition( newPosition ); |
|
1128 } |
|
1129 else |
|
1130 { |
|
1131 |
|
1132 #ifdef _DEBUG |
|
1133 RDebug::Print( _L("VoiceRecorder. Playing.: MovePosition called. New Position: %d:%d"), |
|
1134 I64HIGH( newPosition.Int64() ), I64LOW( newPosition.Int64() ) ); |
|
1135 #endif |
|
1136 |
|
1137 iAudioRecorder->Stop(); |
|
1138 iAudioRecorder->SetPosition( newPosition ); |
|
1139 iAudioRecorder->PlayL(); |
|
1140 if( !iActiveWait.IsStarted() ) |
|
1141 { |
|
1142 iActiveWait.Start(); // CSI: 10 # |
|
1143 } |
|
1144 } |
|
1145 SyncAndNotify(); |
|
1146 return ETrue; |
|
1147 } |
|
1148 |
|
1149 // --------------------------------------------------------------------------- |
|
1150 // CVRMdaRecorder::ConfigureMemoL() |
|
1151 // |
|
1152 // --------------------------------------------------------------------------- |
|
1153 // |
|
1154 void CVRMdaRecorder::ConfigureMemoL() |
|
1155 { |
|
1156 DEB_PRN_0( _L( "CVRMdaRecorder::ConfigureMemoL-Enter" )); |
|
1157 |
|
1158 // Configure bitrate if recording an AMR clip. |
|
1159 // Default bitrate is 12200 and it's used if codec doesn't support |
|
1160 // the bitrate that is retrieved from Central Repository. |
|
1161 if (iMemo->Quality() == EQualityMMSOptimized ) |
|
1162 { |
|
1163 TUint configuredAmrBitrate( VRUtils::AMRBitrateL() ); |
|
1164 TUint amrBitrate( KVRDefaultAmrBitrate ); |
|
1165 |
|
1166 // Fetch supported bitrates and find out if configured bitrate |
|
1167 // is supported |
|
1168 RArray<TUint> rates; |
|
1169 iAudioRecorder->GetSupportedBitRatesL( rates ); |
|
1170 TInt num = rates.Count(); |
|
1171 if(num > 0) |
|
1172 { |
|
1173 rates.Sort(); |
|
1174 TInt found = rates.Find(configuredAmrBitrate); |
|
1175 if (found == KErrNotFound) |
|
1176 { |
|
1177 amrBitrate = rates[num-1]; |
|
1178 } |
|
1179 } |
|
1180 rates.Reset(); // Clear array |
|
1181 iAudioRecorder->SetDestinationBitRateL( amrBitrate ); |
|
1182 |
|
1183 DEB_PRN_0( _L( "CVRMdaRecorder::ConfigureMemoL-Configured MMSOpt bitrate" )); |
|
1184 } |
|
1185 |
|
1186 |
|
1187 // added for supporting mp4 format |
|
1188 #ifdef __AAC_ENCODER_PLUGIN |
|
1189 else if (iMemo->Quality() == EQualityHigh) |
|
1190 { |
|
1191 TInt configuredAacSamplerate( VRUtils::AACSamplerateL() ); |
|
1192 TInt aacSampleRate( KVRDefaultSamplerateAac ); |
|
1193 |
|
1194 TInt configuredAacBitrate( VRUtils::AACBitrateL() ); |
|
1195 TInt aacBitrate( KVRDefaultBitrateAac ); |
|
1196 |
|
1197 TInt configuredAudioMode( VRUtils::AACAudioModeL() ); |
|
1198 |
|
1199 // Sample rate |
|
1200 RArray<TUint> supportedSampleRates; |
|
1201 iAudioRecorder->GetSupportedSampleRatesL(supportedSampleRates); |
|
1202 |
|
1203 TInt num1 = supportedSampleRates.Count(); |
|
1204 if(num1 > 0) |
|
1205 { |
|
1206 supportedSampleRates.Sort(); |
|
1207 TInt found1 = supportedSampleRates.Find(configuredAacSamplerate); |
|
1208 if (found1 == KErrNotFound) |
|
1209 { |
|
1210 aacSampleRate = supportedSampleRates[num1-1]; |
|
1211 } |
|
1212 } |
|
1213 supportedSampleRates.Reset(); |
|
1214 iAudioRecorder->SetDestinationSampleRateL(aacSampleRate); |
|
1215 |
|
1216 DEB_PRN_0( _L( "CVRMdaRecorder::ConfigureMemoL-Configured HiQ sampling rate" )); |
|
1217 |
|
1218 // Bit reate |
|
1219 RArray<TUint> supportedBitRates; |
|
1220 iAudioRecorder->GetSupportedBitRatesL(supportedBitRates); |
|
1221 TInt num2 = supportedBitRates.Count(); |
|
1222 if(num2 > 0) |
|
1223 { |
|
1224 supportedBitRates.Sort(); |
|
1225 TInt found2 = supportedBitRates.Find(configuredAacBitrate); |
|
1226 if (found2 == KErrNotFound) |
|
1227 { |
|
1228 aacBitrate = supportedBitRates[num2-1]; |
|
1229 } |
|
1230 } |
|
1231 supportedBitRates.Reset(); |
|
1232 iAudioRecorder->SetDestinationBitRateL(aacBitrate); |
|
1233 DEB_PRN_0( _L( "CVRMdaRecorder::ConfigureMemoL-Configured HiQ bit rate" )); |
|
1234 |
|
1235 // the audio mode flag |
|
1236 RArray<TUint> supportedNumberOfChannels; |
|
1237 iAudioRecorder->GetSupportedNumberOfChannelsL(supportedNumberOfChannels); |
|
1238 TInt num3 = supportedNumberOfChannels.Count(); |
|
1239 if (num3 > 0) |
|
1240 { |
|
1241 supportedNumberOfChannels.Sort(); |
|
1242 TInt ifFound = supportedNumberOfChannels.Find(configuredAudioMode); |
|
1243 if (ifFound == KErrNotFound) |
|
1244 { |
|
1245 configuredAudioMode = supportedNumberOfChannels [0]; |
|
1246 } |
|
1247 } |
|
1248 supportedNumberOfChannels.Reset(); |
|
1249 iAudioRecorder->SetDestinationNumberOfChannelsL(configuredAudioMode); |
|
1250 |
|
1251 DEB_PRN_0( _L( "CVRMdaRecorder::ConfigureMemoL-Configured HiQ channel" )); |
|
1252 } |
|
1253 #endif // __AAC_ENCODER_PLUGIN |
|
1254 iIsAttachedToMemo = ETrue; |
|
1255 ResetPosition(); |
|
1256 DEB_PRN_0( _L( "CVRMdaRecorder::ConfigureMemoL-Exit" )); |
|
1257 } |
|
1258 |
|
1259 // --------------------------------------------------------------------------- |
|
1260 // CVRMdaRecorder::ResetPosition |
|
1261 // |
|
1262 // --------------------------------------------------------------------------- |
|
1263 // |
|
1264 void CVRMdaRecorder::ResetPosition() |
|
1265 { |
|
1266 if ( iIsAttachedToMemo ) |
|
1267 { |
|
1268 iAudioRecorder->SetPosition( TTimeIntervalMicroSeconds( 0 ) ); |
|
1269 SyncAndNotify(); |
|
1270 } |
|
1271 } |
|
1272 |
|
1273 |
|
1274 // --------------------------------------------------------------------------- |
|
1275 // CVRMdaRecorder::StartTimerL |
|
1276 // Create and start a timer with initial delay of 0 |
|
1277 // and a frequency of one second |
|
1278 // --------------------------------------------------------------------------- |
|
1279 // |
|
1280 void CVRMdaRecorder::StartTimerL() |
|
1281 { |
|
1282 StopTimer(); // stop if already running |
|
1283 |
|
1284 TCallBack cb( TimerCallBack, this ); |
|
1285 iTimer = CPeriodic::NewL( 1 ); // priority = EPriorityNormal + 1 = 1 |
|
1286 iTimer->Start( 0, KVRDisplayUpdateDelay, cb ); |
|
1287 } |
|
1288 |
|
1289 |
|
1290 // --------------------------------------------------------------------------- |
|
1291 // CVRMdaRecorder::StopTimer |
|
1292 // Stop the timer by deleting the CPeriodic object |
|
1293 // --------------------------------------------------------------------------- |
|
1294 // |
|
1295 void CVRMdaRecorder::StopTimer() |
|
1296 { |
|
1297 delete iTimer; |
|
1298 iTimer = NULL; |
|
1299 } |
|
1300 |
|
1301 |
|
1302 // --------------------------------------------------------------------------- |
|
1303 // CVRMdaRecorder::SyncAndNotify |
|
1304 // |
|
1305 // --------------------------------------------------------------------------- |
|
1306 // |
|
1307 void CVRMdaRecorder::SyncAndNotify() |
|
1308 { |
|
1309 if(!iPause) |
|
1310 { |
|
1311 iPosition = iAudioRecorder->Position(); |
|
1312 } |
|
1313 iMemo->SetPosition( iPosition ); |
|
1314 |
|
1315 iMemo->SetDuration( iAudioRecorder->Duration() ); |
|
1316 |
|
1317 for ( int i = 0; i < iObservers.Count(); i++ ) |
|
1318 { |
|
1319 TVRUpdateCommand command( EVRUpdate ); |
|
1320 if ( ( iMemo->Position().Int64() / KVRSecondAsMicroSeconds ) == 1 ) |
|
1321 { |
|
1322 command = EVRUpdate1Second; |
|
1323 } |
|
1324 iObservers[ i ]->Update( command ); |
|
1325 } |
|
1326 } |
|
1327 |
|
1328 |
|
1329 // --------------------------------------------------------------------------- |
|
1330 // CVRMdaRecorder::TimerCallBack |
|
1331 // |
|
1332 // --------------------------------------------------------------------------- |
|
1333 // |
|
1334 TInt CVRMdaRecorder::TimerCallBack( TAny* aMdaRecorder ) |
|
1335 { |
|
1336 CVRMdaRecorder* recorder = reinterpret_cast< CVRMdaRecorder* >( |
|
1337 aMdaRecorder ); |
|
1338 recorder->HandleTick(); |
|
1339 return ETrue; |
|
1340 } |
|
1341 |
|
1342 |
|
1343 // --------------------------------------------------------------------------- |
|
1344 // CVRMdaRecorder::HandleTick |
|
1345 // |
|
1346 // --------------------------------------------------------------------------- |
|
1347 // |
|
1348 void CVRMdaRecorder::HandleTick() |
|
1349 { |
|
1350 SyncAndNotify(); |
|
1351 |
|
1352 if ( iAudioRecorder->State() == CMdaAudioClipUtility::ERecording ) |
|
1353 { |
|
1354 |
|
1355 TTimeIntervalMicroSeconds position( 0 ); |
|
1356 TTimeIntervalMicroSeconds duration( 0 ); |
|
1357 TTimeIntervalMicroSeconds maxDuration( 0 ); |
|
1358 |
|
1359 position = iMemo->Position(); |
|
1360 duration = iMemo->Duration(); |
|
1361 maxDuration = iMemo->MaxDuration(); |
|
1362 |
|
1363 // Position value is used for comparison because it gives more accurate |
|
1364 // value than Duration value |
|
1365 if ( position >= maxDuration ) |
|
1366 { |
|
1367 #ifdef _DEBUG |
|
1368 RDebug::Print( _L("VoiceRecorder: Max duration passed. Position: %d:%d"), |
|
1369 I64HIGH( position.Int64() ), I64LOW( position.Int64() ) ); |
|
1370 #endif |
|
1371 |
|
1372 #ifdef _DEBUG |
|
1373 RDebug::Print( _L("VoiceRecorder: Max duration passed. Duration: %d:%d"), |
|
1374 I64HIGH( duration.Int64() ), I64LOW( duration.Int64() ) ); |
|
1375 #endif |
|
1376 |
|
1377 #ifdef _DEBUG |
|
1378 RDebug::Print( _L("VoiceRecorder: Max duration passed. MaxDuration: %d:%d"), |
|
1379 I64HIGH( maxDuration.Int64() ), I64LOW( maxDuration.Int64() ) ); |
|
1380 #endif |
|
1381 // Note that some data cropping is possible after stopping |
|
1382 // ->Duration decreases |
|
1383 StopAndNotify(); |
|
1384 } |
|
1385 } |
|
1386 } |
|
1387 |
|
1388 |
|
1389 // --------------------------------------------------------------------------- |
|
1390 // CVRMdaRecorder::SetIhf |
|
1391 // |
|
1392 // --------------------------------------------------------------------------- |
|
1393 // |
|
1394 TInt CVRMdaRecorder::SetIhf( TBool /*aEnabled*/ ) |
|
1395 { |
|
1396 return KErrNotSupported; |
|
1397 } |
|
1398 |
|
1399 |
|
1400 // --------------------------------------------------------------------------- |
|
1401 // CVRMdaRecorder::SetPositionL |
|
1402 // |
|
1403 // --------------------------------------------------------------------------- |
|
1404 // |
|
1405 void CVRMdaRecorder::SetPositionL( TInt aSeconds ) |
|
1406 { |
|
1407 __ASSERT_DEBUG( iIsAttachedToMemo, User::Panic( KVRPanic, |
|
1408 EPanicNotAttached ) ); |
|
1409 |
|
1410 if( iAudioRecorder->State() == CMdaAudioClipUtility::ERecording || |
|
1411 iAudioRecorder->State() == CMdaAudioClipUtility::ENotReady ) |
|
1412 { |
|
1413 return; |
|
1414 } |
|
1415 |
|
1416 TInt64 interval ( TInt64( aSeconds ) * KVRSecondAsMicroSeconds ); |
|
1417 |
|
1418 // Truncated to integer values |
|
1419 TInt integerInterval( interval / KVRSecondAsMicroSeconds ); |
|
1420 TInt integerDuration( iAudioRecorder->Duration().Int64() / |
|
1421 KVRSecondAsMicroSeconds ); |
|
1422 |
|
1423 if ( interval < 0 || integerDuration == 0 ) |
|
1424 { |
|
1425 interval = 0; |
|
1426 } |
|
1427 // if gone past the end or integer values are the same in |
|
1428 // duration and position |
|
1429 else if ( interval > iAudioRecorder->Duration().Int64() || |
|
1430 integerInterval == integerDuration ) |
|
1431 { |
|
1432 interval = iAudioRecorder->Duration().Int64(); |
|
1433 } |
|
1434 |
|
1435 TTimeIntervalMicroSeconds newPosition( interval ); |
|
1436 |
|
1437 if ( iPause ) |
|
1438 { |
|
1439 iPosition = newPosition; |
|
1440 } |
|
1441 else if ( iAudioRecorder->State() == CMdaAudioClipUtility::EOpen ) |
|
1442 { |
|
1443 iAudioRecorder->SetPosition( newPosition ); |
|
1444 } |
|
1445 else |
|
1446 { |
|
1447 iAudioRecorder->Stop(); |
|
1448 iAudioRecorder->SetPosition( newPosition ); |
|
1449 iAudioRecorder->PlayL(); |
|
1450 if( !iActiveWait.IsStarted() ) |
|
1451 { |
|
1452 iActiveWait.Start(); // CSI: 10 # |
|
1453 } |
|
1454 } |
|
1455 SyncAndNotify(); |
|
1456 } |
|
1457 |
|
1458 // --------------------------------------------------------- |
|
1459 // From class MBacklightControlObserver. |
|
1460 // CNTExternalEventObserver::LightStatusChanged |
|
1461 // --------------------------------------------------------- |
|
1462 // |
|
1463 void CVRMdaRecorder::LightStatusChanged(TInt aTarget, CHWRMLight::TLightStatus aStatus) |
|
1464 { |
|
1465 |
|
1466 if(aTarget == CHWRMLight::EPrimaryDisplayAndKeyboard || aTarget == CHWRMLight::EPrimaryDisplay) |
|
1467 { |
|
1468 if(aStatus == CHWRMLight::ELightOff) |
|
1469 { |
|
1470 if (iAudioRecorder) |
|
1471 { |
|
1472 if (iAudioRecorder->State() == CMdaAudioClipUtility::ERecording ) // set light to dimmed |
|
1473 { |
|
1474 |
|
1475 TRAPD(err, iLight->LightOnL(CHWRMLight::EPrimaryDisplay, KHWRMInfiniteDuration, 10, ETrue)); |
|
1476 if ( err == KErrNone ) |
|
1477 { |
|
1478 iDimLight = ETrue; |
|
1479 } |
|
1480 |
|
1481 } |
|
1482 } |
|
1483 |
|
1484 return; |
|
1485 } |
|
1486 |
|
1487 if((aStatus == CHWRMLight::ELightOn) && (aTarget == CHWRMLight::EPrimaryKeyboard)) |
|
1488 { |
|
1489 |
|
1490 if (iLight) |
|
1491 { |
|
1492 |
|
1493 CHWRMLight::TLightStatus status = iLight->LightStatus(CHWRMLight::EPrimaryDisplay); |
|
1494 |
|
1495 if( (status == CHWRMLight::ELightOn) && iDimLight ) |
|
1496 { |
|
1497 User::ResetInactivityTime(); |
|
1498 iDimLight = EFalse; |
|
1499 } |
|
1500 } |
|
1501 return; |
|
1502 } |
|
1503 |
|
1504 } |
|
1505 } |
|
1506 |
|
1507 |
|
1508 // --------------------------------------------------------- |
|
1509 // GetInRecordingFlag |
|
1510 // |
|
1511 // --------------------------------------------------------- |
|
1512 // |
|
1513 TBool CVRMdaRecorder::GetInRecordingFlag() |
|
1514 { |
|
1515 return ifInRecording; |
|
1516 } |
|
1517 |
|
1518 |
|
1519 // --------------------------------------------------------- |
|
1520 // SetInRecordingFlag |
|
1521 // --------------------------------------------------------- |
|
1522 // |
|
1523 void CVRMdaRecorder::SetInRecordingFlag(TBool aFlag) |
|
1524 { |
|
1525 ifInRecording = aFlag; |
|
1526 } |
|
1527 |
|
1528 |
|
1529 // --------------------------------------------------------- |
|
1530 // GetInRecordingFlag |
|
1531 // |
|
1532 // --------------------------------------------------------- |
|
1533 // |
|
1534 TBool CVRMdaRecorder::GetIfStopCalled() |
|
1535 { |
|
1536 return ifStopCalled; |
|
1537 } |
|
1538 |
|
1539 |
|
1540 // --------------------------------------------------------- |
|
1541 // SetInRecordingFlag |
|
1542 // --------------------------------------------------------- |
|
1543 // |
|
1544 void CVRMdaRecorder::SetIfStopCalled(TBool aFlag) |
|
1545 { |
|
1546 ifStopCalled = aFlag; |
|
1547 } |
|
1548 |
|
1549 // --------------------------------------------------------- |
|
1550 // IsAttachedToMemo |
|
1551 // --------------------------------------------------------- |
|
1552 // |
|
1553 TBool CVRMdaRecorder::IsAttachedToMemo() |
|
1554 { |
|
1555 return iIsAttachedToMemo; |
|
1556 } |
|
1557 |
|
1558 |
|
1559 // --------------------------------------------------------- |
|
1560 // CreateAudioInput |
|
1561 // --------------------------------------------------------- |
|
1562 // |
|
1563 void CVRMdaRecorder::CreateAudioInputL() |
|
1564 { |
|
1565 CAudioInput::TAudioInputPreference audioInput = CAudioInput::EDefaultMic; |
|
1566 |
|
1567 if ((iAudioRecorder->State() == CMdaAudioClipUtility::EOpen)&& |
|
1568 (!iAudioInput)) |
|
1569 { |
|
1570 iAudioInput = CAudioInput::NewL(*iAudioRecorder); |
|
1571 SetAudioInputL(audioInput); |
|
1572 iCurrentAudioInput = audioInput; |
|
1573 } |
|
1574 |
|
1575 } |
|
1576 // --------------------------------------------------------- |
|
1577 // SetAudioInputL |
|
1578 // --------------------------------------------------------- |
|
1579 // |
|
1580 void CVRMdaRecorder::SetAudioInputL(CAudioInput::TAudioInputPreference aAudioInput) |
|
1581 { |
|
1582 if((iAudioInput)&&(iCurrentAudioInput!=aAudioInput)) |
|
1583 { |
|
1584 RArray<CAudioInput::TAudioInputPreference> inputArray(4); |
|
1585 CleanupClosePushL( inputArray ); |
|
1586 inputArray.Append( aAudioInput ); |
|
1587 iAudioInput->SetAudioInputL( inputArray.Array() ); |
|
1588 CleanupStack::PopAndDestroy( &inputArray ); |
|
1589 iCurrentAudioInput = aAudioInput; |
|
1590 } |
|
1591 |
|
1592 } |
|
1593 |
|
1594 // --------------------------------------------------------- |
|
1595 // DeleteAudioInput |
|
1596 // --------------------------------------------------------- |
|
1597 // |
|
1598 void CVRMdaRecorder::DeleteAudioInput() |
|
1599 { |
|
1600 delete iAudioInput; |
|
1601 iAudioInput = NULL; |
|
1602 } |
|
1603 |
|
1604 // --------------------------------------------------------- |
|
1605 // ConfigSampleRateOfVoiceCallL |
|
1606 // --------------------------------------------------------- |
|
1607 // |
|
1608 void CVRMdaRecorder::ConfigSampleRateOfVoiceCallL() |
|
1609 { |
|
1610 // Sample rate |
|
1611 TUint sampleRates = iAudioRecorder->DestinationSampleRateL(); |
|
1612 TInt configuredAacSamplerate( VRUtils::AACSamplerateL() ); |
|
1613 if(sampleRates == configuredAacSamplerate) |
|
1614 { |
|
1615 return; |
|
1616 } |
|
1617 |
|
1618 if (iMemo->Quality() == EQualityHigh) |
|
1619 { |
|
1620 TInt aacSampleRate( KVRDefaultSamplerateAac ); |
|
1621 // Sample rate |
|
1622 RArray<TUint> supportedSampleRates; |
|
1623 iAudioRecorder->GetSupportedSampleRatesL(supportedSampleRates); |
|
1624 TInt num1 = supportedSampleRates.Count(); |
|
1625 if(num1 > 0) |
|
1626 { |
|
1627 supportedSampleRates.Sort(); |
|
1628 TInt found1 = supportedSampleRates.Find(configuredAacSamplerate); |
|
1629 if (found1 == KErrNotFound) |
|
1630 { |
|
1631 aacSampleRate = supportedSampleRates[num1-1]; |
|
1632 } |
|
1633 } |
|
1634 supportedSampleRates.Reset(); |
|
1635 iAudioRecorder->SetDestinationSampleRateL(aacSampleRate); |
|
1636 } |
|
1637 } |
|
1638 |
|
1639 // End of file |