os/mm/mmlibs/mmfw/tsrc/mmfunittest/Actrl/TestPlugins/AudioController/CustomMmfAudioController.cpp
Update contrib.
1 // Copyright (c) 2002-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.
16 #include <mmf/server/mmffile.h>
17 #include "CustomMmfAudioController.h"
19 #include <mmf/plugin/mmfcontrollerimplementationuids.hrh>
20 #include "ActrlTestUids.h"
22 _LIT(KTestWavFile19, "c:\\mm\\mmf\\testfiles\\actrl\\newmail.wav");
29 CMMFController* CCustomMmfAudioController::NewL()
31 CCustomMmfAudioController* self = new(ELeave) CCustomMmfAudioController;
32 CleanupStack::PushL(self);
34 CleanupStack::Pop( self );
36 return STATIC_CAST( CMMFController*, self );
40 * ~CCustomMmfAudioController
43 CCustomMmfAudioController::~CCustomMmfAudioController()
45 delete iStoppingMessage;
50 * CCustomMmfAudioController
53 CCustomMmfAudioController::CCustomMmfAudioController()
54 :CMMFAudioController(), iIsTest(EFalse)
61 * If Prime fails the client should reset the controller
62 * becaused as noted below this code is not transactional.
65 void CCustomMmfAudioController::PrimeL(TMMFMessage& aMessage)
68 aMessage.Complete(KErrNone);
70 void CCustomMmfAudioController::PlayL(TMMFMessage& aMessage)
73 aMessage.Complete(KErrNone);
75 void CCustomMmfAudioController::PauseL(TMMFMessage& aMessage)
78 aMessage.Complete(KErrNone);
81 void CCustomMmfAudioController::PrimeL()
83 // apply heap check's here
84 // Note if they fail this is the end of the controller
86 // call the base class functionality
87 TRAPD( errorCode, CMMFAudioController::PrimeL());
88 // send an event back to the test framework with
90 TMMFEvent aEvent( KPrimeTestId, errorCode );
91 DoSendEventToClient(aEvent);
92 //[ we need to preserve the leave semantics for the caller]
93 User::LeaveIfError( errorCode );
101 void CCustomMmfAudioController::PlayL()
103 // call the base class functionality
104 TRAPD( errorCode, CMMFAudioController::PlayL());
105 // send an event back to the test framework with
107 TMMFEvent aEvent( KPlayTestId, errorCode );
108 DoSendEventToClient(aEvent);
109 //[ we need to preserve the leave semantics for the caller]
110 User::LeaveIfError( errorCode );
118 void CCustomMmfAudioController::MapdSetVolumeL(TInt aVolume)
120 //Special return code to test fix for PDEF120609, test case id MM-MMF-ACLNT-U-0277-CP
125 CMMFAudioController::MapdSetVolumeL( aVolume );
133 void CCustomMmfAudioController::MapdGetMaxVolumeL(TInt& aMaxVolume)
135 CMMFAudioController::MapdGetMaxVolumeL( aMaxVolume );
142 void CCustomMmfAudioController::MapdGetVolumeL(TInt& aVolume)
144 CMMFAudioController::MapdGetVolumeL( aVolume );
152 void CCustomMmfAudioController::PauseL()
154 TRAPD( errorCode,CMMFAudioController::PauseL());
155 //[ send pause event ]
156 TMMFEvent aEvent( KPauseTestId, errorCode );
157 DoSendEventToClient(aEvent);
158 //[ we need to preserve the leave semantics for the caller]
159 User::LeaveIfError( errorCode );
167 void CCustomMmfAudioController::StopL()
169 TRAPD( errorCode,CMMFAudioController::StopL());
170 //[ send stop event ]
171 TMMFEvent aEvent( KStopTestId, errorCode );
172 DoSendEventToClient(aEvent);
173 //[ we need to preserve the leave semantics for the caller]
174 User::LeaveIfError( errorCode );
182 void CCustomMmfAudioController::ResetL()
184 TRAPD( errorCode,CMMFAudioController::ResetL());
185 //[ send stop event ]
186 TMMFEvent aEvent( KResetTestId, errorCode );
187 DoSendEventToClient(aEvent);
188 //[ we need to preserve the leave semantics for the caller]
189 User::LeaveIfError( errorCode );
197 void CCustomMmfAudioController::RemoveDataSourceL(MDataSource& aDataSource)
199 TRAPD( errorCode,CMMFAudioController::RemoveDataSourceL( aDataSource));
200 //[ send stop event ]
201 TMMFEvent aEvent( KRemoveDataSourceTestId, errorCode );
202 DoSendEventToClient(aEvent);
203 //[ we need to preserve the leave semantics for the caller]
204 User::LeaveIfError( errorCode );
212 void CCustomMmfAudioController::RemoveDataSinkL(MDataSink& aDataSink)
214 TRAPD( errorCode,CMMFAudioController::RemoveDataSinkL( aDataSink));
215 //[ send stop event ]
216 TMMFEvent aEvent( KRemoveDataSinkTestId, errorCode );
217 DoSendEventToClient(aEvent);
218 //[ we need to preserve the leave semantics for the caller]
219 User::LeaveIfError( errorCode );
224 * MarcSetMaxFileSizeL
228 void CCustomMmfAudioController::MarcSetMaxFileSizeL(TInt aFileSize)
230 TRAPD( errorCode,CMMFAudioController::MarcSetMaxFileSizeL( aFileSize));
231 //[ send stop event ]
232 TMMFEvent aEvent( KMarcSetMaxFileSizeId, errorCode );
233 DoSendEventToClient(aEvent);
234 //[ we need to preserve the leave semantics for the caller]
235 User::LeaveIfError( errorCode );
240 * MarcGetRecordTimeAvailableL
244 void CCustomMmfAudioController::MarcGetRecordTimeAvailableL(TTimeIntervalMicroSeconds& aTime)
246 TRAPD( errorCode,CMMFAudioController::MarcGetRecordTimeAvailableL( aTime));
247 //[ send stop event ]
248 TMMFEvent aEvent( KMarcGetRecordTimeAvailId, errorCode );
249 DoSendEventToClient(aEvent);
250 //[ we need to preserve the leave semantics for the caller]
251 User::LeaveIfError( errorCode );
260 void CCustomMmfAudioController::CustomCommand(TMMFMessage& aMessage)
262 //[ check if the command is for the custom plugin
263 // otherwise pass it on to the real audio controller ]
264 TRAPD(err, iStoppingMessage = CCustomMMFMessageHolder::NewL(aMessage));
267 aMessage.Complete(err);
272 if( IsMemoryAllocCmd( aMessage ) )
274 //[ it is a alloc memory test command ]
275 // [ new algorithm adopted from M&G database ]
277 TInt errorCode = KErrNone;
279 TBool completed = EFalse;
280 TBool badResult = EFalse;
281 TBool reachedEnd = EFalse;
285 __UHEAP_SETFAIL(RHeap::EFailNext ,failCount); // Leavescan will think __UHEAP_SETFAIL is a leaving function due to the macro ending in 'L'. Does not leave
287 //NB: Do not use __MM_HEAP_MARK macro's in this test, the cleaning up the CustomMMFAudioController
288 //is insufficient to remove all possible allocated memory from the framework.
289 //CMMFControllerProxyServer::DoStartThreadL has been updated to do heap checking for
290 //the whole server thread.
292 //[ run a scenario of the major api
293 //functions which alloc memory in the controller]
294 TRAP( errorCode, AllocMemoryTestL());
296 if( errorCode == KErrNone )
298 // [ check we have passed through all allocs in the test]
299 TAny* testAlloc = User::Alloc(1);
300 if( testAlloc == NULL )
303 failCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc.
307 User::Free( testAlloc );
310 completed = reachedEnd || badResult;
313 else if( errorCode != KErrNoMemory )
315 // [ we failed for some reason other than memory
316 // allocation, so fail the test ]
321 __UHEAP_SETFAIL(RHeap::ENone ,0);
332 //This flag is used by the audio controller to alter its behaviour
333 //slightly to allow these tests to work
338 aMessage.Complete(KErrNone);
342 aMessage.Complete(errorCode);
347 //[ let the plugin process the message ]
348 CMMFAudioController::CustomCommand(aMessage);
357 TBool CCustomMmfAudioController::IsMemoryAllocCmd( TMMFMessage& )
363 static void CleanupController(TAny* ptr)
365 CMMFAudioController* controller = STATIC_CAST(CMMFAudioController*, ptr);
366 TRAP_IGNORE(controller->CMMFAudioController::ResetL());
375 TInt CCustomMmfAudioController::AllocMemoryTestL()
377 TMMFFileConfig fileConfig; // audio file
379 fileConfig().iPath = KTestWavFile19;
381 //[ lets manufacture a source and sink ]
383 //[Create the source]
384 MDataSource* source = MDataSource::NewSourceL(KUidMmfFileSource, fileConfig);
385 CleanupDeletePushL(source);
387 //[ Create the sink ]
388 MDataSink* sink = MDataSink::NewSinkL(KUidMmfAudioOutput, KNullDesC8);
389 CleanupDeletePushL(sink);
391 // Use a cleanup item to stop & reset the controller and so remove the data
392 // sources/sinks automatically when this funtion leaves. This can be done
393 // before the sinks/sources are added.
394 TCleanupItem cleanupItem(CleanupController, this);
395 CleanupStack::PushL(cleanupItem);
399 CMMFAudioController::AddDataSourceL(*source);
402 CMMFAudioController::AddDataSinkL(*sink);
405 CMMFAudioController::PrimeL();
408 CMMFAudioController::PlayL();
411 CMMFAudioController::PauseL();
414 CMMFAudioController::PlayL();
417 CMMFAudioController::StopL(iStoppingMessage->iMessage);
420 CMMFAudioController::PrimeL();
423 CMMFAudioController::ResetL();
425 CleanupStack::PopAndDestroy(3);// source, sink, cleanupItem
430 //Leaves with KErrNoMemory.
431 CMMFController* CMemoryFailAudioController::NewL()
433 if(ETrue) //condition used to avoid any warning
435 User::Leave(KErrNoMemory);
439 CMemoryFailAudioController::CMemoryFailAudioController():CMMFAudioController()
442 CMemoryFailAudioController::~CMemoryFailAudioController()
446 iSink->SinkThreadLogoff();
450 iClip->SourceThreadLogoff();
454 void CMemoryFailAudioController::AddDataSourceL(MDataSource& aSource)
458 User::Leave(KErrAlreadyExists);
460 if ((aSource.DataSourceType()==KUidMmfDescriptorSource)||
461 (aSource.DataSourceType()==KUidMmfFileSource))
463 User::LeaveIfError(aSource.SourceThreadLogon(*this));
464 iClip = static_cast<CMMFClip*>(&aSource);
467 iClip->SourcePrimeL();
471 iClip->SourceStopL();
476 User::Leave(KErrNotSupported);
480 void CMemoryFailAudioController::AddDataSinkL(MDataSink& aSink)
484 User::Leave(KErrAlreadyExists);
486 if (aSink.DataSinkType()!=KUidMmfAudioOutput)
488 User::Leave(KErrNotSupported);
490 User::LeaveIfError(aSink.SinkThreadLogon(*this));
492 MMMFAudioOutput* audioOutput = static_cast<MMMFAudioOutput*>(&aSink);
493 iMMFDevSound = &(audioOutput->SoundDevice());
494 iMMFDevSound->SetPrioritySettings(iPrioritySettings);
498 void CMemoryFailAudioController::SetPrioritySettings(const TMMFPrioritySettings& aSettings)
500 iPrioritySettings = aSettings;
503 iMMFDevSound->SetPrioritySettings(aSettings);
507 //Does not acces files; returns hard-coded value.
508 TTimeIntervalMicroSeconds CMemoryFailAudioController::DurationL()const
510 return TTimeIntervalMicroSeconds(1000000); //return 1sec
513 CMMFController* CMemoryPassAudioController::NewL()
515 CMemoryPassAudioController* self = new (ELeave) CMemoryPassAudioController();
516 return STATIC_CAST( CMMFController*, self );
518 CMemoryPassAudioController::CMemoryPassAudioController():CMemoryFailAudioController()
522 //Derived from Audio Controller. Panics the controller thread after the play is started
523 CMMFController* CPanicAudioController::NewL()
525 CPanicAudioController* self = new(ELeave) CPanicAudioController;
526 CleanupStack::PushL(self);
528 CleanupStack::Pop( self );
529 return static_cast<CMMFController*>(self);
532 CPanicAudioController::CPanicAudioController():CMMFAudioController()
536 CPanicAudioController::~CPanicAudioController()
541 void CPanicAudioController::AddDataSourceL(MDataSource& aSource)
543 TRAP_IGNORE(CMMFAudioController::AddDataSourceL(aSource));
546 void CPanicAudioController::AddDataSinkL(MDataSink& aSink)
548 TRAP_IGNORE(CMMFAudioController::AddDataSinkL(aSink));
551 void CPanicAudioController::PrimeL()
553 TRAP_IGNORE(CMMFAudioController::PrimeL());
556 void CPanicAudioController::PlayL()
558 TRAP_IGNORE(CMMFAudioController::PlayL());
560 iPanicTimer->Start(1000000, 1000000, TCallBack(PanicTimerComplete, this));
563 void CPanicAudioController::ConstructL()
565 CMMFAudioController::ConstructL();
566 iPanicTimer = CPeriodic::NewL(CActive::EPriorityStandard);
569 TTimeIntervalMicroSeconds CPanicAudioController::DurationL()const
571 return TTimeIntervalMicroSeconds(0);
574 void CPanicAudioController::SetPositionL(const TTimeIntervalMicroSeconds& aPosition)
576 TRAP_IGNORE(CMMFAudioController::SetPositionL(aPosition));
579 TInt CPanicAudioController::PanicTimerComplete(TAny* /*aParent*/)
581 User::Panic(_L("CustomMmfAudioController"), 0);