136 CMPXMetadataExtractor::~CMPXMetadataExtractor() |
143 CMPXMetadataExtractor::~CMPXMetadataExtractor() |
137 { |
144 { |
138 delete iMetadataUtility; |
145 delete iMetadataUtility; |
139 delete iFileInfoUtil; |
146 delete iFileInfoUtil; |
140 delete iDrmMediaUtility; |
147 delete iDrmMediaUtility; |
|
148 delete iTaskTimer; |
|
149 iFile.Close(); |
141 #ifdef RD_MPX_TNM_INTEGRATION |
150 #ifdef RD_MPX_TNM_INTEGRATION |
142 delete iTNManager; |
151 delete iTNManager; |
143 if (iTNSyncWait && iTNSyncWait->IsStarted() ) |
152 if (iTNSyncWait && iTNSyncWait->IsStarted() ) |
144 { |
153 { |
145 iTNSyncWait->AsyncStop(); |
154 iTNSyncWait->AsyncStop(); |
146 } |
155 } |
147 delete iTNSyncWait; |
156 delete iTNSyncWait; |
148 delete iTimer; |
157 delete iTimer; |
|
158 iArrayTNRequestId.Close(); |
|
159 iArrayTasks.Close(); |
149 #endif //RD_MPX_TNM_INTEGRATION |
160 #endif //RD_MPX_TNM_INTEGRATION |
150 |
161 } |
151 MPX_DEBUG2("CMPXMetadataExtractor: TNM Block Count: %d ", iTNMBlockCount ); |
162 |
152 } |
163 // --------------------------------------------------------------------------- |
153 |
164 // Constructs a media properties object : synchronous function |
154 // --------------------------------------------------------------------------- |
|
155 // Constructs a media properties object |
|
156 // --------------------------------------------------------------------------- |
165 // --------------------------------------------------------------------------- |
157 // |
166 // |
158 EXPORT_C void CMPXMetadataExtractor::CreateMediaL( const TDesC& aFile, |
167 EXPORT_C void CMPXMetadataExtractor::CreateMediaL( const TDesC& aFile, |
159 CMPXMedia*& aNewProperty, |
168 CMPXMedia*& aNewProperty, |
160 TBool aMetadataOnly ) |
169 TBool aMetadataOnly ) |
161 { |
170 { |
162 // make a copy of aFile |
171 MPX_FUNC("CMPXMetadataExtractor::CreateMediaL()"); |
163 HBufC* fileName = HBufC::NewL(KMaxFileName); |
172 // check if we are still processing a request. |
164 CleanupStack::PushL( fileName ); |
173 if ( iArrayTasks.Count() ) |
165 fileName->Des().Append( aFile ); |
174 { |
166 MPX_DEBUG2("CMPXMetadataExtractor::CreateMediaL %S <---", fileName ); |
175 MPX_DEBUG1("CMPXMetadataExtractor::CreateMediaL Request ongoing. Abort!" ); |
167 |
176 User::Leave( KErrAbort ); |
168 RArray<TInt> contentIDs; |
177 } |
169 contentIDs.AppendL( KMPXMediaIdGeneral ); |
178 |
170 contentIDs.AppendL( KMPXMediaIdAudio ); |
179 iCancelled = EFalse; |
171 contentIDs.AppendL( KMPXMediaIdMusic ); |
180 iFileOpenError = KErrNone; |
172 contentIDs.AppendL( KMPXMediaIdDrm ); |
181 iObs = NULL; |
173 contentIDs.AppendL( KMPXMediaIdMTP ); |
|
174 aNewProperty = NULL; |
182 aNewProperty = NULL; |
175 CMPXMedia* media = CMPXMedia::NewL( contentIDs.Array() ); |
183 iFileName = aFile; |
176 CleanupStack::PushL( media ); |
184 iMetadataOnly = aMetadataOnly; |
177 contentIDs.Close(); |
185 |
178 |
186 // populate the task array |
179 // CMPXMedia default types |
187 AddTasksL(); |
180 |
188 |
181 media->SetTObjectValueL<TMPXGeneralType>( KMPXMediaGeneralType, |
189 // execute all tasks in the array |
182 EMPXItem ); |
190 while ( iArrayTasks.Count() ) |
183 media->SetTObjectValueL<TMPXGeneralCategory>( KMPXMediaGeneralCategory, |
191 { |
184 EMPXSong ); |
192 // execute task at index 0 |
185 |
193 TRAPD( error, ExecuteTaskL() ); |
186 TParsePtrC parse( *fileName ); |
194 if ( error || iCancelled ) |
187 |
195 { |
188 // Title, default is file name |
196 // cleanup |
189 media->SetTextValueL( KMPXMediaGeneralTitle, |
197 if ( iMedia != NULL ) |
190 parse.Name() ); |
198 { |
191 |
199 delete iMedia; |
192 // Default album track |
200 iMedia = NULL; |
193 media->SetTextValueL( KMPXMediaMusicAlbumTrack, |
201 } |
194 KNullDesC ); |
202 iArrayTasks.Reset(); |
195 |
203 if ( error ) |
196 // Set the Mime Type and collection UID |
204 { |
197 // |
205 CleanUp(); |
198 if( !aMetadataOnly ) |
206 User::LeaveIfError( error ); |
199 { |
207 } |
200 TInt index(KErrNotFound); |
208 break; |
201 TInt count( iSupportedTypes.Count() ); |
209 } |
202 for (TInt i=0; i <count; ++i) |
|
203 { |
|
204 TInt index2(KErrNotFound); |
|
205 const CDesCArray& exts = iSupportedTypes[i]->Extensions(); |
|
206 const TDesC& ext = parse.Ext(); |
|
207 if (!exts.FindIsq(ext, index2)) |
|
208 { // found |
|
209 index = i; |
|
210 break; |
|
211 } |
|
212 } |
|
213 if( KErrNotFound != index ) |
|
214 { |
|
215 MPX_DEBUG1("CMPXMetadataExtractor::CreateMediaPropertiesL apparc <---" ); |
|
216 TInt mimeIndex = SupportedContainerTypeL( *fileName, index ); |
|
217 User::LeaveIfError( mimeIndex ); |
|
218 MPX_DEBUG1("CMPXMetadataExtractor::CreateMediaPropertiesL apparc --->" ); |
|
219 |
|
220 media->SetTextValueL( KMPXMediaGeneralMimeType, |
|
221 iSupportedTypes[index]->Mimetypes()[mimeIndex] ); |
|
222 |
|
223 media->SetTObjectValueL( KMPXMediaGeneralCollectionId, |
|
224 iSupportedTypes[index]->Uid() ); |
|
225 } |
|
226 else |
|
227 { |
|
228 User::Leave(KErrNotSupported); |
|
229 } |
|
230 } |
|
231 else // other case use apparc to fetch and set mimetype |
|
232 { |
|
233 TDataType dataType; |
|
234 TUid dummyUid(KNullUid); |
|
235 iAppArc.AppForDocument(*fileName, dummyUid, dataType); |
|
236 media->SetTextValueL( KMPXMediaGeneralMimeType,dataType.Des() ); |
|
237 } |
|
238 |
210 |
239 // Use file handle here |
211 iArrayTasks.Remove( 0 ); |
240 // |
212 } |
241 RFile file; |
213 |
242 TInt err = file.Open( iFs, *fileName, EFileRead | EFileShareReadersOrWriters ); |
214 aNewProperty = iMedia; |
243 CleanupClosePushL(file); |
215 CleanUp(); |
244 |
|
245 // Initially set default tags. |
|
246 SetDefaultL( *media ); |
|
247 // Metadata related |
|
248 // |
|
249 if( err == KErrNone ) |
|
250 { |
|
251 const TDesC& mimeType = media->ValueText( KMPXMediaGeneralMimeType ); |
|
252 HBufC8* mimeType8 = HBufC8::NewLC( mimeType.Length() ); |
|
253 mimeType8->Des().Append( mimeType ); |
|
254 TRAPD( metadataerror, iMetadataUtility->OpenFileL( file, *mimeType8 ) ); |
|
255 MPX_DEBUG2("CMPXMetadataExtractor::CreateMediaL, error %d parsing metadata", |
|
256 metadataerror ); |
|
257 CleanupStack::PopAndDestroy( mimeType8 ); |
|
258 |
|
259 // Even if there is error extracting metadata, fill extracted tags. |
|
260 TRAP( metadataerror, SetMediaPropertiesL( *media, *fileName ) ); |
|
261 MPX_DEBUG2("CMPXMetadataExtractor::CreateMediaL, error %d setting tags", |
|
262 metadataerror ); |
|
263 |
|
264 // Reset the utility |
|
265 iMetadataUtility->ResetL(); |
|
266 } |
|
267 |
|
268 // Common properties that we can extract |
|
269 // |
|
270 SetExtMediaPropertiesL( *media, *fileName, aMetadataOnly, file, err ); |
|
271 CleanupStack::PopAndDestroy(&file); |
|
272 |
|
273 // Set the pointers now that the object is ready |
|
274 // |
|
275 CleanupStack::Pop( media ); |
|
276 aNewProperty = media; |
|
277 |
|
278 CleanupStack::PopAndDestroy( fileName ); |
|
279 MPX_DEBUG1("CMPXMetadataExtractor::CreateMediaPropertiesL --->"); |
|
280 } |
216 } |
281 |
217 |
282 // --------------------------------------------------------------------------- |
218 // --------------------------------------------------------------------------- |
283 // Sets all of the default media properties |
219 // Sets all of the default media properties |
284 // --------------------------------------------------------------------------- |
220 // --------------------------------------------------------------------------- |
285 // |
221 // |
286 void CMPXMetadataExtractor::SetDefaultL( CMPXMedia& aMediaProp ) |
222 void CMPXMetadataExtractor::SetDefaultL( CMPXMedia& aMediaProp ) |
287 { |
223 { |
|
224 MPX_FUNC("CMPXMetadataExtractor::SetDefaultL()"); |
288 // Comment |
225 // Comment |
289 aMediaProp.SetTextValueL( KMPXMediaGeneralComment, |
226 aMediaProp.SetTextValueL( KMPXMediaGeneralComment, |
290 KNullDesC ); |
227 KNullDesC ); |
291 // Artist |
228 // Artist |
292 aMediaProp.SetTextValueL( KMPXMediaMusicArtist, |
229 aMediaProp.SetTextValueL( KMPXMediaMusicArtist, |
429 valptr.Trim(); |
373 valptr.Trim(); |
430 TInt vallen = value->Length(); |
374 TInt vallen = value->Length(); |
431 if (vallen>0) |
375 if (vallen>0) |
432 { |
376 { |
433 FindAndReplaceForbiddenChars(valptr, vallen); |
377 FindAndReplaceForbiddenChars(valptr, vallen); |
434 aMedia.SetTextValueL(KMPXMediaMusicComposer, *value); |
378 iMedia->SetTextValueL(KMPXMediaMusicComposer, *value); |
435 } |
379 } |
436 break; |
380 break; |
437 } |
381 } |
438 case EMetaDataUrl: |
382 case EMetaDataUrl: |
439 case EMetaDataUserUrl: // fall through |
383 case EMetaDataUserUrl: // fall through |
440 { |
384 { |
441 aMedia.SetTextValueL( KMPXMediaMusicURL, |
385 iMedia->SetTextValueL( KMPXMediaMusicURL, |
442 *value ); |
386 *value ); |
443 break; |
387 break; |
444 } |
388 } |
445 case EMetaDataJpeg: |
389 case EMetaDataJpeg: |
446 { |
390 { |
447 #ifdef RD_MPX_TNM_INTEGRATION |
391 // Album art handled in AddMediaAlbumArtL() |
448 MPX_PERF_START(CMPXMetadataExtractor_SetMediaPropertiesL_JPEG_TNM); |
|
449 TPtrC8 ptr8 = metaCont.Field8( EMetaDataJpeg ); |
|
450 HBufC8* value8; |
|
451 TRAPD( err, value8 = ptr8.AllocL() ); |
|
452 if ( KErrNone != err ) |
|
453 { |
|
454 MPX_DEBUG2("CMPXMetadataExtractor::SetMediaPropertiesL - error jpeg = %i", err); |
|
455 } |
|
456 else |
|
457 { |
|
458 CleanupStack::PushL( value8 ); |
|
459 TRAPD( err, AddMediaAlbumArtL( aMedia, aFile, *value8 ) ); |
|
460 if ( KErrNone != err ) |
|
461 { |
|
462 MPX_DEBUG2("CMPXMetadataExtractor::SetMediaPropertiesL - error album art = %i", err); |
|
463 } |
|
464 CleanupStack::Pop( value8 ); |
|
465 } |
|
466 MPX_PERF_END(CMPXMetadataExtractor_SetMediaPropertiesL_JPEG_TNM); |
|
467 #else //RD_MPX_TNM_INTEGRATION |
|
468 aMedia.SetTextValueL( KMPXMediaMusicAlbumArtFileName, |
|
469 aFile ); |
|
470 #endif //RD_MPX_TNM_INTEGRATION |
|
471 break; |
392 break; |
472 } |
393 } |
473 case EMetaDataCopyright: |
394 case EMetaDataCopyright: |
474 { |
395 { |
475 aMedia.SetTextValueL( KMPXMediaGeneralCopyright, |
396 iMedia->SetTextValueL( KMPXMediaGeneralCopyright, |
476 *value ); |
397 *value ); |
477 break; |
398 break; |
478 } |
399 } |
479 case EMetaDataDuration: |
400 case EMetaDataDuration: |
480 { |
401 { |
481 const TDesC& mimeType = aMedia.ValueText( KMPXMediaGeneralMimeType ); |
402 const TDesC& mimeType = iMedia->ValueText( KMPXMediaGeneralMimeType ); |
482 MPX_DEBUG2("CMPXMetadataExtractor::SetExtMediaPropertiesL, mimeType = %S", &mimeType); |
403 MPX_DEBUG2("CMPXMetadataExtractor::SetExtMediaPropertiesL, mimeType = %S", &mimeType); |
483 |
404 |
484 // Verify if WMA, get the duration |
405 // Verify if WMA, get the duration |
485 if( mimeType.Compare(KWmaMimeType) == 0 || mimeType.Compare(KWmaCafMimeType) == 0 ) |
406 if( mimeType.Compare(KWmaMimeType) == 0 || mimeType.Compare(KWmaCafMimeType) == 0 ) |
486 { |
407 { |
517 if (fieldType != EMetaDataJpeg) |
438 if (fieldType != EMetaDataJpeg) |
518 { |
439 { |
519 CleanupStack::PopAndDestroy( value ); |
440 CleanupStack::PopAndDestroy( value ); |
520 } |
441 } |
521 } |
442 } |
522 |
|
523 MPX_DEBUG1("CMPXMetadataExtractor::SetMediaPropertiesL --->" ); |
|
524 } |
443 } |
525 |
444 |
526 // --------------------------------------------------------------------------- |
445 // --------------------------------------------------------------------------- |
527 // Sets extra media properties not returned by metadata utilities |
446 // Sets extra media properties not returned by metadata utilities |
528 // --------------------------------------------------------------------------- |
447 // --------------------------------------------------------------------------- |
529 // |
448 // |
530 void CMPXMetadataExtractor::SetExtMediaPropertiesL( CMPXMedia& aProp, |
449 void CMPXMetadataExtractor::SetExtMediaPropertiesL() |
531 const TDesC& aFile, |
450 { |
532 TBool aMetadataOnly, |
451 MPX_FUNC("CMPXMetadataExtractor::SetExtMediaPropertiesL()"); |
533 RFile& aFileHandle, |
|
534 TInt aFileErr ) |
|
535 { |
|
536 MPX_DEBUG1("CMPXMetadataExtractor::SetExtMediaPropertiesL <---"); |
|
537 |
452 |
538 // DB Flags to set |
453 // DB Flags to set |
539 // |
454 // |
540 TUint dbFlags(KMPXMediaGeneralFlagsSetOrUnsetBit); |
455 TUint dbFlags(KMPXMediaGeneralFlagsSetOrUnsetBit); |
541 |
456 |
542 // File Path |
457 // File Path |
543 // |
458 // |
544 TParsePtrC parse( aFile ); |
459 TParsePtrC parse( iFileName ); |
545 aProp.SetTextValueL( KMPXMediaGeneralUri, |
460 iMedia->SetTextValueL( KMPXMediaGeneralUri, iFileName ); |
546 aFile ); |
461 iMedia->SetTextValueL( KMPXMediaGeneralDrive, parse.Drive() ); |
547 aProp.SetTextValueL( KMPXMediaGeneralDrive, |
|
548 parse.Drive() ); |
|
549 |
462 |
550 // DRM Rights |
463 // DRM Rights |
551 // |
464 // |
552 CMPXMedia* drm = NULL; |
465 CMPXMedia* drm = NULL; |
553 TRAPD( drmError, iDrmMediaUtility->InitL( aFile ); |
466 TRAPD( drmError, iDrmMediaUtility->InitL( iFileName ); |
554 drm = CMPXMedia::NewL( *iDrmMediaUtility->GetMediaL( KMPXMediaDrmProtected.iAttributeId | |
467 drm = CMPXMedia::NewL( *iDrmMediaUtility->GetMediaL( KMPXMediaDrmProtected.iAttributeId | |
555 KMPXMediaDrmRightsStatus.iAttributeId ) ); |
468 KMPXMediaDrmRightsStatus.iAttributeId ) ); |
556 ); |
469 ); |
557 |
470 |
558 TBool prot(EFalse); |
471 TBool prot(EFalse); |
559 if( drm ) |
472 if( drm ) |
560 { |
473 { |
615 MPX_DEBUG1("CMPXMetadataExtractor::SetExtMediaPropertiesL, skip MMF "); |
528 MPX_DEBUG1("CMPXMetadataExtractor::SetExtMediaPropertiesL, skip MMF "); |
616 } |
529 } |
617 else |
530 else |
618 { |
531 { |
619 MPX_DEBUG1("CMPXMetadataExtractor::SetExtMediaPropertiesL, get MMF controller"); |
532 MPX_DEBUG1("CMPXMetadataExtractor::SetExtMediaPropertiesL, get MMF controller"); |
620 aFileHandle.Size( size ); |
533 iFile.Size( size ); |
621 aProp.SetTObjectValueL<TInt>( KMPXMediaGeneralSize, size ); |
534 iMedia->SetTObjectValueL<TInt>( KMPXMediaGeneralSize, size ); |
622 |
535 |
623 // Duration, bitrate, samplerate, etc |
536 // Duration, bitrate, samplerate, etc |
624 // |
537 // |
625 if( !aMetadataOnly ) |
538 if( !iMetadataOnly ) |
626 { |
539 { |
627 TRAPD(err2, iFileInfoUtil->OpenFileL( |
540 TRAPD(err2, iFileInfoUtil->OpenFileL( |
628 aFileHandle, |
541 iFile, |
629 aProp.ValueText(KMPXMediaGeneralMimeType))); |
542 iMedia->ValueText(KMPXMediaGeneralMimeType))); |
630 MPX_DEBUG2("CMPXMetadataExtractor::SetExtMediaPropertiesL, file info util error %i", err2); |
543 MPX_DEBUG2("CMPXMetadataExtractor::SetExtMediaPropertiesL, file info util error %i", err2); |
631 if( KErrNone == err2 ) |
544 if( KErrNone == err2 ) |
632 { |
545 { |
633 aProp.SetTObjectValueL<TUint>( KMPXMediaAudioBitrate, |
546 iMedia->SetTObjectValueL<TUint>( KMPXMediaAudioBitrate, |
634 iFileInfoUtil->BitRate() ); |
547 iFileInfoUtil->BitRate() ); |
635 aProp.SetTObjectValueL<TUint>( KMPXMediaAudioSamplerate, |
548 iMedia->SetTObjectValueL<TUint>( KMPXMediaAudioSamplerate, |
636 iFileInfoUtil->SampleRate() ); |
549 iFileInfoUtil->SampleRate() ); |
637 TInt64 duration = (TInt64) iFileInfoUtil->Duration().Int64() / 1000; // ms |
550 TInt64 duration = (TInt64) iFileInfoUtil->Duration().Int64() / 1000; // ms |
638 aProp.SetTObjectValueL<TInt32>( KMPXMediaGeneralDuration, |
551 iMedia->SetTObjectValueL<TInt32>( KMPXMediaGeneralDuration, |
639 duration ); |
552 duration ); |
640 |
553 |
641 MPX_DEBUG2("CMPXMetadataExtractor::SetExtMediaPropertiesL -- duration %i", duration); |
554 MPX_DEBUG2("CMPXMetadataExtractor::SetExtMediaPropertiesL -- duration %i", duration); |
642 } |
555 } |
643 |
556 |
644 iFileInfoUtil->Reset(); |
557 iFileInfoUtil->Reset(); |
645 } |
558 } |
646 } |
559 } |
647 } |
560 } |
648 else if( aFileErr == KErrNotFound || aFileErr == KErrPathNotFound ) |
561 else if( iFileOpenError == KErrNotFound || iFileOpenError == KErrPathNotFound ) |
649 { |
562 { |
650 dbFlags |= KMPXMediaGeneralFlagsIsInvalid; |
563 dbFlags |= KMPXMediaGeneralFlagsIsInvalid; |
651 } |
564 } |
652 // Finally set the db flag |
565 // Finally set the db flag |
653 // |
566 // |
654 aProp.SetTObjectValueL( KMPXMediaGeneralFlags, |
567 iMedia->SetTObjectValueL( KMPXMediaGeneralFlags, |
655 dbFlags ); |
568 dbFlags ); |
656 |
|
657 MPX_DEBUG1("CMPXMetadataExtractor::SetExtMediaPropertiesL --->"); |
|
658 } |
569 } |
659 |
570 |
660 // --------------------------------------------------------------------------- |
571 // --------------------------------------------------------------------------- |
661 // Check to see if this file is a supported container |
572 // Check to see if this file is a supported container |
662 // --------------------------------------------------------------------------- |
573 // --------------------------------------------------------------------------- |
663 // |
574 // |
664 TInt CMPXMetadataExtractor::SupportedContainerTypeL( const TDesC& aFile, |
575 TInt CMPXMetadataExtractor::SupportedContainerTypeL( const TDesC& aFile, |
665 TInt aIndex ) |
576 TInt aIndex ) |
666 { |
577 { |
|
578 MPX_FUNC("CMPXMetadataExtractor::SupportedContainerTypeL()"); |
667 TInt index(KErrNotFound); |
579 TInt index(KErrNotFound); |
668 |
580 |
669 TDataType dataType; |
581 TDataType dataType; |
670 TUid dummyUid(KNullUid); |
582 TUid dummyUid(KNullUid); |
671 iAppArc.AppForDocument(aFile, dummyUid, dataType); |
583 iAppArc.AppForDocument(aFile, dummyUid, dataType); |
818 } |
731 } |
819 CleanupStack::PopAndDestroy( &wantedFields ); |
732 CleanupStack::PopAndDestroy( &wantedFields ); |
820 |
733 |
821 if ( !err ) |
734 if ( !err ) |
822 { |
735 { |
823 TRAP( err, GetMediaAlbumArtL( *aMedia, path )); |
736 //check if can send TN request, If thumbnail creation is ongoing, wait til it is done |
|
737 CheckBeforeSendRequest(); |
|
738 TRAP( err, AddMediaAlbumArtL( *aMedia, path )); |
824 } |
739 } |
825 |
740 |
826 // Reset the utility |
741 // Reset the utility |
827 iMetadataUtility->ResetL(); |
742 iMetadataUtility->ResetL(); |
828 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
743 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
829 } |
744 } |
830 #endif |
745 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
831 return err; |
746 return err; |
832 } |
747 } |
833 |
748 |
834 // ---------------------------------------------------------------------------- |
749 // ---------------------------------------------------------------------------- |
835 // Set album art. |
750 // Add album art to media object. |
836 // ---------------------------------------------------------------------------- |
751 // ---------------------------------------------------------------------------- |
837 TInt CMPXMetadataExtractor::GetMediaAlbumArtL( CMPXMedia& aMedia, |
752 void CMPXMetadataExtractor::AddMediaAlbumArtL( CMPXMedia& aMedia, |
838 const TDesC& aFile ) |
753 const TDesC& aFile ) |
839 { |
754 { |
840 MPX_FUNC("CMPXMetadataExtractor::GetMediaAlbumArtL()"); |
755 MPX_FUNC("CMPXMetadataExtractor::AddMediaAlbumArtL()"); |
841 TInt err = KErrNone; |
756 |
842 // get metadata container. |
757 // get metadata container. |
843 const CMetaDataFieldContainer& metaCont = iMetadataUtility->MetaDataFieldsL(); |
758 const CMetaDataFieldContainer& metaCont = iMetadataUtility->MetaDataFieldsL(); |
844 |
|
845 TPtrC8 data8 = metaCont.Field8( EMetaDataJpeg ); |
759 TPtrC8 data8 = metaCont.Field8( EMetaDataJpeg ); |
846 |
760 |
847 if ( data8.Length() ) |
761 if ( data8.Length() ) |
848 { |
762 { |
849 MPX_DEBUG1("CMPXMetadataExtractor::GetMediaAlbumArtL(): Album art exist."); |
763 MPX_DEBUG1("CMPXMetadataExtractor::GetMediaAlbumArtL(): Album art exist."); |
850 |
|
851 #ifdef RD_MPX_TNM_INTEGRATION |
764 #ifdef RD_MPX_TNM_INTEGRATION |
852 HBufC8* value8; |
765 HBufC8* value8 = NULL; |
853 TRAPD( err, value8 = data8.AllocL() ); |
766 TRAPD( err, value8 = data8.AllocL() ); |
854 if ( KErrNone != err ) |
767 if ( KErrNone != err ) |
855 { |
768 { |
856 MPX_DEBUG2("CMPXMetadataExtractor::GetMediaAlbumArtL - error jpeg = %i", err); |
769 MPX_DEBUG2("CMPXMetadataExtractor::GetMediaAlbumArtL - error jpeg = %i", err); |
857 User::Leave( err ); |
770 return; |
858 } |
771 } |
859 CleanupStack::PushL( value8 ); |
772 CleanupStack::PushL( value8 ); |
860 AddMediaAlbumArtL( aMedia, aFile, *value8 ); |
773 |
|
774 TBuf<256> mimeType; |
|
775 mimeType.Copy( KImageFileType ); |
|
776 CThumbnailObjectSource* source = CThumbnailObjectSource::NewL( |
|
777 value8, mimeType, aFile ); |
|
778 TThumbnailRequestId tnId = iTNManager->CreateThumbnails( *source ); |
|
779 iArrayTNRequestId.Append( tnId ); // add thumbnail id to array |
861 CleanupStack::Pop( value8 ); |
780 CleanupStack::Pop( value8 ); |
862 #else // RD_MPX_TNM_INTEGRATION |
781 aMedia.SetTextValueL( KMPXMediaMusicOriginalAlbumArtFileName, aFile ); |
|
782 #endif // RD_MPX_TNM_INTEGRATION |
863 aMedia.SetTextValueL( KMPXMediaMusicAlbumArtFileName, aFile ); |
783 aMedia.SetTextValueL( KMPXMediaMusicAlbumArtFileName, aFile ); |
864 #endif // RD_MPX_TNM_INTEGRATION |
784 } |
865 } |
785 } |
866 else |
786 |
867 { |
787 // ---------------------------------------------------------------------------- |
868 err = KErrNotFound; |
788 // Check if can send request to TNM or not. |
869 } |
789 // ---------------------------------------------------------------------------- |
870 |
|
871 return err; |
|
872 } |
|
873 |
|
874 // ---------------------------------------------------------------------------- |
|
875 // Add album art to media object. |
|
876 // ---------------------------------------------------------------------------- |
|
877 void CMPXMetadataExtractor::AddMediaAlbumArtL( CMPXMedia& aMedia, |
|
878 const TDesC& aFile, |
|
879 TDesC8& aValue ) |
|
880 { |
|
881 MPX_FUNC("CMPXMetadataExtractor::AddMediaAlbumArtL()"); |
|
882 #ifdef RD_MPX_TNM_INTEGRATION |
|
883 |
|
884 //check if can send TN request, If thumbnail creation is ongoing, wait til it is done |
|
885 CheckBeforeSendRequest(); |
|
886 |
|
887 aMedia.SetTextValueL( KMPXMediaMusicAlbumArtFileName, aFile ); |
|
888 |
|
889 TBuf<256> mimeType; |
|
890 mimeType.Copy( KImageFileType ); |
|
891 CThumbnailObjectSource* source = CThumbnailObjectSource::NewLC( |
|
892 &aValue, mimeType, aFile ); |
|
893 iTNManager->CreateThumbnails( *source ); |
|
894 CleanupStack::PopAndDestroy( source ); |
|
895 aMedia.SetTextValueL( KMPXMediaMusicOriginalAlbumArtFileName, aFile ); |
|
896 iOutstandingThumbnailRequest++; |
|
897 |
|
898 #endif // RD_MPX_TNM_INTEGRATION |
|
899 } |
|
900 |
|
901 void CMPXMetadataExtractor::CheckBeforeSendRequest() |
790 void CMPXMetadataExtractor::CheckBeforeSendRequest() |
902 { |
791 { |
903 MPX_FUNC("CMPXMetadataExtractor::CheckBeforeSendRequest()"); |
792 MPX_FUNC("CMPXMetadataExtractor::CheckBeforeSendRequest()"); |
904 #ifdef RD_MPX_TNM_INTEGRATION |
793 #ifdef RD_MPX_TNM_INTEGRATION |
905 MPX_DEBUG2("CMPXMetadataExtractor::CheckBeforeSendRequest(): iOutstandingThumbnailRequest %d", |
794 MPX_DEBUG2("CMPXMetadataExtractor::CheckBeforeSendRequest(): Outstanding Thumbnail Request = %d", |
906 iOutstandingThumbnailRequest); |
795 iArrayTNRequestId.Count()); |
907 // If thumbnail creation is ongoing, wait til it is done |
796 // If thumbnail creation is ongoing, wait til it is done |
908 if ( iOutstandingThumbnailRequest >= KMPXMaxThumbnailRequest ) |
797 if ( iArrayTNRequestId.Count() >= KMPXMaxThumbnailRequest ) |
909 { |
798 { |
910 MPX_DEBUG1("CMPXMetadataExtractor::CheckBeforeSendRequest(): Thumbnail creation ongoing!"); |
799 MPX_DEBUG1("CMPXMetadataExtractor::CheckBeforeSendRequest(): Thumbnail creation ongoing!"); |
911 iTNMBlockCount++; |
|
912 // Cancel timer. |
800 // Cancel timer. |
913 CancelTimeoutTimer(); |
801 CancelTimeoutTimer(); |
914 // Start timer in case there is no callback from ThumbNail Manager. |
802 // Start timer in case there is no callback from ThumbNail Manager. |
915 iTimer->Start( |
803 iTimer->Start( |
916 KMPXTimeoutTimer, |
804 KMPXTimeoutTimer, |
923 iTNSyncWait->Start(); |
811 iTNSyncWait->Start(); |
924 } |
812 } |
925 } |
813 } |
926 #endif // RD_MPX_TNM_INTEGRATION |
814 #endif // RD_MPX_TNM_INTEGRATION |
927 } |
815 } |
|
816 |
|
817 // ---------------------------------------------------------------------------- |
|
818 // Cancel request. This will empty the task array and stop the wait loop. This |
|
819 // will cause the CreateMediaL() to finish more quickly. |
|
820 // ---------------------------------------------------------------------------- |
|
821 EXPORT_C void CMPXMetadataExtractor::CancelRequest() |
|
822 { |
|
823 MPX_FUNC("CMPXMetadataExtractor::CancelRequest()"); |
|
824 iCancelled = ETrue; |
|
825 // Cancel all tasks |
|
826 iArrayTasks.Reset(); |
|
827 // Cancel all thumbnail request |
|
828 CancelAllThumbnailRequests(); |
|
829 StopWaitLoop(); |
|
830 } |
|
831 |
|
832 // ---------------------------------------------------------------------------- |
|
833 // Cancel all outstanding thumbnail requests. |
|
834 // ---------------------------------------------------------------------------- |
|
835 void CMPXMetadataExtractor::CancelAllThumbnailRequests() |
|
836 { |
|
837 MPX_FUNC("CMPXMetadataExtractor::CancelAllThumbnailRequests()"); |
|
838 #ifdef RD_MPX_TNM_INTEGRATION |
|
839 // TODO: remove comments when TNM make CancelRequest asynchronous. |
|
840 /*TInt count = iArrayTNRequestId.Count(); |
|
841 for ( TInt i=0; i<count; i++ ) |
|
842 { |
|
843 iTNManager->CancelRequest( iArrayTNRequestId[i] ); |
|
844 } |
|
845 */ |
|
846 iArrayTNRequestId.Reset(); |
|
847 #endif // RD_MPX_TNM_INTEGRATION |
|
848 } |
|
849 |
|
850 // ---------------------------------------------------------------------------- |
|
851 // Create media and set default data and mimetype. |
|
852 // ---------------------------------------------------------------------------- |
|
853 void CMPXMetadataExtractor::DoCreateMediaL() |
|
854 { |
|
855 MPX_FUNC("CMPXMetadataExtractor::DoCreateMediaL()"); |
|
856 RArray<TInt> contentIDs; |
|
857 contentIDs.AppendL( KMPXMediaIdGeneral ); |
|
858 contentIDs.AppendL( KMPXMediaIdAudio ); |
|
859 contentIDs.AppendL( KMPXMediaIdMusic ); |
|
860 contentIDs.AppendL( KMPXMediaIdDrm ); |
|
861 contentIDs.AppendL( KMPXMediaIdMTP ); |
|
862 iMedia = CMPXMedia::NewL( contentIDs.Array() ); |
|
863 contentIDs.Close(); |
|
864 |
|
865 // CMPXMedia default types |
|
866 iMedia->SetTObjectValueL<TMPXGeneralType>( KMPXMediaGeneralType, |
|
867 EMPXItem ); |
|
868 iMedia->SetTObjectValueL<TMPXGeneralCategory>( KMPXMediaGeneralCategory, |
|
869 EMPXSong ); |
|
870 |
|
871 TParsePtrC parse( iFileName ); |
|
872 // Title, default is file name |
|
873 iMedia->SetTextValueL( KMPXMediaGeneralTitle, |
|
874 parse.Name() ); |
|
875 // Default album track |
|
876 iMedia->SetTextValueL( KMPXMediaMusicAlbumTrack, |
|
877 KNullDesC ); |
|
878 |
|
879 // Set the Mime Type and collection UID |
|
880 // |
|
881 if( !iMetadataOnly ) |
|
882 { |
|
883 TInt index(KErrNotFound); |
|
884 TInt count( iSupportedTypes.Count() ); |
|
885 for (TInt i=0; i <count; ++i) |
|
886 { |
|
887 TInt index2(KErrNotFound); |
|
888 const CDesCArray& exts = iSupportedTypes[i]->Extensions(); |
|
889 const TDesC& ext = parse.Ext(); |
|
890 if (!exts.FindIsq(ext, index2)) |
|
891 { // found |
|
892 index = i; |
|
893 break; |
|
894 } |
|
895 } |
|
896 if( KErrNotFound != index ) |
|
897 { |
|
898 MPX_DEBUG1("CMPXMetadataExtractor::DoCreateMediaL apparc <---" ); |
|
899 TInt mimeIndex = SupportedContainerTypeL( iFileName, index ); |
|
900 User::LeaveIfError( mimeIndex ); |
|
901 MPX_DEBUG1("CMPXMetadataExtractor::DoCreateMediaL apparc --->" ); |
|
902 |
|
903 iMedia->SetTextValueL( KMPXMediaGeneralMimeType, |
|
904 iSupportedTypes[index]->Mimetypes()[mimeIndex] ); |
|
905 |
|
906 iMedia->SetTObjectValueL( KMPXMediaGeneralCollectionId, |
|
907 iSupportedTypes[index]->Uid() ); |
|
908 } |
|
909 else |
|
910 { |
|
911 User::Leave(KErrNotSupported); |
|
912 } |
|
913 } |
|
914 else // other case use apparc to fetch and set mimetype |
|
915 { |
|
916 TDataType dataType; |
|
917 TUid dummyUid(KNullUid); |
|
918 iAppArc.AppForDocument(iFileName, dummyUid, dataType); |
|
919 iMedia->SetTextValueL( KMPXMediaGeneralMimeType,dataType.Des() ); |
|
920 } |
|
921 |
|
922 // Initially set default tags. |
|
923 SetDefaultL( *iMedia ); |
|
924 } |
|
925 |
|
926 // ---------------------------------------------------------------------------- |
|
927 // Execute task at index 0. |
|
928 // ---------------------------------------------------------------------------- |
|
929 void CMPXMetadataExtractor::ExecuteTaskL() |
|
930 { |
|
931 MPX_FUNC("CMPXMetadataExtractor::ExecuteTasksL()"); |
|
932 |
|
933 if ( iArrayTasks.Count() ) |
|
934 { |
|
935 switch ( iArrayTasks[0] ) |
|
936 { |
|
937 case ETaskCreateMedia: |
|
938 DoCreateMediaL(); |
|
939 break; |
|
940 case ETaskAddMetadata: |
|
941 SetMediaPropertiesL(); |
|
942 break; |
|
943 case ETaskAddExtMetadata: |
|
944 SetExtMediaPropertiesL(); |
|
945 break; |
|
946 case ETaskAddAlbumArt: |
|
947 AddMediaAlbumArtL( *iMedia, iFileName ); |
|
948 break; |
|
949 case ETaskCheckBeforeSend: |
|
950 CheckBeforeSendRequest(); |
|
951 break; |
|
952 default: |
|
953 MPX_ASSERT(0); // Should never get here |
|
954 } |
|
955 } |
|
956 } |
|
957 |
|
958 // --------------------------------------------------------------------------- |
|
959 // Constructs a media properties object : asynchronous funcion |
|
960 // --------------------------------------------------------------------------- |
|
961 // |
|
962 EXPORT_C void CMPXMetadataExtractor::CreateMediaAsyncL( const TDesC& aFile, |
|
963 MMPXMetadataExtractorObserver* aObs, |
|
964 TBool aMetadataOnly ) |
|
965 { |
|
966 MPX_FUNC("CMPXMetadataExtractor::CreateMediaAsyncL()"); |
|
967 // check if we are still processing a request. |
|
968 if ( iArrayTasks.Count() ) |
|
969 { |
|
970 MPX_DEBUG1("CMPXMetadataExtractor::CreateMediaAsyncL Request ongoing. Abort!" ); |
|
971 User::Leave( KErrAbort ); |
|
972 } |
|
973 |
|
974 iCancelled = EFalse; |
|
975 iFileOpenError = KErrNone; |
|
976 iFileName = aFile; |
|
977 iObs = aObs; |
|
978 iMetadataOnly = aMetadataOnly; |
|
979 |
|
980 // populate the task array |
|
981 AddTasksL(); |
|
982 |
|
983 // Start task timer to execute task |
|
984 if ( iArrayTasks.Count() ) |
|
985 { |
|
986 if ( iTaskTimer->IsActive() ) |
|
987 { |
|
988 iTaskTimer->Cancel(); |
|
989 } |
|
990 iTaskTimer->Start( 0, 0, TCallBack(TaskTimerCallback, this )); |
|
991 } |
|
992 } |
|
993 |
|
994 // --------------------------------------------------------------------------- |
|
995 // Opens the file |
|
996 // --------------------------------------------------------------------------- |
|
997 // |
|
998 TInt CMPXMetadataExtractor::OpenFile() |
|
999 { |
|
1000 MPX_FUNC("CMPXMetadataExtractor::OpenFile()"); |
|
1001 |
|
1002 // Open the file |
|
1003 iFile.Close(); |
|
1004 TInt error = iFile.Open( iFs, iFileName, EFileRead | EFileShareReadersOrWriters ); |
|
1005 MPX_DEBUG2("CMPXMetadataExtractor::OpenFile open error = %d", error ); |
|
1006 return error; |
|
1007 } |
|
1008 |
|
1009 // --------------------------------------------------------------------------- |
|
1010 // Populat task array |
|
1011 // --------------------------------------------------------------------------- |
|
1012 // |
|
1013 void CMPXMetadataExtractor::AddTasksL() |
|
1014 { |
|
1015 MPX_FUNC("CMPXMetadataExtractor::AddTasks()"); |
|
1016 iFileOpenError = OpenFile(); |
|
1017 |
|
1018 // Do not change the order of the task below. |
|
1019 iArrayTasks.Reset(); |
|
1020 if ( iFileOpenError == KErrNone ) |
|
1021 { |
|
1022 iArrayTasks.AppendL(ETaskCreateMedia); |
|
1023 iArrayTasks.AppendL(ETaskAddMetadata); |
|
1024 iArrayTasks.AppendL(ETaskCheckBeforeSend); |
|
1025 iArrayTasks.AppendL(ETaskAddAlbumArt); |
|
1026 iArrayTasks.AppendL(ETaskAddExtMetadata); |
|
1027 } |
|
1028 else |
|
1029 { |
|
1030 iArrayTasks.AppendL(ETaskCreateMedia); |
|
1031 iArrayTasks.AppendL(ETaskAddExtMetadata); |
|
1032 } |
|
1033 } |
|
1034 |
|
1035 // ---------------------------------------------------------------------------- |
|
1036 // Callback for timer. |
|
1037 // ---------------------------------------------------------------------------- |
|
1038 TInt CMPXMetadataExtractor::TaskTimerCallback(TAny* aPtr) |
|
1039 { |
|
1040 MPX_FUNC("CMPXMetadataExtractor::TaskTimerCallback()"); |
|
1041 |
|
1042 CMPXMetadataExtractor* ptr = |
|
1043 static_cast<CMPXMetadataExtractor*>(aPtr); |
|
1044 |
|
1045 ptr->HandleTaskTimerExpired(); |
|
1046 return KErrNone; |
|
1047 } |
|
1048 |
|
1049 // ---------------------------------------------------------------------------- |
|
1050 // Handle task timer expired |
|
1051 // ---------------------------------------------------------------------------- |
|
1052 void CMPXMetadataExtractor::HandleTaskTimerExpired() |
|
1053 { |
|
1054 MPX_FUNC("CMPXMetadataExtractor::HandleTaskTimerExpired()"); |
|
1055 |
|
1056 iTaskTimer->Cancel(); |
|
1057 // execute task at index 0 |
|
1058 TRAPD( error, ExecuteTaskL() ); |
|
1059 if ( error || iCancelled ) |
|
1060 { |
|
1061 // cleanup |
|
1062 if ( iMedia != NULL ) |
|
1063 { |
|
1064 delete iMedia; |
|
1065 iMedia = NULL; |
|
1066 } |
|
1067 iArrayTasks.Reset(); |
|
1068 } |
|
1069 |
|
1070 // Remove task at index 0. |
|
1071 if ( iArrayTasks.Count() ) |
|
1072 { |
|
1073 iArrayTasks.Remove( 0 ); |
|
1074 } |
|
1075 |
|
1076 // check if we have any more task to run |
|
1077 if ( iArrayTasks.Count() ) |
|
1078 { |
|
1079 // start task timer |
|
1080 iTaskTimer->Start( 0, 0, TCallBack(TaskTimerCallback, this )); |
|
1081 } |
|
1082 else |
|
1083 { |
|
1084 // done |
|
1085 if ( iObs && !iCancelled ) |
|
1086 { |
|
1087 iObs->HandleCreateMediaComplete( iMedia, error ); |
|
1088 } |
|
1089 |
|
1090 CleanUp(); |
|
1091 } |
|
1092 } |
|
1093 |
|
1094 // ---------------------------------------------------------------------------- |
|
1095 // Callback for timer. |
|
1096 // ---------------------------------------------------------------------------- |
|
1097 void CMPXMetadataExtractor::CleanUp() |
|
1098 { |
|
1099 MPX_FUNC("CMPXMetadataExtractor::CleanUp()"); |
|
1100 // Reset the utility |
|
1101 TRAP_IGNORE( iMetadataUtility->ResetL() ); |
|
1102 iFile.Close(); |
|
1103 } |
|
1104 |