os/mm/mmlibs/mmfw/tsrc/mmfunittest/avictrl/testplugins/aviplaycontroller/customaviplaycontroller.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmlibs/mmfw/tsrc/mmfunittest/avictrl/testplugins/aviplaycontroller/customaviplaycontroller.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,369 @@
1.4 +// Copyright (c) 2007-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 "customaviplaycontroller.h"
1.21 +#include "tsu_mmf_avictrltestids.h"
1.22 +
1.23 +#define KInitIncompleteCode KMaxTInt
1.24 +
1.25 +_LIT(KTestAviFile, "c:\\mm\\mmf\\testfiles\\avictrl\\aud_vid.avi");
1.26 +
1.27 +/**
1.28 +*
1.29 +* NewL
1.30 +*
1.31 +*/
1.32 +CMMFController* CCustomAviPlayController::NewL()
1.33 + {
1.34 + CCustomAviPlayController* self = new(ELeave) CCustomAviPlayController;
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 +*
1.44 +* CCustomAviPlayController
1.45 +*
1.46 +*/
1.47 +CCustomAviPlayController::~CCustomAviPlayController()
1.48 + {
1.49 + if (iDataSource)
1.50 + {
1.51 + delete iDataSource;
1.52 + }
1.53 + if (iDataSink)
1.54 + {
1.55 + delete iDataSink;
1.56 + }
1.57 +
1.58 + }
1.59 +
1.60 +/**
1.61 +*
1.62 +* CCustomAviPlayController
1.63 +*
1.64 +*/
1.65 +CCustomAviPlayController::CCustomAviPlayController() : CAviPlayController()
1.66 + {
1.67 + }
1.68 +
1.69 +/**
1.70 +*
1.71 +* Override base class ResetL
1.72 +*
1.73 +*/
1.74 +void CCustomAviPlayController::ResetL()
1.75 + {
1.76 + CAviPlayController::ResetL();
1.77 + if (iDataSource)
1.78 + {
1.79 + delete iDataSource;
1.80 + iDataSource = NULL;
1.81 + }
1.82 + if (iDataSink)
1.83 + {
1.84 + delete iDataSink;
1.85 + iDataSink = NULL;
1.86 + }
1.87 + }
1.88 +
1.89 +/**
1.90 +*
1.91 +* Override base class PrimeL
1.92 +*
1.93 +*/
1.94 +void CCustomAviPlayController::PrimeL(TMMFMessage& aMessage)
1.95 + {
1.96 + if (iMemAllocPrimeTestEnabled)
1.97 + {
1.98 + __UHEAP_SETFAIL(RHeap::EFailNext ,iMemAllocPrimeFailCount);
1.99 + TRAPD(err, CAviPlayController::PrimeL(aMessage));
1.100 + __UHEAP_SETFAIL(RHeap::ENone ,0);
1.101 + User::LeaveIfError(err);
1.102 + }
1.103 + else
1.104 + {
1.105 + CAviPlayController::PrimeL(aMessage);
1.106 + }
1.107 + }
1.108 +
1.109 +/**
1.110 +*
1.111 +* Override base class CustomCommand
1.112 +*
1.113 +*/
1.114 +void CCustomAviPlayController::CustomCommand(TMMFMessage& aMessage)
1.115 + {
1.116 + //[ check if the command is for the custom plugin
1.117 + // otherwise pass it on to the real audio controller ]
1.118 + /*if (iPrimingMessage)
1.119 + {
1.120 + delete iPrimingMessage;
1.121 + iPrimingMessage = NULL;
1.122 + }
1.123 + TRAPD(err, iPrimingMessage = CCustomMMFMessageHolder::NewL(aMessage));
1.124 + if (err != KErrNone)
1.125 + {
1.126 + aMessage.Complete(err);
1.127 + return;
1.128 + }*/
1.129 +
1.130 + if (aMessage.Destination().InterfaceId() == KMemoryAllocationTestId)
1.131 + {
1.132 + switch (aMessage.Function())
1.133 + {
1.134 + case KMemoryAllocTest1:
1.135 + DoMemoryAllocTest1(aMessage);
1.136 + break;
1.137 + case KMemoryAllocTest2:
1.138 + DoPrepareMemoryAllocTest2(aMessage);
1.139 + break;
1.140 + case KMemoryAllocTest3:
1.141 + DoMemoryAllocTest3(aMessage);
1.142 + break;
1.143 + case KOOMPrimeTestEnable:
1.144 + DoSetPrimetTestEnable(aMessage);
1.145 + break;
1.146 + case KOOMPrimeTestFailCount:
1.147 + DoSetPrimetTestFailCount(aMessage);
1.148 + break;
1.149 + }
1.150 + }
1.151 + else
1.152 + {
1.153 + //[ let the plugin process the message ]
1.154 + CAviPlayController::CustomCommand(aMessage);
1.155 + }
1.156 + }
1.157 +
1.158 +static void CleanupController(TAny* ptr)
1.159 + {
1.160 + CCustomAviPlayController* controller = STATIC_CAST(CCustomAviPlayController*, ptr);
1.161 + TRAP_IGNORE(controller->ResetL());
1.162 + }
1.163 +
1.164 +/**
1.165 +*
1.166 +* ConstructL
1.167 +*
1.168 +*/
1.169 +void CCustomAviPlayController::ConstructL()
1.170 + {
1.171 + CAviPlayController::ConstructL();
1.172 + }
1.173 +
1.174 +/**
1.175 +*
1.176 +* DoMemoryAllocTest1
1.177 +*
1.178 +*/
1.179 +void CCustomAviPlayController::DoMemoryAllocTest1(TMMFMessage& aMessage)
1.180 + {
1.181 + //[ it is a alloc memory test command ]
1.182 + // [ new algorithm adopted from M&G database ]
1.183 + //
1.184 + TInt errorCode = KErrNone;
1.185 + TInt failCount = 1;
1.186 + TBool completed = EFalse;
1.187 + TBool badResult = EFalse;
1.188 + TBool reachedEnd = EFalse;
1.189 +
1.190 + for( ; ; )
1.191 + {
1.192 + __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.193 + //NB: Do not use __MM_HEAP_MARK macro's in this test, the cleaning up the CustomMMFAudioController
1.194 + //is insufficient to remove all possible allocated memory from the framework.
1.195 + //CMMFControllerProxyServer::DoStartThreadL has been updated to do heap checking for
1.196 + //the whole server thread.
1.197 +
1.198 + //[ run a scenario of the major api
1.199 + //functions which alloc memory in the controller]
1.200 + TRAP( errorCode,
1.201 + TMMFFileConfig fileConfig; // video file
1.202 + fileConfig().iPath = KTestAviFile;
1.203 +
1.204 + //[ lets manufacture a source and sink ]
1.205 + //[Create the source]
1.206 + MDataSource* source = MDataSource::NewSourceL(KUidMmfFileSource, fileConfig);
1.207 + CleanupDeletePushL(source);
1.208 +
1.209 + //[ Create the sink ]
1.210 + MDataSink* sink = MDataSink::NewSinkL(KUidMmfAudioOutput, KNullDesC8);
1.211 + CleanupDeletePushL(sink);
1.212 +
1.213 + // Use a cleanup item to stop & reset the controller and so remove the data
1.214 + // sources/sinks automatically when this funtion leaves. This can be done
1.215 + // before the sinks/sources are added.
1.216 + TCleanupItem cleanupItem(CleanupController, this);
1.217 + CleanupStack::PushL(cleanupItem);
1.218 +
1.219 + //[ add the source ]
1.220 + CAviPlayController::AddDataSourceL(*source);
1.221 +
1.222 + //[ add the sink ]
1.223 + CAviPlayController::AddDataSinkL(*sink);
1.224 +
1.225 + CleanupStack::PopAndDestroy(3);// source, sink, cleanupItem
1.226 + );
1.227 + if( errorCode == KErrNone )
1.228 + {
1.229 + // [ check we have passed through all allocs in the test]
1.230 + TAny* testAlloc = User::Alloc(1);
1.231 + if( testAlloc == NULL )
1.232 + {
1.233 + reachedEnd = ETrue;
1.234 + failCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc.
1.235 + }
1.236 + else
1.237 + {
1.238 + User::Free( testAlloc );
1.239 + }
1.240 +
1.241 + completed = reachedEnd || badResult;
1.242 +
1.243 + }
1.244 + else if( errorCode != KErrNoMemory && errorCode != KErrCorrupt)
1.245 + {
1.246 + // [ we failed for some reason other than memory
1.247 + // allocation, so fail the test ]
1.248 + completed = ETrue;
1.249 + badResult = ETrue;
1.250 + }
1.251 +
1.252 + __UHEAP_SETFAIL(RHeap::ENone ,0);
1.253 +
1.254 + // [ exit the loop ]
1.255 + if( completed )
1.256 + {
1.257 + break;
1.258 + }
1.259 +
1.260 + failCount +=1;
1.261 + }
1.262 + if(!badResult)
1.263 + {
1.264 + aMessage.Complete(KErrNone);
1.265 + }
1.266 + else
1.267 + {
1.268 + aMessage.Complete(errorCode);
1.269 + }
1.270 + }
1.271 +
1.272 +/**
1.273 +*
1.274 +* DoMemoryAllocTest2
1.275 +*
1.276 +*/
1.277 +void CCustomAviPlayController::DoPrepareMemoryAllocTest2(TMMFMessage& aMessage)
1.278 + {
1.279 + TRAPD(err,
1.280 + TMMFFileConfig fileConfig; // video file
1.281 + fileConfig().iPath = KTestAviFile;
1.282 +
1.283 + // Use a cleanup item to stop & reset the controller and so remove the data
1.284 + // sources/sinks automatically when this funtion leaves. This can be done
1.285 + // before the sinks/sources are added.
1.286 + TCleanupItem cleanupItem(CleanupController, this);
1.287 + CleanupStack::PushL(cleanupItem);
1.288 +
1.289 + //[ lets manufacture a source and sink ]
1.290 + //[Create the source]
1.291 + if (iDataSource)
1.292 + {
1.293 + delete iDataSource;
1.294 + iDataSource = NULL;
1.295 + }
1.296 + iDataSource = MDataSource::NewSourceL(KUidMmfFileSource, fileConfig);
1.297 +
1.298 + //[ Create the sink ]
1.299 + if (iDataSink)
1.300 + {
1.301 + delete iDataSink;
1.302 + iDataSink = NULL;
1.303 + }
1.304 + iDataSink = MDataSink::NewSinkL(KUidMmfAudioOutput, KNullDesC8);
1.305 +
1.306 + //[ add the source ]
1.307 + CAviPlayController::AddDataSourceL(*iDataSource);
1.308 +
1.309 + //[ add the sink ]
1.310 + CAviPlayController::AddDataSinkL(*iDataSink);
1.311 +
1.312 + CleanupStack::Pop(1); // cleanupItem
1.313 + );
1.314 + aMessage.Complete(err);
1.315 + }
1.316 +
1.317 +/**
1.318 +*
1.319 +* DoMemoryAllocTest3
1.320 +*
1.321 +*/
1.322 +void CCustomAviPlayController::DoMemoryAllocTest3(TMMFMessage& aMessage)
1.323 + {
1.324 + __UHEAP_SETFAIL(RHeap::EFailNext ,iMemAllocPrimeFailCount);
1.325 + TRAPD(err,
1.326 + // Use a cleanup item to stop & reset the controller and so remove the data
1.327 + // sources/sinks automatically when this funtion leaves. This can be done
1.328 + // before the sinks/sources are added.
1.329 + TCleanupItem cleanupItem(CleanupController, this);
1.330 + CleanupStack::PushL(cleanupItem);
1.331 +
1.332 + //[ play ]
1.333 + CAviPlayController::PlayL();
1.334 +
1.335 + //[ stop ]
1.336 + CAviPlayController::StopL();
1.337 +
1.338 + //[ reset ]
1.339 + CAviPlayController::ResetL();
1.340 +
1.341 + CleanupStack::PopAndDestroy(1); // cleanupItem
1.342 + );
1.343 + __UHEAP_SETFAIL(RHeap::ENone ,0);
1.344 + aMessage.Complete(err);
1.345 + }
1.346 +
1.347 +/**
1.348 +*
1.349 +* DoSetPrimetTestEnable
1.350 +*
1.351 +*/
1.352 +void CCustomAviPlayController::DoSetPrimetTestEnable(TMMFMessage& aMessage)
1.353 + {
1.354 + TPckgBuf<TBool> primeTestEnable;
1.355 + TInt err = aMessage.ReadData1FromClient(primeTestEnable);
1.356 + aMessage.Complete(err);
1.357 + iMemAllocPrimeTestEnabled = primeTestEnable();
1.358 + }
1.359 +
1.360 +/**
1.361 +*
1.362 +* DoSetPrimetTestFailCount
1.363 +*
1.364 +*/
1.365 +void CCustomAviPlayController::DoSetPrimetTestFailCount(TMMFMessage& aMessage)
1.366 + {
1.367 + TPckgBuf<TInt> primeTestFailCount;
1.368 + TInt err = aMessage.ReadData1FromClient(primeTestFailCount);
1.369 + aMessage.Complete(err);
1.370 + iMemAllocPrimeFailCount = primeTestFailCount();
1.371 + }
1.372 +