mmappcomponents/mmmtpdataprovider/src/mmmtpdputility.cpp
changeset 0 a2952bb97e68
child 9 bee149131e4b
child 25 d881023c13eb
equal deleted inserted replaced
-1:000000000000 0:a2952bb97e68
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation for MTP Common Function
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <bautils.h>
       
    20 #include <e32math.h>
       
    21 #include <f32file.h>
       
    22 #include <mtp/mtpprotocolconstants.h>
       
    23 #include <mtp/mtpdatatypeconstants.h>
       
    24 #include <3gplibrary/mp4lib.h>
       
    25 #include <caf/content.h>
       
    26 #include <mtp/cmtpobjectmetadata.h>
       
    27 #include <mtp/mmtpdataproviderframework.h>
       
    28 #include <mtp/mmtpobjectmgr.h>
       
    29 #include <mtp/tmtptypeuint32.h>
       
    30 
       
    31 // for asf mimetype parsing
       
    32 #ifdef __WINDOWS_MEDIA
       
    33 #include <hxmetadatakeys.h>
       
    34 #include <hxmetadatautil.h>
       
    35 #endif
       
    36 
       
    37 #include "mmmtpdputility.h"
       
    38 #include "mmmtpdpfiledefs.h"
       
    39 #include "mmmtpdplogger.h"
       
    40 
       
    41 using namespace ContentAccess;
       
    42 
       
    43 // local to this file, non standard mimetype used for ASF parsing with helix
       
    44 _LIT( KHxMimeTypeWma, "audio/x-hx-wma" );
       
    45 _LIT( KHxMimeTypeWmv, "video/x-hx-wmv" );
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // MmMtpDpUtility::FormatFromFilename
       
    49 // Utility function to get the type of an object from the filename
       
    50 // The recommended way from the MS implementation
       
    51 // These should be kept in sync with the object formats supported
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 EXPORT_C TMTPFormatCode MmMtpDpUtility::FormatFromFilename( const TDesC& aFullFileName )
       
    55     {
       
    56     if ( aFullFileName.Right( 1 ).CompareF( KTxtBackSlash ) == 0 ) // We have a directory name
       
    57         {
       
    58         return EMTPFormatCodeAssociation;
       
    59         }
       
    60 
       
    61     TParsePtrC file( aFullFileName );
       
    62 
       
    63     // need to do it in popularity of format, to optmize performance
       
    64     if ( file.Ext().CompareF( KTxtExtensionMP3 ) == 0 )
       
    65             return EMTPFormatCodeMP3;
       
    66 
       
    67 #ifdef __WINDOWS_MEDIA
       
    68     if ( file.Ext().CompareF( KTxtExtensionWMA ) == 0 )
       
    69             return EMTPFormatCodeWMA;
       
    70 #endif // __WINDOWS_MEDIA
       
    71     
       
    72     if ( ( file.Ext().CompareF( KTxtExtensionMP4 ) == 0 ) || ( file.Ext().CompareF( KTxtExtensionM4A ) == 0 ) )
       
    73         return EMTPFormatCodeMP4Container;
       
    74 
       
    75     if ( ( file.Ext().CompareF( KTxtExtension3GP ) == 0 ) || ( file.Ext().CompareF( KTxtExtensionO4A ) == 0 ) || ( file.Ext().CompareF( KTxtExtensionO4V ) == 0 ) )
       
    76         return EMTPFormatCode3GPContainer;
       
    77 
       
    78     if ( file.Ext().CompareF( KTxtExtensionAAC ) == 0 )
       
    79         return EMTPFormatCodeAAC;
       
    80     
       
    81     if ( file.Ext().CompareF( KTxtExtensionWAV ) == 0 )
       
    82         return EMTPFormatCodeWAV;
       
    83     
       
    84 #ifdef __WINDOWS_MEDIA
       
    85     if ( file.Ext().CompareF( KTxtExtensionWMV ) == 0 )
       
    86         return EMTPFormatCodeWMV;
       
    87     
       
    88     if ( file.Ext().CompareF( KTxtExtensionASF ) == 0 )
       
    89         return EMTPFormatCodeASF;
       
    90 
       
    91 #endif // __WINDOWS_MEDIA
       
    92 
       
    93     if ( file.Ext().CompareF( KTxtExtensionODF ) == 0 )
       
    94         {
       
    95         HBufC8* mime = MmMtpDpUtility::ContainerMimeType( file.FullName() );
       
    96         if ( mime != NULL )
       
    97             {
       
    98             // 3GP
       
    99             if ( mime->CompareF( KMimeTypeAudio3gpp ) == 0
       
   100                 || mime->CompareF( KMimeTypeVideo3gpp ) == 0 )
       
   101                 {
       
   102                 delete mime;
       
   103                 mime = NULL;
       
   104                 return EMTPFormatCode3GPContainer;
       
   105                 }
       
   106             }
       
   107 
       
   108         if ( mime != NULL )
       
   109             {
       
   110             delete mime;
       
   111             mime = NULL;
       
   112             }
       
   113         }
       
   114 
       
   115     if (( file.Ext().CompareF( KTxtExtensionPLA ) == 0 ) || ( file.Ext().CompareF( KTxtExtensionVIR ) == 0 ) )
       
   116         return EMTPFormatCodeAbstractAudioVideoPlaylist;
       
   117 
       
   118     if ( file.Ext().CompareF( KTxtExtensionM3U ) == 0 )
       
   119         return EMTPFormatCodeM3UPlaylist;
       
   120 
       
   121     return EMTPFormatCodeUndefined;
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // MmMtpDpUtility::HasMetadata
       
   126 // Utility function to determine whether a format has metadata support
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 TBool MmMtpDpUtility::HasMetadata( TUint16 aObjFormatCode )
       
   130     {
       
   131     if ( aObjFormatCode == EMTPFormatCodeMP3
       
   132         || aObjFormatCode == EMTPFormatCodeWMA
       
   133         || aObjFormatCode == EMTPFormatCodeAAC
       
   134         || aObjFormatCode == EMTPFormatCodeWAV
       
   135         || aObjFormatCode == EMTPFormatCodeMP4Container
       
   136         || aObjFormatCode == EMTPFormatCode3GPContainer
       
   137         || aObjFormatCode == EMTPFormatCodeWMV
       
   138         || aObjFormatCode == EMTPFormatCodeASF )
       
   139         {
       
   140         return ETrue;
       
   141         }
       
   142 
       
   143     return EFalse;
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // MmMtpDpUtility::IsVideoL (Slow Version)
       
   148 // Utility function to determine whether a format is Video or not
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 EXPORT_C TBool MmMtpDpUtility::IsVideoL( const TDesC& aFullFileName )
       
   152     {
       
   153     PRINT1( _L( "MM MTP => MmMtpDpUtility::IsVideoL (Slow Version) aFullFileName = %S" ), &aFullFileName );
       
   154 
       
   155     TParse pathParser;
       
   156     User::LeaveIfError( pathParser.Set( aFullFileName, NULL, NULL ) );
       
   157 
       
   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;
       
   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     }
       
   243 
       
   244 // -----------------------------------------------------------------------------
       
   245 // MmMtpDpUtility::ValidateFilename
       
   246 // Check the filename to see if it exceeds Symbian 256 limit.
       
   247 // -----------------------------------------------------------------------------
       
   248 //
       
   249 TBool MmMtpDpUtility::ValidateFilename( const TDesC& aPathName,
       
   250     const TDesC& aFileName )
       
   251     {
       
   252     TBool result = ETrue;
       
   253 
       
   254     if ( ( aPathName.Length() + aFileName.Length() ) > KMaxFileName )
       
   255         {
       
   256         result = EFalse;
       
   257         }
       
   258 
       
   259     return result;
       
   260     }
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 // MmMtpDpUtility::GetObjectSizeL
       
   264 // Get the filesize.
       
   265 // -----------------------------------------------------------------------------
       
   266 //
       
   267 TUint64 MmMtpDpUtility::GetObjectSizeL( RFs& aFs, const TDesC& aFileName )
       
   268     {
       
   269     TEntry fileInfo;
       
   270     // Shouldn't leave
       
   271     User::LeaveIfError( aFs.Entry( aFileName, fileInfo ) );
       
   272     return fileInfo.iSize;
       
   273     }
       
   274 
       
   275 // -----------------------------------------------------------------------------
       
   276 // MmMtpDpUtility::GetDateModifiedL
       
   277 // Get the file date modified.
       
   278 // -----------------------------------------------------------------------------
       
   279 //
       
   280 TTime MmMtpDpUtility::GetObjectDateModifiedL( RFs& aFs, const TDesC& aFullFileName )
       
   281     {
       
   282     TTime dataModified;
       
   283     TEntry fileInfo;
       
   284     // Shouldn't leave
       
   285     User::LeaveIfError( aFs.Entry( aFullFileName, fileInfo ) );
       
   286 
       
   287     dataModified = fileInfo.iModified;
       
   288 
       
   289     return dataModified;
       
   290     }
       
   291 
       
   292 // -----------------------------------------------------------------------------
       
   293 // MmMtpDpUtility::GetProtectionStatusL
       
   294 // Get the file protection status.
       
   295 // -----------------------------------------------------------------------------
       
   296 //
       
   297 TUint16 MmMtpDpUtility::GetProtectionStatusL( RFs& aFs, const TDesC& aFullFileName )
       
   298     {
       
   299     TUint16 protectionStatus = EMTPProtectionNoProtection;
       
   300 
       
   301     TEntry fileInfo;
       
   302     // Shouldn't leave
       
   303     User::LeaveIfError( aFs.Entry( aFullFileName, fileInfo ) );
       
   304     if ( fileInfo.IsReadOnly() )
       
   305         {
       
   306         protectionStatus = EMTPProtectionReadOnly;
       
   307         }
       
   308 
       
   309     return protectionStatus;
       
   310     }
       
   311 
       
   312 // -----------------------------------------------------------------------------
       
   313 // MmMtpDpUtility::CheckPropType
       
   314 // Check if property type match datatype.
       
   315 // -----------------------------------------------------------------------------
       
   316 //
       
   317 TMTPResponseCode MmMtpDpUtility::CheckPropType(TUint16 aPropertyCode, TUint16 aDataType)
       
   318     {
       
   319     PRINT2( _L( "MM MTP => MmMtpDpUtility::CheckPropCode aPropertyCode = 0x%x, aDataType = 0x%x" ), 
       
   320         aPropertyCode, 
       
   321         aDataType );
       
   322 
       
   323     TMTPResponseCode responseCode = EMTPRespCodeOK;
       
   324     switch ( aPropertyCode )
       
   325         {
       
   326         //Access denied Properties
       
   327         case EMTPObjectPropCodeStorageID:
       
   328         case EMTPObjectPropCodeObjectFormat:
       
   329         case EMTPObjectPropCodeProtectionStatus:
       
   330         case EMTPObjectPropCodeObjectSize:
       
   331         case EMTPObjectPropCodeParentObject:
       
   332         case EMTPObjectPropCodePersistentUniqueObjectIdentifier:
       
   333         case EMTPObjectPropCodeDateCreated:
       
   334         case EMTPObjectPropCodeDateModified:
       
   335         case EMTPObjectPropCodeDateAdded:
       
   336         case EMTPObjectPropCodeNonConsumable:
       
   337         case EMTPObjectPropCodeVideoBitRate:
       
   338             {
       
   339             responseCode = EMTPRespCodeAccessDenied;
       
   340             }
       
   341             break;
       
   342 
       
   343         //String properties
       
   344         case EMTPObjectPropCodeObjectFileName: // 0xDC07
       
   345         case EMTPObjectPropCodeName: // 0xDC44
       
   346         case EMTPObjectPropCodeArtist: // 0xDC46
       
   347         case EMTPObjectPropCodeGenre: // 0xDC8C
       
   348         case EMTPObjectPropCodeParentalRating: // 0xDC94
       
   349         case EMTPObjectPropCodeComposer: // 0xDC96
       
   350         case EMTPObjectPropCodeOriginalReleaseDate: // 0xDC99
       
   351         case EMTPObjectPropCodeAlbumName: // 0xDC9A
       
   352         case EMTPObjectPropCodeEncodingProfile: // 0xDEA1
       
   353             {
       
   354             if ( aDataType != EMTPTypeString )
       
   355                 {
       
   356                 responseCode = EMTPRespCodeInvalidObjectPropFormat;
       
   357                 }
       
   358             }
       
   359             break;
       
   360 
       
   361         case EMTPObjectPropCodeDescription:
       
   362             {
       
   363             if ( aDataType != EMTPTypeAUINT16 )
       
   364                 {
       
   365                 responseCode = EMTPRespCodeInvalidObjectPropFormat;
       
   366                 }
       
   367             }
       
   368             break;
       
   369 
       
   370         //Uint32 properties
       
   371         case EMTPObjectPropCodeWidth: // 0xDC87
       
   372         case EMTPObjectPropCodeHeight: // 0xDC88
       
   373         case EMTPObjectPropCodeDuration: // 0xDC89
       
   374         case EMTPObjectPropCodeUseCount: // 0xDC91
       
   375         case EMTPObjectPropCodeSampleRate: // 0xDE93
       
   376         case EMTPObjectPropCodeAudioWAVECodec: // 0xDE99
       
   377         case EMTPObjectPropCodeAudioBitRate: // 0xDE9A
       
   378         case EMTPObjectPropCodeVideoFourCCCodec: // 0xDE9B
       
   379         case EMTPObjectPropCodeFramesPerThousandSeconds: // 0xDE9D
       
   380         case EMTPObjectPropCodeKeyFrameDistance: // 0xDE9E
       
   381             {
       
   382             if ( aDataType != EMTPTypeUINT32 )
       
   383                 {
       
   384                 responseCode = EMTPRespCodeInvalidObjectPropFormat;
       
   385                 }
       
   386             }
       
   387             break;
       
   388 
       
   389         //Uint16 properties
       
   390         case EMTPObjectPropCodeTrack: // 0xDC8B
       
   391         case EMTPObjectPropCodeDRMStatus: // 0xDC9D
       
   392         case EMTPObjectPropCodeNumberOfChannels: // 0xDE94
       
   393         case EMTPObjectPropCodeScanType: // 0xDE97
       
   394             {
       
   395             if ( aDataType != EMTPTypeUINT16 )
       
   396                 {
       
   397                 responseCode = EMTPRespCodeInvalidObjectPropFormat;
       
   398                 }
       
   399             }
       
   400             break;
       
   401 
       
   402         default:
       
   403             {
       
   404             responseCode = EMTPRespCodeInvalidObjectPropCode;
       
   405             }
       
   406             break;
       
   407         }
       
   408     PRINT1( _L( "MM MTP <= MmMtpDpUtility::CheckPropCode responseCode = 0x%x" ), 
       
   409         responseCode );
       
   410     return responseCode;
       
   411     }
       
   412 
       
   413 // -----------------------------------------------------------------------------
       
   414 // MmMtpDpUtility::UpdateObjectFileName
       
   415 // Update object file name.
       
   416 // -----------------------------------------------------------------------------
       
   417 //
       
   418 TInt MmMtpDpUtility::UpdateObjectFileName( RFs& aFs,
       
   419     const TDesC& aFullFileName,
       
   420     TDes& aNewName )
       
   421     {
       
   422     TInt bufSize = aNewName.MaxLength() < KMaxFileName ? aNewName.MaxLength() : KMaxFileName;
       
   423 
       
   424     TParsePtrC parser( aFullFileName );
       
   425     TPtrC ptr( parser.DriveAndPath() );
       
   426 
       
   427     if ( aNewName.Length() + ptr.Length() > bufSize )
       
   428         {
       
   429         return KErrOverflow;
       
   430         }
       
   431     else
       
   432         {
       
   433         aNewName.Insert( 0, ptr );
       
   434         }
       
   435 
       
   436     return aFs.Rename( aFullFileName, aNewName );
       
   437     }
       
   438     
       
   439 // -----------------------------------------------------------------------------
       
   440 // MetadataAccessWrapper::ContainerMimeType
       
   441 // Get mime type from file
       
   442 // -----------------------------------------------------------------------------
       
   443 //
       
   444 HBufC8* MmMtpDpUtility::ContainerMimeType( const TDesC& aFullPath )
       
   445     {
       
   446     PRINT( _L( "MM MTP => MmMtpDpUtility::ContainerMimeType" ) );
       
   447 
       
   448     // parse the file path
       
   449     TParse pathParser;
       
   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 
       
   457     // get the extension of file
       
   458     TPtrC ext( pathParser.Ext() );
       
   459     if ( ext.Length() <= 0 )
       
   460         {
       
   461         PRINT( _L( "MM MTP <> MmMtpDpUtility::ContainerMimeType file ext len == 0" ) );
       
   462         return NULL;
       
   463         }
       
   464 
       
   465     HBufC8* mimebuf = NULL;
       
   466     TInt err = KErrNone;
       
   467 
       
   468     // MP4/3GP
       
   469     if ( ext.CompareF( KTxtExtensionMP4 ) == 0
       
   470         || ext.CompareF( KTxtExtension3GP ) == 0 )
       
   471         {
       
   472         TRAP( err, mimebuf = Mp4MimeTypeL( aFullPath ) );
       
   473         PRINT1( _L("MM MTP <> MmMtpDpUtility::ContainerMimeType, Mp4MimeTypeL err = %d"), err );
       
   474         }
       
   475     else if ( ext.CompareF( KTxtExtensionODF ) == 0 )
       
   476         {
       
   477         TRAP( err, mimebuf = Mp4MimeTypeL( aFullPath ) );
       
   478         PRINT1( _L("MM MTP <> MmMtpDpUtility::ContainerMimeType, OdfMimeTypeL err = %d"), err );
       
   479         }
       
   480 #ifdef __WINDOWS_MEDIA
       
   481     else if ( ext.CompareF( KTxtExtensionASF ) == 0 )
       
   482         {
       
   483         TRAP( err, mimebuf = AsfMimeTypeL( aFullPath ) );
       
   484         PRINT1( _L("MM MTP <> MmMtpDpUtility::ContainerMimeType, AsfMimeTypeL err = %d"), err );
       
   485         }
       
   486 #endif
       
   487     
       
   488     PRINT( _L( "MM MTP <= MmMtpDpUtility::ContainerMimeType" ) );
       
   489     return mimebuf;
       
   490     }
       
   491 
       
   492 // -----------------------------------------------------------------------------
       
   493 // MetadataAccessWrapper::Mp4MimeTypeL
       
   494 // Get mime type from mp4 file
       
   495 // -----------------------------------------------------------------------------
       
   496 //
       
   497 HBufC8* MmMtpDpUtility::Mp4MimeTypeL( const TDesC& aFullPath )
       
   498     {
       
   499     PRINT( _L( "MM MTP => MmMtpDpUtility::Mp4MimeTypeL" ) );
       
   500     HBufC8* mimebuf = NULL;
       
   501     TParsePtrC file( aFullPath );
       
   502     
       
   503     if ( file.Ext().CompareF( KTxtExtensionMP4 ) == 0
       
   504         || file.Ext().CompareF( KTxtExtension3GP ) == 0 )
       
   505         {
       
   506         // get mime from file
       
   507         MP4Handle mp4Handle = NULL;
       
   508 
       
   509         RBuf buf;
       
   510         TInt err = buf.Create( aFullPath.Length() + 1 );
       
   511         User::LeaveIfError( err );
       
   512         buf = aFullPath;
       
   513 
       
   514         // open mp4 file
       
   515         MP4Err mp4err = MP4ParseOpen( &mp4Handle, (MP4FileName) buf.PtrZ() );
       
   516 
       
   517         if ( mp4err == MP4_OK )
       
   518             {
       
   519 
       
   520             mp4_u32 videoLength, videoType, videoWidth, videoHeight, timeScale;
       
   521             mp4_double frameRate;
       
   522 
       
   523             // get video description
       
   524             mp4err = MP4ParseRequestVideoDescription( mp4Handle, &videoLength,
       
   525                 &frameRate, &videoType, &videoWidth, &videoHeight, &timeScale );
       
   526 
       
   527             // not the video file
       
   528             if ( mp4err == MP4_NO_VIDEO )
       
   529                 {
       
   530                 mp4_u32 audioLength, audioType, timeScale, averateBitRate;
       
   531                 mp4_u8 framesPerSample;
       
   532 
       
   533                 // get audio description
       
   534                 mp4err = MP4ParseRequestAudioDescription( mp4Handle,
       
   535                     &audioLength, &audioType, &framesPerSample, &timeScale,
       
   536                     &averateBitRate );
       
   537 
       
   538                 if ( mp4err == MP4_OK )
       
   539                     {
       
   540                     if ( file.Ext().CompareF( KTxtExtension3GP ) == 0 )
       
   541                         {
       
   542                         mimebuf = KMimeTypeAudio3gpp().Alloc();
       
   543                         }
       
   544                     else
       
   545                         {
       
   546                         mimebuf = KMimeTypeAudioMp4().Alloc();
       
   547                         }
       
   548                     }
       
   549                 }
       
   550             // is video file
       
   551             else if ( mp4err == MP4_OK )
       
   552                 {
       
   553                 if ( file.Ext().CompareF( KTxtExtension3GP ) == 0 )
       
   554                     {
       
   555                     mimebuf = KMimeTypeVideo3gpp().Alloc();
       
   556                     }
       
   557                 else
       
   558                     {
       
   559                     mimebuf = KMimeTypeVideoMp4().Alloc();
       
   560                     }
       
   561                 }
       
   562 
       
   563             // Close mp4 parser
       
   564             if ( mp4Handle != NULL )
       
   565                 {
       
   566                 MP4ParseClose( mp4Handle );
       
   567                 }
       
   568             }
       
   569 
       
   570         buf.Close();
       
   571         }
       
   572     else
       
   573         {
       
   574         User::Leave( KErrNotSupported );
       
   575         }
       
   576     
       
   577     if ( mimebuf == NULL )
       
   578         {
       
   579         User::Leave( KErrNotFound );
       
   580         }
       
   581     PRINT( _L( "MM MTP <= MmMtpDpUtility::Mp4MimeTypeL" ) );
       
   582     return mimebuf;
       
   583     }
       
   584 
       
   585 // -----------------------------------------------------------------------------
       
   586 // MetadataAccessWrapper::OdfMimeTypeL
       
   587 // Get mime type from odf file
       
   588 // -----------------------------------------------------------------------------
       
   589 //
       
   590 HBufC8* MmMtpDpUtility::OdfMimeTypeL( const TDesC& aFullPath )
       
   591     {
       
   592     PRINT( _L( "MM MTP => MmMtpDpUtility::OdfMimeTypeL" ) );
       
   593     HBufC8* mimebuf = NULL;
       
   594     
       
   595     TParsePtrC file( aFullPath );
       
   596         
       
   597     if ( file.Ext().CompareF( KTxtExtensionODF ) == 0 )
       
   598         {    
       
   599         CContent* content = CContent::NewL( aFullPath );
       
   600         CleanupStack::PushL( content ); // + content
       
   601         
       
   602         HBufC* buffer = HBufC::NewL( KMimeTypeMaxLength );
       
   603         CleanupStack::PushL( buffer ); // + buffer
       
   604         
       
   605         TPtr data = buffer->Des();
       
   606         TInt err = content->GetStringAttribute( EMimeType, data );
       
   607                 
       
   608         if ( err == KErrNone )
       
   609             {
       
   610             mimebuf = HBufC8::New( buffer->Length() );
       
   611     
       
   612             if (mimebuf == NULL)
       
   613                 {
       
   614                 User::LeaveIfError( KErrNotFound );
       
   615                 }
       
   616             
       
   617             mimebuf->Des().Copy( *buffer );
       
   618             }
       
   619         
       
   620         // leave if NULL
       
   621         if ( mimebuf == NULL )
       
   622             {
       
   623             User::Leave( KErrNotFound );
       
   624             }
       
   625         
       
   626         CleanupStack::PopAndDestroy( buffer ); // - buffer
       
   627         CleanupStack::PopAndDestroy( content ); // - content
       
   628         }
       
   629     else
       
   630         {
       
   631         User::Leave( KErrNotSupported );
       
   632         }
       
   633     
       
   634     PRINT( _L( "MM MTP <= MmMtpDpUtility::OdfMimeTypeL" ) );
       
   635     return mimebuf;
       
   636     }
       
   637 
       
   638 // -----------------------------------------------------------------------------
       
   639 // MetadataAccessWrapper::AsfMimeTypeL
       
   640 // Get mime type from asf file
       
   641 // -----------------------------------------------------------------------------
       
   642 //
       
   643 HBufC8* MmMtpDpUtility::AsfMimeTypeL( const TDesC& aFullPath )
       
   644     {
       
   645     PRINT( _L( "MM MTP => MmMtpDpUtility::AsfMimeTypeL" ) );
       
   646     
       
   647     HBufC8* mimebuf = NULL;
       
   648     
       
   649 #ifdef __WINDOWS_MEDIA
       
   650     TParsePtrC file( aFullPath );
       
   651     
       
   652     if ( file.Ext().CompareF( KTxtExtensionASF ) == 0 )
       
   653         {
       
   654         CHXMetaDataUtility *hxUtility = CHXMetaDataUtility::NewL();
       
   655         CleanupStack::PushL( hxUtility );
       
   656     
       
   657         hxUtility->OpenFileL( aFullPath );
       
   658         
       
   659         HXMetaDataKeys::EHXMetaDataId id;
       
   660         TUint count = 0;
       
   661         TBool isAudio = EFalse;
       
   662         hxUtility->GetMetaDataCount( count );
       
   663         for ( TUint i = 0; i < count; i++ )
       
   664             {    
       
   665             HBufC* buf = NULL;
       
   666             hxUtility->GetMetaDataAt( i, id, buf ); 
       
   667 
       
   668             if ( id == HXMetaDataKeys::EHXMimeType )
       
   669                 {
       
   670                 TPtr des = buf->Des();
       
   671                 
       
   672                 if ( des.Find( KHxMimeTypeWma() ) != KErrNotFound )
       
   673                     {
       
   674                     isAudio = ETrue;
       
   675                     }
       
   676                 else if ( des.Find( KHxMimeTypeWmv() ) != KErrNotFound )
       
   677                     {
       
   678                     PRINT( _L( "MM MTP <> MmMtpDpUtility::AsfMimeTypeL, video" ) );
       
   679                     mimebuf = KMimeTypeVideoWm().Alloc();
       
   680                     break;
       
   681                     }
       
   682                 }
       
   683             else if ( i == count - 1 )
       
   684                 {
       
   685                 if ( isAudio )
       
   686                     {
       
   687                     PRINT( _L( "MM MTP <> MmMtpDpUtility::AsfMimeTypeL, audio" ) );
       
   688                     mimebuf = KMimeTypeAudioWm().Alloc();
       
   689                     }
       
   690                 else
       
   691                     {
       
   692                     User::Leave( KErrNotFound );
       
   693                     }
       
   694                 }
       
   695             }
       
   696 
       
   697         hxUtility->ResetL();
       
   698         CleanupStack::PopAndDestroy( hxUtility );        
       
   699         }
       
   700     else
       
   701         {
       
   702         User::Leave( KErrNotSupported );
       
   703         }
       
   704 
       
   705 #else
       
   706     User::Leave( KErrNotSupported );
       
   707 #endif
       
   708     
       
   709     PRINT( _L( "MM MTP <= MmMtpDpUtility::AsfMimeTypeL" ) );
       
   710     return mimebuf;
       
   711     }
       
   712 
       
   713 // -----------------------------------------------------------------------------
       
   714 // MetadataAccessWrapper::SubFormatCodeFromMime
       
   715 // Get subformat code from mime string
       
   716 // -----------------------------------------------------------------------------
       
   717 //
       
   718 TInt MmMtpDpUtility::SubFormatCodeFromMime( const TDesC8& aMimeType, 
       
   719     TMmMtpSubFormatCode& aSubFormatCode )
       
   720     {
       
   721     PRINT( _L( "MM MTP => MmMtpDpUtility::SubFormatCodeFromMime" ) );
       
   722 
       
   723     if ( aMimeType.CompareF( KMimeTypeVideoMp4 ) == 0
       
   724         || aMimeType.CompareF( KMimeTypeVideo3gpp ) == 0
       
   725 #ifdef __WINDOWS_MEDIA
       
   726         || aMimeType.CompareF( KMimeTypeVideoWm ) == 0
       
   727 #endif
       
   728         )
       
   729         {
       
   730         aSubFormatCode = EMTPSubFormatCodeVideo;
       
   731         }
       
   732     else if ( aMimeType.CompareF( KMimeTypeAudioMp4 ) == 0
       
   733         || aMimeType.CompareF( KMimeTypeAudio3gpp ) == 0
       
   734 #ifdef __WINDOWS_MEDIA
       
   735         || aMimeType.CompareF( KMimeTypeAudioWm ) == 0
       
   736 #endif
       
   737         )
       
   738         {
       
   739         aSubFormatCode = EMTPSubFormatCodeAudio;
       
   740         }
       
   741     else
       
   742         {
       
   743         PRINT( _L( "MM MTP <= MmMtpDpUtility::SubFormatCodeFromMime format not supported" ) );
       
   744         return KErrNotFound;
       
   745         }
       
   746 
       
   747     PRINT( _L( "MM MTP <= MmMtpDpUtility::SubFormatCodeFromMime" ) );
       
   748     return KErrNone;
       
   749     }
       
   750 
       
   751 // -----------------------------------------------------------------------------
       
   752 // MetadataAccessWrapper::GetDrmStatus
       
   753 // Get drm status code from file
       
   754 // -----------------------------------------------------------------------------
       
   755 //
       
   756 EXPORT_C TInt MmMtpDpUtility::GetDrmStatus( const TDesC& aFullFileName )
       
   757     {
       
   758     PRINT1( _L( "MM MTP => MmMtpDpUtility::GetDrmStatus, full file name: %S" ), &aFullFileName );
       
   759     TParsePtrC file( aFullFileName );
       
   760     TInt drmStatus = EMTPDrmStatusUnknown;
       
   761 
       
   762     if ( ( file.Ext().CompareF( KTxtExtensionODF ) == 0 ) ||
       
   763          ( file.Ext().CompareF( KTxtExtensionO4A ) == 0 ) ||
       
   764          ( file.Ext().CompareF( KTxtExtensionO4V ) == 0 ) )
       
   765         {
       
   766         CContent* content = NULL;
       
   767 
       
   768         TRAPD( err, content = CContent::NewL( aFullFileName ) );
       
   769 
       
   770         if ( err == KErrNone )
       
   771             {
       
   772             TInt value = 0;
       
   773 
       
   774             content->GetAttribute( EIsProtected, value );
       
   775 
       
   776             if ( value != 0 )
       
   777                 {
       
   778                 drmStatus = EMTPDrmStatusProtected;
       
   779                 }
       
   780             else
       
   781                 {
       
   782                 drmStatus = EMTPDrmStatusNotProtected;
       
   783                 }
       
   784             }
       
   785 
       
   786         if ( content )
       
   787             {
       
   788             delete content;
       
   789             content = NULL;
       
   790             }
       
   791         }
       
   792 
       
   793     PRINT1( _L( "MM MTP <= MmMtpDpUtility::GetDrmStatus, drmStatus: %d" ), drmStatus );
       
   794     
       
   795     return drmStatus;
       
   796     }
       
   797 
       
   798 //end of file