os/mm/mmlibs/mmfw/tsrc/mmfunittest/Actrl/TestPlugins/AudioController/CustomMmfAudioController.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmlibs/mmfw/tsrc/mmfunittest/Actrl/TestPlugins/AudioController/CustomMmfAudioController.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,584 @@
1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <mmf/server/mmffile.h>
1.20 +#include "CustomMmfAudioController.h"
1.21 +
1.22 +#include <mmf/plugin/mmfcontrollerimplementationuids.hrh>
1.23 +#include "ActrlTestUids.h"
1.24 +
1.25 +_LIT(KTestWavFile19, "c:\\mm\\mmf\\testfiles\\actrl\\newmail.wav");
1.26 +
1.27 +/**
1.28 +*
1.29 +* NewL
1.30 +*
1.31 +*/
1.32 +CMMFController* CCustomMmfAudioController::NewL()
1.33 + {
1.34 + CCustomMmfAudioController* self = new(ELeave) CCustomMmfAudioController;
1.35 + CleanupStack::PushL(self);
1.36 + self->ConstructL();
1.37 + CleanupStack::Pop( self );
1.38 +
1.39 + return STATIC_CAST( CMMFController*, self );
1.40 + }
1.41 +/**
1.42 +*
1.43 +* ~CCustomMmfAudioController
1.44 +*
1.45 +*/
1.46 +CCustomMmfAudioController::~CCustomMmfAudioController()
1.47 + {
1.48 + delete iStoppingMessage;
1.49 + }
1.50 +
1.51 +/**
1.52 +*
1.53 +* CCustomMmfAudioController
1.54 +*
1.55 +*/
1.56 +CCustomMmfAudioController::CCustomMmfAudioController()
1.57 +:CMMFAudioController(), iIsTest(EFalse)
1.58 + {
1.59 + }
1.60 +
1.61 +/**
1.62 + * PrimeL
1.63 + *
1.64 + * If Prime fails the client should reset the controller
1.65 + * becaused as noted below this code is not transactional.
1.66 + *
1.67 + */
1.68 +void CCustomMmfAudioController::PrimeL(TMMFMessage& aMessage)
1.69 + {
1.70 + PrimeL();
1.71 + aMessage.Complete(KErrNone);
1.72 + }
1.73 +void CCustomMmfAudioController::PlayL(TMMFMessage& aMessage)
1.74 + {
1.75 + PlayL();
1.76 + aMessage.Complete(KErrNone);
1.77 + }
1.78 +void CCustomMmfAudioController::PauseL(TMMFMessage& aMessage)
1.79 + {
1.80 + PauseL();
1.81 + aMessage.Complete(KErrNone);
1.82 + }
1.83 +
1.84 +void CCustomMmfAudioController::PrimeL()
1.85 + {
1.86 + // apply heap check's here
1.87 + // Note if they fail this is the end of the controller
1.88 +
1.89 + // call the base class functionality
1.90 + TRAPD( errorCode, CMMFAudioController::PrimeL());
1.91 + // send an event back to the test framework with
1.92 + // the error code
1.93 + TMMFEvent aEvent( KPrimeTestId, errorCode );
1.94 + DoSendEventToClient(aEvent);
1.95 + //[ we need to preserve the leave semantics for the caller]
1.96 + User::LeaveIfError( errorCode );
1.97 + }
1.98 +
1.99 +/**
1.100 + *
1.101 + * PlayL
1.102 + *
1.103 + */
1.104 +void CCustomMmfAudioController::PlayL()
1.105 + {
1.106 +// call the base class functionality
1.107 + TRAPD( errorCode, CMMFAudioController::PlayL());
1.108 + // send an event back to the test framework with
1.109 + // the error code
1.110 + TMMFEvent aEvent( KPlayTestId, errorCode );
1.111 + DoSendEventToClient(aEvent);
1.112 + //[ we need to preserve the leave semantics for the caller]
1.113 + User::LeaveIfError( errorCode );
1.114 + }
1.115 +
1.116 +/**
1.117 +*
1.118 +* MapdSetVolumeL
1.119 +*
1.120 +*/
1.121 +void CCustomMmfAudioController::MapdSetVolumeL(TInt aVolume)
1.122 + {
1.123 + //Special return code to test fix for PDEF120609, test case id MM-MMF-ACLNT-U-0277-CP
1.124 + if (aVolume == -999)
1.125 + {
1.126 + User::Leave(-12345);
1.127 + }
1.128 + CMMFAudioController::MapdSetVolumeL( aVolume );
1.129 + }
1.130 +
1.131 +/**
1.132 +*
1.133 +* MapdGetMaxVolumeL
1.134 +*
1.135 +*/
1.136 +void CCustomMmfAudioController::MapdGetMaxVolumeL(TInt& aMaxVolume)
1.137 + {
1.138 + CMMFAudioController::MapdGetMaxVolumeL( aMaxVolume );
1.139 + }
1.140 +
1.141 +/**
1.142 +* MapdGetVolumeL
1.143 +*
1.144 +*/
1.145 +void CCustomMmfAudioController::MapdGetVolumeL(TInt& aVolume)
1.146 + {
1.147 + CMMFAudioController::MapdGetVolumeL( aVolume );
1.148 + }
1.149 +
1.150 +/**
1.151 +*
1.152 +*PauseL
1.153 +*
1.154 +*/
1.155 +void CCustomMmfAudioController::PauseL()
1.156 + {
1.157 + TRAPD( errorCode,CMMFAudioController::PauseL());
1.158 + //[ send pause event ]
1.159 + TMMFEvent aEvent( KPauseTestId, errorCode );
1.160 + DoSendEventToClient(aEvent);
1.161 + //[ we need to preserve the leave semantics for the caller]
1.162 + User::LeaveIfError( errorCode );
1.163 + }
1.164 +
1.165 +/**
1.166 +*
1.167 +* StopL
1.168 +*
1.169 +*/
1.170 +void CCustomMmfAudioController::StopL()
1.171 + {
1.172 + TRAPD( errorCode,CMMFAudioController::StopL());
1.173 + //[ send stop event ]
1.174 + TMMFEvent aEvent( KStopTestId, errorCode );
1.175 + DoSendEventToClient(aEvent);
1.176 + //[ we need to preserve the leave semantics for the caller]
1.177 + User::LeaveIfError( errorCode );
1.178 + }
1.179 +
1.180 +/**
1.181 +*
1.182 +* ResetL
1.183 +*
1.184 +*/
1.185 +void CCustomMmfAudioController::ResetL()
1.186 + {
1.187 + TRAPD( errorCode,CMMFAudioController::ResetL());
1.188 + //[ send stop event ]
1.189 + TMMFEvent aEvent( KResetTestId, errorCode );
1.190 + DoSendEventToClient(aEvent);
1.191 + //[ we need to preserve the leave semantics for the caller]
1.192 + User::LeaveIfError( errorCode );
1.193 + }
1.194 +
1.195 +/**
1.196 +*
1.197 +* RemoveDataSourceL
1.198 +*
1.199 +*/
1.200 +void CCustomMmfAudioController::RemoveDataSourceL(MDataSource& aDataSource)
1.201 + {
1.202 + TRAPD( errorCode,CMMFAudioController::RemoveDataSourceL( aDataSource));
1.203 + //[ send stop event ]
1.204 + TMMFEvent aEvent( KRemoveDataSourceTestId, errorCode );
1.205 + DoSendEventToClient(aEvent);
1.206 + //[ we need to preserve the leave semantics for the caller]
1.207 + User::LeaveIfError( errorCode );
1.208 + }
1.209 +
1.210 +/**
1.211 +*
1.212 +* RemoveDataSinkL
1.213 +*
1.214 +*/
1.215 +void CCustomMmfAudioController::RemoveDataSinkL(MDataSink& aDataSink)
1.216 + {
1.217 + TRAPD( errorCode,CMMFAudioController::RemoveDataSinkL( aDataSink));
1.218 + //[ send stop event ]
1.219 + TMMFEvent aEvent( KRemoveDataSinkTestId, errorCode );
1.220 + DoSendEventToClient(aEvent);
1.221 + //[ we need to preserve the leave semantics for the caller]
1.222 + User::LeaveIfError( errorCode );
1.223 + }
1.224 +
1.225 +/**
1.226 +*
1.227 +* MarcSetMaxFileSizeL
1.228 +*
1.229 +*/
1.230 +
1.231 +void CCustomMmfAudioController::MarcSetMaxFileSizeL(TInt aFileSize)
1.232 + {
1.233 + TRAPD( errorCode,CMMFAudioController::MarcSetMaxFileSizeL( aFileSize));
1.234 + //[ send stop event ]
1.235 + TMMFEvent aEvent( KMarcSetMaxFileSizeId, errorCode );
1.236 + DoSendEventToClient(aEvent);
1.237 + //[ we need to preserve the leave semantics for the caller]
1.238 + User::LeaveIfError( errorCode );
1.239 + }
1.240 +
1.241 +/**
1.242 +*
1.243 +* MarcGetRecordTimeAvailableL
1.244 +* @param aTime
1.245 +*
1.246 +*/
1.247 +void CCustomMmfAudioController::MarcGetRecordTimeAvailableL(TTimeIntervalMicroSeconds& aTime)
1.248 + {
1.249 + TRAPD( errorCode,CMMFAudioController::MarcGetRecordTimeAvailableL( aTime));
1.250 + //[ send stop event ]
1.251 + TMMFEvent aEvent( KMarcGetRecordTimeAvailId, errorCode );
1.252 + DoSendEventToClient(aEvent);
1.253 + //[ we need to preserve the leave semantics for the caller]
1.254 + User::LeaveIfError( errorCode );
1.255 + }
1.256 +
1.257 +
1.258 +/**
1.259 +*
1.260 +* CustomCommand
1.261 +*
1.262 +*/
1.263 +void CCustomMmfAudioController::CustomCommand(TMMFMessage& aMessage)
1.264 + {
1.265 + //[ check if the command is for the custom plugin
1.266 + // otherwise pass it on to the real audio controller ]
1.267 + TRAPD(err, iStoppingMessage = CCustomMMFMessageHolder::NewL(aMessage));
1.268 + if (err != KErrNone)
1.269 + {
1.270 + aMessage.Complete(err);
1.271 + return;
1.272 + }
1.273 +
1.274 + iIsTest = ETrue;
1.275 + if( IsMemoryAllocCmd( aMessage ) )
1.276 + {
1.277 + //[ it is a alloc memory test command ]
1.278 + // [ new algorithm adopted from M&G database ]
1.279 + //
1.280 + TInt errorCode = KErrNone;
1.281 + TInt failCount = 1;
1.282 + TBool completed = EFalse;
1.283 + TBool badResult = EFalse;
1.284 + TBool reachedEnd = EFalse;
1.285 +
1.286 + for( ; ; )
1.287 + {
1.288 + __UHEAP_SETFAIL(RHeap::EFailNext ,failCount); // Leavescan will think __UHEAP_SETFAIL is a leaving function due to the macro ending in 'L'. Does not leave
1.289 +
1.290 + //NB: Do not use __MM_HEAP_MARK macro's in this test, the cleaning up the CustomMMFAudioController
1.291 + //is insufficient to remove all possible allocated memory from the framework.
1.292 + //CMMFControllerProxyServer::DoStartThreadL has been updated to do heap checking for
1.293 + //the whole server thread.
1.294 +
1.295 + //[ run a scenario of the major api
1.296 + //functions which alloc memory in the controller]
1.297 + TRAP( errorCode, AllocMemoryTestL());
1.298 +
1.299 + if( errorCode == KErrNone )
1.300 + {
1.301 + // [ check we have passed through all allocs in the test]
1.302 + TAny* testAlloc = User::Alloc(1);
1.303 + if( testAlloc == NULL )
1.304 + {
1.305 + reachedEnd = ETrue;
1.306 + failCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc.
1.307 + }
1.308 + else
1.309 + {
1.310 + User::Free( testAlloc );
1.311 + }
1.312 +
1.313 + completed = reachedEnd || badResult;
1.314 +
1.315 + }
1.316 + else if( errorCode != KErrNoMemory )
1.317 + {
1.318 + // [ we failed for some reason other than memory
1.319 + // allocation, so fail the test ]
1.320 + completed = ETrue;
1.321 + badResult = ETrue;
1.322 + }
1.323 +
1.324 + __UHEAP_SETFAIL(RHeap::ENone ,0);
1.325 +
1.326 + // [ exit the loop ]
1.327 + if( completed )
1.328 + {
1.329 + break;
1.330 + }
1.331 +
1.332 + failCount +=1;
1.333 + }
1.334 +
1.335 + //This flag is used by the audio controller to alter its behaviour
1.336 + //slightly to allow these tests to work
1.337 + iIsTest=EFalse;
1.338 +
1.339 + if(!badResult)
1.340 + {
1.341 + aMessage.Complete(KErrNone);
1.342 + }
1.343 + else
1.344 + {
1.345 + aMessage.Complete(errorCode);
1.346 + }
1.347 + }
1.348 + else
1.349 + {
1.350 + //[ let the plugin process the message ]
1.351 + CMMFAudioController::CustomCommand(aMessage);
1.352 + }
1.353 + }
1.354 +
1.355 +/**
1.356 +*
1.357 +* IsMemoryAllocCmd
1.358 +*
1.359 +*/
1.360 +TBool CCustomMmfAudioController::IsMemoryAllocCmd( TMMFMessage& )
1.361 + {
1.362 + return ETrue;
1.363 + }
1.364 +
1.365 +
1.366 +static void CleanupController(TAny* ptr)
1.367 + {
1.368 + CMMFAudioController* controller = STATIC_CAST(CMMFAudioController*, ptr);
1.369 + TRAP_IGNORE(controller->CMMFAudioController::ResetL());
1.370 + }
1.371 +
1.372 +
1.373 +/**
1.374 +*
1.375 +* AllocMemoryTest
1.376 +*
1.377 +*/
1.378 +TInt CCustomMmfAudioController::AllocMemoryTestL()
1.379 + {
1.380 + TMMFFileConfig fileConfig; // audio file
1.381 +
1.382 + fileConfig().iPath = KTestWavFile19;
1.383 +
1.384 + //[ lets manufacture a source and sink ]
1.385 +
1.386 + //[Create the source]
1.387 + MDataSource* source = MDataSource::NewSourceL(KUidMmfFileSource, fileConfig);
1.388 + CleanupDeletePushL(source);
1.389 +
1.390 + //[ Create the sink ]
1.391 + MDataSink* sink = MDataSink::NewSinkL(KUidMmfAudioOutput, KNullDesC8);
1.392 + CleanupDeletePushL(sink);
1.393 +
1.394 + // Use a cleanup item to stop & reset the controller and so remove the data
1.395 + // sources/sinks automatically when this funtion leaves. This can be done
1.396 + // before the sinks/sources are added.
1.397 + TCleanupItem cleanupItem(CleanupController, this);
1.398 + CleanupStack::PushL(cleanupItem);
1.399 +
1.400 +
1.401 + //[ add the source ]
1.402 + CMMFAudioController::AddDataSourceL(*source);
1.403 +
1.404 + //[ add the sink ]
1.405 + CMMFAudioController::AddDataSinkL(*sink);
1.406 +
1.407 + //[ prime ]
1.408 + CMMFAudioController::PrimeL();
1.409 +
1.410 + //[ play ]
1.411 + CMMFAudioController::PlayL();
1.412 +
1.413 + //[ pause ]
1.414 + CMMFAudioController::PauseL();
1.415 +
1.416 + //[ play ]
1.417 + CMMFAudioController::PlayL();
1.418 +
1.419 + //[ stop ]
1.420 + CMMFAudioController::StopL(iStoppingMessage->iMessage);
1.421 +
1.422 + // [ prime ]
1.423 + CMMFAudioController::PrimeL();
1.424 +
1.425 + //[ reset ]
1.426 + CMMFAudioController::ResetL();
1.427 +
1.428 + CleanupStack::PopAndDestroy(3);// source, sink, cleanupItem
1.429 +
1.430 + return KErrNone;
1.431 + }
1.432 +
1.433 +//Leaves with KErrNoMemory.
1.434 +CMMFController* CMemoryFailAudioController::NewL()
1.435 + {
1.436 + if(ETrue) //condition used to avoid any warning
1.437 + {
1.438 + User::Leave(KErrNoMemory);
1.439 + }
1.440 + return NULL;
1.441 + }
1.442 +CMemoryFailAudioController::CMemoryFailAudioController():CMMFAudioController()
1.443 + {
1.444 + }
1.445 +CMemoryFailAudioController::~CMemoryFailAudioController()
1.446 + {
1.447 + if(iSink)
1.448 + {
1.449 + iSink->SinkThreadLogoff();
1.450 + }
1.451 + if(iClip)
1.452 + {
1.453 + iClip->SourceThreadLogoff();
1.454 + }
1.455 + }
1.456 +
1.457 +void CMemoryFailAudioController::AddDataSourceL(MDataSource& aSource)
1.458 + {
1.459 + if (iClip)
1.460 + {
1.461 + User::Leave(KErrAlreadyExists);
1.462 + }
1.463 + if ((aSource.DataSourceType()==KUidMmfDescriptorSource)||
1.464 + (aSource.DataSourceType()==KUidMmfFileSource))
1.465 + {
1.466 + User::LeaveIfError(aSource.SourceThreadLogon(*this));
1.467 + iClip = static_cast<CMMFClip*>(&aSource);
1.468 + if(iClip->Size())
1.469 + {
1.470 + iClip->SourcePrimeL();
1.471 + }
1.472 + else
1.473 + {
1.474 + iClip->SourceStopL();
1.475 + }
1.476 + }
1.477 + else
1.478 + {
1.479 + User::Leave(KErrNotSupported);
1.480 + }
1.481 + }
1.482 +
1.483 +void CMemoryFailAudioController::AddDataSinkL(MDataSink& aSink)
1.484 + {
1.485 + if(iMMFDevSound)
1.486 + {
1.487 + User::Leave(KErrAlreadyExists);
1.488 + }
1.489 + if (aSink.DataSinkType()!=KUidMmfAudioOutput)
1.490 + {
1.491 + User::Leave(KErrNotSupported);
1.492 + }
1.493 + User::LeaveIfError(aSink.SinkThreadLogon(*this));
1.494 + iSink = &aSink;
1.495 + MMMFAudioOutput* audioOutput = static_cast<MMMFAudioOutput*>(&aSink);
1.496 + iMMFDevSound = &(audioOutput->SoundDevice());
1.497 + iMMFDevSound->SetPrioritySettings(iPrioritySettings);
1.498 + return;
1.499 + }
1.500 +
1.501 +void CMemoryFailAudioController::SetPrioritySettings(const TMMFPrioritySettings& aSettings)
1.502 + {
1.503 + iPrioritySettings = aSettings;
1.504 + if (iMMFDevSound)
1.505 + {
1.506 + iMMFDevSound->SetPrioritySettings(aSettings);
1.507 + }
1.508 + }
1.509 +
1.510 +//Does not acces files; returns hard-coded value.
1.511 +TTimeIntervalMicroSeconds CMemoryFailAudioController::DurationL()const
1.512 + {
1.513 + return TTimeIntervalMicroSeconds(1000000); //return 1sec
1.514 + }
1.515 +
1.516 +CMMFController* CMemoryPassAudioController::NewL()
1.517 + {
1.518 + CMemoryPassAudioController* self = new (ELeave) CMemoryPassAudioController();
1.519 + return STATIC_CAST( CMMFController*, self );
1.520 + }
1.521 +CMemoryPassAudioController::CMemoryPassAudioController():CMemoryFailAudioController()
1.522 + {
1.523 + }
1.524 +
1.525 +//Derived from Audio Controller. Panics the controller thread after the play is started
1.526 +CMMFController* CPanicAudioController::NewL()
1.527 + {
1.528 + CPanicAudioController* self = new(ELeave) CPanicAudioController;
1.529 + CleanupStack::PushL(self);
1.530 + self->ConstructL();
1.531 + CleanupStack::Pop( self );
1.532 + return static_cast<CMMFController*>(self);
1.533 + }
1.534 +
1.535 +CPanicAudioController::CPanicAudioController():CMMFAudioController()
1.536 + {
1.537 + }
1.538 +
1.539 +CPanicAudioController::~CPanicAudioController()
1.540 + {
1.541 + delete iPanicTimer;
1.542 + }
1.543 +
1.544 +void CPanicAudioController::AddDataSourceL(MDataSource& aSource)
1.545 + {
1.546 + TRAP_IGNORE(CMMFAudioController::AddDataSourceL(aSource));
1.547 + }
1.548 +
1.549 +void CPanicAudioController::AddDataSinkL(MDataSink& aSink)
1.550 + {
1.551 + TRAP_IGNORE(CMMFAudioController::AddDataSinkL(aSink));
1.552 + }
1.553 +
1.554 +void CPanicAudioController::PrimeL()
1.555 + {
1.556 + TRAP_IGNORE(CMMFAudioController::PrimeL());
1.557 + }
1.558 +
1.559 +void CPanicAudioController::PlayL()
1.560 + {
1.561 + TRAP_IGNORE(CMMFAudioController::PlayL());
1.562 + //trigger the panic
1.563 + iPanicTimer->Start(1000000, 1000000, TCallBack(PanicTimerComplete, this));
1.564 + }
1.565 +
1.566 +void CPanicAudioController::ConstructL()
1.567 + {
1.568 + CMMFAudioController::ConstructL();
1.569 + iPanicTimer = CPeriodic::NewL(CActive::EPriorityStandard);
1.570 + }
1.571 +
1.572 +TTimeIntervalMicroSeconds CPanicAudioController::DurationL()const
1.573 + {
1.574 + return TTimeIntervalMicroSeconds(0);
1.575 + }
1.576 +
1.577 +void CPanicAudioController::SetPositionL(const TTimeIntervalMicroSeconds& aPosition)
1.578 + {
1.579 + TRAP_IGNORE(CMMFAudioController::SetPositionL(aPosition));
1.580 + }
1.581 +
1.582 +TInt CPanicAudioController::PanicTimerComplete(TAny* /*aParent*/)
1.583 + {
1.584 + User::Panic(_L("CustomMmfAudioController"), 0);
1.585 + return KErrNone;
1.586 + }
1.587 +