|
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::initModeFake(Cxe::CameraMode cameraMode) |
|
195 { |
|
196 mFakeCameraDeviceControl->setMode( cameraMode ); |
|
197 if( cameraMode == Cxe::ImageMode) { |
|
198 mFakeStillCaptureControl->setFakeState(CxeStillCaptureControl::Ready); |
|
199 } |
|
200 |
|
201 } |
|
202 |
|
203 void CxeFakeEngine::initMode(Cxe::CameraMode cameraMode) |
|
204 { |
|
205 CX_DEBUG_ENTER_FUNCTION(); |
|
206 |
|
207 if (mode() == cameraMode) { |
|
208 CX_DEBUG(("initMode() called for current mode")); |
|
209 |
|
210 // We're already in the requested mode. However, it is possible |
|
211 // that we need to reserve and power on camera and/or prepare |
|
212 // the capture control. |
|
213 if (reserveNeeded()) { |
|
214 // Camera needs to be reserved. Initialization will continue |
|
215 // when we get the deviceReady() signal. |
|
216 CX_DEBUG(("initMode() - calling reserve()")); |
|
217 mFakeCameraDeviceControl->reserve(); |
|
218 } else if (initNeeded()) { |
|
219 // Camera is reserved and ready, but we need to prepare still image control or |
|
220 // video capture control |
|
221 CX_DEBUG(("initMode() - calling doInit()")); |
|
222 doInit(); |
|
223 } else if (startViewfinderNeeded()) { |
|
224 // Everything is ready and prepared, but we viewfinder is not yet running |
|
225 CX_DEBUG(("initMode() - calling viewfinder start()")); |
|
226 mViewfinderControl->start(); |
|
227 } else { |
|
228 CX_DEBUG(("initMode() - no actions needed")); |
|
229 // Do nothing. |
|
230 // We are either already ready to capture or the we're pending |
|
231 // on prepare complete callback. |
|
232 } |
|
233 } else { |
|
234 CX_DEBUG(("initMode() called for mode switch")); |
|
235 |
|
236 // Mode switch |
|
237 mFakeCameraDeviceControl->setMode(cameraMode); |
|
238 |
|
239 if (reserveNeeded()) { |
|
240 CX_DEBUG(("initMode() - calling reserve()")); |
|
241 mFakeCameraDeviceControl->reserve(); |
|
242 } else if ( mFakeCameraDeviceControl->state() == CxeCameraDeviceControl::Ready ) { |
|
243 CX_DEBUG(("initMode() - calling doInit()")); |
|
244 // Camera device is ready... we only need to prepare video or still |
|
245 // capture control, depending on current mode. |
|
246 doInit(); |
|
247 } else { |
|
248 CX_DEBUG(("initMode() - no actions needed")); |
|
249 // Do nothing. |
|
250 // Camera device control is in Initializing state. Initialization will continue |
|
251 // when we get the deviceReady() callback. |
|
252 } |
|
253 } |
|
254 |
|
255 CX_DEBUG_EXIT_FUNCTION(); |
|
256 } |
|
257 |
|
258 bool CxeFakeEngine::initNeeded() |
|
259 { |
|
260 bool result = false; |
|
261 |
|
262 if (mode() == Cxe::ImageMode && |
|
263 mFakeCameraDeviceControl->state() == CxeCameraDeviceControl::Ready && |
|
264 mFakeStillCaptureControl->state() == CxeStillCaptureControl::Uninitialized) { |
|
265 // We're in still image mode, camera is reserved and ready, but |
|
266 // we need to prepare still image control |
|
267 result = true; |
|
268 } else if (mode() == Cxe::VideoMode && |
|
269 mFakeCameraDeviceControl->state() == CxeCameraDeviceControl::Ready) { |
|
270 if (mVideoCaptureControl->state() == CxeVideoCaptureControl::Open || |
|
271 mVideoCaptureControl->state() == CxeVideoCaptureControl::Idle) { |
|
272 // We're in video mode, camera is reserved and ready, but |
|
273 // we need to open and prepare video recorder. |
|
274 result = true; |
|
275 } |
|
276 } |
|
277 |
|
278 return result; |
|
279 } |
|
280 |
|
281 bool CxeFakeEngine::startViewfinderNeeded() |
|
282 { |
|
283 bool result = false; |
|
284 |
|
285 if (mViewfinderControl->state() != CxeViewfinderControl::Running) { |
|
286 if (mode() == Cxe::ImageMode && |
|
287 mFakeStillCaptureControl->state() == CxeStillCaptureControl::Ready) { |
|
288 // We're in still image mode and ready for capturing... we just need to |
|
289 // start viewfinder. |
|
290 result = true; |
|
291 } else if (mode() == Cxe::VideoMode && |
|
292 mVideoCaptureControl->state() == CxeVideoCaptureControl::Ready) { |
|
293 // We're in video mode and ready for capturing... we just need to |
|
294 // start viewfinder. |
|
295 result = true; |
|
296 } |
|
297 } |
|
298 |
|
299 return result; |
|
300 } |
|
301 |
|
302 bool CxeFakeEngine::reserveNeeded() |
|
303 { |
|
304 CX_DEBUG_ENTER_FUNCTION(); |
|
305 // If camera device control is in Idle state, we need to call reserve() |
|
306 return (mFakeCameraDeviceControl->state() == CxeCameraDeviceControl::Idle); |
|
307 } |
|
308 |
|
309 // This should be the only exported method |
|
310 CxeFakeEngine *CxeFakeEngine::createFakeEngine() |
|
311 { |
|
312 CX_DEBUG_ENTER_FUNCTION(); |
|
313 |
|
314 CxeFakeEngine* res = new CxeFakeEngine(); |
|
315 |
|
316 CX_DEBUG_EXIT_FUNCTION(); |
|
317 return res; |
|
318 } |
|
319 |
|
320 |
|
321 CxeFakeStillCaptureControl &CxeFakeEngine::fakeStillCaptureControl() |
|
322 { |
|
323 return *mFakeStillCaptureControl; |
|
324 } |
|
325 |
|
326 |
|
327 bool CxeFakeEngine::isEngineReady() |
|
328 { |
|
329 bool ready = false; |
|
330 if (mCameraDeviceControl->state() == CxeCameraDeviceControl::Ready && |
|
331 mViewfinderControl->state() == CxeViewfinderControl::Running) { |
|
332 if (mode() == Cxe::ImageMode) { |
|
333 if (mStillCaptureControl->state() == CxeStillCaptureControl::Ready) { |
|
334 ready = true; |
|
335 } |
|
336 } else if (mode() == Cxe::VideoMode) { |
|
337 if (mVideoCaptureControl->state() == CxeVideoCaptureControl::Ready || |
|
338 mVideoCaptureControl->state() == CxeVideoCaptureControl::Recording || |
|
339 mVideoCaptureControl->state() == CxeVideoCaptureControl::Paused ) { |
|
340 ready = true; |
|
341 } |
|
342 } |
|
343 } |
|
344 return ready; |
|
345 } |
|
346 |
|
347 // End of file |