mmdevicefw/mdf/src/codecapi/codecapiresolver.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 // Copyright (c) 2005-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/ecomerrorcodes.h>
       
    18 #include <ecom/ecomresolverparams.h>
       
    19 #include <ecom/implementationinformation.h>
       
    20 #include <ecom/publicregistry.h>
       
    21 #include <mdf/codecapiresolverdata.h>
       
    22 #include <mdf/codecapiresolverutils.h>
       
    23 #include <mdf/codecapivideoresolverutils.h>
       
    24 #include <mdf/codecapiuids.hrh>
       
    25 #include "codecapiresolver.h"
       
    26 
       
    27 /**
       
    28 Constructs a CCodecApiResolver object.
       
    29 @param  aRegistry
       
    30 		A reference to the instantiated registry information 
       
    31 @return An instance of the class or NULL.
       
    32 */
       
    33 CCodecApiResolver* CCodecApiResolver::NewL (MPublicRegistry& aRegistry)
       
    34 	{
       
    35 	return new(ELeave) CCodecApiResolver (aRegistry);
       
    36 	}
       
    37 
       
    38 
       
    39 /**
       
    40 Class destructor.
       
    41 */
       
    42 CCodecApiResolver::~CCodecApiResolver()
       
    43 	{
       
    44 	}
       
    45 
       
    46 /**
       
    47 Class constructor.
       
    48 */
       
    49 CCodecApiResolver::CCodecApiResolver (MPublicRegistry& aRegistry) :
       
    50 	CResolver (aRegistry)
       
    51 	{
       
    52 	}
       
    53 
       
    54 /**
       
    55 Requests the resolver to identify the most appropriate interface implementation.
       
    56 @param  aInterfaceUid
       
    57 		The interface for which an implementation is requested.
       
    58 @param  aAdditionalParameters
       
    59 	    The parameters which must match for an implementation to be suitable. 
       
    60 @return The unique id of the implementation which satisfies the specified parameters. 
       
    61  		KNullUid if not implementation is found.
       
    62 */ 
       
    63 TUid CCodecApiResolver::IdentifyImplementationL(TUid /*aInterfaceUid*/,
       
    64 	const TEComResolverParams& /*aAdditionalParameters*/) const
       
    65 	{
       
    66 	return KNullUid;
       
    67 	}
       
    68 
       
    69 
       
    70 /**
       
    71 Lists all the implementations which satisfy the specified interface definition and the 
       
    72 resolve parameters supplied.
       
    73 @param  aInterfaceUid
       
    74 		The interface for which an implementation is requested.
       
    75 @param  aAdditionalParameters	  	
       
    76 		The parameters which must match for an implementation to be suitable.
       
    77 @return Pointer to an array of suitable implementations. Ownership of this array is passed
       
    78 	    to the calling function. 
       
    79 */
       
    80 RImplInfoArray* CCodecApiResolver::ListAllL(TUid aInterfaceUid,
       
    81 	const TEComResolverParams& aAdditionalParameters) const
       
    82 	{
       
    83 	RImplInfoArray* retList = new (ELeave) RImplInfoArray;
       
    84 	// coverity[double_push]
       
    85 	CleanupStack::PushL(retList);
       
    86 	CleanupClosePushL(*retList);
       
    87 	
       
    88 	CCodecApiResolverData* customMatch = CCodecApiResolverData::NewLC(aAdditionalParameters.DataType());
       
    89 	
       
    90 	TCodecApiResolverMatchType matchType = customMatch->MatchType();
       
    91 	TUid implementationTypeUid 			 = customMatch->ImplementationType();
       
    92 	
       
    93 	// create a list with all 
       
    94 	RImplInfoArray& fullList = iRegistry.ListImplementationsL(aInterfaceUid);
       
    95 	const TInt count = fullList.Count();
       
    96 	
       
    97 	for(TInt index = 0; index < count; index++)
       
    98 		{
       
    99 		TBool matchFound = EFalse;
       
   100 		const CImplementationInformation& impData = *(fullList[index]);
       
   101 		CCodecApiOpaqueData* parse = NULL;
       
   102 		const TDesC8* opaqueData = &impData.OpaqueData();
       
   103 		// if opaque data is empty, move to the next element in the list
       
   104 		if (opaqueData->Length() == 0)
       
   105 			{
       
   106 			continue;
       
   107 			}
       
   108 		// create an instance of the class which holds the opaque data	
       
   109 		TInt error = KErrNotFound;
       
   110 		
       
   111 		if (implementationTypeUid == TUid::Uid(KUidAudioCodec)) 
       
   112 			{
       
   113 			TRAP(error, parse = CCodecApiOpaqueData::NewL(impData.OpaqueData()));	
       
   114 			}
       
   115 		else
       
   116 			{
       
   117 			if ((implementationTypeUid == TUid::Uid(KUidVideoEncoder)) 
       
   118 				|| implementationTypeUid == TUid::Uid(KUidVideoDecoder)) 
       
   119 				{
       
   120 				TRAP(error, parse = CCodecApiVideoOpaqueData::NewL(impData.OpaqueData()));
       
   121 				}	
       
   122 			else
       
   123 				{
       
   124 				error = KErrNotSupported;	
       
   125 				}
       
   126 			} 
       
   127 			
       
   128 		CleanupStack::PushL(parse);	
       
   129 		
       
   130 		if (error)
       
   131 			{
       
   132 			if ((error == KErrNotSupported) || (error == KErrCorrupt))
       
   133 				{
       
   134 				// means that the resource entry was not valid
       
   135 				// we ignore this plugin and try the next one
       
   136 				CleanupStack::PopAndDestroy(parse);
       
   137 				continue;
       
   138 				}
       
   139 			else
       
   140 				{
       
   141 				User::Leave(error);
       
   142 				}				
       
   143 			} //end of 	if (error!=KErrNone)
       
   144 			
       
   145 		// check if the uids are different. If they are, move to the next element
       
   146 		// in the list		
       
   147 		if (implementationTypeUid != parse->TypeUid())
       
   148 			{
       
   149 			CleanupStack::PopAndDestroy(parse);
       
   150 			continue;
       
   151 			}
       
   152 		switch(matchType)
       
   153 			{	
       
   154 			// check that the input data type is what we are looking for
       
   155 			case EMatchInputDataFormat:
       
   156 				if (parse->CompareInputDataType(customMatch->InputDataFormat()))
       
   157 					{
       
   158 					matchFound = ETrue;
       
   159 					}
       
   160 				break;
       
   161 			// check that the output data type is what we are looking for	
       
   162 			case EMatchOutputDataFormat:
       
   163 				if (parse->CompareOutputDataType(customMatch->OutputDataFormat()))
       
   164 					{
       
   165 					matchFound = ETrue;
       
   166 					}
       
   167 				break;
       
   168 			// check that the input and output data type is what we are looking for	
       
   169 			case EMatchInputAndOutputDataFormat:
       
   170 				if (parse->CompareInputDataType(customMatch->InputDataFormat()) 
       
   171 					&& parse->CompareOutputDataType(customMatch->OutputDataFormat()))
       
   172 					{
       
   173 					matchFound = ETrue;
       
   174 					}
       
   175 				break;
       
   176 			default:
       
   177 				{
       
   178 				//matchFound was initialised to EFalse, so fall through				
       
   179 				}				
       
   180 			}
       
   181 		// if a match was found, it will be appended to the list returned by this method
       
   182 		if (matchFound)
       
   183 			{
       
   184 			User::LeaveIfError(retList->Append(fullList[index]));	
       
   185 			}
       
   186 		CleanupStack::PopAndDestroy(parse);
       
   187 		} // end of for
       
   188 	
       
   189 	CleanupStack::PopAndDestroy(customMatch);
       
   190 	CleanupStack::Pop(2, retList);
       
   191 	return retList;	
       
   192 	}
       
   193 
       
   194