|
1 /* |
|
2 * Copyright (c) 2008 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 is used for playing sounds |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <logger.h> |
|
21 |
|
22 #include "cmmaemcresolver.h" |
|
23 #include "hxmetadatautil.h" |
|
24 #include "apgcli.h" |
|
25 #include "apmrec.h" |
|
26 |
|
27 using namespace multimedia; |
|
28 |
|
29 _LIT(KRVMimeType1, "video/x-pn-realvideo"); |
|
30 _LIT(KRVMimeType2, "video/x-realvideo"); |
|
31 _LIT(KRVMimeType3, "video/vnd.rn-realvideo"); |
|
32 |
|
33 // CONSTANTS |
|
34 |
|
35 CMMAEMCResolver* CMMAEMCResolver::NewLC() |
|
36 { |
|
37 LOG( EJavaMMAPI, EInfo, "MMA:CMMAEMCResolver :: NewLC ++"); |
|
38 CMMAEMCResolver* self = new(ELeave)CMMAEMCResolver(); |
|
39 CleanupStack::PushL(self); |
|
40 LOG( EJavaMMAPI, EInfo, "MMA:CMMAEMCResolver :: NewLC --"); |
|
41 return self; |
|
42 } |
|
43 |
|
44 CMMAEMCResolver::~CMMAEMCResolver() |
|
45 { |
|
46 delete iContentType; |
|
47 |
|
48 delete iFileName; |
|
49 |
|
50 delete iMimeType; |
|
51 } |
|
52 |
|
53 HBufC* CMMAEMCResolver::ContentTypeOwnership() |
|
54 { |
|
55 LOG( EJavaMMAPI, EInfo, "MMA:CMMAEMCResolver :: ContentTypeOwnership ++"); |
|
56 HBufC* ct = iContentType; |
|
57 iContentType = NULL; |
|
58 LOG( EJavaMMAPI, EInfo, "MMA:CMMAEMCResolver :: ContentTypeOwnership --"); |
|
59 return ct; |
|
60 } |
|
61 |
|
62 HBufC8* CMMAEMCResolver::MimeTypeOwnership() |
|
63 { |
|
64 LOG( EJavaMMAPI, EInfo, "MMA:CMMAEMCResolver :: MimeTypeOwnership ++"); |
|
65 HBufC8* mt = iMimeType; |
|
66 iMimeType = NULL; |
|
67 LOG( EJavaMMAPI, EInfo, "MMA:CMMAEMCResolver :: MimeTypeOwnership --"); |
|
68 return mt; |
|
69 } |
|
70 |
|
71 HBufC* CMMAEMCResolver::ContentType() |
|
72 { |
|
73 return iContentType; |
|
74 } |
|
75 |
|
76 void CMMAEMCResolver::SetFileNameL(const TDesC* aFileName) |
|
77 { |
|
78 LOG( EJavaMMAPI, EInfo, "MMA:CMMAEMCResolver :: SetFileNameL ++"); |
|
79 HBufC* fn = NULL; |
|
80 if (aFileName) |
|
81 { |
|
82 fn = aFileName->AllocL(); |
|
83 } |
|
84 delete iFileName; |
|
85 iFileName = fn; |
|
86 LOG( EJavaMMAPI, EInfo, "MMA:CMMAEMCResolver :: SetFileNameL --"); |
|
87 } |
|
88 |
|
89 HBufC* CMMAEMCResolver::FileNameOwnership() |
|
90 { |
|
91 LOG( EJavaMMAPI, EInfo, "MMA:CMMAEMCResolver :: FileNameOwnership ++"); |
|
92 HBufC* fn = iFileName; |
|
93 iFileName = NULL; |
|
94 LOG( EJavaMMAPI, EInfo, "MMA:CMMAEMCResolver :: FileNameOwnership --"); |
|
95 return fn; |
|
96 } |
|
97 |
|
98 void CMMAEMCResolver::SetMimeTypeL(const TDesC* aFileName) |
|
99 { |
|
100 LOG( EJavaMMAPI, EInfo, "MMA:CMMAEMCResolver :: SetMimeTypeL +"); |
|
101 if (iContentType) |
|
102 { |
|
103 delete iContentType; |
|
104 iContentType = NULL; |
|
105 } |
|
106 iContentType = HBufC::NewL(KContentTypeMaxLength); |
|
107 TBuf8<KContentTypeMaxLength> mimeType; |
|
108 ResolveContentTypeL(*aFileName,mimeType); |
|
109 iContentType->Des().Copy(mimeType); |
|
110 iMimeType = HBufC8::NewL(mimeType.Length()); //8 bit Descriptor of iContentType |
|
111 iMimeType->Des().Copy(mimeType); |
|
112 |
|
113 LOG( EJavaMMAPI, EInfo, "MMA:CMMAEMCResolver :: SetMimeTypeL -"); |
|
114 } |
|
115 |
|
116 void CMMAEMCResolver::ResolveContentTypeL() |
|
117 { |
|
118 LOG( EJavaMMAPI, EInfo, "MMA:CMMAEMCResolver::ResolveContentTypeL +"); |
|
119 |
|
120 if (iContentType) |
|
121 { |
|
122 delete iContentType; |
|
123 iContentType = NULL; |
|
124 } |
|
125 if (iMimeType) |
|
126 { |
|
127 delete iMimeType; |
|
128 iMimeType = NULL; |
|
129 } |
|
130 |
|
131 iContentType = HBufC::NewL(KContentTypeMaxLength); |
|
132 iMimeType = HBufC8::NewL(KContentTypeMaxLength); |
|
133 |
|
134 if (iFileName->Right(4).Compare(KAacFileExtension()) == 0) |
|
135 { |
|
136 iContentType->Des().Copy(KMimetypeAAC); |
|
137 iMimeType->Des().Copy(KMimetypeAAC); |
|
138 } |
|
139 else if (iFileName->Right(4).Compare(KAmrFileExtension()) == 0) |
|
140 { |
|
141 iContentType->Des().Copy(KMimetypeAMR); |
|
142 iMimeType->Des().Copy(KMimetypeAMR); |
|
143 } |
|
144 else if (iFileName->Right(4).Compare(KAwbFileExtension()) == 0) |
|
145 { |
|
146 iContentType->Des().Copy(KMimetypeAMRWB); |
|
147 iMimeType->Des().Copy(KMimetypeAMRWB); |
|
148 } |
|
149 else if (iFileName->Right(4).Compare(KWmaFileExtension()) == 0) |
|
150 { |
|
151 iContentType->Des().Copy(KMimetypeXMSWMA); |
|
152 iMimeType->Des().Copy(KMimetypeXMSWMA); |
|
153 } |
|
154 else if (iFileName->Right(3).Compare(KRaFileExtension()) == 0) |
|
155 { |
|
156 iContentType->Des().Copy(KMimetypeRM); |
|
157 iMimeType->Des().Copy(KMimetypeRM); |
|
158 } |
|
159 else if (iFileName->Right(4).Compare(KMp3FileExtension()) == 0) |
|
160 { |
|
161 iContentType->Des().Copy(KMimetypeMPEG); |
|
162 iMimeType->Des().Copy(KMimetypeMPEG); |
|
163 } |
|
164 else if (iHeaderData) |
|
165 { |
|
166 RApaLsSession ls; |
|
167 TInt err; |
|
168 err = ls.Connect(); |
|
169 |
|
170 if (iFileName->Right(3).Compare(KRmFileExtension()) == 0) |
|
171 { |
|
172 TBool res = IsRealVideoTypeL(*iHeaderData); |
|
173 |
|
174 if (!res) |
|
175 { |
|
176 iContentType->Des().Copy(KMimetypeRM); |
|
177 iMimeType->Des().Copy(KMimetypeRM); |
|
178 } |
|
179 else |
|
180 { |
|
181 iContentType->Des().Copy(KNullDesC); |
|
182 iMimeType->Des().Copy(KNullDesC8); |
|
183 } |
|
184 } |
|
185 else if ((iFileName->Right(4).Compare(K3gpFileExtension()) == 0) || |
|
186 (iFileName->Right(4).Compare(KMp4FileExtension()) == 0)) |
|
187 { |
|
188 TDataRecognitionResult result; |
|
189 err = ls.RecognizeData(*iFileName, *iHeaderData, result); |
|
190 if (!err && (result.iConfidence >= CApaDataRecognizerType::EProbable)) |
|
191 { |
|
192 iContentType->Des().Copy(result.iDataType.Des8()); |
|
193 iMimeType->Des().Copy(result.iDataType.Des8()); |
|
194 } |
|
195 else |
|
196 { |
|
197 iContentType->Des().Copy(KNullDesC); |
|
198 iMimeType->Des().Copy(KNullDesC8); |
|
199 } |
|
200 } |
|
201 ls.Close(); |
|
202 } |
|
203 else |
|
204 { |
|
205 iContentType->Des().Copy(KNullDesC); |
|
206 iMimeType->Des().Copy(KNullDesC8); |
|
207 } |
|
208 |
|
209 LOG( EJavaMMAPI, EInfo, "MMA:CMMAEMCResolver::ResolveContentTypeL -"); |
|
210 } |
|
211 // |
|
212 |
|
213 void CMMAEMCResolver::ResolveContentTypeL(const TDesC& /*aFileName*/, TDes8& /*aMimeType*/) |
|
214 { |
|
215 LOG( EJavaMMAPI, EInfo, "MMA:CMMAEMCResolver :: ResolveContentTypeL"); |
|
216 } |
|
217 |
|
218 void CMMAEMCResolver::GetSupportedContentTypesL(CDesC16Array& aMimeTypeArray) |
|
219 { |
|
220 LOG( EJavaMMAPI, EInfo, "MMA:CMMAEMCResolver :: GetSupportedContentTypesL +"); |
|
221 // All supported mimetypes are taken from "MimeTypes.h" |
|
222 TBuf16<KContentTypeMaxLength> tempBuf; |
|
223 tempBuf.Copy(KMimetype3GPP); |
|
224 aMimeTypeArray.AppendL(tempBuf); |
|
225 tempBuf.Zero(); |
|
226 tempBuf.Copy(KMimetype3GPP2); |
|
227 aMimeTypeArray.AppendL(tempBuf); |
|
228 tempBuf.Zero(); |
|
229 tempBuf.Copy(KMimetypeAAC); |
|
230 aMimeTypeArray.AppendL(tempBuf); |
|
231 tempBuf.Zero(); |
|
232 tempBuf.Copy(KMimetypeAMR); |
|
233 aMimeTypeArray.AppendL(tempBuf); |
|
234 tempBuf.Zero(); |
|
235 tempBuf.Copy(KMimetypeAMRWB); |
|
236 aMimeTypeArray.AppendL(tempBuf); |
|
237 tempBuf.Zero(); |
|
238 tempBuf.Copy(KMimetypeMPEG); |
|
239 aMimeTypeArray.AppendL(tempBuf); |
|
240 tempBuf.Zero(); |
|
241 tempBuf.Copy(KMimetypeMP4); |
|
242 aMimeTypeArray.AppendL(tempBuf); |
|
243 tempBuf.Zero(); |
|
244 tempBuf.Copy(KMimetypeXMSWMA); |
|
245 aMimeTypeArray.AppendL(tempBuf); |
|
246 tempBuf.Zero(); |
|
247 tempBuf.Copy(KMimetypeRM); |
|
248 aMimeTypeArray.AppendL(tempBuf); |
|
249 LOG( EJavaMMAPI, EInfo, "MMA:CMMAEMCResolver :: GetSupportedContentTypesL -"); |
|
250 } |
|
251 |
|
252 // EMC - II |
|
253 void CMMAEMCResolver::SetSourceInfoL(const HBufC8* aHeaderData) |
|
254 { |
|
255 iHeaderData = aHeaderData; |
|
256 ResolveContentTypeL(); |
|
257 } |
|
258 |
|
259 TBool CMMAEMCResolver::IsRealVideoTypeL(const TDesC8& aHeader) |
|
260 { |
|
261 TBool result = EFalse; |
|
262 |
|
263 CHXMetaDataUtility *putil; |
|
264 putil = CHXMetaDataUtility::NewL(); |
|
265 CleanupStack::PushL(putil); |
|
266 TRAPD(err, putil->OpenDesL((TDesC8 &)aHeader)); |
|
267 ELOG1( EJavaMMAPI, "MMA:CMMAEMCResolver::IsRealVideoTypeL, err = %d", err); |
|
268 |
|
269 if (err != KErrNone) |
|
270 { |
|
271 CleanupStack::Pop(putil); |
|
272 putil->ResetL(); |
|
273 delete putil; |
|
274 return EFalse; |
|
275 } |
|
276 |
|
277 TUint count = 0; |
|
278 putil->GetMetaDataCount(count); |
|
279 |
|
280 TUint i; |
|
281 HXMetaDataKeys::EHXMetaDataId id; |
|
282 |
|
283 for (i = 0; i < count; i++) |
|
284 { |
|
285 HBufC* pDes = NULL; |
|
286 |
|
287 putil->GetMetaDataAt(i, id, pDes); |
|
288 |
|
289 if (id == HXMetaDataKeys::EHXMimeType) |
|
290 { |
|
291 if (IsRealMimeTypeSupported(*pDes)) |
|
292 { |
|
293 result = ETrue; |
|
294 } |
|
295 } |
|
296 } |
|
297 |
|
298 CleanupStack::Pop(putil); |
|
299 |
|
300 putil->ResetL(); |
|
301 delete putil; |
|
302 |
|
303 return result; |
|
304 } |
|
305 |
|
306 TBool CMMAEMCResolver::IsRealMimeTypeSupported(const TDesC& aMimeType) |
|
307 { |
|
308 TBool match = EFalse; |
|
309 |
|
310 if (!aMimeType.Compare(KRVMimeType1())) |
|
311 { |
|
312 match = ETrue; |
|
313 return match; |
|
314 } |
|
315 if (!aMimeType.Compare(KRVMimeType2())) |
|
316 { |
|
317 match = ETrue; |
|
318 return match; |
|
319 } |
|
320 if (!aMimeType.Compare(KRVMimeType3())) |
|
321 { |
|
322 match = ETrue; |
|
323 return match; |
|
324 } |
|
325 |
|
326 return match; |
|
327 } |
|
328 // |
|
329 // END OF FILE |