sl@0: // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: //
sl@0: 
sl@0: #include <ecom/ecom.h>
sl@0: #include <ecom/ecomerrorcodes.h>
sl@0: #include <ecom/ecomresolverparams.h>
sl@0: #include <ecom/implementationinformation.h>
sl@0: #include <ecom/publicregistry.h>
sl@0: #include <mdf/codecapiresolverdata.h>
sl@0: #include <mdf/codecapiresolverutils.h>
sl@0: #include <mdf/codecapivideoresolverutils.h>
sl@0: #include <mdf/codecapiuids.hrh>
sl@0: #include "codecapiresolver.h"
sl@0: 
sl@0: /**
sl@0: Constructs a CCodecApiResolver object.
sl@0: @param  aRegistry
sl@0: 		A reference to the instantiated registry information 
sl@0: @return An instance of the class or NULL.
sl@0: */
sl@0: CCodecApiResolver* CCodecApiResolver::NewL (MPublicRegistry& aRegistry)
sl@0: 	{
sl@0: 	return new(ELeave) CCodecApiResolver (aRegistry);
sl@0: 	}
sl@0: 
sl@0: 
sl@0: /**
sl@0: Class destructor.
sl@0: */
sl@0: CCodecApiResolver::~CCodecApiResolver()
sl@0: 	{
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: Class constructor.
sl@0: */
sl@0: CCodecApiResolver::CCodecApiResolver (MPublicRegistry& aRegistry) :
sl@0: 	CResolver (aRegistry)
sl@0: 	{
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: Requests the resolver to identify the most appropriate interface implementation.
sl@0: @param  aInterfaceUid
sl@0: 		The interface for which an implementation is requested.
sl@0: @param  aAdditionalParameters
sl@0: 	    The parameters which must match for an implementation to be suitable. 
sl@0: @return The unique id of the implementation which satisfies the specified parameters. 
sl@0:  		KNullUid if not implementation is found.
sl@0: */ 
sl@0: TUid CCodecApiResolver::IdentifyImplementationL(TUid /*aInterfaceUid*/,
sl@0: 	const TEComResolverParams& /*aAdditionalParameters*/) const
sl@0: 	{
sl@0: 	return KNullUid;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: /**
sl@0: Lists all the implementations which satisfy the specified interface definition and the 
sl@0: resolve parameters supplied.
sl@0: @param  aInterfaceUid
sl@0: 		The interface for which an implementation is requested.
sl@0: @param  aAdditionalParameters	  	
sl@0: 		The parameters which must match for an implementation to be suitable.
sl@0: @return Pointer to an array of suitable implementations. Ownership of this array is passed
sl@0: 	    to the calling function. 
sl@0: */
sl@0: RImplInfoArray* CCodecApiResolver::ListAllL(TUid aInterfaceUid,
sl@0: 	const TEComResolverParams& aAdditionalParameters) const
sl@0: 	{
sl@0: 	RImplInfoArray* retList = new (ELeave) RImplInfoArray;
sl@0: 	// coverity[double_push]
sl@0: 	CleanupStack::PushL(retList);
sl@0: 	CleanupClosePushL(*retList);
sl@0: 	
sl@0: 	CCodecApiResolverData* customMatch = CCodecApiResolverData::NewLC(aAdditionalParameters.DataType());
sl@0: 	
sl@0: 	TCodecApiResolverMatchType matchType = customMatch->MatchType();
sl@0: 	TUid implementationTypeUid 			 = customMatch->ImplementationType();
sl@0: 	
sl@0: 	// create a list with all 
sl@0: 	RImplInfoArray& fullList = iRegistry.ListImplementationsL(aInterfaceUid);
sl@0: 	const TInt count = fullList.Count();
sl@0: 	
sl@0: 	for(TInt index = 0; index < count; index++)
sl@0: 		{
sl@0: 		TBool matchFound = EFalse;
sl@0: 		const CImplementationInformation& impData = *(fullList[index]);
sl@0: 		CCodecApiOpaqueData* parse = NULL;
sl@0: 		const TDesC8* opaqueData = &impData.OpaqueData();
sl@0: 		// if opaque data is empty, move to the next element in the list
sl@0: 		if (opaqueData->Length() == 0)
sl@0: 			{
sl@0: 			continue;
sl@0: 			}
sl@0: 		// create an instance of the class which holds the opaque data	
sl@0: 		TInt error = KErrNotFound;
sl@0: 		
sl@0: 		if (implementationTypeUid == TUid::Uid(KUidAudioCodec)) 
sl@0: 			{
sl@0: 			TRAP(error, parse = CCodecApiOpaqueData::NewL(impData.OpaqueData()));	
sl@0: 			}
sl@0: 		else
sl@0: 			{
sl@0: 			if ((implementationTypeUid == TUid::Uid(KUidVideoEncoder)) 
sl@0: 				|| implementationTypeUid == TUid::Uid(KUidVideoDecoder)) 
sl@0: 				{
sl@0: 				TRAP(error, parse = CCodecApiVideoOpaqueData::NewL(impData.OpaqueData()));
sl@0: 				}	
sl@0: 			else
sl@0: 				{
sl@0: 				error = KErrNotSupported;	
sl@0: 				}
sl@0: 			} 
sl@0: 			
sl@0: 		CleanupStack::PushL(parse);	
sl@0: 		
sl@0: 		if (error)
sl@0: 			{
sl@0: 			if ((error == KErrNotSupported) || (error == KErrCorrupt))
sl@0: 				{
sl@0: 				// means that the resource entry was not valid
sl@0: 				// we ignore this plugin and try the next one
sl@0: 				CleanupStack::PopAndDestroy(parse);
sl@0: 				continue;
sl@0: 				}
sl@0: 			else
sl@0: 				{
sl@0: 				User::Leave(error);
sl@0: 				}				
sl@0: 			} //end of 	if (error!=KErrNone)
sl@0: 			
sl@0: 		// check if the uids are different. If they are, move to the next element
sl@0: 		// in the list		
sl@0: 		if (implementationTypeUid != parse->TypeUid())
sl@0: 			{
sl@0: 			CleanupStack::PopAndDestroy(parse);
sl@0: 			continue;
sl@0: 			}
sl@0: 		switch(matchType)
sl@0: 			{	
sl@0: 			// check that the input data type is what we are looking for
sl@0: 			case EMatchInputDataFormat:
sl@0: 				if (parse->CompareInputDataType(customMatch->InputDataFormat()))
sl@0: 					{
sl@0: 					matchFound = ETrue;
sl@0: 					}
sl@0: 				break;
sl@0: 			// check that the output data type is what we are looking for	
sl@0: 			case EMatchOutputDataFormat:
sl@0: 				if (parse->CompareOutputDataType(customMatch->OutputDataFormat()))
sl@0: 					{
sl@0: 					matchFound = ETrue;
sl@0: 					}
sl@0: 				break;
sl@0: 			// check that the input and output data type is what we are looking for	
sl@0: 			case EMatchInputAndOutputDataFormat:
sl@0: 				if (parse->CompareInputDataType(customMatch->InputDataFormat()) 
sl@0: 					&& parse->CompareOutputDataType(customMatch->OutputDataFormat()))
sl@0: 					{
sl@0: 					matchFound = ETrue;
sl@0: 					}
sl@0: 				break;
sl@0: 			default:
sl@0: 				{
sl@0: 				//matchFound was initialised to EFalse, so fall through				
sl@0: 				}				
sl@0: 			}
sl@0: 		// if a match was found, it will be appended to the list returned by this method
sl@0: 		if (matchFound)
sl@0: 			{
sl@0: 			User::LeaveIfError(retList->Append(fullList[index]));	
sl@0: 			}
sl@0: 		CleanupStack::PopAndDestroy(parse);
sl@0: 		} // end of for
sl@0: 	
sl@0: 	CleanupStack::PopAndDestroy(customMatch);
sl@0: 	CleanupStack::Pop(2, retList);
sl@0: 	return retList;	
sl@0: 	}
sl@0: 
sl@0: