1 /* Copyright (c) 2012-2014, The Linux Foundataion. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29
30 #define LOG_TAG "QCameraStateMachine"
31
32 #include <utils/Errors.h>
33 #include "QCamera2HWI.h"
34 #include "QCameraStateMachine.h"
35
36 namespace qcamera {
37
38 /*===========================================================================
39 * FUNCTION : smEvtProcRoutine
40 *
41 * DESCRIPTION: Statemachine process thread routine to handle events
42 * in different state.
43 *
44 * PARAMETERS :
45 * @data : ptr to QCameraStateMachine object
46 *
47 * RETURN : none
48 *==========================================================================*/
smEvtProcRoutine(void * data)49 void *QCameraStateMachine::smEvtProcRoutine(void *data)
50 {
51 int running = 1, ret;
52 QCameraStateMachine *pme = (QCameraStateMachine *)data;
53
54 CDBG_HIGH("%s: E", __func__);
55 do {
56 do {
57 ret = cam_sem_wait(&pme->cmd_sem);
58 if (ret != 0 && errno != EINVAL) {
59 ALOGE("%s: cam_sem_wait error (%s)",
60 __func__, strerror(errno));
61 return NULL;
62 }
63 } while (ret != 0);
64
65 // we got notified about new cmd avail in cmd queue
66 // first check API cmd queue
67 qcamera_sm_cmd_t *node = (qcamera_sm_cmd_t *)pme->api_queue.dequeue();
68 if (node == NULL) {
69 // no API cmd, then check evt cmd queue
70 node = (qcamera_sm_cmd_t *)pme->evt_queue.dequeue();
71 }
72 if (node != NULL) {
73 switch (node->cmd) {
74 case QCAMERA_SM_CMD_TYPE_API:
75 pme->stateMachine(node->evt, node->evt_payload);
76 // API is in a way sync call, so evt_payload is managed by HWI
77 // no need to free payload for API
78 break;
79 case QCAMERA_SM_CMD_TYPE_EVT:
80 pme->stateMachine(node->evt, node->evt_payload);
81
82 // EVT is async call, so payload need to be free after use
83 free(node->evt_payload);
84 node->evt_payload = NULL;
85 break;
86 case QCAMERA_SM_CMD_TYPE_EXIT:
87 running = 0;
88 break;
89 default:
90 break;
91 }
92 free(node);
93 node = NULL;
94 }
95 } while (running);
96 CDBG_HIGH("%s: X", __func__);
97 return NULL;
98 }
99
100 /*===========================================================================
101 * FUNCTION : QCameraStateMachine
102 *
103 * DESCRIPTION: constructor of QCameraStateMachine. Will start process thread
104 *
105 * PARAMETERS :
106 * @ctrl : ptr to HWI object
107 *
108 * RETURN : none
109 *==========================================================================*/
QCameraStateMachine(QCamera2HardwareInterface * ctrl)110 QCameraStateMachine::QCameraStateMachine(QCamera2HardwareInterface *ctrl) :
111 api_queue(),
112 evt_queue()
113 {
114 m_parent = ctrl;
115 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
116 cmd_pid = 0;
117 cam_sem_init(&cmd_sem, 0);
118 pthread_create(&cmd_pid,
119 NULL,
120 smEvtProcRoutine,
121 this);
122 }
123
124 /*===========================================================================
125 * FUNCTION : ~QCameraStateMachine
126 *
127 * DESCRIPTION: desctructor of QCameraStateMachine. Will stop process thread.
128 *
129 * PARAMETERS : none
130 *
131 * RETURN : none
132 *==========================================================================*/
~QCameraStateMachine()133 QCameraStateMachine::~QCameraStateMachine()
134 {
135 if (cmd_pid != 0) {
136 qcamera_sm_cmd_t *node =
137 (qcamera_sm_cmd_t *)malloc(sizeof(qcamera_sm_cmd_t));
138 if (NULL != node) {
139 memset(node, 0, sizeof(qcamera_sm_cmd_t));
140 node->cmd = QCAMERA_SM_CMD_TYPE_EXIT;
141
142 api_queue.enqueue((void *)node);
143 cam_sem_post(&cmd_sem);
144
145 /* wait until cmd thread exits */
146 if (pthread_join(cmd_pid, NULL) != 0) {
147 CDBG_HIGH("%s: pthread dead already\n", __func__);
148 }
149 }
150 cmd_pid = 0;
151 }
152 cam_sem_destroy(&cmd_sem);
153 }
154
155 /*===========================================================================
156 * FUNCTION : procAPI
157 *
158 * DESCRIPTION: process incoming API request from framework layer.
159 *
160 * PARAMETERS :
161 * @evt : event to be processed
162 * @api_payload : API payload. Can be NULL if not needed.
163 *
164 * RETURN : int32_t type of status
165 * NO_ERROR -- success
166 * none-zero failure code
167 *==========================================================================*/
procAPI(qcamera_sm_evt_enum_t evt,void * api_payload)168 int32_t QCameraStateMachine::procAPI(qcamera_sm_evt_enum_t evt,
169 void *api_payload)
170 {
171 qcamera_sm_cmd_t *node =
172 (qcamera_sm_cmd_t *)malloc(sizeof(qcamera_sm_cmd_t));
173 if (NULL == node) {
174 ALOGE("%s: No memory for qcamera_sm_cmd_t", __func__);
175 return NO_MEMORY;
176 }
177
178 memset(node, 0, sizeof(qcamera_sm_cmd_t));
179 node->cmd = QCAMERA_SM_CMD_TYPE_API;
180 node->evt = evt;
181 node->evt_payload = api_payload;
182 if (api_queue.enqueue((void *)node)) {
183 cam_sem_post(&cmd_sem);
184 return NO_ERROR;
185 } else {
186 free(node);
187 return UNKNOWN_ERROR;
188 }
189 }
190
191 /*===========================================================================
192 * FUNCTION : procEvt
193 *
194 * DESCRIPTION: process incoming envent from mm-camera-interface and
195 * mm-jpeg-interface.
196 *
197 * PARAMETERS :
198 * @evt : event to be processed
199 * @evt_payload : event payload. Can be NULL if not needed.
200 *
201 * RETURN : int32_t type of status
202 * NO_ERROR -- success
203 * none-zero failure code
204 *==========================================================================*/
procEvt(qcamera_sm_evt_enum_t evt,void * evt_payload)205 int32_t QCameraStateMachine::procEvt(qcamera_sm_evt_enum_t evt,
206 void *evt_payload)
207 {
208 qcamera_sm_cmd_t *node =
209 (qcamera_sm_cmd_t *)malloc(sizeof(qcamera_sm_cmd_t));
210 if (NULL == node) {
211 ALOGE("%s: No memory for qcamera_sm_cmd_t", __func__);
212 return NO_MEMORY;
213 }
214
215 memset(node, 0, sizeof(qcamera_sm_cmd_t));
216 node->cmd = QCAMERA_SM_CMD_TYPE_EVT;
217 node->evt = evt;
218 node->evt_payload = evt_payload;
219 if (evt_queue.enqueue((void *)node)) {
220 cam_sem_post(&cmd_sem);
221 return NO_ERROR;
222 } else {
223 free(node);
224 return UNKNOWN_ERROR;
225 }
226 }
227
228 /*===========================================================================
229 * FUNCTION : stateMachine
230 *
231 * DESCRIPTION: finite state machine entry function. Depends on state,
232 * incoming event will be handled differently.
233 *
234 * PARAMETERS :
235 * @evt : event to be processed
236 * @payload : event payload. Can be NULL if not needed.
237 *
238 * RETURN : int32_t type of status
239 * NO_ERROR -- success
240 * none-zero failure code
241 *==========================================================================*/
stateMachine(qcamera_sm_evt_enum_t evt,void * payload)242 int32_t QCameraStateMachine::stateMachine(qcamera_sm_evt_enum_t evt, void *payload)
243 {
244 int32_t rc = NO_ERROR;
245 ALOGV("%s: m_state %d, event (%d)", __func__, m_state, evt);
246 switch (m_state) {
247 case QCAMERA_SM_STATE_PREVIEW_STOPPED:
248 rc = procEvtPreviewStoppedState(evt, payload);
249 break;
250 case QCAMERA_SM_STATE_PREVIEW_READY:
251 rc = procEvtPreviewReadyState(evt, payload);
252 break;
253 case QCAMERA_SM_STATE_PREVIEWING:
254 rc = procEvtPreviewingState(evt, payload);
255 break;
256 case QCAMERA_SM_STATE_PREPARE_SNAPSHOT:
257 rc = procEvtPrepareSnapshotState(evt, payload);
258 break;
259 case QCAMERA_SM_STATE_PIC_TAKING:
260 rc = procEvtPicTakingState(evt, payload);
261 break;
262 case QCAMERA_SM_STATE_RECORDING:
263 rc = procEvtRecordingState(evt, payload);
264 break;
265 case QCAMERA_SM_STATE_VIDEO_PIC_TAKING:
266 rc = procEvtVideoPicTakingState(evt, payload);
267 break;
268 case QCAMERA_SM_STATE_PREVIEW_PIC_TAKING:
269 rc = procEvtPreviewPicTakingState(evt, payload);
270 break;
271 default:
272 break;
273 }
274
275 return rc;
276 }
277
278 /*===========================================================================
279 * FUNCTION : procEvtPreviewStoppedState
280 *
281 * DESCRIPTION: finite state machine function to handle event in state of
282 * QCAMERA_SM_STATE_PREVIEW_STOPPED.
283 *
284 * PARAMETERS :
285 * @evt : event to be processed
286 * @payload : event payload. Can be NULL if not needed.
287 *
288 * RETURN : int32_t type of status
289 * NO_ERROR -- success
290 * none-zero failure code
291 *==========================================================================*/
procEvtPreviewStoppedState(qcamera_sm_evt_enum_t evt,void * payload)292 int32_t QCameraStateMachine::procEvtPreviewStoppedState(qcamera_sm_evt_enum_t evt,
293 void *payload)
294 {
295 int32_t rc = NO_ERROR;
296 qcamera_api_result_t result;
297 memset(&result, 0, sizeof(qcamera_api_result_t));
298
299 ALOGV("%s: event (%d)", __func__, evt);
300 switch (evt) {
301 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
302 {
303 rc = m_parent->setPreviewWindow((struct preview_stream_ops *)payload);
304 result.status = rc;
305 result.request_api = evt;
306 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
307 m_parent->signalAPIResult(&result);
308 }
309 break;
310 case QCAMERA_SM_EVT_SET_CALLBACKS:
311 {
312 qcamera_sm_evt_setcb_payload_t *setcbs =
313 (qcamera_sm_evt_setcb_payload_t *)payload;
314 rc = m_parent->setCallBacks(setcbs->notify_cb,
315 setcbs->data_cb,
316 setcbs->data_cb_timestamp,
317 setcbs->get_memory,
318 setcbs->user);
319 result.status = rc;
320 result.request_api = evt;
321 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
322 m_parent->signalAPIResult(&result);
323 }
324 break;
325 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
326 {
327 rc = m_parent->enableMsgType(int32_t(payload));
328 result.status = rc;
329 result.request_api = evt;
330 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
331 m_parent->signalAPIResult(&result);
332 }
333 break;
334 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
335 {
336 rc = m_parent->disableMsgType(int32_t(payload));
337 result.status = rc;
338 result.request_api = evt;
339 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
340 m_parent->signalAPIResult(&result);
341 }
342 break;
343 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
344 {
345 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
346 result.status = rc;
347 result.request_api = evt;
348 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
349 result.enabled = enabled;
350 m_parent->signalAPIResult(&result);
351 }
352 break;
353 case QCAMERA_SM_EVT_SET_PARAMS:
354 {
355 bool needRestart = false;
356 rc = m_parent->updateParameters((char*)payload, needRestart);
357 if (needRestart) {
358 // Clear memory pools
359 m_parent->m_memoryPool.clear();
360 }
361 if (rc == NO_ERROR) {
362 rc = m_parent->commitParameterChanges();
363 }
364 result.status = rc;
365 result.request_api = evt;
366 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
367 m_parent->signalAPIResult(&result);
368 }
369 break;
370 case QCAMERA_SM_EVT_GET_PARAMS:
371 {
372 result.params = m_parent->getParameters();
373 rc = NO_ERROR;
374 result.status = rc;
375 result.request_api = evt;
376 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
377 m_parent->signalAPIResult(&result);
378 }
379 break;
380 case QCAMERA_SM_EVT_PUT_PARAMS:
381 {
382 rc = m_parent->putParameters((char*)payload);
383 result.status = rc;
384 result.request_api = evt;
385 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
386 m_parent->signalAPIResult(&result);
387 }
388 break;
389 case QCAMERA_SM_EVT_START_PREVIEW:
390 {
391 if (m_parent->mPreviewWindow == NULL) {
392 rc = m_parent->preparePreview();
393 if(rc == NO_ERROR) {
394 // preview window is not set yet, move to previewReady state
395 m_state = QCAMERA_SM_STATE_PREVIEW_READY;
396 } else {
397 ALOGE("%s: preparePreview failed",__func__);
398 }
399 } else {
400 rc = m_parent->preparePreview();
401 if (rc == NO_ERROR) {
402 rc = m_parent->startPreview();
403 if (rc != NO_ERROR) {
404 m_parent->unpreparePreview();
405 } else {
406 // start preview success, move to previewing state
407 m_state = QCAMERA_SM_STATE_PREVIEWING;
408 }
409 }
410 }
411 result.status = rc;
412 result.request_api = evt;
413 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
414 m_parent->signalAPIResult(&result);
415 }
416 break;
417 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
418 {
419 rc = m_parent->preparePreview();
420 if (rc == NO_ERROR) {
421 rc = m_parent->startPreview();
422 if (rc != NO_ERROR) {
423 m_parent->unpreparePreview();
424 } else {
425 m_state = QCAMERA_SM_STATE_PREVIEWING;
426 }
427 }
428 result.status = rc;
429 result.request_api = evt;
430 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
431 m_parent->signalAPIResult(&result);
432 }
433 break;
434 case QCAMERA_SM_EVT_STOP_PREVIEW:
435 {
436 // no op needed here
437 CDBG_HIGH("%s: already in preview stopped state, do nothing", __func__);
438 result.status = NO_ERROR;
439 result.request_api = evt;
440 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
441 m_parent->signalAPIResult(&result);
442 }
443 break;
444 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
445 case QCAMERA_SM_EVT_RECORDING_ENABLED:
446 {
447 result.status = NO_ERROR;
448 result.request_api = evt;
449 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
450 result.enabled = 0;
451 m_parent->signalAPIResult(&result);
452 }
453 break;
454 case QCAMERA_SM_EVT_RELEASE:
455 {
456 rc = m_parent->release();
457 result.status = rc;
458 result.request_api = evt;
459 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
460 m_parent->signalAPIResult(&result);
461 }
462 break;
463 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
464 {
465 rc = m_parent->storeMetaDataInBuffers(int(payload));
466 result.status = rc;
467 result.request_api = evt;
468 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
469 m_parent->signalAPIResult(&result);
470 }
471 break;
472 case QCAMERA_SM_EVT_DUMP:
473 {
474 rc = m_parent->dump((int)payload);
475 result.status = rc;
476 result.request_api = evt;
477 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
478 m_parent->signalAPIResult(&result);
479 }
480 break;
481 case QCAMERA_SM_EVT_SEND_COMMAND:
482 {
483 qcamera_sm_evt_command_payload_t *cmd_payload =
484 (qcamera_sm_evt_command_payload_t *)payload;
485 rc = m_parent->sendCommand(cmd_payload->cmd,
486 cmd_payload->arg1,
487 cmd_payload->arg2);
488 result.status = rc;
489 result.request_api = evt;
490 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
491 m_parent->signalAPIResult(&result);
492 }
493 break;
494 case QCAMERA_SM_EVT_START_RECORDING:
495 case QCAMERA_SM_EVT_STOP_RECORDING:
496 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
497 case QCAMERA_SM_EVT_PREPARE_SNAPSHOT:
498 case QCAMERA_SM_EVT_TAKE_PICTURE:
499 {
500 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
501 rc = INVALID_OPERATION;
502 result.status = rc;
503 result.request_api = evt;
504 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
505 m_parent->signalAPIResult(&result);
506 }
507 break;
508 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
509 case QCAMERA_SM_EVT_CANCEL_PICTURE:
510 {
511 // no op needed here
512 CDBG_HIGH("%s: No ops for evt(%d) in state(%d)", __func__, evt, m_state);
513 result.status = NO_ERROR;
514 result.request_api = evt;
515 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
516 m_parent->signalAPIResult(&result);
517 }
518 break;
519 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
520 {
521 bool isAFRunning = m_parent->isAFRunning();
522 rc = m_parent->cancelAutoFocus();
523 if (!isAFRunning) {
524 result.status = rc;
525 result.request_api = evt;
526 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
527 m_parent->signalAPIResult(&result);
528 }
529 }
530 break;
531 case QCAMERA_SM_EVT_REG_FACE_IMAGE:
532 {
533 int32_t faceID = 0;
534 qcamera_sm_evt_reg_face_payload_t *reg_payload =
535 (qcamera_sm_evt_reg_face_payload_t *)payload;
536 rc = m_parent->registerFaceImage(reg_payload->img_ptr,
537 reg_payload->config,
538 faceID);
539 result.status = rc;
540 result.request_api = evt;
541 result.result_type = QCAMERA_API_RESULT_TYPE_HANDLE;
542 result.handle = faceID;
543 m_parent->signalAPIResult(&result);
544 }
545 break;
546 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
547 {
548 rc = m_parent->updateThermalLevel(
549 *(qcamera_thermal_level_enum_t *)&payload);
550 }
551 break;
552 case QCAMERA_SM_EVT_EVT_NOTIFY:
553 {
554 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
555 switch (cam_evt->server_event_type) {
556 case CAM_EVENT_TYPE_DAEMON_DIED:
557 {
558 //close the camera backend
559 mm_camera_vtbl_t* handle = m_parent->mCameraHandle;
560 if (handle && handle->ops) {
561 handle->ops->error_close_camera(handle->camera_handle);
562 } else {
563 ALOGE("%s: Could not close because the handle or ops is NULL",
564 __func__);
565 }
566 m_parent->sendEvtNotify(CAMERA_MSG_ERROR,
567 CAMERA_ERROR_SERVER_DIED,
568 0);
569 }
570 break;
571 default:
572 ALOGE("%s: Invalid internal event %d in state(%d)",
573 __func__, cam_evt->server_event_type, m_state);
574 break;
575 }
576 }
577 break;
578 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
579 {
580 // No ops, but need to notify
581 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
582 result.status = rc;
583 result.request_api = evt;
584 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
585 m_parent->signalEvtResult(&result);
586 }
587 break;
588 case QCAMERA_SM_EVT_EVT_INTERNAL:
589 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
590 default:
591 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
592 break;
593 }
594
595 return rc;
596 }
597
598 /*===========================================================================
599 * FUNCTION : procEvtPreviewReadyState
600 *
601 * DESCRIPTION: finite state machine function to handle event in state of
602 * QCAMERA_SM_STATE_PREVIEW_READY.
603 *
604 * PARAMETERS :
605 * @evt : event to be processed
606 * @payload : event payload. Can be NULL if not needed.
607 *
608 * RETURN : int32_t type of status
609 * NO_ERROR -- success
610 * none-zero failure code
611 *==========================================================================*/
procEvtPreviewReadyState(qcamera_sm_evt_enum_t evt,void * payload)612 int32_t QCameraStateMachine::procEvtPreviewReadyState(qcamera_sm_evt_enum_t evt,
613 void *payload)
614 {
615 int32_t rc = NO_ERROR;
616 qcamera_api_result_t result;
617 memset(&result, 0, sizeof(qcamera_api_result_t));
618
619 ALOGV("%s: event (%d)", __func__, evt);
620 switch (evt) {
621 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
622 {
623 m_parent->setPreviewWindow((struct preview_stream_ops *)payload);
624 if (m_parent->mPreviewWindow != NULL) {
625 rc = m_parent->startPreview();
626 if (rc != NO_ERROR) {
627 m_parent->unpreparePreview();
628 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
629 } else {
630 m_state = QCAMERA_SM_STATE_PREVIEWING;
631 }
632 }
633
634 result.status = rc;
635 result.request_api = evt;
636 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
637 m_parent->signalAPIResult(&result);
638 }
639 break;
640 case QCAMERA_SM_EVT_SET_CALLBACKS:
641 {
642 qcamera_sm_evt_setcb_payload_t *setcbs =
643 (qcamera_sm_evt_setcb_payload_t *)payload;
644 rc = m_parent->setCallBacks(setcbs->notify_cb,
645 setcbs->data_cb,
646 setcbs->data_cb_timestamp,
647 setcbs->get_memory,
648 setcbs->user);
649 result.status = rc;
650 result.request_api = evt;
651 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
652 m_parent->signalAPIResult(&result);
653 }
654 break;
655 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
656 {
657 rc = m_parent->enableMsgType(int32_t(payload));
658 result.status = rc;
659 result.request_api = evt;
660 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
661 m_parent->signalAPIResult(&result);
662 }
663 break;
664 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
665 {
666 rc = m_parent->disableMsgType(int32_t(payload));
667 result.status = rc;
668 result.request_api = evt;
669 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
670 m_parent->signalAPIResult(&result);
671 }
672 break;
673 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
674 {
675 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
676 result.status = rc;
677 result.request_api = evt;
678 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
679 result.enabled = enabled;
680 m_parent->signalAPIResult(&result);
681 }
682 break;
683 case QCAMERA_SM_EVT_SET_PARAMS:
684 {
685 bool needRestart = false;
686 rc = m_parent->updateParameters((char*)payload, needRestart);
687 if (rc == NO_ERROR) {
688 if (needRestart) {
689 // need restart preview for parameters to take effect
690 m_parent->unpreparePreview();
691 // Clear memory pools
692 m_parent->m_memoryPool.clear();
693 // commit parameter changes to server
694 m_parent->commitParameterChanges();
695 // prepare preview again
696 rc = m_parent->preparePreview();
697 if (rc != NO_ERROR) {
698 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
699 }
700 } else {
701 rc = m_parent->commitParameterChanges();
702 }
703 }
704
705 result.status = rc;
706 result.request_api = evt;
707 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
708 m_parent->signalAPIResult(&result);
709 }
710 break;
711 case QCAMERA_SM_EVT_GET_PARAMS:
712 {
713 result.params = m_parent->getParameters();
714 rc = NO_ERROR;
715 result.status = rc;
716 result.request_api = evt;
717 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
718 m_parent->signalAPIResult(&result);
719 }
720 break;
721 case QCAMERA_SM_EVT_PUT_PARAMS:
722 {
723 rc = m_parent->putParameters((char*)payload);
724 result.status = rc;
725 result.request_api = evt;
726 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
727 m_parent->signalAPIResult(&result);
728 }
729 break;
730 case QCAMERA_SM_EVT_START_PREVIEW:
731 {
732 // no ops here
733 rc = NO_ERROR;
734 result.status = rc;
735 result.request_api = evt;
736 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
737 m_parent->signalAPIResult(&result);
738 }
739 break;
740 case QCAMERA_SM_EVT_STOP_PREVIEW:
741 {
742 m_parent->unpreparePreview();
743 rc = 0;
744 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
745 result.status = rc;
746 result.request_api = evt;
747 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
748 m_parent->signalAPIResult(&result);
749 }
750 break;
751 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
752 {
753 rc = NO_ERROR;
754 result.status = rc;
755 result.request_api = evt;
756 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
757 result.enabled = 1;
758 m_parent->signalAPIResult(&result);
759 }
760 break;
761 case QCAMERA_SM_EVT_RECORDING_ENABLED:
762 {
763 rc = 0;
764 result.status = rc;
765 result.request_api = evt;
766 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
767 result.enabled = 0;
768 m_parent->signalAPIResult(&result);
769 }
770 break;
771 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
772 {
773 rc = m_parent->storeMetaDataInBuffers(int(payload));
774 result.status = rc;
775 result.request_api = evt;
776 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
777 m_parent->signalAPIResult(&result);
778 }
779 break;
780 case QCAMERA_SM_EVT_DUMP:
781 {
782 rc = m_parent->dump((int)payload);
783 result.status = rc;
784 result.request_api = evt;
785 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
786 m_parent->signalAPIResult(&result);
787 }
788 break;
789 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
790 {
791 rc = m_parent->autoFocus();
792 result.status = rc;
793 result.request_api = evt;
794 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
795 m_parent->signalAPIResult(&result);
796 }
797 break;
798 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
799 {
800 bool isAFRunning = m_parent->isAFRunning();
801 rc = m_parent->cancelAutoFocus();
802 if (!isAFRunning) {
803 result.status = rc;
804 result.request_api = evt;
805 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
806 m_parent->signalAPIResult(&result);
807 }
808 }
809 break;
810 case QCAMERA_SM_EVT_SEND_COMMAND:
811 {
812 qcamera_sm_evt_command_payload_t *cmd_payload =
813 (qcamera_sm_evt_command_payload_t *)payload;
814 rc = m_parent->sendCommand(cmd_payload->cmd,
815 cmd_payload->arg1,
816 cmd_payload->arg2);
817 result.status = rc;
818 result.request_api = evt;
819 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
820 m_parent->signalAPIResult(&result);
821 }
822 break;
823 case QCAMERA_SM_EVT_REG_FACE_IMAGE:
824 {
825 int32_t faceID = 0;
826 qcamera_sm_evt_reg_face_payload_t *reg_payload =
827 (qcamera_sm_evt_reg_face_payload_t *)payload;
828 rc = m_parent->registerFaceImage(reg_payload->img_ptr,
829 reg_payload->config,
830 faceID);
831 result.status = rc;
832 result.request_api = evt;
833 result.result_type = QCAMERA_API_RESULT_TYPE_HANDLE;
834 result.handle = faceID;
835 m_parent->signalAPIResult(&result);
836 }
837 break;
838 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
839 case QCAMERA_SM_EVT_START_RECORDING:
840 case QCAMERA_SM_EVT_STOP_RECORDING:
841 case QCAMERA_SM_EVT_PREPARE_SNAPSHOT:
842 case QCAMERA_SM_EVT_TAKE_PICTURE:
843 case QCAMERA_SM_EVT_CANCEL_PICTURE:
844 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
845 case QCAMERA_SM_EVT_RELEASE:
846 {
847 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
848 rc = INVALID_OPERATION;
849 result.status = rc;
850 result.request_api = evt;
851 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
852 m_parent->signalAPIResult(&result);
853 }
854 break;
855 case QCAMERA_SM_EVT_EVT_NOTIFY:
856 {
857 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
858 switch (cam_evt->server_event_type) {
859 case CAM_EVENT_TYPE_DAEMON_DIED:
860 {
861 //close the camera backend
862 mm_camera_vtbl_t* handle = m_parent->mCameraHandle;
863 if (handle && handle->ops) {
864 handle->ops->error_close_camera(handle->camera_handle);
865 } else {
866 ALOGE("%s: Could not close because the handle or ops is NULL",
867 __func__);
868 }
869 m_parent->sendEvtNotify(CAMERA_MSG_ERROR,
870 CAMERA_ERROR_SERVER_DIED,
871 0);
872 }
873 break;
874 default:
875 ALOGE("%s: Invalid internal event %d in state(%d)",
876 __func__, cam_evt->server_event_type, m_state);
877 break;
878 }
879 }
880 break;
881 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
882 {
883 // No ops, but need to notify
884 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
885 result.status = rc;
886 result.request_api = evt;
887 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
888 m_parent->signalEvtResult(&result);
889 }
890 break;
891 case QCAMERA_SM_EVT_EVT_INTERNAL:
892 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
893 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
894 default:
895 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
896 break;
897 }
898
899 return rc;
900 }
901
902 /*===========================================================================
903 * FUNCTION : procEvtPreviewingState
904 *
905 * DESCRIPTION: finite state machine function to handle event in state of
906 * QCAMERA_SM_STATE_PREVIEWING.
907 *
908 * PARAMETERS :
909 * @evt : event to be processed
910 * @payload : event payload. Can be NULL if not needed.
911 *
912 * RETURN : int32_t type of status
913 * NO_ERROR -- success
914 * none-zero failure code
915 *==========================================================================*/
procEvtPreviewingState(qcamera_sm_evt_enum_t evt,void * payload)916 int32_t QCameraStateMachine::procEvtPreviewingState(qcamera_sm_evt_enum_t evt,
917 void *payload)
918 {
919 int32_t rc = NO_ERROR;
920 qcamera_api_result_t result;
921 memset(&result, 0, sizeof(qcamera_api_result_t));
922
923 ALOGV("%s: event (%d)", __func__, evt);
924 switch (evt) {
925 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
926 {
927 // Error setting preview window during previewing
928 ALOGE("Cannot set preview window when preview is running");
929 rc = INVALID_OPERATION;
930 result.status = rc;
931 result.request_api = evt;
932 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
933 m_parent->signalAPIResult(&result);
934 }
935 break;
936 case QCAMERA_SM_EVT_SET_CALLBACKS:
937 {
938 qcamera_sm_evt_setcb_payload_t *setcbs =
939 (qcamera_sm_evt_setcb_payload_t *)payload;
940 rc = m_parent->setCallBacks(setcbs->notify_cb,
941 setcbs->data_cb,
942 setcbs->data_cb_timestamp,
943 setcbs->get_memory,
944 setcbs->user);
945 result.status = rc;
946 result.request_api = evt;
947 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
948 m_parent->signalAPIResult(&result);
949 }
950 break;
951 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
952 {
953 rc = m_parent->enableMsgType(int32_t(payload));
954 result.status = rc;
955 result.request_api = evt;
956 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
957 m_parent->signalAPIResult(&result);
958 }
959 break;
960 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
961 {
962 rc = m_parent->disableMsgType(int32_t(payload));
963 result.status = rc;
964 result.request_api = evt;
965 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
966 m_parent->signalAPIResult(&result);
967 }
968 break;
969 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
970 {
971 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
972 result.status = rc;
973 result.request_api = evt;
974 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
975 result.enabled = enabled;
976 m_parent->signalAPIResult(&result);
977 }
978 break;
979 case QCAMERA_SM_EVT_SET_PARAMS:
980 {
981 bool needRestart = false;
982 rc = m_parent->updateParameters((char*)payload, needRestart);
983 if (rc == NO_ERROR) {
984 if (needRestart) {
985 // need restart preview for parameters to take effect
986 // stop preview
987 m_parent->stopPreview();
988 // Clear memory pools
989 m_parent->m_memoryPool.clear();
990 // commit parameter changes to server
991 m_parent->commitParameterChanges();
992 // start preview again
993 rc = m_parent->preparePreview();
994 if (rc == NO_ERROR) {
995 rc = m_parent->startPreview();
996 if (rc != NO_ERROR) {
997 m_parent->unpreparePreview();
998 }
999 }
1000 if (rc != NO_ERROR) {
1001 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
1002 }
1003 } else {
1004 rc = m_parent->commitParameterChanges();
1005 }
1006 }
1007 result.status = rc;
1008 result.request_api = evt;
1009 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1010 m_parent->signalAPIResult(&result);
1011 }
1012 break;
1013 case QCAMERA_SM_EVT_GET_PARAMS:
1014 {
1015 result.params = m_parent->getParameters();
1016 rc = NO_ERROR;
1017 result.status = rc;
1018 result.request_api = evt;
1019 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
1020 m_parent->signalAPIResult(&result);
1021 }
1022 break;
1023 case QCAMERA_SM_EVT_PUT_PARAMS:
1024 {
1025 rc = m_parent->putParameters((char*)payload);
1026 result.status = rc;
1027 result.request_api = evt;
1028 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1029 m_parent->signalAPIResult(&result);
1030 }
1031 break;
1032 case QCAMERA_SM_EVT_START_PREVIEW:
1033 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
1034 {
1035 // no ops here
1036 CDBG_HIGH("%s: Already in previewing, no ops here to start preview", __func__);
1037 rc = NO_ERROR;
1038 result.status = rc;
1039 result.request_api = evt;
1040 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1041 m_parent->signalAPIResult(&result);
1042 }
1043 break;
1044 case QCAMERA_SM_EVT_STOP_PREVIEW:
1045 {
1046 rc = m_parent->stopPreview();
1047 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
1048 result.status = rc;
1049 result.request_api = evt;
1050 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1051 m_parent->signalAPIResult(&result);
1052 }
1053 break;
1054 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
1055 {
1056 rc = NO_ERROR;
1057 result.status = rc;
1058 result.request_api = evt;
1059 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1060 result.enabled = 1;
1061 m_parent->signalAPIResult(&result);
1062 }
1063 break;
1064 case QCAMERA_SM_EVT_RECORDING_ENABLED:
1065 {
1066 rc = NO_ERROR;
1067 result.status = rc;
1068 result.request_api = evt;
1069 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1070 result.enabled = 0;
1071 m_parent->signalAPIResult(&result);
1072 }
1073 break;
1074 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
1075 {
1076 rc = m_parent->storeMetaDataInBuffers(int(payload));
1077 result.status = rc;
1078 result.request_api = evt;
1079 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1080 m_parent->signalAPIResult(&result);
1081 }
1082 break;
1083 case QCAMERA_SM_EVT_DUMP:
1084 {
1085 rc = m_parent->dump((int)payload);
1086 result.status = rc;
1087 result.request_api = evt;
1088 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1089 m_parent->signalAPIResult(&result);
1090 }
1091 break;
1092 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
1093 {
1094 rc = m_parent->autoFocus();
1095 result.status = rc;
1096 result.request_api = evt;
1097 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1098 m_parent->signalAPIResult(&result);
1099 }
1100 break;
1101 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
1102 {
1103 bool isAFRunning = m_parent->isAFRunning();
1104 rc = m_parent->cancelAutoFocus();
1105 if (!isAFRunning) {
1106 result.status = rc;
1107 result.request_api = evt;
1108 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1109 m_parent->signalAPIResult(&result);
1110 }
1111 }
1112 break;
1113 case QCAMERA_SM_EVT_START_RECORDING:
1114 {
1115 rc = m_parent->startRecording();
1116 if (rc == NO_ERROR) {
1117 // move state to recording state
1118 m_state = QCAMERA_SM_STATE_RECORDING;
1119 }
1120 result.status = rc;
1121 result.request_api = evt;
1122 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1123 m_parent->signalAPIResult(&result);
1124 }
1125 break;
1126 case QCAMERA_SM_EVT_PREPARE_SNAPSHOT:
1127 {
1128 rc = m_parent->prepareHardwareForSnapshot(FALSE);
1129 if (rc == NO_ERROR) {
1130 // Do not signal API result in this case.
1131 // Need to wait for snapshot done in metadta.
1132 m_state = QCAMERA_SM_STATE_PREPARE_SNAPSHOT;
1133 } else {
1134 // Do not change state in this case.
1135 ALOGE("%s: prepareHardwareForSnapshot failed %d",
1136 __func__, rc);
1137
1138 result.status = rc;
1139 result.request_api = evt;
1140 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1141 m_parent->signalAPIResult(&result);
1142 }
1143 }
1144 break;
1145 case QCAMERA_SM_EVT_TAKE_PICTURE:
1146 {
1147
1148 ALOGV("%s: QCAMERA_SM_EVT_TAKE_PICTURE ", __func__);
1149 if ( m_parent->mParameters.getRecordingHintValue() == false) {
1150 if (m_parent->isZSLMode() || m_parent->isLongshotEnabled()) {
1151 m_state = QCAMERA_SM_STATE_PREVIEW_PIC_TAKING;
1152 rc = m_parent->takePicture();
1153 if (rc != NO_ERROR) {
1154 // move state to previewing state
1155 m_state = QCAMERA_SM_STATE_PREVIEWING;
1156 }
1157 if (!(m_parent->isRetroPicture()) || (rc != NO_ERROR)) {
1158 ALOGD("%s: signal API result, m_state = %d",
1159 __func__, m_state);
1160 result.status = rc;
1161 result.request_api = evt;
1162 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1163 m_parent->signalAPIResult(&result);
1164 }
1165 } else {
1166 m_state = QCAMERA_SM_STATE_PIC_TAKING;
1167 rc = m_parent->takePicture();
1168 if (rc != NO_ERROR) {
1169 // move state to preview stopped state
1170 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
1171 }
1172
1173 result.status = rc;
1174 result.request_api = evt;
1175 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1176 m_parent->signalAPIResult(&result);
1177 }
1178 } else {
1179 m_state = QCAMERA_SM_STATE_PREVIEW_PIC_TAKING;
1180 rc = m_parent->takeLiveSnapshot();
1181 if (rc != NO_ERROR ) {
1182 m_state = QCAMERA_SM_STATE_PREVIEWING;
1183 }
1184 result.status = rc;
1185 result.request_api = evt;
1186 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1187 m_parent->signalAPIResult(&result);
1188 }
1189 }
1190 break;
1191 case QCAMERA_SM_EVT_SEND_COMMAND:
1192 {
1193 qcamera_sm_evt_command_payload_t *cmd_payload =
1194 (qcamera_sm_evt_command_payload_t *)payload;
1195 rc = m_parent->sendCommand(cmd_payload->cmd,
1196 cmd_payload->arg1,
1197 cmd_payload->arg2);
1198 result.status = rc;
1199 result.request_api = evt;
1200 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1201 m_parent->signalAPIResult(&result);
1202 }
1203 break;
1204 case QCAMERA_SM_EVT_REG_FACE_IMAGE:
1205 {
1206 int32_t faceID = 0;
1207 qcamera_sm_evt_reg_face_payload_t *reg_payload =
1208 (qcamera_sm_evt_reg_face_payload_t *)payload;
1209 rc = m_parent->registerFaceImage(reg_payload->img_ptr,
1210 reg_payload->config,
1211 faceID);
1212 result.status = rc;
1213 result.request_api = evt;
1214 result.result_type = QCAMERA_API_RESULT_TYPE_HANDLE;
1215 result.handle = faceID;
1216 m_parent->signalAPIResult(&result);
1217 }
1218 break;
1219 case QCAMERA_SM_EVT_CANCEL_PICTURE:
1220 case QCAMERA_SM_EVT_STOP_RECORDING:
1221 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
1222 case QCAMERA_SM_EVT_RELEASE:
1223 {
1224 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1225 rc = INVALID_OPERATION;
1226 result.status = rc;
1227 result.request_api = evt;
1228 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1229 m_parent->signalAPIResult(&result);
1230 }
1231 break;
1232 case QCAMERA_SM_EVT_EVT_INTERNAL:
1233 {
1234 qcamera_sm_internal_evt_payload_t *internal_evt =
1235 (qcamera_sm_internal_evt_payload_t *)payload;
1236 switch (internal_evt->evt_type) {
1237 case QCAMERA_INTERNAL_EVT_FOCUS_UPDATE:
1238 rc = m_parent->processAutoFocusEvent(internal_evt->focus_data);
1239 break;
1240 case QCAMERA_INTERNAL_EVT_PREP_SNAPSHOT_DONE:
1241 break;
1242 case QCAMERA_INTERNAL_EVT_FACE_DETECT_RESULT:
1243 rc = m_parent->processFaceDetectionResult(&internal_evt->faces_data);
1244 break;
1245 case QCAMERA_INTERNAL_EVT_HISTOGRAM_STATS:
1246 rc = m_parent->processHistogramStats(internal_evt->stats_data);
1247 break;
1248 case QCAMERA_INTERNAL_EVT_CROP_INFO:
1249 rc = m_parent->processZoomEvent(internal_evt->crop_data);
1250 break;
1251 case QCAMERA_INTERNAL_EVT_ASD_UPDATE:
1252 rc = m_parent->processASDUpdate(internal_evt->asd_data);
1253 break;
1254 default:
1255 ALOGE("%s: Invalid internal event %d in state(%d)",
1256 __func__, internal_evt->evt_type, m_state);
1257 break;
1258 }
1259 }
1260 break;
1261 case QCAMERA_SM_EVT_EVT_NOTIFY:
1262 {
1263 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
1264 switch (cam_evt->server_event_type) {
1265 case CAM_EVENT_TYPE_DAEMON_DIED:
1266 {
1267 //close the camera backend
1268 mm_camera_vtbl_t* handle = m_parent->mCameraHandle;
1269 if (handle && handle->ops) {
1270 handle->ops->error_close_camera(handle->camera_handle);
1271 } else {
1272 ALOGE("%s: Could not close because the handle or ops is NULL",
1273 __func__);
1274 }
1275 m_parent->sendEvtNotify(CAMERA_MSG_ERROR,
1276 CAMERA_ERROR_SERVER_DIED,
1277 0);
1278 }
1279 break;
1280 default:
1281 CDBG_HIGH("%s: no handling for server evt (%d) at this state",
1282 __func__, cam_evt->server_event_type);
1283 break;
1284 }
1285 }
1286 break;
1287 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
1288 {
1289 rc = m_parent->updateThermalLevel(
1290 *(qcamera_thermal_level_enum_t *)&payload);
1291 }
1292 break;
1293 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
1294 {
1295 // No ops, but need to notify
1296 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1297 result.status = rc;
1298 result.request_api = evt;
1299 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1300 m_parent->signalEvtResult(&result);
1301 }
1302 break;
1303 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
1304 default:
1305 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1306 break;
1307 }
1308
1309 return rc;
1310 }
1311
1312 /*===========================================================================
1313 * FUNCTION : procEvtPrepareSnapshotState
1314 *
1315 * DESCRIPTION: finite state machine function to handle event in state of
1316 * QCAMERA_SM_STATE_PREPARE_SNAPSHOT.
1317 *
1318 * PARAMETERS :
1319 * @evt : event to be processed
1320 * @payload : event payload. Can be NULL if not needed.
1321 *
1322 * RETURN : int32_t type of status
1323 * NO_ERROR -- success
1324 * none-zero failure code
1325 *==========================================================================*/
procEvtPrepareSnapshotState(qcamera_sm_evt_enum_t evt,void * payload)1326 int32_t QCameraStateMachine::procEvtPrepareSnapshotState(qcamera_sm_evt_enum_t evt,
1327 void *payload)
1328 {
1329 int32_t rc = NO_ERROR;
1330 qcamera_api_result_t result;
1331 memset(&result, 0, sizeof(qcamera_api_result_t));
1332
1333 ALOGV("%s: event (%d)", __func__, evt);
1334 switch (evt) {
1335 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
1336 case QCAMERA_SM_EVT_SET_CALLBACKS:
1337 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
1338 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
1339 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
1340 case QCAMERA_SM_EVT_SET_PARAMS:
1341 case QCAMERA_SM_EVT_GET_PARAMS:
1342 case QCAMERA_SM_EVT_PUT_PARAMS:
1343 case QCAMERA_SM_EVT_START_PREVIEW:
1344 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
1345 case QCAMERA_SM_EVT_STOP_PREVIEW:
1346 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
1347 case QCAMERA_SM_EVT_RECORDING_ENABLED:
1348 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
1349 case QCAMERA_SM_EVT_DUMP:
1350 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
1351 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
1352 case QCAMERA_SM_EVT_START_RECORDING:
1353 case QCAMERA_SM_EVT_TAKE_PICTURE:
1354 case QCAMERA_SM_EVT_PREPARE_SNAPSHOT:
1355 case QCAMERA_SM_EVT_SEND_COMMAND:
1356 case QCAMERA_SM_EVT_CANCEL_PICTURE:
1357 case QCAMERA_SM_EVT_STOP_RECORDING:
1358 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
1359 case QCAMERA_SM_EVT_RELEASE:
1360 {
1361 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1362 rc = INVALID_OPERATION;
1363 result.status = rc;
1364 result.request_api = evt;
1365 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1366 m_parent->signalAPIResult(&result);
1367 }
1368 break;
1369 case QCAMERA_SM_EVT_EVT_INTERNAL:
1370 {
1371 qcamera_sm_internal_evt_payload_t *internal_evt =
1372 (qcamera_sm_internal_evt_payload_t *)payload;
1373 switch (internal_evt->evt_type) {
1374 case QCAMERA_INTERNAL_EVT_FOCUS_UPDATE:
1375 rc = m_parent->processAutoFocusEvent(internal_evt->focus_data);
1376 break;
1377 case QCAMERA_INTERNAL_EVT_PREP_SNAPSHOT_DONE:
1378 CDBG("%s: Received QCAMERA_INTERNAL_EVT_PREP_SNAPSHOT_DONE event",
1379 __func__);
1380 m_parent->processPrepSnapshotDoneEvent(internal_evt->prep_snapshot_state);
1381 m_state = QCAMERA_SM_STATE_PREVIEWING;
1382
1383 result.status = NO_ERROR;
1384 result.request_api = QCAMERA_SM_EVT_PREPARE_SNAPSHOT;
1385 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1386 m_parent->signalAPIResult(&result);
1387 break;
1388 case QCAMERA_INTERNAL_EVT_FACE_DETECT_RESULT:
1389 rc = m_parent->processFaceDetectionResult(&internal_evt->faces_data);
1390 break;
1391 case QCAMERA_INTERNAL_EVT_HISTOGRAM_STATS:
1392 rc = m_parent->processHistogramStats(internal_evt->stats_data);
1393 break;
1394 case QCAMERA_INTERNAL_EVT_CROP_INFO:
1395 rc = m_parent->processZoomEvent(internal_evt->crop_data);
1396 break;
1397 case QCAMERA_INTERNAL_EVT_ASD_UPDATE:
1398 rc = m_parent->processASDUpdate(internal_evt->asd_data);
1399 break;
1400 default:
1401 ALOGE("%s: Invalid internal event %d in state(%d)",
1402 __func__, internal_evt->evt_type, m_state);
1403 break;
1404 }
1405 }
1406 break;
1407 case QCAMERA_SM_EVT_EVT_NOTIFY:
1408 {
1409 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
1410 switch (cam_evt->server_event_type) {
1411 case CAM_EVENT_TYPE_DAEMON_DIED:
1412 {
1413 //close the camera backend
1414 mm_camera_vtbl_t* handle = m_parent->mCameraHandle;
1415 if (handle && handle->ops) {
1416 handle->ops->error_close_camera(handle->camera_handle);
1417 } else {
1418 ALOGE("%s: Could not close because the handle or ops is NULL",
1419 __func__);
1420 }
1421 m_parent->sendEvtNotify(CAMERA_MSG_ERROR,
1422 CAMERA_ERROR_SERVER_DIED,
1423 0);
1424 }
1425 break;
1426 default:
1427 ALOGE("%s: Invalid internal event %d in state(%d)",
1428 __func__, cam_evt->server_event_type, m_state);
1429 break;
1430 }
1431 }
1432 break;
1433 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
1434 {
1435 // No ops, but need to notify
1436 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1437 result.status = rc;
1438 result.request_api = evt;
1439 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1440 m_parent->signalEvtResult(&result);
1441 }
1442 break;
1443 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
1444 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
1445 default:
1446 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1447 break;
1448 }
1449
1450 return rc;
1451 }
1452
1453 /*===========================================================================
1454 * FUNCTION : procEvtPicTakingState
1455 *
1456 * DESCRIPTION: finite state machine function to handle event in state of
1457 * QCAMERA_SM_STATE_PIC_TAKING.
1458 *
1459 * PARAMETERS :
1460 * @evt : event to be processed
1461 * @payload : event payload. Can be NULL if not needed.
1462 *
1463 * RETURN : int32_t type of status
1464 * NO_ERROR -- success
1465 * none-zero failure code
1466 *==========================================================================*/
procEvtPicTakingState(qcamera_sm_evt_enum_t evt,void * payload)1467 int32_t QCameraStateMachine::procEvtPicTakingState(qcamera_sm_evt_enum_t evt,
1468 void *payload)
1469 {
1470 int32_t rc = NO_ERROR;
1471 qcamera_api_result_t result;
1472 memset(&result, 0, sizeof(qcamera_api_result_t));
1473
1474 ALOGV("%s: event (%d)", __func__, evt);
1475 switch (evt) {
1476 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
1477 {
1478 // Error setting preview window during previewing
1479 ALOGE("Cannot set preview window when preview is running");
1480 rc = INVALID_OPERATION;
1481 result.status = rc;
1482 result.request_api = evt;
1483 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1484 m_parent->signalAPIResult(&result);
1485 }
1486 break;
1487 case QCAMERA_SM_EVT_SET_CALLBACKS:
1488 {
1489 qcamera_sm_evt_setcb_payload_t *setcbs =
1490 (qcamera_sm_evt_setcb_payload_t *)payload;
1491 rc = m_parent->setCallBacks(setcbs->notify_cb,
1492 setcbs->data_cb,
1493 setcbs->data_cb_timestamp,
1494 setcbs->get_memory,
1495 setcbs->user);
1496 result.status = rc;
1497 result.request_api = evt;
1498 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1499 m_parent->signalAPIResult(&result);
1500 }
1501 break;
1502 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
1503 {
1504 rc = m_parent->enableMsgType(int32_t(payload));
1505 result.status = rc;
1506 result.request_api = evt;
1507 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1508 m_parent->signalAPIResult(&result);
1509 }
1510 break;
1511 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
1512 {
1513 rc = m_parent->disableMsgType(int32_t(payload));
1514 result.status = rc;
1515 result.request_api = evt;
1516 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1517 m_parent->signalAPIResult(&result);
1518 }
1519 break;
1520 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
1521 {
1522 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
1523 result.status = rc;
1524 result.request_api = evt;
1525 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1526 result.enabled = enabled;
1527 m_parent->signalAPIResult(&result);
1528 }
1529 break;
1530 case QCAMERA_SM_EVT_SET_PARAMS:
1531 {
1532 bool needRestart = false;
1533 rc = m_parent->updateParameters((char*)payload, needRestart);
1534 if (rc == NO_ERROR) {
1535 rc = m_parent->commitParameterChanges();
1536 }
1537 result.status = rc;
1538 result.request_api = evt;
1539 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1540 m_parent->signalAPIResult(&result);
1541 }
1542 break;
1543 case QCAMERA_SM_EVT_GET_PARAMS:
1544 {
1545 result.params = m_parent->getParameters();
1546 rc = NO_ERROR;
1547 result.status = rc;
1548 result.request_api = evt;
1549 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
1550 m_parent->signalAPIResult(&result);
1551 }
1552 break;
1553 case QCAMERA_SM_EVT_PUT_PARAMS:
1554 {
1555 rc = m_parent->putParameters((char*)payload);
1556 result.status = rc;
1557 result.request_api = evt;
1558 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1559 m_parent->signalAPIResult(&result);
1560 }
1561 break;
1562 case QCAMERA_SM_EVT_STOP_PREVIEW:
1563 {
1564 // cancel picture first
1565 rc = m_parent->cancelPicture();
1566 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
1567
1568 result.status = rc;
1569 result.request_api = evt;
1570 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1571 m_parent->signalAPIResult(&result);
1572 }
1573 break;
1574 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
1575 {
1576 rc = NO_ERROR;
1577 result.status = rc;
1578 result.request_api = evt;
1579 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1580 result.enabled = 0;
1581 m_parent->signalAPIResult(&result);
1582 }
1583 break;
1584 case QCAMERA_SM_EVT_RECORDING_ENABLED:
1585 {
1586 rc = NO_ERROR;
1587 result.status = rc;
1588 result.request_api = evt;
1589 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1590 result.enabled = 0;
1591 m_parent->signalAPIResult(&result);
1592 }
1593 break;
1594 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
1595 {
1596 rc = m_parent->storeMetaDataInBuffers(int(payload));
1597 result.status = rc;
1598 result.request_api = evt;
1599 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1600 m_parent->signalAPIResult(&result);
1601 }
1602 break;
1603 case QCAMERA_SM_EVT_DUMP:
1604 {
1605 rc = m_parent->dump((int)payload);
1606 result.status = rc;
1607 result.request_api = evt;
1608 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1609 m_parent->signalAPIResult(&result);
1610 }
1611 break;
1612 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
1613 {
1614 rc = m_parent->autoFocus();
1615 result.status = rc;
1616 result.request_api = evt;
1617 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1618 m_parent->signalAPIResult(&result);
1619 }
1620 break;
1621 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
1622 {
1623 bool isAFRunning = m_parent->isAFRunning();
1624 rc = m_parent->cancelAutoFocus();
1625 if (!isAFRunning) {
1626 result.status = rc;
1627 result.request_api = evt;
1628 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1629 m_parent->signalAPIResult(&result);
1630 }
1631 }
1632 break;
1633 case QCAMERA_SM_EVT_SEND_COMMAND:
1634 {
1635 qcamera_sm_evt_command_payload_t *cmd_payload =
1636 (qcamera_sm_evt_command_payload_t *)payload;
1637 rc = m_parent->sendCommand(cmd_payload->cmd,
1638 cmd_payload->arg1,
1639 cmd_payload->arg2);
1640 #ifndef VANILLA_HAL
1641 if ( CAMERA_CMD_LONGSHOT_OFF == cmd_payload->cmd ) {
1642 // move state to previewing state
1643 m_state = QCAMERA_SM_STATE_PREVIEWING;
1644 }
1645 #endif
1646 result.status = rc;
1647 result.request_api = evt;
1648 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1649 m_parent->signalAPIResult(&result);
1650 }
1651 break;
1652 case QCAMERA_SM_EVT_CANCEL_PICTURE:
1653 {
1654 rc = m_parent->cancelPicture();
1655 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
1656 result.status = rc;
1657 result.request_api = evt;
1658 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1659 m_parent->signalAPIResult(&result);
1660 }
1661 break;
1662 case QCAMERA_SM_EVT_REG_FACE_IMAGE:
1663 {
1664 int32_t faceID = 0;
1665 qcamera_sm_evt_reg_face_payload_t *reg_payload =
1666 (qcamera_sm_evt_reg_face_payload_t *)payload;
1667 rc = m_parent->registerFaceImage(reg_payload->img_ptr,
1668 reg_payload->config,
1669 faceID);
1670 result.status = rc;
1671 result.request_api = evt;
1672 result.result_type = QCAMERA_API_RESULT_TYPE_HANDLE;
1673 result.handle = faceID;
1674 m_parent->signalAPIResult(&result);
1675 }
1676 break;
1677 case QCAMERA_SM_EVT_TAKE_PICTURE:
1678 {
1679 if ( m_parent->isLongshotEnabled() ) {
1680 rc = m_parent->longShot();
1681 } else {
1682 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1683 rc = INVALID_OPERATION;
1684 }
1685
1686 result.status = rc;
1687 result.request_api = evt;
1688 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1689 m_parent->signalAPIResult(&result);
1690 }
1691 break;
1692 case QCAMERA_SM_EVT_PREPARE_SNAPSHOT:
1693 case QCAMERA_SM_EVT_START_RECORDING:
1694 case QCAMERA_SM_EVT_STOP_RECORDING:
1695 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
1696 case QCAMERA_SM_EVT_START_PREVIEW:
1697 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
1698 case QCAMERA_SM_EVT_RELEASE:
1699 {
1700 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1701 rc = INVALID_OPERATION;
1702 result.status = rc;
1703 result.request_api = evt;
1704 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1705 m_parent->signalAPIResult(&result);
1706 }
1707 break;
1708 case QCAMERA_SM_EVT_EVT_INTERNAL:
1709 {
1710 qcamera_sm_internal_evt_payload_t *internal_evt =
1711 (qcamera_sm_internal_evt_payload_t *)payload;
1712 switch (internal_evt->evt_type) {
1713 case QCAMERA_INTERNAL_EVT_FOCUS_UPDATE:
1714 rc = m_parent->processAutoFocusEvent(internal_evt->focus_data);
1715 break;
1716 case QCAMERA_INTERNAL_EVT_PREP_SNAPSHOT_DONE:
1717 break;
1718 case QCAMERA_INTERNAL_EVT_FACE_DETECT_RESULT:
1719 break;
1720 case QCAMERA_INTERNAL_EVT_HISTOGRAM_STATS:
1721 break;
1722 case QCAMERA_INTERNAL_EVT_CROP_INFO:
1723 rc = m_parent->processZoomEvent(internal_evt->crop_data);
1724 break;
1725 case QCAMERA_INTERNAL_EVT_ASD_UPDATE:
1726 rc = m_parent->processASDUpdate(internal_evt->asd_data);
1727 break;
1728 default:
1729 break;
1730 }
1731 }
1732 break;
1733 case QCAMERA_SM_EVT_EVT_NOTIFY:
1734 {
1735 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
1736 switch (cam_evt->server_event_type) {
1737 case CAM_EVENT_TYPE_DAEMON_DIED:
1738 {
1739 //close the camera backend
1740 mm_camera_vtbl_t* handle = m_parent->mCameraHandle;
1741 if (handle && handle->ops) {
1742 handle->ops->error_close_camera(handle->camera_handle);
1743 } else {
1744 ALOGE("%s: Could not close because the handle or ops is NULL",
1745 __func__);
1746 }
1747 m_parent->sendEvtNotify(CAMERA_MSG_ERROR,
1748 CAMERA_ERROR_SERVER_DIED,
1749 0);
1750 }
1751 break;
1752 default:
1753 CDBG_HIGH("%s: no handling for server evt (%d) at this state",
1754 __func__, cam_evt->server_event_type);
1755 break;
1756 }
1757 }
1758 break;
1759 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
1760 {
1761 qcamera_jpeg_evt_payload_t *jpeg_job =
1762 (qcamera_jpeg_evt_payload_t *)payload;
1763 rc = m_parent->processJpegNotify(jpeg_job);
1764 }
1765 break;
1766 case QCAMERA_SM_EVT_STOP_CAPTURE_CHANNEL:
1767 {
1768 bool restartPreview = m_parent->isPreviewRestartEnabled();
1769 rc = m_parent->stopCaptureChannel(restartPreview);
1770
1771 if (restartPreview && (NO_ERROR == rc)) {
1772 rc = m_parent->preparePreview();
1773 if (NO_ERROR == rc) {
1774 m_parent->m_bPreviewStarted = true;
1775 rc = m_parent->startPreview();
1776 }
1777 }
1778
1779 result.status = rc;
1780 result.request_api = evt;
1781 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1782 m_parent->signalAPIResult(&result);
1783 }
1784 break;
1785 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
1786 {
1787 rc = m_parent->cancelPicture();
1788
1789 bool restartPreview = m_parent->isPreviewRestartEnabled();
1790 if (restartPreview) {
1791 m_state = QCAMERA_SM_STATE_PREVIEWING;
1792 } else {
1793 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
1794 }
1795
1796 result.status = rc;
1797 result.request_api = evt;
1798 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1799 m_parent->signalEvtResult(&result);
1800 }
1801 break;
1802 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
1803 {
1804 rc = m_parent->updateThermalLevel(
1805 *(qcamera_thermal_level_enum_t *)&payload);
1806 }
1807 break;
1808 default:
1809 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1810 break;
1811 }
1812
1813 return rc;
1814 }
1815
1816 /*===========================================================================
1817 * FUNCTION : procEvtRecordingState
1818 *
1819 * DESCRIPTION: finite state machine function to handle event in state of
1820 * QCAMERA_SM_STATE_RECORDING.
1821 *
1822 * PARAMETERS :
1823 * @evt : event to be processed
1824 * @payload : event payload. Can be NULL if not needed.
1825 *
1826 * RETURN : int32_t type of status
1827 * NO_ERROR -- success
1828 * none-zero failure code
1829 *==========================================================================*/
procEvtRecordingState(qcamera_sm_evt_enum_t evt,void * payload)1830 int32_t QCameraStateMachine::procEvtRecordingState(qcamera_sm_evt_enum_t evt,
1831 void *payload)
1832 {
1833 int32_t rc = NO_ERROR;
1834 qcamera_api_result_t result;
1835 memset(&result, 0, sizeof(qcamera_api_result_t));
1836
1837 ALOGV("%s: event (%d)", __func__, evt);
1838 switch (evt) {
1839 case QCAMERA_SM_EVT_START_PREVIEW:
1840 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
1841 {
1842 // WA: CTS test VideoSnapshot will try to
1843 // start preview during video recording.
1844 CDBG_HIGH("CTS video restart op");
1845 rc = NO_ERROR;
1846 result.status = rc;
1847 result.request_api = evt;
1848 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1849 m_parent->signalAPIResult(&result);
1850 }
1851 break;
1852 case QCAMERA_SM_EVT_SET_CALLBACKS:
1853 {
1854 qcamera_sm_evt_setcb_payload_t *setcbs =
1855 (qcamera_sm_evt_setcb_payload_t *)payload;
1856 rc = m_parent->setCallBacks(setcbs->notify_cb,
1857 setcbs->data_cb,
1858 setcbs->data_cb_timestamp,
1859 setcbs->get_memory,
1860 setcbs->user);
1861 result.status = rc;
1862 result.request_api = evt;
1863 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1864 m_parent->signalAPIResult(&result);
1865 }
1866 break;
1867 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
1868 {
1869 rc = m_parent->enableMsgType(int32_t(payload));
1870 result.status = rc;
1871 result.request_api = evt;
1872 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1873 m_parent->signalAPIResult(&result);
1874 }
1875 break;
1876 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
1877 {
1878 rc = m_parent->disableMsgType(int32_t(payload));
1879 result.status = rc;
1880 result.request_api = evt;
1881 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1882 m_parent->signalAPIResult(&result);
1883 }
1884 break;
1885 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
1886 {
1887 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
1888 result.status = rc;
1889 result.request_api = evt;
1890 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1891 result.enabled = enabled;
1892 m_parent->signalAPIResult(&result);
1893 }
1894 break;
1895 case QCAMERA_SM_EVT_SET_PARAMS:
1896 {
1897 bool needRestart = false;
1898 rc = m_parent->updateParameters((char*)payload, needRestart);
1899 if (rc == NO_ERROR) {
1900 if (needRestart) {
1901 // cannot set parameters that requires restart during recording
1902 ALOGE("%s: Cannot set parameters that requires restart during recording",
1903 __func__);
1904 rc = BAD_VALUE;
1905 } else {
1906 rc = m_parent->commitParameterChanges();
1907 }
1908 }
1909 result.status = rc;
1910 result.request_api = evt;
1911 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1912 m_parent->signalAPIResult(&result);
1913 }
1914 break;
1915 case QCAMERA_SM_EVT_GET_PARAMS:
1916 {
1917 result.params = m_parent->getParameters();
1918 rc = NO_ERROR;
1919 result.status = rc;
1920 result.request_api = evt;
1921 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
1922 m_parent->signalAPIResult(&result);
1923 }
1924 break;
1925 case QCAMERA_SM_EVT_PUT_PARAMS:
1926 {
1927 rc = m_parent->putParameters((char*)payload);
1928 result.status = rc;
1929 result.request_api = evt;
1930 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1931 m_parent->signalAPIResult(&result);
1932 }
1933 break;
1934 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
1935 {
1936 rc = NO_ERROR;
1937 result.status = rc;
1938 result.request_api = evt;
1939 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1940 result.enabled = 0;
1941 m_parent->signalAPIResult(&result);
1942 }
1943 break;
1944 case QCAMERA_SM_EVT_RECORDING_ENABLED:
1945 {
1946 rc = NO_ERROR;
1947 result.status = rc;
1948 result.request_api = evt;
1949 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1950 result.enabled = 1;
1951 m_parent->signalAPIResult(&result);
1952 }
1953 break;
1954 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
1955 {
1956 rc = m_parent->storeMetaDataInBuffers(int(payload));
1957 result.status = rc;
1958 result.request_api = evt;
1959 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1960 m_parent->signalAPIResult(&result);
1961 }
1962 break;
1963 case QCAMERA_SM_EVT_DUMP:
1964 {
1965 rc = m_parent->dump((int)payload);
1966 result.status = rc;
1967 result.request_api = evt;
1968 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1969 m_parent->signalAPIResult(&result);
1970 }
1971 break;
1972 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
1973 {
1974 rc = m_parent->autoFocus();
1975 result.status = rc;
1976 result.request_api = evt;
1977 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1978 m_parent->signalAPIResult(&result);
1979 }
1980 break;
1981 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
1982 {
1983 bool isAFRunning = m_parent->isAFRunning();
1984 rc = m_parent->cancelAutoFocus();
1985 if (!isAFRunning) {
1986 result.status = rc;
1987 result.request_api = evt;
1988 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1989 m_parent->signalAPIResult(&result);
1990 }
1991 }
1992 break;
1993 case QCAMERA_SM_EVT_SEND_COMMAND:
1994 {
1995 qcamera_sm_evt_command_payload_t *cmd_payload =
1996 (qcamera_sm_evt_command_payload_t *)payload;
1997 rc = m_parent->sendCommand(cmd_payload->cmd,
1998 cmd_payload->arg1,
1999 cmd_payload->arg2);
2000 result.status = rc;
2001 result.request_api = evt;
2002 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2003 m_parent->signalAPIResult(&result);
2004 }
2005 break;
2006 case QCAMERA_SM_EVT_TAKE_PICTURE:
2007 {
2008 m_state = QCAMERA_SM_STATE_VIDEO_PIC_TAKING;
2009 rc = m_parent->takeLiveSnapshot();
2010 if (rc != NO_ERROR) {
2011 m_state = QCAMERA_SM_STATE_RECORDING;
2012 }
2013 result.status = rc;
2014 result.request_api = evt;
2015 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2016 m_parent->signalAPIResult(&result);
2017 }
2018 break;
2019 case QCAMERA_SM_EVT_START_RECORDING:
2020 {
2021 // no ops here
2022 CDBG_HIGH("%s: already in recording state, no ops for start_recording", __func__);
2023 rc = 0;
2024 result.status = rc;
2025 result.request_api = evt;
2026 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2027 m_parent->signalAPIResult(&result);
2028 }
2029 break;
2030 case QCAMERA_SM_EVT_STOP_RECORDING:
2031 {
2032 rc = m_parent->stopRecording();
2033 m_state = QCAMERA_SM_STATE_PREVIEWING;
2034 result.status = rc;
2035 result.request_api = evt;
2036 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2037 m_parent->signalAPIResult(&result);
2038 }
2039 break;
2040 case QCAMERA_SM_EVT_STOP_PREVIEW:
2041 {
2042 rc = m_parent->stopRecording();
2043 m_state = QCAMERA_SM_STATE_PREVIEWING;
2044
2045 rc = m_parent->stopPreview();
2046 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
2047
2048 result.status = rc;
2049 result.request_api = evt;
2050 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2051 m_parent->signalAPIResult(&result);
2052 }
2053 break;
2054 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
2055 {
2056 rc = m_parent->releaseRecordingFrame((const void *)payload);
2057 result.status = rc;
2058 result.request_api = evt;
2059 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2060 m_parent->signalAPIResult(&result);
2061 }
2062 break;
2063 case QCAMERA_SM_EVT_REG_FACE_IMAGE:
2064 {
2065 int32_t faceID = 0;
2066 qcamera_sm_evt_reg_face_payload_t *reg_payload =
2067 (qcamera_sm_evt_reg_face_payload_t *)payload;
2068 rc = m_parent->registerFaceImage(reg_payload->img_ptr,
2069 reg_payload->config,
2070 faceID);
2071 result.status = rc;
2072 result.request_api = evt;
2073 result.result_type = QCAMERA_API_RESULT_TYPE_HANDLE;
2074 result.handle = faceID;
2075 m_parent->signalAPIResult(&result);
2076 }
2077 break;
2078 case QCAMERA_SM_EVT_PREPARE_SNAPSHOT:
2079 {
2080 //In Video snapshot, prepare hardware is a no-op.
2081 result.status = NO_ERROR;
2082 result.request_api = evt;
2083 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2084 m_parent->signalAPIResult(&result);
2085 }
2086 break;
2087 case QCAMERA_SM_EVT_CANCEL_PICTURE:
2088 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
2089 case QCAMERA_SM_EVT_RELEASE:
2090 {
2091 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
2092 rc = INVALID_OPERATION;
2093 result.status = rc;
2094 result.request_api = evt;
2095 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2096 m_parent->signalAPIResult(&result);
2097 }
2098 break;
2099 case QCAMERA_SM_EVT_EVT_INTERNAL:
2100 {
2101 qcamera_sm_internal_evt_payload_t *internal_evt =
2102 (qcamera_sm_internal_evt_payload_t *)payload;
2103 switch (internal_evt->evt_type) {
2104 case QCAMERA_INTERNAL_EVT_FOCUS_UPDATE:
2105 rc = m_parent->processAutoFocusEvent(internal_evt->focus_data);
2106 break;
2107 case QCAMERA_INTERNAL_EVT_PREP_SNAPSHOT_DONE:
2108 break;
2109 case QCAMERA_INTERNAL_EVT_FACE_DETECT_RESULT:
2110 rc = m_parent->processFaceDetectionResult(&internal_evt->faces_data);
2111 break;
2112 case QCAMERA_INTERNAL_EVT_HISTOGRAM_STATS:
2113 rc = m_parent->processHistogramStats(internal_evt->stats_data);
2114 break;
2115 case QCAMERA_INTERNAL_EVT_CROP_INFO:
2116 rc = m_parent->processZoomEvent(internal_evt->crop_data);
2117 break;
2118 case QCAMERA_INTERNAL_EVT_ASD_UPDATE:
2119 rc = m_parent->processASDUpdate(internal_evt->asd_data);
2120 break;
2121 default:
2122 break;
2123 }
2124 }
2125 break;
2126 case QCAMERA_SM_EVT_EVT_NOTIFY:
2127 {
2128 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
2129 switch (cam_evt->server_event_type) {
2130 case CAM_EVENT_TYPE_DAEMON_DIED:
2131 {
2132 //close the camera backend
2133 mm_camera_vtbl_t* handle = m_parent->mCameraHandle;
2134 if (handle && handle->ops) {
2135 handle->ops->error_close_camera(handle->camera_handle);
2136 } else {
2137 ALOGE("%s: Could not close because the handle or ops is NULL",
2138 __func__);
2139 }
2140 m_parent->sendEvtNotify(CAMERA_MSG_ERROR,
2141 CAMERA_ERROR_SERVER_DIED,
2142 0);
2143 }
2144 break;
2145 default:
2146 ALOGE("%s: Invalid internal event %d in state(%d)",
2147 __func__, cam_evt->server_event_type, m_state);
2148 break;
2149 }
2150 }
2151 break;
2152 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
2153 {
2154 rc = m_parent->updateThermalLevel(
2155 *(qcamera_thermal_level_enum_t *)&payload);
2156 }
2157 break;
2158 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
2159 {
2160 // No ops, but need to notify
2161 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
2162 result.status = rc;
2163 result.request_api = evt;
2164 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2165 m_parent->signalEvtResult(&result);
2166 }
2167 break;
2168 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
2169 default:
2170 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
2171 break;
2172 }
2173
2174 return rc;
2175 }
2176
2177 /*===========================================================================
2178 * FUNCTION : procEvtVideoPicTakingState
2179 *
2180 * DESCRIPTION: finite state machine function to handle event in state of
2181 * QCAMERA_SM_STATE_VIDEO_PIC_TAKING.
2182 *
2183 * PARAMETERS :
2184 * @evt : event to be processed
2185 * @payload : event payload. Can be NULL if not needed.
2186 *
2187 * RETURN : int32_t type of status
2188 * NO_ERROR -- success
2189 * none-zero failure code
2190 *==========================================================================*/
procEvtVideoPicTakingState(qcamera_sm_evt_enum_t evt,void * payload)2191 int32_t QCameraStateMachine::procEvtVideoPicTakingState(qcamera_sm_evt_enum_t evt,
2192 void *payload)
2193 {
2194 int32_t rc = NO_ERROR;
2195 qcamera_api_result_t result;
2196 memset(&result, 0, sizeof(qcamera_api_result_t));
2197
2198 ALOGV("%s: event (%d)", __func__, evt);
2199 switch (evt) {
2200 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
2201 {
2202 // Error setting preview window during previewing
2203 ALOGE("Cannot set preview window when preview is running");
2204 rc = INVALID_OPERATION;
2205 result.status = rc;
2206 result.request_api = evt;
2207 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2208 m_parent->signalAPIResult(&result);
2209 }
2210 break;
2211 case QCAMERA_SM_EVT_SET_CALLBACKS:
2212 {
2213 qcamera_sm_evt_setcb_payload_t *setcbs =
2214 (qcamera_sm_evt_setcb_payload_t *)payload;
2215 rc = m_parent->setCallBacks(setcbs->notify_cb,
2216 setcbs->data_cb,
2217 setcbs->data_cb_timestamp,
2218 setcbs->get_memory,
2219 setcbs->user);
2220 result.status = rc;
2221 result.request_api = evt;
2222 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2223 m_parent->signalAPIResult(&result);
2224 }
2225 break;
2226 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
2227 {
2228 rc = m_parent->enableMsgType(int32_t(payload));
2229 result.status = rc;
2230 result.request_api = evt;
2231 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2232 m_parent->signalAPIResult(&result);
2233 }
2234 break;
2235 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
2236 {
2237 rc = m_parent->disableMsgType(int32_t(payload));
2238 result.status = rc;
2239 result.request_api = evt;
2240 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2241 m_parent->signalAPIResult(&result);
2242 }
2243 break;
2244 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
2245 {
2246 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
2247 result.status = rc;
2248 result.request_api = evt;
2249 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
2250 result.enabled = enabled;
2251 m_parent->signalAPIResult(&result);
2252 }
2253 break;
2254 case QCAMERA_SM_EVT_SET_PARAMS:
2255 {
2256 bool needRestart = false;
2257 rc = m_parent->updateParameters((char*)payload, needRestart);
2258 if (rc == NO_ERROR) {
2259 if (needRestart) {
2260 // cannot set parameters that requires restart during recording
2261 ALOGE("%s: Cannot set parameters that requires restart during recording",
2262 __func__);
2263 rc = BAD_VALUE;
2264 } else {
2265 rc = m_parent->commitParameterChanges();
2266 }
2267 }
2268 result.status = rc;
2269 result.request_api = evt;
2270 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2271 m_parent->signalAPIResult(&result);
2272 }
2273 break;
2274 case QCAMERA_SM_EVT_GET_PARAMS:
2275 {
2276 result.params = m_parent->getParameters();
2277 rc = NO_ERROR;
2278 result.status = rc;
2279 result.request_api = evt;
2280 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
2281 m_parent->signalAPIResult(&result);
2282 }
2283 break;
2284 case QCAMERA_SM_EVT_PUT_PARAMS:
2285 {
2286 rc = m_parent->putParameters((char*)payload);
2287 result.status = rc;
2288 result.request_api = evt;
2289 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2290 m_parent->signalAPIResult(&result);
2291 }
2292 break;
2293 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
2294 {
2295 rc = NO_ERROR;
2296 result.status = rc;
2297 result.request_api = evt;
2298 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
2299 result.enabled = 1;
2300 m_parent->signalAPIResult(&result);
2301 }
2302 break;
2303 case QCAMERA_SM_EVT_RECORDING_ENABLED:
2304 {
2305 rc = NO_ERROR;
2306 result.status = rc;
2307 result.request_api = evt;
2308 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
2309 result.enabled = 1;
2310 m_parent->signalAPIResult(&result);
2311 }
2312 break;
2313 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
2314 {
2315 rc = m_parent->storeMetaDataInBuffers(int(payload));
2316 result.status = rc;
2317 result.request_api = evt;
2318 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2319 m_parent->signalAPIResult(&result);
2320 }
2321 break;
2322 case QCAMERA_SM_EVT_DUMP:
2323 {
2324 rc = m_parent->dump((int)payload);
2325 result.status = rc;
2326 result.request_api = evt;
2327 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2328 m_parent->signalAPIResult(&result);
2329 }
2330 break;
2331 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
2332 {
2333 rc = m_parent->autoFocus();
2334 result.status = rc;
2335 result.request_api = evt;
2336 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2337 m_parent->signalAPIResult(&result);
2338 }
2339 break;
2340 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
2341 {
2342 bool isAFRunning = m_parent->isAFRunning();
2343 rc = m_parent->cancelAutoFocus();
2344 if (!isAFRunning) {
2345 result.status = rc;
2346 result.request_api = evt;
2347 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2348 m_parent->signalAPIResult(&result);
2349 }
2350 }
2351 break;
2352 case QCAMERA_SM_EVT_SEND_COMMAND:
2353 {
2354 qcamera_sm_evt_command_payload_t *cmd_payload =
2355 (qcamera_sm_evt_command_payload_t *)payload;
2356 rc = m_parent->sendCommand(cmd_payload->cmd,
2357 cmd_payload->arg1,
2358 cmd_payload->arg2);
2359 result.status = rc;
2360 result.request_api = evt;
2361 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2362 m_parent->signalAPIResult(&result);
2363 }
2364 break;
2365 case QCAMERA_SM_EVT_STOP_RECORDING:
2366 {
2367 rc = m_parent->cancelLiveSnapshot();
2368 m_state = QCAMERA_SM_STATE_RECORDING;
2369
2370 rc = m_parent->stopRecording();
2371 m_state = QCAMERA_SM_STATE_PREVIEWING;
2372
2373 result.status = rc;
2374 result.request_api = evt;
2375 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2376 m_parent->signalAPIResult(&result);
2377 }
2378 break;
2379 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
2380 {
2381 rc = m_parent->releaseRecordingFrame((const void *)payload);
2382 result.status = rc;
2383 result.request_api = evt;
2384 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2385 m_parent->signalAPIResult(&result);
2386 }
2387 break;
2388 case QCAMERA_SM_EVT_CANCEL_PICTURE:
2389 {
2390 rc = m_parent->cancelLiveSnapshot();
2391 m_state = QCAMERA_SM_STATE_RECORDING;
2392 result.status = rc;
2393 result.request_api = evt;
2394 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2395 m_parent->signalAPIResult(&result);
2396 }
2397 break;
2398 case QCAMERA_SM_EVT_REG_FACE_IMAGE:
2399 {
2400 int32_t faceID = 0;
2401 qcamera_sm_evt_reg_face_payload_t *reg_payload =
2402 (qcamera_sm_evt_reg_face_payload_t *)payload;
2403 rc = m_parent->registerFaceImage(reg_payload->img_ptr,
2404 reg_payload->config,
2405 faceID);
2406 result.status = rc;
2407 result.request_api = evt;
2408 result.result_type = QCAMERA_API_RESULT_TYPE_HANDLE;
2409 result.handle = faceID;
2410 m_parent->signalAPIResult(&result);
2411 }
2412 break;
2413 case QCAMERA_SM_EVT_STOP_PREVIEW:
2414 {
2415 rc = m_parent->cancelLiveSnapshot();
2416 m_state = QCAMERA_SM_STATE_RECORDING;
2417
2418 rc = m_parent->stopRecording();
2419 m_state = QCAMERA_SM_STATE_PREVIEWING;
2420
2421 rc = m_parent->stopPreview();
2422 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
2423
2424 result.status = rc;
2425 result.request_api = evt;
2426 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2427 m_parent->signalAPIResult(&result);
2428 }
2429 break;
2430 case QCAMERA_SM_EVT_START_RECORDING:
2431 case QCAMERA_SM_EVT_START_PREVIEW:
2432 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
2433 case QCAMERA_SM_EVT_PREPARE_SNAPSHOT:
2434 case QCAMERA_SM_EVT_TAKE_PICTURE:
2435 case QCAMERA_SM_EVT_RELEASE:
2436 {
2437 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
2438 rc = INVALID_OPERATION;
2439 result.status = rc;
2440 result.request_api = evt;
2441 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2442 m_parent->signalAPIResult(&result);
2443 }
2444 break;
2445 case QCAMERA_SM_EVT_EVT_INTERNAL:
2446 {
2447 qcamera_sm_internal_evt_payload_t *internal_evt =
2448 (qcamera_sm_internal_evt_payload_t *)payload;
2449 switch (internal_evt->evt_type) {
2450 case QCAMERA_INTERNAL_EVT_FOCUS_UPDATE:
2451 rc = m_parent->processAutoFocusEvent(internal_evt->focus_data);
2452 break;
2453 case QCAMERA_INTERNAL_EVT_PREP_SNAPSHOT_DONE:
2454 break;
2455 case QCAMERA_INTERNAL_EVT_FACE_DETECT_RESULT:
2456 rc = m_parent->processFaceDetectionResult(&internal_evt->faces_data);
2457 break;
2458 case QCAMERA_INTERNAL_EVT_HISTOGRAM_STATS:
2459 rc = m_parent->processHistogramStats(internal_evt->stats_data);
2460 break;
2461 case QCAMERA_INTERNAL_EVT_CROP_INFO:
2462 rc = m_parent->processZoomEvent(internal_evt->crop_data);
2463 break;
2464 case QCAMERA_INTERNAL_EVT_ASD_UPDATE:
2465 rc = m_parent->processASDUpdate(internal_evt->asd_data);
2466 break;
2467 default:
2468 break;
2469 }
2470 }
2471 break;
2472 case QCAMERA_SM_EVT_EVT_NOTIFY:
2473 {
2474 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
2475 switch (cam_evt->server_event_type) {
2476 case CAM_EVENT_TYPE_DAEMON_DIED:
2477 {
2478 //close the camera backend
2479 mm_camera_vtbl_t* handle = m_parent->mCameraHandle;
2480 if (handle && handle->ops) {
2481 handle->ops->error_close_camera(handle->camera_handle);
2482 } else {
2483 ALOGE("%s: Could not close because the handle or ops is NULL",
2484 __func__);
2485 }
2486 m_parent->sendEvtNotify(CAMERA_MSG_ERROR,
2487 CAMERA_ERROR_SERVER_DIED,
2488 0);
2489 }
2490 break;
2491 default:
2492 ALOGE("%s: Invalid internal event %d in state(%d)",
2493 __func__, cam_evt->server_event_type, m_state);
2494 break;
2495 }
2496 }
2497 break;
2498 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
2499 {
2500 qcamera_jpeg_evt_payload_t *jpeg_job =
2501 (qcamera_jpeg_evt_payload_t *)payload;
2502 rc = m_parent->processJpegNotify(jpeg_job);
2503 }
2504 break;
2505 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
2506 {
2507 rc = m_parent->cancelLiveSnapshot();
2508 m_state = QCAMERA_SM_STATE_RECORDING;
2509 result.status = rc;
2510 result.request_api = evt;
2511 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2512 m_parent->signalEvtResult(&result);
2513 }
2514 break;
2515 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
2516 {
2517 rc = m_parent->updateThermalLevel(
2518 *(qcamera_thermal_level_enum_t *)&payload);
2519 }
2520 break;
2521 default:
2522 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
2523 break;
2524 }
2525
2526 return rc;
2527 }
2528
2529 /*===========================================================================
2530 * FUNCTION : procEvtPreviewPicTakingState
2531 *
2532 * DESCRIPTION: finite state machine function to handle event in state of
2533 * QCAMERA_SM_STATE_PREVIEW_PIC_TAKING.
2534 *
2535 * PARAMETERS :
2536 * @evt : event to be processed
2537 * @payload : event payload. Can be NULL if not needed.
2538 *
2539 * RETURN : int32_t type of status
2540 * NO_ERROR -- success
2541 * none-zero failure code
2542 *==========================================================================*/
procEvtPreviewPicTakingState(qcamera_sm_evt_enum_t evt,void * payload)2543 int32_t QCameraStateMachine::procEvtPreviewPicTakingState(qcamera_sm_evt_enum_t evt,
2544 void *payload)
2545 {
2546 int32_t rc = NO_ERROR;
2547 qcamera_api_result_t result;
2548 memset(&result, 0, sizeof(qcamera_api_result_t));
2549
2550 ALOGV("%s: event (%d)", __func__, evt);
2551 switch (evt) {
2552 case QCAMERA_SM_EVT_SET_CALLBACKS:
2553 {
2554 qcamera_sm_evt_setcb_payload_t *setcbs =
2555 (qcamera_sm_evt_setcb_payload_t *)payload;
2556 rc = m_parent->setCallBacks(setcbs->notify_cb,
2557 setcbs->data_cb,
2558 setcbs->data_cb_timestamp,
2559 setcbs->get_memory,
2560 setcbs->user);
2561 result.status = rc;
2562 result.request_api = evt;
2563 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2564 m_parent->signalAPIResult(&result);
2565 }
2566 break;
2567 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
2568 {
2569 rc = m_parent->enableMsgType(int32_t(payload));
2570 result.status = rc;
2571 result.request_api = evt;
2572 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2573 m_parent->signalAPIResult(&result);
2574 }
2575 break;
2576 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
2577 {
2578 rc = m_parent->disableMsgType(int32_t(payload));
2579 result.status = rc;
2580 result.request_api = evt;
2581 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2582 m_parent->signalAPIResult(&result);
2583 }
2584 break;
2585 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
2586 {
2587 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
2588 result.status = rc;
2589 result.request_api = evt;
2590 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
2591 result.enabled = enabled;
2592 m_parent->signalAPIResult(&result);
2593 }
2594 break;
2595 case QCAMERA_SM_EVT_SET_PARAMS:
2596 {
2597 bool needRestart = false;
2598 rc = m_parent->updateParameters((char*)payload, needRestart);
2599 if (rc == NO_ERROR) {
2600 if (needRestart) {
2601 // need restart preview for parameters to take effect
2602 // stop preview
2603 m_parent->stopPreview();
2604 // Clear memory pools
2605 m_parent->m_memoryPool.clear();
2606 // commit parameter changes to server
2607 m_parent->commitParameterChanges();
2608 // start preview again
2609 rc = m_parent->preparePreview();
2610 if (rc == NO_ERROR) {
2611 rc = m_parent->startPreview();
2612 if (rc != NO_ERROR) {
2613 m_parent->unpreparePreview();
2614 }
2615 }
2616 if (rc != NO_ERROR) {
2617 m_state = QCAMERA_SM_STATE_PIC_TAKING;
2618 }
2619 } else {
2620 rc = m_parent->commitParameterChanges();
2621 }
2622 }
2623 result.status = rc;
2624 result.request_api = evt;
2625 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2626 m_parent->signalAPIResult(&result);
2627 }
2628 break;
2629 case QCAMERA_SM_EVT_GET_PARAMS:
2630 {
2631 result.params = m_parent->getParameters();
2632 rc = NO_ERROR;
2633 result.status = rc;
2634 result.request_api = evt;
2635 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
2636 m_parent->signalAPIResult(&result);
2637 }
2638 break;
2639 case QCAMERA_SM_EVT_PUT_PARAMS:
2640 {
2641 rc = m_parent->putParameters((char*)payload);
2642 result.status = rc;
2643 result.request_api = evt;
2644 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2645 m_parent->signalAPIResult(&result);
2646 }
2647 break;
2648 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
2649 {
2650 rc = NO_ERROR;
2651 result.status = rc;
2652 result.request_api = evt;
2653 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
2654 result.enabled = 1;
2655 m_parent->signalAPIResult(&result);
2656 }
2657 break;
2658 case QCAMERA_SM_EVT_RECORDING_ENABLED:
2659 {
2660 rc = NO_ERROR;
2661 result.status = rc;
2662 result.request_api = evt;
2663 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
2664 result.enabled = 0;
2665 m_parent->signalAPIResult(&result);
2666 }
2667 break;
2668 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
2669 {
2670 rc = m_parent->storeMetaDataInBuffers(int(payload));
2671 result.status = rc;
2672 result.request_api = evt;
2673 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2674 m_parent->signalAPIResult(&result);
2675 }
2676 break;
2677 case QCAMERA_SM_EVT_DUMP:
2678 {
2679 rc = m_parent->dump((int)payload);
2680 result.status = rc;
2681 result.request_api = evt;
2682 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2683 m_parent->signalAPIResult(&result);
2684 }
2685 break;
2686 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
2687 {
2688 rc = m_parent->autoFocus();
2689 result.status = rc;
2690 result.request_api = evt;
2691 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2692 m_parent->signalAPIResult(&result);
2693 }
2694 break;
2695 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
2696 {
2697 bool isAFRunning = m_parent->isAFRunning();
2698 rc = m_parent->cancelAutoFocus();
2699 if (!isAFRunning) {
2700 result.status = rc;
2701 result.request_api = evt;
2702 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2703 m_parent->signalAPIResult(&result);
2704 }
2705 }
2706 break;
2707 case QCAMERA_SM_EVT_SEND_COMMAND:
2708 {
2709 qcamera_sm_evt_command_payload_t *cmd_payload =
2710 (qcamera_sm_evt_command_payload_t *)payload;
2711 rc = m_parent->sendCommand(cmd_payload->cmd,
2712 cmd_payload->arg1,
2713 cmd_payload->arg2);
2714 #ifndef VANILLA_HAL
2715 if ( CAMERA_CMD_LONGSHOT_OFF == cmd_payload->cmd ) {
2716 // move state to previewing state
2717 m_state = QCAMERA_SM_STATE_PREVIEWING;
2718 }
2719 #endif
2720 result.status = rc;
2721 result.request_api = evt;
2722 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2723 m_parent->signalAPIResult(&result);
2724 }
2725 break;
2726 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
2727 {
2728 rc = m_parent->releaseRecordingFrame((const void *)payload);
2729 result.status = rc;
2730 result.request_api = evt;
2731 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2732 m_parent->signalAPIResult(&result);
2733 }
2734 break;
2735 case QCAMERA_SM_EVT_CANCEL_PICTURE:
2736 {
2737 if (m_parent->isZSLMode() || m_parent->isLongshotEnabled()) {
2738 rc = m_parent->cancelPicture();
2739 } else {
2740 rc = m_parent->cancelLiveSnapshot();
2741 }
2742 m_state = QCAMERA_SM_STATE_PREVIEWING;
2743 result.status = rc;
2744 result.request_api = evt;
2745 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2746 m_parent->signalAPIResult(&result);
2747 }
2748 break;
2749 case QCAMERA_SM_EVT_STOP_PREVIEW:
2750 {
2751 if (m_parent->isZSLMode()) {
2752 // cancel picture first
2753 rc = m_parent->cancelPicture();
2754 m_parent->stopChannel(QCAMERA_CH_TYPE_ZSL);
2755 } else if (m_parent->isLongshotEnabled()) {
2756 // just cancel picture
2757 rc = m_parent->cancelPicture();
2758 } else {
2759 rc = m_parent->cancelLiveSnapshot();
2760 m_parent->stopChannel(QCAMERA_CH_TYPE_PREVIEW);
2761 }
2762 // unprepare preview
2763 m_parent->unpreparePreview();
2764 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
2765 result.status = rc;
2766 result.request_api = evt;
2767 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2768 m_parent->signalAPIResult(&result);
2769 }
2770 break;
2771 case QCAMERA_SM_EVT_START_RECORDING:
2772 {
2773 if (m_parent->isZSLMode()) {
2774 ALOGE("%s: cannot handle evt(%d) in state(%d) in ZSL mode",
2775 __func__, evt, m_state);
2776 rc = INVALID_OPERATION;
2777 } else if (m_parent->isLongshotEnabled()) {
2778 ALOGE("%s: cannot handle evt(%d) in state(%d) in Longshot mode",
2779 __func__, evt, m_state);
2780 rc = INVALID_OPERATION;
2781 } else {
2782 rc = m_parent->startRecording();
2783 if (rc == NO_ERROR) {
2784 m_state = QCAMERA_SM_STATE_VIDEO_PIC_TAKING;
2785 }
2786 }
2787 result.status = rc;
2788 result.request_api = evt;
2789 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2790 m_parent->signalAPIResult(&result);
2791 }
2792 break;
2793 case QCAMERA_SM_EVT_REG_FACE_IMAGE:
2794 {
2795 int32_t faceID = 0;
2796 qcamera_sm_evt_reg_face_payload_t *reg_payload =
2797 (qcamera_sm_evt_reg_face_payload_t *)payload;
2798 rc = m_parent->registerFaceImage(reg_payload->img_ptr,
2799 reg_payload->config,
2800 faceID);
2801 result.status = rc;
2802 result.request_api = evt;
2803 result.result_type = QCAMERA_API_RESULT_TYPE_HANDLE;
2804 result.handle = faceID;
2805 m_parent->signalAPIResult(&result);
2806 }
2807 break;
2808 case QCAMERA_SM_EVT_TAKE_PICTURE:
2809 {
2810 if ( m_parent->isLongshotEnabled() ) {
2811 rc = m_parent->longShot();
2812 } else {
2813 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
2814 rc = INVALID_OPERATION;
2815 }
2816
2817 result.status = rc;
2818 result.request_api = evt;
2819 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2820 m_parent->signalAPIResult(&result);
2821 }
2822 break;
2823
2824 case QCAMERA_SM_EVT_PREPARE_SNAPSHOT:
2825 {
2826 ALOGD("%s: [ZSL Retro]Prepare Snapshot", __func__);
2827 if (m_parent->isRetroPicture()) {
2828 ALOGD("%s: [ZSL Retro] Prepare Snapshot in Retro Mode", __func__);
2829 rc = m_parent->prepareHardwareForSnapshot(FALSE);
2830 if (rc != NO_ERROR) {
2831 ALOGE("%s: [ZSL Retro]prepareHardwareForSnapshot failed %d",
2832 __func__, rc);
2833 result.status = rc;
2834 result.request_api = evt;
2835 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2836 m_parent->signalAPIResult(&result);
2837 }
2838 }
2839 else {
2840 ALOGE("%s: cannot handle evt(%d) in state(%d)",
2841 __func__, evt, m_state);
2842 rc = INVALID_OPERATION;
2843 result.status = rc;
2844 result.request_api = evt;
2845 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2846 m_parent->signalAPIResult(&result);
2847 }
2848 }
2849 break;
2850 case QCAMERA_SM_EVT_STOP_RECORDING:
2851 case QCAMERA_SM_EVT_START_PREVIEW:
2852 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
2853 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
2854 case QCAMERA_SM_EVT_RELEASE:
2855 {
2856 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
2857 rc = INVALID_OPERATION;
2858 result.status = rc;
2859 result.request_api = evt;
2860 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2861 m_parent->signalAPIResult(&result);
2862 }
2863 break;
2864 case QCAMERA_SM_EVT_EVT_INTERNAL:
2865 {
2866 qcamera_sm_internal_evt_payload_t *internal_evt =
2867 (qcamera_sm_internal_evt_payload_t *)payload;
2868 switch (internal_evt->evt_type) {
2869 case QCAMERA_INTERNAL_EVT_FOCUS_UPDATE:
2870 rc = m_parent->processAutoFocusEvent(internal_evt->focus_data);
2871 break;
2872 case QCAMERA_INTERNAL_EVT_PREP_SNAPSHOT_DONE:
2873 ALOGD("%s: [ZSL Retro]Received QCAMERA_INTERNAL_EVT_PREP_SNAPSHOT_DONE event",
2874 __func__);
2875 if (m_parent->isRetroPicture()) {
2876 m_parent->processPrepSnapshotDoneEvent(internal_evt->prep_snapshot_state);
2877 ALOGD("%s: [ZSL Retro] Retro picture", __func__);
2878 result.status = NO_ERROR;
2879 result.request_api = QCAMERA_SM_EVT_PREPARE_SNAPSHOT;
2880 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2881 m_parent->signalAPIResult(&result);
2882 }
2883 else {
2884 ALOGE("%s: [ZSL Retro] Invalid Case for "
2885 "QCAMERA_INTERNAL_EVT_READY_FOR_SNAPSHOT event", __func__);
2886 }
2887 break;
2888 case QCAMERA_INTERNAL_EVT_FACE_DETECT_RESULT:
2889 rc = m_parent->processFaceDetectionResult(&internal_evt->faces_data);
2890 break;
2891 case QCAMERA_INTERNAL_EVT_READY_FOR_SNAPSHOT:
2892 // This is valid only in Retro picture Mode
2893 if (m_parent->isRetroPicture()) {
2894 ALOGD("%s: [ZSL Retro] Received QCAMERA_INTERNAL_EVT_READY_FOR_SNAPSHOT event",
2895 __func__);
2896 result.status = NO_ERROR;
2897 result.request_api = QCAMERA_SM_EVT_TAKE_PICTURE;
2898 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2899 m_parent->signalAPIResult(&result);
2900 }
2901 else {
2902 ALOGD("%s: [ZSL Retro] Wrong Case for "
2903 "QCAMERA_INTERNAL_EVT_READY_FOR_SNAPSHOT event", __func__);
2904 }
2905 break;
2906 case QCAMERA_INTERNAL_EVT_HISTOGRAM_STATS:
2907 rc = m_parent->processHistogramStats(internal_evt->stats_data);
2908 break;
2909 case QCAMERA_INTERNAL_EVT_CROP_INFO:
2910 rc = m_parent->processZoomEvent(internal_evt->crop_data);
2911 break;
2912 case QCAMERA_INTERNAL_EVT_ASD_UPDATE:
2913 rc = m_parent->processASDUpdate(internal_evt->asd_data);
2914 break;
2915 default:
2916 break;
2917 }
2918 }
2919 break;
2920 case QCAMERA_SM_EVT_EVT_NOTIFY:
2921 {
2922 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
2923 switch (cam_evt->server_event_type) {
2924 case CAM_EVENT_TYPE_DAEMON_DIED:
2925 {
2926 //close the camera backend
2927 mm_camera_vtbl_t* handle = m_parent->mCameraHandle;
2928 if (handle && handle->ops) {
2929 handle->ops->error_close_camera(handle->camera_handle);
2930 } else {
2931 ALOGE("%s: Could not close because the handle or ops is NULL",
2932 __func__);
2933 }
2934 m_parent->sendEvtNotify(CAMERA_MSG_ERROR,
2935 CAMERA_ERROR_SERVER_DIED,
2936 0);
2937 }
2938 break;
2939 default:
2940 ALOGE("%s: Invalid internal event %d in state(%d)",
2941 __func__, cam_evt->server_event_type, m_state);
2942 break;
2943 }
2944 }
2945 break;
2946 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
2947 {
2948 ALOGV("%s: [ZSL Retro] Calling Process Jpeg Notify",
2949 __func__);
2950 qcamera_jpeg_evt_payload_t *jpeg_job =
2951 (qcamera_jpeg_evt_payload_t *)payload;
2952 rc = m_parent->processJpegNotify(jpeg_job);
2953 }
2954 break;
2955 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
2956 {
2957 ALOGV("%s: [ZSL Retro] Snapshot Done", __func__);
2958 if (m_parent->isZSLMode() || m_parent->isLongshotEnabled()) {
2959 rc = m_parent->cancelPicture();
2960 } else {
2961 rc = m_parent->cancelLiveSnapshot();
2962 }
2963 m_state = QCAMERA_SM_STATE_PREVIEWING;
2964 if (m_parent->isRetroPicture()){
2965 result.status = rc;
2966 result.request_api = evt;
2967 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2968 ALOGV("\n Signalling for JPEG snapshot done!!");
2969 m_parent->signalAPIResult(&result);
2970
2971 }
2972 result.status = rc;
2973 result.request_api = evt;
2974 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2975 m_parent->signalEvtResult(&result);
2976 }
2977 break;
2978 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
2979 {
2980 rc = m_parent->updateThermalLevel(
2981 *(qcamera_thermal_level_enum_t *)&payload);
2982 }
2983 break;
2984 default:
2985 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
2986 break;
2987 }
2988
2989 return rc;
2990 }
2991
2992 /*===========================================================================
2993 * FUNCTION : isRecording
2994 *
2995 * DESCRIPTION: check if recording is in process.
2996 *
2997 * PARAMETERS : None
2998 *
2999 * RETURN : true -- recording
3000 * false -- not in recording mode
3001 *==========================================================================*/
isRecording()3002 bool QCameraStateMachine::isRecording()
3003 {
3004 switch (m_state) {
3005 case QCAMERA_SM_STATE_RECORDING:
3006 case QCAMERA_SM_STATE_VIDEO_PIC_TAKING:
3007 return true;
3008 default:
3009 return false;
3010 }
3011 }
3012
3013 /*===========================================================================
3014 * FUNCTION : isPreviewRunning
3015 *
3016 * DESCRIPTION: check if preview is in process.
3017 *
3018 * PARAMETERS : None
3019 *
3020 * RETURN : true -- preview running
3021 * false -- preview stopped
3022 *==========================================================================*/
isPreviewRunning()3023 bool QCameraStateMachine::isPreviewRunning()
3024 {
3025 switch (m_state) {
3026 case QCAMERA_SM_STATE_PREVIEWING:
3027 case QCAMERA_SM_STATE_RECORDING:
3028 case QCAMERA_SM_STATE_VIDEO_PIC_TAKING:
3029 case QCAMERA_SM_STATE_PREVIEW_PIC_TAKING:
3030 case QCAMERA_SM_STATE_PREPARE_SNAPSHOT:
3031 case QCAMERA_SM_STATE_PREVIEW_READY:
3032 return true;
3033 default:
3034 return false;
3035 }
3036 }
3037
3038 /*===========================================================================
3039 * FUNCTION : isPreviewReady
3040 *
3041 * DESCRIPTION: check if preview is in ready state.
3042 *
3043 * PARAMETERS : None
3044 *
3045 * RETURN : true -- preview is in ready state
3046 * false -- preview is stopped
3047 *==========================================================================*/
isPreviewReady()3048 bool QCameraStateMachine::isPreviewReady()
3049 {
3050 switch (m_state) {
3051 case QCAMERA_SM_STATE_PREVIEW_READY:
3052 return true;
3053 default:
3054 return false;
3055 }
3056 }
3057
3058 /*===========================================================================
3059 * FUNCTION : isCaptureRunning
3060 *
3061 * DESCRIPTION: check if image capture is in process.
3062 *
3063 * PARAMETERS : None
3064 *
3065 * RETURN : true -- capture running
3066 * false -- capture stopped
3067 *==========================================================================*/
isCaptureRunning()3068 bool QCameraStateMachine::isCaptureRunning()
3069 {
3070 switch (m_state) {
3071 case QCAMERA_SM_STATE_PIC_TAKING:
3072 case QCAMERA_SM_STATE_VIDEO_PIC_TAKING:
3073 case QCAMERA_SM_STATE_PREVIEW_PIC_TAKING:
3074 return true;
3075 default:
3076 return false;
3077 }
3078 }
3079 /*===========================================================================
3080 * FUNCTION : isNonZSLCaptureRunning
3081 *
3082 * DESCRIPTION: check if image capture is in process in non ZSL mode.
3083 *
3084 * PARAMETERS : None
3085 *
3086 * RETURN : true -- capture running in non ZSL mode
3087 * false -- Either in not capture mode or captur is not in non ZSL mode
3088 *==========================================================================*/
isNonZSLCaptureRunning()3089 bool QCameraStateMachine::isNonZSLCaptureRunning()
3090 {
3091 switch (m_state) {
3092 case QCAMERA_SM_STATE_PIC_TAKING:
3093 return true;
3094 default:
3095 return false;
3096 }
3097 }
3098
3099 /*===========================================================================
3100 * FUNCTION : dump
3101 *
3102 * DESCRIPTION: Composes a string based on current configuration
3103 *
3104 * PARAMETERS : none
3105 *
3106 * RETURN : Formatted string
3107 *==========================================================================*/
dump()3108 String8 QCameraStateMachine::dump()
3109 {
3110 String8 str("\n");
3111 char s[128];
3112
3113 snprintf(s, 128, "Is Preview Running: %d\n", isPreviewRunning());
3114 str += s;
3115
3116 snprintf(s, 128, "Is Capture Running: %d\n", isCaptureRunning());
3117 str += s;
3118
3119 snprintf(s, 128, "Is Non ZSL Capture Running: %d\n",
3120 isNonZSLCaptureRunning());
3121 str += s;
3122
3123 snprintf(s, 128, "Current State: %d \n", m_state);
3124 str += s;
3125
3126 switch(m_state){
3127 case QCAMERA_SM_STATE_PREVIEW_STOPPED:
3128 snprintf(s, 128, " QCAMERA_SM_STATE_PREVIEW_STOPPED \n");
3129 break;
3130
3131 case QCAMERA_SM_STATE_PREVIEW_READY:
3132 snprintf(s, 128, " QCAMERA_SM_STATE_PREVIEW_READY \n");
3133 break;
3134
3135 case QCAMERA_SM_STATE_PREVIEWING:
3136 snprintf(s, 128, " QCAMERA_SM_STATE_PREVIEWING \n");
3137 break;
3138
3139 case QCAMERA_SM_STATE_PREPARE_SNAPSHOT:
3140 snprintf(s, 128, " QCAMERA_SM_STATE_PREPARE_SNAPSHOT \n");
3141 break;
3142
3143 case QCAMERA_SM_STATE_PIC_TAKING:
3144 snprintf(s, 128, " QCAMERA_SM_STATE_PIC_TAKING \n");
3145 break;
3146
3147 case QCAMERA_SM_STATE_RECORDING:
3148 snprintf(s, 128, " QCAMERA_SM_STATE_RECORDING \n");
3149 break;
3150
3151 case QCAMERA_SM_STATE_VIDEO_PIC_TAKING:
3152 snprintf(s, 128, " QCAMERA_SM_STATE_VIDEO_PIC_TAKING \n");
3153 break;
3154
3155 case QCAMERA_SM_STATE_PREVIEW_PIC_TAKING:
3156 snprintf(s, 128, " QCAMERA_SM_STATE_PREVIEW_PIC_TAKING \n");
3157 break;
3158 }
3159 str += s;
3160
3161 return str;
3162 }
3163
3164 }; // namespace qcamera
3165