os/mm/mmlibs/mmfw/src/ControllerFramework/RecMmfUtilBody.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 // This is the body of the MMF recognizer utility class
    15 // 
    16 //
    17 
    18 #include <badesca.h>
    19 
    20 #include <mmf/common/mmfcontrollerpluginresolver.h>
    21 #include "RecMmfUtilBody.h"
    22 #include <mmf/server/mmfdatasourcesink.hrh>
    23 
    24 
    25 // MMF Recognizer Utility class body constructor
    26 CMmfRecognizerUtil::CBody::CBody():
    27 	CActive(CActive::EPriorityStandard)
    28 	{
    29 	}
    30 
    31 CMmfRecognizerUtil::CBody::~CBody()
    32 	{
    33 	Cancel();
    34 	iEcomSession.Close();
    35 	iControllers.ResetAndDestroy();
    36 	}
    37 
    38 // Request ECom to be notified when interface implementation registration 
    39 // data changes so that we can refresh the list of interface implementations.
    40 void CMmfRecognizerUtil::CBody::StartNotification()
    41 	{
    42 	iEcomSession.NotifyOnChange(iStatus);
    43 	SetActive();
    44 	}
    45 
    46 // build a list of interface implementation objects
    47 void CMmfRecognizerUtil::CBody::BuildControllerListL()
    48 	{
    49 	iControllers.ResetAndDestroy();
    50 	CMMFControllerPluginSelectionParameters* cSelect = 
    51 		CMMFControllerPluginSelectionParameters::NewLC();
    52 	
    53 	CMMFFormatSelectionParameters* fSelect = 
    54 		CMMFFormatSelectionParameters::NewLC();
    55 
    56 	cSelect->SetRequiredPlayFormatSupportL(*fSelect);
    57 
    58 	// Set the media ids
    59 	RArray<TUid> mediaIds;
    60 	CleanupClosePushL(mediaIds);
    61 
    62 	User::LeaveIfError(mediaIds.Append(KUidMediaTypeAudio));
    63 	User::LeaveIfError(mediaIds.Append(KUidMediaTypeVideo));
    64 	cSelect->SetMediaIdsL(mediaIds, CMMFPluginSelectionParameters::EAllowOtherMediaIds);
    65 																	
    66 	cSelect->ListImplementationsL(iControllers);
    67 
    68 	// Clean up
    69 	CleanupStack::PopAndDestroy(3, cSelect);// mediaIds, fSelect, cSelect
    70 	}
    71 
    72 void CMmfRecognizerUtil::CBody::ConstructL()
    73 	{
    74 	BuildControllerListL();
    75 
    76 	CActiveScheduler::Add(this);
    77 
    78 	iEcomSession = REComSession::OpenL();
    79 
    80 	// request notification from ECOM of any file system changes
    81 	StartNotification();
    82 	}
    83 
    84 void CMmfRecognizerUtil::CBody::RunL()
    85 	{
    86 	BuildControllerListL();
    87 	StartNotification();
    88 	}
    89 
    90 void CMmfRecognizerUtil::CBody::DoCancel()
    91 	{
    92 	if (iStatus == KRequestPending)
    93 		iEcomSession.CancelNotifyOnChange(iStatus);
    94 	}
    95 
    96 /* 	Determine whether the supplied data header on its own is recognized,
    97 	or the data header plus the file suffix together are recognized,
    98 	and if so return the associated MIME type.
    99 	
   100 	@param	aFileName
   101 			The name of the file
   102 	@param	aImageData
   103 			A descriptor containing the header
   104 	@param	aMimeType
   105 			A user-supplied descriptor in which the MIME type is returned
   106 	@leave	KErrUnderflow 
   107 			Not enough data in descriptor to identify whether it is supported
   108 			by any plugin.
   109 	@leave	This method may also leave with one of the system-wide error codes.
   110 	@return	EMatchNone if a match was not found.
   111 			EMatchData if a data match was found.
   112 			EMatchName if a data and file suffix match was found.
   113 	@post	If recognized, the caller's descriptor is filled with the MIME types
   114 */
   115 CMmfRecognizerUtil::TMatchLevel CMmfRecognizerUtil::CBody::GetMimeTypeL(const TDesC& aFileName, const TDesC8& aImageData, TDes8& aMimeType)
   116 	{
   117 	CMmfRecognizerUtil::TMatchLevel matchLevel = EMatchNone;
   118 
   119 	//Get the suffix
   120 	TParse fileName;
   121 	
   122 	// aFileName's length could be greater than KMaxFileName
   123 	// so don't use TFileName here
   124 	TPtrC fName(aFileName);
   125 	if (aFileName.Match(_L("::*")) == 0)
   126  		{
   127 		fName.Set(aFileName.Mid(2));
   128  		}
   129 	User::LeaveIfError(fileName.Set(fName, NULL, NULL));
   130 
   131 	HBufC8* fileSuffix = NULL;
   132 	if(fileName.ExtPresent())
   133 		{
   134 		TPtrC suffixPtr(fileName.Ext());
   135 		fileSuffix = HBufC8::NewLC(suffixPtr.Length());
   136 		fileSuffix->Des().Copy(suffixPtr);
   137 		}
   138 
   139 	// loop through every supported Format of every controller 
   140 	// until we find one that matches the data header on its own,
   141 	// or the data header plus the file suffix together
   142 	for (TInt nController = 0, countControllers = iControllers.Count(); nController < countControllers; nController++)
   143 		{
   144 		CMMFControllerImplementationInformation* controllerImpInfo = iControllers[nController];
   145 
   146 		for (TInt nPlayFormat = 0, countFormats = controllerImpInfo->PlayFormats().Count(); nPlayFormat < countFormats; nPlayFormat++)
   147 			{
   148 			const CMMFFormatImplementationInformation* formatImpInfo = 
   149 				controllerImpInfo->PlayFormats()[nPlayFormat];
   150 			if (formatImpInfo->SupportsHeaderDataL(aImageData))
   151 				{
   152 				const CDesC8Array& supportedMimeTypes = formatImpInfo->SupportedMimeTypes();
   153 				if (supportedMimeTypes.Count() > 0)
   154 					{
   155 					CMmfRecognizerUtil::TMatchLevel previousMatchLevel = matchLevel;
   156 					if(fileSuffix && formatImpInfo->SupportsFileExtension(*fileSuffix))
   157 						matchLevel = EMatchName;
   158 					else
   159 						matchLevel = EMatchData;
   160 					// Use first data match but update if suffix match is found
   161 					if(matchLevel!=previousMatchLevel)
   162 						aMimeType = supportedMimeTypes[0]; // just return the first mime type in the array
   163 					}
   164 				}
   165 			if(matchLevel==EMatchName || (!fileSuffix && matchLevel==EMatchData))
   166 				break;
   167 			}
   168 		if(matchLevel==EMatchName || (!fileSuffix && matchLevel==EMatchData))
   169 			break;
   170 		}
   171 
   172 	if(fileSuffix)
   173 		CleanupStack::PopAndDestroy(fileSuffix);
   174 
   175 	return matchLevel;
   176 	}
   177 
   178 // Static factory constructor. Uses two phase
   179 // construction and leaves nothing on the cleanup stack
   180 // @leave KErrNoMemory
   181 // @return A pointer to the newly created CMmfRecognizerUtilBody object
   182 CMmfRecognizerUtil::CBody* CMmfRecognizerUtil::CBody::NewL()
   183 	{
   184 	CBody* self=new (ELeave) CBody();   
   185 	CleanupStack::PushL(self);
   186 	self->ConstructL();
   187 	CleanupStack::Pop(self);
   188 	return self;
   189 	}
   190 
   191 // Get all the mime types supported by MMF
   192 // @param	aMimeTypes
   193 //          A caller-supplied array of descriptors.
   194 // @leave	This method may leave with one of the system-wide error codes.
   195 // @post    The caller's array is filled with the supported MIME types
   196 void CMmfRecognizerUtil::CBody::GetMimeTypesL(CDesC8Array* aMimeTypes)
   197 	{
   198 
   199 	CMMFControllerPluginSelectionParameters* cSelect = 
   200 												CMMFControllerPluginSelectionParameters::NewLC();
   201 	CMMFFormatSelectionParameters* fSelect = CMMFFormatSelectionParameters::NewLC();
   202 
   203 	// Set the play format selection parameters to be blank  
   204 	//  - format support Is only retrieved if requested.
   205 	cSelect->SetRequiredPlayFormatSupportL(*fSelect);
   206 
   207 	// Set the media ids
   208 	RArray<TUid> mediaIds;
   209 	CleanupClosePushL(mediaIds);	
   210 	User::LeaveIfError(mediaIds.Append(KUidMediaTypeVideo));
   211 	User::LeaveIfError(mediaIds.Append(KUidMediaTypeAudio));
   212 	cSelect->SetMediaIdsL(mediaIds, CMMFPluginSelectionParameters::EAllowOtherMediaIds);
   213 																		   
   214 	// Array to hold all the controller plugins
   215 	RMMFControllerImplInfoArray controllers; 
   216 
   217 	CleanupResetAndDestroyPushL(controllers);
   218 	cSelect->ListImplementationsL(controllers);
   219 
   220 	for (TInt nController = 0, controllerCount = controllers.Count(); nController < controllerCount; nController++)
   221 		{
   222 		for (TInt nPlayFormat = 0, formatCount = controllers[nController]->PlayFormats().Count(); nPlayFormat < formatCount; nPlayFormat++)
   223 			{
   224 			const CMMFFormatImplementationInformation* formatImpInfo = controllers[nController]->PlayFormats()[nPlayFormat];
   225 			const CDesC8Array& supportedMimeTypes = formatImpInfo->SupportedMimeTypes();
   226 			for (TInt nMimeType = 0, mimeTypeCount = supportedMimeTypes.Count(); nMimeType < mimeTypeCount; nMimeType++)
   227 				{
   228 				aMimeTypes->AppendL(supportedMimeTypes[nMimeType]);
   229 				}
   230 			}
   231 		}
   232 					
   233 	// Clean up
   234 	CleanupStack::PopAndDestroy(4, cSelect);//controllers, mediaIds, fSelect, cSelect
   235 	}
   236 
   237 
   238 
   239 
   240