blob: 1c8b1e3d7aaa9f232f40666491e1a3e2b89c0080 [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
32#include <utils/Log.h>
33#include <utils/Errors.h>
34#include "QCamera2HWI.h"
35#include "QCameraStateMachine.h"
36
Shuzhen Wang89635cf2012-12-20 13:47:22 -080037namespace qcamera {
Muhua Libc9a8082012-11-07 15:51:28 -080038
Muhua Lida2c4be2012-11-26 09:14:16 -080039/*===========================================================================
40 * FUNCTION : smEvtProcRoutine
41 *
42 * DESCRIPTION: Statemachine process thread routine to handle events
43 * in different state.
44 *
45 * PARAMETERS :
46 * @data : ptr to QCameraStateMachine object
47 *
48 * RETURN : none
49 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -080050void *QCameraStateMachine::smEvtProcRoutine(void *data)
51{
52 int running = 1, ret;
53 QCameraStateMachine *pme = (QCameraStateMachine *)data;
54
55 ALOGD("%s: E", __func__);
56 do {
57 do {
Shuzhen Wang2da44612012-12-20 10:51:57 -080058 ret = cam_sem_wait(&pme->cmd_sem);
Muhua Libc9a8082012-11-07 15:51:28 -080059 if (ret != 0 && errno != EINVAL) {
Shuzhen Wang2da44612012-12-20 10:51:57 -080060 ALOGE("%s: cam_sem_wait error (%s)",
Muhua Libc9a8082012-11-07 15:51:28 -080061 __func__, strerror(errno));
62 return NULL;
63 }
64 } while (ret != 0);
65
66 // we got notified about new cmd avail in cmd queue
67 // first check API cmd queue
68 qcamera_sm_cmd_t *node = (qcamera_sm_cmd_t *)pme->api_queue.dequeue();
69 if (node == NULL) {
70 // no API cmd, then check evt cmd queue
71 node = (qcamera_sm_cmd_t *)pme->evt_queue.dequeue();
72 }
73 if (node != NULL) {
74 switch (node->cmd) {
75 case QCAMERA_SM_CMD_TYPE_API:
Muhua Li31eaee02012-12-11 08:56:45 -080076 pme->stateMachine(node->evt, node->evt_payload);
77 // API is in a way sync call, so evt_payload is managed by HWI
78 // no need to free payload for API
79 break;
Muhua Libc9a8082012-11-07 15:51:28 -080080 case QCAMERA_SM_CMD_TYPE_EVT:
81 pme->stateMachine(node->evt, node->evt_payload);
Muhua Li31eaee02012-12-11 08:56:45 -080082
83 // EVT is async call, so payload need to be free after use
84 free(node->evt_payload);
85 node->evt_payload = NULL;
Muhua Libc9a8082012-11-07 15:51:28 -080086 break;
87 case QCAMERA_SM_CMD_TYPE_EXIT:
88 running = 0;
89 break;
90 default:
91 break;
92 }
Muhua Li31eaee02012-12-11 08:56:45 -080093 free(node);
94 node = NULL;
Muhua Libc9a8082012-11-07 15:51:28 -080095 }
96 } while (running);
97 ALOGD("%s: X", __func__);
98 return NULL;
99}
100
Muhua Lida2c4be2012-11-26 09:14:16 -0800101/*===========================================================================
102 * FUNCTION : QCameraStateMachine
103 *
104 * DESCRIPTION: constructor of QCameraStateMachine. Will start process thread
105 *
106 * PARAMETERS :
107 * @ctrl : ptr to HWI object
108 *
109 * RETURN : none
110 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800111QCameraStateMachine::QCameraStateMachine(QCamera2HardwareInterface *ctrl) :
112 api_queue(),
113 evt_queue()
114{
115 m_parent = ctrl;
116 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
117 cmd_pid = 0;
Shuzhen Wang2da44612012-12-20 10:51:57 -0800118 cam_sem_init(&cmd_sem, 0);
Muhua Libc9a8082012-11-07 15:51:28 -0800119 pthread_create(&cmd_pid,
120 NULL,
121 smEvtProcRoutine,
122 this);
123}
124
Muhua Lida2c4be2012-11-26 09:14:16 -0800125/*===========================================================================
126 * FUNCTION : ~QCameraStateMachine
127 *
128 * DESCRIPTION: desctructor of QCameraStateMachine. Will stop process thread.
129 *
130 * PARAMETERS : none
131 *
132 * RETURN : none
133 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800134QCameraStateMachine::~QCameraStateMachine()
135{
136 if (cmd_pid != 0) {
137 qcamera_sm_cmd_t *node =
138 (qcamera_sm_cmd_t *)malloc(sizeof(qcamera_sm_cmd_t));
139 if (NULL != node) {
140 memset(node, 0, sizeof(qcamera_sm_cmd_t));
141 node->cmd = QCAMERA_SM_CMD_TYPE_EXIT;
142
143 api_queue.enqueue((void *)node);
Shuzhen Wang2da44612012-12-20 10:51:57 -0800144 cam_sem_post(&cmd_sem);
Muhua Libc9a8082012-11-07 15:51:28 -0800145
146 /* wait until cmd thread exits */
147 if (pthread_join(cmd_pid, NULL) != 0) {
148 ALOGD("%s: pthread dead already\n", __func__);
149 }
150 }
151 cmd_pid = 0;
152 }
Shuzhen Wang2da44612012-12-20 10:51:57 -0800153 cam_sem_destroy(&cmd_sem);
Muhua Libc9a8082012-11-07 15:51:28 -0800154}
155
Muhua Lida2c4be2012-11-26 09:14:16 -0800156/*===========================================================================
157 * FUNCTION : procAPI
158 *
159 * DESCRIPTION: process incoming API request from framework layer.
160 *
161 * PARAMETERS :
162 * @evt : event to be processed
163 * @api_payload : API payload. Can be NULL if not needed.
164 *
165 * RETURN : int32_t type of status
166 * NO_ERROR -- success
167 * none-zero failure code
168 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800169int32_t QCameraStateMachine::procAPI(qcamera_sm_evt_enum_t evt,
170 void *api_payload)
171{
172 qcamera_sm_cmd_t *node =
173 (qcamera_sm_cmd_t *)malloc(sizeof(qcamera_sm_cmd_t));
Muhua Lida2c4be2012-11-26 09:14:16 -0800174 if (NULL == node) {
175 ALOGE("%s: No memory for qcamera_sm_cmd_t", __func__);
176 return NO_MEMORY;
Muhua Libc9a8082012-11-07 15:51:28 -0800177 }
Muhua Lida2c4be2012-11-26 09:14:16 -0800178
179 memset(node, 0, sizeof(qcamera_sm_cmd_t));
180 node->cmd = QCAMERA_SM_CMD_TYPE_API;
181 node->evt = evt;
182 node->evt_payload = api_payload;
183 if (api_queue.enqueue((void *)node)) {
Shuzhen Wang2da44612012-12-20 10:51:57 -0800184 cam_sem_post(&cmd_sem);
Muhua Lida2c4be2012-11-26 09:14:16 -0800185 return NO_ERROR;
186 } else {
187 free(node);
188 return UNKNOWN_ERROR;
189 }
Muhua Libc9a8082012-11-07 15:51:28 -0800190}
191
Muhua Lida2c4be2012-11-26 09:14:16 -0800192/*===========================================================================
193 * FUNCTION : procEvt
194 *
195 * DESCRIPTION: process incoming envent from mm-camera-interface and
196 * mm-jpeg-interface.
197 *
198 * PARAMETERS :
199 * @evt : event to be processed
200 * @evt_payload : event payload. Can be NULL if not needed.
201 *
202 * RETURN : int32_t type of status
203 * NO_ERROR -- success
204 * none-zero failure code
205 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800206int32_t QCameraStateMachine::procEvt(qcamera_sm_evt_enum_t evt,
207 void *evt_payload)
208{
209 qcamera_sm_cmd_t *node =
210 (qcamera_sm_cmd_t *)malloc(sizeof(qcamera_sm_cmd_t));
Muhua Lida2c4be2012-11-26 09:14:16 -0800211 if (NULL == node) {
212 ALOGE("%s: No memory for qcamera_sm_cmd_t", __func__);
213 return NO_MEMORY;
Muhua Libc9a8082012-11-07 15:51:28 -0800214 }
Muhua Lida2c4be2012-11-26 09:14:16 -0800215
216 memset(node, 0, sizeof(qcamera_sm_cmd_t));
217 node->cmd = QCAMERA_SM_CMD_TYPE_EVT;
218 node->evt = evt;
219 node->evt_payload = evt_payload;
220 if (evt_queue.enqueue((void *)node)) {
Shuzhen Wang2da44612012-12-20 10:51:57 -0800221 cam_sem_post(&cmd_sem);
Muhua Lida2c4be2012-11-26 09:14:16 -0800222 return NO_ERROR;
223 } else {
224 free(node);
225 return UNKNOWN_ERROR;
226 }
Muhua Libc9a8082012-11-07 15:51:28 -0800227}
228
Muhua Lida2c4be2012-11-26 09:14:16 -0800229/*===========================================================================
230 * FUNCTION : stateMachine
231 *
232 * DESCRIPTION: finite state machine entry function. Depends on state,
233 * incoming event will be handled differently.
234 *
235 * PARAMETERS :
236 * @evt : event to be processed
237 * @payload : event payload. Can be NULL if not needed.
238 *
239 * RETURN : int32_t type of status
240 * NO_ERROR -- success
241 * none-zero failure code
242 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800243int32_t QCameraStateMachine::stateMachine(qcamera_sm_evt_enum_t evt, void *payload)
244{
245 int32_t rc = NO_ERROR;
246 switch (m_state) {
247 case QCAMERA_SM_STATE_PREVIEW_STOPPED:
248 rc = procEvtPreviewStoppedState(evt, payload);
249 break;
250 case QCAMERA_SM_STATE_PREVIEW_READY:
251 rc = procEvtPreviewReadyState(evt, payload);
252 break;
253 case QCAMERA_SM_STATE_PREVIEWING:
254 rc = procEvtPreviewingState(evt, payload);
255 break;
Shuzhen Wang93f24112013-02-20 16:01:42 -0800256 case QCAMERA_SM_STATE_PREPARE_SNAPSHOT:
257 rc = procEvtPrepareSnapshotState(evt, payload);
258 break;
Muhua Libc9a8082012-11-07 15:51:28 -0800259 case QCAMERA_SM_STATE_PIC_TAKING:
260 rc = procEvtPicTakingState(evt, payload);
261 break;
262 case QCAMERA_SM_STATE_RECORDING:
263 rc = procEvtRecordingState(evt, payload);
264 break;
265 case QCAMERA_SM_STATE_VIDEO_PIC_TAKING:
266 rc = procEvtVideoPicTakingState(evt, payload);
267 break;
268 case QCAMERA_SM_STATE_PREVIEW_PIC_TAKING:
269 rc = procEvtPreviewPicTakingState(evt, payload);
270 break;
271 default:
272 break;
273 }
274
275 return rc;
276}
277
Muhua Lida2c4be2012-11-26 09:14:16 -0800278/*===========================================================================
279 * FUNCTION : procEvtPreviewStoppedState
280 *
281 * DESCRIPTION: finite state machine function to handle event in state of
282 * QCAMERA_SM_STATE_PREVIEW_STOPPED.
283 *
284 * PARAMETERS :
285 * @evt : event to be processed
286 * @payload : event payload. Can be NULL if not needed.
287 *
288 * RETURN : int32_t type of status
289 * NO_ERROR -- success
290 * none-zero failure code
291 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800292int32_t QCameraStateMachine::procEvtPreviewStoppedState(qcamera_sm_evt_enum_t evt,
293 void *payload)
294{
295 int32_t rc = NO_ERROR;
296 qcamera_api_result_t result;
297 memset(&result, 0, sizeof(qcamera_api_result_t));
298
299 switch (evt) {
300 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
301 {
302 rc = m_parent->setPreviewWindow((struct preview_stream_ops *)payload);
303 result.status = rc;
304 result.request_api = evt;
305 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
306 m_parent->signalAPIResult(&result);
307 }
308 break;
309 case QCAMERA_SM_EVT_SET_CALLBACKS:
310 {
311 qcamera_sm_evt_setcb_payload_t *setcbs =
312 (qcamera_sm_evt_setcb_payload_t *)payload;
313 rc = m_parent->setCallBacks(setcbs->notify_cb,
314 setcbs->data_cb,
315 setcbs->data_cb_timestamp,
316 setcbs->get_memory,
317 setcbs->user);
318 result.status = rc;
319 result.request_api = evt;
320 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
321 m_parent->signalAPIResult(&result);
322 }
323 break;
324 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
325 {
326 rc = m_parent->enableMsgType(int32_t(payload));
327 result.status = rc;
328 result.request_api = evt;
329 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
330 m_parent->signalAPIResult(&result);
331 }
332 break;
333 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
334 {
335 rc = m_parent->disableMsgType(int32_t(payload));
336 result.status = rc;
337 result.request_api = evt;
338 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
339 m_parent->signalAPIResult(&result);
340 }
341 break;
342 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
343 {
344 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
345 result.status = rc;
346 result.request_api = evt;
347 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
348 result.enabled = enabled;
349 m_parent->signalAPIResult(&result);
350 }
351 break;
352 case QCAMERA_SM_EVT_SET_PARAMS:
353 {
Muhua Lida2c4be2012-11-26 09:14:16 -0800354 bool needRestart = false;
355 rc = m_parent->updateParameters((char*)payload, needRestart);
356 if (rc == NO_ERROR) {
357 rc = m_parent->commitParameterChanges();
358 }
Muhua Libc9a8082012-11-07 15:51:28 -0800359 result.status = rc;
360 result.request_api = evt;
361 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
362 m_parent->signalAPIResult(&result);
363 }
364 break;
365 case QCAMERA_SM_EVT_GET_PARAMS:
366 {
367 result.params = m_parent->getParameters();
368 rc = NO_ERROR;
369 result.status = rc;
370 result.request_api = evt;
371 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
372 m_parent->signalAPIResult(&result);
373 }
374 break;
375 case QCAMERA_SM_EVT_PUT_PARAMS:
376 {
377 rc = m_parent->putParameters((char*)payload);
378 result.status = rc;
379 result.request_api = evt;
380 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
381 m_parent->signalAPIResult(&result);
382 }
383 break;
384 case QCAMERA_SM_EVT_START_PREVIEW:
385 {
386 if (m_parent->mPreviewWindow == NULL) {
Mansoor Aftab06c809c2013-01-23 19:44:47 -0800387 rc = m_parent->preparePreview();
388 if(rc == NO_ERROR) {
389 // preview window is not set yet, move to previewReady state
390 m_state = QCAMERA_SM_STATE_PREVIEW_READY;
391 } else {
392 ALOGE("%s: preparePreview failed",__func__);
393 }
Muhua Libc9a8082012-11-07 15:51:28 -0800394 } else {
395 rc = m_parent->preparePreview();
Muhua Lida2c4be2012-11-26 09:14:16 -0800396 if (rc == NO_ERROR) {
Muhua Libc9a8082012-11-07 15:51:28 -0800397 rc = m_parent->startPreview();
Muhua Lida2c4be2012-11-26 09:14:16 -0800398 if (rc != NO_ERROR) {
Muhua Libc9a8082012-11-07 15:51:28 -0800399 m_parent->unpreparePreview();
400 } else {
Muhua Lida2c4be2012-11-26 09:14:16 -0800401 // start preview success, move to previewing state
Muhua Libc9a8082012-11-07 15:51:28 -0800402 m_state = QCAMERA_SM_STATE_PREVIEWING;
403 }
404 }
405 }
406 result.status = rc;
407 result.request_api = evt;
408 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
409 m_parent->signalAPIResult(&result);
410 }
411 break;
412 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
413 {
414 rc = m_parent->preparePreview();
415 if (rc == NO_ERROR) {
416 rc = m_parent->startPreview();
417 if (rc != NO_ERROR) {
418 m_parent->unpreparePreview();
419 } else {
420 m_state = QCAMERA_SM_STATE_PREVIEWING;
421 }
422 }
423 result.status = rc;
424 result.request_api = evt;
425 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
426 m_parent->signalAPIResult(&result);
427 }
428 break;
429 case QCAMERA_SM_EVT_STOP_PREVIEW:
430 {
431 // no op needed here
432 ALOGD("%s: already in preview stopped state, do nothing", __func__);
433 result.status = NO_ERROR;
434 result.request_api = evt;
435 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
436 m_parent->signalAPIResult(&result);
437 }
438 break;
439 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
440 case QCAMERA_SM_EVT_RECORDING_ENABLED:
441 {
442 result.status = NO_ERROR;
443 result.request_api = evt;
444 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
445 result.enabled = 0;
446 m_parent->signalAPIResult(&result);
447 }
448 break;
449 case QCAMERA_SM_EVT_RELEASE:
450 {
451 rc = m_parent->release();
452 result.status = rc;
453 result.request_api = evt;
454 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
455 m_parent->signalAPIResult(&result);
456 }
457 break;
458 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
459 {
460 rc = m_parent->storeMetaDataInBuffers(int(payload));
461 result.status = rc;
462 result.request_api = evt;
463 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
464 m_parent->signalAPIResult(&result);
465 }
466 break;
467 case QCAMERA_SM_EVT_DUMP:
468 {
469 rc = m_parent->dump((int)payload);
470 result.status = rc;
471 result.request_api = evt;
472 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
473 m_parent->signalAPIResult(&result);
474 }
475 break;
Ankit Premrajka3b00dc62012-12-14 18:37:52 -0800476 case QCAMERA_SM_EVT_SEND_COMMAND:
477 {
478 qcamera_sm_evt_command_payload_t *cmd_payload =
479 (qcamera_sm_evt_command_payload_t *)payload;
480 rc = m_parent->sendCommand(cmd_payload->cmd,
481 cmd_payload->arg1,
482 cmd_payload->arg2);
483 result.status = rc;
484 result.request_api = evt;
485 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
486 m_parent->signalAPIResult(&result);
487 }
488 break;
Muhua Libc9a8082012-11-07 15:51:28 -0800489 case QCAMERA_SM_EVT_START_RECORDING:
490 case QCAMERA_SM_EVT_STOP_RECORDING:
491 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
Shuzhen Wang93f24112013-02-20 16:01:42 -0800492 case QCAMERA_SM_EVT_PREPARE_SNAPSHOT:
Muhua Libc9a8082012-11-07 15:51:28 -0800493 case QCAMERA_SM_EVT_TAKE_PICTURE:
Muhua Libc9a8082012-11-07 15:51:28 -0800494 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
Muhua Libc9a8082012-11-07 15:51:28 -0800495 {
496 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
497 rc = INVALID_OPERATION;
498 result.status = rc;
499 result.request_api = evt;
500 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
501 m_parent->signalAPIResult(&result);
502 }
503 break;
Muhua Li1612f422013-01-03 11:07:39 -0800504 case QCAMERA_SM_EVT_CANCEL_PICTURE:
505 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
506 {
507 // no op needed here
508 ALOGD("%s: No ops for evt(%d) in state(%d)", __func__, evt, m_state);
509 result.status = NO_ERROR;
510 result.request_api = evt;
511 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
512 m_parent->signalAPIResult(&result);
513 }
514 break;
Muhua Li5858c392013-02-04 17:53:34 -0800515 case QCAMERA_SM_EVT_REG_FACE_IMAGE:
516 {
517 int32_t faceID = 0;
518 qcamera_sm_evt_reg_face_payload_t *reg_payload =
519 (qcamera_sm_evt_reg_face_payload_t *)payload;
520 rc = m_parent->registerFaceImage(reg_payload->img_ptr,
521 reg_payload->config,
522 faceID);
523 result.status = rc;
524 result.request_api = evt;
525 result.result_type = QCAMERA_API_RESULT_TYPE_HANDLE;
526 result.handle = faceID;
527 m_parent->signalAPIResult(&result);
528 }
529 break;
Muhua Li31eaee02012-12-11 08:56:45 -0800530 case QCAMERA_SM_EVT_EVT_INTERNAL:
Muhua Libc9a8082012-11-07 15:51:28 -0800531 case QCAMERA_SM_EVT_EVT_NOTIFY:
532 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
Muhua Lida2c4be2012-11-26 09:14:16 -0800533 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
Shuzhen Wangaa829ce2013-01-09 14:41:49 -0800534 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
Muhua Libc9a8082012-11-07 15:51:28 -0800535 default:
536 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
537 break;
538 }
539
540 return rc;
541}
542
Muhua Lida2c4be2012-11-26 09:14:16 -0800543/*===========================================================================
544 * FUNCTION : procEvtPreviewReadyState
545 *
546 * DESCRIPTION: finite state machine function to handle event in state of
547 * QCAMERA_SM_STATE_PREVIEW_READY.
548 *
549 * PARAMETERS :
550 * @evt : event to be processed
551 * @payload : event payload. Can be NULL if not needed.
552 *
553 * RETURN : int32_t type of status
554 * NO_ERROR -- success
555 * none-zero failure code
556 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800557int32_t QCameraStateMachine::procEvtPreviewReadyState(qcamera_sm_evt_enum_t evt,
558 void *payload)
559{
560 int32_t rc = NO_ERROR;
561 qcamera_api_result_t result;
562 memset(&result, 0, sizeof(qcamera_api_result_t));
563
564 switch (evt) {
565 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
566 {
567 m_parent->setPreviewWindow((struct preview_stream_ops *)payload);
568 if (m_parent->mPreviewWindow != NULL) {
569 rc = m_parent->startPreview();
570 if (rc != NO_ERROR) {
571 m_parent->unpreparePreview();
572 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
573 } else {
574 m_state = QCAMERA_SM_STATE_PREVIEWING;
575 }
576 }
577
578 result.status = rc;
579 result.request_api = evt;
580 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
581 m_parent->signalAPIResult(&result);
582 }
583 break;
584 case QCAMERA_SM_EVT_SET_CALLBACKS:
585 {
586 qcamera_sm_evt_setcb_payload_t *setcbs =
587 (qcamera_sm_evt_setcb_payload_t *)payload;
588 rc = m_parent->setCallBacks(setcbs->notify_cb,
589 setcbs->data_cb,
590 setcbs->data_cb_timestamp,
591 setcbs->get_memory,
592 setcbs->user);
593 result.status = rc;
594 result.request_api = evt;
595 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
596 m_parent->signalAPIResult(&result);
597 }
598 break;
599 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
600 {
601 rc = m_parent->enableMsgType(int32_t(payload));
602 result.status = rc;
603 result.request_api = evt;
604 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
605 m_parent->signalAPIResult(&result);
606 }
607 break;
608 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
609 {
610 rc = m_parent->disableMsgType(int32_t(payload));
611 result.status = rc;
612 result.request_api = evt;
613 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
614 m_parent->signalAPIResult(&result);
615 }
616 break;
617 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
618 {
619 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
620 result.status = rc;
621 result.request_api = evt;
622 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
623 result.enabled = enabled;
624 m_parent->signalAPIResult(&result);
625 }
626 break;
627 case QCAMERA_SM_EVT_SET_PARAMS:
628 {
Muhua Lida2c4be2012-11-26 09:14:16 -0800629 bool needRestart = false;
630 rc = m_parent->updateParameters((char*)payload, needRestart);
631 if (rc == NO_ERROR) {
Muhua Li6d69e932013-01-24 16:39:27 -0800632 if (needRestart) {
633 // need restart preview for parameters to take effect
634 m_parent->unpreparePreview();
635 // commit parameter changes to server
636 m_parent->commitParameterChanges();
637 // prepare preview again
638 rc = m_parent->preparePreview();
639 if (rc != NO_ERROR) {
640 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
641 }
642 } else {
643 rc = m_parent->commitParameterChanges();
644 }
Muhua Lida2c4be2012-11-26 09:14:16 -0800645 }
Muhua Li6d69e932013-01-24 16:39:27 -0800646
Muhua Libc9a8082012-11-07 15:51:28 -0800647 result.status = rc;
648 result.request_api = evt;
649 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
650 m_parent->signalAPIResult(&result);
651 }
652 break;
653 case QCAMERA_SM_EVT_GET_PARAMS:
654 {
655 result.params = m_parent->getParameters();
656 rc = NO_ERROR;
657 result.status = rc;
658 result.request_api = evt;
659 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
660 m_parent->signalAPIResult(&result);
661 }
662 break;
663 case QCAMERA_SM_EVT_PUT_PARAMS:
664 {
665 rc = m_parent->putParameters((char*)payload);
666 result.status = rc;
667 result.request_api = evt;
668 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
669 m_parent->signalAPIResult(&result);
670 }
671 break;
672 case QCAMERA_SM_EVT_START_PREVIEW:
673 {
674 // no ops here
675 rc = NO_ERROR;
676 result.status = rc;
677 result.request_api = evt;
678 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
679 m_parent->signalAPIResult(&result);
680 }
681 break;
682 case QCAMERA_SM_EVT_STOP_PREVIEW:
683 {
684 m_parent->unpreparePreview();
685 rc = 0;
686 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
687 result.status = rc;
688 result.request_api = evt;
689 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
690 m_parent->signalAPIResult(&result);
691 }
692 break;
693 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
694 {
695 rc = NO_ERROR;
696 result.status = rc;
697 result.request_api = evt;
698 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
699 result.enabled = 1;
700 m_parent->signalAPIResult(&result);
701 }
702 break;
703 case QCAMERA_SM_EVT_RECORDING_ENABLED:
704 {
705 rc = 0;
706 result.status = rc;
707 result.request_api = evt;
708 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
709 result.enabled = 0;
710 m_parent->signalAPIResult(&result);
711 }
712 break;
713 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
714 {
715 rc = m_parent->storeMetaDataInBuffers(int(payload));
716 result.status = rc;
717 result.request_api = evt;
718 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
719 m_parent->signalAPIResult(&result);
720 }
721 break;
722 case QCAMERA_SM_EVT_DUMP:
723 {
724 rc = m_parent->dump((int)payload);
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_START_AUTO_FOCUS:
732 {
733 rc = m_parent->autoFocus();
734 result.status = rc;
735 result.request_api = evt;
736 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
737 m_parent->signalAPIResult(&result);
738 }
739 break;
740 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
741 {
742 rc = m_parent->cancelAutoFocus();
743 result.status = rc;
744 result.request_api = evt;
745 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
746 m_parent->signalAPIResult(&result);
747 }
748 break;
749 case QCAMERA_SM_EVT_SEND_COMMAND:
750 {
751 qcamera_sm_evt_command_payload_t *cmd_payload =
752 (qcamera_sm_evt_command_payload_t *)payload;
753 rc = m_parent->sendCommand(cmd_payload->cmd,
754 cmd_payload->arg1,
755 cmd_payload->arg2);
756 result.status = rc;
757 result.request_api = evt;
758 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
759 m_parent->signalAPIResult(&result);
760 }
761 break;
Muhua Li5858c392013-02-04 17:53:34 -0800762 case QCAMERA_SM_EVT_REG_FACE_IMAGE:
763 {
764 int32_t faceID = 0;
765 qcamera_sm_evt_reg_face_payload_t *reg_payload =
766 (qcamera_sm_evt_reg_face_payload_t *)payload;
767 rc = m_parent->registerFaceImage(reg_payload->img_ptr,
768 reg_payload->config,
769 faceID);
770 result.status = rc;
771 result.request_api = evt;
772 result.result_type = QCAMERA_API_RESULT_TYPE_HANDLE;
773 result.handle = faceID;
774 m_parent->signalAPIResult(&result);
775 }
776 break;
Muhua Libc9a8082012-11-07 15:51:28 -0800777 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
778 case QCAMERA_SM_EVT_START_RECORDING:
779 case QCAMERA_SM_EVT_STOP_RECORDING:
Shuzhen Wang93f24112013-02-20 16:01:42 -0800780 case QCAMERA_SM_EVT_PREPARE_SNAPSHOT:
Muhua Libc9a8082012-11-07 15:51:28 -0800781 case QCAMERA_SM_EVT_TAKE_PICTURE:
782 case QCAMERA_SM_EVT_CANCEL_PICTURE:
783 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
784 case QCAMERA_SM_EVT_RELEASE:
785 {
786 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
787 rc = INVALID_OPERATION;
788 result.status = rc;
789 result.request_api = evt;
790 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
791 m_parent->signalAPIResult(&result);
792 }
793 break;
Muhua Li31eaee02012-12-11 08:56:45 -0800794 case QCAMERA_SM_EVT_EVT_INTERNAL:
Muhua Libc9a8082012-11-07 15:51:28 -0800795 case QCAMERA_SM_EVT_EVT_NOTIFY:
796 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
Muhua Lida2c4be2012-11-26 09:14:16 -0800797 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
Shuzhen Wangaa829ce2013-01-09 14:41:49 -0800798 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
Muhua Libc9a8082012-11-07 15:51:28 -0800799 default:
800 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
801 break;
802 }
803
804 return rc;
805}
806
Muhua Lida2c4be2012-11-26 09:14:16 -0800807/*===========================================================================
808 * FUNCTION : procEvtPreviewingState
809 *
810 * DESCRIPTION: finite state machine function to handle event in state of
811 * QCAMERA_SM_STATE_PREVIEWING.
812 *
813 * PARAMETERS :
814 * @evt : event to be processed
815 * @payload : event payload. Can be NULL if not needed.
816 *
817 * RETURN : int32_t type of status
818 * NO_ERROR -- success
819 * none-zero failure code
820 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800821int32_t QCameraStateMachine::procEvtPreviewingState(qcamera_sm_evt_enum_t evt,
822 void *payload)
823{
824 int32_t rc = NO_ERROR;
825 qcamera_api_result_t result;
826 memset(&result, 0, sizeof(qcamera_api_result_t));
827
828 switch (evt) {
829 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
830 {
831 // Error setting preview window during previewing
832 ALOGE("Cannot set preview window when preview is running");
833 rc = INVALID_OPERATION;
834 result.status = rc;
835 result.request_api = evt;
836 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
837 m_parent->signalAPIResult(&result);
838 }
839 break;
840 case QCAMERA_SM_EVT_SET_CALLBACKS:
841 {
842 qcamera_sm_evt_setcb_payload_t *setcbs =
843 (qcamera_sm_evt_setcb_payload_t *)payload;
844 rc = m_parent->setCallBacks(setcbs->notify_cb,
845 setcbs->data_cb,
846 setcbs->data_cb_timestamp,
847 setcbs->get_memory,
848 setcbs->user);
849 result.status = rc;
850 result.request_api = evt;
851 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
852 m_parent->signalAPIResult(&result);
853 }
854 break;
855 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
856 {
857 rc = m_parent->enableMsgType(int32_t(payload));
858 result.status = rc;
859 result.request_api = evt;
860 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
861 m_parent->signalAPIResult(&result);
862 }
863 break;
864 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
865 {
866 rc = m_parent->disableMsgType(int32_t(payload));
867 result.status = rc;
868 result.request_api = evt;
869 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
870 m_parent->signalAPIResult(&result);
871 }
872 break;
873 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
874 {
875 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
876 result.status = rc;
877 result.request_api = evt;
878 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
879 result.enabled = enabled;
880 m_parent->signalAPIResult(&result);
881 }
882 break;
883 case QCAMERA_SM_EVT_SET_PARAMS:
884 {
Muhua Lida2c4be2012-11-26 09:14:16 -0800885 bool needRestart = false;
886 rc = m_parent->updateParameters((char*)payload, needRestart);
887 if (rc == NO_ERROR) {
888 if (needRestart) {
889 // need restart preview for parameters to take effect
890 // stop preview
891 m_parent->stopPreview();
892 // commit parameter changes to server
Muhua Li66f3b532013-01-23 17:19:05 -0800893 m_parent->commitParameterChanges();
Muhua Lida2c4be2012-11-26 09:14:16 -0800894 // start preview again
Muhua Li66f3b532013-01-23 17:19:05 -0800895 rc = m_parent->preparePreview();
896 if (rc == NO_ERROR) {
897 rc = m_parent->startPreview();
898 if (rc != NO_ERROR) {
899 m_parent->unpreparePreview();
900 }
901 }
902 if (rc != NO_ERROR) {
903 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
904 }
Muhua Lida2c4be2012-11-26 09:14:16 -0800905 } else {
906 rc = m_parent->commitParameterChanges();
907 }
908 }
Muhua Libc9a8082012-11-07 15:51:28 -0800909 result.status = rc;
910 result.request_api = evt;
911 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
912 m_parent->signalAPIResult(&result);
913 }
914 break;
915 case QCAMERA_SM_EVT_GET_PARAMS:
916 {
917 result.params = m_parent->getParameters();
918 rc = NO_ERROR;
919 result.status = rc;
920 result.request_api = evt;
921 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
922 m_parent->signalAPIResult(&result);
923 }
924 break;
925 case QCAMERA_SM_EVT_PUT_PARAMS:
926 {
927 rc = m_parent->putParameters((char*)payload);
928 result.status = rc;
929 result.request_api = evt;
930 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
931 m_parent->signalAPIResult(&result);
932 }
933 break;
934 case QCAMERA_SM_EVT_START_PREVIEW:
935 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
936 {
937 // no ops here
938 ALOGD("%s: Already in previewing, no ops here to start preview", __func__);
939 rc = NO_ERROR;
940 result.status = rc;
941 result.request_api = evt;
942 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
943 m_parent->signalAPIResult(&result);
944 }
945 break;
946 case QCAMERA_SM_EVT_STOP_PREVIEW:
947 {
948 rc = m_parent->stopPreview();
949 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
950 result.status = rc;
951 result.request_api = evt;
952 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
953 m_parent->signalAPIResult(&result);
954 }
955 break;
956 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
957 {
958 rc = NO_ERROR;
959 result.status = rc;
960 result.request_api = evt;
961 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
962 result.enabled = 1;
963 m_parent->signalAPIResult(&result);
964 }
965 break;
966 case QCAMERA_SM_EVT_RECORDING_ENABLED:
967 {
968 rc = NO_ERROR;
969 result.status = rc;
970 result.request_api = evt;
971 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
972 result.enabled = 0;
973 m_parent->signalAPIResult(&result);
974 }
975 break;
976 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
977 {
978 rc = m_parent->storeMetaDataInBuffers(int(payload));
979 result.status = rc;
980 result.request_api = evt;
981 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
982 m_parent->signalAPIResult(&result);
983 }
984 break;
985 case QCAMERA_SM_EVT_DUMP:
986 {
987 rc = m_parent->dump((int)payload);
988 result.status = rc;
989 result.request_api = evt;
990 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
991 m_parent->signalAPIResult(&result);
992 }
993 break;
994 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
995 {
996 rc = m_parent->autoFocus();
997 result.status = rc;
998 result.request_api = evt;
999 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1000 m_parent->signalAPIResult(&result);
1001 }
1002 break;
1003 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
1004 {
1005 rc = m_parent->cancelAutoFocus();
1006 result.status = rc;
1007 result.request_api = evt;
1008 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1009 m_parent->signalAPIResult(&result);
1010 }
1011 break;
1012 case QCAMERA_SM_EVT_START_RECORDING:
1013 {
1014 rc = m_parent->startRecording();
1015 if (rc == NO_ERROR) {
1016 // move state to recording state
1017 m_state = QCAMERA_SM_STATE_RECORDING;
1018 }
1019 result.status = rc;
1020 result.request_api = evt;
1021 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1022 m_parent->signalAPIResult(&result);
1023 }
1024 break;
Shuzhen Wang93f24112013-02-20 16:01:42 -08001025 case QCAMERA_SM_EVT_PREPARE_SNAPSHOT:
Muhua Libc9a8082012-11-07 15:51:28 -08001026 {
Shuzhen Wang93f24112013-02-20 16:01:42 -08001027 rc = m_parent->prepareHardwareForSnapshot();
Muhua Libc9a8082012-11-07 15:51:28 -08001028 if (rc == NO_ERROR) {
Shuzhen Wang93f24112013-02-20 16:01:42 -08001029 // Do not signal API result in this case.
1030 // Need to wait for snapshot done in metadta.
1031 m_state = QCAMERA_SM_STATE_PREPARE_SNAPSHOT;
1032 } else {
1033 // Do not change state in this case.
1034 ALOGE("%s: prepareHardwareForSnapshot failed %d",
1035 __func__, rc);
1036
1037 result.status = rc;
1038 result.request_api = evt;
1039 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1040 m_parent->signalAPIResult(&result);
1041 }
1042 }
1043 break;
1044 case QCAMERA_SM_EVT_TAKE_PICTURE:
1045 {
1046 rc = m_parent->takePicture();
1047 if (rc == NO_ERROR) {
1048 // move state to picture taking state
1049 if (m_parent->isZSLMode()) {
1050 m_state = QCAMERA_SM_STATE_PREVIEW_PIC_TAKING;
1051 } else {
1052 m_state = QCAMERA_SM_STATE_PIC_TAKING;
1053 }
Muhua Libc9a8082012-11-07 15:51:28 -08001054 } else {
1055 // move state to preview stopped state
1056 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
1057 }
1058 result.status = rc;
1059 result.request_api = evt;
1060 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1061 m_parent->signalAPIResult(&result);
1062 }
1063 break;
1064 case QCAMERA_SM_EVT_SEND_COMMAND:
1065 {
1066 qcamera_sm_evt_command_payload_t *cmd_payload =
1067 (qcamera_sm_evt_command_payload_t *)payload;
1068 rc = m_parent->sendCommand(cmd_payload->cmd,
1069 cmd_payload->arg1,
1070 cmd_payload->arg2);
1071 result.status = rc;
1072 result.request_api = evt;
1073 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1074 m_parent->signalAPIResult(&result);
1075 }
1076 break;
Muhua Li5858c392013-02-04 17:53:34 -08001077 case QCAMERA_SM_EVT_REG_FACE_IMAGE:
1078 {
1079 int32_t faceID = 0;
1080 qcamera_sm_evt_reg_face_payload_t *reg_payload =
1081 (qcamera_sm_evt_reg_face_payload_t *)payload;
1082 rc = m_parent->registerFaceImage(reg_payload->img_ptr,
1083 reg_payload->config,
1084 faceID);
1085 result.status = rc;
1086 result.request_api = evt;
1087 result.result_type = QCAMERA_API_RESULT_TYPE_HANDLE;
1088 result.handle = faceID;
1089 m_parent->signalAPIResult(&result);
1090 }
1091 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001092 case QCAMERA_SM_EVT_CANCEL_PICTURE:
1093 case QCAMERA_SM_EVT_STOP_RECORDING:
1094 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
1095 case QCAMERA_SM_EVT_RELEASE:
1096 {
1097 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1098 rc = INVALID_OPERATION;
1099 result.status = rc;
1100 result.request_api = evt;
1101 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1102 m_parent->signalAPIResult(&result);
1103 }
1104 break;
Muhua Li31eaee02012-12-11 08:56:45 -08001105 case QCAMERA_SM_EVT_EVT_INTERNAL:
1106 {
1107 qcamera_sm_internal_evt_payload_t *internal_evt =
1108 (qcamera_sm_internal_evt_payload_t *)payload;
1109 switch (internal_evt->evt_type) {
1110 case QCAMERA_INTERNAL_EVT_FOCUS_UPDATE:
1111 rc = m_parent->processAutoFocusEvent(internal_evt->focus_data);
1112 break;
1113 default:
Shuzhen Wang93f24112013-02-20 16:01:42 -08001114 ALOGE("%s: Invalid internal event %d in state(%d)",
1115 __func__, internal_evt->evt_type, m_state);
Muhua Li31eaee02012-12-11 08:56:45 -08001116 break;
1117 }
1118 }
1119 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001120 case QCAMERA_SM_EVT_EVT_NOTIFY:
1121 {
1122 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
1123 switch (cam_evt->server_event_type) {
Muhua Libc9a8082012-11-07 15:51:28 -08001124 default:
1125 ALOGD("%s: no handling for server evt (%d) at this state",
1126 __func__, cam_evt->server_event_type);
1127 break;
1128 }
1129 }
1130 break;
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08001131 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
Emilian Peeve1d5acb2013-02-01 11:29:53 -08001132 {
Shuzhen Wangd415beb2013-02-08 10:28:16 -08001133 rc = m_parent->updateThermalLevel(
1134 *(qcamera_thermal_level_enum_t *)&payload);
Emilian Peeve1d5acb2013-02-01 11:29:53 -08001135 }
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08001136 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001137 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
Muhua Lida2c4be2012-11-26 09:14:16 -08001138 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
Muhua Libc9a8082012-11-07 15:51:28 -08001139 default:
1140 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1141 break;
1142 }
1143
1144 return rc;
1145}
1146
Muhua Lida2c4be2012-11-26 09:14:16 -08001147/*===========================================================================
Shuzhen Wang93f24112013-02-20 16:01:42 -08001148 * FUNCTION : procEvtPrepareSnapshotState
1149 *
1150 * DESCRIPTION: finite state machine function to handle event in state of
1151 * QCAMERA_SM_STATE_PREPARE_SNAPSHOT.
1152 *
1153 * PARAMETERS :
1154 * @evt : event to be processed
1155 * @payload : event payload. Can be NULL if not needed.
1156 *
1157 * RETURN : int32_t type of status
1158 * NO_ERROR -- success
1159 * none-zero failure code
1160 *==========================================================================*/
1161int32_t QCameraStateMachine::procEvtPrepareSnapshotState(qcamera_sm_evt_enum_t evt,
1162 void *payload)
1163{
1164 int32_t rc = NO_ERROR;
1165 qcamera_api_result_t result;
1166 memset(&result, 0, sizeof(qcamera_api_result_t));
1167
1168 switch (evt) {
1169 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
1170 case QCAMERA_SM_EVT_SET_CALLBACKS:
1171 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
1172 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
1173 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
1174 case QCAMERA_SM_EVT_SET_PARAMS:
1175 case QCAMERA_SM_EVT_GET_PARAMS:
1176 case QCAMERA_SM_EVT_PUT_PARAMS:
1177 case QCAMERA_SM_EVT_START_PREVIEW:
1178 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
1179 case QCAMERA_SM_EVT_STOP_PREVIEW:
1180 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
1181 case QCAMERA_SM_EVT_RECORDING_ENABLED:
1182 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
1183 case QCAMERA_SM_EVT_DUMP:
1184 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
1185 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
1186 case QCAMERA_SM_EVT_START_RECORDING:
1187 case QCAMERA_SM_EVT_TAKE_PICTURE:
1188 case QCAMERA_SM_EVT_SEND_COMMAND:
1189 case QCAMERA_SM_EVT_CANCEL_PICTURE:
1190 case QCAMERA_SM_EVT_STOP_RECORDING:
1191 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
1192 case QCAMERA_SM_EVT_RELEASE:
1193 {
1194 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1195 rc = INVALID_OPERATION;
1196 result.status = rc;
1197 result.request_api = evt;
1198 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1199 m_parent->signalAPIResult(&result);
1200 }
1201 break;
1202 case QCAMERA_SM_EVT_EVT_INTERNAL:
1203 {
1204 qcamera_sm_internal_evt_payload_t *internal_evt =
1205 (qcamera_sm_internal_evt_payload_t *)payload;
1206 switch (internal_evt->evt_type) {
1207 case QCAMERA_INTERNAL_EVT_PREP_SNAPSHOT_DONE:
1208 ALOGI("%s: Received QCAMERA_INTERNAL_EVT_PREP_SNAPSHOT_DONE event",
1209 __func__);
1210 m_parent->processPrepSnapshotDoneEvent(internal_evt->prep_snapshot_state);
1211 m_state = QCAMERA_SM_STATE_PREVIEWING;
1212
1213 result.status = NO_ERROR;
1214 result.request_api = QCAMERA_SM_EVT_PREPARE_SNAPSHOT;
1215 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1216 m_parent->signalAPIResult(&result);
1217 break;
1218 default:
1219 ALOGE("%s: Invalid internal event %d in state(%d)",
1220 __func__, internal_evt->evt_type, m_state);
1221 break;
1222 }
1223 }
1224 break;
1225 case QCAMERA_SM_EVT_EVT_NOTIFY:
1226 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
1227 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
1228 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
1229 default:
1230 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1231 break;
1232 }
1233
1234 return rc;
1235}
1236
1237/*===========================================================================
Muhua Lida2c4be2012-11-26 09:14:16 -08001238 * FUNCTION : procEvtPicTakingState
1239 *
1240 * DESCRIPTION: finite state machine function to handle event in state of
1241 * QCAMERA_SM_STATE_PIC_TAKING.
1242 *
1243 * PARAMETERS :
1244 * @evt : event to be processed
1245 * @payload : event payload. Can be NULL if not needed.
1246 *
1247 * RETURN : int32_t type of status
1248 * NO_ERROR -- success
1249 * none-zero failure code
1250 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -08001251int32_t QCameraStateMachine::procEvtPicTakingState(qcamera_sm_evt_enum_t evt,
1252 void *payload)
1253{
1254 int32_t rc = NO_ERROR;
1255 qcamera_api_result_t result;
1256 memset(&result, 0, sizeof(qcamera_api_result_t));
1257
1258 switch (evt) {
1259 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
1260 {
1261 // Error setting preview window during previewing
1262 ALOGE("Cannot set preview window when preview is running");
1263 rc = INVALID_OPERATION;
1264 result.status = rc;
1265 result.request_api = evt;
1266 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1267 m_parent->signalAPIResult(&result);
1268 }
1269 break;
1270 case QCAMERA_SM_EVT_SET_CALLBACKS:
1271 {
1272 qcamera_sm_evt_setcb_payload_t *setcbs =
1273 (qcamera_sm_evt_setcb_payload_t *)payload;
1274 rc = m_parent->setCallBacks(setcbs->notify_cb,
1275 setcbs->data_cb,
1276 setcbs->data_cb_timestamp,
1277 setcbs->get_memory,
1278 setcbs->user);
1279 result.status = rc;
1280 result.request_api = evt;
1281 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1282 m_parent->signalAPIResult(&result);
1283 }
1284 break;
1285 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
1286 {
1287 rc = m_parent->enableMsgType(int32_t(payload));
1288 result.status = rc;
1289 result.request_api = evt;
1290 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1291 m_parent->signalAPIResult(&result);
1292 }
1293 break;
1294 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
1295 {
1296 rc = m_parent->disableMsgType(int32_t(payload));
1297 result.status = rc;
1298 result.request_api = evt;
1299 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1300 m_parent->signalAPIResult(&result);
1301 }
1302 break;
1303 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
1304 {
1305 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
1306 result.status = rc;
1307 result.request_api = evt;
1308 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1309 result.enabled = enabled;
1310 m_parent->signalAPIResult(&result);
1311 }
1312 break;
1313 case QCAMERA_SM_EVT_SET_PARAMS:
1314 {
Muhua Lida2c4be2012-11-26 09:14:16 -08001315 bool needRestart = false;
1316 rc = m_parent->updateParameters((char*)payload, needRestart);
1317 if (rc == NO_ERROR) {
1318 rc = m_parent->commitParameterChanges();
1319 }
Muhua Libc9a8082012-11-07 15:51:28 -08001320 result.status = rc;
1321 result.request_api = evt;
1322 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1323 m_parent->signalAPIResult(&result);
1324 }
1325 break;
1326 case QCAMERA_SM_EVT_GET_PARAMS:
1327 {
1328 result.params = m_parent->getParameters();
1329 rc = NO_ERROR;
1330 result.status = rc;
1331 result.request_api = evt;
1332 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
1333 m_parent->signalAPIResult(&result);
1334 }
1335 break;
1336 case QCAMERA_SM_EVT_PUT_PARAMS:
1337 {
1338 rc = m_parent->putParameters((char*)payload);
1339 result.status = rc;
1340 result.request_api = evt;
1341 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1342 m_parent->signalAPIResult(&result);
1343 }
1344 break;
1345 case QCAMERA_SM_EVT_STOP_PREVIEW:
1346 {
1347 // no ops, since preview is stopped (normal),
1348 // or preview msg type is disabled (ZSL)
1349 rc = NO_ERROR;
1350 result.status = rc;
1351 result.request_api = evt;
1352 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1353 m_parent->signalAPIResult(&result);
1354 }
1355 break;
1356 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
1357 {
1358 rc = NO_ERROR;
1359 result.status = rc;
1360 result.request_api = evt;
1361 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1362 result.enabled = 0;
1363 m_parent->signalAPIResult(&result);
1364 }
1365 break;
1366 case QCAMERA_SM_EVT_RECORDING_ENABLED:
1367 {
1368 rc = NO_ERROR;
1369 result.status = rc;
1370 result.request_api = evt;
1371 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1372 result.enabled = 0;
1373 m_parent->signalAPIResult(&result);
1374 }
1375 break;
1376 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
1377 {
1378 rc = m_parent->storeMetaDataInBuffers(int(payload));
1379 result.status = rc;
1380 result.request_api = evt;
1381 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1382 m_parent->signalAPIResult(&result);
1383 }
1384 break;
1385 case QCAMERA_SM_EVT_DUMP:
1386 {
1387 rc = m_parent->dump((int)payload);
1388 result.status = rc;
1389 result.request_api = evt;
1390 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1391 m_parent->signalAPIResult(&result);
1392 }
1393 break;
1394 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
1395 {
1396 rc = m_parent->autoFocus();
1397 result.status = rc;
1398 result.request_api = evt;
1399 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1400 m_parent->signalAPIResult(&result);
1401 }
1402 break;
1403 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
1404 {
1405 rc = m_parent->cancelAutoFocus();
1406 result.status = rc;
1407 result.request_api = evt;
1408 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1409 m_parent->signalAPIResult(&result);
1410 }
1411 break;
1412 case QCAMERA_SM_EVT_SEND_COMMAND:
1413 {
1414 qcamera_sm_evt_command_payload_t *cmd_payload =
1415 (qcamera_sm_evt_command_payload_t *)payload;
1416 rc = m_parent->sendCommand(cmd_payload->cmd,
1417 cmd_payload->arg1,
1418 cmd_payload->arg2);
1419 result.status = rc;
1420 result.request_api = evt;
1421 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1422 m_parent->signalAPIResult(&result);
1423 }
1424 break;
1425 case QCAMERA_SM_EVT_CANCEL_PICTURE:
1426 {
1427 rc = m_parent->cancelPicture();
1428 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
1429 result.status = rc;
1430 result.request_api = evt;
1431 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1432 m_parent->signalAPIResult(&result);
1433 }
1434 break;
Muhua Li5858c392013-02-04 17:53:34 -08001435 case QCAMERA_SM_EVT_REG_FACE_IMAGE:
1436 {
1437 int32_t faceID = 0;
1438 qcamera_sm_evt_reg_face_payload_t *reg_payload =
1439 (qcamera_sm_evt_reg_face_payload_t *)payload;
1440 rc = m_parent->registerFaceImage(reg_payload->img_ptr,
1441 reg_payload->config,
1442 faceID);
1443 result.status = rc;
1444 result.request_api = evt;
1445 result.result_type = QCAMERA_API_RESULT_TYPE_HANDLE;
1446 result.handle = faceID;
1447 m_parent->signalAPIResult(&result);
1448 }
1449 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001450 case QCAMERA_SM_EVT_TAKE_PICTURE:
1451 case QCAMERA_SM_EVT_START_RECORDING:
1452 case QCAMERA_SM_EVT_STOP_RECORDING:
1453 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
1454 case QCAMERA_SM_EVT_START_PREVIEW:
1455 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
1456 case QCAMERA_SM_EVT_RELEASE:
1457 {
1458 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1459 rc = INVALID_OPERATION;
1460 result.status = rc;
1461 result.request_api = evt;
1462 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1463 m_parent->signalAPIResult(&result);
1464 }
1465 break;
Muhua Li31eaee02012-12-11 08:56:45 -08001466 case QCAMERA_SM_EVT_EVT_INTERNAL:
1467 {
1468 qcamera_sm_internal_evt_payload_t *internal_evt =
1469 (qcamera_sm_internal_evt_payload_t *)payload;
1470 switch (internal_evt->evt_type) {
1471 case QCAMERA_INTERNAL_EVT_FOCUS_UPDATE:
1472 rc = m_parent->processAutoFocusEvent(internal_evt->focus_data);
1473 break;
1474 default:
1475 break;
1476 }
1477 }
1478 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001479 case QCAMERA_SM_EVT_EVT_NOTIFY:
1480 {
1481 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
1482 switch (cam_evt->server_event_type) {
Muhua Libc9a8082012-11-07 15:51:28 -08001483 default:
1484 ALOGD("%s: no handling for server evt (%d) at this state",
1485 __func__, cam_evt->server_event_type);
1486 break;
1487 }
1488 }
1489 break;
1490 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
1491 {
1492 qcamera_jpeg_evt_payload_t *jpeg_job =
1493 (qcamera_jpeg_evt_payload_t *)payload;
1494 rc = m_parent->processJpegNotify(jpeg_job);
1495 }
1496 break;
1497 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
1498 {
1499 rc = m_parent->cancelPicture();
1500 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
1501 }
1502 break;
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08001503 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
Muhua Libc9a8082012-11-07 15:51:28 -08001504 default:
1505 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1506 break;
1507 }
1508
1509 return rc;
1510}
1511
Muhua Lida2c4be2012-11-26 09:14:16 -08001512/*===========================================================================
1513 * FUNCTION : procEvtRecordingState
1514 *
1515 * DESCRIPTION: finite state machine function to handle event in state of
1516 * QCAMERA_SM_STATE_RECORDING.
1517 *
1518 * PARAMETERS :
1519 * @evt : event to be processed
1520 * @payload : event payload. Can be NULL if not needed.
1521 *
1522 * RETURN : int32_t type of status
1523 * NO_ERROR -- success
1524 * none-zero failure code
1525 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -08001526int32_t QCameraStateMachine::procEvtRecordingState(qcamera_sm_evt_enum_t evt,
1527 void *payload)
1528{
1529 int32_t rc = NO_ERROR;
1530 qcamera_api_result_t result;
1531 memset(&result, 0, sizeof(qcamera_api_result_t));
1532
1533 switch (evt) {
1534 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
1535 {
1536 // Error setting preview window during previewing
1537 ALOGE("Cannot set preview window when preview is running");
1538 rc = INVALID_OPERATION;
1539 result.status = rc;
1540 result.request_api = evt;
1541 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1542 m_parent->signalAPIResult(&result);
1543 }
1544 break;
1545 case QCAMERA_SM_EVT_SET_CALLBACKS:
1546 {
1547 qcamera_sm_evt_setcb_payload_t *setcbs =
1548 (qcamera_sm_evt_setcb_payload_t *)payload;
1549 rc = m_parent->setCallBacks(setcbs->notify_cb,
1550 setcbs->data_cb,
1551 setcbs->data_cb_timestamp,
1552 setcbs->get_memory,
1553 setcbs->user);
1554 result.status = rc;
1555 result.request_api = evt;
1556 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1557 m_parent->signalAPIResult(&result);
1558 }
1559 break;
1560 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
1561 {
1562 rc = m_parent->enableMsgType(int32_t(payload));
1563 result.status = rc;
1564 result.request_api = evt;
1565 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1566 m_parent->signalAPIResult(&result);
1567 }
1568 break;
1569 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
1570 {
1571 rc = m_parent->disableMsgType(int32_t(payload));
1572 result.status = rc;
1573 result.request_api = evt;
1574 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1575 m_parent->signalAPIResult(&result);
1576 }
1577 break;
1578 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
1579 {
1580 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
1581 result.status = rc;
1582 result.request_api = evt;
1583 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1584 result.enabled = enabled;
1585 m_parent->signalAPIResult(&result);
1586 }
1587 break;
1588 case QCAMERA_SM_EVT_SET_PARAMS:
1589 {
Muhua Lida2c4be2012-11-26 09:14:16 -08001590 bool needRestart = false;
1591 rc = m_parent->updateParameters((char*)payload, needRestart);
1592 if (rc == NO_ERROR) {
1593 if (needRestart) {
1594 // cannot set parameters that requires restart during recording
1595 ALOGE("%s: Cannot set parameters that requires restart during recording",
1596 __func__);
1597 rc = BAD_VALUE;
1598 } else {
1599 rc = m_parent->commitParameterChanges();
1600 }
1601 }
Muhua Libc9a8082012-11-07 15:51:28 -08001602 result.status = rc;
1603 result.request_api = evt;
1604 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1605 m_parent->signalAPIResult(&result);
1606 }
1607 break;
1608 case QCAMERA_SM_EVT_GET_PARAMS:
1609 {
1610 result.params = m_parent->getParameters();
1611 rc = NO_ERROR;
1612 result.status = rc;
1613 result.request_api = evt;
1614 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
1615 m_parent->signalAPIResult(&result);
1616 }
1617 break;
1618 case QCAMERA_SM_EVT_PUT_PARAMS:
1619 {
1620 rc = m_parent->putParameters((char*)payload);
1621 result.status = rc;
1622 result.request_api = evt;
1623 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1624 m_parent->signalAPIResult(&result);
1625 }
1626 break;
1627 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
1628 {
1629 rc = NO_ERROR;
1630 result.status = rc;
1631 result.request_api = evt;
1632 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1633 result.enabled = 0;
1634 m_parent->signalAPIResult(&result);
1635 }
1636 break;
1637 case QCAMERA_SM_EVT_RECORDING_ENABLED:
1638 {
1639 rc = NO_ERROR;
1640 result.status = rc;
1641 result.request_api = evt;
1642 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1643 result.enabled = 1;
1644 m_parent->signalAPIResult(&result);
1645 }
1646 break;
1647 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
1648 {
1649 rc = m_parent->storeMetaDataInBuffers(int(payload));
1650 result.status = rc;
1651 result.request_api = evt;
1652 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1653 m_parent->signalAPIResult(&result);
1654 }
1655 break;
1656 case QCAMERA_SM_EVT_DUMP:
1657 {
1658 rc = m_parent->dump((int)payload);
1659 result.status = rc;
1660 result.request_api = evt;
1661 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1662 m_parent->signalAPIResult(&result);
1663 }
1664 break;
1665 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
1666 {
1667 rc = m_parent->autoFocus();
1668 result.status = rc;
1669 result.request_api = evt;
1670 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1671 m_parent->signalAPIResult(&result);
1672 }
1673 break;
1674 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
1675 {
1676 rc = m_parent->cancelAutoFocus();
1677 result.status = rc;
1678 result.request_api = evt;
1679 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1680 m_parent->signalAPIResult(&result);
1681 }
1682 break;
1683 case QCAMERA_SM_EVT_SEND_COMMAND:
1684 {
1685 qcamera_sm_evt_command_payload_t *cmd_payload =
1686 (qcamera_sm_evt_command_payload_t *)payload;
1687 rc = m_parent->sendCommand(cmd_payload->cmd,
1688 cmd_payload->arg1,
1689 cmd_payload->arg2);
1690 result.status = rc;
1691 result.request_api = evt;
1692 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1693 m_parent->signalAPIResult(&result);
1694 }
1695 break;
1696 case QCAMERA_SM_EVT_TAKE_PICTURE:
1697 {
Muhua Li1d0c4772013-02-22 15:39:45 -08001698 m_state = QCAMERA_SM_STATE_VIDEO_PIC_TAKING;
Muhua Libc9a8082012-11-07 15:51:28 -08001699 rc = m_parent->takeLiveSnapshot();
Muhua Li1d0c4772013-02-22 15:39:45 -08001700 if (rc != NO_ERROR) {
1701 m_state = QCAMERA_SM_STATE_RECORDING;
Muhua Libc9a8082012-11-07 15:51:28 -08001702 }
1703 result.status = rc;
1704 result.request_api = evt;
1705 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1706 m_parent->signalAPIResult(&result);
1707 }
1708 break;
1709 case QCAMERA_SM_EVT_START_RECORDING:
1710 {
1711 // no ops here
1712 ALOGD("%s: already in recording state, no ops for start_recording", __func__);
1713 rc = 0;
1714 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_STOP_RECORDING:
1721 {
1722 rc = m_parent->stopRecording();
1723 m_state = QCAMERA_SM_STATE_PREVIEWING;
1724 result.status = rc;
1725 result.request_api = evt;
1726 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1727 m_parent->signalAPIResult(&result);
1728 }
1729 break;
1730 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
1731 {
1732 rc = m_parent->releaseRecordingFrame((const void *)payload);
1733 result.status = rc;
1734 result.request_api = evt;
1735 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1736 m_parent->signalAPIResult(&result);
1737 }
1738 break;
Muhua Li5858c392013-02-04 17:53:34 -08001739 case QCAMERA_SM_EVT_REG_FACE_IMAGE:
1740 {
1741 int32_t faceID = 0;
1742 qcamera_sm_evt_reg_face_payload_t *reg_payload =
1743 (qcamera_sm_evt_reg_face_payload_t *)payload;
1744 rc = m_parent->registerFaceImage(reg_payload->img_ptr,
1745 reg_payload->config,
1746 faceID);
1747 result.status = rc;
1748 result.request_api = evt;
1749 result.result_type = QCAMERA_API_RESULT_TYPE_HANDLE;
1750 result.handle = faceID;
1751 m_parent->signalAPIResult(&result);
1752 }
1753 break;
Shuzhen Wang93f24112013-02-20 16:01:42 -08001754 case QCAMERA_SM_EVT_PREPARE_SNAPSHOT:
1755 {
1756 //In Video snapshot, prepare hardware is a no-op.
1757 result.status = NO_ERROR;
1758 result.request_api = evt;
1759 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1760 m_parent->signalAPIResult(&result);
1761 }
1762 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001763 case QCAMERA_SM_EVT_CANCEL_PICTURE:
1764 case QCAMERA_SM_EVT_START_PREVIEW:
1765 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
1766 case QCAMERA_SM_EVT_STOP_PREVIEW:
1767 case QCAMERA_SM_EVT_RELEASE:
1768 {
1769 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1770 rc = INVALID_OPERATION;
1771 result.status = rc;
1772 result.request_api = evt;
1773 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1774 m_parent->signalAPIResult(&result);
1775 }
1776 break;
Muhua Li31eaee02012-12-11 08:56:45 -08001777 case QCAMERA_SM_EVT_EVT_INTERNAL:
1778 {
1779 qcamera_sm_internal_evt_payload_t *internal_evt =
1780 (qcamera_sm_internal_evt_payload_t *)payload;
1781 switch (internal_evt->evt_type) {
1782 case QCAMERA_INTERNAL_EVT_FOCUS_UPDATE:
1783 rc = m_parent->processAutoFocusEvent(internal_evt->focus_data);
1784 break;
1785 default:
1786 break;
1787 }
1788 }
1789 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001790 case QCAMERA_SM_EVT_EVT_NOTIFY:
1791 {
1792 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
1793 switch (cam_evt->server_event_type) {
Muhua Libc9a8082012-11-07 15:51:28 -08001794 default:
1795 ALOGD("%s: no handling for server evt (%d) at this state",
1796 __func__, cam_evt->server_event_type);
1797 break;
1798 }
1799 }
1800 break;
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08001801 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
Emilian Peeve1d5acb2013-02-01 11:29:53 -08001802 {
Shuzhen Wangd415beb2013-02-08 10:28:16 -08001803 rc = m_parent->updateThermalLevel(
1804 *(qcamera_thermal_level_enum_t *)&payload);
Emilian Peeve1d5acb2013-02-01 11:29:53 -08001805 }
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08001806 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001807 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
Muhua Lida2c4be2012-11-26 09:14:16 -08001808 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
Muhua Libc9a8082012-11-07 15:51:28 -08001809 default:
1810 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1811 break;
1812 }
1813
1814 return rc;
1815}
1816
Muhua Lida2c4be2012-11-26 09:14:16 -08001817/*===========================================================================
1818 * FUNCTION : procEvtVideoPicTakingState
1819 *
1820 * DESCRIPTION: finite state machine function to handle event in state of
1821 * QCAMERA_SM_STATE_VIDEO_PIC_TAKING.
1822 *
1823 * PARAMETERS :
1824 * @evt : event to be processed
1825 * @payload : event payload. Can be NULL if not needed.
1826 *
1827 * RETURN : int32_t type of status
1828 * NO_ERROR -- success
1829 * none-zero failure code
1830 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -08001831int32_t QCameraStateMachine::procEvtVideoPicTakingState(qcamera_sm_evt_enum_t evt,
1832 void *payload)
1833{
1834 int32_t rc = NO_ERROR;
1835 qcamera_api_result_t result;
1836 memset(&result, 0, sizeof(qcamera_api_result_t));
1837
1838 switch (evt) {
1839 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
1840 {
1841 // Error setting preview window during previewing
1842 ALOGE("Cannot set preview window when preview is running");
1843 rc = INVALID_OPERATION;
1844 result.status = rc;
1845 result.request_api = evt;
1846 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1847 m_parent->signalAPIResult(&result);
1848 }
1849 break;
1850 case QCAMERA_SM_EVT_SET_CALLBACKS:
1851 {
1852 qcamera_sm_evt_setcb_payload_t *setcbs =
1853 (qcamera_sm_evt_setcb_payload_t *)payload;
1854 rc = m_parent->setCallBacks(setcbs->notify_cb,
1855 setcbs->data_cb,
1856 setcbs->data_cb_timestamp,
1857 setcbs->get_memory,
1858 setcbs->user);
1859 result.status = rc;
1860 result.request_api = evt;
1861 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1862 m_parent->signalAPIResult(&result);
1863 }
1864 break;
1865 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
1866 {
1867 rc = m_parent->enableMsgType(int32_t(payload));
1868 result.status = rc;
1869 result.request_api = evt;
1870 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1871 m_parent->signalAPIResult(&result);
1872 }
1873 break;
1874 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
1875 {
1876 rc = m_parent->disableMsgType(int32_t(payload));
1877 result.status = rc;
1878 result.request_api = evt;
1879 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1880 m_parent->signalAPIResult(&result);
1881 }
1882 break;
1883 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
1884 {
1885 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
1886 result.status = rc;
1887 result.request_api = evt;
1888 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1889 result.enabled = enabled;
1890 m_parent->signalAPIResult(&result);
1891 }
1892 break;
1893 case QCAMERA_SM_EVT_SET_PARAMS:
1894 {
Muhua Lida2c4be2012-11-26 09:14:16 -08001895 bool needRestart = false;
1896 rc = m_parent->updateParameters((char*)payload, needRestart);
1897 if (rc == NO_ERROR) {
1898 if (needRestart) {
1899 // cannot set parameters that requires restart during recording
1900 ALOGE("%s: Cannot set parameters that requires restart during recording",
1901 __func__);
1902 rc = BAD_VALUE;
1903 } else {
1904 rc = m_parent->commitParameterChanges();
1905 }
1906 }
Muhua Libc9a8082012-11-07 15:51:28 -08001907 result.status = rc;
1908 result.request_api = evt;
1909 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1910 m_parent->signalAPIResult(&result);
1911 }
1912 break;
1913 case QCAMERA_SM_EVT_GET_PARAMS:
1914 {
1915 result.params = m_parent->getParameters();
1916 rc = NO_ERROR;
1917 result.status = rc;
1918 result.request_api = evt;
1919 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
1920 m_parent->signalAPIResult(&result);
1921 }
1922 break;
1923 case QCAMERA_SM_EVT_PUT_PARAMS:
1924 {
1925 rc = m_parent->putParameters((char*)payload);
1926 result.status = rc;
1927 result.request_api = evt;
1928 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1929 m_parent->signalAPIResult(&result);
1930 }
1931 break;
1932 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
1933 {
1934 rc = NO_ERROR;
1935 result.status = rc;
1936 result.request_api = evt;
1937 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1938 result.enabled = 1;
1939 m_parent->signalAPIResult(&result);
1940 }
1941 break;
1942 case QCAMERA_SM_EVT_RECORDING_ENABLED:
1943 {
1944 rc = NO_ERROR;
1945 result.status = rc;
1946 result.request_api = evt;
1947 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1948 result.enabled = 1;
1949 m_parent->signalAPIResult(&result);
1950 }
1951 break;
1952 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
1953 {
1954 rc = m_parent->storeMetaDataInBuffers(int(payload));
1955 result.status = rc;
1956 result.request_api = evt;
1957 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1958 m_parent->signalAPIResult(&result);
1959 }
1960 break;
1961 case QCAMERA_SM_EVT_DUMP:
1962 {
1963 rc = m_parent->dump((int)payload);
1964 result.status = rc;
1965 result.request_api = evt;
1966 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1967 m_parent->signalAPIResult(&result);
1968 }
1969 break;
1970 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
1971 {
1972 rc = m_parent->autoFocus();
1973 result.status = rc;
1974 result.request_api = evt;
1975 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1976 m_parent->signalAPIResult(&result);
1977 }
1978 break;
1979 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
1980 {
1981 rc = m_parent->cancelAutoFocus();
1982 result.status = rc;
1983 result.request_api = evt;
1984 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1985 m_parent->signalAPIResult(&result);
1986 }
1987 break;
1988 case QCAMERA_SM_EVT_SEND_COMMAND:
1989 {
1990 qcamera_sm_evt_command_payload_t *cmd_payload =
1991 (qcamera_sm_evt_command_payload_t *)payload;
1992 rc = m_parent->sendCommand(cmd_payload->cmd,
1993 cmd_payload->arg1,
1994 cmd_payload->arg2);
1995 result.status = rc;
1996 result.request_api = evt;
1997 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1998 m_parent->signalAPIResult(&result);
1999 }
2000 break;
2001 case QCAMERA_SM_EVT_STOP_RECORDING:
2002 {
2003 rc = m_parent->stopRecording();
2004 m_state = QCAMERA_SM_STATE_PREVIEW_PIC_TAKING;
2005 result.status = rc;
2006 result.request_api = evt;
2007 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2008 m_parent->signalAPIResult(&result);
2009 }
2010 break;
2011 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
2012 {
2013 rc = m_parent->releaseRecordingFrame((const void *)payload);
2014 result.status = rc;
2015 result.request_api = evt;
2016 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2017 m_parent->signalAPIResult(&result);
2018 }
2019 break;
2020 case QCAMERA_SM_EVT_CANCEL_PICTURE:
2021 {
2022 rc = m_parent->cancelLiveSnapshot();
2023 m_state = QCAMERA_SM_STATE_RECORDING;
2024 result.status = rc;
2025 result.request_api = evt;
2026 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2027 m_parent->signalAPIResult(&result);
2028 }
2029 break;
Muhua Li5858c392013-02-04 17:53:34 -08002030 case QCAMERA_SM_EVT_REG_FACE_IMAGE:
2031 {
2032 int32_t faceID = 0;
2033 qcamera_sm_evt_reg_face_payload_t *reg_payload =
2034 (qcamera_sm_evt_reg_face_payload_t *)payload;
2035 rc = m_parent->registerFaceImage(reg_payload->img_ptr,
2036 reg_payload->config,
2037 faceID);
2038 result.status = rc;
2039 result.request_api = evt;
2040 result.result_type = QCAMERA_API_RESULT_TYPE_HANDLE;
2041 result.handle = faceID;
2042 m_parent->signalAPIResult(&result);
2043 }
2044 break;
Muhua Libc9a8082012-11-07 15:51:28 -08002045 case QCAMERA_SM_EVT_START_RECORDING:
2046 case QCAMERA_SM_EVT_START_PREVIEW:
2047 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
2048 case QCAMERA_SM_EVT_STOP_PREVIEW:
2049 case QCAMERA_SM_EVT_TAKE_PICTURE:
2050 case QCAMERA_SM_EVT_RELEASE:
2051 {
2052 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
2053 rc = INVALID_OPERATION;
2054 result.status = rc;
2055 result.request_api = evt;
2056 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2057 m_parent->signalAPIResult(&result);
2058 }
2059 break;
Muhua Li31eaee02012-12-11 08:56:45 -08002060 case QCAMERA_SM_EVT_EVT_INTERNAL:
2061 {
2062 qcamera_sm_internal_evt_payload_t *internal_evt =
2063 (qcamera_sm_internal_evt_payload_t *)payload;
2064 switch (internal_evt->evt_type) {
2065 case QCAMERA_INTERNAL_EVT_FOCUS_UPDATE:
2066 rc = m_parent->processAutoFocusEvent(internal_evt->focus_data);
2067 break;
2068 default:
2069 break;
2070 }
2071 }
2072 break;
Muhua Libc9a8082012-11-07 15:51:28 -08002073 case QCAMERA_SM_EVT_EVT_NOTIFY:
2074 {
2075 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
2076 switch (cam_evt->server_event_type) {
Muhua Libc9a8082012-11-07 15:51:28 -08002077 default:
2078 ALOGD("%s: no handling for server evt (%d) at this state",
2079 __func__, cam_evt->server_event_type);
2080 break;
2081 }
2082 }
2083 break;
2084 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
2085 {
2086 qcamera_jpeg_evt_payload_t *jpeg_job =
2087 (qcamera_jpeg_evt_payload_t *)payload;
2088 rc = m_parent->processJpegNotify(jpeg_job);
2089 }
2090 break;
2091 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
2092 {
2093 rc = m_parent->cancelLiveSnapshot();
2094 m_state = QCAMERA_SM_STATE_RECORDING;
2095 }
2096 break;
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08002097 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
Emilian Peeve1d5acb2013-02-01 11:29:53 -08002098 {
Shuzhen Wangd415beb2013-02-08 10:28:16 -08002099 rc = m_parent->updateThermalLevel(
2100 *(qcamera_thermal_level_enum_t *)&payload);
Emilian Peeve1d5acb2013-02-01 11:29:53 -08002101 }
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08002102 break;
Muhua Libc9a8082012-11-07 15:51:28 -08002103 default:
2104 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
2105 break;
2106 }
2107
2108 return rc;
2109}
2110
Muhua Lida2c4be2012-11-26 09:14:16 -08002111/*===========================================================================
2112 * FUNCTION : procEvtPreviewPicTakingState
2113 *
2114 * DESCRIPTION: finite state machine function to handle event in state of
2115 * QCAMERA_SM_STATE_PREVIEW_PIC_TAKING.
2116 *
2117 * PARAMETERS :
2118 * @evt : event to be processed
2119 * @payload : event payload. Can be NULL if not needed.
2120 *
2121 * RETURN : int32_t type of status
2122 * NO_ERROR -- success
2123 * none-zero failure code
2124 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -08002125int32_t QCameraStateMachine::procEvtPreviewPicTakingState(qcamera_sm_evt_enum_t evt,
2126 void *payload)
2127{
2128 int32_t rc = NO_ERROR;
2129 qcamera_api_result_t result;
2130 memset(&result, 0, sizeof(qcamera_api_result_t));
2131
2132 switch (evt) {
2133 case QCAMERA_SM_EVT_SET_CALLBACKS:
2134 {
2135 qcamera_sm_evt_setcb_payload_t *setcbs =
2136 (qcamera_sm_evt_setcb_payload_t *)payload;
2137 rc = m_parent->setCallBacks(setcbs->notify_cb,
2138 setcbs->data_cb,
2139 setcbs->data_cb_timestamp,
2140 setcbs->get_memory,
2141 setcbs->user);
2142 result.status = rc;
2143 result.request_api = evt;
2144 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2145 m_parent->signalAPIResult(&result);
2146 }
2147 break;
2148 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
2149 {
2150 rc = m_parent->enableMsgType(int32_t(payload));
2151 result.status = rc;
2152 result.request_api = evt;
2153 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2154 m_parent->signalAPIResult(&result);
2155 }
2156 break;
2157 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
2158 {
2159 rc = m_parent->disableMsgType(int32_t(payload));
2160 result.status = rc;
2161 result.request_api = evt;
2162 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2163 m_parent->signalAPIResult(&result);
2164 }
2165 break;
2166 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
2167 {
2168 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
2169 result.status = rc;
2170 result.request_api = evt;
2171 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
2172 result.enabled = enabled;
2173 m_parent->signalAPIResult(&result);
2174 }
2175 break;
2176 case QCAMERA_SM_EVT_SET_PARAMS:
2177 {
Muhua Lida2c4be2012-11-26 09:14:16 -08002178 bool needRestart = false;
2179 rc = m_parent->updateParameters((char*)payload, needRestart);
2180 if (rc == NO_ERROR) {
2181 if (needRestart) {
2182 // need restart preview for parameters to take effect
2183 // stop preview
2184 m_parent->stopPreview();
2185 // commit parameter changes to server
Muhua Li66f3b532013-01-23 17:19:05 -08002186 m_parent->commitParameterChanges();
Muhua Lida2c4be2012-11-26 09:14:16 -08002187 // start preview again
Muhua Li66f3b532013-01-23 17:19:05 -08002188 rc = m_parent->preparePreview();
2189 if (rc == NO_ERROR) {
2190 rc = m_parent->startPreview();
2191 if (rc != NO_ERROR) {
2192 m_parent->unpreparePreview();
2193 }
2194 }
2195 if (rc != NO_ERROR) {
2196 m_state = QCAMERA_SM_STATE_PIC_TAKING;
2197 }
Muhua Lida2c4be2012-11-26 09:14:16 -08002198 } else {
2199 rc = m_parent->commitParameterChanges();
2200 }
2201 }
Muhua Libc9a8082012-11-07 15:51:28 -08002202 result.status = rc;
2203 result.request_api = evt;
2204 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2205 m_parent->signalAPIResult(&result);
2206 }
2207 break;
2208 case QCAMERA_SM_EVT_GET_PARAMS:
2209 {
2210 result.params = m_parent->getParameters();
2211 rc = NO_ERROR;
2212 result.status = rc;
2213 result.request_api = evt;
2214 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
2215 m_parent->signalAPIResult(&result);
2216 }
2217 break;
2218 case QCAMERA_SM_EVT_PUT_PARAMS:
2219 {
2220 rc = m_parent->putParameters((char*)payload);
2221 result.status = rc;
2222 result.request_api = evt;
2223 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2224 m_parent->signalAPIResult(&result);
2225 }
2226 break;
2227 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
2228 {
2229 rc = NO_ERROR;
2230 result.status = rc;
2231 result.request_api = evt;
2232 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
2233 result.enabled = 1;
2234 m_parent->signalAPIResult(&result);
2235 }
2236 break;
2237 case QCAMERA_SM_EVT_RECORDING_ENABLED:
2238 {
2239 rc = NO_ERROR;
2240 result.status = rc;
2241 result.request_api = evt;
2242 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
2243 result.enabled = 0;
2244 m_parent->signalAPIResult(&result);
2245 }
2246 break;
2247 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
2248 {
2249 rc = m_parent->storeMetaDataInBuffers(int(payload));
2250 result.status = rc;
2251 result.request_api = evt;
2252 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2253 m_parent->signalAPIResult(&result);
2254 }
2255 break;
2256 case QCAMERA_SM_EVT_DUMP:
2257 {
2258 rc = m_parent->dump((int)payload);
2259 result.status = rc;
2260 result.request_api = evt;
2261 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2262 m_parent->signalAPIResult(&result);
2263 }
2264 break;
2265 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
2266 {
2267 rc = m_parent->autoFocus();
2268 result.status = rc;
2269 result.request_api = evt;
2270 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2271 m_parent->signalAPIResult(&result);
2272 }
2273 break;
2274 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
2275 {
2276 rc = m_parent->cancelAutoFocus();
2277 result.status = rc;
2278 result.request_api = evt;
2279 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2280 m_parent->signalAPIResult(&result);
2281 }
2282 break;
2283 case QCAMERA_SM_EVT_SEND_COMMAND:
2284 {
2285 qcamera_sm_evt_command_payload_t *cmd_payload =
2286 (qcamera_sm_evt_command_payload_t *)payload;
2287 rc = m_parent->sendCommand(cmd_payload->cmd,
2288 cmd_payload->arg1,
2289 cmd_payload->arg2);
2290 result.status = rc;
2291 result.request_api = evt;
2292 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2293 m_parent->signalAPIResult(&result);
2294 }
2295 break;
2296 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
2297 {
2298 rc = m_parent->releaseRecordingFrame((const void *)payload);
2299 result.status = rc;
2300 result.request_api = evt;
2301 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2302 m_parent->signalAPIResult(&result);
2303 }
2304 break;
2305 case QCAMERA_SM_EVT_CANCEL_PICTURE:
2306 {
Shuzhen Wang93f24112013-02-20 16:01:42 -08002307 if (m_parent->isZSLMode()) {
2308 rc = m_parent->cancelPicture();
2309 } else {
2310 rc = m_parent->cancelLiveSnapshot();
2311 }
Muhua Libc9a8082012-11-07 15:51:28 -08002312 m_state = QCAMERA_SM_STATE_PREVIEWING;
2313 result.status = rc;
2314 result.request_api = evt;
2315 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2316 m_parent->signalAPIResult(&result);
2317 }
2318 break;
2319 case QCAMERA_SM_EVT_STOP_PREVIEW:
2320 {
2321 m_parent->stopChannel(QCAMERA_CH_TYPE_PREVIEW);
2322 m_parent->delChannel(QCAMERA_CH_TYPE_PREVIEW);
2323 m_parent->delChannel(QCAMERA_CH_TYPE_VIDEO);
2324 m_state = QCAMERA_SM_STATE_PIC_TAKING;
2325 rc = NO_ERROR;
2326 result.status = rc;
2327 result.request_api = evt;
2328 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2329 m_parent->signalAPIResult(&result);
2330 }
2331 break;
2332 case QCAMERA_SM_EVT_START_RECORDING:
2333 {
2334 rc = m_parent->stopRecording();
2335 if (rc == NO_ERROR) {
2336 m_state = QCAMERA_SM_STATE_VIDEO_PIC_TAKING;
2337 }
2338 result.status = rc;
2339 result.request_api = evt;
2340 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2341 m_parent->signalAPIResult(&result);
2342 }
2343 break;
Muhua Li5858c392013-02-04 17:53:34 -08002344 case QCAMERA_SM_EVT_REG_FACE_IMAGE:
2345 {
2346 int32_t faceID = 0;
2347 qcamera_sm_evt_reg_face_payload_t *reg_payload =
2348 (qcamera_sm_evt_reg_face_payload_t *)payload;
2349 rc = m_parent->registerFaceImage(reg_payload->img_ptr,
2350 reg_payload->config,
2351 faceID);
2352 result.status = rc;
2353 result.request_api = evt;
2354 result.result_type = QCAMERA_API_RESULT_TYPE_HANDLE;
2355 result.handle = faceID;
2356 m_parent->signalAPIResult(&result);
2357 }
2358 break;
Muhua Libc9a8082012-11-07 15:51:28 -08002359 case QCAMERA_SM_EVT_STOP_RECORDING:
2360 case QCAMERA_SM_EVT_START_PREVIEW:
2361 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
2362 case QCAMERA_SM_EVT_TAKE_PICTURE:
2363 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
2364 case QCAMERA_SM_EVT_RELEASE:
2365 {
2366 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
2367 rc = INVALID_OPERATION;
2368 result.status = rc;
2369 result.request_api = evt;
2370 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2371 m_parent->signalAPIResult(&result);
2372 }
2373 break;
Muhua Li31eaee02012-12-11 08:56:45 -08002374 case QCAMERA_SM_EVT_EVT_INTERNAL:
2375 {
2376 qcamera_sm_internal_evt_payload_t *internal_evt =
2377 (qcamera_sm_internal_evt_payload_t *)payload;
2378 switch (internal_evt->evt_type) {
2379 case QCAMERA_INTERNAL_EVT_FOCUS_UPDATE:
2380 rc = m_parent->processAutoFocusEvent(internal_evt->focus_data);
2381 break;
2382 default:
2383 break;
2384 }
2385 }
2386 break;
Muhua Libc9a8082012-11-07 15:51:28 -08002387 case QCAMERA_SM_EVT_EVT_NOTIFY:
2388 {
2389 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
2390 switch (cam_evt->server_event_type) {
Muhua Libc9a8082012-11-07 15:51:28 -08002391 default:
2392 ALOGD("%s: no handling for server evt (%d) at this state",
2393 __func__, cam_evt->server_event_type);
2394 break;
2395 }
2396 }
2397 break;
2398 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
2399 {
2400 qcamera_jpeg_evt_payload_t *jpeg_job =
2401 (qcamera_jpeg_evt_payload_t *)payload;
2402 rc = m_parent->processJpegNotify(jpeg_job);
2403 }
2404 break;
2405 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
2406 {
Shuzhen Wang93f24112013-02-20 16:01:42 -08002407 if (m_parent->isZSLMode()) {
2408 rc = m_parent->cancelPicture();
2409 } else {
2410 rc = m_parent->cancelLiveSnapshot();
2411 }
Muhua Libc9a8082012-11-07 15:51:28 -08002412 m_state = QCAMERA_SM_STATE_PREVIEWING;
2413 }
2414 break;
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08002415 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
Emilian Peeve1d5acb2013-02-01 11:29:53 -08002416 {
Shuzhen Wangd415beb2013-02-08 10:28:16 -08002417 rc = m_parent->updateThermalLevel(
2418 *(qcamera_thermal_level_enum_t *)&payload);
Emilian Peeve1d5acb2013-02-01 11:29:53 -08002419 }
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08002420 break;
Muhua Libc9a8082012-11-07 15:51:28 -08002421 default:
2422 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
2423 break;
2424 }
2425
2426 return rc;
2427}
2428
Muhua Lida2c4be2012-11-26 09:14:16 -08002429/*===========================================================================
2430 * FUNCTION : isPreviewRunning
2431 *
2432 * DESCRIPTION: check if preview is in process.
2433 *
2434 * PARAMETERS : None
2435 *
2436 * RETURN : true -- preview running
2437 * false -- preview stopped
2438 *==========================================================================*/
2439bool QCameraStateMachine::isPreviewRunning()
2440{
2441 switch (m_state) {
2442 case QCAMERA_SM_STATE_PREVIEWING:
2443 case QCAMERA_SM_STATE_RECORDING:
2444 case QCAMERA_SM_STATE_VIDEO_PIC_TAKING:
2445 case QCAMERA_SM_STATE_PREVIEW_PIC_TAKING:
2446 return true;
2447 default:
2448 return false;
2449 }
2450}
2451
Shuzhen Wang89635cf2012-12-20 13:47:22 -08002452}; // namespace qcamera