|
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 #include <mmf/server/mmfformat.h> |
|
18 #include <mmf/server/mmfclip.h> |
|
19 #include <mdaaudiosampleeditor.h> |
|
20 #include <mmf/plugin/mmfcontrollerimplementationuids.hrh> |
|
21 #include <mmf/common/mmffourcc.h> |
|
22 #include <mmf/common/mmfpaniccodes.h> |
|
23 #include "TestUseOldCodecAudioController.h" |
|
24 |
|
25 const TUint KSampleRate8000Hz = 8000; |
|
26 const TUint KSampleRate11025Hz = 11025; |
|
27 const TUint KSampleRate16000Hz = 16000; |
|
28 const TUint KSampleRate22050Hz = 22050; |
|
29 const TUint KSampleRate32000Hz = 32000; |
|
30 const TUint KSampleRate44100Hz = 44100; |
|
31 const TUint KSampleRate48000Hz = 48000; |
|
32 const TUint KSampleRate88200Hz = 88200; |
|
33 const TUint KSampleRate96000Hz = 96000; |
|
34 const TUint KNumChannelsMono = 1; |
|
35 const TUint KNumChannelsStereo = 2; |
|
36 |
|
37 /* |
|
38 TMmfAudioControllerPanics is an enumeration with the following entries: |
|
39 EBadArgument indicates a bad argument |
|
40 EBadState indicates a state viaolation |
|
41 EBadInvariant indicates an invariant violation |
|
42 EBadReset indicates failed reset |
|
43 EPostConditionViolation indicates a post condition violation |
|
44 */ |
|
45 enum TMmfAudioControllerPanics |
|
46 { |
|
47 EBadArgument, |
|
48 EBadState, |
|
49 EBadInvariant, |
|
50 EBadReset, |
|
51 EPostConditionViolation |
|
52 }; |
|
53 |
|
54 /** |
|
55 * Panic |
|
56 * This method generates a panic |
|
57 * @param "TInt" |
|
58 * @xxxx |
|
59 */ |
|
60 void Panic(TInt aPanicCode) |
|
61 { |
|
62 _LIT(KMMFAudioControllerPanicCategory, "MMFAudioController"); |
|
63 User::Panic(KMMFAudioControllerPanicCategory, aPanicCode); |
|
64 } |
|
65 |
|
66 /** |
|
67 * Static NewL |
|
68 * |
|
69 * @return CMMFTestUseOldCodecAudioController* |
|
70 */ |
|
71 CMMFController* CMMFTestUseOldCodecAudioController::NewL() |
|
72 { |
|
73 CMMFTestUseOldCodecAudioController* self = new(ELeave) CMMFTestUseOldCodecAudioController; |
|
74 CleanupStack::PushL(self); |
|
75 self->ConstructL(); |
|
76 CleanupStack::Pop( self ); |
|
77 return STATIC_CAST( CMMFController*, self ); |
|
78 } |
|
79 |
|
80 /** |
|
81 * ConstructL |
|
82 * |
|
83 * @xxxx |
|
84 */ |
|
85 void CMMFTestUseOldCodecAudioController::ConstructL() |
|
86 { |
|
87 iDataSource = NULL; |
|
88 iDataSink = NULL; |
|
89 iDataPath = CMMFDataPath::NewL(iMediaId, *this); |
|
90 iSourceFormat = NULL; |
|
91 iSinkFormat = NULL; |
|
92 iSourceAndSinkAdded = EFalse; |
|
93 iStoppingRecording = EFalse; |
|
94 |
|
95 |
|
96 //iMediaId has already been set up |
|
97 SetState( EStopped ); |
|
98 //iPrioritySettings not initialised because they are held by the controller framework |
|
99 |
|
100 // Construct custom command parsers |
|
101 CMMFAudioPlayDeviceCustomCommandParser* audPlayDevParser = CMMFAudioPlayDeviceCustomCommandParser::NewL(*this); |
|
102 CleanupStack::PushL(audPlayDevParser); |
|
103 AddCustomCommandParserL(*audPlayDevParser); |
|
104 CleanupStack::Pop( audPlayDevParser );//audPlayDevParser |
|
105 |
|
106 CMMFAudioRecordDeviceCustomCommandParser* audRecDevParser = CMMFAudioRecordDeviceCustomCommandParser::NewL(*this); |
|
107 CleanupStack::PushL(audRecDevParser); |
|
108 AddCustomCommandParserL(*audRecDevParser); |
|
109 CleanupStack::Pop(audRecDevParser);//audRecDevParser |
|
110 |
|
111 CMMFAudioPlayControllerCustomCommandParser* audPlayConParser = CMMFAudioPlayControllerCustomCommandParser::NewL(*this); |
|
112 CleanupStack::PushL(audPlayConParser); |
|
113 AddCustomCommandParserL(*audPlayConParser); |
|
114 CleanupStack::Pop(audPlayConParser);//audPlayConParser |
|
115 |
|
116 CMMFAudioRecordControllerCustomCommandParser* audRecConParser = CMMFAudioRecordControllerCustomCommandParser::NewL(*this); |
|
117 CleanupStack::PushL(audRecConParser); |
|
118 AddCustomCommandParserL(*audRecConParser); |
|
119 CleanupStack::Pop(audRecConParser);//audRecParser |
|
120 |
|
121 CMMFAudioControllerCustomCommandParser* audConParser = CMMFAudioControllerCustomCommandParser::NewL(*this); |
|
122 CleanupStack::PushL(audConParser); |
|
123 AddCustomCommandParserL(*audConParser); |
|
124 CleanupStack::Pop(audConParser);//audConParser |
|
125 |
|
126 iWaitForAsyncService = new (ELeave) CActiveSchedulerWait; |
|
127 |
|
128 // [ assert the invariant now that we are constructed ] |
|
129 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
130 } |
|
131 |
|
132 /** |
|
133 * |
|
134 * CMMFTestUseOldCodecAudioController |
|
135 * |
|
136 */ |
|
137 |
|
138 CMMFTestUseOldCodecAudioController::CMMFTestUseOldCodecAudioController() : iMediaId(KUidMediaTypeAudio), iState(EStopped) |
|
139 { |
|
140 } |
|
141 |
|
142 /** |
|
143 * |
|
144 * ~CMMFTestUseOldCodecAudioController |
|
145 * |
|
146 */ |
|
147 |
|
148 CMMFTestUseOldCodecAudioController::~CMMFTestUseOldCodecAudioController() |
|
149 { |
|
150 // [ ensure we have logged off the thread ] |
|
151 if( iDataPath ) |
|
152 { |
|
153 iDataPath->ResetL(); // this does not leave |
|
154 } |
|
155 delete iDataPath; |
|
156 delete iSourceFormat; |
|
157 delete iSinkFormat; |
|
158 delete iStoppingMessage; |
|
159 delete iWaitForAsyncService; |
|
160 } |
|
161 |
|
162 /** |
|
163 * AddDataSourceL |
|
164 * |
|
165 * Adds a data source to the controller |
|
166 * |
|
167 * @param aSource |
|
168 * Preconditions: |
|
169 * We are stopped |
|
170 * Source does not already exist |
|
171 * Postconditions: |
|
172 * iDataSource != NULL |
|
173 * iDataSourceAdded == ETrue |
|
174 */ |
|
175 void CMMFTestUseOldCodecAudioController::AddDataSourceL(MDataSource& aSource) |
|
176 { |
|
177 //[ assert the invariant ] |
|
178 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
179 |
|
180 // [ precondition that the controller is stopped ] |
|
181 if( State() != EStopped ) |
|
182 User::Leave( KErrNotReady ); |
|
183 |
|
184 //[ precondition iData source is not already configured ] |
|
185 if (iDataSource) |
|
186 User::Leave(KErrAlreadyExists); |
|
187 |
|
188 // Note that this code is not generic for sources |
|
189 // It it only checks for file, des clips and audio inputs |
|
190 // If a new source type eg a Url Clip then this needs to be added to the supported source Uids |
|
191 if ( SourceFormatRequired( aSource) ) |
|
192 { |
|
193 // Get the format from the Source if possible from no specific supplier |
|
194 TRAPD(err, iSourceFormat = CMMFFormatDecode::NewL(&aSource, KNullDesC)); |
|
195 //[ we want to complete silently for KErrNotSupported |
|
196 // because there is a possibility that the client |
|
197 // wants to add the data format later, see audio api for |
|
198 // a description of this feature] |
|
199 if ((err != KErrNotSupported) && (err != KErrNone)) |
|
200 { |
|
201 User::Leave(err); |
|
202 } |
|
203 } |
|
204 else if (aSource.DataSourceType()==KUidMmfAudioInput) |
|
205 { |
|
206 //[ ensure that the audio input has a pointer to dev sound ] |
|
207 CMMFAudioInput* audioInput = STATIC_CAST(CMMFAudioInput*, &aSource); |
|
208 __ASSERT_ALWAYS( audioInput, Panic(EBadInvariant)); |
|
209 // [ lets load dev sound ] |
|
210 User::LeaveIfError(audioInput->SourceThreadLogon( *this )); |
|
211 } |
|
212 else |
|
213 { |
|
214 User::Leave(KErrNotSupported); |
|
215 } |
|
216 |
|
217 //[ its now safe to set the source ] |
|
218 iDataSource = &aSource ; |
|
219 iDataSource->SetSourcePrioritySettings(iPrioritySettings); |
|
220 |
|
221 //[ assert the post condition ] |
|
222 __ASSERT_ALWAYS(iDataSource, Panic(EMMFAudioControllerPanicDataSourceDoesNotExist)); |
|
223 |
|
224 } |
|
225 |
|
226 |
|
227 /** |
|
228 * AddDataSinkL |
|
229 * |
|
230 * Adds a data sink to the controller |
|
231 * |
|
232 * @param aSink |
|
233 * |
|
234 */ |
|
235 void CMMFTestUseOldCodecAudioController::AddDataSinkL(MDataSink& aSink) |
|
236 { |
|
237 //[ assert the invariant ] |
|
238 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
239 |
|
240 // [ precondition that the controller is stopped ] |
|
241 if( State() != EStopped ) |
|
242 User::Leave( KErrNotReady ); |
|
243 |
|
244 // [ assert precondition that sink does not exist ] |
|
245 if (iDataSink) |
|
246 User::Leave(KErrAlreadyExists); |
|
247 |
|
248 |
|
249 // Note that this code is not generic for sinks |
|
250 // It it only checks for file,des clips and audio outputs |
|
251 // If a new sink type eg a Url Clip then this needs to be added to the supported source Uids |
|
252 if ( SinkFormatRequired( aSink ) ) |
|
253 {//the sink is a clip |
|
254 |
|
255 // Get the format from the Sink if possible from no specific supplier |
|
256 TRAPD(err, iSinkFormat = CMMFFormatEncode::NewL(&aSink, KNullDesC)); |
|
257 //[ we want to complete silently for KErrNotSupported |
|
258 // because there is a possibility that the client |
|
259 // wants to add the data format later, see audio api for |
|
260 // a description of this feature] |
|
261 if ((err != KErrNotSupported) && (err != KErrNone)) |
|
262 { |
|
263 User::Leave(err); |
|
264 } |
|
265 } |
|
266 else if (aSink.DataSinkType()==KUidMmfAudioOutput) |
|
267 { |
|
268 |
|
269 //[ ensure that the audio output has a pointer to dev sound ] |
|
270 CMMFAudioOutput* audioOutput = STATIC_CAST(CMMFAudioOutput*, &aSink); |
|
271 __ASSERT_ALWAYS( audioOutput, Panic(EBadInvariant)); |
|
272 // [ lets load dev sound ] |
|
273 User::LeaveIfError(audioOutput->SinkThreadLogon( *this )); |
|
274 } |
|
275 else |
|
276 { |
|
277 User::Leave(KErrNotSupported); |
|
278 } |
|
279 |
|
280 //[ now that we are sure we have not left we can update the sink |
|
281 // transactionally ] |
|
282 iDataSink = &aSink; |
|
283 iDataSink->SetSinkPrioritySettings(iPrioritySettings); |
|
284 |
|
285 // [ assert post conditions that a sink has been added ] |
|
286 __ASSERT_ALWAYS(iDataSink, Panic(EMMFAudioControllerPanicDataSinkDoesNotExist)); |
|
287 |
|
288 } |
|
289 |
|
290 /** |
|
291 * PrimeL |
|
292 * |
|
293 * If Prime fails the client should reset the controller |
|
294 * because as noted below this code is not transactional. |
|
295 * |
|
296 */ |
|
297 void CMMFTestUseOldCodecAudioController::PrimeL() |
|
298 { |
|
299 //[ assert the invariant ] |
|
300 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
301 |
|
302 //[ assert the precondition ( in a friendly way for this api |
|
303 // that we are either stopped or primed already ] |
|
304 if(!(( State() == EStopped ) || (State() == EPrimed ))) |
|
305 User::Leave( KErrNotReady ); |
|
306 |
|
307 // [ precondition we have a data source & sink ] |
|
308 __ASSERT_ALWAYS( iDataSource, Panic( EBadInvariant)); |
|
309 __ASSERT_ALWAYS( iDataSink, Panic( EBadInvariant)); |
|
310 |
|
311 |
|
312 //[ precondition that we need a source format ] |
|
313 if ( SourceFormatRequired(*iDataSource) && !(iSourceFormat)) |
|
314 User::Leave( KErrNotSupported ); |
|
315 |
|
316 // [ check the precondition if we need a data sink format ] |
|
317 if ( SinkFormatRequired(*iDataSink) && !( iSinkFormat )) |
|
318 User::Leave( KErrNotSupported ); |
|
319 |
|
320 |
|
321 // [ ideally this code should be transaction based and |
|
322 // if failure occurs we roll back to the previous state |
|
323 // in the code below this is not the case and the controller |
|
324 // can be left in an unstable state should any part of prime fail] |
|
325 if (iState == EStopped) |
|
326 { //datapath propagates prime to sink & source |
|
327 |
|
328 TFourCC sinkFormatDataType; |
|
329 if ((iSinkFormat)&&(iDataSource)) |
|
330 {//audio input so recording |
|
331 //need to assign the sink format 4CC to pcm16 |
|
332 //even though it isn't pcm16 , this will cause the audio input |
|
333 //in negotiation to instantiate the null CMMFHwDevice plugin |
|
334 //after the negotiation set it back to the correct datatype |
|
335 //forcing the datapath to use a CMMFCodec |
|
336 sinkFormatDataType = iSinkFormat->SinkDataTypeCode(KUidMediaTypeAudio); //reset this after negotiation |
|
337 iSinkFormat->SetSinkDataTypeCode(KMMFFourCCCodePCM16, KUidMediaTypeAudio); |
|
338 } |
|
339 |
|
340 NegotiateL(); |
|
341 |
|
342 if (!iSourceAndSinkAdded) |
|
343 { |
|
344 //add data source and sinks to datapath - Note cant do this in AddDataSource/Sink |
|
345 //because the sources and sinks aren't configured at this point |
|
346 if (iSourceFormat) |
|
347 iDataPath->AddDataSourceL(iSourceFormat); |
|
348 else if (iDataSource) |
|
349 {//record |
|
350 iDataPath->AddDataSourceL(iDataSource); |
|
351 if (iSinkFormat) //restore the format data type |
|
352 { //this will force datapth to use CMMFCodec |
|
353 iSinkFormat->SetSinkDataTypeCode(sinkFormatDataType,KUidMediaTypeAudio); |
|
354 } |
|
355 } |
|
356 if (iSinkFormat) |
|
357 iDataPath->AddDataSinkL(iSinkFormat); |
|
358 else if (iDataSink) |
|
359 {//play |
|
360 //need to set the audio output fourCC code to pcm16 |
|
361 //in order to force the data path to use a CMMFCodec |
|
362 CMMFAudioOutput* ao = static_cast<CMMFAudioOutput*>(iDataSink); |
|
363 CMMFDevSound* devSound = &(ao->SoundDevice()); |
|
364 |
|
365 //PrimeL() needs to run synchronously but DevSound initialisation is |
|
366 //asynchronous. iWaitForAsyncService halts execution until |
|
367 //iDevSoundEventHandler informs us this process has completed. |
|
368 iDevSoundEventHandler.SetInterceptedDevSoundObserver(ao); |
|
369 iDevSoundEventHandler.SetEventObserver(this); |
|
370 //need to reinitialize the devsound to load up a null pcm16->16 |
|
371 //hw device - note this will delete the previous |
|
372 //non pcm16 hw device |
|
373 //note can't set this on the audio output as this won't update |
|
374 //the hw device |
|
375 devSound->InitializeL(iDevSoundEventHandler,KMMFFourCCCodePCM16,EMMFStatePlaying); |
|
376 iWaitForAsyncService->Start(); |
|
377 |
|
378 //now tell audio output were pcm16 |
|
379 iDataSink->SetSinkDataTypeCode(KMMFFourCCCodePCM16, KUidMediaTypeAudio); |
|
380 iDataPath->AddDataSinkL(iDataSink); |
|
381 } |
|
382 iSourceAndSinkAdded = ETrue ; |
|
383 } |
|
384 |
|
385 iDataPath->PrimeL(); |
|
386 if ((iSinkFormat) && (!iSourceFormat)) |
|
387 {//we are recording to a clip so the data path position is the sink |
|
388 //need to set datapath position to end of format pos (incase sink clip already exists |
|
389 TTimeIntervalMicroSeconds duration = iSinkFormat->Duration(iMediaId); |
|
390 if (duration != TTimeIntervalMicroSeconds(0)) |
|
391 {//the file already exists and has a duration so set data path position to the end of the file |
|
392 iDataPath->SetPositionL(duration); |
|
393 } |
|
394 } |
|
395 //[ it is now safe to make the transition to primed ] |
|
396 SetState( EPrimed ); |
|
397 } |
|
398 else if (State() == EPrimed) |
|
399 { //controller is already primed so just pass prime onto DP |
|
400 iDataPath->PrimeL(); |
|
401 } |
|
402 |
|
403 //[ assert the post condition that we are in the state primed] |
|
404 __ASSERT_ALWAYS( SetState( EPrimed ), Panic( EPostConditionViolation )); |
|
405 // [ assert the invariant] |
|
406 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant ) ); |
|
407 } |
|
408 |
|
409 /** |
|
410 * ResetL |
|
411 * This method resets the controller |
|
412 * |
|
413 */ |
|
414 void CMMFTestUseOldCodecAudioController::ResetL() |
|
415 { |
|
416 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant ) ); |
|
417 |
|
418 // Stop recording if it's not stopped, |
|
419 if (State() != EStopped) |
|
420 { |
|
421 iDataPath->Stop(); |
|
422 SetState(EStopped); |
|
423 } |
|
424 |
|
425 // Remove references to source and sink |
|
426 iDataPath->ResetL(); |
|
427 |
|
428 delete iSourceFormat; iSourceFormat = NULL ; |
|
429 delete iSinkFormat; iSinkFormat = NULL ; |
|
430 |
|
431 //[ ensure loggoff of source and sink ] |
|
432 iDataSource = NULL ; |
|
433 iDataSink = NULL ; |
|
434 iSourceAndSinkAdded = EFalse; |
|
435 |
|
436 // [ assert the invariant] |
|
437 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant ) ); |
|
438 |
|
439 // [ assert the post condition |
|
440 // state == stopped |
|
441 // iDataSource is NULL |
|
442 // iSourceFormat is NULL |
|
443 // iSinkFormat is NULL ] |
|
444 __ASSERT_ALWAYS( ResetPostCondition(), Panic( EBadReset )); |
|
445 __ASSERT_ALWAYS( Invariant(), Panic(EBadState)); |
|
446 } |
|
447 |
|
448 /** |
|
449 * ResetPostCondition |
|
450 * This function determnines if the reset post condition is valid |
|
451 * @xxxx |
|
452 */ |
|
453 TBool CMMFTestUseOldCodecAudioController::ResetPostCondition() const |
|
454 { |
|
455 |
|
456 TBool result = EFalse ; |
|
457 if((iSourceFormat == NULL) && |
|
458 (iDataSink == NULL) && |
|
459 (iDataSource == NULL) && |
|
460 (iSinkFormat == NULL) && |
|
461 (State() == EStopped)) |
|
462 { |
|
463 result = ETrue; |
|
464 } |
|
465 |
|
466 return result; |
|
467 } |
|
468 |
|
469 |
|
470 /** |
|
471 * |
|
472 * PlayL |
|
473 * |
|
474 */ |
|
475 void CMMFTestUseOldCodecAudioController::PlayL() |
|
476 { |
|
477 // [ assert the precondition that the |
|
478 // play command is only activated in the primed state] |
|
479 if ( State() != EPrimed) |
|
480 User::Leave(KErrNotReady); |
|
481 |
|
482 // [ assert the Invariant ] |
|
483 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
484 |
|
485 //[datapath propogates play to sink & source] |
|
486 iDataPath->PlayL(); |
|
487 SetState( EPlaying ); |
|
488 |
|
489 //[ assert the post condition we are playing ] |
|
490 //No - this assumption is not always true if an error occurs eg OOM |
|
491 //the state could be EStopped |
|
492 // __ASSERT_ALWAYS( (State() == EPlaying ), Panic( EBadState)); |
|
493 //[ assert the invariant ] |
|
494 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
495 } |
|
496 |
|
497 /** |
|
498 * PauseL |
|
499 * |
|
500 */ |
|
501 void CMMFTestUseOldCodecAudioController::PauseL() |
|
502 { |
|
503 // [ assert the invariant ] |
|
504 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
505 |
|
506 //[ assert the precondition that we are playing ] |
|
507 if ( State() != EPlaying) |
|
508 User::Leave(KErrNotReady); |
|
509 |
|
510 //[ datapath propogates pause to sink & source ] |
|
511 iDataPath->Pause(); |
|
512 SetState(EPrimed); |
|
513 |
|
514 //[ assert the post condition we are primed ] |
|
515 __ASSERT_ALWAYS( (State() == EPrimed ), Panic( EBadState)); |
|
516 //[ assert the invariant ] |
|
517 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
518 } |
|
519 |
|
520 /** |
|
521 * StopL |
|
522 * |
|
523 */ |
|
524 void CMMFTestUseOldCodecAudioController::StopL(TMMFMessage& aMessage) |
|
525 { |
|
526 //[ assert the invariant ] |
|
527 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
528 // [ precondition that we are not already stopped |
|
529 // && if we are stopped do nothing. |
|
530 //If we are stopping a recording, we need to give the datapath chance to |
|
531 //process that data which has already been captured. We therefore stay in the EPlaying |
|
532 //state, but use iStoppingRecording to indicate that we are stopping. |
|
533 |
|
534 if ((State() != EStopped) && !iStoppingRecording) |
|
535 { |
|
536 if((State() == EPlaying) && (iDataSource->DataSourceType()==KUidMmfAudioInput)) //we are recording |
|
537 { |
|
538 // datapath is requested to stop recording but process any alreay captured buffers, |
|
539 // the pause method is used for this purpose and as such, the data path must |
|
540 // determine that it is recording to be able to act accordingly. |
|
541 // aMessgae is not completed until datapath advises that it has completed. |
|
542 iDataPath->Pause(); |
|
543 iStoppingMessage = CMMFMessageHolder::NewL(aMessage); |
|
544 iStoppingRecording = ETrue; |
|
545 } |
|
546 else |
|
547 { |
|
548 // datapath propogates stop to sink & source |
|
549 iDataPath->Stop(); |
|
550 SetState(EStopped); |
|
551 } |
|
552 } |
|
553 |
|
554 //complete message as request is complete. |
|
555 if(State() == EStopped && !IsUnderTest()) |
|
556 { |
|
557 aMessage.Complete(KErrNone); |
|
558 } |
|
559 |
|
560 //[ assert the invariant ] |
|
561 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
562 } |
|
563 |
|
564 /** |
|
565 * PositionL |
|
566 * Preconditions: |
|
567 * The Controller is in the state EPrimed |
|
568 * @return TTimeIntervalMicroSeconds |
|
569 * |
|
570 */ |
|
571 TTimeIntervalMicroSeconds CMMFTestUseOldCodecAudioController::PositionL() const |
|
572 { |
|
573 //[ assert the invariant ] |
|
574 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
575 // [ precondition that we are playing or primed ] |
|
576 if( !((State() == EPrimed) || (State() == EPlaying))) |
|
577 User::Leave(KErrNotReady); |
|
578 |
|
579 TTimeIntervalMicroSeconds position = iDataPath->Position(); |
|
580 |
|
581 //[ assert the invariant ] |
|
582 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
583 |
|
584 return position; |
|
585 } |
|
586 |
|
587 /** |
|
588 * SetPositionL |
|
589 * |
|
590 * @param aPosition |
|
591 * |
|
592 */ |
|
593 void CMMFTestUseOldCodecAudioController::SetPositionL(const TTimeIntervalMicroSeconds& aPosition) |
|
594 { |
|
595 //[ assert the invariant ] |
|
596 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
597 |
|
598 // [ precondition that we are not already stopped ] |
|
599 if (iState == EStopped) |
|
600 User::Leave(KErrNotReady); |
|
601 |
|
602 //[ precondition that the position is >= 0 && <= Duration ] |
|
603 { |
|
604 TTimeIntervalMicroSeconds theDuration(0); |
|
605 if (iSourceFormat) |
|
606 { //if the source is a clip then the duration always refers to the source - even if the sink is a clip |
|
607 theDuration = iSourceFormat->Duration(iMediaId); |
|
608 } |
|
609 else if (iSinkFormat) |
|
610 { //duration of recorded clip |
|
611 theDuration = iSinkFormat->Duration(iMediaId); |
|
612 } |
|
613 TTimeIntervalMicroSeconds theStart(0); |
|
614 if( ( aPosition < theStart) || ( aPosition > theDuration) ) |
|
615 //[ invalid position before start and after end] |
|
616 User::Leave(KErrArgument); |
|
617 } |
|
618 |
|
619 //[ set the position on the data path ] |
|
620 iDataPath->SetPositionL(aPosition); |
|
621 |
|
622 //[ assert the invariant ] |
|
623 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
624 |
|
625 // [ post condition not checked ] |
|
626 //[ we do not compare the set position with get postion |
|
627 // because the interface to do so is poor ] |
|
628 } |
|
629 |
|
630 /** |
|
631 * |
|
632 * DurationL |
|
633 * |
|
634 * @returns TTimeIntervalMicroSeconds |
|
635 * |
|
636 */ |
|
637 TTimeIntervalMicroSeconds CMMFTestUseOldCodecAudioController::DurationL() const |
|
638 { |
|
639 //[ assert the invariant ] |
|
640 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
641 |
|
642 |
|
643 // [ assert we have a format that supports duration ] |
|
644 if( !( iSourceFormat || iSinkFormat ) ) |
|
645 User::Leave(KErrNotSupported); |
|
646 |
|
647 //[ now do the real work of getting the duration ] |
|
648 // ------------------------------------------------ |
|
649 TTimeIntervalMicroSeconds theDuration(0); |
|
650 if (iSourceFormat) |
|
651 { //if the source is a clip then the duration always refers to the source - even if the sink is a clip |
|
652 theDuration = iSourceFormat->Duration(iMediaId); |
|
653 } |
|
654 else if (iSinkFormat) |
|
655 { //duration of recorded clip |
|
656 theDuration = iSinkFormat->Duration(iMediaId); |
|
657 } |
|
658 |
|
659 //[ assert the invariant ] |
|
660 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
661 |
|
662 return theDuration; |
|
663 } |
|
664 |
|
665 /** |
|
666 * |
|
667 * GetNumberOfMetaDataEntriesL |
|
668 * |
|
669 * @param "TInt" |
|
670 * |
|
671 */ |
|
672 void CMMFTestUseOldCodecAudioController::GetNumberOfMetaDataEntriesL(TInt& aNumberOfEntries ) |
|
673 { |
|
674 |
|
675 //[ assert the invariant ] |
|
676 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
677 |
|
678 //[ precondition that we are in the primed state or stopped ] |
|
679 if( !((State() == EPrimed) || ( State() == EStopped))) |
|
680 User::Leave(KErrNotReady); |
|
681 |
|
682 // [ precondition there is a sink format ] |
|
683 if (!iDataSink) |
|
684 User::Leave(KErrNotSupported); |
|
685 |
|
686 // [ precondition the sink format is an encode format ] |
|
687 if ((iDataSink->DataSinkType()!=KUidMmfAudioOutput) && |
|
688 (iDataSource->DataSourceType()!= KUidMmfAudioInput) ) |
|
689 User::Leave(KErrNotSupported); |
|
690 |
|
691 if (iDataSink->DataSinkType()==KUidMmfAudioOutput) |
|
692 { |
|
693 |
|
694 //[ precondition the format exists ] |
|
695 if( !iSourceFormat ) |
|
696 User::Leave(KErrNotSupported); |
|
697 |
|
698 //[ Get the Number of meta data entries from the sink format ] |
|
699 iSourceFormat->GetNumberOfMetaDataEntriesL( aNumberOfEntries ); |
|
700 } |
|
701 else if (iDataSource->DataSourceType()==KUidMmfAudioInput) |
|
702 { |
|
703 if( !iSinkFormat ) |
|
704 User::Leave(KErrNotSupported); |
|
705 |
|
706 iSinkFormat->GetNumberOfMetaDataEntriesL( aNumberOfEntries ); |
|
707 } |
|
708 |
|
709 //[ assert the invariant ] |
|
710 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
711 |
|
712 } |
|
713 |
|
714 /** |
|
715 * GetMetaDataEntryL |
|
716 * @param aIndex |
|
717 * @returns "CMMFMetaDataEntry*" |
|
718 */ |
|
719 CMMFMetaDataEntry* CMMFTestUseOldCodecAudioController::GetMetaDataEntryL(TInt aIndex ) |
|
720 { |
|
721 //[ assert the invariant ] |
|
722 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
723 |
|
724 //[ precondition that we are in the primed state or stopped ] |
|
725 if( !((State() == EPrimed) || ( State() == EStopped))) |
|
726 User::Leave(KErrNotReady); |
|
727 |
|
728 // [ precondition there is a sink format ] |
|
729 if (!iDataSink) |
|
730 User::Leave(KErrNotSupported); |
|
731 |
|
732 iDataSink->DataSinkType(); |
|
733 iDataSource->DataSourceType(); |
|
734 |
|
735 // [ precondition the sink or source is either an audio output or input ] |
|
736 if ((iDataSink->DataSinkType()!= KUidMmfAudioOutput) && |
|
737 (iDataSource->DataSourceType()!= KUidMmfAudioInput )) |
|
738 User::Leave(KErrNotSupported); |
|
739 |
|
740 //[ Get the meta data entry from the sink format ] |
|
741 CMMFMetaDataEntry* theEntry = NULL; |
|
742 |
|
743 if (iDataSink->DataSinkType()==KUidMmfAudioOutput) |
|
744 { |
|
745 //[ precondition the format exists ] |
|
746 if( !iSourceFormat ) |
|
747 User::Leave(KErrNotSupported); |
|
748 |
|
749 //[ Get the Number of meta data entries from the sink format ] |
|
750 theEntry = iSourceFormat->MetaDataEntryL(aIndex); |
|
751 } |
|
752 else if (iDataSource->DataSourceType()==KUidMmfAudioInput) |
|
753 { |
|
754 //[ precondition the format exits ] |
|
755 if( !iSinkFormat ) |
|
756 User::Leave(KErrNotSupported); |
|
757 theEntry = iSinkFormat->MetaDataEntryL(aIndex); |
|
758 } |
|
759 |
|
760 //[ assert the post condition that the entry is not null ] |
|
761 __ASSERT_ALWAYS( theEntry, Panic(EBadInvariant)); |
|
762 |
|
763 //[ assert the invariant ] |
|
764 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
765 |
|
766 return theEntry; |
|
767 } |
|
768 |
|
769 /** |
|
770 * RemoveDataSourceL |
|
771 * @param aDataSource |
|
772 * |
|
773 */ |
|
774 void CMMFTestUseOldCodecAudioController::RemoveDataSourceL(MDataSource& aDataSource ) |
|
775 { |
|
776 //[ assert the invariant ] |
|
777 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant) ); |
|
778 |
|
779 //[ precondition is that we have a data source ] |
|
780 if( !iDataSource ) |
|
781 User::Leave(KErrNotReady); |
|
782 |
|
783 //[precondition the data source is the data source we have] |
|
784 if( iDataSource != &aDataSource ) |
|
785 User::Leave(KErrArgument); |
|
786 |
|
787 //[ the controller is in the stopped state ] |
|
788 if(State() != EStopped) |
|
789 User::Leave(KErrNotReady); |
|
790 |
|
791 //[ remove the data sink from the controller and delete the format] |
|
792 if( iSourceAndSinkAdded ) |
|
793 { |
|
794 __ASSERT_ALWAYS( iDataPath, Panic( EBadState )); |
|
795 //[ Remove references to source and sink ] |
|
796 iDataPath->ResetL(); |
|
797 iSourceAndSinkAdded = EFalse ; |
|
798 } |
|
799 |
|
800 // [ delete the data sink and format ] |
|
801 iDataSource = NULL ; |
|
802 delete iSourceFormat; |
|
803 iSourceFormat = NULL; |
|
804 |
|
805 // [ assert postcondition we are stopped ] |
|
806 __ASSERT_ALWAYS( (State() == EStopped), Panic(EPostConditionViolation) ); |
|
807 |
|
808 //[ assert postcondition the SourceAndSinkAdded is false ] |
|
809 __ASSERT_ALWAYS( !iSourceAndSinkAdded, Panic( EPostConditionViolation )); |
|
810 |
|
811 //[ assert postcondition the data sinkformat is null ] |
|
812 __ASSERT_ALWAYS( (iSourceFormat == NULL ), Panic( EPostConditionViolation )); |
|
813 |
|
814 //[ assert postcondition the data sink is null ] |
|
815 __ASSERT_ALWAYS( (iDataSource == NULL ), Panic( EPostConditionViolation )); |
|
816 |
|
817 //[ assert the invariant ] |
|
818 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
819 |
|
820 } |
|
821 |
|
822 /** |
|
823 * RemoveDataSinkL |
|
824 * |
|
825 * @param aDataSink |
|
826 * |
|
827 */ |
|
828 void CMMFTestUseOldCodecAudioController::RemoveDataSinkL(MDataSink& aDataSink ) |
|
829 { |
|
830 //[ assert the invariant ] |
|
831 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant) ); |
|
832 |
|
833 //[ precondition is that we have a data sink ] |
|
834 if( !iDataSink ) |
|
835 User::Leave(KErrNotSupported); |
|
836 |
|
837 //[precondition the data sink is the data sink we have] |
|
838 if( iDataSink != &aDataSink ) |
|
839 User::Leave(KErrNotSupported); |
|
840 |
|
841 //[ the controller is in the stopped state ] |
|
842 if(State() != EStopped) |
|
843 User::Leave(KErrNotReady); |
|
844 |
|
845 //[ remove the data sink from the controller and delete the format] |
|
846 if( iSourceAndSinkAdded ) |
|
847 { |
|
848 __ASSERT_ALWAYS( iDataPath, Panic( EBadState )); |
|
849 //[ Remove references to source and sink ] |
|
850 iDataPath->ResetL(); |
|
851 iSourceAndSinkAdded = EFalse ; |
|
852 } |
|
853 |
|
854 // [ reset data sink referenece and remove the format ] |
|
855 iDataSink = NULL ; |
|
856 delete iSinkFormat; |
|
857 iSinkFormat = NULL; |
|
858 |
|
859 // [ assert postcondition we are stopped ] |
|
860 __ASSERT_ALWAYS( (State() == EStopped), Panic(EPostConditionViolation) ); |
|
861 |
|
862 //[ assert postcondition the SourceAndSinkAdded is false ] |
|
863 __ASSERT_ALWAYS( !iSourceAndSinkAdded, Panic( EPostConditionViolation )); |
|
864 |
|
865 //[ assert postcondition the data sinkformat is null ] |
|
866 __ASSERT_ALWAYS( (iSinkFormat == NULL ), Panic( EPostConditionViolation )); |
|
867 |
|
868 //[ assert postcondition the data sink is null ] |
|
869 __ASSERT_ALWAYS( (iDataSink == NULL ), Panic( EPostConditionViolation )); |
|
870 |
|
871 //[ assert the invariant ] |
|
872 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
873 } |
|
874 |
|
875 /** |
|
876 * CustomCommand |
|
877 * @param aMessage |
|
878 */ |
|
879 void CMMFTestUseOldCodecAudioController::CustomCommand(TMMFMessage& aMessage) |
|
880 { |
|
881 //[ assert the invariant ] |
|
882 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
883 // [ We do not have any custom commands ] |
|
884 aMessage.Complete(KErrNotSupported); |
|
885 } |
|
886 |
|
887 /** |
|
888 * NegotiateL |
|
889 * |
|
890 */ |
|
891 void CMMFTestUseOldCodecAudioController::NegotiateL() |
|
892 { |
|
893 //[ assert the invariant ] |
|
894 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
895 |
|
896 //utility function used by custom to negotiate source sink settings after a change |
|
897 if ((iSourceFormat)&&(iSinkFormat)) //convert |
|
898 { |
|
899 iSinkFormat->NegotiateL(*iSourceFormat); |
|
900 iSourceFormat->NegotiateSourceL(*iSinkFormat); |
|
901 iSinkFormat->NegotiateL(*iSourceFormat); |
|
902 |
|
903 // check for upsampling attempts |
|
904 if (iSinkFormat->SampleRate() > iSourceFormat->SampleRate()) |
|
905 { |
|
906 // we don't support upsampling |
|
907 User::Leave( KErrNotSupported ); |
|
908 } |
|
909 } |
|
910 else if ((iDataSource)&&(iSinkFormat)) //record |
|
911 { |
|
912 // need two step negotiation for record |
|
913 // first try to set the audio input settings to match the required settings for recording |
|
914 iDataSource->NegotiateSourceL(*iSinkFormat); |
|
915 // now call negotiateL on the sink in order to tell it what the audio input was set to. |
|
916 iSinkFormat->NegotiateL(*iDataSource); |
|
917 } |
|
918 else if ((iSourceFormat)&&(iDataSink)) //play |
|
919 iDataSink->NegotiateL(*iSourceFormat); |
|
920 |
|
921 //[ assert the invariant ] |
|
922 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
923 } |
|
924 |
|
925 /** |
|
926 * SetPrioritySettings |
|
927 * |
|
928 * @param aPrioritySettings |
|
929 */ |
|
930 void CMMFTestUseOldCodecAudioController::SetPrioritySettings(const TMMFPrioritySettings& aPrioritySettings) |
|
931 { |
|
932 //[ assert the invariant ] |
|
933 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
934 |
|
935 //[ assert the precondition ] |
|
936 if(State() != EStopped) |
|
937 { |
|
938 ASSERT(EFalse); // used to leave here with KErrNotReady |
|
939 return; |
|
940 } |
|
941 |
|
942 //[ update the priority settings of the controller] |
|
943 iPrioritySettings = aPrioritySettings; |
|
944 |
|
945 //pass settings on to source and sink |
|
946 if (iDataSource) |
|
947 { |
|
948 iDataSource->SetSourcePrioritySettings(iPrioritySettings); |
|
949 } |
|
950 if (iDataSink) |
|
951 { |
|
952 iDataSink->SetSinkPrioritySettings(iPrioritySettings); |
|
953 } |
|
954 |
|
955 // assert the post condition |
|
956 //__ASSERT_ALWAYS( (iPrioritySettings == aPrioritySettings), Panic( )); |
|
957 //[ assert the invariant ] |
|
958 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
959 } |
|
960 |
|
961 /** |
|
962 * SendEventToClient |
|
963 * |
|
964 * @param aEvent |
|
965 */ |
|
966 TInt CMMFTestUseOldCodecAudioController::SendEventToClient(const TMMFEvent& aEvent) |
|
967 { |
|
968 //[ assert the invariant ] |
|
969 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
970 |
|
971 TMMFEvent controllerEvent; |
|
972 //Were going to stop playing, force event type to be the correct type |
|
973 controllerEvent.iEventType = KMMFEventCategoryPlaybackComplete; |
|
974 controllerEvent.iErrorCode = aEvent.iErrorCode; |
|
975 |
|
976 |
|
977 |
|
978 //If we receive KErrNone from the DataPath, it indicates that it has |
|
979 //successfully completed playing/converting/recording. |
|
980 if ((aEvent.iEventType == KMMFEventCategoryPlaybackComplete) && |
|
981 (aEvent.iErrorCode == KErrNone)) |
|
982 { |
|
983 if(iStoppingRecording) |
|
984 { |
|
985 iStoppingRecording = EFalse; |
|
986 iDataPath->Stop(); |
|
987 SetState( EStopped ); |
|
988 |
|
989 //complete the clients stop request |
|
990 iStoppingMessage->Complete(KErrNone); |
|
991 delete iStoppingMessage; iStoppingMessage=NULL; |
|
992 |
|
993 //we don't want to send an event to the client |
|
994 return KErrNone; |
|
995 } |
|
996 else |
|
997 {//datapath has reached end of file so set internal state to primed |
|
998 SetState( EPrimed ); |
|
999 } |
|
1000 } |
|
1001 else |
|
1002 { |
|
1003 if ( State()!= EStopped) |
|
1004 { |
|
1005 //datapath propogates stop to sink & source |
|
1006 iDataPath->Stop(); |
|
1007 SetState( EStopped ); |
|
1008 |
|
1009 if(iStoppingRecording) |
|
1010 {// an error has occurred while we were waiting for recording to stop, |
|
1011 //must complete clients request |
|
1012 iStoppingRecording = EFalse; |
|
1013 iStoppingMessage->Complete(aEvent.iErrorCode); |
|
1014 delete iStoppingMessage; iStoppingMessage=NULL; |
|
1015 } |
|
1016 } |
|
1017 } |
|
1018 |
|
1019 //now send event to client... |
|
1020 TInt result = DoSendEventToClient(controllerEvent); |
|
1021 |
|
1022 //[ assert the invariant ] |
|
1023 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1024 |
|
1025 return result; |
|
1026 } |
|
1027 |
|
1028 |
|
1029 /** |
|
1030 * MapdSetVolumeL |
|
1031 * |
|
1032 * @param aVolume |
|
1033 * |
|
1034 */ |
|
1035 void CMMFTestUseOldCodecAudioController::MapdSetVolumeL(TInt aVolume) |
|
1036 { |
|
1037 //[ assert the invariant ] |
|
1038 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1039 |
|
1040 // [ precondition is true for state |
|
1041 // we can set the volume in any state ] |
|
1042 |
|
1043 //[ precondition we have a data sink ] |
|
1044 if (!iDataSink) |
|
1045 User::Leave(KErrNotReady); |
|
1046 |
|
1047 // [ precondition that the data sink is an audio output ] |
|
1048 // Make sure that iDataSink is an Audio Output |
|
1049 if (iDataSink->DataSinkType() != KUidMmfAudioOutput) |
|
1050 User::Leave(KErrNotSupported); |
|
1051 |
|
1052 MMMFAudioOutput* audioOutput = STATIC_CAST(MMMFAudioOutput*, iDataSink); |
|
1053 |
|
1054 // [ assert the precondition that aVolume is in range ] |
|
1055 TInt maxVolume = audioOutput->SoundDevice().MaxVolume(); |
|
1056 if( ( aVolume < 0 ) || ( aVolume > maxVolume )) |
|
1057 User::Leave(KErrArgument); |
|
1058 |
|
1059 //[ set the volume on the device ] |
|
1060 audioOutput->SoundDevice().SetVolume(aVolume); |
|
1061 |
|
1062 //[ assert the post condition volume is equal to a volume] |
|
1063 TInt soundVolume = 0; |
|
1064 soundVolume = audioOutput->SoundDevice().Volume(); |
|
1065 |
|
1066 __ASSERT_ALWAYS( ( soundVolume == aVolume), Panic(EPostConditionViolation)); |
|
1067 |
|
1068 //[ assert the invariant ] |
|
1069 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1070 } |
|
1071 |
|
1072 /** |
|
1073 * |
|
1074 * MapdGetMaxVolumeL |
|
1075 * |
|
1076 * @param aMaxVolume |
|
1077 * |
|
1078 */ |
|
1079 void CMMFTestUseOldCodecAudioController::MapdGetMaxVolumeL(TInt& aMaxVolume) |
|
1080 { |
|
1081 // [ assert the invariant ] |
|
1082 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1083 |
|
1084 //[ we can get max volume in any state ] |
|
1085 |
|
1086 // [ precondition we must have a data sink ] |
|
1087 if (!iDataSink) |
|
1088 User::Leave(KErrNotReady); |
|
1089 |
|
1090 //[ precondition the sink must be an audio output] |
|
1091 // Make sure that iDataSink is an Audio Output |
|
1092 if (iDataSink->DataSinkType() != KUidMmfAudioOutput) |
|
1093 User::Leave(KErrNotSupported); |
|
1094 |
|
1095 //[ get the volume from the device ] |
|
1096 MMMFAudioOutput* audioOutput = STATIC_CAST(MMMFAudioOutput*, iDataSink); |
|
1097 aMaxVolume = audioOutput->SoundDevice().MaxVolume(); |
|
1098 |
|
1099 //[ assert the invariant ] |
|
1100 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1101 |
|
1102 } |
|
1103 |
|
1104 |
|
1105 /** |
|
1106 * |
|
1107 * MapdGetVolumeL |
|
1108 * |
|
1109 * @param aVolume |
|
1110 * |
|
1111 */ |
|
1112 void CMMFTestUseOldCodecAudioController::MapdGetVolumeL(TInt& aVolume) |
|
1113 { |
|
1114 // [ assert the invariant ] |
|
1115 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1116 |
|
1117 //[ precondition that we have a data sink ] |
|
1118 if (!iDataSink) |
|
1119 User::Leave(KErrNotReady); |
|
1120 |
|
1121 //[ precondition iDataSink is an Audio Output ] |
|
1122 if (iDataSink->DataSinkType() != KUidMmfAudioOutput) |
|
1123 User::Leave(KErrNotSupported); |
|
1124 |
|
1125 // [ get the volume ] |
|
1126 MMMFAudioOutput* audioOutput = STATIC_CAST(MMMFAudioOutput*, iDataSink); |
|
1127 aVolume = audioOutput->SoundDevice().Volume(); |
|
1128 |
|
1129 // [ assert precondition that the volume is in range |
|
1130 // 0.. aMaxVolume ] |
|
1131 TInt aMaxVolume = audioOutput->SoundDevice().MaxVolume(); |
|
1132 __ASSERT_ALWAYS( (aVolume <= aMaxVolume), Panic(EBadState)); |
|
1133 __ASSERT_ALWAYS( (aVolume >= 0), Panic(EBadState)); |
|
1134 |
|
1135 // [ assert the invariant ] |
|
1136 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1137 |
|
1138 } |
|
1139 |
|
1140 /** |
|
1141 * |
|
1142 * MapdSetVolumeRampL |
|
1143 * |
|
1144 * @param aRampDuration |
|
1145 * |
|
1146 */ |
|
1147 void CMMFTestUseOldCodecAudioController::MapdSetVolumeRampL(const TTimeIntervalMicroSeconds& aRampDuration) |
|
1148 { |
|
1149 // [ assert the invariant ] |
|
1150 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1151 |
|
1152 //[ precondition that we have a data sink ] |
|
1153 if (!iDataSink) |
|
1154 User::Leave(KErrNotReady); |
|
1155 |
|
1156 // [ precondition iDataSink is an Audio Output ] |
|
1157 if (iDataSink->DataSinkType() != KUidMmfAudioOutput) |
|
1158 User::Leave(KErrNotSupported); |
|
1159 |
|
1160 //[ set the volume ramp ] |
|
1161 MMMFAudioOutput* audioOutput = STATIC_CAST(MMMFAudioOutput*, iDataSink); |
|
1162 audioOutput->SoundDevice().SetVolumeRamp(aRampDuration); |
|
1163 |
|
1164 //[ assert the invariant ] |
|
1165 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1166 |
|
1167 } |
|
1168 |
|
1169 |
|
1170 /** |
|
1171 * |
|
1172 * MapdSetBalanceL |
|
1173 * |
|
1174 * @param aBalance |
|
1175 * |
|
1176 */ |
|
1177 void CMMFTestUseOldCodecAudioController::MapdSetBalanceL(TInt aBalance) |
|
1178 { |
|
1179 //[ assert the invariant ] |
|
1180 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
1181 |
|
1182 // [ precondition is that we have a data sink ] |
|
1183 if (!iDataSink) |
|
1184 User::Leave(KErrNotReady); |
|
1185 |
|
1186 // [ precondition is that the data sink is an audio output] |
|
1187 if (iDataSink->DataSinkType() != KUidMmfAudioOutput) |
|
1188 User::Leave(KErrNotSupported); |
|
1189 |
|
1190 //[ get the audio output ] |
|
1191 MMMFAudioOutput* audioOutput = STATIC_CAST(MMMFAudioOutput*, iDataSink); |
|
1192 |
|
1193 // [ separate out left and right balance ] |
|
1194 TInt left = 0; |
|
1195 TInt right = 0; |
|
1196 CalculateLeftRightBalance( left, right, aBalance ); |
|
1197 |
|
1198 //[ set the balance ] |
|
1199 audioOutput->SoundDevice().SetPlayBalanceL(left, right); |
|
1200 |
|
1201 // [assert the post condition that the balance is set correctly] |
|
1202 TInt rightBalance = 0; |
|
1203 TInt leftBalance = 0; |
|
1204 audioOutput->SoundDevice().GetPlayBalanceL(leftBalance, rightBalance); |
|
1205 |
|
1206 //[ assert post condition holds] |
|
1207 TBool postCondition = (( rightBalance == right) && ( leftBalance == left)); |
|
1208 __ASSERT_ALWAYS( postCondition, Panic( EPostConditionViolation ) ); |
|
1209 |
|
1210 //[ assert the invariant ] |
|
1211 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
1212 } |
|
1213 |
|
1214 /** |
|
1215 * CalculateLeftRightBalance |
|
1216 * @param aLeft |
|
1217 * @param aRight |
|
1218 * @param aBalance |
|
1219 * Preconditions: |
|
1220 * !(aBalance < KMMFBalanceMaxLeft || aBalance > KMMFBalanceMaxRight) |
|
1221 * y = m x + c |
|
1222 * aLeft = m ( aBalance ) + c |
|
1223 * when aBalance = KMMFBalanceMaxLeft aLeft = 100 |
|
1224 * when aBalance = KMMFBalanceMaxRight aLeft = 0 |
|
1225 * 100 = m( KMMFBalanceMaxLeft ) + c |
|
1226 * 0 = m( KMMFBalanceMaxRight ) + c |
|
1227 * c = -(KMMFBalanceMaxRight) m |
|
1228 * 100 = m(KMMFBalanceMaxLeft ) - m(KMMFBalanceMaxRight) |
|
1229 * m = 100/(KMMFBalanceMaxLeft - KMMFBalanceMaxRight ) |
|
1230 * c = -(KMMFBalanceMaxRight) * 100 /(KMMFBalanceMaxLeft - KMMFBalanceMaxRight ) |
|
1231 * aLeft = ( aBalance - KMMFBalanceMaxRight ) * 100 /( KMMFBalanceMaxLeft - KMMFBalanceMaxRight ) |
|
1232 * @xxxx |
|
1233 */ |
|
1234 void CMMFTestUseOldCodecAudioController::CalculateLeftRightBalance( TInt& aLeft, TInt& aRight, TInt aBalance ) const |
|
1235 { |
|
1236 // Check the balance is within limits & modify to min or max values if necessary |
|
1237 if (aBalance < KMMFBalanceMaxLeft) |
|
1238 aBalance = KMMFBalanceMaxLeft; |
|
1239 if (aBalance > KMMFBalanceMaxRight) |
|
1240 aBalance = KMMFBalanceMaxRight; |
|
1241 |
|
1242 // [ assert precondition that aBalance is within limits ] |
|
1243 __ASSERT_ALWAYS( !(aBalance < KMMFBalanceMaxLeft || aBalance > KMMFBalanceMaxRight), Panic(EBadArgument)); |
|
1244 |
|
1245 //[ Now separate percentage balances out from aBalance ] |
|
1246 aLeft = (100 * (aBalance-KMMFBalanceMaxRight)) / (KMMFBalanceMaxLeft-KMMFBalanceMaxRight); |
|
1247 aRight = 100 - aLeft; |
|
1248 |
|
1249 //[ assert post condition that left and right are within range ] |
|
1250 __ASSERT_ALWAYS( ( (aLeft <= 100) && (aLeft >= 0) ), Panic(EPostConditionViolation)); |
|
1251 __ASSERT_ALWAYS( ( (aRight <= 100) && (aRight >= 0) ), Panic(EPostConditionViolation)); |
|
1252 } |
|
1253 |
|
1254 |
|
1255 /** |
|
1256 * MapdGetBalanceL |
|
1257 * @param aBalance |
|
1258 * |
|
1259 */ |
|
1260 void CMMFTestUseOldCodecAudioController::MapdGetBalanceL(TInt& aBalance) |
|
1261 { |
|
1262 //[ assert the invariant ] |
|
1263 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1264 |
|
1265 //[ precondition that we have a sink] |
|
1266 if (!iDataSink) |
|
1267 User::Leave(KErrNotReady); |
|
1268 |
|
1269 // [ iDataSink is an Audio Output ] |
|
1270 if (iDataSink->DataSinkType() != KUidMmfAudioOutput) |
|
1271 User::Leave(KErrNotSupported); |
|
1272 |
|
1273 // [ get the play balance ] |
|
1274 MMMFAudioOutput* audioOutput = STATIC_CAST(MMMFAudioOutput*, iDataSink); |
|
1275 TInt left = 50; // arbitrary values |
|
1276 TInt right = 50; |
|
1277 audioOutput->SoundDevice().GetPlayBalanceL(left, right); |
|
1278 CalculateBalance( aBalance, left, right ); |
|
1279 |
|
1280 //[ assert the invariant ] |
|
1281 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1282 } |
|
1283 |
|
1284 /** |
|
1285 * CalculateBalance |
|
1286 * @param aBalance |
|
1287 * @param aLeft |
|
1288 * @param aRight |
|
1289 * |
|
1290 * follows a simple straight line transformation |
|
1291 * y = m x + c |
|
1292 * m = (KMMFBalanceMaxLeft-KMMFBalanceMaxRight)/ 100 |
|
1293 * c = KMMFBalanceMaxRight |
|
1294 * by substitution |
|
1295 * when aLeft = 0 |
|
1296 * KMMFBalanceMaxRight = m * 0 + c |
|
1297 * c = KMMFBalanceMaxRight |
|
1298 * when aLeft = 100 |
|
1299 * KMMFBalanceMaxLeft = m * 100 + KMMFBalanceMaxRight |
|
1300 * m = ( KMMFBalanceMaxLeft - KMMFBalanceMaxRight ) /100 |
|
1301 */ |
|
1302 void CMMFTestUseOldCodecAudioController::CalculateBalance( TInt& aBalance, TInt aLeft, TInt aRight ) const |
|
1303 { |
|
1304 //[ assert pre conditions ] |
|
1305 __ASSERT_ALWAYS( (( 0 <= aLeft) && ( 100 >= aLeft)), Panic( EBadArgument) ); |
|
1306 __ASSERT_ALWAYS( (( 0 <= aRight) && ( 100 >= aRight)), Panic( EBadArgument) ); |
|
1307 |
|
1308 if ((aLeft > 0) && (aRight > 0)) |
|
1309 { |
|
1310 __ASSERT_ALWAYS( (( aLeft + aRight ) == 100 ), Panic( EBadArgument )); |
|
1311 aBalance = (aLeft * (KMMFBalanceMaxLeft-KMMFBalanceMaxRight))/100 + KMMFBalanceMaxRight; |
|
1312 } |
|
1313 else if ((aLeft == 0) && (aRight == 0)) |
|
1314 { |
|
1315 aBalance = 0; |
|
1316 } |
|
1317 else if ((aLeft == 0) && (aRight > 0)) |
|
1318 { |
|
1319 aBalance = 100; |
|
1320 } |
|
1321 else if ((aLeft > 0) && (aRight == 0)) |
|
1322 { |
|
1323 aBalance = -100; |
|
1324 } |
|
1325 |
|
1326 //[ assert post condition that aBalance is within limits ] |
|
1327 __ASSERT_ALWAYS( !(aBalance < KMMFBalanceMaxLeft || aBalance > KMMFBalanceMaxRight), Panic(EBadArgument)); |
|
1328 |
|
1329 } |
|
1330 |
|
1331 /** |
|
1332 * MardSetGainL |
|
1333 * @param aGain |
|
1334 * |
|
1335 */ |
|
1336 void CMMFTestUseOldCodecAudioController::MardSetGainL(TInt aGain) |
|
1337 { |
|
1338 // [ assert the invariant ] |
|
1339 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1340 |
|
1341 //[ precondition we are in the state stopped ] |
|
1342 if(State() != EStopped) |
|
1343 User::Leave(KErrNotReady); |
|
1344 |
|
1345 // [ assert the precondition that we have a data sink ] |
|
1346 if (!iDataSource) |
|
1347 User::Leave(KErrNotSupported); |
|
1348 |
|
1349 //[ assert the precondition that the data sink is an audio input ] |
|
1350 if (iDataSource->DataSourceType() != KUidMmfAudioInput) |
|
1351 User::Leave(KErrNotReady); |
|
1352 |
|
1353 // Set gain of sound device |
|
1354 MMMFAudioInput* audioInput = STATIC_CAST(MMMFAudioInput*, iDataSource); |
|
1355 audioInput->SoundDevice().SetGain(aGain); |
|
1356 |
|
1357 //[ assert the invariant ] |
|
1358 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1359 |
|
1360 } |
|
1361 |
|
1362 /** |
|
1363 * MardGetMaxGainL |
|
1364 * @param aMaxGain |
|
1365 * |
|
1366 */ |
|
1367 void CMMFTestUseOldCodecAudioController::MardGetMaxGainL(TInt& aMaxGain) |
|
1368 { |
|
1369 // [ assert the invariant ] |
|
1370 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1371 |
|
1372 // [ assert the precondition that we have a source ] |
|
1373 if (!iDataSource) |
|
1374 User::Leave(KErrNotReady); |
|
1375 |
|
1376 //[ assert the precondition that iDataSink is an Audio Input] |
|
1377 if (iDataSource->DataSourceType() != KUidMmfAudioInput) |
|
1378 User::Leave(KErrNotSupported); |
|
1379 |
|
1380 MMMFAudioInput* audioInput = STATIC_CAST(MMMFAudioInput*, iDataSource); |
|
1381 aMaxGain = audioInput->SoundDevice().MaxGain(); |
|
1382 |
|
1383 //[ assert the invariant ] |
|
1384 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1385 |
|
1386 } |
|
1387 |
|
1388 /** |
|
1389 * MardGetGainL |
|
1390 * @param aGain |
|
1391 * |
|
1392 */ |
|
1393 void CMMFTestUseOldCodecAudioController::MardGetGainL(TInt& aGain) |
|
1394 { |
|
1395 //[ assert the invariant ] |
|
1396 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1397 |
|
1398 // [ assert the precondition that we have a sink ] |
|
1399 if (!iDataSource) |
|
1400 User::Leave(KErrNotReady); |
|
1401 |
|
1402 // [ assert the precondition that we have an audio input sink] |
|
1403 if (iDataSource->DataSourceType() != KUidMmfAudioInput) |
|
1404 User::Leave(KErrNotSupported); |
|
1405 |
|
1406 MMMFAudioInput* audioInput = STATIC_CAST(MMMFAudioInput*, iDataSource); |
|
1407 aGain = audioInput->SoundDevice().Gain(); |
|
1408 |
|
1409 //[ assert the invariant ] |
|
1410 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1411 } |
|
1412 |
|
1413 |
|
1414 /** |
|
1415 * |
|
1416 * MardSetBalanceL |
|
1417 * @param aBalance |
|
1418 */ |
|
1419 void CMMFTestUseOldCodecAudioController::MardSetBalanceL(TInt aBalance) |
|
1420 { |
|
1421 // [ assert the invaraiant ] |
|
1422 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1423 |
|
1424 // [ precondition is that we have a data sink ] |
|
1425 if (!iDataSink) |
|
1426 User::Leave(KErrNotReady); |
|
1427 |
|
1428 // [ precondition is that the balance is in range ] |
|
1429 // Make sure aBalance is in the range -100 <-> 100 |
|
1430 if (aBalance < KMMFBalanceMaxLeft || aBalance > KMMFBalanceMaxRight) |
|
1431 User::Leave(KErrArgument); |
|
1432 |
|
1433 // [ precondition is that the data sink is an audio output] |
|
1434 if (iDataSource->DataSourceType() != KUidMmfAudioInput) |
|
1435 User::Leave(KErrNotSupported); |
|
1436 |
|
1437 |
|
1438 //[ get the audio output ] |
|
1439 MMMFAudioInput* audioInput = STATIC_CAST(MMMFAudioInput*, iDataSource); |
|
1440 |
|
1441 // [ separate out left and right balance ] |
|
1442 TInt left = 0; |
|
1443 TInt right = 0; |
|
1444 CalculateLeftRightBalance( left, right, aBalance ); |
|
1445 |
|
1446 //[ set the balance ] |
|
1447 audioInput->SoundDevice().SetRecordBalanceL(left, right); |
|
1448 |
|
1449 // [assert the post condition that the balance is set correctly] |
|
1450 TInt rightBalance = 0; |
|
1451 TInt leftBalance = 0; |
|
1452 audioInput->SoundDevice().GetRecordBalanceL(leftBalance, rightBalance); |
|
1453 |
|
1454 //[ assert post condition holds] |
|
1455 TBool postCondition = (( rightBalance == right) && ( leftBalance == left)); |
|
1456 __ASSERT_ALWAYS( postCondition, Panic( EPostConditionViolation ) ); |
|
1457 |
|
1458 //[ assert the invariant ] |
|
1459 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
1460 |
|
1461 } |
|
1462 |
|
1463 /** |
|
1464 * |
|
1465 * MardGetBalanceL |
|
1466 * @param aBalance |
|
1467 * |
|
1468 */ |
|
1469 void CMMFTestUseOldCodecAudioController::MardGetBalanceL(TInt& aBalance) |
|
1470 { |
|
1471 //[ assert the invariant ] |
|
1472 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1473 |
|
1474 //[ precondition that we have a sink] |
|
1475 if (!iDataSink) |
|
1476 User::Leave(KErrNotReady); |
|
1477 |
|
1478 // [ iDataSink is an Audio Output ] |
|
1479 if (iDataSource->DataSourceType() != KUidMmfAudioInput) |
|
1480 User::Leave(KErrNotSupported); |
|
1481 |
|
1482 // [ get the play balance ] |
|
1483 MMMFAudioInput* audioInput = STATIC_CAST(MMMFAudioInput*, iDataSource); |
|
1484 TInt left = 50; // arbitrary values |
|
1485 TInt right = 50; |
|
1486 audioInput->SoundDevice().GetRecordBalanceL(left, right); |
|
1487 CalculateBalance( aBalance, left, right ); |
|
1488 |
|
1489 //[ assert the invariant ] |
|
1490 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1491 |
|
1492 } |
|
1493 |
|
1494 /** |
|
1495 * MapcSetPlaybackWindowL |
|
1496 * @param aStart |
|
1497 * @param aEnd |
|
1498 * |
|
1499 */ |
|
1500 void CMMFTestUseOldCodecAudioController::MapcSetPlaybackWindowL(const TTimeIntervalMicroSeconds& aStart, const TTimeIntervalMicroSeconds& aEnd) |
|
1501 { |
|
1502 iDataPath->SetPlayWindowL(aStart, aEnd); |
|
1503 } |
|
1504 |
|
1505 /** |
|
1506 * MapcDeletePlaybackWindowL |
|
1507 */ |
|
1508 void CMMFTestUseOldCodecAudioController::MapcDeletePlaybackWindowL() |
|
1509 { |
|
1510 iDataPath->ClearPlayWindowL(); |
|
1511 } |
|
1512 |
|
1513 /** |
|
1514 * MapcGetLoadingProgressL |
|
1515 */ |
|
1516 void CMMFTestUseOldCodecAudioController::MapcGetLoadingProgressL(TInt& /*aPercentageComplete*/) |
|
1517 { |
|
1518 User::Leave(KErrNotSupported); |
|
1519 } |
|
1520 |
|
1521 |
|
1522 /** |
|
1523 * MarcGetRecordTimeAvailableL |
|
1524 * @param aTime |
|
1525 * |
|
1526 */ |
|
1527 void CMMFTestUseOldCodecAudioController::MarcGetRecordTimeAvailableL(TTimeIntervalMicroSeconds& aTime) |
|
1528 { |
|
1529 //[ assert the invariant ] |
|
1530 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1531 |
|
1532 //[ assert the precondition ( in a friendly way for this api |
|
1533 // that we minimally have a data sink ] |
|
1534 if( !iDataSink ) |
|
1535 User::Leave( KErrNotReady ); |
|
1536 |
|
1537 // Use the FormatEncode to get the bytes per second and the sink (clip) to get the bytes available |
|
1538 // return the calculated value. |
|
1539 if ((iDataSink->DataSinkType() != KUidMmfFileSink) && (iDataSink->DataSinkType() != KUidMmfDescriptorSink)) |
|
1540 User::Leave(KErrNotSupported) ; |
|
1541 |
|
1542 // [ max file size ] |
|
1543 //[ pre condition is that we have a sink ] |
|
1544 |
|
1545 // In order to get the record time available we need to take into consideration |
|
1546 // that there may be a max file size ] |
|
1547 TInt64 bytesFree = STATIC_CAST(CMMFClip*, iDataSink)->BytesFree() ; |
|
1548 TInt64 bytesPerSecond = TInt64(0); |
|
1549 //[ set default time available ] |
|
1550 aTime = TTimeIntervalMicroSeconds( 0 ) ; // just return zero |
|
1551 |
|
1552 if( iSinkFormat ) |
|
1553 { |
|
1554 TInt maxFileSize = STATIC_CAST(CMMFFormatEncode*, iSinkFormat)->MaximumClipSize(); |
|
1555 //[ if maxFileSize > 0 we need to limit the bytes free to this value - size ] |
|
1556 if( maxFileSize > 0 ) |
|
1557 { |
|
1558 // [ strangely the size of data written is a TInt ] |
|
1559 TInt fileSize = STATIC_CAST(CMMFClip*, iDataSink)->Size(); |
|
1560 bytesFree = maxFileSize - fileSize; |
|
1561 // [ note it can occur that the fileSize id greater than the MaxFileSize |
|
1562 // due to someone setting the max file size on an existing file ] |
|
1563 if( bytesFree < 0 ) bytesFree = 0; |
|
1564 __ASSERT_DEBUG( ( bytesFree <= maxFileSize), Panic( EBadInvariant) ); |
|
1565 } |
|
1566 bytesPerSecond = STATIC_CAST(CMMFFormatEncode*, iSinkFormat)->BytesPerSecond() ; |
|
1567 } |
|
1568 |
|
1569 //[ now lets perform the calculation of time available ] |
|
1570 if ( bytesPerSecond != TInt64(0) ) |
|
1571 { |
|
1572 aTime = TTimeIntervalMicroSeconds( bytesFree * KOneSecondInMicroSeconds / bytesPerSecond ) ; |
|
1573 } |
|
1574 |
|
1575 //[ assert the invariant ] |
|
1576 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1577 } |
|
1578 |
|
1579 /** |
|
1580 * MarcSetMaxDurationL |
|
1581 * @param aMaxDuration |
|
1582 */ |
|
1583 void CMMFTestUseOldCodecAudioController::MarcSetMaxDurationL(const TTimeIntervalMicroSeconds& ) |
|
1584 { |
|
1585 //[ this method is deprecated and no longer supported ] |
|
1586 User::Leave(KErrNotSupported); |
|
1587 } |
|
1588 |
|
1589 /** |
|
1590 * MarcSetMaxFileSizeL |
|
1591 * @param aFileSize |
|
1592 * @precondition |
|
1593 * The argument aFileSize must be greater than -1 |
|
1594 * zero is used as a sentinel value which means that the file |
|
1595 * can grow without limit |
|
1596 */ |
|
1597 void CMMFTestUseOldCodecAudioController::MarcSetMaxFileSizeL(TInt aFileSize ) |
|
1598 { |
|
1599 //[ assert the invariant ] |
|
1600 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1601 |
|
1602 //[ assert the state is not playing since this opens open |
|
1603 // nefarious posibilities |
|
1604 if(State() == EPlaying ) |
|
1605 User::Leave( KErrNotReady ); |
|
1606 |
|
1607 //[ assert we have a sink format ] |
|
1608 if( !iSinkFormat ) |
|
1609 User::Leave( KErrNotReady ); |
|
1610 |
|
1611 //[ assert file size > -1, as a basic sanity filter |
|
1612 // 0 is the sentinel value which allows a file to grow |
|
1613 // as needed ] |
|
1614 if( aFileSize < 0 ) |
|
1615 User::Leave( KErrArgument ); |
|
1616 |
|
1617 //[ pre condition is that we have a sink ] |
|
1618 STATIC_CAST(CMMFFormatEncode*, iSinkFormat)->SetMaximumClipSizeL( aFileSize ); |
|
1619 |
|
1620 // [ assert the post condition ] |
|
1621 // [since we have no means of querying the value |
|
1622 // we have to assume all went well for now or we left] |
|
1623 |
|
1624 //[ assert the invariant ] |
|
1625 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1626 } |
|
1627 |
|
1628 /** |
|
1629 * MarcCropL |
|
1630 * @param aToEnd |
|
1631 */ |
|
1632 void CMMFTestUseOldCodecAudioController::MarcCropL(TBool aToEnd) |
|
1633 { |
|
1634 //[ assert the invariant ] |
|
1635 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1636 |
|
1637 //[ precondition there is a sink format] |
|
1638 if (!iSinkFormat) |
|
1639 User::Leave(KErrNotSupported); |
|
1640 |
|
1641 iSinkFormat->CropL( PositionL(), aToEnd ); |
|
1642 |
|
1643 //[ assert the invariant ] |
|
1644 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1645 } |
|
1646 |
|
1647 /** |
|
1648 * MarcAddMetaDataEntryL |
|
1649 * @param aNewEntry |
|
1650 */ |
|
1651 void CMMFTestUseOldCodecAudioController::MarcAddMetaDataEntryL(const CMMFMetaDataEntry& aNewEntry ) |
|
1652 { |
|
1653 //[ assert the invariant ] |
|
1654 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1655 |
|
1656 //[ precondition the format exists ] |
|
1657 if( !iSinkFormat ) |
|
1658 User::Leave(KErrNotSupported); |
|
1659 |
|
1660 //[ Add the meta data entry ] |
|
1661 iSinkFormat->AddMetaDataEntryL( aNewEntry ); |
|
1662 |
|
1663 //[ assert the invariant ] |
|
1664 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1665 |
|
1666 } |
|
1667 |
|
1668 /** |
|
1669 * MarcRemoveMetaDataEntryL |
|
1670 * @param aIndex |
|
1671 */ |
|
1672 void CMMFTestUseOldCodecAudioController::MarcRemoveMetaDataEntryL(TInt aIndex) |
|
1673 { |
|
1674 //[ assert the invariant ] |
|
1675 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1676 |
|
1677 //[ precondition that we are in the primed state ] |
|
1678 if( State() != EPrimed) |
|
1679 User::Leave(KErrNotReady); |
|
1680 |
|
1681 //[ precondition the format exists ] |
|
1682 if( !iSinkFormat ) |
|
1683 User::Leave(KErrNotSupported); |
|
1684 |
|
1685 //[ remove the meta data entry ] |
|
1686 iSinkFormat->RemoveMetaDataEntry( aIndex ); |
|
1687 |
|
1688 //[ assert the invariant ] |
|
1689 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1690 |
|
1691 } |
|
1692 |
|
1693 /** |
|
1694 * MarcReplaceMetaDataEntryL |
|
1695 * @param aIndex |
|
1696 * @param aNewEntry |
|
1697 */ |
|
1698 void CMMFTestUseOldCodecAudioController::MarcReplaceMetaDataEntryL(TInt aIndex, const CMMFMetaDataEntry& aNewEntry) |
|
1699 { |
|
1700 //[ assert the invariant ] |
|
1701 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1702 |
|
1703 //[ precondition that we are in the primed state ] |
|
1704 if( State() != EPrimed) |
|
1705 User::Leave(KErrNotReady); |
|
1706 |
|
1707 //[ precondition the format exists ] |
|
1708 if( !iSinkFormat ) |
|
1709 User::Leave(KErrNotSupported); |
|
1710 |
|
1711 //[ replace meta data entry ] |
|
1712 iSinkFormat->ReplaceMetaDataEntryL( aIndex, aNewEntry ); |
|
1713 |
|
1714 //[ assert the invariant ] |
|
1715 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1716 |
|
1717 } |
|
1718 |
|
1719 /** |
|
1720 * MacSetSourceSampleRateL |
|
1721 * @param aSampleRate |
|
1722 */ |
|
1723 void CMMFTestUseOldCodecAudioController::MacSetSourceSampleRateL(TUint aSampleRate) |
|
1724 { |
|
1725 // [ assert the invariant ] |
|
1726 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
1727 |
|
1728 // [ assert the precondition we are stopped ] |
|
1729 if( State() != EStopped ) |
|
1730 User::Leave(KErrNotReady); |
|
1731 |
|
1732 |
|
1733 if (iSourceFormat) |
|
1734 {//only applicable to formats |
|
1735 // don't throw an error if the clip already exists with a different sample rate |
|
1736 TInt error = iSourceFormat->SetSampleRate(aSampleRate); |
|
1737 if (error != KErrNone && error != KErrAlreadyExists) |
|
1738 User::Leave(error); |
|
1739 } |
|
1740 else if (iDataSource && (iDataSource->DataSourceType()==KUidMmfAudioInput)) |
|
1741 { |
|
1742 // cast iDataSource to audio input and set sample rate |
|
1743 MMMFAudioInput* ai = STATIC_CAST(MMMFAudioInput*, iDataSource); |
|
1744 |
|
1745 //note that it is safe to call SoundDevice() |
|
1746 //as the controller logs onto the iDataSource when it is added |
|
1747 TMMFCapabilities devSoundConfig = ai->SoundDevice().Config(); |
|
1748 |
|
1749 ConvertFromSampleRateToDevSoundCapsL(aSampleRate, devSoundConfig); |
|
1750 ai->SoundDevice().SetConfigL(devSoundConfig); |
|
1751 //ReNegotiateL(); |
|
1752 } |
|
1753 else |
|
1754 User::Leave(KErrNotSupported); |
|
1755 |
|
1756 // [assert the post condition ] |
|
1757 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
1758 |
|
1759 } |
|
1760 |
|
1761 /** |
|
1762 * MacSetSourceNumChannelsL |
|
1763 * @param aNumChannels |
|
1764 */ |
|
1765 void CMMFTestUseOldCodecAudioController::MacSetSourceNumChannelsL(TUint aNumChannels) |
|
1766 { |
|
1767 // [ assert the invariant ] |
|
1768 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
1769 |
|
1770 // [assert the precondition that we are stopped ] |
|
1771 if( State() != EStopped ) |
|
1772 User::Leave(KErrNotReady); |
|
1773 |
|
1774 if (iSourceFormat) |
|
1775 {//only applicable to formats |
|
1776 // don't throw an error if the clip already exists with a different number of channels |
|
1777 TInt error = iSourceFormat->SetNumChannels(aNumChannels); |
|
1778 if (error != KErrNone && error != KErrAlreadyExists) |
|
1779 User::Leave(error); |
|
1780 } |
|
1781 else if (iDataSource && (iDataSource->DataSourceType()==KUidMmfAudioInput)) |
|
1782 { |
|
1783 // cast iDataSource to audio input and set num channels |
|
1784 MMMFAudioInput* ai = STATIC_CAST(MMMFAudioInput*, iDataSource); |
|
1785 |
|
1786 //note that it is safe to call SoundDevice() |
|
1787 //as the controller logs onto the iDataSource when it is added |
|
1788 TMMFCapabilities devSoundConfig = ai->SoundDevice().Config(); |
|
1789 |
|
1790 ConvertFromNumChannelsToDevSoundCapsL(aNumChannels, devSoundConfig); |
|
1791 ai->SoundDevice().SetConfigL(devSoundConfig); |
|
1792 //ReNegotiateL(); |
|
1793 } |
|
1794 else |
|
1795 User::Leave(KErrNotSupported); |
|
1796 |
|
1797 // [ assert the invariant ] |
|
1798 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
1799 |
|
1800 } |
|
1801 |
|
1802 /** |
|
1803 * MacSetSourceFormatL |
|
1804 * @param aFormatUid |
|
1805 * |
|
1806 */ |
|
1807 void CMMFTestUseOldCodecAudioController::MacSetSourceFormatL(TUid aFormatUid) |
|
1808 { |
|
1809 //[ assert the invaraint ] |
|
1810 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
1811 |
|
1812 // [ precondition that the controller is stopped ] |
|
1813 if( State() != EStopped ) |
|
1814 User::Leave( KErrNotReady ); |
|
1815 |
|
1816 //[ precondition that the data source exists] |
|
1817 if (!iDataSource) |
|
1818 User::Leave(KErrNotReady); |
|
1819 |
|
1820 //[ precondition that we need a format ] |
|
1821 if( !SourceFormatRequired( *iDataSource ) ) |
|
1822 User::Leave(KErrNotSupported); //cant set source format if source isn't a clip |
|
1823 |
|
1824 //[ if the format exists and the uid of the requested |
|
1825 // format is the same as the existing format then simply |
|
1826 // return otherwise create a new format ] |
|
1827 if( !((iSourceFormat) && ( iSourceFormat->ImplementationUid() == aFormatUid))) |
|
1828 { |
|
1829 // [ delete the old format regardless ] |
|
1830 delete iSourceFormat; |
|
1831 iSourceFormat = NULL; |
|
1832 iSourceFormat = CMMFFormatDecode::NewL(aFormatUid, iDataSource); |
|
1833 } |
|
1834 |
|
1835 //[ assert the invariant ] |
|
1836 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
1837 |
|
1838 //[ assert the post condition that a source format has been constructed ] |
|
1839 __ASSERT_ALWAYS( (iSourceFormat != NULL), Panic( EPostConditionViolation )); |
|
1840 } |
|
1841 |
|
1842 /** |
|
1843 * MacSetSinkSampleRateL |
|
1844 * @param aSampleRate |
|
1845 */ |
|
1846 void CMMFTestUseOldCodecAudioController::MacSetSinkSampleRateL(TUint aSampleRate) |
|
1847 { |
|
1848 //[ assert the invariant ] |
|
1849 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
1850 |
|
1851 // [ assert the precondition that we are stopped ] |
|
1852 if (State() != EStopped ) |
|
1853 User::Leave(KErrNotReady); |
|
1854 |
|
1855 if (iSinkFormat) |
|
1856 {//only applicable to formats |
|
1857 // don't throw an error if the clip already exists with a different sample rate |
|
1858 TInt error = iSinkFormat->SetSampleRate(aSampleRate); |
|
1859 if (error != KErrNone && error != KErrAlreadyExists) |
|
1860 User::Leave(error); |
|
1861 } |
|
1862 else if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput)) |
|
1863 { |
|
1864 // cast iDataSink to audio output and set sample rate |
|
1865 MMMFAudioOutput* ao = STATIC_CAST(MMMFAudioOutput*, iDataSink); |
|
1866 |
|
1867 |
|
1868 |
|
1869 TMMFCapabilities devSoundConfig = ao->SoundDevice().Config(); |
|
1870 ConvertFromSampleRateToDevSoundCapsL(aSampleRate, devSoundConfig); |
|
1871 ao->SoundDevice().SetConfigL(devSoundConfig); |
|
1872 } |
|
1873 else |
|
1874 User::Leave(KErrNotSupported); |
|
1875 |
|
1876 //[ assert the invariant ] |
|
1877 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
1878 } |
|
1879 |
|
1880 /** |
|
1881 * MacSetSinkNumChannelsL |
|
1882 * @param aNumChannels |
|
1883 * |
|
1884 */ |
|
1885 void CMMFTestUseOldCodecAudioController::MacSetSinkNumChannelsL(TUint aNumChannels) |
|
1886 { |
|
1887 //[ assert the invariant ] |
|
1888 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
1889 |
|
1890 // [ assert the precondition that we are stopped ] |
|
1891 if (State() != EStopped ) |
|
1892 User::Leave(KErrNotReady); |
|
1893 |
|
1894 if (iSinkFormat) |
|
1895 {//only applicable to formats |
|
1896 // don't throw an error if the clip already exists with a different number of channels |
|
1897 TInt error = iSinkFormat->SetNumChannels(aNumChannels); |
|
1898 if (error != KErrNone && error != KErrAlreadyExists) |
|
1899 User::Leave(error); |
|
1900 } |
|
1901 else if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput)) |
|
1902 { |
|
1903 // cast iDataSink to audio output and set num channels |
|
1904 MMMFAudioOutput* ao = STATIC_CAST(MMMFAudioOutput*, iDataSink); |
|
1905 |
|
1906 //note that it is safe to call SoundDevice() |
|
1907 //as the controller logs onto the iDataSource when it is added |
|
1908 TMMFCapabilities devSoundConfig = ao->SoundDevice().Config(); |
|
1909 ConvertFromNumChannelsToDevSoundCapsL(aNumChannels, devSoundConfig); |
|
1910 ao->SoundDevice().SetConfigL(devSoundConfig); |
|
1911 } |
|
1912 else |
|
1913 User::Leave(KErrNotSupported); |
|
1914 |
|
1915 // [assert the invariant ] |
|
1916 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
1917 |
|
1918 } |
|
1919 |
|
1920 /** |
|
1921 * MacSetSinkFormatL |
|
1922 * @param aFormatUid |
|
1923 * |
|
1924 */ |
|
1925 void CMMFTestUseOldCodecAudioController::MacSetSinkFormatL(TUid aFormatUid) |
|
1926 { |
|
1927 //[ assert the invariant ] |
|
1928 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
1929 |
|
1930 // [ precondition that the controller is stopped ] |
|
1931 if( State() != EStopped ) |
|
1932 User::Leave( KErrNotReady ); |
|
1933 |
|
1934 //[ precondition that the data sink exists] |
|
1935 if (!iDataSink) |
|
1936 User::Leave(KErrNotReady); |
|
1937 |
|
1938 //[ precondition that we need a format ] |
|
1939 if (!SinkFormatRequired( *iDataSink)) |
|
1940 User::Leave(KErrNotSupported); |
|
1941 |
|
1942 //[ if the format exists and the uid of the requested |
|
1943 // format is the same as the existing format then simply |
|
1944 // return ] |
|
1945 if( !((iSinkFormat) && ( iSinkFormat->ImplementationUid() == aFormatUid))) |
|
1946 { |
|
1947 // [ delete the old format regardless ] |
|
1948 delete iSinkFormat; |
|
1949 iSinkFormat = NULL; |
|
1950 iSinkFormat = CMMFFormatEncode::NewL(aFormatUid, iDataSink); |
|
1951 } |
|
1952 |
|
1953 //[ assert the invariant ] |
|
1954 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
1955 |
|
1956 //[ assert the post condition that a sink format has been constructed ] |
|
1957 __ASSERT_ALWAYS( (iSinkFormat != NULL), Panic( EPostConditionViolation )); |
|
1958 } |
|
1959 |
|
1960 |
|
1961 /** |
|
1962 * MacSetCodecL |
|
1963 * @param aSourceDataType |
|
1964 * @param aSinkDataType |
|
1965 * |
|
1966 */ |
|
1967 void CMMFTestUseOldCodecAudioController::MacSetCodecL(TFourCC aSourceDataType, TFourCC aSinkDataType) |
|
1968 { |
|
1969 //[ assert the invariant ] |
|
1970 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
1971 |
|
1972 //[ assert the precondition ] |
|
1973 if(State() != EStopped) |
|
1974 User::Leave(KErrNotReady); |
|
1975 |
|
1976 //don't set codec directly -just set source & sink fourCC codes |
|
1977 //[ ] |
|
1978 TInt error(KErrNone); |
|
1979 if ((iSinkFormat)&&(aSinkDataType != KMMFFourCCCodeNULL)) |
|
1980 { |
|
1981 error = iSinkFormat->SetSinkDataTypeCode(aSinkDataType,iMediaId); |
|
1982 } |
|
1983 else if((iDataSink) && (aSinkDataType != KMMFFourCCCodeNULL)) |
|
1984 { |
|
1985 error = iDataSink->SetSinkDataTypeCode(aSinkDataType,iMediaId); |
|
1986 } |
|
1987 if ((iSourceFormat)&&(!error)&&(aSourceDataType != KMMFFourCCCodeNULL)) |
|
1988 { |
|
1989 error = iSourceFormat->SetSourceDataTypeCode(aSourceDataType,iMediaId); |
|
1990 } |
|
1991 else if ((iDataSource) && (aSourceDataType != KMMFFourCCCodeNULL)) |
|
1992 { |
|
1993 error = iDataSource->SetSourceDataTypeCode(aSourceDataType,iMediaId); |
|
1994 } |
|
1995 |
|
1996 //[ leave if we are not ready or there was an error ] |
|
1997 User::LeaveIfError(error); |
|
1998 |
|
1999 //[ assert the invariant ] |
|
2000 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
2001 } |
|
2002 |
|
2003 /** |
|
2004 * MacSetSourceBitRateL |
|
2005 * @param "TUint" |
|
2006 * Sets the source bit rate |
|
2007 * |
|
2008 */ |
|
2009 void CMMFTestUseOldCodecAudioController::MacSetSourceBitRateL(TUint aBitRate) |
|
2010 { |
|
2011 //[ assert the invariant ] |
|
2012 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant)); |
|
2013 |
|
2014 //[ assert the precondition ] |
|
2015 if(State() != EStopped) |
|
2016 User::Leave(KErrNotReady); |
|
2017 |
|
2018 //[ pre condition that we have a source format] |
|
2019 if (!iSourceFormat) |
|
2020 User::Leave(KErrNotSupported); |
|
2021 |
|
2022 //only applicable to formats |
|
2023 User::LeaveIfError(iSourceFormat->SetBitRate(aBitRate)); |
|
2024 |
|
2025 //[ assert the set bit rate is the bit rate ] |
|
2026 __ASSERT_ALWAYS( (aBitRate == iSourceFormat->BitRate()), Panic( EPostConditionViolation )); |
|
2027 |
|
2028 //[ assert the invariant ] |
|
2029 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
2030 } |
|
2031 |
|
2032 |
|
2033 /** |
|
2034 * |
|
2035 * MacSetSourceDataTypeL |
|
2036 * @param "TFourCC" |
|
2037 * |
|
2038 */ |
|
2039 void CMMFTestUseOldCodecAudioController::MacSetSourceDataTypeL(TFourCC aDataType) |
|
2040 { |
|
2041 MacSetCodecL(aDataType, KMMFFourCCCodeNULL); |
|
2042 } |
|
2043 |
|
2044 /** |
|
2045 * |
|
2046 * MacSetSinkBitRateL |
|
2047 * @param "TUint" |
|
2048 * |
|
2049 */ |
|
2050 void CMMFTestUseOldCodecAudioController::MacSetSinkBitRateL(TUint aRate) |
|
2051 { |
|
2052 //[ assert the invariant ] |
|
2053 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
2054 |
|
2055 // [ assert we are stopped ] |
|
2056 if( State() != EStopped) |
|
2057 User::Leave( KErrNotReady ); |
|
2058 |
|
2059 //[ pre condition we have a sink format ] |
|
2060 if (!iSinkFormat) |
|
2061 User::Leave(KErrNotSupported); |
|
2062 |
|
2063 //only applicable to formats |
|
2064 User::LeaveIfError(iSinkFormat->SetBitRate(aRate)); |
|
2065 |
|
2066 //[ assert the set bit rate is the bit rate ] |
|
2067 __ASSERT_ALWAYS( (aRate == iSinkFormat->BitRate()), Panic( EBadInvariant)); |
|
2068 |
|
2069 //[ assert the invariant ] |
|
2070 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
2071 } |
|
2072 |
|
2073 /** |
|
2074 * |
|
2075 * MacSetSinkDataTypeL |
|
2076 * @param "TFourCC" |
|
2077 * |
|
2078 */ |
|
2079 void CMMFTestUseOldCodecAudioController::MacSetSinkDataTypeL(TFourCC aDataType) |
|
2080 { |
|
2081 MacSetCodecL(KMMFFourCCCodeNULL, aDataType); |
|
2082 |
|
2083 if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput)) |
|
2084 { |
|
2085 MMMFAudioOutput* ao = STATIC_CAST(MMMFAudioOutput*, iDataSink); |
|
2086 TMMFCapabilities devSoundConfig = ao->SoundDevice().Config(); |
|
2087 RArray<TFourCC> dataTypes; |
|
2088 CleanupClosePushL(dataTypes); |
|
2089 |
|
2090 //[ set dev sound data type here ] |
|
2091 ConvertFromDataTypeToDevSoundCapsL(aDataType, devSoundConfig); |
|
2092 ao->SoundDevice().SetConfigL(devSoundConfig); |
|
2093 CleanupStack::PopAndDestroy();//dataTypes |
|
2094 } |
|
2095 } |
|
2096 |
|
2097 /** |
|
2098 * |
|
2099 * MacGetSourceSampleRateL |
|
2100 * @param "TUint" |
|
2101 * |
|
2102 */ |
|
2103 void CMMFTestUseOldCodecAudioController::MacGetSourceSampleRateL(TUint& aRate) |
|
2104 { |
|
2105 //[ assert the invariant ] |
|
2106 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
2107 |
|
2108 //[ precondition is that we have a source format || |
|
2109 // we have a data source and its an audio input ] |
|
2110 if( !((iDataSource && (iDataSource->DataSourceType()==KUidMmfAudioInput)) || |
|
2111 ( iSourceFormat ))) |
|
2112 User::Leave(KErrNotSupported); |
|
2113 |
|
2114 if (iSourceFormat) |
|
2115 { |
|
2116 aRate = iSourceFormat->SampleRate(); |
|
2117 } |
|
2118 else |
|
2119 { |
|
2120 // cast iDataSource to audio input and query sample rate |
|
2121 MMMFAudioInput* ai = STATIC_CAST(MMMFAudioInput*, iDataSource); |
|
2122 TMMFCapabilities devSoundConfig = ai->SoundDevice().Config(); |
|
2123 RArray<TUint> rates; |
|
2124 CleanupClosePushL(rates); |
|
2125 ConvertFromDevSoundCapsToSampleRatesL(devSoundConfig, rates); |
|
2126 ASSERT(rates.Count()==1);//make sure we've been given the correct config by devsound |
|
2127 aRate = rates[0]; |
|
2128 CleanupStack::PopAndDestroy();//rates |
|
2129 } |
|
2130 |
|
2131 //[ assert the invariant ] |
|
2132 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
2133 } |
|
2134 |
|
2135 /** |
|
2136 * |
|
2137 * MacGetSourceBitRateL |
|
2138 * @param "TUint" |
|
2139 * |
|
2140 */ |
|
2141 void CMMFTestUseOldCodecAudioController::MacGetSourceBitRateL(TUint& aRate) |
|
2142 { |
|
2143 //[ assert the invariant ] |
|
2144 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
2145 |
|
2146 // Can only query formats for bit rate - devsound doesn't do bit rates. |
|
2147 if (!iSourceFormat) |
|
2148 User::Leave(KErrNotSupported); |
|
2149 |
|
2150 aRate = iSourceFormat->BitRate(); |
|
2151 |
|
2152 //[ assert the invariant ] |
|
2153 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
2154 |
|
2155 } |
|
2156 |
|
2157 /** |
|
2158 * |
|
2159 * MacGetSourceNumChannelsL |
|
2160 * @param "TUint&" |
|
2161 * |
|
2162 */ |
|
2163 void CMMFTestUseOldCodecAudioController::MacGetSourceNumChannelsL(TUint& aNumChannels) |
|
2164 { |
|
2165 //[ assert the invariant ] |
|
2166 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
2167 |
|
2168 //[ assert the precondition ] |
|
2169 if( !((iSourceFormat) || |
|
2170 (iDataSource && (iDataSource->DataSourceType()==KUidMmfAudioInput)))) |
|
2171 User::Leave(KErrNotSupported); |
|
2172 |
|
2173 if (iSourceFormat) |
|
2174 { |
|
2175 aNumChannels = iSourceFormat->NumChannels(); |
|
2176 } |
|
2177 else |
|
2178 { |
|
2179 // cast iDataSource to audio input and query num channels |
|
2180 MMMFAudioInput* ai = STATIC_CAST(MMMFAudioInput*, iDataSource); |
|
2181 TMMFCapabilities devSoundConfig = ai->SoundDevice().Config(); |
|
2182 RArray<TUint> numChannels; |
|
2183 CleanupClosePushL(numChannels); |
|
2184 ConvertFromDevSoundCapsToNumChannelsL(devSoundConfig, numChannels); |
|
2185 ASSERT(numChannels.Count()==1); |
|
2186 aNumChannels = numChannels[0]; |
|
2187 CleanupStack::PopAndDestroy();//numChannels |
|
2188 } |
|
2189 |
|
2190 //[ assert the invariant ] |
|
2191 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
2192 |
|
2193 } |
|
2194 |
|
2195 /** |
|
2196 * |
|
2197 * MacGetSourceFormatL |
|
2198 * @param "TUid" |
|
2199 */ |
|
2200 void CMMFTestUseOldCodecAudioController::MacGetSourceFormatL(TUid& aFormat) |
|
2201 { |
|
2202 //[ assert the invariant ] |
|
2203 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
2204 |
|
2205 //[ precondition we have a format ] |
|
2206 if (!iSourceFormat) |
|
2207 User::Leave(KErrNotSupported); |
|
2208 |
|
2209 // [ get the source format uid ] |
|
2210 aFormat = iSourceFormat->ImplementationUid(); |
|
2211 |
|
2212 //[ assert the invariant ] |
|
2213 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); |
|
2214 |
|
2215 } |
|
2216 |
|
2217 /** |
|
2218 * |
|
2219 * MacGetSourceDataTypeL |
|
2220 * @param "TFourCC&" |
|
2221 * |
|
2222 */ |
|
2223 void CMMFTestUseOldCodecAudioController::MacGetSourceDataTypeL(TFourCC& aDataType) |
|
2224 { |
|
2225 if (iSourceFormat) |
|
2226 aDataType = iSourceFormat->SourceDataTypeCode(TMediaId(KUidMediaTypeAudio)); |
|
2227 else if (iDataSource && (iDataSource->DataSourceType()==KUidMmfAudioInput)) |
|
2228 { |
|
2229 // cast iDataSource to audio input and query num channels |
|
2230 MMMFAudioInput* ai = STATIC_CAST(MMMFAudioInput*, iDataSource); |
|
2231 TMMFCapabilities devSoundConfig = ai->SoundDevice().Config(); |
|
2232 RArray<TFourCC> dataTypes; |
|
2233 CleanupClosePushL(dataTypes); |
|
2234 ConvertFromDevSoundCapsToDataTypesL(devSoundConfig, dataTypes); |
|
2235 ASSERT(dataTypes.Count()==1); |
|
2236 aDataType = dataTypes[0]; |
|
2237 CleanupStack::PopAndDestroy();//dataTypes |
|
2238 } |
|
2239 else |
|
2240 User::Leave(KErrNotSupported); |
|
2241 } |
|
2242 |
|
2243 /** |
|
2244 * |
|
2245 * MacGetSinkSampleRateL |
|
2246 * @param "TUint&" |
|
2247 * |
|
2248 */ |
|
2249 |
|
2250 void CMMFTestUseOldCodecAudioController::MacGetSinkSampleRateL(TUint& aRate) |
|
2251 { |
|
2252 if (iSinkFormat) |
|
2253 aRate = iSinkFormat->SampleRate(); |
|
2254 else if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput)) |
|
2255 { |
|
2256 // cast iDataSink to audio output and query sample rate |
|
2257 MMMFAudioOutput* ao = STATIC_CAST(MMMFAudioOutput*, iDataSink); |
|
2258 TMMFCapabilities devSoundConfig = ao->SoundDevice().Config(); |
|
2259 RArray<TUint> rates; |
|
2260 CleanupClosePushL(rates); |
|
2261 ConvertFromDevSoundCapsToSampleRatesL(devSoundConfig, rates); |
|
2262 ASSERT(rates.Count()==1);//make sure we've been given the correct config by devsound |
|
2263 aRate = rates[0]; |
|
2264 CleanupStack::PopAndDestroy();//rates |
|
2265 } |
|
2266 else |
|
2267 User::Leave(KErrNotSupported); |
|
2268 } |
|
2269 |
|
2270 /** |
|
2271 * |
|
2272 * MacGetSinkBitRateL |
|
2273 * @param "TUint&" |
|
2274 * |
|
2275 */ |
|
2276 void CMMFTestUseOldCodecAudioController::MacGetSinkBitRateL(TUint& aRate) |
|
2277 { |
|
2278 if (iSinkFormat) |
|
2279 aRate = iSinkFormat->BitRate(); |
|
2280 else |
|
2281 User::Leave(KErrNotSupported); |
|
2282 } |
|
2283 |
|
2284 /** |
|
2285 * |
|
2286 * MacGetSinkNumChannelsL |
|
2287 * @param "TUint&" |
|
2288 * |
|
2289 */ |
|
2290 void CMMFTestUseOldCodecAudioController::MacGetSinkNumChannelsL(TUint& aNumChannels) |
|
2291 { |
|
2292 if (iSinkFormat) |
|
2293 aNumChannels = iSinkFormat->NumChannels(); |
|
2294 else if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput)) |
|
2295 { |
|
2296 // cast iDataSink to audio output and query num channels |
|
2297 MMMFAudioOutput* ao = STATIC_CAST(MMMFAudioOutput*, iDataSink); |
|
2298 TMMFCapabilities devSoundConfig = ao->SoundDevice().Config(); |
|
2299 RArray<TUint> numChannels; |
|
2300 CleanupClosePushL(numChannels); |
|
2301 ConvertFromDevSoundCapsToNumChannelsL(devSoundConfig, numChannels); |
|
2302 ASSERT(numChannels.Count()==1); |
|
2303 aNumChannels = numChannels[0]; |
|
2304 CleanupStack::PopAndDestroy();//numChannels |
|
2305 } |
|
2306 else |
|
2307 User::Leave(KErrNotSupported); |
|
2308 } |
|
2309 |
|
2310 /** |
|
2311 * |
|
2312 * MacGetSinkFormatL |
|
2313 * @param "TUid&" |
|
2314 * |
|
2315 */ |
|
2316 void CMMFTestUseOldCodecAudioController::MacGetSinkFormatL(TUid& aFormat) |
|
2317 { |
|
2318 if (iSinkFormat) |
|
2319 aFormat = iSinkFormat->ImplementationUid(); |
|
2320 else |
|
2321 User::Leave(KErrNotSupported); |
|
2322 } |
|
2323 |
|
2324 /** |
|
2325 * |
|
2326 * MacGetSinkDataTypeL |
|
2327 * @param "TFourCC&" |
|
2328 * |
|
2329 */ |
|
2330 void CMMFTestUseOldCodecAudioController::MacGetSinkDataTypeL(TFourCC& aDataType) |
|
2331 { |
|
2332 if (iSinkFormat) |
|
2333 aDataType = iSinkFormat->SinkDataTypeCode(TMediaId(KUidMediaTypeAudio)); |
|
2334 else if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput)) |
|
2335 { |
|
2336 // cast iDataSink to audio output and query data type |
|
2337 MMMFAudioOutput* ao = STATIC_CAST(MMMFAudioOutput*, iDataSink); |
|
2338 TMMFCapabilities devSoundConfig = ao->SoundDevice().Config(); |
|
2339 RArray<TFourCC> dataTypes; |
|
2340 CleanupClosePushL(dataTypes); |
|
2341 ConvertFromDevSoundCapsToDataTypesL(devSoundConfig, dataTypes); |
|
2342 ASSERT(dataTypes.Count()==1); |
|
2343 aDataType = dataTypes[0]; |
|
2344 CleanupStack::PopAndDestroy();//dataTypes |
|
2345 } |
|
2346 else |
|
2347 User::Leave(KErrNotSupported); |
|
2348 } |
|
2349 |
|
2350 /** |
|
2351 * |
|
2352 * MacGetSupportedSourceSampleRatesL |
|
2353 * @param "RArray<TUint>&" |
|
2354 * |
|
2355 */ |
|
2356 void CMMFTestUseOldCodecAudioController::MacGetSupportedSourceSampleRatesL(RArray<TUint>& aSupportedRates) |
|
2357 { |
|
2358 aSupportedRates.Reset(); |
|
2359 if (iSourceFormat) |
|
2360 iSourceFormat->GetSupportedSampleRatesL(aSupportedRates); |
|
2361 else if (iDataSource && (iDataSource->DataSourceType()==KUidMmfAudioInput)) |
|
2362 { |
|
2363 // cast iDataSource to audio input and query supported sample rates |
|
2364 MMMFAudioInput* ai = STATIC_CAST(MMMFAudioInput*, iDataSource); |
|
2365 TMMFCapabilities devSoundConfig = ai->SoundDevice().Capabilities(); |
|
2366 ConvertFromDevSoundCapsToSampleRatesL(devSoundConfig, aSupportedRates); |
|
2367 } |
|
2368 else |
|
2369 User::Leave(KErrNotSupported); |
|
2370 } |
|
2371 |
|
2372 /** |
|
2373 * |
|
2374 * MacGetSupportedSourceBitRatesL |
|
2375 * @param "RArray<TUint>&" |
|
2376 * |
|
2377 */ |
|
2378 void CMMFTestUseOldCodecAudioController::MacGetSupportedSourceBitRatesL(RArray<TUint>& aSupportedRates) |
|
2379 { |
|
2380 aSupportedRates.Reset(); |
|
2381 if (iSourceFormat) |
|
2382 iSourceFormat->GetSupportedBitRatesL(aSupportedRates); |
|
2383 else |
|
2384 User::Leave(KErrNotSupported); |
|
2385 } |
|
2386 |
|
2387 /*** |
|
2388 * |
|
2389 * MacGetSupportedSourceNumChannelsL |
|
2390 * @param "RArray<TUint>&" |
|
2391 * |
|
2392 */ |
|
2393 void CMMFTestUseOldCodecAudioController::MacGetSupportedSourceNumChannelsL(RArray<TUint>& aSupportedChannels) |
|
2394 { |
|
2395 aSupportedChannels.Reset(); |
|
2396 if (iSourceFormat) |
|
2397 iSourceFormat->GetSupportedNumChannelsL(aSupportedChannels); |
|
2398 else if (iDataSource && (iDataSource->DataSourceType()==KUidMmfAudioInput)) |
|
2399 { |
|
2400 // cast iDataSource to audio input and query supported num channels |
|
2401 MMMFAudioInput* ai = STATIC_CAST(MMMFAudioInput*, iDataSource); |
|
2402 TMMFCapabilities devSoundConfig = ai->SoundDevice().Capabilities(); |
|
2403 ConvertFromDevSoundCapsToNumChannelsL(devSoundConfig, aSupportedChannels); |
|
2404 } |
|
2405 else |
|
2406 User::Leave(KErrNotSupported); |
|
2407 } |
|
2408 |
|
2409 /*** |
|
2410 * |
|
2411 * MacGetSupportedSourceDataTypesL |
|
2412 * @param "RArray<TFourCC>&" |
|
2413 * |
|
2414 */ |
|
2415 void CMMFTestUseOldCodecAudioController::MacGetSupportedSourceDataTypesL(RArray<TFourCC>& aSupportedDataTypes) |
|
2416 { |
|
2417 aSupportedDataTypes.Reset(); |
|
2418 if (iSourceFormat) |
|
2419 iSourceFormat->GetSupportedDataTypesL(TMediaId(KUidMediaTypeAudio), aSupportedDataTypes); |
|
2420 else if (iDataSource && (iDataSource->DataSourceType()==KUidMmfAudioInput)) |
|
2421 { |
|
2422 // cast iDataSource to audio input and query supported data types |
|
2423 MMMFAudioInput* ai = STATIC_CAST(MMMFAudioInput*, iDataSource); |
|
2424 TMMFCapabilities devSoundConfig = ai->SoundDevice().Capabilities(); |
|
2425 ConvertFromDevSoundCapsToDataTypesL(devSoundConfig, aSupportedDataTypes); |
|
2426 } |
|
2427 else |
|
2428 User::Leave(KErrNotSupported); |
|
2429 } |
|
2430 |
|
2431 /*** |
|
2432 * |
|
2433 * MacGetSupportedSinkSampleRatesL |
|
2434 * @param "RArray<TUint>& " |
|
2435 * |
|
2436 */ |
|
2437 void CMMFTestUseOldCodecAudioController::MacGetSupportedSinkSampleRatesL(RArray<TUint>& aSupportedRates) |
|
2438 { |
|
2439 aSupportedRates.Reset(); |
|
2440 if (iSinkFormat) |
|
2441 iSinkFormat->GetSupportedSampleRatesL(aSupportedRates); |
|
2442 else if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput)) |
|
2443 { |
|
2444 // cast iDataSink to audio output and query supported sample rates |
|
2445 MMMFAudioOutput* ao = STATIC_CAST(MMMFAudioOutput*, iDataSink); |
|
2446 TMMFCapabilities devSoundConfig = ao->SoundDevice().Capabilities(); |
|
2447 ConvertFromDevSoundCapsToSampleRatesL(devSoundConfig, aSupportedRates); |
|
2448 } |
|
2449 else |
|
2450 User::Leave(KErrNotSupported); |
|
2451 } |
|
2452 |
|
2453 /*** |
|
2454 * |
|
2455 * MacGetSupportedSinkBitRatesL |
|
2456 * @param RArray<TUint>& |
|
2457 * |
|
2458 */ |
|
2459 void CMMFTestUseOldCodecAudioController::MacGetSupportedSinkBitRatesL(RArray<TUint>& aSupportedRates) |
|
2460 { |
|
2461 if (iSinkFormat) |
|
2462 iSinkFormat->GetSupportedBitRatesL(aSupportedRates); |
|
2463 else |
|
2464 User::Leave(KErrNotSupported); |
|
2465 } |
|
2466 |
|
2467 /*** |
|
2468 * |
|
2469 * MacGetSupportedSinkNumChannelsL |
|
2470 * @param RArray<TUint>& |
|
2471 * |
|
2472 */ |
|
2473 void CMMFTestUseOldCodecAudioController::MacGetSupportedSinkNumChannelsL(RArray<TUint>& aSupportedChannels) |
|
2474 { |
|
2475 aSupportedChannels.Reset(); |
|
2476 if (iSinkFormat) |
|
2477 iSinkFormat->GetSupportedNumChannelsL(aSupportedChannels); |
|
2478 else if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput)) |
|
2479 { |
|
2480 // cast iDataSink to audio output and query supported channels |
|
2481 MMMFAudioOutput* ao = STATIC_CAST(MMMFAudioOutput*, iDataSink); |
|
2482 TMMFCapabilities devSoundConfig = ao->SoundDevice().Capabilities(); |
|
2483 ConvertFromDevSoundCapsToNumChannelsL(devSoundConfig, aSupportedChannels); |
|
2484 } |
|
2485 else |
|
2486 User::Leave(KErrNotSupported); |
|
2487 } |
|
2488 |
|
2489 /*** |
|
2490 * |
|
2491 * MacGetSupportedSinkDataTypesL |
|
2492 * @param "RArray<TFourCC>&" |
|
2493 */ |
|
2494 void CMMFTestUseOldCodecAudioController::MacGetSupportedSinkDataTypesL(RArray<TFourCC>& aSupportedDataTypes) |
|
2495 { |
|
2496 aSupportedDataTypes.Reset(); |
|
2497 if (iSinkFormat) |
|
2498 iSinkFormat->GetSupportedDataTypesL(TMediaId(KUidMediaTypeAudio), aSupportedDataTypes); |
|
2499 else if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput)) |
|
2500 { |
|
2501 // cast iDataSink to audio output and query supported data types |
|
2502 MMMFAudioOutput* ao = STATIC_CAST(MMMFAudioOutput*, iDataSink); |
|
2503 TMMFCapabilities devSoundConfig = ao->SoundDevice().Capabilities(); |
|
2504 ConvertFromDevSoundCapsToDataTypesL(devSoundConfig, aSupportedDataTypes); |
|
2505 } |
|
2506 else |
|
2507 User::Leave(KErrNotSupported); |
|
2508 } |
|
2509 |
|
2510 /** |
|
2511 * |
|
2512 * ConvertFromDevSoundCapsToSampleRatesL |
|
2513 * @param "const TMMFCapabilities& " |
|
2514 * @param "RArray<TUint>&" |
|
2515 * |
|
2516 */ |
|
2517 void CMMFTestUseOldCodecAudioController::ConvertFromDevSoundCapsToSampleRatesL(const TMMFCapabilities& aDevSoundCaps, RArray<TUint>& aSampleRates) |
|
2518 { |
|
2519 if (aDevSoundCaps.iRate & EMMFSampleRate8000Hz) |
|
2520 User::LeaveIfError(aSampleRates.Append(KSampleRate8000Hz)); |
|
2521 if (aDevSoundCaps.iRate & EMMFSampleRate11025Hz) |
|
2522 User::LeaveIfError(aSampleRates.Append(KSampleRate11025Hz)); |
|
2523 if (aDevSoundCaps.iRate & EMMFSampleRate16000Hz) |
|
2524 User::LeaveIfError(aSampleRates.Append(KSampleRate16000Hz)); |
|
2525 if (aDevSoundCaps.iRate & EMMFSampleRate22050Hz) |
|
2526 User::LeaveIfError(aSampleRates.Append(KSampleRate22050Hz)); |
|
2527 if (aDevSoundCaps.iRate & EMMFSampleRate32000Hz) |
|
2528 User::LeaveIfError(aSampleRates.Append(KSampleRate32000Hz)); |
|
2529 if (aDevSoundCaps.iRate & EMMFSampleRate44100Hz) |
|
2530 User::LeaveIfError(aSampleRates.Append(KSampleRate44100Hz)); |
|
2531 if (aDevSoundCaps.iRate & EMMFSampleRate48000Hz) |
|
2532 User::LeaveIfError(aSampleRates.Append(KSampleRate48000Hz)); |
|
2533 if (aDevSoundCaps.iRate & EMMFSampleRate88200Hz) |
|
2534 User::LeaveIfError(aSampleRates.Append(KSampleRate88200Hz)); |
|
2535 if (aDevSoundCaps.iRate & EMMFSampleRate96000Hz) |
|
2536 User::LeaveIfError(aSampleRates.Append(KSampleRate96000Hz)); |
|
2537 } |
|
2538 |
|
2539 /** |
|
2540 * |
|
2541 * ConvertFromDevSoundCapsToNumChannelsL |
|
2542 * @param "const TMMFCapabilities&" |
|
2543 * @param "RArray<TUint>&" |
|
2544 * |
|
2545 */ |
|
2546 void CMMFTestUseOldCodecAudioController::ConvertFromDevSoundCapsToNumChannelsL(const TMMFCapabilities& aDevSoundCaps, RArray<TUint>& aNumChannels) |
|
2547 { |
|
2548 if (aDevSoundCaps.iChannels & EMMFMono) |
|
2549 User::LeaveIfError(aNumChannels.Append(KNumChannelsMono)); |
|
2550 if (aDevSoundCaps.iChannels & EMMFStereo) |
|
2551 User::LeaveIfError(aNumChannels.Append(KNumChannelsStereo)); |
|
2552 } |
|
2553 |
|
2554 /** |
|
2555 * |
|
2556 * ConvertFromDevSoundCapsToDataTypesL |
|
2557 * @param "const TMMFCapabilities&" |
|
2558 * @param "TMMFCapabilities& aDevSoundCaps, RArray<TFourCC>&" |
|
2559 * |
|
2560 */ |
|
2561 void CMMFTestUseOldCodecAudioController::ConvertFromDevSoundCapsToDataTypesL(const TMMFCapabilities& aDevSoundCaps, RArray<TFourCC>& aDataTypes) |
|
2562 { |
|
2563 if (aDevSoundCaps.iEncoding & EMMFSoundEncoding8BitPCM) |
|
2564 User::LeaveIfError(aDataTypes.Append(KMMFFourCCCodePCM8)); |
|
2565 if (aDevSoundCaps.iEncoding & EMMFSoundEncoding16BitPCM) |
|
2566 User::LeaveIfError(aDataTypes.Append(KMMFFourCCCodePCM16)); |
|
2567 if (aDevSoundCaps.iEncoding & EMMFSoundEncoding8BitALaw) |
|
2568 User::LeaveIfError(aDataTypes.Append(KMMFFourCCCodeALAW)); |
|
2569 if (aDevSoundCaps.iEncoding & EMMFSoundEncoding8BitMuLaw) |
|
2570 User::LeaveIfError(aDataTypes.Append(KMMFFourCCCodeMuLAW)); |
|
2571 } |
|
2572 |
|
2573 /** |
|
2574 * |
|
2575 * ConvertFromSampleRateToDevSoundCapsL |
|
2576 * @param "TUint" |
|
2577 * @param "TMMFCapabilities&" |
|
2578 * |
|
2579 */ |
|
2580 void CMMFTestUseOldCodecAudioController::ConvertFromSampleRateToDevSoundCapsL(TUint aSampleRate, TMMFCapabilities& aDevSoundCaps) |
|
2581 { |
|
2582 if (aSampleRate == KSampleRate8000Hz) |
|
2583 aDevSoundCaps.iRate = EMMFSampleRate8000Hz; |
|
2584 else if (aSampleRate == KSampleRate11025Hz) |
|
2585 aDevSoundCaps.iRate = EMMFSampleRate11025Hz; |
|
2586 else if (aSampleRate == KSampleRate16000Hz) |
|
2587 aDevSoundCaps.iRate = EMMFSampleRate16000Hz; |
|
2588 else if (aSampleRate == KSampleRate22050Hz) |
|
2589 aDevSoundCaps.iRate = EMMFSampleRate22050Hz; |
|
2590 else if (aSampleRate == KSampleRate32000Hz) |
|
2591 aDevSoundCaps.iRate = EMMFSampleRate32000Hz; |
|
2592 else if (aSampleRate == KSampleRate44100Hz) |
|
2593 aDevSoundCaps.iRate = EMMFSampleRate44100Hz; |
|
2594 else if (aSampleRate == KSampleRate48000Hz) |
|
2595 aDevSoundCaps.iRate = EMMFSampleRate48000Hz; |
|
2596 else if (aSampleRate == KSampleRate88200Hz) |
|
2597 aDevSoundCaps.iRate = EMMFSampleRate88200Hz; |
|
2598 else if (aSampleRate == KSampleRate96000Hz) |
|
2599 aDevSoundCaps.iRate = EMMFSampleRate96000Hz; |
|
2600 else |
|
2601 User::Leave(KErrNotSupported); |
|
2602 } |
|
2603 |
|
2604 /** |
|
2605 * |
|
2606 * ConvertFromNumChannelsToDevSoundCapsL |
|
2607 * @param "TUint" |
|
2608 * @param "TMMFCapabilities&" |
|
2609 * |
|
2610 */ |
|
2611 void CMMFTestUseOldCodecAudioController::ConvertFromNumChannelsToDevSoundCapsL(TUint aNumChannels, TMMFCapabilities& aDevSoundCaps) |
|
2612 { |
|
2613 if (aNumChannels == KNumChannelsMono) |
|
2614 aDevSoundCaps.iChannels = EMMFMono; |
|
2615 else if (aNumChannels == KNumChannelsStereo) |
|
2616 aDevSoundCaps.iChannels = EMMFStereo; |
|
2617 else |
|
2618 User::Leave(KErrNotSupported); |
|
2619 } |
|
2620 |
|
2621 /** |
|
2622 * |
|
2623 * ConvertFromDataTypeToDevSoundCapsL |
|
2624 * @param "TFourCC" |
|
2625 * @param "TMMFCapabilities&" |
|
2626 * |
|
2627 */ |
|
2628 void CMMFTestUseOldCodecAudioController::ConvertFromDataTypeToDevSoundCapsL(TFourCC aDataType, TMMFCapabilities& aDevSoundCaps) |
|
2629 { |
|
2630 if (aDataType == KMMFFourCCCodePCM8) |
|
2631 aDevSoundCaps.iEncoding = EMMFSoundEncoding8BitPCM; |
|
2632 else if (aDataType == KMMFFourCCCodePCM16) |
|
2633 aDevSoundCaps.iEncoding = EMMFSoundEncoding16BitPCM; |
|
2634 else if (aDataType == KMMFFourCCCodeALAW) |
|
2635 aDevSoundCaps.iEncoding = EMMFSoundEncoding8BitALaw; |
|
2636 else if (aDataType == KMMFFourCCCodeMuLAW) |
|
2637 aDevSoundCaps.iEncoding = EMMFSoundEncoding8BitMuLaw; |
|
2638 else |
|
2639 User::Leave(KErrNotSupported); |
|
2640 } |
|
2641 |
|
2642 /** |
|
2643 * IsValidStateTransition |
|
2644 * The function validates a state transition from iState to aState |
|
2645 * and returns ETrue if the transition is allowed. |
|
2646 * @param TControllerState |
|
2647 * @returns "TBool" |
|
2648 * @xxxx |
|
2649 */ |
|
2650 TBool CMMFTestUseOldCodecAudioController::IsValidStateTransition( TControllerState aState ) const |
|
2651 { |
|
2652 TBool result = ETrue ; |
|
2653 //[ assert the precondition that aState is a valid State ] |
|
2654 __ASSERT_ALWAYS( IsValidState(aState), Panic( EBadArgument ) ); |
|
2655 //[ assert the invariant that iState is a valid State ] |
|
2656 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant )); |
|
2657 |
|
2658 // [ check the valid state transitions ] |
|
2659 // the only invalid transition is |
|
2660 // stopped to playing |
|
2661 if( ( iState == EStopped ) && ( aState == EPlaying )) |
|
2662 { |
|
2663 result = EFalse ; |
|
2664 } |
|
2665 |
|
2666 //[ assert the invariant that iState is a valid State ] |
|
2667 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant )); |
|
2668 |
|
2669 return result ; |
|
2670 } |
|
2671 |
|
2672 /* |
|
2673 * Invariant |
|
2674 * @returns "TBool" |
|
2675 * This function returns whether the invariant is valid |
|
2676 * @xxxx |
|
2677 */ |
|
2678 TBool CMMFTestUseOldCodecAudioController::Invariant() const |
|
2679 { |
|
2680 //[ The invariant is for now defined |
|
2681 // as simply being in the correct state and |
|
2682 // having iDataPath defined ] |
|
2683 return ( iDataPath )&& IsValidState( iState); |
|
2684 } |
|
2685 |
|
2686 /* |
|
2687 * SetState |
|
2688 * This function sets the state of the controller. |
|
2689 * @returns "TBool" |
|
2690 * @xxxx |
|
2691 */ |
|
2692 TBool CMMFTestUseOldCodecAudioController::SetState(TControllerState aState) |
|
2693 { |
|
2694 TBool result = ETrue; |
|
2695 //[ assert the precondition that the state is a valid state ] |
|
2696 __ASSERT_ALWAYS( IsValidState( aState), Panic( EBadArgument ) ); |
|
2697 //[ assert the invariant the current state is valid ] |
|
2698 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant ) ); |
|
2699 //[ only allow valid state transitions ] |
|
2700 if( IsValidStateTransition( aState ) ) |
|
2701 { |
|
2702 //[ valid state transition set the state] |
|
2703 iState = aState ; |
|
2704 } |
|
2705 else |
|
2706 { |
|
2707 //[ invalid state transition return EFalse ] |
|
2708 result = EFalse; |
|
2709 } |
|
2710 // [ assert the invariant on the state ] |
|
2711 __ASSERT_ALWAYS( Invariant(), Panic( EBadState )); |
|
2712 |
|
2713 return result ; |
|
2714 } |
|
2715 |
|
2716 /* |
|
2717 * IsValidState |
|
2718 * checks whether a state is a valid |
|
2719 * @returns "TBool" |
|
2720 * @param TControllerState |
|
2721 * @xxxx |
|
2722 */ |
|
2723 TBool CMMFTestUseOldCodecAudioController::IsValidState( TControllerState aState ) const |
|
2724 { |
|
2725 TBool result = EFalse; |
|
2726 if(( aState >= EStopped ) && ( aState <= EPlaying )) |
|
2727 { |
|
2728 result = ETrue; |
|
2729 } |
|
2730 return result; |
|
2731 } |
|
2732 |
|
2733 /** |
|
2734 * State |
|
2735 * The function State returns the current state of the audio controller |
|
2736 * @returns "TControllerState" |
|
2737 * @xxxx |
|
2738 */ |
|
2739 CMMFTestUseOldCodecAudioController::TControllerState CMMFTestUseOldCodecAudioController::State() const |
|
2740 { |
|
2741 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant ) ); |
|
2742 return iState; |
|
2743 } |
|
2744 |
|
2745 /** |
|
2746 * |
|
2747 * SinkFormatRequired |
|
2748 * |
|
2749 */ |
|
2750 TBool CMMFTestUseOldCodecAudioController::SinkFormatRequired( MDataSink& aDataSink ) const |
|
2751 { |
|
2752 return (aDataSink.DataSinkType()==KUidMmfFileSink || |
|
2753 aDataSink.DataSinkType()==KUidMmfDescriptorSink); |
|
2754 } |
|
2755 |
|
2756 /** |
|
2757 * |
|
2758 * SourceFormatRequired |
|
2759 * |
|
2760 */ |
|
2761 |
|
2762 TBool CMMFTestUseOldCodecAudioController::SourceFormatRequired(MDataSource& aDataSource) const |
|
2763 { |
|
2764 return (aDataSource.DataSourceType()==KUidMmfFileSource || |
|
2765 aDataSource.DataSourceType()==KUidMmfDescriptorSource); |
|
2766 } |
|
2767 /** |
|
2768 * |
|
2769 * DevSoundInitialised |
|
2770 * Used in certain configurations to resume completion of PrimeL() when it is pending DevSound initialisation. |
|
2771 * |
|
2772 */ |
|
2773 void CMMFTestUseOldCodecAudioController::DevSoundInitialised(TInt /*aError*/) |
|
2774 { |
|
2775 iWaitForAsyncService->AsyncStop(); |
|
2776 } |
|
2777 |
|
2778 CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::TDevSoundEventHandler() |
|
2779 : iInterceptedDevSoundObserver(NULL), iEventObserver(NULL) |
|
2780 { |
|
2781 } |
|
2782 |
|
2783 void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::SetInterceptedDevSoundObserver(MDevSoundObserver* aObserver) |
|
2784 { |
|
2785 iInterceptedDevSoundObserver = aObserver; |
|
2786 } |
|
2787 |
|
2788 void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::SetEventObserver(CMMFTestUseOldCodecAudioController* aObserver) |
|
2789 { |
|
2790 iEventObserver = aObserver; |
|
2791 } |
|
2792 |
|
2793 void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::InitializeComplete(TInt aError) |
|
2794 { |
|
2795 iInterceptedDevSoundObserver->InitializeComplete(aError); |
|
2796 iEventObserver->DevSoundInitialised(aError); |
|
2797 } |
|
2798 |
|
2799 void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::ToneFinished(TInt aError) |
|
2800 { |
|
2801 iInterceptedDevSoundObserver->ToneFinished(aError); |
|
2802 } |
|
2803 |
|
2804 void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::BufferToBeFilled(CMMFBuffer* aBuffer) |
|
2805 { |
|
2806 iInterceptedDevSoundObserver->BufferToBeFilled(aBuffer); |
|
2807 } |
|
2808 |
|
2809 void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::PlayError(TInt aError) |
|
2810 { |
|
2811 iInterceptedDevSoundObserver->PlayError(aError); |
|
2812 } |
|
2813 |
|
2814 void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::BufferToBeEmptied(CMMFBuffer* aBuffer) |
|
2815 { |
|
2816 iInterceptedDevSoundObserver->BufferToBeEmptied(aBuffer); |
|
2817 } |
|
2818 |
|
2819 void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::RecordError(TInt aError) |
|
2820 { |
|
2821 iInterceptedDevSoundObserver->RecordError(aError); |
|
2822 } |
|
2823 |
|
2824 void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::ConvertError(TInt aError) |
|
2825 { |
|
2826 iInterceptedDevSoundObserver->ConvertError(aError); |
|
2827 } |
|
2828 |
|
2829 void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::DeviceMessage(TUid aMessageType, const TDesC8& aMsg) |
|
2830 { |
|
2831 iInterceptedDevSoundObserver->DeviceMessage(aMessageType, aMsg); |
|
2832 } |
|
2833 |
|
2834 |