os/mm/mmlibs/mmfw/tsrc/mmfunittest/avictrl/testplugins/aviplaycontroller/customaviplaycontroller.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include <mmf/server/mmffile.h>
    17 #include "customaviplaycontroller.h"
    18 #include "tsu_mmf_avictrltestids.h"
    19 
    20 #define KInitIncompleteCode KMaxTInt
    21 
    22 _LIT(KTestAviFile, "c:\\mm\\mmf\\testfiles\\avictrl\\aud_vid.avi");
    23 
    24 /**
    25 *
    26 * NewL
    27 *
    28 */
    29 CMMFController* CCustomAviPlayController::NewL()
    30 	{
    31     CCustomAviPlayController* self = new(ELeave) CCustomAviPlayController;
    32 	CleanupStack::PushL(self);
    33 	self->ConstructL();
    34 	CleanupStack::Pop( self );
    35 	
    36 	return STATIC_CAST( CMMFController*, self );
    37 	}
    38 
    39 /**
    40 *
    41 * CCustomAviPlayController
    42 *
    43 */
    44 CCustomAviPlayController::~CCustomAviPlayController()
    45 	{
    46 	if (iDataSource)
    47 		{
    48 		delete iDataSource;
    49 		}
    50 	if (iDataSink)
    51 		{
    52 		delete iDataSink;
    53 		}
    54 		
    55     }
    56 
    57 /**
    58 *
    59 * CCustomAviPlayController
    60 *
    61 */
    62 CCustomAviPlayController::CCustomAviPlayController() :	CAviPlayController()
    63 	{
    64 	}
    65 
    66 /**
    67 *
    68 * Override base class ResetL
    69 *
    70 */
    71 void CCustomAviPlayController::ResetL()
    72 	{
    73 	CAviPlayController::ResetL();
    74 	if (iDataSource)
    75 		{
    76 		delete iDataSource;
    77 		iDataSource = NULL;
    78 		}
    79 	if (iDataSink)
    80 		{
    81 		delete iDataSink;
    82 		iDataSink = NULL;
    83 		}
    84 	}
    85 	
    86 /**
    87 *
    88 * Override base class PrimeL
    89 *
    90 */
    91 void CCustomAviPlayController::PrimeL(TMMFMessage& aMessage)
    92 	{
    93 	if (iMemAllocPrimeTestEnabled)
    94 		{
    95 		__UHEAP_SETFAIL(RHeap::EFailNext ,iMemAllocPrimeFailCount);
    96 		TRAPD(err, CAviPlayController::PrimeL(aMessage));
    97 		__UHEAP_SETFAIL(RHeap::ENone ,0);
    98 		User::LeaveIfError(err);
    99 		}
   100 	else
   101 		{
   102 		CAviPlayController::PrimeL(aMessage);
   103 		}
   104 	}
   105 
   106 /**
   107 *
   108 * Override base class CustomCommand
   109 *
   110 */
   111 void CCustomAviPlayController::CustomCommand(TMMFMessage& aMessage)
   112 	{
   113 	//[ check if the command is for the custom plugin
   114 	// otherwise pass it on to the real audio controller ]
   115 	/*if (iPrimingMessage)
   116 		{
   117 		delete iPrimingMessage;
   118 		iPrimingMessage = NULL;
   119 		}
   120 	TRAPD(err, iPrimingMessage = CCustomMMFMessageHolder::NewL(aMessage));
   121 	if (err != KErrNone)
   122 		{
   123 		aMessage.Complete(err);
   124 		return;
   125 		}*/
   126 	
   127 	if (aMessage.Destination().InterfaceId() == KMemoryAllocationTestId)
   128 		{
   129 		switch (aMessage.Function())
   130 			{
   131 		case KMemoryAllocTest1:
   132 			DoMemoryAllocTest1(aMessage);
   133 			break;
   134 		case KMemoryAllocTest2:
   135 			DoPrepareMemoryAllocTest2(aMessage);
   136 			break;
   137 		case KMemoryAllocTest3:
   138 			DoMemoryAllocTest3(aMessage);
   139 			break;
   140 		case KOOMPrimeTestEnable:
   141 			DoSetPrimetTestEnable(aMessage);
   142 			break;
   143 		case KOOMPrimeTestFailCount:
   144 			DoSetPrimetTestFailCount(aMessage);
   145 			break;
   146 			}
   147 		}
   148 	else
   149 		{
   150 		//[ let the plugin process the message ]
   151 		CAviPlayController::CustomCommand(aMessage);
   152 		}
   153 	}
   154 
   155 static void CleanupController(TAny* ptr)
   156 	{
   157 	CCustomAviPlayController* controller = STATIC_CAST(CCustomAviPlayController*, ptr);
   158 	TRAP_IGNORE(controller->ResetL());
   159 	}
   160 	
   161 /**
   162 *
   163 * ConstructL
   164 *
   165 */
   166 void CCustomAviPlayController::ConstructL()
   167 	{
   168 	CAviPlayController::ConstructL();
   169 	}
   170 
   171 /**
   172 *
   173 * DoMemoryAllocTest1
   174 *
   175 */
   176 void CCustomAviPlayController::DoMemoryAllocTest1(TMMFMessage& aMessage)
   177 	{
   178 	//[ it is a alloc memory test command ]
   179 	// [ new algorithm adopted from M&G database ]
   180 	//
   181 	TInt errorCode = KErrNone;
   182 	TInt failCount  = 1;
   183 	TBool completed  = EFalse;
   184 	TBool badResult  = EFalse;
   185 	TBool reachedEnd = EFalse; 
   186 	
   187 	for( ; ; )
   188 		{
   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.
   194 
   195 		//[ run a scenario of the major api 
   196 		//functions which alloc memory in the controller]
   197 		TRAP( errorCode, 			
   198 			TMMFFileConfig fileConfig; // video file 
   199 			fileConfig().iPath = KTestAviFile;
   200 
   201 			//[ lets manufacture a source and sink ]
   202 			//[Create the source]
   203 			MDataSource* source = MDataSource::NewSourceL(KUidMmfFileSource, fileConfig);
   204 			CleanupDeletePushL(source);
   205 
   206 			//[ Create the sink ]
   207 			MDataSink* sink = MDataSink::NewSinkL(KUidMmfAudioOutput, KNullDesC8);
   208 			CleanupDeletePushL(sink);
   209 
   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);
   215 
   216 			//[ add the source ]
   217 			CAviPlayController::AddDataSourceL(*source);
   218 			 
   219 			//[ add the sink ]
   220 			CAviPlayController::AddDataSinkL(*sink);
   221 
   222 			CleanupStack::PopAndDestroy(3);// source, sink, cleanupItem
   223 		);
   224 		if( errorCode == KErrNone )
   225 			{
   226 			// [ check we have passed through all allocs in the test]
   227 			TAny* testAlloc = User::Alloc(1);
   228 			if( testAlloc == NULL )
   229 				{
   230 				reachedEnd = ETrue;
   231 				failCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc.
   232 				}
   233 			else 
   234 				{
   235 				User::Free( testAlloc );
   236 				}
   237 
   238 			completed = reachedEnd || badResult;
   239 			
   240 			}
   241 		else if( errorCode != KErrNoMemory && errorCode != KErrCorrupt) 
   242 			{
   243 			// [ we failed for some reason other than memory
   244 			//     allocation, so fail the test ]
   245 			completed = ETrue;
   246 			badResult = ETrue;
   247 			}
   248 		
   249 		__UHEAP_SETFAIL(RHeap::ENone ,0);
   250 		
   251 		// [ exit the loop ]
   252 		if( completed )
   253 			{
   254 			break;
   255 			}
   256 
   257 		failCount +=1;
   258 		}
   259 	if(!badResult)
   260 		{
   261 		aMessage.Complete(KErrNone);
   262 		}
   263 	else
   264 		{
   265 		aMessage.Complete(errorCode);
   266 		}
   267 	}
   268 
   269 /**
   270 *
   271 * DoMemoryAllocTest2
   272 *
   273 */
   274 void CCustomAviPlayController::DoPrepareMemoryAllocTest2(TMMFMessage& aMessage)
   275 	{
   276 	TRAPD(err, 
   277 		TMMFFileConfig fileConfig; // video file 
   278 		fileConfig().iPath = KTestAviFile;
   279 
   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);
   285 		
   286 		//[ lets manufacture a source and sink ]
   287 		//[Create the source]
   288 		if (iDataSource)
   289 			{
   290 			delete iDataSource;
   291 			iDataSource = NULL;
   292 			}
   293 		iDataSource = MDataSource::NewSourceL(KUidMmfFileSource, fileConfig);
   294 		
   295 		//[ Create the sink ]
   296 		if (iDataSink)
   297 			{
   298 			delete iDataSink;
   299 			iDataSink = NULL;
   300 			}
   301 		iDataSink = MDataSink::NewSinkL(KUidMmfAudioOutput, KNullDesC8);
   302 		
   303 		//[ add the source ]
   304 		CAviPlayController::AddDataSourceL(*iDataSource);
   305 		 
   306 		//[ add the sink ]
   307 		CAviPlayController::AddDataSinkL(*iDataSink);
   308 
   309 		CleanupStack::Pop(1);	// cleanupItem
   310 		);
   311 	aMessage.Complete(err);
   312 	}
   313 
   314 /**
   315 *
   316 * DoMemoryAllocTest3
   317 *
   318 */
   319 void CCustomAviPlayController::DoMemoryAllocTest3(TMMFMessage& aMessage)
   320 	{
   321 	__UHEAP_SETFAIL(RHeap::EFailNext ,iMemAllocPrimeFailCount);
   322 	TRAPD(err, 
   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);
   328 		
   329 		//[ play ]
   330 		CAviPlayController::PlayL();
   331 		 
   332 		//[ stop ]
   333 		CAviPlayController::StopL();
   334 		 
   335 		//[ reset ]	
   336 		CAviPlayController::ResetL();
   337 
   338 		CleanupStack::PopAndDestroy(1);	// cleanupItem
   339 		);
   340 	__UHEAP_SETFAIL(RHeap::ENone ,0);
   341 	aMessage.Complete(err);
   342 	}
   343 	
   344 /**
   345 *
   346 * DoSetPrimetTestEnable
   347 *
   348 */
   349 void CCustomAviPlayController::DoSetPrimetTestEnable(TMMFMessage& aMessage)
   350 	{
   351 	TPckgBuf<TBool> primeTestEnable;
   352 	TInt err = aMessage.ReadData1FromClient(primeTestEnable);
   353 	aMessage.Complete(err);
   354 	iMemAllocPrimeTestEnabled = primeTestEnable();
   355 	}
   356 
   357 /**
   358 *
   359 * DoSetPrimetTestFailCount
   360 *
   361 */
   362 void CCustomAviPlayController::DoSetPrimetTestFailCount(TMMFMessage& aMessage)
   363 	{
   364 	TPckgBuf<TInt> primeTestFailCount;
   365 	TInt err = aMessage.ReadData1FromClient(primeTestFailCount);
   366 	aMessage.Complete(err);
   367 	iMemAllocPrimeFailCount = primeTestFailCount();
   368 	}
   369