78
|
1 |
|
|
2 |
/*
|
|
3 |
* Copyright (c) 2010 - 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
* All rights reserved.
|
|
5 |
* This component and the accompanying materials are made available
|
|
6 |
* under the terms of "Eclipse Public License v1.0"
|
|
7 |
* which accompanies this distribution, and is available
|
|
8 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
9 |
*
|
|
10 |
* Initial Contributors:
|
|
11 |
* Nokia Corporation - initial contribution.
|
|
12 |
*
|
|
13 |
* Contributors:
|
|
14 |
*
|
|
15 |
* Description: Playback controller class for phone ringingtone server.
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
#include <e32base.h>
|
|
19 |
#include <e32svr.h>
|
|
20 |
#include <utf.h>
|
|
21 |
#include <cntdef.h>
|
|
22 |
#include <apgcli.h>
|
|
23 |
#include <audiopreference.h>
|
|
24 |
#include <profile.hrh>
|
|
25 |
|
|
26 |
#include "cphonetoneserverplaybackcontroller.h"
|
|
27 |
#include "cphonetoneserver.h"
|
|
28 |
#include "cphonetoneserversession.h"
|
|
29 |
#include "mphonetoneserver.h"
|
|
30 |
#include "phoneconstants.h"
|
|
31 |
#include "phoneringingtonetrace.h"
|
|
32 |
|
|
33 |
const TInt KMinVolumeLevel = 1;
|
|
34 |
const TInt KMaxVolumeLevel = 10;
|
|
35 |
|
|
36 |
#if defined( __WINS__ )
|
|
37 |
|
|
38 |
_LIT( KFileListRngMimeType, "rng" );
|
|
39 |
_LIT8( KPhoneNoSoundSequence, "\x00\x11\x06\x05\xFC\x0A\x08\x40\x32\x0A\xF7\x40\x64\x06\x0B" );
|
|
40 |
|
|
41 |
#else
|
|
42 |
|
|
43 |
_LIT( KFileListRngMimeType, "application/vnd.nokia.ringing-tone" );
|
|
44 |
|
|
45 |
#endif
|
|
46 |
|
|
47 |
_LIT( KDefaultTone, "z:\\data\\sounds\\digital\\Nokia tune.aac" );
|
|
48 |
|
|
49 |
// -----------------------------------------------------------------------------
|
|
50 |
// CPhoneToneServerPlaybackController::NewL
|
|
51 |
// -----------------------------------------------------------------------------
|
|
52 |
//
|
|
53 |
CPhoneToneServerPlaybackController* CPhoneToneServerPlaybackController::NewL()
|
|
54 |
{
|
|
55 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::NewL <");
|
|
56 |
CPhoneToneServerPlaybackController* self =
|
|
57 |
new( ELeave )CPhoneToneServerPlaybackController;
|
|
58 |
CleanupStack::PushL( self );
|
|
59 |
self->ConstructL();
|
|
60 |
CleanupStack::Pop( self );
|
|
61 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::NewL >");
|
|
62 |
return self;
|
|
63 |
}
|
|
64 |
|
|
65 |
// -----------------------------------------------------------------------------
|
|
66 |
// CPhoneToneServerPlaybackController::ConstructL
|
|
67 |
// -----------------------------------------------------------------------------
|
|
68 |
//
|
|
69 |
void CPhoneToneServerPlaybackController::ConstructL()
|
|
70 |
{
|
|
71 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::ConstructL <");
|
|
72 |
CTimer::ConstructL();
|
|
73 |
iRingingType = EProfileRingingTypeSilent;
|
|
74 |
iSilentPlayer = CMdaAudioToneUtility::NewL( *this );
|
|
75 |
iSilentPlayer->PrepareToPlayDesSequence( KPhoneNoSoundSequence() );
|
|
76 |
iDefaultPlayer = CMdaAudioPlayerUtility::NewFilePlayerL(
|
|
77 |
KDefaultTone(),
|
|
78 |
*this,
|
|
79 |
KAudioPriorityPhoneCall,
|
|
80 |
static_cast< TMdaPriorityPreference >( KAudioPrefIncomingCall ) );
|
|
81 |
|
|
82 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::ConstructL >");
|
|
83 |
}
|
|
84 |
// -----------------------------------------------------------------------------
|
|
85 |
// CPhoneToneServerPlaybackController::CPhoneToneServerPlaybackController
|
|
86 |
// -----------------------------------------------------------------------------
|
|
87 |
//
|
|
88 |
CPhoneToneServerPlaybackController::CPhoneToneServerPlaybackController():
|
|
89 |
CTimer(EPriorityHigh),
|
|
90 |
iRingingType( EProfileRingingTypeSilent )
|
|
91 |
{
|
|
92 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::CPhoneToneServerPlaybackController <");
|
|
93 |
CActiveScheduler::Add(this);
|
|
94 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::CPhoneToneServerPlaybackController <");
|
|
95 |
}
|
|
96 |
|
|
97 |
// -----------------------------------------------------------------------------
|
|
98 |
// CPhoneToneServerPlaybackController::~CPhoneToneServerPlaybackController
|
|
99 |
// -----------------------------------------------------------------------------
|
|
100 |
//
|
|
101 |
CPhoneToneServerPlaybackController::~CPhoneToneServerPlaybackController()
|
|
102 |
{
|
|
103 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::~CPhoneToneServerPlaybackController <");
|
|
104 |
delete iSilentPlayer;
|
|
105 |
delete iDefaultPlayer;
|
|
106 |
delete iProfileSamplePlayer;
|
|
107 |
delete iProfileTonePlayer;
|
|
108 |
Cancel();
|
|
109 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::~CPhoneToneServerPlaybackController <");
|
|
110 |
}
|
|
111 |
// -----------------------------------------------------------------------------
|
|
112 |
// CPhoneToneServerPlaybackController::RunL
|
|
113 |
// -----------------------------------------------------------------------------
|
|
114 |
//
|
|
115 |
void CPhoneToneServerPlaybackController::RunL()
|
|
116 |
{
|
|
117 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::RunL <");
|
|
118 |
StopAndDeleteProfilePlayer();
|
|
119 |
PlayDefaultTone();
|
|
120 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::RunL >");
|
|
121 |
}
|
|
122 |
|
|
123 |
// -----------------------------------------------------------------------------
|
|
124 |
// CPhoneToneServerPlaybackController::ConvertVolume
|
|
125 |
// -----------------------------------------------------------------------------
|
|
126 |
//
|
|
127 |
TInt CPhoneToneServerPlaybackController::ConvertVolume( TInt aMaxVolume, TInt aVolume )
|
|
128 |
{
|
|
129 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::ConvertVolume <");
|
|
130 |
TInt result = aMaxVolume * aVolume / KMaxVolumeLevel;
|
|
131 |
if ( aVolume == KMinVolumeLevel && result == 0 )
|
|
132 |
{
|
|
133 |
result = 1;
|
|
134 |
}
|
|
135 |
PHONERINGINGTONE_PRINTF("CPhoneToneServerPlaybackController::ConvertVolume - result(%d)", result);
|
|
136 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::ConvertVolume >");
|
|
137 |
return result;
|
|
138 |
}
|
|
139 |
|
|
140 |
// -----------------------------------------------------------------------------
|
|
141 |
// CPhoneToneServerPlaybackController::PlayProfileTone
|
|
142 |
// -----------------------------------------------------------------------------
|
|
143 |
//
|
|
144 |
void CPhoneToneServerPlaybackController::PlayProfileTone()
|
|
145 |
{
|
|
146 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::PlayProfileTone <");
|
|
147 |
if ( iProfileSamplePlayer )
|
|
148 |
{
|
|
149 |
iProfileSamplePlayer->SetVolume(
|
|
150 |
ConvertVolume( iProfileSamplePlayer->MaxVolume(), iVolume ) );
|
|
151 |
iProfileSamplePlayer->SetRepeats(KPhoneMdaAudioToneRepeatForever,
|
|
152 |
TTimeIntervalMicroSeconds( KPhoneRingingRepeatsTrailPause ));
|
|
153 |
iProfileSamplePlayer->Play();
|
|
154 |
}
|
|
155 |
else if ( iProfileTonePlayer )
|
|
156 |
{
|
|
157 |
iProfileTonePlayer->SetVolume(
|
|
158 |
ConvertVolume( iProfileTonePlayer->MaxVolume(), iVolume ) );
|
|
159 |
iProfileTonePlayer->SetRepeats(KPhoneMdaAudioToneRepeatForever,
|
|
160 |
TTimeIntervalMicroSeconds( KPhoneRingingRepeatsTrailPause ));
|
|
161 |
iProfileTonePlayer->Play();
|
|
162 |
}
|
|
163 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::PlayProfileTone >");
|
|
164 |
}
|
|
165 |
|
|
166 |
// -----------------------------------------------------------------------------
|
|
167 |
// CPhoneToneServerPlaybackController::StopAndDeleteProfilePlayer
|
|
168 |
// -----------------------------------------------------------------------------
|
|
169 |
//
|
|
170 |
void CPhoneToneServerPlaybackController::StopAndDeleteProfilePlayer()
|
|
171 |
{
|
|
172 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::DeleteProfilePlayer() <");
|
|
173 |
if ( iProfileSamplePlayer )
|
|
174 |
{
|
|
175 |
iProfileSamplePlayer->Stop();
|
|
176 |
iProfileSamplePlayer->Close();
|
|
177 |
delete iProfileSamplePlayer;
|
|
178 |
iProfileSamplePlayer = NULL;
|
|
179 |
}
|
|
180 |
else if ( iProfileTonePlayer )
|
|
181 |
{
|
|
182 |
if ( EMdaAudioToneUtilityPlaying == iProfileTonePlayer->State() )
|
|
183 |
{
|
|
184 |
iProfileTonePlayer->CancelPlay();
|
|
185 |
}
|
|
186 |
else if (EMdaAudioToneUtilityNotReady == iProfileTonePlayer->State() )
|
|
187 |
{
|
|
188 |
iProfileTonePlayer->CancelPrepare();
|
|
189 |
}
|
|
190 |
delete iProfileTonePlayer;
|
|
191 |
iProfileTonePlayer = NULL;
|
|
192 |
}
|
|
193 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::DeleteProfilePlayer() >");
|
|
194 |
}
|
|
195 |
|
|
196 |
// -----------------------------------------------------------------------------
|
|
197 |
// CPhoneToneServerPlaybackController::IsRngL
|
|
198 |
// -----------------------------------------------------------------------------
|
|
199 |
//
|
|
200 |
TBool CPhoneToneServerPlaybackController::IsRngL( const TDesC& aFile )
|
|
201 |
{
|
|
202 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::IsRng <");
|
|
203 |
#if defined( __WINS__ )
|
|
204 |
|
|
205 |
TInt index = aFile.Find( KFileListRngMimeType() );
|
|
206 |
|
|
207 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::IsRng >");
|
|
208 |
return ( KErrNotFound != index );
|
|
209 |
|
|
210 |
#else
|
|
211 |
|
|
212 |
RApaLsSession apaLsSession;
|
|
213 |
User::LeaveIfError( apaLsSession.Connect() );
|
|
214 |
CleanupClosePushL( apaLsSession );
|
|
215 |
TUid dummyUid = { 0 };
|
|
216 |
TDataType dataType( dummyUid );
|
|
217 |
User::LeaveIfError(
|
|
218 |
apaLsSession.AppForDocument( aFile, dummyUid, dataType ) );
|
|
219 |
CleanupStack::PopAndDestroy( &apaLsSession );
|
|
220 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::IsRng >");
|
|
221 |
return ( dataType.Des().CompareF( KFileListRngMimeType ) == 0 );
|
|
222 |
|
|
223 |
#endif
|
|
224 |
}
|
|
225 |
|
|
226 |
|
|
227 |
// -----------------------------------------------------------------------------
|
|
228 |
// CPhoneToneServerPlaybackController::MapcInitComplete
|
|
229 |
// -----------------------------------------------------------------------------
|
|
230 |
//
|
|
231 |
void CPhoneToneServerPlaybackController::MapcInitComplete( TInt aError,
|
|
232 |
const TTimeIntervalMicroSeconds& /*aDuration*/ )
|
|
233 |
{
|
|
234 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::MapcInitComplete <");
|
|
235 |
PHONERINGINGTONE_PRINTF("CPhoneToneServerPlaybackController::MapcInitComplete - aError(%d)",aError);
|
|
236 |
if ( !iDefaultPlayerInitialized && !aError )
|
|
237 |
{
|
|
238 |
// This player will be initialized first.
|
|
239 |
iDefaultPlayerInitialized = ETrue;
|
|
240 |
iDefaultPlayer->SetRepeats(KPhoneMdaAudioToneRepeatForever,
|
|
241 |
TTimeIntervalMicroSeconds( KPhoneRingingRepeatsTrailPause ));
|
|
242 |
return;
|
|
243 |
}
|
|
244 |
// Player is initialized at startup
|
|
245 |
if ( EProfileRingingTypeSilent == iRingingType )
|
|
246 |
{
|
|
247 |
return;
|
|
248 |
}
|
|
249 |
|
|
250 |
// Cancel backup player timer.
|
|
251 |
Cancel();
|
|
252 |
|
|
253 |
if ( !aError )
|
|
254 |
{
|
|
255 |
PlayProfileTone();
|
|
256 |
}
|
|
257 |
else if ( iDefaultPlayerInitialized )
|
|
258 |
{
|
|
259 |
PlayDefaultTone();
|
|
260 |
}
|
|
261 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::MapcInitComplete >");
|
|
262 |
}
|
|
263 |
|
|
264 |
// -----------------------------------------------------------------------------
|
|
265 |
// CPhoneToneServerPlaybackController::MatoPrepareComplete
|
|
266 |
// -----------------------------------------------------------------------------
|
|
267 |
//
|
|
268 |
void CPhoneToneServerPlaybackController::MatoPrepareComplete( TInt aError )
|
|
269 |
{
|
|
270 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::MatoPrepareComplete <");
|
|
271 |
PHONERINGINGTONE_PRINTF("CPhoneToneServerPlaybackController::MatoPrepareComplete - aError(%d)",aError);
|
|
272 |
|
|
273 |
// Player is initialized at startup
|
|
274 |
if ( EProfileRingingTypeSilent == iRingingType )
|
|
275 |
{
|
|
276 |
return;
|
|
277 |
}
|
|
278 |
|
|
279 |
// Cancel backup player timer.
|
|
280 |
Cancel();
|
|
281 |
|
|
282 |
if ( !aError )
|
|
283 |
{
|
|
284 |
PlayProfileTone();
|
|
285 |
}
|
|
286 |
else if ( iDefaultPlayerInitialized )
|
|
287 |
{
|
|
288 |
PlayDefaultTone();
|
|
289 |
}
|
|
290 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::MatoPrepareComplete >");
|
|
291 |
}
|
|
292 |
|
|
293 |
// -----------------------------------------------------------------------------
|
|
294 |
// CPhoneToneServerPlaybackController::MapcPlayComplete
|
|
295 |
// -----------------------------------------------------------------------------
|
|
296 |
//
|
|
297 |
void CPhoneToneServerPlaybackController::MapcPlayComplete( TInt aError )
|
|
298 |
{
|
|
299 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::MapcPlayComplete <");
|
|
300 |
PHONERINGINGTONE_PRINTF("CPhoneToneServerPlaybackController::MapcPlayComplete - aError(%d)",aError);
|
|
301 |
#if defined (__WINS__)
|
|
302 |
|
|
303 |
// S^4 onwards MdaAudioPlayer returns -5 (Not Supported)
|
|
304 |
// for audio files in emulator.
|
|
305 |
// Error code is ignored to avoid unwanted situation.
|
|
306 |
if ( aError == KErrNotSupported )
|
|
307 |
{
|
|
308 |
aError = KErrNone;
|
|
309 |
}
|
|
310 |
#endif
|
|
311 |
|
|
312 |
if ( aError && iDefaultPlayerInitialized )
|
|
313 |
{
|
|
314 |
PlayDefaultTone();
|
|
315 |
}
|
|
316 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::MapcPlayComplete >");
|
|
317 |
}
|
|
318 |
|
|
319 |
// -----------------------------------------------------------------------------
|
|
320 |
// CPhoneToneServerPlaybackController::MatoPlayComplete
|
|
321 |
// -----------------------------------------------------------------------------
|
|
322 |
//
|
|
323 |
void CPhoneToneServerPlaybackController::MatoPlayComplete( TInt aError )
|
|
324 |
{
|
|
325 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::MatoPlayComplete <");
|
|
326 |
PHONERINGINGTONE_PRINTF("CPhoneToneServerPlaybackController::MatoPlayComplete - aError(%d)",aError);
|
|
327 |
if ( aError && iDefaultPlayerInitialized )
|
|
328 |
{
|
|
329 |
PlayDefaultTone();
|
|
330 |
}
|
|
331 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::MatoPlayComplete >");
|
|
332 |
}
|
|
333 |
|
|
334 |
// -----------------------------------------------------------------------------
|
|
335 |
// CPhoneToneServerPlaybackController::PlaySilentTone
|
|
336 |
// -----------------------------------------------------------------------------
|
|
337 |
|
|
338 |
void CPhoneToneServerPlaybackController::PlaySilentTone()
|
|
339 |
{
|
|
340 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::PlaySilentTone <");
|
|
341 |
iSilentPlayer->Play();
|
|
342 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::PlaySilentTone >");
|
|
343 |
}
|
|
344 |
|
|
345 |
// -----------------------------------------------------------------------------
|
|
346 |
// CPhoneToneServerPlaybackController::PlayNormalTone
|
|
347 |
// -----------------------------------------------------------------------------
|
|
348 |
//
|
|
349 |
void CPhoneToneServerPlaybackController::PlayNormalToneL(
|
|
350 |
const TFileName& aName,
|
|
351 |
TInt aVolume,
|
|
352 |
TProfileRingingType aType )
|
|
353 |
{
|
|
354 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::PlayNormalTone <");
|
|
355 |
PHONERINGINGTONE_PRINTF3("CPhoneToneServerPlaybackController::PlayNormalTone - aName(%S), aVolume(%d), aType(%d)",&aName, aVolume, aType );
|
|
356 |
|
|
357 |
iVolume = aVolume;
|
|
358 |
iRingingType = aType;
|
|
359 |
|
|
360 |
StopAndDeleteProfilePlayer();
|
|
361 |
Cancel();
|
|
362 |
After( KPhoneMaxRingingWaiting );
|
|
363 |
|
|
364 |
if ( !aName.Length() )
|
|
365 |
{
|
|
366 |
PlayDefaultTone();
|
|
367 |
}
|
|
368 |
// RNG file types have to be played with CMdaAudioToneUtility player.
|
|
369 |
// Otherwise use sample player
|
|
370 |
else if ( IsRngL( aName ) )
|
|
371 |
{
|
|
372 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::PlayNormalTone - toneplayer");
|
|
373 |
iProfileTonePlayer = CMdaAudioToneUtility::NewL( *this );
|
|
374 |
iProfileTonePlayer->PrepareToPlayFileSequence( aName );
|
|
375 |
}
|
|
376 |
else
|
|
377 |
{
|
|
378 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::PlayNormalTone - sampleplayer");
|
|
379 |
iProfileSamplePlayer = CMdaAudioPlayerUtility::NewFilePlayerL(
|
|
380 |
aName,
|
|
381 |
*this,
|
|
382 |
KAudioPriorityPhoneCall,
|
|
383 |
static_cast< TMdaPriorityPreference >( KAudioPrefIncomingCall ));
|
|
384 |
}
|
|
385 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::PlayNormalTone >");
|
|
386 |
}
|
|
387 |
|
|
388 |
// -----------------------------------------------------------------------------
|
|
389 |
// CPhoneToneServerSession::PlayDefaultTone
|
|
390 |
// -----------------------------------------------------------------------------
|
|
391 |
//
|
|
392 |
void CPhoneToneServerPlaybackController::PlayDefaultTone()
|
|
393 |
{
|
|
394 |
Cancel();
|
|
395 |
iDefaultPlayer->SetVolume(
|
|
396 |
ConvertVolume( iDefaultPlayer->MaxVolume(), iVolume ) );
|
|
397 |
iDefaultPlayer->Play();
|
|
398 |
}
|
|
399 |
|
|
400 |
// -----------------------------------------------------------------------------
|
|
401 |
// CPhoneToneServerSession::StopTone
|
|
402 |
// -----------------------------------------------------------------------------
|
|
403 |
//
|
|
404 |
void CPhoneToneServerPlaybackController::StopTone()
|
|
405 |
{
|
|
406 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::StopTone() <");
|
|
407 |
|
|
408 |
Cancel();
|
|
409 |
StopAndDeleteProfilePlayer();
|
|
410 |
|
|
411 |
iDefaultPlayer->Stop();
|
|
412 |
|
|
413 |
iSilentPlayer->CancelPlay();
|
|
414 |
PHONERINGINGTONE_PRINT("CPhoneToneServerPlaybackController::StopTone() >");
|
|
415 |
}
|
|
416 |
|
|
417 |
// End of file
|