|
1 /* |
|
2 * Copyright (c) 2006-2007 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: Implementation of base DLNA profile resolver class for audio |
|
15 * files. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 // system includes |
|
25 // NONE |
|
26 |
|
27 // includes |
|
28 #include <mdaaudiosampleeditor.h> // CMdaAudioConvertUtility |
|
29 #include <badesca.h> // CDesC16ArrayFlat |
|
30 #include "upnpaudiosolverbase.h" |
|
31 |
|
32 _LIT( KComponentLogfile, "dlnaprofiler.txt"); |
|
33 #include "upnplog.h" |
|
34 |
|
35 // constants |
|
36 _LIT( KTargetAudioFile, "c:\\unnecessary.txt" ); |
|
37 |
|
38 // audio mime types |
|
39 _LIT8( KAudioMpeg, "audio/mpeg" ); |
|
40 _LIT8( KAudio3gpp, "audio/3gpp" ); |
|
41 _LIT8( KAudioMp4, "audio/mp4" ); |
|
42 _LIT8( KAudioL16, "audio/L16" ); |
|
43 _LIT8( KAudioAdts, "audio/vnd.dlna.adts" ); |
|
44 _LIT8( KAudioWma, "audio/x-ms-wma" ); |
|
45 |
|
46 // audio profiles |
|
47 _LIT( KLpcm, "LPCM" ); |
|
48 _LIT( KMp3, "MP3" ); |
|
49 _LIT( KAac_iso, "AAC_ISO" ); |
|
50 _LIT( KAac_iso_320, "AAC_ISO_320" ); |
|
51 _LIT( KAac_mult5_iso, "AAC_MULT5_ISO" ); |
|
52 _LIT( KWmabase, "WMABASE" ); |
|
53 _LIT( KWmafull, "WMAFULL" ); |
|
54 _LIT( KWmapro, "WMAPRO" ); |
|
55 |
|
56 const TInt KAac_iso_320_max_bitrate = 320000; |
|
57 const TInt KAac_iso_max_samplerate = 48000; |
|
58 const TInt KAac_iso_max_bitrate = 576000; |
|
59 |
|
60 const TInt KWmabase_max_bitrate = 192999; |
|
61 const TInt KWmafull_max_bitrate = 385000; |
|
62 const TInt KWmapro_max_bitrate = 1500000; |
|
63 |
|
64 const TInt KWmabase_max_samplerate = 48000; |
|
65 const TInt KWmafull_max_samplerate = 48000; |
|
66 const TInt KWmapro_max_samplerate = 96000; |
|
67 |
|
68 const TInt KTwo_Channels = 2; |
|
69 const TInt KSix_Channels = 6; |
|
70 const TInt KEight_Channels = 8; |
|
71 |
|
72 // ======== LOCAL FUNCTIONS ======== |
|
73 // NONE |
|
74 |
|
75 // ======== MEMBER FUNCTIONS ======== |
|
76 |
|
77 // -------------------------------------------------------------------------- |
|
78 // CUpnpAudioSolverBase C++ constructor |
|
79 // -------------------------------------------------------------------------- |
|
80 // |
|
81 CUpnpAudioSolverBase::CUpnpAudioSolverBase() |
|
82 { |
|
83 __LOG( "[UPnPDlnaProfiler] CUpnpAudioSolverBase Constructor" ); |
|
84 } |
|
85 |
|
86 // -------------------------------------------------------------------------- |
|
87 // CUpnpAudioSolverBase::ConstructL |
|
88 // -------------------------------------------------------------------------- |
|
89 // |
|
90 void CUpnpAudioSolverBase::ConstructL() |
|
91 { |
|
92 __LOG( "[UPnPDlnaProfiler] CUpnpAudioSolverBase::ConstructL" ); |
|
93 iWait = new( ELeave ) CActiveSchedulerWait; |
|
94 } |
|
95 |
|
96 |
|
97 // -------------------------------------------------------------------------- |
|
98 // CUpnpAudioSolverBase::NewL |
|
99 // -------------------------------------------------------------------------- |
|
100 // |
|
101 CUpnpAudioSolverBase* CUpnpAudioSolverBase::NewL() |
|
102 { |
|
103 __LOG( "[UPnPDlnaProfiler] CUpnpAudioSolverBase::NewL" ); |
|
104 CUpnpAudioSolverBase* self = CUpnpAudioSolverBase::NewLC(); |
|
105 CleanupStack::Pop( self ); |
|
106 return self; |
|
107 } |
|
108 |
|
109 |
|
110 // -------------------------------------------------------------------------- |
|
111 // CUpnpAudioSolverBase::NewLC |
|
112 // -------------------------------------------------------------------------- |
|
113 // |
|
114 CUpnpAudioSolverBase* CUpnpAudioSolverBase::NewLC() |
|
115 { |
|
116 __LOG( "[UPnPDlnaProfiler] CUpnpAudioSolverBase::NewLC" ); |
|
117 CUpnpAudioSolverBase* self = new( ELeave ) CUpnpAudioSolverBase; |
|
118 CleanupStack::PushL( self ); |
|
119 self->ConstructL(); |
|
120 return self; |
|
121 } |
|
122 |
|
123 |
|
124 // -------------------------------------------------------------------------- |
|
125 // CUpnpAudioSolverBase destructor |
|
126 // -------------------------------------------------------------------------- |
|
127 // |
|
128 CUpnpAudioSolverBase::~CUpnpAudioSolverBase() |
|
129 { |
|
130 __LOG( "[UPnPDlnaProfiler] CUpnpAudioSolverBase::Destructor" ); |
|
131 delete iAudioconverter; |
|
132 delete iWait; |
|
133 } |
|
134 |
|
135 // -------------------------------------------------------------------------- |
|
136 // From class MUpnpProfiler. |
|
137 // SupportedProfilesL returns DLNA profiles that are currently supported. |
|
138 // -------------------------------------------------------------------------- |
|
139 // |
|
140 TInt CUpnpAudioSolverBase::SupportedProfilesL( |
|
141 CDesC16ArrayFlat* aProfiles ) const |
|
142 { |
|
143 __LOG( "[UPnPDlnaProfiler] CUpnpAudioSolverBase::\ |
|
144 SupportedProfilesL" ); |
|
145 TInt retval = KErrNone; |
|
146 |
|
147 if ( !aProfiles ) |
|
148 { |
|
149 // Invalid parameter |
|
150 retval = KErrArgument; |
|
151 } |
|
152 else |
|
153 { |
|
154 // append all new profiles recognized by this solver |
|
155 // do not allow duplicates |
|
156 TInt tempPos = KErrNotFound; |
|
157 |
|
158 if ( aProfiles->Find( KLpcm(), tempPos, ECmpFolded ) ) |
|
159 { |
|
160 aProfiles->AppendL( KLpcm() ); |
|
161 } |
|
162 if ( aProfiles->Find( KMp3(), tempPos, ECmpFolded ) ) |
|
163 { |
|
164 aProfiles->AppendL( KMp3() ); |
|
165 } |
|
166 if ( aProfiles->Find( KAac_iso(), tempPos, ECmpFolded ) ) |
|
167 { |
|
168 aProfiles->AppendL( KAac_iso() ); |
|
169 } |
|
170 if ( aProfiles->Find( KAac_iso_320(), tempPos, ECmpFolded ) ) |
|
171 { |
|
172 aProfiles->AppendL( KAac_iso_320() ); |
|
173 } |
|
174 if ( aProfiles->Find( KAac_mult5_iso(), tempPos, ECmpFolded ) ) |
|
175 { |
|
176 aProfiles->AppendL( KAac_mult5_iso() ); |
|
177 } |
|
178 if ( aProfiles->Find( KWmabase(), tempPos, ECmpFolded ) ) |
|
179 { |
|
180 aProfiles->AppendL( KWmabase() ); |
|
181 } |
|
182 if ( aProfiles->Find( KWmafull(), tempPos, ECmpFolded ) ) |
|
183 { |
|
184 aProfiles->AppendL( KWmafull() ); |
|
185 } |
|
186 if ( aProfiles->Find( KWmapro(), tempPos, ECmpFolded ) ) |
|
187 { |
|
188 aProfiles->AppendL( KWmapro() ); |
|
189 } |
|
190 } |
|
191 |
|
192 return retval; |
|
193 } |
|
194 |
|
195 // -------------------------------------------------------------------------- |
|
196 // From class MUpnpProfiler. |
|
197 // ProfileForFileL is for resolving a DLNA profile of a given file. Besides |
|
198 // of file name, also mime type of the file is passed as a parameter in |
|
199 // order to avoid re-opening the file. |
|
200 // -------------------------------------------------------------------------- |
|
201 // |
|
202 HBufC* CUpnpAudioSolverBase::ProfileForFileL( const TDesC& aFilename, |
|
203 const TDesC8& aMimetype, |
|
204 RFile& /*aFile*/ ) |
|
205 { |
|
206 __LOG( "[UPnPDlnaProfiler] CUpnpAudioSolverBase::ProfileForFileL" ); |
|
207 HBufC* retval = NULL; |
|
208 |
|
209 if ( aMimetype.Compare( KAudioMpeg() ) == 0 ) |
|
210 { |
|
211 // Note that MP3X profile is currently not supported. |
|
212 retval = HBufC::NewL( KMp3().Length() ); |
|
213 retval->Des().Append( KMp3() ); |
|
214 } |
|
215 else if ( aMimetype.Compare( KAudioMp4() ) == 0 ) |
|
216 { |
|
217 // obtain bitrate and channel count information from the file |
|
218 GetAudioFileInformationL( aFilename ); |
|
219 |
|
220 retval = DetermineMp4ProfileL(); |
|
221 } |
|
222 else if ( aMimetype.Compare( KAudio3gpp() ) == 0 ) |
|
223 { |
|
224 // obtain bitrate and channel count information from the file |
|
225 GetAudioFileInformationL( aFilename ); |
|
226 |
|
227 retval = Determine3GppProfileL(); |
|
228 } |
|
229 else if ( aMimetype.Left( KAudioL16().Length() ).Compare( |
|
230 KAudioL16() ) == 0 ) |
|
231 { |
|
232 retval = HBufC::NewL( KLpcm().Length() ); |
|
233 retval->Des().Append( KLpcm() ); |
|
234 } |
|
235 else if ( aMimetype.Compare( KAudioWma() ) == 0 ) |
|
236 { |
|
237 // obtain bitrate and channel count information from the file |
|
238 GetAudioFileInformationL( aFilename ); |
|
239 |
|
240 retval = DetermineWmaProfileL(); |
|
241 } |
|
242 else if ( aMimetype.Compare( KAudioAdts() ) == 0 ) |
|
243 { |
|
244 // no audio/vnd.dlna.adts profiles currently supported |
|
245 // obtain bitrate and channel count information from the file |
|
246 //GetAudioFileInformationL( aFilename ); |
|
247 //retval = DetermineAdtsProfileL(); |
|
248 } |
|
249 |
|
250 return retval; |
|
251 } |
|
252 |
|
253 // -------------------------------------------------------------------------- |
|
254 // From class MMdaObjectStateChangeObserver. |
|
255 // MoscoStateChangeEvent callback is called after a call to |
|
256 // CMdaAudioConvertUtility::OpenL has completed. |
|
257 // -------------------------------------------------------------------------- |
|
258 // |
|
259 void CUpnpAudioSolverBase::MoscoStateChangeEvent( CBase */*aObject*/, |
|
260 TInt /*aPreviousState*/, |
|
261 TInt /*aCurrentState*/, |
|
262 TInt aErrorCode ) |
|
263 { |
|
264 __LOG( "[UPnPDlnaProfiler] CUpnpAudioSolverBase::\ |
|
265 MoscoStateChangeEvent" ); |
|
266 if( KErrNone == aErrorCode ) |
|
267 { |
|
268 // get bit rate and channel count of the file. Trap because this |
|
269 // method may not leave. TRAP_IGNORE because there is nothing we |
|
270 // can do in case of leave. |
|
271 TRAP_IGNORE( iBitrate = iAudioconverter->SourceBitRateL() ); |
|
272 TRAP_IGNORE( iChannelCount = |
|
273 iAudioconverter->SourceNumberOfChannelsL() ); |
|
274 TRAP_IGNORE( iSampleRate = |
|
275 iAudioconverter->SourceSampleRateL() ); |
|
276 } |
|
277 |
|
278 // continue execution in ProfileForFileL-method by stopping |
|
279 // ActiveSchedulerWait |
|
280 iWait->AsyncStop(); |
|
281 } |
|
282 |
|
283 // -------------------------------------------------------------------------- |
|
284 // GetAudioFileInformationL is for resolving audio file attributes by using |
|
285 // CMdaAudioConvertUtility. |
|
286 // -------------------------------------------------------------------------- |
|
287 // |
|
288 TInt CUpnpAudioSolverBase::GetAudioFileInformationL( const TDesC& aFilename ) |
|
289 { |
|
290 __LOG( "[UPnPDlnaProfiler] CUpnpAudioSolverBase::\ |
|
291 GetAudioFileInformationL" ); |
|
292 TInt retval = KErrNone; |
|
293 |
|
294 // create audioconverter if it does not exist |
|
295 if ( !iAudioconverter ) |
|
296 { |
|
297 iAudioconverter = CMdaAudioConvertUtility::NewL( *this ); |
|
298 } |
|
299 |
|
300 // Create iWait if it does not exist. Create it here rather than after |
|
301 // OpenL-call so that there will be no problems if somehow OpenL calls |
|
302 // MoscoStateChangeEvent-callback before iWait is created and started. |
|
303 if ( !iWait ) |
|
304 { |
|
305 iWait = new( ELeave ) CActiveSchedulerWait; |
|
306 } |
|
307 |
|
308 // Open file specified in aFilename. This is an asynchronic operation. |
|
309 // Calls MoscoStateChangeEvent callback after completed. |
|
310 TMdaFileClipLocation sinkFile( KTargetAudioFile() ); |
|
311 TMdaRawAudioClipFormat sinkformat; |
|
312 iAudioconverter->OpenL( aFilename, &sinkFile, &sinkformat ); |
|
313 |
|
314 // start CActiveSchedulerWait which is completed in MoscoStateChangeEvent |
|
315 iWait->Start(); |
|
316 |
|
317 // openL + MoscoStateChangeEvent callback executed now |
|
318 delete iAudioconverter; |
|
319 iAudioconverter = NULL; |
|
320 delete iWait; |
|
321 iWait = NULL; |
|
322 |
|
323 // delete temporary file |
|
324 RFs fs; |
|
325 User::LeaveIfError( fs.Connect() ); |
|
326 User::LeaveIfError( fs.Delete( KTargetAudioFile() ) ); |
|
327 fs.Close(); |
|
328 |
|
329 return retval; |
|
330 } |
|
331 |
|
332 // -------------------------------------------------------------------------- |
|
333 // Determine3GppProfileL is for determining profile for 3gpp audio files |
|
334 // -------------------------------------------------------------------------- |
|
335 // |
|
336 HBufC* CUpnpAudioSolverBase::Determine3GppProfileL() const |
|
337 { |
|
338 __LOG( "[UPnPDlnaProfiler] CUpnpAudioSolverBase::\ |
|
339 Determine3GppProfileL" ); |
|
340 HBufC* retval = NULL; |
|
341 |
|
342 if ( iBitrate <= KAac_iso_320_max_bitrate && |
|
343 iSampleRate <= KAac_iso_max_samplerate && |
|
344 iChannelCount <= KTwo_Channels ) |
|
345 { |
|
346 retval = HBufC::NewL( KAac_iso_320().Length() ); |
|
347 retval->Des().Append( KAac_iso_320() ); |
|
348 } |
|
349 else if ( iSampleRate <= KAac_iso_max_samplerate && |
|
350 iChannelCount <= KTwo_Channels ) |
|
351 { |
|
352 retval = HBufC::NewL( KAac_iso().Length() ); |
|
353 retval->Des().Append( KAac_iso() ); |
|
354 } |
|
355 else if ( iSampleRate <= KAac_iso_max_samplerate && |
|
356 iChannelCount <= KSix_Channels ) |
|
357 { |
|
358 retval = HBufC::NewL( KAac_mult5_iso().Length() ); |
|
359 retval->Des().Append( KAac_mult5_iso() ); |
|
360 } |
|
361 |
|
362 return retval; |
|
363 } |
|
364 |
|
365 |
|
366 |
|
367 // -------------------------------------------------------------------------- |
|
368 // DetermineWmaProfileL is for determining profile for wma files |
|
369 // -------------------------------------------------------------------------- |
|
370 // |
|
371 HBufC* CUpnpAudioSolverBase::DetermineWmaProfileL() const |
|
372 { |
|
373 __LOG( "[UPnPDlnaProfiler] CUpnpAudioSolverBase::\ |
|
374 DetermineWmaProfileL" ); |
|
375 HBufC* retval = NULL; |
|
376 |
|
377 if ( iBitrate <= KWmabase_max_bitrate && |
|
378 iSampleRate <= KWmabase_max_samplerate && |
|
379 iChannelCount <= KTwo_Channels ) |
|
380 { |
|
381 retval = HBufC::NewL( KWmabase().Length() ); |
|
382 retval->Des().Append( KWmabase() ); |
|
383 } |
|
384 else if ( iBitrate <= KWmafull_max_bitrate && |
|
385 iSampleRate <= KWmafull_max_samplerate && |
|
386 iChannelCount <= KTwo_Channels ) |
|
387 { |
|
388 retval = HBufC::NewL( KWmafull().Length() ); |
|
389 retval->Des().Append( KWmafull() ); |
|
390 } |
|
391 else if ( iBitrate <= KWmapro_max_bitrate && |
|
392 iSampleRate <= KWmapro_max_samplerate && |
|
393 iChannelCount <= KEight_Channels ) |
|
394 { |
|
395 retval = HBufC::NewL( KWmapro().Length() ); |
|
396 retval->Des().Append( KWmapro() ); |
|
397 } |
|
398 |
|
399 return retval; |
|
400 } |
|
401 |
|
402 // -------------------------------------------------------------------------- |
|
403 // DetermineMp4ProfileL is for determining profile for mp4 audio files |
|
404 // -------------------------------------------------------------------------- |
|
405 // |
|
406 HBufC* CUpnpAudioSolverBase::DetermineMp4ProfileL() const |
|
407 { |
|
408 __LOG( "[UPnPDlnaProfiler] CUpnpAudioSolverBase::\ |
|
409 DetermineMp4ProfileL" ); |
|
410 HBufC* retval = NULL; |
|
411 |
|
412 if ( iBitrate <= KAac_iso_320_max_bitrate && |
|
413 iChannelCount <= KTwo_Channels ) |
|
414 { |
|
415 retval = HBufC::NewL( KAac_iso_320().Length() ); |
|
416 retval->Des().Append( KAac_iso_320() ); |
|
417 } |
|
418 else if ( iBitrate <= KAac_iso_max_bitrate && |
|
419 iChannelCount <= KTwo_Channels ) |
|
420 { |
|
421 retval = HBufC::NewL( KAac_iso().Length() ); |
|
422 retval->Des().Append( KAac_iso() ); |
|
423 } |
|
424 |
|
425 return retval; |
|
426 } |
|
427 |
|
428 |
|
429 // end of file |