54
|
1 |
/*
|
|
2 |
* Copyright (c) 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 Wrapper for Audio Player Utility
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// ===========================================================================
|
|
20 |
// includes
|
|
21 |
#include <mdaaudiosampleplayer.h>
|
|
22 |
#include <AudioPreference.h>
|
|
23 |
|
|
24 |
#include "Cam.hrh"
|
|
25 |
#include "CamPanic.h"
|
|
26 |
#include "camlogging.h"
|
|
27 |
#include "CamUtility.h" // for resource id's of sounds
|
|
28 |
#include "mcamplayerobserver.h"
|
|
29 |
#include "camaudioplayerwrapper.h"
|
|
30 |
#include "CamPerformance.h"
|
|
31 |
#include "OstTraceDefinitions.h"
|
|
32 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
33 |
#include "camaudioplayerwrapperTraces.h"
|
|
34 |
#endif
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
// ===========================================================================
|
|
39 |
// Constants
|
|
40 |
const TReal32 KCamSoundVol = 0.75f;
|
|
41 |
// Migrated directly from old sound player.
|
|
42 |
#ifndef __WINSCW__
|
|
43 |
static const TUint KAudioPriority = KAudioPriorityCameraTone;
|
|
44 |
#else
|
|
45 |
static const TUint KAudioPriority = KAudioPriorityVideoRecording;
|
|
46 |
#endif // __WINSCW__
|
|
47 |
|
|
48 |
|
|
49 |
// ===========================================================================
|
|
50 |
// public constructors and destructor
|
|
51 |
|
|
52 |
// ---------------------------------------------------------------------------
|
|
53 |
// NewL <<static>>
|
|
54 |
// ---------------------------------------------------------------------------
|
|
55 |
//
|
|
56 |
CCamAudioPlayerWrapper*
|
|
57 |
CCamAudioPlayerWrapper::NewL( MCamPlayerObserver& aObserver,
|
|
58 |
TInt aSoundId )
|
|
59 |
{
|
|
60 |
PRINT( _L("Camera => CCamAudioPlayerWrapper::NewL()") );
|
|
61 |
CCamAudioPlayerWrapper* self =
|
|
62 |
new (ELeave) CCamAudioPlayerWrapper( aObserver, aSoundId );
|
|
63 |
|
|
64 |
CleanupStack::PushL( self );
|
|
65 |
self->ConstructL();
|
|
66 |
CleanupStack::Pop( self );
|
|
67 |
|
|
68 |
PRINT( _L("Camera <= CCamAudioPlayerWrapper::NewL()") );
|
|
69 |
return self;
|
|
70 |
}
|
|
71 |
|
|
72 |
// ---------------------------------------------------------------------------
|
|
73 |
// destructor <<virtual>>
|
|
74 |
// ---------------------------------------------------------------------------
|
|
75 |
//
|
|
76 |
CCamAudioPlayerWrapper::~CCamAudioPlayerWrapper()
|
|
77 |
{
|
|
78 |
if( iPlayer )
|
|
79 |
{
|
|
80 |
iPlayer->Stop();
|
|
81 |
iPlayer->Close();
|
|
82 |
delete iPlayer;
|
|
83 |
iPlayer = NULL;
|
|
84 |
}
|
|
85 |
}
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
// ===========================================================================
|
|
90 |
// from CCamPlayerWrapperBase
|
|
91 |
|
|
92 |
// ---------------------------------------------------------------------------
|
|
93 |
// Id <<virtual>><<const>>
|
|
94 |
// ---------------------------------------------------------------------------
|
|
95 |
//
|
|
96 |
TInt
|
|
97 |
CCamAudioPlayerWrapper::Id() const
|
|
98 |
{
|
|
99 |
return iSoundId;
|
|
100 |
}
|
|
101 |
|
|
102 |
// ---------------------------------------------------------------------------
|
|
103 |
// IsEqualSound <<virtual>><<const>>
|
|
104 |
//
|
|
105 |
// Compare if two sounds are equal.
|
|
106 |
// If the ids or filenames match, the sounds are considered to be equal.
|
|
107 |
// ---------------------------------------------------------------------------
|
|
108 |
//
|
|
109 |
TBool
|
|
110 |
CCamAudioPlayerWrapper::IsEqualSound( TInt aSoundId ) const
|
|
111 |
{
|
|
112 |
TInt eq( EFalse );
|
|
113 |
TRAP_IGNORE(
|
|
114 |
{
|
|
115 |
eq = aSoundId == iSoundId
|
|
116 |
|| MapSoundId2FilenameL( aSoundId ) == MapSoundId2FilenameL( iSoundId );
|
|
117 |
});
|
|
118 |
return eq;
|
|
119 |
}
|
|
120 |
|
|
121 |
|
|
122 |
// ---------------------------------------------------------------------------
|
|
123 |
// Play <<virtual>>
|
|
124 |
// ---------------------------------------------------------------------------
|
|
125 |
//
|
|
126 |
void
|
|
127 |
CCamAudioPlayerWrapper::Play( TBool aCallback )
|
|
128 |
{
|
|
129 |
PRINT2( _L("Camera => CCamAudioPlayerWrapper::Play, callback:%d iState[%s]"),
|
|
130 |
aCallback,
|
|
131 |
KCamAudioPlayerWrapperStateNames[iState] );
|
|
132 |
|
|
133 |
switch( iState )
|
|
134 |
{
|
|
135 |
case CCamAudioPlayerWrapper::EReady:
|
|
136 |
iPlayRequested = EFalse;
|
|
137 |
iState = CCamAudioPlayerWrapper::EPlaying;
|
|
138 |
iCallback = aCallback;
|
|
139 |
iPlayer->SetVolume( static_cast<TInt>( iPlayer->MaxVolume()* KCamSoundVol ) );
|
|
140 |
iPlayer->Play();
|
|
141 |
break;
|
|
142 |
|
|
143 |
case CCamAudioPlayerWrapper::EInitializing:
|
|
144 |
iPlayRequested = ETrue;
|
|
145 |
iCallback = aCallback;
|
|
146 |
break;
|
|
147 |
|
|
148 |
case CCamAudioPlayerWrapper::ECorrupt:
|
|
149 |
// Notify observer rigth away as init has failed.
|
|
150 |
iCallback = aCallback;
|
|
151 |
NotifyPlayComplete( KErrCorrupt );
|
|
152 |
break;
|
|
153 |
|
|
154 |
case CCamAudioPlayerWrapper::EPlaying:
|
|
155 |
PRINT( _L("Camera <> WARNING: Still playing old sound, need to stop early") );
|
|
156 |
iPlayer->Stop();
|
|
157 |
// Notify observer that playing was interrupted (if callback was requested for previous play).
|
|
158 |
// Sets state to idle so that we are ready to play again.
|
|
159 |
NotifyPlayComplete( KErrAbort );
|
|
160 |
// Now we can repeat the call as the state is right.
|
|
161 |
Play( aCallback );
|
|
162 |
break;
|
|
163 |
case CCamAudioPlayerWrapper::EIdle:
|
|
164 |
default:
|
|
165 |
//Set state and ignore otherwise...
|
|
166 |
PRINT( _L("Camera <> CCamAudioPlayerWrapper::Play invalid state") );
|
|
167 |
iState = CCamAudioPlayerWrapper::ECorrupt;
|
|
168 |
break;
|
|
169 |
}
|
|
170 |
|
|
171 |
PRINT( _L("Camera <= CCamAudioPlayerWrapper::Play") );
|
|
172 |
}
|
|
173 |
|
|
174 |
|
|
175 |
// ---------------------------------------------------------------------------
|
|
176 |
// CancelPlay <<virtual>>
|
|
177 |
// ---------------------------------------------------------------------------
|
|
178 |
//
|
|
179 |
void
|
|
180 |
CCamAudioPlayerWrapper::CancelPlay()
|
|
181 |
{
|
|
182 |
PRINT1( _L("Camera => CCamAudioPlayerWrapper::CancelPlay, id:%d"), iSoundId );
|
|
183 |
switch( iState )
|
|
184 |
{
|
|
185 |
case CCamAudioPlayerWrapper::EPlaying:
|
|
186 |
PRINT( _L("Camera <> CCamAudioPlayerWrapper::CancelPlay .. iState == EPlaying, call Stop()..") );
|
|
187 |
iPlayer->Stop();
|
|
188 |
NotifyPlayComplete( KErrAbort );
|
|
189 |
break;
|
|
190 |
default:
|
|
191 |
break;
|
|
192 |
}
|
|
193 |
|
|
194 |
// Make sure pending Play() is cancelled.
|
|
195 |
iPlayRequested = EFalse;
|
|
196 |
PRINT( _L("Camera <= CCamAudioPlayerWrapper::CancelPlay") );
|
|
197 |
}
|
|
198 |
|
|
199 |
|
|
200 |
// ===========================================================================
|
|
201 |
// from MMdaAudioPlayerCallback
|
|
202 |
|
|
203 |
// ---------------------------------------------------------------------------
|
|
204 |
// MapcInitComplete <<virtual>>
|
|
205 |
// ---------------------------------------------------------------------------
|
|
206 |
//
|
|
207 |
void
|
|
208 |
CCamAudioPlayerWrapper
|
|
209 |
::MapcInitComplete( TInt aStatus,
|
|
210 |
const TTimeIntervalMicroSeconds& /*aDuration*/ )
|
|
211 |
{
|
|
212 |
PRINT2( _L("Camera => CCamAudioPlayerWrapper::MapcInitComplete, id:%d status:%d"), iSoundId, aStatus );
|
|
213 |
if( KErrNone != aStatus )
|
|
214 |
{
|
|
215 |
// If we encounter an error in init phase,
|
|
216 |
// we'll notify observer once Play gets called.
|
|
217 |
iState = CCamAudioPlayerWrapper::ECorrupt;
|
|
218 |
}
|
|
219 |
else
|
|
220 |
{
|
|
221 |
iState = CCamAudioPlayerWrapper::EReady;
|
|
222 |
}
|
|
223 |
|
|
224 |
// If play has been called before init has finished
|
|
225 |
// try to play now. If we had an error in init,
|
|
226 |
// Play() will handle this based on iState.
|
|
227 |
if( iPlayRequested )
|
|
228 |
{
|
|
229 |
Play( iCallback );
|
|
230 |
}
|
|
231 |
PRINT( _L("Camera <= CCamAudioPlayerWrapper::MapcInitComplete") );
|
|
232 |
}
|
|
233 |
|
|
234 |
// ---------------------------------------------------------------------------
|
|
235 |
// MapcPlayComplete <<virtual>>
|
|
236 |
// ---------------------------------------------------------------------------
|
|
237 |
//
|
|
238 |
void
|
|
239 |
CCamAudioPlayerWrapper::MapcPlayComplete( TInt aStatus )
|
|
240 |
{
|
|
241 |
NotifyPlayComplete( aStatus );
|
|
242 |
}
|
|
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
// ===========================================================================
|
|
248 |
// other public
|
|
249 |
|
|
250 |
// ---------------------------------------------------------------------------
|
|
251 |
// MapSoundId2FilenameL <<static>>
|
|
252 |
// ---------------------------------------------------------------------------
|
|
253 |
//
|
|
254 |
TPtrC
|
|
255 |
CCamAudioPlayerWrapper::MapSoundId2FilenameL( TInt aSoundId )
|
|
256 |
{
|
|
257 |
PRINT1( _L("Camera => CCamAudioPlayerWrapper::MapSoundId2FilenameL, id:%d"), aSoundId );
|
|
258 |
|
|
259 |
TPtrC filename( KNullDesC );
|
|
260 |
|
|
261 |
switch( aSoundId )
|
|
262 |
{
|
|
263 |
case ECamVideoStartSoundId: filename.Set( KCamVideoStartTone ); break;
|
|
264 |
case ECamVideoStopSoundId: filename.Set( KCamVideoStopTone ); break;
|
|
265 |
case ECamVideoPauseSoundId: filename.Set( KCamVideoPauseTone ); break;
|
|
266 |
case ECamVideoResumeSoundId: filename.Set( KCamVideoStartTone ); break;
|
|
267 |
case ECamAutoFocusFailed: User::Leave( KErrNotSupported ); break;
|
|
268 |
case ECamAutoFocusComplete: filename.Set( KCamAutoFocusComplete ); break;
|
|
269 |
case ECamStillCaptureSoundId1: filename.Set( KCamCaptureTone1 ); break;
|
|
270 |
case ECamStillCaptureSoundId2: filename.Set( KCamCaptureTone2 ); break;
|
|
271 |
case ECamStillCaptureSoundId3: filename.Set( KCamCaptureTone3 ); break;
|
|
272 |
case ECamStillCaptureSoundId4: filename.Set( KCamCaptureTone4 ); break;
|
|
273 |
case ECamBurstCaptureSoundId1: filename.Set( KCamBurstCaptureTone1 ); break;
|
|
274 |
case ECamBurstCaptureSoundId2: filename.Set( KCamBurstCaptureTone2 ); break;
|
|
275 |
case ECamBurstCaptureSoundId3: filename.Set( KCamBurstCaptureTone3 ); break;
|
|
276 |
case ECamBurstCaptureSoundId4: filename.Set( KCamBurstCaptureTone4 ); break;
|
|
277 |
|
|
278 |
case ECamSelfTimerSoundId: filename.Set( KCamSelfTimerTone ); break;
|
|
279 |
|
|
280 |
default:
|
|
281 |
__ASSERT_DEBUG( EFalse, CamPanic( ECamPanicNotSupported ) );
|
|
282 |
break;
|
|
283 |
}
|
|
284 |
|
|
285 |
PRINT1( _L("Camera <= CCamAudioPlayerWrapper::MapSoundId2FilenameL, return [%S]"), &filename );
|
|
286 |
return filename;
|
|
287 |
}
|
|
288 |
|
|
289 |
|
|
290 |
|
|
291 |
// ===========================================================================
|
|
292 |
// other private
|
|
293 |
|
|
294 |
// ---------------------------------------------------------------------------
|
|
295 |
// InitL
|
|
296 |
// ---------------------------------------------------------------------------
|
|
297 |
//
|
|
298 |
void
|
|
299 |
CCamAudioPlayerWrapper::InitL()
|
|
300 |
{
|
|
301 |
PRINT( _L("Camera => CCamAudioPlayerWrapper::InitL") );
|
|
302 |
if( CCamAudioPlayerWrapper::EIdle == iState )
|
|
303 |
{
|
|
304 |
iState = CCamAudioPlayerWrapper::EInitializing;
|
|
305 |
// Our process uses multiple players. Ensure they
|
|
306 |
// (or their internal controllers) share the same
|
|
307 |
// heap so we don't run out of memory chunks.
|
|
308 |
iPlayer->UseSharedHeap();
|
|
309 |
iPlayer->OpenFileL( MapSoundId2FilenameL( iSoundId ) );
|
|
310 |
}
|
|
311 |
else
|
|
312 |
{
|
|
313 |
CamPanic( ECamPanicInvalidState );
|
|
314 |
PRINT( _L("Camera <> CCamAudioPlayerWrapper::InitL invalid state") );
|
|
315 |
iState = CCamAudioPlayerWrapper::ECorrupt;
|
|
316 |
User::Leave(KErrCorrupt);
|
|
317 |
}
|
|
318 |
PRINT( _L("Camera <= CCamAudioPlayerWrapper::InitL") );
|
|
319 |
}
|
|
320 |
|
|
321 |
|
|
322 |
// ---------------------------------------------------------------------------
|
|
323 |
// NotifyPlayComplete
|
|
324 |
// ---------------------------------------------------------------------------
|
|
325 |
//
|
|
326 |
void
|
|
327 |
CCamAudioPlayerWrapper::NotifyPlayComplete( TInt aStatus )
|
|
328 |
{
|
|
329 |
PRINT1( _L("Camera => CCamAudioPlayerWrapper::NotifyPlayComplete, status:%d"), aStatus );
|
|
330 |
switch( iState )
|
|
331 |
{
|
|
332 |
// Problem initializing.
|
|
333 |
// Init is not tried again as it could slow down the capturing.
|
|
334 |
case CCamAudioPlayerWrapper::ECorrupt:
|
|
335 |
break;
|
|
336 |
|
|
337 |
// Normal case where the playing has completed.
|
|
338 |
// Set state to EReady to indicate we are ready
|
|
339 |
// for new play request.
|
|
340 |
case CCamAudioPlayerWrapper::EPlaying:
|
|
341 |
iState = CCamAudioPlayerWrapper::EReady;
|
|
342 |
break;
|
|
343 |
|
|
344 |
// Other states not allowed here.
|
|
345 |
default:
|
|
346 |
// Make this player ready that we can play new sound.
|
|
347 |
PRINT( _L("Camera <> CCamAudioPlayerWrapper::NotifyPlayComplete invalid state") );
|
|
348 |
iState = CCamAudioPlayerWrapper::EReady;
|
|
349 |
break;
|
|
350 |
}
|
|
351 |
|
|
352 |
// Clear flag just in case.
|
|
353 |
iPlayRequested = EFalse;
|
|
354 |
|
|
355 |
OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAUDIOPLAYERWRAPPER_NOTIFYPLAYCOMPLETE, "e_CAM_APP_CAPTURE_SOUND_PLAY 0" ); //CCORAPP_CAPTURE_SOUND_PLAY_END
|
|
356 |
|
|
357 |
// Notify observer with our sound id and received status.
|
|
358 |
if( iCallback )
|
|
359 |
iObserver.PlayComplete( aStatus, iSoundId );
|
|
360 |
|
|
361 |
PRINT( _L("Camera <= CCamAudioPlayerWrapper::NotifyPlayComplete") );
|
|
362 |
}
|
|
363 |
|
|
364 |
// ===========================================================================
|
|
365 |
// private constructors
|
|
366 |
|
|
367 |
// ---------------------------------------------------------------------------
|
|
368 |
// ConstructL
|
|
369 |
// ---------------------------------------------------------------------------
|
|
370 |
//
|
|
371 |
void
|
|
372 |
CCamAudioPlayerWrapper::ConstructL()
|
|
373 |
{
|
|
374 |
PRINT( _L("Camera => CCamAudioPlayerWrapper::ConstructL()") );
|
|
375 |
iPlayer = CMdaAudioPlayerUtility::NewL(
|
|
376 |
*this,
|
|
377 |
KAudioPriority ,
|
|
378 |
TMdaPriorityPreference( KAudioPrefCamera ) );
|
|
379 |
|
|
380 |
InitL();
|
|
381 |
PRINT( _L("Camera <= CCamAudioPlayerWrapper::ConstructL()") );
|
|
382 |
}
|
|
383 |
|
|
384 |
|
|
385 |
// ---------------------------------------------------------------------------
|
|
386 |
// C++ constructor
|
|
387 |
// ---------------------------------------------------------------------------
|
|
388 |
//
|
|
389 |
CCamAudioPlayerWrapper
|
|
390 |
::CCamAudioPlayerWrapper( MCamPlayerObserver& aObserver,
|
|
391 |
TInt aSoundId )
|
|
392 |
: iObserver ( aObserver ),
|
|
393 |
iSoundId ( aSoundId ),
|
|
394 |
iPlayer ( NULL ),
|
|
395 |
iState ( CCamAudioPlayerWrapper::EIdle ),
|
|
396 |
iPlayRequested( EFalse ),
|
|
397 |
iCallback ( EFalse )
|
|
398 |
{
|
|
399 |
}
|
|
400 |
|
|
401 |
// ===========================================================================
|
|
402 |
// end of file
|
|
403 |
|