omxil/mmilapi/refomxil/src/omxilgenericilif/omxilgenericilifbody.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 #include "omxilgenericilifbody.h"
       
    18 #include "omxilcoreutils.h"
       
    19 #include "omxilspecversion.h"
       
    20 #include "milifobserver.h"
       
    21 #include "tilstructtypes.h"
       
    22 
       
    23 
       
    24 const TInt KMaxComponentNameLength = 128;
       
    25 
       
    26 
       
    27 COmxILGenericILIF::CBody::CBody(COmxILGenericILIF& aParent,
       
    28 								MILIfObserver& aComponentIfObserver)
       
    29 	:
       
    30 	iParent(aParent),
       
    31 	iIfObserver(aComponentIfObserver)
       
    32 
       
    33 	{
       
    34 	}
       
    35 
       
    36 COmxILGenericILIF::CBody::~CBody()
       
    37 	{
       
    38 	iInputPorts.ResetAndDestroy();
       
    39 	iInputPorts.Close();
       
    40 	iOutputPorts.ResetAndDestroy();
       
    41 	iOutputPorts.Close();
       
    42 	delete iBufferManager;	
       
    43 	delete iCallbacks;	
       
    44 
       
    45 	::OMX_FreeHandle(reinterpret_cast<OMX_HANDLETYPE>(iHandle));
       
    46 	}
       
    47 
       
    48 COmxILGenericILIF::CBody* COmxILGenericILIF::CBody::NewL(COmxILGenericILIF& aParent,
       
    49 													 	 MILIfObserver& aComponentIfObserver,
       
    50 													 	 const TDesC8& aComponentName)
       
    51 	{
       
    52 	CBody* self = new (ELeave) CBody(aParent, aComponentIfObserver);
       
    53 	CleanupStack::PushL(self);
       
    54 	self->ConstructL(aComponentName);
       
    55 	CleanupStack::Pop(self);
       
    56 	return self;
       
    57 	}
       
    58 	
       
    59 void COmxILGenericILIF::CBody::ConstructL(const TDesC8& aComponentName)
       
    60 	{
       
    61 	iCallbacks = COmxCallbacks::NewL(iParent);
       
    62 	
       
    63 	RBuf8 buf;
       
    64 	buf.CleanupClosePushL();
       
    65 	buf.CreateL(aComponentName, KMaxComponentNameLength);
       
    66     TUint8* name = const_cast<TUint8*>(buf.PtrZ());
       
    67 
       
    68 	OMX_ERRORTYPE errorType = ::OMX_GetHandle(reinterpret_cast<OMX_HANDLETYPE*>(&iHandle), 
       
    69 								reinterpret_cast<OMX_STRING>(name), 
       
    70 								iCallbacks, 
       
    71 							    *iCallbacks);
       
    72 	CleanupStack::PopAndDestroy(&buf);
       
    73 								
       
    74 	User::LeaveIfError(ConvertOmxErrorType(errorType));
       
    75 
       
    76 	iBufferManager = new (ELeave) COmxBufferManager(iHandle);
       
    77 	}
       
    78 
       
    79 OMX_COMPONENTTYPE* COmxILGenericILIF::CBody::Handle() const
       
    80 	{
       
    81 	return iHandle;	
       
    82 	}
       
    83 	
       
    84 TInt COmxILGenericILIF::CBody::OmxGetComponentVersion(TPtr8 aComponentName, 
       
    85 													  OMX_VERSIONTYPE* aComponentVersion, 
       
    86 													  OMX_VERSIONTYPE* aSpecVersion, 
       
    87 													  OMX_UUIDTYPE* aComponentUUID)
       
    88 	{
       
    89 	ASSERT(aComponentVersion);
       
    90 	ASSERT(aSpecVersion);
       
    91 	ASSERT(aComponentUUID);
       
    92 
       
    93 	TUint8* cname = const_cast<TUint8*>(aComponentName.PtrZ());
       
    94 	OMX_ERRORTYPE error = iHandle->GetComponentVersion(reinterpret_cast<OMX_HANDLETYPE>(iHandle), 
       
    95 						  reinterpret_cast<OMX_STRING>(cname), aComponentVersion, aSpecVersion, aComponentUUID);
       
    96 
       
    97 	TLex8 lex(cname);
       
    98 	TInt length;
       
    99 	for( length = 0; !lex.Eos(); ++length )
       
   100 		{
       
   101 		lex.Inc();
       
   102 		}
       
   103 	aComponentName.SetLength(length);
       
   104 
       
   105 	return ConvertOmxErrorType(error);
       
   106 	}
       
   107 	
       
   108 TInt COmxILGenericILIF::CBody::OmxSendCommand(OMX_COMMANDTYPE aCmd, 
       
   109 											  TUint32 aParam, 
       
   110 											  TAny* aCmdData)
       
   111 	{
       
   112 	OMX_ERRORTYPE error = iHandle->SendCommand(reinterpret_cast<OMX_HANDLETYPE>(iHandle), aCmd, aParam, aCmdData);
       
   113 	return ConvertOmxErrorType(error);
       
   114 	}
       
   115 
       
   116 TInt COmxILGenericILIF::CBody::OmxGetParameter(OMX_INDEXTYPE aParamIndex, 
       
   117 											   TAny* aValue)
       
   118 	{
       
   119 	ASSERT(aValue);
       
   120 
       
   121 	OMX_ERRORTYPE error = iHandle->GetParameter(reinterpret_cast<OMX_HANDLETYPE>(iHandle), aParamIndex, aValue);
       
   122 	return ConvertOmxErrorType(error);
       
   123 	}
       
   124 	
       
   125 TInt COmxILGenericILIF::CBody::OmxSetParameter(OMX_INDEXTYPE aIndex, 
       
   126 											   TAny* aValue)
       
   127 	{
       
   128 	ASSERT(aValue);
       
   129 
       
   130 	OMX_ERRORTYPE error = iHandle->SetParameter(reinterpret_cast<OMX_HANDLETYPE>(iHandle), aIndex, aValue);
       
   131 	return ConvertOmxErrorType(error);
       
   132 	}
       
   133 
       
   134 TInt COmxILGenericILIF::CBody::OmxGetConfig(OMX_INDEXTYPE aIndex, 
       
   135 											TAny* aValue)
       
   136 	{
       
   137 	ASSERT(aValue);
       
   138 
       
   139 	OMX_ERRORTYPE error = iHandle->GetConfig(reinterpret_cast<OMX_HANDLETYPE>(iHandle), aIndex, aValue);
       
   140 	return ConvertOmxErrorType(error);
       
   141 	}
       
   142 	
       
   143 TInt COmxILGenericILIF::CBody::OmxSetConfig(OMX_INDEXTYPE aIndex, 
       
   144 											TAny* aValue)
       
   145 	{
       
   146 	ASSERT(aValue);
       
   147 
       
   148 	OMX_ERRORTYPE error = iHandle->SetConfig(reinterpret_cast<OMX_HANDLETYPE>(iHandle), aIndex, aValue);
       
   149 	return ConvertOmxErrorType(error);
       
   150 	}
       
   151 	
       
   152 TInt COmxILGenericILIF::CBody::OmxGetExtensionIndex(const TDesC8& aParameterName, 
       
   153 													OMX_INDEXTYPE* aIndexType)
       
   154 	{
       
   155 	HBufC8* buf = HBufC8::New(aParameterName.Length()+1);
       
   156 	if (buf == NULL)
       
   157 		{
       
   158 		return KErrNoMemory;
       
   159 		}
       
   160 	else
       
   161 		{
       
   162 		*buf = aParameterName;
       
   163 		TUint8* cstring = const_cast<TUint8*>(buf->Des().PtrZ());
       
   164 		OMX_ERRORTYPE error = iHandle->GetExtensionIndex(reinterpret_cast<OMX_HANDLETYPE>(iHandle), reinterpret_cast<char*>(cstring), aIndexType);
       
   165 		delete buf;
       
   166 		return ConvertOmxErrorType(error);
       
   167 		}
       
   168 	}
       
   169 
       
   170 TInt COmxILGenericILIF::CBody::OmxGetState(OMX_STATETYPE*  aState)
       
   171 	{
       
   172 	
       
   173 	OMX_ERRORTYPE error = iHandle->GetState(reinterpret_cast<OMX_HANDLETYPE>(iHandle), aState);
       
   174 	return ConvertOmxErrorType(error);
       
   175 	}
       
   176 	
       
   177 TInt COmxILGenericILIF::CBody::OmxComponentTunnelRequest(TUint32 aPortInput, 
       
   178 														 OMX_HANDLETYPE aOutput, 
       
   179 														 TUint32 aPortOutput)
       
   180 	{
       
   181 	OMX_ERRORTYPE error = ::OMX_SetupTunnel(aOutput, aPortOutput, reinterpret_cast<OMX_HANDLETYPE>(iHandle), aPortInput);
       
   182 	return ConvertOmxErrorType(error);
       
   183 	}
       
   184 	
       
   185 TInt COmxILGenericILIF::CBody::OmxComponentDisconnectTunnel(TUint32 aPortInput, 
       
   186 														 	OMX_HANDLETYPE aOutput, 
       
   187 														 	TUint32 aPortOutput)
       
   188 	{
       
   189 	OMX_ERRORTYPE error = ::OMX_SetupTunnel(aOutput, aPortOutput, 0, 0);
       
   190 	if (error == OMX_ErrorNone)
       
   191 		{
       
   192 		error = ::OMX_SetupTunnel(0, 0, reinterpret_cast<OMX_HANDLETYPE>(iHandle), aPortInput);
       
   193 		}
       
   194 	return ConvertOmxErrorType(error);
       
   195 	}
       
   196 
       
   197 TInt COmxILGenericILIF::CBody::OmxUseBuffer(CMMFBuffer* aBuffer, 
       
   198 											TUint32 aPortIndex)
       
   199 	{
       
   200 	ASSERT(aBuffer);
       
   201 
       
   202 	return (iBufferManager->UseBuffer(*aBuffer, aPortIndex));	
       
   203 	}
       
   204 
       
   205 CMMFBuffer* COmxILGenericILIF::CBody::OmxAllocateBufferL(TUint32 aPortIndex, 
       
   206 														 TUint32 aSizeBytes)
       
   207 	{
       
   208 	return (iBufferManager->AllocateBufferL(aPortIndex, aSizeBytes));
       
   209 	}
       
   210 
       
   211 TInt COmxILGenericILIF::CBody::OmxFreeBuffer(CMMFBuffer* aBuffer)
       
   212 	{
       
   213 	ASSERT(aBuffer);
       
   214 
       
   215 	return (iBufferManager->FreeBuffer(aBuffer));
       
   216 	}
       
   217 
       
   218 TInt COmxILGenericILIF::CBody::OmxEmptyThisBuffer(const CMMFBuffer* aBuffer, 
       
   219 												  MOmxILComponentIfObserver* aObserver)
       
   220 	{
       
   221 	ASSERT(aBuffer);
       
   222 
       
   223 	return (iBufferManager->EmptyThisBuffer(aBuffer, aObserver));
       
   224 	}
       
   225 
       
   226 TInt COmxILGenericILIF::CBody::OmxFillThisBuffer(CMMFBuffer* aBuffer, 
       
   227 												 MOmxILComponentIfObserver* aObserver)
       
   228 	{
       
   229 	ASSERT(aBuffer);
       
   230 
       
   231 	return (iBufferManager->FillThisBuffer(aBuffer, aObserver));
       
   232 	}
       
   233 
       
   234 TInt COmxILGenericILIF::CBody::OmxComponentRoleEnum(TPtr8& aComponentRole, 
       
   235 													TUint32 aIndex)
       
   236 	{
       
   237 	TUint8* role = const_cast<TUint8*> (aComponentRole.PtrZ());
       
   238 	OMX_ERRORTYPE error = iHandle->ComponentRoleEnum(reinterpret_cast<OMX_HANDLETYPE>(iHandle), reinterpret_cast<OMX_U8*>(role), aIndex);
       
   239 
       
   240 	TLex8 lex(role);
       
   241 	TInt length;
       
   242 	for( length = 0; !lex.Eos(); ++length )
       
   243 		{
       
   244 		lex.Inc();
       
   245 		}
       
   246 	aComponentRole.SetLength(length);
       
   247 
       
   248 	return ConvertOmxErrorType(error);
       
   249 	}
       
   250 
       
   251 TInt COmxILGenericILIF::CBody::SetIfToRole(const TUid& aComponentRole)
       
   252 	{
       
   253 	iFormat = aComponentRole;
       
   254 	return KErrNone;
       
   255 	}
       
   256 
       
   257 TInt COmxILGenericILIF::CBody::GetIfRole(TUid& aComponentRole) const
       
   258 	{
       
   259 	aComponentRole = iFormat;
       
   260 	return KErrNone;	
       
   261 	}
       
   262 	
       
   263 TInt COmxILGenericILIF::CBody::SetPortsL()
       
   264 	{
       
   265 	OMX_PORT_PARAM_TYPE param;
       
   266 	param.nVersion = KOMXILSpecVersion;
       
   267 	param.nSize = sizeof(OMX_PORT_PARAM_TYPE);
       
   268 	TInt err = OmxGetParameter(OMX_IndexParamAudioInit, &param);
       
   269 	
       
   270 	if (err == KErrNone)
       
   271 		{
       
   272 		for (TInt i=0; i < param.nPorts && err == KErrNone; i++ ) 
       
   273 			{
       
   274 			OMX_PARAM_PORTDEFINITIONTYPE portInfo;
       
   275 			portInfo.nPortIndex = i;
       
   276 			portInfo.nVersion = KOMXILSpecVersion;
       
   277 			portInfo.nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
       
   278 			err = OmxGetParameter(OMX_IndexParamPortDefinition, &portInfo);	
       
   279 			if (err == KErrNone)
       
   280 				{
       
   281 				if (portInfo.eDir == OMX_DirInput)
       
   282 					{
       
   283 					COmxILGenericPortILIF* inputPort = COmxILGenericPortILIF::NewL(iParent, EDirInput, portInfo.nPortIndex);
       
   284 					err = iInputPorts.Append(inputPort);
       
   285 					}
       
   286 				else
       
   287 					{
       
   288 					COmxILGenericPortILIF* outputPort = COmxILGenericPortILIF::NewL(iParent, EDirOutput, portInfo.nPortIndex);
       
   289 					err = iOutputPorts.Append(outputPort);				
       
   290 					}
       
   291 				}
       
   292 			}
       
   293 		}
       
   294 	return err;
       
   295 	}
       
   296 
       
   297 TInt COmxILGenericILIF::CBody::GetComponentPorts(RPointerArray<MILComponentPortIf>& aComponentPorts, 
       
   298 												 OMX_DIRTYPE aDirection)
       
   299 	{
       
   300 	TInt err = KErrNone;
       
   301 	if 	(aDirection == OMX_DirInput)
       
   302 		{
       
   303 		const TInt counter = iInputPorts.Count();
       
   304 		for (TInt i=0; i < counter && err == KErrNone; i++ )
       
   305 			{
       
   306 			err = aComponentPorts.Append(iInputPorts[i]);
       
   307 			}
       
   308 		}
       
   309 	else if (aDirection == OMX_DirOutput)
       
   310 		{
       
   311 		const TInt counter = iOutputPorts.Count();
       
   312 		for (TInt i=0; i < counter && err == KErrNone; i++ )
       
   313 			{
       
   314 			err = aComponentPorts.Append(iOutputPorts[i]);
       
   315 			}			
       
   316 		}
       
   317 	else 
       
   318 		{
       
   319 		err = KErrNotSupported;
       
   320 		}
       
   321 	return err;
       
   322 	}
       
   323 
       
   324 TInt COmxILGenericILIF::CBody::FillBufferDone(CMMFBuffer* aBuffer, 
       
   325 											  TInt aPortIndex)
       
   326 	{
       
   327 	ASSERT(aBuffer);
       
   328 	
       
   329 	// Loop through all output ports to search for the interface associated to this port index
       
   330 	const TInt counter = iOutputPorts.Count();
       
   331 	for (TInt i=0; i < counter; i++ )
       
   332 		{
       
   333 		if (iOutputPorts[i]->PortIndex() == aPortIndex)
       
   334 			{
       
   335 			return (iIfObserver.BufferDelivered(iOutputPorts[i], aBuffer));
       
   336 			}
       
   337 		}
       
   338 
       
   339 	return KErrNotFound;
       
   340 	}
       
   341 
       
   342 TInt COmxILGenericILIF::CBody::EmptyBufferDone(const CMMFBuffer* aBuffer, 
       
   343 											   TInt aPortIndex)
       
   344 	{
       
   345 	ASSERT(aBuffer);
       
   346 
       
   347 	// Loop through all input ports to search for the interface associated to this port index
       
   348 	const TInt counter = iInputPorts.Count();
       
   349 	for (TInt i=0; i < counter; i++ )
       
   350 		{
       
   351 		if (iInputPorts[i]->PortIndex() == aPortIndex)
       
   352 			{
       
   353 			return (iIfObserver.BufferDelivered(iInputPorts[i], aBuffer));
       
   354 			}
       
   355 		}
       
   356 
       
   357 	return KErrNotFound;
       
   358 	}
       
   359 
       
   360 TInt COmxILGenericILIF::CBody::EventHandler(OMX_EVENTTYPE aEvent, 
       
   361 											TUint32 aData1, 
       
   362 											TUint32 aData2, 
       
   363 											TAny* /*aExtraInfo*/)
       
   364 	{
       
   365 	TInt err = KErrNone;
       
   366 	TILEvent thisEvent;
       
   367 
       
   368 	switch (aEvent)
       
   369 		{
       
   370 		case OMX_EventCmdComplete:
       
   371 			{
       
   372 			thisEvent.iEvent = EEventCmdComplete;
       
   373 			if (aData1 == OMX_CommandStateSet)
       
   374 				{
       
   375 				thisEvent.iData1 = ECommandStateSet;				
       
   376 				OMX_STATETYPE state = static_cast<OMX_STATETYPE>(aData2);	
       
   377 				thisEvent.iData2 = ConvertOmxState(state);
       
   378 				err = iIfObserver.MsgFromILComponent(&iParent, thisEvent); 
       
   379 				break;	
       
   380 				}
       
   381 			else if (aData1 == OMX_CommandFlush)
       
   382 				{
       
   383 				thisEvent.iData1 = ECommandFlush;				
       
   384 				thisEvent.iData2 = aData2; // Port index
       
   385 				err = iIfObserver.MsgFromILComponent(&iParent, thisEvent); 
       
   386 				}
       
   387 			else if (aData1 == OMX_CommandPortDisable)
       
   388 				{
       
   389 				thisEvent.iData1 = ECommandPortDisable;				
       
   390 				thisEvent.iData2 = aData2; // Port index
       
   391 				err = iIfObserver.MsgFromILComponent(&iParent, thisEvent); 
       
   392 				}
       
   393 			else if (aData1 == OMX_CommandPortEnable)
       
   394 				{
       
   395 				thisEvent.iData1 = ECommandPortEnable;				
       
   396 				thisEvent.iData2 = aData2; // Port index
       
   397 				err = iIfObserver.MsgFromILComponent(&iParent, thisEvent); 
       
   398 				}
       
   399 			else 
       
   400 				{
       
   401 				err = KErrNotSupported; 
       
   402 				}
       
   403 			
       
   404 			break;
       
   405 			}
       
   406 		case OMX_EventBufferFlag:
       
   407 			{
       
   408 			// Propagate the EOF up to client as KErrUnderflow
       
   409 			thisEvent.iEvent = EEventBufferFlag;
       
   410 			thisEvent.iData1 = aData1;				
       
   411 			thisEvent.iData2 = static_cast<TUint32>(KErrUnderflow);
       
   412 			err = iIfObserver.MsgFromILComponent(&iParent, thisEvent); 
       
   413 			break;
       
   414 			}
       
   415 		case OMX_EventError:
       
   416 			{
       
   417 			// Propagate the error up to client
       
   418 			thisEvent.iEvent = EEventError;
       
   419 			OMX_ERRORTYPE errorx = static_cast<OMX_ERRORTYPE>(aData1);
       
   420 			thisEvent.iData1 = ConvertOmxErrorType(errorx);				
       
   421 			err = iIfObserver.MsgFromILComponent(&iParent, thisEvent); 
       
   422 			break;
       
   423 			}
       
   424 		default:
       
   425 			{
       
   426 			err = KErrNotSupported;
       
   427 			}
       
   428 		}
       
   429 	return err;
       
   430 	}