os/mm/mmlibs/mmfw/tsrc/mmfintegrationtest/ACLNT/UseOldCodecAudioController/TestUseOldCodecAudioController.cpp
Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
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"
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;
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
45 enum TMmfAudioControllerPanics
51 EPostConditionViolation
56 * This method generates a panic
60 void Panic(TInt aPanicCode)
62 _LIT(KMMFAudioControllerPanicCategory, "MMFAudioController");
63 User::Panic(KMMFAudioControllerPanicCategory, aPanicCode);
69 * @return CMMFTestUseOldCodecAudioController*
71 CMMFController* CMMFTestUseOldCodecAudioController::NewL()
73 CMMFTestUseOldCodecAudioController* self = new(ELeave) CMMFTestUseOldCodecAudioController;
74 CleanupStack::PushL(self);
76 CleanupStack::Pop( self );
77 return STATIC_CAST( CMMFController*, self );
85 void CMMFTestUseOldCodecAudioController::ConstructL()
89 iDataPath = CMMFDataPath::NewL(iMediaId, *this);
92 iSourceAndSinkAdded = EFalse;
93 iStoppingRecording = EFalse;
96 //iMediaId has already been set up
98 //iPrioritySettings not initialised because they are held by the controller framework
100 // Construct custom command parsers
101 CMMFAudioPlayDeviceCustomCommandParser* audPlayDevParser = CMMFAudioPlayDeviceCustomCommandParser::NewL(*this);
102 CleanupStack::PushL(audPlayDevParser);
103 AddCustomCommandParserL(*audPlayDevParser);
104 CleanupStack::Pop( audPlayDevParser );//audPlayDevParser
106 CMMFAudioRecordDeviceCustomCommandParser* audRecDevParser = CMMFAudioRecordDeviceCustomCommandParser::NewL(*this);
107 CleanupStack::PushL(audRecDevParser);
108 AddCustomCommandParserL(*audRecDevParser);
109 CleanupStack::Pop(audRecDevParser);//audRecDevParser
111 CMMFAudioPlayControllerCustomCommandParser* audPlayConParser = CMMFAudioPlayControllerCustomCommandParser::NewL(*this);
112 CleanupStack::PushL(audPlayConParser);
113 AddCustomCommandParserL(*audPlayConParser);
114 CleanupStack::Pop(audPlayConParser);//audPlayConParser
116 CMMFAudioRecordControllerCustomCommandParser* audRecConParser = CMMFAudioRecordControllerCustomCommandParser::NewL(*this);
117 CleanupStack::PushL(audRecConParser);
118 AddCustomCommandParserL(*audRecConParser);
119 CleanupStack::Pop(audRecConParser);//audRecParser
121 CMMFAudioControllerCustomCommandParser* audConParser = CMMFAudioControllerCustomCommandParser::NewL(*this);
122 CleanupStack::PushL(audConParser);
123 AddCustomCommandParserL(*audConParser);
124 CleanupStack::Pop(audConParser);//audConParser
126 iWaitForAsyncService = new (ELeave) CActiveSchedulerWait;
128 // [ assert the invariant now that we are constructed ]
129 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
134 * CMMFTestUseOldCodecAudioController
138 CMMFTestUseOldCodecAudioController::CMMFTestUseOldCodecAudioController() : iMediaId(KUidMediaTypeAudio), iState(EStopped)
144 * ~CMMFTestUseOldCodecAudioController
148 CMMFTestUseOldCodecAudioController::~CMMFTestUseOldCodecAudioController()
150 // [ ensure we have logged off the thread ]
153 iDataPath->ResetL(); // this does not leave
156 delete iSourceFormat;
158 delete iStoppingMessage;
159 delete iWaitForAsyncService;
165 * Adds a data source to the controller
170 * Source does not already exist
172 * iDataSource != NULL
173 * iDataSourceAdded == ETrue
175 void CMMFTestUseOldCodecAudioController::AddDataSourceL(MDataSource& aSource)
177 //[ assert the invariant ]
178 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
180 // [ precondition that the controller is stopped ]
181 if( State() != EStopped )
182 User::Leave( KErrNotReady );
184 //[ precondition iData source is not already configured ]
186 User::Leave(KErrAlreadyExists);
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) )
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))
204 else if (aSource.DataSourceType()==KUidMmfAudioInput)
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 ));
214 User::Leave(KErrNotSupported);
217 //[ its now safe to set the source ]
218 iDataSource = &aSource ;
219 iDataSource->SetSourcePrioritySettings(iPrioritySettings);
221 //[ assert the post condition ]
222 __ASSERT_ALWAYS(iDataSource, Panic(EMMFAudioControllerPanicDataSourceDoesNotExist));
230 * Adds a data sink to the controller
235 void CMMFTestUseOldCodecAudioController::AddDataSinkL(MDataSink& aSink)
237 //[ assert the invariant ]
238 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
240 // [ precondition that the controller is stopped ]
241 if( State() != EStopped )
242 User::Leave( KErrNotReady );
244 // [ assert precondition that sink does not exist ]
246 User::Leave(KErrAlreadyExists);
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
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))
266 else if (aSink.DataSinkType()==KUidMmfAudioOutput)
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 ));
277 User::Leave(KErrNotSupported);
280 //[ now that we are sure we have not left we can update the sink
283 iDataSink->SetSinkPrioritySettings(iPrioritySettings);
285 // [ assert post conditions that a sink has been added ]
286 __ASSERT_ALWAYS(iDataSink, Panic(EMMFAudioControllerPanicDataSinkDoesNotExist));
293 * If Prime fails the client should reset the controller
294 * because as noted below this code is not transactional.
297 void CMMFTestUseOldCodecAudioController::PrimeL()
299 //[ assert the invariant ]
300 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
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 );
307 // [ precondition we have a data source & sink ]
308 __ASSERT_ALWAYS( iDataSource, Panic( EBadInvariant));
309 __ASSERT_ALWAYS( iDataSink, Panic( EBadInvariant));
312 //[ precondition that we need a source format ]
313 if ( SourceFormatRequired(*iDataSource) && !(iSourceFormat))
314 User::Leave( KErrNotSupported );
316 // [ check the precondition if we need a data sink format ]
317 if ( SinkFormatRequired(*iDataSink) && !( iSinkFormat ))
318 User::Leave( KErrNotSupported );
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
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);
342 if (!iSourceAndSinkAdded)
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
347 iDataPath->AddDataSourceL(iSourceFormat);
348 else if (iDataSource)
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);
357 iDataPath->AddDataSinkL(iSinkFormat);
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());
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
375 devSound->InitializeL(iDevSoundEventHandler,KMMFFourCCCodePCM16,EMMFStatePlaying);
376 iWaitForAsyncService->Start();
378 //now tell audio output were pcm16
379 iDataSink->SetSinkDataTypeCode(KMMFFourCCCodePCM16, KUidMediaTypeAudio);
380 iDataPath->AddDataSinkL(iDataSink);
382 iSourceAndSinkAdded = ETrue ;
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);
395 //[ it is now safe to make the transition to primed ]
398 else if (State() == EPrimed)
399 { //controller is already primed so just pass prime onto DP
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 ) );
411 * This method resets the controller
414 void CMMFTestUseOldCodecAudioController::ResetL()
416 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant ) );
418 // Stop recording if it's not stopped,
419 if (State() != EStopped)
425 // Remove references to source and sink
428 delete iSourceFormat; iSourceFormat = NULL ;
429 delete iSinkFormat; iSinkFormat = NULL ;
431 //[ ensure loggoff of source and sink ]
434 iSourceAndSinkAdded = EFalse;
436 // [ assert the invariant]
437 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant ) );
439 // [ assert the post condition
441 // iDataSource is NULL
442 // iSourceFormat is NULL
443 // iSinkFormat is NULL ]
444 __ASSERT_ALWAYS( ResetPostCondition(), Panic( EBadReset ));
445 __ASSERT_ALWAYS( Invariant(), Panic(EBadState));
450 * This function determnines if the reset post condition is valid
453 TBool CMMFTestUseOldCodecAudioController::ResetPostCondition() const
456 TBool result = EFalse ;
457 if((iSourceFormat == NULL) &&
458 (iDataSink == NULL) &&
459 (iDataSource == NULL) &&
460 (iSinkFormat == NULL) &&
461 (State() == EStopped))
475 void CMMFTestUseOldCodecAudioController::PlayL()
477 // [ assert the precondition that the
478 // play command is only activated in the primed state]
479 if ( State() != EPrimed)
480 User::Leave(KErrNotReady);
482 // [ assert the Invariant ]
483 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
485 //[datapath propogates play to sink & source]
487 SetState( EPlaying );
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));
501 void CMMFTestUseOldCodecAudioController::PauseL()
503 // [ assert the invariant ]
504 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
506 //[ assert the precondition that we are playing ]
507 if ( State() != EPlaying)
508 User::Leave(KErrNotReady);
510 //[ datapath propogates pause to sink & source ]
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));
524 void CMMFTestUseOldCodecAudioController::StopL(TMMFMessage& aMessage)
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.
534 if ((State() != EStopped) && !iStoppingRecording)
536 if((State() == EPlaying) && (iDataSource->DataSourceType()==KUidMmfAudioInput)) //we are recording
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.
543 iStoppingMessage = CMMFMessageHolder::NewL(aMessage);
544 iStoppingRecording = ETrue;
548 // datapath propogates stop to sink & source
554 //complete message as request is complete.
555 if(State() == EStopped && !IsUnderTest())
557 aMessage.Complete(KErrNone);
560 //[ assert the invariant ]
561 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
567 * The Controller is in the state EPrimed
568 * @return TTimeIntervalMicroSeconds
571 TTimeIntervalMicroSeconds CMMFTestUseOldCodecAudioController::PositionL() const
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);
579 TTimeIntervalMicroSeconds position = iDataPath->Position();
581 //[ assert the invariant ]
582 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
593 void CMMFTestUseOldCodecAudioController::SetPositionL(const TTimeIntervalMicroSeconds& aPosition)
595 //[ assert the invariant ]
596 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
598 // [ precondition that we are not already stopped ]
599 if (iState == EStopped)
600 User::Leave(KErrNotReady);
602 //[ precondition that the position is >= 0 && <= Duration ]
604 TTimeIntervalMicroSeconds theDuration(0);
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);
609 else if (iSinkFormat)
610 { //duration of recorded clip
611 theDuration = iSinkFormat->Duration(iMediaId);
613 TTimeIntervalMicroSeconds theStart(0);
614 if( ( aPosition < theStart) || ( aPosition > theDuration) )
615 //[ invalid position before start and after end]
616 User::Leave(KErrArgument);
619 //[ set the position on the data path ]
620 iDataPath->SetPositionL(aPosition);
622 //[ assert the invariant ]
623 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
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 ]
634 * @returns TTimeIntervalMicroSeconds
637 TTimeIntervalMicroSeconds CMMFTestUseOldCodecAudioController::DurationL() const
639 //[ assert the invariant ]
640 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
643 // [ assert we have a format that supports duration ]
644 if( !( iSourceFormat || iSinkFormat ) )
645 User::Leave(KErrNotSupported);
647 //[ now do the real work of getting the duration ]
648 // ------------------------------------------------
649 TTimeIntervalMicroSeconds theDuration(0);
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);
654 else if (iSinkFormat)
655 { //duration of recorded clip
656 theDuration = iSinkFormat->Duration(iMediaId);
659 //[ assert the invariant ]
660 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
667 * GetNumberOfMetaDataEntriesL
672 void CMMFTestUseOldCodecAudioController::GetNumberOfMetaDataEntriesL(TInt& aNumberOfEntries )
675 //[ assert the invariant ]
676 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
678 //[ precondition that we are in the primed state or stopped ]
679 if( !((State() == EPrimed) || ( State() == EStopped)))
680 User::Leave(KErrNotReady);
682 // [ precondition there is a sink format ]
684 User::Leave(KErrNotSupported);
686 // [ precondition the sink format is an encode format ]
687 if ((iDataSink->DataSinkType()!=KUidMmfAudioOutput) &&
688 (iDataSource->DataSourceType()!= KUidMmfAudioInput) )
689 User::Leave(KErrNotSupported);
691 if (iDataSink->DataSinkType()==KUidMmfAudioOutput)
694 //[ precondition the format exists ]
696 User::Leave(KErrNotSupported);
698 //[ Get the Number of meta data entries from the sink format ]
699 iSourceFormat->GetNumberOfMetaDataEntriesL( aNumberOfEntries );
701 else if (iDataSource->DataSourceType()==KUidMmfAudioInput)
704 User::Leave(KErrNotSupported);
706 iSinkFormat->GetNumberOfMetaDataEntriesL( aNumberOfEntries );
709 //[ assert the invariant ]
710 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
717 * @returns "CMMFMetaDataEntry*"
719 CMMFMetaDataEntry* CMMFTestUseOldCodecAudioController::GetMetaDataEntryL(TInt aIndex )
721 //[ assert the invariant ]
722 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
724 //[ precondition that we are in the primed state or stopped ]
725 if( !((State() == EPrimed) || ( State() == EStopped)))
726 User::Leave(KErrNotReady);
728 // [ precondition there is a sink format ]
730 User::Leave(KErrNotSupported);
732 iDataSink->DataSinkType();
733 iDataSource->DataSourceType();
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);
740 //[ Get the meta data entry from the sink format ]
741 CMMFMetaDataEntry* theEntry = NULL;
743 if (iDataSink->DataSinkType()==KUidMmfAudioOutput)
745 //[ precondition the format exists ]
747 User::Leave(KErrNotSupported);
749 //[ Get the Number of meta data entries from the sink format ]
750 theEntry = iSourceFormat->MetaDataEntryL(aIndex);
752 else if (iDataSource->DataSourceType()==KUidMmfAudioInput)
754 //[ precondition the format exits ]
756 User::Leave(KErrNotSupported);
757 theEntry = iSinkFormat->MetaDataEntryL(aIndex);
760 //[ assert the post condition that the entry is not null ]
761 __ASSERT_ALWAYS( theEntry, Panic(EBadInvariant));
763 //[ assert the invariant ]
764 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
774 void CMMFTestUseOldCodecAudioController::RemoveDataSourceL(MDataSource& aDataSource )
776 //[ assert the invariant ]
777 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant) );
779 //[ precondition is that we have a data source ]
781 User::Leave(KErrNotReady);
783 //[precondition the data source is the data source we have]
784 if( iDataSource != &aDataSource )
785 User::Leave(KErrArgument);
787 //[ the controller is in the stopped state ]
788 if(State() != EStopped)
789 User::Leave(KErrNotReady);
791 //[ remove the data sink from the controller and delete the format]
792 if( iSourceAndSinkAdded )
794 __ASSERT_ALWAYS( iDataPath, Panic( EBadState ));
795 //[ Remove references to source and sink ]
797 iSourceAndSinkAdded = EFalse ;
800 // [ delete the data sink and format ]
802 delete iSourceFormat;
803 iSourceFormat = NULL;
805 // [ assert postcondition we are stopped ]
806 __ASSERT_ALWAYS( (State() == EStopped), Panic(EPostConditionViolation) );
808 //[ assert postcondition the SourceAndSinkAdded is false ]
809 __ASSERT_ALWAYS( !iSourceAndSinkAdded, Panic( EPostConditionViolation ));
811 //[ assert postcondition the data sinkformat is null ]
812 __ASSERT_ALWAYS( (iSourceFormat == NULL ), Panic( EPostConditionViolation ));
814 //[ assert postcondition the data sink is null ]
815 __ASSERT_ALWAYS( (iDataSource == NULL ), Panic( EPostConditionViolation ));
817 //[ assert the invariant ]
818 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
828 void CMMFTestUseOldCodecAudioController::RemoveDataSinkL(MDataSink& aDataSink )
830 //[ assert the invariant ]
831 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant) );
833 //[ precondition is that we have a data sink ]
835 User::Leave(KErrNotSupported);
837 //[precondition the data sink is the data sink we have]
838 if( iDataSink != &aDataSink )
839 User::Leave(KErrNotSupported);
841 //[ the controller is in the stopped state ]
842 if(State() != EStopped)
843 User::Leave(KErrNotReady);
845 //[ remove the data sink from the controller and delete the format]
846 if( iSourceAndSinkAdded )
848 __ASSERT_ALWAYS( iDataPath, Panic( EBadState ));
849 //[ Remove references to source and sink ]
851 iSourceAndSinkAdded = EFalse ;
854 // [ reset data sink referenece and remove the format ]
859 // [ assert postcondition we are stopped ]
860 __ASSERT_ALWAYS( (State() == EStopped), Panic(EPostConditionViolation) );
862 //[ assert postcondition the SourceAndSinkAdded is false ]
863 __ASSERT_ALWAYS( !iSourceAndSinkAdded, Panic( EPostConditionViolation ));
865 //[ assert postcondition the data sinkformat is null ]
866 __ASSERT_ALWAYS( (iSinkFormat == NULL ), Panic( EPostConditionViolation ));
868 //[ assert postcondition the data sink is null ]
869 __ASSERT_ALWAYS( (iDataSink == NULL ), Panic( EPostConditionViolation ));
871 //[ assert the invariant ]
872 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
879 void CMMFTestUseOldCodecAudioController::CustomCommand(TMMFMessage& aMessage)
881 //[ assert the invariant ]
882 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
883 // [ We do not have any custom commands ]
884 aMessage.Complete(KErrNotSupported);
891 void CMMFTestUseOldCodecAudioController::NegotiateL()
893 //[ assert the invariant ]
894 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
896 //utility function used by custom to negotiate source sink settings after a change
897 if ((iSourceFormat)&&(iSinkFormat)) //convert
899 iSinkFormat->NegotiateL(*iSourceFormat);
900 iSourceFormat->NegotiateSourceL(*iSinkFormat);
901 iSinkFormat->NegotiateL(*iSourceFormat);
903 // check for upsampling attempts
904 if (iSinkFormat->SampleRate() > iSourceFormat->SampleRate())
906 // we don't support upsampling
907 User::Leave( KErrNotSupported );
910 else if ((iDataSource)&&(iSinkFormat)) //record
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);
918 else if ((iSourceFormat)&&(iDataSink)) //play
919 iDataSink->NegotiateL(*iSourceFormat);
921 //[ assert the invariant ]
922 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
926 * SetPrioritySettings
928 * @param aPrioritySettings
930 void CMMFTestUseOldCodecAudioController::SetPrioritySettings(const TMMFPrioritySettings& aPrioritySettings)
932 //[ assert the invariant ]
933 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
935 //[ assert the precondition ]
936 if(State() != EStopped)
938 ASSERT(EFalse); // used to leave here with KErrNotReady
942 //[ update the priority settings of the controller]
943 iPrioritySettings = aPrioritySettings;
945 //pass settings on to source and sink
948 iDataSource->SetSourcePrioritySettings(iPrioritySettings);
952 iDataSink->SetSinkPrioritySettings(iPrioritySettings);
955 // assert the post condition
956 //__ASSERT_ALWAYS( (iPrioritySettings == aPrioritySettings), Panic( ));
957 //[ assert the invariant ]
958 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
966 TInt CMMFTestUseOldCodecAudioController::SendEventToClient(const TMMFEvent& aEvent)
968 //[ assert the invariant ]
969 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
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;
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))
983 if(iStoppingRecording)
985 iStoppingRecording = EFalse;
987 SetState( EStopped );
989 //complete the clients stop request
990 iStoppingMessage->Complete(KErrNone);
991 delete iStoppingMessage; iStoppingMessage=NULL;
993 //we don't want to send an event to the client
997 {//datapath has reached end of file so set internal state to primed
1003 if ( State()!= EStopped)
1005 //datapath propogates stop to sink & source
1007 SetState( EStopped );
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;
1019 //now send event to client...
1020 TInt result = DoSendEventToClient(controllerEvent);
1022 //[ assert the invariant ]
1023 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1035 void CMMFTestUseOldCodecAudioController::MapdSetVolumeL(TInt aVolume)
1037 //[ assert the invariant ]
1038 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1040 // [ precondition is true for state
1041 // we can set the volume in any state ]
1043 //[ precondition we have a data sink ]
1045 User::Leave(KErrNotReady);
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);
1052 MMMFAudioOutput* audioOutput = STATIC_CAST(MMMFAudioOutput*, iDataSink);
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);
1059 //[ set the volume on the device ]
1060 audioOutput->SoundDevice().SetVolume(aVolume);
1062 //[ assert the post condition volume is equal to a volume]
1063 TInt soundVolume = 0;
1064 soundVolume = audioOutput->SoundDevice().Volume();
1066 __ASSERT_ALWAYS( ( soundVolume == aVolume), Panic(EPostConditionViolation));
1068 //[ assert the invariant ]
1069 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1079 void CMMFTestUseOldCodecAudioController::MapdGetMaxVolumeL(TInt& aMaxVolume)
1081 // [ assert the invariant ]
1082 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1084 //[ we can get max volume in any state ]
1086 // [ precondition we must have a data sink ]
1088 User::Leave(KErrNotReady);
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);
1095 //[ get the volume from the device ]
1096 MMMFAudioOutput* audioOutput = STATIC_CAST(MMMFAudioOutput*, iDataSink);
1097 aMaxVolume = audioOutput->SoundDevice().MaxVolume();
1099 //[ assert the invariant ]
1100 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1112 void CMMFTestUseOldCodecAudioController::MapdGetVolumeL(TInt& aVolume)
1114 // [ assert the invariant ]
1115 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1117 //[ precondition that we have a data sink ]
1119 User::Leave(KErrNotReady);
1121 //[ precondition iDataSink is an Audio Output ]
1122 if (iDataSink->DataSinkType() != KUidMmfAudioOutput)
1123 User::Leave(KErrNotSupported);
1125 // [ get the volume ]
1126 MMMFAudioOutput* audioOutput = STATIC_CAST(MMMFAudioOutput*, iDataSink);
1127 aVolume = audioOutput->SoundDevice().Volume();
1129 // [ assert precondition that the volume is in range
1131 TInt aMaxVolume = audioOutput->SoundDevice().MaxVolume();
1132 __ASSERT_ALWAYS( (aVolume <= aMaxVolume), Panic(EBadState));
1133 __ASSERT_ALWAYS( (aVolume >= 0), Panic(EBadState));
1135 // [ assert the invariant ]
1136 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1142 * MapdSetVolumeRampL
1144 * @param aRampDuration
1147 void CMMFTestUseOldCodecAudioController::MapdSetVolumeRampL(const TTimeIntervalMicroSeconds& aRampDuration)
1149 // [ assert the invariant ]
1150 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1152 //[ precondition that we have a data sink ]
1154 User::Leave(KErrNotReady);
1156 // [ precondition iDataSink is an Audio Output ]
1157 if (iDataSink->DataSinkType() != KUidMmfAudioOutput)
1158 User::Leave(KErrNotSupported);
1160 //[ set the volume ramp ]
1161 MMMFAudioOutput* audioOutput = STATIC_CAST(MMMFAudioOutput*, iDataSink);
1162 audioOutput->SoundDevice().SetVolumeRamp(aRampDuration);
1164 //[ assert the invariant ]
1165 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1177 void CMMFTestUseOldCodecAudioController::MapdSetBalanceL(TInt aBalance)
1179 //[ assert the invariant ]
1180 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
1182 // [ precondition is that we have a data sink ]
1184 User::Leave(KErrNotReady);
1186 // [ precondition is that the data sink is an audio output]
1187 if (iDataSink->DataSinkType() != KUidMmfAudioOutput)
1188 User::Leave(KErrNotSupported);
1190 //[ get the audio output ]
1191 MMMFAudioOutput* audioOutput = STATIC_CAST(MMMFAudioOutput*, iDataSink);
1193 // [ separate out left and right balance ]
1196 CalculateLeftRightBalance( left, right, aBalance );
1198 //[ set the balance ]
1199 audioOutput->SoundDevice().SetPlayBalanceL(left, right);
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);
1206 //[ assert post condition holds]
1207 TBool postCondition = (( rightBalance == right) && ( leftBalance == left));
1208 __ASSERT_ALWAYS( postCondition, Panic( EPostConditionViolation ) );
1210 //[ assert the invariant ]
1211 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
1215 * CalculateLeftRightBalance
1220 * !(aBalance < KMMFBalanceMaxLeft || aBalance > KMMFBalanceMaxRight)
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 )
1234 void CMMFTestUseOldCodecAudioController::CalculateLeftRightBalance( TInt& aLeft, TInt& aRight, TInt aBalance ) const
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;
1242 // [ assert precondition that aBalance is within limits ]
1243 __ASSERT_ALWAYS( !(aBalance < KMMFBalanceMaxLeft || aBalance > KMMFBalanceMaxRight), Panic(EBadArgument));
1245 //[ Now separate percentage balances out from aBalance ]
1246 aLeft = (100 * (aBalance-KMMFBalanceMaxRight)) / (KMMFBalanceMaxLeft-KMMFBalanceMaxRight);
1247 aRight = 100 - aLeft;
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));
1260 void CMMFTestUseOldCodecAudioController::MapdGetBalanceL(TInt& aBalance)
1262 //[ assert the invariant ]
1263 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1265 //[ precondition that we have a sink]
1267 User::Leave(KErrNotReady);
1269 // [ iDataSink is an Audio Output ]
1270 if (iDataSink->DataSinkType() != KUidMmfAudioOutput)
1271 User::Leave(KErrNotSupported);
1273 // [ get the play balance ]
1274 MMMFAudioOutput* audioOutput = STATIC_CAST(MMMFAudioOutput*, iDataSink);
1275 TInt left = 50; // arbitrary values
1277 audioOutput->SoundDevice().GetPlayBalanceL(left, right);
1278 CalculateBalance( aBalance, left, right );
1280 //[ assert the invariant ]
1281 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1290 * follows a simple straight line transformation
1292 * m = (KMMFBalanceMaxLeft-KMMFBalanceMaxRight)/ 100
1293 * c = KMMFBalanceMaxRight
1296 * KMMFBalanceMaxRight = m * 0 + c
1297 * c = KMMFBalanceMaxRight
1299 * KMMFBalanceMaxLeft = m * 100 + KMMFBalanceMaxRight
1300 * m = ( KMMFBalanceMaxLeft - KMMFBalanceMaxRight ) /100
1302 void CMMFTestUseOldCodecAudioController::CalculateBalance( TInt& aBalance, TInt aLeft, TInt aRight ) const
1304 //[ assert pre conditions ]
1305 __ASSERT_ALWAYS( (( 0 <= aLeft) && ( 100 >= aLeft)), Panic( EBadArgument) );
1306 __ASSERT_ALWAYS( (( 0 <= aRight) && ( 100 >= aRight)), Panic( EBadArgument) );
1308 if ((aLeft > 0) && (aRight > 0))
1310 __ASSERT_ALWAYS( (( aLeft + aRight ) == 100 ), Panic( EBadArgument ));
1311 aBalance = (aLeft * (KMMFBalanceMaxLeft-KMMFBalanceMaxRight))/100 + KMMFBalanceMaxRight;
1313 else if ((aLeft == 0) && (aRight == 0))
1317 else if ((aLeft == 0) && (aRight > 0))
1321 else if ((aLeft > 0) && (aRight == 0))
1326 //[ assert post condition that aBalance is within limits ]
1327 __ASSERT_ALWAYS( !(aBalance < KMMFBalanceMaxLeft || aBalance > KMMFBalanceMaxRight), Panic(EBadArgument));
1336 void CMMFTestUseOldCodecAudioController::MardSetGainL(TInt aGain)
1338 // [ assert the invariant ]
1339 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1341 //[ precondition we are in the state stopped ]
1342 if(State() != EStopped)
1343 User::Leave(KErrNotReady);
1345 // [ assert the precondition that we have a data sink ]
1347 User::Leave(KErrNotSupported);
1349 //[ assert the precondition that the data sink is an audio input ]
1350 if (iDataSource->DataSourceType() != KUidMmfAudioInput)
1351 User::Leave(KErrNotReady);
1353 // Set gain of sound device
1354 MMMFAudioInput* audioInput = STATIC_CAST(MMMFAudioInput*, iDataSource);
1355 audioInput->SoundDevice().SetGain(aGain);
1357 //[ assert the invariant ]
1358 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1367 void CMMFTestUseOldCodecAudioController::MardGetMaxGainL(TInt& aMaxGain)
1369 // [ assert the invariant ]
1370 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1372 // [ assert the precondition that we have a source ]
1374 User::Leave(KErrNotReady);
1376 //[ assert the precondition that iDataSink is an Audio Input]
1377 if (iDataSource->DataSourceType() != KUidMmfAudioInput)
1378 User::Leave(KErrNotSupported);
1380 MMMFAudioInput* audioInput = STATIC_CAST(MMMFAudioInput*, iDataSource);
1381 aMaxGain = audioInput->SoundDevice().MaxGain();
1383 //[ assert the invariant ]
1384 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1393 void CMMFTestUseOldCodecAudioController::MardGetGainL(TInt& aGain)
1395 //[ assert the invariant ]
1396 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1398 // [ assert the precondition that we have a sink ]
1400 User::Leave(KErrNotReady);
1402 // [ assert the precondition that we have an audio input sink]
1403 if (iDataSource->DataSourceType() != KUidMmfAudioInput)
1404 User::Leave(KErrNotSupported);
1406 MMMFAudioInput* audioInput = STATIC_CAST(MMMFAudioInput*, iDataSource);
1407 aGain = audioInput->SoundDevice().Gain();
1409 //[ assert the invariant ]
1410 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1419 void CMMFTestUseOldCodecAudioController::MardSetBalanceL(TInt aBalance)
1421 // [ assert the invaraiant ]
1422 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1424 // [ precondition is that we have a data sink ]
1426 User::Leave(KErrNotReady);
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);
1433 // [ precondition is that the data sink is an audio output]
1434 if (iDataSource->DataSourceType() != KUidMmfAudioInput)
1435 User::Leave(KErrNotSupported);
1438 //[ get the audio output ]
1439 MMMFAudioInput* audioInput = STATIC_CAST(MMMFAudioInput*, iDataSource);
1441 // [ separate out left and right balance ]
1444 CalculateLeftRightBalance( left, right, aBalance );
1446 //[ set the balance ]
1447 audioInput->SoundDevice().SetRecordBalanceL(left, right);
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);
1454 //[ assert post condition holds]
1455 TBool postCondition = (( rightBalance == right) && ( leftBalance == left));
1456 __ASSERT_ALWAYS( postCondition, Panic( EPostConditionViolation ) );
1458 //[ assert the invariant ]
1459 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
1469 void CMMFTestUseOldCodecAudioController::MardGetBalanceL(TInt& aBalance)
1471 //[ assert the invariant ]
1472 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1474 //[ precondition that we have a sink]
1476 User::Leave(KErrNotReady);
1478 // [ iDataSink is an Audio Output ]
1479 if (iDataSource->DataSourceType() != KUidMmfAudioInput)
1480 User::Leave(KErrNotSupported);
1482 // [ get the play balance ]
1483 MMMFAudioInput* audioInput = STATIC_CAST(MMMFAudioInput*, iDataSource);
1484 TInt left = 50; // arbitrary values
1486 audioInput->SoundDevice().GetRecordBalanceL(left, right);
1487 CalculateBalance( aBalance, left, right );
1489 //[ assert the invariant ]
1490 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1495 * MapcSetPlaybackWindowL
1500 void CMMFTestUseOldCodecAudioController::MapcSetPlaybackWindowL(const TTimeIntervalMicroSeconds& aStart, const TTimeIntervalMicroSeconds& aEnd)
1502 iDataPath->SetPlayWindowL(aStart, aEnd);
1506 * MapcDeletePlaybackWindowL
1508 void CMMFTestUseOldCodecAudioController::MapcDeletePlaybackWindowL()
1510 iDataPath->ClearPlayWindowL();
1514 * MapcGetLoadingProgressL
1516 void CMMFTestUseOldCodecAudioController::MapcGetLoadingProgressL(TInt& /*aPercentageComplete*/)
1518 User::Leave(KErrNotSupported);
1523 * MarcGetRecordTimeAvailableL
1527 void CMMFTestUseOldCodecAudioController::MarcGetRecordTimeAvailableL(TTimeIntervalMicroSeconds& aTime)
1529 //[ assert the invariant ]
1530 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1532 //[ assert the precondition ( in a friendly way for this api
1533 // that we minimally have a data sink ]
1535 User::Leave( KErrNotReady );
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) ;
1542 // [ max file size ]
1543 //[ pre condition is that we have a sink ]
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
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 )
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) );
1566 bytesPerSecond = STATIC_CAST(CMMFFormatEncode*, iSinkFormat)->BytesPerSecond() ;
1569 //[ now lets perform the calculation of time available ]
1570 if ( bytesPerSecond != TInt64(0) )
1572 aTime = TTimeIntervalMicroSeconds( bytesFree * KOneSecondInMicroSeconds / bytesPerSecond ) ;
1575 //[ assert the invariant ]
1576 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1580 * MarcSetMaxDurationL
1581 * @param aMaxDuration
1583 void CMMFTestUseOldCodecAudioController::MarcSetMaxDurationL(const TTimeIntervalMicroSeconds& )
1585 //[ this method is deprecated and no longer supported ]
1586 User::Leave(KErrNotSupported);
1590 * MarcSetMaxFileSizeL
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
1597 void CMMFTestUseOldCodecAudioController::MarcSetMaxFileSizeL(TInt aFileSize )
1599 //[ assert the invariant ]
1600 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1602 //[ assert the state is not playing since this opens open
1603 // nefarious posibilities
1604 if(State() == EPlaying )
1605 User::Leave( KErrNotReady );
1607 //[ assert we have a sink format ]
1609 User::Leave( KErrNotReady );
1611 //[ assert file size > -1, as a basic sanity filter
1612 // 0 is the sentinel value which allows a file to grow
1615 User::Leave( KErrArgument );
1617 //[ pre condition is that we have a sink ]
1618 STATIC_CAST(CMMFFormatEncode*, iSinkFormat)->SetMaximumClipSizeL( aFileSize );
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]
1624 //[ assert the invariant ]
1625 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1632 void CMMFTestUseOldCodecAudioController::MarcCropL(TBool aToEnd)
1634 //[ assert the invariant ]
1635 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1637 //[ precondition there is a sink format]
1639 User::Leave(KErrNotSupported);
1641 iSinkFormat->CropL( PositionL(), aToEnd );
1643 //[ assert the invariant ]
1644 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1648 * MarcAddMetaDataEntryL
1651 void CMMFTestUseOldCodecAudioController::MarcAddMetaDataEntryL(const CMMFMetaDataEntry& aNewEntry )
1653 //[ assert the invariant ]
1654 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1656 //[ precondition the format exists ]
1658 User::Leave(KErrNotSupported);
1660 //[ Add the meta data entry ]
1661 iSinkFormat->AddMetaDataEntryL( aNewEntry );
1663 //[ assert the invariant ]
1664 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1669 * MarcRemoveMetaDataEntryL
1672 void CMMFTestUseOldCodecAudioController::MarcRemoveMetaDataEntryL(TInt aIndex)
1674 //[ assert the invariant ]
1675 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1677 //[ precondition that we are in the primed state ]
1678 if( State() != EPrimed)
1679 User::Leave(KErrNotReady);
1681 //[ precondition the format exists ]
1683 User::Leave(KErrNotSupported);
1685 //[ remove the meta data entry ]
1686 iSinkFormat->RemoveMetaDataEntry( aIndex );
1688 //[ assert the invariant ]
1689 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1694 * MarcReplaceMetaDataEntryL
1698 void CMMFTestUseOldCodecAudioController::MarcReplaceMetaDataEntryL(TInt aIndex, const CMMFMetaDataEntry& aNewEntry)
1700 //[ assert the invariant ]
1701 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1703 //[ precondition that we are in the primed state ]
1704 if( State() != EPrimed)
1705 User::Leave(KErrNotReady);
1707 //[ precondition the format exists ]
1709 User::Leave(KErrNotSupported);
1711 //[ replace meta data entry ]
1712 iSinkFormat->ReplaceMetaDataEntryL( aIndex, aNewEntry );
1714 //[ assert the invariant ]
1715 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1720 * MacSetSourceSampleRateL
1721 * @param aSampleRate
1723 void CMMFTestUseOldCodecAudioController::MacSetSourceSampleRateL(TUint aSampleRate)
1725 // [ assert the invariant ]
1726 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
1728 // [ assert the precondition we are stopped ]
1729 if( State() != EStopped )
1730 User::Leave(KErrNotReady);
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)
1740 else if (iDataSource && (iDataSource->DataSourceType()==KUidMmfAudioInput))
1742 // cast iDataSource to audio input and set sample rate
1743 MMMFAudioInput* ai = STATIC_CAST(MMMFAudioInput*, iDataSource);
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();
1749 ConvertFromSampleRateToDevSoundCapsL(aSampleRate, devSoundConfig);
1750 ai->SoundDevice().SetConfigL(devSoundConfig);
1754 User::Leave(KErrNotSupported);
1756 // [assert the post condition ]
1757 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
1762 * MacSetSourceNumChannelsL
1763 * @param aNumChannels
1765 void CMMFTestUseOldCodecAudioController::MacSetSourceNumChannelsL(TUint aNumChannels)
1767 // [ assert the invariant ]
1768 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
1770 // [assert the precondition that we are stopped ]
1771 if( State() != EStopped )
1772 User::Leave(KErrNotReady);
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)
1781 else if (iDataSource && (iDataSource->DataSourceType()==KUidMmfAudioInput))
1783 // cast iDataSource to audio input and set num channels
1784 MMMFAudioInput* ai = STATIC_CAST(MMMFAudioInput*, iDataSource);
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();
1790 ConvertFromNumChannelsToDevSoundCapsL(aNumChannels, devSoundConfig);
1791 ai->SoundDevice().SetConfigL(devSoundConfig);
1795 User::Leave(KErrNotSupported);
1797 // [ assert the invariant ]
1798 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
1803 * MacSetSourceFormatL
1807 void CMMFTestUseOldCodecAudioController::MacSetSourceFormatL(TUid aFormatUid)
1809 //[ assert the invaraint ]
1810 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
1812 // [ precondition that the controller is stopped ]
1813 if( State() != EStopped )
1814 User::Leave( KErrNotReady );
1816 //[ precondition that the data source exists]
1818 User::Leave(KErrNotReady);
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
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)))
1829 // [ delete the old format regardless ]
1830 delete iSourceFormat;
1831 iSourceFormat = NULL;
1832 iSourceFormat = CMMFFormatDecode::NewL(aFormatUid, iDataSource);
1835 //[ assert the invariant ]
1836 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
1838 //[ assert the post condition that a source format has been constructed ]
1839 __ASSERT_ALWAYS( (iSourceFormat != NULL), Panic( EPostConditionViolation ));
1843 * MacSetSinkSampleRateL
1844 * @param aSampleRate
1846 void CMMFTestUseOldCodecAudioController::MacSetSinkSampleRateL(TUint aSampleRate)
1848 //[ assert the invariant ]
1849 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
1851 // [ assert the precondition that we are stopped ]
1852 if (State() != EStopped )
1853 User::Leave(KErrNotReady);
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)
1862 else if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput))
1864 // cast iDataSink to audio output and set sample rate
1865 MMMFAudioOutput* ao = STATIC_CAST(MMMFAudioOutput*, iDataSink);
1869 TMMFCapabilities devSoundConfig = ao->SoundDevice().Config();
1870 ConvertFromSampleRateToDevSoundCapsL(aSampleRate, devSoundConfig);
1871 ao->SoundDevice().SetConfigL(devSoundConfig);
1874 User::Leave(KErrNotSupported);
1876 //[ assert the invariant ]
1877 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
1881 * MacSetSinkNumChannelsL
1882 * @param aNumChannels
1885 void CMMFTestUseOldCodecAudioController::MacSetSinkNumChannelsL(TUint aNumChannels)
1887 //[ assert the invariant ]
1888 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
1890 // [ assert the precondition that we are stopped ]
1891 if (State() != EStopped )
1892 User::Leave(KErrNotReady);
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)
1901 else if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput))
1903 // cast iDataSink to audio output and set num channels
1904 MMMFAudioOutput* ao = STATIC_CAST(MMMFAudioOutput*, iDataSink);
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);
1913 User::Leave(KErrNotSupported);
1915 // [assert the invariant ]
1916 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
1925 void CMMFTestUseOldCodecAudioController::MacSetSinkFormatL(TUid aFormatUid)
1927 //[ assert the invariant ]
1928 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
1930 // [ precondition that the controller is stopped ]
1931 if( State() != EStopped )
1932 User::Leave( KErrNotReady );
1934 //[ precondition that the data sink exists]
1936 User::Leave(KErrNotReady);
1938 //[ precondition that we need a format ]
1939 if (!SinkFormatRequired( *iDataSink))
1940 User::Leave(KErrNotSupported);
1942 //[ if the format exists and the uid of the requested
1943 // format is the same as the existing format then simply
1945 if( !((iSinkFormat) && ( iSinkFormat->ImplementationUid() == aFormatUid)))
1947 // [ delete the old format regardless ]
1950 iSinkFormat = CMMFFormatEncode::NewL(aFormatUid, iDataSink);
1953 //[ assert the invariant ]
1954 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
1956 //[ assert the post condition that a sink format has been constructed ]
1957 __ASSERT_ALWAYS( (iSinkFormat != NULL), Panic( EPostConditionViolation ));
1963 * @param aSourceDataType
1964 * @param aSinkDataType
1967 void CMMFTestUseOldCodecAudioController::MacSetCodecL(TFourCC aSourceDataType, TFourCC aSinkDataType)
1969 //[ assert the invariant ]
1970 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
1972 //[ assert the precondition ]
1973 if(State() != EStopped)
1974 User::Leave(KErrNotReady);
1976 //don't set codec directly -just set source & sink fourCC codes
1978 TInt error(KErrNone);
1979 if ((iSinkFormat)&&(aSinkDataType != KMMFFourCCCodeNULL))
1981 error = iSinkFormat->SetSinkDataTypeCode(aSinkDataType,iMediaId);
1983 else if((iDataSink) && (aSinkDataType != KMMFFourCCCodeNULL))
1985 error = iDataSink->SetSinkDataTypeCode(aSinkDataType,iMediaId);
1987 if ((iSourceFormat)&&(!error)&&(aSourceDataType != KMMFFourCCCodeNULL))
1989 error = iSourceFormat->SetSourceDataTypeCode(aSourceDataType,iMediaId);
1991 else if ((iDataSource) && (aSourceDataType != KMMFFourCCCodeNULL))
1993 error = iDataSource->SetSourceDataTypeCode(aSourceDataType,iMediaId);
1996 //[ leave if we are not ready or there was an error ]
1997 User::LeaveIfError(error);
1999 //[ assert the invariant ]
2000 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
2004 * MacSetSourceBitRateL
2006 * Sets the source bit rate
2009 void CMMFTestUseOldCodecAudioController::MacSetSourceBitRateL(TUint aBitRate)
2011 //[ assert the invariant ]
2012 __ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
2014 //[ assert the precondition ]
2015 if(State() != EStopped)
2016 User::Leave(KErrNotReady);
2018 //[ pre condition that we have a source format]
2020 User::Leave(KErrNotSupported);
2022 //only applicable to formats
2023 User::LeaveIfError(iSourceFormat->SetBitRate(aBitRate));
2025 //[ assert the set bit rate is the bit rate ]
2026 __ASSERT_ALWAYS( (aBitRate == iSourceFormat->BitRate()), Panic( EPostConditionViolation ));
2028 //[ assert the invariant ]
2029 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
2035 * MacSetSourceDataTypeL
2039 void CMMFTestUseOldCodecAudioController::MacSetSourceDataTypeL(TFourCC aDataType)
2041 MacSetCodecL(aDataType, KMMFFourCCCodeNULL);
2046 * MacSetSinkBitRateL
2050 void CMMFTestUseOldCodecAudioController::MacSetSinkBitRateL(TUint aRate)
2052 //[ assert the invariant ]
2053 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
2055 // [ assert we are stopped ]
2056 if( State() != EStopped)
2057 User::Leave( KErrNotReady );
2059 //[ pre condition we have a sink format ]
2061 User::Leave(KErrNotSupported);
2063 //only applicable to formats
2064 User::LeaveIfError(iSinkFormat->SetBitRate(aRate));
2066 //[ assert the set bit rate is the bit rate ]
2067 __ASSERT_ALWAYS( (aRate == iSinkFormat->BitRate()), Panic( EBadInvariant));
2069 //[ assert the invariant ]
2070 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
2075 * MacSetSinkDataTypeL
2079 void CMMFTestUseOldCodecAudioController::MacSetSinkDataTypeL(TFourCC aDataType)
2081 MacSetCodecL(KMMFFourCCCodeNULL, aDataType);
2083 if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput))
2085 MMMFAudioOutput* ao = STATIC_CAST(MMMFAudioOutput*, iDataSink);
2086 TMMFCapabilities devSoundConfig = ao->SoundDevice().Config();
2087 RArray<TFourCC> dataTypes;
2088 CleanupClosePushL(dataTypes);
2090 //[ set dev sound data type here ]
2091 ConvertFromDataTypeToDevSoundCapsL(aDataType, devSoundConfig);
2092 ao->SoundDevice().SetConfigL(devSoundConfig);
2093 CleanupStack::PopAndDestroy();//dataTypes
2099 * MacGetSourceSampleRateL
2103 void CMMFTestUseOldCodecAudioController::MacGetSourceSampleRateL(TUint& aRate)
2105 //[ assert the invariant ]
2106 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
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)) ||
2112 User::Leave(KErrNotSupported);
2116 aRate = iSourceFormat->SampleRate();
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
2128 CleanupStack::PopAndDestroy();//rates
2131 //[ assert the invariant ]
2132 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
2137 * MacGetSourceBitRateL
2141 void CMMFTestUseOldCodecAudioController::MacGetSourceBitRateL(TUint& aRate)
2143 //[ assert the invariant ]
2144 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
2146 // Can only query formats for bit rate - devsound doesn't do bit rates.
2148 User::Leave(KErrNotSupported);
2150 aRate = iSourceFormat->BitRate();
2152 //[ assert the invariant ]
2153 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
2159 * MacGetSourceNumChannelsL
2163 void CMMFTestUseOldCodecAudioController::MacGetSourceNumChannelsL(TUint& aNumChannels)
2165 //[ assert the invariant ]
2166 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
2168 //[ assert the precondition ]
2169 if( !((iSourceFormat) ||
2170 (iDataSource && (iDataSource->DataSourceType()==KUidMmfAudioInput))))
2171 User::Leave(KErrNotSupported);
2175 aNumChannels = iSourceFormat->NumChannels();
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
2190 //[ assert the invariant ]
2191 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
2197 * MacGetSourceFormatL
2200 void CMMFTestUseOldCodecAudioController::MacGetSourceFormatL(TUid& aFormat)
2202 //[ assert the invariant ]
2203 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
2205 //[ precondition we have a format ]
2207 User::Leave(KErrNotSupported);
2209 // [ get the source format uid ]
2210 aFormat = iSourceFormat->ImplementationUid();
2212 //[ assert the invariant ]
2213 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
2219 * MacGetSourceDataTypeL
2223 void CMMFTestUseOldCodecAudioController::MacGetSourceDataTypeL(TFourCC& aDataType)
2226 aDataType = iSourceFormat->SourceDataTypeCode(TMediaId(KUidMediaTypeAudio));
2227 else if (iDataSource && (iDataSource->DataSourceType()==KUidMmfAudioInput))
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
2240 User::Leave(KErrNotSupported);
2245 * MacGetSinkSampleRateL
2250 void CMMFTestUseOldCodecAudioController::MacGetSinkSampleRateL(TUint& aRate)
2253 aRate = iSinkFormat->SampleRate();
2254 else if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput))
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
2264 CleanupStack::PopAndDestroy();//rates
2267 User::Leave(KErrNotSupported);
2272 * MacGetSinkBitRateL
2276 void CMMFTestUseOldCodecAudioController::MacGetSinkBitRateL(TUint& aRate)
2279 aRate = iSinkFormat->BitRate();
2281 User::Leave(KErrNotSupported);
2286 * MacGetSinkNumChannelsL
2290 void CMMFTestUseOldCodecAudioController::MacGetSinkNumChannelsL(TUint& aNumChannels)
2293 aNumChannels = iSinkFormat->NumChannels();
2294 else if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput))
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
2307 User::Leave(KErrNotSupported);
2316 void CMMFTestUseOldCodecAudioController::MacGetSinkFormatL(TUid& aFormat)
2319 aFormat = iSinkFormat->ImplementationUid();
2321 User::Leave(KErrNotSupported);
2326 * MacGetSinkDataTypeL
2330 void CMMFTestUseOldCodecAudioController::MacGetSinkDataTypeL(TFourCC& aDataType)
2333 aDataType = iSinkFormat->SinkDataTypeCode(TMediaId(KUidMediaTypeAudio));
2334 else if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput))
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
2347 User::Leave(KErrNotSupported);
2352 * MacGetSupportedSourceSampleRatesL
2353 * @param "RArray<TUint>&"
2356 void CMMFTestUseOldCodecAudioController::MacGetSupportedSourceSampleRatesL(RArray<TUint>& aSupportedRates)
2358 aSupportedRates.Reset();
2360 iSourceFormat->GetSupportedSampleRatesL(aSupportedRates);
2361 else if (iDataSource && (iDataSource->DataSourceType()==KUidMmfAudioInput))
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);
2369 User::Leave(KErrNotSupported);
2374 * MacGetSupportedSourceBitRatesL
2375 * @param "RArray<TUint>&"
2378 void CMMFTestUseOldCodecAudioController::MacGetSupportedSourceBitRatesL(RArray<TUint>& aSupportedRates)
2380 aSupportedRates.Reset();
2382 iSourceFormat->GetSupportedBitRatesL(aSupportedRates);
2384 User::Leave(KErrNotSupported);
2389 * MacGetSupportedSourceNumChannelsL
2390 * @param "RArray<TUint>&"
2393 void CMMFTestUseOldCodecAudioController::MacGetSupportedSourceNumChannelsL(RArray<TUint>& aSupportedChannels)
2395 aSupportedChannels.Reset();
2397 iSourceFormat->GetSupportedNumChannelsL(aSupportedChannels);
2398 else if (iDataSource && (iDataSource->DataSourceType()==KUidMmfAudioInput))
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);
2406 User::Leave(KErrNotSupported);
2411 * MacGetSupportedSourceDataTypesL
2412 * @param "RArray<TFourCC>&"
2415 void CMMFTestUseOldCodecAudioController::MacGetSupportedSourceDataTypesL(RArray<TFourCC>& aSupportedDataTypes)
2417 aSupportedDataTypes.Reset();
2419 iSourceFormat->GetSupportedDataTypesL(TMediaId(KUidMediaTypeAudio), aSupportedDataTypes);
2420 else if (iDataSource && (iDataSource->DataSourceType()==KUidMmfAudioInput))
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);
2428 User::Leave(KErrNotSupported);
2433 * MacGetSupportedSinkSampleRatesL
2434 * @param "RArray<TUint>& "
2437 void CMMFTestUseOldCodecAudioController::MacGetSupportedSinkSampleRatesL(RArray<TUint>& aSupportedRates)
2439 aSupportedRates.Reset();
2441 iSinkFormat->GetSupportedSampleRatesL(aSupportedRates);
2442 else if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput))
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);
2450 User::Leave(KErrNotSupported);
2455 * MacGetSupportedSinkBitRatesL
2456 * @param RArray<TUint>&
2459 void CMMFTestUseOldCodecAudioController::MacGetSupportedSinkBitRatesL(RArray<TUint>& aSupportedRates)
2462 iSinkFormat->GetSupportedBitRatesL(aSupportedRates);
2464 User::Leave(KErrNotSupported);
2469 * MacGetSupportedSinkNumChannelsL
2470 * @param RArray<TUint>&
2473 void CMMFTestUseOldCodecAudioController::MacGetSupportedSinkNumChannelsL(RArray<TUint>& aSupportedChannels)
2475 aSupportedChannels.Reset();
2477 iSinkFormat->GetSupportedNumChannelsL(aSupportedChannels);
2478 else if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput))
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);
2486 User::Leave(KErrNotSupported);
2491 * MacGetSupportedSinkDataTypesL
2492 * @param "RArray<TFourCC>&"
2494 void CMMFTestUseOldCodecAudioController::MacGetSupportedSinkDataTypesL(RArray<TFourCC>& aSupportedDataTypes)
2496 aSupportedDataTypes.Reset();
2498 iSinkFormat->GetSupportedDataTypesL(TMediaId(KUidMediaTypeAudio), aSupportedDataTypes);
2499 else if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput))
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);
2507 User::Leave(KErrNotSupported);
2512 * ConvertFromDevSoundCapsToSampleRatesL
2513 * @param "const TMMFCapabilities& "
2514 * @param "RArray<TUint>&"
2517 void CMMFTestUseOldCodecAudioController::ConvertFromDevSoundCapsToSampleRatesL(const TMMFCapabilities& aDevSoundCaps, RArray<TUint>& aSampleRates)
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));
2541 * ConvertFromDevSoundCapsToNumChannelsL
2542 * @param "const TMMFCapabilities&"
2543 * @param "RArray<TUint>&"
2546 void CMMFTestUseOldCodecAudioController::ConvertFromDevSoundCapsToNumChannelsL(const TMMFCapabilities& aDevSoundCaps, RArray<TUint>& aNumChannels)
2548 if (aDevSoundCaps.iChannels & EMMFMono)
2549 User::LeaveIfError(aNumChannels.Append(KNumChannelsMono));
2550 if (aDevSoundCaps.iChannels & EMMFStereo)
2551 User::LeaveIfError(aNumChannels.Append(KNumChannelsStereo));
2556 * ConvertFromDevSoundCapsToDataTypesL
2557 * @param "const TMMFCapabilities&"
2558 * @param "TMMFCapabilities& aDevSoundCaps, RArray<TFourCC>&"
2561 void CMMFTestUseOldCodecAudioController::ConvertFromDevSoundCapsToDataTypesL(const TMMFCapabilities& aDevSoundCaps, RArray<TFourCC>& aDataTypes)
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));
2575 * ConvertFromSampleRateToDevSoundCapsL
2577 * @param "TMMFCapabilities&"
2580 void CMMFTestUseOldCodecAudioController::ConvertFromSampleRateToDevSoundCapsL(TUint aSampleRate, TMMFCapabilities& aDevSoundCaps)
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;
2601 User::Leave(KErrNotSupported);
2606 * ConvertFromNumChannelsToDevSoundCapsL
2608 * @param "TMMFCapabilities&"
2611 void CMMFTestUseOldCodecAudioController::ConvertFromNumChannelsToDevSoundCapsL(TUint aNumChannels, TMMFCapabilities& aDevSoundCaps)
2613 if (aNumChannels == KNumChannelsMono)
2614 aDevSoundCaps.iChannels = EMMFMono;
2615 else if (aNumChannels == KNumChannelsStereo)
2616 aDevSoundCaps.iChannels = EMMFStereo;
2618 User::Leave(KErrNotSupported);
2623 * ConvertFromDataTypeToDevSoundCapsL
2625 * @param "TMMFCapabilities&"
2628 void CMMFTestUseOldCodecAudioController::ConvertFromDataTypeToDevSoundCapsL(TFourCC aDataType, TMMFCapabilities& aDevSoundCaps)
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;
2639 User::Leave(KErrNotSupported);
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
2650 TBool CMMFTestUseOldCodecAudioController::IsValidStateTransition( TControllerState aState ) const
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 ));
2658 // [ check the valid state transitions ]
2659 // the only invalid transition is
2660 // stopped to playing
2661 if( ( iState == EStopped ) && ( aState == EPlaying ))
2666 //[ assert the invariant that iState is a valid State ]
2667 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant ));
2675 * This function returns whether the invariant is valid
2678 TBool CMMFTestUseOldCodecAudioController::Invariant() const
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);
2688 * This function sets the state of the controller.
2692 TBool CMMFTestUseOldCodecAudioController::SetState(TControllerState aState)
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 ) )
2702 //[ valid state transition set the state]
2707 //[ invalid state transition return EFalse ]
2710 // [ assert the invariant on the state ]
2711 __ASSERT_ALWAYS( Invariant(), Panic( EBadState ));
2718 * checks whether a state is a valid
2720 * @param TControllerState
2723 TBool CMMFTestUseOldCodecAudioController::IsValidState( TControllerState aState ) const
2725 TBool result = EFalse;
2726 if(( aState >= EStopped ) && ( aState <= EPlaying ))
2735 * The function State returns the current state of the audio controller
2736 * @returns "TControllerState"
2739 CMMFTestUseOldCodecAudioController::TControllerState CMMFTestUseOldCodecAudioController::State() const
2741 __ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant ) );
2747 * SinkFormatRequired
2750 TBool CMMFTestUseOldCodecAudioController::SinkFormatRequired( MDataSink& aDataSink ) const
2752 return (aDataSink.DataSinkType()==KUidMmfFileSink ||
2753 aDataSink.DataSinkType()==KUidMmfDescriptorSink);
2758 * SourceFormatRequired
2762 TBool CMMFTestUseOldCodecAudioController::SourceFormatRequired(MDataSource& aDataSource) const
2764 return (aDataSource.DataSourceType()==KUidMmfFileSource ||
2765 aDataSource.DataSourceType()==KUidMmfDescriptorSource);
2769 * DevSoundInitialised
2770 * Used in certain configurations to resume completion of PrimeL() when it is pending DevSound initialisation.
2773 void CMMFTestUseOldCodecAudioController::DevSoundInitialised(TInt /*aError*/)
2775 iWaitForAsyncService->AsyncStop();
2778 CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::TDevSoundEventHandler()
2779 : iInterceptedDevSoundObserver(NULL), iEventObserver(NULL)
2783 void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::SetInterceptedDevSoundObserver(MDevSoundObserver* aObserver)
2785 iInterceptedDevSoundObserver = aObserver;
2788 void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::SetEventObserver(CMMFTestUseOldCodecAudioController* aObserver)
2790 iEventObserver = aObserver;
2793 void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::InitializeComplete(TInt aError)
2795 iInterceptedDevSoundObserver->InitializeComplete(aError);
2796 iEventObserver->DevSoundInitialised(aError);
2799 void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::ToneFinished(TInt aError)
2801 iInterceptedDevSoundObserver->ToneFinished(aError);
2804 void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::BufferToBeFilled(CMMFBuffer* aBuffer)
2806 iInterceptedDevSoundObserver->BufferToBeFilled(aBuffer);
2809 void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::PlayError(TInt aError)
2811 iInterceptedDevSoundObserver->PlayError(aError);
2814 void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::BufferToBeEmptied(CMMFBuffer* aBuffer)
2816 iInterceptedDevSoundObserver->BufferToBeEmptied(aBuffer);
2819 void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::RecordError(TInt aError)
2821 iInterceptedDevSoundObserver->RecordError(aError);
2824 void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::ConvertError(TInt aError)
2826 iInterceptedDevSoundObserver->ConvertError(aError);
2829 void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::DeviceMessage(TUid aMessageType, const TDesC8& aMsg)
2831 iInterceptedDevSoundObserver->DeviceMessage(aMessageType, aMsg);