|
1 /* |
|
2 * Copyright (c) 2004 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: Audio recorder class. Client side for audio thread |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "CCMRAudioRecorder.h" |
|
22 #include "CCMRSupportedCodecs.h" |
|
23 #include "CCMRAudioCodecs.h" |
|
24 #include "CCMRAudioCodecData.h" |
|
25 #include "CCMRActiveOutput.h" |
|
26 #include "CCMRVideoHWParams.h" |
|
27 |
|
28 #include <mmf/server/mmfdatabuffer.h> |
|
29 #include <mmf/server/mmfaudioinput.h> |
|
30 #include <AudioPreference.h> // For MMF audio preference definitions. |
|
31 |
|
32 // MACROS |
|
33 |
|
34 // Assertion macro wrapper for code cleanup |
|
35 #define ARASSERT(x) __ASSERT_DEBUG(x, User::Panic(_L("CCMRAUDIORECORDER"), EInternalAssertionFailure)) |
|
36 |
|
37 // Debug print macro |
|
38 #ifdef _DEBUG |
|
39 #include <e32svr.h> |
|
40 #define PRINT(x) RDebug::Print x |
|
41 #else |
|
42 #define PRINT(x) |
|
43 #endif |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 // ================= MEMBER FUNCTIONS ======================= |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CCMRAudioRecorder::CCMRAudioRecorder |
|
52 // |
|
53 // Default constructor. |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 CCMRAudioRecorder::CCMRAudioRecorder() |
|
57 { |
|
58 iObserver = NULL; |
|
59 iDataSource = NULL; |
|
60 iThreadCreated = EFalse; |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CCMRAudioRecorder::~CCMRAudioRecorder |
|
65 // |
|
66 // Destructor. |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 CCMRAudioRecorder::~CCMRAudioRecorder() |
|
70 { |
|
71 PRINT((_L("CCMRAudioRecorder::~CCMRAudioRecorder() in"))); |
|
72 |
|
73 delete iThreadEventMonitor; |
|
74 iThreadEventMonitor = NULL; |
|
75 |
|
76 if ( iThreadCreated ) |
|
77 { |
|
78 iThreadProxy.Close(); |
|
79 } |
|
80 //audio thread already logs off audio source (=> deletes it) |
|
81 PRINT((_L("CCMRAudioRecorder::~CCMRAudioRecorder() thread closed"))); |
|
82 |
|
83 iObserver = NULL; |
|
84 iDataSource = NULL; |
|
85 iOutputAO = NULL; |
|
86 |
|
87 delete iAudioCodecs; |
|
88 iAudioCodecs = NULL; |
|
89 |
|
90 PRINT((_L("CCMRAudioRecorder::~CCMRAudioRecorder() out"))); |
|
91 } |
|
92 |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CCMRAudioRecorder::NewL |
|
96 // |
|
97 // Two-phased constructor. |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 CCMRAudioRecorder* CCMRAudioRecorder::NewL() |
|
101 { |
|
102 |
|
103 CCMRAudioRecorder* self = new (ELeave) CCMRAudioRecorder; |
|
104 CleanupStack::PushL(self); |
|
105 self->ConstructL(); |
|
106 CleanupStack::Pop(); |
|
107 return self; |
|
108 |
|
109 } |
|
110 |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CCMRAudioRecorder::ConstructL |
|
114 // |
|
115 // Symbian 2nd phase constructor. |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 void CCMRAudioRecorder::ConstructL() |
|
119 { |
|
120 SetState(EStateNone); |
|
121 iPrioritySettings.iPriority = KAudioPriorityVideoRecording; |
|
122 iPrioritySettings.iPref = TMdaPriorityPreference( KAudioPrefVideoRecording ); |
|
123 |
|
124 RArray<TFourCC> audioTypes; |
|
125 CleanupClosePushL( audioTypes ); |
|
126 audioTypes.Reset(); |
|
127 |
|
128 iAudioCodecs = CCMRAudioCodecs::NewL(); |
|
129 iAudioCodecs->GetSupportedAudioCodecsL( audioTypes ); |
|
130 // audioTypes have always >= 1 element now |
|
131 if ( audioTypes.Count() > 0 ) |
|
132 { |
|
133 iAudioCodecFourCC = TFourCC(audioTypes[0]); |
|
134 iAudioCodecs->SetAudioCodecL( iAudioCodecFourCC ); |
|
135 CCMRRecorderBase::SetTargetBitRateL( iAudioCodecs->GetCodecDataL()->GetBitRateL() ); |
|
136 } |
|
137 else |
|
138 { |
|
139 // no audio codecs exist. Must anyway create audio recorder, since mediarecorder should work also video-only and codec support is checked later |
|
140 iAudioCodecFourCC = TFourCC(' ',' ',' ',' '); |
|
141 } |
|
142 |
|
143 CleanupStack::PopAndDestroy( &audioTypes ); // calls also audioTypes.Close() |
|
144 } |
|
145 |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // CCMRAudioRecorder::OpenL |
|
149 // |
|
150 // Open recorder. This is like audio controller's AddSource |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 void CCMRAudioRecorder::OpenL(MCMRAudioRecorderObserver *aObserver, MDataSource *aSource, |
|
154 CCMRActiveOutput* aOutputAO, const TFourCC& aAudioType, CCMRConfigManager* aConfig ) |
|
155 { |
|
156 PRINT((_L("CCMRAudioRecorder::OpenL() in"))); |
|
157 if ( State() != EStateNone ) |
|
158 { |
|
159 PRINT((_L("CCMRAudioRecorder::OpenL() already exists"))); |
|
160 User::Leave( KErrAlreadyExists ); |
|
161 } |
|
162 |
|
163 // save the references/pointers |
|
164 iObserver = aObserver; |
|
165 iConfig = aConfig; |
|
166 iConfig->SetAudioCodec( iAudioCodecFourCC ); |
|
167 |
|
168 // check the source type |
|
169 if ( aSource && aSource->DataSourceType() != KUidMmfAudioInput) |
|
170 { |
|
171 PRINT((_L("CCMRAudioRecorder::OpenL() unsupported source"))); |
|
172 User::Leave(KErrNotSupported); |
|
173 } |
|
174 iDataSource = aSource; |
|
175 |
|
176 iOutputAO = aOutputAO; |
|
177 |
|
178 // create thread for audio |
|
179 User::LeaveIfError(iThreadProxy.CreateSubThread(iThreadCreated)); |
|
180 User::LeaveIfError(iThreadProxy.SetOutput(iOutputAO)); |
|
181 |
|
182 iThreadEventMonitor = CCMRSubThreadEventMonitor::NewL(*this, iThreadProxy); |
|
183 iThreadEventMonitor->Start(); |
|
184 |
|
185 // add data source => we will be connected also to DevSound and then we can use e.g. gain settings |
|
186 if (iDataSource) |
|
187 { |
|
188 User::LeaveIfError(iThreadProxy.AddDataSource(iDataSource)); |
|
189 } |
|
190 |
|
191 // set config manager to thread |
|
192 User::LeaveIfError(iThreadProxy.SetConfigManager( aConfig )); |
|
193 |
|
194 // SetAudioCodec requires we are at least open |
|
195 SetState( EStateOpen ); |
|
196 iObserver->MaroStateChange( State() ); |
|
197 |
|
198 SetAudioCodecL( aAudioType ); |
|
199 |
|
200 PRINT((_L("CCMRAudioRecorder::OpenL() out"))); |
|
201 } |
|
202 |
|
203 |
|
204 // ----------------------------------------------------------------------------- |
|
205 // CCMRAudioRecorder::SetAudioCodecL |
|
206 // |
|
207 // Set audio codec to be used (overrides the one given in OpenL) |
|
208 // ----------------------------------------------------------------------------- |
|
209 // |
|
210 void CCMRAudioRecorder::SetAudioCodecL( const TFourCC& aAudioType ) |
|
211 { |
|
212 PRINT((_L("CCMRAudioRecorder::SetAudioCodecL() in"))); |
|
213 if ( ( State() != EStateOpen ) && ( State() != EStateReadyToRecord ) ) |
|
214 { |
|
215 PRINT((_L("CCMRAudioRecorder::SetAudioCodecL() wrong state"))); |
|
216 User::Leave(KErrNotReady); |
|
217 } |
|
218 if ( aAudioType != iAudioCodecFourCC ) |
|
219 { |
|
220 iAudioCodecs->SetAudioCodecL( aAudioType ); |
|
221 iAudioCodecFourCC = aAudioType; |
|
222 iConfig->SetAudioCodec(iAudioCodecFourCC); |
|
223 |
|
224 SetState( EStateOpen ); |
|
225 iObserver->MaroStateChange( State() ); |
|
226 } |
|
227 PRINT((_L("CCMRAudioRecorder::SetAudioCodecL() out"))); |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // CCMRAudioRecorder::GetAudioCodecL |
|
232 // Get the used audio codec. |
|
233 // (other items were commented in a header). |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 void CCMRAudioRecorder::GetAudioCodecL( TFourCC& aAudioType ) const |
|
237 { |
|
238 if ( (State() == EStateNone) || (iAudioCodecs->GetCodecDataL() == NULL) ) |
|
239 { |
|
240 PRINT((_L("CCMRAudioRecorder::GetAudioCodecL() wrong state"))); |
|
241 User::Leave(KErrNotReady); |
|
242 } |
|
243 |
|
244 aAudioType = iAudioCodecs->GetCodecDataL()->GetCodecFourCCL(); |
|
245 } |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // CCMRAudioRecorder::GetSupportedAudioCodecsL |
|
249 // Get the supported & installed audio codecs. |
|
250 // This can be called also when the recorder is not open |
|
251 // (other items were commented in a header). |
|
252 // ----------------------------------------------------------------------------- |
|
253 // |
|
254 void CCMRAudioRecorder::GetSupportedAudioCodecsL( RArray<TFourCC>& aAudioTypes ) const |
|
255 { |
|
256 aAudioTypes.Reset(); |
|
257 |
|
258 iAudioCodecs->GetSupportedAudioCodecsL( aAudioTypes ); |
|
259 |
|
260 } |
|
261 |
|
262 // ----------------------------------------------------------------------------- |
|
263 // CCMRAudioRecorder::SetPriorityL |
|
264 // |
|
265 // Set audio priority (for DevSound) |
|
266 // ----------------------------------------------------------------------------- |
|
267 // |
|
268 void CCMRAudioRecorder::SetPriorityL(const TMMFPrioritySettings& aPrioritySettings) |
|
269 { |
|
270 if ( State() == EStateNone || State() == EStateRecording || State() == EStatePaused ) |
|
271 { |
|
272 PRINT((_L("CCMRAudioRecorder::SetPriorityL() wrong state"))); |
|
273 User::Leave(KErrNotReady); |
|
274 } |
|
275 if ( aPrioritySettings.iPriority < EMdaPriorityMin || aPrioritySettings.iPriority > EMdaPriorityMax ) |
|
276 { |
|
277 // outside allowed range |
|
278 PRINT((_L("CCMRAudioRecorder::SetPriorityL() unsupported priority"))); |
|
279 User::Leave( KErrArgument ); |
|
280 } |
|
281 |
|
282 iPrioritySettings = aPrioritySettings; |
|
283 SetState( EStateOpen ); |
|
284 iObserver->MaroStateChange( State() ); |
|
285 |
|
286 } |
|
287 |
|
288 |
|
289 // ----------------------------------------------------------------------------- |
|
290 // CCMRAudioRecorder::SetTargetBitRateL |
|
291 // |
|
292 // Set audio bitrate. Note: checked only in PrepareL |
|
293 // ----------------------------------------------------------------------------- |
|
294 // |
|
295 void CCMRAudioRecorder::SetTargetBitRateL(TInt aBitRate) |
|
296 { |
|
297 PRINT((_L("CCMRAudioRecorder::SetTargetBitRateL() in"))); |
|
298 if ( (( State() != EStateOpen ) && ( State() != EStateReadyToRecord )) || (iAudioCodecs->GetCodecDataL() == NULL) ) |
|
299 { |
|
300 PRINT((_L("CCMRAudioRecorder::SetTargetBitRateL() wrong state"))); |
|
301 User::Leave(KErrNotReady); |
|
302 } |
|
303 |
|
304 iAudioCodecs->GetCodecDataL()->SetBitRateL( aBitRate ); |
|
305 // if we are here, the bitrate was ok, store it also here since the system assumes recorder class stores it |
|
306 CCMRRecorderBase::SetTargetBitRateL( aBitRate ); |
|
307 |
|
308 SetState( EStateOpen ); |
|
309 iObserver->MaroStateChange( State() ); |
|
310 PRINT((_L("CCMRAudioRecorder::SetTargetBitRateL() out"))); |
|
311 } |
|
312 |
|
313 // ----------------------------------------------------------------------------- |
|
314 // CCMRAudioRecorder::SetTargetSampleRateL |
|
315 // |
|
316 // Set audio samplerate. AAC only. |
|
317 // ----------------------------------------------------------------------------- |
|
318 // |
|
319 void CCMRAudioRecorder::SetTargetSampleRateL(TInt aSampleRate) |
|
320 { |
|
321 PRINT((_L("CCMRAudioRecorder::SetTargetSampleRateL() in, samplerate=%d"),aSampleRate)); |
|
322 if ( (( State() != EStateOpen ) && ( State() != EStateReadyToRecord )) || (iAudioCodecs->GetCodecDataL() == NULL) ) |
|
323 { |
|
324 PRINT((_L("CCMRAudioRecorder::SetTargetSampleRateL() wrong state"))); |
|
325 User::Leave(KErrNotReady); |
|
326 } |
|
327 |
|
328 iAudioCodecs->GetCodecDataL()->SetSampleRateL( aSampleRate ); |
|
329 |
|
330 SetState( EStateOpen ); |
|
331 iObserver->MaroStateChange( State() ); |
|
332 PRINT((_L("CCMRAudioRecorder::SetTargetSampleRateL() out"))); |
|
333 } |
|
334 |
|
335 // ----------------------------------------------------------------------------- |
|
336 // CCMRAudioRecorder::SetChannelModeL |
|
337 // |
|
338 // Set audio channel mode. AAC only. |
|
339 // ----------------------------------------------------------------------------- |
|
340 // |
|
341 void CCMRAudioRecorder::SetChannelModeL(TInt aChannelMode) |
|
342 { |
|
343 PRINT((_L("CCMRAudioRecorder::SetChannelModeL() in, channelmode=%d"), aChannelMode)); |
|
344 if ( (( State() != EStateOpen ) && ( State() != EStateReadyToRecord )) || (iAudioCodecs->GetCodecDataL() == NULL) ) |
|
345 { |
|
346 PRINT((_L("CCMRAudioRecorder::SetChannelModeL() wrong state"))); |
|
347 User::Leave(KErrNotReady); |
|
348 } |
|
349 |
|
350 iAudioCodecs->GetCodecDataL()->SetChannelModeL( aChannelMode ); |
|
351 |
|
352 SetState( EStateOpen ); |
|
353 iObserver->MaroStateChange( State() ); |
|
354 PRINT((_L("CCMRAudioRecorder::SetChannelModeL() out"))); |
|
355 } |
|
356 |
|
357 // ----------------------------------------------------------------------------- |
|
358 // CCMRAudioRecorder::MaxGainL |
|
359 // |
|
360 // Get maximum gain from audio input |
|
361 // ----------------------------------------------------------------------------- |
|
362 // |
|
363 TInt CCMRAudioRecorder::MaxGainL() |
|
364 { |
|
365 PRINT((_L("CCMRAudioRecorder::MaxGainL() in"))); |
|
366 if ( State() == EStateNone ) |
|
367 { |
|
368 PRINT((_L("CCMRAudioRecorder::MaxGainL() wrong state"))); |
|
369 User::Leave( KErrNotReady ); |
|
370 } |
|
371 |
|
372 // check max gain from sound device |
|
373 TInt gain; |
|
374 User::LeaveIfError( iThreadProxy.MaxGain( gain )); |
|
375 PRINT((_L("CCMRAudioRecorder::MaxGainL() almost out, max gain %d"),gain)); |
|
376 return gain; |
|
377 } |
|
378 |
|
379 // ----------------------------------------------------------------------------- |
|
380 // CCMRAudioRecorder::GainL |
|
381 // |
|
382 // Get current gain from audio input |
|
383 // ----------------------------------------------------------------------------- |
|
384 // |
|
385 TInt CCMRAudioRecorder::GainL() |
|
386 { |
|
387 PRINT((_L("CCMRAudioRecorder::GainL() in"))); |
|
388 if ( State() == EStateNone ) |
|
389 { |
|
390 PRINT((_L("CCMRAudioRecorder::GainL() wrong state"))); |
|
391 User::Leave( KErrNotReady ); |
|
392 } |
|
393 |
|
394 // check current gain from sound device |
|
395 TInt gain; |
|
396 User::LeaveIfError( iThreadProxy.GetGain( gain )); |
|
397 PRINT((_L("CCMRAudioRecorder::GainL() almost out, gain %d"),gain)); |
|
398 return gain; |
|
399 } |
|
400 |
|
401 |
|
402 // ----------------------------------------------------------------------------- |
|
403 // CCMRAudioRecorder::SetGainL |
|
404 // |
|
405 // Sets gain for audio input. Can be done before and during recording |
|
406 // and is effective immediately |
|
407 // ----------------------------------------------------------------------------- |
|
408 // |
|
409 void CCMRAudioRecorder::SetGainL(TInt aGain) |
|
410 { |
|
411 PRINT((_L("CCMRAudioRecorder::SetGainL() in"))); |
|
412 if ( State() == EStateNone ) |
|
413 { |
|
414 PRINT((_L("CCMRAudioRecorder::SetGainL() wrong state"))); |
|
415 User::Leave( KErrNotReady ); |
|
416 } |
|
417 if ( aGain >= 0 ) |
|
418 { |
|
419 User::LeaveIfError( iThreadProxy.SetGain(aGain)); |
|
420 |
|
421 PRINT((_L("CCMRAudioRecorder::SetGainL() out"))); |
|
422 } |
|
423 else |
|
424 { |
|
425 PRINT((_L("CCMRAudioRecorder::SetGainL() out due to illegal argument: %d"),aGain)); |
|
426 User::Leave( KErrArgument ); |
|
427 } |
|
428 } |
|
429 |
|
430 // ----------------------------------------------------------------------------- |
|
431 // CCMRAudioRecorder::GetThreadPriority |
|
432 // |
|
433 // Get audio thread priority |
|
434 // ----------------------------------------------------------------------------- |
|
435 // |
|
436 TThreadPriority CCMRAudioRecorder::GetThreadPriority() const |
|
437 { |
|
438 return iThreadProxy.GetThreadPriority(); |
|
439 } |
|
440 |
|
441 // ----------------------------------------------------------------------------- |
|
442 // CCMRAudioRecorder::PrepareL |
|
443 // |
|
444 // Prepare recorder for recording (freeze settings / implements PrimeL) |
|
445 // ----------------------------------------------------------------------------- |
|
446 // |
|
447 void CCMRAudioRecorder::PrepareL() |
|
448 { |
|
449 PRINT((_L("CCMRAudioRecorder::PrepareL() in "))); |
|
450 |
|
451 if ( (State() != EStateOpen) && (State() != EStateReadyToRecord) ) |
|
452 { |
|
453 PRINT((_L("CCMRAudioRecorder::PrepareL() wrong state"))); |
|
454 User::Leave( KErrNotReady ); |
|
455 } |
|
456 |
|
457 if ( !iThreadCreated ) |
|
458 { |
|
459 PRINT((_L("CCMRAudioRecorder::PrepareL() no thread"))); |
|
460 User::Leave( KErrNotReady ); |
|
461 } |
|
462 |
|
463 // set priority settings |
|
464 User::LeaveIfError( iThreadProxy.SetPriority(iPrioritySettings)); |
|
465 |
|
466 // give handle to the audio codec |
|
467 User::LeaveIfError( iThreadProxy.SetAudioCodec( iAudioCodecs->GetCodecDataL() ) ); |
|
468 |
|
469 // inform sink about average audio bitrate |
|
470 User::LeaveIfError( iOutputAO->SetAverageAudioBitRate(iAudioCodecs->GetCodecDataL()->GetBitRateL()) ); |
|
471 |
|
472 // prime the audio thread |
|
473 User::LeaveIfError(iThreadProxy.Prime()); |
|
474 PRINT((_L("CCMRAudioRecorder::PrepareL(), iThreadProxy.Prime() done") )); |
|
475 |
|
476 //no need to be in preparing state; prepare is synchronous |
|
477 |
|
478 SetState( EStateReadyToRecord ); |
|
479 iObserver->MaroStateChange( State() ); |
|
480 |
|
481 PRINT((_L("CCMRAudioRecorder::PrepareL() out "))); |
|
482 } |
|
483 |
|
484 |
|
485 |
|
486 // ----------------------------------------------------------------------------- |
|
487 // CCMRAudioRecorder::RecordL |
|
488 // |
|
489 // Start recording |
|
490 // ----------------------------------------------------------------------------- |
|
491 // |
|
492 void CCMRAudioRecorder::RecordL() |
|
493 { |
|
494 PRINT((_L("CCMRAudioRecorder::RecordL() in "))); |
|
495 if ( (State() == EStateRecording) || (State() == EStatePaused) ) |
|
496 { |
|
497 // ignore, already recording |
|
498 return; |
|
499 } |
|
500 |
|
501 if ( State() != EStateReadyToRecord ) |
|
502 { |
|
503 PRINT((_L("CCMRAudioRecorder::RecordL() wrong state"))); |
|
504 User::Leave(KErrNotReady); |
|
505 } |
|
506 |
|
507 if ( State() == EStateReadyToRecord ) |
|
508 { |
|
509 User::LeaveIfError(iThreadProxy.Play()); |
|
510 |
|
511 SetState( EStateRecording ); |
|
512 iObserver->MaroStateChange( State() ); |
|
513 } |
|
514 |
|
515 PRINT((_L("CCMRAudioRecorder::RecordL() out "))); |
|
516 } |
|
517 |
|
518 // ----------------------------------------------------------------------------- |
|
519 // CCMRAudioRecorder::StopL |
|
520 // |
|
521 // Stop recording |
|
522 // ----------------------------------------------------------------------------- |
|
523 // |
|
524 void CCMRAudioRecorder::StopL() |
|
525 { |
|
526 PRINT((_L("CCMRAudioRecorder::StopL() in "))); |
|
527 |
|
528 if ( (State() == EStateRecording) || (State() == EStatePaused) ) |
|
529 { |
|
530 |
|
531 User::LeaveIfError(iThreadProxy.Stop()); |
|
532 SetState( EStateStopping ); |
|
533 } |
|
534 PRINT((_L("CCMRAudioRecorder::StopL() out "))); |
|
535 } |
|
536 |
|
537 // ----------------------------------------------------------------------------- |
|
538 // CCMRAudioRecorder::PauseL |
|
539 // |
|
540 // Pause recording |
|
541 // ----------------------------------------------------------------------------- |
|
542 // |
|
543 void CCMRAudioRecorder::PauseL() |
|
544 { |
|
545 if ( State() == EStateRecording ) |
|
546 { |
|
547 User::LeaveIfError(iThreadProxy.Pause()); |
|
548 // pause was sync |
|
549 SetState( EStatePaused ); |
|
550 iObserver->MaroStateChange( State() ); |
|
551 } |
|
552 } |
|
553 |
|
554 // ----------------------------------------------------------------------------- |
|
555 // CCMRAudioRecorder::ResumeL |
|
556 // |
|
557 // Resume recording |
|
558 // ----------------------------------------------------------------------------- |
|
559 // |
|
560 void CCMRAudioRecorder::ResumeL() |
|
561 { |
|
562 if ( State() == EStatePaused ) |
|
563 { |
|
564 User::LeaveIfError(iThreadProxy.Play()); |
|
565 |
|
566 SetState( EStateRecording ); |
|
567 iObserver->MaroStateChange( State() ); |
|
568 } |
|
569 } |
|
570 |
|
571 // ----------------------------------------------------------------------------- |
|
572 // CCMRAudioRecorder::WaitUntilStoppedL |
|
573 // Wait until audio thread has stopped recording |
|
574 // |
|
575 // ----------------------------------------------------------------------------- |
|
576 // |
|
577 void CCMRAudioRecorder::WaitUntilStoppedL() |
|
578 { |
|
579 if ( (State() == EStateRecording) || (State() == EStatePaused) || (State() == EStateStopping)) |
|
580 { |
|
581 // not stopped yet |
|
582 User::LeaveIfError(iThreadProxy.WaitUntilStopped()); |
|
583 // wait was sync |
|
584 SetState( EStateReadyToRecord ); |
|
585 } |
|
586 } |
|
587 |
|
588 // ----------------------------------------------------------------------------- |
|
589 // CCMRAudioRecorder::AVSyncAdjustmentStart |
|
590 // Get default AV sync adjustment for start of recording, depending on codec type |
|
591 // |
|
592 // ----------------------------------------------------------------------------- |
|
593 // |
|
594 TInt CCMRAudioRecorder::AVSyncAdjustmentStart() |
|
595 { |
|
596 if ( iConfig && iConfig->IsICMConfigDataAvailable() ) |
|
597 { |
|
598 return iConfig->VideoQualitySettings().iAVSyncStartDelay; |
|
599 } |
|
600 |
|
601 TCMRCodecType type = ECodecTypeSW; |
|
602 |
|
603 TRAPD(err, type = iAudioCodecs->GetCodecDataL()->GetCodecSWHWTypeL()); |
|
604 ARASSERT( err == KErrNone ); |
|
605 if ( err ) {} |
|
606 |
|
607 if ( type == ECodecTypeHW ) |
|
608 { |
|
609 //HW codecs (DevSound outputs compressed data) |
|
610 return KCMRInitialVideoAudioTimeSyncHW; |
|
611 } |
|
612 else |
|
613 { |
|
614 //SW codecs (DevSound outputs PCM) |
|
615 return KCMRInitialVideoAudioTimeSyncSW; |
|
616 } |
|
617 |
|
618 } |
|
619 |
|
620 // ----------------------------------------------------------------------------- |
|
621 // CCMRAudioRecorder::AVSyncAdjustmentResume |
|
622 // Get default AV sync adjustment for resume of recording, depending on codec type |
|
623 // |
|
624 // ----------------------------------------------------------------------------- |
|
625 // |
|
626 TInt CCMRAudioRecorder::AVSyncAdjustmentResume() |
|
627 { |
|
628 if ( iConfig && iConfig->IsICMConfigDataAvailable() ) |
|
629 { |
|
630 return iConfig->VideoQualitySettings().iAVSyncResumeDelay; |
|
631 } |
|
632 |
|
633 TCMRCodecType type = ECodecTypeSW; |
|
634 |
|
635 TRAPD(err, type = iAudioCodecs->GetCodecDataL()->GetCodecSWHWTypeL()); |
|
636 ARASSERT( err == KErrNone ); |
|
637 if ( err ) {} |
|
638 |
|
639 if ( type == ECodecTypeHW ) |
|
640 { |
|
641 //HW codecs (DevSound outputs compressed data) |
|
642 return KCMRPauseVideoAudioTimeSyncHW; |
|
643 } |
|
644 else |
|
645 { |
|
646 //SW codecs (DevSound outputs PCM) |
|
647 return KCMRPauseVideoAudioTimeSyncSW; |
|
648 } |
|
649 |
|
650 } |
|
651 |
|
652 // ----------------------------------------------------------------------------- |
|
653 // CCMRAudioRecorder::HandleEvent |
|
654 // Handle event from audio thread |
|
655 // |
|
656 // ----------------------------------------------------------------------------- |
|
657 // |
|
658 void CCMRAudioRecorder::HandleEvent(const TMMFEvent& aEvent) |
|
659 { |
|
660 PRINT((_L("CCMRAudioRecorder::HandleEvent(), aEvent.iEventType %d aEvent.iErrorCode %d"), aEvent.iEventType.iUid, aEvent.iErrorCode )); |
|
661 |
|
662 if (aEvent.iEventType == KMMFEventCategoryPlaybackComplete) |
|
663 { |
|
664 // Lose of audio resource is signalled like this. Also some errors are signaled using this event |
|
665 // If aEvent.iErrorCode == KErrDied, dev policy kicked us out, if it is something else, some other error occurred |
|
666 // audio-thread goes to stopped state before sending this |
|
667 SetState( EStateReadyToRecord ); |
|
668 iObserver->MaroStateChange( State() ); |
|
669 iObserver->MaroError( aEvent.iErrorCode ); |
|
670 PRINT((_L("CCMRAudioRecorder::HandleEvent(), state changed to ready and error informed") )); |
|
671 } |
|
672 else if (aEvent.iErrorCode != KErrNone ) |
|
673 { |
|
674 if ( aEvent.iErrorCode == KErrServerTerminated ) |
|
675 { |
|
676 // audio thread terminated, no need to stop etc anything |
|
677 PRINT((_L("CCMRAudioRecorder::HandleEvent(), audio thread terminated") )); |
|
678 SetState( EStateNone ); |
|
679 iObserver->MaroError( aEvent.iErrorCode ); |
|
680 iObserver->MaroStateChange( State() ); |
|
681 } |
|
682 else |
|
683 { |
|
684 // some other event, e.g. OOM |
|
685 if ( (State() == EStateRecording) || (State() == EStatePaused) ) |
|
686 { |
|
687 // stop first |
|
688 PRINT((_L("CCMRAudioRecorder::HandleEvent(), error received but must stop first") )); |
|
689 iErrorCode = aEvent.iErrorCode; |
|
690 if ( iThreadProxy.Stop() == KErrNone ) |
|
691 { |
|
692 // wait until stopped |
|
693 iThreadProxy.WaitUntilStopped(); |
|
694 // wait was sync, can proceed with error handling |
|
695 } |
|
696 } |
|
697 //inform observer about error |
|
698 SetState( EStateNone ); |
|
699 iObserver->MaroError( aEvent.iErrorCode ); |
|
700 iObserver->MaroStateChange( State() ); |
|
701 PRINT((_L("CCMRAudioRecorder::HandleEvent(), state changed to ready and error informed") )); |
|
702 } |
|
703 } |
|
704 else |
|
705 { |
|
706 // some event without an errorcode! Don't know if this is possible |
|
707 } |
|
708 |
|
709 } |