|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Part of the MVS Agents for TechView |
|
15 // |
|
16 |
|
17 #include "agentsutility.h" |
|
18 #include <e32def.h> |
|
19 const TInt KMaxHeaderSize = 256; |
|
20 |
|
21 //CMVSControllerPluginInfo methods |
|
22 |
|
23 /** |
|
24 Constructs and initialises a new instance of the controller plugin information class. |
|
25 |
|
26 The function leaves if the controller plugin information object cannot be created. |
|
27 |
|
28 No callback notification is made upon completion of NewL(). |
|
29 |
|
30 @return A pointer to the new controller plugin information object. |
|
31 |
|
32 */ |
|
33 EXPORT_C CMVSControllerPluginInfo* CMVSControllerPluginInfo::NewL() |
|
34 { |
|
35 CMVSControllerPluginInfo* self = new(ELeave) CMVSControllerPluginInfo(); |
|
36 CleanupStack::PushL(self); |
|
37 self->ConstructL(); |
|
38 CleanupStack::Pop(self); |
|
39 return self; |
|
40 } |
|
41 |
|
42 |
|
43 void CMVSControllerPluginInfo::ConstructL() |
|
44 { |
|
45 TInt err = KErrNone; |
|
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)); |
|
54 |
|
55 TRAP(err, cSelect->SetMediaIdsL(mediaIds, |
|
56 CMMFPluginSelectionParameters::EAllowOtherMediaIds)); |
|
57 mediaIds.Close(); |
|
58 |
|
59 fSelect = CMMFFormatSelectionParameters::NewLC(); |
|
60 |
|
61 TRAP(err, { |
|
62 cSelect->SetRequiredRecordFormatSupportL(*fSelect); |
|
63 //Populate the controllers array |
|
64 cSelect->ListImplementationsL(iControllers); |
|
65 }); |
|
66 CleanupStack::PopAndDestroy(2); |
|
67 |
|
68 for(TInt count = 0;count < iControllers.Count();count++) |
|
69 { |
|
70 iUidArray.AppendL(iControllers[count]->Uid()); |
|
71 } |
|
72 //During the construction get all the supported controllers,not for a specific extension. |
|
73 CollectAudioControllersL(NULL); |
|
74 CollectVideoControllersL(NULL); |
|
75 } |
|
76 |
|
77 |
|
78 void CMVSControllerPluginInfo::CollectAudioControllersL(TDesC* aExt) |
|
79 { |
|
80 TInt err = KErrNone; |
|
81 CMMFControllerPluginSelectionParameters* cSelect=NULL; |
|
82 CMMFFormatSelectionParameters* fSelect=NULL; |
|
83 |
|
84 cSelect = CMMFControllerPluginSelectionParameters::NewLC(); |
|
85 RArray<TUid> mediaIds; //search for audio only |
|
86 TRAP(err, mediaIds.Append(KUidMediaTypeAudio)); |
|
87 |
|
88 TRAP(err, cSelect->SetMediaIdsL(mediaIds, |
|
89 CMMFPluginSelectionParameters::EAllowOnlySuppliedMediaIds)); |
|
90 |
|
91 mediaIds.Close(); |
|
92 |
|
93 fSelect = CMMFFormatSelectionParameters::NewLC(); |
|
94 if(aExt!=NULL) |
|
95 { |
|
96 fSelect->SetMatchToFileNameL(*aExt); |
|
97 } |
|
98 TRAP(err, { |
|
99 cSelect->SetRequiredRecordFormatSupportL(*fSelect); |
|
100 //Populate the controllers array |
|
101 cSelect->ListImplementationsL(iAudioControllers); |
|
102 }); |
|
103 |
|
104 CleanupStack::PopAndDestroy(2); |
|
105 |
|
106 for(TInt count = 0;count < iAudioControllers.Count();count++) |
|
107 { |
|
108 iAudioUidArray.AppendL(iAudioControllers[count]->Uid()); |
|
109 } |
|
110 } |
|
111 |
|
112 |
|
113 |
|
114 void CMVSControllerPluginInfo::CollectAudioPlayControllersL(TDesC* aExt) |
|
115 { |
|
116 TInt err = KErrNone; |
|
117 CMMFFormatSelectionParameters* sSelect=NULL; |
|
118 CMMFControllerPluginSelectionParameters* pSelect=NULL; |
|
119 |
|
120 RArray<TUid> mediaIds; //search for audio only |
|
121 pSelect = CMMFControllerPluginSelectionParameters::NewLC(); |
|
122 |
|
123 TRAP(err, mediaIds.Append(KUidMediaTypeAudio)); |
|
124 |
|
125 TRAP(err, pSelect->SetMediaIdsL(mediaIds, |
|
126 CMMFPluginSelectionParameters::EAllowOnlySuppliedMediaIds)); |
|
127 |
|
128 mediaIds.Close(); |
|
129 |
|
130 sSelect = CMMFFormatSelectionParameters::NewLC(); |
|
131 if(aExt!=NULL) |
|
132 { |
|
133 sSelect->SetMatchToFileNameL(*aExt); |
|
134 } |
|
135 |
|
136 TRAP(err,{ |
|
137 pSelect->SetRequiredPlayFormatSupportL(*sSelect); |
|
138 //populate the play controllers array |
|
139 pSelect->ListImplementationsL(iAudioPlayControllers); |
|
140 }); |
|
141 CleanupStack::PopAndDestroy(2); |
|
142 |
|
143 for(TInt count = 0;count < iAudioPlayControllers.Count();count++) |
|
144 { |
|
145 iAudioPlayUidArray.AppendL(iAudioPlayControllers[count]->Uid()); |
|
146 } |
|
147 iFileLogger.Write(_L("CollectingAudioControllers ")); |
|
148 } |
|
149 |
|
150 |
|
151 void CMVSControllerPluginInfo::CollectVideoControllersL(TDesC* aExt) |
|
152 { |
|
153 TInt err = KErrNone; |
|
154 CMMFControllerPluginSelectionParameters* cSelect=NULL; |
|
155 CMMFFormatSelectionParameters* fSelect=NULL; |
|
156 |
|
157 cSelect = CMMFControllerPluginSelectionParameters::NewLC(); |
|
158 RArray<TUid> mediaIds; //search for audio only |
|
159 TRAP(err, mediaIds.Append(KUidMediaTypeVideo)); |
|
160 |
|
161 TRAP(err, cSelect->SetMediaIdsL(mediaIds, |
|
162 CMMFPluginSelectionParameters::EAllowOtherMediaIds)); |
|
163 mediaIds.Close(); |
|
164 |
|
165 fSelect = CMMFFormatSelectionParameters::NewLC(); |
|
166 if(aExt!=NULL) |
|
167 { |
|
168 fSelect->SetMatchToFileNameL(*aExt); |
|
169 } |
|
170 TRAP(err, { |
|
171 cSelect->SetRequiredRecordFormatSupportL(*fSelect); |
|
172 //Populate the controllers array |
|
173 cSelect->ListImplementationsL(iVideoControllers); |
|
174 }); |
|
175 |
|
176 CleanupStack::PopAndDestroy(2); |
|
177 |
|
178 for(TInt count = 0;count < iVideoControllers.Count();count++) |
|
179 { |
|
180 iVideoUidArray.AppendL(iVideoControllers[count]->Uid()); |
|
181 } |
|
182 iFileLogger.Write(_L("CollectingVideoControllers ")) ; |
|
183 } |
|
184 |
|
185 /** |
|
186 Destructor. |
|
187 |
|
188 Frees all resources owned by the object prior to its destruction. |
|
189 */ |
|
190 EXPORT_C CMVSControllerPluginInfo::~CMVSControllerPluginInfo() |
|
191 { |
|
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(); |
|
202 iUidArray.Close(); |
|
203 iAudioUidArray.Close(); |
|
204 iAudioPlayUidArray.Close(); |
|
205 iVideoUidArray.Close(); |
|
206 if(iFileLogger.Handle()) |
|
207 { |
|
208 iFileLogger.CloseLog(); |
|
209 iFileLogger.Close(); |
|
210 } |
|
211 } |
|
212 |
|
213 |
|
214 CMVSControllerPluginInfo::CMVSControllerPluginInfo() |
|
215 { |
|
216 } |
|
217 |
|
218 |
|
219 /** |
|
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 |
|
222 |
|
223 The data must be in a supported format (for example, WAV ,OGG or AVI). |
|
224 |
|
225 @param aDisplayNames |
|
226 This array will contain all the displaynames of the controllers when this method returns. |
|
227 @param aUidArray |
|
228 This array will contain all the Uids when this method returns. |
|
229 |
|
230 @return number of plugins existing in the system. |
|
231 |
|
232 */ |
|
233 EXPORT_C TInt CMVSControllerPluginInfo::GetPluginListL(CDesCArrayFlat* aDisplayNames, RArray<TUid>& aUidArray) |
|
234 { |
|
235 for(TInt counter = 0;counter < iControllers.Count();counter++) |
|
236 { |
|
237 aDisplayNames->AppendL(iControllers[counter]->DisplayName()); |
|
238 aUidArray.Append(iUidArray[counter]); |
|
239 } |
|
240 iFileLogger.Write(_L("Getting the Plugin List")); |
|
241 return aUidArray.Count(); |
|
242 } |
|
243 |
|
244 |
|
245 /** |
|
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 |
|
248 |
|
249 @param aDisplayNames |
|
250 This array will contain all the displaynames of the audio controllers for the specified |
|
251 extension, when this method returns. |
|
252 @param aUidArray |
|
253 This array will contain all the corresponding Uids when this method returns. |
|
254 @param aExt |
|
255 The specific extension (for example WAV or OGG) for which the supported controllers is to be retrieved |
|
256 |
|
257 @return number of audio plugins existing in the system. |
|
258 |
|
259 */ |
|
260 EXPORT_C TInt CMVSControllerPluginInfo::GetAudioPluginListL(CDesCArrayFlat* aDisplayNames, RArray<TUid>& aUidArray,RArray<TUid>& aUidPlayArray, TDesC* aExt) |
|
261 { |
|
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++) |
|
269 { |
|
270 aDisplayNames->AppendL(iAudioControllers[counter]->DisplayName()); |
|
271 aUidArray.Append(iAudioUidArray[counter]); |
|
272 } |
|
273 for(TInt counter = 0;counter < iAudioPlayControllers.Count();counter++) |
|
274 { |
|
275 aUidPlayArray.Append(iAudioPlayUidArray[counter]); |
|
276 } |
|
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(); |
|
287 } |
|
288 |
|
289 |
|
290 /** |
|
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 |
|
293 |
|
294 @param aDisplayNames |
|
295 This array will contain all the displaynames of the video controllers for the specified |
|
296 extension, when this method returns. |
|
297 @param aUidArray |
|
298 This array will contain all the corresponding Uids when this method returns. |
|
299 @param aExt |
|
300 The specific extension (for example AVI) for which the supported controllers is to be retrieved. |
|
301 |
|
302 @return number of video plugins existing in the system. |
|
303 |
|
304 */ |
|
305 EXPORT_C TInt CMVSControllerPluginInfo::GetVideoPluginListL(CDesCArrayFlat* aDisplayNames, RArray<TUid>& aUidArray,TDesC* aExt) |
|
306 { |
|
307 iVideoControllers.ResetAndDestroy(); |
|
308 iVideoUidArray.Reset(); |
|
309 CollectVideoControllersL(aExt); |
|
310 for(TInt counter = 0;counter < iVideoControllers.Count();counter++) |
|
311 { |
|
312 aDisplayNames->AppendL(iVideoControllers[counter]->DisplayName()); |
|
313 aUidArray.Append(iVideoUidArray[counter]); |
|
314 } |
|
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(); |
|
322 } |
|
323 |
|
324 |
|
325 /** |
|
326 Extracts the list of all the extensions supported. |
|
327 |
|
328 All the supported extensions by the system are retrieved including both audio and video. |
|
329 |
|
330 @param aMediaType |
|
331 Specifies the media type ie audio/video. |
|
332 @param aExtArray |
|
333 This array will contain all the supported extensions, when this method returns. |
|
334 |
|
335 @return number of supported extensions existing in the system. |
|
336 |
|
337 */ |
|
338 EXPORT_C TInt CMVSControllerPluginInfo::GetExtensionListL(TBool aMediaType, CDesCArrayFlat* aExtArray) |
|
339 { |
|
340 CMMFFormatImplementationInformation* formatInfo; |
|
341 if(aMediaType)//selected video |
|
342 { |
|
343 if(iVideoUidArray.Count()) |
|
344 { |
|
345 for(TInt counter = 0; counter < iVideoUidArray.Count(); counter++) |
|
346 { |
|
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++) |
|
351 { |
|
352 formatInfo = recFormatInfo[n]; |
|
353 const CDesC8Array& fileExtensions = formatInfo->SupportedFileExtensions(); |
|
354 for(TInt innerCounter = 0;innerCounter < fileExtensions.Count();innerCounter++) |
|
355 { |
|
356 TBuf<16> buf; |
|
357 buf.Zero(); |
|
358 buf.Copy(fileExtensions[innerCounter]); |
|
359 aExtArray->AppendL(buf); |
|
360 } |
|
361 } |
|
362 } |
|
363 } |
|
364 } |
|
365 else |
|
366 { |
|
367 if(iAudioUidArray.Count()) |
|
368 { |
|
369 for(TInt counter = 0; counter < iAudioUidArray.Count(); counter++) |
|
370 { |
|
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++) |
|
375 { |
|
376 formatInfo = recFormatInfo[n]; |
|
377 const CDesC8Array& fileExtensions = formatInfo->SupportedFileExtensions(); |
|
378 for(TInt innerCounter = 0;innerCounter < fileExtensions.Count();innerCounter++) |
|
379 { |
|
380 TBuf<16> buf; |
|
381 buf.Zero(); |
|
382 buf.Copy(fileExtensions[innerCounter]); |
|
383 aExtArray->AppendL(buf); |
|
384 } |
|
385 } |
|
386 } |
|
387 } |
|
388 } |
|
389 iFileLogger.Write(_L("Getting the Extension List")); |
|
390 return(aExtArray->Count()); |
|
391 } |
|
392 |
|
393 |
|
394 /** |
|
395 Returns the type of the given media file. Returns NULL Uid if the |
|
396 file is not supported by MMF. |
|
397 |
|
398 @param aFile |
|
399 The name of the media file. |
|
400 |
|
401 @return Uid of the media. |
|
402 */ |
|
403 EXPORT_C TUid CMVSControllerPluginInfo::GetMediaTypeL(TDesC& aFile) |
|
404 { |
|
405 CMMFControllerPluginSelectionParameters* cSelect=NULL; |
|
406 CMMFFormatSelectionParameters* fSelect=NULL; |
|
407 TUid uid=TUid::Null(); |
|
408 |
|
409 iSupportedControllers.ResetAndDestroy(); |
|
410 iSupportedControllers.Close(); |
|
411 |
|
412 cSelect = CMMFControllerPluginSelectionParameters::NewLC(); |
|
413 |
|
414 fSelect = CMMFFormatSelectionParameters::NewLC(); |
|
415 fSelect->SetMatchToFileNameL(aFile); |
|
416 |
|
417 cSelect->SetRequiredPlayFormatSupportL(*fSelect); |
|
418 //Populate the controllers array |
|
419 cSelect->ListImplementationsL(iSupportedControllers); |
|
420 |
|
421 |
|
422 if(iSupportedControllers.Count()) |
|
423 { |
|
424 //must be sufficient to check with one. not sure if MVS plays midi! |
|
425 TBool video = iSupportedControllers[0]->SupportsMediaId(KUidMediaTypeVideo); |
|
426 if(video) |
|
427 { |
|
428 uid=KUidMediaTypeVideo; |
|
429 } |
|
430 else |
|
431 { |
|
432 uid=KUidMediaTypeAudio; |
|
433 } |
|
434 CleanupStack::PopAndDestroy(2,cSelect);//fselect, cselect |
|
435 } |
|
436 else |
|
437 { |
|
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(); |
|
442 |
|
443 GetHeaderL(aFile, headerDataPtr); |
|
444 |
|
445 fSelect->SetMatchToHeaderDataL(headerDataPtr); |
|
446 cSelect->SetRequiredPlayFormatSupportL(*fSelect); |
|
447 //Populate the controllers array |
|
448 cSelect->ListImplementationsL(iSupportedControllers); |
|
449 |
|
450 if(iSupportedControllers.Count()) |
|
451 { |
|
452 TBool video = iSupportedControllers[0]->SupportsMediaId(KUidMediaTypeVideo); |
|
453 if(video) |
|
454 { |
|
455 uid=KUidMediaTypeVideo; |
|
456 } |
|
457 else |
|
458 { |
|
459 uid=KUidMediaTypeAudio; |
|
460 } |
|
461 } |
|
462 CleanupStack::PopAndDestroy(3,cSelect);//fselect, cselect,headerData |
|
463 } |
|
464 |
|
465 return uid; |
|
466 } |
|
467 |
|
468 |
|
469 /** |
|
470 Returns the controller implementation information associated with the given controller |
|
471 |
|
472 @param aControllerUid |
|
473 The Uid of the controller plugin |
|
474 |
|
475 @return controller implementation structure |
|
476 */ |
|
477 EXPORT_C CMMFControllerImplementationInformation& CMVSControllerPluginInfo::GetControllerInfo(TUid aControllerUid) |
|
478 { |
|
479 TInt index = -1; |
|
480 for(TInt counter = 0; counter < iUidArray.Count(); counter++) |
|
481 { |
|
482 TUid controllerUid = iUidArray[counter]; |
|
483 if(controllerUid == aControllerUid) |
|
484 { |
|
485 index = counter; |
|
486 } |
|
487 } |
|
488 iFileLogger.Write(_L("Getting the controller info")); |
|
489 return *(iControllers[index]); |
|
490 } |
|
491 |
|
492 void CMVSControllerPluginInfo::GetHeaderL(TDesC& aFileName, TDes8& aHeaderData) |
|
493 { |
|
494 RFile file; |
|
495 RFs fs; |
|
496 |
|
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)); |
|
502 |
|
503 CleanupStack::PopAndDestroy(2,&fs); |
|
504 } |
|
505 |