|
1 /* |
|
2 * Copyright (c) 2004 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: This class implements an 3gp metadata parser as specified in |
|
15 * www.3gpp.org (specification 3GPP TS 26.244 V6.0.0). |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <Oma2Agent.h> |
|
23 #include "MetaDataParserDcf2.h" |
|
24 #include "MetaDataParserFactory.h" |
|
25 #ifdef _DEBUG |
|
26 #include <e32svr.h> |
|
27 #endif |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS =============================== |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CMetaDataParserDcf2::CMetaDataParserDcf2 |
|
33 // C++ default constructor can NOT contain any code, that |
|
34 // might leave. |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 CMetaDataParserDcf2::CMetaDataParserDcf2() |
|
38 { |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CMetaDataParserDcf2::ConstructL |
|
43 // Symbian 2nd phase constructor can leave. |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 void CMetaDataParserDcf2::ConstructL() |
|
47 { |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CMetaDataParserDcf2::NewL |
|
52 // Two-phased constructor. |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 CMetaDataParserDcf2* CMetaDataParserDcf2::NewL() |
|
56 { |
|
57 #ifdef _DEBUG |
|
58 RDebug::Print(_L("CMetaDataParserDcf2::NewL")); |
|
59 #endif |
|
60 CMetaDataParserDcf2* self = new( ELeave ) CMetaDataParserDcf2; |
|
61 CleanupStack::PushL( self ); |
|
62 self->ConstructL(); |
|
63 CleanupStack::Pop(); |
|
64 return self; |
|
65 } |
|
66 |
|
67 // Destructor |
|
68 CMetaDataParserDcf2::~CMetaDataParserDcf2() |
|
69 { |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CMetaDataParserDcf2::ParseL |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 void CMetaDataParserDcf2::ParseL( |
|
77 const RArray<TMetaDataFieldId>& aWantedFields, |
|
78 CMetaDataFieldContainer& aContainer ) |
|
79 { |
|
80 #ifdef _DEBUG |
|
81 RDebug::Print(_L("CMetaDataParserDcf2::ParseL")); |
|
82 #endif |
|
83 iContainer = &aContainer; |
|
84 |
|
85 if ( aWantedFields.Count() == 0 ) |
|
86 { |
|
87 ReadMetaDataEntryL(ContentAccess::ETitle, EMetaDataSongTitle); |
|
88 ReadMetaDataEntryL(ContentAccess::EDescription, EMetaDataComment); |
|
89 ReadMetaDataEntryL(ContentAccess::EAuthor, EMetaDataComposer); |
|
90 ReadMetaDataEntryL(ContentAccess::EContentURI, EMetaDataUrl); |
|
91 ReadMetaDataEntryL(EPerformer, EMetaDataArtist); |
|
92 ReadMetaDataEntryL(EAlbumTitle, EMetaDataAlbum); |
|
93 ReadMetaDataEntryL(EAlbumTrack, EMetaDataAlbumTrack); |
|
94 ReadMetaDataEntryL(EContentVendor, EMetaDataVendor); |
|
95 ReadMetaDataEntryL(ECopyright, EMetaDataCopyright); |
|
96 ReadMetaDataEntryL(EGenre, EMetaDataGenre); |
|
97 ReadMetaDataEntryL(ERatingInfo, EMetaDataRating); |
|
98 ReadMetaDataEntryL(ERecordingYear, EMetaDataYear); |
|
99 ReadMetaDataEntryL(ECoverUri, EMetaDataJpeg); |
|
100 } |
|
101 else |
|
102 { |
|
103 // Look for it in the wanted field array |
|
104 TInt count( aWantedFields.Count() ); |
|
105 for ( TInt i = 0; i < count; i++ ) |
|
106 { |
|
107 switch ( aWantedFields[ i ] ) |
|
108 { |
|
109 case EMetaDataSongTitle: |
|
110 ReadMetaDataEntryL(ContentAccess::ETitle, EMetaDataSongTitle); |
|
111 break; |
|
112 case EMetaDataComment: |
|
113 ReadMetaDataEntryL(ContentAccess::EDescription, EMetaDataComment); |
|
114 break; |
|
115 case EMetaDataComposer: |
|
116 ReadMetaDataEntryL(ContentAccess::EAuthor, EMetaDataComposer); |
|
117 break; |
|
118 case EMetaDataUrl: |
|
119 ReadMetaDataEntryL(ContentAccess::EContentURI, EMetaDataUrl); |
|
120 break; |
|
121 case EMetaDataArtist: |
|
122 ReadMetaDataEntryL(EPerformer, EMetaDataArtist); |
|
123 break; |
|
124 case EMetaDataAlbum: |
|
125 ReadMetaDataEntryL(EAlbumTitle, EMetaDataAlbum); |
|
126 break; |
|
127 case EMetaDataAlbumTrack: |
|
128 ReadMetaDataEntryL(EAlbumTrack, EMetaDataAlbumTrack); |
|
129 break; |
|
130 case EMetaDataVendor: |
|
131 ReadMetaDataEntryL(EContentVendor, EMetaDataVendor); |
|
132 break; |
|
133 case EMetaDataCopyright: |
|
134 ReadMetaDataEntryL(ECopyright, EMetaDataCopyright); |
|
135 break; |
|
136 case EMetaDataGenre: |
|
137 ReadMetaDataEntryL(EGenre, EMetaDataGenre); |
|
138 break; |
|
139 case EMetaDataRating: |
|
140 ReadMetaDataEntryL(ERatingInfo, EMetaDataRating); |
|
141 break; |
|
142 case EMetaDataYear: |
|
143 ReadMetaDataEntryL(ERecordingYear, EMetaDataYear); |
|
144 break; |
|
145 case EMetaDataJpeg: |
|
146 ReadMetaDataEntryL(ECoverUri, EMetaDataJpeg); |
|
147 break; |
|
148 default: |
|
149 break; |
|
150 } |
|
151 } |
|
152 } |
|
153 |
|
154 // check if need to parse from payload |
|
155 if(aWantedFields.Count() == 0) |
|
156 { |
|
157 if ( !((CMetaDataSourceFile*)iSource)->KeyExist() ) |
|
158 { |
|
159 return; // no rights |
|
160 } |
|
161 // rights present, parse payload for more fields |
|
162 CMetaDataParser* parser = NULL; |
|
163 TInt start = 0; |
|
164 ((CMetaDataSourceFile*)iSource)->Seek(ESeekStart, start); |
|
165 parser = CMetaDataParserFactory::CreateID3ParserL(*iSource); |
|
166 if (parser == NULL) |
|
167 { |
|
168 TRAPD(err, parser = CMetaDataParserFactory::CreateMP4ParserFileL(*iSource)); |
|
169 if(err || !parser ) |
|
170 { |
|
171 return; // no valid parsers found |
|
172 } |
|
173 } |
|
174 CleanupStack::PushL(parser); |
|
175 CMetaDataFieldContainer *newContainer = CMetaDataFieldContainer::NewL(); |
|
176 CleanupStack::PushL(newContainer); |
|
177 RArray<TMetaDataFieldId> zeroWantedFields; |
|
178 CleanupClosePushL(zeroWantedFields); |
|
179 parser->ParseL(zeroWantedFields, *newContainer); |
|
180 CleanupStack::PopAndDestroy(); // zeroWantedFields |
|
181 if(newContainer->Count() == 0) |
|
182 { |
|
183 CleanupStack::PopAndDestroy(2); // newContainer, parser |
|
184 return; |
|
185 } |
|
186 for(TInt i = 0; i < newContainer->Count(); i++) |
|
187 { |
|
188 // copy extra items from new container to container |
|
189 TMetaDataFieldId newFieldId = EUnknownMetaDataField; |
|
190 TPtrC data = newContainer->At(i, newFieldId); |
|
191 TBool found = EFalse; |
|
192 for(TInt j = 0; j < iContainer->Count(); j++) |
|
193 { |
|
194 TMetaDataFieldId fieldId = EUnknownMetaDataField; |
|
195 iContainer->At(j, fieldId); |
|
196 if(newFieldId == fieldId) |
|
197 { |
|
198 // exists |
|
199 found = ETrue; |
|
200 break; |
|
201 } |
|
202 } |
|
203 if(!found) |
|
204 { |
|
205 if(newFieldId == EMetaDataJpeg) |
|
206 { |
|
207 TPtrC8 data8 = newContainer->Field8(newFieldId); |
|
208 iContainer->AppendL(newFieldId, data8); |
|
209 } |
|
210 else |
|
211 { |
|
212 iContainer->AppendL(newFieldId, data); |
|
213 } |
|
214 |
|
215 } |
|
216 } |
|
217 CleanupStack::PopAndDestroy(2); // newContainer, parser |
|
218 return; |
|
219 } |
|
220 |
|
221 if(aWantedFields.Count() <= aContainer.Count()) |
|
222 { |
|
223 return; |
|
224 } |
|
225 else // parse payload |
|
226 { |
|
227 if ( !((CMetaDataSourceFile*)iSource)->KeyExist() ) |
|
228 { |
|
229 return; // no rights |
|
230 } |
|
231 // rights present, parse payload for more fields |
|
232 CMetaDataParser* parser = NULL; |
|
233 TInt start = 0; |
|
234 ((CMetaDataSourceFile*)iSource)->Seek(ESeekStart, start); |
|
235 parser = CMetaDataParserFactory::CreateID3ParserL(*iSource); |
|
236 if (parser == NULL) |
|
237 { |
|
238 TRAPD(err, parser = CMetaDataParserFactory::CreateMP4ParserFileL(*iSource)); |
|
239 if(err || !parser ) |
|
240 { |
|
241 return; // no valid parsers found |
|
242 } |
|
243 } |
|
244 CleanupStack::PushL(parser); |
|
245 // create new wanted fields |
|
246 RArray<TMetaDataFieldId> newWantedFields; |
|
247 CleanupClosePushL(newWantedFields); |
|
248 for(TInt i = 0; i < aWantedFields.Count(); i++) |
|
249 { |
|
250 TMetaDataFieldId wantedFieldId = aWantedFields[i]; |
|
251 TBool found = EFalse; |
|
252 for(TInt j = 0; j < iContainer->Count(); j++) |
|
253 { |
|
254 TMetaDataFieldId parsedFieldId = EUnknownMetaDataField; |
|
255 iContainer->At(j, parsedFieldId); |
|
256 if(wantedFieldId == parsedFieldId) |
|
257 { |
|
258 // found wanted field id |
|
259 found = ETrue; |
|
260 break; |
|
261 } |
|
262 } |
|
263 if(!found) |
|
264 { |
|
265 newWantedFields.AppendL(wantedFieldId); |
|
266 } |
|
267 } |
|
268 if(newWantedFields.Count() != 0) |
|
269 { |
|
270 parser->ParseL(newWantedFields, *iContainer); |
|
271 } |
|
272 CleanupStack::PopAndDestroy(2); // newWantedFields, parser |
|
273 } |
|
274 } |
|
275 |
|
276 // ----------------------------------------------------------------------------- |
|
277 // CMetaDataParserDcf2::InitializeFileL |
|
278 // Symbian 2nd phase constructor can leave. |
|
279 // ----------------------------------------------------------------------------- |
|
280 // |
|
281 void CMetaDataParserDcf2::InitializeFileL(CMetaDataSource* aSource) |
|
282 { |
|
283 #ifdef _DEBUG |
|
284 RDebug::Print(_L("CMetaDataParserDcf2::InitializeFileL")); |
|
285 #endif |
|
286 iSource = aSource; |
|
287 ValidateL(); |
|
288 #ifdef _DEBUG |
|
289 RDebug::Print(_L("CMetaDataParserDcf2::InitializeFileL - Done")); |
|
290 #endif |
|
291 } |
|
292 |
|
293 // ----------------------------------------------------------------------------- |
|
294 // CMetaDataParserDcf2::ValidateL |
|
295 // ----------------------------------------------------------------------------- |
|
296 // |
|
297 TBool CMetaDataParserDcf2::ValidateL() |
|
298 { |
|
299 iExists = ETrue; |
|
300 return ETrue; |
|
301 } |
|
302 |
|
303 void CMetaDataParserDcf2::ReadMetaDataEntryL(TInt aEntryName, |
|
304 TMetaDataFieldId aFieldId) |
|
305 { |
|
306 if(aEntryName == ECoverUri) |
|
307 { |
|
308 HBufC8* pic = NULL; |
|
309 TInt err = KErrNone; |
|
310 err = ((CMetaDataSourceFile*)iSource)->GetAttributeL(aEntryName, &pic); |
|
311 if(err != KErrNone) |
|
312 { |
|
313 delete pic; |
|
314 return; |
|
315 } |
|
316 if(pic->Length() > 0) |
|
317 { |
|
318 iContainer->AppendL( aFieldId, *pic ); |
|
319 } |
|
320 delete pic; |
|
321 return; |
|
322 } |
|
323 // else |
|
324 TInt err = KErrNone; |
|
325 TBuf <256> headerValue; |
|
326 err = ((CMetaDataSourceFile*)iSource)->GetStringAttribute(aEntryName, headerValue); |
|
327 |
|
328 if(err != KErrNone) |
|
329 { |
|
330 return; |
|
331 } |
|
332 TPtrC info = StripTrailingZeroes(headerValue); |
|
333 if(info.Length() > 0) |
|
334 { |
|
335 iContainer->AppendL( aFieldId, info ); |
|
336 } |
|
337 } |
|
338 |
|
339 // End of File |