harvester/harvesterplugins/VideoPlugin/src/harvestervideoplugin.cpp
branchRCL_3
changeset 30 3e156c80c15d
parent 27 4a4892eec172
child 47 b73252188534
equal deleted inserted replaced
27:4a4892eec172 30:3e156c80c15d
    50 _LIT( KMimeTypeAvi,        "video/avi");
    50 _LIT( KMimeTypeAvi,        "video/avi");
    51 _LIT( KMimeTypeVideoMatroska, "video/x-matroska");
    51 _LIT( KMimeTypeVideoMatroska, "video/x-matroska");
    52 _LIT( KMimeTypeAudioMatroska, "audio/x-matroska");
    52 _LIT( KMimeTypeAudioMatroska, "audio/x-matroska");
    53 _LIT( KMimeTypeWmv, "video/x-ms-wmv");
    53 _LIT( KMimeTypeWmv, "video/x-ms-wmv");
    54 _LIT( KMimeTypeDivx, "video/x-hx-divx");
    54 _LIT( KMimeTypeDivx, "video/x-hx-divx");
       
    55 _LIT( KMimeTypeAsf, "video/x-ms-asf");
    55 
    56 
    56 _LIT( KExtensionMp4,   "mp4" );
    57 _LIT( KExtensionMp4,   "mp4" );
    57 _LIT( KExtensionMpg4,  "mpg4" );
    58 _LIT( KExtensionMpg4,  "mpg4" );
    58 _LIT( KExtensionMpeg4, "mpeg4" );
    59 _LIT( KExtensionMpeg4, "mpeg4" );
    59 _LIT( KExtensionM4v,   "m4v" );
    60 _LIT( KExtensionM4v,   "m4v" );
    67 _LIT( KExtensionAvi,    "avi" );
    68 _LIT( KExtensionAvi,    "avi" );
    68 _LIT( KExtensionMkv,    "mkv" );
    69 _LIT( KExtensionMkv,    "mkv" );
    69 _LIT( KExtensionRa,     "ra" );
    70 _LIT( KExtensionRa,     "ra" );
    70 _LIT( KExtensionWmv,     "wmv" );
    71 _LIT( KExtensionWmv,     "wmv" );
    71 _LIT( KExtensionDivx,     "divx" );
    72 _LIT( KExtensionDivx,     "divx" );
       
    73 _LIT( KExtensionAsf,     "asf" );
    72 
    74 
    73 _LIT(KVideo, "Video");
    75 _LIT(KVideo, "Video");
    74 _LIT(KAudio, "Audio");
    76 _LIT(KAudio, "Audio");
    75 
    77 
    76 _LIT(KAudioAC3, "audio/AC3");
    78 _LIT(KAudioAC3, "audio/AC3");
   271     // Wmv
   273     // Wmv
   272     User::LeaveIfError( iMimeTypeMappings.InsertInOrder( THarvestingHandling(
   274     User::LeaveIfError( iMimeTypeMappings.InsertInOrder( THarvestingHandling(
   273             KExtensionWmv(), KMimeTypeWmv(), 
   275             KExtensionWmv(), KMimeTypeWmv(), 
   274             TVideoMetadataHandling( TVideoMetadataHandling::EHexilMetadataHandling, KVideo(),
   276             TVideoMetadataHandling( TVideoMetadataHandling::EHexilMetadataHandling, KVideo(),
   275                     KMimeTypeWmv(), KMimeTypeWmv() ) ), 
   277                     KMimeTypeWmv(), KMimeTypeWmv() ) ), 
       
   278             cmp ) );
       
   279 
       
   280     // Asf
       
   281     User::LeaveIfError( iMimeTypeMappings.InsertInOrder( THarvestingHandling(
       
   282             KExtensionAsf(), KMimeTypeAsf(), 
       
   283             TVideoMetadataHandling( TVideoMetadataHandling::EHexilMetadataHandling, KVideo(),
       
   284                     KMimeTypeAsf(), KMimeTypeAsf() ) ), 
   276             cmp ) );
   285             cmp ) );
   277 
   286 
   278     TFileName videos = PathInfo::VideosPath();
   287     TFileName videos = PathInfo::VideosPath();
   279     
   288     
   280     TFileName phonePath = PathInfo::PhoneMemoryRootPath();
   289     TFileName phonePath = PathInfo::PhoneMemoryRootPath();
  1144 
  1153 
  1145 #ifdef MDS_MP4LIB_USAGE 
  1154 #ifdef MDS_MP4LIB_USAGE 
  1146 void CHarvesterVideoPlugin::GetMp4Type( RFile64& aFile, TDes& aType )
  1155 void CHarvesterVideoPlugin::GetMp4Type( RFile64& aFile, TDes& aType )
  1147     {
  1156     {
  1148     WRITELOG( "CHarvesterVideoPlugin::GetMp4Mime - MP4ParseOpenFileHandle - start" );
  1157     WRITELOG( "CHarvesterVideoPlugin::GetMp4Mime - MP4ParseOpenFileHandle - start" );
       
  1158     TFileName tempName;
       
  1159     TUint32 mediaId( 0 );
       
  1160     TInt blackListError( KErrNone );
       
  1161 
       
  1162     blackListError = GetFileFullNameAndMediaId( aFile, tempName, mediaId );
       
  1163     if( blackListError == KErrNone )
       
  1164         {
       
  1165         blackListError == AddFileToBlackList( tempName, mediaId );
       
  1166         }
       
  1167 
  1149     MP4Handle handle;
  1168     MP4Handle handle;
  1150 
  1169 
  1151     MP4Err mp4err = MP4ParseOpenFileHandle64( &handle, &aFile );
  1170     MP4Err mp4err = MP4ParseOpenFileHandle64( &handle, &aFile );
  1152     
  1171     
  1153     WRITELOG( "CHarvesterVideoPlugin::GetMp4Mime - MP4ParseOpenFileHandle - ready" );
  1172     WRITELOG( "CHarvesterVideoPlugin::GetMp4Mime - MP4ParseOpenFileHandle - ready" );
  1179     else
  1198     else
  1180     	{
  1199     	{
  1181     	aType.Copy( KVideo() );
  1200     	aType.Copy( KVideo() );
  1182     	}
  1201     	}
  1183 
  1202 
       
  1203     if( blackListError == KErrNone )
       
  1204         {
       
  1205         RemoveFileFromBlackList( tempName, mediaId );
       
  1206         }
       
  1207 
  1184     MP4ParseClose( handle );
  1208     MP4ParseClose( handle );
  1185 	}
  1209 	}
  1186 #else
  1210 #else
  1187 void CHarvesterVideoPlugin::GetMp4Type( RFile64& /*aFile*/, TDes& /*aType*/ )
  1211 void CHarvesterVideoPlugin::GetMp4Type( RFile64& /*aFile*/, TDes& /*aType*/ )
  1188     {
  1212     {
  1194 	TBool possibleVideo = EFalse;
  1218 	TBool possibleVideo = EFalse;
  1195 
  1219 
  1196 	CHXMetaDataUtility* helixMetadata = CHXMetaDataUtility::NewL();
  1220 	CHXMetaDataUtility* helixMetadata = CHXMetaDataUtility::NewL();
  1197 	CleanupStack::PushL( helixMetadata );
  1221 	CleanupStack::PushL( helixMetadata );
  1198 
  1222 
  1199 	TFileName tempName;
  1223     TFileName tempName;
  1200 	TUint32 mediaId( 0 );
  1224     TUint32 mediaId( 0 );
  1201 	TInt blackListError( KErrNone );
  1225     TInt blackListError( KErrNone );
  1202 	
  1226     
  1203     if( iBlacklist )
  1227     blackListError = GetFileFullNameAndMediaId( aFile, tempName, mediaId );
  1204         {
  1228     if( blackListError == KErrNone )
  1205         WRITELOG( "CHarvesterVideoPlugin::GetRmTypeL - Adding URI to blacklist" );
  1229         {
  1206         blackListError = aFile.FullName( tempName );
  1230         AddFileToBlackList( tempName, mediaId );
  1207         if( blackListError == KErrNone )
       
  1208             {
       
  1209             blackListError = iMediaIdUtil->GetMediaId( tempName, mediaId );
       
  1210             if( blackListError == KErrNone )
       
  1211                 {
       
  1212                 TTime modified ( 0 );
       
  1213                 blackListError = iFs.Modified( tempName, modified );
       
  1214                 if( blackListError == KErrNone )
       
  1215                     {
       
  1216                     iBlacklist->AddFile( tempName, mediaId, modified );
       
  1217                     }
       
  1218                 }
       
  1219             }
       
  1220         }
  1231         }
  1221 	
  1232 	
  1222 	TRAPD( err, helixMetadata->OpenFileL( aFile ) );
  1233 	TRAPD( err, helixMetadata->OpenFileL( aFile ) );
  1223 
  1234 
  1224 	if( err == KErrNone )
  1235 	if( err == KErrNone )
  1257 			HBufC* mime = mimes[i];
  1268 			HBufC* mime = mimes[i];
  1258 	
  1269 	
  1259 			// "application/vnd.rn-realmedia" or "application/vnd.rn-realmedia-vbr"
  1270 			// "application/vnd.rn-realmedia" or "application/vnd.rn-realmedia-vbr"
  1260 			if( MdsUtils::Find( *mime, KMimeTypeRm() ) != KErrNotFound )
  1271 			if( MdsUtils::Find( *mime, KMimeTypeRm() ) != KErrNotFound )
  1261 				{
  1272 				{
  1262 				WRITELOG1( "CHarvesterVideoPlugin::GetObjectType - mimetype %S. Object type Rm", mime );
  1273 				WRITELOG1( "CHarvesterVideoPlugin::GetRmTypeL - mimetype %S. Object type Rm", mime );
  1263 				if( possibleVideo )
  1274 				if( possibleVideo )
  1264 					{
  1275 					{
  1265 					aType.Copy( KVideo );
  1276 					aType.Copy( KVideo );
  1266 					}
  1277 					}
  1267 				else
  1278 				else
  1271 				
  1282 				
  1272 				break;
  1283 				break;
  1273 				}
  1284 				}
  1274 			else if( MdsUtils::Find( *mime, KVideo() ) != KErrNotFound )
  1285 			else if( MdsUtils::Find( *mime, KVideo() ) != KErrNotFound )
  1275 				{
  1286 				{
  1276 				WRITELOG1( "CHarvesterVideoPlugin::GetObjectType - mimetype %S. Object type Video", mime );
  1287 				WRITELOG1( "CHarvesterVideoPlugin::GetRmTypeL - mimetype %S. Object type Video", mime );
  1277 				aType.Copy( KVideo );
  1288 				aType.Copy( KVideo );
  1278 	
  1289 	
  1279 				// use MIME with "video" substring, if file might be video
  1290 				// use MIME with "video" substring, if file might be video
  1280 				if( possibleVideo )
  1291 				if( possibleVideo )
  1281 					{
  1292 					{
  1282 					break;
  1293 					break;
  1283 					}
  1294 					}
  1284 				}
  1295 				}
  1285 			else if( MdsUtils::Find( *mime, KAudio() ) != KErrNotFound )
  1296 			else if( MdsUtils::Find( *mime, KAudio() ) != KErrNotFound )
  1286 				{
  1297 				{
  1287 				WRITELOG1( "CHarvesterVideoPlugin::GetObjectType - mimetype %S. Object type Audio", mime );
  1298 				WRITELOG1( "CHarvesterVideoPlugin::GetRmTypeL - mimetype %S. Object type Audio", mime );
  1288 				aType.Copy( KAudio );
  1299 				aType.Copy( KAudio );
  1289 				}
  1300 				}
  1290 			// Set to Video, regardless how badly file is corrupted
  1301 			// Set to Video, regardless how badly file is corrupted
  1291 			else
  1302 			else
  1292 				{
  1303 				{
  1301 	else
  1312 	else
  1302 		{
  1313 		{
  1303 		aType.Copy( KVideo );
  1314 		aType.Copy( KVideo );
  1304 		}
  1315 		}
  1305 	
  1316 	
  1306     if ( iBlacklist && blackListError == KErrNone )
  1317     if( blackListError == KErrNone )
  1307         {
  1318         {
  1308         WRITELOG( "CHarvesterVideoPlugin::GetRmTypeL - Removing URI from blacklist" );
  1319         RemoveFileFromBlackList( tempName, mediaId );
  1309         iBlacklist->RemoveFile( tempName, mediaId );
  1320         }
  1310         }
  1321     
  1311     
       
  1312 	helixMetadata->ResetL();
       
  1313     CleanupStack::PopAndDestroy( helixMetadata );
  1322     CleanupStack::PopAndDestroy( helixMetadata );
  1314 	}
  1323 	}
       
  1324 
       
  1325 TInt CHarvesterVideoPlugin::AddFileToBlackList( const TFileName& aFullName, const TUint32& aMediaId )
       
  1326     {
       
  1327     TInt blackListError( KErrNone );
       
  1328 
       
  1329     TTime modified ( 0 );
       
  1330     blackListError = iFs.Modified( aFullName, modified );
       
  1331     if( blackListError == KErrNone )
       
  1332         {
       
  1333         WRITELOG( "CHarvesterVideoPlugin::AddFileToBlackList - Adding URI to blacklist" );
       
  1334         iBlacklist->AddFile( aFullName, aMediaId, modified );
       
  1335         }
       
  1336 
       
  1337     return blackListError;
       
  1338     }
       
  1339 
       
  1340 TInt CHarvesterVideoPlugin::RemoveFileFromBlackList( const TFileName& aFullName, const TUint32& aMediaId )
       
  1341     {
       
  1342     TInt blackListError( KErrNone );
       
  1343 
       
  1344     if( iBlacklist )
       
  1345         {
       
  1346         WRITELOG( "CHarvesterVideoPlugin::RemoveFileFromBlackList - Removing URI from blacklist" );
       
  1347         blackListError = iBlacklist->RemoveFile( aFullName, aMediaId );
       
  1348         }
       
  1349 
       
  1350     return blackListError;
       
  1351     }
       
  1352 
       
  1353 TInt CHarvesterVideoPlugin::GetFileFullNameAndMediaId( const RFile64& aFile, TFileName& aFullName, TUint32& aMediaId)
       
  1354     {
       
  1355     TInt blackListError( KErrNone );
       
  1356 
       
  1357     if( iBlacklist )
       
  1358         {
       
  1359         WRITELOG( "CHarvesterVideoPlugin::GetFileFullNameAndMediaId" );
       
  1360         blackListError = aFile.FullName( aFullName );
       
  1361         if( blackListError == KErrNone )
       
  1362             {
       
  1363             blackListError = iMediaIdUtil->GetMediaId( aFullName, aMediaId );
       
  1364             }
       
  1365         }
       
  1366     else
       
  1367         {
       
  1368         blackListError = KErrNotReady;
       
  1369         }
       
  1370  
       
  1371     return blackListError;
       
  1372     }
  1315 
  1373 
  1316 const THarvestingHandling* CHarvesterVideoPlugin::FindHandler( const TDesC& aUri )
  1374 const THarvestingHandling* CHarvesterVideoPlugin::FindHandler( const TDesC& aUri )
  1317 	{
  1375 	{
  1318 	TParsePtrC parse( aUri );
  1376 	TParsePtrC parse( aUri );
  1319     TPtrC ext = parse.Ext();
  1377     TPtrC ext = parse.Ext();