mmappcomponents/mmmtpdataprovider/src/mmmtpdputility.cpp
changeset 25 d881023c13eb
parent 0 a2952bb97e68
child 27 cbb1bfb7ebfb
equal deleted inserted replaced
21:a05c44bc3c61 25:d881023c13eb
    34 #include <hxmetadatautil.h>
    34 #include <hxmetadatautil.h>
    35 #endif
    35 #endif
    36 
    36 
    37 #include "mmmtpdputility.h"
    37 #include "mmmtpdputility.h"
    38 #include "mmmtpdpfiledefs.h"
    38 #include "mmmtpdpfiledefs.h"
       
    39 #include "tobjectdescription.h"
    39 #include "mmmtpdplogger.h"
    40 #include "mmmtpdplogger.h"
    40 
    41 
    41 using namespace ContentAccess;
    42 using namespace ContentAccess;
    42 
    43 
    43 // local to this file, non standard mimetype used for ASF parsing with helix
    44 // local to this file, non standard mimetype used for ASF parsing with helix
    44 _LIT( KHxMimeTypeWma, "audio/x-hx-wma" );
    45 _LIT( KHxMimeTypeWma, "audio/x-hx-wma" );
    45 _LIT( KHxMimeTypeWmv, "video/x-hx-wmv" );
    46 _LIT( KHxMimeTypeWmv, "video/x-hx-wmv" );
       
    47 
       
    48 const TInt KMaxRenameTimes = 10;
       
    49 const TInt KRenameThreshold = 100 * 1000; // (100 millisec)
    46 
    50 
    47 // -----------------------------------------------------------------------------
    51 // -----------------------------------------------------------------------------
    48 // MmMtpDpUtility::FormatFromFilename
    52 // MmMtpDpUtility::FormatFromFilename
    49 // Utility function to get the type of an object from the filename
    53 // Utility function to get the type of an object from the filename
    50 // The recommended way from the MS implementation
    54 // The recommended way from the MS implementation
    58         return EMTPFormatCodeAssociation;
    62         return EMTPFormatCodeAssociation;
    59         }
    63         }
    60 
    64 
    61     TParsePtrC file( aFullFileName );
    65     TParsePtrC file( aFullFileName );
    62 
    66 
       
    67     if ( !file.ExtPresent() )
       
    68         return EMTPFormatCodeUndefined;
       
    69 
    63     // need to do it in popularity of format, to optmize performance
    70     // need to do it in popularity of format, to optmize performance
    64     if ( file.Ext().CompareF( KTxtExtensionMP3 ) == 0 )
    71     if ( file.Ext().CompareF( KTxtExtensionMP3 ) == 0 )
    65             return EMTPFormatCodeMP3;
    72             return EMTPFormatCodeMP3;
    66 
    73 
    67 #ifdef __WINDOWS_MEDIA
    74 #ifdef __WINDOWS_MEDIA
    68     if ( file.Ext().CompareF( KTxtExtensionWMA ) == 0 )
    75     if ( file.Ext().CompareF( KTxtExtensionWMA ) == 0 )
    69             return EMTPFormatCodeWMA;
    76             return EMTPFormatCodeWMA;
    70 #endif // __WINDOWS_MEDIA
    77 #endif // __WINDOWS_MEDIA
    71     
    78 
    72     if ( ( file.Ext().CompareF( KTxtExtensionMP4 ) == 0 ) || ( file.Ext().CompareF( KTxtExtensionM4A ) == 0 ) )
    79     if ( ( file.Ext().CompareF( KTxtExtensionMP4 ) == 0 )
       
    80         || ( file.Ext().CompareF( KTxtExtensionM4A ) == 0 ) )
    73         return EMTPFormatCodeMP4Container;
    81         return EMTPFormatCodeMP4Container;
    74 
    82 
    75     if ( ( file.Ext().CompareF( KTxtExtension3GP ) == 0 ) || ( file.Ext().CompareF( KTxtExtensionO4A ) == 0 ) || ( file.Ext().CompareF( KTxtExtensionO4V ) == 0 ) )
    83     if ( ( file.Ext().CompareF( KTxtExtension3GP ) == 0 )
       
    84         || ( file.Ext().CompareF( KTxtExtension3G2 ) == 0 )
       
    85         || ( file.Ext().CompareF( KTxtExtensionO4A ) == 0 )
       
    86         || ( file.Ext().CompareF( KTxtExtensionO4V ) == 0 ) )
    76         return EMTPFormatCode3GPContainer;
    87         return EMTPFormatCode3GPContainer;
    77 
    88 
    78     if ( file.Ext().CompareF( KTxtExtensionAAC ) == 0 )
    89     if ( file.Ext().CompareF( KTxtExtensionAAC ) == 0 )
    79         return EMTPFormatCodeAAC;
    90         return EMTPFormatCodeAAC;
    80     
    91 
    81     if ( file.Ext().CompareF( KTxtExtensionWAV ) == 0 )
    92     if ( file.Ext().CompareF( KTxtExtensionWAV ) == 0 )
    82         return EMTPFormatCodeWAV;
    93         return EMTPFormatCodeWAV;
    83     
    94 
    84 #ifdef __WINDOWS_MEDIA
    95 #ifdef __WINDOWS_MEDIA
    85     if ( file.Ext().CompareF( KTxtExtensionWMV ) == 0 )
    96     if ( file.Ext().CompareF( KTxtExtensionWMV ) == 0 )
    86         return EMTPFormatCodeWMV;
    97         return EMTPFormatCodeWMV;
    87     
    98 
    88     if ( file.Ext().CompareF( KTxtExtensionASF ) == 0 )
    99     if ( file.Ext().CompareF( KTxtExtensionASF ) == 0 )
    89         return EMTPFormatCodeASF;
   100         return EMTPFormatCodeASF;
    90 
   101 
    91 #endif // __WINDOWS_MEDIA
   102 #endif // __WINDOWS_MEDIA
    92 
   103 
   109             {
   120             {
   110             delete mime;
   121             delete mime;
   111             mime = NULL;
   122             mime = NULL;
   112             }
   123             }
   113         }
   124         }
       
   125 
       
   126     if ( file.Ext().CompareF( KTxtExtensionALB ) == 0 )
       
   127         return EMTPFormatCodeAbstractAudioAlbum;
   114 
   128 
   115     if (( file.Ext().CompareF( KTxtExtensionPLA ) == 0 ) || ( file.Ext().CompareF( KTxtExtensionVIR ) == 0 ) )
   129     if (( file.Ext().CompareF( KTxtExtensionPLA ) == 0 ) || ( file.Ext().CompareF( KTxtExtensionVIR ) == 0 ) )
   116         return EMTPFormatCodeAbstractAudioVideoPlaylist;
   130         return EMTPFormatCodeAbstractAudioVideoPlaylist;
   117 
   131 
   118     if ( file.Ext().CompareF( KTxtExtensionM3U ) == 0 )
   132     if ( file.Ext().CompareF( KTxtExtensionM3U ) == 0 )
   142 
   156 
   143     return EFalse;
   157     return EFalse;
   144     }
   158     }
   145 
   159 
   146 // -----------------------------------------------------------------------------
   160 // -----------------------------------------------------------------------------
   147 // MmMtpDpUtility::IsVideoL (Slow Version)
   161 // MmMtpDpUtility::HasReference
   148 // Utility function to determine whether a format is Video or not
   162 // Utility function to decide if there is any reference
   149 // -----------------------------------------------------------------------------
   163 // -----------------------------------------------------------------------------
   150 //
   164 //
   151 EXPORT_C TBool MmMtpDpUtility::IsVideoL( const TDesC& aFullFileName )
   165 TBool MmMtpDpUtility::HasReference( TUint16 aObjFormatCode )
   152     {
   166     {
   153     PRINT1( _L( "MM MTP => MmMtpDpUtility::IsVideoL (Slow Version) aFullFileName = %S" ), &aFullFileName );
   167     if ( aObjFormatCode == EMTPFormatCodeAbstractAudioAlbum
   154 
   168         || aObjFormatCode == EMTPFormatCodeAbstractAudioVideoPlaylist
   155     TParse pathParser;
   169         || aObjFormatCode == EMTPFormatCodeM3UPlaylist )
   156     User::LeaveIfError( pathParser.Set( aFullFileName, NULL, NULL ) );
   170         return ETrue;
   157 
   171     else
   158     TPtrC ext( pathParser.Ext() );
       
   159 
       
   160     if ( ext.Length() <= 0 )
       
   161         {
       
   162         PRINT( _L( "MM MTP <> MmMtpDpUtility::IsVideoL ext len <= 0, return false" ) );
       
   163         return EFalse;
   172         return EFalse;
   164         }
       
   165 
       
   166     // move WMV early to optmize comparison
       
   167     if ( ext.CompareF( KTxtExtensionWMV ) == 0 )
       
   168         {
       
   169         return ETrue;
       
   170         }
       
   171     else if ( ext.CompareF( KTxtExtensionMP4 ) == 0
       
   172         || ext.CompareF( KTxtExtension3GP ) == 0
       
   173         || ext.CompareF( KTxtExtensionODF ) == 0 
       
   174         || ext.CompareF( KTxtExtensionASF ) == 0 )
       
   175             {
       
   176             HBufC8* mimetype = ContainerMimeType( aFullFileName );
       
   177             User::LeaveIfNull( mimetype );
       
   178 
       
   179             CleanupStack::PushL( mimetype ); // + mimetype
       
   180 
       
   181             TMmMtpSubFormatCode subFormatCode;
       
   182 
       
   183             User::LeaveIfError( SubFormatCodeFromMime( *mimetype, subFormatCode ) );
       
   184             CleanupStack::PopAndDestroy( mimetype ); // - mimetype
       
   185 
       
   186             if ( subFormatCode == EMTPSubFormatCodeVideo )
       
   187                 {
       
   188                 return ETrue;
       
   189                 }
       
   190             else
       
   191                 {
       
   192                 return EFalse;
       
   193                 }
       
   194             }
       
   195     else if ( ext.CompareF( KTxtExtensionO4V ) == 0 )
       
   196         return ETrue;
       
   197 
       
   198     // other format, as audio
       
   199     return EFalse;
       
   200     }
       
   201 
       
   202 // -----------------------------------------------------------------------------
       
   203 // MmMtpDpUtility::IsVideoL (Fast Version)
       
   204 // Utility function to determine whether a format is Video or not
       
   205 // -----------------------------------------------------------------------------
       
   206 //
       
   207 TBool MmMtpDpUtility::IsVideoL( const TDesC& aFullFileName, 
       
   208     const MMTPDataProviderFramework& aFramework )
       
   209     {
       
   210     PRINT1( _L( "MM MTP => MmMtpDpUtility::IsVideoL (Fast Version) aFullFileName = %S" ), &aFullFileName );
       
   211     
       
   212     CMTPObjectMetaData* info = CMTPObjectMetaData::NewLC(); // + info
       
   213     aFramework.ObjectMgr().ObjectL( aFullFileName, *info );
       
   214 
       
   215     TUint formatCode = info->Uint( CMTPObjectMetaData::EFormatCode );
       
   216     TUint subFormatCode = info->Uint( CMTPObjectMetaData::EFormatSubCode );
       
   217 
       
   218     CleanupStack::PopAndDestroy( info ); // - info
       
   219     
       
   220     if ( formatCode == EMTPFormatCodeWMV )
       
   221         {
       
   222         return ETrue;
       
   223         }
       
   224     else if ( ( formatCode == EMTPFormatCodeMP4Container )
       
   225         || ( formatCode == EMTPFormatCode3GPContainer )
       
   226         || ( formatCode == EMTPFormatCodeASF ) )
       
   227         {
       
   228         if ( subFormatCode == EMTPSubFormatCodeAudio )
       
   229             {
       
   230             return EFalse;
       
   231             }
       
   232         else if ( subFormatCode == EMTPSubFormatCodeVideo )
       
   233             {
       
   234             return ETrue;
       
   235             }
       
   236         }
       
   237 
       
   238     PRINT( _L( "MM MTP <= MmMtpDpUtility::IsVideoL (Fast Version)" ) );
       
   239 
       
   240     // other format, as audio
       
   241     return EFalse;
       
   242     }
   173     }
   243 
   174 
   244 // -----------------------------------------------------------------------------
   175 // -----------------------------------------------------------------------------
   245 // MmMtpDpUtility::ValidateFilename
   176 // MmMtpDpUtility::ValidateFilename
   246 // Check the filename to see if it exceeds Symbian 256 limit.
   177 // Check the filename to see if it exceeds Symbian 256 limit.
   267 TUint64 MmMtpDpUtility::GetObjectSizeL( RFs& aFs, const TDesC& aFileName )
   198 TUint64 MmMtpDpUtility::GetObjectSizeL( RFs& aFs, const TDesC& aFileName )
   268     {
   199     {
   269     TEntry fileInfo;
   200     TEntry fileInfo;
   270     // Shouldn't leave
   201     // Shouldn't leave
   271     User::LeaveIfError( aFs.Entry( aFileName, fileInfo ) );
   202     User::LeaveIfError( aFs.Entry( aFileName, fileInfo ) );
   272     return fileInfo.iSize;
   203     return fileInfo.FileSize();
   273     }
   204     }
   274 
   205 
   275 // -----------------------------------------------------------------------------
   206 // -----------------------------------------------------------------------------
   276 // MmMtpDpUtility::GetDateModifiedL
   207 // MmMtpDpUtility::GetDateModifiedL
   277 // Get the file date modified.
   208 // Get the file date modified.
   278 // -----------------------------------------------------------------------------
   209 // -----------------------------------------------------------------------------
   279 //
   210 //
   280 TTime MmMtpDpUtility::GetObjectDateModifiedL( RFs& aFs, const TDesC& aFullFileName )
   211 void MmMtpDpUtility::GetObjectDateModifiedL( RFs& aFs, const TDesC& aFullFileName, TDes& aDateModified )
   281     {
   212     {
   282     TTime dataModified;
   213     TTime date;
   283     TEntry fileInfo;
   214     TEntry fileInfo;
   284     // Shouldn't leave
   215     // Shouldn't leave
   285     User::LeaveIfError( aFs.Entry( aFullFileName, fileInfo ) );
   216     User::LeaveIfError( aFs.Entry( aFullFileName, fileInfo ) );
   286 
   217     date = fileInfo.iModified;
   287     dataModified = fileInfo.iModified;
   218     date.FormatL( aDateModified, KMtpDateTimeFormat );
   288 
       
   289     return dataModified;
       
   290     }
   219     }
   291 
   220 
   292 // -----------------------------------------------------------------------------
   221 // -----------------------------------------------------------------------------
   293 // MmMtpDpUtility::GetProtectionStatusL
   222 // MmMtpDpUtility::GetProtectionStatusL
   294 // Get the file protection status.
   223 // Get the file protection status.
   304     if ( fileInfo.IsReadOnly() )
   233     if ( fileInfo.IsReadOnly() )
   305         {
   234         {
   306         protectionStatus = EMTPProtectionReadOnly;
   235         protectionStatus = EMTPProtectionReadOnly;
   307         }
   236         }
   308 
   237 
       
   238     PRINT2( _L( "MM MTP <> MmMtpDpUtility::GetProtectionStatusL aFullFileName = %S, protectionStatus = 0x%x" ),
       
   239         &aFullFileName,
       
   240         protectionStatus );
       
   241 
   309     return protectionStatus;
   242     return protectionStatus;
   310     }
   243     }
   311 
   244 
   312 // -----------------------------------------------------------------------------
   245 // -----------------------------------------------------------------------------
   313 // MmMtpDpUtility::CheckPropType
   246 // MmMtpDpUtility::CheckPropType
   314 // Check if property type match datatype.
   247 // Check if property type match datatype.
   315 // -----------------------------------------------------------------------------
   248 // -----------------------------------------------------------------------------
   316 //
   249 //
   317 TMTPResponseCode MmMtpDpUtility::CheckPropType(TUint16 aPropertyCode, TUint16 aDataType)
   250 TMTPResponseCode MmMtpDpUtility::CheckPropType( TUint16 aPropertyCode, TUint16 aDataType )
   318     {
   251     {
   319     PRINT2( _L( "MM MTP => MmMtpDpUtility::CheckPropCode aPropertyCode = 0x%x, aDataType = 0x%x" ), 
   252     PRINT2( _L( "MM MTP => MmMtpDpUtility::CheckPropCode aPropertyCode = 0x%x, aDataType = 0x%x" ),
   320         aPropertyCode, 
   253         aPropertyCode,
   321         aDataType );
   254         aDataType );
   322 
   255 
   323     TMTPResponseCode responseCode = EMTPRespCodeOK;
   256     TMTPResponseCode responseCode = EMTPRespCodeOK;
   324     switch ( aPropertyCode )
   257     switch ( aPropertyCode )
   325         {
   258         {
   331         case EMTPObjectPropCodeParentObject:
   264         case EMTPObjectPropCodeParentObject:
   332         case EMTPObjectPropCodePersistentUniqueObjectIdentifier:
   265         case EMTPObjectPropCodePersistentUniqueObjectIdentifier:
   333         case EMTPObjectPropCodeDateCreated:
   266         case EMTPObjectPropCodeDateCreated:
   334         case EMTPObjectPropCodeDateModified:
   267         case EMTPObjectPropCodeDateModified:
   335         case EMTPObjectPropCodeDateAdded:
   268         case EMTPObjectPropCodeDateAdded:
   336         case EMTPObjectPropCodeNonConsumable:
       
   337         case EMTPObjectPropCodeVideoBitRate:
   269         case EMTPObjectPropCodeVideoBitRate:
       
   270         case EMTPObjectPropCodeRepresentativeSampleFormat:
       
   271         case EMTPObjectPropCodeRepresentativeSampleSize:
       
   272         case EMTPObjectPropCodeRepresentativeSampleHeight:
       
   273         case EMTPObjectPropCodeRepresentativeSampleWidth:
   338             {
   274             {
   339             responseCode = EMTPRespCodeAccessDenied;
   275             responseCode = EMTPRespCodeAccessDenied;
   340             }
   276             }
   341             break;
   277             break;
   342 
   278 
   348         case EMTPObjectPropCodeParentalRating: // 0xDC94
   284         case EMTPObjectPropCodeParentalRating: // 0xDC94
   349         case EMTPObjectPropCodeComposer: // 0xDC96
   285         case EMTPObjectPropCodeComposer: // 0xDC96
   350         case EMTPObjectPropCodeOriginalReleaseDate: // 0xDC99
   286         case EMTPObjectPropCodeOriginalReleaseDate: // 0xDC99
   351         case EMTPObjectPropCodeAlbumName: // 0xDC9A
   287         case EMTPObjectPropCodeAlbumName: // 0xDC9A
   352         case EMTPObjectPropCodeEncodingProfile: // 0xDEA1
   288         case EMTPObjectPropCodeEncodingProfile: // 0xDEA1
       
   289         case EMTPObjectPropCodeAlbumArtist: // 0xDC9B
   353             {
   290             {
   354             if ( aDataType != EMTPTypeString )
   291             if ( aDataType != EMTPTypeString )
   355                 {
   292                 {
   356                 responseCode = EMTPRespCodeInvalidObjectPropFormat;
   293                 responseCode = EMTPRespCodeInvalidObjectPropFormat;
   357                 }
   294                 }
   369 
   306 
   370         //Uint32 properties
   307         //Uint32 properties
   371         case EMTPObjectPropCodeWidth: // 0xDC87
   308         case EMTPObjectPropCodeWidth: // 0xDC87
   372         case EMTPObjectPropCodeHeight: // 0xDC88
   309         case EMTPObjectPropCodeHeight: // 0xDC88
   373         case EMTPObjectPropCodeDuration: // 0xDC89
   310         case EMTPObjectPropCodeDuration: // 0xDC89
   374         case EMTPObjectPropCodeUseCount: // 0xDC91
       
   375         case EMTPObjectPropCodeSampleRate: // 0xDE93
   311         case EMTPObjectPropCodeSampleRate: // 0xDE93
   376         case EMTPObjectPropCodeAudioWAVECodec: // 0xDE99
   312         case EMTPObjectPropCodeAudioWAVECodec: // 0xDE99
   377         case EMTPObjectPropCodeAudioBitRate: // 0xDE9A
   313         case EMTPObjectPropCodeAudioBitRate: // 0xDE9A
   378         case EMTPObjectPropCodeVideoFourCCCodec: // 0xDE9B
   314         case EMTPObjectPropCodeVideoFourCCCodec: // 0xDE9B
   379         case EMTPObjectPropCodeFramesPerThousandSeconds: // 0xDE9D
   315         case EMTPObjectPropCodeFramesPerThousandSeconds: // 0xDE9D
   397                 responseCode = EMTPRespCodeInvalidObjectPropFormat;
   333                 responseCode = EMTPRespCodeInvalidObjectPropFormat;
   398                 }
   334                 }
   399             }
   335             }
   400             break;
   336             break;
   401 
   337 
       
   338         // Uint8 properties
       
   339         case EMTPObjectPropCodeNonConsumable:
       
   340         case EMTPExtObjectPropCodeOmaDrmStatus: // 0xDB01
       
   341             {
       
   342             if ( aDataType != EMTPTypeUINT8 )
       
   343                 {
       
   344                 responseCode = EMTPRespCodeInvalidObjectPropFormat;
       
   345                 }
       
   346             }
       
   347             break;
       
   348 
       
   349         case EMTPObjectPropCodeRepresentativeSampleData:
       
   350             {
       
   351             if ( aDataType != EMTPTypeAUINT8 )
       
   352                 {
       
   353                 responseCode = EMTPRespCodeInvalidObjectPropFormat;
       
   354                 }
       
   355             }
       
   356             break;
       
   357 
   402         default:
   358         default:
   403             {
   359             {
   404             responseCode = EMTPRespCodeInvalidObjectPropCode;
   360             responseCode = EMTPRespCodeInvalidObjectPropCode;
   405             }
   361             }
   406             break;
   362             break;
   407         }
   363         }
   408     PRINT1( _L( "MM MTP <= MmMtpDpUtility::CheckPropCode responseCode = 0x%x" ), 
   364     PRINT1( _L( "MM MTP <= MmMtpDpUtility::CheckPropCode responseCode = 0x%x" ),
   409         responseCode );
   365         responseCode );
   410     return responseCode;
   366     return responseCode;
   411     }
   367     }
   412 
   368 
   413 // -----------------------------------------------------------------------------
   369 // -----------------------------------------------------------------------------
   431     else
   387     else
   432         {
   388         {
   433         aNewName.Insert( 0, ptr );
   389         aNewName.Insert( 0, ptr );
   434         }
   390         }
   435 
   391 
   436     return aFs.Rename( aFullFileName, aNewName );
   392     TInt ret = KErrNone;
   437     }
   393     // Some other component might be holding on to the file (MDS background harvesting),
   438     
   394     // try again after 100 millisec, up to 10 times, before give up
       
   395     TInt count = KMaxRenameTimes;
       
   396     while ( count > 0 )
       
   397         {
       
   398         ret = aFs.Rename( aFullFileName, aNewName );
       
   399         if ( ( ret == KErrInUse ) && ( count > 1 ) )
       
   400             {
       
   401             User::After( KRenameThreshold );
       
   402             count--;
       
   403             }
       
   404         else
       
   405             {
       
   406             break;
       
   407             }
       
   408         }
       
   409 
       
   410     PRINT1( _L( "MM MTP <> MmMtpDpUtility::UpdateObjectFileName, ret = %d" ), ret );
       
   411 
       
   412     return ret;
       
   413     }
       
   414 
   439 // -----------------------------------------------------------------------------
   415 // -----------------------------------------------------------------------------
   440 // MetadataAccessWrapper::ContainerMimeType
   416 // MetadataAccessWrapper::ContainerMimeType
   441 // Get mime type from file
   417 // Get mime type from file
   442 // -----------------------------------------------------------------------------
   418 // -----------------------------------------------------------------------------
   443 //
   419 //
   444 HBufC8* MmMtpDpUtility::ContainerMimeType( const TDesC& aFullPath )
   420 HBufC8* MmMtpDpUtility::ContainerMimeType( const TDesC& aFullPath )
   445     {
   421     {
   446     PRINT( _L( "MM MTP => MmMtpDpUtility::ContainerMimeType" ) );
   422     PRINT( _L( "MM MTP => MmMtpDpUtility::ContainerMimeType" ) );
   447 
   423 
   448     // parse the file path
   424     // parse the file path
   449     TParse pathParser;
   425     TParsePtrC pathParser( aFullPath );
   450     TInt retCode = pathParser.Set( aFullPath, NULL, NULL );
       
   451     if ( retCode != KErrNone )
       
   452         {
       
   453         PRINT( _L( "MM MTP <> MmMtpDpUtility::ContainerMimeType parse path failed" ) );
       
   454         return NULL;
       
   455         }
       
   456 
   426 
   457     // get the extension of file
   427     // get the extension of file
   458     TPtrC ext( pathParser.Ext() );
   428     TPtrC ext( pathParser.Ext() );
   459     if ( ext.Length() <= 0 )
   429     if ( ext.Length() <= 0 )
   460         {
   430         {
   465     HBufC8* mimebuf = NULL;
   435     HBufC8* mimebuf = NULL;
   466     TInt err = KErrNone;
   436     TInt err = KErrNone;
   467 
   437 
   468     // MP4/3GP
   438     // MP4/3GP
   469     if ( ext.CompareF( KTxtExtensionMP4 ) == 0
   439     if ( ext.CompareF( KTxtExtensionMP4 ) == 0
   470         || ext.CompareF( KTxtExtension3GP ) == 0 )
   440         || ext.CompareF( KTxtExtension3GP ) == 0
       
   441         || ext.CompareF( KTxtExtension3G2 ) == 0 )
   471         {
   442         {
   472         TRAP( err, mimebuf = Mp4MimeTypeL( aFullPath ) );
   443         TRAP( err, mimebuf = Mp4MimeTypeL( aFullPath ) );
   473         PRINT1( _L("MM MTP <> MmMtpDpUtility::ContainerMimeType, Mp4MimeTypeL err = %d"), err );
   444         PRINT1( _L("MM MTP <> MmMtpDpUtility::ContainerMimeType, Mp4MimeTypeL err = %d"), err );
   474         }
   445         }
   475     else if ( ext.CompareF( KTxtExtensionODF ) == 0 )
   446     else if ( ext.CompareF( KTxtExtensionODF ) == 0 )
   476         {
   447         {
   477         TRAP( err, mimebuf = Mp4MimeTypeL( aFullPath ) );
   448         TRAP( err, mimebuf = OdfMimeTypeL( aFullPath ) );
   478         PRINT1( _L("MM MTP <> MmMtpDpUtility::ContainerMimeType, OdfMimeTypeL err = %d"), err );
   449         PRINT1( _L("MM MTP <> MmMtpDpUtility::ContainerMimeType, OdfMimeTypeL err = %d"), err );
   479         }
   450         }
   480 #ifdef __WINDOWS_MEDIA
   451 #ifdef __WINDOWS_MEDIA
   481     else if ( ext.CompareF( KTxtExtensionASF ) == 0 )
   452     else if ( ext.CompareF( KTxtExtensionASF ) == 0 )
   482         {
   453         {
   483         TRAP( err, mimebuf = AsfMimeTypeL( aFullPath ) );
   454         TRAP( err, mimebuf = AsfMimeTypeL( aFullPath ) );
   484         PRINT1( _L("MM MTP <> MmMtpDpUtility::ContainerMimeType, AsfMimeTypeL err = %d"), err );
   455         PRINT1( _L("MM MTP <> MmMtpDpUtility::ContainerMimeType, AsfMimeTypeL err = %d"), err );
   485         }
   456         }
   486 #endif
   457 #endif
   487     
   458 
   488     PRINT( _L( "MM MTP <= MmMtpDpUtility::ContainerMimeType" ) );
   459     PRINT( _L( "MM MTP <= MmMtpDpUtility::ContainerMimeType" ) );
   489     return mimebuf;
   460     return mimebuf;
   490     }
   461     }
   491 
   462 
   492 // -----------------------------------------------------------------------------
   463 // -----------------------------------------------------------------------------
   497 HBufC8* MmMtpDpUtility::Mp4MimeTypeL( const TDesC& aFullPath )
   468 HBufC8* MmMtpDpUtility::Mp4MimeTypeL( const TDesC& aFullPath )
   498     {
   469     {
   499     PRINT( _L( "MM MTP => MmMtpDpUtility::Mp4MimeTypeL" ) );
   470     PRINT( _L( "MM MTP => MmMtpDpUtility::Mp4MimeTypeL" ) );
   500     HBufC8* mimebuf = NULL;
   471     HBufC8* mimebuf = NULL;
   501     TParsePtrC file( aFullPath );
   472     TParsePtrC file( aFullPath );
   502     
   473 
   503     if ( file.Ext().CompareF( KTxtExtensionMP4 ) == 0
   474     if ( file.Ext().CompareF( KTxtExtensionMP4 ) == 0
   504         || file.Ext().CompareF( KTxtExtension3GP ) == 0 )
   475         || file.Ext().CompareF( KTxtExtension3GP ) == 0
       
   476         || file.Ext().CompareF( KTxtExtension3G2 ) == 0 )
   505         {
   477         {
   506         // get mime from file
   478         // get mime from file
   507         MP4Handle mp4Handle = NULL;
   479         MP4Handle mp4Handle = NULL;
   508 
   480 
   509         RBuf buf;
   481         RBuf buf;
   535                     &audioLength, &audioType, &framesPerSample, &timeScale,
   507                     &audioLength, &audioType, &framesPerSample, &timeScale,
   536                     &averateBitRate );
   508                     &averateBitRate );
   537 
   509 
   538                 if ( mp4err == MP4_OK )
   510                 if ( mp4err == MP4_OK )
   539                     {
   511                     {
   540                     if ( file.Ext().CompareF( KTxtExtension3GP ) == 0 )
   512                     if ( file.Ext().CompareF( KTxtExtension3GP ) == 0
       
   513                         || file.Ext().CompareF( KTxtExtension3G2 ) == 0 )
   541                         {
   514                         {
   542                         mimebuf = KMimeTypeAudio3gpp().Alloc();
   515                         mimebuf = KMimeTypeAudio3gpp().Alloc();
   543                         }
   516                         }
   544                     else
   517                     else
   545                         {
   518                         {
   548                     }
   521                     }
   549                 }
   522                 }
   550             // is video file
   523             // is video file
   551             else if ( mp4err == MP4_OK )
   524             else if ( mp4err == MP4_OK )
   552                 {
   525                 {
   553                 if ( file.Ext().CompareF( KTxtExtension3GP ) == 0 )
   526                 if ( file.Ext().CompareF( KTxtExtension3GP ) == 0 
       
   527                     || file.Ext().CompareF( KTxtExtension3G2 ) == 0 )
   554                     {
   528                     {
   555                     mimebuf = KMimeTypeVideo3gpp().Alloc();
   529                     mimebuf = KMimeTypeVideo3gpp().Alloc();
   556                     }
   530                     }
   557                 else
   531                 else
   558                     {
   532                     {
   571         }
   545         }
   572     else
   546     else
   573         {
   547         {
   574         User::Leave( KErrNotSupported );
   548         User::Leave( KErrNotSupported );
   575         }
   549         }
   576     
   550 
   577     if ( mimebuf == NULL )
   551     if ( mimebuf == NULL )
   578         {
   552         {
   579         User::Leave( KErrNotFound );
   553         User::Leave( KErrNotFound );
   580         }
   554         }
   581     PRINT( _L( "MM MTP <= MmMtpDpUtility::Mp4MimeTypeL" ) );
   555     PRINT( _L( "MM MTP <= MmMtpDpUtility::Mp4MimeTypeL" ) );
   589 //
   563 //
   590 HBufC8* MmMtpDpUtility::OdfMimeTypeL( const TDesC& aFullPath )
   564 HBufC8* MmMtpDpUtility::OdfMimeTypeL( const TDesC& aFullPath )
   591     {
   565     {
   592     PRINT( _L( "MM MTP => MmMtpDpUtility::OdfMimeTypeL" ) );
   566     PRINT( _L( "MM MTP => MmMtpDpUtility::OdfMimeTypeL" ) );
   593     HBufC8* mimebuf = NULL;
   567     HBufC8* mimebuf = NULL;
   594     
   568 
   595     TParsePtrC file( aFullPath );
   569     TParsePtrC file( aFullPath );
   596         
   570 
   597     if ( file.Ext().CompareF( KTxtExtensionODF ) == 0 )
   571     if ( file.Ext().CompareF( KTxtExtensionODF ) == 0 )
   598         {    
   572         {
   599         CContent* content = CContent::NewL( aFullPath );
   573         CContent* content = CContent::NewL( aFullPath );
   600         CleanupStack::PushL( content ); // + content
   574         CleanupStack::PushL( content ); // + content
   601         
   575 
   602         HBufC* buffer = HBufC::NewL( KMimeTypeMaxLength );
   576         HBufC* buffer = HBufC::NewL( KMimeTypeMaxLength );
   603         CleanupStack::PushL( buffer ); // + buffer
   577         CleanupStack::PushL( buffer ); // + buffer
   604         
   578 
   605         TPtr data = buffer->Des();
   579         TPtr data = buffer->Des();
   606         TInt err = content->GetStringAttribute( EMimeType, data );
   580         TInt err = content->GetStringAttribute( EMimeType, data );
   607                 
   581 
   608         if ( err == KErrNone )
   582         if ( err == KErrNone )
   609             {
   583             {
   610             mimebuf = HBufC8::New( buffer->Length() );
   584             mimebuf = HBufC8::New( buffer->Length() );
   611     
   585 
   612             if (mimebuf == NULL)
   586             if (mimebuf == NULL)
   613                 {
   587                 {
   614                 User::LeaveIfError( KErrNotFound );
   588                 User::LeaveIfError( KErrNotFound );
   615                 }
   589                 }
   616             
   590 
   617             mimebuf->Des().Copy( *buffer );
   591             mimebuf->Des().Copy( *buffer );
   618             }
   592             }
   619         
   593 
   620         // leave if NULL
   594         // leave if NULL
   621         if ( mimebuf == NULL )
   595         if ( mimebuf == NULL )
   622             {
   596             {
   623             User::Leave( KErrNotFound );
   597             User::Leave( KErrNotFound );
   624             }
   598             }
   625         
   599 
   626         CleanupStack::PopAndDestroy( buffer ); // - buffer
   600         CleanupStack::PopAndDestroy( buffer ); // - buffer
   627         CleanupStack::PopAndDestroy( content ); // - content
   601         CleanupStack::PopAndDestroy( content ); // - content
   628         }
   602         }
   629     else
   603     else
   630         {
   604         {
   631         User::Leave( KErrNotSupported );
   605         User::Leave( KErrNotSupported );
   632         }
   606         }
   633     
   607 
   634     PRINT( _L( "MM MTP <= MmMtpDpUtility::OdfMimeTypeL" ) );
   608     PRINT( _L( "MM MTP <= MmMtpDpUtility::OdfMimeTypeL" ) );
   635     return mimebuf;
   609     return mimebuf;
   636     }
   610     }
   637 
   611 
   638 // -----------------------------------------------------------------------------
   612 // -----------------------------------------------------------------------------
   640 // Get mime type from asf file
   614 // Get mime type from asf file
   641 // -----------------------------------------------------------------------------
   615 // -----------------------------------------------------------------------------
   642 //
   616 //
   643 HBufC8* MmMtpDpUtility::AsfMimeTypeL( const TDesC& aFullPath )
   617 HBufC8* MmMtpDpUtility::AsfMimeTypeL( const TDesC& aFullPath )
   644     {
   618     {
   645     PRINT( _L( "MM MTP => MmMtpDpUtility::AsfMimeTypeL" ) );
   619     PRINT1( _L( "MM MTP => MmMtpDpUtility::AsfMimeTypeL, aFullPath = %S" ), &aFullPath );
   646     
   620 
   647     HBufC8* mimebuf = NULL;
   621     HBufC8* mimebuf = NULL;
   648     
   622 
   649 #ifdef __WINDOWS_MEDIA
   623 #ifdef __WINDOWS_MEDIA
   650     TParsePtrC file( aFullPath );
   624     TParsePtrC file( aFullPath );
   651     
   625 
   652     if ( file.Ext().CompareF( KTxtExtensionASF ) == 0 )
   626     if ( file.Ext().CompareF( KTxtExtensionASF ) == 0 )
   653         {
   627         {
   654         CHXMetaDataUtility *hxUtility = CHXMetaDataUtility::NewL();
   628         CHXMetaDataUtility *hxUtility = CHXMetaDataUtility::NewL();
   655         CleanupStack::PushL( hxUtility );
   629         CleanupStack::PushL( hxUtility );
   656     
   630 
   657         hxUtility->OpenFileL( aFullPath );
   631         hxUtility->OpenFileL( aFullPath );
   658         
   632         PRINT( _L( "MM MTP <> MmMtpDpUtility::AsfMimeTypeL OpenFileL" ) );
       
   633 
   659         HXMetaDataKeys::EHXMetaDataId id;
   634         HXMetaDataKeys::EHXMetaDataId id;
   660         TUint count = 0;
   635         TUint count = 0;
   661         TBool isAudio = EFalse;
   636         TBool isAudio = EFalse;
   662         hxUtility->GetMetaDataCount( count );
   637         hxUtility->GetMetaDataCount( count );
   663         for ( TUint i = 0; i < count; i++ )
   638         for ( TUint i = 0; i < count; i++ )
   664             {    
   639             {
   665             HBufC* buf = NULL;
   640             HBufC* buf = NULL;
   666             hxUtility->GetMetaDataAt( i, id, buf ); 
   641             hxUtility->GetMetaDataAt( i, id, buf );
   667 
   642 
   668             if ( id == HXMetaDataKeys::EHXMimeType )
   643             if ( id == HXMetaDataKeys::EHXMimeType )
   669                 {
   644                 {
   670                 TPtr des = buf->Des();
   645                 TPtr des = buf->Des();
   671                 
   646 
   672                 if ( des.Find( KHxMimeTypeWma() ) != KErrNotFound )
   647                 if ( des.Find( KHxMimeTypeWma() ) != KErrNotFound )
   673                     {
   648                     {
   674                     isAudio = ETrue;
   649                     isAudio = ETrue;
   675                     }
   650                     }
   676                 else if ( des.Find( KHxMimeTypeWmv() ) != KErrNotFound )
   651                 else if ( des.Find( KHxMimeTypeWmv() ) != KErrNotFound )
   693                     }
   668                     }
   694                 }
   669                 }
   695             }
   670             }
   696 
   671 
   697         hxUtility->ResetL();
   672         hxUtility->ResetL();
   698         CleanupStack::PopAndDestroy( hxUtility );        
   673         CleanupStack::PopAndDestroy( hxUtility );
   699         }
   674         }
   700     else
   675     else
   701         {
   676         {
   702         User::Leave( KErrNotSupported );
   677         User::Leave( KErrNotSupported );
   703         }
   678         }
   704 
   679 
   705 #else
   680 #else
   706     User::Leave( KErrNotSupported );
   681     User::Leave( KErrNotSupported );
   707 #endif
   682 #endif
   708     
   683 
   709     PRINT( _L( "MM MTP <= MmMtpDpUtility::AsfMimeTypeL" ) );
   684     PRINT( _L( "MM MTP <= MmMtpDpUtility::AsfMimeTypeL" ) );
   710     return mimebuf;
   685     return mimebuf;
   711     }
   686     }
   712 
   687 
   713 // -----------------------------------------------------------------------------
   688 // -----------------------------------------------------------------------------
   714 // MetadataAccessWrapper::SubFormatCodeFromMime
   689 // MetadataAccessWrapper::SubFormatCodeFromMime
   715 // Get subformat code from mime string
   690 // Get subformat code from mime string
   716 // -----------------------------------------------------------------------------
   691 // -----------------------------------------------------------------------------
   717 //
   692 //
   718 TInt MmMtpDpUtility::SubFormatCodeFromMime( const TDesC8& aMimeType, 
   693 TMmMtpSubFormatCode MmMtpDpUtility::SubFormatCodeFromMime( const TDesC8& aMimeType )
   719     TMmMtpSubFormatCode& aSubFormatCode )
       
   720     {
   694     {
   721     PRINT( _L( "MM MTP => MmMtpDpUtility::SubFormatCodeFromMime" ) );
   695     PRINT( _L( "MM MTP => MmMtpDpUtility::SubFormatCodeFromMime" ) );
       
   696 
       
   697     TMmMtpSubFormatCode subFormatCode = EMTPSubFormatCodeUnknown;
   722 
   698 
   723     if ( aMimeType.CompareF( KMimeTypeVideoMp4 ) == 0
   699     if ( aMimeType.CompareF( KMimeTypeVideoMp4 ) == 0
   724         || aMimeType.CompareF( KMimeTypeVideo3gpp ) == 0
   700         || aMimeType.CompareF( KMimeTypeVideo3gpp ) == 0
   725 #ifdef __WINDOWS_MEDIA
   701 #ifdef __WINDOWS_MEDIA
   726         || aMimeType.CompareF( KMimeTypeVideoWm ) == 0
   702         || aMimeType.CompareF( KMimeTypeVideoWm ) == 0
   727 #endif
   703 #endif
   728         )
   704         )
   729         {
   705         {
   730         aSubFormatCode = EMTPSubFormatCodeVideo;
   706         subFormatCode = EMTPSubFormatCodeVideo;
   731         }
   707         }
   732     else if ( aMimeType.CompareF( KMimeTypeAudioMp4 ) == 0
   708     else if ( aMimeType.CompareF( KMimeTypeAudioMp4 ) == 0
   733         || aMimeType.CompareF( KMimeTypeAudio3gpp ) == 0
   709         || aMimeType.CompareF( KMimeTypeAudio3gpp ) == 0
   734 #ifdef __WINDOWS_MEDIA
   710 #ifdef __WINDOWS_MEDIA
   735         || aMimeType.CompareF( KMimeTypeAudioWm ) == 0
   711         || aMimeType.CompareF( KMimeTypeAudioWm ) == 0
   736 #endif
   712 #endif
   737         )
   713         )
   738         {
   714         {
   739         aSubFormatCode = EMTPSubFormatCodeAudio;
   715         subFormatCode = EMTPSubFormatCodeAudio;
   740         }
   716         }
   741     else
   717     else
   742         {
   718         {
   743         PRINT( _L( "MM MTP <= MmMtpDpUtility::SubFormatCodeFromMime format not supported" ) );
   719         PRINT( _L( "MM MTP <= MmMtpDpUtility::SubFormatCodeFromMime format not supported" ) );
   744         return KErrNotFound;
   720         subFormatCode = EMTPSubFormatCodeUndefine;
   745         }
   721         }
   746 
   722 
   747     PRINT( _L( "MM MTP <= MmMtpDpUtility::SubFormatCodeFromMime" ) );
   723     PRINT1( _L( "MM MTP <= MmMtpDpUtility::SubFormatCodeFromMime SubFormatCode = %d" ), subFormatCode );
   748     return KErrNone;
   724 
       
   725     return subFormatCode;
   749     }
   726     }
   750 
   727 
   751 // -----------------------------------------------------------------------------
   728 // -----------------------------------------------------------------------------
   752 // MetadataAccessWrapper::GetDrmStatus
   729 // MetadataAccessWrapper::GetDrmStatus
   753 // Get drm status code from file
   730 // Get drm status code from file
   789             content = NULL;
   766             content = NULL;
   790             }
   767             }
   791         }
   768         }
   792 
   769 
   793     PRINT1( _L( "MM MTP <= MmMtpDpUtility::GetDrmStatus, drmStatus: %d" ), drmStatus );
   770     PRINT1( _L( "MM MTP <= MmMtpDpUtility::GetDrmStatus, drmStatus: %d" ), drmStatus );
   794     
   771 
   795     return drmStatus;
   772     return drmStatus;
   796     }
   773     }
   797 
   774 
   798 //end of file
   775 // end of file