blob: 507f9749b47ab210ddcbf56dfa2e4d7613753be7 [file] [log] [blame]
Muhua Li1612f422013-01-03 11:07:39 -08001/* Copyright (c) 2012-2013, The Linux Foundataion. All rights reserved.
Muhua Libc9a8082012-11-07 15:51:28 -08002*
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
Muhua Libc9a8082012-11-07 15:51:28 -080032#include <utils/Errors.h>
33#include "QCamera2HWI.h"
34#include "QCameraStateMachine.h"
35
Shuzhen Wang89635cf2012-12-20 13:47:22 -080036namespace qcamera {
Muhua Libc9a8082012-11-07 15:51:28 -080037
Muhua Lida2c4be2012-11-26 09:14:16 -080038/*===========================================================================
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 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -080049void *QCameraStateMachine::smEvtProcRoutine(void *data)
50{
51 int running = 1, ret;
52 QCameraStateMachine *pme = (QCameraStateMachine *)data;
53
54 ALOGD("%s: E", __func__);
55 do {
56 do {
Shuzhen Wang2da44612012-12-20 10:51:57 -080057 ret = cam_sem_wait(&pme->cmd_sem);
Muhua Libc9a8082012-11-07 15:51:28 -080058 if (ret != 0 && errno != EINVAL) {
Shuzhen Wang2da44612012-12-20 10:51:57 -080059 ALOGE("%s: cam_sem_wait error (%s)",
Muhua Libc9a8082012-11-07 15:51:28 -080060 __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:
Muhua Li31eaee02012-12-11 08:56:45 -080075 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;
Muhua Libc9a8082012-11-07 15:51:28 -080079 case QCAMERA_SM_CMD_TYPE_EVT:
80 pme->stateMachine(node->evt, node->evt_payload);
Muhua Li31eaee02012-12-11 08:56:45 -080081
82 // EVT is async call, so payload need to be free after use
83 free(node->evt_payload);
84 node->evt_payload = NULL;
Muhua Libc9a8082012-11-07 15:51:28 -080085 break;
86 case QCAMERA_SM_CMD_TYPE_EXIT:
87 running = 0;
88 break;
89 default:
90 break;
91 }
Muhua Li31eaee02012-12-11 08:56:45 -080092 free(node);
93 node = NULL;
Muhua Libc9a8082012-11-07 15:51:28 -080094 }
95 } while (running);
96 ALOGD("%s: X", __func__);
97 return NULL;
98}
99
Muhua Lida2c4be2012-11-26 09:14:16 -0800100/*===========================================================================
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 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800110QCameraStateMachine::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;
Shuzhen Wang2da44612012-12-20 10:51:57 -0800117 cam_sem_init(&cmd_sem, 0);
Muhua Libc9a8082012-11-07 15:51:28 -0800118 pthread_create(&cmd_pid,
119 NULL,
120 smEvtProcRoutine,
121 this);
122}
123
Muhua Lida2c4be2012-11-26 09:14:16 -0800124/*===========================================================================
125 * FUNCTION : ~QCameraStateMachine
126 *
127 * DESCRIPTION: desctructor of QCameraStateMachine. Will stop process thread.
128 *
129 * PARAMETERS : none
130 *
131 * RETURN : none
132 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800133QCameraStateMachine::~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);
Shuzhen Wang2da44612012-12-20 10:51:57 -0800143 cam_sem_post(&cmd_sem);
Muhua Libc9a8082012-11-07 15:51:28 -0800144
145 /* wait until cmd thread exits */
146 if (pthread_join(cmd_pid, NULL) != 0) {
147 ALOGD("%s: pthread dead already\n", __func__);
148 }
149 }
150 cmd_pid = 0;
151 }
Shuzhen Wang2da44612012-12-20 10:51:57 -0800152 cam_sem_destroy(&cmd_sem);
Muhua Libc9a8082012-11-07 15:51:28 -0800153}
154
Muhua Lida2c4be2012-11-26 09:14:16 -0800155/*===========================================================================
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 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800168int32_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));
Muhua Lida2c4be2012-11-26 09:14:16 -0800173 if (NULL == node) {
174 ALOGE("%s: No memory for qcamera_sm_cmd_t", __func__);
175 return NO_MEMORY;
Muhua Libc9a8082012-11-07 15:51:28 -0800176 }
Muhua Lida2c4be2012-11-26 09:14:16 -0800177
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)) {
Shuzhen Wang2da44612012-12-20 10:51:57 -0800183 cam_sem_post(&cmd_sem);
Muhua Lida2c4be2012-11-26 09:14:16 -0800184 return NO_ERROR;
185 } else {
186 free(node);
187 return UNKNOWN_ERROR;
188 }
Muhua Libc9a8082012-11-07 15:51:28 -0800189}
190
Muhua Lida2c4be2012-11-26 09:14:16 -0800191/*===========================================================================
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 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800205int32_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));
Muhua Lida2c4be2012-11-26 09:14:16 -0800210 if (NULL == node) {
211 ALOGE("%s: No memory for qcamera_sm_cmd_t", __func__);
212 return NO_MEMORY;
Muhua Libc9a8082012-11-07 15:51:28 -0800213 }
Muhua Lida2c4be2012-11-26 09:14:16 -0800214
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)) {
Shuzhen Wang2da44612012-12-20 10:51:57 -0800220 cam_sem_post(&cmd_sem);
Muhua Lida2c4be2012-11-26 09:14:16 -0800221 return NO_ERROR;
222 } else {
223 free(node);
224 return UNKNOWN_ERROR;
225 }
Muhua Libc9a8082012-11-07 15:51:28 -0800226}
227
Muhua Lida2c4be2012-11-26 09:14:16 -0800228/*===========================================================================
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 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800242int32_t QCameraStateMachine::stateMachine(qcamera_sm_evt_enum_t evt, void *payload)
243{
244 int32_t rc = NO_ERROR;
245 switch (m_state) {
246 case QCAMERA_SM_STATE_PREVIEW_STOPPED:
247 rc = procEvtPreviewStoppedState(evt, payload);
248 break;
249 case QCAMERA_SM_STATE_PREVIEW_READY:
250 rc = procEvtPreviewReadyState(evt, payload);
251 break;
252 case QCAMERA_SM_STATE_PREVIEWING:
253 rc = procEvtPreviewingState(evt, payload);
254 break;
Shuzhen Wang93f24112013-02-20 16:01:42 -0800255 case QCAMERA_SM_STATE_PREPARE_SNAPSHOT:
256 rc = procEvtPrepareSnapshotState(evt, payload);
257 break;
Muhua Libc9a8082012-11-07 15:51:28 -0800258 case QCAMERA_SM_STATE_PIC_TAKING:
259 rc = procEvtPicTakingState(evt, payload);
260 break;
261 case QCAMERA_SM_STATE_RECORDING:
262 rc = procEvtRecordingState(evt, payload);
263 break;
264 case QCAMERA_SM_STATE_VIDEO_PIC_TAKING:
265 rc = procEvtVideoPicTakingState(evt, payload);
266 break;
267 case QCAMERA_SM_STATE_PREVIEW_PIC_TAKING:
268 rc = procEvtPreviewPicTakingState(evt, payload);
269 break;
270 default:
271 break;
272 }
273
274 return rc;
275}
276
Muhua Lida2c4be2012-11-26 09:14:16 -0800277/*===========================================================================
278 * FUNCTION : procEvtPreviewStoppedState
279 *
280 * DESCRIPTION: finite state machine function to handle event in state of
281 * QCAMERA_SM_STATE_PREVIEW_STOPPED.
282 *
283 * PARAMETERS :
284 * @evt : event to be processed
285 * @payload : event payload. Can be NULL if not needed.
286 *
287 * RETURN : int32_t type of status
288 * NO_ERROR -- success
289 * none-zero failure code
290 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800291int32_t QCameraStateMachine::procEvtPreviewStoppedState(qcamera_sm_evt_enum_t evt,
292 void *payload)
293{
294 int32_t rc = NO_ERROR;
295 qcamera_api_result_t result;
296 memset(&result, 0, sizeof(qcamera_api_result_t));
297
298 switch (evt) {
299 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
300 {
301 rc = m_parent->setPreviewWindow((struct preview_stream_ops *)payload);
302 result.status = rc;
303 result.request_api = evt;
304 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
305 m_parent->signalAPIResult(&result);
306 }
307 break;
308 case QCAMERA_SM_EVT_SET_CALLBACKS:
309 {
310 qcamera_sm_evt_setcb_payload_t *setcbs =
311 (qcamera_sm_evt_setcb_payload_t *)payload;
312 rc = m_parent->setCallBacks(setcbs->notify_cb,
313 setcbs->data_cb,
314 setcbs->data_cb_timestamp,
315 setcbs->get_memory,
316 setcbs->user);
317 result.status = rc;
318 result.request_api = evt;
319 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
320 m_parent->signalAPIResult(&result);
321 }
322 break;
323 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
324 {
325 rc = m_parent->enableMsgType(int32_t(payload));
326 result.status = rc;
327 result.request_api = evt;
328 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
329 m_parent->signalAPIResult(&result);
330 }
331 break;
332 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
333 {
334 rc = m_parent->disableMsgType(int32_t(payload));
335 result.status = rc;
336 result.request_api = evt;
337 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
338 m_parent->signalAPIResult(&result);
339 }
340 break;
341 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
342 {
343 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
344 result.status = rc;
345 result.request_api = evt;
346 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
347 result.enabled = enabled;
348 m_parent->signalAPIResult(&result);
349 }
350 break;
351 case QCAMERA_SM_EVT_SET_PARAMS:
352 {
Muhua Lida2c4be2012-11-26 09:14:16 -0800353 bool needRestart = false;
354 rc = m_parent->updateParameters((char*)payload, needRestart);
355 if (rc == NO_ERROR) {
356 rc = m_parent->commitParameterChanges();
357 }
Muhua Libc9a8082012-11-07 15:51:28 -0800358 result.status = rc;
359 result.request_api = evt;
360 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
361 m_parent->signalAPIResult(&result);
362 }
363 break;
364 case QCAMERA_SM_EVT_GET_PARAMS:
365 {
366 result.params = m_parent->getParameters();
367 rc = NO_ERROR;
368 result.status = rc;
369 result.request_api = evt;
370 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
371 m_parent->signalAPIResult(&result);
372 }
373 break;
374 case QCAMERA_SM_EVT_PUT_PARAMS:
375 {
376 rc = m_parent->putParameters((char*)payload);
377 result.status = rc;
378 result.request_api = evt;
379 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
380 m_parent->signalAPIResult(&result);
381 }
382 break;
383 case QCAMERA_SM_EVT_START_PREVIEW:
384 {
385 if (m_parent->mPreviewWindow == NULL) {
Mansoor Aftab06c809c2013-01-23 19:44:47 -0800386 rc = m_parent->preparePreview();
387 if(rc == NO_ERROR) {
388 // preview window is not set yet, move to previewReady state
389 m_state = QCAMERA_SM_STATE_PREVIEW_READY;
390 } else {
391 ALOGE("%s: preparePreview failed",__func__);
392 }
Muhua Libc9a8082012-11-07 15:51:28 -0800393 } else {
394 rc = m_parent->preparePreview();
Muhua Lida2c4be2012-11-26 09:14:16 -0800395 if (rc == NO_ERROR) {
Muhua Libc9a8082012-11-07 15:51:28 -0800396 rc = m_parent->startPreview();
Muhua Lida2c4be2012-11-26 09:14:16 -0800397 if (rc != NO_ERROR) {
Muhua Libc9a8082012-11-07 15:51:28 -0800398 m_parent->unpreparePreview();
399 } else {
Muhua Lida2c4be2012-11-26 09:14:16 -0800400 // start preview success, move to previewing state
Muhua Libc9a8082012-11-07 15:51:28 -0800401 m_state = QCAMERA_SM_STATE_PREVIEWING;
402 }
403 }
404 }
405 result.status = rc;
406 result.request_api = evt;
407 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
408 m_parent->signalAPIResult(&result);
409 }
410 break;
411 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
412 {
413 rc = m_parent->preparePreview();
414 if (rc == NO_ERROR) {
415 rc = m_parent->startPreview();
416 if (rc != NO_ERROR) {
417 m_parent->unpreparePreview();
418 } else {
419 m_state = QCAMERA_SM_STATE_PREVIEWING;
420 }
421 }
422 result.status = rc;
423 result.request_api = evt;
424 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
425 m_parent->signalAPIResult(&result);
426 }
427 break;
428 case QCAMERA_SM_EVT_STOP_PREVIEW:
429 {
430 // no op needed here
431 ALOGD("%s: already in preview stopped state, do nothing", __func__);
432 result.status = NO_ERROR;
433 result.request_api = evt;
434 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
435 m_parent->signalAPIResult(&result);
436 }
437 break;
438 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
439 case QCAMERA_SM_EVT_RECORDING_ENABLED:
440 {
441 result.status = NO_ERROR;
442 result.request_api = evt;
443 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
444 result.enabled = 0;
445 m_parent->signalAPIResult(&result);
446 }
447 break;
448 case QCAMERA_SM_EVT_RELEASE:
449 {
450 rc = m_parent->release();
451 result.status = rc;
452 result.request_api = evt;
453 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
454 m_parent->signalAPIResult(&result);
455 }
456 break;
457 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
458 {
459 rc = m_parent->storeMetaDataInBuffers(int(payload));
460 result.status = rc;
461 result.request_api = evt;
462 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
463 m_parent->signalAPIResult(&result);
464 }
465 break;
466 case QCAMERA_SM_EVT_DUMP:
467 {
468 rc = m_parent->dump((int)payload);
469 result.status = rc;
470 result.request_api = evt;
471 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
472 m_parent->signalAPIResult(&result);
473 }
474 break;
Ankit Premrajka3b00dc62012-12-14 18:37:52 -0800475 case QCAMERA_SM_EVT_SEND_COMMAND:
476 {
477 qcamera_sm_evt_command_payload_t *cmd_payload =
478 (qcamera_sm_evt_command_payload_t *)payload;
479 rc = m_parent->sendCommand(cmd_payload->cmd,
480 cmd_payload->arg1,
481 cmd_payload->arg2);
482 result.status = rc;
483 result.request_api = evt;
484 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
485 m_parent->signalAPIResult(&result);
486 }
487 break;
Muhua Libc9a8082012-11-07 15:51:28 -0800488 case QCAMERA_SM_EVT_START_RECORDING:
489 case QCAMERA_SM_EVT_STOP_RECORDING:
490 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
Shuzhen Wang93f24112013-02-20 16:01:42 -0800491 case QCAMERA_SM_EVT_PREPARE_SNAPSHOT:
Muhua Libc9a8082012-11-07 15:51:28 -0800492 case QCAMERA_SM_EVT_TAKE_PICTURE:
Muhua Libc9a8082012-11-07 15:51:28 -0800493 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
Muhua Libc9a8082012-11-07 15:51:28 -0800494 {
495 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
496 rc = INVALID_OPERATION;
497 result.status = rc;
498 result.request_api = evt;
499 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
500 m_parent->signalAPIResult(&result);
501 }
502 break;
Muhua Li1612f422013-01-03 11:07:39 -0800503 case QCAMERA_SM_EVT_CANCEL_PICTURE:
Muhua Li1612f422013-01-03 11:07:39 -0800504 {
505 // no op needed here
506 ALOGD("%s: No ops for evt(%d) in state(%d)", __func__, evt, m_state);
507 result.status = NO_ERROR;
508 result.request_api = evt;
509 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
510 m_parent->signalAPIResult(&result);
511 }
512 break;
Muhua Li0c14e432013-03-06 15:50:17 -0800513 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
514 {
515 rc = m_parent->cancelAutoFocus();
516 result.status = rc;
517 result.request_api = evt;
518 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
519 m_parent->signalAPIResult(&result);
520 }
521 break;
Muhua Li5858c392013-02-04 17:53:34 -0800522 case QCAMERA_SM_EVT_REG_FACE_IMAGE:
523 {
524 int32_t faceID = 0;
525 qcamera_sm_evt_reg_face_payload_t *reg_payload =
526 (qcamera_sm_evt_reg_face_payload_t *)payload;
527 rc = m_parent->registerFaceImage(reg_payload->img_ptr,
528 reg_payload->config,
529 faceID);
530 result.status = rc;
531 result.request_api = evt;
532 result.result_type = QCAMERA_API_RESULT_TYPE_HANDLE;
533 result.handle = faceID;
534 m_parent->signalAPIResult(&result);
535 }
536 break;
Emilian Peev2ae455e2013-04-18 10:41:56 +0300537 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
538 {
539 rc = m_parent->updateThermalLevel(
540 *(qcamera_thermal_level_enum_t *)&payload);
541 }
542 break;
Muhua Libc9a8082012-11-07 15:51:28 -0800543 case QCAMERA_SM_EVT_EVT_NOTIFY:
Emilian Peev15690592013-04-19 09:55:40 +0300544 {
545 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
546 switch (cam_evt->server_event_type) {
547 case CAM_EVENT_TYPE_DAEMON_DIED:
548 {
Emilian Peev15690592013-04-19 09:55:40 +0300549 m_parent->sendEvtNotify(CAMERA_MSG_ERROR,
550 CAMERA_ERROR_SERVER_DIED,
551 0);
552 }
553 break;
554 default:
555 ALOGE("%s: Invalid internal event %d in state(%d)",
556 __func__, cam_evt->server_event_type, m_state);
557 break;
558 }
559 }
560 break;
Muhua Lic9390df2013-05-22 17:54:13 -0700561 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
562 {
563 // No ops, but need to notify
564 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
565 result.status = rc;
566 result.request_api = evt;
567 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
568 m_parent->signalEvtResult(&result);
569 }
570 break;
Emilian Peev15690592013-04-19 09:55:40 +0300571 case QCAMERA_SM_EVT_EVT_INTERNAL:
Muhua Libc9a8082012-11-07 15:51:28 -0800572 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
573 default:
574 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
575 break;
576 }
577
578 return rc;
579}
580
Muhua Lida2c4be2012-11-26 09:14:16 -0800581/*===========================================================================
582 * FUNCTION : procEvtPreviewReadyState
583 *
584 * DESCRIPTION: finite state machine function to handle event in state of
585 * QCAMERA_SM_STATE_PREVIEW_READY.
586 *
587 * PARAMETERS :
588 * @evt : event to be processed
589 * @payload : event payload. Can be NULL if not needed.
590 *
591 * RETURN : int32_t type of status
592 * NO_ERROR -- success
593 * none-zero failure code
594 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800595int32_t QCameraStateMachine::procEvtPreviewReadyState(qcamera_sm_evt_enum_t evt,
596 void *payload)
597{
598 int32_t rc = NO_ERROR;
599 qcamera_api_result_t result;
600 memset(&result, 0, sizeof(qcamera_api_result_t));
601
602 switch (evt) {
603 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
604 {
605 m_parent->setPreviewWindow((struct preview_stream_ops *)payload);
606 if (m_parent->mPreviewWindow != NULL) {
607 rc = m_parent->startPreview();
608 if (rc != NO_ERROR) {
609 m_parent->unpreparePreview();
610 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
611 } else {
612 m_state = QCAMERA_SM_STATE_PREVIEWING;
613 }
614 }
615
616 result.status = rc;
617 result.request_api = evt;
618 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
619 m_parent->signalAPIResult(&result);
620 }
621 break;
622 case QCAMERA_SM_EVT_SET_CALLBACKS:
623 {
624 qcamera_sm_evt_setcb_payload_t *setcbs =
625 (qcamera_sm_evt_setcb_payload_t *)payload;
626 rc = m_parent->setCallBacks(setcbs->notify_cb,
627 setcbs->data_cb,
628 setcbs->data_cb_timestamp,
629 setcbs->get_memory,
630 setcbs->user);
631 result.status = rc;
632 result.request_api = evt;
633 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
634 m_parent->signalAPIResult(&result);
635 }
636 break;
637 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
638 {
639 rc = m_parent->enableMsgType(int32_t(payload));
640 result.status = rc;
641 result.request_api = evt;
642 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
643 m_parent->signalAPIResult(&result);
644 }
645 break;
646 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
647 {
648 rc = m_parent->disableMsgType(int32_t(payload));
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_MSG_TYPE_ENABLED:
656 {
657 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
658 result.status = rc;
659 result.request_api = evt;
660 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
661 result.enabled = enabled;
662 m_parent->signalAPIResult(&result);
663 }
664 break;
665 case QCAMERA_SM_EVT_SET_PARAMS:
666 {
Muhua Lida2c4be2012-11-26 09:14:16 -0800667 bool needRestart = false;
668 rc = m_parent->updateParameters((char*)payload, needRestart);
669 if (rc == NO_ERROR) {
Muhua Li6d69e932013-01-24 16:39:27 -0800670 if (needRestart) {
671 // need restart preview for parameters to take effect
672 m_parent->unpreparePreview();
673 // commit parameter changes to server
674 m_parent->commitParameterChanges();
675 // prepare preview again
676 rc = m_parent->preparePreview();
677 if (rc != NO_ERROR) {
678 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
679 }
680 } else {
681 rc = m_parent->commitParameterChanges();
682 }
Muhua Lida2c4be2012-11-26 09:14:16 -0800683 }
Muhua Li6d69e932013-01-24 16:39:27 -0800684
Muhua Libc9a8082012-11-07 15:51:28 -0800685 result.status = rc;
686 result.request_api = evt;
687 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
688 m_parent->signalAPIResult(&result);
689 }
690 break;
691 case QCAMERA_SM_EVT_GET_PARAMS:
692 {
693 result.params = m_parent->getParameters();
694 rc = NO_ERROR;
695 result.status = rc;
696 result.request_api = evt;
697 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
698 m_parent->signalAPIResult(&result);
699 }
700 break;
701 case QCAMERA_SM_EVT_PUT_PARAMS:
702 {
703 rc = m_parent->putParameters((char*)payload);
704 result.status = rc;
705 result.request_api = evt;
706 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
707 m_parent->signalAPIResult(&result);
708 }
709 break;
710 case QCAMERA_SM_EVT_START_PREVIEW:
711 {
712 // no ops here
713 rc = NO_ERROR;
714 result.status = rc;
715 result.request_api = evt;
716 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
717 m_parent->signalAPIResult(&result);
718 }
719 break;
720 case QCAMERA_SM_EVT_STOP_PREVIEW:
721 {
722 m_parent->unpreparePreview();
723 rc = 0;
724 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
725 result.status = rc;
726 result.request_api = evt;
727 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
728 m_parent->signalAPIResult(&result);
729 }
730 break;
731 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
732 {
733 rc = NO_ERROR;
734 result.status = rc;
735 result.request_api = evt;
736 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
737 result.enabled = 1;
738 m_parent->signalAPIResult(&result);
739 }
740 break;
741 case QCAMERA_SM_EVT_RECORDING_ENABLED:
742 {
743 rc = 0;
744 result.status = rc;
745 result.request_api = evt;
746 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
747 result.enabled = 0;
748 m_parent->signalAPIResult(&result);
749 }
750 break;
751 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
752 {
753 rc = m_parent->storeMetaDataInBuffers(int(payload));
754 result.status = rc;
755 result.request_api = evt;
756 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
757 m_parent->signalAPIResult(&result);
758 }
759 break;
760 case QCAMERA_SM_EVT_DUMP:
761 {
762 rc = m_parent->dump((int)payload);
763 result.status = rc;
764 result.request_api = evt;
765 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
766 m_parent->signalAPIResult(&result);
767 }
768 break;
769 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
770 {
771 rc = m_parent->autoFocus();
772 result.status = rc;
773 result.request_api = evt;
774 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
775 m_parent->signalAPIResult(&result);
776 }
777 break;
778 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
779 {
780 rc = m_parent->cancelAutoFocus();
781 result.status = rc;
782 result.request_api = evt;
783 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
784 m_parent->signalAPIResult(&result);
785 }
786 break;
787 case QCAMERA_SM_EVT_SEND_COMMAND:
788 {
789 qcamera_sm_evt_command_payload_t *cmd_payload =
790 (qcamera_sm_evt_command_payload_t *)payload;
791 rc = m_parent->sendCommand(cmd_payload->cmd,
792 cmd_payload->arg1,
793 cmd_payload->arg2);
794 result.status = rc;
795 result.request_api = evt;
796 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
797 m_parent->signalAPIResult(&result);
798 }
799 break;
Muhua Li5858c392013-02-04 17:53:34 -0800800 case QCAMERA_SM_EVT_REG_FACE_IMAGE:
801 {
802 int32_t faceID = 0;
803 qcamera_sm_evt_reg_face_payload_t *reg_payload =
804 (qcamera_sm_evt_reg_face_payload_t *)payload;
805 rc = m_parent->registerFaceImage(reg_payload->img_ptr,
806 reg_payload->config,
807 faceID);
808 result.status = rc;
809 result.request_api = evt;
810 result.result_type = QCAMERA_API_RESULT_TYPE_HANDLE;
811 result.handle = faceID;
812 m_parent->signalAPIResult(&result);
813 }
814 break;
Muhua Libc9a8082012-11-07 15:51:28 -0800815 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
816 case QCAMERA_SM_EVT_START_RECORDING:
817 case QCAMERA_SM_EVT_STOP_RECORDING:
Shuzhen Wang93f24112013-02-20 16:01:42 -0800818 case QCAMERA_SM_EVT_PREPARE_SNAPSHOT:
Muhua Libc9a8082012-11-07 15:51:28 -0800819 case QCAMERA_SM_EVT_TAKE_PICTURE:
820 case QCAMERA_SM_EVT_CANCEL_PICTURE:
821 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
822 case QCAMERA_SM_EVT_RELEASE:
823 {
824 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
825 rc = INVALID_OPERATION;
826 result.status = rc;
827 result.request_api = evt;
828 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
829 m_parent->signalAPIResult(&result);
830 }
831 break;
832 case QCAMERA_SM_EVT_EVT_NOTIFY:
Emilian Peev15690592013-04-19 09:55:40 +0300833 {
834 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
835 switch (cam_evt->server_event_type) {
836 case CAM_EVENT_TYPE_DAEMON_DIED:
837 {
Emilian Peev15690592013-04-19 09:55:40 +0300838 m_parent->sendEvtNotify(CAMERA_MSG_ERROR,
839 CAMERA_ERROR_SERVER_DIED,
840 0);
841 }
842 break;
843 default:
844 ALOGE("%s: Invalid internal event %d in state(%d)",
845 __func__, cam_evt->server_event_type, m_state);
846 break;
847 }
848 }
849 break;
Muhua Lic9390df2013-05-22 17:54:13 -0700850 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
851 {
852 // No ops, but need to notify
853 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
854 result.status = rc;
855 result.request_api = evt;
856 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
857 m_parent->signalEvtResult(&result);
858 }
859 break;
Emilian Peev15690592013-04-19 09:55:40 +0300860 case QCAMERA_SM_EVT_EVT_INTERNAL:
Muhua Libc9a8082012-11-07 15:51:28 -0800861 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
Shuzhen Wangaa829ce2013-01-09 14:41:49 -0800862 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
Muhua Libc9a8082012-11-07 15:51:28 -0800863 default:
864 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
865 break;
866 }
867
868 return rc;
869}
870
Muhua Lida2c4be2012-11-26 09:14:16 -0800871/*===========================================================================
872 * FUNCTION : procEvtPreviewingState
873 *
874 * DESCRIPTION: finite state machine function to handle event in state of
875 * QCAMERA_SM_STATE_PREVIEWING.
876 *
877 * PARAMETERS :
878 * @evt : event to be processed
879 * @payload : event payload. Can be NULL if not needed.
880 *
881 * RETURN : int32_t type of status
882 * NO_ERROR -- success
883 * none-zero failure code
884 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800885int32_t QCameraStateMachine::procEvtPreviewingState(qcamera_sm_evt_enum_t evt,
886 void *payload)
887{
888 int32_t rc = NO_ERROR;
889 qcamera_api_result_t result;
890 memset(&result, 0, sizeof(qcamera_api_result_t));
891
892 switch (evt) {
893 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
894 {
895 // Error setting preview window during previewing
896 ALOGE("Cannot set preview window when preview is running");
897 rc = INVALID_OPERATION;
898 result.status = rc;
899 result.request_api = evt;
900 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
901 m_parent->signalAPIResult(&result);
902 }
903 break;
904 case QCAMERA_SM_EVT_SET_CALLBACKS:
905 {
906 qcamera_sm_evt_setcb_payload_t *setcbs =
907 (qcamera_sm_evt_setcb_payload_t *)payload;
908 rc = m_parent->setCallBacks(setcbs->notify_cb,
909 setcbs->data_cb,
910 setcbs->data_cb_timestamp,
911 setcbs->get_memory,
912 setcbs->user);
913 result.status = rc;
914 result.request_api = evt;
915 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
916 m_parent->signalAPIResult(&result);
917 }
918 break;
919 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
920 {
921 rc = m_parent->enableMsgType(int32_t(payload));
922 result.status = rc;
923 result.request_api = evt;
924 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
925 m_parent->signalAPIResult(&result);
926 }
927 break;
928 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
929 {
930 rc = m_parent->disableMsgType(int32_t(payload));
931 result.status = rc;
932 result.request_api = evt;
933 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
934 m_parent->signalAPIResult(&result);
935 }
936 break;
937 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
938 {
939 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
940 result.status = rc;
941 result.request_api = evt;
942 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
943 result.enabled = enabled;
944 m_parent->signalAPIResult(&result);
945 }
946 break;
947 case QCAMERA_SM_EVT_SET_PARAMS:
948 {
Muhua Lida2c4be2012-11-26 09:14:16 -0800949 bool needRestart = false;
950 rc = m_parent->updateParameters((char*)payload, needRestart);
951 if (rc == NO_ERROR) {
952 if (needRestart) {
953 // need restart preview for parameters to take effect
954 // stop preview
955 m_parent->stopPreview();
956 // commit parameter changes to server
Muhua Li66f3b532013-01-23 17:19:05 -0800957 m_parent->commitParameterChanges();
Muhua Lida2c4be2012-11-26 09:14:16 -0800958 // start preview again
Muhua Li66f3b532013-01-23 17:19:05 -0800959 rc = m_parent->preparePreview();
960 if (rc == NO_ERROR) {
961 rc = m_parent->startPreview();
962 if (rc != NO_ERROR) {
963 m_parent->unpreparePreview();
964 }
965 }
966 if (rc != NO_ERROR) {
967 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
968 }
Muhua Lida2c4be2012-11-26 09:14:16 -0800969 } else {
970 rc = m_parent->commitParameterChanges();
971 }
972 }
Muhua Libc9a8082012-11-07 15:51:28 -0800973 result.status = rc;
974 result.request_api = evt;
975 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
976 m_parent->signalAPIResult(&result);
977 }
978 break;
979 case QCAMERA_SM_EVT_GET_PARAMS:
980 {
981 result.params = m_parent->getParameters();
982 rc = NO_ERROR;
983 result.status = rc;
984 result.request_api = evt;
985 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
986 m_parent->signalAPIResult(&result);
987 }
988 break;
989 case QCAMERA_SM_EVT_PUT_PARAMS:
990 {
991 rc = m_parent->putParameters((char*)payload);
992 result.status = rc;
993 result.request_api = evt;
994 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
995 m_parent->signalAPIResult(&result);
996 }
997 break;
998 case QCAMERA_SM_EVT_START_PREVIEW:
999 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
1000 {
1001 // no ops here
1002 ALOGD("%s: Already in previewing, no ops here to start preview", __func__);
1003 rc = NO_ERROR;
1004 result.status = rc;
1005 result.request_api = evt;
1006 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1007 m_parent->signalAPIResult(&result);
1008 }
1009 break;
1010 case QCAMERA_SM_EVT_STOP_PREVIEW:
1011 {
1012 rc = m_parent->stopPreview();
1013 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
1014 result.status = rc;
1015 result.request_api = evt;
1016 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1017 m_parent->signalAPIResult(&result);
1018 }
1019 break;
1020 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
1021 {
1022 rc = NO_ERROR;
1023 result.status = rc;
1024 result.request_api = evt;
1025 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1026 result.enabled = 1;
1027 m_parent->signalAPIResult(&result);
1028 }
1029 break;
1030 case QCAMERA_SM_EVT_RECORDING_ENABLED:
1031 {
1032 rc = NO_ERROR;
1033 result.status = rc;
1034 result.request_api = evt;
1035 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1036 result.enabled = 0;
1037 m_parent->signalAPIResult(&result);
1038 }
1039 break;
1040 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
1041 {
1042 rc = m_parent->storeMetaDataInBuffers(int(payload));
1043 result.status = rc;
1044 result.request_api = evt;
1045 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1046 m_parent->signalAPIResult(&result);
1047 }
1048 break;
1049 case QCAMERA_SM_EVT_DUMP:
1050 {
1051 rc = m_parent->dump((int)payload);
1052 result.status = rc;
1053 result.request_api = evt;
1054 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1055 m_parent->signalAPIResult(&result);
1056 }
1057 break;
1058 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
1059 {
1060 rc = m_parent->autoFocus();
1061 result.status = rc;
1062 result.request_api = evt;
1063 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1064 m_parent->signalAPIResult(&result);
1065 }
1066 break;
1067 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
1068 {
1069 rc = m_parent->cancelAutoFocus();
1070 result.status = rc;
1071 result.request_api = evt;
1072 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1073 m_parent->signalAPIResult(&result);
1074 }
1075 break;
1076 case QCAMERA_SM_EVT_START_RECORDING:
1077 {
1078 rc = m_parent->startRecording();
1079 if (rc == NO_ERROR) {
1080 // move state to recording state
1081 m_state = QCAMERA_SM_STATE_RECORDING;
1082 }
1083 result.status = rc;
1084 result.request_api = evt;
1085 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1086 m_parent->signalAPIResult(&result);
1087 }
1088 break;
Shuzhen Wang93f24112013-02-20 16:01:42 -08001089 case QCAMERA_SM_EVT_PREPARE_SNAPSHOT:
Muhua Libc9a8082012-11-07 15:51:28 -08001090 {
Muhua Li0c14e432013-03-06 15:50:17 -08001091 rc = m_parent->prepareHardwareForSnapshot(FALSE);
Muhua Libc9a8082012-11-07 15:51:28 -08001092 if (rc == NO_ERROR) {
Shuzhen Wang93f24112013-02-20 16:01:42 -08001093 // Do not signal API result in this case.
1094 // Need to wait for snapshot done in metadta.
1095 m_state = QCAMERA_SM_STATE_PREPARE_SNAPSHOT;
1096 } else {
1097 // Do not change state in this case.
1098 ALOGE("%s: prepareHardwareForSnapshot failed %d",
1099 __func__, rc);
1100
1101 result.status = rc;
1102 result.request_api = evt;
1103 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1104 m_parent->signalAPIResult(&result);
1105 }
1106 }
1107 break;
1108 case QCAMERA_SM_EVT_TAKE_PICTURE:
1109 {
Muhua Li8e614bc2013-04-17 17:38:42 -07001110 if ( m_parent->mParameters.getRecordingHintValue() == false) {
Shuzhen Wang93f24112013-02-20 16:01:42 -08001111 if (m_parent->isZSLMode()) {
1112 m_state = QCAMERA_SM_STATE_PREVIEW_PIC_TAKING;
Muhua Lia9dca012013-05-03 22:37:42 -07001113 rc = m_parent->takePicture();
1114 if (rc != NO_ERROR) {
1115 // move state to previewing state
1116 m_state = QCAMERA_SM_STATE_PREVIEWING;
1117 }
Shuzhen Wang93f24112013-02-20 16:01:42 -08001118 } else {
1119 m_state = QCAMERA_SM_STATE_PIC_TAKING;
Muhua Lia9dca012013-05-03 22:37:42 -07001120 rc = m_parent->takePicture();
1121 if (rc != NO_ERROR) {
1122 // move state to preview stopped state
1123 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
1124 }
Shuzhen Wang93f24112013-02-20 16:01:42 -08001125 }
Muhua Lia9dca012013-05-03 22:37:42 -07001126
1127 result.status = rc;
1128 result.request_api = evt;
1129 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1130 m_parent->signalAPIResult(&result);
Muhua Li8e614bc2013-04-17 17:38:42 -07001131 } else {
Muhua Lia9dca012013-05-03 22:37:42 -07001132 m_state = QCAMERA_SM_STATE_PREVIEW_PIC_TAKING;
Muhua Li8e614bc2013-04-17 17:38:42 -07001133 rc = m_parent->takeLiveSnapshot();
Muhua Lia9dca012013-05-03 22:37:42 -07001134 if (rc != NO_ERROR ) {
1135 m_state = QCAMERA_SM_STATE_PREVIEWING;
Muhua Li8e614bc2013-04-17 17:38:42 -07001136 }
Muhua Lia9dca012013-05-03 22:37:42 -07001137 result.status = rc;
1138 result.request_api = evt;
1139 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1140 m_parent->signalAPIResult(&result);
Muhua Li8e614bc2013-04-17 17:38:42 -07001141 }
Muhua Libc9a8082012-11-07 15:51:28 -08001142 }
1143 break;
1144 case QCAMERA_SM_EVT_SEND_COMMAND:
1145 {
1146 qcamera_sm_evt_command_payload_t *cmd_payload =
1147 (qcamera_sm_evt_command_payload_t *)payload;
1148 rc = m_parent->sendCommand(cmd_payload->cmd,
1149 cmd_payload->arg1,
1150 cmd_payload->arg2);
1151 result.status = rc;
1152 result.request_api = evt;
1153 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1154 m_parent->signalAPIResult(&result);
1155 }
1156 break;
Muhua Li5858c392013-02-04 17:53:34 -08001157 case QCAMERA_SM_EVT_REG_FACE_IMAGE:
1158 {
1159 int32_t faceID = 0;
1160 qcamera_sm_evt_reg_face_payload_t *reg_payload =
1161 (qcamera_sm_evt_reg_face_payload_t *)payload;
1162 rc = m_parent->registerFaceImage(reg_payload->img_ptr,
1163 reg_payload->config,
1164 faceID);
1165 result.status = rc;
1166 result.request_api = evt;
1167 result.result_type = QCAMERA_API_RESULT_TYPE_HANDLE;
1168 result.handle = faceID;
1169 m_parent->signalAPIResult(&result);
1170 }
1171 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001172 case QCAMERA_SM_EVT_CANCEL_PICTURE:
1173 case QCAMERA_SM_EVT_STOP_RECORDING:
1174 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
1175 case QCAMERA_SM_EVT_RELEASE:
1176 {
1177 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1178 rc = INVALID_OPERATION;
1179 result.status = rc;
1180 result.request_api = evt;
1181 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1182 m_parent->signalAPIResult(&result);
1183 }
1184 break;
Muhua Li31eaee02012-12-11 08:56:45 -08001185 case QCAMERA_SM_EVT_EVT_INTERNAL:
1186 {
1187 qcamera_sm_internal_evt_payload_t *internal_evt =
1188 (qcamera_sm_internal_evt_payload_t *)payload;
1189 switch (internal_evt->evt_type) {
1190 case QCAMERA_INTERNAL_EVT_FOCUS_UPDATE:
1191 rc = m_parent->processAutoFocusEvent(internal_evt->focus_data);
1192 break;
Muhua Li510aab22013-05-28 17:00:38 -07001193 case QCAMERA_INTERNAL_EVT_PREP_SNAPSHOT_DONE:
1194 break;
1195 case QCAMERA_INTERNAL_EVT_FACE_DETECT_RESULT:
1196 rc = m_parent->processFaceDetectionResult(&internal_evt->faces_data);
1197 break;
1198 case QCAMERA_INTERNAL_EVT_HISTOGRAM_STATS:
1199 rc = m_parent->processHistogramStats(internal_evt->stats_data);
1200 break;
1201 case QCAMERA_INTERNAL_EVT_CROP_INFO:
1202 rc = m_parent->processZoomEvent(internal_evt->crop_data);
1203 break;
Muhua Li31eaee02012-12-11 08:56:45 -08001204 default:
Shuzhen Wang93f24112013-02-20 16:01:42 -08001205 ALOGE("%s: Invalid internal event %d in state(%d)",
1206 __func__, internal_evt->evt_type, m_state);
Muhua Li31eaee02012-12-11 08:56:45 -08001207 break;
1208 }
1209 }
1210 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001211 case QCAMERA_SM_EVT_EVT_NOTIFY:
1212 {
1213 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
1214 switch (cam_evt->server_event_type) {
Emilian Peev15690592013-04-19 09:55:40 +03001215 case CAM_EVENT_TYPE_DAEMON_DIED:
1216 {
Emilian Peev15690592013-04-19 09:55:40 +03001217 m_parent->sendEvtNotify(CAMERA_MSG_ERROR,
1218 CAMERA_ERROR_SERVER_DIED,
1219 0);
1220 }
1221 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001222 default:
1223 ALOGD("%s: no handling for server evt (%d) at this state",
1224 __func__, cam_evt->server_event_type);
1225 break;
1226 }
1227 }
1228 break;
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08001229 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
Emilian Peeve1d5acb2013-02-01 11:29:53 -08001230 {
Shuzhen Wangd415beb2013-02-08 10:28:16 -08001231 rc = m_parent->updateThermalLevel(
1232 *(qcamera_thermal_level_enum_t *)&payload);
Emilian Peeve1d5acb2013-02-01 11:29:53 -08001233 }
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08001234 break;
Muhua Lida2c4be2012-11-26 09:14:16 -08001235 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
Muhua Lic9390df2013-05-22 17:54:13 -07001236 {
1237 // No ops, but need to notify
1238 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1239 result.status = rc;
1240 result.request_api = evt;
1241 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1242 m_parent->signalEvtResult(&result);
1243 }
1244 break;
1245 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
Muhua Libc9a8082012-11-07 15:51:28 -08001246 default:
1247 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1248 break;
1249 }
1250
1251 return rc;
1252}
1253
Muhua Lida2c4be2012-11-26 09:14:16 -08001254/*===========================================================================
Shuzhen Wang93f24112013-02-20 16:01:42 -08001255 * FUNCTION : procEvtPrepareSnapshotState
1256 *
1257 * DESCRIPTION: finite state machine function to handle event in state of
1258 * QCAMERA_SM_STATE_PREPARE_SNAPSHOT.
1259 *
1260 * PARAMETERS :
1261 * @evt : event to be processed
1262 * @payload : event payload. Can be NULL if not needed.
1263 *
1264 * RETURN : int32_t type of status
1265 * NO_ERROR -- success
1266 * none-zero failure code
1267 *==========================================================================*/
1268int32_t QCameraStateMachine::procEvtPrepareSnapshotState(qcamera_sm_evt_enum_t evt,
1269 void *payload)
1270{
1271 int32_t rc = NO_ERROR;
1272 qcamera_api_result_t result;
1273 memset(&result, 0, sizeof(qcamera_api_result_t));
1274
1275 switch (evt) {
1276 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
1277 case QCAMERA_SM_EVT_SET_CALLBACKS:
1278 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
1279 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
1280 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
1281 case QCAMERA_SM_EVT_SET_PARAMS:
1282 case QCAMERA_SM_EVT_GET_PARAMS:
1283 case QCAMERA_SM_EVT_PUT_PARAMS:
1284 case QCAMERA_SM_EVT_START_PREVIEW:
1285 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
1286 case QCAMERA_SM_EVT_STOP_PREVIEW:
1287 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
1288 case QCAMERA_SM_EVT_RECORDING_ENABLED:
1289 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
1290 case QCAMERA_SM_EVT_DUMP:
1291 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
1292 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
1293 case QCAMERA_SM_EVT_START_RECORDING:
1294 case QCAMERA_SM_EVT_TAKE_PICTURE:
Muhua Li510aab22013-05-28 17:00:38 -07001295 case QCAMERA_SM_EVT_PREPARE_SNAPSHOT:
Shuzhen Wang93f24112013-02-20 16:01:42 -08001296 case QCAMERA_SM_EVT_SEND_COMMAND:
1297 case QCAMERA_SM_EVT_CANCEL_PICTURE:
1298 case QCAMERA_SM_EVT_STOP_RECORDING:
1299 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
1300 case QCAMERA_SM_EVT_RELEASE:
1301 {
1302 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1303 rc = INVALID_OPERATION;
1304 result.status = rc;
1305 result.request_api = evt;
1306 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1307 m_parent->signalAPIResult(&result);
1308 }
1309 break;
1310 case QCAMERA_SM_EVT_EVT_INTERNAL:
1311 {
1312 qcamera_sm_internal_evt_payload_t *internal_evt =
1313 (qcamera_sm_internal_evt_payload_t *)payload;
1314 switch (internal_evt->evt_type) {
Muhua Li6f3c5322013-05-08 17:20:17 -07001315 case QCAMERA_INTERNAL_EVT_FOCUS_UPDATE:
1316 rc = m_parent->processAutoFocusEvent(internal_evt->focus_data);
1317 break;
Shuzhen Wang93f24112013-02-20 16:01:42 -08001318 case QCAMERA_INTERNAL_EVT_PREP_SNAPSHOT_DONE:
1319 ALOGI("%s: Received QCAMERA_INTERNAL_EVT_PREP_SNAPSHOT_DONE event",
1320 __func__);
1321 m_parent->processPrepSnapshotDoneEvent(internal_evt->prep_snapshot_state);
1322 m_state = QCAMERA_SM_STATE_PREVIEWING;
1323
1324 result.status = NO_ERROR;
1325 result.request_api = QCAMERA_SM_EVT_PREPARE_SNAPSHOT;
1326 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1327 m_parent->signalAPIResult(&result);
1328 break;
Muhua Li510aab22013-05-28 17:00:38 -07001329 case QCAMERA_INTERNAL_EVT_FACE_DETECT_RESULT:
1330 rc = m_parent->processFaceDetectionResult(&internal_evt->faces_data);
1331 break;
1332 case QCAMERA_INTERNAL_EVT_HISTOGRAM_STATS:
1333 rc = m_parent->processHistogramStats(internal_evt->stats_data);
1334 break;
1335 case QCAMERA_INTERNAL_EVT_CROP_INFO:
1336 rc = m_parent->processZoomEvent(internal_evt->crop_data);
1337 break;
Shuzhen Wang93f24112013-02-20 16:01:42 -08001338 default:
1339 ALOGE("%s: Invalid internal event %d in state(%d)",
1340 __func__, internal_evt->evt_type, m_state);
1341 break;
1342 }
1343 }
1344 break;
1345 case QCAMERA_SM_EVT_EVT_NOTIFY:
Emilian Peev15690592013-04-19 09:55:40 +03001346 {
1347 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
1348 switch (cam_evt->server_event_type) {
1349 case CAM_EVENT_TYPE_DAEMON_DIED:
1350 {
Emilian Peev15690592013-04-19 09:55:40 +03001351 m_parent->sendEvtNotify(CAMERA_MSG_ERROR,
1352 CAMERA_ERROR_SERVER_DIED,
1353 0);
1354 }
1355 break;
1356 default:
1357 ALOGE("%s: Invalid internal event %d in state(%d)",
1358 __func__, cam_evt->server_event_type, m_state);
1359 break;
1360 }
1361 }
1362 break;
Muhua Lic9390df2013-05-22 17:54:13 -07001363 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
1364 {
1365 // No ops, but need to notify
1366 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1367 result.status = rc;
1368 result.request_api = evt;
1369 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1370 m_parent->signalEvtResult(&result);
1371 }
1372 break;
Shuzhen Wang93f24112013-02-20 16:01:42 -08001373 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
1374 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
Shuzhen Wang93f24112013-02-20 16:01:42 -08001375 default:
1376 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1377 break;
1378 }
1379
1380 return rc;
1381}
1382
1383/*===========================================================================
Muhua Lida2c4be2012-11-26 09:14:16 -08001384 * FUNCTION : procEvtPicTakingState
1385 *
1386 * DESCRIPTION: finite state machine function to handle event in state of
1387 * QCAMERA_SM_STATE_PIC_TAKING.
1388 *
1389 * PARAMETERS :
1390 * @evt : event to be processed
1391 * @payload : event payload. Can be NULL if not needed.
1392 *
1393 * RETURN : int32_t type of status
1394 * NO_ERROR -- success
1395 * none-zero failure code
1396 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -08001397int32_t QCameraStateMachine::procEvtPicTakingState(qcamera_sm_evt_enum_t evt,
1398 void *payload)
1399{
1400 int32_t rc = NO_ERROR;
1401 qcamera_api_result_t result;
1402 memset(&result, 0, sizeof(qcamera_api_result_t));
1403
1404 switch (evt) {
1405 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
1406 {
1407 // Error setting preview window during previewing
1408 ALOGE("Cannot set preview window when preview is running");
1409 rc = INVALID_OPERATION;
1410 result.status = rc;
1411 result.request_api = evt;
1412 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1413 m_parent->signalAPIResult(&result);
1414 }
1415 break;
1416 case QCAMERA_SM_EVT_SET_CALLBACKS:
1417 {
1418 qcamera_sm_evt_setcb_payload_t *setcbs =
1419 (qcamera_sm_evt_setcb_payload_t *)payload;
1420 rc = m_parent->setCallBacks(setcbs->notify_cb,
1421 setcbs->data_cb,
1422 setcbs->data_cb_timestamp,
1423 setcbs->get_memory,
1424 setcbs->user);
1425 result.status = rc;
1426 result.request_api = evt;
1427 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1428 m_parent->signalAPIResult(&result);
1429 }
1430 break;
1431 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
1432 {
1433 rc = m_parent->enableMsgType(int32_t(payload));
1434 result.status = rc;
1435 result.request_api = evt;
1436 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1437 m_parent->signalAPIResult(&result);
1438 }
1439 break;
1440 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
1441 {
1442 rc = m_parent->disableMsgType(int32_t(payload));
1443 result.status = rc;
1444 result.request_api = evt;
1445 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1446 m_parent->signalAPIResult(&result);
1447 }
1448 break;
1449 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
1450 {
1451 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
1452 result.status = rc;
1453 result.request_api = evt;
1454 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1455 result.enabled = enabled;
1456 m_parent->signalAPIResult(&result);
1457 }
1458 break;
1459 case QCAMERA_SM_EVT_SET_PARAMS:
1460 {
Muhua Lida2c4be2012-11-26 09:14:16 -08001461 bool needRestart = false;
1462 rc = m_parent->updateParameters((char*)payload, needRestart);
1463 if (rc == NO_ERROR) {
1464 rc = m_parent->commitParameterChanges();
1465 }
Muhua Libc9a8082012-11-07 15:51:28 -08001466 result.status = rc;
1467 result.request_api = evt;
1468 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1469 m_parent->signalAPIResult(&result);
1470 }
1471 break;
1472 case QCAMERA_SM_EVT_GET_PARAMS:
1473 {
1474 result.params = m_parent->getParameters();
1475 rc = NO_ERROR;
1476 result.status = rc;
1477 result.request_api = evt;
1478 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
1479 m_parent->signalAPIResult(&result);
1480 }
1481 break;
1482 case QCAMERA_SM_EVT_PUT_PARAMS:
1483 {
1484 rc = m_parent->putParameters((char*)payload);
1485 result.status = rc;
1486 result.request_api = evt;
1487 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1488 m_parent->signalAPIResult(&result);
1489 }
1490 break;
1491 case QCAMERA_SM_EVT_STOP_PREVIEW:
1492 {
Muhua Libd1b6122013-03-05 15:25:27 -08001493 // cancel picture first
1494 rc = m_parent->cancelPicture();
1495 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
1496
Muhua Libc9a8082012-11-07 15:51:28 -08001497 result.status = rc;
1498 result.request_api = evt;
1499 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1500 m_parent->signalAPIResult(&result);
1501 }
1502 break;
1503 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
1504 {
1505 rc = NO_ERROR;
1506 result.status = rc;
1507 result.request_api = evt;
1508 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1509 result.enabled = 0;
1510 m_parent->signalAPIResult(&result);
1511 }
1512 break;
1513 case QCAMERA_SM_EVT_RECORDING_ENABLED:
1514 {
1515 rc = NO_ERROR;
1516 result.status = rc;
1517 result.request_api = evt;
1518 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1519 result.enabled = 0;
1520 m_parent->signalAPIResult(&result);
1521 }
1522 break;
1523 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
1524 {
1525 rc = m_parent->storeMetaDataInBuffers(int(payload));
1526 result.status = rc;
1527 result.request_api = evt;
1528 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1529 m_parent->signalAPIResult(&result);
1530 }
1531 break;
1532 case QCAMERA_SM_EVT_DUMP:
1533 {
1534 rc = m_parent->dump((int)payload);
1535 result.status = rc;
1536 result.request_api = evt;
1537 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1538 m_parent->signalAPIResult(&result);
1539 }
1540 break;
1541 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
1542 {
1543 rc = m_parent->autoFocus();
1544 result.status = rc;
1545 result.request_api = evt;
1546 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1547 m_parent->signalAPIResult(&result);
1548 }
1549 break;
1550 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
1551 {
1552 rc = m_parent->cancelAutoFocus();
1553 result.status = rc;
1554 result.request_api = evt;
1555 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1556 m_parent->signalAPIResult(&result);
1557 }
1558 break;
1559 case QCAMERA_SM_EVT_SEND_COMMAND:
1560 {
1561 qcamera_sm_evt_command_payload_t *cmd_payload =
1562 (qcamera_sm_evt_command_payload_t *)payload;
1563 rc = m_parent->sendCommand(cmd_payload->cmd,
1564 cmd_payload->arg1,
1565 cmd_payload->arg2);
1566 result.status = rc;
1567 result.request_api = evt;
1568 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1569 m_parent->signalAPIResult(&result);
1570 }
1571 break;
1572 case QCAMERA_SM_EVT_CANCEL_PICTURE:
1573 {
1574 rc = m_parent->cancelPicture();
1575 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
1576 result.status = rc;
1577 result.request_api = evt;
1578 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1579 m_parent->signalAPIResult(&result);
1580 }
1581 break;
Muhua Li5858c392013-02-04 17:53:34 -08001582 case QCAMERA_SM_EVT_REG_FACE_IMAGE:
1583 {
1584 int32_t faceID = 0;
1585 qcamera_sm_evt_reg_face_payload_t *reg_payload =
1586 (qcamera_sm_evt_reg_face_payload_t *)payload;
1587 rc = m_parent->registerFaceImage(reg_payload->img_ptr,
1588 reg_payload->config,
1589 faceID);
1590 result.status = rc;
1591 result.request_api = evt;
1592 result.result_type = QCAMERA_API_RESULT_TYPE_HANDLE;
1593 result.handle = faceID;
1594 m_parent->signalAPIResult(&result);
1595 }
1596 break;
Muhua Li510aab22013-05-28 17:00:38 -07001597 case QCAMERA_SM_EVT_PREPARE_SNAPSHOT:
Muhua Libc9a8082012-11-07 15:51:28 -08001598 case QCAMERA_SM_EVT_TAKE_PICTURE:
1599 case QCAMERA_SM_EVT_START_RECORDING:
1600 case QCAMERA_SM_EVT_STOP_RECORDING:
1601 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
1602 case QCAMERA_SM_EVT_START_PREVIEW:
1603 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
1604 case QCAMERA_SM_EVT_RELEASE:
1605 {
1606 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1607 rc = INVALID_OPERATION;
1608 result.status = rc;
1609 result.request_api = evt;
1610 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1611 m_parent->signalAPIResult(&result);
1612 }
1613 break;
Muhua Li31eaee02012-12-11 08:56:45 -08001614 case QCAMERA_SM_EVT_EVT_INTERNAL:
1615 {
1616 qcamera_sm_internal_evt_payload_t *internal_evt =
1617 (qcamera_sm_internal_evt_payload_t *)payload;
1618 switch (internal_evt->evt_type) {
1619 case QCAMERA_INTERNAL_EVT_FOCUS_UPDATE:
1620 rc = m_parent->processAutoFocusEvent(internal_evt->focus_data);
1621 break;
Muhua Li510aab22013-05-28 17:00:38 -07001622 case QCAMERA_INTERNAL_EVT_PREP_SNAPSHOT_DONE:
1623 break;
1624 case QCAMERA_INTERNAL_EVT_FACE_DETECT_RESULT:
1625 break;
1626 case QCAMERA_INTERNAL_EVT_HISTOGRAM_STATS:
1627 break;
1628 case QCAMERA_INTERNAL_EVT_CROP_INFO:
1629 rc = m_parent->processZoomEvent(internal_evt->crop_data);
1630 break;
Muhua Li31eaee02012-12-11 08:56:45 -08001631 default:
1632 break;
1633 }
1634 }
1635 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001636 case QCAMERA_SM_EVT_EVT_NOTIFY:
1637 {
1638 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
1639 switch (cam_evt->server_event_type) {
Emilian Peev15690592013-04-19 09:55:40 +03001640 case CAM_EVENT_TYPE_DAEMON_DIED:
1641 {
Emilian Peev15690592013-04-19 09:55:40 +03001642 m_parent->sendEvtNotify(CAMERA_MSG_ERROR,
1643 CAMERA_ERROR_SERVER_DIED,
1644 0);
1645 }
1646 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001647 default:
1648 ALOGD("%s: no handling for server evt (%d) at this state",
1649 __func__, cam_evt->server_event_type);
1650 break;
1651 }
1652 }
1653 break;
1654 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
1655 {
1656 qcamera_jpeg_evt_payload_t *jpeg_job =
1657 (qcamera_jpeg_evt_payload_t *)payload;
1658 rc = m_parent->processJpegNotify(jpeg_job);
1659 }
1660 break;
1661 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
1662 {
1663 rc = m_parent->cancelPicture();
1664 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
Emilian Peev6d90c1f2013-04-12 09:33:06 +03001665 result.status = rc;
1666 result.request_api = evt;
1667 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1668 m_parent->signalEvtResult(&result);
Muhua Libc9a8082012-11-07 15:51:28 -08001669 }
1670 break;
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08001671 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
Emilian Peev2ae455e2013-04-18 10:41:56 +03001672 {
1673 rc = m_parent->updateThermalLevel(
1674 *(qcamera_thermal_level_enum_t *)&payload);
1675 }
1676 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001677 default:
1678 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1679 break;
1680 }
1681
1682 return rc;
1683}
1684
Muhua Lida2c4be2012-11-26 09:14:16 -08001685/*===========================================================================
1686 * FUNCTION : procEvtRecordingState
1687 *
1688 * DESCRIPTION: finite state machine function to handle event in state of
1689 * QCAMERA_SM_STATE_RECORDING.
1690 *
1691 * PARAMETERS :
1692 * @evt : event to be processed
1693 * @payload : event payload. Can be NULL if not needed.
1694 *
1695 * RETURN : int32_t type of status
1696 * NO_ERROR -- success
1697 * none-zero failure code
1698 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -08001699int32_t QCameraStateMachine::procEvtRecordingState(qcamera_sm_evt_enum_t evt,
1700 void *payload)
1701{
1702 int32_t rc = NO_ERROR;
1703 qcamera_api_result_t result;
1704 memset(&result, 0, sizeof(qcamera_api_result_t));
1705
1706 switch (evt) {
Emilian Peev88293e92013-06-07 12:37:18 +03001707 case QCAMERA_SM_EVT_START_PREVIEW:
Muhua Libc9a8082012-11-07 15:51:28 -08001708 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
1709 {
Emilian Peev88293e92013-06-07 12:37:18 +03001710 // WA: CTS test VideoSnapshot will try to
1711 // start preview during video recording.
1712 ALOGE("CTS video restart op");
1713 rc = NO_ERROR;
Muhua Libc9a8082012-11-07 15:51:28 -08001714 result.status = rc;
1715 result.request_api = evt;
1716 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1717 m_parent->signalAPIResult(&result);
1718 }
1719 break;
1720 case QCAMERA_SM_EVT_SET_CALLBACKS:
1721 {
1722 qcamera_sm_evt_setcb_payload_t *setcbs =
1723 (qcamera_sm_evt_setcb_payload_t *)payload;
1724 rc = m_parent->setCallBacks(setcbs->notify_cb,
1725 setcbs->data_cb,
1726 setcbs->data_cb_timestamp,
1727 setcbs->get_memory,
1728 setcbs->user);
1729 result.status = rc;
1730 result.request_api = evt;
1731 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1732 m_parent->signalAPIResult(&result);
1733 }
1734 break;
1735 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
1736 {
1737 rc = m_parent->enableMsgType(int32_t(payload));
1738 result.status = rc;
1739 result.request_api = evt;
1740 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1741 m_parent->signalAPIResult(&result);
1742 }
1743 break;
1744 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
1745 {
1746 rc = m_parent->disableMsgType(int32_t(payload));
1747 result.status = rc;
1748 result.request_api = evt;
1749 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1750 m_parent->signalAPIResult(&result);
1751 }
1752 break;
1753 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
1754 {
1755 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
1756 result.status = rc;
1757 result.request_api = evt;
1758 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1759 result.enabled = enabled;
1760 m_parent->signalAPIResult(&result);
1761 }
1762 break;
1763 case QCAMERA_SM_EVT_SET_PARAMS:
1764 {
Muhua Lida2c4be2012-11-26 09:14:16 -08001765 bool needRestart = false;
1766 rc = m_parent->updateParameters((char*)payload, needRestart);
1767 if (rc == NO_ERROR) {
1768 if (needRestart) {
1769 // cannot set parameters that requires restart during recording
1770 ALOGE("%s: Cannot set parameters that requires restart during recording",
1771 __func__);
1772 rc = BAD_VALUE;
1773 } else {
1774 rc = m_parent->commitParameterChanges();
1775 }
1776 }
Muhua Libc9a8082012-11-07 15:51:28 -08001777 result.status = rc;
1778 result.request_api = evt;
1779 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1780 m_parent->signalAPIResult(&result);
1781 }
1782 break;
1783 case QCAMERA_SM_EVT_GET_PARAMS:
1784 {
1785 result.params = m_parent->getParameters();
1786 rc = NO_ERROR;
1787 result.status = rc;
1788 result.request_api = evt;
1789 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
1790 m_parent->signalAPIResult(&result);
1791 }
1792 break;
1793 case QCAMERA_SM_EVT_PUT_PARAMS:
1794 {
1795 rc = m_parent->putParameters((char*)payload);
1796 result.status = rc;
1797 result.request_api = evt;
1798 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1799 m_parent->signalAPIResult(&result);
1800 }
1801 break;
1802 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
1803 {
1804 rc = NO_ERROR;
1805 result.status = rc;
1806 result.request_api = evt;
1807 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1808 result.enabled = 0;
1809 m_parent->signalAPIResult(&result);
1810 }
1811 break;
1812 case QCAMERA_SM_EVT_RECORDING_ENABLED:
1813 {
1814 rc = NO_ERROR;
1815 result.status = rc;
1816 result.request_api = evt;
1817 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1818 result.enabled = 1;
1819 m_parent->signalAPIResult(&result);
1820 }
1821 break;
1822 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
1823 {
1824 rc = m_parent->storeMetaDataInBuffers(int(payload));
1825 result.status = rc;
1826 result.request_api = evt;
1827 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1828 m_parent->signalAPIResult(&result);
1829 }
1830 break;
1831 case QCAMERA_SM_EVT_DUMP:
1832 {
1833 rc = m_parent->dump((int)payload);
1834 result.status = rc;
1835 result.request_api = evt;
1836 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1837 m_parent->signalAPIResult(&result);
1838 }
1839 break;
1840 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
1841 {
1842 rc = m_parent->autoFocus();
1843 result.status = rc;
1844 result.request_api = evt;
1845 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1846 m_parent->signalAPIResult(&result);
1847 }
1848 break;
1849 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
1850 {
1851 rc = m_parent->cancelAutoFocus();
1852 result.status = rc;
1853 result.request_api = evt;
1854 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1855 m_parent->signalAPIResult(&result);
1856 }
1857 break;
1858 case QCAMERA_SM_EVT_SEND_COMMAND:
1859 {
1860 qcamera_sm_evt_command_payload_t *cmd_payload =
1861 (qcamera_sm_evt_command_payload_t *)payload;
1862 rc = m_parent->sendCommand(cmd_payload->cmd,
1863 cmd_payload->arg1,
1864 cmd_payload->arg2);
1865 result.status = rc;
1866 result.request_api = evt;
1867 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1868 m_parent->signalAPIResult(&result);
1869 }
1870 break;
1871 case QCAMERA_SM_EVT_TAKE_PICTURE:
1872 {
Muhua Li1d0c4772013-02-22 15:39:45 -08001873 m_state = QCAMERA_SM_STATE_VIDEO_PIC_TAKING;
Muhua Libc9a8082012-11-07 15:51:28 -08001874 rc = m_parent->takeLiveSnapshot();
Muhua Li1d0c4772013-02-22 15:39:45 -08001875 if (rc != NO_ERROR) {
1876 m_state = QCAMERA_SM_STATE_RECORDING;
Muhua Libc9a8082012-11-07 15:51:28 -08001877 }
1878 result.status = rc;
1879 result.request_api = evt;
1880 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1881 m_parent->signalAPIResult(&result);
1882 }
1883 break;
1884 case QCAMERA_SM_EVT_START_RECORDING:
1885 {
1886 // no ops here
1887 ALOGD("%s: already in recording state, no ops for start_recording", __func__);
1888 rc = 0;
1889 result.status = rc;
1890 result.request_api = evt;
1891 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1892 m_parent->signalAPIResult(&result);
1893 }
1894 break;
1895 case QCAMERA_SM_EVT_STOP_RECORDING:
1896 {
1897 rc = m_parent->stopRecording();
1898 m_state = QCAMERA_SM_STATE_PREVIEWING;
1899 result.status = rc;
1900 result.request_api = evt;
1901 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1902 m_parent->signalAPIResult(&result);
1903 }
1904 break;
Emilian Peevf392f172013-05-13 16:29:53 -07001905 case QCAMERA_SM_EVT_STOP_PREVIEW:
1906 {
1907 rc = m_parent->stopRecording();
1908 m_state = QCAMERA_SM_STATE_PREVIEWING;
1909
1910 rc = m_parent->stopPreview();
1911 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
1912
1913 result.status = rc;
1914 result.request_api = evt;
1915 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1916 m_parent->signalAPIResult(&result);
1917 }
1918 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001919 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
1920 {
1921 rc = m_parent->releaseRecordingFrame((const void *)payload);
1922 result.status = rc;
1923 result.request_api = evt;
1924 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1925 m_parent->signalAPIResult(&result);
1926 }
1927 break;
Muhua Li5858c392013-02-04 17:53:34 -08001928 case QCAMERA_SM_EVT_REG_FACE_IMAGE:
1929 {
1930 int32_t faceID = 0;
1931 qcamera_sm_evt_reg_face_payload_t *reg_payload =
1932 (qcamera_sm_evt_reg_face_payload_t *)payload;
1933 rc = m_parent->registerFaceImage(reg_payload->img_ptr,
1934 reg_payload->config,
1935 faceID);
1936 result.status = rc;
1937 result.request_api = evt;
1938 result.result_type = QCAMERA_API_RESULT_TYPE_HANDLE;
1939 result.handle = faceID;
1940 m_parent->signalAPIResult(&result);
1941 }
1942 break;
Shuzhen Wang93f24112013-02-20 16:01:42 -08001943 case QCAMERA_SM_EVT_PREPARE_SNAPSHOT:
1944 {
1945 //In Video snapshot, prepare hardware is a no-op.
1946 result.status = NO_ERROR;
1947 result.request_api = evt;
1948 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1949 m_parent->signalAPIResult(&result);
1950 }
1951 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001952 case QCAMERA_SM_EVT_CANCEL_PICTURE:
Muhua Libc9a8082012-11-07 15:51:28 -08001953 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
Muhua Libc9a8082012-11-07 15:51:28 -08001954 case QCAMERA_SM_EVT_RELEASE:
1955 {
1956 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1957 rc = INVALID_OPERATION;
1958 result.status = rc;
1959 result.request_api = evt;
1960 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1961 m_parent->signalAPIResult(&result);
1962 }
1963 break;
Muhua Li31eaee02012-12-11 08:56:45 -08001964 case QCAMERA_SM_EVT_EVT_INTERNAL:
1965 {
1966 qcamera_sm_internal_evt_payload_t *internal_evt =
1967 (qcamera_sm_internal_evt_payload_t *)payload;
1968 switch (internal_evt->evt_type) {
1969 case QCAMERA_INTERNAL_EVT_FOCUS_UPDATE:
1970 rc = m_parent->processAutoFocusEvent(internal_evt->focus_data);
1971 break;
Muhua Li510aab22013-05-28 17:00:38 -07001972 case QCAMERA_INTERNAL_EVT_PREP_SNAPSHOT_DONE:
1973 break;
1974 case QCAMERA_INTERNAL_EVT_FACE_DETECT_RESULT:
1975 rc = m_parent->processFaceDetectionResult(&internal_evt->faces_data);
1976 break;
1977 case QCAMERA_INTERNAL_EVT_HISTOGRAM_STATS:
1978 rc = m_parent->processHistogramStats(internal_evt->stats_data);
1979 break;
1980 case QCAMERA_INTERNAL_EVT_CROP_INFO:
1981 rc = m_parent->processZoomEvent(internal_evt->crop_data);
1982 break;
Muhua Li31eaee02012-12-11 08:56:45 -08001983 default:
1984 break;
1985 }
1986 }
1987 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001988 case QCAMERA_SM_EVT_EVT_NOTIFY:
1989 {
1990 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
1991 switch (cam_evt->server_event_type) {
Emilian Peev15690592013-04-19 09:55:40 +03001992 case CAM_EVENT_TYPE_DAEMON_DIED:
1993 {
Emilian Peev15690592013-04-19 09:55:40 +03001994 m_parent->sendEvtNotify(CAMERA_MSG_ERROR,
1995 CAMERA_ERROR_SERVER_DIED,
1996 0);
1997 }
1998 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001999 default:
Emilian Peev15690592013-04-19 09:55:40 +03002000 ALOGE("%s: Invalid internal event %d in state(%d)",
2001 __func__, cam_evt->server_event_type, m_state);
Muhua Libc9a8082012-11-07 15:51:28 -08002002 break;
2003 }
2004 }
2005 break;
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08002006 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
Emilian Peeve1d5acb2013-02-01 11:29:53 -08002007 {
Shuzhen Wangd415beb2013-02-08 10:28:16 -08002008 rc = m_parent->updateThermalLevel(
2009 *(qcamera_thermal_level_enum_t *)&payload);
Emilian Peeve1d5acb2013-02-01 11:29:53 -08002010 }
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08002011 break;
Muhua Lida2c4be2012-11-26 09:14:16 -08002012 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
Muhua Lic9390df2013-05-22 17:54:13 -07002013 {
2014 // No ops, but need to notify
2015 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
2016 result.status = rc;
2017 result.request_api = evt;
2018 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2019 m_parent->signalEvtResult(&result);
2020 }
2021 break;
2022 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
Muhua Libc9a8082012-11-07 15:51:28 -08002023 default:
2024 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
2025 break;
2026 }
2027
2028 return rc;
2029}
2030
Muhua Lida2c4be2012-11-26 09:14:16 -08002031/*===========================================================================
2032 * FUNCTION : procEvtVideoPicTakingState
2033 *
2034 * DESCRIPTION: finite state machine function to handle event in state of
2035 * QCAMERA_SM_STATE_VIDEO_PIC_TAKING.
2036 *
2037 * PARAMETERS :
2038 * @evt : event to be processed
2039 * @payload : event payload. Can be NULL if not needed.
2040 *
2041 * RETURN : int32_t type of status
2042 * NO_ERROR -- success
2043 * none-zero failure code
2044 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -08002045int32_t QCameraStateMachine::procEvtVideoPicTakingState(qcamera_sm_evt_enum_t evt,
2046 void *payload)
2047{
2048 int32_t rc = NO_ERROR;
2049 qcamera_api_result_t result;
2050 memset(&result, 0, sizeof(qcamera_api_result_t));
2051
2052 switch (evt) {
2053 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
2054 {
2055 // Error setting preview window during previewing
2056 ALOGE("Cannot set preview window when preview is running");
2057 rc = INVALID_OPERATION;
2058 result.status = rc;
2059 result.request_api = evt;
2060 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2061 m_parent->signalAPIResult(&result);
2062 }
2063 break;
2064 case QCAMERA_SM_EVT_SET_CALLBACKS:
2065 {
2066 qcamera_sm_evt_setcb_payload_t *setcbs =
2067 (qcamera_sm_evt_setcb_payload_t *)payload;
2068 rc = m_parent->setCallBacks(setcbs->notify_cb,
2069 setcbs->data_cb,
2070 setcbs->data_cb_timestamp,
2071 setcbs->get_memory,
2072 setcbs->user);
2073 result.status = rc;
2074 result.request_api = evt;
2075 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2076 m_parent->signalAPIResult(&result);
2077 }
2078 break;
2079 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
2080 {
2081 rc = m_parent->enableMsgType(int32_t(payload));
2082 result.status = rc;
2083 result.request_api = evt;
2084 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2085 m_parent->signalAPIResult(&result);
2086 }
2087 break;
2088 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
2089 {
2090 rc = m_parent->disableMsgType(int32_t(payload));
2091 result.status = rc;
2092 result.request_api = evt;
2093 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2094 m_parent->signalAPIResult(&result);
2095 }
2096 break;
2097 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
2098 {
2099 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
2100 result.status = rc;
2101 result.request_api = evt;
2102 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
2103 result.enabled = enabled;
2104 m_parent->signalAPIResult(&result);
2105 }
2106 break;
2107 case QCAMERA_SM_EVT_SET_PARAMS:
2108 {
Muhua Lida2c4be2012-11-26 09:14:16 -08002109 bool needRestart = false;
2110 rc = m_parent->updateParameters((char*)payload, needRestart);
2111 if (rc == NO_ERROR) {
2112 if (needRestart) {
2113 // cannot set parameters that requires restart during recording
2114 ALOGE("%s: Cannot set parameters that requires restart during recording",
2115 __func__);
2116 rc = BAD_VALUE;
2117 } else {
2118 rc = m_parent->commitParameterChanges();
2119 }
2120 }
Muhua Libc9a8082012-11-07 15:51:28 -08002121 result.status = rc;
2122 result.request_api = evt;
2123 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2124 m_parent->signalAPIResult(&result);
2125 }
2126 break;
2127 case QCAMERA_SM_EVT_GET_PARAMS:
2128 {
2129 result.params = m_parent->getParameters();
2130 rc = NO_ERROR;
2131 result.status = rc;
2132 result.request_api = evt;
2133 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
2134 m_parent->signalAPIResult(&result);
2135 }
2136 break;
2137 case QCAMERA_SM_EVT_PUT_PARAMS:
2138 {
2139 rc = m_parent->putParameters((char*)payload);
2140 result.status = rc;
2141 result.request_api = evt;
2142 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2143 m_parent->signalAPIResult(&result);
2144 }
2145 break;
2146 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
2147 {
2148 rc = NO_ERROR;
2149 result.status = rc;
2150 result.request_api = evt;
2151 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
2152 result.enabled = 1;
2153 m_parent->signalAPIResult(&result);
2154 }
2155 break;
2156 case QCAMERA_SM_EVT_RECORDING_ENABLED:
2157 {
2158 rc = NO_ERROR;
2159 result.status = rc;
2160 result.request_api = evt;
2161 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
2162 result.enabled = 1;
2163 m_parent->signalAPIResult(&result);
2164 }
2165 break;
2166 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
2167 {
2168 rc = m_parent->storeMetaDataInBuffers(int(payload));
2169 result.status = rc;
2170 result.request_api = evt;
2171 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2172 m_parent->signalAPIResult(&result);
2173 }
2174 break;
2175 case QCAMERA_SM_EVT_DUMP:
2176 {
2177 rc = m_parent->dump((int)payload);
2178 result.status = rc;
2179 result.request_api = evt;
2180 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2181 m_parent->signalAPIResult(&result);
2182 }
2183 break;
2184 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
2185 {
2186 rc = m_parent->autoFocus();
2187 result.status = rc;
2188 result.request_api = evt;
2189 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2190 m_parent->signalAPIResult(&result);
2191 }
2192 break;
2193 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
2194 {
2195 rc = m_parent->cancelAutoFocus();
2196 result.status = rc;
2197 result.request_api = evt;
2198 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2199 m_parent->signalAPIResult(&result);
2200 }
2201 break;
2202 case QCAMERA_SM_EVT_SEND_COMMAND:
2203 {
2204 qcamera_sm_evt_command_payload_t *cmd_payload =
2205 (qcamera_sm_evt_command_payload_t *)payload;
2206 rc = m_parent->sendCommand(cmd_payload->cmd,
2207 cmd_payload->arg1,
2208 cmd_payload->arg2);
2209 result.status = rc;
2210 result.request_api = evt;
2211 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2212 m_parent->signalAPIResult(&result);
2213 }
2214 break;
2215 case QCAMERA_SM_EVT_STOP_RECORDING:
2216 {
2217 rc = m_parent->stopRecording();
2218 m_state = QCAMERA_SM_STATE_PREVIEW_PIC_TAKING;
2219 result.status = rc;
2220 result.request_api = evt;
2221 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2222 m_parent->signalAPIResult(&result);
2223 }
2224 break;
2225 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
2226 {
2227 rc = m_parent->releaseRecordingFrame((const void *)payload);
2228 result.status = rc;
2229 result.request_api = evt;
2230 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2231 m_parent->signalAPIResult(&result);
2232 }
2233 break;
2234 case QCAMERA_SM_EVT_CANCEL_PICTURE:
2235 {
2236 rc = m_parent->cancelLiveSnapshot();
2237 m_state = QCAMERA_SM_STATE_RECORDING;
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;
Muhua Li5858c392013-02-04 17:53:34 -08002244 case QCAMERA_SM_EVT_REG_FACE_IMAGE:
2245 {
2246 int32_t faceID = 0;
2247 qcamera_sm_evt_reg_face_payload_t *reg_payload =
2248 (qcamera_sm_evt_reg_face_payload_t *)payload;
2249 rc = m_parent->registerFaceImage(reg_payload->img_ptr,
2250 reg_payload->config,
2251 faceID);
2252 result.status = rc;
2253 result.request_api = evt;
2254 result.result_type = QCAMERA_API_RESULT_TYPE_HANDLE;
2255 result.handle = faceID;
2256 m_parent->signalAPIResult(&result);
2257 }
2258 break;
Emilian Peevf392f172013-05-13 16:29:53 -07002259 case QCAMERA_SM_EVT_STOP_PREVIEW:
2260 {
2261 rc = m_parent->cancelLiveSnapshot();
2262 m_state = QCAMERA_SM_STATE_RECORDING;
2263
2264 rc = m_parent->stopRecording();
2265 m_state = QCAMERA_SM_STATE_PREVIEWING;
2266
2267 rc = m_parent->stopPreview();
2268 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
2269
2270 result.status = rc;
2271 result.request_api = evt;
2272 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2273 m_parent->signalAPIResult(&result);
2274 }
2275 break;
Muhua Libc9a8082012-11-07 15:51:28 -08002276 case QCAMERA_SM_EVT_START_RECORDING:
2277 case QCAMERA_SM_EVT_START_PREVIEW:
2278 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
Muhua Li510aab22013-05-28 17:00:38 -07002279 case QCAMERA_SM_EVT_PREPARE_SNAPSHOT:
Muhua Libc9a8082012-11-07 15:51:28 -08002280 case QCAMERA_SM_EVT_TAKE_PICTURE:
2281 case QCAMERA_SM_EVT_RELEASE:
2282 {
2283 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
2284 rc = INVALID_OPERATION;
2285 result.status = rc;
2286 result.request_api = evt;
2287 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2288 m_parent->signalAPIResult(&result);
2289 }
2290 break;
Muhua Li31eaee02012-12-11 08:56:45 -08002291 case QCAMERA_SM_EVT_EVT_INTERNAL:
2292 {
2293 qcamera_sm_internal_evt_payload_t *internal_evt =
2294 (qcamera_sm_internal_evt_payload_t *)payload;
2295 switch (internal_evt->evt_type) {
2296 case QCAMERA_INTERNAL_EVT_FOCUS_UPDATE:
2297 rc = m_parent->processAutoFocusEvent(internal_evt->focus_data);
2298 break;
Muhua Li510aab22013-05-28 17:00:38 -07002299 case QCAMERA_INTERNAL_EVT_PREP_SNAPSHOT_DONE:
2300 break;
2301 case QCAMERA_INTERNAL_EVT_FACE_DETECT_RESULT:
2302 rc = m_parent->processFaceDetectionResult(&internal_evt->faces_data);
2303 break;
2304 case QCAMERA_INTERNAL_EVT_HISTOGRAM_STATS:
2305 rc = m_parent->processHistogramStats(internal_evt->stats_data);
2306 break;
2307 case QCAMERA_INTERNAL_EVT_CROP_INFO:
2308 rc = m_parent->processZoomEvent(internal_evt->crop_data);
2309 break;
Muhua Li31eaee02012-12-11 08:56:45 -08002310 default:
2311 break;
2312 }
2313 }
2314 break;
Muhua Libc9a8082012-11-07 15:51:28 -08002315 case QCAMERA_SM_EVT_EVT_NOTIFY:
2316 {
2317 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
2318 switch (cam_evt->server_event_type) {
Emilian Peev15690592013-04-19 09:55:40 +03002319 case CAM_EVENT_TYPE_DAEMON_DIED:
2320 {
Emilian Peev15690592013-04-19 09:55:40 +03002321 m_parent->sendEvtNotify(CAMERA_MSG_ERROR,
2322 CAMERA_ERROR_SERVER_DIED,
2323 0);
2324 }
2325 break;
Muhua Libc9a8082012-11-07 15:51:28 -08002326 default:
Emilian Peev15690592013-04-19 09:55:40 +03002327 ALOGE("%s: Invalid internal event %d in state(%d)",
2328 __func__, cam_evt->server_event_type, m_state);
Muhua Libc9a8082012-11-07 15:51:28 -08002329 break;
2330 }
2331 }
2332 break;
2333 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
2334 {
2335 qcamera_jpeg_evt_payload_t *jpeg_job =
2336 (qcamera_jpeg_evt_payload_t *)payload;
2337 rc = m_parent->processJpegNotify(jpeg_job);
2338 }
2339 break;
2340 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
2341 {
2342 rc = m_parent->cancelLiveSnapshot();
2343 m_state = QCAMERA_SM_STATE_RECORDING;
Emilian Peev6d90c1f2013-04-12 09:33:06 +03002344 result.status = rc;
2345 result.request_api = evt;
2346 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2347 m_parent->signalEvtResult(&result);
Muhua Libc9a8082012-11-07 15:51:28 -08002348 }
2349 break;
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08002350 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
Emilian Peeve1d5acb2013-02-01 11:29:53 -08002351 {
Shuzhen Wangd415beb2013-02-08 10:28:16 -08002352 rc = m_parent->updateThermalLevel(
2353 *(qcamera_thermal_level_enum_t *)&payload);
Emilian Peeve1d5acb2013-02-01 11:29:53 -08002354 }
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08002355 break;
Muhua Libc9a8082012-11-07 15:51:28 -08002356 default:
2357 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
2358 break;
2359 }
2360
2361 return rc;
2362}
2363
Muhua Lida2c4be2012-11-26 09:14:16 -08002364/*===========================================================================
2365 * FUNCTION : procEvtPreviewPicTakingState
2366 *
2367 * DESCRIPTION: finite state machine function to handle event in state of
2368 * QCAMERA_SM_STATE_PREVIEW_PIC_TAKING.
2369 *
2370 * PARAMETERS :
2371 * @evt : event to be processed
2372 * @payload : event payload. Can be NULL if not needed.
2373 *
2374 * RETURN : int32_t type of status
2375 * NO_ERROR -- success
2376 * none-zero failure code
2377 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -08002378int32_t QCameraStateMachine::procEvtPreviewPicTakingState(qcamera_sm_evt_enum_t evt,
2379 void *payload)
2380{
2381 int32_t rc = NO_ERROR;
2382 qcamera_api_result_t result;
2383 memset(&result, 0, sizeof(qcamera_api_result_t));
2384
2385 switch (evt) {
2386 case QCAMERA_SM_EVT_SET_CALLBACKS:
2387 {
2388 qcamera_sm_evt_setcb_payload_t *setcbs =
2389 (qcamera_sm_evt_setcb_payload_t *)payload;
2390 rc = m_parent->setCallBacks(setcbs->notify_cb,
2391 setcbs->data_cb,
2392 setcbs->data_cb_timestamp,
2393 setcbs->get_memory,
2394 setcbs->user);
2395 result.status = rc;
2396 result.request_api = evt;
2397 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2398 m_parent->signalAPIResult(&result);
2399 }
2400 break;
2401 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
2402 {
2403 rc = m_parent->enableMsgType(int32_t(payload));
2404 result.status = rc;
2405 result.request_api = evt;
2406 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2407 m_parent->signalAPIResult(&result);
2408 }
2409 break;
2410 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
2411 {
2412 rc = m_parent->disableMsgType(int32_t(payload));
2413 result.status = rc;
2414 result.request_api = evt;
2415 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2416 m_parent->signalAPIResult(&result);
2417 }
2418 break;
2419 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
2420 {
2421 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
2422 result.status = rc;
2423 result.request_api = evt;
2424 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
2425 result.enabled = enabled;
2426 m_parent->signalAPIResult(&result);
2427 }
2428 break;
2429 case QCAMERA_SM_EVT_SET_PARAMS:
2430 {
Muhua Lida2c4be2012-11-26 09:14:16 -08002431 bool needRestart = false;
2432 rc = m_parent->updateParameters((char*)payload, needRestart);
2433 if (rc == NO_ERROR) {
2434 if (needRestart) {
2435 // need restart preview for parameters to take effect
2436 // stop preview
2437 m_parent->stopPreview();
2438 // commit parameter changes to server
Muhua Li66f3b532013-01-23 17:19:05 -08002439 m_parent->commitParameterChanges();
Muhua Lida2c4be2012-11-26 09:14:16 -08002440 // start preview again
Muhua Li66f3b532013-01-23 17:19:05 -08002441 rc = m_parent->preparePreview();
2442 if (rc == NO_ERROR) {
2443 rc = m_parent->startPreview();
2444 if (rc != NO_ERROR) {
2445 m_parent->unpreparePreview();
2446 }
2447 }
2448 if (rc != NO_ERROR) {
2449 m_state = QCAMERA_SM_STATE_PIC_TAKING;
2450 }
Muhua Lida2c4be2012-11-26 09:14:16 -08002451 } else {
2452 rc = m_parent->commitParameterChanges();
2453 }
2454 }
Muhua Libc9a8082012-11-07 15:51:28 -08002455 result.status = rc;
2456 result.request_api = evt;
2457 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2458 m_parent->signalAPIResult(&result);
2459 }
2460 break;
2461 case QCAMERA_SM_EVT_GET_PARAMS:
2462 {
2463 result.params = m_parent->getParameters();
2464 rc = NO_ERROR;
2465 result.status = rc;
2466 result.request_api = evt;
2467 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
2468 m_parent->signalAPIResult(&result);
2469 }
2470 break;
2471 case QCAMERA_SM_EVT_PUT_PARAMS:
2472 {
2473 rc = m_parent->putParameters((char*)payload);
2474 result.status = rc;
2475 result.request_api = evt;
2476 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2477 m_parent->signalAPIResult(&result);
2478 }
2479 break;
2480 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
2481 {
2482 rc = NO_ERROR;
2483 result.status = rc;
2484 result.request_api = evt;
2485 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
2486 result.enabled = 1;
2487 m_parent->signalAPIResult(&result);
2488 }
2489 break;
2490 case QCAMERA_SM_EVT_RECORDING_ENABLED:
2491 {
2492 rc = NO_ERROR;
2493 result.status = rc;
2494 result.request_api = evt;
2495 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
2496 result.enabled = 0;
2497 m_parent->signalAPIResult(&result);
2498 }
2499 break;
2500 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
2501 {
2502 rc = m_parent->storeMetaDataInBuffers(int(payload));
2503 result.status = rc;
2504 result.request_api = evt;
2505 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2506 m_parent->signalAPIResult(&result);
2507 }
2508 break;
2509 case QCAMERA_SM_EVT_DUMP:
2510 {
2511 rc = m_parent->dump((int)payload);
2512 result.status = rc;
2513 result.request_api = evt;
2514 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2515 m_parent->signalAPIResult(&result);
2516 }
2517 break;
2518 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
2519 {
2520 rc = m_parent->autoFocus();
2521 result.status = rc;
2522 result.request_api = evt;
2523 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2524 m_parent->signalAPIResult(&result);
2525 }
2526 break;
2527 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
2528 {
2529 rc = m_parent->cancelAutoFocus();
2530 result.status = rc;
2531 result.request_api = evt;
2532 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2533 m_parent->signalAPIResult(&result);
2534 }
2535 break;
2536 case QCAMERA_SM_EVT_SEND_COMMAND:
2537 {
2538 qcamera_sm_evt_command_payload_t *cmd_payload =
2539 (qcamera_sm_evt_command_payload_t *)payload;
2540 rc = m_parent->sendCommand(cmd_payload->cmd,
2541 cmd_payload->arg1,
2542 cmd_payload->arg2);
2543 result.status = rc;
2544 result.request_api = evt;
2545 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2546 m_parent->signalAPIResult(&result);
2547 }
2548 break;
2549 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
2550 {
2551 rc = m_parent->releaseRecordingFrame((const void *)payload);
2552 result.status = rc;
2553 result.request_api = evt;
2554 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2555 m_parent->signalAPIResult(&result);
2556 }
2557 break;
2558 case QCAMERA_SM_EVT_CANCEL_PICTURE:
2559 {
Shuzhen Wang93f24112013-02-20 16:01:42 -08002560 if (m_parent->isZSLMode()) {
2561 rc = m_parent->cancelPicture();
2562 } else {
2563 rc = m_parent->cancelLiveSnapshot();
2564 }
Muhua Libc9a8082012-11-07 15:51:28 -08002565 m_state = QCAMERA_SM_STATE_PREVIEWING;
2566 result.status = rc;
2567 result.request_api = evt;
2568 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2569 m_parent->signalAPIResult(&result);
2570 }
2571 break;
2572 case QCAMERA_SM_EVT_STOP_PREVIEW:
2573 {
Muhua Libd1b6122013-03-05 15:25:27 -08002574 if (m_parent->isZSLMode()) {
2575 // cancel picture first
2576 rc = m_parent->cancelPicture();
2577 m_parent->stopChannel(QCAMERA_CH_TYPE_ZSL);
2578 } else {
2579 rc = m_parent->cancelLiveSnapshot();
2580 m_parent->stopChannel(QCAMERA_CH_TYPE_PREVIEW);
2581 }
2582 // unprepare preview
2583 m_parent->unpreparePreview();
2584 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
Muhua Libc9a8082012-11-07 15:51:28 -08002585 result.status = rc;
2586 result.request_api = evt;
2587 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2588 m_parent->signalAPIResult(&result);
2589 }
2590 break;
2591 case QCAMERA_SM_EVT_START_RECORDING:
2592 {
Muhua Licf1cf672013-05-10 09:42:50 -07002593 if (m_parent->isZSLMode()) {
2594 ALOGE("%s: cannot handle evt(%d) in state(%d) in ZSL mode",
2595 __func__, evt, m_state);
2596 rc = INVALID_OPERATION;
2597 } else {
2598 rc = m_parent->startRecording();
2599 if (rc == NO_ERROR) {
2600 m_state = QCAMERA_SM_STATE_VIDEO_PIC_TAKING;
2601 }
Muhua Libc9a8082012-11-07 15:51:28 -08002602 }
2603 result.status = rc;
2604 result.request_api = evt;
2605 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2606 m_parent->signalAPIResult(&result);
2607 }
2608 break;
Muhua Li5858c392013-02-04 17:53:34 -08002609 case QCAMERA_SM_EVT_REG_FACE_IMAGE:
2610 {
2611 int32_t faceID = 0;
2612 qcamera_sm_evt_reg_face_payload_t *reg_payload =
2613 (qcamera_sm_evt_reg_face_payload_t *)payload;
2614 rc = m_parent->registerFaceImage(reg_payload->img_ptr,
2615 reg_payload->config,
2616 faceID);
2617 result.status = rc;
2618 result.request_api = evt;
2619 result.result_type = QCAMERA_API_RESULT_TYPE_HANDLE;
2620 result.handle = faceID;
2621 m_parent->signalAPIResult(&result);
2622 }
2623 break;
Muhua Libc9a8082012-11-07 15:51:28 -08002624 case QCAMERA_SM_EVT_STOP_RECORDING:
2625 case QCAMERA_SM_EVT_START_PREVIEW:
2626 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
Muhua Li510aab22013-05-28 17:00:38 -07002627 case QCAMERA_SM_EVT_PREPARE_SNAPSHOT:
Muhua Libc9a8082012-11-07 15:51:28 -08002628 case QCAMERA_SM_EVT_TAKE_PICTURE:
2629 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
2630 case QCAMERA_SM_EVT_RELEASE:
2631 {
2632 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
2633 rc = INVALID_OPERATION;
2634 result.status = rc;
2635 result.request_api = evt;
2636 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2637 m_parent->signalAPIResult(&result);
2638 }
2639 break;
Muhua Li31eaee02012-12-11 08:56:45 -08002640 case QCAMERA_SM_EVT_EVT_INTERNAL:
2641 {
2642 qcamera_sm_internal_evt_payload_t *internal_evt =
2643 (qcamera_sm_internal_evt_payload_t *)payload;
2644 switch (internal_evt->evt_type) {
2645 case QCAMERA_INTERNAL_EVT_FOCUS_UPDATE:
2646 rc = m_parent->processAutoFocusEvent(internal_evt->focus_data);
2647 break;
Muhua Li510aab22013-05-28 17:00:38 -07002648 case QCAMERA_INTERNAL_EVT_PREP_SNAPSHOT_DONE:
2649 break;
2650 case QCAMERA_INTERNAL_EVT_FACE_DETECT_RESULT:
2651 rc = m_parent->processFaceDetectionResult(&internal_evt->faces_data);
2652 break;
2653 case QCAMERA_INTERNAL_EVT_HISTOGRAM_STATS:
2654 rc = m_parent->processHistogramStats(internal_evt->stats_data);
2655 break;
2656 case QCAMERA_INTERNAL_EVT_CROP_INFO:
2657 rc = m_parent->processZoomEvent(internal_evt->crop_data);
2658 break;
Muhua Li31eaee02012-12-11 08:56:45 -08002659 default:
2660 break;
2661 }
2662 }
2663 break;
Muhua Libc9a8082012-11-07 15:51:28 -08002664 case QCAMERA_SM_EVT_EVT_NOTIFY:
2665 {
2666 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
2667 switch (cam_evt->server_event_type) {
Emilian Peev15690592013-04-19 09:55:40 +03002668 case CAM_EVENT_TYPE_DAEMON_DIED:
2669 {
Emilian Peev15690592013-04-19 09:55:40 +03002670 m_parent->sendEvtNotify(CAMERA_MSG_ERROR,
2671 CAMERA_ERROR_SERVER_DIED,
2672 0);
2673 }
2674 break;
Muhua Libc9a8082012-11-07 15:51:28 -08002675 default:
Emilian Peev15690592013-04-19 09:55:40 +03002676 ALOGE("%s: Invalid internal event %d in state(%d)",
2677 __func__, cam_evt->server_event_type, m_state);
Muhua Libc9a8082012-11-07 15:51:28 -08002678 break;
2679 }
2680 }
2681 break;
2682 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
2683 {
2684 qcamera_jpeg_evt_payload_t *jpeg_job =
2685 (qcamera_jpeg_evt_payload_t *)payload;
2686 rc = m_parent->processJpegNotify(jpeg_job);
2687 }
2688 break;
2689 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
2690 {
Shuzhen Wang93f24112013-02-20 16:01:42 -08002691 if (m_parent->isZSLMode()) {
2692 rc = m_parent->cancelPicture();
2693 } else {
2694 rc = m_parent->cancelLiveSnapshot();
2695 }
Muhua Libc9a8082012-11-07 15:51:28 -08002696 m_state = QCAMERA_SM_STATE_PREVIEWING;
Emilian Peev6d90c1f2013-04-12 09:33:06 +03002697 result.status = rc;
2698 result.request_api = evt;
2699 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2700 m_parent->signalEvtResult(&result);
Muhua Libc9a8082012-11-07 15:51:28 -08002701 }
2702 break;
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08002703 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
Emilian Peeve1d5acb2013-02-01 11:29:53 -08002704 {
Shuzhen Wangd415beb2013-02-08 10:28:16 -08002705 rc = m_parent->updateThermalLevel(
2706 *(qcamera_thermal_level_enum_t *)&payload);
Emilian Peeve1d5acb2013-02-01 11:29:53 -08002707 }
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08002708 break;
Muhua Libc9a8082012-11-07 15:51:28 -08002709 default:
2710 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
2711 break;
2712 }
2713
2714 return rc;
2715}
2716
Muhua Lida2c4be2012-11-26 09:14:16 -08002717/*===========================================================================
2718 * FUNCTION : isPreviewRunning
2719 *
2720 * DESCRIPTION: check if preview is in process.
2721 *
2722 * PARAMETERS : None
2723 *
2724 * RETURN : true -- preview running
2725 * false -- preview stopped
2726 *==========================================================================*/
2727bool QCameraStateMachine::isPreviewRunning()
2728{
2729 switch (m_state) {
2730 case QCAMERA_SM_STATE_PREVIEWING:
2731 case QCAMERA_SM_STATE_RECORDING:
2732 case QCAMERA_SM_STATE_VIDEO_PIC_TAKING:
2733 case QCAMERA_SM_STATE_PREVIEW_PIC_TAKING:
Muhua Libf818e52013-04-23 18:05:26 -07002734 case QCAMERA_SM_STATE_PREPARE_SNAPSHOT:
Muhua Lida2c4be2012-11-26 09:14:16 -08002735 return true;
2736 default:
2737 return false;
2738 }
2739}
2740
Shuzhen Wang89635cf2012-12-20 13:47:22 -08002741}; // namespace qcamera