harvester/harvesterplugins/VideoPlugin/src/harvestervideoplugin.cpp
branchRCL_3
changeset 19 b73252188534
parent 14 3e156c80c15d
child 20 f23c07ec56e2
equal deleted inserted replaced
18:63c982fb92f2 19:b73252188534
    83 _LIT(KInUse, "InUse");
    83 _LIT(KInUse, "InUse");
    84 
    84 
    85 const TInt KKiloBytes = 1024;
    85 const TInt KKiloBytes = 1024;
    86 const TReal32 KThousandReal = 1000.0;
    86 const TReal32 KThousandReal = 1000.0;
    87 
    87 
    88 CHarvesterVideoPluginPropertyDefs::CHarvesterVideoPluginPropertyDefs() : CBase()
    88 CHarvesterVideoPluginPropertyDefs::CHarvesterVideoPluginPropertyDefs() : CBase(),
       
    89     iCreationDatePropertyDef( NULL )
    89 	{
    90 	{
    90 	}
    91 	}
    91 
    92 
    92 void CHarvesterVideoPluginPropertyDefs::ConstructL(CMdEObjectDef& aObjectDef)
    93 void CHarvesterVideoPluginPropertyDefs::ConstructL(CMdEObjectDef& aObjectDef)
    93 	{
    94 	{
    94 	CMdENamespaceDef& nsDef = aObjectDef.NamespaceDef();
    95     SetByObjectDefL( aObjectDef );
    95 	
    96 	}
    96 	// Common property definitions
    97 
    97 	CMdEObjectDef& objectDef = nsDef.GetObjectDefL( Object::KBaseObject );
    98 CHarvesterVideoPluginPropertyDefs* CHarvesterVideoPluginPropertyDefs::NewL()
    98 	iCreationDatePropertyDef = &objectDef.GetPropertyDefL( Object::KCreationDateProperty );
    99     {
    99 	iLastModifiedDatePropertyDef = &objectDef.GetPropertyDefL( Object::KLastModifiedDateProperty );
   100     CHarvesterVideoPluginPropertyDefs* self = 
   100 	iSizePropertyDef = &objectDef.GetPropertyDefL( Object::KSizeProperty );
   101         new (ELeave) CHarvesterVideoPluginPropertyDefs();
   101 	iTimeOffsetPropertyDef = &objectDef.GetPropertyDefL( Object::KTimeOffsetProperty );
   102     return self;
   102 	iItemTypePropertyDef = &objectDef.GetPropertyDefL( Object::KItemTypeProperty );
   103     }
   103 	iTitlePropertyDef = &objectDef.GetPropertyDefL( Object::KTitleProperty );
   104 
   104 	iDefaultFolderPropertyDef = &objectDef.GetPropertyDefL( Object::KInDefaultFolder );
   105 void CHarvesterVideoPluginPropertyDefs::SetByObjectDefL( CMdEObjectDef& aObjectDef )
   105 
   106     {
   106 	CMdEObjectDef& mediaDef = nsDef.GetObjectDefL( MediaObject::KMediaObject );
   107     CMdENamespaceDef& nsDef = aObjectDef.NamespaceDef();
   107 	iReleaseDatePropertyDef = &mediaDef.GetPropertyDefL( MediaObject::KReleaseDateProperty );
   108     
   108 	iCaptureDatePropertyDef = &mediaDef.GetPropertyDefL( MediaObject::KCaptureDateProperty );
   109     // Common property definitions
   109 	iDurationPropertyDef = &mediaDef.GetPropertyDefL( MediaObject::KDurationProperty );
   110     CMdEObjectDef& objectDef = nsDef.GetObjectDefL( Object::KBaseObject );
   110 	iWidthPropertyDef = &mediaDef.GetPropertyDefL( MediaObject::KWidthProperty );
   111     iCreationDatePropertyDef = &objectDef.GetPropertyDefL( Object::KCreationDateProperty );
   111 	iHeightPropertyDef = &mediaDef.GetPropertyDefL( MediaObject::KHeightProperty );
   112     iLastModifiedDatePropertyDef = &objectDef.GetPropertyDefL( Object::KLastModifiedDateProperty );
   112 	iBitratePropertyDef = &mediaDef.GetPropertyDefL( MediaObject::KBitrateProperty );
   113     iSizePropertyDef = &objectDef.GetPropertyDefL( Object::KSizeProperty );
   113 	iCopyrightPropertyDef = &mediaDef.GetPropertyDefL( MediaObject::KCopyrightProperty );
   114     iTimeOffsetPropertyDef = &objectDef.GetPropertyDefL( Object::KTimeOffsetProperty );
   114 	iAuthorPropertyDef = &mediaDef.GetPropertyDefL( MediaObject::KAuthorProperty );
   115     iItemTypePropertyDef = &objectDef.GetPropertyDefL( Object::KItemTypeProperty );
   115 	iGenrePropertyDef = &mediaDef.GetPropertyDefL( MediaObject::KGenreProperty );
   116     iTitlePropertyDef = &objectDef.GetPropertyDefL( Object::KTitleProperty );
   116 	iArtistPropertyDef = &mediaDef.GetPropertyDefL( MediaObject::KArtistProperty );
   117     iDefaultFolderPropertyDef = &objectDef.GetPropertyDefL( Object::KInDefaultFolder );
   117 	iDescriptionPropertyDef = &mediaDef.GetPropertyDefL( MediaObject::KDescriptionProperty );
   118 
       
   119     CMdEObjectDef& mediaDef = nsDef.GetObjectDefL( MediaObject::KMediaObject );
       
   120     iReleaseDatePropertyDef = &mediaDef.GetPropertyDefL( MediaObject::KReleaseDateProperty );
       
   121     iCaptureDatePropertyDef = &mediaDef.GetPropertyDefL( MediaObject::KCaptureDateProperty );
       
   122     iDurationPropertyDef = &mediaDef.GetPropertyDefL( MediaObject::KDurationProperty );
       
   123     iWidthPropertyDef = &mediaDef.GetPropertyDefL( MediaObject::KWidthProperty );
       
   124     iHeightPropertyDef = &mediaDef.GetPropertyDefL( MediaObject::KHeightProperty );
       
   125     iBitratePropertyDef = &mediaDef.GetPropertyDefL( MediaObject::KBitrateProperty );
       
   126     iCopyrightPropertyDef = &mediaDef.GetPropertyDefL( MediaObject::KCopyrightProperty );
       
   127     iAuthorPropertyDef = &mediaDef.GetPropertyDefL( MediaObject::KAuthorProperty );
       
   128     iGenrePropertyDef = &mediaDef.GetPropertyDefL( MediaObject::KGenreProperty );
       
   129     iArtistPropertyDef = &mediaDef.GetPropertyDefL( MediaObject::KArtistProperty );
       
   130     iDescriptionPropertyDef = &mediaDef.GetPropertyDefL( MediaObject::KDescriptionProperty );
   118     iDrmPropertyDef = &mediaDef.GetPropertyDefL( MediaObject::KDRMProperty );
   131     iDrmPropertyDef = &mediaDef.GetPropertyDefL( MediaObject::KDRMProperty );
   119 	
   132     
   120 	iAudioFourCCDef = &mediaDef.GetPropertyDefL( MediaObject::KAudioFourCCProperty );
   133     iAudioFourCCDef = &mediaDef.GetPropertyDefL( MediaObject::KAudioFourCCProperty );
   121 
   134 
   122 	// Video property definitions
   135     // Video property definitions
   123 	CMdEObjectDef& videoDef = nsDef.GetObjectDefL( Video::KVideoObject );
   136     CMdEObjectDef& videoDef = nsDef.GetObjectDefL( Video::KVideoObject );
   124 	iFrameratePropertyDef = &videoDef.GetPropertyDefL( Video::KFramerateProperty );
   137     iFrameratePropertyDef = &videoDef.GetPropertyDefL( Video::KFramerateProperty );
   125 
   138 
   126 	// Audio property definitions
   139     // Audio property definitions
   127 	CMdEObjectDef& audioDef = nsDef.GetObjectDefL( Audio::KAudioObject );
   140     CMdEObjectDef& audioDef = nsDef.GetObjectDefL( Audio::KAudioObject );
   128 	iSamplingFrequencyPropertyDef = &audioDef.GetPropertyDefL( Audio::KSamplingFrequencyProperty );
   141     iSamplingFrequencyPropertyDef = &audioDef.GetPropertyDefL( Audio::KSamplingFrequencyProperty );
   129 	}
   142     }
   130 
       
   131 CHarvesterVideoPluginPropertyDefs* CHarvesterVideoPluginPropertyDefs::NewL(CMdEObjectDef& aObjectDef)
       
   132 	{
       
   133 	CHarvesterVideoPluginPropertyDefs* self = 
       
   134 		new (ELeave) CHarvesterVideoPluginPropertyDefs();
       
   135 	CleanupStack::PushL( self );
       
   136 	self->ConstructL( aObjectDef );
       
   137 	CleanupStack::Pop( self );
       
   138 	return self;
       
   139 	}
       
   140 
   143 
   141 /**
   144 /**
   142 * Default constructor
   145 * Default constructor
   143 */
   146 */
   144 CHarvesterVideoPlugin::CHarvesterVideoPlugin() : CHarvesterPlugin(), iPropDefs( NULL )
   147 CHarvesterVideoPlugin::CHarvesterVideoPlugin() : CHarvesterPlugin(), iPropDefs( NULL )
   163 * Destruction
   166 * Destruction
   164 */
   167 */
   165 CHarvesterVideoPlugin::~CHarvesterVideoPlugin()
   168 CHarvesterVideoPlugin::~CHarvesterVideoPlugin()
   166 	{
   169 	{
   167 	delete iPropDefs;
   170 	delete iPropDefs;
       
   171 	iPropDefs = NULL;
   168 	iMimeTypeMappings.Close();
   172 	iMimeTypeMappings.Close();
   169     RMediaIdUtil::ReleaseInstance();
   173     RMediaIdUtil::ReleaseInstance();
   170 
   174 
   171     delete iPhoneVideosPath;
   175     delete iPhoneVideosPath;
       
   176     iPhoneVideosPath = NULL;
   172     delete iMmcVideosPath;
   177     delete iMmcVideosPath;
       
   178     iMmcVideosPath = NULL;
   173     
   179     
   174 	WRITELOG("CHarvesterVideoPlugin::CHarvesterVideoPlugin()");
   180 	WRITELOG("CHarvesterVideoPlugin::CHarvesterVideoPlugin()");
   175 	}
   181 	}
   176 
   182 
   177 /**
   183 /**
   178 * 2nd phase constructor
   184 * 2nd phase constructor
   179 */
   185 */
   180 void CHarvesterVideoPlugin::ConstructL()
   186 void CHarvesterVideoPlugin::ConstructL()
   181 	{
   187 	{
   182 	WRITELOG( "CHarvesterVideoPlugin::ConstructL() - begin" );
   188 	WRITELOG( "CHarvesterVideoPlugin::ConstructL() - begin" );
       
   189 	
       
   190 	iPropDefs = CHarvesterVideoPluginPropertyDefs::NewL();
   183 	
   191 	
   184 	TLinearOrder< THarvestingHandling > cmp( THarvestingHandling::CompareFunction );
   192 	TLinearOrder< THarvestingHandling > cmp( THarvestingHandling::CompareFunction );
   185 
   193 
   186 	// MPEG4
   194 	// MPEG4
   187 	User::LeaveIfError( iMimeTypeMappings.InsertInOrder( THarvestingHandling(
   195 	User::LeaveIfError( iMimeTypeMappings.InsertInOrder( THarvestingHandling(
   546             }
   554             }
   547         }
   555         }
   548     
   556     
   549     if( !dataExtracted )
   557     if( !dataExtracted )
   550         {
   558         {
   551         TEntry entry;
   559         // If file could be opened, use file handle to fetch base data, otherwise
   552         const TInt errorcode = iFs.Entry( uri, entry );
   560         // attempt to fetch the data from TEntry 
   553         
   561         if( error == KErrNone )
   554         if ( errorcode != KErrNone )
       
   555             {
   562             {
   556             WRITELOG1( "CHarvesterVideoPlugin - Error getting entry: %d", errorcode );
   563             User::LeaveIfError( file.Modified( aVHD.iModified ) );
   557             CleanupStack::PopAndDestroy( &file );
   564             User::LeaveIfError( file.Size( aVHD.iFileSize ) );            
   558             User::Leave( errorcode );
       
   559             }
   565             }
   560         
   566         else
   561         aVHD.iModified = entry.iModified;
   567             {
   562         aVHD.iFileSize = (TUint)entry.iSize;
   568             TEntry entry;
       
   569             const TInt errorcode = iFs.Entry( uri, entry );
       
   570         
       
   571             if ( errorcode != KErrNone )
       
   572                 {
       
   573                 WRITELOG1( "CHarvesterVideoPlugin - Error getting entry: %d", errorcode );
       
   574                 CleanupStack::PopAndDestroy( &file );
       
   575                 User::Leave( errorcode );
       
   576                 }
       
   577         
       
   578             aVHD.iModified = entry.iModified;
       
   579             aVHD.iFileSize = (TUint)entry.iSize;        
       
   580             }
   563         
   581         
   564         WRITELOG1( "CHarvesterVideoPlugin - File size: %d", aVHD.iFileSize );
   582         WRITELOG1( "CHarvesterVideoPlugin - File size: %d", aVHD.iFileSize );
   565         }
   583         }
   566 
       
   567     // now the minimum information has been harvested
       
   568     // from now on the harvested data should always be stored
       
   569 
       
   570     const THarvestingHandling* mapping = FindHandler( uri );
       
   571     
       
   572     if( !mapping )
       
   573     	{
       
   574     	CleanupStack::PopAndDestroy( &file );
       
   575     	User::Leave( KErrNotFound );
       
   576     	}
       
   577 
   584 
   578     aVHD.iVideoObject = aMetadataObject.Def().Name().Compare( KVideo ) == 0;
   585     aVHD.iVideoObject = aMetadataObject.Def().Name().Compare( KVideo ) == 0;
   579 
   586 
   580     if( error != KErrNone )
   587     if( error != KErrNone )
   581         {
   588         {
   582         WRITELOG1( "CHarvesterVideoPlugin - File open error: %d", error );
   589         WRITELOG1( "CHarvesterVideoPlugin - File open error: %d", error );
   583         CleanupStack::PopAndDestroy( &file );
   590         CleanupStack::PopAndDestroy( &file );
   584         User::Leave( KErrCompletion );
   591         User::Leave( KErrCompletion );
   585         }
   592         }
   586     
   593     
       
   594     // now the minimum information has been harvested
       
   595     // from now on the harvested data should always be stored
       
   596 
       
   597     const THarvestingHandling* mapping = FindHandler( uri );
       
   598     
       
   599     if( !mapping )
       
   600     	{
       
   601     	CleanupStack::PopAndDestroy( &file );
       
   602     	User::Leave( KErrNotFound );
       
   603     	}
       
   604     
   587     if ( mapping->iHandler.iLibrary == TVideoMetadataHandling::EHexilMetadataHandling )
   605     if ( mapping->iHandler.iLibrary == TVideoMetadataHandling::EHexilMetadataHandling )
   588     	{
   606     	{
   589     	// doesn't own pointers to MIME types
   607     	// doesn't own pointers to MIME types
   590     	RPointerArray<HBufC> mimes;
   608     	RPointerArray<HBufC> mimes;
   591     	CleanupClosePushL( mimes );
   609     	CleanupClosePushL( mimes );
   592 
   610 
   593         TPtrC ext;
   611         TPtrC ext;
   594         MdsUtils::GetExt( uri, ext );
   612         const TBool exists = MdsUtils::GetExt( uri, ext );
   595         
   613         
   596         // Check for possibly protected content
   614         // Check for possibly protected content
   597         if( ext.CompareF( KExtensionWmv ) == 0 )
   615         if( exists && ext.CompareF( KExtensionWmv ) == 0 )
   598             {
   616             {
   599             ContentAccess::CContent* content = ContentAccess::CContent::NewLC( uri );
   617             ContentAccess::CContent* content = ContentAccess::CContent::NewLC( uri );
   600             ContentAccess::CData* data = content->OpenContentLC( ContentAccess::EPeek );
   618             ContentAccess::CData* data = content->OpenContentLC( ContentAccess::EPeek );
   601             
   619             
   602             data->GetAttribute( ContentAccess::EIsProtected, aVHD.iDrmProtected );
   620             data->GetAttribute( ContentAccess::EIsProtected, aVHD.iDrmProtected );
   605     	
   623     	
   606     	CHXMetaDataUtility* helixMetadata = CHXMetaDataUtility::NewL();
   624     	CHXMetaDataUtility* helixMetadata = CHXMetaDataUtility::NewL();
   607         CleanupStack::PushL( helixMetadata );
   625         CleanupStack::PushL( helixMetadata );
   608         
   626         
   609         TRAP( error, helixMetadata->OpenFileL( file ) );        
   627         TRAP( error, helixMetadata->OpenFileL( file ) );        
       
   628 
       
   629         // No need for the file handle anymore so closing it
       
   630         file.Close();
   610         
   631         
   611         if ( error == KErrNone )
   632         if ( error == KErrNone )
   612         	{
   633         	{
   613         	HBufC *buf = NULL;
   634         	HBufC *buf = NULL;
   614         	HXMetaDataKeys::EHXMetaDataId metaid;        	
   635         	HXMetaDataKeys::EHXMetaDataId metaid;        	
   787         if( mime.Ptr() && ( mime.Length() > 0 ) )
   808         if( mime.Ptr() && ( mime.Length() > 0 ) )
   788         	{
   809         	{
   789         	aVHD.iMimeBuf = mime.Alloc();
   810         	aVHD.iMimeBuf = mime.Alloc();
   790         	}
   811         	}
   791         
   812         
       
   813         helixMetadata->ResetL();
   792         CleanupStack::PopAndDestroy( helixMetadata );
   814         CleanupStack::PopAndDestroy( helixMetadata );
   793         
   815         
   794         // don't destory mime type pointers just clean array
   816         // don't destory mime type pointers just clean array
   795         CleanupStack::PopAndDestroy( &mimes );
   817         CleanupStack::PopAndDestroy( &mimes );
   796         
   818         
   980 		TBool aIsAdd )
  1002 		TBool aIsAdd )
   981     {
  1003     {
   982     WRITELOG("CHarvesterVideoPlugin::HandleObjectPropertiesL ");
  1004     WRITELOG("CHarvesterVideoPlugin::HandleObjectPropertiesL ");
   983 
  1005 
   984     CMdEObject& mdeObject = aHD.MdeObject();
  1006     CMdEObject& mdeObject = aHD.MdeObject();
   985 
  1007     
   986     if( !iPropDefs )
  1008     InitPropDefsL( mdeObject.Def() );
   987     	{
       
   988     	CMdEObjectDef& objectDef = mdeObject.Def();
       
   989     	iPropDefs = CHarvesterVideoPluginPropertyDefs::NewL( objectDef );
       
   990     	// Prefetch max text lengt for validity checking
       
   991     	iMaxTextLength = iPropDefs->iCopyrightPropertyDef->MaxTextLengthL();
       
   992     	}
       
   993 
  1009 
   994     TTimeIntervalSeconds timeOffsetSeconds = User::UTCOffset();
  1010     TTimeIntervalSeconds timeOffsetSeconds = User::UTCOffset();
   995     TTime localModifiedDate = aVHD.iModified + timeOffsetSeconds;
  1011     TTime localModifiedDate = aVHD.iModified + timeOffsetSeconds;
   996 
  1012 
   997     if( !mdeObject.Placeholder() )
  1013     if( !mdeObject.Placeholder() )
  1215 
  1231 
  1216 void CHarvesterVideoPlugin::GetRmTypeL( RFile64& aFile, TDes& aType )
  1232 void CHarvesterVideoPlugin::GetRmTypeL( RFile64& aFile, TDes& aType )
  1217 	{
  1233 	{
  1218 	TBool possibleVideo = EFalse;
  1234 	TBool possibleVideo = EFalse;
  1219 
  1235 
  1220 	CHXMetaDataUtility* helixMetadata = CHXMetaDataUtility::NewL();
       
  1221 	CleanupStack::PushL( helixMetadata );
       
  1222 
       
  1223     TFileName tempName;
  1236     TFileName tempName;
  1224     TUint32 mediaId( 0 );
  1237     TUint32 mediaId( 0 );
  1225     TInt blackListError( KErrNone );
  1238     TInt blackListError( KErrNone );
  1226     
  1239     
  1227     blackListError = GetFileFullNameAndMediaId( aFile, tempName, mediaId );
  1240     blackListError = GetFileFullNameAndMediaId( aFile, tempName, mediaId );
  1228     if( blackListError == KErrNone )
  1241     if( blackListError == KErrNone )
  1229         {
  1242         {
  1230         AddFileToBlackList( tempName, mediaId );
  1243         blackListError = AddFileToBlackList( tempName, mediaId );
  1231         }
  1244         }
  1232 	
  1245 	
       
  1246     CHXMetaDataUtility* helixMetadata = CHXMetaDataUtility::NewL();
       
  1247     CleanupStack::PushL( helixMetadata );
       
  1248     
  1233 	TRAPD( err, helixMetadata->OpenFileL( aFile ) );
  1249 	TRAPD( err, helixMetadata->OpenFileL( aFile ) );
  1234 
  1250 
  1235 	if( err == KErrNone )
  1251 	if( err == KErrNone )
  1236 		{
  1252 		{
  1237 		// doesn't own pointers to MIME types
  1253 		// doesn't own pointers to MIME types
  1311 	// Set to Video, regardless how badly file is corrupted
  1327 	// Set to Video, regardless how badly file is corrupted
  1312 	else
  1328 	else
  1313 		{
  1329 		{
  1314 		aType.Copy( KVideo );
  1330 		aType.Copy( KVideo );
  1315 		}
  1331 		}
       
  1332 
       
  1333 	helixMetadata->ResetL();
       
  1334     CleanupStack::PopAndDestroy( helixMetadata );
  1316 	
  1335 	
  1317     if( blackListError == KErrNone )
  1336     if( blackListError == KErrNone )
  1318         {
  1337         {
  1319         RemoveFileFromBlackList( tempName, mediaId );
  1338         RemoveFileFromBlackList( tempName, mediaId );
  1320         }
  1339         }
  1321     
  1340     
  1322     CleanupStack::PopAndDestroy( helixMetadata );
       
  1323 	}
  1341 	}
  1324 
  1342 
  1325 TInt CHarvesterVideoPlugin::AddFileToBlackList( const TFileName& aFullName, const TUint32& aMediaId )
  1343 TInt CHarvesterVideoPlugin::AddFileToBlackList( const TFileName& aFullName, const TUint32& aMediaId )
  1326     {
  1344     {
  1327     TInt blackListError( KErrNone );
  1345     TInt blackListError( KErrNone );
  1329     TTime modified ( 0 );
  1347     TTime modified ( 0 );
  1330     blackListError = iFs.Modified( aFullName, modified );
  1348     blackListError = iFs.Modified( aFullName, modified );
  1331     if( blackListError == KErrNone )
  1349     if( blackListError == KErrNone )
  1332         {
  1350         {
  1333         WRITELOG( "CHarvesterVideoPlugin::AddFileToBlackList - Adding URI to blacklist" );
  1351         WRITELOG( "CHarvesterVideoPlugin::AddFileToBlackList - Adding URI to blacklist" );
  1334         iBlacklist->AddFile( aFullName, aMediaId, modified );
  1352         blackListError = iBlacklist->AddFile( aFullName, aMediaId, modified );
  1335         }
  1353         }
  1336 
  1354 
  1337     return blackListError;
  1355     return blackListError;
  1338     }
  1356     }
  1339 
  1357 
  1427         return;
  1445         return;
  1428         }
  1446         }
  1429     return;
  1447     return;
  1430     }
  1448     }
  1431 
  1449 
       
  1450 void CHarvesterVideoPlugin::InitPropDefsL(CMdEObjectDef& aObjectDef)
       
  1451     {
       
  1452     if( !iPropDefs->iCreationDatePropertyDef )
       
  1453         {
       
  1454         iPropDefs->SetByObjectDefL( aObjectDef );
       
  1455         // Prefetch max text lengt for validity checking
       
  1456         iMaxTextLength = iPropDefs->iCopyrightPropertyDef->MaxTextLengthL();
       
  1457         }
       
  1458     }
       
  1459 
  1432 // End of file
  1460 // End of file
  1433 
  1461