mmappcomponents/mmmtpdataprovider/src/mmmtpdputility.cpp
branchRCL_3
changeset 14 05b0d2323768
parent 9 bee149131e4b
child 17 780c925249c1
equal deleted inserted replaced
9:bee149131e4b 14:05b0d2323768
    73     if ( ( file.Ext().CompareF( KTxtExtensionMP4 ) == 0 )
    73     if ( ( file.Ext().CompareF( KTxtExtensionMP4 ) == 0 )
    74         || ( file.Ext().CompareF( KTxtExtensionM4A ) == 0 ) )
    74         || ( file.Ext().CompareF( KTxtExtensionM4A ) == 0 ) )
    75         return EMTPFormatCodeMP4Container;
    75         return EMTPFormatCodeMP4Container;
    76 
    76 
    77     if ( ( file.Ext().CompareF( KTxtExtension3GP ) == 0 )
    77     if ( ( file.Ext().CompareF( KTxtExtension3GP ) == 0 )
       
    78         || ( file.Ext().CompareF( KTxtExtension3G2 ) == 0 )
    78         || ( file.Ext().CompareF( KTxtExtensionO4A ) == 0 )
    79         || ( file.Ext().CompareF( KTxtExtensionO4A ) == 0 )
    79         || ( file.Ext().CompareF( KTxtExtensionO4V ) == 0 ) )
    80         || ( file.Ext().CompareF( KTxtExtensionO4V ) == 0 ) )
    80         return EMTPFormatCode3GPContainer;
    81         return EMTPFormatCode3GPContainer;
    81 
    82 
    82     if ( file.Ext().CompareF( KTxtExtensionAAC ) == 0 )
    83     if ( file.Ext().CompareF( KTxtExtensionAAC ) == 0 )
   161     else
   162     else
   162         return EFalse;
   163         return EFalse;
   163     }
   164     }
   164 
   165 
   165 // -----------------------------------------------------------------------------
   166 // -----------------------------------------------------------------------------
   166 // MmMtpDpUtility::IsVideoL (Slow Version)
   167 // MmMtpDpUtility::IsVideo (Slow Version)
   167 // Utility function to determine whether a format is Video or not
   168 // Utility function to determine whether a format is Video or not
   168 // -----------------------------------------------------------------------------
   169 // -----------------------------------------------------------------------------
   169 //
   170 //
   170 EXPORT_C TBool MmMtpDpUtility::IsVideoL( const TDesC& aFullFileName )
   171 EXPORT_C TBool MmMtpDpUtility::IsVideo( const TDesC& aFullFileName )
   171     {
   172     {
   172     PRINT1( _L( "MM MTP => MmMtpDpUtility::IsVideoL (Slow Version) aFullFileName = %S" ), &aFullFileName );
   173     PRINT1( _L( "MM MTP => MmMtpDpUtility::IsVideoL (Slow Version) aFullFileName = %S" ), &aFullFileName );
   173 
   174 
   174     TParse pathParser;
   175     TParsePtrC pathParser( aFullFileName );
   175     User::LeaveIfError( pathParser.Set( aFullFileName, NULL, NULL ) );
       
   176 
       
   177     TPtrC ext( pathParser.Ext() );
   176     TPtrC ext( pathParser.Ext() );
   178 
   177 
   179     if ( ext.Length() <= 0 )
   178     if ( ext.Length() <= 0 )
   180         {
   179         {
   181         PRINT( _L( "MM MTP <> MmMtpDpUtility::IsVideoL ext len <= 0, return false" ) );
   180         PRINT( _L( "MM MTP <> MmMtpDpUtility::IsVideoL ext len <= 0, return false" ) );
   187         {
   186         {
   188         return ETrue;
   187         return ETrue;
   189         }
   188         }
   190     else if ( ext.CompareF( KTxtExtensionMP4 ) == 0
   189     else if ( ext.CompareF( KTxtExtensionMP4 ) == 0
   191         || ext.CompareF( KTxtExtension3GP ) == 0
   190         || ext.CompareF( KTxtExtension3GP ) == 0
       
   191         || ext.CompareF( KTxtExtension3G2 ) == 0
   192         || ext.CompareF( KTxtExtensionODF ) == 0
   192         || ext.CompareF( KTxtExtensionODF ) == 0
   193         || ext.CompareF( KTxtExtensionASF ) == 0 )
   193         || ext.CompareF( KTxtExtensionASF ) == 0 )
   194         {
   194         {
   195         HBufC8* mimetype = ContainerMimeType( aFullFileName );
   195         HBufC8* mimetype = ContainerMimeType( aFullFileName );
   196         User::LeaveIfNull( mimetype );
   196         if ( mimetype != NULL )
   197 
   197             {
   198         CleanupStack::PushL( mimetype ); // + mimetype
   198             TMmMtpSubFormatCode subFormatCode;
   199 
   199 
   200         TMmMtpSubFormatCode subFormatCode;
   200             TInt err = SubFormatCodeFromMime(*mimetype, subFormatCode);
   201 
   201             PRINT1( _L( "MM MTP <> MmMtpDpUtility::IsVideoL SubFormatCodeFromMime err = %d" ), err );
   202         User::LeaveIfError( SubFormatCodeFromMime( *mimetype, subFormatCode ) );
   202             
   203         CleanupStack::PopAndDestroy( mimetype ); // - mimetype
   203             if ( subFormatCode == EMTPSubFormatCodeVideo )
   204 
   204                 {
   205         if ( subFormatCode == EMTPSubFormatCodeVideo )
   205                 return ETrue;
   206             {
   206                 }
   207             return ETrue;
       
   208             }
       
   209         else
       
   210             {
       
   211             return EFalse;
       
   212             }
   207             }
   213         }
   208         }
   214     else if ( ext.CompareF( KTxtExtensionO4V ) == 0 )
   209     else if ( ext.CompareF( KTxtExtensionO4V ) == 0 )
   215         return ETrue;
   210         return ETrue;
   216 
   211 
   217     // other format, as audio
   212     // NOTE: Treate all non-video files as audio files even it's not audio
       
   213     // since the entry is not going to be find out in MPX
       
   214     // we can handle that situation gracefully.
   218     return EFalse;
   215     return EFalse;
   219     }
   216     }
   220 
   217 
   221 // -----------------------------------------------------------------------------
   218 // -----------------------------------------------------------------------------
   222 // MmMtpDpUtility::IsVideoL (Fast Version)
   219 // MmMtpDpUtility::IsVideoL (Fast Version)
   231     CMTPObjectMetaData* info = CMTPObjectMetaData::NewLC(); // + info
   228     CMTPObjectMetaData* info = CMTPObjectMetaData::NewLC(); // + info
   232     aFramework.ObjectMgr().ObjectL( aFullFileName, *info );
   229     aFramework.ObjectMgr().ObjectL( aFullFileName, *info );
   233 
   230 
   234     TUint formatCode = info->Uint( CMTPObjectMetaData::EFormatCode );
   231     TUint formatCode = info->Uint( CMTPObjectMetaData::EFormatCode );
   235     TUint subFormatCode = info->Uint( CMTPObjectMetaData::EFormatSubCode );
   232     TUint subFormatCode = info->Uint( CMTPObjectMetaData::EFormatSubCode );
   236 
   233     TBool ifNeedParse = ( ( formatCode == EMTPFormatCodeMP4Container )
       
   234         || ( formatCode == EMTPFormatCode3GPContainer )
       
   235         || ( formatCode== EMTPFormatCodeASF ) )
       
   236         && ( subFormatCode == EMTPSubFormatCodeUnknown );
       
   237     TBool isVideo = EFalse;
       
   238     if ( ifNeedParse )
       
   239         {
       
   240         isVideo = MmMtpDpUtility::IsVideo( aFullFileName );
       
   241         subFormatCode = isVideo ? EMTPSubFormatCodeVideo : EMTPSubFormatCodeAudio;
       
   242 
       
   243         // Once we got the subformat code, set it into fw db
       
   244         aFramework.ObjectMgr().ModifyObjectL( *info );
       
   245         }
       
   246     else
       
   247         {
       
   248         isVideo = MmMtpDpUtility::IsVideoL( formatCode, subFormatCode );
       
   249         }
       
   250         
   237     CleanupStack::PopAndDestroy( info ); // - info
   251     CleanupStack::PopAndDestroy( info ); // - info
   238 
   252 
   239     return MmMtpDpUtility::IsVideoL( formatCode, subFormatCode );
   253     return isVideo;
   240     }
   254     }
   241 
   255 
   242 // -----------------------------------------------------------------------------
   256 // -----------------------------------------------------------------------------
   243 // MmMtpDpUtility::IsVideoL (Fast Version)
   257 // MmMtpDpUtility::IsVideoL (Fast Version)
   244 // Utility function to determine whether a format is Video or not
   258 // Utility function to determine whether a format is Video or not
   490 HBufC8* MmMtpDpUtility::ContainerMimeType( const TDesC& aFullPath )
   504 HBufC8* MmMtpDpUtility::ContainerMimeType( const TDesC& aFullPath )
   491     {
   505     {
   492     PRINT( _L( "MM MTP => MmMtpDpUtility::ContainerMimeType" ) );
   506     PRINT( _L( "MM MTP => MmMtpDpUtility::ContainerMimeType" ) );
   493 
   507 
   494     // parse the file path
   508     // parse the file path
   495     TParse pathParser;
   509     TParsePtrC pathParser( aFullPath );
   496     TInt retCode = pathParser.Set( aFullPath, NULL, NULL );
       
   497     if ( retCode != KErrNone )
       
   498         {
       
   499         PRINT( _L( "MM MTP <> MmMtpDpUtility::ContainerMimeType parse path failed" ) );
       
   500         return NULL;
       
   501         }
       
   502 
   510 
   503     // get the extension of file
   511     // get the extension of file
   504     TPtrC ext( pathParser.Ext() );
   512     TPtrC ext( pathParser.Ext() );
   505     if ( ext.Length() <= 0 )
   513     if ( ext.Length() <= 0 )
   506         {
   514         {
   511     HBufC8* mimebuf = NULL;
   519     HBufC8* mimebuf = NULL;
   512     TInt err = KErrNone;
   520     TInt err = KErrNone;
   513 
   521 
   514     // MP4/3GP
   522     // MP4/3GP
   515     if ( ext.CompareF( KTxtExtensionMP4 ) == 0
   523     if ( ext.CompareF( KTxtExtensionMP4 ) == 0
   516         || ext.CompareF( KTxtExtension3GP ) == 0 )
   524         || ext.CompareF( KTxtExtension3GP ) == 0
       
   525         || ext.CompareF( KTxtExtension3G2 ) == 0 )
   517         {
   526         {
   518         TRAP( err, mimebuf = Mp4MimeTypeL( aFullPath ) );
   527         TRAP( err, mimebuf = Mp4MimeTypeL( aFullPath ) );
   519         PRINT1( _L("MM MTP <> MmMtpDpUtility::ContainerMimeType, Mp4MimeTypeL err = %d"), err );
   528         PRINT1( _L("MM MTP <> MmMtpDpUtility::ContainerMimeType, Mp4MimeTypeL err = %d"), err );
   520         }
   529         }
   521     else if ( ext.CompareF( KTxtExtensionODF ) == 0 )
   530     else if ( ext.CompareF( KTxtExtensionODF ) == 0 )
   522         {
   531         {
   523         TRAP( err, mimebuf = Mp4MimeTypeL( aFullPath ) );
   532         TRAP( err, mimebuf = OdfMimeTypeL( aFullPath ) );
   524         PRINT1( _L("MM MTP <> MmMtpDpUtility::ContainerMimeType, OdfMimeTypeL err = %d"), err );
   533         PRINT1( _L("MM MTP <> MmMtpDpUtility::ContainerMimeType, OdfMimeTypeL err = %d"), err );
   525         }
   534         }
   526 #ifdef __WINDOWS_MEDIA
   535 #ifdef __WINDOWS_MEDIA
   527     else if ( ext.CompareF( KTxtExtensionASF ) == 0 )
   536     else if ( ext.CompareF( KTxtExtensionASF ) == 0 )
   528         {
   537         {
   545     PRINT( _L( "MM MTP => MmMtpDpUtility::Mp4MimeTypeL" ) );
   554     PRINT( _L( "MM MTP => MmMtpDpUtility::Mp4MimeTypeL" ) );
   546     HBufC8* mimebuf = NULL;
   555     HBufC8* mimebuf = NULL;
   547     TParsePtrC file( aFullPath );
   556     TParsePtrC file( aFullPath );
   548 
   557 
   549     if ( file.Ext().CompareF( KTxtExtensionMP4 ) == 0
   558     if ( file.Ext().CompareF( KTxtExtensionMP4 ) == 0
   550         || file.Ext().CompareF( KTxtExtension3GP ) == 0 )
   559         || file.Ext().CompareF( KTxtExtension3GP ) == 0
       
   560         || file.Ext().CompareF( KTxtExtension3G2 ) == 0 )
   551         {
   561         {
   552         // get mime from file
   562         // get mime from file
   553         MP4Handle mp4Handle = NULL;
   563         MP4Handle mp4Handle = NULL;
   554 
   564 
   555         RBuf buf;
   565         RBuf buf;
   581                     &audioLength, &audioType, &framesPerSample, &timeScale,
   591                     &audioLength, &audioType, &framesPerSample, &timeScale,
   582                     &averateBitRate );
   592                     &averateBitRate );
   583 
   593 
   584                 if ( mp4err == MP4_OK )
   594                 if ( mp4err == MP4_OK )
   585                     {
   595                     {
   586                     if ( file.Ext().CompareF( KTxtExtension3GP ) == 0 )
   596                     if ( file.Ext().CompareF( KTxtExtension3GP ) == 0
       
   597                         || file.Ext().CompareF( KTxtExtension3G2 ) == 0 )
   587                         {
   598                         {
   588                         mimebuf = KMimeTypeAudio3gpp().Alloc();
   599                         mimebuf = KMimeTypeAudio3gpp().Alloc();
   589                         }
   600                         }
   590                     else
   601                     else
   591                         {
   602                         {
   594                     }
   605                     }
   595                 }
   606                 }
   596             // is video file
   607             // is video file
   597             else if ( mp4err == MP4_OK )
   608             else if ( mp4err == MP4_OK )
   598                 {
   609                 {
   599                 if ( file.Ext().CompareF( KTxtExtension3GP ) == 0 )
   610                 if ( file.Ext().CompareF( KTxtExtension3GP ) == 0 
       
   611                     || file.Ext().CompareF( KTxtExtension3G2 ) == 0 )
   600                     {
   612                     {
   601                     mimebuf = KMimeTypeVideo3gpp().Alloc();
   613                     mimebuf = KMimeTypeVideo3gpp().Alloc();
   602                     }
   614                     }
   603                 else
   615                 else
   604                     {
   616                     {
   686 // Get mime type from asf file
   698 // Get mime type from asf file
   687 // -----------------------------------------------------------------------------
   699 // -----------------------------------------------------------------------------
   688 //
   700 //
   689 HBufC8* MmMtpDpUtility::AsfMimeTypeL( const TDesC& aFullPath )
   701 HBufC8* MmMtpDpUtility::AsfMimeTypeL( const TDesC& aFullPath )
   690     {
   702     {
   691     PRINT( _L( "MM MTP => MmMtpDpUtility::AsfMimeTypeL" ) );
   703     PRINT1( _L( "MM MTP => MmMtpDpUtility::AsfMimeTypeL, aFullPath = %S" ), &aFullPath );
   692 
   704 
   693     HBufC8* mimebuf = NULL;
   705     HBufC8* mimebuf = NULL;
   694 
   706 
   695 #ifdef __WINDOWS_MEDIA
   707 #ifdef __WINDOWS_MEDIA
   696     TParsePtrC file( aFullPath );
   708     TParsePtrC file( aFullPath );
   699         {
   711         {
   700         CHXMetaDataUtility *hxUtility = CHXMetaDataUtility::NewL();
   712         CHXMetaDataUtility *hxUtility = CHXMetaDataUtility::NewL();
   701         CleanupStack::PushL( hxUtility );
   713         CleanupStack::PushL( hxUtility );
   702 
   714 
   703         hxUtility->OpenFileL( aFullPath );
   715         hxUtility->OpenFileL( aFullPath );
       
   716         PRINT( _L( "MM MTP <> MmMtpDpUtility::AsfMimeTypeL OpenFileL" ) );
   704 
   717 
   705         HXMetaDataKeys::EHXMetaDataId id;
   718         HXMetaDataKeys::EHXMetaDataId id;
   706         TUint count = 0;
   719         TUint count = 0;
   707         TBool isAudio = EFalse;
   720         TBool isAudio = EFalse;
   708         hxUtility->GetMetaDataCount( count );
   721         hxUtility->GetMetaDataCount( count );