author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 21:14:08 +0300 | |
branch | RCL_3 |
changeset 56 | 2cbbefa9af78 |
parent 53 | 3de6c4cf6b67 |
permissions | -rw-r--r-- |
53 | 1 |
/* |
2 |
* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 |
* All rights reserved. |
|
4 |
* This component and the accompanying materials are made available |
|
5 |
* under the terms of "Eclipse Public License v1.0" |
|
6 |
* which accompanies this distribution, and is available |
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
* |
|
9 |
* Initial Contributors: |
|
10 |
* Nokia Corporation - initial contribution. |
|
11 |
* |
|
12 |
* Contributors: |
|
13 |
* |
|
14 |
* Description: MPX album utility API |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
#include <e32std.h> |
|
19 |
#include <MetaDataUtility.h> |
|
20 |
#include <MetaDataFieldContainer.h> |
|
21 |
#include <mpxuser.h> |
|
22 |
#include <mpxmedia.h> |
|
23 |
#include <mpxmediamusicdefs.h> |
|
24 |
#include <mpxmediageneraldefs.h> |
|
25 |
#include <mpxlog.h> |
|
26 |
||
27 |
#include "mpxalbumartutilobserver.h" |
|
28 |
#include "mpximageutil.h" |
|
29 |
#include "mpxalbumartutil.h" |
|
30 |
#include <thumbnaildata.h> |
|
31 |
#include <thumbnailobjectsource.h> |
|
32 |
||
33 |
_LIT( KMPXAlbumMimeType, "audio/mpeg3" ); |
|
34 |
||
35 |
// ============================== MEMBER FUNCTIONS ============================ |
|
36 |
||
37 |
// ---------------------------------------------------------------------------- |
|
38 |
// Create the playback utility object |
|
39 |
// ---------------------------------------------------------------------------- |
|
40 |
// |
|
41 |
EXPORT_C CMPXAlbumArtUtil* CMPXAlbumArtUtil::NewL() |
|
42 |
{ |
|
43 |
CMPXAlbumArtUtil* self = new(ELeave)CMPXAlbumArtUtil(); |
|
44 |
CleanupStack::PushL(self); |
|
45 |
self->ConstructL(); |
|
46 |
CleanupStack::Pop(self); |
|
47 |
return self; |
|
48 |
} |
|
49 |
||
50 |
||
51 |
// ---------------------------------------------------------------------------- |
|
52 |
// Destructor |
|
53 |
// ---------------------------------------------------------------------------- |
|
54 |
// |
|
55 |
EXPORT_C CMPXAlbumArtUtil::~CMPXAlbumArtUtil() |
|
56 |
{ |
|
57 |
if (iArtUtil) |
|
58 |
{ |
|
59 |
iArtUtil->CancelRequest(); |
|
60 |
delete iArtUtil; |
|
61 |
} |
|
62 |
if(iFilename) |
|
63 |
{ |
|
64 |
delete iFilename; |
|
65 |
iFilename = NULL; |
|
66 |
} |
|
67 |
delete iThumbnailManager; |
|
68 |
} |
|
69 |
||
70 |
||
71 |
// ---------------------------------------------------------------------------- |
|
72 |
// Constructor |
|
73 |
// ---------------------------------------------------------------------------- |
|
74 |
// |
|
75 |
CMPXAlbumArtUtil::CMPXAlbumArtUtil() |
|
76 |
{ |
|
77 |
} |
|
78 |
||
79 |
// ---------------------------------------------------------------------------- |
|
80 |
// Constructor |
|
81 |
// ---------------------------------------------------------------------------- |
|
82 |
// |
|
83 |
void CMPXAlbumArtUtil::ConstructL() |
|
84 |
{ |
|
85 |
MPX_FUNC("CMPXAlbumArtUtil::ConstructL()"); |
|
86 |
iThumbnailManager = CThumbnailManager::NewL( *this ); |
|
87 |
iThumbnailManager->SetFlagsL( CThumbnailManager::EDefaultFlags ); |
|
88 |
iThumbnailManager->SetQualityPreferenceL( CThumbnailManager::EOptimizeForPerformance ); |
|
89 |
} |
|
90 |
||
91 |
// ---------------------------------------------------------------------------- |
|
92 |
// Create the playback utility object |
|
93 |
// ---------------------------------------------------------------------------- |
|
94 |
// |
|
95 |
EXPORT_C void CMPXAlbumArtUtil::ExtractAlbumArtL(const CMPXMedia& aMedia, |
|
96 |
MMPXAlbumArtUtilObserver& aObs, |
|
97 |
const TSize& aSize, |
|
98 |
TBool aLargestFromCache, |
|
99 |
TDisplayMode aDisplayMode /*= EColor64K*/) |
|
100 |
{ |
|
101 |
MPX_DEBUG1("CMPXAlbumArtUtil::ExtractAlbumArtL(): Entering"); |
|
102 |
MPX_DEBUG_THREAD("CMPXAlbumArtUtil::ExtractAlbumArtL()"); |
|
103 |
if(iFilename) |
|
104 |
{ |
|
105 |
delete iFilename; |
|
106 |
iFilename = NULL; |
|
107 |
} |
|
108 |
if ( iArtUtil ) |
|
109 |
{ |
|
110 |
delete iArtUtil; |
|
111 |
iArtUtil = NULL; |
|
112 |
} |
|
113 |
iArtUtil = CMPXImageUtil::NewL(aObs); |
|
114 |
iDisplayMode = aDisplayMode; |
|
115 |
iImageSize = aSize; |
|
116 |
iObserver = &aObs; |
|
117 |
||
118 |
if (aMedia.IsSupported( KMPXMediaMusicAlbumArtFileName )) |
|
119 |
{ |
|
120 |
if ( aMedia.ValueText( KMPXMediaMusicAlbumArtFileName ).Length() == 0) |
|
121 |
{ |
|
122 |
iReqId = 0; |
|
123 |
User::Leave( KErrNotFound ); |
|
124 |
} |
|
125 |
} |
|
126 |
||
127 |
if ( aMedia.IsSupported( KMPXMediaGeneralUri ) && |
|
128 |
aMedia.IsSupported( KMPXMediaMusicAlbumArtFileName )) |
|
129 |
{ |
|
130 |
iFilename = aMedia.ValueText( KMPXMediaMusicAlbumArtFileName ).AllocL(); |
|
131 |
||
132 |
if ( aLargestFromCache ) |
|
133 |
{ |
|
134 |
iThumbnailManager->SetThumbnailSizeL(EAudioFullScreenThumbnailSize); |
|
135 |
} |
|
136 |
else |
|
137 |
{ |
|
138 |
iThumbnailManager->SetThumbnailSizeL(aSize); |
|
139 |
} |
|
140 |
||
141 |
ExtractThumbnailL(&aMedia); |
|
142 |
} |
|
143 |
else |
|
144 |
{ |
|
145 |
User::Leave( KErrNotFound ); |
|
146 |
} |
|
147 |
MPX_DEBUG1("CMPXAlbumArtUtil::ExtractAlbumArtL(): Exiting"); |
|
148 |
} |
|
149 |
||
150 |
// ----------------------------------------------------------------------------- |
|
151 |
// Cancel Asynch requests |
|
152 |
// ----------------------------------------------------------------------------- |
|
153 |
// |
|
154 |
EXPORT_C void CMPXAlbumArtUtil::CancelRequest() |
|
155 |
{ |
|
156 |
MPX_DEBUG1("CMPXAlbumArtUtil::CancelRequest(): Entering"); |
|
157 |
if ( iArtUtil ) |
|
158 |
{ |
|
159 |
iArtUtil->CancelRequest(); |
|
160 |
delete iArtUtil; |
|
161 |
iArtUtil = 0; |
|
162 |
} |
|
163 |
if ( iThumbnailManager && iReqId > 0 ) |
|
164 |
{ |
|
165 |
iThumbnailManager->CancelRequest(iReqId); |
|
166 |
} |
|
167 |
iReqId = 0; |
|
168 |
MPX_DEBUG1("CMPXAlbumArtUtil::CancelRequest(): Exiting"); |
|
169 |
} |
|
170 |
||
171 |
// ---------------------------------------------------------------------------- |
|
172 |
// Extract binary data from file |
|
173 |
// ---------------------------------------------------------------------------- |
|
174 |
// |
|
175 |
HBufC8* CMPXAlbumArtUtil::ExtractBinaryMetaDataLC(const TDesC& aFilename, |
|
176 |
TMetaDataFieldId aFieldId) |
|
177 |
{ |
|
178 |
MPX_DEBUG1("CMPXAlbumArtUtil::ExtractBinaryMetaDataLC(): Entering"); |
|
179 |
HBufC8* ret(NULL); |
|
180 |
||
181 |
if (EUnknownMetaDataField != aFieldId) |
|
182 |
{ |
|
183 |
CMetaDataUtility* metaDataUtil = CMetaDataUtility::NewL(); |
|
184 |
CleanupStack::PushL( metaDataUtil ); |
|
185 |
||
186 |
RArray<TMetaDataFieldId> wantedFields; |
|
187 |
CleanupClosePushL(wantedFields); |
|
188 |
wantedFields.AppendL(aFieldId); |
|
189 |
||
190 |
metaDataUtil->OpenFileL(aFilename, wantedFields); |
|
191 |
const CMetaDataFieldContainer& metaCont = |
|
192 |
metaDataUtil->MetaDataFieldsL(); |
|
193 |
TPtrC data = metaCont.Field( aFieldId ); |
|
194 |
if(data.Length()==0) |
|
195 |
{ |
|
196 |
User::Leave( KErrNotFound ); |
|
197 |
} |
|
198 |
ret = MPXUser::Alloc8L(data); |
|
199 |
||
200 |
CleanupStack::PopAndDestroy(&wantedFields); |
|
201 |
CleanupStack::PopAndDestroy(metaDataUtil); |
|
202 |
CleanupStack::PushL( ret ); |
|
203 |
} |
|
204 |
else |
|
205 |
{ |
|
206 |
ret = HBufC8::NewLC(0); |
|
207 |
} |
|
208 |
||
209 |
MPX_DEBUG1("CMPXAlbumArtUtil::ExtractBinaryMetaDataLC(): Exiting"); |
|
210 |
return ret; |
|
211 |
} |
|
212 |
||
213 |
// ----------------------------------------------------------------------------- |
|
214 |
// Preview thumbnail generation or loading is complete. |
|
215 |
// ----------------------------------------------------------------------------- |
|
216 |
// |
|
217 |
void CMPXAlbumArtUtil::ThumbnailPreviewReady( |
|
218 |
MThumbnailData& /*aThumbnail*/, |
|
219 |
TThumbnailRequestId /*aId*/ ) |
|
220 |
{ |
|
221 |
MPX_FUNC( "CMPXAlbumArtUtil::ThumbnailPreviewReady" ); |
|
222 |
// Not used |
|
223 |
} |
|
224 |
||
225 |
||
226 |
// ----------------------------------------------------------------------------- |
|
227 |
// Final thumbnail bitmap generation or loading is complete. |
|
228 |
// ----------------------------------------------------------------------------- |
|
229 |
// |
|
230 |
void CMPXAlbumArtUtil::ThumbnailReady( |
|
231 |
TInt aError, MThumbnailData& aThumbnail, |
|
232 |
TThumbnailRequestId aId ) |
|
233 |
{ |
|
234 |
MPX_DEBUG2( "CMPXAlbumArtUtil::ThumbnailReady error = %d", aError); |
|
235 |
||
236 |
if (aError == KErrNone) |
|
237 |
{ |
|
238 |
CFbsBitmap* tempBitmap; |
|
239 |
tempBitmap = aThumbnail.DetachBitmap(); |
|
240 |
if (tempBitmap) |
|
241 |
{ |
|
242 |
if(iReqId == aId) |
|
243 |
{ |
|
244 |
iObserver->ExtractAlbumArtCompleted( tempBitmap, KErrNone ); |
|
245 |
} |
|
246 |
else |
|
247 |
{ |
|
248 |
delete tempBitmap; |
|
249 |
} |
|
250 |
} |
|
251 |
else if(iReqId == aId) |
|
252 |
{ |
|
253 |
iObserver->ExtractAlbumArtCompleted( NULL, KErrNotFound ); |
|
254 |
} |
|
255 |
} |
|
56
2cbbefa9af78
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
256 |
else if ( aError == KErrUnderflow || aError == KErrTimedOut || aError == KErrCompletion) |
2cbbefa9af78
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
257 |
{ |
2cbbefa9af78
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
258 |
// Abort imaging decoding |
2cbbefa9af78
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
259 |
iObserver->ExtractAlbumArtCompleted( NULL, KErrNotFound ); |
2cbbefa9af78
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
260 |
} |
53 | 261 |
else if (iArtUtil && iFilename) |
262 |
{ |
|
263 |
TRAPD( err, |
|
264 |
HBufC8* art( ExtractBinaryMetaDataLC(iFilename->Des(),EMetaDataJpeg )); |
|
265 |
CleanupStack::Pop(art); |
|
266 |
iArtUtil->StartToDecodeL(iImageSize, art, iDisplayMode) ); |
|
267 |
||
268 |
if (err != KErrNone) |
|
269 |
{ |
|
270 |
iObserver->ExtractAlbumArtCompleted( NULL, KErrNotFound ); |
|
271 |
} |
|
272 |
} |
|
56
2cbbefa9af78
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
273 |
else |
2cbbefa9af78
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
274 |
{ |
2cbbefa9af78
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
275 |
iObserver->ExtractAlbumArtCompleted( NULL, KErrNotFound ); |
2cbbefa9af78
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
276 |
} |
2cbbefa9af78
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
277 |
|
53 | 278 |
iReqId = 0; |
279 |
} |
|
280 |
||
281 |
// ----------------------------------------------------------------------------- |
|
282 |
// Extract Thumbnail for the current song |
|
283 |
// ----------------------------------------------------------------------------- |
|
284 |
// |
|
285 |
void CMPXAlbumArtUtil::ExtractThumbnailL( |
|
286 |
const CMPXMedia* aMedia) |
|
287 |
{ |
|
288 |
MPX_FUNC("CMPXAlbumArtUtil::ExtractThumbnailL"); |
|
289 |
||
290 |
TMPXItemId currentId( aMedia->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) ); |
|
291 |
if (currentId == KMPXInvalidItemId ) |
|
292 |
{ |
|
293 |
User::Leave( KErrNotFound ); |
|
294 |
} |
|
295 |
if (aMedia->IsSupported( KMPXMediaMusicAlbumArtFileName ) ) |
|
296 |
{ |
|
297 |
const TDesC& album = aMedia->ValueText( KMPXMediaMusicAlbumArtFileName ); |
|
298 |
#ifdef _DEBUG |
|
299 |
RDebug::RawPrint(album); |
|
300 |
#endif |
|
301 |
if (album.Compare( KNullDesC) != 0 ) |
|
302 |
{ |
|
303 |
CThumbnailObjectSource* source = CThumbnailObjectSource::NewLC( album, KMPXAlbumMimeType ); |
|
304 |
TInt ret = NULL; |
|
305 |
if(iThumbnailManager && iReqId >0) |
|
306 |
{ |
|
307 |
iThumbnailManager->CancelRequest( iReqId ); |
|
308 |
} |
|
309 |
if(iThumbnailManager) |
|
310 |
{ |
|
311 |
TRAPD(err, iReqId = TInt (iThumbnailManager->GetThumbnailL( *source, (TAny*)ret))); |
|
312 |
if( err != KErrNone) |
|
313 |
{ |
|
314 |
User::Leave( KErrNotFound ); |
|
315 |
} |
|
316 |
} |
|
317 |
CleanupStack::PopAndDestroy( source ); |
|
318 |
} |
|
319 |
} |
|
320 |
} |
|
321 |