omxil/omxilcomponentcommon/src/common/omxilfsm.cpp
changeset 0 40261b775718
child 16 eedf2dcd43c6
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 /**
       
    18  @file
       
    19  @internalComponent
       
    20 */
       
    21 
       
    22 #include "log.h"
       
    23 #include "omxilfsm.h"
       
    24 #include "omxilstate.h"
       
    25 #include "omxilportmanager.h"
       
    26 #include "omxilconfigmanager.h"
       
    27 #include "omxilcallbackmanager.h"
       
    28 #include "omxilprocessingfunction.h"
       
    29 
       
    30 #define RETURN_OMX_ERROR_AND_EVENT_IF_NEEDED(_a)						\
       
    31 	{																	\
       
    32 	const OMX_ERRORTYPE _err = _a;										\
       
    33 	if (OMX_ErrorNone == _err) return _err;								\
       
    34 	else return SendOmxErrorEventIfNeeded(_err);						\
       
    35 	}
       
    36 
       
    37 
       
    38 const TInt COmxILFsm::KMaxMsgQueueEntries;
       
    39 
       
    40 EXPORT_C COmxILFsm*
       
    41 COmxILFsm::NewL(COmxILComponent& aComponent,
       
    42 				COmxILProcessingFunction& aProcFunction,
       
    43 				COmxILPortManager& aPortManager,
       
    44 				COmxILConfigManager& aConfigManager,
       
    45 				MOmxILCallbackManagerIf& aCallbacks)
       
    46 	{
       
    47     DEBUG_PRINTF(_L8("COmxILFsm::NewLC"));
       
    48 
       
    49 	COmxILFsm* self = new (ELeave) COmxILFsm(aComponent,
       
    50 											 aProcFunction,
       
    51 											 aPortManager,
       
    52 											 aConfigManager,
       
    53 											 aCallbacks);
       
    54 	CleanupStack::PushL(self);
       
    55 	self->ConstructL();
       
    56 	CleanupStack::Pop(self);
       
    57 	return (self);
       
    58 	}
       
    59 
       
    60 void
       
    61 COmxILFsm::ConstructL()
       
    62 	{
       
    63     DEBUG_PRINTF(_L8("COmxILFsm::ConstructL"));
       
    64 
       
    65 	// Create the FSM states
       
    66 
       
    67 	// Init the array
       
    68 	for (TUint i=0; i < EStateMax; ++i)
       
    69 		{
       
    70 		iStates.AppendL(NULL);
       
    71 		}
       
    72 
       
    73 	// Add the standard states...
       
    74 	iStates[EStateInvalid]			= new (ELeave)COmxILStateInvalid;
       
    75 	iStates[EStateLoaded]			= new (ELeave)COmxILStateLoaded;
       
    76 	iStates[EStateIdle]				= new (ELeave)COmxILStateIdle;
       
    77 	iStates[EStateExecuting]		= new (ELeave)COmxILStateExecuting;
       
    78 	iStates[EStatePause]			= new (ELeave)COmxILStatePause;
       
    79 	iStates[EStateWaitForResources] = new (ELeave)COmxILStateWaitForResources;
       
    80 
       
    81 	// Now add the substates
       
    82 	iStates[ESubStateLoadedToIdle]	  = new (ELeave)COmxILStateLoadedToIdle;
       
    83 	iStates[ESubStateIdleToLoaded]	  = new (ELeave)COmxILStateIdleToLoaded;
       
    84 	iStates[ESubStateExecutingToIdle] = new (ELeave)COmxILStateExecutingToIdle;
       
    85 	iStates[ESubStatePauseToIdle]	  = new (ELeave)COmxILStatePauseToIdle;
       
    86 
       
    87 	iCallbacks.SetPortManager(iPortManager);
       
    88 	iCallbacks.SetFsm(*this);
       
    89 
       
    90 	}
       
    91 
       
    92 COmxILFsm::COmxILFsm(COmxILComponent& aComponent,
       
    93 					 COmxILProcessingFunction& aProcFunction,
       
    94 					 COmxILPortManager& aPortManager,
       
    95 					 COmxILConfigManager& aConfigManager,
       
    96 					 MOmxILCallbackManagerIf& aCallbacks)
       
    97 	:
       
    98 	iComponent(aComponent),
       
    99 	iProcFunction(aProcFunction),
       
   100 	iPortManager(aPortManager),
       
   101 	iConfigManager(aConfigManager),
       
   102 	iCallbacks(aCallbacks),
       
   103 	iStates(),
       
   104 	iCurrentStateIndex(EStateMax),
       
   105 	ipCurrentState(0)
       
   106 	{
       
   107     DEBUG_PRINTF(_L8("COmxILFsm::COmxILFsm"));
       
   108 	}
       
   109 
       
   110 COmxILFsm::~COmxILFsm()
       
   111 	{
       
   112     DEBUG_PRINTF(_L8("COmxILFsm::~COmxILFsm"));
       
   113 
       
   114 	iCurrentStateIndex = EStateMax;
       
   115 	ipCurrentState = 0;
       
   116 	iStates.ResetAndDestroy();
       
   117 
       
   118 	}
       
   119 
       
   120 OMX_ERRORTYPE
       
   121 COmxILFsm::InitFsm()
       
   122 	{
       
   123     DEBUG_PRINTF(_L8("COmxILFsm::InitFsm"));
       
   124 
       
   125 	// Let's get ready to handle API calls...
       
   126 	iCurrentStateIndex = EStateLoaded;
       
   127 	ipCurrentState	   = iStates[iCurrentStateIndex];
       
   128 	return OMX_ErrorNone;
       
   129 
       
   130 	}
       
   131 
       
   132 COmxILComponent*
       
   133 COmxILFsm::GetComponent() const
       
   134 	{
       
   135 	return &iComponent;
       
   136 	}
       
   137 
       
   138 OMX_ERRORTYPE
       
   139 COmxILFsm::PopulateBuffer(OMX_BUFFERHEADERTYPE** appBufferHdr,
       
   140 						  OMX_U32 aPortIndex,
       
   141 						  OMX_PTR apAppPrivate,
       
   142 						  OMX_U32 aSizeBytes,
       
   143 						  OMX_U8* apBuffer)
       
   144 	{
       
   145     DEBUG_PRINTF(_L8("COmxILFsm::PopulateBuffer"));
       
   146 
       
   147 	TBool portPopulationCompleted = EFalse;
       
   148 	OMX_ERRORTYPE omxRetValue =
       
   149 		ipCurrentState->PopulateBuffer(*this,
       
   150 									   appBufferHdr,
       
   151 									   aPortIndex,
       
   152 									   apAppPrivate,
       
   153 									   aSizeBytes,
       
   154 									   apBuffer,
       
   155 									   portPopulationCompleted);
       
   156 
       
   157 	if (OMX_ErrorNone == omxRetValue)
       
   158 		{
       
   159 		if (portPopulationCompleted &&
       
   160 			ESubStateLoadedToIdle == iCurrentStateIndex &&
       
   161 			iPortManager.AllPortsPopulated())
       
   162 			{
       
   163 			// Complete here the transition to OMX_StateIdle
       
   164 			omxRetValue = FsmTransition(EStateIdle);
       
   165 			if (OMX_ErrorNone == omxRetValue)
       
   166 				{
       
   167 				// Notify the IL client that port population has
       
   168 				// completed sucessfully
       
   169 				omxRetValue = iCallbacks.TransitionCompleteNotification(
       
   170 					OMX_StateIdle);
       
   171 
       
   172 				}
       
   173 			}
       
   174 		}
       
   175 
       
   176 	if (OMX_ErrorNone == omxRetValue ||
       
   177 		OMX_ErrorInsufficientResources == omxRetValue)
       
   178 		{
       
   179 		// OMX_ErrorInsufficientResources is allowed in OMX_EmptyThisBuffer and
       
   180 		// OMX_FillThisBuffer
       
   181 		return omxRetValue;
       
   182 		}
       
   183 	else
       
   184 		{
       
   185 		return SendOmxErrorEventIfNeeded(omxRetValue);
       
   186 		}
       
   187 
       
   188 	}
       
   189 
       
   190 OMX_ERRORTYPE
       
   191 COmxILFsm::FsmTransition(TStateIndex aNewState)
       
   192 	{
       
   193     DEBUG_PRINTF2(_L8("COmxILFsm::FsmTransition : %d"), aNewState);
       
   194 
       
   195 	__ASSERT_ALWAYS(aNewState < EStateMax,
       
   196 					User::Panic(KOmxILFsmPanicCategory, 1));
       
   197 
       
   198 	if (aNewState != iCurrentStateIndex)
       
   199 		{
       
   200 		// We notify the processing function of all the state transitions, even
       
   201 		// if they are not to a final OpenMAX IL state.
       
   202 		OMX_ERRORTYPE omxRetValue;
       
   203 		if (OMX_ErrorNone !=
       
   204 			(omxRetValue =
       
   205 			 iProcFunction.StateTransitionIndication(aNewState)))
       
   206 			{
       
   207 			// No need of propagating further error codes if the component is
       
   208 			// transitioning to OMX_StateInvalid or if the PF itself is
       
   209 			// invalidating the component...
       
   210 			if (EStateInvalid != aNewState &&
       
   211 				OMX_ErrorInvalidState != omxRetValue)
       
   212 				{
       
   213 				return omxRetValue;
       
   214 				}
       
   215 			}
       
   216 
       
   217 		iCurrentStateIndex = aNewState;
       
   218 		ipCurrentState = iStates[iCurrentStateIndex];
       
   219 
       
   220 		}
       
   221 
       
   222 	return OMX_ErrorNone;
       
   223 
       
   224 	}
       
   225 
       
   226 OMX_ERRORTYPE
       
   227 COmxILFsm::FsmTransition(TUint32 aNewState)
       
   228 	{
       
   229 
       
   230 	return FsmTransition(static_cast<TStateIndex>(aNewState));
       
   231 
       
   232 	}
       
   233 
       
   234 
       
   235 OMX_ERRORTYPE
       
   236 COmxILFsm::GetComponentVersion(OMX_STRING aComponentName,
       
   237 							   OMX_VERSIONTYPE* apComponentVersion,
       
   238 							   OMX_VERSIONTYPE* apSpecVersion,
       
   239 							   OMX_UUIDTYPE* apComponentUUID) const
       
   240 	{
       
   241     DEBUG_PRINTF(_L8("COmxILFsm::GetComponentVersion"));
       
   242 
       
   243 	__ASSERT_DEBUG(iCurrentStateIndex != EStateMax,
       
   244 				   User::Panic(KOmxILFsmPanicCategory, 1));
       
   245 
       
   246 	// This api should not be allowed in OMX_StateInvalid
       
   247 	if (EStateInvalid == iCurrentStateIndex)
       
   248 		{
       
   249 		return SendOmxErrorEventIfNeeded(OMX_ErrorInvalidState);
       
   250 		}
       
   251 
       
   252 	if (!aComponentName ||
       
   253 		!apComponentVersion ||
       
   254 		!apSpecVersion ||
       
   255 		!apComponentUUID)
       
   256 		{
       
   257 		return OMX_ErrorBadParameter;
       
   258 		}
       
   259 
       
   260 	// This API call is independent of the current state. Its handled by the
       
   261 	// the config manager
       
   262 
       
   263 	RETURN_OMX_ERROR_AND_EVENT_IF_NEEDED(
       
   264 		iConfigManager.GetComponentVersion(
       
   265 			aComponentName,
       
   266 			apComponentVersion,
       
   267 			apSpecVersion,
       
   268 			apComponentUUID));
       
   269 	}
       
   270 
       
   271 
       
   272 OMX_ERRORTYPE
       
   273 COmxILFsm::SendCommand(OMX_COMMANDTYPE aCommand,
       
   274 					   TUint32 anParam1,
       
   275 					   TAny* apCmdData)
       
   276 	{
       
   277     DEBUG_PRINTF3(_L8("COmxILFsm::SendCommand : command [%d] Param1 [%d]"), aCommand, anParam1);
       
   278 
       
   279 	__ASSERT_DEBUG(iCurrentStateIndex != EStateMax,
       
   280 				   User::Panic(KOmxILFsmPanicCategory, 1));
       
   281 
       
   282 	// Do some very minor error checking here to try to save some time...
       
   283 	if (OMX_CommandStateSet == aCommand &&
       
   284 		anParam1 > OMX_StateWaitForResources)
       
   285 		{
       
   286 		return OMX_ErrorBadParameter;
       
   287 		}
       
   288 
       
   289 	TOmxILCommand command(aCommand, anParam1, apCmdData);
       
   290 	OMX_ERRORTYPE sendCommandError;
       
   291 	switch (aCommand)
       
   292 		{
       
   293 	case OMX_CommandStateSet:
       
   294 		{
       
   295 		sendCommandError = ipCurrentState->CommandStateSet(*this, command);
       
   296 		}
       
   297 		break;
       
   298 	case OMX_CommandFlush:
       
   299 		{
       
   300 		sendCommandError = ipCurrentState->CommandFlush(*this, command);
       
   301 		}
       
   302 		break;
       
   303 	case OMX_CommandPortDisable:
       
   304 		{
       
   305 		sendCommandError = ipCurrentState->CommandPortDisable(*this, command);
       
   306 		}
       
   307 		break;
       
   308 	case OMX_CommandPortEnable:
       
   309 		{
       
   310 		sendCommandError = ipCurrentState->CommandPortEnable(*this, command);
       
   311 		}
       
   312 		break;
       
   313 	case OMX_CommandMarkBuffer:
       
   314 		{
       
   315 		sendCommandError = ipCurrentState->CommandMarkBuffer(*this, command);
       
   316 		}
       
   317 		break;
       
   318 	default:
       
   319 		{
       
   320 		// This is an invalid command type
       
   321 		return OMX_ErrorBadParameter;
       
   322 		}
       
   323 		};
       
   324 
       
   325 	if (OMX_ErrorNone == sendCommandError ||
       
   326 		OMX_ErrorInsufficientResources == sendCommandError)
       
   327 		{
       
   328 		// OMX_ErrorInsufficientResources is allowed in OMX_SendCommand
       
   329 		return sendCommandError;
       
   330 		}
       
   331 	else
       
   332 		{
       
   333 		return SendOmxErrorEventIfNeeded(sendCommandError);
       
   334 		}
       
   335 
       
   336 	}
       
   337 
       
   338 
       
   339 OMX_ERRORTYPE
       
   340 COmxILFsm::GetParameter(OMX_INDEXTYPE aParamIndex,
       
   341 						TAny* apComponentParameterStructure) const
       
   342 	{
       
   343     DEBUG_PRINTF(_L8("COmxILFsm::GetParameter"));
       
   344 
       
   345 	__ASSERT_DEBUG(iCurrentStateIndex != EStateMax,
       
   346 				   User::Panic(KOmxILFsmPanicCategory, 1));
       
   347 
       
   348 	if (!apComponentParameterStructure)
       
   349 		{
       
   350 		return OMX_ErrorBadParameter;
       
   351 		}
       
   352 
       
   353 	RETURN_OMX_ERROR_AND_EVENT_IF_NEEDED(
       
   354 		ipCurrentState->GetParameter(*this, aParamIndex,
       
   355 									 apComponentParameterStructure));
       
   356 	}
       
   357 
       
   358 
       
   359 OMX_ERRORTYPE
       
   360 COmxILFsm::SetParameter(OMX_INDEXTYPE aParamIndex,
       
   361 						const TAny* apComponentParameterStructure)
       
   362 	{
       
   363     DEBUG_PRINTF(_L8("COmxILFsm::SetParameter"));
       
   364 
       
   365 	__ASSERT_DEBUG(iCurrentStateIndex != EStateMax,
       
   366 				   User::Panic(KOmxILFsmPanicCategory, 1));
       
   367 
       
   368 	if (!apComponentParameterStructure)
       
   369 		{
       
   370 		return OMX_ErrorBadParameter;
       
   371 		}
       
   372 
       
   373 	RETURN_OMX_ERROR_AND_EVENT_IF_NEEDED(
       
   374 	ipCurrentState->SetParameter(*this, aParamIndex,
       
   375 								 apComponentParameterStructure));
       
   376 	}
       
   377 
       
   378 
       
   379 OMX_ERRORTYPE
       
   380 COmxILFsm::GetConfig(OMX_INDEXTYPE aConfigIndex,
       
   381 					 TAny* apComponentConfigStructure) const
       
   382 	{
       
   383     DEBUG_PRINTF(_L8("COmxILFsm::GetConfig"));
       
   384 
       
   385 	__ASSERT_DEBUG(iCurrentStateIndex != EStateMax,
       
   386 				   User::Panic(KOmxILFsmPanicCategory, 1));
       
   387 
       
   388 	if (!apComponentConfigStructure)
       
   389 		{
       
   390 		return OMX_ErrorBadParameter;
       
   391 		}
       
   392 
       
   393 	RETURN_OMX_ERROR_AND_EVENT_IF_NEEDED(
       
   394 		ipCurrentState->GetConfig(*this,
       
   395 								  aConfigIndex,
       
   396 								  apComponentConfigStructure));
       
   397 
       
   398 	}
       
   399 
       
   400 
       
   401 OMX_ERRORTYPE
       
   402 COmxILFsm::SetConfig(OMX_INDEXTYPE aIndex,
       
   403 					 const TAny* apComponentConfigStructure)
       
   404 	{
       
   405     DEBUG_PRINTF(_L8("COmxILFsm::SetConfig"));
       
   406 
       
   407 	__ASSERT_DEBUG(iCurrentStateIndex != EStateMax,
       
   408 				   User::Panic(KOmxILFsmPanicCategory, 1));
       
   409 
       
   410 	if (!apComponentConfigStructure)
       
   411 		{
       
   412 		return OMX_ErrorBadParameter;
       
   413 		}
       
   414 
       
   415 	RETURN_OMX_ERROR_AND_EVENT_IF_NEEDED(
       
   416 		ipCurrentState->SetConfig(*this, aIndex, apComponentConfigStructure));
       
   417 
       
   418 	}
       
   419 
       
   420 
       
   421 OMX_ERRORTYPE
       
   422 COmxILFsm::GetExtensionIndex(
       
   423 	OMX_STRING aParameterName,
       
   424 	OMX_INDEXTYPE* apIndexType) const
       
   425 	{
       
   426     DEBUG_PRINTF(_L8("COmxILFsm::GetExtensionIndex"));
       
   427 
       
   428 	__ASSERT_DEBUG(iCurrentStateIndex != EStateMax,
       
   429 				   User::Panic(KOmxILFsmPanicCategory, 1));
       
   430 
       
   431 	if (!apIndexType || !aParameterName)
       
   432 		{
       
   433 		return OMX_ErrorBadParameter;
       
   434 		}
       
   435 
       
   436 	RETURN_OMX_ERROR_AND_EVENT_IF_NEEDED(
       
   437 		ipCurrentState->GetExtensionIndex(*this,
       
   438 										  aParameterName,
       
   439 										  apIndexType));
       
   440 	}
       
   441 
       
   442 
       
   443 OMX_ERRORTYPE
       
   444 COmxILFsm::GetState(OMX_STATETYPE* apState) const
       
   445 	{
       
   446     DEBUG_PRINTF(_L8("COmxILFsm::GetState"));
       
   447 
       
   448 	__ASSERT_DEBUG(iCurrentStateIndex != EStateMax,
       
   449 				   User::Panic(KOmxILFsmPanicCategory, 1));
       
   450 
       
   451 	if (!apState)
       
   452 		{
       
   453 		return OMX_ErrorBadParameter;
       
   454 		}
       
   455 
       
   456 	*apState = ipCurrentState->GetState();
       
   457 
       
   458 	return OMX_ErrorNone;
       
   459 
       
   460 	}
       
   461 
       
   462 
       
   463 OMX_ERRORTYPE
       
   464 COmxILFsm::ComponentTunnelRequest(OMX_U32 aPort,
       
   465 								  OMX_HANDLETYPE aTunneledComp,
       
   466 								  OMX_U32 aTunneledPort,
       
   467 								  OMX_TUNNELSETUPTYPE* apTunnelSetup)
       
   468 	{
       
   469     DEBUG_PRINTF(_L8("COmxILFsm::ComponentTunnelRequest"));
       
   470 
       
   471 	__ASSERT_DEBUG(iCurrentStateIndex != EStateMax,
       
   472 				   User::Panic(KOmxILFsmPanicCategory, 1));
       
   473 
       
   474 	// Here, since NULL is a valid parameter for aTunneledComp, checking of
       
   475 	// input parameters is completely done by the ports.
       
   476 	RETURN_OMX_ERROR_AND_EVENT_IF_NEEDED(
       
   477 		ipCurrentState->ComponentTunnelRequest(*this,
       
   478 											   aPort,
       
   479 											   aTunneledComp,
       
   480 											   aTunneledPort,
       
   481 											   apTunnelSetup));
       
   482 
       
   483 	}
       
   484 
       
   485 
       
   486 OMX_ERRORTYPE
       
   487 COmxILFsm::UseBuffer(OMX_BUFFERHEADERTYPE** appBufferHdr,
       
   488 					 OMX_U32 aPortIndex,
       
   489 					 OMX_PTR apAppPrivate,
       
   490 					 OMX_U32 aSizeBytes,
       
   491 					 OMX_U8* apBuffer)
       
   492 	{
       
   493     DEBUG_PRINTF(_L8("COmxILFsm::UseBuffer"));
       
   494 
       
   495 	__ASSERT_DEBUG(iCurrentStateIndex != EStateMax,
       
   496 				   User::Panic(KOmxILFsmPanicCategory, 1));
       
   497 
       
   498 	if (!appBufferHdr || !aSizeBytes || !apBuffer)
       
   499 		{
       
   500 		return OMX_ErrorBadParameter;
       
   501 		}
       
   502 
       
   503 	return PopulateBuffer(appBufferHdr,
       
   504 						  aPortIndex,
       
   505 						  apAppPrivate,
       
   506 						  aSizeBytes,
       
   507 						  apBuffer);
       
   508 
       
   509 	}
       
   510 
       
   511 
       
   512 OMX_ERRORTYPE
       
   513 COmxILFsm::AllocateBuffer(OMX_BUFFERHEADERTYPE** appBufferHdr,
       
   514 						  OMX_U32 aPortIndex,
       
   515 						  OMX_PTR apAppPrivate,
       
   516 						  OMX_U32 aSizeBytes)
       
   517 	{
       
   518     DEBUG_PRINTF(_L8("COmxILFsm::AllocateBuffer"));
       
   519 
       
   520 	__ASSERT_DEBUG(iCurrentStateIndex != EStateMax,
       
   521 				   User::Panic(KOmxILFsmPanicCategory, 1));
       
   522 
       
   523 	if (!appBufferHdr || !aSizeBytes)
       
   524 		{
       
   525 		return OMX_ErrorBadParameter;
       
   526 		}
       
   527 
       
   528 
       
   529 	return PopulateBuffer(appBufferHdr,
       
   530 						  aPortIndex,
       
   531 						  apAppPrivate,
       
   532 						  aSizeBytes,
       
   533 						  0);
       
   534 
       
   535 	}
       
   536 
       
   537 
       
   538 OMX_ERRORTYPE
       
   539 COmxILFsm::FreeBuffer(OMX_U32 aPortIndex,
       
   540 					  OMX_BUFFERHEADERTYPE* apBuffer)
       
   541 	{
       
   542     DEBUG_PRINTF(_L8("COmxILFsm::FreeBuffer"));
       
   543 
       
   544 	__ASSERT_DEBUG(iCurrentStateIndex != EStateMax,
       
   545 				   User::Panic(KOmxILFsmPanicCategory, 1));
       
   546 
       
   547 	if (!apBuffer)
       
   548 		{
       
   549 		return OMX_ErrorBadParameter;
       
   550 		}
       
   551 
       
   552 	TBool portDepopulationCompleted = EFalse;
       
   553 	OMX_ERRORTYPE omxRetValue =
       
   554 		ipCurrentState->FreeBuffer(*this,
       
   555 								   aPortIndex,
       
   556 								   apBuffer,
       
   557 								   portDepopulationCompleted);
       
   558 
       
   559 	if (OMX_ErrorNone == omxRetValue)
       
   560 		{
       
   561 		if (portDepopulationCompleted)
       
   562 			{
       
   563 			if (ESubStateIdleToLoaded == iCurrentStateIndex)
       
   564 				{
       
   565 				if (iPortManager.AllPortsDePopulated())
       
   566 					{
       
   567 					// Complete here the transition to OMX_StateLoaded
       
   568 					omxRetValue = FsmTransition(EStateLoaded);
       
   569 					if (OMX_ErrorNone == omxRetValue)
       
   570 						{
       
   571 						// Notify the IL client that port depopulation has
       
   572 						// completed sucessfully
       
   573 						omxRetValue =
       
   574 							iCallbacks.TransitionCompleteNotification(
       
   575 							OMX_StateLoaded);
       
   576 						}
       
   577 					}
       
   578 				}
       
   579 			}
       
   580 		}
       
   581 
       
   582 	if (OMX_ErrorNone == omxRetValue)
       
   583 		{
       
   584 		return OMX_ErrorNone;
       
   585 		}
       
   586 	else
       
   587 		{
       
   588 		return SendOmxErrorEventIfNeeded(omxRetValue);
       
   589 		}
       
   590 
       
   591 	}
       
   592 
       
   593 
       
   594 OMX_ERRORTYPE
       
   595 COmxILFsm::EmptyThisBuffer(OMX_BUFFERHEADERTYPE* apBuffer)
       
   596 	{
       
   597     DEBUG_PRINTF2(_L8("COmxILFsm::EmptyThisBuffer : BUFFER [%X]"), apBuffer);
       
   598 
       
   599 	__ASSERT_DEBUG(iCurrentStateIndex != EStateMax,
       
   600 				   User::Panic(KOmxILFsmPanicCategory, 1));
       
   601 
       
   602 	if (!apBuffer)
       
   603 		{
       
   604 		return OMX_ErrorBadParameter;
       
   605 		}
       
   606 
       
   607 	RETURN_OMX_ERROR_AND_EVENT_IF_NEEDED(
       
   608 		ipCurrentState->EmptyThisBuffer(*this, apBuffer));
       
   609 
       
   610 	}
       
   611 
       
   612 
       
   613 OMX_ERRORTYPE
       
   614 COmxILFsm::FillThisBuffer(OMX_BUFFERHEADERTYPE* apBuffer)
       
   615 	{
       
   616     DEBUG_PRINTF2(_L8("COmxILFsm::FillThisBuffer : BUFFER [%X]"), apBuffer);
       
   617 
       
   618 	__ASSERT_DEBUG(iCurrentStateIndex != EStateMax,
       
   619 				   User::Panic(KOmxILFsmPanicCategory, 1));
       
   620 
       
   621 	if (!apBuffer)
       
   622 		{
       
   623 		return OMX_ErrorBadParameter;
       
   624 		}
       
   625 
       
   626 	RETURN_OMX_ERROR_AND_EVENT_IF_NEEDED(
       
   627 		ipCurrentState->FillThisBuffer(*this, apBuffer));
       
   628 
       
   629 	}
       
   630 
       
   631 
       
   632 OMX_ERRORTYPE
       
   633 COmxILFsm::SetCallbacks(const OMX_CALLBACKTYPE* apCallbacks,
       
   634 						const OMX_PTR apAppData)
       
   635 	{
       
   636     DEBUG_PRINTF(_L8("COmxILFsm::SetCallbacks"));
       
   637 
       
   638 	__ASSERT_DEBUG(iCurrentStateIndex != EStateMax,
       
   639 				   User::Panic(KOmxILFsmPanicCategory, 1));
       
   640 
       
   641 	if (!apCallbacks)
       
   642 		{
       
   643 		return OMX_ErrorBadParameter;
       
   644 		}
       
   645 
       
   646 	// This api should only be allowed in OMX_StateLoaded
       
   647 	if (EStateLoaded != iCurrentStateIndex)
       
   648 		{
       
   649 		return OMX_ErrorIncorrectStateOperation;
       
   650 		}
       
   651 
       
   652 	RETURN_OMX_ERROR_AND_EVENT_IF_NEEDED(
       
   653 		iCallbacks.RegisterILClientCallbacks(apCallbacks, apAppData));
       
   654 
       
   655 	}
       
   656 
       
   657 
       
   658 OMX_ERRORTYPE
       
   659 COmxILFsm::UseEGLImage(OMX_BUFFERHEADERTYPE** /*appBufferHdr*/,
       
   660 					   OMX_U32 /*aPortIndex*/,
       
   661 					   OMX_PTR /*aAppPrivate*/,
       
   662 					   void* /*eglImage*/)
       
   663 	{
       
   664     DEBUG_PRINTF(_L8("COmxILFsm::UseEGLImage"));
       
   665 
       
   666 	__ASSERT_DEBUG(iCurrentStateIndex != EStateMax,
       
   667 				   User::Panic(KOmxILFsmPanicCategory, 1));
       
   668 
       
   669 	return OMX_ErrorNotImplemented;
       
   670 	}
       
   671 
       
   672 OMX_ERRORTYPE
       
   673 COmxILFsm::ComponentRoleEnum(OMX_U8* aRole,
       
   674 							 OMX_U32 aIndex) const
       
   675 	{
       
   676     DEBUG_PRINTF(_L8("COmxILFsm::ComponentRoleEnum"));
       
   677 
       
   678 	__ASSERT_DEBUG(iCurrentStateIndex != EStateMax,
       
   679 				   User::Panic(KOmxILFsmPanicCategory, 1));
       
   680 
       
   681 	// This api should not be allowed in OMX_StateInvalid
       
   682 	if (EStateInvalid == iCurrentStateIndex)
       
   683 		{
       
   684 		return SendOmxErrorEventIfNeeded(OMX_ErrorInvalidState);
       
   685 		}
       
   686 
       
   687 	if (!aRole)
       
   688 		{
       
   689 		return OMX_ErrorBadParameter;
       
   690 		}
       
   691 
       
   692 	RETURN_OMX_ERROR_AND_EVENT_IF_NEEDED(
       
   693 		iConfigManager.ComponentRoleEnum(aRole,
       
   694 										 aIndex));
       
   695 
       
   696 	}
       
   697 
       
   698 /**
       
   699    This method is here to fullfill the following functionalities:
       
   700 
       
   701    -# It is used to make sure that the component error codes are returned to
       
   702       the IL Client in a way that conforms with Table 3-9 of the OpenMAX IL
       
   703       1.1.1 spec. This table specifies which error codes must be sent with
       
   704       EventHandler. If an error code is to be sent via EventHandler, the API
       
   705       return code must be OMX_ErrorNone.
       
   706 
       
   707    -# This method is also used to invalidate the component whenever an internal
       
   708       component action returns OMX_ErrorInvalidState. For example, this is
       
   709       useful when code executed by a port or by the processing function cannot
       
   710       recover from an internal error. Returning OMX_ErrorInvalidState in that
       
   711       kind of situation will invalidate the component in
       
   712       SendOmxErrorEventIfNeeded and the event will be conveyed to the IL Client
       
   713       as mandated by the spec.
       
   714 
       
   715    @param aError An OpenMAX IL error code.
       
   716  */
       
   717 OMX_ERRORTYPE
       
   718 COmxILFsm::SendOmxErrorEventIfNeeded(OMX_ERRORTYPE aError)
       
   719 	{
       
   720 	DEBUG_PRINTF2(_L8("COmxILFsm::SendOmxErrorEventIfNeeded - aError = 0x%X"), aError);
       
   721 
       
   722 	OMX_ERRORTYPE returnError = aError;
       
   723 	switch(aError)
       
   724 		{
       
   725 	case OMX_ErrorInsufficientResources:
       
   726 		{
       
   727 		DEBUG_PRINTF(_L8("COmxILFsm::SendOmxErrorEventIfNeeded aError[OMX_ErrorInsufficientResources]"));
       
   728 		iCallbacks.ErrorEventNotification(aError);
       
   729 		}
       
   730 		break;
       
   731 	case OMX_ErrorInvalidState:
       
   732 		{
       
   733 		DEBUG_PRINTF(_L8("COmxILFsm::SendOmxErrorEventIfNeeded aError[OMX_ErrorInvalidState]"));
       
   734 		iCallbacks.ErrorEventNotification(aError);
       
   735 		if (EStateInvalid != iCurrentStateIndex)
       
   736 			{
       
   737 			returnError = OMX_ErrorNone;
       
   738 			}
       
   739 		}
       
   740 		break;
       
   741 	case OMX_ErrorUnderflow:
       
   742 	case OMX_ErrorOverflow:
       
   743 	case OMX_ErrorHardware:
       
   744 	case OMX_ErrorStreamCorrupt:
       
   745 	case OMX_ErrorResourcesLost:
       
   746 	case OMX_ErrorSameState:
       
   747 	case OMX_ErrorResourcesPreempted:
       
   748 	case OMX_ErrorPortUnresponsiveDuringAllocation:
       
   749 	case OMX_ErrorPortUnresponsiveDuringDeallocation:
       
   750 	case OMX_ErrorPortUnresponsiveDuringStop:
       
   751 	case OMX_ErrorIncorrectStateTransition:
       
   752 	case OMX_ErrorPortUnpopulated:
       
   753 	case OMX_ErrorDynamicResourcesUnavailable:
       
   754 	case OMX_ErrorMbErrorsInFrame:
       
   755 	case OMX_ErrorFormatNotDetected:
       
   756 		{
       
   757 		DEBUG_PRINTF2(_L8("COmxILFsm::SendOmxErrorEventIfNeeded aError[%X]"), aError);
       
   758 		iCallbacks.ErrorEventNotification(aError);
       
   759 		returnError = OMX_ErrorNone;
       
   760 		}
       
   761 		break;
       
   762 		};
       
   763 
       
   764 	if(OMX_ErrorInvalidState == aError &&
       
   765 	   EStateInvalid != iCurrentStateIndex)
       
   766 		{
       
   767 		// Invalidate this component. This instance of the component should be
       
   768 		// destroyed by the IL Client after this. No need to check error code.
       
   769 		FsmTransition(EStateInvalid);
       
   770 		}
       
   771 
       
   772 	return returnError;
       
   773 
       
   774 	}
       
   775 
       
   776 OMX_ERRORTYPE
       
   777 COmxILFsm::SendOmxErrorEventIfNeeded(OMX_ERRORTYPE aError) const
       
   778 	{
       
   779 	DEBUG_PRINTF(_L8("COmxILFsm::SendOmxErrorEventIfNeeded"));
       
   780 
       
   781 	return const_cast<COmxILFsm*>(this)->SendOmxErrorEventIfNeeded(aError);
       
   782 
       
   783 	}