mmhais/videohai/devvideo/src/DevVideo/devvideointernal.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 // Copyright (c) 2003-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 "devvideointernal.h"
       
    17 #ifdef SYMBIAN_MULTIMEDIA_CODEC_API
       
    18 #include <mdf/codecapiresolverdata.h>
       
    19 #include <mdf/codecapiuids.hrh>
       
    20 #include <mdf/codecapiresolver.hrh>
       
    21 #include <mm/mmpluginutils.h>
       
    22 
       
    23 #include "videoplayhwdevice.h"
       
    24 
       
    25 void DevVideoUtilities::FindVideoDecoderPluginsL(const TDesC8& aMimeType, RImplInfoPtrArray& aImplInfoArray)
       
    26 	{
       
    27 	CCodecApiResolverData* customMatchData = CCodecApiResolverData::NewLC();
       
    28 	customMatchData->SetMatchType(EMatchInputDataFormat);
       
    29 	customMatchData->SetImplementationType(TUid::Uid(KUidVideoDecoder));
       
    30 	// string value of the input source data	
       
    31 	customMatchData->SetInputDataL(aMimeType);
       
    32 	
       
    33   	HBufC8* package  = customMatchData->NewPackLC(); // parameters to match sent as "default data"
       
    34 	MmPluginUtils::FindImplementationsL(TUid::Uid(KUidMdfProcessingUnit), aImplInfoArray, *package, TUid::Uid(KUidCodecApiResolverImplementation));
       
    35 	CleanupStack::PopAndDestroy(2, customMatchData); // package, customMatchData
       
    36 	}
       
    37 
       
    38 
       
    39 void DevVideoUtilities::FindVideoEncoderPluginsL(const TDesC8& aMimeType, RImplInfoPtrArray& aImplInfoArray)
       
    40 	{
       
    41 	CCodecApiResolverData* customMatchData = CCodecApiResolverData::NewLC();
       
    42 	customMatchData->SetMatchType(EMatchOutputDataFormat);
       
    43 	customMatchData->SetImplementationType(TUid::Uid(KUidVideoEncoder));
       
    44 	// string value of the input source data	
       
    45 	customMatchData->SetOutputDataL(aMimeType);
       
    46 	
       
    47  	HBufC8* package  = customMatchData->NewPackLC(); // parameters to match sent as "default data"	
       
    48 	MmPluginUtils::FindImplementationsL(TUid::Uid(KUidMdfProcessingUnit), aImplInfoArray, *package, TUid::Uid(KUidCodecApiResolverImplementation));
       
    49 	CleanupStack::PopAndDestroy(2, customMatchData); // package, customMatchData
       
    50 	}
       
    51 
       
    52 void DevVideoUtilities::CreatePuListL(RImplInfoPtrArray& aImplInfoArray)
       
    53 	{
       
    54 	// we can use REComSession::ListImplementationsL() straight, and skip the sort step of MmPluginUtils
       
    55 	// as this list is used purely to feedback into FindPu below, and see if the plugin is a PU and not a HwDevice
       
    56 	aImplInfoArray.Reset();
       
    57 	REComSession::ListImplementationsL(TUid::Uid(KUidMdfProcessingUnit), aImplInfoArray);
       
    58 	}
       
    59 	
       
    60 	
       
    61 const CImplementationInformation* DevVideoUtilities::FindPu(const RImplInfoPtrArray& aImplInfoArray, TUid aPuUid)
       
    62 	{
       
    63 	CImplementationInformation* info = NULL;
       
    64 	for (TInt i=0;i<aImplInfoArray.Count() && info == NULL;i++)
       
    65 		{
       
    66 		if (aImplInfoArray[i]->ImplementationUid() == aPuUid)
       
    67 			{
       
    68 			info = aImplInfoArray[i];
       
    69 			}
       
    70 		}
       
    71 	return info;
       
    72 	}
       
    73 
       
    74 #endif // SYMBIAN_MULTIMEDIA_CODEC_API
       
    75 
       
    76 TInt DevVideoUtilities::ConvertTextToTUint32(const TDesC8& aData, TUint32& aNumber)
       
    77 	{
       
    78 	// Work out whether aData is in hex or not by looking for an 0x at the beginning
       
    79 	TInt error = KErrNone;
       
    80 
       
    81 	_LIT8(K0x, "0x");
       
    82 	if (aData.FindF(K0x) == 0)
       
    83 		{
       
    84 		// Data is in hex
       
    85 		// Discard the '0x'
       
    86 		TLex8 lex(aData.Right(aData.Length() - K0x().Length()));
       
    87 		error = lex.Val(aNumber, EHex);
       
    88 		}
       
    89 	else
       
    90 		{
       
    91 		// Assume aData is in decimal
       
    92 		TLex8 lex(aData);
       
    93 		error = lex.Val(aNumber, EDecimal);
       
    94 		}
       
    95 
       
    96 	return error;
       
    97 	}
       
    98 
       
    99 void DevVideoUtilities::MatchPrePostProcessorCapabilitiesL(const RImplInfoPtrArray& aPlugins, TUint32 aReqPrePostProcType, RArray<TUid>& aMatchingPlugins)
       
   100 	{
       
   101 	aMatchingPlugins.Reset();
       
   102 
       
   103 	TInt count = aPlugins.Count();
       
   104 	for (TInt i=0; i<count; i++)
       
   105 		{
       
   106 		const CImplementationInformation* plugin = aPlugins[i];
       
   107 		TUint32 pluginPostProcType = 0;
       
   108 		TInt error = ConvertTextToTUint32(plugin->OpaqueData(), pluginPostProcType);
       
   109 		if (error == KErrNone)
       
   110 			{
       
   111 			// Check the plugin has at least the pre/post processing capabilities demanded by the client
       
   112 			if ((pluginPostProcType & aReqPrePostProcType) == aReqPrePostProcType)
       
   113 				{
       
   114 				User::LeaveIfError(aMatchingPlugins.Append(plugin->ImplementationUid()));
       
   115 				}
       
   116 			}
       
   117 		else if (error == KErrCorrupt)
       
   118 			{
       
   119 			// In debug mode leave, in release mode just swallow the error since we
       
   120 			// don't want to allow broken plugins to prevent other plugins being recognised.
       
   121 #ifdef _DEBUG
       
   122 			User::Leave(error);
       
   123 #endif //_DEBUG
       
   124 			}
       
   125 		else
       
   126 			{
       
   127 			User::Leave(error);
       
   128 			}
       
   129 		}
       
   130 	}
       
   131 
       
   132 void DevVideoUtilities::SelectPluginBasedOnMatchType(const TDesC8& aMatchType, RImplInfoPtrArray& aImplInfoArray)
       
   133 	{
       
   134 	// In this function if allowing wildcards then TDesC8::Match is used which returns 
       
   135 	// the position of the match or KErrNotFound
       
   136 	// If not allowing wildcards then TDesC8::Compare is used which returns a TInt which
       
   137 	// indicates if one descriptor is bigger than the other (0 if they are identical)
       
   138 	TBool matchResult = ETrue;
       
   139 	
       
   140 	if(aMatchType.Length() == 0)
       
   141 		{
       
   142 		return;
       
   143 		}
       
   144 	else
       
   145 		{
       
   146 		TInt count = aImplInfoArray.Count();
       
   147 
       
   148 		_LIT8(KdataSeparator, "||");
       
   149 		const TInt separatorLength = KdataSeparator().Length();
       
   150 
       
   151 		for (TInt index = 0; index < count;)
       
   152 			{
       
   153 			CImplementationInformation* plugin = aImplInfoArray[index];
       
   154 			const TDesC8& mimeType = plugin->DataType();
       
   155 		
       
   156 			// Look for the section separator marker '||'
       
   157 			TInt separatorPos = mimeType.Find(KdataSeparator);
       
   158 
       
   159 			if(separatorPos == KErrNotFound)
       
   160 				{
       
   161 					matchResult = aMatchType.MatchF(mimeType) != KErrNotFound;
       
   162 				}
       
   163 			else
       
   164 				{
       
   165 				// Find the first section, up to the separator
       
   166 				TPtrC8 dataSection = mimeType.Left(separatorPos);
       
   167 				TPtrC8 remainingData = mimeType.Mid(separatorPos + separatorLength);
       
   168 
       
   169 				// Match against each section in turn
       
   170 				while(separatorPos != KErrNotFound)
       
   171 					{
       
   172 					matchResult = aMatchType.MatchF(dataSection) != KErrNotFound;
       
   173 
       
   174 					// If we found it then no need to continue, so return
       
   175 					if(matchResult)
       
   176 						break;
       
   177 
       
   178 					// Move on to the next section
       
   179 					separatorPos = remainingData.Find(KdataSeparator);
       
   180 					if(separatorPos != KErrNotFound)
       
   181 						{
       
   182 						dataSection.Set(remainingData.Left(separatorPos));
       
   183 						remainingData.Set(remainingData.Mid(separatorPos + separatorLength));
       
   184 						}
       
   185 					else
       
   186 						{
       
   187 						dataSection.Set(remainingData);
       
   188 						}
       
   189 					} // end of while
       
   190 
       
   191 					// Check the final part
       
   192 					matchResult = aMatchType.MatchF(dataSection) != KErrNotFound;
       
   193 					
       
   194 				} //end of else
       
   195 
       
   196 				// if a match was found increment the array,
       
   197 				// otherwise remove the element from the array
       
   198 				if (matchResult)
       
   199 					{
       
   200 					index++;
       
   201 					}
       
   202 				else
       
   203 					{
       
   204 					delete aImplInfoArray[index];
       
   205 					aImplInfoArray.Remove(index);
       
   206 	    			count--;
       
   207 					}
       
   208 				
       
   209 			} //end of for
       
   210 		}
       
   211 	}
       
   212 
       
   213