1 /* |
|
2 * Copyright (c) 2007-2008 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: Tone Wrapper implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <mdaaudiotoneplayer.h> |
|
21 #include <AudioPreference.h> |
|
22 |
|
23 #include "CamPanic.h" |
|
24 #include "camlogging.h" |
|
25 #include "mcamplayerobserver.h" |
|
26 #include "camtoneplayerwrapper.h" |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 // =========================================================================== |
|
32 // public constructors and destructor |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // NewL <<static>> |
|
36 // |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 CCamTonePlayerWrapper* |
|
40 CCamTonePlayerWrapper::NewL( MCamPlayerObserver& aObserver ) |
|
41 { |
|
42 CCamTonePlayerWrapper* self = |
|
43 new (ELeave) CCamTonePlayerWrapper( aObserver ); |
|
44 |
|
45 CleanupStack::PushL( self ); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop( self ); |
|
48 |
|
49 return self; |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // destructor <<virtual>> |
|
54 // |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 CCamTonePlayerWrapper::~CCamTonePlayerWrapper() |
|
58 { |
|
59 CancelPlay(); |
|
60 |
|
61 delete iTone; |
|
62 iTone = NULL; |
|
63 } |
|
64 |
|
65 |
|
66 // =========================================================================== |
|
67 // from MMdaAudioToneObserver |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // MatoPrepareComplete <<virtual>> |
|
71 // |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 void |
|
75 CCamTonePlayerWrapper::MatoPrepareComplete( TInt aStatus ) |
|
76 { |
|
77 PRINT( _L("Camera => CCamTonePlayerWrapper::MatoPrepareComplete") ); |
|
78 if( KErrNone == aStatus ) |
|
79 { |
|
80 iState = CCamTonePlayerWrapper::EPlaying; |
|
81 iTone->Play(); |
|
82 #ifdef __WINSCW__ |
|
83 // The tone player does not give a callback on the emulator. |
|
84 // Emulate a callback here. |
|
85 MatoPlayComplete( KErrNone ); |
|
86 #endif // __WINSCW__ |
|
87 } |
|
88 else if( iCallback ) |
|
89 { |
|
90 NotifyPlayComplete( aStatus ); |
|
91 } |
|
92 else |
|
93 { |
|
94 // No action |
|
95 } |
|
96 |
|
97 PRINT( _L("Camera <= CCamTonePlayerWrapper::MatoPrepareComplete") ); |
|
98 } |
|
99 |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // MatoPlayComplete <<virtual>> |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 void |
|
106 CCamTonePlayerWrapper::MatoPlayComplete( TInt aStatus ) |
|
107 { |
|
108 NotifyPlayComplete( aStatus ); |
|
109 } |
|
110 |
|
111 |
|
112 |
|
113 // =========================================================================== |
|
114 // other public |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // PlayTone |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 void |
|
121 CCamTonePlayerWrapper::PlayTone( TInt aToneInHz, |
|
122 TInt aLengthInUs, |
|
123 TReal32 aVolumeInPercent, |
|
124 TBool aCallback ) |
|
125 { |
|
126 PRINT2( _L("Camera => CCamTonePlayerWrapper::PlayTone, callback:%d iState[%s]"), |
|
127 aCallback, |
|
128 KCamTonePlayerWrapperStateNames[iState] ); |
|
129 |
|
130 iCallback = aCallback; |
|
131 |
|
132 switch( iState ) |
|
133 { |
|
134 // --------------------------------- |
|
135 case CCamTonePlayerWrapper::EIdle: |
|
136 { |
|
137 iState = CCamTonePlayerWrapper::EInitializing; |
|
138 iTone->SetVolume( aVolumeInPercent * iTone->MaxVolume() ); |
|
139 iTone->PrepareToPlayTone( aToneInHz, aLengthInUs ); |
|
140 |
|
141 break; |
|
142 } |
|
143 // --------------------------------- |
|
144 case CCamTonePlayerWrapper::EInitializing: |
|
145 case CCamTonePlayerWrapper::EPlaying: |
|
146 { |
|
147 // Do notification, if asked. |
|
148 // This play request is simply skipped, |
|
149 // as there's tone playing on the way right now. |
|
150 if( aCallback ) |
|
151 { |
|
152 iObserver.PlayComplete( KErrInUse, -1 ); //iState-1 is another suggestion. |
|
153 } |
|
154 break; |
|
155 } |
|
156 default: |
|
157 CamPanic( ECamPanicInvalidState ); |
|
158 break; |
|
159 // --------------------------------- |
|
160 } |
|
161 |
|
162 PRINT( _L("Camera <= CCamAudioPlayerWrapper::Play") ); |
|
163 } |
|
164 |
|
165 |
|
166 // --------------------------------------------------------------------------- |
|
167 // CancelPlay |
|
168 // --------------------------------------------------------------------------- |
|
169 // |
|
170 void |
|
171 CCamTonePlayerWrapper::CancelPlay() |
|
172 { |
|
173 if( iTone ) |
|
174 { |
|
175 switch( iState ) |
|
176 { |
|
177 case CCamTonePlayerWrapper::EPlaying: |
|
178 iTone->CancelPlay(); |
|
179 // Because of the observer callback function MMdaAudioToneObserver::MatoPrepareComplete() is not called, |
|
180 // so set state to idle directly |
|
181 iState = CCamTonePlayerWrapper::EIdle; |
|
182 break; |
|
183 case CCamTonePlayerWrapper::EInitializing: |
|
184 iTone->CancelPrepare(); |
|
185 // Because of the observer callback function MMdaAudioToneObserver::MatoPrepareComplete() is not called, |
|
186 // so set state to idle directly |
|
187 iState = CCamTonePlayerWrapper::EIdle; |
|
188 break; |
|
189 case CCamTonePlayerWrapper::EIdle: |
|
190 default: |
|
191 break; |
|
192 } |
|
193 } |
|
194 } |
|
195 |
|
196 |
|
197 |
|
198 // =========================================================================== |
|
199 // other private |
|
200 |
|
201 // --------------------------------------------------------------------------- |
|
202 // NotifyPlayComplete |
|
203 // --------------------------------------------------------------------------- |
|
204 // |
|
205 void |
|
206 CCamTonePlayerWrapper::NotifyPlayComplete( TInt aStatus ) |
|
207 { |
|
208 PRINT( _L("Camera => CCamTonePlayerWrapper::NotifyPlayComplete") ); |
|
209 |
|
210 // Play is complete, return to idle state. |
|
211 iState = CCamTonePlayerWrapper::EIdle; |
|
212 |
|
213 // Notify observer received status. |
|
214 // Sound id is not usable here. |
|
215 if( iCallback ) |
|
216 iObserver.PlayComplete( aStatus, -1 ); |
|
217 |
|
218 PRINT( _L("Camera <= CCamTonePlayerWrapper::NotifyPlayComplete") ); |
|
219 } |
|
220 |
|
221 |
|
222 |
|
223 // =========================================================================== |
|
224 // private constructors |
|
225 |
|
226 // --------------------------------------------------------------------------- |
|
227 // ConstructL |
|
228 // --------------------------------------------------------------------------- |
|
229 // |
|
230 void |
|
231 CCamTonePlayerWrapper::ConstructL() |
|
232 { |
|
233 iTone = CMdaAudioToneUtility::NewL( |
|
234 *this, |
|
235 NULL, |
|
236 KAudioPriorityCameraTone, |
|
237 TMdaPriorityPreference( KAudioPrefCamera ) ); |
|
238 } |
|
239 |
|
240 |
|
241 // --------------------------------------------------------------------------- |
|
242 // constructor |
|
243 // --------------------------------------------------------------------------- |
|
244 // |
|
245 CCamTonePlayerWrapper |
|
246 ::CCamTonePlayerWrapper( MCamPlayerObserver& aObserver ) |
|
247 : iObserver ( aObserver ), |
|
248 iTone ( NULL ), |
|
249 iState ( CCamTonePlayerWrapper::EIdle ), |
|
250 iCallback ( EFalse ) |
|
251 { |
|
252 } |
|
253 |
|
254 // =========================================================================== |
|
255 // end of file |
|