mmappcomponents/mmmtpdataprovider/src/mmmtpdputility.cpp
changeset 27 cbb1bfb7ebfb
parent 25 d881023c13eb
child 32 edd273b3192a
equal deleted inserted replaced
25:d881023c13eb 27:cbb1bfb7ebfb
    36 
    36 
    37 #include "mmmtpdputility.h"
    37 #include "mmmtpdputility.h"
    38 #include "mmmtpdpfiledefs.h"
    38 #include "mmmtpdpfiledefs.h"
    39 #include "tobjectdescription.h"
    39 #include "tobjectdescription.h"
    40 #include "mmmtpdplogger.h"
    40 #include "mmmtpdplogger.h"
       
    41 #include "mmmtpdp_variant.hrh"
    41 
    42 
    42 using namespace ContentAccess;
    43 using namespace ContentAccess;
    43 
    44 
    44 // local to this file, non standard mimetype used for ASF parsing with helix
    45 // local to this file, non standard mimetype used for ASF parsing with helix
    45 _LIT( KHxMimeTypeWma, "audio/x-hx-wma" );
    46 _LIT( KHxMimeTypeWma, "audio/x-hx-wma" );
    55 // These should be kept in sync with the object formats supported
    56 // These should be kept in sync with the object formats supported
    56 // -----------------------------------------------------------------------------
    57 // -----------------------------------------------------------------------------
    57 //
    58 //
    58 EXPORT_C TMTPFormatCode MmMtpDpUtility::FormatFromFilename( const TDesC& aFullFileName )
    59 EXPORT_C TMTPFormatCode MmMtpDpUtility::FormatFromFilename( const TDesC& aFullFileName )
    59     {
    60     {
       
    61     TMTPFormatCode format = EMTPFormatCodeUndefined;
       
    62 
    60     if ( aFullFileName.Right( 1 ).CompareF( KTxtBackSlash ) == 0 ) // We have a directory name
    63     if ( aFullFileName.Right( 1 ).CompareF( KTxtBackSlash ) == 0 ) // We have a directory name
    61         {
    64         {
    62         return EMTPFormatCodeAssociation;
    65         format = EMTPFormatCodeAssociation;
    63         }
    66         }
    64 
    67     else 
    65     TParsePtrC file( aFullFileName );
    68         {
    66 
    69         TParsePtrC file( aFullFileName );
    67     if ( !file.ExtPresent() )
    70 
    68         return EMTPFormatCodeUndefined;
    71         if ( file.ExtPresent() )
    69 
    72             {
    70     // need to do it in popularity of format, to optmize performance
    73             // need to do it in popularity of format, to optmize performance
    71     if ( file.Ext().CompareF( KTxtExtensionMP3 ) == 0 )
    74             if ( file.Ext().CompareF( KTxtExtensionMP3 ) == 0 )
    72             return EMTPFormatCodeMP3;
    75                 format = EMTPFormatCodeMP3;
    73 
       
    74 #ifdef __WINDOWS_MEDIA
    76 #ifdef __WINDOWS_MEDIA
    75     if ( file.Ext().CompareF( KTxtExtensionWMA ) == 0 )
    77             else if ( file.Ext().CompareF( KTxtExtensionWMA ) == 0 )
    76             return EMTPFormatCodeWMA;
    78                 format = EMTPFormatCodeWMA;
    77 #endif // __WINDOWS_MEDIA
    79 #endif // __WINDOWS_MEDIA
    78 
    80             else if (( file.Ext().CompareF( KTxtExtensionPLA ) == 0 ) 
    79     if ( ( file.Ext().CompareF( KTxtExtensionMP4 ) == 0 )
    81                 || ( file.Ext().CompareF( KTxtExtensionVIR ) == 0 ) )
    80         || ( file.Ext().CompareF( KTxtExtensionM4A ) == 0 ) )
    82                 format = EMTPFormatCodeAbstractAudioVideoPlaylist;
    81         return EMTPFormatCodeMP4Container;
    83             else if ( ( file.Ext().CompareF( KTxtExtensionMP4 ) == 0 )
    82 
    84                 || ( file.Ext().CompareF( KTxtExtensionM4A ) == 0 ) )
    83     if ( ( file.Ext().CompareF( KTxtExtension3GP ) == 0 )
    85                 format = EMTPFormatCodeMP4Container;
    84         || ( file.Ext().CompareF( KTxtExtension3G2 ) == 0 )
    86             else if ( ( file.Ext().CompareF( KTxtExtension3GP ) == 0 )
    85         || ( file.Ext().CompareF( KTxtExtensionO4A ) == 0 )
    87                 || ( file.Ext().CompareF( KTxtExtension3G2 ) == 0 )
    86         || ( file.Ext().CompareF( KTxtExtensionO4V ) == 0 ) )
    88                 || ( file.Ext().CompareF( KTxtExtensionO4A ) == 0 )
    87         return EMTPFormatCode3GPContainer;
    89                 || ( file.Ext().CompareF( KTxtExtensionO4V ) == 0 ) )
    88 
    90                 format = EMTPFormatCode3GPContainer;
    89     if ( file.Ext().CompareF( KTxtExtensionAAC ) == 0 )
    91             else if ( file.Ext().CompareF( KTxtExtensionAAC ) == 0 )
    90         return EMTPFormatCodeAAC;
    92                 format = EMTPFormatCodeAAC;
    91 
    93             else if ( file.Ext().CompareF( KTxtExtensionWAV ) == 0 )
    92     if ( file.Ext().CompareF( KTxtExtensionWAV ) == 0 )
    94                 format = EMTPFormatCodeWAV;
    93         return EMTPFormatCodeWAV;
       
    94 
       
    95 #ifdef __WINDOWS_MEDIA
    95 #ifdef __WINDOWS_MEDIA
    96     if ( file.Ext().CompareF( KTxtExtensionWMV ) == 0 )
    96             else if ( file.Ext().CompareF( KTxtExtensionWMV ) == 0 )
    97         return EMTPFormatCodeWMV;
    97                 format = EMTPFormatCodeWMV;
    98 
    98             else if ( file.Ext().CompareF( KTxtExtensionASF ) == 0 )
    99     if ( file.Ext().CompareF( KTxtExtensionASF ) == 0 )
    99                 format = EMTPFormatCodeASF;
   100         return EMTPFormatCodeASF;
       
   101 
       
   102 #endif // __WINDOWS_MEDIA
   100 #endif // __WINDOWS_MEDIA
   103 
   101             else if ( file.Ext().CompareF( KTxtExtensionODF ) == 0 )
   104     if ( file.Ext().CompareF( KTxtExtensionODF ) == 0 )
   102                 {
   105         {
   103                 HBufC8* mime = MmMtpDpUtility::OdfMimeTypeL( file.FullName() );
   106         HBufC8* mime = MmMtpDpUtility::ContainerMimeType( file.FullName() );
   104                 if ( mime != NULL )
   107         if ( mime != NULL )
   105                     {
   108             {
   106                     // 3GP
   109             // 3GP
   107                     if ( mime->CompareF( KMimeTypeAudio3gpp ) == 0
   110             if ( mime->CompareF( KMimeTypeAudio3gpp ) == 0
   108                         || mime->CompareF( KMimeTypeVideo3gpp ) == 0 )
   111                 || mime->CompareF( KMimeTypeVideo3gpp ) == 0 )
   109                         {
   112                 {
   110                         delete mime;
   113                 delete mime;
   111                         mime = NULL;
   114                 mime = NULL;
   112                         format = EMTPFormatCode3GPContainer;
   115                 return EMTPFormatCode3GPContainer;
   113                         }
   116                 }
   114                     }
   117             }
   115 
   118 
   116                 if ( mime != NULL )
   119         if ( mime != NULL )
   117                     {
   120             {
   118                     delete mime;
   121             delete mime;
   119                     mime = NULL;
   122             mime = NULL;
   120                     }
   123             }
   121                 }
   124         }
   122 #ifdef MMMTPDP_ABSTRACTAUDIOALBUM_SUPPORT
   125 
   123             else if ( file.Ext().CompareF( KTxtExtensionALB ) == 0 )
   126     if ( file.Ext().CompareF( KTxtExtensionALB ) == 0 )
   124                 format = EMTPFormatCodeAbstractAudioAlbum;
   127         return EMTPFormatCodeAbstractAudioAlbum;
   125 #endif // MMMTPDP_ABSTRACTAUDIOALBUM_SUPPORT
   128 
   126             else if ( file.Ext().CompareF( KTxtExtensionM3U ) == 0 )
   129     if (( file.Ext().CompareF( KTxtExtensionPLA ) == 0 ) || ( file.Ext().CompareF( KTxtExtensionVIR ) == 0 ) )
   127                 format = EMTPFormatCodeM3UPlaylist;
   130         return EMTPFormatCodeAbstractAudioVideoPlaylist;
   128             }
   131 
   129         }
   132     if ( file.Ext().CompareF( KTxtExtensionM3U ) == 0 )
   130 
   133         return EMTPFormatCodeM3UPlaylist;
   131     return format;
   134 
       
   135     return EMTPFormatCodeUndefined;
       
   136     }
   132     }
   137 
   133 
   138 // -----------------------------------------------------------------------------
   134 // -----------------------------------------------------------------------------
   139 // MmMtpDpUtility::HasMetadata
   135 // MmMtpDpUtility::HasMetadata
   140 // Utility function to determine whether a format has metadata support
   136 // Utility function to determine whether a format has metadata support
   411 
   407 
   412     return ret;
   408     return ret;
   413     }
   409     }
   414 
   410 
   415 // -----------------------------------------------------------------------------
   411 // -----------------------------------------------------------------------------
   416 // MetadataAccessWrapper::ContainerMimeType
       
   417 // Get mime type from file
       
   418 // -----------------------------------------------------------------------------
       
   419 //
       
   420 HBufC8* MmMtpDpUtility::ContainerMimeType( const TDesC& aFullPath )
       
   421     {
       
   422     PRINT( _L( "MM MTP => MmMtpDpUtility::ContainerMimeType" ) );
       
   423 
       
   424     // parse the file path
       
   425     TParsePtrC pathParser( aFullPath );
       
   426 
       
   427     // get the extension of file
       
   428     TPtrC ext( pathParser.Ext() );
       
   429     if ( ext.Length() <= 0 )
       
   430         {
       
   431         PRINT( _L( "MM MTP <> MmMtpDpUtility::ContainerMimeType file ext len == 0" ) );
       
   432         return NULL;
       
   433         }
       
   434 
       
   435     HBufC8* mimebuf = NULL;
       
   436     TInt err = KErrNone;
       
   437 
       
   438     // MP4/3GP
       
   439     if ( ext.CompareF( KTxtExtensionMP4 ) == 0
       
   440         || ext.CompareF( KTxtExtension3GP ) == 0
       
   441         || ext.CompareF( KTxtExtension3G2 ) == 0 )
       
   442         {
       
   443         TRAP( err, mimebuf = Mp4MimeTypeL( aFullPath ) );
       
   444         PRINT1( _L("MM MTP <> MmMtpDpUtility::ContainerMimeType, Mp4MimeTypeL err = %d"), err );
       
   445         }
       
   446     else if ( ext.CompareF( KTxtExtensionODF ) == 0 )
       
   447         {
       
   448         TRAP( err, mimebuf = OdfMimeTypeL( aFullPath ) );
       
   449         PRINT1( _L("MM MTP <> MmMtpDpUtility::ContainerMimeType, OdfMimeTypeL err = %d"), err );
       
   450         }
       
   451 #ifdef __WINDOWS_MEDIA
       
   452     else if ( ext.CompareF( KTxtExtensionASF ) == 0 )
       
   453         {
       
   454         TRAP( err, mimebuf = AsfMimeTypeL( aFullPath ) );
       
   455         PRINT1( _L("MM MTP <> MmMtpDpUtility::ContainerMimeType, AsfMimeTypeL err = %d"), err );
       
   456         }
       
   457 #endif
       
   458 
       
   459     PRINT( _L( "MM MTP <= MmMtpDpUtility::ContainerMimeType" ) );
       
   460     return mimebuf;
       
   461     }
       
   462 
       
   463 // -----------------------------------------------------------------------------
       
   464 // MetadataAccessWrapper::Mp4MimeTypeL
   412 // MetadataAccessWrapper::Mp4MimeTypeL
   465 // Get mime type from mp4 file
   413 // Get mime type from mp4 file
   466 // -----------------------------------------------------------------------------
   414 // -----------------------------------------------------------------------------
   467 //
   415 //
   468 HBufC8* MmMtpDpUtility::Mp4MimeTypeL( const TDesC& aFullPath )
   416 HBufC8* MmMtpDpUtility::Mp4MimeTypeL( const TDesC& aFullPath )
   521                     }
   469                     }
   522                 }
   470                 }
   523             // is video file
   471             // is video file
   524             else if ( mp4err == MP4_OK )
   472             else if ( mp4err == MP4_OK )
   525                 {
   473                 {
   526                 if ( file.Ext().CompareF( KTxtExtension3GP ) == 0 
   474                 if ( file.Ext().CompareF( KTxtExtension3GP ) == 0
   527                     || file.Ext().CompareF( KTxtExtension3G2 ) == 0 )
   475                     || file.Ext().CompareF( KTxtExtension3G2 ) == 0 )
   528                     {
   476                     {
   529                     mimebuf = KMimeTypeVideo3gpp().Alloc();
   477                     mimebuf = KMimeTypeVideo3gpp().Alloc();
   530                     }
   478                     }
   531                 else
   479                 else
   564 HBufC8* MmMtpDpUtility::OdfMimeTypeL( const TDesC& aFullPath )
   512 HBufC8* MmMtpDpUtility::OdfMimeTypeL( const TDesC& aFullPath )
   565     {
   513     {
   566     PRINT( _L( "MM MTP => MmMtpDpUtility::OdfMimeTypeL" ) );
   514     PRINT( _L( "MM MTP => MmMtpDpUtility::OdfMimeTypeL" ) );
   567     HBufC8* mimebuf = NULL;
   515     HBufC8* mimebuf = NULL;
   568 
   516 
   569     TParsePtrC file( aFullPath );
   517     CContent* content = CContent::NewL( aFullPath );
   570 
   518     CleanupStack::PushL( content ); // + content
   571     if ( file.Ext().CompareF( KTxtExtensionODF ) == 0 )
   519 
   572         {
   520     HBufC* buffer = HBufC::NewL( KMimeTypeMaxLength );
   573         CContent* content = CContent::NewL( aFullPath );
   521     CleanupStack::PushL( buffer ); // + buffer
   574         CleanupStack::PushL( content ); // + content
   522 
   575 
   523     TPtr data = buffer->Des();
   576         HBufC* buffer = HBufC::NewL( KMimeTypeMaxLength );
   524     TInt err = content->GetStringAttribute( EMimeType, data );
   577         CleanupStack::PushL( buffer ); // + buffer
   525 
   578 
   526     if ( err == KErrNone )
   579         TPtr data = buffer->Des();
   527         {
   580         TInt err = content->GetStringAttribute( EMimeType, data );
   528         mimebuf = HBufC8::New( buffer->Length() );
   581 
   529 
   582         if ( err == KErrNone )
       
   583             {
       
   584             mimebuf = HBufC8::New( buffer->Length() );
       
   585 
       
   586             if (mimebuf == NULL)
       
   587                 {
       
   588                 User::LeaveIfError( KErrNotFound );
       
   589                 }
       
   590 
       
   591             mimebuf->Des().Copy( *buffer );
       
   592             }
       
   593 
       
   594         // leave if NULL
       
   595         if ( mimebuf == NULL )
   530         if ( mimebuf == NULL )
   596             {
   531             {
   597             User::Leave( KErrNotFound );
   532             User::LeaveIfError( KErrNotFound );
   598             }
   533             }
   599 
   534 
   600         CleanupStack::PopAndDestroy( buffer ); // - buffer
   535         mimebuf->Des().Copy( *buffer );
   601         CleanupStack::PopAndDestroy( content ); // - content
   536         }
   602         }
   537 
   603     else
   538     // leave if NULL
   604         {
   539     if ( mimebuf == NULL )
   605         User::Leave( KErrNotSupported );
   540         {
   606         }
   541         User::Leave( KErrNotFound );
       
   542         }
       
   543 
       
   544     CleanupStack::PopAndDestroy( buffer ); // - buffer
       
   545     CleanupStack::PopAndDestroy( content ); // - content
   607 
   546 
   608     PRINT( _L( "MM MTP <= MmMtpDpUtility::OdfMimeTypeL" ) );
   547     PRINT( _L( "MM MTP <= MmMtpDpUtility::OdfMimeTypeL" ) );
   609     return mimebuf;
   548     return mimebuf;
   610     }
   549     }
   611 
   550 
   619     PRINT1( _L( "MM MTP => MmMtpDpUtility::AsfMimeTypeL, aFullPath = %S" ), &aFullPath );
   558     PRINT1( _L( "MM MTP => MmMtpDpUtility::AsfMimeTypeL, aFullPath = %S" ), &aFullPath );
   620 
   559 
   621     HBufC8* mimebuf = NULL;
   560     HBufC8* mimebuf = NULL;
   622 
   561 
   623 #ifdef __WINDOWS_MEDIA
   562 #ifdef __WINDOWS_MEDIA
   624     TParsePtrC file( aFullPath );
   563     CHXMetaDataUtility *hxUtility = CHXMetaDataUtility::NewL();
   625 
   564     CleanupStack::PushL( hxUtility );
   626     if ( file.Ext().CompareF( KTxtExtensionASF ) == 0 )
   565 
   627         {
   566     hxUtility->OpenFileL( aFullPath );
   628         CHXMetaDataUtility *hxUtility = CHXMetaDataUtility::NewL();
   567     PRINT( _L( "MM MTP <> MmMtpDpUtility::AsfMimeTypeL OpenFileL" ) );
   629         CleanupStack::PushL( hxUtility );
   568 
   630 
   569     HXMetaDataKeys::EHXMetaDataId id;
   631         hxUtility->OpenFileL( aFullPath );
   570     TUint count = 0;
   632         PRINT( _L( "MM MTP <> MmMtpDpUtility::AsfMimeTypeL OpenFileL" ) );
   571     TBool isAudio = EFalse;
   633 
   572     hxUtility->GetMetaDataCount( count );
   634         HXMetaDataKeys::EHXMetaDataId id;
   573     for ( TUint i = 0; i < count; i++ )
   635         TUint count = 0;
   574         {
   636         TBool isAudio = EFalse;
   575         HBufC* buf = NULL;
   637         hxUtility->GetMetaDataCount( count );
   576         hxUtility->GetMetaDataAt( i, id, buf );
   638         for ( TUint i = 0; i < count; i++ )
   577 
   639             {
   578         if ( id == HXMetaDataKeys::EHXMimeType )
   640             HBufC* buf = NULL;
   579             {
   641             hxUtility->GetMetaDataAt( i, id, buf );
   580             TPtr des = buf->Des();
   642 
   581 
   643             if ( id == HXMetaDataKeys::EHXMimeType )
   582             if ( des.Find( KHxMimeTypeWma() ) != KErrNotFound )
   644                 {
   583                 {
   645                 TPtr des = buf->Des();
   584                 isAudio = ETrue;
   646 
   585                 }
   647                 if ( des.Find( KHxMimeTypeWma() ) != KErrNotFound )
   586             else if ( des.Find( KHxMimeTypeWmv() ) != KErrNotFound )
   648                     {
   587                 {
   649                     isAudio = ETrue;
   588                 PRINT( _L( "MM MTP <> MmMtpDpUtility::AsfMimeTypeL, video" ) );
   650                     }
   589                 mimebuf = KMimeTypeVideoWm().Alloc();
   651                 else if ( des.Find( KHxMimeTypeWmv() ) != KErrNotFound )
   590                 break;
   652                     {
   591                 }
   653                     PRINT( _L( "MM MTP <> MmMtpDpUtility::AsfMimeTypeL, video" ) );
   592             }
   654                     mimebuf = KMimeTypeVideoWm().Alloc();
   593         else if ( i == count - 1 )
   655                     break;
   594             {
   656                     }
   595             if ( isAudio )
   657                 }
   596                 {
   658             else if ( i == count - 1 )
   597                 PRINT( _L( "MM MTP <> MmMtpDpUtility::AsfMimeTypeL, audio" ) );
   659                 {
   598                 mimebuf = KMimeTypeAudioWm().Alloc();
   660                 if ( isAudio )
   599                 }
   661                     {
   600             else
   662                     PRINT( _L( "MM MTP <> MmMtpDpUtility::AsfMimeTypeL, audio" ) );
   601                 {
   663                     mimebuf = KMimeTypeAudioWm().Alloc();
   602                 User::Leave( KErrNotFound );
   664                     }
   603                 }
   665                 else
   604             }
   666                     {
   605         }
   667                     User::Leave( KErrNotFound );
   606 
   668                     }
   607     hxUtility->ResetL();
   669                 }
   608     CleanupStack::PopAndDestroy( hxUtility );
   670             }
       
   671 
       
   672         hxUtility->ResetL();
       
   673         CleanupStack::PopAndDestroy( hxUtility );
       
   674         }
       
   675     else
       
   676         {
       
   677         User::Leave( KErrNotSupported );
       
   678         }
       
   679 
       
   680 #else
   609 #else
   681     User::Leave( KErrNotSupported );
   610     User::Leave( KErrNotSupported );
   682 #endif
   611 #endif
   683 
   612 
   684     PRINT( _L( "MM MTP <= MmMtpDpUtility::AsfMimeTypeL" ) );
   613     PRINT( _L( "MM MTP <= MmMtpDpUtility::AsfMimeTypeL" ) );
   715         subFormatCode = EMTPSubFormatCodeAudio;
   644         subFormatCode = EMTPSubFormatCodeAudio;
   716         }
   645         }
   717     else
   646     else
   718         {
   647         {
   719         PRINT( _L( "MM MTP <= MmMtpDpUtility::SubFormatCodeFromMime format not supported" ) );
   648         PRINT( _L( "MM MTP <= MmMtpDpUtility::SubFormatCodeFromMime format not supported" ) );
   720         subFormatCode = EMTPSubFormatCodeUndefine;
   649         subFormatCode = EMTPSubFormatCodeUndefined;
   721         }
   650         }
   722 
   651 
   723     PRINT1( _L( "MM MTP <= MmMtpDpUtility::SubFormatCodeFromMime SubFormatCode = %d" ), subFormatCode );
   652     PRINT1( _L( "MM MTP <= MmMtpDpUtility::SubFormatCodeFromMime SubFormatCode = %d" ), subFormatCode );
   724 
   653 
   725     return subFormatCode;
   654     return subFormatCode;