262 const TDesC& mimeType = iMedia->ValueText( KMPXMediaGeneralMimeType ); |
267 const TDesC& mimeType = iMedia->ValueText( KMPXMediaGeneralMimeType ); |
263 HBufC8* mimeType8 = HBufC8::NewLC( mimeType.Length() ); |
268 HBufC8* mimeType8 = HBufC8::NewLC( mimeType.Length() ); |
264 mimeType8->Des().Append( mimeType ); |
269 mimeType8->Des().Append( mimeType ); |
265 |
270 |
266 // Continue to extract metadata even if fail. |
271 // Continue to extract metadata even if fail. |
267 TRAPD( metadataerror, iMetadataUtility->OpenFileL( iFile, *mimeType8 ) ); |
272 MPX_TRAPD( metadataerror, iMetadataUtility->OpenFileL( iFile, *mimeType8 ) ); |
268 MPX_DEBUG2("CMPXMetadataExtractor::CreateMediaL, error %d parsing metadata", |
|
269 metadataerror ); |
|
270 CleanupStack::PopAndDestroy( mimeType8 ); |
273 CleanupStack::PopAndDestroy( mimeType8 ); |
271 |
274 |
|
275 // Get MetadataUtility Container |
272 const CMetaDataFieldContainer& metaCont = iMetadataUtility->MetaDataFieldsL(); |
276 const CMetaDataFieldContainer& metaCont = iMetadataUtility->MetaDataFieldsL(); |
|
277 |
|
278 // Get DRM data |
|
279 // Need the protected flag from metadataUtility Container |
|
280 MPX_TRAPD( drmerror, SetDrmMediaPropertiesL( metaCont ) ); |
|
281 MPX_DEBUG2("CMPXMetadataExtractor::SetMediaPropertiesL, result=%d getting drm data", |
|
282 drmerror ); |
|
283 |
|
284 // Get metadata fields |
273 TInt count( metaCont.Count() ); |
285 TInt count( metaCont.Count() ); |
274 for( TInt i=0; i<count; ++i ) |
286 for( TInt i=0; i<count; ++i ) |
275 { |
287 { |
276 TMetaDataFieldId fieldType; |
288 TMetaDataFieldId fieldType; |
277 |
289 |
279 metaCont.FieldIdAt( i, fieldType ); // get the field type |
291 metaCont.FieldIdAt( i, fieldType ); // get the field type |
280 |
292 |
281 // get the value, except for album art |
293 // get the value, except for album art |
282 if ( fieldType != EMetaDataJpeg ) |
294 if ( fieldType != EMetaDataJpeg ) |
283 { |
295 { |
284 TRAPD( err, value = metaCont.At( i, fieldType ).AllocL() ); |
296 MPX_TRAPD( err, value = metaCont.At( i, fieldType ).AllocL() ); |
285 if ( KErrNone != err ) |
297 if ( KErrNone != err ) |
286 { |
298 { |
287 MPX_DEBUG2("CMPXMetadataExtractor::SetMediaPropertiesL - error = %i", err); |
299 MPX_DEBUG2("CMPXMetadataExtractor::SetMediaPropertiesL - error = %i", err); |
288 continue; |
300 continue; |
289 } |
301 } |
448 // |
460 // |
449 void CMPXMetadataExtractor::SetExtMediaPropertiesL() |
461 void CMPXMetadataExtractor::SetExtMediaPropertiesL() |
450 { |
462 { |
451 MPX_FUNC("CMPXMetadataExtractor::SetExtMediaPropertiesL()"); |
463 MPX_FUNC("CMPXMetadataExtractor::SetExtMediaPropertiesL()"); |
452 |
464 |
453 // DB Flags to set |
|
454 // |
|
455 TUint dbFlags(KMPXMediaGeneralFlagsSetOrUnsetBit); |
|
456 |
|
457 // File Path |
|
458 // |
|
459 TParsePtrC parse( iFileName ); |
|
460 iMedia->SetTextValueL( KMPXMediaGeneralUri, iFileName ); |
|
461 iMedia->SetTextValueL( KMPXMediaGeneralDrive, parse.Drive() ); |
|
462 |
|
463 // DRM Rights |
|
464 // |
|
465 CMPXMedia* drm = NULL; |
|
466 TRAPD( drmError, iDrmMediaUtility->InitL( iFileName ); |
|
467 drm = CMPXMedia::NewL( *iDrmMediaUtility->GetMediaL( KMPXMediaDrmProtected.iAttributeId | |
|
468 KMPXMediaDrmRightsStatus.iAttributeId ) ); |
|
469 ); |
|
470 |
|
471 TBool prot(EFalse); |
|
472 if( drm ) |
|
473 { |
|
474 CleanupStack::PushL( drm ); |
|
475 MPX_DEBUG1("CMPXMetadataExtractor::SetExtMediaPropertiesL -- is a drm file"); |
|
476 if( drm->IsSupported( KMPXMediaDrmProtected ) ) |
|
477 { |
|
478 prot = drm->ValueTObjectL<TBool>( KMPXMediaDrmProtected ); |
|
479 MPX_DEBUG2("CMPXMetadataExtractor::SetExtMediaPropertiesL protected %i", prot); |
|
480 } |
|
481 |
|
482 TMPXMediaDrmRightsStatus status(EMPXDrmRightsFull); |
|
483 if( drm->IsSupported( KMPXMediaDrmRightsStatus ) ) |
|
484 { |
|
485 status = drm->ValueTObjectL<TMPXMediaDrmRightsStatus>(KMPXMediaDrmRightsStatus); |
|
486 iMedia->SetTObjectValueL<TInt>(KMPXMediaDrmRightsStatus, status ); |
|
487 MPX_DEBUG2("CMPXMetadataExtractor::SetExtMediaPropertiesL -- status %i", status); |
|
488 } |
|
489 |
|
490 // Set DB flags |
|
491 dbFlags |= KMPXMediaGeneralFlagsIsDrmProtected; |
|
492 if( status != EMPXDrmRightsFull && status != EMPXDrmRightsRestricted && status != EMPXDrmRightsPreview ) |
|
493 { |
|
494 dbFlags |= KMPXMediaGeneralFlagsIsDrmLicenceInvalid; |
|
495 } |
|
496 CleanupStack::PopAndDestroy( drm ); |
|
497 } |
|
498 |
|
499 // Trapped PV DRM error. If -46, we know the file has no rights |
|
500 // |
|
501 if( drmError == KErrPermissionDenied ) |
|
502 { |
|
503 dbFlags |= KMPXMediaGeneralFlagsIsDrmLicenceInvalid; |
|
504 } |
|
505 else |
|
506 { |
|
507 User::LeaveIfError( drmError ); |
|
508 } |
|
509 |
|
510 iMedia->SetTObjectValueL<TBool>( KMPXMediaDrmProtected, prot ); |
|
511 iMedia->SetTObjectValueL<TUint16>( KMPXMediaMTPDrmStatus, (TUint16)prot ); |
|
512 |
|
513 iDrmMediaUtility->Close(); |
|
514 |
|
515 // |
465 // |
516 // File Size --- The following needs MMF support |
466 // File Size --- The following needs MMF support |
517 // |
467 // |
518 TInt size( 0 ); |
468 TInt size( 0 ); |
519 if( iFileOpenError == KErrNone ) |
469 if( iFileOpenError == KErrNone ) |
520 { |
470 { |
521 const TDesC& mimeType = iMedia->ValueText( KMPXMediaGeneralMimeType ); |
471 const TDesC& mimeType = iMedia->ValueText( KMPXMediaGeneralMimeType ); |
522 MPX_DEBUG2("CMPXMetadataExtractor::SetExtMediaPropertiesL, mimeType = %S", &mimeType); |
472 MPX_DEBUG2("CMPXMetadataExtractor::SetExtMediaPropertiesL, mimeType = %S", &mimeType); |
|
473 iFile.Size( size ); |
|
474 iMedia->SetTObjectValueL<TInt>( KMPXMediaGeneralSize, size ); |
523 |
475 |
524 // Verify if WMA, skip getting info from MMF |
476 // Verify if WMA, skip getting info from MMF |
525 if( mimeType.Compare(KWmaMimeType) == 0 || mimeType.Compare(KWmaCafMimeType) == 0 ) |
477 if( mimeType.Compare(KWmaMimeType) == 0 || mimeType.Compare(KWmaCafMimeType) == 0 ) |
526 { |
478 { |
527 // No need to get MMF support |
479 // No need to get MMF support |
528 MPX_DEBUG1("CMPXMetadataExtractor::SetExtMediaPropertiesL, skip MMF "); |
480 MPX_DEBUG1("CMPXMetadataExtractor::SetExtMediaPropertiesL, skip MMF "); |
529 } |
481 } |
530 else |
482 else |
531 { |
483 { |
532 MPX_DEBUG1("CMPXMetadataExtractor::SetExtMediaPropertiesL, get MMF controller"); |
484 MPX_DEBUG1("CMPXMetadataExtractor::SetExtMediaPropertiesL, get MMF controller"); |
533 iFile.Size( size ); |
|
534 iMedia->SetTObjectValueL<TInt>( KMPXMediaGeneralSize, size ); |
|
535 |
|
536 // Duration, bitrate, samplerate, etc |
485 // Duration, bitrate, samplerate, etc |
537 // |
486 // |
538 if( !iMetadataOnly ) |
487 if( !iMetadataOnly ) |
539 { |
488 { |
540 TRAPD(err2, iFileInfoUtil->OpenFileL( |
489 MPX_TRAPD(err2, iFileInfoUtil->OpenFileL( |
541 iFile, |
490 iFile, |
542 iMedia->ValueText(KMPXMediaGeneralMimeType))); |
491 iMedia->ValueText(KMPXMediaGeneralMimeType))); |
543 MPX_DEBUG2("CMPXMetadataExtractor::SetExtMediaPropertiesL, file info util error %i", err2); |
492 MPX_DEBUG2("CMPXMetadataExtractor::SetExtMediaPropertiesL, file info util error %i", err2); |
544 if( KErrNone == err2 ) |
493 if( KErrNone == err2 ) |
545 { |
494 { |
742 { |
683 { |
743 const TDesC& mimeType = aMedia->ValueText( KMPXMediaGeneralMimeType ); |
684 const TDesC& mimeType = aMedia->ValueText( KMPXMediaGeneralMimeType ); |
744 MPX_DEBUG2("CMPXMetadataExtractor::ExtractAlbumArtL MimeType:%S ", &mimeType ); |
685 MPX_DEBUG2("CMPXMetadataExtractor::ExtractAlbumArtL MimeType:%S ", &mimeType ); |
745 HBufC8* mimeType8 = HBufC8::NewLC( mimeType.Length() ); |
686 HBufC8* mimeType8 = HBufC8::NewLC( mimeType.Length() ); |
746 mimeType8->Des().Append( mimeType ); |
687 mimeType8->Des().Append( mimeType ); |
747 TRAP( err, iMetadataUtility->OpenFileL( path, wantedFields, *mimeType8 ) ); |
688 MPX_TRAP( err, iMetadataUtility->OpenFileL( path, wantedFields, *mimeType8 ) ); |
748 CleanupStack::PopAndDestroy( mimeType8 ); |
689 CleanupStack::PopAndDestroy( mimeType8 ); |
749 } |
690 } |
750 else |
691 else |
751 { |
692 { |
752 TRAP( err, iMetadataUtility->OpenFileL( path, wantedFields ) ); |
693 MPX_TRAP( err, iMetadataUtility->OpenFileL( path, wantedFields ) ); |
753 } |
694 } |
754 CleanupStack::PopAndDestroy( &wantedFields ); |
695 CleanupStack::PopAndDestroy( &wantedFields ); |
755 |
696 |
756 if ( !err ) |
697 if ( !err ) |
757 { |
698 { |
758 //check if can send TN request, If thumbnail creation is ongoing, wait til it is done |
699 //check if can send TN request, If thumbnail creation is ongoing, wait til it is done |
759 CheckBeforeSendRequest(); |
700 CheckBeforeSendRequest(); |
760 TRAP( err, AddMediaAlbumArtL( *aMedia, path )); |
701 MPX_TRAP( err, AddMediaAlbumArtL( *aMedia, path )); |
761 } |
702 } |
762 |
703 |
763 // Reset the utility |
704 // Reset the utility |
764 iMetadataUtility->ResetL(); |
705 iMetadataUtility->ResetL(); |
765 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
706 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
873 // Create media and set default data and mimetype. |
814 // Create media and set default data and mimetype. |
874 // ---------------------------------------------------------------------------- |
815 // ---------------------------------------------------------------------------- |
875 void CMPXMetadataExtractor::DoCreateMediaL() |
816 void CMPXMetadataExtractor::DoCreateMediaL() |
876 { |
817 { |
877 MPX_FUNC("CMPXMetadataExtractor::DoCreateMediaL()"); |
818 MPX_FUNC("CMPXMetadataExtractor::DoCreateMediaL()"); |
|
819 MPX_ASSERT( iMedia == NULL ); |
878 RArray<TInt> contentIDs; |
820 RArray<TInt> contentIDs; |
|
821 CleanupClosePushL( contentIDs ); |
879 contentIDs.AppendL( KMPXMediaIdGeneral ); |
822 contentIDs.AppendL( KMPXMediaIdGeneral ); |
880 contentIDs.AppendL( KMPXMediaIdAudio ); |
823 contentIDs.AppendL( KMPXMediaIdAudio ); |
881 contentIDs.AppendL( KMPXMediaIdMusic ); |
824 contentIDs.AppendL( KMPXMediaIdMusic ); |
882 contentIDs.AppendL( KMPXMediaIdDrm ); |
825 contentIDs.AppendL( KMPXMediaIdDrm ); |
883 contentIDs.AppendL( KMPXMediaIdMTP ); |
826 contentIDs.AppendL( KMPXMediaIdMTP ); |
884 iMedia = CMPXMedia::NewL( contentIDs.Array() ); |
827 iMedia = CMPXMedia::NewL( contentIDs.Array() ); |
885 contentIDs.Close(); |
828 CleanupStack::PopAndDestroy( &contentIDs ); |
886 |
829 |
887 // CMPXMedia default types |
830 // CMPXMedia default types |
888 iMedia->SetTObjectValueL<TMPXGeneralType>( KMPXMediaGeneralType, |
831 iMedia->SetTObjectValueL<TMPXGeneralType>( KMPXMediaGeneralType, |
889 EMPXItem ); |
832 EMPXItem ); |
890 iMedia->SetTObjectValueL<TMPXGeneralCategory>( KMPXMediaGeneralCategory, |
833 iMedia->SetTObjectValueL<TMPXGeneralCategory>( KMPXMediaGeneralCategory, |
1039 |
982 |
1040 // Do not change the order of the task below. |
983 // Do not change the order of the task below. |
1041 iArrayTasks.Reset(); |
984 iArrayTasks.Reset(); |
1042 if ( iFileOpenError == KErrNone ) |
985 if ( iFileOpenError == KErrNone ) |
1043 { |
986 { |
|
987 // to avoid resources contention (i.e. accessing sql, file system, etc) |
|
988 // Ordering the tasks - so no multiple tasks run at the same time |
|
989 // put the longest running task at the last (i.e. thumbnailing) |
1044 iArrayTasks.AppendL(ETaskCreateMedia); |
990 iArrayTasks.AppendL(ETaskCreateMedia); |
1045 iArrayTasks.AppendL(ETaskAddMetadata); |
991 iArrayTasks.AppendL(ETaskAddExtMetadata); // Get the MMF first |
|
992 iArrayTasks.AppendL(ETaskAddMetadata); // Get metadata & maybe drm data |
1046 iArrayTasks.AppendL(ETaskCheckBeforeSend); |
993 iArrayTasks.AppendL(ETaskCheckBeforeSend); |
1047 iArrayTasks.AppendL(ETaskAddAlbumArt); |
994 iArrayTasks.AppendL(ETaskAddAlbumArt); // Get album art / thumbnail last |
1048 iArrayTasks.AppendL(ETaskAddExtMetadata); |
|
1049 } |
995 } |
1050 else |
996 else |
1051 { |
997 { |
1052 iArrayTasks.AppendL(ETaskCreateMedia); |
998 iArrayTasks.AppendL(ETaskCreateMedia); |
1053 iArrayTasks.AppendL(ETaskAddExtMetadata); |
999 iArrayTasks.AppendL(ETaskAddExtMetadata); |
1073 // ---------------------------------------------------------------------------- |
1019 // ---------------------------------------------------------------------------- |
1074 void CMPXMetadataExtractor::HandleTaskTimerExpired() |
1020 void CMPXMetadataExtractor::HandleTaskTimerExpired() |
1075 { |
1021 { |
1076 MPX_FUNC("CMPXMetadataExtractor::HandleTaskTimerExpired()"); |
1022 MPX_FUNC("CMPXMetadataExtractor::HandleTaskTimerExpired()"); |
1077 |
1023 |
1078 iTaskTimer->Cancel(); |
1024 if ( iTaskTimer && iTaskTimer->IsActive() ) |
|
1025 { |
|
1026 iTaskTimer->Cancel(); |
|
1027 } |
1079 // execute task at index 0 |
1028 // execute task at index 0 |
1080 TRAPD( error, ExecuteTaskL() ); |
1029 MPX_TRAPD( error, ExecuteTaskL() ); |
1081 if ( error || iCancelled ) |
1030 if ( error || iCancelled ) |
1082 { |
1031 { |
1083 // cleanup |
1032 // cleanup |
1084 if ( iMedia != NULL ) |
1033 if ( iMedia != NULL ) |
1085 { |
1034 { |
1122 // Reset the utility |
1072 // Reset the utility |
1123 TRAP_IGNORE( iMetadataUtility->ResetL() ); |
1073 TRAP_IGNORE( iMetadataUtility->ResetL() ); |
1124 iFile.Close(); |
1074 iFile.Close(); |
1125 } |
1075 } |
1126 |
1076 |
|
1077 |
|
1078 // --------------------------------------------------------------------------- |
|
1079 // Sets DRRM media properties not returned by metadata utilities |
|
1080 // --------------------------------------------------------------------------- |
|
1081 // |
|
1082 void CMPXMetadataExtractor::SetDrmMediaPropertiesL(const CMetaDataFieldContainer& aMetaCont) |
|
1083 { |
|
1084 MPX_FUNC("CMPXMetadataExtractor::SetDrmMediaPropertiesL()"); |
|
1085 |
|
1086 TBool prot(EFalse); |
|
1087 // DB Flags to set |
|
1088 TUint dbFlags(KMPXMediaGeneralFlagsSetOrUnsetBit); |
|
1089 // Validate the objects to be used |
|
1090 MPX_ASSERT(iMedia); |
|
1091 MPX_ASSERT(iDrmMediaUtility); |
|
1092 |
|
1093 // File Path |
|
1094 TParsePtrC parse( iFileName ); |
|
1095 iMedia->SetTextValueL( KMPXMediaGeneralUri, iFileName ); |
|
1096 iMedia->SetTextValueL( KMPXMediaGeneralDrive, parse.Drive() ); |
|
1097 MPX_DEBUG2("CMPXMetadataExtractor::SetDrmMediaPropertiesL - Filename=%S", &iFileName); |
|
1098 |
|
1099 // get the protected flag from MetadataUtility Container |
|
1100 TPtrC ptr = aMetaCont.Field( EMetaDataProtected ); |
|
1101 MPX_DEBUG2("CMPXMetadataExtractor::SetDrmMediaPropertiesL -- status=%S", &ptr); |
|
1102 _LIT( KNonProtected, "0" ); |
|
1103 if ( ptr.Compare( KNonProtected ) == 0 ) |
|
1104 { |
|
1105 // this is non-protected file |
|
1106 // prot = EFalse |
|
1107 MPX_DEBUG1("CMPXMetadataExtractor::SetDrmMediaPropertiesL - non protected"); |
|
1108 iMedia->SetTObjectValueL<TBool>( KMPXMediaDrmProtected, prot ); |
|
1109 iMedia->SetTObjectValueL<TUint16>( KMPXMediaMTPDrmStatus, (TUint16)prot ); |
|
1110 } |
|
1111 else |
|
1112 { // DRM file |
|
1113 |
|
1114 // DRM Rights |
|
1115 // |
|
1116 CMPXMedia* drm = NULL; |
|
1117 MPX_TRAPD( drmError, iDrmMediaUtility->InitL( iFileName ); |
|
1118 drm = CMPXMedia::NewL( *iDrmMediaUtility->GetMediaL( KMPXMediaDrmProtected.iAttributeId | |
|
1119 KMPXMediaDrmRightsStatus.iAttributeId ) ); |
|
1120 ); |
|
1121 |
|
1122 TBool prot(EFalse); |
|
1123 if( drm ) |
|
1124 { |
|
1125 CleanupStack::PushL( drm ); |
|
1126 MPX_DEBUG1("CMPXMetadataExtractor::SetDrmMediaPropertiesL -- is a drm file"); |
|
1127 if( drm->IsSupported( KMPXMediaDrmProtected ) ) |
|
1128 { |
|
1129 prot = drm->ValueTObjectL<TBool>( KMPXMediaDrmProtected ); |
|
1130 MPX_DEBUG2("CMPXMetadataExtractor::SetDrmMediaPropertiesL protected %i", prot); |
|
1131 } |
|
1132 |
|
1133 TMPXMediaDrmRightsStatus status(EMPXDrmRightsFull); |
|
1134 if( drm->IsSupported( KMPXMediaDrmRightsStatus ) ) |
|
1135 { |
|
1136 status = drm->ValueTObjectL<TMPXMediaDrmRightsStatus>(KMPXMediaDrmRightsStatus); |
|
1137 iMedia->SetTObjectValueL<TInt>(KMPXMediaDrmRightsStatus, status ); |
|
1138 MPX_DEBUG2("CMPXMetadataExtractor::SetDrmMediaPropertiesL -- status %i", status); |
|
1139 } |
|
1140 |
|
1141 // Set DB flags |
|
1142 dbFlags |= KMPXMediaGeneralFlagsIsDrmProtected; |
|
1143 if( status != EMPXDrmRightsFull && status != EMPXDrmRightsRestricted && status != EMPXDrmRightsPreview ) |
|
1144 { |
|
1145 dbFlags |= KMPXMediaGeneralFlagsIsDrmLicenceInvalid; |
|
1146 } |
|
1147 CleanupStack::PopAndDestroy( drm ); |
|
1148 } |
|
1149 |
|
1150 // Trapped PV DRM error. If -46, we know the file has no rights |
|
1151 // |
|
1152 if( drmError == KErrPermissionDenied ) |
|
1153 { |
|
1154 dbFlags |= KMPXMediaGeneralFlagsIsDrmLicenceInvalid; |
|
1155 } |
|
1156 else |
|
1157 { |
|
1158 User::LeaveIfError( drmError ); |
|
1159 } |
|
1160 |
|
1161 iMedia->SetTObjectValueL<TBool>( KMPXMediaDrmProtected, prot ); |
|
1162 iMedia->SetTObjectValueL<TUint16>( KMPXMediaMTPDrmStatus, (TUint16)prot ); |
|
1163 |
|
1164 iDrmMediaUtility->Close(); |
|
1165 |
|
1166 } // DRM file |
|
1167 |
|
1168 |
|
1169 // verify the file open status |
|
1170 if( iFileOpenError == KErrNotFound || iFileOpenError == KErrPathNotFound ) |
|
1171 { |
|
1172 dbFlags |= KMPXMediaGeneralFlagsIsInvalid; |
|
1173 } |
|
1174 |
|
1175 // Finally set the db flag |
|
1176 // |
|
1177 iMedia->SetTObjectValueL( KMPXMediaGeneralFlags, dbFlags ); |
|
1178 |
|
1179 } |