os/mm/mmlibs/mmfw/tsrc/mmfunittest/avictrl/testplugins/aviplaycontroller/customaviplaycontroller.cpp
First public contribution.
1 // Copyright (c) 2007-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 "customaviplaycontroller.h"
18 #include "tsu_mmf_avictrltestids.h"
20 #define KInitIncompleteCode KMaxTInt
22 _LIT(KTestAviFile, "c:\\mm\\mmf\\testfiles\\avictrl\\aud_vid.avi");
29 CMMFController* CCustomAviPlayController::NewL()
31 CCustomAviPlayController* self = new(ELeave) CCustomAviPlayController;
32 CleanupStack::PushL(self);
34 CleanupStack::Pop( self );
36 return STATIC_CAST( CMMFController*, self );
41 * CCustomAviPlayController
44 CCustomAviPlayController::~CCustomAviPlayController()
59 * CCustomAviPlayController
62 CCustomAviPlayController::CCustomAviPlayController() : CAviPlayController()
68 * Override base class ResetL
71 void CCustomAviPlayController::ResetL()
73 CAviPlayController::ResetL();
88 * Override base class PrimeL
91 void CCustomAviPlayController::PrimeL(TMMFMessage& aMessage)
93 if (iMemAllocPrimeTestEnabled)
95 __UHEAP_SETFAIL(RHeap::EFailNext ,iMemAllocPrimeFailCount);
96 TRAPD(err, CAviPlayController::PrimeL(aMessage));
97 __UHEAP_SETFAIL(RHeap::ENone ,0);
98 User::LeaveIfError(err);
102 CAviPlayController::PrimeL(aMessage);
108 * Override base class CustomCommand
111 void CCustomAviPlayController::CustomCommand(TMMFMessage& aMessage)
113 //[ check if the command is for the custom plugin
114 // otherwise pass it on to the real audio controller ]
115 /*if (iPrimingMessage)
117 delete iPrimingMessage;
118 iPrimingMessage = NULL;
120 TRAPD(err, iPrimingMessage = CCustomMMFMessageHolder::NewL(aMessage));
123 aMessage.Complete(err);
127 if (aMessage.Destination().InterfaceId() == KMemoryAllocationTestId)
129 switch (aMessage.Function())
131 case KMemoryAllocTest1:
132 DoMemoryAllocTest1(aMessage);
134 case KMemoryAllocTest2:
135 DoPrepareMemoryAllocTest2(aMessage);
137 case KMemoryAllocTest3:
138 DoMemoryAllocTest3(aMessage);
140 case KOOMPrimeTestEnable:
141 DoSetPrimetTestEnable(aMessage);
143 case KOOMPrimeTestFailCount:
144 DoSetPrimetTestFailCount(aMessage);
150 //[ let the plugin process the message ]
151 CAviPlayController::CustomCommand(aMessage);
155 static void CleanupController(TAny* ptr)
157 CCustomAviPlayController* controller = STATIC_CAST(CCustomAviPlayController*, ptr);
158 TRAP_IGNORE(controller->ResetL());
166 void CCustomAviPlayController::ConstructL()
168 CAviPlayController::ConstructL();
176 void CCustomAviPlayController::DoMemoryAllocTest1(TMMFMessage& aMessage)
178 //[ it is a alloc memory test command ]
179 // [ new algorithm adopted from M&G database ]
181 TInt errorCode = KErrNone;
183 TBool completed = EFalse;
184 TBool badResult = EFalse;
185 TBool reachedEnd = EFalse;
189 __UHEAP_SETFAIL(RHeap::EFailNext ,failCount); // Leavescan will think __UHEAP_SETFAIL is a leaving function due to the macro ending in 'L'. Does not leave
190 //NB: Do not use __MM_HEAP_MARK macro's in this test, the cleaning up the CustomMMFAudioController
191 //is insufficient to remove all possible allocated memory from the framework.
192 //CMMFControllerProxyServer::DoStartThreadL has been updated to do heap checking for
193 //the whole server thread.
195 //[ run a scenario of the major api
196 //functions which alloc memory in the controller]
198 TMMFFileConfig fileConfig; // video file
199 fileConfig().iPath = KTestAviFile;
201 //[ lets manufacture a source and sink ]
202 //[Create the source]
203 MDataSource* source = MDataSource::NewSourceL(KUidMmfFileSource, fileConfig);
204 CleanupDeletePushL(source);
206 //[ Create the sink ]
207 MDataSink* sink = MDataSink::NewSinkL(KUidMmfAudioOutput, KNullDesC8);
208 CleanupDeletePushL(sink);
210 // Use a cleanup item to stop & reset the controller and so remove the data
211 // sources/sinks automatically when this funtion leaves. This can be done
212 // before the sinks/sources are added.
213 TCleanupItem cleanupItem(CleanupController, this);
214 CleanupStack::PushL(cleanupItem);
217 CAviPlayController::AddDataSourceL(*source);
220 CAviPlayController::AddDataSinkL(*sink);
222 CleanupStack::PopAndDestroy(3);// source, sink, cleanupItem
224 if( errorCode == KErrNone )
226 // [ check we have passed through all allocs in the test]
227 TAny* testAlloc = User::Alloc(1);
228 if( testAlloc == NULL )
231 failCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc.
235 User::Free( testAlloc );
238 completed = reachedEnd || badResult;
241 else if( errorCode != KErrNoMemory && errorCode != KErrCorrupt)
243 // [ we failed for some reason other than memory
244 // allocation, so fail the test ]
249 __UHEAP_SETFAIL(RHeap::ENone ,0);
261 aMessage.Complete(KErrNone);
265 aMessage.Complete(errorCode);
274 void CCustomAviPlayController::DoPrepareMemoryAllocTest2(TMMFMessage& aMessage)
277 TMMFFileConfig fileConfig; // video file
278 fileConfig().iPath = KTestAviFile;
280 // Use a cleanup item to stop & reset the controller and so remove the data
281 // sources/sinks automatically when this funtion leaves. This can be done
282 // before the sinks/sources are added.
283 TCleanupItem cleanupItem(CleanupController, this);
284 CleanupStack::PushL(cleanupItem);
286 //[ lets manufacture a source and sink ]
287 //[Create the source]
293 iDataSource = MDataSource::NewSourceL(KUidMmfFileSource, fileConfig);
295 //[ Create the sink ]
301 iDataSink = MDataSink::NewSinkL(KUidMmfAudioOutput, KNullDesC8);
304 CAviPlayController::AddDataSourceL(*iDataSource);
307 CAviPlayController::AddDataSinkL(*iDataSink);
309 CleanupStack::Pop(1); // cleanupItem
311 aMessage.Complete(err);
319 void CCustomAviPlayController::DoMemoryAllocTest3(TMMFMessage& aMessage)
321 __UHEAP_SETFAIL(RHeap::EFailNext ,iMemAllocPrimeFailCount);
323 // Use a cleanup item to stop & reset the controller and so remove the data
324 // sources/sinks automatically when this funtion leaves. This can be done
325 // before the sinks/sources are added.
326 TCleanupItem cleanupItem(CleanupController, this);
327 CleanupStack::PushL(cleanupItem);
330 CAviPlayController::PlayL();
333 CAviPlayController::StopL();
336 CAviPlayController::ResetL();
338 CleanupStack::PopAndDestroy(1); // cleanupItem
340 __UHEAP_SETFAIL(RHeap::ENone ,0);
341 aMessage.Complete(err);
346 * DoSetPrimetTestEnable
349 void CCustomAviPlayController::DoSetPrimetTestEnable(TMMFMessage& aMessage)
351 TPckgBuf<TBool> primeTestEnable;
352 TInt err = aMessage.ReadData1FromClient(primeTestEnable);
353 aMessage.Complete(err);
354 iMemAllocPrimeTestEnabled = primeTestEnable();
359 * DoSetPrimetTestFailCount
362 void CCustomAviPlayController::DoSetPrimetTestFailCount(TMMFMessage& aMessage)
364 TPckgBuf<TInt> primeTestFailCount;
365 TInt err = aMessage.ReadData1FromClient(primeTestFailCount);
366 aMessage.Complete(err);
367 iMemAllocPrimeFailCount = primeTestFailCount();