1 /* |
|
2 * Copyright (c) 2009 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: Implements the ECom plugin for HTI audio playback control |
|
15 * service. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <apgcli.h> |
|
23 #include <AudioPreference.h> |
|
24 #include <bautils.h> |
|
25 #include <e32std.h> |
|
26 #include <HtiDispatcherInterface.h> |
|
27 #include <HtiLogging.h> |
|
28 #include <pathinfo.h> |
|
29 |
|
30 #include "HtiAudioServicePlugin.h" |
|
31 |
|
32 // EXTERNAL DATA STRUCTURES |
|
33 |
|
34 // EXTERNAL FUNCTION PROTOTYPES |
|
35 |
|
36 // CONSTANTS |
|
37 const static TInt KPlayToneCmdLength = 13; |
|
38 const static TInt KPlayTone2CmdLength = 16; |
|
39 const static TInt KStopCmdLength = 1; |
|
40 const static TInt KSetVolCmdLength = 2; |
|
41 const static TInt KSetVol2CmdLength = 5; |
|
42 const static TInt KListCmdMinLength = 4; |
|
43 const static TInt KPlayDtmfCmdMinLength = 17; |
|
44 const static TInt KPlayDtmf2CmdMinLength = 20; |
|
45 const static TInt KPlayFileCmdMinLength = 21; |
|
46 const static TInt KPlayFile2CmdMinLength = 24; |
|
47 const static TInt KDurationCmdMinLength = 6; |
|
48 const static TInt KMaxVolCmdMinLength = 6; |
|
49 |
|
50 const static TInt KTUintSize = sizeof( TUint ); |
|
51 |
|
52 // MACROS |
|
53 |
|
54 // LOCAL CONSTANTS AND MACROS |
|
55 const static TUid KAudioServiceUid = { 0x10210CCB }; |
|
56 |
|
57 _LIT( KBackslash, "\\" ); |
|
58 _LIT( KRngMimeType, "application/vnd.nokia.ringing-tone" ); |
|
59 _LIT( KAudioMimeType, "audio/*" ); |
|
60 |
|
61 // NOTE: Max length for error description is defined |
|
62 // in HtiDispatcherInterface.h (currently 118). |
|
63 _LIT8( KErrorNoCmd, "ERROR: No command given" ); |
|
64 _LIT8( KErrorUnknownCmd, "ERROR: Unknown Audio Service command" ); |
|
65 _LIT8( KErrorInvalidParameters, |
|
66 "ERROR: Invalid parameter data for this command" ); |
|
67 _LIT8( KErrorInvalidPath, "ERROR: Invalid path" ); |
|
68 _LIT8( KErrorToneInitFailed, "ERROR: Tone initialization failed" ); |
|
69 _LIT8( KErrorTonePlayFailed, "ERROR: Tone playing failed" ); |
|
70 _LIT8( KErrorFileInitFailed, "ERROR: File playing initialization failed" ); |
|
71 _LIT8( KErrorFilePlayFailed, "ERROR: File playing failed" ); |
|
72 _LIT8( KErrorBusyPlaying, "ERROR: Currently busy playing" ); |
|
73 _LIT8( KErrorNothingPlaying, "ERROR: Nothing playing" ); |
|
74 _LIT8( KErrorDurationFailed, "ERROR: Duration query failed" ); |
|
75 _LIT8( KErrorMaxVolFailed, "ERROR: Max volume query failed" ); |
|
76 _LIT8( KErrorPosition, "ERROR: Invalid start or end position value" ); |
|
77 |
|
78 // MODULE DATA STRUCTURES |
|
79 |
|
80 // LOCAL FUNCTION PROTOTYPES |
|
81 |
|
82 // FORWARD DECLARATIONS |
|
83 |
|
84 // ============================= LOCAL FUNCTIONS =============================== |
|
85 |
|
86 // ============================ MEMBER FUNCTIONS =============================== |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CHtiAudioServicePlugin::CHtiAudioServicePlugin |
|
90 // C++ default constructor can NOT contain any code, that might leave. |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 CHtiAudioServicePlugin::CHtiAudioServicePlugin():iIsBusy( EFalse ), |
|
94 iIsPlaying( EFalse ), |
|
95 iCommandId( 0 ), |
|
96 iPlayCommandId( 0 ), |
|
97 iMessage( NULL ), |
|
98 iErrorCode( 0 ), |
|
99 iVolume( 0 ), |
|
100 iRepeats( 0 ), |
|
101 iTrailingSilence( 0 ), |
|
102 iDtmfLength( 0 ), |
|
103 iDtmfGapLength( 0 ), |
|
104 iStartPos( 0 ), |
|
105 iEndPos( 0 ) |
|
106 { |
|
107 } |
|
108 |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // CHtiAudioServicePlugin::ConstructL |
|
112 // Symbian 2nd phase constructor can leave. |
|
113 // ----------------------------------------------------------------------------- |
|
114 // |
|
115 void CHtiAudioServicePlugin::ConstructL() |
|
116 { |
|
117 } |
|
118 |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // CHtiAudioServicePlugin::NewL |
|
122 // Two-phased constructor. |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 CHtiAudioServicePlugin* CHtiAudioServicePlugin::NewL() |
|
126 { |
|
127 CHtiAudioServicePlugin* self = new (ELeave) CHtiAudioServicePlugin; |
|
128 CleanupStack::PushL( self ); |
|
129 self->ConstructL(); |
|
130 CleanupStack::Pop(); |
|
131 return self; |
|
132 } |
|
133 |
|
134 |
|
135 // Destructor |
|
136 CHtiAudioServicePlugin::~CHtiAudioServicePlugin() |
|
137 { |
|
138 delete iMessage; |
|
139 iMessage = NULL; |
|
140 delete iAudioPlayer; |
|
141 iAudioPlayer = NULL; |
|
142 delete iTonePlayer; |
|
143 iTonePlayer = NULL; |
|
144 } |
|
145 |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // CHtiAudioServicePlugin::ProcessMessageL |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 void CHtiAudioServicePlugin::ProcessMessageL( const TDesC8& aMessage, |
|
152 THtiMessagePriority /*aPriority*/ ) |
|
153 { |
|
154 HTI_LOG_FUNC_IN( "CHtiAudioServicePlugin::ProcessMessageL" ); |
|
155 HTI_LOG_FORMAT( "Message length = %d", aMessage.Length() ); |
|
156 |
|
157 if ( iIsBusy ) |
|
158 { |
|
159 HTI_LOG_TEXT( "Plugin is busy - leaving" ); |
|
160 User::Leave( KErrInUse ); |
|
161 } |
|
162 |
|
163 // Will be set to EFalse in the SendResponseMsg or SendErrorResponseMsg |
|
164 // methods when the response has been successfully sent and the plugin is |
|
165 // ready for next message. |
|
166 iIsBusy = ETrue; |
|
167 |
|
168 if ( aMessage.Length() < 1 ) |
|
169 { |
|
170 User::LeaveIfError( |
|
171 SendErrorResponseMsg( KErrArgument, KErrorNoCmd ) ); |
|
172 return; |
|
173 } |
|
174 |
|
175 iCommandId = aMessage[0]; |
|
176 HTI_LOG_FORMAT( "Command = %d", iCommandId ); |
|
177 TInt err = KErrNone; |
|
178 |
|
179 if ( iCommandId == ECmdListAudioFiles ) |
|
180 { |
|
181 TRAP( err, HandleListAudioFilesCmdL( aMessage ) ); |
|
182 } |
|
183 |
|
184 else if ( iCommandId == ECmdPlayFile || iCommandId == ECmdPlayFile2) |
|
185 { |
|
186 TRAP( err, HandlePlayFileCmdL( aMessage ) ); |
|
187 } |
|
188 |
|
189 else if ( iCommandId == ECmdPlayTone || iCommandId == ECmdPlayTone2) |
|
190 { |
|
191 TRAP( err, HandlePlayToneCmdL( aMessage ) ); |
|
192 } |
|
193 |
|
194 else if ( iCommandId == ECmdPlayDtmf || iCommandId == ECmdPlayDtmf2) |
|
195 { |
|
196 TRAP( err, HandlePlayDtmfCmdL( aMessage ) ); |
|
197 } |
|
198 |
|
199 else if ( iCommandId == ECmdStop ) |
|
200 { |
|
201 TRAP( err, HandleStopCmdL( aMessage ) ); |
|
202 } |
|
203 |
|
204 else if ( iCommandId == ECmdGetDuration ) |
|
205 { |
|
206 TRAP( err, HandleGetDurationCmdL( aMessage ) ); |
|
207 } |
|
208 |
|
209 else if ( iCommandId == ECmdGetMaxVol || iCommandId == ECmdGetMaxVol2) |
|
210 { |
|
211 TRAP( err, HandleGetMaxVolCmdL( aMessage ) ); |
|
212 } |
|
213 |
|
214 else if ( iCommandId == ECmdSetVol || iCommandId == ECmdSetVol2) |
|
215 { |
|
216 TRAP( err, HandleSetVolCmdL( aMessage ) ); |
|
217 } |
|
218 |
|
219 else |
|
220 { |
|
221 User::LeaveIfError( |
|
222 SendErrorResponseMsg( KErrArgument, KErrorUnknownCmd ) ); |
|
223 } |
|
224 |
|
225 if ( err != KErrNone ) |
|
226 { |
|
227 User::LeaveIfError( |
|
228 SendErrorResponseMsg( err, KNullDesC8, iCommandId ) ); |
|
229 } |
|
230 |
|
231 HTI_LOG_FUNC_OUT( "CHtiAudioServicePlugin::ProcessMessageL" ); |
|
232 } |
|
233 |
|
234 |
|
235 // ----------------------------------------------------------------------------- |
|
236 // CHtiAudioServicePlugin::HandleListAudioFilesCmdL() |
|
237 // ----------------------------------------------------------------------------- |
|
238 // |
|
239 void CHtiAudioServicePlugin::HandleListAudioFilesCmdL( const TDesC8& aMessage ) |
|
240 { |
|
241 HTI_LOG_FUNC_IN( "CHtiAudioServicePlugin::HandleListAudioFilesCmdL" ); |
|
242 |
|
243 RFs fsSession; |
|
244 User::LeaveIfError( fsSession.Connect() ); |
|
245 CleanupClosePushL( fsSession ); |
|
246 |
|
247 // Build a list of directories to scan |
|
248 CDesCArraySeg* directories = new (ELeave) CDesCArraySeg( 5 ); |
|
249 CleanupStack::PushL( directories ); |
|
250 |
|
251 if ( aMessage.Length() == 1 ) // Add default sound directories |
|
252 { |
|
253 TFileName directory; |
|
254 |
|
255 // ROM |
|
256 directory.Append( PathInfo::RomRootPath() ); |
|
257 directory.Append( PathInfo::SoundsPath() ); |
|
258 if ( BaflUtils::PathExists( fsSession, directory ) ) |
|
259 { |
|
260 directories->AppendL( directory ); |
|
261 AddSubdirsRecursivelyL( directories->MdcaPoint( |
|
262 directories->Count() - 1 ), *directories, fsSession ); |
|
263 } |
|
264 |
|
265 // Phone memory |
|
266 directory.Zero(); |
|
267 directory.Append( PathInfo::PhoneMemoryRootPath() ); |
|
268 directory.Append( PathInfo::SoundsPath() ); |
|
269 if ( BaflUtils::PathExists( fsSession, directory ) ) |
|
270 { |
|
271 directories->AppendL( directory ); |
|
272 AddSubdirsRecursivelyL( directories->MdcaPoint( |
|
273 directories->Count() - 1 ), *directories, fsSession ); |
|
274 } |
|
275 |
|
276 // Memory card |
|
277 directory.Zero(); |
|
278 directory.Append( PathInfo::MemoryCardRootPath() ); |
|
279 directory.Append( PathInfo::SoundsPath() ); |
|
280 if ( BaflUtils::PathExists( fsSession, directory ) ) |
|
281 { |
|
282 directories->AppendL( directory ); |
|
283 AddSubdirsRecursivelyL( directories->MdcaPoint( |
|
284 directories->Count() - 1 ), *directories, fsSession ); |
|
285 } |
|
286 } |
|
287 |
|
288 else // Add given directory |
|
289 { |
|
290 if ( aMessage.Length() < KListCmdMinLength ) |
|
291 { |
|
292 User::LeaveIfError( SendErrorResponseMsg( |
|
293 KErrArgument, KErrorInvalidParameters ) ); |
|
294 CleanupStack::PopAndDestroy( 2 ); // directories, fsSession |
|
295 return; |
|
296 } |
|
297 |
|
298 TInt pathLength = aMessage[1]; |
|
299 if ( ( aMessage.Length() - pathLength ) != KListCmdMinLength - 2 ) |
|
300 { |
|
301 User::LeaveIfError( SendErrorResponseMsg( |
|
302 KErrArgument, KErrorInvalidParameters ) ); |
|
303 CleanupStack::PopAndDestroy( 2 ); // directories, fsSession |
|
304 return; |
|
305 } |
|
306 |
|
307 TFileName directory; |
|
308 TInt nextOffset = ParseString( aMessage, 1, directory ); |
|
309 TInt dirLength = directory.Length(); |
|
310 if ( dirLength < 2 || nextOffset < 0 ) |
|
311 { |
|
312 User::LeaveIfError( SendErrorResponseMsg( |
|
313 KErrArgument, KErrorInvalidParameters ) ); |
|
314 CleanupStack::PopAndDestroy( 2 ); // directories, fsSession |
|
315 return; |
|
316 } |
|
317 |
|
318 HTI_LOG_DES( directory ); |
|
319 |
|
320 if ( directory[dirLength - 1] != '\\' ) |
|
321 { |
|
322 HTI_LOG_TEXT( "Adding backslash to the end" ); |
|
323 directory.Append( KBackslash ); |
|
324 HTI_LOG_DES( directory ); |
|
325 } |
|
326 |
|
327 if ( BaflUtils::PathExists( fsSession, directory ) ) |
|
328 { |
|
329 HTI_LOG_TEXT( "Given path exists" ); |
|
330 directories->AppendL( directory ); |
|
331 AddSubdirsRecursivelyL( directories->MdcaPoint( |
|
332 directories->Count() - 1 ), *directories, fsSession ); |
|
333 } |
|
334 } |
|
335 |
|
336 // Buffer for the file list that is returned |
|
337 CBufFlat* fileListBuf = CBufFlat::NewL( 256 ); |
|
338 CleanupStack::PushL( fileListBuf ); |
|
339 TInt bufPos = 0; |
|
340 |
|
341 TInt audioFileCount = 0; |
|
342 TInt dirCount( directories->Count() ); |
|
343 HTI_LOG_FORMAT( "Total directory count = %d", dirCount ); |
|
344 |
|
345 if ( dirCount == 0 ) |
|
346 { |
|
347 HTI_LOG_TEXT( "The given directory did not exist" ); |
|
348 User::LeaveIfError( SendErrorResponseMsg( |
|
349 KErrArgument, KErrorInvalidPath ) ); |
|
350 CleanupStack::PopAndDestroy( 3 ); // fileListBuf, directories, fsSession |
|
351 return; |
|
352 } |
|
353 |
|
354 // Loop all the directories |
|
355 for ( TInt i = 0; i < dirCount; i++ ) |
|
356 { |
|
357 HTI_LOG_TEXT( "Reading dir:" ); |
|
358 HTI_LOG_DES( directories->MdcaPoint( i ) ); |
|
359 CDir* dir; |
|
360 TInt err = fsSession.GetDir( directories->MdcaPoint( i ), |
|
361 KEntryAttNormal, ESortNone, dir ); |
|
362 if ( err ) |
|
363 { |
|
364 delete dir; |
|
365 dir = NULL; |
|
366 continue; // This dir is skipped |
|
367 } |
|
368 CleanupStack::PushL( dir ); |
|
369 |
|
370 // Loop all the entries in this directory |
|
371 TInt fileCount( dir->Count() ); |
|
372 for ( TInt j = 0; j < fileCount; j++ ) |
|
373 { |
|
374 TFileName filePath; |
|
375 filePath.Copy( directories->MdcaPoint( i ) ); |
|
376 filePath.Append( ( *dir )[j].iName ); |
|
377 |
|
378 // Check MIME type match |
|
379 if ( MatchMimeTypeL( filePath, KAudioMimeType ) || |
|
380 MatchMimeTypeL( filePath, KRngMimeType ) ) |
|
381 { |
|
382 HBufC8* filePathBuf8 = HBufC8::NewLC( KMaxFileName ); |
|
383 filePathBuf8->Des().Copy( filePath ); |
|
384 TInt pathLength = filePathBuf8->Length(); |
|
385 HTI_LOG_DES( *filePathBuf8 ); |
|
386 fileListBuf->ExpandL( bufPos, pathLength + 1 ); |
|
387 TBuf8<1> lengthBuf; |
|
388 lengthBuf.Append( pathLength ); |
|
389 fileListBuf->Write( bufPos, lengthBuf, 1 ); |
|
390 bufPos++; |
|
391 fileListBuf->Write( bufPos, filePathBuf8->Ptr(), pathLength ); |
|
392 bufPos += pathLength; |
|
393 CleanupStack::PopAndDestroy(); // filePathBuf8 |
|
394 audioFileCount++; |
|
395 } |
|
396 |
|
397 } // files loop |
|
398 CleanupStack::PopAndDestroy(); // dir |
|
399 } // directories loop |
|
400 |
|
401 HTI_LOG_FORMAT( "Total audio file count = %d", audioFileCount ); |
|
402 |
|
403 // All files added - write number of files to the beginning of buffer... |
|
404 TBuf8<2> countBuf; |
|
405 countBuf.Append( (TUint8*)(&audioFileCount), 2 ); |
|
406 fileListBuf->InsertL( 0, countBuf, 2 ); |
|
407 |
|
408 // ...and send it away |
|
409 TPtr8 ptr = fileListBuf->Ptr( 0 ); |
|
410 User::LeaveIfError( SendResponseMsg( ptr ) ); |
|
411 |
|
412 CleanupStack::PopAndDestroy( 3 ); // fileListBuf, directories, fsSession |
|
413 |
|
414 HTI_LOG_FUNC_OUT( "CHtiAudioServicePlugin::HandleListAudioFilesCmdL" ); |
|
415 } |
|
416 |
|
417 |
|
418 // ----------------------------------------------------------------------------- |
|
419 // CHtiAudioServicePlugin::HandlePlayFileCmdL() |
|
420 // ----------------------------------------------------------------------------- |
|
421 // |
|
422 void CHtiAudioServicePlugin::HandlePlayFileCmdL( const TDesC8&aMessage ) |
|
423 { |
|
424 HTI_LOG_FUNC_IN( "CHtiAudioServicePlugin::HandlePlayFileCmdL" ); |
|
425 |
|
426 if ( iIsPlaying ) |
|
427 { |
|
428 User::LeaveIfError( SendErrorResponseMsg( |
|
429 KErrInUse, KErrorBusyPlaying ) ); |
|
430 return; |
|
431 } |
|
432 |
|
433 iPlayCommandId = (TUint8) aMessage[0]; |
|
434 |
|
435 /* |
|
436 Message bytes: |
|
437 0 = command code |
|
438 1 = path length |
|
439 2 - n = full path to file |
|
440 next 1 or 4 = volume |
|
441 next 4 = start position |
|
442 next 4 = end position |
|
443 next 1 = repeats |
|
444 next 4 = silence between repeats |
|
445 next 1 = audio setting |
|
446 */ |
|
447 |
|
448 if ( aMessage.Length() < KPlayFileCmdMinLength ) |
|
449 { |
|
450 User::LeaveIfError( SendErrorResponseMsg( |
|
451 KErrArgument, KErrorInvalidParameters ) ); |
|
452 return; |
|
453 } |
|
454 |
|
455 // Parse parameter values from the message |
|
456 const TUint8* ptr = aMessage.Ptr(); |
|
457 TInt pathLength = aMessage[1]; |
|
458 |
|
459 if ( (iPlayCommandId == ECmdPlayFile && |
|
460 ( aMessage.Length() - pathLength ) != ( KPlayFileCmdMinLength - 4 )) |
|
461 || (iPlayCommandId == ECmdPlayFile2 && |
|
462 ( aMessage.Length() - pathLength ) != ( KPlayFile2CmdMinLength - 4 ))) |
|
463 { |
|
464 User::LeaveIfError( SendErrorResponseMsg( |
|
465 KErrArgument, KErrorInvalidParameters ) ); |
|
466 return; |
|
467 } |
|
468 |
|
469 TFileName filePath; |
|
470 TInt nextOffset = ParseString( aMessage, 1, filePath ); |
|
471 if ( filePath.Length() < 2 || nextOffset < 0 ) |
|
472 { |
|
473 User::LeaveIfError( SendErrorResponseMsg( |
|
474 KErrArgument, KErrorInvalidParameters ) ); |
|
475 return; |
|
476 } |
|
477 HTI_LOG_TEXT( "Full file path:" ); |
|
478 HTI_LOG_DES( filePath ); |
|
479 if(iPlayCommandId == ECmdPlayFile) |
|
480 { |
|
481 iVolume = aMessage[nextOffset]; |
|
482 nextOffset++; |
|
483 } |
|
484 else |
|
485 { |
|
486 iVolume = ParseUint32( ptr + nextOffset ); |
|
487 nextOffset += 4; |
|
488 } |
|
489 HTI_LOG_FORMAT( "Volume = %d", iVolume ); |
|
490 iStartPos = ParseUint32( ptr + nextOffset ); |
|
491 HTI_LOG_FORMAT( "Start position = %d", iStartPos ); |
|
492 nextOffset += 4; |
|
493 iEndPos = ParseUint32( ptr + nextOffset ); |
|
494 HTI_LOG_FORMAT( "End position = %d", iEndPos ); |
|
495 nextOffset += 4; |
|
496 iRepeats = aMessage[nextOffset]; |
|
497 nextOffset++; |
|
498 HTI_LOG_FORMAT( "Repeats = %d", iRepeats ); |
|
499 iTrailingSilence = ParseUint32( ptr + nextOffset ); |
|
500 HTI_LOG_FORMAT( "Trailing silence = %d", iTrailingSilence ); |
|
501 nextOffset += 4; |
|
502 TInt audioSetting = aMessage[nextOffset]; |
|
503 HTI_LOG_FORMAT( "Audio setting = %d", audioSetting ); |
|
504 |
|
505 // Set audio settings |
|
506 if ( audioSetting > ERingTonePreview ) audioSetting = EDefault; |
|
507 SetAudioSettings( ( TAudioSetting ) audioSetting ); |
|
508 |
|
509 // Check if file is rng ringtone, it has to be played using tone player - |
|
510 // other formats are played with audio player. |
|
511 |
|
512 TInt err = KErrNone; |
|
513 TBool isRng = EFalse; |
|
514 TRAP( err, isRng = MatchMimeTypeL( filePath, KRngMimeType ) ); |
|
515 |
|
516 if ( err ) |
|
517 { |
|
518 User::LeaveIfError( SendErrorResponseMsg( err, KErrorFileInitFailed ) ); |
|
519 return; |
|
520 } |
|
521 |
|
522 if ( isRng ) |
|
523 { |
|
524 HTI_LOG_TEXT( "File is RNG - creating tone player" ); |
|
525 TRAP( err, iTonePlayer = CMdaAudioToneUtility::NewL( |
|
526 *this, NULL, iAudioPriority, iAudioPriorityPreference ) ); |
|
527 } |
|
528 |
|
529 else |
|
530 { |
|
531 HTI_LOG_TEXT( "File is not RNG - creating audio player" ); |
|
532 TRAP( err, iAudioPlayer = CMdaAudioPlayerUtility::NewFilePlayerL( |
|
533 filePath, *this, iAudioPriority, iAudioPriorityPreference ) ); |
|
534 // MapcInitComplete callback function will be called |
|
535 } |
|
536 |
|
537 if ( err ) |
|
538 { |
|
539 delete iAudioPlayer; |
|
540 iAudioPlayer = NULL; |
|
541 delete iTonePlayer; |
|
542 iTonePlayer = NULL; |
|
543 User::LeaveIfError( SendErrorResponseMsg( |
|
544 err, KErrorFileInitFailed ) ); |
|
545 } |
|
546 |
|
547 if ( iTonePlayer ) |
|
548 { |
|
549 iTonePlayer->PrepareToPlayFileSequence( filePath ); |
|
550 // MatoPrepareComplete callback function will be called |
|
551 } |
|
552 |
|
553 HTI_LOG_FUNC_OUT( "CHtiAudioServicePlugin::HandlePlayFileCmdL" ); |
|
554 } |
|
555 |
|
556 |
|
557 // ----------------------------------------------------------------------------- |
|
558 // CHtiAudioServicePlugin::HandlePlayToneCmdL() |
|
559 // ----------------------------------------------------------------------------- |
|
560 // |
|
561 void CHtiAudioServicePlugin::HandlePlayToneCmdL( const TDesC8& aMessage ) |
|
562 { |
|
563 HTI_LOG_FUNC_IN( "CHtiAudioServicePlugin::HandlePlayToneCmdL" ); |
|
564 |
|
565 if ( iIsPlaying ) |
|
566 { |
|
567 User::LeaveIfError( SendErrorResponseMsg( |
|
568 KErrInUse, KErrorBusyPlaying ) ); |
|
569 return; |
|
570 } |
|
571 |
|
572 iPlayCommandId = (TUint8)aMessage[0]; |
|
573 |
|
574 /* |
|
575 Message bytes(ECmdPlayTone): |
|
576 0 = command code |
|
577 1 - 2 = frequency value |
|
578 3 - 6 = duration value |
|
579 7 = volume value |
|
580 8 = repeat value |
|
581 9 - 12 = silence between repeats |
|
582 |
|
583 Message bytes(ECmdPlayTone2): |
|
584 0 = command code |
|
585 1 - 2 = frequency value |
|
586 3 - 6 = duration value |
|
587 7 - 10 = volume value |
|
588 11 = repeat value |
|
589 12- 15 = silence between repeats |
|
590 */ |
|
591 |
|
592 if ( (iPlayCommandId == ECmdPlayTone && aMessage.Length() != KPlayToneCmdLength) |
|
593 || (iPlayCommandId == ECmdPlayTone2 && aMessage.Length() != KPlayTone2CmdLength)) |
|
594 { |
|
595 User::LeaveIfError( SendErrorResponseMsg( |
|
596 KErrArgument, KErrorInvalidParameters ) ); |
|
597 return; |
|
598 } |
|
599 |
|
600 // Parse parameter values from the message |
|
601 const TUint8* ptr = aMessage.Ptr(); |
|
602 TInt nextOffset = 1; |
|
603 TInt frequency = ParseUint16( ptr + nextOffset ); |
|
604 HTI_LOG_FORMAT( "Freq = %d", frequency ); |
|
605 nextOffset += 2; |
|
606 TUint duration = ParseUint32( ptr + 3 ); |
|
607 HTI_LOG_FORMAT( "Duration = %d", duration ); |
|
608 nextOffset += 4; |
|
609 if(iPlayCommandId == ECmdPlayTone) |
|
610 { |
|
611 iVolume = aMessage[nextOffset]; |
|
612 nextOffset++; |
|
613 } |
|
614 else |
|
615 { |
|
616 iVolume = ParseUint32( ptr + nextOffset ); |
|
617 nextOffset += 4; |
|
618 } |
|
619 HTI_LOG_FORMAT( "Volume = %d", iVolume ); |
|
620 iRepeats = aMessage[nextOffset]; |
|
621 nextOffset++; |
|
622 HTI_LOG_FORMAT( "Repeats = %d", iRepeats ); |
|
623 iTrailingSilence = ParseUint32( ptr + nextOffset ); |
|
624 nextOffset +=4; |
|
625 HTI_LOG_FORMAT( "Silence = %d", iTrailingSilence ); |
|
626 |
|
627 TRAPD( err, iTonePlayer = CMdaAudioToneUtility::NewL( *this ) ); |
|
628 |
|
629 if ( err ) |
|
630 { |
|
631 delete iTonePlayer; |
|
632 iTonePlayer = NULL; |
|
633 User::LeaveIfError( SendErrorResponseMsg( |
|
634 err, KErrorToneInitFailed ) ); |
|
635 } |
|
636 |
|
637 iTonePlayer->PrepareToPlayTone( frequency, |
|
638 TTimeIntervalMicroSeconds( duration ) ); |
|
639 // MatoPrepareComplete callback function will be called when ready to play |
|
640 HTI_LOG_FUNC_OUT( "CHtiAudioServicePlugin::HandlePlayToneCmdL" ); |
|
641 } |
|
642 |
|
643 |
|
644 // ----------------------------------------------------------------------------- |
|
645 // CHtiAudioServicePlugin::HandlePlayDtmfCmdL() |
|
646 // ----------------------------------------------------------------------------- |
|
647 // |
|
648 void CHtiAudioServicePlugin::HandlePlayDtmfCmdL( const TDesC8& aMessage ) |
|
649 { |
|
650 HTI_LOG_FUNC_IN( "CHtiAudioServicePlugin::HandlePlayDtmfCmdL" ); |
|
651 |
|
652 if ( iIsPlaying ) |
|
653 { |
|
654 User::LeaveIfError( SendErrorResponseMsg( |
|
655 KErrInUse, KErrorBusyPlaying ) ); |
|
656 return; |
|
657 } |
|
658 |
|
659 iPlayCommandId = (TUint8)aMessage[0]; |
|
660 |
|
661 /* |
|
662 Message bytes: |
|
663 0 = command code |
|
664 1 = DTMF string length |
|
665 2 - n = dtmf string |
|
666 next 4 = tone length |
|
667 next 4 = tone gap length |
|
668 next 1 or 4 = volume |
|
669 next 1 = repeats |
|
670 next 4 = silence between repeats |
|
671 */ |
|
672 |
|
673 if ( (iPlayCommandId == ECmdPlayDtmf && aMessage.Length() < KPlayDtmfCmdMinLength ) |
|
674 || (iPlayCommandId == ECmdPlayDtmf2 && aMessage.Length() < KPlayDtmf2CmdMinLength )) |
|
675 { |
|
676 User::LeaveIfError( SendErrorResponseMsg( |
|
677 KErrArgument, KErrorInvalidParameters ) ); |
|
678 return; |
|
679 } |
|
680 |
|
681 // Parse parameter values from the message |
|
682 const TUint8* ptr = aMessage.Ptr(); |
|
683 TInt stringLength = aMessage[1]; |
|
684 |
|
685 if ( (iPlayCommandId == ECmdPlayDtmf && ( aMessage.Length() - stringLength ) != |
|
686 ( KPlayDtmfCmdMinLength - 1 )) |
|
687 || (iPlayCommandId == ECmdPlayDtmf2 && ( aMessage.Length() - stringLength ) != |
|
688 ( KPlayDtmf2CmdMinLength - 1 ))) |
|
689 { |
|
690 User::LeaveIfError( SendErrorResponseMsg( |
|
691 KErrArgument, KErrorInvalidParameters ) ); |
|
692 return; |
|
693 } |
|
694 |
|
695 TBuf<255> dtmfString; |
|
696 TInt nextOffset = ParseString( aMessage, 1, dtmfString ); |
|
697 if ( dtmfString.Length() < 1 || nextOffset < 0 ) |
|
698 { |
|
699 User::LeaveIfError( SendErrorResponseMsg( |
|
700 KErrArgument, KErrorInvalidParameters ) ); |
|
701 return; |
|
702 } |
|
703 HTI_LOG_TEXT( "DTMF string:" ); |
|
704 HTI_LOG_DES( dtmfString ); |
|
705 iDtmfLength = ParseUint32( ptr + nextOffset ); |
|
706 nextOffset += 4; |
|
707 HTI_LOG_FORMAT( "DTMF length = %d", iDtmfLength ); |
|
708 iDtmfGapLength = ParseUint32( ptr + nextOffset ); |
|
709 nextOffset += 4; |
|
710 HTI_LOG_FORMAT( "DTMF gap length = %d", iDtmfGapLength ); |
|
711 if(iPlayCommandId == ECmdPlayDtmf) |
|
712 { |
|
713 iVolume = aMessage[nextOffset]; |
|
714 nextOffset++; |
|
715 } |
|
716 else |
|
717 { |
|
718 iVolume = ParseUint32( ptr + nextOffset ); |
|
719 nextOffset += 4; |
|
720 } |
|
721 HTI_LOG_FORMAT( "Volume = %d", iVolume ); |
|
722 iRepeats = aMessage[nextOffset]; |
|
723 nextOffset++; |
|
724 HTI_LOG_FORMAT( "Repeats = %d", iRepeats ); |
|
725 iTrailingSilence = ParseUint32( ptr + nextOffset ); |
|
726 HTI_LOG_FORMAT( "Trailing silence = %d", iTrailingSilence ); |
|
727 |
|
728 SetAudioSettings( EDtmfString ); |
|
729 |
|
730 TRAPD( err, iTonePlayer = CMdaAudioToneUtility::NewL( |
|
731 *this, NULL, iAudioPriority, iAudioPriorityPreference ) ); |
|
732 |
|
733 if ( err ) |
|
734 { |
|
735 delete iTonePlayer; |
|
736 iTonePlayer = NULL; |
|
737 User::LeaveIfError( SendErrorResponseMsg( err, KErrorToneInitFailed ) ); |
|
738 } |
|
739 |
|
740 iTonePlayer->PrepareToPlayDTMFString( dtmfString ); |
|
741 // MatoPrepareComplete callback function will be called when ready to play |
|
742 HTI_LOG_FUNC_OUT( "CHtiAudioServicePlugin::HandlePlayDtmfCmdL" ); |
|
743 } |
|
744 |
|
745 |
|
746 // ----------------------------------------------------------------------------- |
|
747 // CHtiAudioServicePlugin::HandleStopCmdL() |
|
748 // ----------------------------------------------------------------------------- |
|
749 // |
|
750 void CHtiAudioServicePlugin::HandleStopCmdL( const TDesC8& aMessage ) |
|
751 { |
|
752 HTI_LOG_FUNC_IN( "CHtiAudioServicePlugin::HandleStopCmdL" ); |
|
753 |
|
754 if ( aMessage.Length() != KStopCmdLength ) |
|
755 { |
|
756 User::LeaveIfError( SendErrorResponseMsg( |
|
757 KErrArgument, KErrorInvalidParameters ) ); |
|
758 return; |
|
759 } |
|
760 |
|
761 if ( !iIsPlaying ) |
|
762 { |
|
763 HTI_LOG_TEXT( "Not playing - nothing to stop" ); |
|
764 // Just send "OK" reply if nothing is currently playing |
|
765 User::LeaveIfError( SendResponseMsg( _L8( "OK" ) ) ); |
|
766 } |
|
767 |
|
768 else |
|
769 { |
|
770 if ( iAudioPlayer ) |
|
771 { |
|
772 HTI_LOG_TEXT( "Stopping audio player" ); |
|
773 iAudioPlayer->Stop(); |
|
774 iIsPlaying = EFalse; |
|
775 delete iAudioPlayer; |
|
776 iAudioPlayer = NULL; |
|
777 // According to documentation should call MapcPlayComplete callback |
|
778 // method but it doesn't, so sending reply here. |
|
779 User::LeaveIfError( SendResponseMsg( _L8( "OK" ) ) ); |
|
780 } |
|
781 |
|
782 else if ( iTonePlayer ) |
|
783 { |
|
784 HTI_LOG_TEXT( "Stopping tone player" ); |
|
785 iTonePlayer->CancelPlay(); |
|
786 iIsPlaying = EFalse; |
|
787 delete iTonePlayer; |
|
788 iTonePlayer = NULL; |
|
789 // Callback method MatoPlayComplete is not called - |
|
790 // sending reply here. |
|
791 User::LeaveIfError( SendResponseMsg( _L8( "OK" ) ) ); |
|
792 } |
|
793 } |
|
794 HTI_LOG_FUNC_OUT( "CHtiAudioServicePlugin::HandleStopCmdL" ); |
|
795 } |
|
796 |
|
797 |
|
798 // ----------------------------------------------------------------------------- |
|
799 // CHtiAudioServicePlugin::HandleGetDurationCmdL() |
|
800 // ----------------------------------------------------------------------------- |
|
801 // |
|
802 void CHtiAudioServicePlugin::HandleGetDurationCmdL( const TDesC8& aMessage ) |
|
803 { |
|
804 HTI_LOG_FUNC_IN( "CHtiAudioServicePlugin::HandleGetDurationCmdL" ); |
|
805 |
|
806 if ( iIsPlaying ) |
|
807 { |
|
808 // If currently playing, no parameters allowed. Returns the duration |
|
809 // of currently playing sound. |
|
810 if ( aMessage.Length() != 1 ) |
|
811 { |
|
812 User::LeaveIfError( SendErrorResponseMsg( |
|
813 KErrInUse, KErrorBusyPlaying ) ); |
|
814 return; |
|
815 } |
|
816 |
|
817 if ( iAudioPlayer ) |
|
818 { |
|
819 TTimeIntervalMicroSeconds durationValue = |
|
820 iAudioPlayer->Duration(); |
|
821 |
|
822 if ( I64HIGH( durationValue.Int64() ) > 0 ) |
|
823 { |
|
824 User::LeaveIfError( SendErrorResponseMsg( |
|
825 KErrOverflow, KErrorDurationFailed ) ); |
|
826 return; |
|
827 } |
|
828 else |
|
829 { |
|
830 TUint duration = I64LOW( durationValue.Int64() ); |
|
831 TBuf8<KTUintSize> durationBuf; |
|
832 durationBuf.Append( (TUint8*)(&duration), KTUintSize ); |
|
833 User::LeaveIfError( SendResponseMsg( durationBuf ) ); |
|
834 return; |
|
835 } |
|
836 } |
|
837 |
|
838 else // Duration supported only for audio player |
|
839 { |
|
840 User::LeaveIfError( SendErrorResponseMsg( |
|
841 KErrNotSupported, KErrorDurationFailed ) ); |
|
842 return; |
|
843 } |
|
844 } |
|
845 |
|
846 /* Command must have file path parameter if not currently playing. |
|
847 Message bytes: |
|
848 0 = command code |
|
849 1 = path length |
|
850 2 - n = full path to file |
|
851 */ |
|
852 |
|
853 if ( aMessage.Length() < KDurationCmdMinLength ) |
|
854 { |
|
855 User::LeaveIfError( SendErrorResponseMsg( |
|
856 KErrArgument, KErrorInvalidParameters ) ); |
|
857 return; |
|
858 } |
|
859 |
|
860 TInt pathLength = aMessage[1]; |
|
861 if ( ( aMessage.Length() - pathLength ) != |
|
862 ( KDurationCmdMinLength - 4 ) ) |
|
863 { |
|
864 User::LeaveIfError( SendErrorResponseMsg( |
|
865 KErrArgument, KErrorInvalidParameters ) ); |
|
866 return; |
|
867 } |
|
868 |
|
869 // Parse parameter values from the message |
|
870 TFileName filePath; |
|
871 TInt nextOffset = ParseString( aMessage, 1, filePath ); |
|
872 if ( filePath.Length() < 2 || nextOffset < 0 ) |
|
873 { |
|
874 User::LeaveIfError( SendErrorResponseMsg( |
|
875 KErrArgument, KErrorInvalidParameters ) ); |
|
876 return; |
|
877 } |
|
878 HTI_LOG_TEXT( "Full file path:" ); |
|
879 HTI_LOG_DES( filePath ); |
|
880 |
|
881 TRAPD( err, iAudioPlayer = CMdaAudioPlayerUtility::NewFilePlayerL( |
|
882 filePath, *this ) ); |
|
883 if ( err ) |
|
884 { |
|
885 delete iAudioPlayer; |
|
886 iAudioPlayer = NULL; |
|
887 User::LeaveIfError( SendErrorResponseMsg( err, KErrorDurationFailed ) ); |
|
888 } |
|
889 |
|
890 // MapcInitComplete callback function will be called |
|
891 HTI_LOG_FUNC_OUT( "CHtiAudioServicePlugin::HandleGetDurationCmdL" ); |
|
892 } |
|
893 |
|
894 |
|
895 // ----------------------------------------------------------------------------- |
|
896 // CHtiAudioServicePlugin::HandleGetMaxVolCmdL() |
|
897 // ----------------------------------------------------------------------------- |
|
898 // |
|
899 void CHtiAudioServicePlugin::HandleGetMaxVolCmdL( const TDesC8& aMessage ) |
|
900 { |
|
901 HTI_LOG_FUNC_IN( "CHtiAudioServicePlugin::HandleGetMaxVolCmdL" ); |
|
902 |
|
903 if ( iIsPlaying ) |
|
904 { |
|
905 // If currently playing, no parameters allowed. Returns the max volume |
|
906 // of currently playing sound. |
|
907 if ( aMessage.Length() != 1 ) |
|
908 { |
|
909 User::LeaveIfError( SendErrorResponseMsg( |
|
910 KErrInUse, KErrorBusyPlaying ) ); |
|
911 return; |
|
912 } |
|
913 |
|
914 TInt maxVol = -1; |
|
915 |
|
916 if ( iAudioPlayer ) |
|
917 { |
|
918 maxVol = iAudioPlayer->MaxVolume(); |
|
919 } |
|
920 |
|
921 else if ( iTonePlayer ) |
|
922 { |
|
923 maxVol = iTonePlayer->MaxVolume(); |
|
924 } |
|
925 |
|
926 HTI_LOG_FORMAT( "Max volume = %d", maxVol ); |
|
927 |
|
928 if ( maxVol < 0 ) |
|
929 { |
|
930 // Should not happen |
|
931 User::LeaveIfError( SendErrorResponseMsg( |
|
932 KErrGeneral, KErrorMaxVolFailed ) ); |
|
933 return; |
|
934 } |
|
935 |
|
936 if(aMessage[0] == ECmdGetMaxVol) |
|
937 { |
|
938 if ( maxVol > 255 ) maxVol = 255; |
|
939 TBuf8<1> maxVolBuf; |
|
940 maxVolBuf.Append( maxVol ); |
|
941 User::LeaveIfError( SendResponseMsg( maxVolBuf ) ); |
|
942 } |
|
943 else |
|
944 { |
|
945 TBuf8<4> maxVolBuf; |
|
946 maxVolBuf.Append( (TUint8*) &maxVol, 4 ); |
|
947 User::LeaveIfError( SendResponseMsg( maxVolBuf ) ); |
|
948 } |
|
949 return; |
|
950 } |
|
951 |
|
952 /* |
|
953 Message bytes: |
|
954 0 = command code |
|
955 1 = path length |
|
956 2 - n = full path to file |
|
957 */ |
|
958 |
|
959 if ( aMessage.Length() < KMaxVolCmdMinLength ) |
|
960 { |
|
961 User::LeaveIfError( SendErrorResponseMsg( |
|
962 KErrArgument, KErrorInvalidParameters ) ); |
|
963 return; |
|
964 } |
|
965 |
|
966 TInt pathLength = aMessage[1]; |
|
967 if ( ( aMessage.Length() - pathLength ) != ( KMaxVolCmdMinLength - 4 ) ) |
|
968 { |
|
969 User::LeaveIfError( SendErrorResponseMsg( |
|
970 KErrArgument, KErrorInvalidParameters ) ); |
|
971 return; |
|
972 } |
|
973 |
|
974 // Parse parameter values from the message |
|
975 TFileName filePath; |
|
976 TInt nextOffset = ParseString( aMessage, 1, filePath ); |
|
977 if ( filePath.Length() < 2 || nextOffset < 0 ) |
|
978 { |
|
979 User::LeaveIfError( SendErrorResponseMsg( |
|
980 KErrArgument, KErrorInvalidParameters ) ); |
|
981 return; |
|
982 } |
|
983 HTI_LOG_TEXT( "Full file path:" ); |
|
984 HTI_LOG_DES( filePath ); |
|
985 |
|
986 TInt err = KErrNone; |
|
987 TBool isRng = EFalse; |
|
988 TRAP( err, isRng = MatchMimeTypeL( filePath, KRngMimeType ) ); |
|
989 |
|
990 if ( err ) |
|
991 { |
|
992 User::LeaveIfError( SendErrorResponseMsg( err, KErrorMaxVolFailed ) ); |
|
993 return; |
|
994 } |
|
995 |
|
996 if ( isRng ) |
|
997 { |
|
998 HTI_LOG_TEXT( "File is RNG - creating tone player" ); |
|
999 TRAP( err, iTonePlayer = CMdaAudioToneUtility::NewL( *this ) ); |
|
1000 } |
|
1001 |
|
1002 else |
|
1003 { |
|
1004 HTI_LOG_TEXT( "File is not RNG - creating audio player" ); |
|
1005 TRAP( err, iAudioPlayer = CMdaAudioPlayerUtility::NewFilePlayerL( |
|
1006 filePath, *this ) ); |
|
1007 // MapcInitComplete callback function will be called |
|
1008 } |
|
1009 |
|
1010 if ( err ) |
|
1011 { |
|
1012 delete iAudioPlayer; |
|
1013 iAudioPlayer = NULL; |
|
1014 delete iTonePlayer; |
|
1015 iTonePlayer = NULL; |
|
1016 User::LeaveIfError( SendErrorResponseMsg( err, KErrorMaxVolFailed ) ); |
|
1017 } |
|
1018 |
|
1019 if ( iTonePlayer ) |
|
1020 { |
|
1021 iTonePlayer->PrepareToPlayFileSequence( filePath ); |
|
1022 // MatoPrepareComplete callback function will be called |
|
1023 } |
|
1024 |
|
1025 HTI_LOG_FUNC_OUT( "CHtiAudioServicePlugin::HandleGetMaxVolCmdL" ); |
|
1026 } |
|
1027 |
|
1028 |
|
1029 // ----------------------------------------------------------------------------- |
|
1030 // CHtiAudioServicePlugin::HandleSetVolCmdL() |
|
1031 // ----------------------------------------------------------------------------- |
|
1032 // |
|
1033 void CHtiAudioServicePlugin::HandleSetVolCmdL( const TDesC8& aMessage ) |
|
1034 { |
|
1035 HTI_LOG_FUNC_IN( "CHtiAudioServicePlugin::HandleSetVolCmdL" ); |
|
1036 |
|
1037 if ( (aMessage[0] == ECmdSetVol && aMessage.Length() != KSetVolCmdLength ) |
|
1038 || (aMessage[0] == ECmdSetVol2 && aMessage.Length() != KSetVol2CmdLength )) |
|
1039 { |
|
1040 User::LeaveIfError( SendErrorResponseMsg( KErrArgument, |
|
1041 KErrorInvalidParameters ) ); |
|
1042 } |
|
1043 |
|
1044 if ( !iIsPlaying ) |
|
1045 { |
|
1046 HTI_LOG_TEXT( "Nothing playing - not setting volume" ); |
|
1047 User::LeaveIfError( SendErrorResponseMsg( |
|
1048 KErrNotReady, KErrorNothingPlaying ) ); |
|
1049 } |
|
1050 |
|
1051 else if(aMessage[0] == ECmdSetVol) |
|
1052 { |
|
1053 TInt volume = aMessage[1]; // [0] = command code, [1] = volume value |
|
1054 HTI_LOG_FORMAT( "requested volume = %d", volume ); |
|
1055 |
|
1056 if ( iAudioPlayer ) |
|
1057 { |
|
1058 HTI_LOG_TEXT( "Setting audio player volume" ); |
|
1059 TInt maxVol = iAudioPlayer->MaxVolume(); |
|
1060 HTI_LOG_FORMAT( "max volume = %d", maxVol ); |
|
1061 if ( volume > maxVol ) volume = maxVol; |
|
1062 iAudioPlayer->SetVolume( volume ); |
|
1063 TBuf8<1> volBuf; |
|
1064 volBuf.Append( volume ); |
|
1065 User::LeaveIfError( SendResponseMsg( volBuf ) ); |
|
1066 } |
|
1067 else if ( iTonePlayer ) |
|
1068 { |
|
1069 HTI_LOG_TEXT( "Setting tone player volume" ); |
|
1070 TInt maxVol = iTonePlayer->MaxVolume(); |
|
1071 HTI_LOG_FORMAT( "max volume = %d", maxVol ); |
|
1072 if ( volume > maxVol ) volume = maxVol; |
|
1073 iTonePlayer->SetVolume( volume ); |
|
1074 TBuf8<1> volBuf; |
|
1075 volBuf.Append( volume ); |
|
1076 User::LeaveIfError( SendResponseMsg( volBuf ) ); |
|
1077 } |
|
1078 } |
|
1079 else if(aMessage[0] == ECmdSetVol2) |
|
1080 { |
|
1081 TInt volume = aMessage[1] + (aMessage[2] << 8) |
|
1082 + (aMessage[3] << 16) + (aMessage[4] << 24); |
|
1083 HTI_LOG_FORMAT( "requested volume = %d", volume ); |
|
1084 |
|
1085 if ( iAudioPlayer ) |
|
1086 { |
|
1087 HTI_LOG_TEXT( "Setting audio player volume" ); |
|
1088 TInt maxVol = iAudioPlayer->MaxVolume(); |
|
1089 HTI_LOG_FORMAT( "max volume = %d", maxVol ); |
|
1090 if ( volume > maxVol ) volume = maxVol; |
|
1091 iAudioPlayer->SetVolume( volume ); |
|
1092 TBuf8<4> volBuf; |
|
1093 volBuf.Append( (TUint8*)&volume, 4 ); |
|
1094 User::LeaveIfError( SendResponseMsg( volBuf ) ); |
|
1095 } |
|
1096 else if ( iTonePlayer ) |
|
1097 { |
|
1098 HTI_LOG_TEXT( "Setting tone player volume" ); |
|
1099 TInt maxVol = iTonePlayer->MaxVolume(); |
|
1100 HTI_LOG_FORMAT( "max volume = %d", maxVol ); |
|
1101 if ( volume > maxVol ) volume = maxVol; |
|
1102 iTonePlayer->SetVolume( volume ); |
|
1103 TBuf8<4> volBuf; |
|
1104 volBuf.Append( (TUint8*)&volume, 4 ); |
|
1105 User::LeaveIfError( SendResponseMsg( volBuf ) ); |
|
1106 } |
|
1107 } |
|
1108 HTI_LOG_FUNC_OUT( "CHtiAudioServicePlugin::HandleSetVolCmdL" ); |
|
1109 } |
|
1110 |
|
1111 |
|
1112 // ----------------------------------------------------------------------------- |
|
1113 // CHtiAudioServicePlugin::MatoPrepareComplete() |
|
1114 // Tone player prepare complete |
|
1115 // ----------------------------------------------------------------------------- |
|
1116 // |
|
1117 void CHtiAudioServicePlugin::MatoPrepareComplete( TInt aError ) |
|
1118 { |
|
1119 HTI_LOG_FUNC_IN( "CHtiAudioServicePlugin::MatoPrepareComplete" ); |
|
1120 |
|
1121 if ( iCommandId == ECmdGetMaxVol || iCommandId == ECmdGetMaxVol2) |
|
1122 { |
|
1123 if ( aError ) |
|
1124 { |
|
1125 SendErrorResponseMsg( aError, KErrorMaxVolFailed ); |
|
1126 } |
|
1127 |
|
1128 else |
|
1129 { |
|
1130 TInt maxVol = iTonePlayer->MaxVolume(); |
|
1131 HTI_LOG_FORMAT( "Max volume = %d", maxVol ); |
|
1132 if(iCommandId == ECmdGetMaxVol) |
|
1133 { |
|
1134 if ( maxVol > 255 ) maxVol = 255; |
|
1135 TBuf8<1> maxVolBuf; |
|
1136 maxVolBuf.Append( maxVol ); |
|
1137 SendResponseMsg( maxVolBuf ); |
|
1138 } |
|
1139 else |
|
1140 { |
|
1141 TBuf8<4> maxVolBuf; |
|
1142 maxVolBuf.Append( (TUint8*)&maxVol, 4 ); |
|
1143 SendResponseMsg( maxVolBuf ); |
|
1144 } |
|
1145 } |
|
1146 |
|
1147 delete iTonePlayer; |
|
1148 iTonePlayer = NULL; |
|
1149 return; |
|
1150 } |
|
1151 |
|
1152 if ( aError ) |
|
1153 { |
|
1154 SendErrorResponseMsg( aError, KErrorToneInitFailed ); |
|
1155 delete iTonePlayer; |
|
1156 iTonePlayer = NULL; |
|
1157 } |
|
1158 |
|
1159 else |
|
1160 { |
|
1161 if ( iCommandId == ECmdPlayDtmf || iCommandId == ECmdPlayDtmf2) |
|
1162 { |
|
1163 iTonePlayer->SetDTMFLengths( |
|
1164 TTimeIntervalMicroSeconds32( iDtmfLength ), |
|
1165 TTimeIntervalMicroSeconds32( iDtmfGapLength ), |
|
1166 TTimeIntervalMicroSeconds32( 0 ) ); |
|
1167 } |
|
1168 |
|
1169 if ( iVolume > iTonePlayer->MaxVolume() ) |
|
1170 { |
|
1171 iVolume = iTonePlayer->MaxVolume(); |
|
1172 } |
|
1173 |
|
1174 iTonePlayer->SetVolume( iVolume ); |
|
1175 iTonePlayer->SetRepeats( iRepeats + 1, |
|
1176 TTimeIntervalMicroSeconds( iTrailingSilence ) ); |
|
1177 iIsPlaying = ETrue; |
|
1178 iTonePlayer->Play(); |
|
1179 iIsBusy = EFalse; |
|
1180 // MatoPlayComplete callback function will be called when playing ends. |
|
1181 } |
|
1182 |
|
1183 HTI_LOG_FUNC_OUT( "CHtiAudioServicePlugin::MatoPrepareComplete" ); |
|
1184 } |
|
1185 |
|
1186 |
|
1187 // ----------------------------------------------------------------------------- |
|
1188 // CHtiAudioServicePlugin::MatoPlayComplete() |
|
1189 // Tone play complete |
|
1190 // ----------------------------------------------------------------------------- |
|
1191 // |
|
1192 void CHtiAudioServicePlugin::MatoPlayComplete( TInt aError ) |
|
1193 { |
|
1194 HTI_LOG_FUNC_IN( "CHtiAudioServicePlugin::MatoPlayComplete" ); |
|
1195 |
|
1196 iIsPlaying = EFalse; |
|
1197 iIsBusy = ETrue; // Busy dispatching the play complete message |
|
1198 |
|
1199 if ( aError ) |
|
1200 { |
|
1201 SendErrorResponseMsg( aError, KErrorTonePlayFailed, iPlayCommandId ); |
|
1202 } |
|
1203 |
|
1204 else |
|
1205 { |
|
1206 SendResponseMsg( _L8( "OK" ), iPlayCommandId ); |
|
1207 } |
|
1208 |
|
1209 delete iTonePlayer; |
|
1210 iTonePlayer = NULL; |
|
1211 |
|
1212 HTI_LOG_FUNC_OUT( "CHtiAudioServicePlugin::MatoPlayComplete" ); |
|
1213 } |
|
1214 |
|
1215 |
|
1216 // ----------------------------------------------------------------------------- |
|
1217 // CHtiAudioServicePlugin::MapcInitComplete() |
|
1218 // Audio player init complete |
|
1219 // ----------------------------------------------------------------------------- |
|
1220 // |
|
1221 void CHtiAudioServicePlugin::MapcInitComplete( TInt aError, |
|
1222 const TTimeIntervalMicroSeconds& aDuration ) |
|
1223 { |
|
1224 HTI_LOG_FUNC_IN( "CHtiAudioServicePlugin::MapcInitComplete" ); |
|
1225 |
|
1226 if ( iCommandId == ECmdPlayFile || iCommandId == ECmdPlayFile2) |
|
1227 { |
|
1228 if ( aError ) |
|
1229 { |
|
1230 SendErrorResponseMsg( aError, KErrorFileInitFailed ); |
|
1231 delete iAudioPlayer; |
|
1232 iAudioPlayer = NULL; |
|
1233 } |
|
1234 |
|
1235 else |
|
1236 { |
|
1237 if ( iEndPos < iStartPos || |
|
1238 TTimeIntervalMicroSeconds( iStartPos ) > aDuration ) |
|
1239 { |
|
1240 SendErrorResponseMsg( KErrArgument, KErrorPosition ); |
|
1241 delete iAudioPlayer; |
|
1242 iAudioPlayer = NULL; |
|
1243 return; |
|
1244 } |
|
1245 |
|
1246 if ( iEndPos > 0 ) |
|
1247 { |
|
1248 iAudioPlayer->SetPlayWindow( |
|
1249 TTimeIntervalMicroSeconds( iStartPos ), |
|
1250 TTimeIntervalMicroSeconds( iEndPos ) ); |
|
1251 } |
|
1252 |
|
1253 HTI_LOG_FORMAT( "Max volume = %d", iAudioPlayer->MaxVolume() ); |
|
1254 HTI_LOG_FORMAT( "Setting volume = %d", iVolume ); |
|
1255 if ( iVolume > iAudioPlayer->MaxVolume() ) |
|
1256 { |
|
1257 iVolume = iAudioPlayer->MaxVolume(); |
|
1258 } |
|
1259 |
|
1260 iAudioPlayer->SetVolume( iVolume ); |
|
1261 iAudioPlayer->SetRepeats( iRepeats, |
|
1262 TTimeIntervalMicroSeconds( iTrailingSilence ) ); |
|
1263 iIsPlaying = ETrue; |
|
1264 iAudioPlayer->Play(); |
|
1265 |
|
1266 // Have to do this after play command because |
|
1267 // volume setting before play seems to have no effect. |
|
1268 iAudioPlayer->SetVolume( 0 ); |
|
1269 iAudioPlayer->SetVolume( iVolume ); |
|
1270 |
|
1271 iIsBusy = EFalse; |
|
1272 // MapcPlayComplete callback function is called when playing ends |
|
1273 } |
|
1274 } |
|
1275 |
|
1276 else if ( iCommandId == ECmdGetDuration ) |
|
1277 { |
|
1278 if ( aError ) |
|
1279 { |
|
1280 SendErrorResponseMsg( aError, KErrorDurationFailed ); |
|
1281 } |
|
1282 |
|
1283 else |
|
1284 { |
|
1285 if ( I64HIGH( aDuration.Int64() ) > 0 ) |
|
1286 { |
|
1287 SendErrorResponseMsg( KErrOverflow, KErrorDurationFailed ); |
|
1288 } |
|
1289 else |
|
1290 { |
|
1291 TUint duration = I64LOW( aDuration.Int64() ); |
|
1292 TBuf8<KTUintSize> durationBuf; |
|
1293 durationBuf.Append( (TUint8*)(&duration), KTUintSize ); |
|
1294 SendResponseMsg( durationBuf ); |
|
1295 } |
|
1296 } |
|
1297 delete iAudioPlayer; |
|
1298 iAudioPlayer = NULL; |
|
1299 } |
|
1300 |
|
1301 else if ( iCommandId == ECmdGetMaxVol || iCommandId == ECmdGetMaxVol2) |
|
1302 { |
|
1303 if ( aError ) |
|
1304 { |
|
1305 SendErrorResponseMsg( aError, KErrorMaxVolFailed ); |
|
1306 } |
|
1307 |
|
1308 else |
|
1309 { |
|
1310 TInt maxVol = iAudioPlayer->MaxVolume(); |
|
1311 HTI_LOG_FORMAT( "Max volume = %d", maxVol ); |
|
1312 if(iCommandId == ECmdGetMaxVol) |
|
1313 { |
|
1314 if ( maxVol > 255 ) maxVol = 255; |
|
1315 TBuf8<1> maxVolBuf; |
|
1316 maxVolBuf.Append( maxVol ); |
|
1317 SendResponseMsg( maxVolBuf ); |
|
1318 } |
|
1319 else |
|
1320 { |
|
1321 TBuf8<4> maxVolBuf; |
|
1322 maxVolBuf.Append( (TUint8*)&maxVol, 4 ); |
|
1323 SendResponseMsg( maxVolBuf ); |
|
1324 } |
|
1325 } |
|
1326 delete iAudioPlayer; |
|
1327 iAudioPlayer = NULL; |
|
1328 } |
|
1329 |
|
1330 HTI_LOG_FUNC_OUT( "CHtiAudioServicePlugin::MapcInitComplete" ); |
|
1331 } |
|
1332 |
|
1333 |
|
1334 // ----------------------------------------------------------------------------- |
|
1335 // CHtiAudioServicePlugin::MapcPlayComplete() |
|
1336 // Audio play complete |
|
1337 // ----------------------------------------------------------------------------- |
|
1338 // |
|
1339 void CHtiAudioServicePlugin::MapcPlayComplete( TInt aError ) |
|
1340 { |
|
1341 HTI_LOG_FUNC_IN( "CHtiAudioServicePlugin::MapcPlayComplete" ); |
|
1342 |
|
1343 iIsPlaying = EFalse; |
|
1344 iIsBusy = ETrue; // Busy dispatching the play complete message |
|
1345 |
|
1346 if ( aError ) |
|
1347 { |
|
1348 SendErrorResponseMsg( aError, KErrorFilePlayFailed, ECmdPlayFile ); |
|
1349 } |
|
1350 |
|
1351 else |
|
1352 { |
|
1353 SendResponseMsg( _L8( "OK" ), iPlayCommandId ); |
|
1354 } |
|
1355 |
|
1356 delete iAudioPlayer; |
|
1357 iAudioPlayer = NULL; |
|
1358 |
|
1359 HTI_LOG_FUNC_OUT( "CHtiAudioServicePlugin::MapcPlayComplete" ); |
|
1360 } |
|
1361 |
|
1362 |
|
1363 // ----------------------------------------------------------------------------- |
|
1364 // CHtiAudioServicePlugin::NotifyMemoryChange |
|
1365 // Called when HTI Framework has dispatched a message forward and the amount |
|
1366 // of free memory in the message queue has changed. |
|
1367 // ----------------------------------------------------------------------------- |
|
1368 // |
|
1369 void CHtiAudioServicePlugin::NotifyMemoryChange( TInt aAvailableMemory ) |
|
1370 { |
|
1371 if ( iIsBusy && iMessage ) |
|
1372 { |
|
1373 if ( aAvailableMemory >= iMessage->Size() ) |
|
1374 { |
|
1375 if ( iErrorCode == 0 ) |
|
1376 { |
|
1377 TInt err = iDispatcher->DispatchOutgoingMessage( |
|
1378 iMessage, KAudioServiceUid ); |
|
1379 |
|
1380 if ( err == KErrNone ) |
|
1381 { |
|
1382 // Ownership of iMessage has been transferred |
|
1383 iMessage = NULL; |
|
1384 iIsBusy = EFalse; |
|
1385 iDispatcher->RemoveMemoryObserver( this ); |
|
1386 } |
|
1387 |
|
1388 else if ( err == KErrNoMemory ) |
|
1389 { |
|
1390 // Keep retrying. |
|
1391 } |
|
1392 |
|
1393 else // Give up on sending |
|
1394 { |
|
1395 delete iMessage; |
|
1396 iMessage = NULL; |
|
1397 iIsBusy = EFalse; |
|
1398 iDispatcher->RemoveMemoryObserver( this ); |
|
1399 } |
|
1400 } |
|
1401 |
|
1402 else |
|
1403 { |
|
1404 TInt err = iDispatcher->DispatchOutgoingErrorMessage( |
|
1405 iErrorCode, *iMessage, KAudioServiceUid ); |
|
1406 |
|
1407 // If it was success or some other error than KErrNoMemory |
|
1408 // we are done sending or trying to send this message. |
|
1409 if ( err != KErrNoMemory ) |
|
1410 { |
|
1411 delete iMessage; |
|
1412 iMessage = NULL; |
|
1413 iIsBusy = EFalse; |
|
1414 iDispatcher->RemoveMemoryObserver( this ); |
|
1415 } |
|
1416 |
|
1417 else |
|
1418 { |
|
1419 // Keep retrying. |
|
1420 } |
|
1421 } |
|
1422 } |
|
1423 } |
|
1424 } |
|
1425 |
|
1426 |
|
1427 // ----------------------------------------------------------------------------- |
|
1428 // CHtiAudioServicePlugin::IsBusy |
|
1429 // ----------------------------------------------------------------------------- |
|
1430 // |
|
1431 TBool CHtiAudioServicePlugin::IsBusy() |
|
1432 { |
|
1433 return iIsBusy; |
|
1434 } |
|
1435 |
|
1436 |
|
1437 // ----------------------------------------------------------------------------- |
|
1438 // CHtiAudioServicePlugin::SendResponseMsg |
|
1439 // Sends a message out to the message dispatcher. |
|
1440 // ----------------------------------------------------------------------------- |
|
1441 // |
|
1442 TInt CHtiAudioServicePlugin::SendResponseMsg( const TDesC8& aMsg, |
|
1443 const TUint8 aCommandId ) |
|
1444 { |
|
1445 HTI_LOG_FUNC_IN( "CHtiAudioServicePlugin::SendResponseMsg" ); |
|
1446 |
|
1447 iErrorCode = 0; |
|
1448 |
|
1449 if ( iDispatcher == NULL ) |
|
1450 { |
|
1451 iIsBusy = EFalse; |
|
1452 return KErrGeneral; |
|
1453 } |
|
1454 |
|
1455 iDispatcher->RemoveMemoryObserver( this ); |
|
1456 |
|
1457 delete iMessage; |
|
1458 iMessage = NULL; |
|
1459 iMessage = HBufC8::New( aMsg.Length() + 1 ); |
|
1460 |
|
1461 if ( iMessage == NULL ) |
|
1462 { |
|
1463 iIsBusy = EFalse; |
|
1464 return KErrNoMemory; |
|
1465 } |
|
1466 |
|
1467 TPtr8 ptr8 = iMessage->Des(); |
|
1468 if ( aCommandId != 0 ) |
|
1469 { |
|
1470 ptr8.Append( aCommandId ); |
|
1471 } |
|
1472 else |
|
1473 { |
|
1474 ptr8.Append( iCommandId ); |
|
1475 } |
|
1476 |
|
1477 ptr8.Append( aMsg ); |
|
1478 |
|
1479 TInt err = KErrNone; |
|
1480 |
|
1481 err = iDispatcher->DispatchOutgoingMessage( iMessage, KAudioServiceUid ); |
|
1482 |
|
1483 if ( err == KErrNoMemory ) |
|
1484 { |
|
1485 HTI_LOG_TEXT( "Message queue memory full - waiting" ); |
|
1486 iIsBusy = ETrue; // Should already be true, but just in case |
|
1487 iDispatcher->AddMemoryObserver( this ); |
|
1488 // For the caller of this method all is OK, sending is just delayed |
|
1489 err = KErrNone; |
|
1490 } |
|
1491 |
|
1492 else if ( err == KErrNone ) |
|
1493 { |
|
1494 HTI_LOG_TEXT( "Message sent to dispatcher" ); |
|
1495 iMessage = NULL; // Ownership of iMessage has been transferred |
|
1496 iIsBusy = EFalse; |
|
1497 } |
|
1498 |
|
1499 else // give up on sending |
|
1500 { |
|
1501 HTI_LOG_FORMAT( "Other dispatcher error %d", err ); |
|
1502 delete iMessage; |
|
1503 iMessage = NULL; |
|
1504 iIsBusy = EFalse; |
|
1505 } |
|
1506 |
|
1507 HTI_LOG_FUNC_OUT( "CHtiAudioServicePlugin::SendResponseMsg" ); |
|
1508 return err; |
|
1509 } |
|
1510 |
|
1511 |
|
1512 // ----------------------------------------------------------------------------- |
|
1513 // CHtiAudioServicePlugin::SendErrorResponseMsg |
|
1514 // Sends an error message out to the message dispatcher. |
|
1515 // ----------------------------------------------------------------------------- |
|
1516 // |
|
1517 TInt CHtiAudioServicePlugin::SendErrorResponseMsg( TInt aErrorCode, |
|
1518 const TDesC8& aErrorDescription, |
|
1519 const TUint8 aCommandId ) |
|
1520 { |
|
1521 HTI_LOG_FUNC_IN( "CHtiAudioServicePlugin::SendErrorResponseMsg" ); |
|
1522 |
|
1523 iErrorCode = aErrorCode; |
|
1524 |
|
1525 if ( iDispatcher == NULL ) |
|
1526 { |
|
1527 iIsBusy = EFalse; |
|
1528 return KErrGeneral; |
|
1529 } |
|
1530 |
|
1531 iDispatcher->RemoveMemoryObserver( this ); |
|
1532 |
|
1533 delete iMessage; |
|
1534 iMessage = NULL; |
|
1535 iMessage = HBufC8::New( aErrorDescription.Length() + 1 ); |
|
1536 |
|
1537 if ( iMessage == NULL ) |
|
1538 { |
|
1539 iIsBusy = EFalse; |
|
1540 return KErrNoMemory; |
|
1541 } |
|
1542 |
|
1543 TPtr8 ptr8 = iMessage->Des(); |
|
1544 if ( aCommandId != 0 ) |
|
1545 { |
|
1546 ptr8.Append( aCommandId ); |
|
1547 } |
|
1548 else |
|
1549 { |
|
1550 ptr8.Append( iCommandId ); |
|
1551 } |
|
1552 |
|
1553 ptr8.Append( aErrorDescription ); |
|
1554 |
|
1555 TInt err = KErrNone; |
|
1556 |
|
1557 err = iDispatcher->DispatchOutgoingErrorMessage( |
|
1558 aErrorCode, *iMessage, KAudioServiceUid ); |
|
1559 |
|
1560 if ( err == KErrNoMemory ) |
|
1561 { |
|
1562 HTI_LOG_TEXT( "Message queue memory full - waiting" ); |
|
1563 iIsBusy = ETrue; // Should already be true, but just in case |
|
1564 iDispatcher->AddMemoryObserver( this ); |
|
1565 // For the caller of this method all is OK, sending is just delayed |
|
1566 err = KErrNone; |
|
1567 } |
|
1568 |
|
1569 else if ( err == KErrNone ) |
|
1570 { |
|
1571 HTI_LOG_TEXT( "Error message sent to dispatcher" ); |
|
1572 delete iMessage; |
|
1573 iMessage = NULL; |
|
1574 iIsBusy = EFalse; |
|
1575 } |
|
1576 |
|
1577 else // give up on sending |
|
1578 { |
|
1579 HTI_LOG_FORMAT( "Other dispatcher error %d", err ); |
|
1580 delete iMessage; |
|
1581 iMessage = NULL; |
|
1582 iIsBusy = EFalse; |
|
1583 } |
|
1584 |
|
1585 HTI_LOG_FUNC_OUT( "CHtiAudioServicePlugin::SendErrorResponseMsg" ); |
|
1586 return err; |
|
1587 } |
|
1588 |
|
1589 |
|
1590 // ----------------------------------------------------------------------------- |
|
1591 // CHtiAudioServicePlugin::ParseString() |
|
1592 // ----------------------------------------------------------------------------- |
|
1593 // |
|
1594 TInt CHtiAudioServicePlugin::ParseString( const TDesC8& aRequest, |
|
1595 TInt aOffset, |
|
1596 TDes& aResult ) |
|
1597 { |
|
1598 HTI_LOG_FUNC_IN( "CHtiAudioServicePlugin::ParseString" ); |
|
1599 |
|
1600 // If offset outside the string return empty string |
|
1601 if ( aOffset >= aRequest.Size() ) |
|
1602 { |
|
1603 return aOffset; |
|
1604 } |
|
1605 |
|
1606 TInt length = aRequest[aOffset]; |
|
1607 HTI_LOG_FORMAT( "String length = %d", length ); |
|
1608 |
|
1609 // If length is zero return empty string |
|
1610 if ( length < 1 ) |
|
1611 { |
|
1612 return aOffset + 1; |
|
1613 } |
|
1614 |
|
1615 if ( length > aResult.MaxLength() ) |
|
1616 { |
|
1617 return KErrBadDescriptor; |
|
1618 } |
|
1619 |
|
1620 TInt nextOffset = length + aOffset + 1; |
|
1621 HTI_LOG_FORMAT( "Next offset = %d", nextOffset ); |
|
1622 HTI_LOG_FORMAT( "Request size = %d", aRequest.Size() ); |
|
1623 |
|
1624 if ( nextOffset > aRequest.Size() ) |
|
1625 { |
|
1626 return KErrArgument; |
|
1627 } |
|
1628 |
|
1629 aResult.Copy( aRequest.Mid( aOffset + 1, length ) ); |
|
1630 |
|
1631 HTI_LOG_FUNC_OUT( "CHtiAudioServicePlugin::ParseString" ); |
|
1632 return nextOffset; |
|
1633 } |
|
1634 |
|
1635 |
|
1636 // ----------------------------------------------------------------------------- |
|
1637 // CHtiAudioServicePlugin::AddSubdirsRecursivelyL |
|
1638 // Scan all subdirectories from the given path and add them to the aArray. |
|
1639 // ----------------------------------------------------------------------------- |
|
1640 // |
|
1641 void CHtiAudioServicePlugin::AddSubdirsRecursivelyL( const TDesC& aPath, |
|
1642 CDesCArraySeg& aArray, |
|
1643 RFs& aFs ) |
|
1644 { |
|
1645 HTI_LOG_FUNC_IN( "CHtiAudioServicePlugin::AddSubdirsRecursivelyL" ); |
|
1646 |
|
1647 CDirScan* dirScan = CDirScan::NewL( aFs ); |
|
1648 CleanupStack::PushL( dirScan ); |
|
1649 |
|
1650 TFileName* path = new (ELeave) TFileName; |
|
1651 CleanupStack::PushL( path ); |
|
1652 |
|
1653 CDir* directory = NULL; |
|
1654 TPtrC currentPath; |
|
1655 |
|
1656 dirScan->SetScanDataL( aPath, KEntryAttMatchExclusive | KEntryAttDir, ESortNone ); |
|
1657 dirScan->NextL( directory ); |
|
1658 |
|
1659 while ( directory ) |
|
1660 { |
|
1661 CleanupStack::PushL( directory ); |
|
1662 currentPath.Set( dirScan->FullPath() ); |
|
1663 |
|
1664 TInt dirCount( directory->Count() ); |
|
1665 for ( TInt i = 0; i < dirCount ; ++i ) |
|
1666 { |
|
1667 path->Copy( currentPath ); |
|
1668 path->Append( ( *directory )[ i ].iName ); |
|
1669 path->Append( KBackslash ); |
|
1670 aArray.AppendL( *path ); |
|
1671 } |
|
1672 |
|
1673 CleanupStack::PopAndDestroy( directory ); |
|
1674 directory = NULL; |
|
1675 |
|
1676 dirScan->NextL( directory ); |
|
1677 } |
|
1678 |
|
1679 CleanupStack::PopAndDestroy( 2 ); // path, dirScan |
|
1680 |
|
1681 HTI_LOG_FUNC_OUT( "CHtiAudioServicePlugin::AddSubdirsRecursivelyL" ); |
|
1682 } |
|
1683 |
|
1684 |
|
1685 // ----------------------------------------------------------------------------- |
|
1686 // CHtiAudioServicePlugin::MatchMimeTypeL |
|
1687 // Check if the MIME type of the given file matches to the given pattern. |
|
1688 // ----------------------------------------------------------------------------- |
|
1689 // |
|
1690 TBool CHtiAudioServicePlugin::MatchMimeTypeL( const TDesC& aFilePath, |
|
1691 const TDesC& aMimeTypeMatchPattern ) |
|
1692 { |
|
1693 HTI_LOG_FUNC_IN( "CHtiAudioServicePlugin::MatchMimeTypeL" ); |
|
1694 |
|
1695 RApaLsSession apaSession; |
|
1696 User::LeaveIfError( apaSession.Connect() ); |
|
1697 CleanupClosePushL( apaSession ); |
|
1698 |
|
1699 TUid dummyUid( KNullUid ); |
|
1700 TDataType dataType; |
|
1701 User::LeaveIfError( apaSession.AppForDocument( aFilePath, |
|
1702 dummyUid, |
|
1703 dataType ) ); |
|
1704 CleanupStack::PopAndDestroy(); // apaSession |
|
1705 |
|
1706 if ( dataType.Des().MatchF( aMimeTypeMatchPattern ) >= 0 ) |
|
1707 { |
|
1708 HTI_LOG_TEXT( "Match" ); |
|
1709 return ETrue; |
|
1710 } |
|
1711 |
|
1712 HTI_LOG_TEXT( "Not match" ); |
|
1713 HTI_LOG_FUNC_OUT( "CHtiAudioServicePlugin::MatchMimeTypeL" ); |
|
1714 return EFalse; |
|
1715 } |
|
1716 |
|
1717 |
|
1718 // ----------------------------------------------------------------------------- |
|
1719 // CHtiAudioServicePlugin::SetAudioSettings |
|
1720 // Set the audio priority and priority preference values. |
|
1721 // ----------------------------------------------------------------------------- |
|
1722 // |
|
1723 void CHtiAudioServicePlugin::SetAudioSettings( TAudioSetting aSetting ) |
|
1724 { |
|
1725 HTI_LOG_FUNC_IN( "CHtiAudioServicePlugin::SetAudioSettings" ); |
|
1726 HTI_LOG_FORMAT( "Setting values for audio setting %d", aSetting ); |
|
1727 |
|
1728 switch ( aSetting ) |
|
1729 { |
|
1730 case EGeneralMusic: |
|
1731 { |
|
1732 iAudioPriority = KAudioPriorityRealOnePlayer; |
|
1733 iAudioPriorityPreference = |
|
1734 ( TMdaPriorityPreference ) KAudioPrefRealOneLocalPlayback; |
|
1735 break; |
|
1736 } |
|
1737 |
|
1738 case ERingTonePreview: |
|
1739 { |
|
1740 iAudioPriority = KAudioPriorityRingingTonePreview; |
|
1741 iAudioPriorityPreference = |
|
1742 ( TMdaPriorityPreference ) KAudioPrefRingFilePreview; |
|
1743 break; |
|
1744 } |
|
1745 /* |
|
1746 case EIncomingCall: |
|
1747 { |
|
1748 iAudioPriority = KAudioPriorityPhoneCall; |
|
1749 iAudioPriorityPreference = |
|
1750 ( TMdaPriorityPreference ) KAudioPrefIncomingCall; |
|
1751 break; |
|
1752 } |
|
1753 */ |
|
1754 case EDtmfString: |
|
1755 { |
|
1756 |
|
1757 iAudioPriority = KAudioPriorityDTMFString; |
|
1758 iAudioPriorityPreference = |
|
1759 ( TMdaPriorityPreference ) KAudioDTMFString; |
|
1760 break; |
|
1761 } |
|
1762 |
|
1763 default: |
|
1764 { |
|
1765 iAudioPriority = EMdaPriorityNormal; |
|
1766 iAudioPriorityPreference = EMdaPriorityPreferenceTimeAndQuality; |
|
1767 break; |
|
1768 } |
|
1769 } |
|
1770 |
|
1771 HTI_LOG_FUNC_OUT( "CHtiAudioServicePlugin::SetAudioSettings" ); |
|
1772 } |
|
1773 |
|
1774 |
|
1775 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
1776 |
|
1777 // End of File |
|