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: // Part of the MVS Agents for TechView sl@0: // sl@0: sl@0: #include "agentsutility.h" sl@0: #include sl@0: const TInt KMaxHeaderSize = 256; sl@0: sl@0: //CMVSControllerPluginInfo methods sl@0: sl@0: /** sl@0: Constructs and initialises a new instance of the controller plugin information class. sl@0: sl@0: The function leaves if the controller plugin information object cannot be created. sl@0: sl@0: No callback notification is made upon completion of NewL(). sl@0: sl@0: @return A pointer to the new controller plugin information object. sl@0: sl@0: */ sl@0: EXPORT_C CMVSControllerPluginInfo* CMVSControllerPluginInfo::NewL() sl@0: { sl@0: CMVSControllerPluginInfo* self = new(ELeave) CMVSControllerPluginInfo(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: sl@0: void CMVSControllerPluginInfo::ConstructL() sl@0: { sl@0: TInt err = KErrNone; sl@0: CMMFControllerPluginSelectionParameters* cSelect=NULL; sl@0: CMMFFormatSelectionParameters* fSelect=NULL; sl@0: User::LeaveIfError(iFileLogger.Connect()); sl@0: iFileLogger.CreateLog(_L("LogMVSappUi"),_L("LogFile.txt"),EFileLoggingModeAppend); sl@0: cSelect = CMMFControllerPluginSelectionParameters::NewLC(); sl@0: RArray mediaIds; //search for both audio and video sl@0: TRAP(err, mediaIds.Append(KUidMediaTypeAudio)); sl@0: TRAP(err, mediaIds.Append(KUidMediaTypeVideo)); sl@0: sl@0: TRAP(err, cSelect->SetMediaIdsL(mediaIds, sl@0: CMMFPluginSelectionParameters::EAllowOtherMediaIds)); sl@0: mediaIds.Close(); sl@0: sl@0: fSelect = CMMFFormatSelectionParameters::NewLC(); sl@0: sl@0: TRAP(err, { sl@0: cSelect->SetRequiredRecordFormatSupportL(*fSelect); sl@0: //Populate the controllers array sl@0: cSelect->ListImplementationsL(iControllers); sl@0: }); sl@0: CleanupStack::PopAndDestroy(2); sl@0: sl@0: for(TInt count = 0;count < iControllers.Count();count++) sl@0: { sl@0: iUidArray.AppendL(iControllers[count]->Uid()); sl@0: } sl@0: //During the construction get all the supported controllers,not for a specific extension. sl@0: CollectAudioControllersL(NULL); sl@0: CollectVideoControllersL(NULL); sl@0: } sl@0: sl@0: sl@0: void CMVSControllerPluginInfo::CollectAudioControllersL(TDesC* aExt) sl@0: { sl@0: TInt err = KErrNone; sl@0: CMMFControllerPluginSelectionParameters* cSelect=NULL; sl@0: CMMFFormatSelectionParameters* fSelect=NULL; sl@0: sl@0: cSelect = CMMFControllerPluginSelectionParameters::NewLC(); sl@0: RArray mediaIds; //search for audio only sl@0: TRAP(err, mediaIds.Append(KUidMediaTypeAudio)); sl@0: sl@0: TRAP(err, cSelect->SetMediaIdsL(mediaIds, sl@0: CMMFPluginSelectionParameters::EAllowOnlySuppliedMediaIds)); sl@0: sl@0: mediaIds.Close(); sl@0: sl@0: fSelect = CMMFFormatSelectionParameters::NewLC(); sl@0: if(aExt!=NULL) sl@0: { sl@0: fSelect->SetMatchToFileNameL(*aExt); sl@0: } sl@0: TRAP(err, { sl@0: cSelect->SetRequiredRecordFormatSupportL(*fSelect); sl@0: //Populate the controllers array sl@0: cSelect->ListImplementationsL(iAudioControllers); sl@0: }); sl@0: sl@0: CleanupStack::PopAndDestroy(2); sl@0: sl@0: for(TInt count = 0;count < iAudioControllers.Count();count++) sl@0: { sl@0: iAudioUidArray.AppendL(iAudioControllers[count]->Uid()); sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: void CMVSControllerPluginInfo::CollectAudioPlayControllersL(TDesC* aExt) sl@0: { sl@0: TInt err = KErrNone; sl@0: CMMFFormatSelectionParameters* sSelect=NULL; sl@0: CMMFControllerPluginSelectionParameters* pSelect=NULL; sl@0: sl@0: RArray mediaIds; //search for audio only sl@0: pSelect = CMMFControllerPluginSelectionParameters::NewLC(); sl@0: sl@0: TRAP(err, mediaIds.Append(KUidMediaTypeAudio)); sl@0: sl@0: TRAP(err, pSelect->SetMediaIdsL(mediaIds, sl@0: CMMFPluginSelectionParameters::EAllowOnlySuppliedMediaIds)); sl@0: sl@0: mediaIds.Close(); sl@0: sl@0: sSelect = CMMFFormatSelectionParameters::NewLC(); sl@0: if(aExt!=NULL) sl@0: { sl@0: sSelect->SetMatchToFileNameL(*aExt); sl@0: } sl@0: sl@0: TRAP(err,{ sl@0: pSelect->SetRequiredPlayFormatSupportL(*sSelect); sl@0: //populate the play controllers array sl@0: pSelect->ListImplementationsL(iAudioPlayControllers); sl@0: }); sl@0: CleanupStack::PopAndDestroy(2); sl@0: sl@0: for(TInt count = 0;count < iAudioPlayControllers.Count();count++) sl@0: { sl@0: iAudioPlayUidArray.AppendL(iAudioPlayControllers[count]->Uid()); sl@0: } sl@0: iFileLogger.Write(_L("CollectingAudioControllers ")); sl@0: } sl@0: sl@0: sl@0: void CMVSControllerPluginInfo::CollectVideoControllersL(TDesC* aExt) sl@0: { sl@0: TInt err = KErrNone; sl@0: CMMFControllerPluginSelectionParameters* cSelect=NULL; sl@0: CMMFFormatSelectionParameters* fSelect=NULL; sl@0: sl@0: cSelect = CMMFControllerPluginSelectionParameters::NewLC(); sl@0: RArray mediaIds; //search for audio only sl@0: TRAP(err, mediaIds.Append(KUidMediaTypeVideo)); sl@0: sl@0: TRAP(err, cSelect->SetMediaIdsL(mediaIds, sl@0: CMMFPluginSelectionParameters::EAllowOtherMediaIds)); sl@0: mediaIds.Close(); sl@0: sl@0: fSelect = CMMFFormatSelectionParameters::NewLC(); sl@0: if(aExt!=NULL) sl@0: { sl@0: fSelect->SetMatchToFileNameL(*aExt); sl@0: } sl@0: TRAP(err, { sl@0: cSelect->SetRequiredRecordFormatSupportL(*fSelect); sl@0: //Populate the controllers array sl@0: cSelect->ListImplementationsL(iVideoControllers); sl@0: }); sl@0: sl@0: CleanupStack::PopAndDestroy(2); sl@0: sl@0: for(TInt count = 0;count < iVideoControllers.Count();count++) sl@0: { sl@0: iVideoUidArray.AppendL(iVideoControllers[count]->Uid()); sl@0: } sl@0: iFileLogger.Write(_L("CollectingVideoControllers ")) ; sl@0: } sl@0: sl@0: /** sl@0: Destructor. sl@0: sl@0: Frees all resources owned by the object prior to its destruction. sl@0: */ sl@0: EXPORT_C CMVSControllerPluginInfo::~CMVSControllerPluginInfo() sl@0: { sl@0: iControllers.ResetAndDestroy(); sl@0: iControllers.Close(); sl@0: iSupportedControllers.ResetAndDestroy(); sl@0: iSupportedControllers.Close(); sl@0: iAudioControllers.ResetAndDestroy(); sl@0: iAudioControllers.Close(); sl@0: iAudioPlayControllers.ResetAndDestroy(); sl@0: iAudioPlayControllers.Close(); sl@0: iVideoControllers.ResetAndDestroy(); sl@0: iVideoControllers.Close(); sl@0: iUidArray.Close(); sl@0: iAudioUidArray.Close(); sl@0: iAudioPlayUidArray.Close(); sl@0: iVideoUidArray.Close(); sl@0: if(iFileLogger.Handle()) sl@0: { sl@0: iFileLogger.CloseLog(); sl@0: iFileLogger.Close(); sl@0: } sl@0: } sl@0: sl@0: sl@0: CMVSControllerPluginInfo::CMVSControllerPluginInfo() sl@0: { sl@0: } sl@0: sl@0: sl@0: /** sl@0: Fetches an array of all the display names of the sl@0: controller plugins existing currently in the system and an array of their Uid's sl@0: sl@0: The data must be in a supported format (for example, WAV ,OGG or AVI). sl@0: sl@0: @param aDisplayNames sl@0: This array will contain all the displaynames of the controllers when this method returns. sl@0: @param aUidArray sl@0: This array will contain all the Uids when this method returns. sl@0: sl@0: @return number of plugins existing in the system. sl@0: sl@0: */ sl@0: EXPORT_C TInt CMVSControllerPluginInfo::GetPluginListL(CDesCArrayFlat* aDisplayNames, RArray& aUidArray) sl@0: { sl@0: for(TInt counter = 0;counter < iControllers.Count();counter++) sl@0: { sl@0: aDisplayNames->AppendL(iControllers[counter]->DisplayName()); sl@0: aUidArray.Append(iUidArray[counter]); sl@0: } sl@0: iFileLogger.Write(_L("Getting the Plugin List")); sl@0: return aUidArray.Count(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Fetches an array of all the display names of the sl@0: audio controller plugins existing currently in the system and an array of their Uid's sl@0: sl@0: @param aDisplayNames sl@0: This array will contain all the displaynames of the audio controllers for the specified sl@0: extension, when this method returns. sl@0: @param aUidArray sl@0: This array will contain all the corresponding Uids when this method returns. sl@0: @param aExt sl@0: The specific extension (for example WAV or OGG) for which the supported controllers is to be retrieved sl@0: sl@0: @return number of audio plugins existing in the system. sl@0: sl@0: */ sl@0: EXPORT_C TInt CMVSControllerPluginInfo::GetAudioPluginListL(CDesCArrayFlat* aDisplayNames, RArray& aUidArray,RArray& aUidPlayArray, TDesC* aExt) sl@0: { sl@0: iAudioControllers.ResetAndDestroy(); sl@0: iAudioUidArray.Reset(); sl@0: iAudioPlayControllers.ResetAndDestroy(); sl@0: iAudioPlayUidArray.Reset(); sl@0: CollectAudioControllersL(aExt); sl@0: CollectAudioPlayControllersL(aExt); sl@0: for(TInt counter = 0;counter < iAudioControllers.Count();counter++) sl@0: { sl@0: aDisplayNames->AppendL(iAudioControllers[counter]->DisplayName()); sl@0: aUidArray.Append(iAudioUidArray[counter]); sl@0: } sl@0: for(TInt counter = 0;counter < iAudioPlayControllers.Count();counter++) sl@0: { sl@0: aUidPlayArray.Append(iAudioPlayUidArray[counter]); sl@0: } sl@0: iFileLogger.Write(_L("Getting the Audio Plugin List")); sl@0: //Flushing out the existing seleced data and filling in with sl@0: //all the audio controllers and corresponding UID's for the next run sl@0: iAudioControllers.ResetAndDestroy(); sl@0: iAudioUidArray.Reset(); sl@0: iAudioPlayControllers.ResetAndDestroy(); sl@0: iAudioPlayUidArray.Reset(); sl@0: iFileLogger.Write(_L("Getting the Video Plugin List")); sl@0: CollectAudioControllersL(NULL); sl@0: return aUidArray.Count(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Fetches an array of all the display names of the sl@0: video controller plugins existing currently in the system and an array of their Uid's sl@0: sl@0: @param aDisplayNames sl@0: This array will contain all the displaynames of the video controllers for the specified sl@0: extension, when this method returns. sl@0: @param aUidArray sl@0: This array will contain all the corresponding Uids when this method returns. sl@0: @param aExt sl@0: The specific extension (for example AVI) for which the supported controllers is to be retrieved. sl@0: sl@0: @return number of video plugins existing in the system. sl@0: sl@0: */ sl@0: EXPORT_C TInt CMVSControllerPluginInfo::GetVideoPluginListL(CDesCArrayFlat* aDisplayNames, RArray& aUidArray,TDesC* aExt) sl@0: { sl@0: iVideoControllers.ResetAndDestroy(); sl@0: iVideoUidArray.Reset(); sl@0: CollectVideoControllersL(aExt); sl@0: for(TInt counter = 0;counter < iVideoControllers.Count();counter++) sl@0: { sl@0: aDisplayNames->AppendL(iVideoControllers[counter]->DisplayName()); sl@0: aUidArray.Append(iVideoUidArray[counter]); sl@0: } sl@0: //Flushing out the existing seleced data and filling in with sl@0: //all the video controllers and corresponding UID's for the next run sl@0: iVideoControllers.ResetAndDestroy(); sl@0: iVideoUidArray.Reset(); sl@0: iFileLogger.Write(_L("Getting the Video Plugin List")); sl@0: CollectVideoControllersL(NULL); sl@0: return aUidArray.Count(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Extracts the list of all the extensions supported. sl@0: sl@0: All the supported extensions by the system are retrieved including both audio and video. sl@0: sl@0: @param aMediaType sl@0: Specifies the media type ie audio/video. sl@0: @param aExtArray sl@0: This array will contain all the supported extensions, when this method returns. sl@0: sl@0: @return number of supported extensions existing in the system. sl@0: sl@0: */ sl@0: EXPORT_C TInt CMVSControllerPluginInfo::GetExtensionListL(TBool aMediaType, CDesCArrayFlat* aExtArray) sl@0: { sl@0: CMMFFormatImplementationInformation* formatInfo; sl@0: if(aMediaType)//selected video sl@0: { sl@0: if(iVideoUidArray.Count()) sl@0: { sl@0: for(TInt counter = 0; counter < iVideoUidArray.Count(); counter++) sl@0: { sl@0: CMMFControllerImplementationInformation& plugin= *(iVideoControllers[counter]); sl@0: //Collect all supported 'Recording' formats sl@0: const RMMFFormatImplInfoArray& recFormatInfo = plugin.RecordFormats(); sl@0: for(TInt n = 0; n < recFormatInfo.Count(); n++) sl@0: { sl@0: formatInfo = recFormatInfo[n]; sl@0: const CDesC8Array& fileExtensions = formatInfo->SupportedFileExtensions(); sl@0: for(TInt innerCounter = 0;innerCounter < fileExtensions.Count();innerCounter++) sl@0: { sl@0: TBuf<16> buf; sl@0: buf.Zero(); sl@0: buf.Copy(fileExtensions[innerCounter]); sl@0: aExtArray->AppendL(buf); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: } sl@0: else sl@0: { sl@0: if(iAudioUidArray.Count()) sl@0: { sl@0: for(TInt counter = 0; counter < iAudioUidArray.Count(); counter++) sl@0: { sl@0: CMMFControllerImplementationInformation& plugin= *(iAudioControllers[counter]); sl@0: //Collect all supported 'Recording' formats sl@0: const RMMFFormatImplInfoArray& recFormatInfo = plugin.RecordFormats(); sl@0: for(TInt n = 0; n < recFormatInfo.Count(); n++) sl@0: { sl@0: formatInfo = recFormatInfo[n]; sl@0: const CDesC8Array& fileExtensions = formatInfo->SupportedFileExtensions(); sl@0: for(TInt innerCounter = 0;innerCounter < fileExtensions.Count();innerCounter++) sl@0: { sl@0: TBuf<16> buf; sl@0: buf.Zero(); sl@0: buf.Copy(fileExtensions[innerCounter]); sl@0: aExtArray->AppendL(buf); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: } sl@0: iFileLogger.Write(_L("Getting the Extension List")); sl@0: return(aExtArray->Count()); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Returns the type of the given media file. Returns NULL Uid if the sl@0: file is not supported by MMF. sl@0: sl@0: @param aFile sl@0: The name of the media file. sl@0: sl@0: @return Uid of the media. sl@0: */ sl@0: EXPORT_C TUid CMVSControllerPluginInfo::GetMediaTypeL(TDesC& aFile) sl@0: { sl@0: CMMFControllerPluginSelectionParameters* cSelect=NULL; sl@0: CMMFFormatSelectionParameters* fSelect=NULL; sl@0: TUid uid=TUid::Null(); sl@0: sl@0: iSupportedControllers.ResetAndDestroy(); sl@0: iSupportedControllers.Close(); sl@0: sl@0: cSelect = CMMFControllerPluginSelectionParameters::NewLC(); sl@0: sl@0: fSelect = CMMFFormatSelectionParameters::NewLC(); sl@0: fSelect->SetMatchToFileNameL(aFile); sl@0: sl@0: cSelect->SetRequiredPlayFormatSupportL(*fSelect); sl@0: //Populate the controllers array sl@0: cSelect->ListImplementationsL(iSupportedControllers); sl@0: sl@0: sl@0: if(iSupportedControllers.Count()) sl@0: { sl@0: //must be sufficient to check with one. not sure if MVS plays midi! sl@0: TBool video = iSupportedControllers[0]->SupportsMediaId(KUidMediaTypeVideo); sl@0: if(video) sl@0: { sl@0: uid=KUidMediaTypeVideo; sl@0: } sl@0: else sl@0: { sl@0: uid=KUidMediaTypeAudio; sl@0: } sl@0: CleanupStack::PopAndDestroy(2,cSelect);//fselect, cselect sl@0: } sl@0: else sl@0: { sl@0: //If we are here, file extension has not matched any controller sl@0: //Try to find controller based on header data sl@0: HBufC8* headerData = HBufC8::NewLC(KMaxHeaderSize); sl@0: TPtr8 headerDataPtr = headerData->Des(); sl@0: sl@0: GetHeaderL(aFile, headerDataPtr); sl@0: sl@0: fSelect->SetMatchToHeaderDataL(headerDataPtr); sl@0: cSelect->SetRequiredPlayFormatSupportL(*fSelect); sl@0: //Populate the controllers array sl@0: cSelect->ListImplementationsL(iSupportedControllers); sl@0: sl@0: if(iSupportedControllers.Count()) sl@0: { sl@0: TBool video = iSupportedControllers[0]->SupportsMediaId(KUidMediaTypeVideo); sl@0: if(video) sl@0: { sl@0: uid=KUidMediaTypeVideo; sl@0: } sl@0: else sl@0: { sl@0: uid=KUidMediaTypeAudio; sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(3,cSelect);//fselect, cselect,headerData sl@0: } sl@0: sl@0: return uid; sl@0: } sl@0: sl@0: sl@0: /** sl@0: Returns the controller implementation information associated with the given controller sl@0: sl@0: @param aControllerUid sl@0: The Uid of the controller plugin sl@0: sl@0: @return controller implementation structure sl@0: */ sl@0: EXPORT_C CMMFControllerImplementationInformation& CMVSControllerPluginInfo::GetControllerInfo(TUid aControllerUid) sl@0: { sl@0: TInt index = -1; sl@0: for(TInt counter = 0; counter < iUidArray.Count(); counter++) sl@0: { sl@0: TUid controllerUid = iUidArray[counter]; sl@0: if(controllerUid == aControllerUid) sl@0: { sl@0: index = counter; sl@0: } sl@0: } sl@0: iFileLogger.Write(_L("Getting the controller info")); sl@0: return *(iControllers[index]); sl@0: } sl@0: sl@0: void CMVSControllerPluginInfo::GetHeaderL(TDesC& aFileName, TDes8& aHeaderData) sl@0: { sl@0: RFile file; sl@0: RFs fs; sl@0: sl@0: User::LeaveIfError(fs.Connect()); sl@0: CleanupClosePushL(fs); sl@0: User::LeaveIfError(file.Open(fs, aFileName, EFileShareReadersOnly)); sl@0: CleanupClosePushL(file); sl@0: User::LeaveIfError(file.Read(aHeaderData,KMaxHeaderSize)); sl@0: sl@0: CleanupStack::PopAndDestroy(2,&fs); sl@0: } sl@0: