omxil/omxilcomponentcommon/src/common/omxilcomponent.cpp
changeset 56 b6488ac24ddc
parent 47 481b3bce574a
child 57 1cbb0d5bf7f2
equal deleted inserted replaced
47:481b3bce574a 56:b6488ac24ddc
     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  @file
       
    18  @internalComponent
       
    19 */
       
    20 
       
    21 #include "log.h"
       
    22 #include "omxilcomponent.h"
       
    23 #include "omxilfsm.h"
       
    24 #include "omxilcallbackmanager.h"
       
    25 #include "omxilconfigmanager.h"
       
    26 
       
    27 
       
    28 EXPORT_C
       
    29 COmxILComponent::COmxILComponent()
       
    30 	{
       
    31     DEBUG_PRINTF(_L8("COmxILComponent::COmxILComponent"));
       
    32 
       
    33 	}
       
    34 
       
    35 
       
    36 EXPORT_C
       
    37 COmxILComponent::~COmxILComponent()
       
    38 	{
       
    39     DEBUG_PRINTF2(_L8("COmxILComponent::~COmxILComponent : Handle[%X]"), ipHandle);
       
    40 	iComponentName.Close();
       
    41 	}
       
    42 
       
    43 
       
    44 EXPORT_C void
       
    45 COmxILComponent::InitComponentL()
       
    46 	{
       
    47     DEBUG_PRINTF2(_L8("COmxILComponent::InitComponent : Handle[%X]"), ipHandle);
       
    48 
       
    49 	__ASSERT_ALWAYS(ipHandle && ipFsm && ipConfigManager, User::Invariant());
       
    50 
       
    51 	char componentNamebuffer[OMX_MAX_STRINGNAME_SIZE];
       
    52 	OMX_VERSIONTYPE componentVersion;
       
    53 	OMX_VERSIONTYPE specVersion;
       
    54 	OMX_UUIDTYPE componentUid;
       
    55 
       
    56 	ipConfigManager->GetComponentVersion(componentNamebuffer,
       
    57 										 &componentVersion,
       
    58 										 &specVersion,
       
    59 										 &componentUid);
       
    60 	TBuf8<128> componentNameBuf8;
       
    61 	componentNameBuf8 = const_cast<const TUint8*>(reinterpret_cast<TUint8*>(componentNamebuffer));
       
    62 	iComponentName.CreateL(componentNameBuf8, componentNameBuf8.Length() + 1);
       
    63 	iComponentName.PtrZ();
       
    64     DEBUG_PRINTF2(_L8("COmxILComponent::InitComponent : [%S]"), &iComponentName);
       
    65 
       
    66 	// Fill in the component handle
       
    67 	ipHandle->nVersion				 = componentVersion;
       
    68 	// The FSM will take care of all the API calls
       
    69 	ipHandle->pComponentPrivate		 = ipFsm;
       
    70 	ipHandle->GetComponentVersion	 = COmxILComponent::GetComponentVersion;
       
    71 	ipHandle->SendCommand			 = COmxILComponent::SendCommand;
       
    72 	ipHandle->GetParameter			 = COmxILComponent::GetParameter;
       
    73 	ipHandle->SetParameter			 = COmxILComponent::SetParameter;
       
    74 	ipHandle->GetConfig				 = COmxILComponent::GetConfig;
       
    75 	ipHandle->SetConfig				 = COmxILComponent::SetConfig;
       
    76 	ipHandle->GetExtensionIndex		 = COmxILComponent::GetExtensionIndex;
       
    77 	ipHandle->GetState				 = COmxILComponent::GetState;
       
    78 	ipHandle->ComponentTunnelRequest = COmxILComponent::ComponentTunnelRequest;
       
    79 	ipHandle->UseBuffer				 = COmxILComponent::UseBuffer;
       
    80 	ipHandle->AllocateBuffer		 = COmxILComponent::AllocateBuffer;
       
    81 	ipHandle->FreeBuffer			 = COmxILComponent::FreeBuffer;
       
    82 	ipHandle->EmptyThisBuffer		 = COmxILComponent::EmptyThisBuffer;
       
    83 	ipHandle->FillThisBuffer		 = COmxILComponent::FillThisBuffer;
       
    84 	ipHandle->SetCallbacks			 = COmxILComponent::SetCallbacks;
       
    85 	ipHandle->ComponentDeInit		 = COmxILComponent::ComponentDeInit;
       
    86 	ipHandle->UseEGLImage			 = COmxILComponent::UseEGLImage;
       
    87 	ipHandle->ComponentRoleEnum		 = COmxILComponent::ComponentRoleEnum;
       
    88 
       
    89 	OMX_ERRORTYPE omxRetValue =
       
    90 		ipCallbackManager->RegisterComponentHandle(ipHandle);
       
    91 	if (OMX_ErrorNone != omxRetValue)
       
    92 		{
       
    93 		if (OMX_ErrorInsufficientResources == omxRetValue)
       
    94 			{
       
    95 			User::Leave(KErrNoMemory);
       
    96 			}
       
    97 		User::Leave(KErrGeneral);
       
    98 		}
       
    99 
       
   100 	// Let's init the FSM...
       
   101 	ipFsm->InitFsm();
       
   102 
       
   103 	}
       
   104 
       
   105 OMX_ERRORTYPE
       
   106 COmxILComponent::GetComponentVersion(
       
   107 	OMX_HANDLETYPE aComponent,
       
   108 	OMX_STRING aComponentName,
       
   109 	OMX_VERSIONTYPE* apComponentVersion,
       
   110 	OMX_VERSIONTYPE* apSpecVersion,
       
   111 	OMX_UUIDTYPE* apComponentUUID)
       
   112 	{
       
   113     DEBUG_PRINTF2(_L8("COmxILComponent::GetComponentVersion : Handle[%X]"), aComponent);
       
   114     OMX_ERRORTYPE omxError;
       
   115     omxError = (static_cast<COmxILFsm*>
       
   116 			((static_cast<OMX_COMPONENTTYPE*>(aComponent))->pComponentPrivate))->
       
   117 		GetComponentVersion(aComponentName, apComponentVersion,
       
   118 							apSpecVersion, apComponentUUID);
       
   119     return omxError;
       
   120 	}
       
   121 
       
   122 OMX_ERRORTYPE
       
   123 COmxILComponent::SendCommand(
       
   124 	OMX_HANDLETYPE aComponent,
       
   125 	OMX_COMMANDTYPE aCmd,
       
   126 	OMX_U32 aParam1,
       
   127 	OMX_PTR aCmdData)
       
   128 	{
       
   129     DEBUG_PRINTF2(_L8("COmxILComponent::SendCommand : Handle[%X]"), aComponent);
       
   130     OMX_ERRORTYPE omxError;
       
   131 	omxError =  (static_cast<COmxILFsm*>
       
   132 			((static_cast<OMX_COMPONENTTYPE*>(aComponent))->pComponentPrivate))->
       
   133 		SendCommand(aCmd ,aParam1, aCmdData);
       
   134 	
       
   135 	return omxError;
       
   136 	}
       
   137 
       
   138 OMX_ERRORTYPE
       
   139 COmxILComponent::GetParameter(
       
   140 	OMX_HANDLETYPE aComponent,
       
   141 	OMX_INDEXTYPE aParamIndex,
       
   142 	OMX_PTR aComponentParameterStructure)
       
   143 	{
       
   144     DEBUG_PRINTF3(_L8("COmxILComponent::GetParameter : Handle[%X]; ParamIndex[0x%X]"), aComponent, aParamIndex);
       
   145     
       
   146     OMX_ERRORTYPE omxError;
       
   147 	omxError = (static_cast<COmxILFsm*>
       
   148 			((static_cast<OMX_COMPONENTTYPE*>(aComponent))->pComponentPrivate))->
       
   149 		GetParameter(aParamIndex, aComponentParameterStructure);
       
   150 	
       
   151 	return omxError;
       
   152 	}
       
   153 
       
   154 OMX_ERRORTYPE
       
   155 COmxILComponent::SetParameter(
       
   156 	OMX_HANDLETYPE aComponent,
       
   157 	OMX_INDEXTYPE aIndex,
       
   158 	OMX_PTR aComponentParameterStructure)
       
   159 	{
       
   160     DEBUG_PRINTF3(_L8("COmxILComponent::SetParameter : Handle[%X]; ParamIndex[0x%X]"), aComponent, aIndex);
       
   161     
       
   162     OMX_ERRORTYPE omxError;
       
   163 	omxError = (static_cast<COmxILFsm*>
       
   164 			((static_cast<OMX_COMPONENTTYPE*>(aComponent))->pComponentPrivate))->
       
   165 		SetParameter(aIndex,
       
   166 					 const_cast<const TAny*>(aComponentParameterStructure));
       
   167 
       
   168 	return omxError;
       
   169 	}
       
   170 
       
   171 OMX_ERRORTYPE
       
   172 COmxILComponent::GetConfig(
       
   173 	OMX_HANDLETYPE aComponent,
       
   174 	OMX_INDEXTYPE aIndex,
       
   175 	OMX_PTR aComponentParameterStructure)
       
   176 	{
       
   177     DEBUG_PRINTF3(_L8("COmxILComponent::GetConfig : Handle[%X]; ConfigIndex[0x%X]"), aComponent, aIndex);
       
   178     OMX_ERRORTYPE omxError;
       
   179 	omxError = (static_cast<COmxILFsm*>
       
   180 			((static_cast<OMX_COMPONENTTYPE*>(aComponent))->pComponentPrivate))->
       
   181 		GetConfig(aIndex, aComponentParameterStructure);
       
   182 	return omxError;
       
   183 	}
       
   184 
       
   185 OMX_ERRORTYPE
       
   186 COmxILComponent::SetConfig(
       
   187 	OMX_HANDLETYPE aComponent,
       
   188 	OMX_INDEXTYPE aIndex,
       
   189 	OMX_PTR aComponentConfigStructure)
       
   190 	{
       
   191     DEBUG_PRINTF3(_L8("COmxILComponent::SetConfig : Handle[%X]; ConfigIndex[0x%X]"), aComponent, aIndex);
       
   192     OMX_ERRORTYPE omxError;
       
   193 	omxError = (static_cast<COmxILFsm*>
       
   194 			((static_cast<OMX_COMPONENTTYPE*>(aComponent))->pComponentPrivate))->
       
   195 		SetConfig(aIndex, const_cast<const TAny*>(aComponentConfigStructure));
       
   196 	return omxError;
       
   197 	}
       
   198 
       
   199 OMX_ERRORTYPE
       
   200 COmxILComponent::GetExtensionIndex(
       
   201 	OMX_HANDLETYPE aComponent,
       
   202 	OMX_STRING aParameterName,
       
   203 	OMX_INDEXTYPE* aIndexType)
       
   204 	{
       
   205     DEBUG_PRINTF2(_L8("COmxILComponent::GetExtensionIndex : Handle[%X]"), aComponent);
       
   206     OMX_ERRORTYPE omxError;
       
   207 	omxError = (static_cast<COmxILFsm*>
       
   208 			((static_cast<OMX_COMPONENTTYPE*>(aComponent))->pComponentPrivate))->
       
   209 		GetExtensionIndex(aParameterName, aIndexType);
       
   210 	return omxError;
       
   211 	}
       
   212 
       
   213 OMX_ERRORTYPE
       
   214 COmxILComponent::GetState(
       
   215 	OMX_HANDLETYPE aComponent,
       
   216 	OMX_STATETYPE* aState)
       
   217 	{
       
   218     DEBUG_PRINTF2(_L8("COmxILComponent::GetState : Handle[%X]"), aComponent);
       
   219     OMX_ERRORTYPE omxError;
       
   220     omxError = (static_cast<COmxILFsm*>
       
   221 			((static_cast<OMX_COMPONENTTYPE*>(aComponent))->pComponentPrivate))->
       
   222 		GetState(aState);
       
   223     return omxError;
       
   224 	}
       
   225 
       
   226 OMX_ERRORTYPE
       
   227 COmxILComponent::ComponentTunnelRequest(
       
   228 	OMX_HANDLETYPE aComponent,
       
   229 	OMX_U32 aPort,
       
   230 	OMX_HANDLETYPE aTunneledComp,
       
   231 	OMX_U32 aTunneledPort,
       
   232 	OMX_TUNNELSETUPTYPE* aTunnelSetup)
       
   233 	{
       
   234     DEBUG_PRINTF2(_L8("COmxILComponent::ComponentTunnelRequest : Handle[%X]"), aComponent);
       
   235     OMX_ERRORTYPE omxError;
       
   236 	omxError = (static_cast<COmxILFsm*>
       
   237 			((static_cast<OMX_COMPONENTTYPE*>(aComponent))->pComponentPrivate))->
       
   238 		ComponentTunnelRequest(aPort, aTunneledComp,
       
   239 							   aTunneledPort, aTunnelSetup);
       
   240     return omxError;
       
   241 	}
       
   242 
       
   243 OMX_ERRORTYPE
       
   244 COmxILComponent::UseBuffer(
       
   245 	OMX_HANDLETYPE aComponent,
       
   246 	OMX_BUFFERHEADERTYPE** appBufferHdr,
       
   247 	OMX_U32 aPortIndex,
       
   248 	OMX_PTR apAppPrivate,
       
   249 	OMX_U32 aSizeBytes,
       
   250 	OMX_U8* aBuffer)
       
   251 	{
       
   252     DEBUG_PRINTF2(_L8("COmxILComponent::UseBuffer : Handle[%X]"), aComponent);
       
   253     OMX_ERRORTYPE omxError;
       
   254     omxError = (static_cast<COmxILFsm*>
       
   255 			((static_cast<OMX_COMPONENTTYPE*>(aComponent))->pComponentPrivate))->
       
   256 		UseBuffer(appBufferHdr, aPortIndex, apAppPrivate, aSizeBytes, aBuffer);
       
   257     return omxError;
       
   258 	}
       
   259 
       
   260 OMX_ERRORTYPE
       
   261 COmxILComponent::AllocateBuffer(
       
   262 	OMX_HANDLETYPE aComponent,
       
   263 	OMX_BUFFERHEADERTYPE** apBuffer,
       
   264 	OMX_U32 aPortIndex,
       
   265 	OMX_PTR aAppData,
       
   266 	OMX_U32 aSizeBytes)
       
   267 	{
       
   268     DEBUG_PRINTF2(_L8("COmxILComponent::AllocateBuffer : Handle[%X]"), aComponent);
       
   269     OMX_ERRORTYPE omxError;
       
   270     omxError = (static_cast<COmxILFsm*>
       
   271 			((static_cast<OMX_COMPONENTTYPE*>(aComponent))->pComponentPrivate))->
       
   272 		AllocateBuffer(apBuffer, aPortIndex, aAppData, aSizeBytes);
       
   273     return omxError;
       
   274 	}
       
   275 
       
   276 OMX_ERRORTYPE
       
   277 COmxILComponent::FreeBuffer(
       
   278 	OMX_HANDLETYPE aComponent,
       
   279 	OMX_U32 aPortIndex,
       
   280 	OMX_BUFFERHEADERTYPE* aBuffer)
       
   281 	{
       
   282     DEBUG_PRINTF2(_L8("COmxILComponent::FreeBuffer : Handle[%X]"), aComponent);
       
   283     OMX_ERRORTYPE omxError;
       
   284     omxError = (static_cast<COmxILFsm*>
       
   285 			((static_cast<OMX_COMPONENTTYPE*>(aComponent))->pComponentPrivate))->
       
   286 		FreeBuffer(aPortIndex, aBuffer);
       
   287     return omxError;
       
   288 	}
       
   289 
       
   290 OMX_ERRORTYPE
       
   291 COmxILComponent::EmptyThisBuffer(
       
   292 	OMX_HANDLETYPE aComponent,
       
   293 	OMX_BUFFERHEADERTYPE* aBuffer)
       
   294 	{
       
   295     DEBUG_PRINTF2(_L8("COmxILComponent::EmptyThisBuffer : Handle[%X]"), aComponent);
       
   296 #ifdef _OMXIL_COMMON_BUFFER_TRACING_ON
       
   297 	RDebug::Print(_L("COmxILComponent::EmptyThisBuffer component=0x%08X header=0x%08X port=%d flags=0x%X filledLen=%d timeStamp=%Ld"),
       
   298 		aComponent, aBuffer, aBuffer->nInputPortIndex, aBuffer->nFlags, aBuffer->nFilledLen, aBuffer->nTimeStamp);
       
   299 #endif
       
   300 	OMX_ERRORTYPE omxError;
       
   301 	omxError =  (static_cast<COmxILFsm*>
       
   302 			((static_cast<OMX_COMPONENTTYPE*>(aComponent))->pComponentPrivate))->
       
   303 		EmptyThisBuffer(aBuffer);
       
   304 	
       
   305 	return omxError;
       
   306 	}
       
   307 
       
   308 OMX_ERRORTYPE
       
   309 COmxILComponent::FillThisBuffer(
       
   310 	OMX_HANDLETYPE aComponent,
       
   311 	OMX_BUFFERHEADERTYPE* aBuffer)
       
   312 	{
       
   313     DEBUG_PRINTF2(_L8("COmxILComponent::FillThisBuffer : Handle[%X]"), aComponent);
       
   314 #ifdef _OMXIL_COMMON_BUFFER_TRACING_ON
       
   315 	RDebug::Print(_L("COmxILComponent::FillThisBuffer component=0x%08X header=0x%08X port=%d"), aComponent, aBuffer, aBuffer->nOutputPortIndex);
       
   316 #endif
       
   317 	
       
   318 	OMX_ERRORTYPE omxError;
       
   319 	omxError =  (static_cast<COmxILFsm*>
       
   320 			((static_cast<OMX_COMPONENTTYPE*>(aComponent))->pComponentPrivate))->
       
   321 		FillThisBuffer(aBuffer);
       
   322 	
       
   323 	return omxError;
       
   324 	}
       
   325 
       
   326 OMX_ERRORTYPE
       
   327 COmxILComponent::SetCallbacks(
       
   328 	OMX_HANDLETYPE aComponent,
       
   329 	OMX_CALLBACKTYPE* aCallbacks,
       
   330 	OMX_PTR aAppData)
       
   331 	{
       
   332     DEBUG_PRINTF2(_L8("COmxILComponent::SetCallbacks : Handle[%X]"), aComponent);
       
   333     OMX_ERRORTYPE omxError;
       
   334 	omxError = (static_cast<COmxILFsm*>
       
   335 			((static_cast<OMX_COMPONENTTYPE*>(aComponent))->pComponentPrivate))->
       
   336 		SetCallbacks(const_cast<const OMX_CALLBACKTYPE*>(aCallbacks), aAppData);
       
   337 	return omxError;
       
   338 	}
       
   339 
       
   340 OMX_ERRORTYPE
       
   341 COmxILComponent::ComponentDeInit(
       
   342 	OMX_HANDLETYPE aComponent)
       
   343 	{
       
   344     DEBUG_PRINTF2(_L8("COmxILComponent::ComponentDeInit : Handle[%X]"), aComponent);
       
   345 	delete (static_cast<COmxILComponent*>(
       
   346 				(static_cast<COmxILFsm*>(
       
   347 					(static_cast<OMX_COMPONENTTYPE*>(aComponent))->
       
   348 					pComponentPrivate))->GetComponent()));
       
   349 	return OMX_ErrorNone;
       
   350 	}
       
   351 
       
   352 OMX_ERRORTYPE
       
   353 COmxILComponent::UseEGLImage(
       
   354 		OMX_HANDLETYPE aComponent,
       
   355 		OMX_BUFFERHEADERTYPE** appBufferHdr,
       
   356 		OMX_U32 aPortIndex,
       
   357 		OMX_PTR aAppPrivate,
       
   358 		void* eglImage)
       
   359 	{
       
   360     DEBUG_PRINTF2(_L8("COmxILComponent::UseEGLImage : Handle[%X]"), aComponent);
       
   361     OMX_ERRORTYPE omxError;
       
   362     omxError = (static_cast<COmxILFsm*>
       
   363 			((static_cast<OMX_COMPONENTTYPE*>(aComponent))->pComponentPrivate))->
       
   364 		UseEGLImage(appBufferHdr, aPortIndex, aAppPrivate, eglImage);
       
   365     return omxError;
       
   366 	}
       
   367 
       
   368 OMX_ERRORTYPE
       
   369 COmxILComponent::ComponentRoleEnum(
       
   370 	OMX_HANDLETYPE aComponent,
       
   371 	OMX_U8* aRole,
       
   372 	OMX_U32 aIndex)
       
   373 	{
       
   374     DEBUG_PRINTF2(_L8("COmxILComponent::ComponentRoleEnum : Handle[%X]"), aComponent);
       
   375     OMX_ERRORTYPE omxError;
       
   376     omxError = (static_cast<COmxILFsm*>
       
   377 			((static_cast<OMX_COMPONENTTYPE*>(aComponent))->pComponentPrivate))->
       
   378 		ComponentRoleEnum(aRole, aIndex);
       
   379     return omxError;
       
   380 	}
       
   381 
       
   382 /*static*/ EXPORT_C OMX_ERRORTYPE COmxILComponent::SymbianErrorToGetHandleError(TInt aSymbianError)
       
   383 	{
       
   384 	switch(aSymbianError)
       
   385 		{
       
   386 	case KErrNone:
       
   387 		return OMX_ErrorNone;
       
   388 	case KErrNoMemory:
       
   389 		return OMX_ErrorInsufficientResources;
       
   390 	case KErrArgument:
       
   391 		return OMX_ErrorBadParameter;
       
   392 		};
       
   393 
       
   394 	return OMX_ErrorUndefined;	
       
   395 	}