omxil_generic/omxilloader/src/omxilsymbiancomponentloader.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 #include <ecom/ecom.h>
       
    17 #include <ecom/implementationproxy.h>
       
    18 #include "omxilsymbiancomponentloader.h"
       
    19 #include "omxiluids.hrh"
       
    20 #include <openmax/il/core/omxilloaderif.h>
       
    21 #include <openmax/il/khronos/v1_x/OMX_Core.h>
       
    22 #include <openmax/il/khronos/v1_x/OMX_Component.h>
       
    23 #include <string.h>
       
    24 #include <delimitedparser8.h>
       
    25 #include <openmax/il/core/omxilloaderif.hrh>
       
    26 #include <openmax/il/loader/omxilcomponentif.hrh>
       
    27 #include "log.h"
       
    28 
       
    29 OMX_ERRORTYPE OmxInitializeComponentLoader(OMX_LOADERTYPE *loader);
       
    30 OMX_ERRORTYPE OmxUnInitializeComponentLoader(OMX_LOADERTYPE *loader);
       
    31 OMX_ERRORTYPE OmxLoadComponent(	OMX_LOADERTYPE *loader,
       
    32 								OMX_OUT OMX_HANDLETYPE* pHandle,
       
    33 								OMX_IN  OMX_STRING cComponentName,
       
    34 								OMX_IN  OMX_PTR pAppData,
       
    35 								OMX_IN  OMX_CALLBACKTYPE* pCallBacks);
       
    36 OMX_ERRORTYPE OmxUnloadComponent( OMX_LOADERTYPE *loader, 
       
    37 								  OMX_HANDLETYPE hComponent);
       
    38 OMX_ERRORTYPE OmxComponentNameEnum(	OMX_LOADERTYPE *loader,
       
    39 							        OMX_OUT OMX_STRING cComponentName,
       
    40 							        OMX_IN OMX_U32 nNameLength,
       
    41 							        OMX_IN  OMX_U32 nIndex);
       
    42 OMX_ERRORTYPE OmxGetRolesOfComponent( OMX_LOADERTYPE *loader,
       
    43 							          OMX_IN OMX_STRING compName,
       
    44 							          OMX_INOUT OMX_U32 *pNumRoles,
       
    45 							          OMX_OUT OMX_U8 **roles);
       
    46 OMX_ERRORTYPE OmxGetComponentsOfRole( OMX_LOADERTYPE *loader,
       
    47 							          OMX_IN OMX_STRING role,
       
    48 							          OMX_INOUT OMX_U32 *pNumComps,
       
    49 							          OMX_INOUT OMX_U8  **compNames);
       
    50 
       
    51 
       
    52 
       
    53 OMX_ERRORTYPE OmxInitializeComponentLoader(OMX_LOADERTYPE *loader)
       
    54 	{
       
    55 	return ((CSymbianOmxComponentLoader*)((OMX_LOADERTYPE*)loader)->pLoaderPrivate)->InitializeComponentLoader();
       
    56 	}
       
    57 
       
    58 OMX_ERRORTYPE OmxUnInitializeComponentLoader(OMX_LOADERTYPE *loader)
       
    59 	{
       
    60 	return ((CSymbianOmxComponentLoader*)((OMX_LOADERTYPE*)loader)->pLoaderPrivate)->UnInitializeComponentLoader(loader);
       
    61 	}
       
    62 
       
    63 OMX_ERRORTYPE OmxLoadComponent(	OMX_LOADERTYPE *loader,
       
    64 								OMX_OUT OMX_HANDLETYPE* pHandle,
       
    65 								OMX_IN  OMX_STRING cComponentName,
       
    66 								OMX_IN  OMX_PTR pAppData,
       
    67 								OMX_IN  OMX_CALLBACKTYPE* pCallBacks)
       
    68 	{
       
    69 	return ((CSymbianOmxComponentLoader*)((OMX_LOADERTYPE*)loader)->pLoaderPrivate)->LoadComponent(pHandle,cComponentName,pAppData,pCallBacks);
       
    70 	}
       
    71 
       
    72 OMX_ERRORTYPE OmxUnloadComponent( OMX_LOADERTYPE *loader, 
       
    73 								  OMX_HANDLETYPE hComponent)
       
    74 	{
       
    75 	return ((CSymbianOmxComponentLoader*)((OMX_LOADERTYPE*)loader)->pLoaderPrivate)->UnloadComponent(hComponent);
       
    76 	}
       
    77 
       
    78 OMX_ERRORTYPE OmxComponentNameEnum(	OMX_LOADERTYPE *loader,
       
    79 							        OMX_OUT OMX_STRING cComponentName,
       
    80 							        OMX_IN OMX_U32 nNameLength,
       
    81 							        OMX_IN  OMX_U32 nIndex)
       
    82 	{
       
    83 	return ((CSymbianOmxComponentLoader*)((OMX_LOADERTYPE*)loader)->pLoaderPrivate)->ComponentNameEnum(cComponentName,nNameLength,nIndex);
       
    84 	}
       
    85 
       
    86 OMX_ERRORTYPE OmxGetRolesOfComponent( OMX_LOADERTYPE *loader,
       
    87 							          OMX_IN OMX_STRING compName,
       
    88 							          OMX_INOUT OMX_U32 *pNumRoles,
       
    89 							          OMX_OUT OMX_U8 **roles)
       
    90 	{
       
    91 	return ((CSymbianOmxComponentLoader*)((OMX_LOADERTYPE*)loader)->pLoaderPrivate)->GetRolesOfComponent(compName,pNumRoles,roles);
       
    92 	}
       
    93 
       
    94 OMX_ERRORTYPE OmxGetComponentsOfRole( OMX_LOADERTYPE *loader,
       
    95 							          OMX_IN OMX_STRING role,
       
    96 							          OMX_INOUT OMX_U32 *pNumComps,
       
    97 							          OMX_INOUT OMX_U8  **compNames)
       
    98 	{
       
    99 	return ((CSymbianOmxComponentLoader*)((OMX_LOADERTYPE*)loader)->pLoaderPrivate)->GetComponentsOfRole(role,pNumComps,compNames);
       
   100 	}
       
   101 
       
   102 OMX_ERRORTYPE CSymbianOmxComponentLoader::InitializeComponentLoader()
       
   103 	{
       
   104 	RImplInfoPtrArray ecomArray;
       
   105 	TRAPD(error,REComSession::ListImplementationsL(TUid::Uid(KUidOmxILSymbianComponentIf),ecomArray));
       
   106 	if( error != KErrNone )
       
   107 		{
       
   108 		ecomArray.ResetAndDestroy();
       
   109 		return OMX_ErrorInsufficientResources;
       
   110 		}
       
   111 	TInt index;
       
   112 	CImplementationInformation* info;
       
   113 
       
   114 	TOmxComponentInfo component;
       
   115 	
       
   116 	iComponentNameList.Reset();
       
   117 	
       
   118 	const TInt KEcomArrayCount = ecomArray.Count();
       
   119 	for( index=0; index<KEcomArrayCount && error == KErrNone; ++index )
       
   120 		{
       
   121 		info = ecomArray[index];
       
   122 		component.iUid = info->ImplementationUid();
       
   123 		if( info->DisplayName().Length() >= OMX_MAX_STRINGNAME_SIZE || 
       
   124 			info->DataType().Length() >= OMX_MAX_ROLESBUFFER_SIZE )
       
   125 			{
       
   126 			error = KErrBadName;
       
   127 			break;
       
   128 			}
       
   129 
       
   130 		component.iComponentName.Copy(info->DisplayName());
       
   131 		component.iRoles.Copy(info->DataType());
       
   132 
       
   133 		error = iComponentNameList.Append(component);
       
   134 		if(error)
       
   135 			{
       
   136 			break;
       
   137 			}
       
   138 		}
       
   139 	ecomArray.ResetAndDestroy();
       
   140 	if( error != KErrNone )
       
   141 		{
       
   142 		if( error == KErrNoMemory )
       
   143 			{
       
   144 			return OMX_ErrorInsufficientResources;
       
   145 			}
       
   146 
       
   147 		return OMX_ErrorUndefined;
       
   148 		}
       
   149 	return OMX_ErrorNone;
       
   150 	}
       
   151 
       
   152 OMX_ERRORTYPE CSymbianOmxComponentLoader::UnInitializeComponentLoader(OMX_LOADERTYPE * /*loader*/)
       
   153 	{
       
   154 	iComponentNameList.Reset();
       
   155 	iComponents.ResetAndDestroy();
       
   156 	return OMX_ErrorNone;
       
   157 	}
       
   158 
       
   159 OMX_ERRORTYPE CSymbianOmxComponentLoader::LoadComponent(	OMX_HANDLETYPE* pHandle,
       
   160 								OMX_STRING cComponentName,
       
   161 								OMX_PTR pAppData,
       
   162 								OMX_CALLBACKTYPE* pCallBacks)
       
   163 	{
       
   164 	TInt index;
       
   165     TPtrC8 lComponentName(reinterpret_cast<TUint8 *>(cComponentName), strlen(cComponentName));
       
   166     COmxILComponentIf* component = NULL;
       
   167 	OMX_ERRORTYPE error = OMX_ErrorComponentNotFound;
       
   168 
       
   169     const TInt KComponentNameListCount = iComponentNameList.Count();
       
   170     for( index = 0; index < KComponentNameListCount; ++index )
       
   171 		{
       
   172 		TOmxComponentInfo& comp = iComponentNameList[index];
       
   173 		DEBUG_PRINTF3(_L8("CSymbianOmxComponentLoader::LoadComponent : comp [%index] [%S]"), index, &comp.iComponentName);
       
   174 		if( comp.iComponentName.CompareF(lComponentName) == 0 )
       
   175 			{
       
   176 			TRAPD(err, component = COmxILComponentIf::CreateImplementationL(iComponentNameList[index].iUid));
       
   177 			if( err != KErrNone )
       
   178 				{
       
   179 				if ( err == KErrNoMemory )
       
   180 					{
       
   181 					return OMX_ErrorInsufficientResources;
       
   182 					}
       
   183 				else
       
   184 					{
       
   185 					return OMX_ErrorInvalidComponent;
       
   186 					}
       
   187 				}
       
   188 
       
   189 			*pHandle = component->Handle();
       
   190 			if( !*pHandle )
       
   191 				{
       
   192 				return OMX_ErrorInvalidComponent;
       
   193 				}
       
   194 
       
   195 			error = (static_cast<OMX_COMPONENTTYPE*>(*pHandle))->SetCallbacks(*pHandle, pCallBacks, pAppData);
       
   196 			
       
   197 			if(error != OMX_ErrorNone)
       
   198 				{
       
   199 				(static_cast<OMX_COMPONENTTYPE*>(*pHandle))->ComponentDeInit(*pHandle);
       
   200 				delete component;
       
   201 				return error;
       
   202 				}
       
   203 			if( iComponents.Append(component) != KErrNone )
       
   204 				{
       
   205 				(static_cast<OMX_COMPONENTTYPE*>(*pHandle))->ComponentDeInit(*pHandle);
       
   206 				delete component;
       
   207 				return OMX_ErrorInsufficientResources;
       
   208 				}
       
   209 			return error;
       
   210 			}
       
   211 		}
       
   212     return error;
       
   213 	}
       
   214 
       
   215 OMX_ERRORTYPE CSymbianOmxComponentLoader::UnloadComponent( OMX_HANDLETYPE hComponent)
       
   216 	{
       
   217 	TInt index;
       
   218 	COmxILComponentIf* component;
       
   219 
       
   220 	const TInt KComponentsCount = iComponents.Count();
       
   221 	for( index = 0; index < KComponentsCount; ++index )
       
   222 		{
       
   223 		component = iComponents[index];
       
   224 		if( component->Handle() == hComponent )
       
   225 			{
       
   226 			(static_cast<OMX_COMPONENTTYPE*>(hComponent))->ComponentDeInit( hComponent );
       
   227 			delete component;
       
   228 			iComponents.Remove(index);
       
   229 			return OMX_ErrorNone;
       
   230 			}
       
   231 		}
       
   232 	return OMX_ErrorComponentNotFound;
       
   233 	}
       
   234 
       
   235 OMX_ERRORTYPE CSymbianOmxComponentLoader::ComponentNameEnum(	OMX_STRING aComponentName,
       
   236 							        OMX_U32 aNameLength,
       
   237 							        OMX_U32 aIndex)
       
   238 	{
       
   239 	ASSERT(aComponentName);
       
   240 
       
   241 	const TInt KIndexForPopulateList = 0;
       
   242 	if ( aIndex == KIndexForPopulateList )
       
   243 		{
       
   244 		RImplInfoPtrArray ecomArray;
       
   245 		TRAPD(error, REComSession::ListImplementationsL(TUid::Uid(KUidOmxILSymbianComponentIf), ecomArray));
       
   246 		if (error != KErrNone)
       
   247 			{
       
   248 			return OMX_ErrorUndefined;
       
   249 			}
       
   250 		TInt index;
       
   251 		iComponentNameList.Reset();
       
   252 
       
   253 		const TInt KEcomArrayCount = ecomArray.Count();
       
   254 		// Create Controller Implementation Information for each entry
       
   255 		for (index=0; index<KEcomArrayCount; ++index)
       
   256 			{
       
   257 			CImplementationInformation& info = *(ecomArray[index]);
       
   258 			TOmxComponentInfo component;
       
   259 			
       
   260 			component.iUid = info.ImplementationUid();
       
   261 			if( info.DisplayName().Length() >= OMX_MAX_STRINGNAME_SIZE || 
       
   262 				info.DataType().Length() >= OMX_MAX_ROLESBUFFER_SIZE )
       
   263 				{
       
   264 				error = KErrBadName;
       
   265 				break;
       
   266 				}
       
   267 			component.iComponentName.Copy(info.DisplayName());
       
   268 			component.iRoles.Copy(info.DataType());
       
   269 			error = iComponentNameList.Append(component);
       
   270 			if( error != KErrNone )
       
   271 				{
       
   272 				break;
       
   273 				}
       
   274 			}
       
   275 		ecomArray.ResetAndDestroy();
       
   276 		if( error != KErrNone )
       
   277 			{
       
   278 			return OMX_ErrorUndefined;
       
   279 			}
       
   280 		}
       
   281 	if (aIndex<iComponentNameList.Count())
       
   282 		{
       
   283 		TOmxComponentInfo& comp = iComponentNameList[aIndex];
       
   284 		TPtr8 ptr((TUint8*)aComponentName, 0, aNameLength);
       
   285 		ptr.Copy(comp.iComponentName);
       
   286 		ptr.PtrZ();
       
   287 		}
       
   288 	else
       
   289 		{
       
   290 		return OMX_ErrorNoMore;
       
   291 		}
       
   292 	return OMX_ErrorNone;
       
   293 	}
       
   294 
       
   295 OMX_ERRORTYPE CSymbianOmxComponentLoader::GetRolesOfComponent( OMX_STRING compName,
       
   296 							          OMX_U32 *pNumRoles,
       
   297 							          OMX_U8 **roles)
       
   298 	{
       
   299 	TInt index, roleindex;
       
   300 
       
   301 	ASSERT(pNumRoles);
       
   302     if( !compName )
       
   303     	{
       
   304     	return OMX_ErrorBadParameter;
       
   305     	}
       
   306 		
       
   307     TPtrC8 tComponentName(reinterpret_cast<TUint8 *>(compName), strlen(compName));		
       
   308 
       
   309     OMX_ERRORTYPE error = OMX_ErrorInvalidComponentName;
       
   310     const TInt KComponentNameListCount = iComponentNameList.Count();
       
   311     for( index = 0, roleindex = 0; index < KComponentNameListCount; ++index )
       
   312 		{
       
   313 		if( iComponentNameList[index].iComponentName.Compare(tComponentName) == 0 )
       
   314 			{
       
   315 			char parser[OMX_MAX_ROLESBUFFER_SIZE], *p;
       
   316 			size_t size;
       
   317 			TInt i, j;
       
   318 
       
   319 			size = iComponentNameList[index].iRoles.Length();
       
   320 
       
   321 			strncpy(parser, 
       
   322 					reinterpret_cast<char*>(const_cast<unsigned char*>(iComponentNameList[index].iRoles.Ptr())),
       
   323 					size);
       
   324 			parser[size]=0;
       
   325 
       
   326 			for( i=0, j=0, p=parser; i<size; ++i, ++j, ++p )
       
   327 				{
       
   328 				if( *p == ',' )
       
   329 					{
       
   330 					if( roles && (roleindex < *pNumRoles) )
       
   331 						{
       
   332 						roles[roleindex][j] = 0;
       
   333 						}
       
   334 					if( i < size )
       
   335 						{
       
   336 						++roleindex;
       
   337 						j=-1;
       
   338 						}
       
   339 					}
       
   340 				else
       
   341 					{
       
   342 					if( roles && (roleindex < *pNumRoles) )
       
   343 						{
       
   344 						roles[roleindex][j] = *p;
       
   345 						}
       
   346 					}
       
   347 				}
       
   348 			if( roles && (roleindex < *pNumRoles) )
       
   349 				{
       
   350 				roles[roleindex][j] = 0;
       
   351 				}
       
   352 			++roleindex;
       
   353 			error = OMX_ErrorNone;
       
   354 			break;
       
   355 			}
       
   356 		}
       
   357     *pNumRoles = roleindex;
       
   358     return error;
       
   359 	}
       
   360 
       
   361 OMX_ERRORTYPE CSymbianOmxComponentLoader::GetComponentsOfRole( OMX_STRING role,
       
   362 							          OMX_U32 *pNumComps,
       
   363 							          OMX_U8  **compNames)
       
   364 	{
       
   365 	TInt index, compindex;
       
   366     TPtrC8 lRole(reinterpret_cast<TUint8 *>(role), strlen(role));
       
   367 
       
   368 	ASSERT(pNumComps);
       
   369 
       
   370     TInt KComponentNameListCount = iComponentNameList.Count();
       
   371     for( index = 0, compindex = 0; index < KComponentNameListCount; ++index )
       
   372 		{
       
   373 		if( iComponentNameList[index].iRoles.Find(lRole) != KErrNotFound )
       
   374 			{
       
   375 			if( compNames != NULL )
       
   376 				{
       
   377 				if( compNames[compindex]!= NULL )
       
   378 					{
       
   379 		            strncpy((char*)compNames[compindex],(char*)iComponentNameList[index].iComponentName.Ptr(),iComponentNameList[index].iComponentName.Length());
       
   380 		            compNames[compindex][iComponentNameList[index].iComponentName.Size()]=0;
       
   381 					}
       
   382 				else
       
   383 					{
       
   384 					return OMX_ErrorBadParameter;
       
   385 					}
       
   386 				}
       
   387 			++compindex;
       
   388 			}
       
   389 		}
       
   390     *pNumComps = compindex;
       
   391     return OMX_ErrorNone;
       
   392 	}
       
   393 
       
   394 OMX_HANDLETYPE CSymbianOmxComponentLoader::Handle()
       
   395 	{
       
   396 	return iHandle;
       
   397 	}
       
   398 
       
   399 CSymbianOmxComponentLoader::CSymbianOmxComponentLoader()
       
   400 	{
       
   401 	}
       
   402 
       
   403 CSymbianOmxComponentLoader::~CSymbianOmxComponentLoader()
       
   404 	{
       
   405 	delete iHandle;
       
   406 	}
       
   407 
       
   408 void CSymbianOmxComponentLoader::ConstructL()
       
   409 	{
       
   410 	iHandle = new(ELeave) OMX_LOADERTYPE;
       
   411 	
       
   412 	iHandle->InitializeComponentLoader = &::OmxInitializeComponentLoader;
       
   413 	iHandle->UnInitializeComponentLoader = &::OmxUnInitializeComponentLoader;
       
   414 	iHandle->LoadComponent = &::OmxLoadComponent;
       
   415 	iHandle->UnloadComponent = &::OmxUnloadComponent;
       
   416 	iHandle->ComponentNameEnum = &::OmxComponentNameEnum;
       
   417 	iHandle->GetRolesOfComponent = &::OmxGetRolesOfComponent;
       
   418 	iHandle->GetComponentsOfRole = &::OmxGetComponentsOfRole;
       
   419 	
       
   420 	iHandle->pLoaderPrivate = this;
       
   421 	}
       
   422 
       
   423 CSymbianOmxComponentLoader* CSymbianOmxComponentLoader::NewL()
       
   424 	{
       
   425 	CSymbianOmxComponentLoader* self = new(ELeave) CSymbianOmxComponentLoader;
       
   426 	CleanupStack::PushL(self);
       
   427 	self->ConstructL();
       
   428 	CleanupStack::Pop();
       
   429 	
       
   430 	return self;
       
   431 	}
       
   432 
       
   433 // ECOM
       
   434 const TImplementationProxy ImplementationTable[] = 
       
   435 	{
       
   436 	IMPLEMENTATION_PROXY_ENTRY(KUidOmxILSymbianComponentLoader, CSymbianOmxComponentLoader::NewL),
       
   437 	};
       
   438 
       
   439 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   440 	{
       
   441 	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   442 	return ImplementationTable;
       
   443 	}