mmappcomponents/harvester/metadataextractor/src/mpxmetadataextractor.cpp
changeset 48 b7b49303d0c0
parent 45 09978a29cfde
child 54 fa0adf088850
equal deleted inserted replaced
45:09978a29cfde 48:b7b49303d0c0
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  Extracts metadata from a file
    14 * Description:  Extracts metadata from a file
    15 *  Version     : %version: da1mmcf#38.1.4.2.6.1.5.3.5 % << Don't touch! Updated by Synergy at check-out.
    15 *  Version     : %version: da1mmcf#38.1.4.2.6.1.5.3.6 % << Don't touch! Updated by Synergy at check-out.
    16 *
    16 *
    17 */
    17 */
    18 
    18 
    19 #include <e32base.h>
    19 #include <e32base.h>
    20 #include <badesca.h>
    20 #include <badesca.h>
    50 _LIT( KWmaCafMimeType, "x-caf-audio/x-ms-wma" );
    50 _LIT( KWmaCafMimeType, "x-caf-audio/x-ms-wma" );
    51 
    51 
    52 #ifdef RD_MPX_TNM_INTEGRATION
    52 #ifdef RD_MPX_TNM_INTEGRATION
    53 _LIT( KImageFileType, "image/jpeg" );
    53 _LIT( KImageFileType, "image/jpeg" );
    54 const TInt KMPXTimeoutTimer = 3000000; // 3 seconds
    54 const TInt KMPXTimeoutTimer = 3000000; // 3 seconds
    55 const TInt KMPXMaxThumbnailRequest = 2; 
    55 const TInt KMPXMaxThumbnailRequest = 2;
    56 #endif //RD_MPX_TNM_INTEGRATION
    56 #endif //RD_MPX_TNM_INTEGRATION
    57 
    57 
    58 #ifdef ABSTRACTAUDIOALBUM_INCLUDED
    58 #ifdef ABSTRACTAUDIOALBUM_INCLUDED
    59 _LIT( KNonEmbeddedArtExt, ".alb" );
    59 _LIT( KNonEmbeddedArtExt, ".alb" );
    60 #endif
    60 #endif
   184     iFileOpenError = KErrNone;
   184     iFileOpenError = KErrNone;
   185     iObs = NULL;
   185     iObs = NULL;
   186     aNewProperty = NULL;
   186     aNewProperty = NULL;
   187     iFileName = aFile;
   187     iFileName = aFile;
   188     iMetadataOnly = aMetadataOnly;
   188     iMetadataOnly = aMetadataOnly;
   189     
   189 
   190     // populate the task array
   190     // populate the task array
   191     AddTasksL();
   191     AddTasksL();
   192     
   192 
   193     // execute all tasks in the array
   193     // execute all tasks in the array
   194     while ( iArrayTasks.Count() )
   194     while ( iArrayTasks.Count() )
   195         {
   195         {
   196         // execute task at index 0
   196         // execute task at index 0
   197         MPX_TRAPD( error, ExecuteTaskL() );
   197         MPX_TRAPD( error, ExecuteTaskL() );
   209                 CleanUp();
   209                 CleanUp();
   210                 User::LeaveIfError( error );
   210                 User::LeaveIfError( error );
   211                 }
   211                 }
   212             break;
   212             break;
   213             }
   213             }
   214         
   214 
   215         iArrayTasks.Remove( 0 );
   215         iArrayTasks.Remove( 0 );
   216         }
   216         }
   217     
   217 
   218     aNewProperty = iMedia;
   218     aNewProperty = iMedia;
   219     iMedia = NULL;  // ownership transferred.
   219     iMedia = NULL;  // ownership transferred.
   220     CleanUp();
   220     CleanUp();
   221     }
   221     }
   222 
   222 
   234     aMediaProp.SetTextValueL( KMPXMediaMusicArtist,
   234     aMediaProp.SetTextValueL( KMPXMediaMusicArtist,
   235                               KNullDesC );
   235                               KNullDesC );
   236     // Album
   236     // Album
   237     aMediaProp.SetTextValueL( KMPXMediaMusicAlbum,
   237     aMediaProp.SetTextValueL( KMPXMediaMusicAlbum,
   238                               KNullDesC );
   238                               KNullDesC );
   239     // Year
       
   240     aMediaProp.SetTObjectValueL<TInt64>( KMPXMediaMusicYear,
       
   241                                          (TInt64) 0 );
       
   242     // Track
   239     // Track
   243     aMediaProp.SetTextValueL( KMPXMediaMusicAlbumTrack,
   240     aMediaProp.SetTextValueL( KMPXMediaMusicAlbumTrack,
   244                               KNullDesC );
   241                               KNullDesC );
   245     // Genre
   242     // Genre
   246     aMediaProp.SetTextValueL( KMPXMediaMusicGenre,
   243     aMediaProp.SetTextValueL( KMPXMediaMusicGenre,
   265     MPX_FUNC("CMPXMetadataExtractor::SetMediaPropertiesL()");
   262     MPX_FUNC("CMPXMetadataExtractor::SetMediaPropertiesL()");
   266 
   263 
   267     const TDesC& mimeType = iMedia->ValueText( KMPXMediaGeneralMimeType );
   264     const TDesC& mimeType = iMedia->ValueText( KMPXMediaGeneralMimeType );
   268     HBufC8* mimeType8 = HBufC8::NewLC( mimeType.Length() );
   265     HBufC8* mimeType8 = HBufC8::NewLC( mimeType.Length() );
   269     mimeType8->Des().Append( mimeType );
   266     mimeType8->Des().Append( mimeType );
   270     
   267 
   271     // Continue to extract metadata even if fail.
   268     // Continue to extract metadata even if fail.
   272     MPX_TRAPD( metadataerror, iMetadataUtility->OpenFileL( iFile, *mimeType8 ) );
   269     MPX_TRAPD( metadataerror, iMetadataUtility->OpenFileL( iFile, *mimeType8 ) );
   273     CleanupStack::PopAndDestroy( mimeType8 );
   270     CleanupStack::PopAndDestroy( mimeType8 );
   274     
   271 
   275     // Get MetadataUtility Container
   272     // Get MetadataUtility Container
   276     const CMetaDataFieldContainer& metaCont = iMetadataUtility->MetaDataFieldsL();
   273     const CMetaDataFieldContainer& metaCont = iMetadataUtility->MetaDataFieldsL();
   277 
   274 
   278     // Get DRM data
   275     // Get DRM data
   279     // Need the protected flag from metadataUtility Container
   276     // Need the protected flag from metadataUtility Container
   280     MPX_TRAPD( drmerror, SetDrmMediaPropertiesL( metaCont ) );
   277     MPX_TRAPD( drmerror, SetDrmMediaPropertiesL( metaCont ) );
   281     MPX_DEBUG2("CMPXMetadataExtractor::SetMediaPropertiesL, result=%d getting drm data", 
   278     MPX_DEBUG2("CMPXMetadataExtractor::SetMediaPropertiesL, result=%d getting drm data",
   282             drmerror );
   279             drmerror );
   283         
   280 
   284     // Get metadata fields
   281     // Get metadata fields
   285     TInt count( metaCont.Count() );
   282     TInt count( metaCont.Count() );
   286     for( TInt i=0; i<count; ++i )
   283     for( TInt i=0; i<count; ++i )
   287         {
   284         {
   288         TMetaDataFieldId fieldType;
   285         TMetaDataFieldId fieldType;
   289 
   286 
   290         HBufC* value = NULL;
   287         HBufC* value = NULL;
   291         metaCont.FieldIdAt( i, fieldType );  // get the field type
   288         metaCont.FieldIdAt( i, fieldType );  // get the field type
   292         
   289 
   293         // get the value, except for album art
   290         // get the value, except for album art
   294         if ( fieldType != EMetaDataJpeg )
   291         if ( fieldType != EMetaDataJpeg )
   295            {
   292            {
   296             MPX_TRAPD( err, value = metaCont.At( i, fieldType ).AllocL() );
   293             MPX_TRAPD( err, value = metaCont.At( i, fieldType ).AllocL() );
   297            if ( KErrNone != err )
   294            if ( KErrNone != err )
   298                {
   295                {
   299                MPX_DEBUG2("CMPXMetadataExtractor::SetMediaPropertiesL - error = %i", err);           
   296                MPX_DEBUG2("CMPXMetadataExtractor::SetMediaPropertiesL - error = %i", err);
   300                continue;
   297                continue;
   301                }     
   298                }
   302            CleanupStack::PushL( value );
   299            CleanupStack::PushL( value );
   303            }
   300            }
   304         
   301 
   305         switch( fieldType )
   302         switch( fieldType )
   306             {
   303             {
   307             case EMetaDataSongTitle:
   304             case EMetaDataSongTitle:
   308                 {
   305                 {
   309                 TPtr valptr = value->Des();
   306                 TPtr valptr = value->Des();
   407                 {
   404                 {
   408                 iMedia->SetTextValueL( KMPXMediaGeneralCopyright,
   405                 iMedia->SetTextValueL( KMPXMediaGeneralCopyright,
   409                                       *value );
   406                                       *value );
   410                 break;
   407                 break;
   411                 }
   408                 }
   412             case EMetaDataDuration:     
   409             case EMetaDataDuration:
   413                 {                  
   410                 {
   414                 const TDesC& mimeType = iMedia->ValueText( KMPXMediaGeneralMimeType );
   411                 const TDesC& mimeType = iMedia->ValueText( KMPXMediaGeneralMimeType );
   415                 MPX_DEBUG2("CMPXMetadataExtractor::SetMediaPropertiesL, mimeType = %S", &mimeType);   
   412                 MPX_DEBUG2("CMPXMetadataExtractor::SetMediaPropertiesL, mimeType = %S", &mimeType);
   416                 
   413 
   417                 // Verify if WMA, get the duration
   414                 // Verify if WMA, get the duration
   418                 if( mimeType.Compare(KWmaMimeType) == 0 || mimeType.Compare(KWmaCafMimeType) == 0 )
   415                 if( mimeType.Compare(KWmaMimeType) == 0 || mimeType.Compare(KWmaCafMimeType) == 0 )
   419                     {
   416                     {
   420                     MPX_DEBUG1("CMPXMetadataExtractor::SetMediaPropertiesL- WMA");                         
   417                     MPX_DEBUG1("CMPXMetadataExtractor::SetMediaPropertiesL- WMA");
   421 
   418 
   422                     // Perform the duration conversion
   419                     // Perform the duration conversion
   423                     TLex lexer( *value );
   420                     TLex lexer( *value );
   424                     TInt32 duration ( 0 );
   421                     TInt32 duration ( 0 );
   425                     lexer.Val( duration );   // [second]      
   422                     lexer.Val( duration );   // [second]
   426                     duration *= 1000;        // [msec]
   423                     duration *= 1000;        // [msec]
   427                 
   424 
   428                     iMedia->SetTObjectValueL<TInt32>( KMPXMediaGeneralDuration,
   425                     iMedia->SetTObjectValueL<TInt32>( KMPXMediaGeneralDuration,
   429                                                 duration );      
   426                                                 duration );
   430                 
   427 
   431                     MPX_DEBUG2("CMPXMetadataExtractor::SetMediaPropertiesL- duration = %i", duration);  
   428                     MPX_DEBUG2("CMPXMetadataExtractor::SetMediaPropertiesL- duration = %i", duration);
   432                     }
   429                     }
   433                 break;
   430                 break;
   434                 }
   431                 }
   435             case EMetaDataSampleRate:     
   432             case EMetaDataSampleRate:
   436                 {                  
   433                 {
   437                 const TDesC& mimeType = iMedia->ValueText( KMPXMediaGeneralMimeType );
   434                 const TDesC& mimeType = iMedia->ValueText( KMPXMediaGeneralMimeType );
   438                 MPX_DEBUG2("CMPXMetadataExtractor::SetMediaPropertiesL, mimeType = %S", &mimeType);   
   435                 MPX_DEBUG2("CMPXMetadataExtractor::SetMediaPropertiesL, mimeType = %S", &mimeType);
   439                 
   436 
   440                 // Verify if WMA, get the sample rate
   437                 // Verify if WMA, get the sample rate
   441                 if( mimeType.Compare(KWmaMimeType) == 0 || mimeType.Compare(KWmaCafMimeType) == 0 )
   438                 if( mimeType.Compare(KWmaMimeType) == 0 || mimeType.Compare(KWmaCafMimeType) == 0 )
   442                     {
   439                     {
   443                     MPX_DEBUG1("CMPXMetadataExtractor::SetMediaPropertiesL- WMA");                         
   440                     MPX_DEBUG1("CMPXMetadataExtractor::SetMediaPropertiesL- WMA");
   444 
   441 
   445                     // Perform the sample rate conversion
   442                     // Perform the sample rate conversion
   446                     TLex lexer( *value );
   443                     TLex lexer( *value );
   447                     TInt32 sampleRate ( 0 );
   444                     TInt32 sampleRate ( 0 );
   448                     lexer.Val( sampleRate );         
   445                     lexer.Val( sampleRate );
   449                     
   446 
   450                     iMedia->SetTObjectValueL<TUint>( KMPXMediaAudioSamplerate,
   447                     iMedia->SetTObjectValueL<TUint>( KMPXMediaAudioSamplerate,
   451                                                       sampleRate );
   448                                                       sampleRate );
   452                            
   449 
   453                     MPX_DEBUG2("CMPXMetadataExtractor::SetMediaPropertiesL- sample rate = %i", sampleRate);  
   450                     MPX_DEBUG2("CMPXMetadataExtractor::SetMediaPropertiesL- sample rate = %i", sampleRate);
   454                     }
   451                     }
   455                 break;
   452                 break;
   456                 }
   453                 }
   457             case EMetaDataBitRate:     
   454             case EMetaDataBitRate:
   458                 {                  
   455                 {
   459                 const TDesC& mimeType = iMedia->ValueText( KMPXMediaGeneralMimeType );
   456                 const TDesC& mimeType = iMedia->ValueText( KMPXMediaGeneralMimeType );
   460                 MPX_DEBUG2("CMPXMetadataExtractor::SetMediaPropertiesL, mimeType = %S", &mimeType);   
   457                 MPX_DEBUG2("CMPXMetadataExtractor::SetMediaPropertiesL, mimeType = %S", &mimeType);
   461                 
   458 
   462                 // Verify if WMA, get the duration
   459                 // Verify if WMA, get the duration
   463                 if( mimeType.Compare(KWmaMimeType) == 0 || mimeType.Compare(KWmaCafMimeType) == 0 )
   460                 if( mimeType.Compare(KWmaMimeType) == 0 || mimeType.Compare(KWmaCafMimeType) == 0 )
   464                     {
   461                     {
   465                     MPX_DEBUG1("CMPXMetadataExtractor::SetMediaPropertiesL- WMA");                         
   462                     MPX_DEBUG1("CMPXMetadataExtractor::SetMediaPropertiesL- WMA");
   466 
   463 
   467                     // Perform the duration conversion
   464                     // Perform the duration conversion
   468                     TLex lexer( *value );
   465                     TLex lexer( *value );
   469                     TInt32 bitRate ( 0 );
   466                     TInt32 bitRate ( 0 );
   470                     lexer.Val( bitRate );   
   467                     lexer.Val( bitRate );
   471                 
   468 
   472                     iMedia->SetTObjectValueL<TUint>( KMPXMediaAudioBitrate,
   469                     iMedia->SetTObjectValueL<TUint>( KMPXMediaAudioBitrate,
   473                                                      bitRate );
   470                                                      bitRate );
   474                 
   471 
   475                     MPX_DEBUG2("CMPXMetadataExtractor::SetMediaPropertiesL- duration = %i", bitRate);  
   472                     MPX_DEBUG2("CMPXMetadataExtractor::SetMediaPropertiesL- duration = %i", bitRate);
   476                     }
   473                     }
   477                 break;
   474                 break;
   478                 }
   475                 }
   479             case EMetaDataOriginalArtist:  // fall through
   476             case EMetaDataOriginalArtist:  // fall through
   480             case EMetaDataVendor:          // fall through
   477             case EMetaDataVendor:          // fall through
   491                 break;
   488                 break;
   492                 }
   489                 }
   493             }
   490             }
   494         if (fieldType != EMetaDataJpeg)
   491         if (fieldType != EMetaDataJpeg)
   495             {
   492             {
   496             CleanupStack::PopAndDestroy( value );       
   493             CleanupStack::PopAndDestroy( value );
   497             }
   494             }
   498         }
   495         }
   499     }
   496     }
   500 
   497 
   501 // ---------------------------------------------------------------------------
   498 // ---------------------------------------------------------------------------
   511     //
   508     //
   512     TInt size( 0 );
   509     TInt size( 0 );
   513     if( iFileOpenError == KErrNone )
   510     if( iFileOpenError == KErrNone )
   514         {
   511         {
   515         const TDesC& mimeType = iMedia->ValueText( KMPXMediaGeneralMimeType );
   512         const TDesC& mimeType = iMedia->ValueText( KMPXMediaGeneralMimeType );
   516         MPX_DEBUG2("CMPXMetadataExtractor::SetExtMediaPropertiesL, mimeType = %S", &mimeType);   
   513         MPX_DEBUG2("CMPXMetadataExtractor::SetExtMediaPropertiesL, mimeType = %S", &mimeType);
   517         iFile.Size( size );
   514         iFile.Size( size );
   518         iMedia->SetTObjectValueL<TInt>( KMPXMediaGeneralSize, size );
   515         iMedia->SetTObjectValueL<TInt>( KMPXMediaGeneralSize, size );
   519         
   516 
   520         // Verify if WMA, skip getting info from MMF
   517         // Verify if WMA, skip getting info from MMF
   521         if( mimeType.Compare(KWmaMimeType) == 0 || mimeType.Compare(KWmaCafMimeType) == 0 )
   518         if( mimeType.Compare(KWmaMimeType) == 0 || mimeType.Compare(KWmaCafMimeType) == 0 )
   522             {
   519             {
   523             // No need to get MMF support
   520             // No need to get MMF support
   524             MPX_DEBUG1("CMPXMetadataExtractor::SetExtMediaPropertiesL, skip MMF ");   
   521             MPX_DEBUG1("CMPXMetadataExtractor::SetExtMediaPropertiesL, skip MMF ");
   525             }
   522             }
   526         else
   523         else
   527             {
   524             {
   528             MPX_DEBUG1("CMPXMetadataExtractor::SetExtMediaPropertiesL, get MMF controller");   
   525             MPX_DEBUG1("CMPXMetadataExtractor::SetExtMediaPropertiesL, get MMF controller");
   529             // Duration, bitrate, samplerate, etc
   526             // Duration, bitrate, samplerate, etc
   530             //
   527             //
   531             if( !iMetadataOnly )
   528             if( !iMetadataOnly )
   532             {
   529             {
   533                 MPX_TRAPD(err2, iFileInfoUtil->OpenFileL(
   530                 MPX_TRAPD(err2, iFileInfoUtil->OpenFileL(
   534                           iFile, 
   531                           iFile,
   535                           iMedia->ValueText(KMPXMediaGeneralMimeType)));
   532                           iMedia->ValueText(KMPXMediaGeneralMimeType)));
   536                 MPX_DEBUG2("CMPXMetadataExtractor::SetExtMediaPropertiesL, file info util error %i", err2);
   533                 MPX_DEBUG2("CMPXMetadataExtractor::SetExtMediaPropertiesL, file info util error %i", err2);
   537                 if( KErrNone == err2 )
   534                 if( KErrNone == err2 )
   538                     {
   535                     {
   539                     iMedia->SetTObjectValueL<TUint>( KMPXMediaAudioBitrate,
   536                     iMedia->SetTObjectValueL<TUint>( KMPXMediaAudioBitrate,
   544                     iMedia->SetTObjectValueL<TInt32>( KMPXMediaGeneralDuration,
   541                     iMedia->SetTObjectValueL<TInt32>( KMPXMediaGeneralDuration,
   545                                                     duration );
   542                                                     duration );
   546 
   543 
   547                     MPX_DEBUG2("CMPXMetadataExtractor::SetExtMediaPropertiesL -- duration %i", duration);
   544                     MPX_DEBUG2("CMPXMetadataExtractor::SetExtMediaPropertiesL -- duration %i", duration);
   548                     }
   545                     }
   549                 
   546 
   550                 iFileInfoUtil->Reset();
   547                 iFileInfoUtil->Reset();
   551                 }
   548                 }
   552             }
   549             }
   553         }
   550         }
   554     }
   551     }
   580 
   577 
   581 // ---------------------------------------------------------------------------
   578 // ---------------------------------------------------------------------------
   582 // CMPXMetadataExtractor::ThumbnailPreviewReady
   579 // CMPXMetadataExtractor::ThumbnailPreviewReady
   583 // Callback but not used here
   580 // Callback but not used here
   584 // ---------------------------------------------------------------------------
   581 // ---------------------------------------------------------------------------
   585 void CMPXMetadataExtractor::ThumbnailPreviewReady( 
   582 void CMPXMetadataExtractor::ThumbnailPreviewReady(
   586         MThumbnailData& /*aThumbnail*/, TThumbnailRequestId /*aId*/ )
   583         MThumbnailData& /*aThumbnail*/, TThumbnailRequestId /*aId*/ )
   587     {
   584     {
   588     MPX_FUNC("CMPXMetadataExtractor::ThumbnailPreviewReady()");
   585     MPX_FUNC("CMPXMetadataExtractor::ThumbnailPreviewReady()");
   589     }
   586     }
   590         
   587 
   591 
   588 
   592 // ---------------------------------------------------------------------------
   589 // ---------------------------------------------------------------------------
   593 // CMPXMetadataExtractor::ThumbnailReady
   590 // CMPXMetadataExtractor::ThumbnailReady
   594 // Callback but not used here
   591 // Callback but not used here
   595 // ---------------------------------------------------------------------------
   592 // ---------------------------------------------------------------------------
   596 void CMPXMetadataExtractor::ThumbnailReady( TInt /*aError*/, 
   593 void CMPXMetadataExtractor::ThumbnailReady( TInt /*aError*/,
   597         MThumbnailData& /*aThumbnail*/, TThumbnailRequestId aId )
   594         MThumbnailData& /*aThumbnail*/, TThumbnailRequestId aId )
   598     {
   595     {
   599     MPX_FUNC("CMPXMetadataExtractor::ThumbnailReady()");
   596     MPX_FUNC("CMPXMetadataExtractor::ThumbnailReady()");
   600     
   597 
   601     // Remove thumbnail id from array.
   598     // Remove thumbnail id from array.
   602     TInt index = iArrayTNRequestId.Find( aId );
   599     TInt index = iArrayTNRequestId.Find( aId );
   603     if ( index >= 0 )
   600     if ( index >= 0 )
   604         {
   601         {
   605         iArrayTNRequestId.Remove( index );
   602         iArrayTNRequestId.Remove( index );
   620     {
   617     {
   621     MPX_FUNC("CMPXMetadataExtractor::TimeoutTimerCallback()");
   618     MPX_FUNC("CMPXMetadataExtractor::TimeoutTimerCallback()");
   622 
   619 
   623     CMPXMetadataExtractor* ptr =
   620     CMPXMetadataExtractor* ptr =
   624         static_cast<CMPXMetadataExtractor*>(aPtr);
   621         static_cast<CMPXMetadataExtractor*>(aPtr);
   625         
   622 
   626     // Timer expired before thumbnail callback occurred. Stop wait loop to unblock. 
   623     // Timer expired before thumbnail callback occurred. Stop wait loop to unblock.
   627     ptr->StopWaitLoop();
   624     ptr->StopWaitLoop();
   628     return KErrNone;
   625     return KErrNone;
   629     }
   626     }
   630 
   627 
   631 // ----------------------------------------------------------------------------
   628 // ----------------------------------------------------------------------------
   634 void CMPXMetadataExtractor::StopWaitLoop()
   631 void CMPXMetadataExtractor::StopWaitLoop()
   635     {
   632     {
   636     MPX_FUNC("CMPXMetadataExtractor::StopWaitLoop()");
   633     MPX_FUNC("CMPXMetadataExtractor::StopWaitLoop()");
   637     // Cancel timer
   634     // Cancel timer
   638     CancelTimeoutTimer();
   635     CancelTimeoutTimer();
   639     
   636 
   640     // Stop wait loop to unblock.
   637     // Stop wait loop to unblock.
   641     if ( iTNSyncWait->IsStarted() )
   638     if ( iTNSyncWait->IsStarted() )
   642         {
   639         {
   643         MPX_DEBUG1("CMPXMetadataExtractor::StopWaitLoop(): Stopping the wait loop.");
   640         MPX_DEBUG1("CMPXMetadataExtractor::StopWaitLoop(): Stopping the wait loop.");
   644         iTNSyncWait->AsyncStop();
   641         iTNSyncWait->AsyncStop();
   645         }
   642         }
   646     }
   643     }
   647 
   644 
   648 // ----------------------------------------------------------------------------
   645 // ----------------------------------------------------------------------------
   649 // Cancel timer. 
   646 // Cancel timer.
   650 // ----------------------------------------------------------------------------
   647 // ----------------------------------------------------------------------------
   651 void CMPXMetadataExtractor::CancelTimeoutTimer()
   648 void CMPXMetadataExtractor::CancelTimeoutTimer()
   652     {
   649     {
   653     MPX_FUNC("CMPXMetadataExtractor::CancelTimeoutTimer()");
   650     MPX_FUNC("CMPXMetadataExtractor::CancelTimeoutTimer()");
   654     
   651 
   655     // Cancel timer.
   652     // Cancel timer.
   656     if ( iTimer && iTimer->IsActive() )
   653     if ( iTimer && iTimer->IsActive() )
   657         {
   654         {
   658         MPX_DEBUG1("CMPXMetadataExtractor::CancelTimeoutTimer(): Timer active, cancelling");
   655         MPX_DEBUG1("CMPXMetadataExtractor::CancelTimeoutTimer(): Timer active, cancelling");
   659         iTimer->Cancel();
   656         iTimer->Cancel();
   666 EXPORT_C TInt CMPXMetadataExtractor::ExtractAlbumArtL( CMPXMedia* aMedia )
   663 EXPORT_C TInt CMPXMetadataExtractor::ExtractAlbumArtL( CMPXMedia* aMedia )
   667     {
   664     {
   668     MPX_FUNC("CMPXMetadataExtractor::ExtractAlbumArtL()");
   665     MPX_FUNC("CMPXMetadataExtractor::ExtractAlbumArtL()");
   669     TInt err = KErrNone;
   666     TInt err = KErrNone;
   670     iCancelled = EFalse;
   667     iCancelled = EFalse;
   671     
   668 
   672     if ( !aMedia->IsSupported(KMPXMediaGeneralUri) )
   669     if ( !aMedia->IsSupported(KMPXMediaGeneralUri) )
   673         {
   670         {
   674         return KErrArgument;
   671         return KErrArgument;
   675         }
   672         }
   676     
   673 
   677     // Get full file name.
   674     // Get full file name.
   678     const TDesC& path = aMedia->ValueText(KMPXMediaGeneralUri);
   675     const TDesC& path = aMedia->ValueText(KMPXMediaGeneralUri);
   679     MPX_DEBUG2("CMPXMetadataExtractor::ExtractAlbumArtL Filename:%S ", &path );
   676     MPX_DEBUG2("CMPXMetadataExtractor::ExtractAlbumArtL Filename:%S ", &path );
   680 #ifdef ABSTRACTAUDIOALBUM_INCLUDED
   677 #ifdef ABSTRACTAUDIOALBUM_INCLUDED
   681     TParsePtrC parse( path );
   678     TParsePtrC parse( path );
   693             TBuf<20> mimeType(KImageFileType);
   690             TBuf<20> mimeType(KImageFileType);
   694             TInt sampleData = aMedia->ValueTObjectL<TInt>(KMPXMediaMTPSampleData);
   691             TInt sampleData = aMedia->ValueTObjectL<TInt>(KMPXMediaMTPSampleData);
   695             HBufC8* value8 = ((HBufC8*)sampleData)->Des().AllocLC();   // make a local copy of sampleData
   692             HBufC8* value8 = ((HBufC8*)sampleData)->Des().AllocLC();   // make a local copy of sampleData
   696             source = CThumbnailObjectSource::NewLC(
   693             source = CThumbnailObjectSource::NewLC(
   697                 value8, mimeType, path );    // give up ownership of value8
   694                 value8, mimeType, path );    // give up ownership of value8
   698             
   695 
   699             MPX_DEBUG1("CMPXMetadataExtractor::ExtractAlbumArtL source created from buffer");
   696             MPX_DEBUG1("CMPXMetadataExtractor::ExtractAlbumArtL source created from buffer");
   700             TThumbnailRequestId tnId = iTNManager->CreateThumbnails( *source );
   697             TThumbnailRequestId tnId = iTNManager->CreateThumbnails( *source );
   701             iArrayTNRequestId.Append( tnId );
   698             iArrayTNRequestId.Append( tnId );
   702             CleanupStack::PopAndDestroy( source );
   699             CleanupStack::PopAndDestroy( source );
   703             CleanupStack::Pop( value8 );
   700             CleanupStack::Pop( value8 );
   704             }
   701             }
   705         else
   702         else
   706             {
   703             {
   707             source = CThumbnailObjectSource::NewLC(
   704             source = CThumbnailObjectSource::NewLC(
   708                 path, KImageFileType  );
   705                 path, KImageFileType  );
   709             
   706 
   710             MPX_DEBUG1("CMPXMetadataExtractor::ExtractAlbumArtL source created from path");
   707             MPX_DEBUG1("CMPXMetadataExtractor::ExtractAlbumArtL source created from path");
   711             TThumbnailRequestId tnId = iTNManager->CreateThumbnails( *source );
   708             TThumbnailRequestId tnId = iTNManager->CreateThumbnails( *source );
   712             iArrayTNRequestId.Append( tnId );
   709             iArrayTNRequestId.Append( tnId );
   713             CleanupStack::PopAndDestroy( source );
   710             CleanupStack::PopAndDestroy( source );
   714             }
   711             }
   719 #endif // ABSTRACTAUDIOALBUM_INCLUDED
   716 #endif // ABSTRACTAUDIOALBUM_INCLUDED
   720     // create wanted fields array
   717     // create wanted fields array
   721     RArray<TMetaDataFieldId> wantedFields;
   718     RArray<TMetaDataFieldId> wantedFields;
   722     CleanupClosePushL( wantedFields );
   719     CleanupClosePushL( wantedFields );
   723     wantedFields.Append(EMetaDataJpeg);
   720     wantedFields.Append(EMetaDataJpeg);
   724     
   721 
   725     // Open file
   722     // Open file
   726     if ( aMedia->IsSupported(KMPXMediaGeneralMimeType) )
   723     if ( aMedia->IsSupported(KMPXMediaGeneralMimeType) )
   727         {
   724         {
   728         const TDesC& mimeType = aMedia->ValueText( KMPXMediaGeneralMimeType );
   725         const TDesC& mimeType = aMedia->ValueText( KMPXMediaGeneralMimeType );
   729         MPX_DEBUG2("CMPXMetadataExtractor::ExtractAlbumArtL MimeType:%S ", &mimeType );
   726         MPX_DEBUG2("CMPXMetadataExtractor::ExtractAlbumArtL MimeType:%S ", &mimeType );
   735     else
   732     else
   736         {
   733         {
   737         MPX_TRAP( err, iMetadataUtility->OpenFileL( path, wantedFields ) );
   734         MPX_TRAP( err, iMetadataUtility->OpenFileL( path, wantedFields ) );
   738         }
   735         }
   739     CleanupStack::PopAndDestroy( &wantedFields );
   736     CleanupStack::PopAndDestroy( &wantedFields );
   740     
   737 
   741     if ( !err )
   738     if ( !err )
   742         {
   739         {
   743         //check if can send TN request, If thumbnail creation is ongoing, wait til it is done
   740         //check if can send TN request, If thumbnail creation is ongoing, wait til it is done
   744         CheckBeforeSendRequest();
   741         CheckBeforeSendRequest();
   745         MPX_TRAP( err, AddMediaAlbumArtL( *aMedia, path ));
   742         MPX_TRAP( err, AddMediaAlbumArtL( *aMedia, path ));
   754     }
   751     }
   755 
   752 
   756 // ----------------------------------------------------------------------------
   753 // ----------------------------------------------------------------------------
   757 // Add album art to media object.
   754 // Add album art to media object.
   758 // ----------------------------------------------------------------------------
   755 // ----------------------------------------------------------------------------
   759 void CMPXMetadataExtractor::AddMediaAlbumArtL( CMPXMedia& aMedia, 
   756 void CMPXMetadataExtractor::AddMediaAlbumArtL( CMPXMedia& aMedia,
   760                                                const TDesC& aFile )
   757                                                const TDesC& aFile )
   761     {
   758     {
   762     MPX_FUNC("CMPXMetadataExtractor::AddMediaAlbumArtL()");
   759     MPX_FUNC("CMPXMetadataExtractor::AddMediaAlbumArtL()");
   763     
   760 
   764     // get metadata container.
   761     // get metadata container.
   765     const CMetaDataFieldContainer& metaCont = iMetadataUtility->MetaDataFieldsL();
   762     const CMetaDataFieldContainer& metaCont = iMetadataUtility->MetaDataFieldsL();
   766     TPtrC8 data8 = metaCont.Field8( EMetaDataJpeg );
   763     TPtrC8 data8 = metaCont.Field8( EMetaDataJpeg );
   767    
   764 
   768     if ( data8.Length() )
   765     if ( data8.Length() )
   769         {
   766         {
   770         MPX_DEBUG1("CMPXMetadataExtractor::GetMediaAlbumArtL(): Album art exist.");
   767         MPX_DEBUG1("CMPXMetadataExtractor::GetMediaAlbumArtL(): Album art exist.");
   771 #ifdef RD_MPX_TNM_INTEGRATION
   768 #ifdef RD_MPX_TNM_INTEGRATION
   772         HBufC8* value8 = NULL; 
   769         HBufC8* value8 = NULL;
   773         MPX_TRAPD( err, value8 = data8.AllocL() );
   770         MPX_TRAPD( err, value8 = data8.AllocL() );
   774         if ( KErrNone != err )
   771         if ( KErrNone != err )
   775             {
   772             {
   776             MPX_DEBUG2("CMPXMetadataExtractor::GetMediaAlbumArtL - error jpeg = %i", err);
   773             MPX_DEBUG2("CMPXMetadataExtractor::GetMediaAlbumArtL - error jpeg = %i", err);
   777             return;
   774             return;
   778             }              
   775             }
   779         CleanupStack::PushL( value8 );
   776         CleanupStack::PushL( value8 );
   780     
   777 
   781         TBuf<256> mimeType;
   778         TBuf<256> mimeType;
   782         mimeType.Copy( KImageFileType );
   779         mimeType.Copy( KImageFileType );
   783         CThumbnailObjectSource* source = CThumbnailObjectSource::NewL(
   780         CThumbnailObjectSource* source = CThumbnailObjectSource::NewL(
   784                 value8, mimeType, aFile );
   781                 value8, mimeType, aFile );
   785         TThumbnailRequestId tnId = iTNManager->CreateThumbnails( *source );
   782         TThumbnailRequestId tnId = iTNManager->CreateThumbnails( *source );
   786         iArrayTNRequestId.Append( tnId ); // add thumbnail id to array
   783         iArrayTNRequestId.Append( tnId ); // add thumbnail id to array
   787         CleanupStack::Pop( value8 );
   784         CleanupStack::Pop( value8 );
   788         delete source;
   785         delete source;
   789         
   786 
   790         aMedia.SetTextValueL( KMPXMediaMusicOriginalAlbumArtFileName, aFile );
   787         aMedia.SetTextValueL( KMPXMediaMusicOriginalAlbumArtFileName, aFile );
   791 #endif // RD_MPX_TNM_INTEGRATION          
   788 #endif // RD_MPX_TNM_INTEGRATION
   792         aMedia.SetTextValueL( KMPXMediaMusicAlbumArtFileName, aFile );
   789         aMedia.SetTextValueL( KMPXMediaMusicAlbumArtFileName, aFile );
   793         }
   790         }
   794     }
   791     }
   795 
   792 
   796 // ----------------------------------------------------------------------------
   793 // ----------------------------------------------------------------------------
   927         TDataType dataType;
   924         TDataType dataType;
   928         TUid dummyUid(KNullUid);
   925         TUid dummyUid(KNullUid);
   929         iAppArc.AppForDocument(iFileName, dummyUid, dataType);
   926         iAppArc.AppForDocument(iFileName, dummyUid, dataType);
   930         iMedia->SetTextValueL( KMPXMediaGeneralMimeType,dataType.Des() );
   927         iMedia->SetTextValueL( KMPXMediaGeneralMimeType,dataType.Des() );
   931         }
   928         }
   932         
   929 
   933     // Initially set default tags.
   930     // Initially set default tags.
   934     SetDefaultL( *iMedia );
   931     SetDefaultL( *iMedia );
   935     }
   932     }
   936 
   933 
   937 // ----------------------------------------------------------------------------
   934 // ----------------------------------------------------------------------------
   979     if ( iArrayTasks.Count() )
   976     if ( iArrayTasks.Count() )
   980         {
   977         {
   981         MPX_DEBUG1("CMPXMetadataExtractor::CreateMediaAsyncL Request ongoing. Abort!" );
   978         MPX_DEBUG1("CMPXMetadataExtractor::CreateMediaAsyncL Request ongoing. Abort!" );
   982         User::Leave( KErrAbort );
   979         User::Leave( KErrAbort );
   983         }
   980         }
   984     
   981 
   985     iCancelled = EFalse;
   982     iCancelled = EFalse;
   986     iFileOpenError = KErrNone;
   983     iFileOpenError = KErrNone;
   987     iFileName = aFile;
   984     iFileName = aFile;
   988     iObs = aObs;
   985     iObs = aObs;
   989     iMetadataOnly = aMetadataOnly;
   986     iMetadataOnly = aMetadataOnly;
   990     
   987 
   991     // populate the task array
   988     // populate the task array
   992     AddTasksL();
   989     AddTasksL();
   993     
   990 
   994     // Start task timer to execute task
   991     // Start task timer to execute task
   995     if ( iArrayTasks.Count() )
   992     if ( iArrayTasks.Count() )
   996         {
   993         {
   997         if ( iTaskTimer->IsActive() )
   994         if ( iTaskTimer->IsActive() )
   998             {
   995             {
   999             iTaskTimer->Cancel();
   996             iTaskTimer->Cancel();
  1000             }   
   997             }
  1001         iTaskTimer->Start( 0, 0, TCallBack(TaskTimerCallback, this ));
   998         iTaskTimer->Start( 0, 0, TCallBack(TaskTimerCallback, this ));
  1002         }
   999         }
  1003     }
  1000     }
  1004 
  1001 
  1005 // ---------------------------------------------------------------------------
  1002 // ---------------------------------------------------------------------------
  1007 // ---------------------------------------------------------------------------
  1004 // ---------------------------------------------------------------------------
  1008 //
  1005 //
  1009 TInt CMPXMetadataExtractor::OpenFile()
  1006 TInt CMPXMetadataExtractor::OpenFile()
  1010     {
  1007     {
  1011     MPX_FUNC("CMPXMetadataExtractor::OpenFile()");
  1008     MPX_FUNC("CMPXMetadataExtractor::OpenFile()");
  1012     
  1009 
  1013     // Open the file
  1010     // Open the file
  1014     iFile.Close();
  1011     iFile.Close();
  1015     TInt error = iFile.Open( iFs, iFileName, EFileRead | EFileShareReadersOrWriters );
  1012     TInt error = iFile.Open( iFs, iFileName, EFileRead | EFileShareReadersOrWriters );
  1016     MPX_DEBUG2("CMPXMetadataExtractor::OpenFile open error = %d", error );
  1013     MPX_DEBUG2("CMPXMetadataExtractor::OpenFile open error = %d", error );
  1017     return error;
  1014     return error;
  1023 //
  1020 //
  1024 void CMPXMetadataExtractor::AddTasksL()
  1021 void CMPXMetadataExtractor::AddTasksL()
  1025     {
  1022     {
  1026     MPX_FUNC("CMPXMetadataExtractor::AddTasks()");
  1023     MPX_FUNC("CMPXMetadataExtractor::AddTasks()");
  1027     iFileOpenError = OpenFile();
  1024     iFileOpenError = OpenFile();
  1028     
  1025 
  1029     // Do not change the order of the task below.
  1026     // Do not change the order of the task below.
  1030     iArrayTasks.Reset();
  1027     iArrayTasks.Reset();
  1031     if ( iFileOpenError == KErrNone )
  1028     if ( iFileOpenError == KErrNone )
  1032         {
  1029         {
  1033         // to avoid resources contention (i.e. accessing sql, file system, etc)
  1030         // to avoid resources contention (i.e. accessing sql, file system, etc)
  1064 // Handle task timer expired
  1061 // Handle task timer expired
  1065 // ----------------------------------------------------------------------------
  1062 // ----------------------------------------------------------------------------
  1066 void CMPXMetadataExtractor::HandleTaskTimerExpired()
  1063 void CMPXMetadataExtractor::HandleTaskTimerExpired()
  1067     {
  1064     {
  1068     MPX_FUNC("CMPXMetadataExtractor::HandleTaskTimerExpired()");
  1065     MPX_FUNC("CMPXMetadataExtractor::HandleTaskTimerExpired()");
  1069     
  1066 
  1070     if ( iTaskTimer && iTaskTimer->IsActive() )
  1067     if ( iTaskTimer && iTaskTimer->IsActive() )
  1071         {
  1068         {
  1072         iTaskTimer->Cancel();
  1069         iTaskTimer->Cancel();
  1073         }
  1070         }
  1074     // execute task at index 0
  1071     // execute task at index 0
  1081             delete iMedia;
  1078             delete iMedia;
  1082             iMedia = NULL;
  1079             iMedia = NULL;
  1083             }
  1080             }
  1084         iArrayTasks.Reset();
  1081         iArrayTasks.Reset();
  1085         }
  1082         }
  1086     
  1083 
  1087     // Remove task at index 0.
  1084     // Remove task at index 0.
  1088     if ( iArrayTasks.Count() )
  1085     if ( iArrayTasks.Count() )
  1089         {
  1086         {
  1090         iArrayTasks.Remove( 0 );
  1087         iArrayTasks.Remove( 0 );
  1091         }
  1088         }
  1092     
  1089 
  1093     // check if we have any more task to run
  1090     // check if we have any more task to run
  1094     if ( iArrayTasks.Count() )
  1091     if ( iArrayTasks.Count() )
  1095         {
  1092         {
  1096         // start task timer
  1093         // start task timer
  1097         iTaskTimer->Start( 0, 0, TCallBack(TaskTimerCallback, this ));
  1094         iTaskTimer->Start( 0, 0, TCallBack(TaskTimerCallback, this ));
  1102         if ( iObs && !iCancelled )
  1099         if ( iObs && !iCancelled )
  1103             {
  1100             {
  1104             iObs->HandleCreateMediaComplete( iMedia, error );
  1101             iObs->HandleCreateMediaComplete( iMedia, error );
  1105             iMedia = NULL;  // ownership transferred.
  1102             iMedia = NULL;  // ownership transferred.
  1106             }
  1103             }
  1107         
  1104 
  1108         CleanUp();
  1105         CleanUp();
  1109         }
  1106         }
  1110     }
  1107     }
  1111 
  1108 
  1112 // ----------------------------------------------------------------------------
  1109 // ----------------------------------------------------------------------------
  1133     // DB Flags to set
  1130     // DB Flags to set
  1134     TUint dbFlags(KMPXMediaGeneralFlagsSetOrUnsetBit);
  1131     TUint dbFlags(KMPXMediaGeneralFlagsSetOrUnsetBit);
  1135     // Validate the objects to be used
  1132     // Validate the objects to be used
  1136     MPX_ASSERT(iMedia);
  1133     MPX_ASSERT(iMedia);
  1137     MPX_ASSERT(iDrmMediaUtility);
  1134     MPX_ASSERT(iDrmMediaUtility);
  1138     
  1135 
  1139     // File Path
  1136     // File Path
  1140     TParsePtrC parse( iFileName );
  1137     TParsePtrC parse( iFileName );
  1141     iMedia->SetTextValueL( KMPXMediaGeneralUri, iFileName );
  1138     iMedia->SetTextValueL( KMPXMediaGeneralUri, iFileName );
  1142     iMedia->SetTextValueL( KMPXMediaGeneralDrive, parse.Drive() );
  1139     iMedia->SetTextValueL( KMPXMediaGeneralDrive, parse.Drive() );
  1143     MPX_DEBUG2("CMPXMetadataExtractor::SetDrmMediaPropertiesL - Filename=%S", &iFileName);
  1140     MPX_DEBUG2("CMPXMetadataExtractor::SetDrmMediaPropertiesL - Filename=%S", &iFileName);
  1144 
  1141 
  1145     // get the protected flag from MetadataUtility Container
  1142     // get the protected flag from MetadataUtility Container
  1146     TPtrC ptr = aMetaCont.Field( EMetaDataProtected );  
  1143     TPtrC ptr = aMetaCont.Field( EMetaDataProtected );
  1147     MPX_DEBUG2("CMPXMetadataExtractor::SetDrmMediaPropertiesL -- status=%S", &ptr);
  1144     MPX_DEBUG2("CMPXMetadataExtractor::SetDrmMediaPropertiesL -- status=%S", &ptr);
  1148     _LIT( KNonProtected, "0" );
  1145     _LIT( KNonProtected, "0" );
  1149     if ( ptr.Compare( KNonProtected ) == 0 )
  1146     if ( ptr.Compare( KNonProtected ) == 0 )
  1150         {
  1147         {
  1151         // this is non-protected file
  1148         // this is non-protected file
  1152         // prot = EFalse
  1149         // prot = EFalse
  1153         MPX_DEBUG1("CMPXMetadataExtractor::SetDrmMediaPropertiesL - non protected");
  1150         MPX_DEBUG1("CMPXMetadataExtractor::SetDrmMediaPropertiesL - non protected");
  1154         iMedia->SetTObjectValueL<TBool>( KMPXMediaDrmProtected, prot );
  1151         iMedia->SetTObjectValueL<TBool>( KMPXMediaDrmProtected, prot );
  1155         iMedia->SetTObjectValueL<TUint16>( KMPXMediaMTPDrmStatus, (TUint16)prot );
  1152         iMedia->SetTObjectValueL<TUint16>( KMPXMediaMTPDrmStatus, (TUint16)prot );
  1156         }
  1153         }
  1157     else  
  1154     else
  1158         {  // DRM file
  1155         {  // DRM file
  1159 
  1156 
  1160         // DRM Rights
  1157         // DRM Rights
  1161         //
  1158         //
  1162         CMPXMedia* drm = NULL;
  1159         CMPXMedia* drm = NULL;
  1204             User::LeaveIfError( drmError );
  1201             User::LeaveIfError( drmError );
  1205             }
  1202             }
  1206 
  1203 
  1207         iMedia->SetTObjectValueL<TBool>( KMPXMediaDrmProtected, prot );
  1204         iMedia->SetTObjectValueL<TBool>( KMPXMediaDrmProtected, prot );
  1208         iMedia->SetTObjectValueL<TUint16>( KMPXMediaMTPDrmStatus, (TUint16)prot );
  1205         iMedia->SetTObjectValueL<TUint16>( KMPXMediaMTPDrmStatus, (TUint16)prot );
  1209     
  1206 
  1210         iDrmMediaUtility->Close();
  1207         iDrmMediaUtility->Close();
  1211     
  1208 
  1212         }  // DRM file
  1209         }  // DRM file
  1213 
  1210 
  1214     
  1211 
  1215     // verify the file open status
  1212     // verify the file open status
  1216     if( iFileOpenError == KErrNotFound || iFileOpenError == KErrPathNotFound )
  1213     if( iFileOpenError == KErrNotFound || iFileOpenError == KErrPathNotFound )
  1217         {
  1214         {
  1218         dbFlags |= KMPXMediaGeneralFlagsIsInvalid;
  1215         dbFlags |= KMPXMediaGeneralFlagsIsInvalid;
  1219         }
  1216         }
  1220     
  1217 
  1221     // Finally set the db flag
  1218     // Finally set the db flag
  1222     //
  1219     //
  1223     iMedia->SetTObjectValueL( KMPXMediaGeneralFlags, dbFlags );
  1220     iMedia->SetTObjectValueL( KMPXMediaGeneralFlags, dbFlags );
  1224    
  1221 
  1225     }
  1222     }