mmappcomponents/mmmtpdataprovider/src/mmmtpdputility.cpp
branchRCL_3
changeset 23 4740b34b83ce
parent 19 51035f0751c2
child 28 f56ec6ce2732
equal deleted inserted replaced
19:51035f0751c2 23:4740b34b83ce
    98             else if ( file.Ext().CompareF( KTxtExtensionASF ) == 0 )
    98             else if ( file.Ext().CompareF( KTxtExtensionASF ) == 0 )
    99                 format = EMTPFormatCodeASF;
    99                 format = EMTPFormatCodeASF;
   100 #endif // __WINDOWS_MEDIA
   100 #endif // __WINDOWS_MEDIA
   101             else if ( file.Ext().CompareF( KTxtExtensionODF ) == 0 )
   101             else if ( file.Ext().CompareF( KTxtExtensionODF ) == 0 )
   102                 {
   102                 {
   103                 HBufC8* mime = MmMtpDpUtility::ContainerMimeType( file.FullName() );
   103                 HBufC8* mime = MmMtpDpUtility::OdfMimeTypeL( file.FullName() );
   104                 if ( mime != NULL )
   104                 if ( mime != NULL )
   105                     {
   105                     {
   106                     // 3GP
   106                     // 3GP
   107                     if ( mime->CompareF( KMimeTypeAudio3gpp ) == 0
   107                     if ( mime->CompareF( KMimeTypeAudio3gpp ) == 0
   108                         || mime->CompareF( KMimeTypeVideo3gpp ) == 0 )
   108                         || mime->CompareF( KMimeTypeVideo3gpp ) == 0 )
   407 
   407 
   408     return ret;
   408     return ret;
   409     }
   409     }
   410 
   410 
   411 // -----------------------------------------------------------------------------
   411 // -----------------------------------------------------------------------------
   412 // MetadataAccessWrapper::ContainerMimeType
       
   413 // Get mime type from file
       
   414 // -----------------------------------------------------------------------------
       
   415 //
       
   416 HBufC8* MmMtpDpUtility::ContainerMimeType( const TDesC& aFullPath )
       
   417     {
       
   418     PRINT( _L( "MM MTP => MmMtpDpUtility::ContainerMimeType" ) );
       
   419 
       
   420     // parse the file path
       
   421     TParsePtrC pathParser( aFullPath );
       
   422 
       
   423     // get the extension of file
       
   424     TPtrC ext( pathParser.Ext() );
       
   425     if ( ext.Length() <= 0 )
       
   426         {
       
   427         PRINT( _L( "MM MTP <> MmMtpDpUtility::ContainerMimeType file ext len == 0" ) );
       
   428         return NULL;
       
   429         }
       
   430 
       
   431     HBufC8* mimebuf = NULL;
       
   432     TInt err = KErrNone;
       
   433 
       
   434     // MP4/3GP
       
   435     if ( ext.CompareF( KTxtExtensionMP4 ) == 0
       
   436         || ext.CompareF( KTxtExtension3GP ) == 0
       
   437         || ext.CompareF( KTxtExtension3G2 ) == 0 )
       
   438         {
       
   439         TRAP( err, mimebuf = Mp4MimeTypeL( aFullPath ) );
       
   440         PRINT1( _L("MM MTP <> MmMtpDpUtility::ContainerMimeType, Mp4MimeTypeL err = %d"), err );
       
   441         }
       
   442     else if ( ext.CompareF( KTxtExtensionODF ) == 0 )
       
   443         {
       
   444         TRAP( err, mimebuf = OdfMimeTypeL( aFullPath ) );
       
   445         PRINT1( _L("MM MTP <> MmMtpDpUtility::ContainerMimeType, OdfMimeTypeL err = %d"), err );
       
   446         }
       
   447 #ifdef __WINDOWS_MEDIA
       
   448     else if ( ext.CompareF( KTxtExtensionASF ) == 0 )
       
   449         {
       
   450         TRAP( err, mimebuf = AsfMimeTypeL( aFullPath ) );
       
   451         PRINT1( _L("MM MTP <> MmMtpDpUtility::ContainerMimeType, AsfMimeTypeL err = %d"), err );
       
   452         }
       
   453 #endif
       
   454 
       
   455     PRINT( _L( "MM MTP <= MmMtpDpUtility::ContainerMimeType" ) );
       
   456     return mimebuf;
       
   457     }
       
   458 
       
   459 // -----------------------------------------------------------------------------
       
   460 // MetadataAccessWrapper::Mp4MimeTypeL
   412 // MetadataAccessWrapper::Mp4MimeTypeL
   461 // Get mime type from mp4 file
   413 // Get mime type from mp4 file
   462 // -----------------------------------------------------------------------------
   414 // -----------------------------------------------------------------------------
   463 //
   415 //
   464 HBufC8* MmMtpDpUtility::Mp4MimeTypeL( const TDesC& aFullPath )
   416 HBufC8* MmMtpDpUtility::Mp4MimeTypeL( const TDesC& aFullPath )
   517                     }
   469                     }
   518                 }
   470                 }
   519             // is video file
   471             // is video file
   520             else if ( mp4err == MP4_OK )
   472             else if ( mp4err == MP4_OK )
   521                 {
   473                 {
   522                 if ( file.Ext().CompareF( KTxtExtension3GP ) == 0 
   474                 if ( file.Ext().CompareF( KTxtExtension3GP ) == 0
   523                     || file.Ext().CompareF( KTxtExtension3G2 ) == 0 )
   475                     || file.Ext().CompareF( KTxtExtension3G2 ) == 0 )
   524                     {
   476                     {
   525                     mimebuf = KMimeTypeVideo3gpp().Alloc();
   477                     mimebuf = KMimeTypeVideo3gpp().Alloc();
   526                     }
   478                     }
   527                 else
   479                 else
   560 HBufC8* MmMtpDpUtility::OdfMimeTypeL( const TDesC& aFullPath )
   512 HBufC8* MmMtpDpUtility::OdfMimeTypeL( const TDesC& aFullPath )
   561     {
   513     {
   562     PRINT( _L( "MM MTP => MmMtpDpUtility::OdfMimeTypeL" ) );
   514     PRINT( _L( "MM MTP => MmMtpDpUtility::OdfMimeTypeL" ) );
   563     HBufC8* mimebuf = NULL;
   515     HBufC8* mimebuf = NULL;
   564 
   516 
   565     TParsePtrC file( aFullPath );
   517     CContent* content = CContent::NewL( aFullPath );
   566 
   518     CleanupStack::PushL( content ); // + content
   567     if ( file.Ext().CompareF( KTxtExtensionODF ) == 0 )
   519 
   568         {
   520     HBufC* buffer = HBufC::NewL( KMimeTypeMaxLength );
   569         CContent* content = CContent::NewL( aFullPath );
   521     CleanupStack::PushL( buffer ); // + buffer
   570         CleanupStack::PushL( content ); // + content
   522 
   571 
   523     TPtr data = buffer->Des();
   572         HBufC* buffer = HBufC::NewL( KMimeTypeMaxLength );
   524     TInt err = content->GetStringAttribute( EMimeType, data );
   573         CleanupStack::PushL( buffer ); // + buffer
   525 
   574 
   526     if ( err == KErrNone )
   575         TPtr data = buffer->Des();
   527         {
   576         TInt err = content->GetStringAttribute( EMimeType, data );
   528         mimebuf = HBufC8::New( buffer->Length() );
   577 
   529 
   578         if ( err == KErrNone )
       
   579             {
       
   580             mimebuf = HBufC8::New( buffer->Length() );
       
   581 
       
   582             if (mimebuf == NULL)
       
   583                 {
       
   584                 User::LeaveIfError( KErrNotFound );
       
   585                 }
       
   586 
       
   587             mimebuf->Des().Copy( *buffer );
       
   588             }
       
   589 
       
   590         // leave if NULL
       
   591         if ( mimebuf == NULL )
   530         if ( mimebuf == NULL )
   592             {
   531             {
   593             User::Leave( KErrNotFound );
   532             User::LeaveIfError( KErrNotFound );
   594             }
   533             }
   595 
   534 
   596         CleanupStack::PopAndDestroy( buffer ); // - buffer
   535         mimebuf->Des().Copy( *buffer );
   597         CleanupStack::PopAndDestroy( content ); // - content
   536         }
   598         }
   537 
   599     else
   538     // leave if NULL
   600         {
   539     if ( mimebuf == NULL )
   601         User::Leave( KErrNotSupported );
   540         {
   602         }
   541         User::Leave( KErrNotFound );
       
   542         }
       
   543 
       
   544     CleanupStack::PopAndDestroy( buffer ); // - buffer
       
   545     CleanupStack::PopAndDestroy( content ); // - content
   603 
   546 
   604     PRINT( _L( "MM MTP <= MmMtpDpUtility::OdfMimeTypeL" ) );
   547     PRINT( _L( "MM MTP <= MmMtpDpUtility::OdfMimeTypeL" ) );
   605     return mimebuf;
   548     return mimebuf;
   606     }
   549     }
   607 
   550 
   615     PRINT1( _L( "MM MTP => MmMtpDpUtility::AsfMimeTypeL, aFullPath = %S" ), &aFullPath );
   558     PRINT1( _L( "MM MTP => MmMtpDpUtility::AsfMimeTypeL, aFullPath = %S" ), &aFullPath );
   616 
   559 
   617     HBufC8* mimebuf = NULL;
   560     HBufC8* mimebuf = NULL;
   618 
   561 
   619 #ifdef __WINDOWS_MEDIA
   562 #ifdef __WINDOWS_MEDIA
   620     TParsePtrC file( aFullPath );
   563     CHXMetaDataUtility *hxUtility = CHXMetaDataUtility::NewL();
   621 
   564     CleanupStack::PushL( hxUtility );
   622     if ( file.Ext().CompareF( KTxtExtensionASF ) == 0 )
   565 
   623         {
   566     hxUtility->OpenFileL( aFullPath );
   624         CHXMetaDataUtility *hxUtility = CHXMetaDataUtility::NewL();
   567     PRINT( _L( "MM MTP <> MmMtpDpUtility::AsfMimeTypeL OpenFileL" ) );
   625         CleanupStack::PushL( hxUtility );
   568 
   626 
   569     HXMetaDataKeys::EHXMetaDataId id;
   627         hxUtility->OpenFileL( aFullPath );
   570     TUint count = 0;
   628         PRINT( _L( "MM MTP <> MmMtpDpUtility::AsfMimeTypeL OpenFileL" ) );
   571     TBool isAudio = EFalse;
   629 
   572     hxUtility->GetMetaDataCount( count );
   630         HXMetaDataKeys::EHXMetaDataId id;
   573     for ( TUint i = 0; i < count; i++ )
   631         TUint count = 0;
   574         {
   632         TBool isAudio = EFalse;
   575         HBufC* buf = NULL;
   633         hxUtility->GetMetaDataCount( count );
   576         hxUtility->GetMetaDataAt( i, id, buf );
   634         for ( TUint i = 0; i < count; i++ )
   577 
   635             {
   578         if ( id == HXMetaDataKeys::EHXMimeType )
   636             HBufC* buf = NULL;
   579             {
   637             hxUtility->GetMetaDataAt( i, id, buf );
   580             TPtr des = buf->Des();
   638 
   581 
   639             if ( id == HXMetaDataKeys::EHXMimeType )
   582             if ( des.Find( KHxMimeTypeWma() ) != KErrNotFound )
   640                 {
   583                 {
   641                 TPtr des = buf->Des();
   584                 isAudio = ETrue;
   642 
   585                 }
   643                 if ( des.Find( KHxMimeTypeWma() ) != KErrNotFound )
   586             else if ( des.Find( KHxMimeTypeWmv() ) != KErrNotFound )
   644                     {
   587                 {
   645                     isAudio = ETrue;
   588                 PRINT( _L( "MM MTP <> MmMtpDpUtility::AsfMimeTypeL, video" ) );
   646                     }
   589                 mimebuf = KMimeTypeVideoWm().Alloc();
   647                 else if ( des.Find( KHxMimeTypeWmv() ) != KErrNotFound )
   590                 break;
   648                     {
   591                 }
   649                     PRINT( _L( "MM MTP <> MmMtpDpUtility::AsfMimeTypeL, video" ) );
   592             }
   650                     mimebuf = KMimeTypeVideoWm().Alloc();
   593         else if ( i == count - 1 )
   651                     break;
   594             {
   652                     }
   595             if ( isAudio )
   653                 }
   596                 {
   654             else if ( i == count - 1 )
   597                 PRINT( _L( "MM MTP <> MmMtpDpUtility::AsfMimeTypeL, audio" ) );
   655                 {
   598                 mimebuf = KMimeTypeAudioWm().Alloc();
   656                 if ( isAudio )
   599                 }
   657                     {
   600             else
   658                     PRINT( _L( "MM MTP <> MmMtpDpUtility::AsfMimeTypeL, audio" ) );
   601                 {
   659                     mimebuf = KMimeTypeAudioWm().Alloc();
   602                 User::Leave( KErrNotFound );
   660                     }
   603                 }
   661                 else
   604             }
   662                     {
   605         }
   663                     User::Leave( KErrNotFound );
   606 
   664                     }
   607     hxUtility->ResetL();
   665                 }
   608     CleanupStack::PopAndDestroy( hxUtility );
   666             }
       
   667 
       
   668         hxUtility->ResetL();
       
   669         CleanupStack::PopAndDestroy( hxUtility );
       
   670         }
       
   671     else
       
   672         {
       
   673         User::Leave( KErrNotSupported );
       
   674         }
       
   675 
       
   676 #else
   609 #else
   677     User::Leave( KErrNotSupported );
   610     User::Leave( KErrNotSupported );
   678 #endif
   611 #endif
   679 
   612 
   680     PRINT( _L( "MM MTP <= MmMtpDpUtility::AsfMimeTypeL" ) );
   613     PRINT( _L( "MM MTP <= MmMtpDpUtility::AsfMimeTypeL" ) );
   711         subFormatCode = EMTPSubFormatCodeAudio;
   644         subFormatCode = EMTPSubFormatCodeAudio;
   712         }
   645         }
   713     else
   646     else
   714         {
   647         {
   715         PRINT( _L( "MM MTP <= MmMtpDpUtility::SubFormatCodeFromMime format not supported" ) );
   648         PRINT( _L( "MM MTP <= MmMtpDpUtility::SubFormatCodeFromMime format not supported" ) );
   716         subFormatCode = EMTPSubFormatCodeUndefine;
   649         subFormatCode = EMTPSubFormatCodeUndefined;
   717         }
   650         }
   718 
   651 
   719     PRINT1( _L( "MM MTP <= MmMtpDpUtility::SubFormatCodeFromMime SubFormatCode = %d" ), subFormatCode );
   652     PRINT1( _L( "MM MTP <= MmMtpDpUtility::SubFormatCodeFromMime SubFormatCode = %d" ), subFormatCode );
   720 
   653 
   721     return subFormatCode;
   654     return subFormatCode;