blob: 275ed5f230833ca1d3e034e780801e27b7f5953d [file] [log] [blame]
Muhua Libc9a8082012-11-07 15:51:28 -08001/* Copyright (c) 2012, The Linux Foundataion. All rights reserved.
2*
3* Redistribution and use in source and binary forms, with or without
4* modification, are permitted provided that the following conditions are
5* met:
6* * Redistributions of source code must retain the above copyright
7* notice, this list of conditions and the following disclaimer.
8* * Redistributions in binary form must reproduce the above
9* copyright notice, this list of conditions and the following
10* disclaimer in the documentation and/or other materials provided
11* with the distribution.
12* * Neither the name of The Linux Foundation nor the names of its
13* contributors may be used to endorse or promote products derived
14* from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*
28*/
29
30#define LOG_TAG "QCameraStateMachine"
31
32#include <utils/Log.h>
33#include <utils/Errors.h>
34#include "QCamera2HWI.h"
35#include "QCameraStateMachine.h"
36
37namespace android {
38
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 {
58 ret = sem_wait(&pme->cmd_sem);
59 if (ret != 0 && errno != EINVAL) {
60 ALOGE("%s: sem_wait error (%s)",
61 __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:
76 case QCAMERA_SM_CMD_TYPE_EVT:
77 pme->stateMachine(node->evt, node->evt_payload);
78 break;
79 case QCAMERA_SM_CMD_TYPE_EXIT:
80 running = 0;
81 break;
82 default:
83 break;
84 }
85 }
86 } while (running);
87 ALOGD("%s: X", __func__);
88 return NULL;
89}
90
Muhua Lida2c4be2012-11-26 09:14:16 -080091/*===========================================================================
92 * FUNCTION : QCameraStateMachine
93 *
94 * DESCRIPTION: constructor of QCameraStateMachine. Will start process thread
95 *
96 * PARAMETERS :
97 * @ctrl : ptr to HWI object
98 *
99 * RETURN : none
100 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800101QCameraStateMachine::QCameraStateMachine(QCamera2HardwareInterface *ctrl) :
102 api_queue(),
103 evt_queue()
104{
105 m_parent = ctrl;
106 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
107 cmd_pid = 0;
108 sem_init(&cmd_sem, 0, 0);
109 pthread_create(&cmd_pid,
110 NULL,
111 smEvtProcRoutine,
112 this);
113}
114
Muhua Lida2c4be2012-11-26 09:14:16 -0800115/*===========================================================================
116 * FUNCTION : ~QCameraStateMachine
117 *
118 * DESCRIPTION: desctructor of QCameraStateMachine. Will stop process thread.
119 *
120 * PARAMETERS : none
121 *
122 * RETURN : none
123 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800124QCameraStateMachine::~QCameraStateMachine()
125{
126 if (cmd_pid != 0) {
127 qcamera_sm_cmd_t *node =
128 (qcamera_sm_cmd_t *)malloc(sizeof(qcamera_sm_cmd_t));
129 if (NULL != node) {
130 memset(node, 0, sizeof(qcamera_sm_cmd_t));
131 node->cmd = QCAMERA_SM_CMD_TYPE_EXIT;
132
133 api_queue.enqueue((void *)node);
134 sem_post(&cmd_sem);
135
136 /* wait until cmd thread exits */
137 if (pthread_join(cmd_pid, NULL) != 0) {
138 ALOGD("%s: pthread dead already\n", __func__);
139 }
140 }
141 cmd_pid = 0;
142 }
143 sem_destroy(&cmd_sem);
144}
145
Muhua Lida2c4be2012-11-26 09:14:16 -0800146/*===========================================================================
147 * FUNCTION : procAPI
148 *
149 * DESCRIPTION: process incoming API request from framework layer.
150 *
151 * PARAMETERS :
152 * @evt : event to be processed
153 * @api_payload : API payload. Can be NULL if not needed.
154 *
155 * RETURN : int32_t type of status
156 * NO_ERROR -- success
157 * none-zero failure code
158 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800159int32_t QCameraStateMachine::procAPI(qcamera_sm_evt_enum_t evt,
160 void *api_payload)
161{
162 qcamera_sm_cmd_t *node =
163 (qcamera_sm_cmd_t *)malloc(sizeof(qcamera_sm_cmd_t));
Muhua Lida2c4be2012-11-26 09:14:16 -0800164 if (NULL == node) {
165 ALOGE("%s: No memory for qcamera_sm_cmd_t", __func__);
166 return NO_MEMORY;
Muhua Libc9a8082012-11-07 15:51:28 -0800167 }
Muhua Lida2c4be2012-11-26 09:14:16 -0800168
169 memset(node, 0, sizeof(qcamera_sm_cmd_t));
170 node->cmd = QCAMERA_SM_CMD_TYPE_API;
171 node->evt = evt;
172 node->evt_payload = api_payload;
173 if (api_queue.enqueue((void *)node)) {
174 sem_post(&cmd_sem);
175 return NO_ERROR;
176 } else {
177 free(node);
178 return UNKNOWN_ERROR;
179 }
Muhua Libc9a8082012-11-07 15:51:28 -0800180}
181
Muhua Lida2c4be2012-11-26 09:14:16 -0800182/*===========================================================================
183 * FUNCTION : procEvt
184 *
185 * DESCRIPTION: process incoming envent from mm-camera-interface and
186 * mm-jpeg-interface.
187 *
188 * PARAMETERS :
189 * @evt : event to be processed
190 * @evt_payload : event payload. Can be NULL if not needed.
191 *
192 * RETURN : int32_t type of status
193 * NO_ERROR -- success
194 * none-zero failure code
195 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800196int32_t QCameraStateMachine::procEvt(qcamera_sm_evt_enum_t evt,
197 void *evt_payload)
198{
199 qcamera_sm_cmd_t *node =
200 (qcamera_sm_cmd_t *)malloc(sizeof(qcamera_sm_cmd_t));
Muhua Lida2c4be2012-11-26 09:14:16 -0800201 if (NULL == node) {
202 ALOGE("%s: No memory for qcamera_sm_cmd_t", __func__);
203 return NO_MEMORY;
Muhua Libc9a8082012-11-07 15:51:28 -0800204 }
Muhua Lida2c4be2012-11-26 09:14:16 -0800205
206 memset(node, 0, sizeof(qcamera_sm_cmd_t));
207 node->cmd = QCAMERA_SM_CMD_TYPE_EVT;
208 node->evt = evt;
209 node->evt_payload = evt_payload;
210 if (evt_queue.enqueue((void *)node)) {
211 sem_post(&cmd_sem);
212 return NO_ERROR;
213 } else {
214 free(node);
215 return UNKNOWN_ERROR;
216 }
Muhua Libc9a8082012-11-07 15:51:28 -0800217}
218
Muhua Lida2c4be2012-11-26 09:14:16 -0800219/*===========================================================================
220 * FUNCTION : stateMachine
221 *
222 * DESCRIPTION: finite state machine entry function. Depends on state,
223 * incoming event will be handled differently.
224 *
225 * PARAMETERS :
226 * @evt : event to be processed
227 * @payload : event payload. Can be NULL if not needed.
228 *
229 * RETURN : int32_t type of status
230 * NO_ERROR -- success
231 * none-zero failure code
232 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800233int32_t QCameraStateMachine::stateMachine(qcamera_sm_evt_enum_t evt, void *payload)
234{
235 int32_t rc = NO_ERROR;
236 switch (m_state) {
237 case QCAMERA_SM_STATE_PREVIEW_STOPPED:
238 rc = procEvtPreviewStoppedState(evt, payload);
239 break;
240 case QCAMERA_SM_STATE_PREVIEW_READY:
241 rc = procEvtPreviewReadyState(evt, payload);
242 break;
243 case QCAMERA_SM_STATE_PREVIEWING:
244 rc = procEvtPreviewingState(evt, payload);
245 break;
246 case QCAMERA_SM_STATE_PIC_TAKING:
247 rc = procEvtPicTakingState(evt, payload);
248 break;
249 case QCAMERA_SM_STATE_RECORDING:
250 rc = procEvtRecordingState(evt, payload);
251 break;
252 case QCAMERA_SM_STATE_VIDEO_PIC_TAKING:
253 rc = procEvtVideoPicTakingState(evt, payload);
254 break;
255 case QCAMERA_SM_STATE_PREVIEW_PIC_TAKING:
256 rc = procEvtPreviewPicTakingState(evt, payload);
257 break;
258 default:
259 break;
260 }
261
262 return rc;
263}
264
Muhua Lida2c4be2012-11-26 09:14:16 -0800265/*===========================================================================
266 * FUNCTION : procEvtPreviewStoppedState
267 *
268 * DESCRIPTION: finite state machine function to handle event in state of
269 * QCAMERA_SM_STATE_PREVIEW_STOPPED.
270 *
271 * PARAMETERS :
272 * @evt : event to be processed
273 * @payload : event payload. Can be NULL if not needed.
274 *
275 * RETURN : int32_t type of status
276 * NO_ERROR -- success
277 * none-zero failure code
278 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800279int32_t QCameraStateMachine::procEvtPreviewStoppedState(qcamera_sm_evt_enum_t evt,
280 void *payload)
281{
282 int32_t rc = NO_ERROR;
283 qcamera_api_result_t result;
284 memset(&result, 0, sizeof(qcamera_api_result_t));
285
286 switch (evt) {
287 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
288 {
289 rc = m_parent->setPreviewWindow((struct preview_stream_ops *)payload);
290 result.status = rc;
291 result.request_api = evt;
292 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
293 m_parent->signalAPIResult(&result);
294 }
295 break;
296 case QCAMERA_SM_EVT_SET_CALLBACKS:
297 {
298 qcamera_sm_evt_setcb_payload_t *setcbs =
299 (qcamera_sm_evt_setcb_payload_t *)payload;
300 rc = m_parent->setCallBacks(setcbs->notify_cb,
301 setcbs->data_cb,
302 setcbs->data_cb_timestamp,
303 setcbs->get_memory,
304 setcbs->user);
305 result.status = rc;
306 result.request_api = evt;
307 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
308 m_parent->signalAPIResult(&result);
309 }
310 break;
311 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
312 {
313 rc = m_parent->enableMsgType(int32_t(payload));
314 result.status = rc;
315 result.request_api = evt;
316 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
317 m_parent->signalAPIResult(&result);
318 }
319 break;
320 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
321 {
322 rc = m_parent->disableMsgType(int32_t(payload));
323 result.status = rc;
324 result.request_api = evt;
325 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
326 m_parent->signalAPIResult(&result);
327 }
328 break;
329 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
330 {
331 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
332 result.status = rc;
333 result.request_api = evt;
334 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
335 result.enabled = enabled;
336 m_parent->signalAPIResult(&result);
337 }
338 break;
339 case QCAMERA_SM_EVT_SET_PARAMS:
340 {
Muhua Lida2c4be2012-11-26 09:14:16 -0800341 bool needRestart = false;
342 rc = m_parent->updateParameters((char*)payload, needRestart);
343 if (rc == NO_ERROR) {
344 rc = m_parent->commitParameterChanges();
345 }
Muhua Libc9a8082012-11-07 15:51:28 -0800346 result.status = rc;
347 result.request_api = evt;
348 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
349 m_parent->signalAPIResult(&result);
350 }
351 break;
352 case QCAMERA_SM_EVT_GET_PARAMS:
353 {
354 result.params = m_parent->getParameters();
355 rc = NO_ERROR;
356 result.status = rc;
357 result.request_api = evt;
358 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
359 m_parent->signalAPIResult(&result);
360 }
361 break;
362 case QCAMERA_SM_EVT_PUT_PARAMS:
363 {
364 rc = m_parent->putParameters((char*)payload);
365 result.status = rc;
366 result.request_api = evt;
367 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
368 m_parent->signalAPIResult(&result);
369 }
370 break;
371 case QCAMERA_SM_EVT_START_PREVIEW:
372 {
373 if (m_parent->mPreviewWindow == NULL) {
Muhua Lida2c4be2012-11-26 09:14:16 -0800374 // preview window is not set yet, move to previewReady state
Muhua Libc9a8082012-11-07 15:51:28 -0800375 m_state = QCAMERA_SM_STATE_PREVIEW_READY;
376 rc = NO_ERROR;
377 } else {
378 rc = m_parent->preparePreview();
Muhua Lida2c4be2012-11-26 09:14:16 -0800379 if (rc == NO_ERROR) {
Muhua Libc9a8082012-11-07 15:51:28 -0800380 rc = m_parent->startPreview();
Muhua Lida2c4be2012-11-26 09:14:16 -0800381 if (rc != NO_ERROR) {
Muhua Libc9a8082012-11-07 15:51:28 -0800382 m_parent->unpreparePreview();
383 } else {
Muhua Lida2c4be2012-11-26 09:14:16 -0800384 // start preview success, move to previewing state
Muhua Libc9a8082012-11-07 15:51:28 -0800385 m_state = QCAMERA_SM_STATE_PREVIEWING;
386 }
387 }
388 }
389 result.status = rc;
390 result.request_api = evt;
391 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
392 m_parent->signalAPIResult(&result);
393 }
394 break;
395 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
396 {
397 rc = m_parent->preparePreview();
398 if (rc == NO_ERROR) {
399 rc = m_parent->startPreview();
400 if (rc != NO_ERROR) {
401 m_parent->unpreparePreview();
402 } else {
403 m_state = QCAMERA_SM_STATE_PREVIEWING;
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_STOP_PREVIEW:
413 {
414 // no op needed here
415 ALOGD("%s: already in preview stopped state, do nothing", __func__);
416 result.status = NO_ERROR;
417 result.request_api = evt;
418 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
419 m_parent->signalAPIResult(&result);
420 }
421 break;
422 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
423 case QCAMERA_SM_EVT_RECORDING_ENABLED:
424 {
425 result.status = NO_ERROR;
426 result.request_api = evt;
427 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
428 result.enabled = 0;
429 m_parent->signalAPIResult(&result);
430 }
431 break;
432 case QCAMERA_SM_EVT_RELEASE:
433 {
434 rc = m_parent->release();
435 result.status = rc;
436 result.request_api = evt;
437 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
438 m_parent->signalAPIResult(&result);
439 }
440 break;
441 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
442 {
443 rc = m_parent->storeMetaDataInBuffers(int(payload));
444 result.status = rc;
445 result.request_api = evt;
446 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
447 m_parent->signalAPIResult(&result);
448 }
449 break;
450 case QCAMERA_SM_EVT_DUMP:
451 {
452 rc = m_parent->dump((int)payload);
453 result.status = rc;
454 result.request_api = evt;
455 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
456 m_parent->signalAPIResult(&result);
457 }
458 break;
459 case QCAMERA_SM_EVT_START_RECORDING:
460 case QCAMERA_SM_EVT_STOP_RECORDING:
461 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
462 case QCAMERA_SM_EVT_TAKE_PICTURE:
463 case QCAMERA_SM_EVT_CANCEL_PICTURE:
464 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
465 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
466 case QCAMERA_SM_EVT_SEND_COMMAND:
467 {
468 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
469 rc = INVALID_OPERATION;
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;
476 case QCAMERA_SM_EVT_EVT_NOTIFY:
477 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
Muhua Lida2c4be2012-11-26 09:14:16 -0800478 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
Muhua Libc9a8082012-11-07 15:51:28 -0800479 default:
480 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
481 break;
482 }
483
484 return rc;
485}
486
Muhua Lida2c4be2012-11-26 09:14:16 -0800487/*===========================================================================
488 * FUNCTION : procEvtPreviewReadyState
489 *
490 * DESCRIPTION: finite state machine function to handle event in state of
491 * QCAMERA_SM_STATE_PREVIEW_READY.
492 *
493 * PARAMETERS :
494 * @evt : event to be processed
495 * @payload : event payload. Can be NULL if not needed.
496 *
497 * RETURN : int32_t type of status
498 * NO_ERROR -- success
499 * none-zero failure code
500 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800501int32_t QCameraStateMachine::procEvtPreviewReadyState(qcamera_sm_evt_enum_t evt,
502 void *payload)
503{
504 int32_t rc = NO_ERROR;
505 qcamera_api_result_t result;
506 memset(&result, 0, sizeof(qcamera_api_result_t));
507
508 switch (evt) {
509 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
510 {
511 m_parent->setPreviewWindow((struct preview_stream_ops *)payload);
512 if (m_parent->mPreviewWindow != NULL) {
513 rc = m_parent->startPreview();
514 if (rc != NO_ERROR) {
515 m_parent->unpreparePreview();
516 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
517 } else {
518 m_state = QCAMERA_SM_STATE_PREVIEWING;
519 }
520 }
521
522 result.status = rc;
523 result.request_api = evt;
524 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
525 m_parent->signalAPIResult(&result);
526 }
527 break;
528 case QCAMERA_SM_EVT_SET_CALLBACKS:
529 {
530 qcamera_sm_evt_setcb_payload_t *setcbs =
531 (qcamera_sm_evt_setcb_payload_t *)payload;
532 rc = m_parent->setCallBacks(setcbs->notify_cb,
533 setcbs->data_cb,
534 setcbs->data_cb_timestamp,
535 setcbs->get_memory,
536 setcbs->user);
537 result.status = rc;
538 result.request_api = evt;
539 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
540 m_parent->signalAPIResult(&result);
541 }
542 break;
543 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
544 {
545 rc = m_parent->enableMsgType(int32_t(payload));
546 result.status = rc;
547 result.request_api = evt;
548 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
549 m_parent->signalAPIResult(&result);
550 }
551 break;
552 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
553 {
554 rc = m_parent->disableMsgType(int32_t(payload));
555 result.status = rc;
556 result.request_api = evt;
557 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
558 m_parent->signalAPIResult(&result);
559 }
560 break;
561 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
562 {
563 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
564 result.status = rc;
565 result.request_api = evt;
566 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
567 result.enabled = enabled;
568 m_parent->signalAPIResult(&result);
569 }
570 break;
571 case QCAMERA_SM_EVT_SET_PARAMS:
572 {
Muhua Lida2c4be2012-11-26 09:14:16 -0800573 bool needRestart = false;
574 rc = m_parent->updateParameters((char*)payload, needRestart);
575 if (rc == NO_ERROR) {
576 rc = m_parent->commitParameterChanges();
577 }
Muhua Libc9a8082012-11-07 15:51:28 -0800578 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_GET_PARAMS:
585 {
586 result.params = m_parent->getParameters();
587 rc = NO_ERROR;
588 result.status = rc;
589 result.request_api = evt;
590 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
591 m_parent->signalAPIResult(&result);
592 }
593 break;
594 case QCAMERA_SM_EVT_PUT_PARAMS:
595 {
596 rc = m_parent->putParameters((char*)payload);
597 result.status = rc;
598 result.request_api = evt;
599 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
600 m_parent->signalAPIResult(&result);
601 }
602 break;
603 case QCAMERA_SM_EVT_START_PREVIEW:
604 {
605 // no ops here
606 rc = NO_ERROR;
607 result.status = rc;
608 result.request_api = evt;
609 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
610 m_parent->signalAPIResult(&result);
611 }
612 break;
613 case QCAMERA_SM_EVT_STOP_PREVIEW:
614 {
615 m_parent->unpreparePreview();
616 rc = 0;
617 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
618 result.status = rc;
619 result.request_api = evt;
620 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
621 m_parent->signalAPIResult(&result);
622 }
623 break;
624 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
625 {
626 rc = NO_ERROR;
627 result.status = rc;
628 result.request_api = evt;
629 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
630 result.enabled = 1;
631 m_parent->signalAPIResult(&result);
632 }
633 break;
634 case QCAMERA_SM_EVT_RECORDING_ENABLED:
635 {
636 rc = 0;
637 result.status = rc;
638 result.request_api = evt;
639 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
640 result.enabled = 0;
641 m_parent->signalAPIResult(&result);
642 }
643 break;
644 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
645 {
646 rc = m_parent->storeMetaDataInBuffers(int(payload));
647 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_DUMP:
654 {
655 rc = m_parent->dump((int)payload);
656 result.status = rc;
657 result.request_api = evt;
658 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
659 m_parent->signalAPIResult(&result);
660 }
661 break;
662 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
663 {
664 rc = m_parent->autoFocus();
665 result.status = rc;
666 result.request_api = evt;
667 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
668 m_parent->signalAPIResult(&result);
669 }
670 break;
671 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
672 {
673 rc = m_parent->cancelAutoFocus();
674 result.status = rc;
675 result.request_api = evt;
676 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
677 m_parent->signalAPIResult(&result);
678 }
679 break;
680 case QCAMERA_SM_EVT_SEND_COMMAND:
681 {
682 qcamera_sm_evt_command_payload_t *cmd_payload =
683 (qcamera_sm_evt_command_payload_t *)payload;
684 rc = m_parent->sendCommand(cmd_payload->cmd,
685 cmd_payload->arg1,
686 cmd_payload->arg2);
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_START_NODISPLAY_PREVIEW:
694 case QCAMERA_SM_EVT_START_RECORDING:
695 case QCAMERA_SM_EVT_STOP_RECORDING:
696 case QCAMERA_SM_EVT_TAKE_PICTURE:
697 case QCAMERA_SM_EVT_CANCEL_PICTURE:
698 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
699 case QCAMERA_SM_EVT_RELEASE:
700 {
701 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
702 rc = INVALID_OPERATION;
703 result.status = rc;
704 result.request_api = evt;
705 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
706 m_parent->signalAPIResult(&result);
707 }
708 break;
709 case QCAMERA_SM_EVT_EVT_NOTIFY:
710 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
Muhua Lida2c4be2012-11-26 09:14:16 -0800711 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
Muhua Libc9a8082012-11-07 15:51:28 -0800712 default:
713 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
714 break;
715 }
716
717 return rc;
718}
719
Muhua Lida2c4be2012-11-26 09:14:16 -0800720/*===========================================================================
721 * FUNCTION : procEvtPreviewingState
722 *
723 * DESCRIPTION: finite state machine function to handle event in state of
724 * QCAMERA_SM_STATE_PREVIEWING.
725 *
726 * PARAMETERS :
727 * @evt : event to be processed
728 * @payload : event payload. Can be NULL if not needed.
729 *
730 * RETURN : int32_t type of status
731 * NO_ERROR -- success
732 * none-zero failure code
733 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800734int32_t QCameraStateMachine::procEvtPreviewingState(qcamera_sm_evt_enum_t evt,
735 void *payload)
736{
737 int32_t rc = NO_ERROR;
738 qcamera_api_result_t result;
739 memset(&result, 0, sizeof(qcamera_api_result_t));
740
741 switch (evt) {
742 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
743 {
744 // Error setting preview window during previewing
745 ALOGE("Cannot set preview window when preview is running");
746 rc = INVALID_OPERATION;
747 result.status = rc;
748 result.request_api = evt;
749 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
750 m_parent->signalAPIResult(&result);
751 }
752 break;
753 case QCAMERA_SM_EVT_SET_CALLBACKS:
754 {
755 qcamera_sm_evt_setcb_payload_t *setcbs =
756 (qcamera_sm_evt_setcb_payload_t *)payload;
757 rc = m_parent->setCallBacks(setcbs->notify_cb,
758 setcbs->data_cb,
759 setcbs->data_cb_timestamp,
760 setcbs->get_memory,
761 setcbs->user);
762 result.status = rc;
763 result.request_api = evt;
764 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
765 m_parent->signalAPIResult(&result);
766 }
767 break;
768 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
769 {
770 rc = m_parent->enableMsgType(int32_t(payload));
771 result.status = rc;
772 result.request_api = evt;
773 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
774 m_parent->signalAPIResult(&result);
775 }
776 break;
777 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
778 {
779 rc = m_parent->disableMsgType(int32_t(payload));
780 result.status = rc;
781 result.request_api = evt;
782 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
783 m_parent->signalAPIResult(&result);
784 }
785 break;
786 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
787 {
788 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
789 result.status = rc;
790 result.request_api = evt;
791 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
792 result.enabled = enabled;
793 m_parent->signalAPIResult(&result);
794 }
795 break;
796 case QCAMERA_SM_EVT_SET_PARAMS:
797 {
Muhua Lida2c4be2012-11-26 09:14:16 -0800798 bool needRestart = false;
799 rc = m_parent->updateParameters((char*)payload, needRestart);
800 if (rc == NO_ERROR) {
801 if (needRestart) {
802 // need restart preview for parameters to take effect
803 // stop preview
804 m_parent->stopPreview();
805 // commit parameter changes to server
806 rc = m_parent->commitParameterChanges();
807 // start preview again
808 m_parent->startPreview();
809 } else {
810 rc = m_parent->commitParameterChanges();
811 }
812 }
Muhua Libc9a8082012-11-07 15:51:28 -0800813 result.status = rc;
814 result.request_api = evt;
815 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
816 m_parent->signalAPIResult(&result);
817 }
818 break;
819 case QCAMERA_SM_EVT_GET_PARAMS:
820 {
821 result.params = m_parent->getParameters();
822 rc = NO_ERROR;
823 result.status = rc;
824 result.request_api = evt;
825 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
826 m_parent->signalAPIResult(&result);
827 }
828 break;
829 case QCAMERA_SM_EVT_PUT_PARAMS:
830 {
831 rc = m_parent->putParameters((char*)payload);
832 result.status = rc;
833 result.request_api = evt;
834 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
835 m_parent->signalAPIResult(&result);
836 }
837 break;
838 case QCAMERA_SM_EVT_START_PREVIEW:
839 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
840 {
841 // no ops here
842 ALOGD("%s: Already in previewing, no ops here to start preview", __func__);
843 rc = NO_ERROR;
844 result.status = rc;
845 result.request_api = evt;
846 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
847 m_parent->signalAPIResult(&result);
848 }
849 break;
850 case QCAMERA_SM_EVT_STOP_PREVIEW:
851 {
852 rc = m_parent->stopPreview();
853 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
854 result.status = rc;
855 result.request_api = evt;
856 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
857 m_parent->signalAPIResult(&result);
858 }
859 break;
860 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
861 {
862 rc = NO_ERROR;
863 result.status = rc;
864 result.request_api = evt;
865 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
866 result.enabled = 1;
867 m_parent->signalAPIResult(&result);
868 }
869 break;
870 case QCAMERA_SM_EVT_RECORDING_ENABLED:
871 {
872 rc = NO_ERROR;
873 result.status = rc;
874 result.request_api = evt;
875 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
876 result.enabled = 0;
877 m_parent->signalAPIResult(&result);
878 }
879 break;
880 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
881 {
882 rc = m_parent->storeMetaDataInBuffers(int(payload));
883 result.status = rc;
884 result.request_api = evt;
885 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
886 m_parent->signalAPIResult(&result);
887 }
888 break;
889 case QCAMERA_SM_EVT_DUMP:
890 {
891 rc = m_parent->dump((int)payload);
892 result.status = rc;
893 result.request_api = evt;
894 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
895 m_parent->signalAPIResult(&result);
896 }
897 break;
898 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
899 {
900 rc = m_parent->autoFocus();
901 result.status = rc;
902 result.request_api = evt;
903 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
904 m_parent->signalAPIResult(&result);
905 }
906 break;
907 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
908 {
909 rc = m_parent->cancelAutoFocus();
910 result.status = rc;
911 result.request_api = evt;
912 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
913 m_parent->signalAPIResult(&result);
914 }
915 break;
916 case QCAMERA_SM_EVT_START_RECORDING:
917 {
918 rc = m_parent->startRecording();
919 if (rc == NO_ERROR) {
920 // move state to recording state
921 m_state = QCAMERA_SM_STATE_RECORDING;
922 }
923 result.status = rc;
924 result.request_api = evt;
925 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
926 m_parent->signalAPIResult(&result);
927 }
928 break;
929 case QCAMERA_SM_EVT_TAKE_PICTURE:
930 {
931 rc = m_parent->takePicture();
932 if (rc == NO_ERROR) {
933 // move state to picture taking state
934 m_state = QCAMERA_SM_STATE_PIC_TAKING;
935 } else {
936 // move state to preview stopped state
937 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
938 }
939 result.status = rc;
940 result.request_api = evt;
941 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
942 m_parent->signalAPIResult(&result);
943 }
944 break;
945 case QCAMERA_SM_EVT_SEND_COMMAND:
946 {
947 qcamera_sm_evt_command_payload_t *cmd_payload =
948 (qcamera_sm_evt_command_payload_t *)payload;
949 rc = m_parent->sendCommand(cmd_payload->cmd,
950 cmd_payload->arg1,
951 cmd_payload->arg2);
952 result.status = rc;
953 result.request_api = evt;
954 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
955 m_parent->signalAPIResult(&result);
956 }
957 break;
958 case QCAMERA_SM_EVT_CANCEL_PICTURE:
959 case QCAMERA_SM_EVT_STOP_RECORDING:
960 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
961 case QCAMERA_SM_EVT_RELEASE:
962 {
963 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
964 rc = INVALID_OPERATION;
965 result.status = rc;
966 result.request_api = evt;
967 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
968 m_parent->signalAPIResult(&result);
969 }
970 break;
971 case QCAMERA_SM_EVT_EVT_NOTIFY:
972 {
973 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
974 switch (cam_evt->server_event_type) {
975 case CAM_EVENT_TYPE_AUTO_FOCUS_DONE:
976 rc = m_parent->processAutoFocusEvent(cam_evt->status);
977 break;
978 case CAM_EVENT_TYPE_ZOOM_DONE:
979 rc = m_parent->processZoomEvent(cam_evt->status);
980 break;
981 default:
982 ALOGD("%s: no handling for server evt (%d) at this state",
983 __func__, cam_evt->server_event_type);
984 break;
985 }
986 }
987 break;
988 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
Muhua Lida2c4be2012-11-26 09:14:16 -0800989 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
Muhua Libc9a8082012-11-07 15:51:28 -0800990 default:
991 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
992 break;
993 }
994
995 return rc;
996}
997
Muhua Lida2c4be2012-11-26 09:14:16 -0800998/*===========================================================================
999 * FUNCTION : procEvtPicTakingState
1000 *
1001 * DESCRIPTION: finite state machine function to handle event in state of
1002 * QCAMERA_SM_STATE_PIC_TAKING.
1003 *
1004 * PARAMETERS :
1005 * @evt : event to be processed
1006 * @payload : event payload. Can be NULL if not needed.
1007 *
1008 * RETURN : int32_t type of status
1009 * NO_ERROR -- success
1010 * none-zero failure code
1011 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -08001012int32_t QCameraStateMachine::procEvtPicTakingState(qcamera_sm_evt_enum_t evt,
1013 void *payload)
1014{
1015 int32_t rc = NO_ERROR;
1016 qcamera_api_result_t result;
1017 memset(&result, 0, sizeof(qcamera_api_result_t));
1018
1019 switch (evt) {
1020 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
1021 {
1022 // Error setting preview window during previewing
1023 ALOGE("Cannot set preview window when preview is running");
1024 rc = INVALID_OPERATION;
1025 result.status = rc;
1026 result.request_api = evt;
1027 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1028 m_parent->signalAPIResult(&result);
1029 }
1030 break;
1031 case QCAMERA_SM_EVT_SET_CALLBACKS:
1032 {
1033 qcamera_sm_evt_setcb_payload_t *setcbs =
1034 (qcamera_sm_evt_setcb_payload_t *)payload;
1035 rc = m_parent->setCallBacks(setcbs->notify_cb,
1036 setcbs->data_cb,
1037 setcbs->data_cb_timestamp,
1038 setcbs->get_memory,
1039 setcbs->user);
1040 result.status = rc;
1041 result.request_api = evt;
1042 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1043 m_parent->signalAPIResult(&result);
1044 }
1045 break;
1046 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
1047 {
1048 rc = m_parent->enableMsgType(int32_t(payload));
1049 result.status = rc;
1050 result.request_api = evt;
1051 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1052 m_parent->signalAPIResult(&result);
1053 }
1054 break;
1055 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
1056 {
1057 rc = m_parent->disableMsgType(int32_t(payload));
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_MSG_TYPE_ENABLED:
1065 {
1066 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
1067 result.status = rc;
1068 result.request_api = evt;
1069 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1070 result.enabled = enabled;
1071 m_parent->signalAPIResult(&result);
1072 }
1073 break;
1074 case QCAMERA_SM_EVT_SET_PARAMS:
1075 {
Muhua Lida2c4be2012-11-26 09:14:16 -08001076 bool needRestart = false;
1077 rc = m_parent->updateParameters((char*)payload, needRestart);
1078 if (rc == NO_ERROR) {
1079 rc = m_parent->commitParameterChanges();
1080 }
Muhua Libc9a8082012-11-07 15:51:28 -08001081 result.status = rc;
1082 result.request_api = evt;
1083 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1084 m_parent->signalAPIResult(&result);
1085 }
1086 break;
1087 case QCAMERA_SM_EVT_GET_PARAMS:
1088 {
1089 result.params = m_parent->getParameters();
1090 rc = NO_ERROR;
1091 result.status = rc;
1092 result.request_api = evt;
1093 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
1094 m_parent->signalAPIResult(&result);
1095 }
1096 break;
1097 case QCAMERA_SM_EVT_PUT_PARAMS:
1098 {
1099 rc = m_parent->putParameters((char*)payload);
1100 result.status = rc;
1101 result.request_api = evt;
1102 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1103 m_parent->signalAPIResult(&result);
1104 }
1105 break;
1106 case QCAMERA_SM_EVT_STOP_PREVIEW:
1107 {
1108 // no ops, since preview is stopped (normal),
1109 // or preview msg type is disabled (ZSL)
1110 rc = NO_ERROR;
1111 result.status = rc;
1112 result.request_api = evt;
1113 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1114 m_parent->signalAPIResult(&result);
1115 }
1116 break;
1117 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
1118 {
1119 rc = NO_ERROR;
1120 result.status = rc;
1121 result.request_api = evt;
1122 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1123 result.enabled = 0;
1124 m_parent->signalAPIResult(&result);
1125 }
1126 break;
1127 case QCAMERA_SM_EVT_RECORDING_ENABLED:
1128 {
1129 rc = NO_ERROR;
1130 result.status = rc;
1131 result.request_api = evt;
1132 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1133 result.enabled = 0;
1134 m_parent->signalAPIResult(&result);
1135 }
1136 break;
1137 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
1138 {
1139 rc = m_parent->storeMetaDataInBuffers(int(payload));
1140 result.status = rc;
1141 result.request_api = evt;
1142 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1143 m_parent->signalAPIResult(&result);
1144 }
1145 break;
1146 case QCAMERA_SM_EVT_DUMP:
1147 {
1148 rc = m_parent->dump((int)payload);
1149 result.status = rc;
1150 result.request_api = evt;
1151 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1152 m_parent->signalAPIResult(&result);
1153 }
1154 break;
1155 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
1156 {
1157 rc = m_parent->autoFocus();
1158 result.status = rc;
1159 result.request_api = evt;
1160 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1161 m_parent->signalAPIResult(&result);
1162 }
1163 break;
1164 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
1165 {
1166 rc = m_parent->cancelAutoFocus();
1167 result.status = rc;
1168 result.request_api = evt;
1169 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1170 m_parent->signalAPIResult(&result);
1171 }
1172 break;
1173 case QCAMERA_SM_EVT_SEND_COMMAND:
1174 {
1175 qcamera_sm_evt_command_payload_t *cmd_payload =
1176 (qcamera_sm_evt_command_payload_t *)payload;
1177 rc = m_parent->sendCommand(cmd_payload->cmd,
1178 cmd_payload->arg1,
1179 cmd_payload->arg2);
1180 result.status = rc;
1181 result.request_api = evt;
1182 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1183 m_parent->signalAPIResult(&result);
1184 }
1185 break;
1186 case QCAMERA_SM_EVT_CANCEL_PICTURE:
1187 {
1188 rc = m_parent->cancelPicture();
1189 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
1190 result.status = rc;
1191 result.request_api = evt;
1192 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1193 m_parent->signalAPIResult(&result);
1194 }
1195 break;
1196 case QCAMERA_SM_EVT_TAKE_PICTURE:
1197 case QCAMERA_SM_EVT_START_RECORDING:
1198 case QCAMERA_SM_EVT_STOP_RECORDING:
1199 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
1200 case QCAMERA_SM_EVT_START_PREVIEW:
1201 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
1202 case QCAMERA_SM_EVT_RELEASE:
1203 {
1204 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1205 rc = INVALID_OPERATION;
1206 result.status = rc;
1207 result.request_api = evt;
1208 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1209 m_parent->signalAPIResult(&result);
1210 }
1211 break;
1212 case QCAMERA_SM_EVT_EVT_NOTIFY:
1213 {
1214 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
1215 switch (cam_evt->server_event_type) {
1216 case CAM_EVENT_TYPE_AUTO_FOCUS_DONE:
1217 rc = m_parent->processAutoFocusEvent(cam_evt->status);
1218 break;
1219 case CAM_EVENT_TYPE_ZOOM_DONE:
1220 rc = m_parent->processZoomEvent(cam_evt->status);
1221 break;
1222 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;
1229 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
1230 {
1231 qcamera_jpeg_evt_payload_t *jpeg_job =
1232 (qcamera_jpeg_evt_payload_t *)payload;
1233 rc = m_parent->processJpegNotify(jpeg_job);
1234 }
1235 break;
1236 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
1237 {
1238 rc = m_parent->cancelPicture();
1239 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
1240 }
1241 break;
1242 default:
1243 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1244 break;
1245 }
1246
1247 return rc;
1248}
1249
Muhua Lida2c4be2012-11-26 09:14:16 -08001250/*===========================================================================
1251 * FUNCTION : procEvtRecordingState
1252 *
1253 * DESCRIPTION: finite state machine function to handle event in state of
1254 * QCAMERA_SM_STATE_RECORDING.
1255 *
1256 * PARAMETERS :
1257 * @evt : event to be processed
1258 * @payload : event payload. Can be NULL if not needed.
1259 *
1260 * RETURN : int32_t type of status
1261 * NO_ERROR -- success
1262 * none-zero failure code
1263 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -08001264int32_t QCameraStateMachine::procEvtRecordingState(qcamera_sm_evt_enum_t evt,
1265 void *payload)
1266{
1267 int32_t rc = NO_ERROR;
1268 qcamera_api_result_t result;
1269 memset(&result, 0, sizeof(qcamera_api_result_t));
1270
1271 switch (evt) {
1272 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
1273 {
1274 // Error setting preview window during previewing
1275 ALOGE("Cannot set preview window when preview is running");
1276 rc = INVALID_OPERATION;
1277 result.status = rc;
1278 result.request_api = evt;
1279 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1280 m_parent->signalAPIResult(&result);
1281 }
1282 break;
1283 case QCAMERA_SM_EVT_SET_CALLBACKS:
1284 {
1285 qcamera_sm_evt_setcb_payload_t *setcbs =
1286 (qcamera_sm_evt_setcb_payload_t *)payload;
1287 rc = m_parent->setCallBacks(setcbs->notify_cb,
1288 setcbs->data_cb,
1289 setcbs->data_cb_timestamp,
1290 setcbs->get_memory,
1291 setcbs->user);
1292 result.status = rc;
1293 result.request_api = evt;
1294 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1295 m_parent->signalAPIResult(&result);
1296 }
1297 break;
1298 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
1299 {
1300 rc = m_parent->enableMsgType(int32_t(payload));
1301 result.status = rc;
1302 result.request_api = evt;
1303 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1304 m_parent->signalAPIResult(&result);
1305 }
1306 break;
1307 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
1308 {
1309 rc = m_parent->disableMsgType(int32_t(payload));
1310 result.status = rc;
1311 result.request_api = evt;
1312 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1313 m_parent->signalAPIResult(&result);
1314 }
1315 break;
1316 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
1317 {
1318 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
1319 result.status = rc;
1320 result.request_api = evt;
1321 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1322 result.enabled = enabled;
1323 m_parent->signalAPIResult(&result);
1324 }
1325 break;
1326 case QCAMERA_SM_EVT_SET_PARAMS:
1327 {
Muhua Lida2c4be2012-11-26 09:14:16 -08001328 bool needRestart = false;
1329 rc = m_parent->updateParameters((char*)payload, needRestart);
1330 if (rc == NO_ERROR) {
1331 if (needRestart) {
1332 // cannot set parameters that requires restart during recording
1333 ALOGE("%s: Cannot set parameters that requires restart during recording",
1334 __func__);
1335 rc = BAD_VALUE;
1336 } else {
1337 rc = m_parent->commitParameterChanges();
1338 }
1339 }
Muhua Libc9a8082012-11-07 15:51:28 -08001340 result.status = rc;
1341 result.request_api = evt;
1342 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1343 m_parent->signalAPIResult(&result);
1344 }
1345 break;
1346 case QCAMERA_SM_EVT_GET_PARAMS:
1347 {
1348 result.params = m_parent->getParameters();
1349 rc = NO_ERROR;
1350 result.status = rc;
1351 result.request_api = evt;
1352 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
1353 m_parent->signalAPIResult(&result);
1354 }
1355 break;
1356 case QCAMERA_SM_EVT_PUT_PARAMS:
1357 {
1358 rc = m_parent->putParameters((char*)payload);
1359 result.status = rc;
1360 result.request_api = evt;
1361 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1362 m_parent->signalAPIResult(&result);
1363 }
1364 break;
1365 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
1366 {
1367 rc = NO_ERROR;
1368 result.status = rc;
1369 result.request_api = evt;
1370 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1371 result.enabled = 0;
1372 m_parent->signalAPIResult(&result);
1373 }
1374 break;
1375 case QCAMERA_SM_EVT_RECORDING_ENABLED:
1376 {
1377 rc = NO_ERROR;
1378 result.status = rc;
1379 result.request_api = evt;
1380 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1381 result.enabled = 1;
1382 m_parent->signalAPIResult(&result);
1383 }
1384 break;
1385 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
1386 {
1387 rc = m_parent->storeMetaDataInBuffers(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_DUMP:
1395 {
1396 rc = m_parent->dump((int)payload);
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_START_AUTO_FOCUS:
1404 {
1405 rc = m_parent->autoFocus();
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_STOP_AUTO_FOCUS:
1413 {
1414 rc = m_parent->cancelAutoFocus();
1415 result.status = rc;
1416 result.request_api = evt;
1417 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1418 m_parent->signalAPIResult(&result);
1419 }
1420 break;
1421 case QCAMERA_SM_EVT_SEND_COMMAND:
1422 {
1423 qcamera_sm_evt_command_payload_t *cmd_payload =
1424 (qcamera_sm_evt_command_payload_t *)payload;
1425 rc = m_parent->sendCommand(cmd_payload->cmd,
1426 cmd_payload->arg1,
1427 cmd_payload->arg2);
1428 result.status = rc;
1429 result.request_api = evt;
1430 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1431 m_parent->signalAPIResult(&result);
1432 }
1433 break;
1434 case QCAMERA_SM_EVT_TAKE_PICTURE:
1435 {
1436 rc = m_parent->takeLiveSnapshot();
1437 if (rc == 0) {
1438 m_state = QCAMERA_SM_STATE_VIDEO_PIC_TAKING;
1439 }
1440 result.status = rc;
1441 result.request_api = evt;
1442 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1443 m_parent->signalAPIResult(&result);
1444 }
1445 break;
1446 case QCAMERA_SM_EVT_START_RECORDING:
1447 {
1448 // no ops here
1449 ALOGD("%s: already in recording state, no ops for start_recording", __func__);
1450 rc = 0;
1451 result.status = rc;
1452 result.request_api = evt;
1453 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1454 m_parent->signalAPIResult(&result);
1455 }
1456 break;
1457 case QCAMERA_SM_EVT_STOP_RECORDING:
1458 {
1459 rc = m_parent->stopRecording();
1460 m_state = QCAMERA_SM_STATE_PREVIEWING;
1461 result.status = rc;
1462 result.request_api = evt;
1463 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1464 m_parent->signalAPIResult(&result);
1465 }
1466 break;
1467 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
1468 {
1469 rc = m_parent->releaseRecordingFrame((const void *)payload);
1470 result.status = rc;
1471 result.request_api = evt;
1472 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1473 m_parent->signalAPIResult(&result);
1474 }
1475 break;
1476 case QCAMERA_SM_EVT_CANCEL_PICTURE:
1477 case QCAMERA_SM_EVT_START_PREVIEW:
1478 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
1479 case QCAMERA_SM_EVT_STOP_PREVIEW:
1480 case QCAMERA_SM_EVT_RELEASE:
1481 {
1482 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1483 rc = INVALID_OPERATION;
1484 result.status = rc;
1485 result.request_api = evt;
1486 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1487 m_parent->signalAPIResult(&result);
1488 }
1489 break;
1490 case QCAMERA_SM_EVT_EVT_NOTIFY:
1491 {
1492 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
1493 switch (cam_evt->server_event_type) {
1494 case CAM_EVENT_TYPE_AUTO_FOCUS_DONE:
1495 rc = m_parent->processAutoFocusEvent(cam_evt->status);
1496 break;
1497 case CAM_EVENT_TYPE_ZOOM_DONE:
1498 rc = m_parent->processZoomEvent(cam_evt->status);
1499 break;
1500 default:
1501 ALOGD("%s: no handling for server evt (%d) at this state",
1502 __func__, cam_evt->server_event_type);
1503 break;
1504 }
1505 }
1506 break;
1507 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
Muhua Lida2c4be2012-11-26 09:14:16 -08001508 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
Muhua Libc9a8082012-11-07 15:51:28 -08001509 default:
1510 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1511 break;
1512 }
1513
1514 return rc;
1515}
1516
Muhua Lida2c4be2012-11-26 09:14:16 -08001517/*===========================================================================
1518 * FUNCTION : procEvtVideoPicTakingState
1519 *
1520 * DESCRIPTION: finite state machine function to handle event in state of
1521 * QCAMERA_SM_STATE_VIDEO_PIC_TAKING.
1522 *
1523 * PARAMETERS :
1524 * @evt : event to be processed
1525 * @payload : event payload. Can be NULL if not needed.
1526 *
1527 * RETURN : int32_t type of status
1528 * NO_ERROR -- success
1529 * none-zero failure code
1530 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -08001531int32_t QCameraStateMachine::procEvtVideoPicTakingState(qcamera_sm_evt_enum_t evt,
1532 void *payload)
1533{
1534 int32_t rc = NO_ERROR;
1535 qcamera_api_result_t result;
1536 memset(&result, 0, sizeof(qcamera_api_result_t));
1537
1538 switch (evt) {
1539 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
1540 {
1541 // Error setting preview window during previewing
1542 ALOGE("Cannot set preview window when preview is running");
1543 rc = INVALID_OPERATION;
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_SET_CALLBACKS:
1551 {
1552 qcamera_sm_evt_setcb_payload_t *setcbs =
1553 (qcamera_sm_evt_setcb_payload_t *)payload;
1554 rc = m_parent->setCallBacks(setcbs->notify_cb,
1555 setcbs->data_cb,
1556 setcbs->data_cb_timestamp,
1557 setcbs->get_memory,
1558 setcbs->user);
1559 result.status = rc;
1560 result.request_api = evt;
1561 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1562 m_parent->signalAPIResult(&result);
1563 }
1564 break;
1565 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
1566 {
1567 rc = m_parent->enableMsgType(int32_t(payload));
1568 result.status = rc;
1569 result.request_api = evt;
1570 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1571 m_parent->signalAPIResult(&result);
1572 }
1573 break;
1574 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
1575 {
1576 rc = m_parent->disableMsgType(int32_t(payload));
1577 result.status = rc;
1578 result.request_api = evt;
1579 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1580 m_parent->signalAPIResult(&result);
1581 }
1582 break;
1583 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
1584 {
1585 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
1586 result.status = rc;
1587 result.request_api = evt;
1588 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1589 result.enabled = enabled;
1590 m_parent->signalAPIResult(&result);
1591 }
1592 break;
1593 case QCAMERA_SM_EVT_SET_PARAMS:
1594 {
Muhua Lida2c4be2012-11-26 09:14:16 -08001595 bool needRestart = false;
1596 rc = m_parent->updateParameters((char*)payload, needRestart);
1597 if (rc == NO_ERROR) {
1598 if (needRestart) {
1599 // cannot set parameters that requires restart during recording
1600 ALOGE("%s: Cannot set parameters that requires restart during recording",
1601 __func__);
1602 rc = BAD_VALUE;
1603 } else {
1604 rc = m_parent->commitParameterChanges();
1605 }
1606 }
Muhua Libc9a8082012-11-07 15:51:28 -08001607 result.status = rc;
1608 result.request_api = evt;
1609 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1610 m_parent->signalAPIResult(&result);
1611 }
1612 break;
1613 case QCAMERA_SM_EVT_GET_PARAMS:
1614 {
1615 result.params = m_parent->getParameters();
1616 rc = NO_ERROR;
1617 result.status = rc;
1618 result.request_api = evt;
1619 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
1620 m_parent->signalAPIResult(&result);
1621 }
1622 break;
1623 case QCAMERA_SM_EVT_PUT_PARAMS:
1624 {
1625 rc = m_parent->putParameters((char*)payload);
1626 result.status = rc;
1627 result.request_api = evt;
1628 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1629 m_parent->signalAPIResult(&result);
1630 }
1631 break;
1632 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
1633 {
1634 rc = NO_ERROR;
1635 result.status = rc;
1636 result.request_api = evt;
1637 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1638 result.enabled = 1;
1639 m_parent->signalAPIResult(&result);
1640 }
1641 break;
1642 case QCAMERA_SM_EVT_RECORDING_ENABLED:
1643 {
1644 rc = NO_ERROR;
1645 result.status = rc;
1646 result.request_api = evt;
1647 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1648 result.enabled = 1;
1649 m_parent->signalAPIResult(&result);
1650 }
1651 break;
1652 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
1653 {
1654 rc = m_parent->storeMetaDataInBuffers(int(payload));
1655 result.status = rc;
1656 result.request_api = evt;
1657 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1658 m_parent->signalAPIResult(&result);
1659 }
1660 break;
1661 case QCAMERA_SM_EVT_DUMP:
1662 {
1663 rc = m_parent->dump((int)payload);
1664 result.status = rc;
1665 result.request_api = evt;
1666 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1667 m_parent->signalAPIResult(&result);
1668 }
1669 break;
1670 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
1671 {
1672 rc = m_parent->autoFocus();
1673 result.status = rc;
1674 result.request_api = evt;
1675 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1676 m_parent->signalAPIResult(&result);
1677 }
1678 break;
1679 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
1680 {
1681 rc = m_parent->cancelAutoFocus();
1682 result.status = rc;
1683 result.request_api = evt;
1684 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1685 m_parent->signalAPIResult(&result);
1686 }
1687 break;
1688 case QCAMERA_SM_EVT_SEND_COMMAND:
1689 {
1690 qcamera_sm_evt_command_payload_t *cmd_payload =
1691 (qcamera_sm_evt_command_payload_t *)payload;
1692 rc = m_parent->sendCommand(cmd_payload->cmd,
1693 cmd_payload->arg1,
1694 cmd_payload->arg2);
1695 result.status = rc;
1696 result.request_api = evt;
1697 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1698 m_parent->signalAPIResult(&result);
1699 }
1700 break;
1701 case QCAMERA_SM_EVT_STOP_RECORDING:
1702 {
1703 rc = m_parent->stopRecording();
1704 m_state = QCAMERA_SM_STATE_PREVIEW_PIC_TAKING;
1705 result.status = rc;
1706 result.request_api = evt;
1707 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1708 m_parent->signalAPIResult(&result);
1709 }
1710 break;
1711 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
1712 {
1713 rc = m_parent->releaseRecordingFrame((const void *)payload);
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_CANCEL_PICTURE:
1721 {
1722 rc = m_parent->cancelLiveSnapshot();
1723 m_state = QCAMERA_SM_STATE_RECORDING;
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_START_RECORDING:
1731 case QCAMERA_SM_EVT_START_PREVIEW:
1732 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
1733 case QCAMERA_SM_EVT_STOP_PREVIEW:
1734 case QCAMERA_SM_EVT_TAKE_PICTURE:
1735 case QCAMERA_SM_EVT_RELEASE:
1736 {
1737 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1738 rc = INVALID_OPERATION;
1739 result.status = rc;
1740 result.request_api = evt;
1741 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1742 m_parent->signalAPIResult(&result);
1743 }
1744 break;
1745 case QCAMERA_SM_EVT_EVT_NOTIFY:
1746 {
1747 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
1748 switch (cam_evt->server_event_type) {
1749 case CAM_EVENT_TYPE_AUTO_FOCUS_DONE:
1750 rc = m_parent->processAutoFocusEvent(cam_evt->status);
1751 break;
1752 case CAM_EVENT_TYPE_ZOOM_DONE:
1753 rc = m_parent->processZoomEvent(cam_evt->status);
1754 break;
1755 default:
1756 ALOGD("%s: no handling for server evt (%d) at this state",
1757 __func__, cam_evt->server_event_type);
1758 break;
1759 }
1760 }
1761 break;
1762 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
1763 {
1764 qcamera_jpeg_evt_payload_t *jpeg_job =
1765 (qcamera_jpeg_evt_payload_t *)payload;
1766 rc = m_parent->processJpegNotify(jpeg_job);
1767 }
1768 break;
1769 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
1770 {
1771 rc = m_parent->cancelLiveSnapshot();
1772 m_state = QCAMERA_SM_STATE_RECORDING;
1773 }
1774 break;
1775 default:
1776 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1777 break;
1778 }
1779
1780 return rc;
1781}
1782
Muhua Lida2c4be2012-11-26 09:14:16 -08001783/*===========================================================================
1784 * FUNCTION : procEvtPreviewPicTakingState
1785 *
1786 * DESCRIPTION: finite state machine function to handle event in state of
1787 * QCAMERA_SM_STATE_PREVIEW_PIC_TAKING.
1788 *
1789 * PARAMETERS :
1790 * @evt : event to be processed
1791 * @payload : event payload. Can be NULL if not needed.
1792 *
1793 * RETURN : int32_t type of status
1794 * NO_ERROR -- success
1795 * none-zero failure code
1796 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -08001797int32_t QCameraStateMachine::procEvtPreviewPicTakingState(qcamera_sm_evt_enum_t evt,
1798 void *payload)
1799{
1800 int32_t rc = NO_ERROR;
1801 qcamera_api_result_t result;
1802 memset(&result, 0, sizeof(qcamera_api_result_t));
1803
1804 switch (evt) {
1805 case QCAMERA_SM_EVT_SET_CALLBACKS:
1806 {
1807 qcamera_sm_evt_setcb_payload_t *setcbs =
1808 (qcamera_sm_evt_setcb_payload_t *)payload;
1809 rc = m_parent->setCallBacks(setcbs->notify_cb,
1810 setcbs->data_cb,
1811 setcbs->data_cb_timestamp,
1812 setcbs->get_memory,
1813 setcbs->user);
1814 result.status = rc;
1815 result.request_api = evt;
1816 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1817 m_parent->signalAPIResult(&result);
1818 }
1819 break;
1820 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
1821 {
1822 rc = m_parent->enableMsgType(int32_t(payload));
1823 result.status = rc;
1824 result.request_api = evt;
1825 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1826 m_parent->signalAPIResult(&result);
1827 }
1828 break;
1829 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
1830 {
1831 rc = m_parent->disableMsgType(int32_t(payload));
1832 result.status = rc;
1833 result.request_api = evt;
1834 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1835 m_parent->signalAPIResult(&result);
1836 }
1837 break;
1838 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
1839 {
1840 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
1841 result.status = rc;
1842 result.request_api = evt;
1843 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1844 result.enabled = enabled;
1845 m_parent->signalAPIResult(&result);
1846 }
1847 break;
1848 case QCAMERA_SM_EVT_SET_PARAMS:
1849 {
Muhua Lida2c4be2012-11-26 09:14:16 -08001850 bool needRestart = false;
1851 rc = m_parent->updateParameters((char*)payload, needRestart);
1852 if (rc == NO_ERROR) {
1853 if (needRestart) {
1854 // need restart preview for parameters to take effect
1855 // stop preview
1856 m_parent->stopPreview();
1857 // commit parameter changes to server
1858 rc = m_parent->commitParameterChanges();
1859 // start preview again
1860 m_parent->startPreview();
1861 } else {
1862 rc = m_parent->commitParameterChanges();
1863 }
1864 }
Muhua Libc9a8082012-11-07 15:51:28 -08001865 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_GET_PARAMS:
1872 {
1873 result.params = m_parent->getParameters();
1874 rc = NO_ERROR;
1875 result.status = rc;
1876 result.request_api = evt;
1877 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
1878 m_parent->signalAPIResult(&result);
1879 }
1880 break;
1881 case QCAMERA_SM_EVT_PUT_PARAMS:
1882 {
1883 rc = m_parent->putParameters((char*)payload);
1884 result.status = rc;
1885 result.request_api = evt;
1886 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1887 m_parent->signalAPIResult(&result);
1888 }
1889 break;
1890 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
1891 {
1892 rc = NO_ERROR;
1893 result.status = rc;
1894 result.request_api = evt;
1895 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1896 result.enabled = 1;
1897 m_parent->signalAPIResult(&result);
1898 }
1899 break;
1900 case QCAMERA_SM_EVT_RECORDING_ENABLED:
1901 {
1902 rc = NO_ERROR;
1903 result.status = rc;
1904 result.request_api = evt;
1905 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1906 result.enabled = 0;
1907 m_parent->signalAPIResult(&result);
1908 }
1909 break;
1910 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
1911 {
1912 rc = m_parent->storeMetaDataInBuffers(int(payload));
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;
1919 case QCAMERA_SM_EVT_DUMP:
1920 {
1921 rc = m_parent->dump((int)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;
1928 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
1929 {
1930 rc = m_parent->autoFocus();
1931 result.status = rc;
1932 result.request_api = evt;
1933 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1934 m_parent->signalAPIResult(&result);
1935 }
1936 break;
1937 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
1938 {
1939 rc = m_parent->cancelAutoFocus();
1940 result.status = rc;
1941 result.request_api = evt;
1942 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1943 m_parent->signalAPIResult(&result);
1944 }
1945 break;
1946 case QCAMERA_SM_EVT_SEND_COMMAND:
1947 {
1948 qcamera_sm_evt_command_payload_t *cmd_payload =
1949 (qcamera_sm_evt_command_payload_t *)payload;
1950 rc = m_parent->sendCommand(cmd_payload->cmd,
1951 cmd_payload->arg1,
1952 cmd_payload->arg2);
1953 result.status = rc;
1954 result.request_api = evt;
1955 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1956 m_parent->signalAPIResult(&result);
1957 }
1958 break;
1959 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
1960 {
1961 rc = m_parent->releaseRecordingFrame((const void *)payload);
1962 result.status = rc;
1963 result.request_api = evt;
1964 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1965 m_parent->signalAPIResult(&result);
1966 }
1967 break;
1968 case QCAMERA_SM_EVT_CANCEL_PICTURE:
1969 {
1970 rc = m_parent->cancelLiveSnapshot();
1971 m_state = QCAMERA_SM_STATE_PREVIEWING;
1972 result.status = rc;
1973 result.request_api = evt;
1974 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1975 m_parent->signalAPIResult(&result);
1976 }
1977 break;
1978 case QCAMERA_SM_EVT_STOP_PREVIEW:
1979 {
1980 m_parent->stopChannel(QCAMERA_CH_TYPE_PREVIEW);
1981 m_parent->delChannel(QCAMERA_CH_TYPE_PREVIEW);
1982 m_parent->delChannel(QCAMERA_CH_TYPE_VIDEO);
1983 m_state = QCAMERA_SM_STATE_PIC_TAKING;
1984 rc = NO_ERROR;
1985 result.status = rc;
1986 result.request_api = evt;
1987 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1988 m_parent->signalAPIResult(&result);
1989 }
1990 break;
1991 case QCAMERA_SM_EVT_START_RECORDING:
1992 {
1993 rc = m_parent->stopRecording();
1994 if (rc == NO_ERROR) {
1995 m_state = QCAMERA_SM_STATE_VIDEO_PIC_TAKING;
1996 }
1997 result.status = rc;
1998 result.request_api = evt;
1999 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2000 m_parent->signalAPIResult(&result);
2001 }
2002 break;
2003 case QCAMERA_SM_EVT_STOP_RECORDING:
2004 case QCAMERA_SM_EVT_START_PREVIEW:
2005 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
2006 case QCAMERA_SM_EVT_TAKE_PICTURE:
2007 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
2008 case QCAMERA_SM_EVT_RELEASE:
2009 {
2010 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
2011 rc = INVALID_OPERATION;
2012 result.status = rc;
2013 result.request_api = evt;
2014 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2015 m_parent->signalAPIResult(&result);
2016 }
2017 break;
2018 case QCAMERA_SM_EVT_EVT_NOTIFY:
2019 {
2020 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
2021 switch (cam_evt->server_event_type) {
2022 case CAM_EVENT_TYPE_AUTO_FOCUS_DONE:
2023 rc = m_parent->processAutoFocusEvent(cam_evt->status);
2024 break;
2025 case CAM_EVENT_TYPE_ZOOM_DONE:
2026 rc = m_parent->processZoomEvent(cam_evt->status);
2027 break;
2028 default:
2029 ALOGD("%s: no handling for server evt (%d) at this state",
2030 __func__, cam_evt->server_event_type);
2031 break;
2032 }
2033 }
2034 break;
2035 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
2036 {
2037 qcamera_jpeg_evt_payload_t *jpeg_job =
2038 (qcamera_jpeg_evt_payload_t *)payload;
2039 rc = m_parent->processJpegNotify(jpeg_job);
2040 }
2041 break;
2042 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
2043 {
2044 rc = m_parent->cancelLiveSnapshot();
2045 m_state = QCAMERA_SM_STATE_PREVIEWING;
2046 }
2047 break;
2048 default:
2049 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
2050 break;
2051 }
2052
2053 return rc;
2054}
2055
Muhua Lida2c4be2012-11-26 09:14:16 -08002056/*===========================================================================
2057 * FUNCTION : isPreviewRunning
2058 *
2059 * DESCRIPTION: check if preview is in process.
2060 *
2061 * PARAMETERS : None
2062 *
2063 * RETURN : true -- preview running
2064 * false -- preview stopped
2065 *==========================================================================*/
2066bool QCameraStateMachine::isPreviewRunning()
2067{
2068 switch (m_state) {
2069 case QCAMERA_SM_STATE_PREVIEWING:
2070 case QCAMERA_SM_STATE_RECORDING:
2071 case QCAMERA_SM_STATE_VIDEO_PIC_TAKING:
2072 case QCAMERA_SM_STATE_PREVIEW_PIC_TAKING:
2073 return true;
2074 default:
2075 return false;
2076 }
2077}
2078
Muhua Libc9a8082012-11-07 15:51:28 -08002079}; // namespace android