harvester/harvesterplugins/AudioPlugin/src/harvesteraudioplugin.cpp
branchRCL_3
changeset 57 2872ae438bf7
parent 47 b73252188534
child 63 e538444823de
equal deleted inserted replaced
53:29d87345eaeb 57:2872ae438bf7
    20 #include <harvesterdata.h>
    20 #include <harvesterdata.h>
    21 #include <mdenamespacedef.h>
    21 #include <mdenamespacedef.h>
    22 #include <mdeobjectdef.h>
    22 #include <mdeobjectdef.h>
    23 #include <mdeobject.h>
    23 #include <mdeobject.h>
    24 #include <centralrepository.h>
    24 #include <centralrepository.h>
    25 #include <caf/caf.h>
       
    26 #include <pathinfo.h>
    25 #include <pathinfo.h>
    27 
    26 
    28 #include "harvestercommon.h"
    27 #include "harvestercommon.h"
    29 #include "harvesteraudioplugin.h"
    28 #include "harvesteraudioplugin.h"
    30 #include "harvesteraudiopluginutils.h"
    29 #include "harvesteraudiopluginutils.h"
    34 #include "harvesterlog.h"
    33 #include "harvesterlog.h"
    35 
    34 
    36 const TInt KMimeLength( 10 );
    35 const TInt KMimeLength( 10 );
    37 const TUid KHarvesterRepoUid = { 0x200009FE };
    36 const TUid KHarvesterRepoUid = { 0x200009FE };
    38 const TUint32 KEnableAlbumArtHarvest = 0x00090001;
    37 const TUint32 KEnableAlbumArtHarvest = 0x00090001;
       
    38 const TInt KKiloBytes = 1024;
    39 
    39 
    40 CHarvesterAudioPluginPropertyDefs::CHarvesterAudioPluginPropertyDefs() : CBase(),
    40 CHarvesterAudioPluginPropertyDefs::CHarvesterAudioPluginPropertyDefs() : CBase(),
    41     iCreationDatePropertyDef( NULL )
    41     iCreationDatePropertyDef( NULL )
    42 	{
    42 	{
    43 	}
    43 	}
    77     iCopyrightPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KCopyrightProperty );
    77     iCopyrightPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KCopyrightProperty );
    78     iTrackPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KTrackProperty );
    78     iTrackPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KTrackProperty );
    79     iThumbnailPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KThumbnailPresentProperty );
    79     iThumbnailPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KThumbnailPresentProperty );
    80     iDatePropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KReleaseDateProperty );
    80     iDatePropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KReleaseDateProperty );
    81     iDrmPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KDRMProperty );
    81     iDrmPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KDRMProperty );
       
    82     iBitratePropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KBitrateProperty );
    82 
    83 
    83     // Audio property definitions
    84     // Audio property definitions
    84     CMdEObjectDef& audioDef = nsDef.GetObjectDefL( MdeConstants::Audio::KAudioObject );
    85     CMdEObjectDef& audioDef = nsDef.GetObjectDefL( MdeConstants::Audio::KAudioObject );
    85     iAlbumPropertyDef = &audioDef.GetPropertyDefL( MdeConstants::Audio::KAlbumProperty );
    86     iAlbumPropertyDef = &audioDef.GetPropertyDefL( MdeConstants::Audio::KAlbumProperty );
    86     iComposerPropertyDef = &audioDef.GetPropertyDefL( MdeConstants::Audio::KComposerProperty );
    87     iComposerPropertyDef = &audioDef.GetPropertyDefL( MdeConstants::Audio::KComposerProperty );
    87     iOriginalArtistPropertyDef = &audioDef.GetPropertyDefL( MdeConstants::Audio::KOriginalArtistProperty );
    88     iOriginalArtistPropertyDef = &audioDef.GetPropertyDefL( MdeConstants::Audio::KOriginalArtistProperty );
       
    89     iSampleRatePropertyDef = &audioDef.GetPropertyDefL( MdeConstants::Audio::KSamplingFrequencyProperty );
       
    90     iAlbumArtistPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::Audio::KAlbumArtistProperty );
    88     }
    91     }
    89 
    92 
    90 using namespace MdeConstants;
    93 using namespace MdeConstants;
    91 
    94 
    92 // ---------------------------------------------------------------------------
    95 // ---------------------------------------------------------------------------
   340 // ---------------------------------------------------------------------------
   343 // ---------------------------------------------------------------------------
   341 // CHarvesterAudioPlugin::GetMusicPropertiesL
   344 // CHarvesterAudioPlugin::GetMusicPropertiesL
   342 // ---------------------------------------------------------------------------
   345 // ---------------------------------------------------------------------------
   343 //    
   346 //    
   344 void CHarvesterAudioPlugin::GetMusicPropertiesL( CHarvesterData* aHD,
   347 void CHarvesterAudioPlugin::GetMusicPropertiesL( CHarvesterData* aHD,
   345                                       TBool aIsAdd, TPtrC aMimeType )
   348                                       TBool aIsAdd, TPtrC /*aMimeType*/ )
   346     {
   349     {
   347 #ifdef _DEBUG
   350 #ifdef _DEBUG
   348     TTime dStart, dStop;
   351     TTime dStart, dStop;
   349     dStart.UniversalTime();
   352     dStart.UniversalTime();
   350     dStop.UniversalTime();
   353     dStop.UniversalTime();
   351     WRITELOG1( "CHarvesterAudioPlugin::GetMusicPropertiesL start %d us", (TInt)dStop.MicroSecondsFrom(dStart).Int64() );
   354     WRITELOG1( "CHarvesterAudioPlugin::GetMusicPropertiesL start %d us", (TInt)dStop.MicroSecondsFrom(dStart).Int64() );
   352 #endif
   355 #endif
   353     
   356     
   354     CMdEObject& mdeObject = aHD->MdeObject();
   357     CMdEObject& mdeObject = aHD->MdeObject();
   355     const TDesC& uri = mdeObject.Uri();
   358     const TDesC& uri = mdeObject.Uri();
   356  
       
   357     InitPropDefsL( mdeObject.Def() );
       
   358 
       
   359     TBool possiblyProtectedContent( EFalse );
       
   360     if( aMimeType.Length() > 0 )
       
   361         {
       
   362         if( aMimeType == KMimeTypeWma )
       
   363             {
       
   364             possiblyProtectedContent = ETrue;
       
   365             }
       
   366         }
       
   367 
       
   368     if( possiblyProtectedContent )
       
   369         {
       
   370         ContentAccess::CContent* content = ContentAccess::CContent::NewLC( uri );
       
   371         ContentAccess::CData* data = content->OpenContentLC( ContentAccess::EPeek );
       
   372         
       
   373         TBool protectedContent( EFalse );
       
   374         TInt err = data->GetAttribute( ContentAccess::EIsProtected, protectedContent );
       
   375         if( err == KErrNone && protectedContent )
       
   376             {
       
   377             CMdeObjectWrapper::HandleObjectPropertyL( mdeObject, 
       
   378                     *iPropDefs->iDrmPropertyDef, &protectedContent, aIsAdd );
       
   379             }
       
   380         CleanupStack::PopAndDestroy( 2 ); // content, data
       
   381         }
       
   382 
   359 
   383     TBool parsed( EFalse );
   360     TBool parsed( EFalse );
   384     TRAPD( parseError, parsed = iAudioParser->ParseL( uri ) );
   361     TRAPD( parseError, parsed = iAudioParser->ParseL( uri ) );
   385 
   362 
   386     if( !parsed || (parseError != KErrNone) )
   363     if( !parsed || (parseError != KErrNone) )
   387     	{
   364     	{
   388     	iAudioParser->ResetL();
   365     	iAudioParser->ResetL();
   389     	return;
   366     	return;
   390     	}
   367     	}
   391 
   368 
       
   369     InitPropDefsL( mdeObject.Def() );
       
   370     
   392     // We do not want to get all long text fields at this time
   371     // We do not want to get all long text fields at this time
   393     TPtrC song      = iAudioParser->MetaDataFieldL( CAudioMDParser::EAudioMDFieldSong );
   372     TPtrC song        = iAudioParser->MetaDataFieldL( CAudioMDParser::EAudioMDFieldSong );
   394     TPtrC artist    = iAudioParser->MetaDataFieldL( CAudioMDParser::EAudioMDFieldArtist );
   373     TPtrC artist      = iAudioParser->MetaDataFieldL( CAudioMDParser::EAudioMDFieldArtist );
   395     TPtrC album     = iAudioParser->MetaDataFieldL( CAudioMDParser::EAudioMDFieldAlbum );
   374     TPtrC album       = iAudioParser->MetaDataFieldL( CAudioMDParser::EAudioMDFieldAlbum );
   396     TPtrC genre     = iAudioParser->MetaDataFieldL( CAudioMDParser::EAudioMDFieldGenre );
   375     TPtrC genre       = iAudioParser->MetaDataFieldL( CAudioMDParser::EAudioMDFieldGenre );
   397     TPtrC composer  = iAudioParser->MetaDataFieldL( CAudioMDParser::EAudioMDFieldComposer );
   376     TPtrC composer    = iAudioParser->MetaDataFieldL( CAudioMDParser::EAudioMDFieldComposer );
   398     TPtrC rating    = iAudioParser->MetaDataFieldL( CAudioMDParser::EAudioMDFieldRating );
   377     TPtrC rating      = iAudioParser->MetaDataFieldL( CAudioMDParser::EAudioMDFieldRating );
   399     TPtrC orgArtist = iAudioParser->MetaDataFieldL( CAudioMDParser::EAudioMDFieldOriginalArtist );
   378     TPtrC orgArtist   = iAudioParser->MetaDataFieldL( CAudioMDParser::EAudioMDFieldOriginalArtist );
   400     TPtrC track     = iAudioParser->MetaDataFieldL( CAudioMDParser::EAudioMDFieldTrack );
   379     TPtrC track       = iAudioParser->MetaDataFieldL( CAudioMDParser::EAudioMDFieldTrack );
   401     TPtrC duration  = iAudioParser->MetaDataFieldL( CAudioMDParser::EAudioMDFieldDuration );
   380     TPtrC duration    = iAudioParser->MetaDataFieldL( CAudioMDParser::EAudioMDFieldDuration );
   402     TPtrC copyright     = iAudioParser->MetaDataFieldL( CAudioMDParser::EAudioMDFieldCopyright );
   381     TPtrC copyright   = iAudioParser->MetaDataFieldL( CAudioMDParser::EAudioMDFieldCopyright );
   403     TPtrC date     = iAudioParser->MetaDataFieldL( CAudioMDParser::EAudioMDFieldDate );
   382     TPtrC date        = iAudioParser->MetaDataFieldL( CAudioMDParser::EAudioMDFieldDate );   
       
   383     TPtrC prot        = iAudioParser->MetaDataFieldL( CAudioMDParser::EAudioMDFieldProtected );
       
   384     TPtrC samplerate  = iAudioParser->MetaDataFieldL( CAudioMDParser::EAudioMDFieldSampleRate );
       
   385     TPtrC bitrate     = iAudioParser->MetaDataFieldL( CAudioMDParser::EAudioMDFieldBitRate );
       
   386     TPtrC albumartist = iAudioParser->MetaDataFieldL( CAudioMDParser::EAudioMDFieldAlbumArtist );
   404     
   387     
   405     TPtrC8 jpeg = iAudioParser->MetaDataField8L( CAudioMDParser::EAudioMDFieldJpeg );
   388     TPtrC8 jpeg = iAudioParser->MetaDataField8L( CAudioMDParser::EAudioMDFieldJpeg );
   406  
   389  
   407     // Time offset
   390     // Time offset
   408     TTimeIntervalSeconds timeOffsetSeconds = User::UTCOffset();
   391     TTimeIntervalSeconds timeOffsetSeconds = User::UTCOffset();
   513         && date.Length() < iPropDefs->iDatePropertyDef->MaxTextLengthL() )
   496         && date.Length() < iPropDefs->iDatePropertyDef->MaxTextLengthL() )
   514         {
   497         {
   515         TTime releaseDate( date );
   498         TTime releaseDate( date );
   516         CMdeObjectWrapper::HandleObjectPropertyL( mdeObject, 
   499         CMdeObjectWrapper::HandleObjectPropertyL( mdeObject, 
   517                 *iPropDefs->iDatePropertyDef, &releaseDate, aIsAdd );
   500                 *iPropDefs->iDatePropertyDef, &releaseDate, aIsAdd );
       
   501         }
       
   502 
       
   503     TLex lex;
       
   504     
       
   505     if ( prot.Length() > 0 )
       
   506         {
       
   507         lex.Assign( prot );
       
   508         TInt protValue( 0 );
       
   509         if( KErrNone == lex.Val( protValue ) && protValue == 1 )
       
   510             {
       
   511             CMdeObjectWrapper::HandleObjectPropertyL( mdeObject, 
       
   512                     *iPropDefs->iDrmPropertyDef, &protValue, aIsAdd );
       
   513             }
       
   514         }
       
   515     
       
   516     if ( samplerate.Length() )
       
   517         {
       
   518         lex.Assign( samplerate );
       
   519         TReal32 value( 0 );
       
   520         if( KErrNone == lex.Val( value ) && value != 0 )
       
   521             {
       
   522             CMdeObjectWrapper::HandleObjectPropertyL( mdeObject, 
       
   523                     *iPropDefs->iSampleRatePropertyDef, &value, aIsAdd );
       
   524             }
       
   525         }
       
   526     
       
   527     if ( bitrate.Length() > 0 )
       
   528         {
       
   529         lex.Assign( bitrate );
       
   530         TInt value( 0 );
       
   531         if( KErrNone == lex.Val( value ) && value != 0 )
       
   532             {
       
   533             value /= KKiloBytes;
       
   534             CMdeObjectWrapper::HandleObjectPropertyL( mdeObject, 
       
   535                     *iPropDefs->iBitratePropertyDef, &value, aIsAdd );
       
   536             }
       
   537         }
       
   538     
       
   539     if ( albumartist.Length() > 0
       
   540         && albumartist.Length() < iPropDefs->iDatePropertyDef->MaxTextLengthL() )
       
   541         {
       
   542         CMdeObjectWrapper::HandleObjectPropertyL( mdeObject, 
       
   543                 *iPropDefs->iAlbumArtistPropertyDef, &albumartist, aIsAdd );
   518         }
   544         }
   519 
   545 
   520     if( iHarvestAlbumArt && iTNM && jpeg.Length() > 0 )
   546     if( iHarvestAlbumArt && iTNM && jpeg.Length() > 0 )
   521         {
   547         {
   522         HBufC8* jpegBuf = jpeg.AllocLC();  
   548         HBufC8* jpegBuf = jpeg.AllocLC();