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: |
|
15 * |
|
16 */ |
|
17 #include "cxefakeengine.h" |
|
18 #include "cxecameradevicecontrolsymbian.h" |
|
19 #include "cxefakestillcapturecontrol.h" |
|
20 #include "cxevideocapturecontrolsymbian.h" |
|
21 #include "cxestillcapturecontrolsymbian.h" |
|
22 #include "cxefakeviewfindercontrol.h" |
|
23 #include "cxezoomcontrolsymbian.h" |
|
24 #include "cxutils.h" |
|
25 #include "cxesettingsimp.h" |
|
26 #include "cxefeaturemanagerimp.h" |
|
27 #include "cxesettingsmodel.h" |
|
28 #include "cxesoundplayersymbian.h" |
|
29 #include "cxefakeautofocuscontrol.h" |
|
30 |
|
31 // Member Functions |
|
32 |
|
33 CxeFakeEngine::CxeFakeEngine() |
|
34 : mViewfinderControl( NULL ), |
|
35 mFakeStillCaptureControl( NULL ), |
|
36 mVideoCaptureControl( NULL ), |
|
37 mZoomControl( NULL ), |
|
38 mSettings( NULL ) |
|
39 { |
|
40 CX_DEBUG_ENTER_FUNCTION(); |
|
41 |
|
42 // Create all control classes |
|
43 mFakeCameraDeviceControl = new CxeFakeCameraDeviceControl(); |
|
44 |
|
45 CxeCameraDevice* cameraDevice = mFakeCameraDeviceControl->cameraDevice(); |
|
46 |
|
47 mSettingsModel = new CxeSettingsModel(); |
|
48 mSettings = new CxeSettingsImp(*mSettingsModel); |
|
49 mFeatureManager = new CxeFeatureManagerImp(*mSettingsModel); |
|
50 mSoundPlayer = new CxeSoundPlayerSymbian(*mFakeCameraDeviceControl); |
|
51 mFilenameGenerator = new CxeFilenameGeneratorSymbian(*mSettings, mode()); |
|
52 |
|
53 mViewfinderControl = new CxeFakeViewfinderControl(); |
|
54 |
|
55 mFakeStillCaptureControl = new CxeFakeStillCaptureControl(); |
|
56 mFakeAutoFocusControl = new CxeFakeAutoFocusControl(); |
|
57 mVideoCaptureControl = new CxeVideoCaptureControlSymbian(); |
|
58 |
|
59 // connecting camera mode changes to updating capture sounds |
|
60 connect(mFakeCameraDeviceControl, SIGNAL(initModeComplete(CxeError::Id)), |
|
61 mSoundPlayer, SLOT(updateCaptureSound())); |
|
62 |
|
63 // connecting scene setting change callbacks to ViewfinderControl |
|
64 connect(mSettings, SIGNAL(settingValueChanged(const QString&,QVariant)), |
|
65 mViewfinderControl, SLOT(handleSettingValueChanged(const QString&,QVariant))); |
|
66 |
|
67 connect(mSettings, SIGNAL(sceneChanged(CxeScene&)), |
|
68 mViewfinderControl, SLOT(handleSceneChanged(CxeScene&))); |
|
69 |
|
70 // enabling scene setting change callbacks to stillcapturecontrol |
|
71 connect(mSettings, SIGNAL(settingValueChanged(const QString&,QVariant)), |
|
72 mFakeStillCaptureControl, SLOT(handleSettingValueChanged(const QString&,QVariant))); |
|
73 |
|
74 connect(mSettings, SIGNAL(sceneChanged(CxeScene&)), |
|
75 mFakeStillCaptureControl, SLOT(handleSceneChanged(CxeScene&))); |
|
76 |
|
77 // enabling scene setting change callbacks to videocapturecontrol |
|
78 connect(mSettings, SIGNAL(settingValueChanged(const QString&,QVariant)), |
|
79 mVideoCaptureControl, SLOT(handleSettingValueChanged(const QString&,QVariant))); |
|
80 |
|
81 connect(mSettings, SIGNAL(sceneChanged(CxeScene&)), |
|
82 mVideoCaptureControl, SLOT(handleSceneChanged(CxeScene&))); |
|
83 |
|
84 |
|
85 // enabling callbacks to Autofocus control |
|
86 connect(mSettings, SIGNAL(sceneChanged(CxeScene&)), |
|
87 mFakeAutoFocusControl, SLOT(handleSceneChanged(CxeScene&)) ); |
|
88 |
|
89 // Connect signals for ECam events |
|
90 // TJ |
|
91 connect( mFakeCameraDeviceControl, SIGNAL(cameraEvent(int,int)), |
|
92 mFakeStillCaptureControl, SLOT(handleCameraEvent(int,int)) ); |
|
93 connect( mFakeCameraDeviceControl, SIGNAL(cameraEvent(int,int)), |
|
94 mVideoCaptureControl, SLOT(handleCameraEvent(int,int)) ); |
|
95 connect( mFakeCameraDeviceControl, SIGNAL(cameraEvent(int,int)), |
|
96 mFakeAutoFocusControl, SLOT(handleCameraEvent(int,int)) ); |
|
97 |
|
98 // Connect signal for device ready events |
|
99 connect( mFakeCameraDeviceControl, SIGNAL(deviceReady()), |
|
100 this, SLOT(doInit()) ); |
|
101 |
|
102 // Connect ECam image buffer ready event |
|
103 connect( mFakeCameraDeviceControl, SIGNAL(imageBufferReady(MCameraBuffer*,int)), |
|
104 mFakeStillCaptureControl, SLOT(handleImageData(MCameraBuffer*,int)) ); |
|
105 |
|
106 // Connect ECam VF frame ready event |
|
107 connect( mFakeCameraDeviceControl, SIGNAL(vfFrameReady(MCameraBuffer*,int)), |
|
108 mViewfinderControl, SLOT(handleVfFrame(MCameraBuffer*,int)) ); |
|
109 |
|
110 // Connect image and video init complete signals to CameraDeviceControl initModeComplete |
|
111 connect(mFakeStillCaptureControl, SIGNAL(imagePrepareComplete(CxeError::Id)), |
|
112 mFakeCameraDeviceControl, SIGNAL(initModeComplete(CxeError::Id)) ); |
|
113 |
|
114 connect(mVideoCaptureControl, SIGNAL(videoPrepareComplete(CxeError::Id)), |
|
115 mFakeCameraDeviceControl, SIGNAL(initModeComplete(CxeError::Id)) ); |
|
116 |
|
117 CX_DEBUG_EXIT_FUNCTION(); |
|
118 } |
|
119 |
|
120 CxeFakeEngine::~CxeFakeEngine() |
|
121 { |
|
122 CX_DEBUG_ENTER_FUNCTION(); |
|
123 |
|
124 delete mViewfinderControl; |
|
125 delete mZoomControl; |
|
126 delete mVideoCaptureControl; |
|
127 delete mSoundPlayer; |
|
128 delete mFilenameGenerator; |
|
129 |
|
130 CX_DEBUG_EXIT_FUNCTION(); |
|
131 } |
|
132 |
|
133 CxeCameraDeviceControl &CxeFakeEngine::cameraDeviceControl() |
|
134 { |
|
135 return *mFakeCameraDeviceControl; |
|
136 } |
|
137 |
|
138 CxeViewfinderControl &CxeFakeEngine::viewfinderControl() |
|
139 { |
|
140 return *mViewfinderControl; |
|
141 } |
|
142 |
|
143 CxeStillCaptureControlSymbian &CxeFakeEngine::stillCaptureControl() |
|
144 { |
|
145 return *mFakeStillCaptureControl; |
|
146 } |
|
147 |
|
148 CxeVideoCaptureControlSymbian &CxeFakeEngine::videoCaptureControl() |
|
149 { |
|
150 return *mVideoCaptureControl; |
|
151 } |
|
152 |
|
153 CxeAutoFocusControlSymbian &CxeFakeEngine::autoFocusControl() |
|
154 { |
|
155 return *mFakeAutoFocusControl; |
|
156 } |
|
157 |
|
158 CxeZoomControlSymbian &CxeFakeEngine::zoomControl() |
|
159 { |
|
160 return *mZoomControl; |
|
161 } |
|
162 |
|
163 // Get the settings handle |
|
164 CxeSettings &CxeFakeEngine::settings() |
|
165 { |
|
166 return *mSettings; |
|
167 } |
|
168 |
|
169 CxeFeatureManager& CxeFakeEngine::featureManager() |
|
170 { |
|
171 return *mFeatureManager; |
|
172 } |
|
173 |
|
174 void CxeFakeEngine::doInit() |
|
175 { |
|
176 CX_DEBUG_ENTER_FUNCTION(); |
|
177 // load settings whenever we change mode or start camera or switch camera |
|
178 //static_cast<CxeSettingsImp*>(mSettings)->loadSettings(mode()); |
|
179 mFilenameGenerator->init(mode()); |
|
180 |
|
181 if ( mode() == Cxe::ImageMode ) { |
|
182 mFakeStillCaptureControl->init(); |
|
183 } else if ( mode() == Cxe::VideoMode ) { |
|
184 mFakeStillCaptureControl->deinit(); |
|
185 mVideoCaptureControl->init(); |
|
186 } |
|
187 } |
|
188 |
|
189 Cxe::CameraMode CxeFakeEngine::mode() const |
|
190 { |
|
191 return mFakeCameraDeviceControl->mode(); |
|
192 } |
|
193 |
|
194 void CxeFakeEngine::setMode(Cxe::CameraMode mode) |
|
195 { |
|
196 mFakeCameraDeviceControl->setMode(mode); |
|
197 } |
|
198 |
|
199 void CxeFakeEngine::initModeFake(Cxe::CameraMode cameraMode) |
|
200 { |
|
201 mFakeCameraDeviceControl->setMode( cameraMode ); |
|
202 if( cameraMode == Cxe::ImageMode) { |
|
203 mFakeStillCaptureControl->setFakeState(CxeStillCaptureControl::Ready); |
|
204 } |
|
205 |
|
206 } |
|
207 |
|
208 void CxeFakeEngine::initMode(Cxe::CameraMode cameraMode) |
|
209 { |
|
210 CX_DEBUG_ENTER_FUNCTION(); |
|
211 |
|
212 if (mode() == cameraMode) { |
|
213 CX_DEBUG(("initMode() called for current mode")); |
|
214 |
|
215 // We're already in the requested mode. However, it is possible |
|
216 // that we need to reserve and power on camera and/or prepare |
|
217 // the capture control. |
|
218 if (reserveNeeded()) { |
|
219 // Camera needs to be reserved. Initialization will continue |
|
220 // when we get the deviceReady() signal. |
|
221 CX_DEBUG(("initMode() - calling reserve()")); |
|
222 mFakeCameraDeviceControl->reserve(); |
|
223 } else if (initNeeded()) { |
|
224 // Camera is reserved and ready, but we need to prepare still image control or |
|
225 // video capture control |
|
226 CX_DEBUG(("initMode() - calling doInit()")); |
|
227 doInit(); |
|
228 } else if (startViewfinderNeeded()) { |
|
229 // Everything is ready and prepared, but we viewfinder is not yet running |
|
230 CX_DEBUG(("initMode() - calling viewfinder start()")); |
|
231 mViewfinderControl->start(); |
|
232 } else { |
|
233 CX_DEBUG(("initMode() - no actions needed")); |
|
234 // Do nothing. |
|
235 // We are either already ready to capture or the we're pending |
|
236 // on prepare complete callback. |
|
237 } |
|
238 } else { |
|
239 CX_DEBUG(("initMode() called for mode switch")); |
|
240 |
|
241 // Mode switch |
|
242 mFakeCameraDeviceControl->setMode(cameraMode); |
|
243 |
|
244 if (reserveNeeded()) { |
|
245 CX_DEBUG(("initMode() - calling reserve()")); |
|
246 mFakeCameraDeviceControl->reserve(); |
|
247 } else if ( mFakeCameraDeviceControl->state() == CxeCameraDeviceControl::Ready ) { |
|
248 CX_DEBUG(("initMode() - calling doInit()")); |
|
249 // Camera device is ready... we only need to prepare video or still |
|
250 // capture control, depending on current mode. |
|
251 doInit(); |
|
252 } else { |
|
253 CX_DEBUG(("initMode() - no actions needed")); |
|
254 // Do nothing. |
|
255 // Camera device control is in Initializing state. Initialization will continue |
|
256 // when we get the deviceReady() callback. |
|
257 } |
|
258 } |
|
259 |
|
260 CX_DEBUG_EXIT_FUNCTION(); |
|
261 } |
|
262 |
|
263 bool CxeFakeEngine::initNeeded() |
|
264 { |
|
265 bool result = false; |
|
266 |
|
267 if (mode() == Cxe::ImageMode && |
|
268 mFakeCameraDeviceControl->state() == CxeCameraDeviceControl::Ready && |
|
269 mFakeStillCaptureControl->state() == CxeStillCaptureControl::Uninitialized) { |
|
270 // We're in still image mode, camera is reserved and ready, but |
|
271 // we need to prepare still image control |
|
272 result = true; |
|
273 } else if (mode() == Cxe::VideoMode && |
|
274 mFakeCameraDeviceControl->state() == CxeCameraDeviceControl::Ready) { |
|
275 if (mVideoCaptureControl->state() == CxeVideoCaptureControl::Open || |
|
276 mVideoCaptureControl->state() == CxeVideoCaptureControl::Idle) { |
|
277 // We're in video mode, camera is reserved and ready, but |
|
278 // we need to open and prepare video recorder. |
|
279 result = true; |
|
280 } |
|
281 } |
|
282 |
|
283 return result; |
|
284 } |
|
285 |
|
286 bool CxeFakeEngine::startViewfinderNeeded() |
|
287 { |
|
288 bool result = false; |
|
289 |
|
290 if (mViewfinderControl->state() != CxeViewfinderControl::Running) { |
|
291 if (mode() == Cxe::ImageMode && |
|
292 mFakeStillCaptureControl->state() == CxeStillCaptureControl::Ready) { |
|
293 // We're in still image mode and ready for capturing... we just need to |
|
294 // start viewfinder. |
|
295 result = true; |
|
296 } else if (mode() == Cxe::VideoMode && |
|
297 mVideoCaptureControl->state() == CxeVideoCaptureControl::Ready) { |
|
298 // We're in video mode and ready for capturing... we just need to |
|
299 // start viewfinder. |
|
300 result = true; |
|
301 } |
|
302 } |
|
303 |
|
304 return result; |
|
305 } |
|
306 |
|
307 bool CxeFakeEngine::reserveNeeded() |
|
308 { |
|
309 CX_DEBUG_ENTER_FUNCTION(); |
|
310 // If camera device control is in Idle state, we need to call reserve() |
|
311 return (mFakeCameraDeviceControl->state() == CxeCameraDeviceControl::Idle); |
|
312 } |
|
313 |
|
314 // This should be the only exported method |
|
315 CxeFakeEngine *CxeFakeEngine::createFakeEngine() |
|
316 { |
|
317 CX_DEBUG_ENTER_FUNCTION(); |
|
318 |
|
319 CxeFakeEngine* res = new CxeFakeEngine(); |
|
320 |
|
321 CX_DEBUG_EXIT_FUNCTION(); |
|
322 return res; |
|
323 } |
|
324 |
|
325 |
|
326 CxeFakeStillCaptureControl &CxeFakeEngine::fakeStillCaptureControl() |
|
327 { |
|
328 return *mFakeStillCaptureControl; |
|
329 } |
|
330 |
|
331 |
|
332 bool CxeFakeEngine::isEngineReady() |
|
333 { |
|
334 bool ready = false; |
|
335 if (mCameraDeviceControl->state() == CxeCameraDeviceControl::Ready && |
|
336 mViewfinderControl->state() == CxeViewfinderControl::Running) { |
|
337 if (mode() == Cxe::ImageMode) { |
|
338 if (mStillCaptureControl->state() == CxeStillCaptureControl::Ready) { |
|
339 ready = true; |
|
340 } |
|
341 } else if (mode() == Cxe::VideoMode) { |
|
342 if (mVideoCaptureControl->state() == CxeVideoCaptureControl::Ready || |
|
343 mVideoCaptureControl->state() == CxeVideoCaptureControl::Recording || |
|
344 mVideoCaptureControl->state() == CxeVideoCaptureControl::Paused ) { |
|
345 ready = true; |
|
346 } |
|
347 } |
|
348 } |
|
349 return ready; |
|
350 } |
|
351 |
|
352 // End of file |
|