|
1 /* |
|
2 * Copyright (c) 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: Audio Play Controller Recognizer |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <f32file.h> // for RDebug |
|
20 #include <implementationproxy.h> |
|
21 #include "HXAudioPlayControllerRecognizer.h" |
|
22 |
|
23 #ifdef RD_RA_SUPPORT_FOR_MUSIC_PLAYER |
|
24 #include <hxmetadatakeys.h> |
|
25 #include <hxmetadatautil.h> |
|
26 _LIT(KRAVideoType, "video/"); //Moved inside Flag for build warining |
|
27 #endif |
|
28 |
|
29 const TUid KUidMimeRARecognizer = {0x10207B62}; |
|
30 |
|
31 _LIT8(KRAMimeType, "audio/x-pn-realaudio"); |
|
32 _LIT(KRAMimeType1, "audio/x-pn-realaudio"); |
|
33 _LIT(KRAMimeType2, "audio/x-realaudio"); |
|
34 _LIT(KRAMimeType3, "audio/vnd.rn-realaudio"); |
|
35 |
|
36 |
|
37 _LIT(KASFMimeType1, "audio/x-hx-wma"); |
|
38 _LIT(KASFMimeType2, "video/x-hx-wmv"); |
|
39 |
|
40 _LIT8(KASFAudioMimeType, "audio/x-ms-wma"); |
|
41 _LIT8(KASFVideoMimeType, "video/x-ms-wmv"); |
|
42 |
|
43 _LIT(KDotASF, ".asf"); |
|
44 _LIT(KDotWMA, ".wma"); |
|
45 _LIT(KDotWMV, ".wmv"); |
|
46 _LIT8(KRMFileHeader, ".RMF"); |
|
47 |
|
48 // ======== MEMBER FUNCTIONS ======== |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CHXAudioPlayControllerRecognizer::CHXAudioPlayControllerRecognizer() |
|
52 // C++ default constructor can NOT contain any code, that |
|
53 // might leave. |
|
54 // Call base constructor with the recognizer's UID and confidence level |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 CHXAudioPlayControllerRecognizer::CHXAudioPlayControllerRecognizer() |
|
58 : CApaDataRecognizerType(KUidMimeRARecognizer, CApaDataRecognizerType::EHigh) |
|
59 { |
|
60 // Set the number of data (MIME) types supported by this recognizer. |
|
61 iCountDataTypes = 1; |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CHXAudioPlayControllerRecognizer::ConstructL() |
|
66 // Symbian 2nd phase constructor can leave. |
|
67 // ----------------------------------------------------------------------------- |
|
68 |
|
69 void CHXAudioPlayControllerRecognizer::ConstructL() |
|
70 { |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CHXAudioPlayControllerRecognizer::NewL() |
|
75 // Two-phased constructor. |
|
76 // ----------------------------------------------------------------------------- |
|
77 CHXAudioPlayControllerRecognizer* CHXAudioPlayControllerRecognizer::NewL() |
|
78 { |
|
79 #ifdef _DEBUG |
|
80 RDebug::Print(_L("CHXAudioPlayControllerRecognizer::NewL")); |
|
81 #endif |
|
82 CHXAudioPlayControllerRecognizer* self = new (ELeave) CHXAudioPlayControllerRecognizer(); |
|
83 CleanupStack::PushL(self); |
|
84 self->ConstructL(); |
|
85 CleanupStack::Pop(self); |
|
86 return self; |
|
87 } |
|
88 |
|
89 // Destructor |
|
90 CHXAudioPlayControllerRecognizer::~CHXAudioPlayControllerRecognizer() |
|
91 { |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CHXAudioPlayControllerRecognizer::SupportedDataTypeL |
|
96 // Return the MimeType of the DataType depending on |
|
97 // mime type of the file |
|
98 // ----------------------------------------------------------------------------- |
|
99 |
|
100 TDataType CHXAudioPlayControllerRecognizer::SupportedDataTypeL( |
|
101 TInt aIndex ) const |
|
102 { |
|
103 #ifdef _DEBUG |
|
104 RDebug::Print(_L("CHXAudioPlayControllerRecognizer::SupportedDataTypeL [%d]"), aIndex); |
|
105 #endif |
|
106 TDataType dataType; |
|
107 switch ( aIndex ) |
|
108 { |
|
109 case 0: |
|
110 dataType = TDataType(KRAMimeType); |
|
111 break; |
|
112 default: |
|
113 User::Leave(KErrArgument); |
|
114 break; |
|
115 } |
|
116 return dataType; |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CHXAudioPlayControllerRecognizer::PreferredBufSize() |
|
121 // Return the supposed minimum buffer size we need to |
|
122 // successfully recognize the data |
|
123 // ----------------------------------------------------------------------------- |
|
124 |
|
125 TUint CHXAudioPlayControllerRecognizer::PreferredBufSize() |
|
126 { |
|
127 return 0; |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CHXAudioPlayControllerRecognizer::DoRecognizeL |
|
132 // Attempt to recognize the data |
|
133 // this recognizer only attempts to match the data and/or file suffix |
|
134 // |
|
135 // NB if the file is not recognized, this function should NOT leave : |
|
136 // it should instead set iConfidence = ENotRecognized and return |
|
137 // the function should only leave if there is an out-of-memory condition |
|
138 // ----------------------------------------------------------------------------- |
|
139 |
|
140 void CHXAudioPlayControllerRecognizer::DoRecognizeL( |
|
141 const TDesC& aName, |
|
142 const TDesC8& aBuffer ) |
|
143 { |
|
144 #ifdef _DEBUG |
|
145 RDebug::Print(_L("CHXAudioPlayControllerRecognizer::DoRecognizeL: ")); |
|
146 RDebug::RawPrint(aName); |
|
147 RDebug::Print(_L(" ")); |
|
148 #endif |
|
149 // assume match will fail |
|
150 iConfidence = CApaDataRecognizerType::ENotRecognized; |
|
151 |
|
152 // Checks for only RA files with .RMF header and files with .ASF extension |
|
153 |
|
154 if (( aBuffer.Length() >= KRMFileHeader().Length() |
|
155 && (aBuffer.Left( KRMFileHeader().Length()).CompareF(KRMFileHeader()) == 0 )) |
|
156 || aName.Right( KDotASF.iTypeLength ).CompareF(KDotASF) == 0 |
|
157 || aName.Right( KDotWMV.iTypeLength ).CompareF(KDotWMV) == 0 |
|
158 || aName.Right( KDotWMA.iTypeLength ).CompareF(KDotWMA) == 0) |
|
159 { |
|
160 #ifdef RD_RA_SUPPORT_FOR_MUSIC_PLAYER |
|
161 |
|
162 CHXMetaDataUtility *putil; |
|
163 putil = CHXMetaDataUtility::NewL(); |
|
164 CleanupStack::PushL(putil); |
|
165 RFile *pHandle = NULL; |
|
166 TRAPD(err, pHandle = FilePassedByHandleL()); |
|
167 if(pHandle) |
|
168 { |
|
169 TRAP(err,putil->OpenFileL((RFile &)*pHandle)); |
|
170 } |
|
171 else |
|
172 { |
|
173 TRAP(err,putil->OpenFileL((TDesC &)aName)); |
|
174 } |
|
175 |
|
176 if(err != KErrNone) |
|
177 { |
|
178 CleanupStack::Pop(putil); |
|
179 putil->ResetL(); |
|
180 delete putil; |
|
181 return; |
|
182 } |
|
183 |
|
184 TUint count = 0; |
|
185 putil->GetMetaDataCount(count); |
|
186 |
|
187 TUint i; |
|
188 HXMetaDataKeys::EHXMetaDataId id; |
|
189 |
|
190 for (i=0; i<count; i++) |
|
191 { |
|
192 HBufC* pDes = NULL; |
|
193 |
|
194 putil->GetMetaDataAt(i, id, pDes); |
|
195 |
|
196 if(id == HXMetaDataKeys::EHXMimeType) |
|
197 { |
|
198 |
|
199 TPtr des = pDes->Des(); |
|
200 TInt res = des.Find(KRAVideoType()); |
|
201 if(res == KErrNotFound) |
|
202 { |
|
203 if(IsRealMimeTypeSupported(*pDes)) |
|
204 { |
|
205 iDataType = TDataType(KRAMimeType); |
|
206 iConfidence = ECertain; |
|
207 } |
|
208 else if(IsASFTypeSupported(*pDes)) |
|
209 { |
|
210 iDataType = TDataType(KASFAudioMimeType); |
|
211 iConfidence = ECertain; |
|
212 } |
|
213 } |
|
214 else |
|
215 { |
|
216 if(IsASFTypeSupported(*pDes)) |
|
217 { |
|
218 iDataType = TDataType(KASFVideoMimeType); |
|
219 iConfidence = ECertain; |
|
220 } |
|
221 else |
|
222 { |
|
223 iDataType = TDataType(KNullUid); |
|
224 iConfidence = CApaDataRecognizerType::ENotRecognized; |
|
225 } |
|
226 break; |
|
227 } |
|
228 } |
|
229 |
|
230 } |
|
231 |
|
232 CleanupStack::Pop(putil); |
|
233 |
|
234 putil->ResetL(); |
|
235 delete putil; |
|
236 |
|
237 #endif // RD_RA_SUPPORT_FOR_MUSIC_PLAYER |
|
238 } |
|
239 } |
|
240 |
|
241 TBool CHXAudioPlayControllerRecognizer::IsRealMimeTypeSupported(const TDesC& aMimeType) |
|
242 { |
|
243 TBool match = false; |
|
244 |
|
245 if(!aMimeType.Compare(KRAMimeType1())) |
|
246 { |
|
247 match = true; |
|
248 return match; |
|
249 } |
|
250 if(!aMimeType.Compare(KRAMimeType2())) |
|
251 { |
|
252 match = true; |
|
253 return match; |
|
254 } |
|
255 if(!aMimeType.Compare(KRAMimeType3())) |
|
256 { |
|
257 match = true; |
|
258 return match; |
|
259 } |
|
260 |
|
261 return match; |
|
262 } |
|
263 |
|
264 |
|
265 TBool CHXAudioPlayControllerRecognizer::IsASFTypeSupported(const TDesC& aMimeType) |
|
266 { |
|
267 TBool match = false; |
|
268 |
|
269 if((aMimeType.Compare(KASFMimeType1()) == 0) || (aMimeType.Compare(KASFMimeType2()) == 0)) |
|
270 { |
|
271 match = true; |
|
272 return match; |
|
273 } |
|
274 return match; |
|
275 } |
|
276 |
|
277 |
|
278 // ----------------------------------------------------------------------------- |
|
279 // CApaDataRecognizerType* CreateRecognizerL() |
|
280 // Used to create an instance of a CApaDataRecognizerType-derived class |
|
281 // ----------------------------------------------------------------------------- |
|
282 CApaDataRecognizerType* CHXAudioPlayControllerRecognizer::CreateRecognizerL() |
|
283 { |
|
284 return new (ELeave) CHXAudioPlayControllerRecognizer (); |
|
285 } |
|
286 |
|
287 const TImplementationProxy ImplementationTable[] = |
|
288 { |
|
289 IMPLEMENTATION_PROXY_ENTRY(0x10207B63, CHXAudioPlayControllerRecognizer::CreateRecognizerL) |
|
290 }; |
|
291 |
|
292 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) |
|
293 { |
|
294 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); |
|
295 return ImplementationTable; |
|
296 } |
|
297 |
|
298 |
|
299 // End of file |