os/mm/mmlibs/mmfw/tsrc/mmvalidationsuite/mmvalidationsuiteagents/src/agentsutility.cpp
First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Part of the MVS Agents for TechView
17 #include "agentsutility.h"
19 const TInt KMaxHeaderSize = 256;
21 //CMVSControllerPluginInfo methods
24 Constructs and initialises a new instance of the controller plugin information class.
26 The function leaves if the controller plugin information object cannot be created.
28 No callback notification is made upon completion of NewL().
30 @return A pointer to the new controller plugin information object.
33 EXPORT_C CMVSControllerPluginInfo* CMVSControllerPluginInfo::NewL()
35 CMVSControllerPluginInfo* self = new(ELeave) CMVSControllerPluginInfo();
36 CleanupStack::PushL(self);
38 CleanupStack::Pop(self);
43 void CMVSControllerPluginInfo::ConstructL()
46 CMMFControllerPluginSelectionParameters* cSelect=NULL;
47 CMMFFormatSelectionParameters* fSelect=NULL;
48 User::LeaveIfError(iFileLogger.Connect());
49 iFileLogger.CreateLog(_L("LogMVSappUi"),_L("LogFile.txt"),EFileLoggingModeAppend);
50 cSelect = CMMFControllerPluginSelectionParameters::NewLC();
51 RArray<TUid> mediaIds; //search for both audio and video
52 TRAP(err, mediaIds.Append(KUidMediaTypeAudio));
53 TRAP(err, mediaIds.Append(KUidMediaTypeVideo));
55 TRAP(err, cSelect->SetMediaIdsL(mediaIds,
56 CMMFPluginSelectionParameters::EAllowOtherMediaIds));
59 fSelect = CMMFFormatSelectionParameters::NewLC();
62 cSelect->SetRequiredRecordFormatSupportL(*fSelect);
63 //Populate the controllers array
64 cSelect->ListImplementationsL(iControllers);
66 CleanupStack::PopAndDestroy(2);
68 for(TInt count = 0;count < iControllers.Count();count++)
70 iUidArray.AppendL(iControllers[count]->Uid());
72 //During the construction get all the supported controllers,not for a specific extension.
73 CollectAudioControllersL(NULL);
74 CollectVideoControllersL(NULL);
78 void CMVSControllerPluginInfo::CollectAudioControllersL(TDesC* aExt)
81 CMMFControllerPluginSelectionParameters* cSelect=NULL;
82 CMMFFormatSelectionParameters* fSelect=NULL;
84 cSelect = CMMFControllerPluginSelectionParameters::NewLC();
85 RArray<TUid> mediaIds; //search for audio only
86 TRAP(err, mediaIds.Append(KUidMediaTypeAudio));
88 TRAP(err, cSelect->SetMediaIdsL(mediaIds,
89 CMMFPluginSelectionParameters::EAllowOnlySuppliedMediaIds));
93 fSelect = CMMFFormatSelectionParameters::NewLC();
96 fSelect->SetMatchToFileNameL(*aExt);
99 cSelect->SetRequiredRecordFormatSupportL(*fSelect);
100 //Populate the controllers array
101 cSelect->ListImplementationsL(iAudioControllers);
104 CleanupStack::PopAndDestroy(2);
106 for(TInt count = 0;count < iAudioControllers.Count();count++)
108 iAudioUidArray.AppendL(iAudioControllers[count]->Uid());
114 void CMVSControllerPluginInfo::CollectAudioPlayControllersL(TDesC* aExt)
117 CMMFFormatSelectionParameters* sSelect=NULL;
118 CMMFControllerPluginSelectionParameters* pSelect=NULL;
120 RArray<TUid> mediaIds; //search for audio only
121 pSelect = CMMFControllerPluginSelectionParameters::NewLC();
123 TRAP(err, mediaIds.Append(KUidMediaTypeAudio));
125 TRAP(err, pSelect->SetMediaIdsL(mediaIds,
126 CMMFPluginSelectionParameters::EAllowOnlySuppliedMediaIds));
130 sSelect = CMMFFormatSelectionParameters::NewLC();
133 sSelect->SetMatchToFileNameL(*aExt);
137 pSelect->SetRequiredPlayFormatSupportL(*sSelect);
138 //populate the play controllers array
139 pSelect->ListImplementationsL(iAudioPlayControllers);
141 CleanupStack::PopAndDestroy(2);
143 for(TInt count = 0;count < iAudioPlayControllers.Count();count++)
145 iAudioPlayUidArray.AppendL(iAudioPlayControllers[count]->Uid());
147 iFileLogger.Write(_L("CollectingAudioControllers "));
151 void CMVSControllerPluginInfo::CollectVideoControllersL(TDesC* aExt)
154 CMMFControllerPluginSelectionParameters* cSelect=NULL;
155 CMMFFormatSelectionParameters* fSelect=NULL;
157 cSelect = CMMFControllerPluginSelectionParameters::NewLC();
158 RArray<TUid> mediaIds; //search for audio only
159 TRAP(err, mediaIds.Append(KUidMediaTypeVideo));
161 TRAP(err, cSelect->SetMediaIdsL(mediaIds,
162 CMMFPluginSelectionParameters::EAllowOtherMediaIds));
165 fSelect = CMMFFormatSelectionParameters::NewLC();
168 fSelect->SetMatchToFileNameL(*aExt);
171 cSelect->SetRequiredRecordFormatSupportL(*fSelect);
172 //Populate the controllers array
173 cSelect->ListImplementationsL(iVideoControllers);
176 CleanupStack::PopAndDestroy(2);
178 for(TInt count = 0;count < iVideoControllers.Count();count++)
180 iVideoUidArray.AppendL(iVideoControllers[count]->Uid());
182 iFileLogger.Write(_L("CollectingVideoControllers ")) ;
188 Frees all resources owned by the object prior to its destruction.
190 EXPORT_C CMVSControllerPluginInfo::~CMVSControllerPluginInfo()
192 iControllers.ResetAndDestroy();
193 iControllers.Close();
194 iSupportedControllers.ResetAndDestroy();
195 iSupportedControllers.Close();
196 iAudioControllers.ResetAndDestroy();
197 iAudioControllers.Close();
198 iAudioPlayControllers.ResetAndDestroy();
199 iAudioPlayControllers.Close();
200 iVideoControllers.ResetAndDestroy();
201 iVideoControllers.Close();
203 iAudioUidArray.Close();
204 iAudioPlayUidArray.Close();
205 iVideoUidArray.Close();
206 if(iFileLogger.Handle())
208 iFileLogger.CloseLog();
214 CMVSControllerPluginInfo::CMVSControllerPluginInfo()
220 Fetches an array of all the display names of the
221 controller plugins existing currently in the system and an array of their Uid's
223 The data must be in a supported format (for example, WAV ,OGG or AVI).
226 This array will contain all the displaynames of the controllers when this method returns.
228 This array will contain all the Uids when this method returns.
230 @return number of plugins existing in the system.
233 EXPORT_C TInt CMVSControllerPluginInfo::GetPluginListL(CDesCArrayFlat* aDisplayNames, RArray<TUid>& aUidArray)
235 for(TInt counter = 0;counter < iControllers.Count();counter++)
237 aDisplayNames->AppendL(iControllers[counter]->DisplayName());
238 aUidArray.Append(iUidArray[counter]);
240 iFileLogger.Write(_L("Getting the Plugin List"));
241 return aUidArray.Count();
246 Fetches an array of all the display names of the
247 audio controller plugins existing currently in the system and an array of their Uid's
250 This array will contain all the displaynames of the audio controllers for the specified
251 extension, when this method returns.
253 This array will contain all the corresponding Uids when this method returns.
255 The specific extension (for example WAV or OGG) for which the supported controllers is to be retrieved
257 @return number of audio plugins existing in the system.
260 EXPORT_C TInt CMVSControllerPluginInfo::GetAudioPluginListL(CDesCArrayFlat* aDisplayNames, RArray<TUid>& aUidArray,RArray<TUid>& aUidPlayArray, TDesC* aExt)
262 iAudioControllers.ResetAndDestroy();
263 iAudioUidArray.Reset();
264 iAudioPlayControllers.ResetAndDestroy();
265 iAudioPlayUidArray.Reset();
266 CollectAudioControllersL(aExt);
267 CollectAudioPlayControllersL(aExt);
268 for(TInt counter = 0;counter < iAudioControllers.Count();counter++)
270 aDisplayNames->AppendL(iAudioControllers[counter]->DisplayName());
271 aUidArray.Append(iAudioUidArray[counter]);
273 for(TInt counter = 0;counter < iAudioPlayControllers.Count();counter++)
275 aUidPlayArray.Append(iAudioPlayUidArray[counter]);
277 iFileLogger.Write(_L("Getting the Audio Plugin List"));
278 //Flushing out the existing seleced data and filling in with
279 //all the audio controllers and corresponding UID's for the next run
280 iAudioControllers.ResetAndDestroy();
281 iAudioUidArray.Reset();
282 iAudioPlayControllers.ResetAndDestroy();
283 iAudioPlayUidArray.Reset();
284 iFileLogger.Write(_L("Getting the Video Plugin List"));
285 CollectAudioControllersL(NULL);
286 return aUidArray.Count();
291 Fetches an array of all the display names of the
292 video controller plugins existing currently in the system and an array of their Uid's
295 This array will contain all the displaynames of the video controllers for the specified
296 extension, when this method returns.
298 This array will contain all the corresponding Uids when this method returns.
300 The specific extension (for example AVI) for which the supported controllers is to be retrieved.
302 @return number of video plugins existing in the system.
305 EXPORT_C TInt CMVSControllerPluginInfo::GetVideoPluginListL(CDesCArrayFlat* aDisplayNames, RArray<TUid>& aUidArray,TDesC* aExt)
307 iVideoControllers.ResetAndDestroy();
308 iVideoUidArray.Reset();
309 CollectVideoControllersL(aExt);
310 for(TInt counter = 0;counter < iVideoControllers.Count();counter++)
312 aDisplayNames->AppendL(iVideoControllers[counter]->DisplayName());
313 aUidArray.Append(iVideoUidArray[counter]);
315 //Flushing out the existing seleced data and filling in with
316 //all the video controllers and corresponding UID's for the next run
317 iVideoControllers.ResetAndDestroy();
318 iVideoUidArray.Reset();
319 iFileLogger.Write(_L("Getting the Video Plugin List"));
320 CollectVideoControllersL(NULL);
321 return aUidArray.Count();
326 Extracts the list of all the extensions supported.
328 All the supported extensions by the system are retrieved including both audio and video.
331 Specifies the media type ie audio/video.
333 This array will contain all the supported extensions, when this method returns.
335 @return number of supported extensions existing in the system.
338 EXPORT_C TInt CMVSControllerPluginInfo::GetExtensionListL(TBool aMediaType, CDesCArrayFlat* aExtArray)
340 CMMFFormatImplementationInformation* formatInfo;
341 if(aMediaType)//selected video
343 if(iVideoUidArray.Count())
345 for(TInt counter = 0; counter < iVideoUidArray.Count(); counter++)
347 CMMFControllerImplementationInformation& plugin= *(iVideoControllers[counter]);
348 //Collect all supported 'Recording' formats
349 const RMMFFormatImplInfoArray& recFormatInfo = plugin.RecordFormats();
350 for(TInt n = 0; n < recFormatInfo.Count(); n++)
352 formatInfo = recFormatInfo[n];
353 const CDesC8Array& fileExtensions = formatInfo->SupportedFileExtensions();
354 for(TInt innerCounter = 0;innerCounter < fileExtensions.Count();innerCounter++)
358 buf.Copy(fileExtensions[innerCounter]);
359 aExtArray->AppendL(buf);
367 if(iAudioUidArray.Count())
369 for(TInt counter = 0; counter < iAudioUidArray.Count(); counter++)
371 CMMFControllerImplementationInformation& plugin= *(iAudioControllers[counter]);
372 //Collect all supported 'Recording' formats
373 const RMMFFormatImplInfoArray& recFormatInfo = plugin.RecordFormats();
374 for(TInt n = 0; n < recFormatInfo.Count(); n++)
376 formatInfo = recFormatInfo[n];
377 const CDesC8Array& fileExtensions = formatInfo->SupportedFileExtensions();
378 for(TInt innerCounter = 0;innerCounter < fileExtensions.Count();innerCounter++)
382 buf.Copy(fileExtensions[innerCounter]);
383 aExtArray->AppendL(buf);
389 iFileLogger.Write(_L("Getting the Extension List"));
390 return(aExtArray->Count());
395 Returns the type of the given media file. Returns NULL Uid if the
396 file is not supported by MMF.
399 The name of the media file.
401 @return Uid of the media.
403 EXPORT_C TUid CMVSControllerPluginInfo::GetMediaTypeL(TDesC& aFile)
405 CMMFControllerPluginSelectionParameters* cSelect=NULL;
406 CMMFFormatSelectionParameters* fSelect=NULL;
407 TUid uid=TUid::Null();
409 iSupportedControllers.ResetAndDestroy();
410 iSupportedControllers.Close();
412 cSelect = CMMFControllerPluginSelectionParameters::NewLC();
414 fSelect = CMMFFormatSelectionParameters::NewLC();
415 fSelect->SetMatchToFileNameL(aFile);
417 cSelect->SetRequiredPlayFormatSupportL(*fSelect);
418 //Populate the controllers array
419 cSelect->ListImplementationsL(iSupportedControllers);
422 if(iSupportedControllers.Count())
424 //must be sufficient to check with one. not sure if MVS plays midi!
425 TBool video = iSupportedControllers[0]->SupportsMediaId(KUidMediaTypeVideo);
428 uid=KUidMediaTypeVideo;
432 uid=KUidMediaTypeAudio;
434 CleanupStack::PopAndDestroy(2,cSelect);//fselect, cselect
438 //If we are here, file extension has not matched any controller
439 //Try to find controller based on header data
440 HBufC8* headerData = HBufC8::NewLC(KMaxHeaderSize);
441 TPtr8 headerDataPtr = headerData->Des();
443 GetHeaderL(aFile, headerDataPtr);
445 fSelect->SetMatchToHeaderDataL(headerDataPtr);
446 cSelect->SetRequiredPlayFormatSupportL(*fSelect);
447 //Populate the controllers array
448 cSelect->ListImplementationsL(iSupportedControllers);
450 if(iSupportedControllers.Count())
452 TBool video = iSupportedControllers[0]->SupportsMediaId(KUidMediaTypeVideo);
455 uid=KUidMediaTypeVideo;
459 uid=KUidMediaTypeAudio;
462 CleanupStack::PopAndDestroy(3,cSelect);//fselect, cselect,headerData
470 Returns the controller implementation information associated with the given controller
472 @param aControllerUid
473 The Uid of the controller plugin
475 @return controller implementation structure
477 EXPORT_C CMMFControllerImplementationInformation& CMVSControllerPluginInfo::GetControllerInfo(TUid aControllerUid)
480 for(TInt counter = 0; counter < iUidArray.Count(); counter++)
482 TUid controllerUid = iUidArray[counter];
483 if(controllerUid == aControllerUid)
488 iFileLogger.Write(_L("Getting the controller info"));
489 return *(iControllers[index]);
492 void CMVSControllerPluginInfo::GetHeaderL(TDesC& aFileName, TDes8& aHeaderData)
497 User::LeaveIfError(fs.Connect());
498 CleanupClosePushL(fs);
499 User::LeaveIfError(file.Open(fs, aFileName, EFileShareReadersOnly));
500 CleanupClosePushL(file);
501 User::LeaveIfError(file.Read(aHeaderData,KMaxHeaderSize));
503 CleanupStack::PopAndDestroy(2,&fs);