omxil/xmltestharness/xmlclient/src/omxscripttest.cpp
branchOpenMAX-IL_SHAI
changeset 16 eedf2dcd43c6
equal deleted inserted replaced
15:c1e808730d6c 16:eedf2dcd43c6
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "omxscripttest.h"
       
    19 #include "paramconversion.h"
       
    20 #include "statedes.h"
       
    21 
       
    22 #include "omxutil.h"
       
    23 #include "nontunneledhandler.h"
       
    24 
       
    25 #include "log.h"
       
    26 #include "omx_xml_script.h"
       
    27 #include "transition.h"
       
    28 #include "parsemap.h"
       
    29 #include <uri8.h>
       
    30 
       
    31 #include "baseprofilehandler.h"
       
    32 #include "baseprofiletimestamping.h"
       
    33 #include "windowmanager.h"
       
    34 
       
    35 
       
    36 //Logical IL headers
       
    37 //#include <openmax/logicalil/extensions/omxlilsymvidgraphicsinksurfaceidextns.h>
       
    38 //#include <openmax/logicalil/extensions/omxlilsymaudpcmextns.h>
       
    39 
       
    40 ///////////////////////////////////////////////////////////////////////////////
       
    41 // Temporary work-around for floating point issues on HREF 8500 ED hardware
       
    42 // Using this macro, code that uses TReal will be #defined out if running on ED.
       
    43 // TODO: Remove HREF_ED_WITHOUT_FLOATING_POINT and all of its conditional code
       
    44 // once the floating point issue has been solved.
       
    45 #if defined(NCP_COMMON_BRIDGE_FAMILY) && !defined(__WINSCW__)
       
    46 #define HREF_ED_WITHOUT_FLOATING_POINT
       
    47 #endif
       
    48 
       
    49 DECL_PARSETYPE(OMX_EVENTTYPE);
       
    50 
       
    51 _LIT8(KILTypeString, "LOGICAL");
       
    52 
       
    53 static TInt StopScheduler(TAny* unused);
       
    54 
       
    55 /**
       
    56  * Runs an OMX test specified in an XML file.
       
    57  * @param aScriptFilename path to XML file
       
    58  * @param aScriptSection section name in XML file
       
    59  */
       
    60 void ROmxScriptTest::RunTestL(const TDesC& aScriptFilename, const TDesC& aScriptSection)
       
    61 	{
       
    62 	User::LeaveIfError(iEventHandler.Create());
       
    63 	iStopSchedulerCallback = new(ELeave) CAsyncCallBack(StopScheduler, CActive::EPriorityHigh);
       
    64 	
       
    65 	RFs fs;
       
    66 	User::LeaveIfError(fs.Connect());
       
    67 	CleanupClosePushL(fs);
       
    68 
       
    69 	INFO_PRINTF3(_L("Executing test steps in section %S of %S"), &aScriptSection, &aScriptFilename);
       
    70 	
       
    71 	TPtrC filename;
       
    72 	COmxScriptParser* parser = COmxScriptParser::NewL(fs, aScriptFilename, *this);
       
    73 	CleanupStack::PushL(parser);
       
    74 	
       
    75 	// this drives the methods from MOmxScriptIf
       
    76 	TBool success = parser->RunScriptL(aScriptSection);
       
    77 	if(success)
       
    78 		{
       
    79 		StopTest(EPass);
       
    80 		}
       
    81 	else
       
    82 		{
       
    83 		ERR_PRINTF1(_L("Script did not complete"));
       
    84 		StopTest(EFail);
       
    85 		}
       
    86 	
       
    87 	CleanupStack::PopAndDestroy(2, &fs);	// fs, parser
       
    88 	
       
    89 	User::LeaveIfError(Reason());
       
    90 	}
       
    91 
       
    92 /**
       
    93  * Constructs an object to parse and execute an OMX test case specified in
       
    94  * an XML file.
       
    95  * @param reference to logger interface to receive test messages
       
    96  */
       
    97 ROmxScriptTest::ROmxScriptTest(MOmxScriptTestLogger& aLogger):
       
    98 	iCoreLoaded(EFalse),
       
    99 	iEventHandler(*this),
       
   100 	iState(OMX_StateLoaded),
       
   101 	iWindowManager(NULL),
       
   102 	iVideoFitMode(EVideoFitRotateScaleAndCentre),
       
   103 	iTimer(NULL),
       
   104 	iWaitingForEvents(EFalse),
       
   105 	iNonTunneledHandler(NULL),
       
   106 	iBufferHandler(NULL),
       
   107 	iBufferSinkHandler(NULL),
       
   108 	iReason(KErrNone),
       
   109 	iVerdict(EPending),
       
   110 	iLogger(aLogger),
       
   111 	iStopSchedulerCallback(NULL),
       
   112     iPortBufferHandler(NULL)
       
   113 	{
       
   114 	}
       
   115 
       
   116 /**
       
   117  * Destroys all resources created by this object. 
       
   118  */
       
   119 void ROmxScriptTest::Close()
       
   120 	{
       
   121 	// release memory and unload components
       
   122 	// ~CComponentInfo unloads component in correct thread
       
   123 	iComponents.ResetAndDestroy();
       
   124 	
       
   125 	if(iCoreLoaded)
       
   126 		{
       
   127 		INFO_PRINTF1(_L("OMX_Deinit()"));
       
   128 		iCoreLoaded = EFalse;
       
   129 		OMX_ERRORTYPE error = OMX_Deinit();
       
   130 		if(error)
       
   131 			{
       
   132 			FailWithOmxError(_L("OMX_Deinit"), error);
       
   133 			}
       
   134 		}
       
   135 	REComSession::FinalClose();
       
   136 	iEventHandler.Close();
       
   137 	delete iWindowManager;
       
   138 	iWindowManager = NULL;
       
   139 	iState = OMX_StateLoaded;
       
   140 	
       
   141 	if (iTimer)
       
   142 		{
       
   143 		iTimer->Cancel();
       
   144 		delete iTimer;
       
   145 		iTimer = NULL;
       
   146 		}
       
   147 	
       
   148 	iExpectedEvents.Close();
       
   149 	iIgnoredEvents.Close();
       
   150 	
       
   151 	if (iNonTunneledHandler)
       
   152 		{
       
   153 		delete iNonTunneledHandler;
       
   154 		iNonTunneledHandler = NULL;
       
   155 		}
       
   156 	
       
   157    if(iPortBufferHandler)
       
   158        {
       
   159        delete iPortBufferHandler;
       
   160        iPortBufferHandler = NULL;
       
   161        }
       
   162 	
       
   163 	delete iStopSchedulerCallback;
       
   164 	iStopSchedulerCallback = NULL;
       
   165 	
       
   166 	iTunnels.Close();
       
   167 	}
       
   168 
       
   169 // allows OMX components to be placed on the cleanup stack
       
   170 //void ROmxScriptTest::CleanupOmxComponent(TAny* aPtr)
       
   171 //	{
       
   172 //	OMX_COMPONENTTYPE* component = static_cast<OMX_COMPONENTTYPE*>(aPtr);
       
   173 //	OMX_ERRORTYPE error = OMX_FreeHandle(component);
       
   174 //	// if this method is called, we are already in an error condition,
       
   175 //	// but OMX_FreeHandle should still succeed. Perhaps a cleaner way of
       
   176 //	// reporting any error is desired, but this is a static method so we
       
   177 //	// lack the context to call the standard logging mechanism.
       
   178 //	__ASSERT_DEBUG(!error, User::Invariant());
       
   179 //	}
       
   180 
       
   181 TBool ROmxScriptTest::MosLoadComponentL(const TDesC8& aComp, const TDesC8& aName, TBool aBaseProfile, const TDesC8* aBaseImpl, TBool aLoadInCoreServerThread)
       
   182 	{
       
   183 	if(!iCoreLoaded)
       
   184 		{
       
   185 		INFO_PRINTF1(_L("OMX_Init()"));
       
   186 		OMX_ERRORTYPE error = OMX_Init();
       
   187 		if(error)
       
   188 			{
       
   189 			CleanupStack::PopAndDestroy(2);
       
   190 			FailWithOmxError(_L("OMX_Init()"), error);
       
   191 			return EFalse;
       
   192 			}
       
   193 		iCoreLoaded = ETrue;
       
   194 		}
       
   195 	
       
   196 	// convert from 8-bit descriptor for logging
       
   197 	TBuf<64> nameCopy;
       
   198 	nameCopy.Copy(aName);
       
   199 	INFO_PRINTF2(_L("Loading component %S"), &nameCopy);
       
   200 
       
   201 	CComponentInfo* componentInfo = CComponentInfo::NewL(*this);
       
   202 	CleanupStack::PushL(componentInfo);
       
   203 	componentInfo->iShortName = HBufC8::NewL(aComp.Length());
       
   204 	*(componentInfo->iShortName) = aComp;
       
   205 	// allow room for the '\0' used in call to OMX_GetHandle
       
   206 	componentInfo->iComponentName = HBufC8::NewL(aName.Length() + 1);
       
   207 	*(componentInfo->iComponentName) = aName;
       
   208 	
       
   209 
       
   210 	OMX_ERRORTYPE error = OMX_ErrorNone;
       
   211 	if (aBaseProfile)
       
   212 	    {
       
   213 	    if (*aBaseImpl == _L8("base"))
       
   214 	        {
       
   215 	        componentInfo->iBaseHandler = new (ELeave) CBaseProfileHandler(*this, iEventHandler);
       
   216 	        componentInfo->iComponent = componentInfo->iBaseHandler->LoadComponentL(*componentInfo->iShortName, *componentInfo->iComponentName);
       
   217 	        
       
   218 	        }
       
   219 	    else if (*aBaseImpl == _L8("timestampcheck"))
       
   220             {
       
   221             componentInfo->iBaseHandler = new (ELeave) CBaseProfileTimestampHandling(*this, iEventHandler);
       
   222             componentInfo->iComponent = componentInfo->iBaseHandler->LoadComponentL(*componentInfo->iShortName, *componentInfo->iComponentName);
       
   223             
       
   224             }
       
   225 
       
   226 	    }
       
   227 	else
       
   228         {
       
   229         OMX_CALLBACKTYPE& callbacks = iEventHandler.CallbackStruct();
       
   230         // NOTE componentInfo.iShortName and componentInfo.iComponentName still on the cleanup stack
       
   231         
       
   232         if(aLoadInCoreServerThread)
       
   233             {
       
   234             INFO_PRINTF2(_L("Loading component %S in Core Server thread"), &nameCopy);
       
   235             if(componentInfo->iThreadRequest == NULL)
       
   236                 {
       
   237                 componentInfo->iThreadRequest = COmxThreadRequest::NewL();
       
   238                 }
       
   239             error = componentInfo->iThreadRequest->GetHandle((TAny**) &(componentInfo->iComponent), (OMX_STRING) componentInfo->iComponentName->Des().PtrZ(), &iEventHandler, &callbacks);
       
   240             }
       
   241         else
       
   242             {
       
   243             INFO_PRINTF2(_L("Loading component %S in Client thread"), &nameCopy);
       
   244             error = OMX_GetHandle((TAny**) &(componentInfo->iComponent), (OMX_STRING) componentInfo->iComponentName->Des().PtrZ(), &iEventHandler, &callbacks);
       
   245             }
       
   246         }
       
   247 	if(error || (componentInfo->iComponent == NULL))
       
   248 		{
       
   249 		CleanupStack::PopAndDestroy();	// delete component info
       
   250 		FailWithOmxError(_L("OMX_GetHandle()"), error);
       
   251 		return EFalse;
       
   252 		}
       
   253 
       
   254 	RDebug::Print(_L("OMX_GetHandle name=%S handle=0x%08X"), &nameCopy, componentInfo->iComponent);
       
   255 	iEventHandler.AddComponentL(componentInfo->iComponent, nameCopy);
       
   256 	iComponents.AppendL(componentInfo);
       
   257 	CleanupStack::Pop(1, componentInfo);
       
   258 	return ETrue;
       
   259 	}
       
   260 
       
   261 TBool ROmxScriptTest::MosSetupTunnel(const TDesC8& aSourceComp, TInt aSourcePort,
       
   262                                      const TDesC8& aSinkComp, TInt aSinkPort, OMX_ERRORTYPE aExpectedError)
       
   263 	{
       
   264 	OMX_COMPONENTTYPE* source = NULL;
       
   265 	OMX_COMPONENTTYPE* sink = NULL;
       
   266 	if(aSourceComp!=KNullDesC8)
       
   267 		{
       
   268 		source = ComponentByName(aSourceComp);
       
   269 		}
       
   270 	
       
   271 	if(aSinkComp!=KNullDesC8)
       
   272 		{
       
   273 		sink = ComponentByName(aSinkComp);
       
   274 		}
       
   275 	 
       
   276 	//support for testing tunnel breakup
       
   277 	if(source || sink)
       
   278 		{
       
   279 		OMX_ERRORTYPE error = OMX_SetupTunnel(source, aSourcePort, sink, aSinkPort);
       
   280 		// TODO check tunnel reconfiguration
       
   281 		if(error == OMX_ErrorNone)
       
   282 			{
       
   283 			RegisterTunnel(source, aSourcePort, sink, aSinkPort);
       
   284 			}
       
   285 		if(error != aExpectedError)
       
   286 			{
       
   287 			ERR_PRINTF3(_L("MosSetupTunnel OMX_SetupTunnel: Error 0x%X does not match expected error 0x%X"), error, aExpectedError);
       
   288 			TBuf8<64> msg8;
       
   289 			msg8.Format(_L8("source=%S:%d sink=%S:%d"), &aSourceComp, aSourcePort, &aSinkComp, aSinkPort);
       
   290 			TBuf<64> msg;
       
   291 			msg.Copy(msg8);
       
   292 			INFO_PRINTF1(msg);
       
   293 			return EFalse;
       
   294 			}
       
   295 		return ETrue;
       
   296 		}
       
   297 	else
       
   298 		{
       
   299 		// source or sink names not recognized
       
   300 		return EFalse;
       
   301 		}
       
   302 	}
       
   303 
       
   304 TBool ROmxScriptTest::MosSetupNonTunnel(const TDesC8& aSourceComp, TInt aSourcePort,
       
   305                                         const TDesC8& aSinkComp, TInt aSinkPort,
       
   306                                         OMX_BUFFERSUPPLIERTYPE aSupplier)
       
   307 	{
       
   308 	OMX_COMPONENTTYPE* source = ComponentByName(aSourceComp);
       
   309 	OMX_COMPONENTTYPE* sink = ComponentByName(aSinkComp);
       
   310 	if(source && sink)
       
   311 		{
       
   312 		OMX_PARAM_PORTDEFINITIONTYPE portDef;
       
   313 		portDef.nSize = sizeof(portDef);
       
   314 		portDef.nVersion = KOmxVersion;
       
   315 		portDef.nPortIndex = aSourcePort;
       
   316 		OMX_ERRORTYPE error = source->GetParameter(source, OMX_IndexParamPortDefinition, &portDef);
       
   317 		if(error != OMX_ErrorNone)
       
   318 			{
       
   319 			FailWithOmxError(_L("GetParameter"), error);
       
   320 			return EFalse;
       
   321 			}
       
   322 
       
   323 		TInt numBufs = portDef.nBufferCountActual;
       
   324 		TInt bufSize = portDef.nBufferSize;
       
   325 
       
   326 		portDef.nPortIndex = aSinkPort;
       
   327 		error = sink->GetParameter(sink, OMX_IndexParamPortDefinition, &portDef);
       
   328 		if(error != OMX_ErrorNone)
       
   329 			{
       
   330 			FailWithOmxError(_L("GetParameter"), error);
       
   331 			return EFalse;
       
   332 			}
       
   333 		
       
   334 		if (portDef.nBufferCountActual != numBufs)
       
   335 			{
       
   336 			ERR_PRINTF1(_L("Number of buffers does not match for non tunneled setup"));
       
   337 			return EFalse;
       
   338 			}
       
   339 
       
   340 		if (portDef.nBufferSize > bufSize)
       
   341 			{
       
   342 			bufSize = portDef.nBufferSize;
       
   343 			}
       
   344 
       
   345 		if (!iNonTunneledHandler)
       
   346 			{
       
   347 			iNonTunneledHandler = new CNonTunneledHandler();
       
   348 
       
   349 			if (!iNonTunneledHandler)
       
   350 				{
       
   351 				return EFalse;
       
   352 				}
       
   353 			}
       
   354 
       
   355 		TRAPD(err, iNonTunneledHandler->AddLinkL(source, aSourcePort, sink, aSinkPort, aSupplier, numBufs, bufSize));
       
   356 		if (err != KErrNone)
       
   357 			return EFalse;
       
   358 
       
   359 		return ETrue;
       
   360 		}
       
   361 	else
       
   362 		{
       
   363 		// source or sink names not recognized
       
   364 		return EFalse;
       
   365 		}
       
   366 	}
       
   367 
       
   368 
       
   369 TBool ROmxScriptTest::MosSetupBufferForPortL(const TDesC8& aComp,TInt aPortIndex, const TDesC& aFileName,TInt aHeaderLength,OMX_BUFFERSUPPLIERTYPE aSupplier)
       
   370     {
       
   371     TBuf<64> compConverted;
       
   372     compConverted.Copy(aComp);
       
   373     INFO_PRINTF3(_L("MosSetupBufferForPort comp %S port %d"), &compConverted, aPortIndex);
       
   374     OMX_COMPONENTTYPE* comp = ComponentByName(aComp);
       
   375     
       
   376     if(comp)
       
   377         {
       
   378         OMX_PARAM_PORTDEFINITIONTYPE portDef;
       
   379         portDef.nSize = sizeof(portDef);
       
   380         portDef.nVersion = KOmxVersion;
       
   381         portDef.nPortIndex = aPortIndex;
       
   382         OMX_ERRORTYPE error = comp->GetParameter(comp, OMX_IndexParamPortDefinition, &portDef);
       
   383         if(error != OMX_ErrorNone)
       
   384             {
       
   385             FailWithOmxError(_L("GetParameter"), error);
       
   386             return EFalse;
       
   387             }
       
   388 
       
   389         OMX_DIRTYPE portDirType = portDef.eDir;
       
   390 
       
   391         if(!iPortBufferHandler)
       
   392             {
       
   393             iPortBufferHandler = new (ELeave)CPortBufferHandler;
       
   394             }
       
   395         
       
   396         iPortBufferHandler->AddPortL(comp,aPortIndex,aFileName,aSupplier,portDirType,iLogger,aHeaderLength);
       
   397         }
       
   398     return ETrue;    
       
   399     }
       
   400 
       
   401 TBool ROmxScriptTest::MosAllTransitionL(OMX_STATETYPE aState, OMX_ERRORTYPE aExpectedError, TTransitionOrder aOrder)
       
   402 	{
       
   403 	INFO_PRINTF2(_L("Transitioning all components to %S"), StateDes(aState));
       
   404 	if(aOrder == ELoadOrder && aState == OMX_StateIdle && iState == OMX_StateLoaded)
       
   405 		{
       
   406 		WARN_PRINTF1(_L("Using component load order for loaded -> idle transition order"));
       
   407 		}
       
   408 	iEventHandler.AwaitTransition(aState, iState);
       
   409 	RArray<TInt> order;
       
   410 	CleanupClosePushL(order);
       
   411 	order.ReserveL(iComponents.Count());
       
   412 	if(aOrder == ELoadOrder)
       
   413 		{
       
   414 		for(TInt index = 0; index < iComponents.Count(); index++)
       
   415 			{
       
   416 			order.Append(index);
       
   417 			}
       
   418 		}
       
   419 	else if(aOrder == EAutoOrder)
       
   420 		{
       
   421 		TRAPD(error, FindTransitionOrderL(iComponents, iTunnels, order));
       
   422 		if(error != KErrNone)
       
   423 			{
       
   424 			ERR_PRINTF2(_L("Error determining transition order, error=%d"), error);
       
   425 			User::Leave(error);
       
   426 			}
       
   427 		}
       
   428 	
       
   429 	if(aState == OMX_StateIdle && iState == OMX_StateExecuting)
       
   430 		{
       
   431 		// use reverse order for Idle->Executing transition
       
   432 		TInt left = 0, right = order.Count() - 1;
       
   433 		while(left < right)
       
   434 			{
       
   435 			TInt tmp = order[left];
       
   436 			order[left] = order[right];
       
   437 			order[right] = tmp;
       
   438 			left++;
       
   439 			right--;
       
   440 			}
       
   441 		}
       
   442 	
       
   443 	if(aOrder == EAutoOrder)
       
   444 		{
       
   445 		TBuf<128> orderDes;
       
   446 		for(TInt index = 0, count = order.Count(); index < count; index++)
       
   447 			{
       
   448 			HBufC8* name8 = iComponents[order[index]]->iShortName;
       
   449 			TBuf<16> name;
       
   450 			name.Copy(*name8);
       
   451 			if(index > 0)
       
   452 				{
       
   453 				orderDes.Append(_L(", "));
       
   454 				}
       
   455 			orderDes.Append(name);
       
   456 			}
       
   457 		INFO_PRINTF2(_L("Auto-detected transition order: %S"), &orderDes);
       
   458 		}
       
   459 	
       
   460 	TBool commandError = EFalse;
       
   461 	TBool ret = EFalse;
       
   462 	for(TInt orderIndex = 0, count = order.Count(); orderIndex < count; orderIndex++)
       
   463 		{
       
   464 		TInt index = order[orderIndex];
       
   465 		CComponentInfo* compInfo = iComponents[index];
       
   466 		OMX_COMPONENTTYPE* component = compInfo->iComponent;
       
   467 		OMX_ERRORTYPE error = component->SendCommand(component, OMX_CommandStateSet, aState, NULL);
       
   468 		if(error)
       
   469 			{
       
   470 			TBuf<128> msg;
       
   471 			msg.Format(_L("SendCommand(OMX_CommandStateSet, %S)"), StateDes(aState));
       
   472 			if(error != aExpectedError)
       
   473 				{
       
   474 				FailWithOmxError(compInfo->iShortName->Des(), msg, error);
       
   475 				ret = EFalse;
       
   476 				}
       
   477 			else //Need to stop the tests now be cause an error has occurred, even if it is expected.
       
   478 				{
       
   479 				StopTest(EPass);
       
   480 				ret = ETrue;
       
   481 				}
       
   482 			commandError = ETrue;
       
   483 			break;
       
   484 			}
       
   485 
       
   486 		if (!HandleNonTunneledBuffers(aState, component))
       
   487 			{
       
   488 			commandError = ETrue;
       
   489 			ret = EFalse;
       
   490 			break;
       
   491 			}
       
   492 	if(!HandlePortBufferHandler(aState, component))
       
   493 		    {
       
   494 		    return EFalse;
       
   495 		    }
       
   496 		}
       
   497 	CleanupStack::PopAndDestroy(&order);
       
   498 	if(commandError)
       
   499 		{
       
   500 		return ret;
       
   501 		}
       
   502 	
       
   503 	// wait for the transitions to complete
       
   504 	// use a nested loop of the active scheduler
       
   505 	// AllComponentsTransitioned() calls EndWait() 
       
   506 	BeginWait();
       
   507 	return Reason() == KErrNone;
       
   508 	}
       
   509 	
       
   510 TBool ROmxScriptTest::MosTransition(const TDesC8& aComp, OMX_STATETYPE aState, TBool aAsync)
       
   511 	{
       
   512 	TBuf<64> compConverted;
       
   513 	compConverted.Copy(aComp);
       
   514 	INFO_PRINTF3(_L("Transitioning %S component to %S"), &compConverted, StateDes(aState));
       
   515 
       
   516 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
   517 	if(!component)
       
   518 		{
       
   519 		return EFalse;
       
   520 		}
       
   521 
       
   522 	if (!aAsync)
       
   523 		{
       
   524 		iEventHandler.AwaitSingleTransition(component, aState, iState);
       
   525 		}
       
   526 	else
       
   527 		{
       
   528 		//Don't want to force a wait on this state transition so instead of using the event handler add the event to the expected list
       
   529 		TExpectedEvent event;
       
   530 		event.iComponent = component;
       
   531 		event.iEvent = OMX_EventCmdComplete;
       
   532 		event.iData1 = OMX_CommandStateSet;
       
   533 		event.iData2 = aState;
       
   534 		event.iEventData = NULL;
       
   535 		TRAPD(err, iExpectedEvents.AppendL(event));
       
   536 		if (err != KErrNone)
       
   537 			return EFalse;
       
   538 		}
       
   539 		
       
   540 	OMX_ERRORTYPE error = component->SendCommand(component, OMX_CommandStateSet, aState, NULL);
       
   541 	if(error)
       
   542 		{
       
   543 		FailWithOmxError(_L("SendCommand(OMX_CommandStateSet)"), error);
       
   544 		return EFalse;
       
   545 		}
       
   546 
       
   547 	if (!HandleNonTunneledBuffers(aState, component))
       
   548 		{
       
   549 		return EFalse;
       
   550 		}
       
   551 	
       
   552 	if(!HandlePortBufferHandler(aState, component))
       
   553          {
       
   554          return EFalse;
       
   555          }
       
   556 		
       
   557 	if (!aAsync)
       
   558 		{
       
   559 		BeginWait();
       
   560 		}
       
   561 	return Reason() == KErrNone;
       
   562 	}	
       
   563 
       
   564 TBool ROmxScriptTest::MosFailingTransition(const TDesC8& aComp, OMX_STATETYPE aState,OMX_ERRORTYPE aExpectedError)
       
   565 	{
       
   566 	TBuf<64> compConverted;
       
   567 	compConverted.Copy(aComp);
       
   568 	INFO_PRINTF3(_L("Transitioning %S component to %S"), &compConverted, StateDes(aState));
       
   569 
       
   570 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
   571 	if(!component)
       
   572 		{
       
   573 		return EFalse;
       
   574 		}
       
   575 
       
   576 	OMX_ERRORTYPE error = component->SendCommand(component, OMX_CommandStateSet, aState, NULL);
       
   577 	if(error == aExpectedError)
       
   578 		{
       
   579 		return ETrue;
       
   580 		}
       
   581 	else
       
   582 		{
       
   583 		return EFalse;
       
   584 		}
       
   585 	}
       
   586 
       
   587 TBool ROmxScriptTest::MosWaitEOS()
       
   588 	{
       
   589 	// AllComponentsEOS() calls EndWait()
       
   590 	INFO_PRINTF1(_L("Waiting for End of Stream from all components"));
       
   591 	iEventHandler.AwaitEOS();
       
   592 	BeginWait();
       
   593 	return ETrue;
       
   594 	}
       
   595 
       
   596 TBool ROmxScriptTest::MosWaitEOS(const TDesC8& aComp)
       
   597 	{
       
   598 	// AllComponentsEOS() calls EndWait()
       
   599 	TBuf<16> comp16;
       
   600 	comp16.Copy(aComp);
       
   601 	INFO_PRINTF2(_L("Waiting for End of Stream from component %S"), &comp16);
       
   602 	OMX_COMPONENTTYPE* compHandle = ComponentByName(aComp);
       
   603 	if(compHandle == NULL)
       
   604 		{
       
   605 		return EFalse;
       
   606 		}
       
   607 	iEventHandler.AwaitEOS(compHandle);
       
   608 	BeginWait();
       
   609 	return ETrue;
       
   610 	}
       
   611 
       
   612 TBool ROmxScriptTest::MosWaitL(TTimeIntervalMicroSeconds32 aDelay)
       
   613 	{
       
   614 	if (iTimer)
       
   615 		{
       
   616 		iTimer->Cancel();
       
   617 		}
       
   618 	else
       
   619 		{
       
   620 		iTimer = CVideoTestTimer::NewL(*this);		
       
   621 		}	
       
   622 	
       
   623 	iTimer->Start(aDelay);
       
   624 	BeginWait();
       
   625 	return ETrue;		
       
   626 	}
       
   627 
       
   628 TBool ROmxScriptTest::MosExpectEventL(const TDesC8& aComp, OMX_EVENTTYPE aEvent, TUint32 aData1, TUint32 aData2)
       
   629 	{
       
   630 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
   631 	if(!component)
       
   632 		{
       
   633 		return EFalse;
       
   634 		}
       
   635 	
       
   636 	TExpectedEvent event;	
       
   637 	event.iComponent = component;
       
   638 	event.iEvent = aEvent;
       
   639 	event.iData1 = aData1;
       
   640 	event.iData2 = aData2;
       
   641 	event.iEventData = NULL;
       
   642 	iExpectedEvents.AppendL(event);
       
   643 
       
   644 	return ETrue;
       
   645 	}
       
   646 
       
   647 TBool ROmxScriptTest::MosWaitForAllEventsL()
       
   648 	{
       
   649 	if(iExpectedEvents.Count() > 0)
       
   650 		{
       
   651 		iWaitingForEvents = ETrue;
       
   652 		BeginWait();
       
   653 		iWaitingForEvents = EFalse;
       
   654 		__ASSERT_ALWAYS(iExpectedEvents.Count() == 0, User::Invariant());
       
   655 		}
       
   656 	return ETrue;
       
   657 	}
       
   658 
       
   659 TBool ROmxScriptTest::MosSetFilename(const TDesC8& aComp, const TDesC& aFilename)
       
   660 	{
       
   661 	TBuf<64> compConverted;
       
   662 	compConverted.Copy(aComp);
       
   663 	INFO_PRINTF3(_L("Setting filename on component %S to %S"), &compConverted, &aFilename);
       
   664 	
       
   665 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
   666 	if(!component)
       
   667 		{
       
   668 		return EFalse;
       
   669 		}
       
   670 	
       
   671 	OMX_PARAM_CONTENTURITYPE* contentURI = NULL;
       
   672 	TRAPD(err, contentURI = ParamConversion::FilenameAsContentUriStructV1_1L(aFilename));
       
   673 	if(err==KErrBadName)//logical IL tests pass just the filename. so try adding the directory path
       
   674 	    {
       
   675 	    TBuf<64> fileName;
       
   676 	    fileName.Copy(KPortDirectoryPath);
       
   677 	    fileName.Append(aFilename);
       
   678 	    err=KErrNone;
       
   679 	    TRAP(err, contentURI = ParamConversion::FilenameAsContentUriStructV1_1L(fileName));
       
   680 	    }
       
   681 	if(err)
       
   682 	  {
       
   683 	  ERR_PRINTF2(_L("Error converting filename to OMX_CONTENTURI (%d)"), err);
       
   684 	  return EFalse;
       
   685 	  }
       
   686 	OMX_ERRORTYPE error = component->SetParameter(component, OMX_IndexParamContentURI, contentURI);
       
   687 	delete contentURI;
       
   688 	if(error)
       
   689 		{
       
   690 		FailWithOmxError(_L("SetParameter(OMX_IndexParamContentURI)"), error);
       
   691 		return EFalse;
       
   692 		}
       
   693 	else
       
   694 		{
       
   695 		return ETrue;
       
   696 		}
       
   697 	}
       
   698 
       
   699 TBool ROmxScriptTest::MosSetBadFilename(const TDesC8& aComp)
       
   700 	{
       
   701 	TBuf<64> compConverted;
       
   702 	compConverted.Copy(aComp);
       
   703 	INFO_PRINTF2(_L("Setting filename on component %S"), &compConverted);
       
   704 
       
   705 	TText8 cstr[6] =  {':', 'e' ,'l' ,'l' ,'o','\0'};
       
   706 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
   707 	if(!component)
       
   708 		{
       
   709 		return EFalse;
       
   710 		}
       
   711 	OMX_PARAM_CONTENTURITYPE* contentURI = reinterpret_cast<OMX_PARAM_CONTENTURITYPE*>(new TUint8[15]);
       
   712 	if (!contentURI)
       
   713 		return EFalse;
       
   714 		
       
   715 	TPtr8 uriStructDes(contentURI->contentURI, sizeof(cstr));
       
   716 	uriStructDes = cstr;
       
   717 
       
   718 	OMX_ERRORTYPE error = component->SetParameter(component, OMX_IndexParamContentURI, contentURI);
       
   719 	delete contentURI;
       
   720 	
       
   721 	return ETrue;
       
   722 
       
   723 	}
       
   724 
       
   725 TBool ROmxScriptTest::MosGetFilename(const TDesC8& aComp, TDesC& aFilename)
       
   726 	{
       
   727 	TBuf<64> compConverted;
       
   728 	compConverted.Copy(aComp);
       
   729 	INFO_PRINTF2(_L("Getting filename on component %S"), &compConverted);
       
   730 	
       
   731 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
   732 	if(!component)
       
   733 		{
       
   734 		return EFalse;
       
   735 		}
       
   736 	OMX_PARAM_CONTENTURITYPE* contentURI = NULL;
       
   737 	TRAPD(err, contentURI = ParamConversion::FilenameAsContentUriStructV1_1L(aFilename));
       
   738 	if(err)
       
   739 		{
       
   740 		ERR_PRINTF2(_L("Error converting filename to OMX_CONTENTURI (%d)"), err);
       
   741 		return EFalse;
       
   742 		}
       
   743 	OMX_ERRORTYPE error = component->GetParameter(component, OMX_IndexParamContentURI, contentURI);
       
   744 	delete contentURI;
       
   745 	if((error != OMX_ErrorNone) && (error != OMX_ErrorOverflow) && (error != OMX_ErrorUnsupportedSetting))
       
   746 		{
       
   747 		FailWithOmxError(_L("GetParameter(OMX_IndexParamContentURI)"), error);
       
   748 		return EFalse;
       
   749 		}
       
   750 	else
       
   751 		{
       
   752 		return ETrue;
       
   753 		}
       
   754 	}
       
   755 
       
   756 
       
   757 void ROmxScriptTest::FormatHex(const TDesC8& bin, TDes& hex)
       
   758 	{
       
   759 	__ASSERT_DEBUG(hex.MaxLength() == bin.Length() * 2, User::Invariant());
       
   760 	hex.SetLength(0);
       
   761 	for(TInt index = 0, length = bin.Length(); index < length; index++)
       
   762 		{
       
   763 		TUint8 octet = bin[index];
       
   764 		hex.AppendFormat(_L("%02X"), octet);
       
   765 		}
       
   766 	}
       
   767 
       
   768 TBool ROmxScriptTest::MosSetBufferCount(const TDesC8& aComp, TInt aPortIndex, TInt aCount, OMX_ERRORTYPE aExpectedError)
       
   769 	{
       
   770 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
   771 	if(!component)
       
   772 		{
       
   773 		return EFalse;
       
   774 		}
       
   775 	
       
   776 	OMX_PARAM_PORTDEFINITIONTYPE portDef;
       
   777 	portDef.nVersion = KOmxVersion;
       
   778 	portDef.nSize = sizeof(portDef);
       
   779 	portDef.nPortIndex = aPortIndex;
       
   780 	
       
   781 	OMX_ERRORTYPE error = component->GetParameter(component, OMX_IndexParamPortDefinition, &portDef);
       
   782 	if(error)
       
   783 		{
       
   784 		FailWithOmxError(_L("OMX_GetParameter()"), error);
       
   785 		return EFalse;
       
   786 		}
       
   787 
       
   788 	portDef.nBufferCountActual = aCount;
       
   789 	
       
   790 	INFO_PRINTF3(_L("MosSetBufferCount count %d; dir %d"), portDef.nBufferCountActual, portDef.eDir);
       
   791 
       
   792 	error = component->SetParameter(component, OMX_IndexParamPortDefinition, &portDef);
       
   793 	if(aExpectedError != error)
       
   794 		{
       
   795 		ERR_PRINTF3(_L("MosSetBufferCount OMX_SetParameter() error 0x%X, expecting 0x%X"), error, aExpectedError);
       
   796 		return EFalse;
       
   797 		}
       
   798 	return ETrue;
       
   799 	}
       
   800 
       
   801 
       
   802 TBool ROmxScriptTest::MosBufferSupplierOverrideL(
       
   803     const TDesC8& aSourceComp, 
       
   804     TInt aSourcePort,
       
   805 	const TDesC8& aSinkComp, TInt aSinkPort,
       
   806 	OMX_BUFFERSUPPLIERTYPE aSupplier, 
       
   807 	OMX_ERRORTYPE aExpectedSourceError,
       
   808 	OMX_ERRORTYPE aExpectedSinkError
       
   809 	)
       
   810 	{
       
   811 	OMX_COMPONENTTYPE* source = ComponentByName(aSourceComp);
       
   812 	OMX_COMPONENTTYPE* sink = ComponentByName(aSinkComp);
       
   813 	if(!source || !sink)
       
   814 		{
       
   815 		return EFalse;
       
   816 		}
       
   817 	
       
   818 	OMX_PARAM_BUFFERSUPPLIERTYPE param;
       
   819 	param.nSize = sizeof(param);
       
   820 	param.nVersion = KOmxVersion;
       
   821 	param.nPortIndex = aSourcePort;
       
   822 	param.eBufferSupplier = aSupplier;
       
   823 	OMX_ERRORTYPE error = source->SetParameter(source, OMX_IndexParamCompBufferSupplier, &param);
       
   824 	if(error != aExpectedSourceError)
       
   825 		{
       
   826 		ERR_PRINTF3(_L("MosBufferSupplierOverrideL source->SetParameter error 0x%X, expected 0x%X"), error, aExpectedSourceError);
       
   827 		return EFalse;
       
   828 		}
       
   829 
       
   830 	param.nPortIndex = aSinkPort;
       
   831 	error = sink->SetParameter(sink, OMX_IndexParamCompBufferSupplier, &param);
       
   832 	if(error != aExpectedSinkError)
       
   833 		{
       
   834 		ERR_PRINTF3(_L("MosBufferSupplierOverrideL sink->SetParameter error 0x%X, expected 0x%X"), error, aExpectedSinkError);
       
   835 		return EFalse;
       
   836 		}
       
   837 	return ETrue;
       
   838 	}
       
   839 
       
   840 
       
   841 TBool ROmxScriptTest::MosSetVideoPortDefL(const TDesC8& aComp, TInt aPortIndex, TInt aWidth, TInt aHeight, OMX_COLOR_FORMATTYPE* aColorFormat, OMX_VIDEO_CODINGTYPE* aCodingType, TInt aStride, TReal aFps, OMX_ERRORTYPE aExpectedError)
       
   842 	{
       
   843 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
   844 	if(!component)
       
   845 		{
       
   846 		return EFalse;
       
   847 		}
       
   848 	
       
   849 	OMX_PARAM_PORTDEFINITIONTYPE portDef;
       
   850 	portDef.nSize = sizeof(portDef);
       
   851 	portDef.nVersion = KOmxVersion;
       
   852 	portDef.nPortIndex = aPortIndex;
       
   853 	OMX_ERRORTYPE error = component->GetParameter(component, OMX_IndexParamPortDefinition, &portDef);
       
   854 	if(error)
       
   855 		{
       
   856 		FailWithOmxError(_L("GetParameter()"), error);
       
   857 		return EFalse;
       
   858 		}
       
   859 	if(aWidth != -1)
       
   860 		{
       
   861 		portDef.format.video.nFrameWidth = aWidth;
       
   862 		}
       
   863 	if(aHeight != -1)
       
   864 		{
       
   865 		portDef.format.video.nFrameHeight = aHeight;
       
   866 		}
       
   867 	
       
   868 	if (aColorFormat)
       
   869 		{
       
   870 		portDef.format.video.eColorFormat = *aColorFormat;
       
   871 		}
       
   872 
       
   873 	if (aCodingType)
       
   874 		{
       
   875 		portDef.format.video.eCompressionFormat = *aCodingType;
       
   876 		}
       
   877 		
       
   878 	if(aStride != -1)
       
   879 		{
       
   880 		portDef.format.video.nStride = aStride;
       
   881 		}
       
   882 #ifndef HREF_ED_WITHOUT_FLOATING_POINT
       
   883 	if(aFps != -1)
       
   884 		{
       
   885 		//TODO Fixup by removing below camera case, once camera team make appropiate changes to validateframerate function.
       
   886 		//Currently the camera function only allows fps >=15 AND <=120 and it isnt in the Q16 format that is required.
       
   887 		//Leave in the next two lines uncommented.
       
   888 		//TUint32 fpsQ16 = (TUint32) (aFps * 65536 + 0.5);
       
   889 		//portDef.format.video.xFramerate = fpsQ16;
       
   890 		//Changed xml file from 10fps to 15fps due to camera constraint.Will need to be changed back also
       
   891 		//BEGIN HACK CODE
       
   892 		_LIT8(KCamera,"OMX.SYMBIAN.VIDEO.CAMERASOURCE");
       
   893 		_LIT8(KLogicalILCamera,"OMX.SYMBIAN.LOGICAL.VIDEO.CAMERASOURCE");
       
   894 		TBool cameraTest = EFalse;
       
   895 		for(TInt index = 0, count = iComponents.Count(); index < count; index++)
       
   896 			{
       
   897 			const CComponentInfo* componentInfo = iComponents[index];
       
   898 			if(componentInfo->iComponent == component)
       
   899 				{
       
   900 				if((*(componentInfo->iComponentName) == KCamera)||(*(componentInfo->iComponentName) == KLogicalILCamera))
       
   901 					{
       
   902 					portDef.format.video.xFramerate = aFps;
       
   903 					cameraTest = ETrue;
       
   904 					}
       
   905 				break;
       
   906 				}
       
   907 			}
       
   908 		if(cameraTest == EFalse)
       
   909 			{
       
   910 			TUint32 fpsQ16 = (TUint32) (aFps * 65536 + 0.5);
       
   911 			portDef.format.video.xFramerate = fpsQ16;
       
   912 			}
       
   913 		}
       
   914 	//END HACK CODE.
       
   915 #else	
       
   916 	portDef.format.video.xFramerate = 0;
       
   917 #endif //HREF_ED_WITHOUT_FLOATING_POINT
       
   918 	error = component->SetParameter(component, OMX_IndexParamPortDefinition, &portDef);
       
   919 	if(error != aExpectedError)
       
   920 		{
       
   921 		ERR_PRINTF3(_L("MosSetVideoPortDefL SetParameter() error 0x%X, expected 0x%X"), error, aExpectedError);
       
   922 		return EFalse;
       
   923 		}
       
   924 	return ETrue;
       
   925 	}
       
   926 	
       
   927 TBool ROmxScriptTest::MosCheckStateL(const TDesC8& aComp, OMX_STATETYPE aState)
       
   928 	{
       
   929 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
   930 	if(!component)
       
   931 		{
       
   932 		return EFalse;
       
   933 		}
       
   934 	OMX_STATETYPE state;
       
   935 	OMX_ERRORTYPE error = component->GetState(component, &state);
       
   936 	if(error)
       
   937 		{
       
   938 		FailWithOmxError(_L("GetState()"), error);
       
   939 		return EFalse;
       
   940 		}
       
   941 	if(state != aState)
       
   942 		{
       
   943 		TBuf<64> compConverted;
       
   944 		compConverted.Copy(aComp);
       
   945 		ERR_PRINTF4(_L("Expected component %S to be in state %S, actually in %S"), &compConverted, StateDes(aState), StateDes(state));
       
   946 		StopTest(EFail);
       
   947 		return EFalse;
       
   948 		}
       
   949 	return ETrue;
       
   950 	}
       
   951 
       
   952 TBool ROmxScriptTest::MosCheckVideoPortDefL(const TDesC8& aComp, TInt aPortIndex, TInt aWidth, TInt aHeight, OMX_VIDEO_CODINGTYPE aCoding, OMX_COLOR_FORMATTYPE aColorFormat)
       
   953 	{
       
   954 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
   955 	if(!component)
       
   956 		{
       
   957 		return EFalse;
       
   958 		}
       
   959 	OMX_PARAM_PORTDEFINITIONTYPE portDef;
       
   960 	portDef.nSize = sizeof(portDef);
       
   961 	portDef.nVersion = KOmxVersion;
       
   962 	portDef.nPortIndex = aPortIndex;
       
   963 	OMX_ERRORTYPE error = component->GetParameter(component, OMX_IndexParamPortDefinition, &portDef);
       
   964 	if(error)
       
   965 		{
       
   966 		FailWithOmxError(_L("GetParameter()"), error);
       
   967 		return EFalse;
       
   968 		}
       
   969 	OMX_VIDEO_PORTDEFINITIONTYPE& vidDef = portDef.format.video;
       
   970 	if( vidDef.nFrameWidth == aWidth &&
       
   971 		vidDef.nFrameHeight == aHeight &&
       
   972 		vidDef.eCompressionFormat == aCoding &&
       
   973 		vidDef.eColorFormat == aColorFormat)
       
   974 		{
       
   975 		return ETrue;
       
   976 		}
       
   977 	else
       
   978 		{
       
   979 		ERR_PRINTF1(_L("video port definition did not match expected values"));
       
   980 		StopTest(EFail);
       
   981 		return EFalse;
       
   982 		}
       
   983 	}
       
   984 
       
   985 TBool ROmxScriptTest::MosCheckMetaDataL(const TDesC8& aComp, TInt aPortIndex, OMX_METADATASCOPETYPE aScope, const TDesC8& aAtomType, TUint32 aAtomIndex, const TDesC8& aData)
       
   986 	{
       
   987 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
   988 	if(!component)
       
   989 		{
       
   990 		return EFalse;
       
   991 		}
       
   992 		
       
   993 	OMX_CONFIG_METADATAITEMTYPE* metadata = reinterpret_cast<OMX_CONFIG_METADATAITEMTYPE*>(new(ELeave) TUint8[102400]);
       
   994 	CleanupStack::PushL(metadata);
       
   995 
       
   996 	metadata->nSize = 102400;
       
   997 	metadata->nVersion = KOmxVersion;
       
   998 	metadata->eScopeMode = aScope;
       
   999 	metadata->nScopeSpecifier = aPortIndex;
       
  1000 	metadata->nMetadataItemIndex = aAtomIndex;
       
  1001 	metadata->nKeySizeUsed = aAtomType.Length();
       
  1002 	
       
  1003 	TPtr8 keyDes(metadata->nKey, metadata->nKeySizeUsed);
       
  1004 	keyDes = aAtomType;
       
  1005 	
       
  1006 	metadata->nValueMaxSize = metadata->nSize - _FOFF(OMX_CONFIG_METADATAITEMTYPE, nValue);
       
  1007 		
       
  1008 	OMX_ERRORTYPE error = component->GetParameter(component, OMX_IndexConfigMetadataItem, metadata);
       
  1009 	if(error)
       
  1010 		{
       
  1011 		CleanupStack::PopAndDestroy(metadata);
       
  1012 		FailWithOmxError(_L("GetParameter()"), error);
       
  1013 		return EFalse;
       
  1014 		}
       
  1015 
       
  1016 	TPtrC8 valueDes(metadata->nValue, metadata->nValueSizeUsed);	
       
  1017 	if(valueDes.Compare(aData) == 0)
       
  1018 		{
       
  1019 		CleanupStack::PopAndDestroy(metadata);
       
  1020 		return ETrue;
       
  1021 		}
       
  1022 	else
       
  1023 		{
       
  1024 		ERR_PRINTF1(_L("Did not read metedata"));
       
  1025 		CleanupStack::PopAndDestroy(metadata);
       
  1026 		StopTest(EFail);
       
  1027 		return EFalse;
       
  1028 		}
       
  1029 	}
       
  1030 
       
  1031 TBool ROmxScriptTest::MosGetParameterUnknownIndexTypeL(const TDesC8& aComp, TInt aPortIndex, OMX_METADATASCOPETYPE aScope, const TDesC8& aAtomType, TUint32 aAtomIndex, const TDesC8& /*aData*/)
       
  1032 	{
       
  1033 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  1034 	if(!component)
       
  1035 		{
       
  1036 		return EFalse;
       
  1037 		}
       
  1038 		
       
  1039 	OMX_CONFIG_METADATAITEMTYPE* metadata = reinterpret_cast<OMX_CONFIG_METADATAITEMTYPE*>(new(ELeave) TUint8[102400]);
       
  1040 	CleanupStack::PushL(metadata);
       
  1041 
       
  1042 	metadata->nSize = 102400;
       
  1043 	metadata->nVersion = KOmxVersion;
       
  1044 	metadata->eScopeMode = aScope;
       
  1045 	metadata->nScopeSpecifier = aPortIndex;
       
  1046 	metadata->nMetadataItemIndex = aAtomIndex;
       
  1047 	metadata->nKeySizeUsed = aAtomType.Length();
       
  1048 	
       
  1049 	TPtr8 keyDes(metadata->nKey, metadata->nKeySizeUsed);
       
  1050 	keyDes = aAtomType;
       
  1051 	
       
  1052 	metadata->nValueMaxSize = metadata->nSize - _FOFF(OMX_CONFIG_METADATAITEMTYPE, nValue);
       
  1053 
       
  1054 	OMX_ERRORTYPE error = component->GetParameter(component, OMX_IndexParamAudioG723, metadata);
       
  1055 	INFO_PRINTF2(_L("MosGetParameterUnknownIndexTypeL: %d"), error);
       
  1056 
       
  1057 	CleanupStack::PopAndDestroy(metadata);
       
  1058 
       
  1059 	if(error)
       
  1060 		{
       
  1061 		// This is what we expected
       
  1062 		return ETrue;
       
  1063 		}
       
  1064 
       
  1065 	ERR_PRINTF1(_L("MosGetParameterUnknownIndexTypeL unexpectedly received OMX_ErrorNone"));
       
  1066 	StopTest(EFail);
       
  1067 	return EFalse;	
       
  1068 	}
       
  1069 	
       
  1070 TBool ROmxScriptTest::MosSetParameterUnknownIndexTypeL(const TDesC8& aComp, TInt aPortIndex, OMX_METADATASCOPETYPE aScope, const TDesC8& aAtomType, TUint32 aAtomIndex, const TDesC8& /*aData*/)
       
  1071 	{
       
  1072 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  1073 	if(!component)
       
  1074 		{
       
  1075 		return EFalse;
       
  1076 		}
       
  1077 		
       
  1078 	OMX_CONFIG_METADATAITEMTYPE* metadata = reinterpret_cast<OMX_CONFIG_METADATAITEMTYPE*>(new(ELeave) TUint8[102400]);
       
  1079 	CleanupStack::PushL(metadata);
       
  1080 
       
  1081 	metadata->nSize = 102400;
       
  1082 	metadata->nVersion = KOmxVersion;
       
  1083 	metadata->eScopeMode = aScope;
       
  1084 	metadata->nScopeSpecifier = aPortIndex;
       
  1085 	metadata->nMetadataItemIndex = aAtomIndex;
       
  1086 	metadata->nKeySizeUsed = aAtomType.Length();
       
  1087 	
       
  1088 	TPtr8 keyDes(metadata->nKey, metadata->nKeySizeUsed);
       
  1089 	keyDes = aAtomType;
       
  1090 	
       
  1091 	metadata->nValueMaxSize = metadata->nSize - _FOFF(OMX_CONFIG_METADATAITEMTYPE, nValue);
       
  1092 
       
  1093 	OMX_ERRORTYPE error = component->SetParameter(component, OMX_IndexParamAudioG723, metadata);
       
  1094 
       
  1095 	CleanupStack::PopAndDestroy(metadata);
       
  1096 
       
  1097 	if(error)
       
  1098 		{
       
  1099 		// This is what we expected
       
  1100 		return ETrue;
       
  1101 		}
       
  1102 
       
  1103 	ERR_PRINTF1(_L("MosSetParameterUnknownIndexTypeL unexpectedly received OMX_ErrorNone"));
       
  1104 	StopTest(EFail);
       
  1105 	return EFalse;
       
  1106 	}
       
  1107 TBool ROmxScriptTest::MosDisablePort(const TDesC8& aComp, TInt aPortIndex)
       
  1108 	{
       
  1109 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  1110 	if(!component)
       
  1111 		{
       
  1112 		return EFalse;
       
  1113 		}
       
  1114 
       
  1115 	OMX_ERRORTYPE error = component->SendCommand(component, OMX_CommandPortDisable, aPortIndex, NULL);
       
  1116 	if(error)
       
  1117 		{
       
  1118 		FailWithOmxError(aComp, _L("OMX_SendCommand(OMX_CommandPortDisable)"), error);
       
  1119 		return EFalse;
       
  1120 		}
       
  1121 
       
  1122 	return ETrue;
       
  1123 	}
       
  1124 
       
  1125 TBool ROmxScriptTest::MosEnablePort(const TDesC8& aComp, TInt aPortIndex)
       
  1126 	{
       
  1127 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  1128 	if(!component)
       
  1129 		{
       
  1130 		return EFalse;
       
  1131 		}
       
  1132 
       
  1133 	OMX_ERRORTYPE error = component->SendCommand(component, OMX_CommandPortEnable, aPortIndex, NULL);
       
  1134 	if(error)
       
  1135 		{
       
  1136 		FailWithOmxError(aComp, _L("OMX_SendCommand(OMX_CommandPortEnable)"), error);
       
  1137 		return EFalse;
       
  1138 		}
       
  1139 
       
  1140 	return ETrue;
       
  1141 	}
       
  1142 
       
  1143 TBool ROmxScriptTest::MosIgnoreEventL(const TDesC8& aComp, OMX_EVENTTYPE aEvent, TUint32 aData1, TUint32 aData2)
       
  1144 	{
       
  1145 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  1146 	if(!component)
       
  1147 		{
       
  1148 		return EFalse;
       
  1149 		}
       
  1150 	
       
  1151 	TExpectedEvent event;	
       
  1152 	event.iComponent = component;
       
  1153 	event.iEvent = aEvent;
       
  1154 	event.iData1 = aData1;
       
  1155 	event.iData2 = aData2;
       
  1156 	event.iEventData = NULL;
       
  1157 	iIgnoredEvents.AppendL(event);
       
  1158 
       
  1159 	return ETrue;
       
  1160 	}
       
  1161 
       
  1162 TBool ROmxScriptTest::MosSetPcmAudioPortDefL(const TDesC8& aComp,
       
  1163 											 TInt aPortIndex,
       
  1164 											 TInt aNumChannels,
       
  1165 											 TInt aSamplingRate,
       
  1166 											 TInt aBitsperSample, 
       
  1167 											 OMX_NUMERICALDATATYPE aNumData,
       
  1168 											 OMX_ENDIANTYPE aEndian,
       
  1169 											 OMX_BOOL* aInterleaved,
       
  1170 											 const TDesC8* aEncoding )
       
  1171 	{
       
  1172 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  1173 	if(!component)
       
  1174 		{
       
  1175 		return EFalse;
       
  1176 		}
       
  1177 
       
  1178 	OMX_AUDIO_PARAM_PCMMODETYPE pcmModeType;
       
  1179 	pcmModeType.nSize = sizeof(pcmModeType);
       
  1180 	pcmModeType.nVersion = KOmxVersion;
       
  1181 	pcmModeType.nPortIndex = aPortIndex;
       
  1182 	OMX_ERRORTYPE error = component->GetParameter(component, OMX_IndexParamAudioPcm, &pcmModeType);
       
  1183 	if(error)
       
  1184 		{
       
  1185 		FailWithOmxError(_L("GetParameter()"), error);
       
  1186 		return EFalse;
       
  1187 		}
       
  1188 	if(aNumChannels != KErrNotFound)
       
  1189 		{
       
  1190 		pcmModeType.nChannels = aNumChannels;
       
  1191 		}
       
  1192 	if(aSamplingRate != KErrNotFound)
       
  1193 		{
       
  1194 		pcmModeType.nSamplingRate = aSamplingRate;
       
  1195 		}
       
  1196 	if(aBitsperSample != KErrNotFound)
       
  1197 		{
       
  1198 		pcmModeType.nBitPerSample = aBitsperSample;
       
  1199 		}
       
  1200 	if((aNumData != OMX_NumercialDataMax) && (aNumData != KErrNotFound))
       
  1201  		{
       
  1202  		pcmModeType.eNumData = aNumData;
       
  1203  		}
       
  1204  	if((aEndian != OMX_EndianMax) && (aEndian != KErrNotFound))
       
  1205  		{
       
  1206  		pcmModeType.eEndian = aEndian;
       
  1207  		}
       
  1208  	if(aInterleaved != NULL)
       
  1209  		{
       
  1210  		pcmModeType.bInterleaved = *aInterleaved;
       
  1211  		}
       
  1212     if (aEncoding)
       
  1213         {
       
  1214         if (*aEncoding==_L8("linear")) pcmModeType.ePCMMode = OMX_AUDIO_PCMModeLinear;
       
  1215         else if (*aEncoding==_L8("alaw")) pcmModeType.ePCMMode = OMX_AUDIO_PCMModeALaw;
       
  1216         else if (*aEncoding==_L8("mulaw")) pcmModeType.ePCMMode = OMX_AUDIO_PCMModeMULaw;
       
  1217         else FailWithOmxError(_L("Invalid PCM encoding parameter"), OMX_ErrorBadParameter);
       
  1218         }
       
  1219 	error = component->SetParameter(component, OMX_IndexParamAudioPcm, &pcmModeType);
       
  1220 	if(error)
       
  1221 		{
       
  1222 		FailWithOmxError(_L("SetParameter()"), error);
       
  1223 		return EFalse;
       
  1224 		}
       
  1225 	return ETrue;
       
  1226 	}
       
  1227 
       
  1228 TBool ROmxScriptTest::MosSetConfigAudioMuteL(const TDesC8& aComp,
       
  1229                                              TInt aPortIndex,
       
  1230                                              TBool aMute)
       
  1231     {
       
  1232     OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  1233     if(!component)
       
  1234         {
       
  1235         return EFalse;
       
  1236         }
       
  1237 
       
  1238     OMX_AUDIO_CONFIG_MUTETYPE audioMuteType;
       
  1239     audioMuteType.nSize = sizeof(audioMuteType);
       
  1240     audioMuteType.nVersion = KOmxVersion;
       
  1241     audioMuteType.nPortIndex = aPortIndex;
       
  1242     OMX_ERRORTYPE error = component->GetConfig(component, OMX_IndexConfigAudioMute, &audioMuteType);
       
  1243     if(error)
       
  1244         {
       
  1245         FailWithOmxError(_L("GetConfig()"), error);
       
  1246         return EFalse;
       
  1247         }
       
  1248     audioMuteType.bMute = (aMute ? OMX_TRUE : OMX_FALSE);
       
  1249 
       
  1250     error = component->SetConfig(component, OMX_IndexConfigAudioMute, &audioMuteType);
       
  1251     if(error)
       
  1252         {
       
  1253         FailWithOmxError(_L("SetConfig()"), error);
       
  1254         return EFalse;
       
  1255         }
       
  1256     return ETrue;
       
  1257     }
       
  1258 
       
  1259 TBool ROmxScriptTest::MosCheckConfigAudioMuteL(const TDesC8& aComp,
       
  1260                                              TInt aPortIndex,
       
  1261                                              TBool aMute)
       
  1262     {
       
  1263     OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  1264     if(!component)
       
  1265         {
       
  1266         User::Leave(KErrGeneral);
       
  1267         }
       
  1268 
       
  1269     OMX_AUDIO_CONFIG_MUTETYPE audioMuteType;
       
  1270     audioMuteType.nSize = sizeof(audioMuteType);
       
  1271     audioMuteType.nVersion = KOmxVersion;
       
  1272     audioMuteType.nPortIndex = aPortIndex;
       
  1273     OMX_ERRORTYPE error = component->GetConfig(component, OMX_IndexConfigAudioMute, &audioMuteType);
       
  1274     if(error)
       
  1275         {
       
  1276         FailWithOmxError(_L("GetConfig()"), error);
       
  1277         return EFalse;
       
  1278         }
       
  1279 
       
  1280     if(audioMuteType.bMute != aMute)
       
  1281         {
       
  1282         ERR_PRINTF1(_L("Mute not what expected."));
       
  1283         StopTest(KErrGeneral, EFail);
       
  1284         return EFalse;
       
  1285         }
       
  1286     return ETrue;
       
  1287     }
       
  1288 
       
  1289 
       
  1290 
       
  1291 
       
  1292 TBool ROmxScriptTest::MosSetConfigAudioVolumeL(const TDesC8& aComp,
       
  1293                                              TInt aPortIndex,
       
  1294                                              TBool aLinear, 
       
  1295                                              TInt aMinVolume, 
       
  1296                                              TInt aMaxVolume, 
       
  1297                                              TInt aVolume,
       
  1298                                              OMX_ERRORTYPE aExpectedError)
       
  1299     {
       
  1300     OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  1301     if(!component)
       
  1302         {
       
  1303         return EFalse;
       
  1304         }
       
  1305 
       
  1306     OMX_AUDIO_CONFIG_VOLUMETYPE audioVolumeType;
       
  1307     audioVolumeType.nSize = sizeof(audioVolumeType);
       
  1308     audioVolumeType.nVersion = KOmxVersion;
       
  1309     audioVolumeType.nPortIndex = aPortIndex;
       
  1310     OMX_ERRORTYPE error = component->GetConfig(component, OMX_IndexConfigAudioVolume, &audioVolumeType);
       
  1311     if(error)
       
  1312         {
       
  1313         FailWithOmxError(_L("GetConfig()"), error);
       
  1314         return EFalse;
       
  1315         }
       
  1316     if(aMinVolume != -1)
       
  1317         {
       
  1318         audioVolumeType.sVolume.nMin = aMinVolume;
       
  1319         }
       
  1320     if(aMaxVolume != -1)
       
  1321         {
       
  1322         audioVolumeType.sVolume.nMax = aMaxVolume;
       
  1323         }
       
  1324     if(aVolume != -1)
       
  1325         {
       
  1326         audioVolumeType.sVolume.nValue = aVolume;
       
  1327         }
       
  1328     audioVolumeType.bLinear = (aLinear ? OMX_TRUE : OMX_FALSE);
       
  1329         
       
  1330     error = component->SetConfig(component, OMX_IndexConfigAudioVolume, &audioVolumeType);
       
  1331     if(error != aExpectedError)
       
  1332         {
       
  1333         FailWithOmxError(_L("SetConfig()"), error);
       
  1334         return EFalse;
       
  1335         }
       
  1336     return ETrue;
       
  1337     }
       
  1338 
       
  1339 TBool ROmxScriptTest::MosCheckConfigAudioVolumeL(const TDesC8& aComp,
       
  1340                                              TInt aPortIndex,
       
  1341                                              TBool aLinear, 
       
  1342                                              TInt aMinVolume, 
       
  1343                                              TInt aMaxVolume, 
       
  1344                                              TInt aVolume)
       
  1345     {
       
  1346     OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  1347     if(!component)
       
  1348         {
       
  1349         User::Leave(KErrGeneral);
       
  1350         }
       
  1351 
       
  1352     OMX_AUDIO_CONFIG_VOLUMETYPE audioVolumeType;
       
  1353     audioVolumeType.nSize = sizeof(audioVolumeType);
       
  1354     audioVolumeType.nVersion = KOmxVersion;
       
  1355     audioVolumeType.nPortIndex = aPortIndex;
       
  1356     OMX_ERRORTYPE error = component->GetConfig(component, OMX_IndexConfigAudioVolume, &audioVolumeType);
       
  1357     if(error)
       
  1358         {
       
  1359         FailWithOmxError(_L("GetConfig()"), error);
       
  1360         User::Leave(KErrGeneral);
       
  1361         }
       
  1362     if(aMinVolume != -1)
       
  1363         {
       
  1364         if (audioVolumeType.sVolume.nMin != aMinVolume)
       
  1365             {
       
  1366             ERR_PRINTF1(_L("Min volume not what expected."));
       
  1367             StopTest(KErrGeneral, EFail);
       
  1368             return EFalse;
       
  1369             }
       
  1370         }
       
  1371     if(aMaxVolume != -1)
       
  1372         {
       
  1373         if (audioVolumeType.sVolume.nMax != aMaxVolume)
       
  1374             {
       
  1375             ERR_PRINTF1(_L("Max volume not what expected."));
       
  1376             StopTest(KErrGeneral, EFail);
       
  1377             return EFalse;
       
  1378             }
       
  1379         }
       
  1380     if(aVolume != -1)
       
  1381         {
       
  1382         if (audioVolumeType.sVolume.nValue != aVolume)
       
  1383             {
       
  1384             ERR_PRINTF1(_L("Volume not what expected."));
       
  1385             StopTest(KErrGeneral, EFail);
       
  1386             return EFalse;
       
  1387             }
       
  1388         }
       
  1389     if(audioVolumeType.bLinear != aLinear)
       
  1390         {
       
  1391         ERR_PRINTF1(_L("Linear not what expected."));
       
  1392         StopTest(KErrGeneral, EFail);
       
  1393         return EFalse;
       
  1394         }
       
  1395     return ETrue;
       
  1396     }
       
  1397 
       
  1398 
       
  1399 TBool ROmxScriptTest::MosSetAacAudioPortDefL(const TDesC8& aComp, TInt aPortIndex, TInt aNumChannels, TInt aSamplingRate, TInt aBitRate, TInt aAudioBandwidth, TInt aFrameLength, TInt aAacTools, TInt aAacErTools, TInt aProfile, TInt aStreamFormat, TInt aChannelMode)
       
  1400 	{
       
  1401 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  1402 	if(!component)
       
  1403 		{
       
  1404 		return EFalse;
       
  1405 		}
       
  1406 
       
  1407 	OMX_AUDIO_PARAM_AACPROFILETYPE aacProfile;
       
  1408 	aacProfile.nSize = sizeof(aacProfile);
       
  1409 	aacProfile.nVersion = KOmxVersion;
       
  1410 	aacProfile.nPortIndex = aPortIndex;
       
  1411 	OMX_ERRORTYPE error = component->GetParameter(component, OMX_IndexParamAudioAac, &aacProfile);
       
  1412 	if(error)
       
  1413 		{
       
  1414 		FailWithOmxError(_L("GetParameter()"), error);
       
  1415 		return EFalse;
       
  1416 		}
       
  1417 	
       
  1418 	if(aNumChannels != -1)
       
  1419 		{
       
  1420 		aacProfile.nChannels = aNumChannels;
       
  1421 		}
       
  1422 	if(aSamplingRate != -1)
       
  1423 		{
       
  1424 		aacProfile.nSampleRate = aSamplingRate;
       
  1425 		}
       
  1426 	if(aBitRate != -1)
       
  1427 		{
       
  1428 		aacProfile.nBitRate = aBitRate;
       
  1429 		}
       
  1430 	if(aAudioBandwidth != -1)
       
  1431 		{
       
  1432 		aacProfile.nAudioBandWidth = aAudioBandwidth;
       
  1433 		}
       
  1434 	if(aFrameLength != -1)
       
  1435 		{
       
  1436 		aacProfile.nFrameLength = aFrameLength;
       
  1437 		}
       
  1438 	if(aAacTools != -1)
       
  1439 		{
       
  1440 		aacProfile.nAACtools = aAacTools;
       
  1441 		}
       
  1442 	if(aAacErTools != -1)
       
  1443 		{
       
  1444 		aacProfile.nAACERtools = aAacErTools;
       
  1445 		}
       
  1446 	if(aProfile != -1)
       
  1447 		{
       
  1448 		aacProfile.eAACProfile = static_cast<OMX_AUDIO_AACPROFILETYPE>(aProfile);
       
  1449 		}
       
  1450 	if(aStreamFormat != -1)
       
  1451 		{
       
  1452 		aacProfile.eAACStreamFormat = static_cast<OMX_AUDIO_AACSTREAMFORMATTYPE>(aStreamFormat);
       
  1453 		}
       
  1454 	if(aChannelMode != -1)
       
  1455 		{
       
  1456 		aacProfile.eChannelMode = static_cast<OMX_AUDIO_CHANNELMODETYPE>(aChannelMode);
       
  1457 		}
       
  1458 	
       
  1459 	error = component->SetParameter(component, OMX_IndexParamAudioAac, &aacProfile);
       
  1460 	if(error)
       
  1461 		{
       
  1462 		FailWithOmxError(_L("SetParameter()"), error);
       
  1463 		return EFalse;
       
  1464 		}
       
  1465 	return ETrue;	
       
  1466 	}
       
  1467 
       
  1468 TBool ROmxScriptTest::MosSetAudioPortDefL(const TDesC8& aComp, TInt aPortIndex, OMX_AUDIO_CODINGTYPE* aCodingType)
       
  1469 	{
       
  1470 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  1471 	if(!component)
       
  1472 		{
       
  1473 		return EFalse;
       
  1474 		}
       
  1475 	
       
  1476 	OMX_PARAM_PORTDEFINITIONTYPE portDef;
       
  1477 	portDef.nSize = sizeof(portDef);
       
  1478 	portDef.nVersion = KOmxVersion;
       
  1479 	portDef.nPortIndex = aPortIndex;
       
  1480 	OMX_ERRORTYPE error = component->GetParameter(component, OMX_IndexParamPortDefinition, &portDef);
       
  1481 	if(error)
       
  1482 		{
       
  1483 		FailWithOmxError(_L("GetParameter()"), error);
       
  1484 		return EFalse;
       
  1485 		}
       
  1486 	if(aCodingType)
       
  1487 		{
       
  1488 		portDef.format.audio.eEncoding = *aCodingType;
       
  1489 		}
       
  1490 	error = component->SetParameter(component, OMX_IndexParamPortDefinition, &portDef);
       
  1491 	if(error)
       
  1492 		{
       
  1493 		FailWithOmxError(_L("SetParameter()"), error);
       
  1494 		return EFalse;
       
  1495 		}
       
  1496 	return ETrue;
       
  1497 	}
       
  1498 
       
  1499 TBool ROmxScriptTest::MosSetRefClockTypeL(const TDesC8& aComp, OMX_TIME_REFCLOCKTYPE aRefClockType)
       
  1500 	{
       
  1501 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  1502 	if(!component)
       
  1503 		{
       
  1504 		return EFalse;
       
  1505 		}
       
  1506 
       
  1507 	OMX_TIME_CONFIG_ACTIVEREFCLOCKTYPE conf;
       
  1508 	conf.nVersion = KOmxVersion;
       
  1509 	conf.nSize = sizeof(conf);
       
  1510 	conf.eClock = aRefClockType;
       
  1511 
       
  1512 	OMX_ERRORTYPE error = component->SetConfig(component, OMX_IndexConfigTimeActiveRefClock, &conf);
       
  1513 	if(error != OMX_ErrorNone)
       
  1514 		{
       
  1515 		FailWithOmxError(_L("OMX_SetConfig(OMX_IndexConfigTimeActiveRefClock)"), error);
       
  1516 		return EFalse;
       
  1517 		}
       
  1518 	
       
  1519 	return ETrue;
       
  1520 	}
       
  1521 
       
  1522 TBool ROmxScriptTest::MosSetClockTimeScale(const TDesC8& aComp, OMX_S32 aScale)
       
  1523 {
       
  1524 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  1525 	if(!component)
       
  1526 		{
       
  1527 		return EFalse;
       
  1528 		}
       
  1529 
       
  1530 	INFO_PRINTF2(_L("MosSetClockTimeScale %d"), aScale);
       
  1531 
       
  1532 	OMX_TIME_CONFIG_SCALETYPE conf;
       
  1533 	conf.nSize = sizeof(conf);
       
  1534 	conf.nVersion = KOmxVersion;
       
  1535 	conf.xScale = aScale;
       
  1536 
       
  1537 	OMX_ERRORTYPE error = component->SetConfig(component, OMX_IndexConfigTimeScale, &conf);
       
  1538 	if(error != OMX_ErrorNone)
       
  1539 		{
       
  1540 		FailWithOmxError(_L("OMX_SetConfig(OMX_IndexConfigTimeClockState)"), error);
       
  1541 		return EFalse;
       
  1542 		}
       
  1543 	
       
  1544 	return ETrue;
       
  1545 }	
       
  1546 	
       
  1547 TBool ROmxScriptTest::MosSetClockStateL(const TDesC8& aComp, OMX_TIME_CLOCKSTATE aClockState, TInt aStartTime, TInt aOffset, TUint32 aWaitMask)
       
  1548 	{
       
  1549 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  1550 	if(!component)
       
  1551 		{
       
  1552 		return EFalse;
       
  1553 		}
       
  1554 
       
  1555 	OMX_TIME_CONFIG_CLOCKSTATETYPE conf;
       
  1556 	conf.nVersion = KOmxVersion;
       
  1557 	conf.nSize = sizeof(conf);
       
  1558 	conf.eState = aClockState;
       
  1559 	conf.nStartTime = aStartTime;
       
  1560 	conf.nOffset = aOffset;
       
  1561 	conf.nWaitMask = aWaitMask;
       
  1562 
       
  1563 	OMX_ERRORTYPE error = component->SetConfig(component, OMX_IndexConfigTimeClockState, &conf);
       
  1564 	if(error != OMX_ErrorNone)
       
  1565 		{
       
  1566 		FailWithOmxError(_L("OMX_SetConfig(OMX_IndexConfigTimeClockState)"), error);
       
  1567 		return EFalse;
       
  1568 		}
       
  1569 	
       
  1570 	return ETrue;
       
  1571 	}
       
  1572 	
       
  1573 // Buffer component handler
       
  1574 
       
  1575 TBool ROmxScriptTest::MosSetVideoEncQuantL(const TDesC8& aComp, TInt aPortIndex, TInt aQpb)
       
  1576 	{
       
  1577 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  1578 	if(!component)
       
  1579 		{
       
  1580 		return EFalse;
       
  1581 		}
       
  1582 	
       
  1583 	OMX_VIDEO_PARAM_QUANTIZATIONTYPE videoQuantization;
       
  1584 	videoQuantization.nSize = sizeof(videoQuantization);
       
  1585 	videoQuantization.nVersion = KOmxVersion;
       
  1586 	videoQuantization.nPortIndex = aPortIndex;
       
  1587 	videoQuantization.nQpB = aQpb;
       
  1588 
       
  1589 	OMX_ERRORTYPE error = component->SetParameter(component, static_cast<OMX_INDEXTYPE>(OMX_IndexParamVideoQuantization), &videoQuantization);
       
  1590 	if(error)
       
  1591 		{
       
  1592 		FailWithOmxError(_L("MosSetVideoEncQuantL SetParameter()"), error);
       
  1593 		return EFalse;
       
  1594 		}
       
  1595 	
       
  1596 	error = component->GetParameter(component, OMX_IndexParamVideoQuantization, &videoQuantization);
       
  1597 	if(error)
       
  1598 		{
       
  1599 		FailWithOmxError(_L("MosSetVideoEncQuantL GetParameter()"), error);
       
  1600 		return EFalse;
       
  1601 		}
       
  1602 	
       
  1603 	if (videoQuantization.nQpB != aQpb)
       
  1604 		{
       
  1605 		ERR_PRINTF3(_L("MosSetVideoEncQuantL Compare QPB failed - Got %d, Expected %d"), videoQuantization.nQpB, aQpb);
       
  1606 		return EFalse;
       
  1607 		}
       
  1608 
       
  1609 	return ETrue;
       
  1610 	}
       
  1611 
       
  1612 TBool ROmxScriptTest::MosSetVideoEncMotionVectL(const TDesC8& aComp, TInt aPortIndex, 
       
  1613 		TInt aAccuracy,	TInt aSxSearchrange, TInt aSySearchrange, OMX_ERRORTYPE aExpectedError)
       
  1614 	{
       
  1615 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  1616 	if(!component)
       
  1617 		{
       
  1618 		return EFalse;
       
  1619 		}
       
  1620 	
       
  1621 	OMX_VIDEO_PARAM_MOTIONVECTORTYPE motionVect;
       
  1622 	motionVect.nSize = sizeof(motionVect);
       
  1623 	motionVect.nVersion = KOmxVersion;
       
  1624 	motionVect.nPortIndex = aPortIndex;
       
  1625 	motionVect.eAccuracy = (OMX_VIDEO_MOTIONVECTORTYPE)aAccuracy;
       
  1626 	motionVect.sXSearchRange = aSxSearchrange;
       
  1627 	motionVect.sYSearchRange = aSySearchrange;
       
  1628 
       
  1629 	OMX_ERRORTYPE error = component->SetParameter(component, static_cast<OMX_INDEXTYPE>(OMX_IndexParamVideoMotionVector), &motionVect);
       
  1630 	if(aExpectedError != error)
       
  1631 		{
       
  1632 		ERR_PRINTF3(_L("MosSetVideoEncMotionVectL SetParameter() returned error 0x%X, expected error 0x%X"), error, aExpectedError);
       
  1633 		return EFalse;
       
  1634 		}
       
  1635 	
       
  1636 	if (aExpectedError)
       
  1637 		{
       
  1638 		return ETrue;
       
  1639 		}
       
  1640 	
       
  1641 	error = component->GetParameter(component, OMX_IndexParamVideoMotionVector, &motionVect);
       
  1642 	if(error)
       
  1643 		{
       
  1644 		FailWithOmxError(_L("MosSetVideoEncMotionVectL GetParameter()"), error);
       
  1645 		return EFalse;
       
  1646 		}
       
  1647 	
       
  1648 	if (motionVect.eAccuracy != aAccuracy || motionVect.sXSearchRange != aSxSearchrange ||
       
  1649 			motionVect.sYSearchRange != aSySearchrange)
       
  1650 		{
       
  1651 		ERR_PRINTF1(_L("MosSetVideoEncMotionVectL GetParameter() did not return expeccted value"));
       
  1652 		return EFalse;
       
  1653 		}
       
  1654 
       
  1655 	return ETrue;
       
  1656 	}
       
  1657 
       
  1658 TBool ROmxScriptTest::MosSetVideoEncMpeg4TypeL(const TDesC8& aComp, TInt aPortIndex, 
       
  1659 		OMX_VIDEO_MPEG4PROFILETYPE aMpeg4Profile, OMX_VIDEO_MPEG4LEVELTYPE aMpeg4Level, OMX_ERRORTYPE aExpectedError)
       
  1660     {
       
  1661     OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  1662 	if(!component)
       
  1663 		{
       
  1664 		return EFalse;
       
  1665 		}
       
  1666 	
       
  1667 	OMX_VIDEO_PARAM_MPEG4TYPE mpeg4;
       
  1668 	mpeg4.nSize = sizeof(mpeg4);
       
  1669 	mpeg4.nVersion = KOmxVersion;
       
  1670 	mpeg4.nPortIndex = aPortIndex;
       
  1671 	mpeg4.eProfile = aMpeg4Profile;
       
  1672 	mpeg4.eLevel = aMpeg4Level;
       
  1673 	
       
  1674 	OMX_ERRORTYPE error = component->SetParameter(component, static_cast<OMX_INDEXTYPE>(OMX_IndexParamVideoMpeg4), &mpeg4);
       
  1675 	if(aExpectedError != error)
       
  1676 		{
       
  1677 		ERR_PRINTF3(_L("MosSetVideoEncMpeg4TypeL SetParameter() returned error 0x%X, expected error 0x%X"), error, aExpectedError);
       
  1678 		return EFalse;
       
  1679 		}
       
  1680 	if (aExpectedError)
       
  1681 		{
       
  1682 		return ETrue;
       
  1683 		}
       
  1684 	
       
  1685 	error = component->GetParameter(component, OMX_IndexParamVideoMpeg4, &mpeg4);
       
  1686 	if(error)
       
  1687 		{
       
  1688 		FailWithOmxError(_L("MosSetVideoEncMpeg4TypeL GetParameter()"), error);
       
  1689 		return EFalse;
       
  1690 		}
       
  1691 	
       
  1692 	if (mpeg4.eProfile != aMpeg4Profile || mpeg4.eLevel != aMpeg4Level)
       
  1693 		{
       
  1694 		ERR_PRINTF1(_L("MosSetVideoEncMpeg4TypeL GetParameter() did not return expeccted value"));
       
  1695 		return EFalse;
       
  1696 		}
       
  1697 	return ETrue;
       
  1698     }
       
  1699 
       
  1700 TBool ROmxScriptTest::MosSetVideoEncBitRateL(const TDesC8& aComp, TInt aPortIndex, 
       
  1701 		OMX_VIDEO_CONTROLRATETYPE aControlRate, TInt aTargetBitrate, OMX_ERRORTYPE aExpectedError)
       
  1702     {
       
  1703     OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  1704 	if(!component)
       
  1705 		{
       
  1706 		return EFalse;
       
  1707 		}
       
  1708 	
       
  1709 	OMX_VIDEO_PARAM_BITRATETYPE bitRate;
       
  1710 	bitRate.nSize = sizeof(bitRate);
       
  1711 	bitRate.nVersion = KOmxVersion;
       
  1712 	bitRate.nPortIndex = aPortIndex;
       
  1713 	bitRate.eControlRate = aControlRate;
       
  1714 	bitRate.nTargetBitrate = aTargetBitrate;
       
  1715 	
       
  1716 	OMX_ERRORTYPE error = component->SetParameter(component, static_cast<OMX_INDEXTYPE>(OMX_IndexParamVideoBitrate), &bitRate);
       
  1717 	if(aExpectedError != error)
       
  1718 		{
       
  1719 		ERR_PRINTF3(_L("MosSetVideoEncBitRateL SetParameter() returned error 0x%X, expected error 0x%X"), error, aExpectedError);
       
  1720 		return EFalse;
       
  1721 		}
       
  1722 	if (aExpectedError)
       
  1723 		{
       
  1724 		return ETrue;
       
  1725 		}
       
  1726 	
       
  1727 	error = component->GetParameter(component, OMX_IndexParamVideoBitrate, &bitRate);
       
  1728 	if(error)
       
  1729 		{
       
  1730 		FailWithOmxError(_L("MosSetVideoEncBitRateL GetParameter()"), error);
       
  1731 		return EFalse;
       
  1732 		}
       
  1733 	
       
  1734 	if (bitRate.eControlRate != aControlRate || bitRate.nTargetBitrate != aTargetBitrate)
       
  1735 		{
       
  1736 		ERR_PRINTF1(_L("MosSetVideoEncBitRateL GetParameter() did not return expeccted value"));
       
  1737 		return EFalse;
       
  1738 		}
       
  1739 	return ETrue;
       
  1740     }
       
  1741 
       
  1742 void ROmxScriptTest::WriteInt32(TUint8* aPtr, TInt32 aData)
       
  1743 	{
       
  1744 	aPtr[0] = TUint8(aData>>24);
       
  1745 	aPtr[1] = TUint8(aData>>16);
       
  1746 	aPtr[2] = TUint8(aData>>8);
       
  1747 	aPtr[3] = TUint8(aData);
       
  1748 	}
       
  1749 	
       
  1750 
       
  1751 TBool ROmxScriptTest::ShortNameMatchComparison(const TDesC8* aShortName, const CComponentInfo& aComponentInfo)
       
  1752     {
       
  1753     if (*aShortName == *aComponentInfo.iShortName)
       
  1754         {
       
  1755         return ETrue;
       
  1756         }
       
  1757     return EFalse;
       
  1758     }
       
  1759 
       
  1760 TBool ROmxScriptTest::ComponentLogicalIL(const TDesC8& aName)
       
  1761     {
       
  1762     for(TInt index = 0, count = iComponents.Count(); index < count; index++)
       
  1763         {
       
  1764         CComponentInfo* component = iComponents[index];
       
  1765         if(*(component->iShortName) == aName)
       
  1766             {
       
  1767             if(component->iComponentName->FindC(KILTypeString()) == KErrNotFound)
       
  1768                 {
       
  1769                 // is not LIL
       
  1770                 return EFalse;
       
  1771                 }
       
  1772             else
       
  1773                 {
       
  1774                 // is LIL
       
  1775                 return ETrue;
       
  1776                 }
       
  1777             }
       
  1778         }
       
  1779     ERR_PRINTF1(_L("LogicalILComponent() - Component not found"));
       
  1780     StopTest(EFail);
       
  1781     
       
  1782     return EFalse;
       
  1783     }
       
  1784 
       
  1785 TBool ROmxScriptTest::ComponentPhysicalIL(const TDesC8& aName)
       
  1786     {
       
  1787     for(TInt index = 0, count = iComponents.Count(); index < count; index++)
       
  1788         {
       
  1789         CComponentInfo* component = iComponents[index];
       
  1790         if(*(component->iShortName) == aName)
       
  1791             {
       
  1792             if(component->iComponentName->FindC(KILTypeString) == KErrNotFound)
       
  1793                 {
       
  1794                 // is PIL
       
  1795                 return ETrue;
       
  1796                 }
       
  1797             else
       
  1798                 {
       
  1799                 // is not PIL
       
  1800                 return EFalse;
       
  1801                 }
       
  1802             }
       
  1803         }
       
  1804     ERR_PRINTF1(_L("PhysicalILComponent() - Component not found"));
       
  1805     StopTest(EFail);
       
  1806     
       
  1807     return EFalse;
       
  1808     }
       
  1809     
       
  1810 OMX_COMPONENTTYPE* ROmxScriptTest::ComponentByName(const TDesC8& aName)
       
  1811 	{
       
  1812 	for(TInt index = 0, count = iComponents.Count(); index < count; index++)
       
  1813 		{
       
  1814 		CComponentInfo* component = iComponents[index];
       
  1815 		if(*(component->iShortName) == aName)
       
  1816 			{
       
  1817 			return component->iComponent;
       
  1818 			}
       
  1819 		}
       
  1820 	HBufC* name = HBufC::New(aName.Length());
       
  1821 	if(!name)
       
  1822 		{
       
  1823 		ERR_PRINTF1(_L("Component not found"));
       
  1824 		StopTest(EFail);
       
  1825 		}
       
  1826 	else
       
  1827 		{
       
  1828 		name->Des().Copy(aName);
       
  1829 		ERR_PRINTF2(_L("Component %S not found"), name);
       
  1830 		delete name;
       
  1831 		StopTest(EFail);
       
  1832 		}
       
  1833 	return NULL;
       
  1834 	}
       
  1835 
       
  1836 
       
  1837 
       
  1838 void ROmxScriptTest::GetComponentName(const OMX_COMPONENTTYPE* aHandle, TDes& aName)
       
  1839 	{
       
  1840 	for(TInt index = 0, count = iComponents.Count(); index < count; index++)
       
  1841 		{
       
  1842 		const CComponentInfo* component = iComponents[index];
       
  1843 		if(component->iComponent == aHandle)
       
  1844 			{
       
  1845 			aName.Copy(*(component->iShortName));
       
  1846 			return;
       
  1847 			}
       
  1848 		}
       
  1849 	ERR_PRINTF1(_L("Invalid component handle"));
       
  1850 	StopTest(EFail);
       
  1851 	aName = _L("<invalid handle>");
       
  1852 	}
       
  1853 
       
  1854 void ROmxScriptTest::FailWithOmxError(const TDesC& aOperation, OMX_ERRORTYPE aError)
       
  1855 	{	
       
  1856 	if(aError != OMX_ErrorNone)
       
  1857 		{
       
  1858 		TBuf<64> errorDes;
       
  1859 		OMXUtil::ErrorDes(aError, errorDes);
       
  1860 		ERR_PRINTF3(_L("%S returned %S"), &aOperation, &errorDes);
       
  1861 		StopTest(EFail);
       
  1862 		}
       
  1863 	}
       
  1864 
       
  1865 void ROmxScriptTest::FailWithOmxError(const TDesC8& aComponent, const TDesC& aOperation, OMX_ERRORTYPE aError)
       
  1866 	{
       
  1867 	if(aError != OMX_ErrorNone)
       
  1868 		{
       
  1869 		TBuf<64> errorDes;
       
  1870 		TBuf<64> componentDes16;
       
  1871 		componentDes16.Copy(aComponent);
       
  1872 		OMXUtil::ErrorDes(aError, errorDes);
       
  1873 		ERR_PRINTF4(_L("%S->%S returned %S"), &componentDes16, &aOperation, &errorDes);
       
  1874 		StopTest(EFail);
       
  1875 		}
       
  1876 	}
       
  1877 
       
  1878 void ROmxScriptTest::AllComponentsEOS()
       
  1879 	{
       
  1880 	EndWait();
       
  1881 	}
       
  1882 
       
  1883 void ROmxScriptTest::AllComponentsTransitioned(OMX_STATETYPE aNewState,
       
  1884 			                                   OMX_STATETYPE aOldState)
       
  1885 	{
       
  1886 	__ASSERT_ALWAYS(aOldState == iState, User::Invariant());
       
  1887 	iState = aNewState;
       
  1888 	EndWait();
       
  1889 	}
       
  1890 
       
  1891 void ROmxScriptTest::EventReceived(OMX_COMPONENTTYPE* aComponent, OMX_EVENTTYPE aEvent, TUint32 aData1, TUint32 aData2, TAny* aEventData)
       
  1892 	{
       
  1893 
       
  1894 	if ((iMsgQueue.Handle()) && (aEvent == OMX_EventCmdComplete))
       
  1895 		{		
       
  1896 		iMsgQueue.Close();
       
  1897 		}
       
  1898 	
       
  1899 	
       
  1900 	// If the Graphic Sink has created a surface, assign it to the window
       
  1901 	if(aEvent == OMX_EventPortSettingsChanged)
       
  1902 		{
       
  1903 		  // do nothing
       
  1904 		}
       
  1905 	
       
  1906 	// ignore buffer flag events except EOS
       
  1907 
       
  1908 	TInt index = 0;
       
  1909 	TInt count = iExpectedEvents.Count();
       
  1910 	for(; index < count; index++)
       
  1911 		{
       
  1912 		const TExpectedEvent& event = iExpectedEvents[index];
       
  1913 		if( event.iComponent == aComponent &&
       
  1914 		    event.iEvent == aEvent &&
       
  1915 			event.iData1 == aData1 &&
       
  1916 			event.iData2 == aData2 &&
       
  1917 			event.iEventData == aEventData)
       
  1918 			{
       
  1919 			break;
       
  1920 			}
       
  1921 		}
       
  1922 	if(index == count)
       
  1923 		{
       
  1924 		// event was not expected, see if we can ignore this event
       
  1925 		TInt count1 = iIgnoredEvents.Count();
       
  1926 		TInt index1 = 0;
       
  1927 		for(; index1 < count1; index1++)
       
  1928 		    {
       
  1929 		    const TExpectedEvent& event = iIgnoredEvents[index1];
       
  1930 		    if( event.iComponent == aComponent &&
       
  1931 		              event.iEvent == aEvent &&
       
  1932 		              event.iData1 == aData1 &&
       
  1933 		              event.iData2 == aData2 &&
       
  1934 		              event.iEventData == aEventData)
       
  1935 		        {
       
  1936 		        return;
       
  1937 		        }
       
  1938 		    }
       
  1939 		 
       
  1940 		// event was not expected and we can't ignore the event, so fail the test		
       
  1941 		TBuf<64> name;
       
  1942 		GetComponentName(aComponent, name);
       
  1943 		char hexBuf[11];
       
  1944 		TBuf<32> eventWideChar;
       
  1945 		eventWideChar.Copy(TPtrC8((unsigned char*) format_OMX_EVENTTYPE(aEvent, hexBuf)));
       
  1946 		ERR_PRINTF2(_L("Unexpected event received from component %S"), &name);
       
  1947 		ERR_PRINTF5(_L("aEvent=%S aData1=0x%08X aData2=0x%08X, aEventData=0x%08X"), &eventWideChar, aData1, aData2, aEventData);
       
  1948 		StopTest(EFail);
       
  1949 		return;
       
  1950 		}
       
  1951 	iExpectedEvents.Remove(index);
       
  1952 	if(iWaitingForEvents && iExpectedEvents.Count() == 0)
       
  1953 		{
       
  1954 		EndWait();
       
  1955 		}
       
  1956 	}
       
  1957 
       
  1958 void ROmxScriptTest::ComponentTransitioned(OMX_STATETYPE aNewState,
       
  1959 			                                     OMX_STATETYPE aOldState)
       
  1960 	{
       
  1961 	__ASSERT_ALWAYS(aOldState == iState, User::Invariant());
       
  1962 	iState = aNewState;
       
  1963 	EndWait();
       
  1964 	}
       
  1965 
       
  1966 void ROmxScriptTest::BufferDone(OMX_COMPONENTTYPE* aComponent, OMX_BUFFERHEADERTYPE* aBufHdr, TBool aSource)
       
  1967 	{
       
  1968 	if (iNonTunneledHandler)
       
  1969 		{
       
  1970 		iNonTunneledHandler->BufferDone(aComponent, aBufHdr, aSource);
       
  1971 		}
       
  1972 	
       
  1973 	if(iPortBufferHandler)
       
  1974 	    {
       
  1975 	    iPortBufferHandler->BufferDone(aComponent, aBufHdr, aSource);
       
  1976 	    }
       
  1977 		
       
  1978 	}
       
  1979 
       
  1980 void ROmxScriptTest::TimerExpired()
       
  1981 	{
       
  1982 	EndWait();
       
  1983 	}
       
  1984 
       
  1985 TBool ROmxScriptTest::HandleNonTunneledBuffers(OMX_STATETYPE aNewState, OMX_COMPONENTTYPE* aComp)
       
  1986 	{
       
  1987 	if (iNonTunneledHandler)
       
  1988 		{
       
  1989 		if (iState == OMX_StateLoaded && aNewState == OMX_StateIdle)
       
  1990 			{
       
  1991 			TRAPD(err, iNonTunneledHandler->AllocateBuffersL(aComp));
       
  1992 			if (err != KErrNone)
       
  1993 				{
       
  1994 				ERR_PRINTF2(_L("Non-tunneled AllocateBuffersL failed (%d)"), err);
       
  1995 				return EFalse;
       
  1996 				}
       
  1997 			}
       
  1998 		else if (iState == OMX_StateIdle && aNewState == OMX_StateExecuting)
       
  1999 			{
       
  2000 			TRAPD(err, iNonTunneledHandler->FillBuffers(aComp));
       
  2001 			if (err != KErrNone)
       
  2002 				{
       
  2003 				ERR_PRINTF2(_L("Non-tunneled FillBuffersL failed (%d)"), err);
       
  2004 				return EFalse;
       
  2005 				}		
       
  2006 			}
       
  2007 		else if (iState == OMX_StateExecuting && aNewState == OMX_StateIdle)
       
  2008 			{
       
  2009 			TRAPD(err, iNonTunneledHandler->HoldBuffers(aComp));
       
  2010 			if (err != KErrNone)
       
  2011 				{
       
  2012 				ERR_PRINTF2(_L("Non-tunneled HoldBuffersL failed (%d)"), err);
       
  2013 				return EFalse;
       
  2014 				}
       
  2015 			}
       
  2016 		else if (iState == OMX_StateIdle && aNewState == OMX_StateLoaded)
       
  2017 			{
       
  2018 			TRAPD(err, iNonTunneledHandler->FreeBuffers(aComp));
       
  2019 			if (err != KErrNone)
       
  2020 				{
       
  2021 				ERR_PRINTF2(_L("Non-tunneled FreeBuffersL failed (%d)"), err);
       
  2022 				return EFalse;
       
  2023 				}
       
  2024 			}
       
  2025 		}
       
  2026 	
       
  2027 	return ETrue;
       
  2028 	}
       
  2029 
       
  2030 
       
  2031 TBool ROmxScriptTest::HandlePortBufferHandler(OMX_STATETYPE aNewState, OMX_COMPONENTTYPE* aComp)
       
  2032     {
       
  2033     if(iPortBufferHandler)
       
  2034         {
       
  2035         if (iState == OMX_StateLoaded && aNewState == OMX_StateIdle)
       
  2036             {
       
  2037             TRAPD(err, iPortBufferHandler->AllocateBuffersL(aComp));
       
  2038             if (err != KErrNone)
       
  2039                 {
       
  2040                 ERR_PRINTF2(_L("PortBufferHandler AllocateBuffersL failed (%d)"), err);
       
  2041                 return EFalse;
       
  2042                 }
       
  2043             }
       
  2044         else if (iState == OMX_StateIdle && aNewState == OMX_StateExecuting)
       
  2045             {
       
  2046 
       
  2047             }
       
  2048         else if (iState == OMX_StateExecuting && aNewState == OMX_StateIdle)
       
  2049             {
       
  2050             }
       
  2051         else if (iState == OMX_StateIdle && aNewState == OMX_StateLoaded)
       
  2052             {
       
  2053             TRAPD(err, iPortBufferHandler->FreeBuffers(aComp));
       
  2054             if (err != KErrNone)
       
  2055                 {
       
  2056                 ERR_PRINTF2(_L("PortBufferHandler FreeBuffersL failed (%d)"), err);
       
  2057                 return EFalse;
       
  2058                 }
       
  2059             }
       
  2060         }
       
  2061     return ETrue;
       
  2062     }
       
  2063 
       
  2064 TBool ROmxScriptTest::MosSetActiveStream(const TDesC8& aComp, TUint32 aPortIndex)
       
  2065     {
       
  2066     OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  2067 	if(!component)
       
  2068 		{
       
  2069 		return EFalse;
       
  2070 		}
       
  2071 
       
  2072 	OMX_PARAM_PORTDEFINITIONTYPE portDef;
       
  2073 	portDef.nVersion = KOmxVersion;
       
  2074 	portDef.nSize = sizeof(portDef);
       
  2075 	portDef.nPortIndex = aPortIndex;
       
  2076 	
       
  2077 	OMX_ERRORTYPE error = component->GetParameter(component, OMX_IndexParamPortDefinition, &portDef);
       
  2078 	if(error)
       
  2079 		{
       
  2080 		FailWithOmxError(_L("OMX_GetParameter()"), error);
       
  2081 		return EFalse;
       
  2082 		}
       
  2083 		
       
  2084 	error = component->SetParameter(component, OMX_IndexParamActiveStream, &portDef);
       
  2085 	if((error != OMX_ErrorNone) && (error != OMX_ErrorUnsupportedSetting))
       
  2086 		{
       
  2087 		FailWithOmxError(_L("SetParameter"), error);
       
  2088 		return EFalse;
       
  2089 		}
       
  2090 	return ETrue;
       
  2091     }
       
  2092 
       
  2093 TBool ROmxScriptTest::MosGetActiveStream(const TDesC8& aComp, TUint32 aPortIndex)
       
  2094     {
       
  2095     OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  2096 	if(!component)
       
  2097 		{
       
  2098 		return EFalse;
       
  2099 		}
       
  2100 
       
  2101 	OMX_PARAM_PORTDEFINITIONTYPE portDef;
       
  2102 	portDef.nVersion = KOmxVersion;
       
  2103 	portDef.nSize = sizeof(portDef);
       
  2104 	portDef.nPortIndex = aPortIndex;
       
  2105 
       
  2106 	OMX_ERRORTYPE error = component->GetParameter(component, OMX_IndexParamActiveStream, &portDef);
       
  2107 	if(error)
       
  2108 		{
       
  2109 		FailWithOmxError(_L("OMX_GetParameter()"), error);
       
  2110 		return EFalse;
       
  2111 		}
       
  2112 		
       
  2113 	return ETrue;
       
  2114     }
       
  2115     
       
  2116 
       
  2117 TBool ROmxScriptTest::MosSetVideoFitModeL(TVideoFitMode aVideoFitMode)
       
  2118 	{
       
  2119 	iVideoFitMode = aVideoFitMode;
       
  2120 	return ETrue;
       
  2121 	}
       
  2122 
       
  2123 // FIXME duplication with MosSetAacAudioPortDefL
       
  2124 TBool ROmxScriptTest::MosSetAACProfileL(const TDesC8& aComp, TInt aPortIndex, TInt aChannels, TInt aSamplingRate, TInt aBitRate, TInt aAudioBandwidth, TInt aFrameLength, TInt aAACTools, TInt aAACERTools, OMX_AUDIO_AACPROFILETYPE aProfile, OMX_AUDIO_AACSTREAMFORMATTYPE aStreamFormat, OMX_AUDIO_CHANNELMODETYPE aChannelMode)
       
  2125 	{
       
  2126 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  2127 	if(!component)
       
  2128 		{
       
  2129 		return EFalse;
       
  2130 		}
       
  2131 	
       
  2132 	OMX_AUDIO_PARAM_AACPROFILETYPE param;
       
  2133 	param.nSize = sizeof(param);
       
  2134 	param.nVersion = KOmxVersion;
       
  2135 	param.nPortIndex = aPortIndex;
       
  2136 	
       
  2137 	OMX_ERRORTYPE error = OMX_GetParameter(component, OMX_IndexParamAudioAac, &param);
       
  2138 	if(error)
       
  2139 		{
       
  2140 		FailWithOmxError(_L("OMX_GetParameter(AudioAAC)"), error);
       
  2141 		return EFalse;
       
  2142 		}
       
  2143 	
       
  2144 	// TODO don't overwrite unspecified values
       
  2145 	param.nChannels = aChannels;
       
  2146 	param.nSampleRate = aSamplingRate;
       
  2147 	param.nBitRate = aBitRate;
       
  2148 	param.nAudioBandWidth = aAudioBandwidth;
       
  2149 	param.nFrameLength = aFrameLength;
       
  2150 	param.nAACtools = aAACTools;
       
  2151 	param.nAACERtools = aAACERTools;
       
  2152 	param.eAACProfile = aProfile;
       
  2153 	param.eAACStreamFormat = aStreamFormat;
       
  2154 	param.eChannelMode = aChannelMode;
       
  2155 	
       
  2156 	error = OMX_SetParameter(component, OMX_IndexParamAudioAac, &param);
       
  2157 	if(error)
       
  2158 		{
       
  2159 		FailWithOmxError(_L("OMX_SetParameter(AudioAAC)"), error);
       
  2160 		return EFalse;
       
  2161 		}
       
  2162 	return ETrue;
       
  2163 	}
       
  2164 
       
  2165 TBool ROmxScriptTest::MosGetExtensionIndex(const TDesC8& aComp, const TDesC8& aParameterName, OMX_ERRORTYPE aExpectedError)
       
  2166     {
       
  2167     OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  2168 	if(!component)
       
  2169 		{
       
  2170 		return EFalse;
       
  2171 		}
       
  2172 		
       
  2173 	TBuf8<128> extension;
       
  2174 	extension.Copy(aParameterName); 
       
  2175 	
       
  2176 	OMX_INDEXTYPE indexType = OMX_IndexMax;
       
  2177 	OMX_ERRORTYPE error = component->GetExtensionIndex(component, (OMX_STRING) extension.PtrZ(), &indexType);
       
  2178 	if(error != aExpectedError)
       
  2179 		{
       
  2180 		ERR_PRINTF3(_L("MosGetExtensionIndex GetExtensionIndex() error 0x%X, expected 0x%X"), error, aExpectedError);
       
  2181 		return EFalse;
       
  2182 		}
       
  2183 
       
  2184 	return ETrue;	
       
  2185     }
       
  2186     
       
  2187 TBool ROmxScriptTest::MosCheckTimeClockState(const TDesC8& aComp, OMX_TIME_CLOCKSTATE aExpectedState)
       
  2188     {
       
  2189     OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  2190     
       
  2191 	if (!component)
       
  2192 		{
       
  2193 		StopTest(EFail);
       
  2194 		return EFalse;
       
  2195 		}
       
  2196 	
       
  2197 	OMX_TIME_CONFIG_CLOCKSTATETYPE timeClockState;
       
  2198 	timeClockState.nSize = sizeof(timeClockState);
       
  2199 	timeClockState.nVersion = KOmxVersion;
       
  2200     
       
  2201 	if(component->GetConfig(component, OMX_IndexConfigTimeClockState, &timeClockState) != OMX_ErrorNone)
       
  2202 		{
       
  2203 		StopTest(EFail);
       
  2204 		return EFalse;	
       
  2205 		}
       
  2206 	
       
  2207 	if (timeClockState.eState != aExpectedState)
       
  2208 		{
       
  2209 		ERR_PRINTF3(_L("Clock state %d does not match expected %d"), timeClockState.eState, aExpectedState);
       
  2210 		StopTest(EFail);
       
  2211 		return EFalse;	
       
  2212 		}
       
  2213 	
       
  2214 	return ETrue;
       
  2215     }
       
  2216 
       
  2217 TBool ROmxScriptTest::MosCheckMediaTime(const TDesC8& aComp, TInt aPortIndex, OMX_TICKS aMediaTime, TBool aMoreThan)
       
  2218 	{
       
  2219     OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  2220     
       
  2221 	if (!component)
       
  2222 		{
       
  2223 		StopTest(EFail);
       
  2224 		return EFalse;
       
  2225 		}
       
  2226 
       
  2227 	OMX_TIME_CONFIG_TIMESTAMPTYPE timeInfo;
       
  2228 	timeInfo.nSize = sizeof(timeInfo);
       
  2229 	timeInfo.nVersion = KOmxVersion;
       
  2230 	timeInfo.nPortIndex = aPortIndex;
       
  2231 
       
  2232 	if (component->GetConfig(component, OMX_IndexConfigTimeCurrentMediaTime, &timeInfo) != OMX_ErrorNone)
       
  2233 		{
       
  2234 		StopTest(EFail);
       
  2235 		return EFalse;	
       
  2236 		}
       
  2237 
       
  2238 	if (aMoreThan)
       
  2239 	  {
       
  2240 	    INFO_PRINTF3(_L("MosCheckMediaTime() %ld > %ld"), timeInfo.nTimestamp, aMediaTime);
       
  2241 
       
  2242 	    if (timeInfo.nTimestamp < aMediaTime)
       
  2243 		{
       
  2244 		INFO_PRINTF3(_L("FAILED! MosCheckMediaTime() Expecting %ld > %ld"), timeInfo.nTimestamp, aMediaTime);
       
  2245 		StopTest(EFail);
       
  2246 		return EFalse;	
       
  2247 		}
       
  2248 	  }
       
  2249 	else
       
  2250 	  {
       
  2251 	    INFO_PRINTF3(_L("MosCheckMediaTime() %ld < %ld"), timeInfo.nTimestamp, aMediaTime);
       
  2252 
       
  2253 	    if (timeInfo.nTimestamp > aMediaTime)
       
  2254 		{
       
  2255 		INFO_PRINTF3(_L("FAILED! MosCheckMediaTime() expecting %ld < %ld"), timeInfo.nTimestamp, aMediaTime);
       
  2256 		StopTest(EFail);
       
  2257 		return EFalse;	
       
  2258 		}
       
  2259 	  }
       
  2260 
       
  2261 	return ETrue;
       
  2262 	}
       
  2263 
       
  2264 TBool ROmxScriptTest::MosBaseSupportPortL(const TDesC8& aComp, TInt aPortIndex)
       
  2265     {
       
  2266     TInt componentIndex = iComponents.Find(aComp, ROmxScriptTest::ShortNameMatchComparison);    
       
  2267     if (componentIndex == KErrNotFound)
       
  2268         {
       
  2269         return EFalse;
       
  2270         }
       
  2271     iComponents[componentIndex]->iBaseHandler->AddPortSupportL(aPortIndex);
       
  2272  
       
  2273     return ETrue;
       
  2274     }
       
  2275 
       
  2276 TBool ROmxScriptTest::MosBaseSetAutonomous(const TDesC8& aComp, TInt aPortIndex, TBool aEnabled)
       
  2277     {
       
  2278     TInt componentIndex = iComponents.Find(aComp, ROmxScriptTest::ShortNameMatchComparison);    
       
  2279     if (componentIndex == KErrNotFound)
       
  2280         {
       
  2281         return EFalse;
       
  2282         }
       
  2283     iComponents[componentIndex]->iBaseHandler->SetAutoMode(aPortIndex, aEnabled);
       
  2284     return ETrue;   
       
  2285     }
       
  2286 
       
  2287 TBool ROmxScriptTest::MosBaseAllocateBuffersL(const TDesC8& aComp, TInt aPortIndex, TInt aNumberBuffers)
       
  2288     {
       
  2289     TInt componentIndex = iComponents.Find(aComp, ROmxScriptTest::ShortNameMatchComparison);    
       
  2290     if (componentIndex == KErrNotFound)
       
  2291         {
       
  2292         return EFalse;
       
  2293         }
       
  2294     iComponents[componentIndex]->iBaseHandler->SetupBuffersL(aPortIndex,aNumberBuffers);
       
  2295     return ETrue;     
       
  2296     }
       
  2297 	
       
  2298 TBool ROmxScriptTest::MosBaseFreeAllocatedBuffersL(const TDesC8& aComp)
       
  2299 	{
       
  2300     TInt componentIndex = iComponents.Find(aComp, ROmxScriptTest::ShortNameMatchComparison);    
       
  2301     if (componentIndex == KErrNotFound)
       
  2302         {
       
  2303         return EFalse;
       
  2304         }
       
  2305 	iComponents[componentIndex]->iBaseHandler->FreeAllocatedBuffersL();
       
  2306 	return ETrue;
       
  2307 	}
       
  2308 
       
  2309 TBool ROmxScriptTest::MosBaseSetBufSupplier(const TDesC8& aComp, TInt aPortIndex, TBool aComponentSupplier)
       
  2310     {
       
  2311     TInt componentIndex = iComponents.Find(aComp, ROmxScriptTest::ShortNameMatchComparison);    
       
  2312     if (componentIndex == KErrNotFound)
       
  2313         {
       
  2314         return EFalse;
       
  2315         }
       
  2316     iComponents[componentIndex]->iBaseHandler->SetBufferSupplier(aPortIndex, aComponentSupplier);
       
  2317     return ETrue;     
       
  2318     }
       
  2319 
       
  2320 TBool ROmxScriptTest::MosBaseFillThisBuffer(const TDesC8& aComp, TInt aPortIndex, TInt aPortRelBufIndex)
       
  2321     {
       
  2322     TInt componentIndex = iComponents.Find(aComp, ROmxScriptTest::ShortNameMatchComparison);    
       
  2323     if (componentIndex == KErrNotFound)
       
  2324         {
       
  2325         return EFalse;
       
  2326         }
       
  2327     iComponents[componentIndex]->iBaseHandler->FillThisBuffer(aPortIndex, aPortRelBufIndex);
       
  2328     return ETrue;  
       
  2329     }
       
  2330 
       
  2331 TBool ROmxScriptTest::MosBaseEmptyThisBuffer(const TDesC8& aComp, TInt aPortIndex, TInt aPortRelBufIndex)
       
  2332     {
       
  2333     TInt componentIndex = iComponents.Find(aComp, ROmxScriptTest::ShortNameMatchComparison);    
       
  2334     if (componentIndex == KErrNotFound)
       
  2335         {
       
  2336         return EFalse;
       
  2337         }
       
  2338     iComponents[componentIndex]->iBaseHandler->EmptyThisBuffer(aPortIndex, aPortRelBufIndex);
       
  2339     return ETrue;  
       
  2340     }
       
  2341 
       
  2342 TBool ROmxScriptTest::MosBaseWaitForBuffer(const TDesC8& aComp, TInt aPortIndex, TInt aPortRelBufIndex)
       
  2343     {
       
  2344     TInt componentIndex = iComponents.Find(aComp, ROmxScriptTest::ShortNameMatchComparison);    
       
  2345     if (componentIndex == KErrNotFound)
       
  2346         {
       
  2347         return EFalse;
       
  2348         }
       
  2349     iComponents[componentIndex]->iBaseHandler->WaitForBufferCompletion(aPortIndex, aPortRelBufIndex);
       
  2350     return ETrue;  
       
  2351     }
       
  2352 
       
  2353 TBool ROmxScriptTest::MosBaseTimestampPassClock(const TDesC8& aCompReceiving, const TDesC8& aClockCompToPass)
       
  2354     {
       
  2355     TInt receiveCompIndex = iComponents.Find(aCompReceiving, ROmxScriptTest::ShortNameMatchComparison);    
       
  2356     if (receiveCompIndex == KErrNotFound)
       
  2357         {
       
  2358         return EFalse;
       
  2359         }
       
  2360     
       
  2361     TInt clockCompIndex = iComponents.Find(aClockCompToPass, ROmxScriptTest::ShortNameMatchComparison);    
       
  2362     if (clockCompIndex == KErrNotFound)
       
  2363         {
       
  2364         return EFalse;
       
  2365         }
       
  2366     
       
  2367     CBaseProfileTimestampHandling* timestampBaseHandler = static_cast<CBaseProfileTimestampHandling*>(iComponents[receiveCompIndex]->iBaseHandler);
       
  2368     timestampBaseHandler->SetClockComponent(iComponents[clockCompIndex]->iComponent);
       
  2369         
       
  2370     return ETrue;
       
  2371     }
       
  2372 
       
  2373 TBool ROmxScriptTest::MosBaseTimestampCheckTimestampL(const TDesC8& aComp, TInt aPortIndex, TUint aExpectedTime, TUint aTolerance)
       
  2374     {
       
  2375     TInt componentIndex = iComponents.Find(aComp, ROmxScriptTest::ShortNameMatchComparison);    
       
  2376     if (componentIndex == KErrNotFound)
       
  2377         {
       
  2378         return EFalse;
       
  2379         }
       
  2380     
       
  2381     CBaseProfileTimestampHandling* timestampBaseHandler = static_cast<CBaseProfileTimestampHandling*>(iComponents[componentIndex]->iBaseHandler);
       
  2382     timestampBaseHandler->QueueTimestampCheckL(aPortIndex, aExpectedTime, aTolerance);
       
  2383 
       
  2384     return ETrue;
       
  2385     }
       
  2386 
       
  2387 TBool ROmxScriptTest::MosBaseTimestampCompareWithRefClockL(const TDesC8& aComp, TInt aPortIndex, TUint aTolerance)
       
  2388     {
       
  2389     TInt componentIndex = iComponents.Find(aComp, ROmxScriptTest::ShortNameMatchComparison);    
       
  2390     if (componentIndex == KErrNotFound)
       
  2391         {
       
  2392         return EFalse;
       
  2393         }
       
  2394     
       
  2395     CBaseProfileTimestampHandling* timestampBaseHandler = static_cast<CBaseProfileTimestampHandling*>(iComponents[componentIndex]->iBaseHandler);
       
  2396     timestampBaseHandler->QueueCompareWithRefClockL(aPortIndex, aTolerance);
       
  2397 
       
  2398     return ETrue;
       
  2399     }
       
  2400 
       
  2401 
       
  2402 TBool ROmxScriptTest::MosStartBuffersforPort( const TDesC8& aComp, TInt aPortIndex)
       
  2403     {
       
  2404     OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  2405      if(!component)
       
  2406          {
       
  2407          return EFalse;
       
  2408          }
       
  2409      
       
  2410      if(iPortBufferHandler)
       
  2411          {
       
  2412          iPortBufferHandler->Start(component,aPortIndex);
       
  2413          }
       
  2414      return ETrue;
       
  2415     }
       
  2416 
       
  2417 void ROmxScriptTest::BeginWait()
       
  2418 	{
       
  2419 	CActiveScheduler::Start();
       
  2420 	}
       
  2421 
       
  2422 void ROmxScriptTest::EndWait()
       
  2423 	{
       
  2424 	// use a CAsyncCallBack to call CActiveScheduler::Stop
       
  2425 	// the main reason for doing this is to allow EndWait
       
  2426 	// to be called from any thread but to stop the scheduler
       
  2427 	// of the script parser thread.
       
  2428 	iStopSchedulerCallback->CallBack();
       
  2429 	}
       
  2430 
       
  2431 
       
  2432 
       
  2433 //
       
  2434 TBool ROmxScriptTest::MosDeleteFileL(const TDesC& aFileName, TBool aFileMustExist)
       
  2435 	{
       
  2436 	RFs fs;
       
  2437 	
       
  2438 	User::LeaveIfError(fs.Connect());
       
  2439 	CleanupClosePushL(fs);
       
  2440 	TInt err = fs.Delete(aFileName);
       
  2441 	if (err != KErrNone)
       
  2442 		{
       
  2443 		if (err != KErrNotFound || aFileMustExist)
       
  2444 			{
       
  2445 			ERR_PRINTF3(_L("Error %d deleting file %S"), err, &aFileName);
       
  2446 			User::Leave(err);
       
  2447 			}
       
  2448 		}
       
  2449 
       
  2450 	INFO_PRINTF2(_L("Deleted file %S"), &aFileName);
       
  2451 
       
  2452 	CleanupStack::PopAndDestroy(&fs);
       
  2453 	return ETrue;
       
  2454 	}
       
  2455 
       
  2456 //
       
  2457 //
       
  2458 //
       
  2459 TBool ROmxScriptTest::MosLogAllEventsL()
       
  2460 	{
       
  2461 	return ETrue;
       
  2462 	}
       
  2463 
       
  2464 //
       
  2465 //
       
  2466 //
       
  2467 TBool ROmxScriptTest::MosSetSensorModeTypeL(const TDesC8& aComp, TInt aPort, TInt aFrameRate, TBool aOneShot, TInt aWidth, TInt aHeight)
       
  2468 	{
       
  2469 	OMX_COMPONENTTYPE* comp = ComponentByName(aComp);
       
  2470 	if (!comp)
       
  2471 		{
       
  2472 		return EFalse;
       
  2473 		}
       
  2474 	
       
  2475 	OMX_PARAM_SENSORMODETYPE sensor;
       
  2476 	sensor.nVersion = KOmxVersion;
       
  2477 	sensor.nSize = sizeof(OMX_PARAM_SENSORMODETYPE);
       
  2478 	sensor.nPortIndex = aPort;
       
  2479 	sensor.sFrameSize.nSize = sizeof(OMX_FRAMESIZETYPE);
       
  2480 	sensor.sFrameSize.nVersion = KOmxVersion;
       
  2481 	sensor.sFrameSize.nPortIndex = aPort;
       
  2482 
       
  2483 	OMX_ERRORTYPE omxErr = comp->GetParameter(comp, OMX_IndexParamCommonSensorMode, &sensor);
       
  2484 	if (omxErr != OMX_ErrorNone)
       
  2485 		{
       
  2486 		ERR_PRINTF2(_L("Error %08X returned from GetParameter"), omxErr);
       
  2487 		return EFalse;
       
  2488 		}
       
  2489 		
       
  2490 	sensor.bOneShot = (aOneShot ? OMX_TRUE : OMX_FALSE);
       
  2491 	if (aFrameRate != -1) sensor.nFrameRate = aFrameRate;	
       
  2492 	if (aWidth != -1) sensor.sFrameSize.nWidth = aWidth;
       
  2493 	if (aHeight != -1) sensor.sFrameSize.nHeight = aHeight;
       
  2494 	
       
  2495 	omxErr = comp->SetParameter(comp, OMX_IndexParamCommonSensorMode, &sensor);
       
  2496 	if (omxErr != OMX_ErrorNone)
       
  2497 		{
       
  2498 		ERR_PRINTF2(_L("Error %08X returned from SetParameter"), omxErr);
       
  2499 		}
       
  2500 		
       
  2501 	return (omxErr == OMX_ErrorNone);
       
  2502 	}
       
  2503 
       
  2504 //
       
  2505 //
       
  2506 //
       
  2507 TBool ROmxScriptTest::MosSetCaptureModeTypeL(const TDesC8& aComp, TInt aPort, TBool aContinuous, TBool aFrameLimited, TInt aFrameLimit)
       
  2508     {
       
  2509     OMX_COMPONENTTYPE* comp = ComponentByName(aComp);
       
  2510     if (!comp)
       
  2511         {
       
  2512         return EFalse;
       
  2513         }
       
  2514     
       
  2515     OMX_CONFIG_CAPTUREMODETYPE captureModeType;  
       
  2516     captureModeType.nSize = sizeof(OMX_CONFIG_CAPTUREMODETYPE);
       
  2517     captureModeType.nVersion = KOmxVersion;
       
  2518     captureModeType.nPortIndex = aPort;
       
  2519     captureModeType.bContinuous = (aContinuous ? OMX_TRUE : OMX_FALSE); 
       
  2520     captureModeType.bFrameLimited = (aFrameLimited ? OMX_TRUE : OMX_FALSE);
       
  2521     captureModeType.nFrameLimit = aFrameLimit;
       
  2522     OMX_ERRORTYPE omxErr = comp->SetConfig(comp,OMX_IndexConfigCaptureMode,&captureModeType); 
       
  2523     
       
  2524     if (omxErr != OMX_ErrorNone)
       
  2525         {
       
  2526         ERR_PRINTF2(_L("Error %08X returned from SetConfig"), omxErr);
       
  2527         }
       
  2528     
       
  2529     return (omxErr == OMX_ErrorNone);
       
  2530     }
       
  2531 
       
  2532 //
       
  2533 
       
  2534 static TInt StopScheduler(TAny* /*unused*/)
       
  2535 	{
       
  2536 	CActiveScheduler::Stop();
       
  2537 	return 0;
       
  2538 	}
       
  2539 
       
  2540 void ROmxScriptTest::StopTest(TOmxScriptTestVerdict aVerdict)
       
  2541 	{
       
  2542 	switch(aVerdict)
       
  2543 		{
       
  2544 	case EPass:
       
  2545 		StopTest(KErrNone, EPass);
       
  2546 		break;
       
  2547 	case EFail:
       
  2548 		StopTest(KErrGeneral, EFail);
       
  2549 		break;
       
  2550 	default:
       
  2551 		User::Invariant();
       
  2552 		}
       
  2553 	}
       
  2554 
       
  2555 /**
       
  2556  * Stores the result of the test case. If called multiple times, the first
       
  2557  * case of EFail will persist.
       
  2558  * @param aError system-wide error code
       
  2559  * @param aVerdict either EPass or EFail
       
  2560  */
       
  2561 void ROmxScriptTest::StopTest(TInt aError, TOmxScriptTestVerdict aVerdict)
       
  2562 	{
       
  2563 	__ASSERT_ALWAYS(aVerdict != EPending, User::Invariant());
       
  2564 	// first negative result persists
       
  2565 	if(iVerdict != EFail)
       
  2566 		{
       
  2567 		iReason = aError;
       
  2568 		iVerdict = aVerdict;
       
  2569 		}
       
  2570 	}
       
  2571 
       
  2572 void ROmxScriptTest::FailTest(const TDesC& aErrorMsg)
       
  2573     {
       
  2574     ERR_PRINTF1(aErrorMsg);
       
  2575     StopTest(EFail);
       
  2576     }
       
  2577 
       
  2578 /**
       
  2579  * @return the error code set via StopTest. Defaults to KErrNone.
       
  2580  */
       
  2581 TInt ROmxScriptTest::Reason() const
       
  2582 	{
       
  2583 	return iReason;
       
  2584 	}
       
  2585 
       
  2586 /**
       
  2587  * @return the verdict set via StopTest. Defaults to EPending.
       
  2588  */
       
  2589 ROmxScriptTest::TOmxScriptTestVerdict ROmxScriptTest::Verdict() const
       
  2590 	{
       
  2591 	return iVerdict;
       
  2592 	}
       
  2593 
       
  2594 /**
       
  2595  * Overflow handler to generate a warning message if a log line will not fit
       
  2596  * in the descriptor.
       
  2597  */
       
  2598 class TOverflowHandler : public TDes16Overflow
       
  2599 	{
       
  2600 public:
       
  2601 	void Overflow(TDes& aDes)
       
  2602 		{
       
  2603 		_LIT(KWarning, "[truncated]");
       
  2604 		if(aDes.Length() + KWarning().Length() > aDes.MaxLength())
       
  2605 			{
       
  2606 			aDes.SetLength(aDes.Length() - KWarning().Length());
       
  2607 			}
       
  2608 		aDes.Append(KWarning);
       
  2609 		}
       
  2610 	};
       
  2611 
       
  2612 /**
       
  2613  * Target of ERR_PRINTFx, INFO_PRINTFx, WARN_PRINTFx macros.
       
  2614  * Message is formatted then passed to the MOmxScriptTestLogger.
       
  2615  */
       
  2616 void ROmxScriptTest::LogExtra(const TText8* aFile, TInt aLine, TOmxScriptSeverity aSeverity,
       
  2617 			TRefByValue<const TDesC16> aFmt,...)
       
  2618 	{
       
  2619 	VA_LIST aList;
       
  2620 	VA_START(aList, aFmt);
       
  2621 
       
  2622 	TOverflowHandler overflow;
       
  2623 	TBuf<255> msg;
       
  2624 	msg.AppendFormatList(aFmt, aList, &overflow);
       
  2625 	
       
  2626 	iLogger.Log(aFile, aLine, aSeverity, msg);
       
  2627 	
       
  2628 	VA_END(aList);
       
  2629 	}
       
  2630 
       
  2631 void ROmxScriptTest::RegisterTunnel(OMX_COMPONENTTYPE* aSourceComp, TInt aSourcePort, OMX_COMPONENTTYPE* aSinkComp, TInt aSinkPort)
       
  2632 	{
       
  2633 	// delete previous registration
       
  2634 	for(TInt index = 0, count = iTunnels.Count(); index < count; index++)
       
  2635 		{
       
  2636 		const TTunnelInfo& info = iTunnels[index];
       
  2637 		if(info.iSourceComponent == aSourceComp && info.iSourcePort == aSourcePort ||
       
  2638 			info.iSinkComponent == aSinkComp && info.iSinkPort == aSinkPort)
       
  2639 			{
       
  2640 			iTunnels.Remove(index);
       
  2641 			index--;
       
  2642 			count--;
       
  2643 			}
       
  2644 		}
       
  2645 	
       
  2646 	TTunnelInfo info;
       
  2647 	info.iSourceComponent = aSourceComp;
       
  2648 	info.iSourcePort = aSourcePort;
       
  2649 	info.iSinkComponent = aSinkComp;
       
  2650 	info.iSinkPort = aSinkPort;
       
  2651 	TInt error = iTunnels.Append(info);
       
  2652 	if(error)
       
  2653 		{
       
  2654 		User::Panic(_L("omxscript"), KErrNoMemory);
       
  2655 		}
       
  2656 	}
       
  2657 
       
  2658 void ROmxScriptTest::FindTransitionOrderL(const RPointerArray<CComponentInfo>& aComponents,
       
  2659 						  const RTunnelRelations& aTunnelRelations,
       
  2660 						  RArray<TInt>& aOrder)
       
  2661 	{
       
  2662 	RPointerArray<OMX_COMPONENTTYPE> componentsSimple;
       
  2663 	CleanupClosePushL(componentsSimple);
       
  2664 	componentsSimple.ReserveL(aComponents.Count());
       
  2665 	for(TInt index = 0, count = aComponents.Count(); index < count; index++)
       
  2666 		{
       
  2667 		componentsSimple.AppendL(aComponents[index]->iComponent);
       
  2668 		}
       
  2669 	RSupplierRelations supplierRelations;
       
  2670 	CleanupStack::PushL(TCleanupItem(CloseSupplierRelations, &supplierRelations));
       
  2671 	TInt numComponents = aComponents.Count();
       
  2672 	supplierRelations.ReserveL(numComponents);
       
  2673 	for(TInt index = 0; index < numComponents; index++)
       
  2674 		{
       
  2675 		supplierRelations.Append(RArray<TInt>());
       
  2676 		}
       
  2677 	TInt numTunnels = aTunnelRelations.Count();
       
  2678 	for(TInt index = 0; index < numTunnels; index++)
       
  2679 		{
       
  2680 		const TTunnelInfo& tunnelInfo = aTunnelRelations[index];
       
  2681 		TInt outputCompIndex = componentsSimple.Find(tunnelInfo.iSourceComponent);
       
  2682 		User::LeaveIfError(outputCompIndex);
       
  2683 		TInt inputCompIndex = componentsSimple.Find(tunnelInfo.iSinkComponent);
       
  2684 		User::LeaveIfError(inputCompIndex);
       
  2685 		
       
  2686 		OMX_PARAM_BUFFERSUPPLIERTYPE supplier;
       
  2687 		supplier.nSize = sizeof(supplier);
       
  2688 		supplier.nVersion = KOmxVersion;
       
  2689 		supplier.nPortIndex = tunnelInfo.iSourcePort;
       
  2690 		OMX_ERRORTYPE error = OMX_GetParameter(tunnelInfo.iSourceComponent,
       
  2691 				OMX_IndexParamCompBufferSupplier,
       
  2692 				&supplier);
       
  2693 		if(error != OMX_ErrorNone)
       
  2694 			{
       
  2695 			User::Leave(KErrGeneral);
       
  2696 			}
       
  2697 		if(supplier.eBufferSupplier == OMX_BufferSupplyInput)
       
  2698 			{
       
  2699 			supplierRelations[inputCompIndex].AppendL(outputCompIndex);
       
  2700 			}
       
  2701 		else if(supplier.eBufferSupplier == OMX_BufferSupplyOutput)
       
  2702 			{
       
  2703 			supplierRelations[outputCompIndex].AppendL(inputCompIndex);
       
  2704 			}
       
  2705 		else
       
  2706 			{
       
  2707 			User::Leave(KErrArgument);
       
  2708 			}
       
  2709 		}
       
  2710 
       
  2711 	::FindTransitionOrderL(supplierRelations, aOrder);
       
  2712 	
       
  2713 	CleanupStack::PopAndDestroy(2, &componentsSimple);
       
  2714 	}
       
  2715 
       
  2716 TBool ROmxScriptTest::MosCheckClockStateL(const TDesC8& aComp, OMX_TIME_CLOCKSTATE aClockState)
       
  2717 	{
       
  2718 	/*
       
  2719 	TODO: Verify that this is a clock component?
       
  2720 	 */
       
  2721 	
       
  2722 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  2723 	if(!component)
       
  2724 		{
       
  2725 		return EFalse;
       
  2726 		}
       
  2727 
       
  2728 	OMX_TIME_CONFIG_CLOCKSTATETYPE conf;
       
  2729 	conf.nVersion = KOmxVersion;
       
  2730 	conf.nSize = sizeof(conf);
       
  2731 	/*
       
  2732 	Completed by GetConfig()
       
  2733 
       
  2734 	conf.eState
       
  2735 	conf.nStartTime
       
  2736 	conf.nOffset
       
  2737 	conf.nWaitMask
       
  2738 	*/
       
  2739 
       
  2740 	OMX_ERRORTYPE error = component->GetConfig(component, OMX_IndexConfigTimeClockState, &conf);
       
  2741 	if(error != OMX_ErrorNone)
       
  2742 		{
       
  2743 		FailWithOmxError(_L("OMX_GetConfig(OMX_IndexConfigTimeClockState)"), error);
       
  2744 		return EFalse;
       
  2745 		}
       
  2746 
       
  2747 	if(conf.eState != aClockState)
       
  2748 		{
       
  2749 // TODO: What about the other values?
       
  2750 		ERR_PRINTF3(_L("Clock component expected to be in clock state %S, is actually in %S"), ClockStateDes(aClockState), ClockStateDes(conf.eState));
       
  2751 		StopTest(EFail);
       
  2752 		return EFalse;
       
  2753 		}
       
  2754 	
       
  2755 	TBuf<64> compConverted;
       
  2756 	compConverted.Copy(aComp);
       
  2757 	INFO_PRINTF3(_L("State of %S is %S"), &compConverted, ClockStateDes(aClockState));
       
  2758 	
       
  2759 	return ETrue;
       
  2760 	}
       
  2761 
       
  2762 // for debugging...
       
  2763 TBool ROmxScriptTest::MosCheckTimePositionL(const TDesC8& aComp, TInt aPortIndex, TInt aTimestamp)
       
  2764     {
       
  2765     OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  2766     if(!component)
       
  2767         {
       
  2768         return EFalse;
       
  2769         }
       
  2770 
       
  2771     OMX_TIME_CONFIG_TIMESTAMPTYPE conf;
       
  2772     conf.nVersion = KOmxVersion;
       
  2773     conf.nSize = sizeof(conf);
       
  2774     conf.nPortIndex = aPortIndex;
       
  2775     /*
       
  2776     To be filled by GetConfig()
       
  2777     conf.nTimestamp;
       
  2778     */ 
       
  2779 
       
  2780     OMX_ERRORTYPE error = component->GetConfig(component, OMX_IndexConfigTimePosition, &conf);
       
  2781     if(error != OMX_ErrorNone)
       
  2782         {
       
  2783         FailWithOmxError(_L("OMX_GetConfig(OMX_IndexConfigTimePosition)"), error);
       
  2784         return EFalse;
       
  2785         }
       
  2786 	if(conf.nTimestamp != aTimestamp)
       
  2787 		{
       
  2788 		TBuf<64> compConverted;
       
  2789 		compConverted.Copy(aComp);
       
  2790 		ERR_PRINTF5(_L("Port %d of component %S time position expected to be %d, but is actually %d"), aPortIndex, &compConverted, aTimestamp, conf.nTimestamp);
       
  2791 		StopTest(EFail);
       
  2792 		return EFalse;
       
  2793 		}
       
  2794     
       
  2795     TBuf<64> compConverted;
       
  2796     compConverted.Copy(aComp);
       
  2797     INFO_PRINTF4(_L("Port %d of component %S time position verified to be %d"), aPortIndex, &compConverted, conf.nTimestamp);
       
  2798     
       
  2799     return ETrue;
       
  2800     }
       
  2801 
       
  2802 TBool ROmxScriptTest::MosSetTimePositionL(const TDesC8& aComp, TInt aPortIndex, TInt aTimestamp)
       
  2803     {
       
  2804     OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  2805     if(!component)
       
  2806         {
       
  2807         return EFalse;
       
  2808         }
       
  2809 
       
  2810     OMX_TIME_CONFIG_TIMESTAMPTYPE conf;
       
  2811     conf.nVersion = KOmxVersion;
       
  2812     conf.nSize = sizeof(conf);
       
  2813     conf.nPortIndex = aPortIndex;
       
  2814     conf.nTimestamp = aTimestamp;
       
  2815 
       
  2816     OMX_ERRORTYPE error = component->SetConfig(component, OMX_IndexConfigTimePosition, &conf);
       
  2817     if(error != OMX_ErrorNone)
       
  2818         {
       
  2819         FailWithOmxError(_L("OMX_SetConfig(OMX_IndexConfigTimePosition)"), error);
       
  2820         return EFalse;
       
  2821         }
       
  2822     
       
  2823     TBuf<64> compConverted;
       
  2824     compConverted.Copy(aComp);
       
  2825     INFO_PRINTF4(_L("Port %d of component %S time position set to %d"), aPortIndex, &compConverted, aTimestamp);
       
  2826     
       
  2827     return ETrue;
       
  2828     }
       
  2829 TBool ROmxScriptTest::MosMarkBuffer(const TDesC8& aComp, TInt aPortIndex, const TDesC8& aTargetComp, TInt markData)
       
  2830 	{
       
  2831 	OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  2832 	OMX_COMPONENTTYPE* targetComponent = ComponentByName(aTargetComp);
       
  2833 	if(component == NULL || targetComponent == NULL)
       
  2834 		{
       
  2835 		return EFalse;
       
  2836 		}
       
  2837 	
       
  2838 	OMX_MARKTYPE mark;
       
  2839 	mark.hMarkTargetComponent = targetComponent;
       
  2840 	mark.pMarkData = reinterpret_cast<TAny*>(markData);
       
  2841 	
       
  2842 	OMX_ERRORTYPE error = OMX_SendCommand(component, OMX_CommandMarkBuffer, aPortIndex, &mark);
       
  2843 	if(error)
       
  2844 		{
       
  2845 		FailWithOmxError(aComp, _L("SendCommand(MarkBuffer)"), error);
       
  2846 		return EFalse;
       
  2847 		}
       
  2848 	else
       
  2849 		{
       
  2850 		return ETrue;
       
  2851 		}
       
  2852 	}
       
  2853 
       
  2854 void ROmxScriptTest::MosParseError(const TDesC& aError)
       
  2855     {
       
  2856     ERR_PRINTF1(aError);
       
  2857     }
       
  2858 
       
  2859 ROmxScriptTest::CComponentInfo* ROmxScriptTest::CComponentInfo::NewL(ROmxScriptTest& aTestController)
       
  2860     {
       
  2861     CComponentInfo* self = new (ELeave) CComponentInfo(aTestController);
       
  2862     CleanupStack::PushL(self);
       
  2863     self->ConstructL();
       
  2864     CleanupStack::Pop(self);
       
  2865     return self;
       
  2866     }
       
  2867 
       
  2868 void ROmxScriptTest::CComponentInfo::ConstructL()
       
  2869     {
       
  2870 	}
       
  2871 
       
  2872 TBool ROmxScriptTest::MosSetClientStartTimeL(const TDesC8& aComp, TInt aPortIndex, TInt aTimestamp)
       
  2873     {
       
  2874     OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  2875     if(!component)
       
  2876         {
       
  2877         return EFalse;
       
  2878         }
       
  2879 
       
  2880     OMX_TIME_CONFIG_TIMESTAMPTYPE conf;
       
  2881     conf.nVersion = KOmxVersion;
       
  2882     conf.nSize = sizeof(conf);
       
  2883     conf.nPortIndex = aPortIndex;
       
  2884     conf.nTimestamp = aTimestamp;
       
  2885 
       
  2886     OMX_ERRORTYPE error = component->SetConfig(component, OMX_IndexConfigTimeClientStartTime, &conf);
       
  2887     if(error != OMX_ErrorNone)
       
  2888         {
       
  2889         FailWithOmxError(_L("OMX_SetConfig(OMX_IndexConfigTimeClientStartTime)"), error);
       
  2890         return EFalse;
       
  2891         }
       
  2892     
       
  2893     TBuf<64> compConverted;
       
  2894     compConverted.Copy(aComp);
       
  2895     INFO_PRINTF4(_L("Port %d of component %S time position set to %d"), aPortIndex, &compConverted, aTimestamp);
       
  2896     
       
  2897     return ETrue;
       
  2898     }
       
  2899 
       
  2900 TBool ROmxScriptTest::MosSetCurrentAudioReferenceTimeL(const TDesC8& aComp, TInt aPortIndex, TInt aTimestamp)
       
  2901     {
       
  2902     OMX_COMPONENTTYPE* component = ComponentByName(aComp);
       
  2903     if(!component)
       
  2904         {
       
  2905         return EFalse;
       
  2906         }
       
  2907 
       
  2908     OMX_TIME_CONFIG_TIMESTAMPTYPE conf;
       
  2909     conf.nVersion = KOmxVersion;
       
  2910     conf.nSize = sizeof(conf);
       
  2911     conf.nPortIndex = aPortIndex;
       
  2912     conf.nTimestamp = aTimestamp;
       
  2913 
       
  2914     OMX_ERRORTYPE error = component->SetConfig(component, OMX_IndexConfigTimeCurrentAudioReference, &conf);
       
  2915     if(error != OMX_ErrorNone)
       
  2916         {
       
  2917         FailWithOmxError(_L("OMX_SetConfig(OMX_IndexConfigTimeCurrentAudioReference)"), error);
       
  2918         return EFalse;
       
  2919         }
       
  2920     
       
  2921     TBuf<64> compConverted;
       
  2922     compConverted.Copy(aComp);
       
  2923     INFO_PRINTF4(_L("Port %d of component %S time position set to %d"), aPortIndex, &compConverted, aTimestamp);
       
  2924     
       
  2925     return ETrue;
       
  2926     }
       
  2927 
       
  2928 	
       
  2929 ROmxScriptTest::CComponentInfo::CComponentInfo(ROmxScriptTest& aTestController)
       
  2930 : iTestController(aTestController)    
       
  2931     {
       
  2932     }
       
  2933 
       
  2934 ROmxScriptTest::CComponentInfo::~CComponentInfo()
       
  2935     {
       
  2936     // convert from 8-bit descriptors for logging
       
  2937     TBuf<64> shortName;
       
  2938     TBuf<64> compName;
       
  2939     shortName.Copy(*iShortName);
       
  2940     compName.Copy(*iComponentName);
       
  2941     OMX_ERRORTYPE error = OMX_ErrorNone;
       
  2942     if(iComponent != NULL)
       
  2943         {
       
  2944         iTestController.INFO_PRINTF3(_L("Unloading component %S (%S)"), &shortName, &compName);
       
  2945         if(iThreadRequest != NULL)
       
  2946             {
       
  2947             error = iThreadRequest->FreeHandle(iComponent);
       
  2948             delete iShortName;
       
  2949             delete iComponentName;
       
  2950             delete iBaseHandler;
       
  2951             }
       
  2952         else
       
  2953             {
       
  2954             delete iShortName;
       
  2955             delete iComponentName;
       
  2956             delete iBaseHandler;
       
  2957             error = OMX_FreeHandle(iComponent);
       
  2958             }
       
  2959         }
       
  2960     
       
  2961     if(error)
       
  2962         {
       
  2963         iTestController.FailWithOmxError(_L("OMX_FreeHandle()"), error);
       
  2964         }
       
  2965     delete iThreadRequest;
       
  2966 	}
       
  2967 void HashFilter_16bit_EndianSwap(RBuf8& aBuf)
       
  2968     {
       
  2969     for (TInt i=0;i<aBuf.Length();i+=2)
       
  2970         {
       
  2971         TUint8 tmp = aBuf[i];
       
  2972         aBuf[i] = aBuf[i+1];
       
  2973         aBuf[i+1] = tmp;
       
  2974         }
       
  2975     }
       
  2976 
       
  2977 void HashFilter_16bit_BE_SignednessSwap(RBuf8& aBuf)
       
  2978     {
       
  2979     for (TInt i=0;i<aBuf.Length();i+=2)
       
  2980         {
       
  2981         aBuf[i] ^= 0x80;
       
  2982         }
       
  2983     }
       
  2984 
       
  2985 void HashFilter_16bit_LE_SignednessSwap(RBuf8& aBuf)
       
  2986     {
       
  2987     for (TInt i=0;i<aBuf.Length();i+=2)
       
  2988         {
       
  2989         aBuf[i+1] ^= 0x80;
       
  2990         }
       
  2991     }
       
  2992 
       
  2993 void HashFilter_16bit_BE_MsbOnly(RBuf8& aBuf)
       
  2994     {
       
  2995     TInt src = 0;
       
  2996     TInt dest = 0;
       
  2997     
       
  2998     while (src<aBuf.Length())
       
  2999         {
       
  3000         aBuf[dest] = aBuf[src];
       
  3001         src+=2;
       
  3002         dest++;
       
  3003         }
       
  3004     
       
  3005     aBuf.SetLength(dest);
       
  3006     }
       
  3007 
       
  3008 void HashFilter_16bit_LE_MsbOnly(RBuf8& aBuf)
       
  3009     {
       
  3010     TInt src = 1;
       
  3011     TInt dest = 0;
       
  3012     
       
  3013     while (src<aBuf.Length())
       
  3014         {
       
  3015         aBuf[dest] = aBuf[src];
       
  3016         src+=2;
       
  3017         dest++;
       
  3018         }
       
  3019     
       
  3020     aBuf.SetLength(dest);
       
  3021     }
       
  3022 
       
  3023 ROmxScriptTest::THashFilter ROmxScriptTest::GetHashFilterByName(const TDesC8& aName)
       
  3024     {
       
  3025     if (aName.Length()==0) return NULL;
       
  3026     else if (aName==_L8("endianswap")) return &HashFilter_16bit_EndianSwap;
       
  3027     else if (aName==_L8("signswap16be")) return &HashFilter_16bit_BE_SignednessSwap;
       
  3028     else if (aName==_L8("signswap16le")) return &HashFilter_16bit_LE_SignednessSwap;
       
  3029     else if (aName==_L8("msbonly16be")) return &HashFilter_16bit_BE_MsbOnly;
       
  3030     else if (aName==_L8("msbonly16le")) return &HashFilter_16bit_LE_MsbOnly;
       
  3031     else User::Invariant();
       
  3032     return NULL; // Inaccessible
       
  3033     }