omxil_generic/omxilcomplib/src/omxilconfigmanagerimpl.cpp
changeset 0 0e4a32b9112d
equal deleted inserted replaced
-1:000000000000 0:0e4a32b9112d
       
     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 <e32cmn.h>
       
    23 #include <openmax/il/khronos/v1_x/OMX_Core.h>
       
    24 
       
    25 #include "log.h"
       
    26 #include <openmax/il/common/omxilconfigmanager.h>
       
    27 #include <openmax/il/common/omxilspecversion.h>
       
    28 #include <openmax/il/common/omxilutil.h>
       
    29 #include "omxilportmanagerif.h"
       
    30 #include "omxilconfigmanagerimpl.h"
       
    31 
       
    32 // NOTE: OMX_UUIDTYPE[128] is defined in OMX_Types.h
       
    33 #define KMAX_UUIDTYPE_SIZE 128
       
    34 
       
    35 COmxILConfigManagerImpl*
       
    36 COmxILConfigManagerImpl::NewL(
       
    37 	const TDesC8& aComponentName,
       
    38 	const OMX_VERSIONTYPE& aComponentVersion,
       
    39 	const RPointerArray<TDesC8>& aComponentRoleList)
       
    40 	{
       
    41     DEBUG_PRINTF(_L8("COmxILConfigManagerImpl::NewL"));
       
    42 	COmxILConfigManagerImpl* self = new (ELeave)COmxILConfigManagerImpl();
       
    43 	CleanupStack::PushL(self);
       
    44 	self->ConstructL(aComponentName,
       
    45 					 aComponentVersion,
       
    46 					 aComponentRoleList);
       
    47 	CleanupStack::Pop(self);
       
    48 	return self;
       
    49 
       
    50 	}
       
    51 
       
    52 void
       
    53 COmxILConfigManagerImpl::ConstructL(const TDesC8& aComponentName,
       
    54 								const OMX_VERSIONTYPE& aComponentVersion,
       
    55 								const RPointerArray<TDesC8>& aComponentRoleList)
       
    56 	{
       
    57     DEBUG_PRINTF(_L8("COmxILConfigManagerImpl::ConstructL"));
       
    58 
       
    59 	iComponentName.CreateL(aComponentName, OMX_MAX_STRINGNAME_SIZE);
       
    60 	iComponentName.PtrZ();
       
    61 	iComponentVersion.s = aComponentVersion.s;
       
    62 
       
    63 	// Note that the first role in the list of roles becomes the default role
       
    64 	// assumed by the component
       
    65 
       
    66 	const TUint rolesCount = aComponentRoleList.Count();
       
    67 	for (TUint i=0; i<rolesCount; ++i)
       
    68 		{
       
    69 		iComponentRoleList.AppendL(aComponentRoleList[i]->AllocLC());
       
    70 		CleanupStack::Pop();
       
    71 		}
       
    72 
       
    73 
       
    74 	InsertParamIndexL(OMX_IndexParamDisableResourceConcealment);
       
    75 	InsertParamIndexL(OMX_IndexParamSuspensionPolicy);
       
    76 	InsertParamIndexL(OMX_IndexParamStandardComponentRole);
       
    77 	InsertParamIndexL(OMX_IndexParamPriorityMgmt);
       
    78 	InsertConfigIndexL(OMX_IndexConfigPriorityMgmt);
       
    79 
       
    80 	}
       
    81 
       
    82 COmxILConfigManagerImpl::COmxILConfigManagerImpl()
       
    83 	:
       
    84 	iComponentName(),
       
    85 	iComponentRoleList(),
       
    86 	iCurrentRoleIndex(0)
       
    87 
       
    88 	{
       
    89     DEBUG_PRINTF(_L8("COmxILConfigManagerImpl::COmxILConfigManagerImpl"));
       
    90 
       
    91 	iParamDisableResourceConcealment.nSize						   = sizeof(OMX_RESOURCECONCEALMENTTYPE);
       
    92 	iParamDisableResourceConcealment.nVersion					   = TOmxILSpecVersion();
       
    93 	iParamDisableResourceConcealment.bResourceConcealmentForbidden = OMX_TRUE;
       
    94 
       
    95 	iParamSuspensionPolicy.nSize	= sizeof(OMX_PARAM_SUSPENSIONPOLICYTYPE);
       
    96 	iParamSuspensionPolicy.nVersion = TOmxILSpecVersion();
       
    97 	iParamSuspensionPolicy.ePolicy	= OMX_SuspensionDisabled;
       
    98 
       
    99 	iConfigPriorityMgmt.nSize		   = sizeof(OMX_PRIORITYMGMTTYPE);
       
   100 	iConfigPriorityMgmt.nVersion	   = TOmxILSpecVersion();
       
   101 	iConfigPriorityMgmt.nGroupPriority = 0;
       
   102 	iConfigPriorityMgmt.nGroupID	   = 0;
       
   103 
       
   104 	}
       
   105 
       
   106 COmxILConfigManagerImpl::~COmxILConfigManagerImpl()
       
   107 	{
       
   108     DEBUG_PRINTF(_L8("COmxILConfigManagerImpl::~COmxILConfigManagerImpl"));
       
   109 
       
   110 	iComponentName.Close();
       
   111 	iComponentRoleList.ResetAndDestroy();
       
   112 	}
       
   113 
       
   114 OMX_ERRORTYPE
       
   115 COmxILConfigManagerImpl::GetComponentVersion(OMX_STRING aComponentName,
       
   116 										 OMX_VERSIONTYPE* apComponentVersion,
       
   117 										 OMX_VERSIONTYPE* apSpecVersion,
       
   118 										 OMX_UUIDTYPE* apComponentUUID) const
       
   119 	{
       
   120     DEBUG_PRINTF(_L8("COmxILConfigManagerImpl::GetComponentVersion"));
       
   121 
       
   122 	TPtr8 name(reinterpret_cast<TUint8*>(aComponentName),
       
   123 			   OMX_MAX_STRINGNAME_SIZE);
       
   124 	name.Copy(iComponentName);
       
   125 	name.PtrZ();
       
   126 
       
   127 	(*apComponentVersion) = iComponentVersion;
       
   128 	(*apSpecVersion)	  = TOmxILSpecVersion();
       
   129 
       
   130 	// Generate a component uuid
       
   131 	TUint32 uid = reinterpret_cast<TUint32>(this);
       
   132 	TPtr8 uidPtr(reinterpret_cast<TUint8*>(*apComponentUUID),
       
   133 				  KMAX_UUIDTYPE_SIZE);
       
   134 	uidPtr = TPtr8(reinterpret_cast<TUint8*>(uid), sizeof(uid));
       
   135 
       
   136 	return OMX_ErrorNone;
       
   137 
       
   138 	}
       
   139 
       
   140 OMX_ERRORTYPE
       
   141 COmxILConfigManagerImpl::GetParameter(OMX_INDEXTYPE aParamIndex,
       
   142 								  TAny* apComponentParameterStructure) const
       
   143 	{
       
   144     DEBUG_PRINTF(_L8("COmxILConfigManagerImpl::GetParameter"));
       
   145 
       
   146 	TInt index = FindParamIndex(aParamIndex);
       
   147 	if (KErrNotFound == index)
       
   148 		{
       
   149 		return OMX_ErrorUnsupportedIndex;
       
   150 		}
       
   151 
       
   152 	OMX_ERRORTYPE omxRetValue = OMX_ErrorNone;
       
   153 	switch(aParamIndex)
       
   154 		{
       
   155 	case OMX_IndexParamStandardComponentRole:
       
   156 		{
       
   157 		if (OMX_ErrorNone != (omxRetValue =
       
   158 							  TOmxILUtil::CheckOmxStructSizeAndVersion(
       
   159 								  apComponentParameterStructure,
       
   160 								  sizeof(OMX_PARAM_COMPONENTROLETYPE))))
       
   161 			{
       
   162 			return omxRetValue;
       
   163 			}
       
   164 
       
   165 		OMX_PARAM_COMPONENTROLETYPE* pComponentRole
       
   166 			= static_cast<OMX_PARAM_COMPONENTROLETYPE*>(
       
   167 				apComponentParameterStructure);
       
   168 
       
   169 		// Here, the role returned must be the role that this component is
       
   170 		// currently assuming
       
   171 		TPtr8 role(reinterpret_cast<TUint8*>(pComponentRole->cRole),
       
   172 				   OMX_MAX_STRINGNAME_SIZE);
       
   173 
       
   174 		role = *(iComponentRoleList[iCurrentRoleIndex]);
       
   175 		role.PtrZ();
       
   176 
       
   177 		}
       
   178 		break;
       
   179 
       
   180 	case OMX_IndexParamDisableResourceConcealment:
       
   181 		{
       
   182 		if (OMX_ErrorNone != (omxRetValue =
       
   183 							  TOmxILUtil::CheckOmxStructSizeAndVersion(
       
   184 								  apComponentParameterStructure,
       
   185 								  sizeof(OMX_RESOURCECONCEALMENTTYPE))))
       
   186 			{
       
   187 			return omxRetValue;
       
   188 			}
       
   189 
       
   190 		OMX_RESOURCECONCEALMENTTYPE* pResConceal
       
   191 			= static_cast<OMX_RESOURCECONCEALMENTTYPE*>(
       
   192 				apComponentParameterStructure);
       
   193 
       
   194 		*pResConceal = iParamDisableResourceConcealment;
       
   195 
       
   196 		}
       
   197 		break;
       
   198 	case OMX_IndexParamSuspensionPolicy:
       
   199 		{
       
   200 		if (OMX_ErrorNone != (omxRetValue =
       
   201 							  TOmxILUtil::CheckOmxStructSizeAndVersion(
       
   202 								  apComponentParameterStructure,
       
   203 								  sizeof(OMX_PARAM_SUSPENSIONPOLICYTYPE))))
       
   204 			{
       
   205 			return omxRetValue;
       
   206 			}
       
   207 
       
   208 		OMX_PARAM_SUSPENSIONPOLICYTYPE* pSuspensionPolicy
       
   209 			= static_cast<OMX_PARAM_SUSPENSIONPOLICYTYPE*>(
       
   210 				apComponentParameterStructure);
       
   211 
       
   212 		*pSuspensionPolicy = iParamSuspensionPolicy;
       
   213 
       
   214 		}
       
   215 		break;
       
   216 
       
   217 	case OMX_IndexParamPriorityMgmt:
       
   218 		{
       
   219 		if (OMX_ErrorNone != (omxRetValue =
       
   220 							  TOmxILUtil::CheckOmxStructSizeAndVersion(
       
   221 								  apComponentParameterStructure,
       
   222 								  sizeof(OMX_PRIORITYMGMTTYPE))))
       
   223 			{
       
   224 			return omxRetValue;
       
   225 			}
       
   226 
       
   227 		OMX_PRIORITYMGMTTYPE* pPriorityMgmt
       
   228 			= static_cast<OMX_PRIORITYMGMTTYPE*>(
       
   229 				apComponentParameterStructure);
       
   230 
       
   231 		*pPriorityMgmt = iConfigPriorityMgmt;
       
   232 
       
   233 		}
       
   234 		break;
       
   235 
       
   236 	default:
       
   237 		{
       
   238 		__ASSERT_ALWAYS(EFalse,
       
   239 						User::Panic(KOmxILConfigManagerPanicCategory, 1));
       
   240 		}
       
   241 		};
       
   242 
       
   243 	return OMX_ErrorNone;
       
   244 
       
   245 	}
       
   246 
       
   247 OMX_ERRORTYPE
       
   248 COmxILConfigManagerImpl::SetParameter(OMX_INDEXTYPE aParamIndex,
       
   249 								  const TAny* apComponentParameterStructure,
       
   250 								  OMX_BOOL aInitTime /*  = OMX_TRUE */)
       
   251 	{
       
   252     DEBUG_PRINTF(_L8("COmxILConfigManagerImpl::SetParameter"));
       
   253 
       
   254 	TInt index = FindParamIndex(aParamIndex);
       
   255 	if (KErrNotFound == index)
       
   256 		{
       
   257 		return OMX_ErrorUnsupportedIndex;
       
   258 		}
       
   259 
       
   260 	OMX_ERRORTYPE omxRetValue = OMX_ErrorNone;
       
   261 	switch(aParamIndex)
       
   262 		{
       
   263 	case OMX_IndexParamStandardComponentRole:
       
   264 		{
       
   265 		if (!aInitTime)
       
   266 			{
       
   267 			return OMX_ErrorIncorrectStateOperation;
       
   268 			}
       
   269 
       
   270 		if (OMX_ErrorNone != (omxRetValue =
       
   271 							  TOmxILUtil::CheckOmxStructSizeAndVersion(
       
   272 								  const_cast<OMX_PTR>(apComponentParameterStructure),
       
   273 								  sizeof(OMX_PARAM_COMPONENTROLETYPE))))
       
   274 			{
       
   275 			return omxRetValue;
       
   276 			}
       
   277 
       
   278 		const OMX_PARAM_COMPONENTROLETYPE* pComponentRole
       
   279 			= static_cast<const OMX_PARAM_COMPONENTROLETYPE*>(
       
   280 				apComponentParameterStructure);
       
   281 
       
   282 		TPtrC8 roleToFindPtr(
       
   283 			static_cast<const TUint8*>(pComponentRole->cRole));
       
   284 
       
   285 		HBufC8* pRoleToFind = HBufC8::New(OMX_MAX_STRINGNAME_SIZE);
       
   286 		if (!pRoleToFind)
       
   287 			{
       
   288 			return OMX_ErrorInsufficientResources;
       
   289 			}
       
   290 		*pRoleToFind = roleToFindPtr;
       
   291 
       
   292 		TInt newRoleIndex = 0;
       
   293 		if (KErrNotFound ==
       
   294 			(newRoleIndex =
       
   295 			 iComponentRoleList.Find(pRoleToFind,
       
   296 									 TIdentityRelation<HBufC8>(
       
   297 										 &COmxILConfigManagerImpl::CompareRoles))))
       
   298 			{
       
   299 			delete pRoleToFind;
       
   300 			return OMX_ErrorBadParameter;
       
   301 			}
       
   302 
       
   303 		if (*pRoleToFind != *(iComponentRoleList[iCurrentRoleIndex]))
       
   304 			{
       
   305 			// At this point, it is mandated that the component populates all
       
   306 			// defaults according to the new role that has just been set by the
       
   307 			// IL Client
       
   308 			if (OMX_ErrorNone !=
       
   309 				(omxRetValue =
       
   310 				 ipPortManager->ComponentRoleIndication(newRoleIndex)))
       
   311 				{
       
   312 				delete pRoleToFind;
       
   313 				return omxRetValue;
       
   314 				}
       
   315 
       
   316 			iCurrentRoleIndex = newRoleIndex;
       
   317 
       
   318 			}
       
   319 
       
   320 		delete pRoleToFind;
       
   321 
       
   322 		}
       
   323 		break;
       
   324 
       
   325 	case OMX_IndexParamDisableResourceConcealment:
       
   326 		{
       
   327 		if (!aInitTime)
       
   328 			{
       
   329 			return OMX_ErrorIncorrectStateOperation;
       
   330 			}
       
   331 
       
   332 		if (OMX_ErrorNone != (omxRetValue =
       
   333 							  TOmxILUtil::CheckOmxStructSizeAndVersion(
       
   334 								  const_cast<OMX_PTR>(apComponentParameterStructure),
       
   335 								  sizeof(OMX_RESOURCECONCEALMENTTYPE))))
       
   336 			{
       
   337 			return omxRetValue;
       
   338 			}
       
   339 
       
   340 		const OMX_RESOURCECONCEALMENTTYPE* pResConceal
       
   341 			= static_cast<const OMX_RESOURCECONCEALMENTTYPE*>(
       
   342 				apComponentParameterStructure);
       
   343 
       
   344 		iParamDisableResourceConcealment = *pResConceal;
       
   345 
       
   346 		}
       
   347 		break;
       
   348 
       
   349 	case OMX_IndexParamSuspensionPolicy:
       
   350 		{
       
   351 		if (!aInitTime)
       
   352 			{
       
   353 			return OMX_ErrorIncorrectStateOperation;
       
   354 			}
       
   355 
       
   356 		if (OMX_ErrorNone != (omxRetValue =
       
   357 							  TOmxILUtil::CheckOmxStructSizeAndVersion(
       
   358 								  const_cast<OMX_PTR>(apComponentParameterStructure),
       
   359 								  sizeof(OMX_PARAM_SUSPENSIONPOLICYTYPE))))
       
   360 			{
       
   361 			return omxRetValue;
       
   362 			}
       
   363 
       
   364 		const OMX_PARAM_SUSPENSIONPOLICYTYPE* pSuspensionPolicy
       
   365 			= static_cast<const OMX_PARAM_SUSPENSIONPOLICYTYPE*>(
       
   366 				apComponentParameterStructure);
       
   367 
       
   368 		// OMX_SuspensionEnabled is the last of the supported values as of
       
   369 		// v1.1.1
       
   370 		if (pSuspensionPolicy->ePolicy > OMX_SuspensionEnabled)
       
   371 			{
       
   372 			return OMX_ErrorBadParameter;
       
   373 			}
       
   374 
       
   375 		iParamSuspensionPolicy = *pSuspensionPolicy;
       
   376 
       
   377 		}
       
   378 		break;
       
   379 
       
   380 	case OMX_IndexParamPriorityMgmt:
       
   381 		{
       
   382 		if (!aInitTime)
       
   383 			{
       
   384 			return OMX_ErrorIncorrectStateOperation;
       
   385 			}
       
   386 
       
   387 		if (OMX_ErrorNone != (omxRetValue =
       
   388 							  TOmxILUtil::CheckOmxStructSizeAndVersion(
       
   389 								  const_cast<OMX_PTR>(apComponentParameterStructure),
       
   390 								  sizeof(OMX_PRIORITYMGMTTYPE))))
       
   391 			{
       
   392 			return omxRetValue;
       
   393 			}
       
   394 
       
   395 
       
   396 		const OMX_PRIORITYMGMTTYPE* pPriorityMgmt
       
   397 			= static_cast<const OMX_PRIORITYMGMTTYPE*>(
       
   398 				apComponentParameterStructure);
       
   399 
       
   400 		iConfigPriorityMgmt = *pPriorityMgmt;
       
   401 
       
   402 		}
       
   403 		break;
       
   404 
       
   405 	default:
       
   406 		{
       
   407 		__ASSERT_ALWAYS(EFalse,
       
   408 						User::Panic(KOmxILConfigManagerPanicCategory, 1));
       
   409 		}
       
   410 		};
       
   411 
       
   412 	return OMX_ErrorNone;
       
   413 
       
   414 	}
       
   415 
       
   416 OMX_ERRORTYPE
       
   417 COmxILConfigManagerImpl::GetConfig(OMX_INDEXTYPE aConfigIndex,
       
   418 							   TAny* apComponentConfigStructure) const
       
   419 	{
       
   420     DEBUG_PRINTF(_L8("COmxILConfigManagerImpl::GetConfig"));
       
   421 
       
   422 	TInt index = FindConfigIndex(aConfigIndex);
       
   423 	if (KErrNotFound == index)
       
   424 		{
       
   425 		return OMX_ErrorUnsupportedIndex;
       
   426 		}
       
   427 
       
   428 	OMX_ERRORTYPE omxRetValue = OMX_ErrorNone;
       
   429 	switch(aConfigIndex)
       
   430 		{
       
   431 	case OMX_IndexConfigPriorityMgmt:
       
   432 		{
       
   433 		if (OMX_ErrorNone != (omxRetValue =
       
   434 							  TOmxILUtil::CheckOmxStructSizeAndVersion(
       
   435 								  apComponentConfigStructure,
       
   436 								  sizeof(OMX_PRIORITYMGMTTYPE))))
       
   437 			{
       
   438 			return omxRetValue;
       
   439 			}
       
   440 
       
   441 		OMX_PRIORITYMGMTTYPE* pPriorityMgmt
       
   442 			= static_cast<OMX_PRIORITYMGMTTYPE*>(
       
   443 				apComponentConfigStructure);
       
   444 
       
   445 		*pPriorityMgmt = iConfigPriorityMgmt;
       
   446 
       
   447 		}
       
   448 		break;
       
   449 	default:
       
   450 		{
       
   451 		__ASSERT_ALWAYS(EFalse,
       
   452 						User::Panic(KOmxILConfigManagerPanicCategory, 1));
       
   453 		}
       
   454 		};
       
   455 
       
   456 	return OMX_ErrorNone;
       
   457 
       
   458 	}
       
   459 
       
   460 OMX_ERRORTYPE
       
   461 COmxILConfigManagerImpl::SetConfig(OMX_INDEXTYPE aConfigIndex,
       
   462 							   const TAny* apComponentConfigStructure)
       
   463 
       
   464 	{
       
   465     DEBUG_PRINTF(_L8("COmxILConfigManagerImpl::SetConfig"));
       
   466 
       
   467 	TInt index = FindConfigIndex(aConfigIndex);
       
   468 	if (KErrNotFound == index)
       
   469 		{
       
   470 		return OMX_ErrorUnsupportedIndex;
       
   471 		}
       
   472 
       
   473 	OMX_ERRORTYPE omxRetValue = OMX_ErrorNone;
       
   474 	switch(aConfigIndex)
       
   475 		{
       
   476 	case OMX_IndexConfigPriorityMgmt:
       
   477 		{
       
   478 		if (OMX_ErrorNone !=
       
   479 			(omxRetValue =
       
   480 			 TOmxILUtil::CheckOmxStructSizeAndVersion(
       
   481 				 const_cast<OMX_PTR>(apComponentConfigStructure),
       
   482 				 sizeof(OMX_PRIORITYMGMTTYPE))))
       
   483 			{
       
   484 			return omxRetValue;
       
   485 			}
       
   486 
       
   487 		const OMX_PRIORITYMGMTTYPE* pPriorityMgmt
       
   488 			= static_cast<const OMX_PRIORITYMGMTTYPE*>(
       
   489 				apComponentConfigStructure);
       
   490 
       
   491 		iConfigPriorityMgmt = *pPriorityMgmt;
       
   492 
       
   493 		}
       
   494 		break;
       
   495 	default:
       
   496 		{
       
   497 		__ASSERT_ALWAYS(EFalse,
       
   498 						User::Panic(KOmxILConfigManagerPanicCategory, 1));
       
   499 		}
       
   500 		};
       
   501 
       
   502 	return OMX_ErrorNone;
       
   503 
       
   504 	}
       
   505 
       
   506 OMX_ERRORTYPE
       
   507 COmxILConfigManagerImpl::ComponentRoleEnum(OMX_U8* aRole,
       
   508 									   OMX_U32 aIndex) const
       
   509 	{
       
   510     DEBUG_PRINTF(_L8("COmxILConfigManagerImpl::ComponentRoleEnum"));
       
   511 
       
   512     // TWC:OpenmaxIL requires error code OMX_ErrorNoMore to be returned when no more roles
       
   513     if (aIndex >= iComponentRoleList.Count())
       
   514 		{
       
   515 		return OMX_ErrorNoMore;
       
   516 		}
       
   517 
       
   518 	HBufC8* pRole = iComponentRoleList[aIndex];
       
   519 
       
   520 	TPtr8 role(reinterpret_cast<TUint8*>(aRole),
       
   521 			   OMX_MAX_STRINGNAME_SIZE);
       
   522 	role = *pRole;
       
   523 	role.PtrZ();
       
   524 
       
   525 	return OMX_ErrorNone;
       
   526 
       
   527 	}
       
   528 
       
   529 TBool
       
   530 COmxILConfigManagerImpl::CompareRoles(
       
   531 	const HBufC8& aRole1, const HBufC8& aRole2)
       
   532 	{
       
   533 	return (aRole1 == aRole2);
       
   534 	}
       
   535 
       
   536 void COmxILConfigManagerImpl::SetPortManager(MOmxILPortManagerIf* aPortManager)
       
   537 	{
       
   538 	ipPortManager = aPortManager;
       
   539 	}