os/mm/mmlibs/mmfw/tsrc/mmvalidationsuite/mmvalidationsuiteagents/src/agentsutility.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmlibs/mmfw/tsrc/mmvalidationsuite/mmvalidationsuiteagents/src/agentsutility.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,505 @@
1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Part of the MVS Agents for TechView
1.18 +//
1.19 +
1.20 +#include "agentsutility.h"
1.21 +#include <e32def.h>
1.22 +const TInt KMaxHeaderSize = 256;
1.23 +
1.24 +//CMVSControllerPluginInfo methods
1.25 +
1.26 +/**
1.27 +Constructs and initialises a new instance of the controller plugin information class.
1.28 +
1.29 +The function leaves if the controller plugin information object cannot be created.
1.30 +
1.31 +No callback notification is made upon completion of NewL().
1.32 +
1.33 +@return A pointer to the new controller plugin information object.
1.34 +
1.35 +*/
1.36 +EXPORT_C CMVSControllerPluginInfo* CMVSControllerPluginInfo::NewL()
1.37 + {
1.38 + CMVSControllerPluginInfo* self = new(ELeave) CMVSControllerPluginInfo();
1.39 + CleanupStack::PushL(self);
1.40 + self->ConstructL();
1.41 + CleanupStack::Pop(self);
1.42 + return self;
1.43 + }
1.44 +
1.45 +
1.46 +void CMVSControllerPluginInfo::ConstructL()
1.47 + {
1.48 + TInt err = KErrNone;
1.49 + CMMFControllerPluginSelectionParameters* cSelect=NULL;
1.50 + CMMFFormatSelectionParameters* fSelect=NULL;
1.51 + User::LeaveIfError(iFileLogger.Connect());
1.52 + iFileLogger.CreateLog(_L("LogMVSappUi"),_L("LogFile.txt"),EFileLoggingModeAppend);
1.53 + cSelect = CMMFControllerPluginSelectionParameters::NewLC();
1.54 + RArray<TUid> mediaIds; //search for both audio and video
1.55 + TRAP(err, mediaIds.Append(KUidMediaTypeAudio));
1.56 + TRAP(err, mediaIds.Append(KUidMediaTypeVideo));
1.57 +
1.58 + TRAP(err, cSelect->SetMediaIdsL(mediaIds,
1.59 + CMMFPluginSelectionParameters::EAllowOtherMediaIds));
1.60 + mediaIds.Close();
1.61 +
1.62 + fSelect = CMMFFormatSelectionParameters::NewLC();
1.63 +
1.64 + TRAP(err, {
1.65 + cSelect->SetRequiredRecordFormatSupportL(*fSelect);
1.66 + //Populate the controllers array
1.67 + cSelect->ListImplementationsL(iControllers);
1.68 + });
1.69 + CleanupStack::PopAndDestroy(2);
1.70 +
1.71 + for(TInt count = 0;count < iControllers.Count();count++)
1.72 + {
1.73 + iUidArray.AppendL(iControllers[count]->Uid());
1.74 + }
1.75 + //During the construction get all the supported controllers,not for a specific extension.
1.76 + CollectAudioControllersL(NULL);
1.77 + CollectVideoControllersL(NULL);
1.78 + }
1.79 +
1.80 +
1.81 +void CMVSControllerPluginInfo::CollectAudioControllersL(TDesC* aExt)
1.82 + {
1.83 + TInt err = KErrNone;
1.84 + CMMFControllerPluginSelectionParameters* cSelect=NULL;
1.85 + CMMFFormatSelectionParameters* fSelect=NULL;
1.86 +
1.87 + cSelect = CMMFControllerPluginSelectionParameters::NewLC();
1.88 + RArray<TUid> mediaIds; //search for audio only
1.89 + TRAP(err, mediaIds.Append(KUidMediaTypeAudio));
1.90 +
1.91 + TRAP(err, cSelect->SetMediaIdsL(mediaIds,
1.92 + CMMFPluginSelectionParameters::EAllowOnlySuppliedMediaIds));
1.93 +
1.94 + mediaIds.Close();
1.95 +
1.96 + fSelect = CMMFFormatSelectionParameters::NewLC();
1.97 + if(aExt!=NULL)
1.98 + {
1.99 + fSelect->SetMatchToFileNameL(*aExt);
1.100 + }
1.101 + TRAP(err, {
1.102 + cSelect->SetRequiredRecordFormatSupportL(*fSelect);
1.103 + //Populate the controllers array
1.104 + cSelect->ListImplementationsL(iAudioControllers);
1.105 + });
1.106 +
1.107 + CleanupStack::PopAndDestroy(2);
1.108 +
1.109 + for(TInt count = 0;count < iAudioControllers.Count();count++)
1.110 + {
1.111 + iAudioUidArray.AppendL(iAudioControllers[count]->Uid());
1.112 + }
1.113 + }
1.114 +
1.115 +
1.116 +
1.117 +void CMVSControllerPluginInfo::CollectAudioPlayControllersL(TDesC* aExt)
1.118 + {
1.119 + TInt err = KErrNone;
1.120 + CMMFFormatSelectionParameters* sSelect=NULL;
1.121 + CMMFControllerPluginSelectionParameters* pSelect=NULL;
1.122 +
1.123 + RArray<TUid> mediaIds; //search for audio only
1.124 + pSelect = CMMFControllerPluginSelectionParameters::NewLC();
1.125 +
1.126 + TRAP(err, mediaIds.Append(KUidMediaTypeAudio));
1.127 +
1.128 + TRAP(err, pSelect->SetMediaIdsL(mediaIds,
1.129 + CMMFPluginSelectionParameters::EAllowOnlySuppliedMediaIds));
1.130 +
1.131 + mediaIds.Close();
1.132 +
1.133 + sSelect = CMMFFormatSelectionParameters::NewLC();
1.134 + if(aExt!=NULL)
1.135 + {
1.136 + sSelect->SetMatchToFileNameL(*aExt);
1.137 + }
1.138 +
1.139 + TRAP(err,{
1.140 + pSelect->SetRequiredPlayFormatSupportL(*sSelect);
1.141 + //populate the play controllers array
1.142 + pSelect->ListImplementationsL(iAudioPlayControllers);
1.143 + });
1.144 + CleanupStack::PopAndDestroy(2);
1.145 +
1.146 + for(TInt count = 0;count < iAudioPlayControllers.Count();count++)
1.147 + {
1.148 + iAudioPlayUidArray.AppendL(iAudioPlayControllers[count]->Uid());
1.149 + }
1.150 + iFileLogger.Write(_L("CollectingAudioControllers "));
1.151 + }
1.152 +
1.153 +
1.154 +void CMVSControllerPluginInfo::CollectVideoControllersL(TDesC* aExt)
1.155 + {
1.156 + TInt err = KErrNone;
1.157 + CMMFControllerPluginSelectionParameters* cSelect=NULL;
1.158 + CMMFFormatSelectionParameters* fSelect=NULL;
1.159 +
1.160 + cSelect = CMMFControllerPluginSelectionParameters::NewLC();
1.161 + RArray<TUid> mediaIds; //search for audio only
1.162 + TRAP(err, mediaIds.Append(KUidMediaTypeVideo));
1.163 +
1.164 + TRAP(err, cSelect->SetMediaIdsL(mediaIds,
1.165 + CMMFPluginSelectionParameters::EAllowOtherMediaIds));
1.166 + mediaIds.Close();
1.167 +
1.168 + fSelect = CMMFFormatSelectionParameters::NewLC();
1.169 + if(aExt!=NULL)
1.170 + {
1.171 + fSelect->SetMatchToFileNameL(*aExt);
1.172 + }
1.173 + TRAP(err, {
1.174 + cSelect->SetRequiredRecordFormatSupportL(*fSelect);
1.175 + //Populate the controllers array
1.176 + cSelect->ListImplementationsL(iVideoControllers);
1.177 + });
1.178 +
1.179 + CleanupStack::PopAndDestroy(2);
1.180 +
1.181 + for(TInt count = 0;count < iVideoControllers.Count();count++)
1.182 + {
1.183 + iVideoUidArray.AppendL(iVideoControllers[count]->Uid());
1.184 + }
1.185 + iFileLogger.Write(_L("CollectingVideoControllers ")) ;
1.186 + }
1.187 +
1.188 +/**
1.189 +Destructor.
1.190 +
1.191 +Frees all resources owned by the object prior to its destruction.
1.192 +*/
1.193 +EXPORT_C CMVSControllerPluginInfo::~CMVSControllerPluginInfo()
1.194 + {
1.195 + iControllers.ResetAndDestroy();
1.196 + iControllers.Close();
1.197 + iSupportedControllers.ResetAndDestroy();
1.198 + iSupportedControllers.Close();
1.199 + iAudioControllers.ResetAndDestroy();
1.200 + iAudioControllers.Close();
1.201 + iAudioPlayControllers.ResetAndDestroy();
1.202 + iAudioPlayControllers.Close();
1.203 + iVideoControllers.ResetAndDestroy();
1.204 + iVideoControllers.Close();
1.205 + iUidArray.Close();
1.206 + iAudioUidArray.Close();
1.207 + iAudioPlayUidArray.Close();
1.208 + iVideoUidArray.Close();
1.209 + if(iFileLogger.Handle())
1.210 + {
1.211 + iFileLogger.CloseLog();
1.212 + iFileLogger.Close();
1.213 + }
1.214 + }
1.215 +
1.216 +
1.217 +CMVSControllerPluginInfo::CMVSControllerPluginInfo()
1.218 + {
1.219 + }
1.220 +
1.221 +
1.222 +/**
1.223 +Fetches an array of all the display names of the
1.224 +controller plugins existing currently in the system and an array of their Uid's
1.225 +
1.226 +The data must be in a supported format (for example, WAV ,OGG or AVI).
1.227 +
1.228 +@param aDisplayNames
1.229 + This array will contain all the displaynames of the controllers when this method returns.
1.230 +@param aUidArray
1.231 + This array will contain all the Uids when this method returns.
1.232 +
1.233 +@return number of plugins existing in the system.
1.234 +
1.235 +*/
1.236 +EXPORT_C TInt CMVSControllerPluginInfo::GetPluginListL(CDesCArrayFlat* aDisplayNames, RArray<TUid>& aUidArray)
1.237 + {
1.238 + for(TInt counter = 0;counter < iControllers.Count();counter++)
1.239 + {
1.240 + aDisplayNames->AppendL(iControllers[counter]->DisplayName());
1.241 + aUidArray.Append(iUidArray[counter]);
1.242 + }
1.243 + iFileLogger.Write(_L("Getting the Plugin List"));
1.244 + return aUidArray.Count();
1.245 + }
1.246 +
1.247 +
1.248 +/**
1.249 +Fetches an array of all the display names of the
1.250 +audio controller plugins existing currently in the system and an array of their Uid's
1.251 +
1.252 +@param aDisplayNames
1.253 + This array will contain all the displaynames of the audio controllers for the specified
1.254 + extension, when this method returns.
1.255 +@param aUidArray
1.256 + This array will contain all the corresponding Uids when this method returns.
1.257 +@param aExt
1.258 + The specific extension (for example WAV or OGG) for which the supported controllers is to be retrieved
1.259 +
1.260 +@return number of audio plugins existing in the system.
1.261 +
1.262 +*/
1.263 +EXPORT_C TInt CMVSControllerPluginInfo::GetAudioPluginListL(CDesCArrayFlat* aDisplayNames, RArray<TUid>& aUidArray,RArray<TUid>& aUidPlayArray, TDesC* aExt)
1.264 + {
1.265 + iAudioControllers.ResetAndDestroy();
1.266 + iAudioUidArray.Reset();
1.267 + iAudioPlayControllers.ResetAndDestroy();
1.268 + iAudioPlayUidArray.Reset();
1.269 + CollectAudioControllersL(aExt);
1.270 + CollectAudioPlayControllersL(aExt);
1.271 + for(TInt counter = 0;counter < iAudioControllers.Count();counter++)
1.272 + {
1.273 + aDisplayNames->AppendL(iAudioControllers[counter]->DisplayName());
1.274 + aUidArray.Append(iAudioUidArray[counter]);
1.275 + }
1.276 + for(TInt counter = 0;counter < iAudioPlayControllers.Count();counter++)
1.277 + {
1.278 + aUidPlayArray.Append(iAudioPlayUidArray[counter]);
1.279 + }
1.280 + iFileLogger.Write(_L("Getting the Audio Plugin List"));
1.281 + //Flushing out the existing seleced data and filling in with
1.282 + //all the audio controllers and corresponding UID's for the next run
1.283 + iAudioControllers.ResetAndDestroy();
1.284 + iAudioUidArray.Reset();
1.285 + iAudioPlayControllers.ResetAndDestroy();
1.286 + iAudioPlayUidArray.Reset();
1.287 + iFileLogger.Write(_L("Getting the Video Plugin List"));
1.288 + CollectAudioControllersL(NULL);
1.289 + return aUidArray.Count();
1.290 + }
1.291 +
1.292 +
1.293 +/**
1.294 +Fetches an array of all the display names of the
1.295 +video controller plugins existing currently in the system and an array of their Uid's
1.296 +
1.297 +@param aDisplayNames
1.298 + This array will contain all the displaynames of the video controllers for the specified
1.299 + extension, when this method returns.
1.300 +@param aUidArray
1.301 + This array will contain all the corresponding Uids when this method returns.
1.302 +@param aExt
1.303 + The specific extension (for example AVI) for which the supported controllers is to be retrieved.
1.304 +
1.305 +@return number of video plugins existing in the system.
1.306 +
1.307 +*/
1.308 +EXPORT_C TInt CMVSControllerPluginInfo::GetVideoPluginListL(CDesCArrayFlat* aDisplayNames, RArray<TUid>& aUidArray,TDesC* aExt)
1.309 + {
1.310 + iVideoControllers.ResetAndDestroy();
1.311 + iVideoUidArray.Reset();
1.312 + CollectVideoControllersL(aExt);
1.313 + for(TInt counter = 0;counter < iVideoControllers.Count();counter++)
1.314 + {
1.315 + aDisplayNames->AppendL(iVideoControllers[counter]->DisplayName());
1.316 + aUidArray.Append(iVideoUidArray[counter]);
1.317 + }
1.318 + //Flushing out the existing seleced data and filling in with
1.319 + //all the video controllers and corresponding UID's for the next run
1.320 + iVideoControllers.ResetAndDestroy();
1.321 + iVideoUidArray.Reset();
1.322 + iFileLogger.Write(_L("Getting the Video Plugin List"));
1.323 + CollectVideoControllersL(NULL);
1.324 + return aUidArray.Count();
1.325 + }
1.326 +
1.327 +
1.328 +/**
1.329 +Extracts the list of all the extensions supported.
1.330 +
1.331 +All the supported extensions by the system are retrieved including both audio and video.
1.332 +
1.333 +@param aMediaType
1.334 + Specifies the media type ie audio/video.
1.335 +@param aExtArray
1.336 + This array will contain all the supported extensions, when this method returns.
1.337 +
1.338 +@return number of supported extensions existing in the system.
1.339 +
1.340 +*/
1.341 +EXPORT_C TInt CMVSControllerPluginInfo::GetExtensionListL(TBool aMediaType, CDesCArrayFlat* aExtArray)
1.342 + {
1.343 + CMMFFormatImplementationInformation* formatInfo;
1.344 + if(aMediaType)//selected video
1.345 + {
1.346 + if(iVideoUidArray.Count())
1.347 + {
1.348 + for(TInt counter = 0; counter < iVideoUidArray.Count(); counter++)
1.349 + {
1.350 + CMMFControllerImplementationInformation& plugin= *(iVideoControllers[counter]);
1.351 + //Collect all supported 'Recording' formats
1.352 + const RMMFFormatImplInfoArray& recFormatInfo = plugin.RecordFormats();
1.353 + for(TInt n = 0; n < recFormatInfo.Count(); n++)
1.354 + {
1.355 + formatInfo = recFormatInfo[n];
1.356 + const CDesC8Array& fileExtensions = formatInfo->SupportedFileExtensions();
1.357 + for(TInt innerCounter = 0;innerCounter < fileExtensions.Count();innerCounter++)
1.358 + {
1.359 + TBuf<16> buf;
1.360 + buf.Zero();
1.361 + buf.Copy(fileExtensions[innerCounter]);
1.362 + aExtArray->AppendL(buf);
1.363 + }
1.364 + }
1.365 + }
1.366 + }
1.367 + }
1.368 + else
1.369 + {
1.370 + if(iAudioUidArray.Count())
1.371 + {
1.372 + for(TInt counter = 0; counter < iAudioUidArray.Count(); counter++)
1.373 + {
1.374 + CMMFControllerImplementationInformation& plugin= *(iAudioControllers[counter]);
1.375 + //Collect all supported 'Recording' formats
1.376 + const RMMFFormatImplInfoArray& recFormatInfo = plugin.RecordFormats();
1.377 + for(TInt n = 0; n < recFormatInfo.Count(); n++)
1.378 + {
1.379 + formatInfo = recFormatInfo[n];
1.380 + const CDesC8Array& fileExtensions = formatInfo->SupportedFileExtensions();
1.381 + for(TInt innerCounter = 0;innerCounter < fileExtensions.Count();innerCounter++)
1.382 + {
1.383 + TBuf<16> buf;
1.384 + buf.Zero();
1.385 + buf.Copy(fileExtensions[innerCounter]);
1.386 + aExtArray->AppendL(buf);
1.387 + }
1.388 + }
1.389 + }
1.390 + }
1.391 + }
1.392 + iFileLogger.Write(_L("Getting the Extension List"));
1.393 + return(aExtArray->Count());
1.394 + }
1.395 +
1.396 +
1.397 +/**
1.398 +Returns the type of the given media file. Returns NULL Uid if the
1.399 + file is not supported by MMF.
1.400 +
1.401 +@param aFile
1.402 + The name of the media file.
1.403 +
1.404 +@return Uid of the media.
1.405 +*/
1.406 +EXPORT_C TUid CMVSControllerPluginInfo::GetMediaTypeL(TDesC& aFile)
1.407 + {
1.408 + CMMFControllerPluginSelectionParameters* cSelect=NULL;
1.409 + CMMFFormatSelectionParameters* fSelect=NULL;
1.410 + TUid uid=TUid::Null();
1.411 +
1.412 + iSupportedControllers.ResetAndDestroy();
1.413 + iSupportedControllers.Close();
1.414 +
1.415 + cSelect = CMMFControllerPluginSelectionParameters::NewLC();
1.416 +
1.417 + fSelect = CMMFFormatSelectionParameters::NewLC();
1.418 + fSelect->SetMatchToFileNameL(aFile);
1.419 +
1.420 + cSelect->SetRequiredPlayFormatSupportL(*fSelect);
1.421 + //Populate the controllers array
1.422 + cSelect->ListImplementationsL(iSupportedControllers);
1.423 +
1.424 +
1.425 + if(iSupportedControllers.Count())
1.426 + {
1.427 + //must be sufficient to check with one. not sure if MVS plays midi!
1.428 + TBool video = iSupportedControllers[0]->SupportsMediaId(KUidMediaTypeVideo);
1.429 + if(video)
1.430 + {
1.431 + uid=KUidMediaTypeVideo;
1.432 + }
1.433 + else
1.434 + {
1.435 + uid=KUidMediaTypeAudio;
1.436 + }
1.437 + CleanupStack::PopAndDestroy(2,cSelect);//fselect, cselect
1.438 + }
1.439 + else
1.440 + {
1.441 + //If we are here, file extension has not matched any controller
1.442 + //Try to find controller based on header data
1.443 + HBufC8* headerData = HBufC8::NewLC(KMaxHeaderSize);
1.444 + TPtr8 headerDataPtr = headerData->Des();
1.445 +
1.446 + GetHeaderL(aFile, headerDataPtr);
1.447 +
1.448 + fSelect->SetMatchToHeaderDataL(headerDataPtr);
1.449 + cSelect->SetRequiredPlayFormatSupportL(*fSelect);
1.450 + //Populate the controllers array
1.451 + cSelect->ListImplementationsL(iSupportedControllers);
1.452 +
1.453 + if(iSupportedControllers.Count())
1.454 + {
1.455 + TBool video = iSupportedControllers[0]->SupportsMediaId(KUidMediaTypeVideo);
1.456 + if(video)
1.457 + {
1.458 + uid=KUidMediaTypeVideo;
1.459 + }
1.460 + else
1.461 + {
1.462 + uid=KUidMediaTypeAudio;
1.463 + }
1.464 + }
1.465 + CleanupStack::PopAndDestroy(3,cSelect);//fselect, cselect,headerData
1.466 + }
1.467 +
1.468 + return uid;
1.469 + }
1.470 +
1.471 +
1.472 +/**
1.473 +Returns the controller implementation information associated with the given controller
1.474 +
1.475 +@param aControllerUid
1.476 + The Uid of the controller plugin
1.477 +
1.478 +@return controller implementation structure
1.479 +*/
1.480 +EXPORT_C CMMFControllerImplementationInformation& CMVSControllerPluginInfo::GetControllerInfo(TUid aControllerUid)
1.481 + {
1.482 + TInt index = -1;
1.483 + for(TInt counter = 0; counter < iUidArray.Count(); counter++)
1.484 + {
1.485 + TUid controllerUid = iUidArray[counter];
1.486 + if(controllerUid == aControllerUid)
1.487 + {
1.488 + index = counter;
1.489 + }
1.490 + }
1.491 + iFileLogger.Write(_L("Getting the controller info"));
1.492 + return *(iControllers[index]);
1.493 + }
1.494 +
1.495 +void CMVSControllerPluginInfo::GetHeaderL(TDesC& aFileName, TDes8& aHeaderData)
1.496 + {
1.497 + RFile file;
1.498 + RFs fs;
1.499 +
1.500 + User::LeaveIfError(fs.Connect());
1.501 + CleanupClosePushL(fs);
1.502 + User::LeaveIfError(file.Open(fs, aFileName, EFileShareReadersOnly));
1.503 + CleanupClosePushL(file);
1.504 + User::LeaveIfError(file.Read(aHeaderData,KMaxHeaderSize));
1.505 +
1.506 + CleanupStack::PopAndDestroy(2,&fs);
1.507 + }
1.508 +