27 #include "cxestillcapturecontrolsymbian.h" |
28 #include "cxestillcapturecontrolsymbian.h" |
28 #include "cxeimagedataqueuesymbian.h" |
29 #include "cxeimagedataqueuesymbian.h" |
29 #include "cxefilenamegenerator.h" |
30 #include "cxefilenamegenerator.h" |
30 #include "cxefilesavethread.h" |
31 #include "cxefilesavethread.h" |
31 #include "cxutils.h" |
32 #include "cxutils.h" |
32 #include "cxesysutil.h" |
|
33 #include "cxecameradevicecontrol.h" |
33 #include "cxecameradevicecontrol.h" |
34 #include "cxecameradevice.h" |
34 #include "cxecameradevice.h" |
35 #include "cxesoundplayersymbian.h" |
35 #include "cxesoundplayersymbian.h" |
36 #include "cxestillimagesymbian.h" |
36 #include "cxestillimagesymbian.h" |
37 #include "cxeviewfindercontrol.h" |
37 #include "cxeviewfindercontrol.h" |
58 |
59 |
59 /** |
60 /** |
60 * Constructor. |
61 * Constructor. |
61 */ |
62 */ |
62 CxeStillCaptureControlSymbian::CxeStillCaptureControlSymbian( |
63 CxeStillCaptureControlSymbian::CxeStillCaptureControlSymbian( |
63 CxeCameraDevice &cameraDevice, |
64 CxeCameraDevice &cameraDevice, |
64 CxeViewfinderControl &viewfinderControl, |
65 CxeViewfinderControl &viewfinderControl, |
65 CxeCameraDeviceControl &cameraDeviceControl, |
66 CxeCameraDeviceControl &cameraDeviceControl, |
66 CxeFilenameGenerator &nameGenerator, |
67 CxeFilenameGenerator &nameGenerator, |
67 CxeSensorEventHandler &sensorEventHandler, |
68 CxeSensorEventHandler &sensorEventHandler, |
68 CxeAutoFocusControl &autoFocusControl, |
69 CxeAutoFocusControl &autoFocusControl, |
69 CxeSettings &settings, |
70 CxeSettings &settings, |
70 CxeQualityPresets &qualityPresets, |
71 CxeQualityPresets &qualityPresets, |
71 CxeFileSaveThread &fileSaveThread) |
72 CxeFileSaveThread &fileSaveThread, |
72 : CxeStateMachine("CxeStillCaptureControlSymbian"), |
73 CxeDiskMonitor &diskMonitor) |
73 mCameraDevice(cameraDevice), |
74 : CxeStateMachine("CxeStillCaptureControlSymbian"), |
74 mViewfinderControl(viewfinderControl), |
75 mCameraDevice(cameraDevice), |
75 mCameraDeviceControl(cameraDeviceControl), |
76 mViewfinderControl(viewfinderControl), |
76 mFilenameGenerator(nameGenerator), |
77 mCameraDeviceControl(cameraDeviceControl), |
77 mSensorEventHandler(sensorEventHandler), |
78 mFilenameGenerator(nameGenerator), |
78 mAutoFocusControl(autoFocusControl), |
79 mSensorEventHandler(sensorEventHandler), |
79 mSettings(settings), |
80 mAutoFocusControl(autoFocusControl), |
80 mQualityPresets(qualityPresets), |
81 mSettings(settings), |
81 mFileSaveThread(fileSaveThread), |
82 mQualityPresets(qualityPresets), |
82 mMode(SingleImageCapture), |
83 mFileSaveThread(fileSaveThread), |
83 mAfState(CxeAutoFocusControl::Unknown) |
84 mDiskMonitor(diskMonitor), |
84 { |
85 mMode(SingleImageCapture), |
85 CX_DEBUG_ENTER_FUNCTION(); |
86 mAfState(CxeAutoFocusControl::Unknown) |
|
87 { |
|
88 CX_DEBUG_ENTER_FUNCTION(); |
|
89 OstTrace0(camerax_performance, CXESTILLCAPTURECONTROLSYMBIAN_CREATE_IN, "msg: e_CX_STILLCAPTURECONTROL_NEW 1"); |
86 |
90 |
87 qRegisterMetaType<CxeStillCaptureControl::State>(); |
91 qRegisterMetaType<CxeStillCaptureControl::State>(); |
88 initializeStates(); |
92 initializeStates(); |
89 reset(); |
93 reset(); |
90 |
94 |
|
95 // If camera is already allocated, call the slot ourselves. |
|
96 if (mCameraDevice.camera()) { |
|
97 handleCameraAllocated(CxeError::None); |
|
98 } |
|
99 |
|
100 OstTrace0(camerax_performance, CXESTILLCAPTURECONTROLSYMBIAN_CREATE_MID1, "msg: e_CX_ENGINE_CONNECT_SIGNALS 1"); |
91 // connect signals from cameraDevice to recieve events when camera reference changes |
101 // connect signals from cameraDevice to recieve events when camera reference changes |
92 connect(&cameraDevice, SIGNAL(prepareForCameraDelete()), |
102 connect(&cameraDevice, SIGNAL(prepareForCameraDelete()), |
93 this, SLOT(prepareForCameraDelete())); |
103 this, SLOT(prepareForCameraDelete())); |
94 connect(&cameraDevice, SIGNAL(prepareForRelease()), |
104 connect(&cameraDevice, SIGNAL(prepareForRelease()), |
95 this, SLOT(prepareForRelease())); |
105 this, SLOT(prepareForRelease())); |
108 this, SLOT(handleImageData(MCameraBuffer*,int))); |
118 this, SLOT(handleImageData(MCameraBuffer*,int))); |
109 // Connect signals for ECam events |
119 // Connect signals for ECam events |
110 connect(&mCameraDeviceControl, SIGNAL(cameraEvent(int,int)), |
120 connect(&mCameraDeviceControl, SIGNAL(cameraEvent(int,int)), |
111 this, SLOT(handleCameraEvent(int,int))); |
121 this, SLOT(handleCameraEvent(int,int))); |
112 |
122 |
|
123 OstTrace0(camerax_performance, CXESTILLCAPTURECONTROLSYMBIAN_CREATE_MID2, "msg: e_CX_ENGINE_CONNECT_SIGNALS 0"); |
|
124 |
113 mImageDataQueue = new CxeImageDataQueueSymbian(); |
125 mImageDataQueue = new CxeImageDataQueueSymbian(); |
114 mAutoFocusSoundPlayer = new CxeSoundPlayerSymbian(CxeSoundPlayerSymbian::AutoFocus); |
126 mAutoFocusSoundPlayer = new CxeSoundPlayerSymbian(CxeSoundPlayerSymbian::AutoFocus); |
115 mCaptureSoundPlayer = new CxeSoundPlayerSymbian(CxeSoundPlayerSymbian::StillCapture); |
127 mCaptureSoundPlayer = new CxeSoundPlayerSymbian(CxeSoundPlayerSymbian::StillCapture); |
116 |
128 |
|
129 OstTrace0(camerax_performance, CXESTILLCAPTURECONTROLSYMBIAN_CREATE_OUT, "msg: e_CX_STILLCAPTURECONTROL_NEW 0"); |
117 CX_DEBUG_EXIT_FUNCTION(); |
130 CX_DEBUG_EXIT_FUNCTION(); |
118 } |
131 } |
119 |
132 |
120 /** |
133 /** |
121 * Destructor. |
134 * Destructor. |
169 * Initialize the still image capture control. |
182 * Initialize the still image capture control. |
170 */ |
183 */ |
171 void CxeStillCaptureControlSymbian::init() |
184 void CxeStillCaptureControlSymbian::init() |
172 { |
185 { |
173 CX_DEBUG_ENTER_FUNCTION(); |
186 CX_DEBUG_ENTER_FUNCTION(); |
174 OstTrace0(camerax_performance, CXESTILLCAPTURECONTROLSYMBIAN_INIT, "msg: e_CX_STILL_CAPCONT_INIT 1"); |
187 OstTrace0(camerax_performance, CXESTILLCAPTURECONTROLSYMBIAN_INIT_IN, "msg: e_CX_STILL_CAPCONT_INIT 1"); |
175 |
188 |
176 if (state() == Uninitialized) { |
189 if (state() == Uninitialized) { |
177 prepare(); |
190 prepare(); |
178 // Initialize orientation sensor and other sensors |
191 // Initialize orientation sensor and other sensors |
179 mSensorEventHandler.init(); |
192 mSensorEventHandler.init(); |
180 } |
193 } |
181 |
194 |
182 OstTrace0(camerax_performance, DUP1_CXESTILLCAPTURECONTROLSYMBIAN_INIT, "msg: e_CX_STILL_CAPCONT_INIT 0"); |
195 OstTrace0(camerax_performance, CXESTILLCAPTURECONTROLSYMBIAN_INIT_OUT, "msg: e_CX_STILL_CAPCONT_INIT 0"); |
183 CX_DEBUG_EXIT_FUNCTION(); |
196 CX_DEBUG_EXIT_FUNCTION(); |
184 } |
197 } |
185 |
198 |
186 /** |
199 /** |
187 * Un-initialize the image mode. |
200 * Un-initialize the image mode. |
188 */ |
201 */ |
189 void CxeStillCaptureControlSymbian::deinit() |
202 void CxeStillCaptureControlSymbian::deinit() |
190 { |
203 { |
191 CX_DEBUG_ENTER_FUNCTION(); |
204 CX_DEBUG_ENTER_FUNCTION(); |
192 OstTrace0( camerax_performance, CXESTILLCAPTURECONTROLSYMBIAN_DEINIT, "msg: e_CX_STILL_CAPCONT_DEINIT 1" ); |
|
193 |
205 |
194 if (state() == Uninitialized) { |
206 if (state() == Uninitialized) { |
195 // nothing to do |
207 // nothing to do |
196 return; |
208 return; |
197 } |
209 } |
198 |
210 |
|
211 OstTrace0( camerax_performance, CXESTILLCAPTURECONTROLSYMBIAN_DEINIT_IN, "msg: e_CX_STILL_CAPCONT_DEINIT 1" ); |
|
212 |
|
213 // Stop monitoring disk space. |
|
214 mDiskMonitor.stop(); |
|
215 disconnect(&mDiskMonitor, SIGNAL(diskSpaceChanged()), this, SLOT(handleDiskSpaceChanged())); |
|
216 |
199 //stop viewfinder |
217 //stop viewfinder |
200 mViewfinderControl.stop(); |
218 mViewfinderControl.stop(); |
201 |
219 |
202 // disable sensor event handler. |
220 // disable sensor event handler. |
203 mSensorEventHandler.deinit(); |
221 mSensorEventHandler.deinit(); |
251 ecamStillResolutionIndex = 0; |
269 ecamStillResolutionIndex = 0; |
252 } |
270 } |
253 |
271 |
254 // Prepare Image capture |
272 // Prepare Image capture |
255 CCamera::TFormat imgFormat = supportedStillFormat(mCameraDeviceControl.cameraIndex()); |
273 CCamera::TFormat imgFormat = supportedStillFormat(mCameraDeviceControl.cameraIndex()); |
256 OstTrace0(camerax_performance, DUP2_CXESTILLCAPTURECONTROLSYMBIAN_PREPARE, "msg: e_CX_PREPARE_IMAGE_CAPTURE 1"); |
274 OstTrace0(camerax_performance, CXESTILLCAPTURECONTROLSYMBIAN_PREPARE_MID1, "msg: e_CX_PREPARE_IMAGE_CAPTURE 1"); |
257 TRAP(err, mCameraDevice.camera()->PrepareImageCaptureL(imgFormat, ecamStillResolutionIndex)); |
275 TRAP(err, mCameraDevice.camera()->PrepareImageCaptureL(imgFormat, ecamStillResolutionIndex)); |
258 OstTrace0(camerax_performance, DUP3_CXESTILLCAPTURECONTROLSYMBIAN_PREPARE, "msg: e_CX_PREPARE_IMAGE_CAPTURE 0"); |
276 OstTrace0(camerax_performance, CXESTILLCAPTURECONTROLSYMBIAN_PREPARE_MID2, "msg: e_CX_PREPARE_IMAGE_CAPTURE 0"); |
259 |
277 |
260 CX_DEBUG(("PrepareImageCaptureL done, err=%d, resolution index = %d", err, ecamStillResolutionIndex)); |
278 CX_DEBUG(("PrepareImageCaptureL done, err=%d, resolution index = %d", err, ecamStillResolutionIndex)); |
261 |
279 |
262 if (!err) { |
280 if (!err) { |
263 // still capture prepare went fine, try preparing snapshot |
281 // still capture prepare went fine, try preparing snapshot |
266 } else { |
284 } else { |
267 err = KErrNotFound; |
285 err = KErrNotFound; |
268 } |
286 } |
269 |
287 |
270 if (!err) { |
288 if (!err) { |
271 MCameraFaceTracking *faceTracking = mCameraDevice.faceTracking(); |
|
272 if (faceTracking) { |
|
273 // Enable AF reticule drawing by adaptation |
|
274 TRAP_IGNORE(faceTracking->EnableFaceIndicatorsL(ETrue)); |
|
275 } |
|
276 |
|
277 // Start viewfinder before claiming to be ready, |
289 // Start viewfinder before claiming to be ready, |
278 // as e.g. pending capture might be started by state change, |
290 // as e.g. pending capture might be started by state change, |
279 // and viewfinder start might have problems with just started capturing. |
291 // and viewfinder start might have problems with just started capturing. |
280 // If viewfinder is already running, this call does nothing. |
292 // If viewfinder is already running, this call does nothing. |
281 mViewfinderControl.start(); |
293 mViewfinderControl.start(); |
|
294 |
|
295 // Start monitoring disk space. |
|
296 mDiskMonitor.start(); |
|
297 connect(&mDiskMonitor, SIGNAL(diskSpaceChanged()), this, SLOT(handleDiskSpaceChanged())); |
|
298 |
|
299 |
|
300 // Enable AF reticule drawing by adaptation |
|
301 MCameraFaceTracking *faceTracking = mCameraDevice.faceTracking(); |
|
302 if (faceTracking) { |
|
303 TRAP_IGNORE(faceTracking->EnableFaceIndicatorsL(ETrue)); |
|
304 } |
282 |
305 |
283 // Still capture and still snapshot are OK. |
306 // Still capture and still snapshot are OK. |
284 // We can safely set state to READY. |
307 // We can safely set state to READY. |
285 setState(Ready); |
308 setState(Ready); |
286 |
309 |
408 void CxeStillCaptureControlSymbian::capture() |
431 void CxeStillCaptureControlSymbian::capture() |
409 { |
432 { |
410 CX_DEBUG_ENTER_FUNCTION(); |
433 CX_DEBUG_ENTER_FUNCTION(); |
411 CX_ASSERT_ALWAYS(mCameraDevice.camera()); |
434 CX_ASSERT_ALWAYS(mCameraDevice.camera()); |
412 |
435 |
413 // Play the capture sound and start image capture |
436 // Start the image capture as fast as possible to minimize lag. |
414 mCaptureSoundPlayer->play(); |
437 // Check e.g. space available *after* this. |
415 |
|
416 setState(Capturing); |
|
417 mCameraDevice.camera()->CaptureImage(); |
438 mCameraDevice.camera()->CaptureImage(); |
418 |
439 |
419 //! @todo: NOTE: This call may not stay here. It can move depending on the implementation for burst capture. |
440 if (imagesLeft() > 0) { |
420 if (mMode == BurstCapture) { |
441 mCaptureSoundPlayer->play(); |
421 // Start a new filename sequence |
442 setState(Capturing); |
422 mFilenameGenerator.startNewImageFilenameSequence(); |
443 |
|
444 //! @todo: NOTE: This call may not stay here. It can move depending on the implementation for burst capture. |
|
445 if (mMode == BurstCapture) { |
|
446 // Start a new filename sequence |
|
447 mFilenameGenerator.startNewImageFilenameSequence(); |
|
448 } |
|
449 } else { |
|
450 // There's no space for the image. |
|
451 // Cancel started capturing. |
|
452 mCameraDevice.camera()->CancelCaptureImage(); |
|
453 |
|
454 // Report error. |
|
455 // Ui notification has anyway some delays, hence handling VF after this. |
|
456 emit imageCaptured(CxeError::DiskFull, CxeStillImage::INVALID_ID); |
|
457 |
|
458 // Capturing stops viewfinder, so restart it now. |
|
459 mViewfinderControl.stop(); |
|
460 mViewfinderControl.start(); |
423 } |
461 } |
424 |
462 |
425 CX_DEBUG_EXIT_FUNCTION(); |
463 CX_DEBUG_EXIT_FUNCTION(); |
426 } |
464 } |
427 |
465 |
633 if (settingId == CxeSettingIds::IMAGE_QUALITY) { |
672 if (settingId == CxeSettingIds::IMAGE_QUALITY) { |
634 // re-prepare for still |
673 // re-prepare for still |
635 if (state() == Ready) { |
674 if (state() == Ready) { |
636 deinit(); |
675 deinit(); |
637 init(); |
676 init(); |
|
677 } |
|
678 } |
|
679 |
|
680 CX_DEBUG_EXIT_FUNCTION(); |
|
681 } |
|
682 |
|
683 /*! |
|
684 * Disk space changed. |
|
685 * Emit remaining images changed signal, if space change affects it. |
|
686 */ |
|
687 void CxeStillCaptureControlSymbian::handleDiskSpaceChanged() |
|
688 { |
|
689 CX_DEBUG_ENTER_FUNCTION(); |
|
690 |
|
691 // Ignore updates on other states. |
|
692 if (state() == CxeStillCaptureControl::Ready) { |
|
693 |
|
694 int images = calculateRemainingImages(mCurrentImageDetails.mEstimatedSize); |
|
695 |
|
696 if (images != mCurrentImageDetails.mPossibleImages) { |
|
697 CX_DEBUG(("CxeStillCaptureControlSymbian - available images changed %d -> %d", |
|
698 mCurrentImageDetails.mPossibleImages, images)); |
|
699 |
|
700 mCurrentImageDetails.mPossibleImages = images; |
|
701 emit availableImagesChanged(); |
638 } |
702 } |
639 } |
703 } |
640 |
704 |
641 CX_DEBUG_EXIT_FUNCTION(); |
705 CX_DEBUG_EXIT_FUNCTION(); |
642 } |
706 } |