|
1 /* |
|
2 * Copyright (c) 2008 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: Implementation of CMediaRecognizer |
|
15 * |
|
16 */ |
|
17 |
|
18 // Version : %version: 7 % |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 #include <utf.h> |
|
24 #include <eikenv.h> |
|
25 #include <bautils.h> |
|
26 #include <mmf/server/mmfdatasourcesink.hrh> |
|
27 #include <mediarecognizer.h> |
|
28 |
|
29 #include "playbackhelper_log.h" |
|
30 |
|
31 // CONSTANTS |
|
32 _LIT8(KDataTypeRAM,"audio/x-pn-realaudio-plugin"); |
|
33 _LIT8(KDataTypeSDP,"application/sdp"); |
|
34 _LIT8(KDataTypePlaylist,"audio/mpegurl"); |
|
35 _LIT8(KDataTypeRNG,"application/vnd.nokia.ringing-tone"); |
|
36 |
|
37 _LIT8(KDataTypeMp3,"audio/mp3"); |
|
38 _LIT8(KDataTypeXmp3,"audio/x-mp3"); |
|
39 _LIT8(KDataTypeAudio3gp,"audio/3gpp"); |
|
40 _LIT8(KDataTypeFlashVideo,"video/x-flv"); |
|
41 _LIT8(KDataTypeText,"text"); |
|
42 |
|
43 _LIT8(KDataTypeAVI,"video/avi"); |
|
44 _LIT8(KDataTypeMsAVI,"video/msvideo"); |
|
45 _LIT8(KDataTypeMsAVIVideo,"video/x-msvideo"); |
|
46 |
|
47 _LIT8(KDataTypeMatroskaVideo ,"video/x-matroska"); |
|
48 |
|
49 #ifdef __WINDOWS_MEDIA |
|
50 _LIT8(KDataTypeWMV_APP,"application/vnd.rn-wmv"); |
|
51 _LIT8(KDataTypeWMV,"video/x-ms-wmv"); |
|
52 _LIT8(KDataTypeASF,"application/vnd.ms-asf"); |
|
53 _LIT8(KDataTypeASX, "video/x-ms-asf"); |
|
54 _LIT(KRtspTcpPrefix,"rtspt://"); |
|
55 _LIT(KRtspUdpPrefix,"rtspu://"); |
|
56 _LIT(KHttpPrefix,"http://"); |
|
57 _LIT(KHttpTcpPrefix,"httpt://"); |
|
58 _LIT(KMmsPrefix,"mms://"); |
|
59 _LIT(KMmstPrefix,"mmst://"); |
|
60 #endif // __WINDOWS_MEDIA |
|
61 |
|
62 _LIT8(KDmFileExtension,".dm"); |
|
63 _LIT8(KDcfFileExtension,".dcf"); |
|
64 _LIT8(KOdfFileExtension,".odf"); |
|
65 _LIT(KRtspPrefix,"rtsp://"); |
|
66 _LIT(KFilePrefix,"file://"); |
|
67 |
|
68 const TInt KDefaultBufferSize = 1000; |
|
69 const TInt KMinPrefixLength = 6; |
|
70 |
|
71 |
|
72 // ============================ MEMBER FUNCTIONS =================================================== |
|
73 |
|
74 // ------------------------------------------------------------------------------------------------- |
|
75 // CMediaRecognizer::CMediaRecognizer |
|
76 // C++ default constructor can NOT contain any code, that might leave. |
|
77 // ------------------------------------------------------------------------------------------------- |
|
78 // |
|
79 CMediaRecognizer::CMediaRecognizer() |
|
80 { |
|
81 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::CMediaRecognizer()")); |
|
82 } |
|
83 |
|
84 // ------------------------------------------------------------------------------------------------- |
|
85 // CMediaRecognizer::ConstructL |
|
86 // Symbian 2nd phase constructor can leave. |
|
87 // ------------------------------------------------------------------------------------------------- |
|
88 // |
|
89 void CMediaRecognizer::ConstructL() |
|
90 { |
|
91 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::ConstructL()")); |
|
92 |
|
93 User::LeaveIfError( iFs.Connect() ); |
|
94 } |
|
95 |
|
96 // ------------------------------------------------------------------------------------------------- |
|
97 // CMediaRecognizer::NewL |
|
98 // Two-phased constructor. |
|
99 // ------------------------------------------------------------------------------------------------- |
|
100 // |
|
101 EXPORT_C CMediaRecognizer* CMediaRecognizer::NewL() |
|
102 { |
|
103 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::NewL()")); |
|
104 |
|
105 CMediaRecognizer* self = new( ELeave ) CMediaRecognizer; |
|
106 CleanupStack::PushL( self ); |
|
107 self->ConstructL(); |
|
108 CleanupStack::Pop(); |
|
109 return self; |
|
110 } |
|
111 |
|
112 // ------------------------------------------------------------------------------------------------- |
|
113 // CMediaRecognizer::~CMediaRecognizer |
|
114 // Destructor |
|
115 // ------------------------------------------------------------------------------------------------- |
|
116 // |
|
117 EXPORT_C CMediaRecognizer::~CMediaRecognizer() |
|
118 { |
|
119 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::~CMediaRecognizer()")); |
|
120 |
|
121 if ( iFileHandle.SubSessionHandle() ) |
|
122 { |
|
123 iFileHandle.Close(); |
|
124 } |
|
125 |
|
126 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
127 if ( iFileHandle64.SubSessionHandle() ) |
|
128 { |
|
129 iFileHandle64.Close(); |
|
130 } |
|
131 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
132 |
|
133 iFs.Close(); |
|
134 } |
|
135 |
|
136 // ------------------------------------------------------------------------------------------------- |
|
137 // CMediaRecognizer::IdentifyMediaTypeL |
|
138 // ------------------------------------------------------------------------------------------------- |
|
139 // |
|
140 EXPORT_C CMediaRecognizer::TMediaType |
|
141 CMediaRecognizer::IdentifyMediaTypeL( const TDesC& aMediaName, TBool aIncludeUrls ) |
|
142 { |
|
143 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::IdentifyMediaTypeL( %S )"), &aMediaName); |
|
144 |
|
145 TMediaType ret = EUnidentified; |
|
146 |
|
147 if ( BaflUtils::FileExists( iFs, aMediaName ) ) |
|
148 { |
|
149 ret = MediaTypeL( aMediaName ); |
|
150 } |
|
151 else if ( aIncludeUrls && IsValidStreamingPrefix( aMediaName ) ) |
|
152 { |
|
153 ret = EUrl; |
|
154 } |
|
155 |
|
156 return ret; |
|
157 } |
|
158 |
|
159 // ------------------------------------------------------------------------------------------------- |
|
160 // CMediaRecognizer::IdentifyMediaTypeL |
|
161 // ------------------------------------------------------------------------------------------------- |
|
162 // |
|
163 EXPORT_C CMediaRecognizer::TMediaType |
|
164 CMediaRecognizer::IdentifyMediaTypeL( const TDesC& aMediaName, RFile& aFile, TBool aIncludeUrls ) |
|
165 { |
|
166 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::IdentifyMediaTypeL( %S, RFile )"), &aMediaName); |
|
167 |
|
168 if ( aFile.SubSessionHandle() ) |
|
169 { |
|
170 iFileHandle.Close(); |
|
171 User::LeaveIfError( iFileHandle.Duplicate( aFile ) ); |
|
172 } |
|
173 |
|
174 TMediaType ret = EUnidentified; |
|
175 |
|
176 if ( FileHandleExists() ) |
|
177 { |
|
178 ret = MediaTypeL( aMediaName ); |
|
179 } |
|
180 else if ( aIncludeUrls && IsValidStreamingPrefix( aMediaName ) ) |
|
181 { |
|
182 ret = EUrl; |
|
183 } |
|
184 |
|
185 return ret; |
|
186 } |
|
187 |
|
188 // ------------------------------------------------------------------------------------------------- |
|
189 // CMediaRecognizer::MediaTypeL |
|
190 // ------------------------------------------------------------------------------------------------- |
|
191 // |
|
192 CMediaRecognizer::TMediaType CMediaRecognizer::MediaTypeL( const TDesC& aMediaName ) |
|
193 { |
|
194 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::MediaTypeL( %S )"), &aMediaName); |
|
195 |
|
196 TMediaType ret = EUnidentified; |
|
197 |
|
198 TDataRecognitionResult fileRecognitionResult; |
|
199 RecognizeFileL( aMediaName, fileRecognitionResult ); |
|
200 |
|
201 if ( ! fileRecognitionResult.iDataType.Des8().CompareF( KDataTypeSDP ) ) |
|
202 { |
|
203 ret = ELocalSdpFile; |
|
204 } |
|
205 else if ( ! fileRecognitionResult.iDataType.Des8().CompareF( KDataTypeRAM ) ) |
|
206 { |
|
207 ret = ELocalRamFile; |
|
208 } |
|
209 else |
|
210 { |
|
211 // |
|
212 // Create a list of the controller plugins that support video |
|
213 // |
|
214 RMMFControllerImplInfoArray videoControllers; |
|
215 CleanupResetAndDestroyPushL( videoControllers ); |
|
216 |
|
217 CreateVideoFormatsArrayL( videoControllers ); |
|
218 |
|
219 if ( FileHasVideoSupportL( aMediaName, fileRecognitionResult, videoControllers ) ) |
|
220 { |
|
221 ret = ELocalVideoFile; |
|
222 } |
|
223 #ifdef __WINDOWS_MEDIA |
|
224 else if ( ! fileRecognitionResult.iDataType.Des8().CompareF( KDataTypeWMV ) || |
|
225 ! fileRecognitionResult.iDataType.Des8().CompareF( KDataTypeWMV_APP ) || |
|
226 ! fileRecognitionResult.iDataType.Des8().CompareF( KDataTypeASF ) ) |
|
227 { |
|
228 ret = ELocalVideoFile; |
|
229 } |
|
230 else if ( ! fileRecognitionResult.iDataType.Des8().CompareF(KDataTypeASX) ) |
|
231 { |
|
232 ret = ELocalAsxFile; |
|
233 } |
|
234 #endif // __WINDOWS_MEDIA |
|
235 else if ( ! fileRecognitionResult.iDataType.Des8().CompareF( KDataTypeAVI ) || |
|
236 ! fileRecognitionResult.iDataType.Des8().CompareF( KDataTypeMsAVI) || |
|
237 ! fileRecognitionResult.iDataType.Des8().CompareF( KDataTypeMsAVIVideo) ) |
|
238 { |
|
239 ret = ELocalVideoFile; |
|
240 } |
|
241 else if ( ! fileRecognitionResult.iDataType.Des8().CompareF(KDataTypeFlashVideo) ) |
|
242 { |
|
243 ret = EFlashVideoFile; |
|
244 } |
|
245 else if ( ! fileRecognitionResult.iDataType.Des8().CompareF( KDataTypePlaylist ) ) |
|
246 { |
|
247 ret = ELocalAudioPlaylist; |
|
248 } |
|
249 else if ( ! fileRecognitionResult.iDataType.Des8().CompareF( KDataTypeMatroskaVideo ) ) |
|
250 { |
|
251 ret = ELocalVideoFile; |
|
252 } |
|
253 else |
|
254 { |
|
255 // |
|
256 // Create a list of the controller plugins that support audio |
|
257 // |
|
258 RMMFControllerImplInfoArray audioControllers; |
|
259 CleanupResetAndDestroyPushL( audioControllers ); |
|
260 |
|
261 CreateAudioFormatsArrayL( audioControllers ); |
|
262 |
|
263 if ( FileHasAudioSupport( aMediaName, |
|
264 fileRecognitionResult, |
|
265 audioControllers, |
|
266 videoControllers ) ) |
|
267 { |
|
268 ret = ELocalAudioFile; |
|
269 } |
|
270 |
|
271 CleanupStack::PopAndDestroy(); // audioControllers |
|
272 } |
|
273 |
|
274 CleanupStack::PopAndDestroy(); // videoControllers |
|
275 } |
|
276 |
|
277 return ret; |
|
278 } |
|
279 |
|
280 // ------------------------------------------------------------------------------------------------- |
|
281 // CMediaRecognizer::MimeTypeL |
|
282 // ------------------------------------------------------------------------------------------------- |
|
283 // |
|
284 EXPORT_C TBuf<KMaxDataTypeLength> CMediaRecognizer::MimeTypeL( const TDesC& aLocalFile ) |
|
285 { |
|
286 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::MimeTypeL()")); |
|
287 |
|
288 TDataRecognitionResult fileRecognitionResult; |
|
289 RecognizeFileL(aLocalFile,fileRecognitionResult); |
|
290 TPtrC mimeType( KNullDesC ); |
|
291 |
|
292 if (fileRecognitionResult.iConfidence >= CApaDataRecognizerType::EPossible) |
|
293 { |
|
294 mimeType.Set( fileRecognitionResult.iDataType.Des() ); |
|
295 } |
|
296 |
|
297 return mimeType; |
|
298 } |
|
299 |
|
300 // ------------------------------------------------------------------------------------------------- |
|
301 // CMediaRecognizer::FreeFilehandle |
|
302 // ------------------------------------------------------------------------------------------------- |
|
303 // |
|
304 EXPORT_C void CMediaRecognizer::FreeFilehandle() |
|
305 { |
|
306 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::FreeFilehandle()")); |
|
307 |
|
308 if ( iFileHandle.SubSessionHandle() ) |
|
309 { |
|
310 iFileHandle.Close(); |
|
311 } |
|
312 |
|
313 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
314 if ( iFileHandle64.SubSessionHandle() ) |
|
315 { |
|
316 iFileHandle64.Close(); |
|
317 } |
|
318 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
319 |
|
320 } |
|
321 |
|
322 // ------------------------------------------------------------------------------------------------- |
|
323 // CMediaRecognizer::FileHasVideoSupport |
|
324 // ------------------------------------------------------------------------------------------------- |
|
325 // |
|
326 TBool CMediaRecognizer::FileHasVideoSupportL( const TDesC& aFileName, |
|
327 TDataRecognitionResult& aFileRecognitionResult, |
|
328 RMMFControllerImplInfoArray& aVideoControllers ) |
|
329 { |
|
330 TBool videoSupport = EFalse; |
|
331 |
|
332 if ( aFileRecognitionResult.iConfidence >= CApaDataRecognizerType::EPossible ) |
|
333 { |
|
334 for ( TInt i = 0 ; i < aVideoControllers.Count() ; i++ ) |
|
335 { |
|
336 RMMFFormatImplInfoArray formats = aVideoControllers[i]->PlayFormats(); |
|
337 |
|
338 for ( TInt j = 0; j < formats.Count() ; j++ ) |
|
339 { |
|
340 if ( formats[j]->SupportsMimeType( aFileRecognitionResult.iDataType.Des8() ) ) |
|
341 { |
|
342 TPtrC8 iDataTypePtr = aFileRecognitionResult.iDataType.Des8(); |
|
343 |
|
344 if ( iDataTypePtr.Find( KDataTypeText ) == KErrNotFound ) |
|
345 { |
|
346 videoSupport = ETrue; |
|
347 } |
|
348 } |
|
349 else if ( formats[j]->SupportsHeaderDataL( aFileRecognitionResult.iDataType.Des8())) |
|
350 { |
|
351 TParsePtrC parser( aFileName ); |
|
352 TBuf8<KMaxFileName> fileExtension; |
|
353 fileExtension.Copy( parser.Ext() ); |
|
354 |
|
355 TBuf8<KMaxFileName> dmExtension( KDmFileExtension ); |
|
356 TBuf8<KMaxFileName> dcfExtension( KDcfFileExtension ); |
|
357 TBuf8<KMaxFileName> odfExtension( KOdfFileExtension ); |
|
358 |
|
359 if ( ( fileExtension.Compare( dmExtension ) == 0 ) || |
|
360 ( fileExtension.Compare( dcfExtension ) == 0 ) || |
|
361 ( fileExtension.Compare( odfExtension ) == 0 ) ) |
|
362 { |
|
363 videoSupport = ETrue; |
|
364 } |
|
365 } |
|
366 } |
|
367 } |
|
368 } |
|
369 |
|
370 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::FileHasVideoSupport() support video [%d]"), videoSupport); |
|
371 |
|
372 return videoSupport; |
|
373 } |
|
374 |
|
375 // ------------------------------------------------------------------------------------------------- |
|
376 // CMediaRecognizer::FileHasAudioSupport |
|
377 // ------------------------------------------------------------------------------------------------- |
|
378 // |
|
379 TBool CMediaRecognizer::FileHasAudioSupport( const TDesC& aFileName, |
|
380 TDataRecognitionResult& aFileRecognitionResult, |
|
381 RMMFControllerImplInfoArray& aAudioControllers, |
|
382 RMMFControllerImplInfoArray& aVideoControllers ) |
|
383 { |
|
384 |
|
385 TBool audioSupport = EFalse; |
|
386 |
|
387 if ( aFileRecognitionResult.iConfidence >= CApaDataRecognizerType::EPossible ) |
|
388 { |
|
389 for ( TInt i = 0 ; i < aAudioControllers.Count() ; i++ ) |
|
390 { |
|
391 RMMFFormatImplInfoArray formats = aAudioControllers[i]->PlayFormats(); |
|
392 |
|
393 for ( TInt j = 0; j < formats.Count() ; j++ ) |
|
394 { |
|
395 if ( formats[j]->SupportsMimeType( aFileRecognitionResult.iDataType.Des8() ) ) |
|
396 { |
|
397 TPtrC8 iDataTypePtr = aFileRecognitionResult.iDataType.Des8(); |
|
398 |
|
399 if ( iDataTypePtr.Find( KDataTypeText ) == KErrNotFound ) |
|
400 { |
|
401 audioSupport = ETrue; |
|
402 } |
|
403 } |
|
404 } |
|
405 } |
|
406 } |
|
407 else |
|
408 { |
|
409 // |
|
410 // If we can't quess, try with file extension |
|
411 // |
|
412 TParsePtrC parser( aFileName ); |
|
413 TBuf8<KMaxFileName> fileExtension; |
|
414 fileExtension.Copy( parser.Ext() ); |
|
415 for ( TInt i = 0 ; i < aVideoControllers.Count() ; i++ ) |
|
416 { |
|
417 RMMFFormatImplInfoArray formats = aAudioControllers[i]->PlayFormats(); |
|
418 |
|
419 for ( TInt j = 0; j < formats.Count() ; j++) |
|
420 { |
|
421 if ( formats[j]->SupportsFileExtension( fileExtension ) ) |
|
422 { |
|
423 audioSupport = ETrue; |
|
424 } |
|
425 } |
|
426 } |
|
427 } |
|
428 |
|
429 if ( audioSupport && |
|
430 aFileRecognitionResult.iDataType.Des8().CompareF( KDataTypeRNG ) && |
|
431 aFileRecognitionResult.iDataType.Des8().CompareF( KDataTypeMp3 ) && |
|
432 aFileRecognitionResult.iDataType.Des8().CompareF( KDataTypeXmp3 ) && |
|
433 aFileRecognitionResult.iDataType.Des8().CompareF( KDataTypeAudio3gp ) ) |
|
434 { |
|
435 audioSupport = EFalse; |
|
436 } |
|
437 |
|
438 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::FileHasAudioSupport() audio support [%d]"), audioSupport); |
|
439 |
|
440 return audioSupport; |
|
441 } |
|
442 |
|
443 // ------------------------------------------------------------------------------------------------- |
|
444 // CMediaRecognizer::MimeTypeL |
|
445 // ------------------------------------------------------------------------------------------------- |
|
446 // |
|
447 EXPORT_C TBuf<KMaxDataTypeLength> CMediaRecognizer::MimeTypeL( RFile& aFile ) |
|
448 { |
|
449 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::MimeTypeL( RFile )")); |
|
450 |
|
451 if ( aFile.SubSessionHandle() ) |
|
452 { |
|
453 iFileHandle.Close(); |
|
454 // Preferred |
|
455 User::LeaveIfError( iFileHandle.Duplicate( aFile ) ); |
|
456 } |
|
457 |
|
458 // If new handle is not valid, old might still be |
|
459 if ( !FileHandleExists() ) |
|
460 { |
|
461 User::Leave( KErrBadHandle ); |
|
462 } |
|
463 |
|
464 TDataRecognitionResult fileRecognitionResult; |
|
465 RecognizeFileL( KNullDesC(), fileRecognitionResult ); |
|
466 TPtrC mimeType( KNullDesC ); |
|
467 |
|
468 if (fileRecognitionResult.iConfidence >= CApaDataRecognizerType::EPossible) |
|
469 { |
|
470 mimeType.Set( fileRecognitionResult.iDataType.Des() ); |
|
471 } |
|
472 |
|
473 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::MimeTypeL( RFile ) ret [%S]"),&mimeType); |
|
474 |
|
475 return mimeType; |
|
476 } |
|
477 |
|
478 // ------------------------------------------------------------------------------------------------- |
|
479 // CMediaRecognizer::CreateVideoFormatsArrayL |
|
480 // ------------------------------------------------------------------------------------------------- |
|
481 // |
|
482 void CMediaRecognizer::CreateVideoFormatsArrayL( RMMFControllerImplInfoArray& aVideoControllers ) |
|
483 { |
|
484 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::CreateVideoFormatsArrayL()")); |
|
485 |
|
486 CMMFControllerPluginSelectionParameters* cSelect = |
|
487 CMMFControllerPluginSelectionParameters::NewLC(); |
|
488 |
|
489 CMMFFormatSelectionParameters* fSelect = CMMFFormatSelectionParameters::NewLC(); |
|
490 |
|
491 // Set the play and record format selection parameters to be blank. |
|
492 // - format support is only retrieved if requested. |
|
493 cSelect->SetRequiredPlayFormatSupportL( *fSelect ); |
|
494 |
|
495 // Set the media ids |
|
496 RArray<TUid> mediaIds; |
|
497 CleanupClosePushL( mediaIds ); |
|
498 User::LeaveIfError( mediaIds.Append( KUidMediaTypeVideo ) ); |
|
499 |
|
500 //get plugins that support at least video |
|
501 cSelect->SetMediaIdsL( mediaIds, CMMFPluginSelectionParameters::EAllowOtherMediaIds ); |
|
502 |
|
503 // aVideoControllers contains now all plugins that support at least video |
|
504 cSelect->ListImplementationsL( aVideoControllers ); |
|
505 |
|
506 // Clean up |
|
507 CleanupStack::PopAndDestroy( 3 ); //fSelect, cSelect, mediaIds |
|
508 } |
|
509 |
|
510 // ------------------------------------------------------------------------------------------------- |
|
511 // CMediaRecognizer::CreateAudioFormatsArrayL |
|
512 // ------------------------------------------------------------------------------------------------- |
|
513 // |
|
514 void CMediaRecognizer::CreateAudioFormatsArrayL( RMMFControllerImplInfoArray& aAudioControllers ) |
|
515 { |
|
516 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::CreateAudioFormatsArrayL()")); |
|
517 |
|
518 CMMFControllerPluginSelectionParameters* cSelect = |
|
519 CMMFControllerPluginSelectionParameters::NewLC(); |
|
520 |
|
521 CMMFFormatSelectionParameters* fSelect = CMMFFormatSelectionParameters::NewLC(); |
|
522 |
|
523 // Set the play and record format selection parameters to be blank. |
|
524 // - format support is only retrieved if requested. |
|
525 cSelect->SetRequiredPlayFormatSupportL( *fSelect ); |
|
526 |
|
527 // Set the media ids |
|
528 RArray<TUid> mediaIds; |
|
529 CleanupClosePushL( mediaIds ); |
|
530 User::LeaveIfError( mediaIds.Append( KUidMediaTypeAudio ) ); |
|
531 |
|
532 // Get plugins that supports audio only |
|
533 cSelect->SetMediaIdsL( mediaIds, CMMFPluginSelectionParameters::EAllowOnlySuppliedMediaIds ); |
|
534 |
|
535 // aAudioControllers contains now all audio plugins that support at least audio. |
|
536 cSelect->ListImplementationsL( aAudioControllers ); |
|
537 |
|
538 // Clean up |
|
539 CleanupStack::PopAndDestroy( 3 ); //fSelect, cSelect, mediaIds |
|
540 } |
|
541 |
|
542 // ------------------------------------------------------------------------------------------------- |
|
543 // CMediaRecognizer::RecognizeFileL |
|
544 // ------------------------------------------------------------------------------------------------- |
|
545 // |
|
546 void CMediaRecognizer::RecognizeFileL( const TDesC& aFileName, TDataRecognitionResult& aResult ) |
|
547 { |
|
548 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::RecognizeFileL()")); |
|
549 |
|
550 aResult.Reset(); |
|
551 |
|
552 TInt bufSize( 0 ); |
|
553 RApaLsSession recognizer; |
|
554 User::LeaveIfError( recognizer.Connect() ); |
|
555 |
|
556 CleanupClosePushL( recognizer ); |
|
557 |
|
558 if ( recognizer.GetMaxDataBufSize( bufSize ) || bufSize <= 0 ) |
|
559 { |
|
560 bufSize = KDefaultBufferSize; |
|
561 } |
|
562 |
|
563 HBufC8* fBuf = HBufC8::NewLC( bufSize ); |
|
564 TPtr8 fileBuf = fBuf->Des(); |
|
565 |
|
566 // recognize file |
|
567 if ( FileHandleExists() ) |
|
568 { |
|
569 User::LeaveIfError( recognizer.RecognizeData( iFileHandle, aResult ) ); |
|
570 } |
|
571 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
572 else if ( FileHandle64Exists() ) |
|
573 { |
|
574 User::LeaveIfError( recognizer.RecognizeData( iFileHandle64, aResult ) ); |
|
575 } |
|
576 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
577 else |
|
578 { |
|
579 // read file |
|
580 User::LeaveIfError( ReadFile( aFileName, fileBuf, bufSize ) ); |
|
581 User::LeaveIfError( recognizer.RecognizeData( aFileName, fileBuf, aResult ) ); |
|
582 } |
|
583 |
|
584 CleanupStack::PopAndDestroy( 2 ); // fBuf & recognizer |
|
585 } |
|
586 |
|
587 // ------------------------------------------------------------------------------------------------- |
|
588 // CMediaRecognizer::ReadFile |
|
589 // ------------------------------------------------------------------------------------------------- |
|
590 // |
|
591 TInt CMediaRecognizer::ReadFile( const TDesC& aFileName, TDes8& aBuf, TInt aBufSize ) |
|
592 { |
|
593 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::ReadFile( %S )"), &aFileName); |
|
594 |
|
595 TInt err = KErrNone; |
|
596 |
|
597 // |
|
598 // open using 32-bit file handle |
|
599 // |
|
600 err = ReadFileViaNewFileHandle( aFileName, aBuf, aBufSize ); |
|
601 |
|
602 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
603 if ( err == KErrTooBig ) |
|
604 { |
|
605 // |
|
606 // if 32-bit file handle fails, open using 64-bit file handle |
|
607 // |
|
608 err = ReadFileViaNewFileHandle64( aFileName, aBuf, aBufSize ); |
|
609 } |
|
610 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
611 |
|
612 return err; |
|
613 } |
|
614 |
|
615 // ------------------------------------------------------------------------------------------------- |
|
616 // CMediaRecognizer::FileHandleExists |
|
617 // ------------------------------------------------------------------------------------------------- |
|
618 // |
|
619 TBool CMediaRecognizer::FileHandleExists() |
|
620 { |
|
621 TInt size = 0; |
|
622 TInt err = KErrNone; |
|
623 TBool exist = EFalse; |
|
624 |
|
625 if ( iFileHandle.SubSessionHandle() ) |
|
626 { |
|
627 err = iFileHandle.Size( size ); |
|
628 } |
|
629 |
|
630 if ( err == KErrNone && size > 0 ) |
|
631 { |
|
632 exist = ETrue; |
|
633 } |
|
634 |
|
635 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::FileHandleExists() exist [%d]"), exist); |
|
636 |
|
637 return exist; |
|
638 } |
|
639 |
|
640 //-------------------------------------------------------------------------------------------------- |
|
641 // CMediaRecognizer::IsValidStreamingPrefix |
|
642 // Check for a valid streaming prefix given a URL |
|
643 //-------------------------------------------------------------------------------------------------- |
|
644 // |
|
645 EXPORT_C TBool CMediaRecognizer::IsValidStreamingPrefix( const TDesC& aUrl ) |
|
646 { |
|
647 TBool retVal = EFalse; |
|
648 |
|
649 if ( aUrl.Length() >= KMinPrefixLength ) |
|
650 { |
|
651 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::IsValidStreamingPrefix(%S)"), &aUrl); |
|
652 |
|
653 #ifdef __WINDOWS_MEDIA |
|
654 if ( ( ! aUrl.Left(KRtspPrefix().Length()).CompareF(KRtspPrefix) ) || |
|
655 ( ! aUrl.Left(KHttpPrefix().Length()).CompareF(KHttpPrefix) ) || |
|
656 ( ! aUrl.Left(KMmsPrefix().Length()).CompareF(KMmsPrefix) ) || |
|
657 ( ! aUrl.Left(KMmstPrefix().Length()).CompareF(KMmstPrefix) ) || |
|
658 ( ! aUrl.Left(KHttpTcpPrefix().Length()).CompareF(KHttpTcpPrefix) ) || |
|
659 ( ! aUrl.Left(KRtspTcpPrefix().Length()).CompareF(KRtspTcpPrefix) ) || |
|
660 ( ! aUrl.Left(KRtspUdpPrefix().Length()).CompareF(KRtspUdpPrefix) ) ) |
|
661 #else |
|
662 if ( ! aUrl.Left( KRtspPrefix().Length() ).CompareF( KRtspPrefix ) ) |
|
663 #endif |
|
664 { |
|
665 retVal = ETrue; |
|
666 } |
|
667 } |
|
668 |
|
669 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::IsValidStreamingPrefix() ret %d"), retVal); |
|
670 |
|
671 return retVal; |
|
672 } |
|
673 |
|
674 //-------------------------------------------------------------------------------------------------- |
|
675 // CMediaRecognizer::IsValidUrlPrefix |
|
676 // Check for a valid prefix given a URL |
|
677 //-------------------------------------------------------------------------------------------------- |
|
678 // |
|
679 EXPORT_C TBool CMediaRecognizer::IsValidUrlPrefix( const TDesC& aUrl ) |
|
680 { |
|
681 TBool retVal = EFalse; |
|
682 |
|
683 if ( aUrl.Length() >= KMinPrefixLength ) |
|
684 { |
|
685 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::IsValidUrlPrefix(%S)"), &aUrl); |
|
686 |
|
687 |
|
688 if ( ( ! aUrl.Left(KFilePrefix().Length()).CompareF(KFilePrefix) ) || |
|
689 #ifdef __WINDOWS_MEDIA |
|
690 ( ! aUrl.Left(KHttpPrefix().Length()).CompareF(KHttpPrefix) ) || |
|
691 ( ! aUrl.Left(KMmsPrefix().Length()).CompareF(KMmsPrefix) ) || |
|
692 ( ! aUrl.Left(KMmstPrefix().Length()).CompareF(KMmstPrefix) ) || |
|
693 ( ! aUrl.Left(KHttpTcpPrefix().Length()).CompareF(KHttpTcpPrefix) ) || |
|
694 ( ! aUrl.Left(KRtspTcpPrefix().Length()).CompareF(KRtspTcpPrefix) ) || |
|
695 ( ! aUrl.Left(KRtspUdpPrefix().Length()).CompareF(KRtspUdpPrefix) ) || |
|
696 #endif |
|
697 ( ! aUrl.Left(KRtspPrefix().Length()).CompareF(KRtspPrefix) ) ) |
|
698 { |
|
699 retVal = ETrue; |
|
700 } |
|
701 } |
|
702 |
|
703 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::IsValidUrlPrefix() ret %d"), retVal); |
|
704 |
|
705 return retVal; |
|
706 } |
|
707 |
|
708 //-------------------------------------------------------------------------------------------------- |
|
709 // CMediaRecognizer::IsValidUrlPrefix |
|
710 // Check for a valid prefix given a URL |
|
711 //-------------------------------------------------------------------------------------------------- |
|
712 // |
|
713 EXPORT_C TBool CMediaRecognizer::IsValidUrlPrefix( const TDesC8& aUrl ) |
|
714 { |
|
715 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::IsValidUrlPrefix(TDesC8)")); |
|
716 |
|
717 TBool retVal = EFalse; |
|
718 |
|
719 if ( aUrl.Length() >= KMinPrefixLength ) |
|
720 { |
|
721 HBufC16* buf16 = NULL; |
|
722 |
|
723 TRAPD( err, buf16 = CnvUtfConverter::ConvertToUnicodeFromUtf8L(aUrl); ); |
|
724 |
|
725 if ( ! err ) |
|
726 { |
|
727 retVal = IsValidUrlPrefix( buf16->Des() ); |
|
728 delete buf16; |
|
729 } |
|
730 } |
|
731 |
|
732 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::IsValidUrlPrefix(TDesC8) ret %d"), retVal); |
|
733 |
|
734 return retVal; |
|
735 } |
|
736 |
|
737 // ------------------------------------------------------------------------------------------------- |
|
738 // CMediaRecognizer::ReadFileViaNewFileHandle |
|
739 // ------------------------------------------------------------------------------------------------- |
|
740 // |
|
741 TInt CMediaRecognizer::ReadFileViaNewFileHandle( const TDesC& aFileName, TDes8& aBuf, TInt aBufSize ) |
|
742 { |
|
743 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::ReadFileViaNewFileHandle()")); |
|
744 |
|
745 TInt err = KErrNone; |
|
746 |
|
747 RFile file; |
|
748 err = file.Open( iFs, aFileName, EFileRead | EFileShareReadersOnly ); |
|
749 |
|
750 if ( err ) |
|
751 { |
|
752 err = file.Open( iFs, aFileName, EFileRead | EFileShareAny ); |
|
753 } |
|
754 |
|
755 if ( err == KErrNone ) |
|
756 { |
|
757 // read the beginning of the file |
|
758 err = file.Read( 0, aBuf, aBufSize ); |
|
759 file.Close(); |
|
760 } |
|
761 |
|
762 return err; |
|
763 } |
|
764 |
|
765 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
766 |
|
767 // ------------------------------------------------------------------------------------------------- |
|
768 // CMediaRecognizer::IdentifyMediaTypeL |
|
769 // ------------------------------------------------------------------------------------------------- |
|
770 // |
|
771 EXPORT_C CMediaRecognizer::TMediaType |
|
772 CMediaRecognizer::IdentifyMediaTypeL( const TDesC& aMediaName, RFile64& aFile, TBool aIncludeUrls ) |
|
773 { |
|
774 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::IdentifyMediaTypeL( %S, RFile64 )"), &aMediaName); |
|
775 |
|
776 if ( aFile.SubSessionHandle() ) |
|
777 { |
|
778 iFileHandle64.Close(); |
|
779 User::LeaveIfError( iFileHandle64.Duplicate( aFile ) ); |
|
780 } |
|
781 |
|
782 TMediaType ret = EUnidentified; |
|
783 |
|
784 if ( FileHandle64Exists() ) |
|
785 { |
|
786 ret = MediaTypeL( aMediaName ); |
|
787 } |
|
788 else if ( aIncludeUrls && IsValidStreamingPrefix( aMediaName ) ) |
|
789 { |
|
790 ret = EUrl; |
|
791 } |
|
792 |
|
793 return ret; |
|
794 } |
|
795 |
|
796 // ------------------------------------------------------------------------------------------------- |
|
797 // CMediaRecognizer::MimeTypeL |
|
798 // ------------------------------------------------------------------------------------------------- |
|
799 // |
|
800 EXPORT_C TBuf<KMaxDataTypeLength> CMediaRecognizer::MimeTypeL( RFile64& aFile ) |
|
801 { |
|
802 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::MimeTypeL( RFile64 )")); |
|
803 |
|
804 if ( aFile.SubSessionHandle() ) |
|
805 { |
|
806 iFileHandle64.Close(); |
|
807 // Preferred |
|
808 User::LeaveIfError( iFileHandle64.Duplicate( aFile ) ); |
|
809 } |
|
810 |
|
811 // If new handle is not valid, old might still be |
|
812 if ( !FileHandle64Exists() ) |
|
813 { |
|
814 User::Leave( KErrBadHandle ); |
|
815 } |
|
816 |
|
817 TDataRecognitionResult fileRecognitionResult; |
|
818 RecognizeFileL( KNullDesC(), fileRecognitionResult ); |
|
819 TPtrC mimeType( KNullDesC ); |
|
820 |
|
821 if (fileRecognitionResult.iConfidence >= CApaDataRecognizerType::EPossible) |
|
822 { |
|
823 mimeType.Set( fileRecognitionResult.iDataType.Des() ); |
|
824 } |
|
825 |
|
826 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::DetermineMimeTypeL( RFile64 ) ret [%S]"), &mimeType); |
|
827 |
|
828 return mimeType; |
|
829 } |
|
830 |
|
831 |
|
832 // ------------------------------------------------------------------------------------------------- |
|
833 // CMediaRecognizer::FileHandle64Exists |
|
834 // ------------------------------------------------------------------------------------------------- |
|
835 // |
|
836 TBool CMediaRecognizer::FileHandle64Exists() |
|
837 { |
|
838 TInt64 size = 0; |
|
839 TInt err = KErrNone; |
|
840 TBool exist = EFalse; |
|
841 |
|
842 if ( iFileHandle64.SubSessionHandle() ) |
|
843 { |
|
844 err = iFileHandle64.Size( size ); |
|
845 } |
|
846 |
|
847 if ( err == KErrNone && size > 0 ) |
|
848 { |
|
849 exist = ETrue; |
|
850 } |
|
851 |
|
852 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::FileHandle64Exists() exist [%d]"), exist); |
|
853 |
|
854 return exist; |
|
855 } |
|
856 |
|
857 // ------------------------------------------------------------------------------------------------- |
|
858 // CMediaRecognizer::ReadFileViaCurrentFileHandle64 |
|
859 // ------------------------------------------------------------------------------------------------- |
|
860 // |
|
861 TInt CMediaRecognizer::ReadFileViaNewFileHandle64( const TDesC& aFileName, TDes8& aBuf, TInt aBufSize ) |
|
862 { |
|
863 PLAYBACKHELPER_DEBUG(_L("CMediaRecognizer::ReadFileViaNewFileHandle64()")); |
|
864 |
|
865 TInt err = KErrNone; |
|
866 |
|
867 RFile64 file; |
|
868 err = file.Open( iFs, aFileName, EFileRead | EFileShareReadersOnly ); |
|
869 |
|
870 if ( err ) |
|
871 { |
|
872 err = file.Open( iFs, aFileName, EFileRead | EFileShareAny ); |
|
873 } |
|
874 |
|
875 if ( err == KErrNone ) |
|
876 { |
|
877 // read the beginning of the file |
|
878 err = file.Read( 0, aBuf, aBufSize ); |
|
879 file.Close(); |
|
880 } |
|
881 |
|
882 return err; |
|
883 } |
|
884 |
|
885 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
886 |
|
887 |
|
888 |
|
889 // End of File |