sl@0: // Copyright (c) 2003-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: // This is the body of the MMF recognizer utility class sl@0: // sl@0: // sl@0: sl@0: #include sl@0: sl@0: #include sl@0: #include "RecMmfUtilBody.h" sl@0: #include sl@0: sl@0: sl@0: // MMF Recognizer Utility class body constructor sl@0: CMmfRecognizerUtil::CBody::CBody(): sl@0: CActive(CActive::EPriorityStandard) sl@0: { sl@0: } sl@0: sl@0: CMmfRecognizerUtil::CBody::~CBody() sl@0: { sl@0: Cancel(); sl@0: iEcomSession.Close(); sl@0: iControllers.ResetAndDestroy(); sl@0: } sl@0: sl@0: // Request ECom to be notified when interface implementation registration sl@0: // data changes so that we can refresh the list of interface implementations. sl@0: void CMmfRecognizerUtil::CBody::StartNotification() sl@0: { sl@0: iEcomSession.NotifyOnChange(iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: // build a list of interface implementation objects sl@0: void CMmfRecognizerUtil::CBody::BuildControllerListL() sl@0: { sl@0: iControllers.ResetAndDestroy(); sl@0: CMMFControllerPluginSelectionParameters* cSelect = sl@0: CMMFControllerPluginSelectionParameters::NewLC(); sl@0: sl@0: CMMFFormatSelectionParameters* fSelect = sl@0: CMMFFormatSelectionParameters::NewLC(); sl@0: sl@0: cSelect->SetRequiredPlayFormatSupportL(*fSelect); sl@0: sl@0: // Set the media ids sl@0: RArray mediaIds; sl@0: CleanupClosePushL(mediaIds); sl@0: sl@0: User::LeaveIfError(mediaIds.Append(KUidMediaTypeAudio)); sl@0: User::LeaveIfError(mediaIds.Append(KUidMediaTypeVideo)); sl@0: cSelect->SetMediaIdsL(mediaIds, CMMFPluginSelectionParameters::EAllowOtherMediaIds); sl@0: sl@0: cSelect->ListImplementationsL(iControllers); sl@0: sl@0: // Clean up sl@0: CleanupStack::PopAndDestroy(3, cSelect);// mediaIds, fSelect, cSelect sl@0: } sl@0: sl@0: void CMmfRecognizerUtil::CBody::ConstructL() sl@0: { sl@0: BuildControllerListL(); sl@0: sl@0: CActiveScheduler::Add(this); sl@0: sl@0: iEcomSession = REComSession::OpenL(); sl@0: sl@0: // request notification from ECOM of any file system changes sl@0: StartNotification(); sl@0: } sl@0: sl@0: void CMmfRecognizerUtil::CBody::RunL() sl@0: { sl@0: BuildControllerListL(); sl@0: StartNotification(); sl@0: } sl@0: sl@0: void CMmfRecognizerUtil::CBody::DoCancel() sl@0: { sl@0: if (iStatus == KRequestPending) sl@0: iEcomSession.CancelNotifyOnChange(iStatus); sl@0: } sl@0: sl@0: /* Determine whether the supplied data header on its own is recognized, sl@0: or the data header plus the file suffix together are recognized, sl@0: and if so return the associated MIME type. sl@0: sl@0: @param aFileName sl@0: The name of the file sl@0: @param aImageData sl@0: A descriptor containing the header sl@0: @param aMimeType sl@0: A user-supplied descriptor in which the MIME type is returned sl@0: @leave KErrUnderflow sl@0: Not enough data in descriptor to identify whether it is supported sl@0: by any plugin. sl@0: @leave This method may also leave with one of the system-wide error codes. sl@0: @return EMatchNone if a match was not found. sl@0: EMatchData if a data match was found. sl@0: EMatchName if a data and file suffix match was found. sl@0: @post If recognized, the caller's descriptor is filled with the MIME types sl@0: */ sl@0: CMmfRecognizerUtil::TMatchLevel CMmfRecognizerUtil::CBody::GetMimeTypeL(const TDesC& aFileName, const TDesC8& aImageData, TDes8& aMimeType) sl@0: { sl@0: CMmfRecognizerUtil::TMatchLevel matchLevel = EMatchNone; sl@0: sl@0: //Get the suffix sl@0: TParse fileName; sl@0: sl@0: // aFileName's length could be greater than KMaxFileName sl@0: // so don't use TFileName here sl@0: TPtrC fName(aFileName); sl@0: if (aFileName.Match(_L("::*")) == 0) sl@0: { sl@0: fName.Set(aFileName.Mid(2)); sl@0: } sl@0: User::LeaveIfError(fileName.Set(fName, NULL, NULL)); sl@0: sl@0: HBufC8* fileSuffix = NULL; sl@0: if(fileName.ExtPresent()) sl@0: { sl@0: TPtrC suffixPtr(fileName.Ext()); sl@0: fileSuffix = HBufC8::NewLC(suffixPtr.Length()); sl@0: fileSuffix->Des().Copy(suffixPtr); sl@0: } sl@0: sl@0: // loop through every supported Format of every controller sl@0: // until we find one that matches the data header on its own, sl@0: // or the data header plus the file suffix together sl@0: for (TInt nController = 0, countControllers = iControllers.Count(); nController < countControllers; nController++) sl@0: { sl@0: CMMFControllerImplementationInformation* controllerImpInfo = iControllers[nController]; sl@0: sl@0: for (TInt nPlayFormat = 0, countFormats = controllerImpInfo->PlayFormats().Count(); nPlayFormat < countFormats; nPlayFormat++) sl@0: { sl@0: const CMMFFormatImplementationInformation* formatImpInfo = sl@0: controllerImpInfo->PlayFormats()[nPlayFormat]; sl@0: if (formatImpInfo->SupportsHeaderDataL(aImageData)) sl@0: { sl@0: const CDesC8Array& supportedMimeTypes = formatImpInfo->SupportedMimeTypes(); sl@0: if (supportedMimeTypes.Count() > 0) sl@0: { sl@0: CMmfRecognizerUtil::TMatchLevel previousMatchLevel = matchLevel; sl@0: if(fileSuffix && formatImpInfo->SupportsFileExtension(*fileSuffix)) sl@0: matchLevel = EMatchName; sl@0: else sl@0: matchLevel = EMatchData; sl@0: // Use first data match but update if suffix match is found sl@0: if(matchLevel!=previousMatchLevel) sl@0: aMimeType = supportedMimeTypes[0]; // just return the first mime type in the array sl@0: } sl@0: } sl@0: if(matchLevel==EMatchName || (!fileSuffix && matchLevel==EMatchData)) sl@0: break; sl@0: } sl@0: if(matchLevel==EMatchName || (!fileSuffix && matchLevel==EMatchData)) sl@0: break; sl@0: } sl@0: sl@0: if(fileSuffix) sl@0: CleanupStack::PopAndDestroy(fileSuffix); sl@0: sl@0: return matchLevel; sl@0: } sl@0: sl@0: // Static factory constructor. Uses two phase sl@0: // construction and leaves nothing on the cleanup stack sl@0: // @leave KErrNoMemory sl@0: // @return A pointer to the newly created CMmfRecognizerUtilBody object sl@0: CMmfRecognizerUtil::CBody* CMmfRecognizerUtil::CBody::NewL() sl@0: { sl@0: CBody* self=new (ELeave) CBody(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: // Get all the mime types supported by MMF sl@0: // @param aMimeTypes sl@0: // A caller-supplied array of descriptors. sl@0: // @leave This method may leave with one of the system-wide error codes. sl@0: // @post The caller's array is filled with the supported MIME types sl@0: void CMmfRecognizerUtil::CBody::GetMimeTypesL(CDesC8Array* aMimeTypes) sl@0: { sl@0: sl@0: CMMFControllerPluginSelectionParameters* cSelect = sl@0: CMMFControllerPluginSelectionParameters::NewLC(); sl@0: CMMFFormatSelectionParameters* fSelect = CMMFFormatSelectionParameters::NewLC(); sl@0: sl@0: // Set the play format selection parameters to be blank sl@0: // - format support Is only retrieved if requested. sl@0: cSelect->SetRequiredPlayFormatSupportL(*fSelect); sl@0: sl@0: // Set the media ids sl@0: RArray mediaIds; sl@0: CleanupClosePushL(mediaIds); sl@0: User::LeaveIfError(mediaIds.Append(KUidMediaTypeVideo)); sl@0: User::LeaveIfError(mediaIds.Append(KUidMediaTypeAudio)); sl@0: cSelect->SetMediaIdsL(mediaIds, CMMFPluginSelectionParameters::EAllowOtherMediaIds); sl@0: sl@0: // Array to hold all the controller plugins sl@0: RMMFControllerImplInfoArray controllers; sl@0: sl@0: CleanupResetAndDestroyPushL(controllers); sl@0: cSelect->ListImplementationsL(controllers); sl@0: sl@0: for (TInt nController = 0, controllerCount = controllers.Count(); nController < controllerCount; nController++) sl@0: { sl@0: for (TInt nPlayFormat = 0, formatCount = controllers[nController]->PlayFormats().Count(); nPlayFormat < formatCount; nPlayFormat++) sl@0: { sl@0: const CMMFFormatImplementationInformation* formatImpInfo = controllers[nController]->PlayFormats()[nPlayFormat]; sl@0: const CDesC8Array& supportedMimeTypes = formatImpInfo->SupportedMimeTypes(); sl@0: for (TInt nMimeType = 0, mimeTypeCount = supportedMimeTypes.Count(); nMimeType < mimeTypeCount; nMimeType++) sl@0: { sl@0: aMimeTypes->AppendL(supportedMimeTypes[nMimeType]); sl@0: } sl@0: } sl@0: } sl@0: sl@0: // Clean up sl@0: CleanupStack::PopAndDestroy(4, cSelect);//controllers, mediaIds, fSelect, cSelect sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: