1 /* |
|
2 * Copyright (c) 2009-2010 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: |
|
15 * |
|
16 */ |
|
17 #include <cxesoundplayersymbian.h> |
|
18 #include <AudioPreference.h> |
|
19 #include <ProfileEngineSDKCRKeys.h> |
|
20 #include "cxutils.h" |
|
21 #include "cxecameradevicecontrolsymbian.h" |
|
22 #include "cxestate.h" |
|
23 #include "cxesettings.h" |
|
24 |
|
25 |
|
26 const TUint KCxeAudioPriority = KAudioPriorityCameraTone; |
|
27 |
|
28 _LIT(KCxeCaptureSound, "z:\\system\\sounds\\digital\\capture.wav"); |
|
29 _LIT(KCxeVideoStartSound, "z:\\system\\sounds\\digital\\videoStart.wav"); |
|
30 _LIT(KCxeVideoStopSound, "z:\\system\\sounds\\digital\\videoStop.wav"); |
|
31 _LIT(KCxeAutoFocusSound, "z:\\system\\sounds\\digital\\autoFocus.wav"); |
|
32 |
|
33 |
|
34 CxeSoundPlayerSymbian::CxeSoundPlayerSymbian(CaptureSound soundId, |
|
35 CxeSettings &settings) : |
|
36 CxeStateMachine("CxeSoundPlayerSymbian"), |
|
37 mAudioPlayer(NULL), |
|
38 mSoundId(soundId), |
|
39 mUseSound(true), |
|
40 mCaptureSoundForced(false), |
|
41 mSettings(settings) |
|
42 { |
|
43 CX_DEBUG_ENTER_FUNCTION(); |
|
44 |
|
45 checkCaptureSoundSettings(); |
|
46 |
|
47 // connect to setting changed signal in order to monitor |
|
48 // profile warning tone changes |
|
49 connect(&mSettings, |
|
50 SIGNAL(settingValueChanged(long int, unsigned long int, QVariant)), |
|
51 this, SLOT(enableSound(long int, unsigned long int, QVariant))); |
|
52 |
|
53 qRegisterMetaType<CxeSoundPlayerSymbian::State>(); |
|
54 initializeStates(); |
|
55 |
|
56 doOpen(); |
|
57 CX_DEBUG_EXIT_FUNCTION(); |
|
58 } |
|
59 |
|
60 CxeSoundPlayerSymbian::~CxeSoundPlayerSymbian() |
|
61 { |
|
62 CX_DEBUG_ENTER_FUNCTION(); |
|
63 |
|
64 delete mAudioPlayer; |
|
65 |
|
66 CX_DEBUG_EXIT_FUNCTION(); |
|
67 } |
|
68 |
|
69 /*! |
|
70 * Plays the current sound file if soundplayer is in correct state. Once |
|
71 * playing is finished or there is an error playComplete signal is emitted. |
|
72 * \sa playComplete() |
|
73 */ |
|
74 void CxeSoundPlayerSymbian::play() |
|
75 { |
|
76 CX_DEBUG_ENTER_FUNCTION(); |
|
77 CX_DEBUG(("CxeSoundPlayerSymbian::play mSoundId: %d, state: %d", mSoundId, state())); |
|
78 |
|
79 // Only play the capture sound if CMdaAudioPlayerUtility is initialised |
|
80 if (state() == Ready) { |
|
81 |
|
82 if (mUseSound) { |
|
83 //! @todo: Define & implement what to do, when sound is already playing. |
|
84 // Important for sequence mode. |
|
85 setState(Playing); |
|
86 mAudioPlayer->Play(); |
|
87 } else { |
|
88 CX_DEBUG(("CxeSoundPlayerSymbian::play capture sounds turned off")); |
|
89 |
|
90 // sounds are off and we don't play the sound, |
|
91 // act as the sound has been played |
|
92 emit playComplete(KErrNone); |
|
93 } |
|
94 |
|
95 } else if( state() == NotReady ) { |
|
96 // Here sound loading has failed. |
|
97 // Emit signal with error code. |
|
98 emit playComplete(KErrNotReady); |
|
99 } |
|
100 |
|
101 CX_DEBUG_EXIT_FUNCTION(); |
|
102 } |
|
103 |
|
104 |
|
105 void CxeSoundPlayerSymbian::MapcInitComplete(TInt aStatus, const TTimeIntervalMicroSeconds &/*aDuration*/) |
|
106 { |
|
107 CX_DEBUG_IN_FUNCTION(); |
|
108 CX_DEBUG(("MapcInitComplete aStatus: %d", aStatus)); |
|
109 |
|
110 if (aStatus) { |
|
111 setState(NotReady); |
|
112 } else { |
|
113 setState(Ready); |
|
114 } |
|
115 } |
|
116 |
|
117 void CxeSoundPlayerSymbian::MapcPlayComplete(TInt aStatus) |
|
118 { |
|
119 CX_DEBUG_IN_FUNCTION(); |
|
120 CX_DEBUG(("MapcPlayComplete aStatus: %d", aStatus)); |
|
121 |
|
122 if (aStatus != KErrNone && aStatus != KErrInUse) { |
|
123 // An error occurred. Close and reopen sound player to be sure. |
|
124 mAudioPlayer->Close(); |
|
125 setState(NotReady); |
|
126 doOpen(); |
|
127 } else { |
|
128 setState(Ready); |
|
129 } |
|
130 |
|
131 emit playComplete(aStatus); |
|
132 } |
|
133 |
|
134 void CxeSoundPlayerSymbian::doOpen() |
|
135 { |
|
136 CX_DEBUG(("Calling OpenFileL for sound %d", mSoundId)); |
|
137 TInt error = KErrNone; |
|
138 const TDesC* filename = 0; |
|
139 switch (mSoundId) { |
|
140 case StillCapture: |
|
141 filename = &KCxeCaptureSound; |
|
142 break; |
|
143 case VideoCaptureStart: |
|
144 filename = &KCxeVideoStartSound; |
|
145 break; |
|
146 case VideoCaptureStop: |
|
147 filename = &KCxeVideoStopSound; |
|
148 break; |
|
149 case AutoFocus: |
|
150 filename = &KCxeAutoFocusSound; |
|
151 break; |
|
152 default: |
|
153 // sound is not known |
|
154 mSoundId = Unknown; |
|
155 break; |
|
156 } |
|
157 |
|
158 if (filename) { |
|
159 if (mAudioPlayer) { |
|
160 delete mAudioPlayer; |
|
161 mAudioPlayer = 0; |
|
162 } |
|
163 TRAP(error, mAudioPlayer = |
|
164 CMdaAudioPlayerUtility::NewFilePlayerL(*filename, |
|
165 *this, KCxeAudioPriority, |
|
166 TMdaPriorityPreference(KAudioPrefCamera))); |
|
167 if (!error) { |
|
168 setState(Opening); |
|
169 } else { |
|
170 setState(NotReady); |
|
171 } |
|
172 } else { |
|
173 setState(NotReady); |
|
174 } |
|
175 } |
|
176 |
|
177 |
|
178 void CxeSoundPlayerSymbian::handleStateChanged(int newStateId, CxeError::Id error) |
|
179 { |
|
180 Q_UNUSED(newStateId); |
|
181 Q_UNUSED(error); |
|
182 // No implementation needed, because state is not visible outside of this class |
|
183 } |
|
184 |
|
185 /*! |
|
186 * Returns the current sound player state. |
|
187 * \return Current state |
|
188 */ |
|
189 CxeSoundPlayerSymbian::State CxeSoundPlayerSymbian::state() const |
|
190 { |
|
191 return static_cast<State>(stateId()); |
|
192 } |
|
193 |
|
194 /*! |
|
195 * Initialize CxeStateMachine. |
|
196 */ |
|
197 void CxeSoundPlayerSymbian::initializeStates() |
|
198 { |
|
199 // addState(id, name, allowed next states) |
|
200 addState(new CxeState(NotReady, "NotReady", Opening)); |
|
201 addState(new CxeState(Opening, "Opening", NotReady | Ready)); |
|
202 addState(new CxeState(Ready, "Ready", Playing | Opening | NotReady)); |
|
203 addState(new CxeState(Playing, "Playing", Ready | Opening | NotReady)); |
|
204 |
|
205 setInitialState(NotReady); |
|
206 } |
|
207 |
|
208 /*! |
|
209 * Enables or disables the capture sound. If capture sound is forced to |
|
210 * be always on, then the capture sound cannot be disabled. |
|
211 * |
|
212 * \param uid UID of the changed setting |
|
213 * \param key Key of the changed setting |
|
214 * \param value New setting value |
|
215 */ |
|
216 void CxeSoundPlayerSymbian::enableSound(long int uid, unsigned long int key, QVariant value) |
|
217 { |
|
218 |
|
219 // selftimer is only interested in warning tones |
|
220 if (uid == KCRUidProfileEngine.iUid && key == KProEngActiveWarningTones) { |
|
221 CX_DEBUG_IN_FUNCTION(); |
|
222 // possible values are: |
|
223 // 0 -> warning tones off |
|
224 // 1 -> warning tones on |
|
225 bool warningTonesEnabled = (value.toInt() == 1); |
|
226 |
|
227 // update sound |
|
228 mUseSound = mCaptureSoundForced || warningTonesEnabled; |
|
229 } |
|
230 |
|
231 CX_DEBUG(("CxeSoundPlayerSymbian::enableSound <> Use sound [%d]", |
|
232 mUseSound)); |
|
233 } |
|
234 |
|
235 /*! |
|
236 * Checks the initial capture sound settings based on profile warning tones |
|
237 * and whether the capture sound is forced to be always on. Connects settings |
|
238 * signal for capture sounds changes to enableCaptureSound slot. |
|
239 * |
|
240 * \sa enableCaptureSound() |
|
241 */ |
|
242 void CxeSoundPlayerSymbian::checkCaptureSoundSettings() |
|
243 { |
|
244 |
|
245 CX_DEBUG_ENTER_FUNCTION(); |
|
246 |
|
247 QVariant value(0); |
|
248 |
|
249 // get current profile setting for using camerasound |
|
250 // camera sound follows warning tone setting |
|
251 unsigned long int key = KProEngActiveWarningTones; |
|
252 long int uid = KCRUidProfileEngine.iUid; |
|
253 mSettings.get(uid, key, Cxe::Repository, value); |
|
254 |
|
255 // possible values are: |
|
256 // 0 -> warning tones off |
|
257 // 1 -> warning tones on |
|
258 bool warningTonesEnabled = (value.toInt() == 1); |
|
259 CX_DEBUG(("Warning tones enabled [%d]", value.toInt())); |
|
260 |
|
261 // check whether capture sound is forced or not |
|
262 mCaptureSoundForced = mSettings.get<bool>(CxeSettingIds::CAPTURE_SOUND_ALWAYS_ON, false); |
|
263 CX_DEBUG(("Capture sound forced [%d]", mCaptureSoundForced)); |
|
264 |
|
265 // use sound if forced on or warningtones are enabled |
|
266 mUseSound = mCaptureSoundForced || warningTonesEnabled; |
|
267 CX_DEBUG(("Use sound [%d]", mUseSound)); |
|
268 |
|
269 CX_DEBUG_EXIT_FUNCTION(); |
|
270 } |
|
271 |
|
272 |
|
273 // end of file |
|
274 |
|