|
1 /* |
|
2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: This class is responsible for reading file info |
|
15 * Version : %version: da1mmcf#5.1.3.1.6 % << Don't touch! Updated by Synergy at check-out. |
|
16 * |
|
17 * Copyright © 2005 Nokia. All rights reserved. |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <mmf/common/mmfstandardcustomcommands.h> |
|
23 #include <mmf/server/mmffile.h> |
|
24 #include <mmf/common/mmcaf.h> |
|
25 #include <mpxlog.h> |
|
26 #include "mpxfileinfoutility.h" |
|
27 using namespace ContentAccess; |
|
28 |
|
29 // CONSTANTS |
|
30 const TInt KMCExpandSize = 100; |
|
31 |
|
32 // ============================ MEMBER FUNCTIONS ============================== |
|
33 |
|
34 // ---------------------------------------------------------------------------- |
|
35 // Two-phased constructor. |
|
36 // ---------------------------------------------------------------------------- |
|
37 // |
|
38 CMPXFileInfoUtility* CMPXFileInfoUtility::NewL() |
|
39 { |
|
40 CMPXFileInfoUtility* self = NewLC(); |
|
41 CleanupStack::Pop(self); |
|
42 return self; |
|
43 } |
|
44 |
|
45 // ---------------------------------------------------------------------------- |
|
46 // Two-phased constructor, leave object pointer in the cleanup stack |
|
47 // ---------------------------------------------------------------------------- |
|
48 // |
|
49 CMPXFileInfoUtility* CMPXFileInfoUtility::NewLC() |
|
50 { |
|
51 CMPXFileInfoUtility* self = new (ELeave) CMPXFileInfoUtility(); |
|
52 CleanupStack::PushL(self); |
|
53 self->ConstructL(); |
|
54 return self; |
|
55 } |
|
56 |
|
57 // ---------------------------------------------------------------------------- |
|
58 // C++ default constructor can NOT contain any code, that might leave |
|
59 // ---------------------------------------------------------------------------- |
|
60 // |
|
61 CMPXFileInfoUtility::CMPXFileInfoUtility(): iCurrentControllerUid(NULL) |
|
62 { |
|
63 } |
|
64 |
|
65 // Destructor |
|
66 CMPXFileInfoUtility::~CMPXFileInfoUtility() |
|
67 { |
|
68 iAudioControllers.ResetAndDestroy(); |
|
69 //Reset(); |
|
70 // Close all MMF controllers in the cache |
|
71 TPtrHashMapIter<TUint32, RMMFController> iter(iMMFControllers); |
|
72 RMMFController* controller; |
|
73 |
|
74 while((controller = const_cast<RMMFController*>(iter.NextValue())) != NULL) |
|
75 { |
|
76 controller->Close(); |
|
77 } |
|
78 |
|
79 iMMFControllers.ResetAndDestroy(); |
|
80 iMMFControllers.Close(); |
|
81 |
|
82 // delete non cached controller |
|
83 if(iController) |
|
84 { |
|
85 iController->Close(); |
|
86 delete iController; |
|
87 iController = NULL; |
|
88 } |
|
89 |
|
90 REComSession::FinalClose(); |
|
91 } |
|
92 |
|
93 // ---------------------------------------------------------------------------- |
|
94 // Symbian 2nd phase constructor can leave. |
|
95 // ---------------------------------------------------------------------------- |
|
96 // |
|
97 void CMPXFileInfoUtility::ConstructL() |
|
98 { |
|
99 CreateAudioFormatsArrayL(); |
|
100 } |
|
101 |
|
102 // ---------------------------------------------------------------------------- |
|
103 // Open a file using audio controller |
|
104 // ---------------------------------------------------------------------------- |
|
105 // |
|
106 void CMPXFileInfoUtility::OpenFileL(RFile& aFile, |
|
107 const TDesC& aMimeType /*= KNullDesC*/) |
|
108 { |
|
109 MPX_DEBUG1("CMPXFileInfoUtility::OpenFileL()"); |
|
110 Reset(); |
|
111 |
|
112 HBufC* fileNameBuf = HBufC::NewLC(KMaxFileName); |
|
113 TPtr fileName = fileNameBuf->Des(); |
|
114 aFile.FullName(fileName); |
|
115 |
|
116 TUid pluginUid; |
|
117 FindController(fileName, aMimeType, pluginUid); |
|
118 CleanupStack::PopAndDestroy(fileNameBuf); |
|
119 |
|
120 // Open a new controller |
|
121 OpenControllerL(pluginUid); |
|
122 TMMFMessageDestination dataSource; |
|
123 |
|
124 TPtrC defaultID(KDefaultContentObject); |
|
125 TBool enableUI = EFalse; |
|
126 |
|
127 //Code taken from TMMFileHandleSource |
|
128 |
|
129 |
|
130 //{//build custom mmf message packet |
|
131 //based on CMMFileSourceSink::DoCreateFileHandleSourceConfigDataL() |
|
132 CBufFlat* buf = CBufFlat::NewL(KMCExpandSize); |
|
133 CleanupStack::PushL(buf); |
|
134 RBufWriteStream stream; |
|
135 stream.Open(*buf); |
|
136 CleanupClosePushL(stream); |
|
137 |
|
138 TPckgBuf<RFile*> fileptr(&aFile); |
|
139 stream.WriteInt32L(KMMFileHandleSourceUid.iUid); |
|
140 stream.WriteL(fileptr); |
|
141 |
|
142 //Code taken from TMMFileHandleSource |
|
143 |
|
144 TInt length = 0; |
|
145 //if (defaultID != NULL) |
|
146 length = defaultID.Length(); |
|
147 stream.WriteInt32L(length); |
|
148 //if (length>0) |
|
149 stream.WriteL(defaultID); |
|
150 |
|
151 stream.WriteInt32L(enableUI); |
|
152 |
|
153 stream.CommitL(); |
|
154 CleanupStack::PopAndDestroy(&stream); |
|
155 //iSourceSinkData = buf->Ptr(0).AllocL(); |
|
156 |
|
157 //CleanupStack::PopAndDestroy(buf); |
|
158 //} |
|
159 |
|
160 // User::LeaveIfError(iController->Reset()); |
|
161 |
|
162 |
|
163 // Add new data source |
|
164 User::LeaveIfError(iController->AddDataSource(KUidMmfFileSource, |
|
165 buf->Ptr(0), |
|
166 dataSource)); |
|
167 |
|
168 User::LeaveIfError(iController->AddDataSink(KUidMmfAudioOutput, |
|
169 KNullDesC8)); |
|
170 CleanupStack::PopAndDestroy(buf); |
|
171 } |
|
172 |
|
173 // ---------------------------------------------------------------------------- |
|
174 // Reset file info utility |
|
175 // ---------------------------------------------------------------------------- |
|
176 // |
|
177 void CMPXFileInfoUtility::Reset() |
|
178 { |
|
179 // Reset the controller |
|
180 if(iController) |
|
181 { |
|
182 if(iCurrentControllerUid == 0x101FAFB1 || iCurrentControllerUid == 0x10283351 |
|
183 || iCurrentControllerUid == 0x10207B65 ) |
|
184 { |
|
185 iController->Close(); |
|
186 delete iController; |
|
187 iController = NULL; |
|
188 } |
|
189 else |
|
190 { |
|
191 iController->Reset(); |
|
192 } |
|
193 } |
|
194 |
|
195 } |
|
196 |
|
197 // ---------------------------------------------------------------------------- |
|
198 // Get the duration of a song |
|
199 // ---------------------------------------------------------------------------- |
|
200 // |
|
201 TTimeIntervalMicroSeconds CMPXFileInfoUtility::Duration() |
|
202 { |
|
203 MPX_DEBUG1("CMPXFileInfoUtility::Duration()"); |
|
204 TTimeIntervalMicroSeconds duration; |
|
205 TInt err = iController->GetDuration(duration); |
|
206 if(err != KErrNone) |
|
207 { |
|
208 duration = TInt64(0); |
|
209 } |
|
210 return duration; |
|
211 } |
|
212 |
|
213 // ---------------------------------------------------------------------------- |
|
214 // Get the bit rate of a song |
|
215 // ---------------------------------------------------------------------------- |
|
216 // |
|
217 TUint CMPXFileInfoUtility::BitRate() |
|
218 { |
|
219 RMMFAudioControllerCustomCommands customCommands(*iController); |
|
220 |
|
221 TUint bitRate(0); |
|
222 //Ignore return value, bitRate remain 0 if error |
|
223 customCommands.GetSourceBitRate(bitRate); |
|
224 return bitRate; |
|
225 } |
|
226 |
|
227 // ---------------------------------------------------------------------------- |
|
228 // Get the sample rate of a song |
|
229 // ---------------------------------------------------------------------------- |
|
230 // |
|
231 TUint CMPXFileInfoUtility::SampleRate() |
|
232 { |
|
233 RMMFAudioControllerCustomCommands customCommands(*iController); |
|
234 |
|
235 TUint sampleRate(0) ; |
|
236 //Ignore return value, sampleRate remain 0 if error |
|
237 customCommands.GetSourceSampleRate(sampleRate); |
|
238 return sampleRate; |
|
239 } |
|
240 |
|
241 // ---------------------------------------------------------------------------- |
|
242 // Find a controller based on mime type, then file name |
|
243 // ---------------------------------------------------------------------------- |
|
244 void CMPXFileInfoUtility::FindController(const TDesC& aFileName, |
|
245 const TDesC& aMimeType, |
|
246 TUid& aUid) |
|
247 { |
|
248 MPX_DEBUG1("CMPXFileInfoUtility::FindControllerL()"); |
|
249 TBool found(EFalse); |
|
250 TInt i(0); |
|
251 TInt j(0); |
|
252 TInt count = iAudioControllers.Count(); |
|
253 |
|
254 // try with MIME type |
|
255 if (aMimeType.Length() > 0) |
|
256 { |
|
257 TBuf8<KMaxDataTypeLength> mimeType; |
|
258 mimeType.Copy(aMimeType); |
|
259 for (i = 0 ; !found && i < count; i++) |
|
260 { |
|
261 RMMFFormatImplInfoArray formats = |
|
262 iAudioControllers[i]->PlayFormats(); |
|
263 for (j = 0; j < formats.Count() ; j++) |
|
264 { |
|
265 if (formats[j]->SupportsMimeType(mimeType)) |
|
266 { |
|
267 aUid = iAudioControllers[i]->Uid(); |
|
268 found = ETrue; |
|
269 break; |
|
270 } |
|
271 } |
|
272 } |
|
273 } |
|
274 // try file extension |
|
275 if (!found) |
|
276 { |
|
277 TParsePtrC parser(aFileName); |
|
278 TBuf8<KMaxFileName> fileExtension; |
|
279 fileExtension.Copy(parser.Ext()); |
|
280 for (i = 0 ; !found && i < count; i++) |
|
281 { |
|
282 RMMFFormatImplInfoArray formats = |
|
283 iAudioControllers[i]->PlayFormats(); |
|
284 for (j = 0; j < formats.Count() ; j++) |
|
285 { |
|
286 if (formats[j]->SupportsFileExtension(fileExtension)) |
|
287 { |
|
288 aUid = iAudioControllers[i]->Uid(); |
|
289 found = ETrue; |
|
290 break; |
|
291 } |
|
292 } |
|
293 } |
|
294 } |
|
295 } |
|
296 |
|
297 // ---------------------------------------------------------------------------- |
|
298 // Open a controller based on file name |
|
299 // The Controller Framework APIs are made of three distinct areas: choosing a |
|
300 // controller plugin, loading and controlling a controller plugin, and custom |
|
301 // commands. |
|
302 // ---------------------------------------------------------------------------- |
|
303 void CMPXFileInfoUtility::OpenControllerL(const TUid& aUid) |
|
304 { |
|
305 MPX_DEBUG1("CMPXFileInfoUtility::OpenControllerL()"); |
|
306 |
|
307 // 3gp and helix (wma) do not allow controller caching |
|
308 if(aUid.iUid == 0x101FAFB1 || aUid.iUid == 0x10283351 |
|
309 || aUid.iUid == 0x10207B65 ) |
|
310 { |
|
311 iCurrentControllerUid = aUid.iUid; |
|
312 TMMFPrioritySettings prioritySettings; |
|
313 prioritySettings.iPriority = EMdaPriorityNormal; |
|
314 prioritySettings.iPref = EMdaPriorityPreferenceTimeAndQuality; |
|
315 |
|
316 iController = new (ELeave) RMMFController; |
|
317 |
|
318 // Controller loading |
|
319 User::LeaveIfError(iController->Open(aUid, prioritySettings)); |
|
320 |
|
321 iCurrentControllerUid = aUid.iUid; |
|
322 return; |
|
323 } |
|
324 |
|
325 // check if we already have controller open for this UID in the cache |
|
326 RMMFController* controller = const_cast<RMMFController*>(iMMFControllers.Find(aUid.iUid)); |
|
327 |
|
328 if(!controller) |
|
329 { |
|
330 // Controller not found from the cache |
|
331 |
|
332 // Allocate and open new controller for this UID |
|
333 controller = new (ELeave) RMMFController; |
|
334 CleanupStack::PushL(controller); |
|
335 |
|
336 TUint32* key = new (ELeave) TUint32(aUid.iUid); |
|
337 CleanupStack::PushL(key); |
|
338 // Now instantiate the first controller in the array |
|
339 TMMFPrioritySettings prioritySettings; |
|
340 prioritySettings.iPriority = EMdaPriorityNormal; |
|
341 prioritySettings.iPref = EMdaPriorityPreferenceTimeAndQuality; |
|
342 |
|
343 // Try to open controller |
|
344 User::LeaveIfError(controller->Open(aUid, |
|
345 prioritySettings)); |
|
346 |
|
347 iMMFControllers.InsertL(key, controller); |
|
348 |
|
349 // iMMFController owns the objects now |
|
350 CleanupStack::Pop(2); |
|
351 |
|
352 } |
|
353 |
|
354 iController = controller; |
|
355 iCurrentControllerUid = aUid.iUid; |
|
356 |
|
357 } |
|
358 |
|
359 // ----------------------------------------------------------------------------- |
|
360 // CMPXFileInfoUtility::CreateAudioFormatsArrayL |
|
361 // ----------------------------------------------------------------------------- |
|
362 // |
|
363 void CMPXFileInfoUtility::CreateAudioFormatsArrayL() |
|
364 { |
|
365 CMMFControllerPluginSelectionParameters* cSelect = |
|
366 CMMFControllerPluginSelectionParameters::NewLC(); |
|
367 CMMFFormatSelectionParameters* fSelect = |
|
368 CMMFFormatSelectionParameters::NewLC(); |
|
369 // Set the play and record format selection parameters to be blank. |
|
370 // - format support is only retrieved if requested. |
|
371 cSelect->SetRequiredPlayFormatSupportL(*fSelect); |
|
372 // Set the media ids |
|
373 RArray<TUid> mediaIds; |
|
374 CleanupClosePushL(mediaIds); |
|
375 User::LeaveIfError(mediaIds.Append(KUidMediaTypeAudio)); |
|
376 // Get plugins that supports audio only |
|
377 cSelect->SetMediaIdsL( mediaIds, |
|
378 CMMFPluginSelectionParameters::EAllowOnlySuppliedMediaIds ); |
|
379 // iAudioControllers contains now all audio plugins that |
|
380 // support at least audio. |
|
381 cSelect->ListImplementationsL(iAudioControllers); |
|
382 // Clean up |
|
383 CleanupStack::PopAndDestroy(3); //fSelect, cSelect, mediaIds |
|
384 } |
|
385 |
|
386 // End of File |