blob: 8bc0ede837daf9fad38b9e60908c47580ed5a252 [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;
256 case QCAMERA_SM_STATE_PIC_TAKING:
257 rc = procEvtPicTakingState(evt, payload);
258 break;
259 case QCAMERA_SM_STATE_RECORDING:
260 rc = procEvtRecordingState(evt, payload);
261 break;
262 case QCAMERA_SM_STATE_VIDEO_PIC_TAKING:
263 rc = procEvtVideoPicTakingState(evt, payload);
264 break;
265 case QCAMERA_SM_STATE_PREVIEW_PIC_TAKING:
266 rc = procEvtPreviewPicTakingState(evt, payload);
267 break;
268 default:
269 break;
270 }
271
272 return rc;
273}
274
Muhua Lida2c4be2012-11-26 09:14:16 -0800275/*===========================================================================
276 * FUNCTION : procEvtPreviewStoppedState
277 *
278 * DESCRIPTION: finite state machine function to handle event in state of
279 * QCAMERA_SM_STATE_PREVIEW_STOPPED.
280 *
281 * PARAMETERS :
282 * @evt : event to be processed
283 * @payload : event payload. Can be NULL if not needed.
284 *
285 * RETURN : int32_t type of status
286 * NO_ERROR -- success
287 * none-zero failure code
288 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800289int32_t QCameraStateMachine::procEvtPreviewStoppedState(qcamera_sm_evt_enum_t evt,
290 void *payload)
291{
292 int32_t rc = NO_ERROR;
293 qcamera_api_result_t result;
294 memset(&result, 0, sizeof(qcamera_api_result_t));
295
296 switch (evt) {
297 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
298 {
299 rc = m_parent->setPreviewWindow((struct preview_stream_ops *)payload);
300 result.status = rc;
301 result.request_api = evt;
302 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
303 m_parent->signalAPIResult(&result);
304 }
305 break;
306 case QCAMERA_SM_EVT_SET_CALLBACKS:
307 {
308 qcamera_sm_evt_setcb_payload_t *setcbs =
309 (qcamera_sm_evt_setcb_payload_t *)payload;
310 rc = m_parent->setCallBacks(setcbs->notify_cb,
311 setcbs->data_cb,
312 setcbs->data_cb_timestamp,
313 setcbs->get_memory,
314 setcbs->user);
315 result.status = rc;
316 result.request_api = evt;
317 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
318 m_parent->signalAPIResult(&result);
319 }
320 break;
321 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
322 {
323 rc = m_parent->enableMsgType(int32_t(payload));
324 result.status = rc;
325 result.request_api = evt;
326 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
327 m_parent->signalAPIResult(&result);
328 }
329 break;
330 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
331 {
332 rc = m_parent->disableMsgType(int32_t(payload));
333 result.status = rc;
334 result.request_api = evt;
335 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
336 m_parent->signalAPIResult(&result);
337 }
338 break;
339 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
340 {
341 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
342 result.status = rc;
343 result.request_api = evt;
344 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
345 result.enabled = enabled;
346 m_parent->signalAPIResult(&result);
347 }
348 break;
349 case QCAMERA_SM_EVT_SET_PARAMS:
350 {
Muhua Lida2c4be2012-11-26 09:14:16 -0800351 bool needRestart = false;
352 rc = m_parent->updateParameters((char*)payload, needRestart);
353 if (rc == NO_ERROR) {
354 rc = m_parent->commitParameterChanges();
355 }
Muhua Libc9a8082012-11-07 15:51:28 -0800356 result.status = rc;
357 result.request_api = evt;
358 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
359 m_parent->signalAPIResult(&result);
360 }
361 break;
362 case QCAMERA_SM_EVT_GET_PARAMS:
363 {
364 result.params = m_parent->getParameters();
365 rc = NO_ERROR;
366 result.status = rc;
367 result.request_api = evt;
368 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
369 m_parent->signalAPIResult(&result);
370 }
371 break;
372 case QCAMERA_SM_EVT_PUT_PARAMS:
373 {
374 rc = m_parent->putParameters((char*)payload);
375 result.status = rc;
376 result.request_api = evt;
377 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
378 m_parent->signalAPIResult(&result);
379 }
380 break;
381 case QCAMERA_SM_EVT_START_PREVIEW:
382 {
383 if (m_parent->mPreviewWindow == NULL) {
Mansoor Aftab06c809c2013-01-23 19:44:47 -0800384 rc = m_parent->preparePreview();
385 if(rc == NO_ERROR) {
386 // preview window is not set yet, move to previewReady state
387 m_state = QCAMERA_SM_STATE_PREVIEW_READY;
388 } else {
389 ALOGE("%s: preparePreview failed",__func__);
390 }
Muhua Libc9a8082012-11-07 15:51:28 -0800391 } else {
392 rc = m_parent->preparePreview();
Muhua Lida2c4be2012-11-26 09:14:16 -0800393 if (rc == NO_ERROR) {
Muhua Libc9a8082012-11-07 15:51:28 -0800394 rc = m_parent->startPreview();
Muhua Lida2c4be2012-11-26 09:14:16 -0800395 if (rc != NO_ERROR) {
Muhua Libc9a8082012-11-07 15:51:28 -0800396 m_parent->unpreparePreview();
397 } else {
Muhua Lida2c4be2012-11-26 09:14:16 -0800398 // start preview success, move to previewing state
Muhua Libc9a8082012-11-07 15:51:28 -0800399 m_state = QCAMERA_SM_STATE_PREVIEWING;
400 }
401 }
402 }
403 result.status = rc;
404 result.request_api = evt;
405 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
406 m_parent->signalAPIResult(&result);
407 }
408 break;
409 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
410 {
411 rc = m_parent->preparePreview();
412 if (rc == NO_ERROR) {
413 rc = m_parent->startPreview();
414 if (rc != NO_ERROR) {
415 m_parent->unpreparePreview();
416 } else {
417 m_state = QCAMERA_SM_STATE_PREVIEWING;
418 }
419 }
420 result.status = rc;
421 result.request_api = evt;
422 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
423 m_parent->signalAPIResult(&result);
424 }
425 break;
426 case QCAMERA_SM_EVT_STOP_PREVIEW:
427 {
428 // no op needed here
429 ALOGD("%s: already in preview stopped state, do nothing", __func__);
430 result.status = NO_ERROR;
431 result.request_api = evt;
432 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
433 m_parent->signalAPIResult(&result);
434 }
435 break;
436 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
437 case QCAMERA_SM_EVT_RECORDING_ENABLED:
438 {
439 result.status = NO_ERROR;
440 result.request_api = evt;
441 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
442 result.enabled = 0;
443 m_parent->signalAPIResult(&result);
444 }
445 break;
446 case QCAMERA_SM_EVT_RELEASE:
447 {
448 rc = m_parent->release();
449 result.status = rc;
450 result.request_api = evt;
451 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
452 m_parent->signalAPIResult(&result);
453 }
454 break;
455 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
456 {
457 rc = m_parent->storeMetaDataInBuffers(int(payload));
458 result.status = rc;
459 result.request_api = evt;
460 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
461 m_parent->signalAPIResult(&result);
462 }
463 break;
464 case QCAMERA_SM_EVT_DUMP:
465 {
466 rc = m_parent->dump((int)payload);
467 result.status = rc;
468 result.request_api = evt;
469 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
470 m_parent->signalAPIResult(&result);
471 }
472 break;
Ankit Premrajka3b00dc62012-12-14 18:37:52 -0800473 case QCAMERA_SM_EVT_SEND_COMMAND:
474 {
475 qcamera_sm_evt_command_payload_t *cmd_payload =
476 (qcamera_sm_evt_command_payload_t *)payload;
477 rc = m_parent->sendCommand(cmd_payload->cmd,
478 cmd_payload->arg1,
479 cmd_payload->arg2);
480 result.status = rc;
481 result.request_api = evt;
482 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
483 m_parent->signalAPIResult(&result);
484 }
485 break;
Muhua Libc9a8082012-11-07 15:51:28 -0800486 case QCAMERA_SM_EVT_START_RECORDING:
487 case QCAMERA_SM_EVT_STOP_RECORDING:
488 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
489 case QCAMERA_SM_EVT_TAKE_PICTURE:
Muhua Libc9a8082012-11-07 15:51:28 -0800490 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
Muhua Libc9a8082012-11-07 15:51:28 -0800491 {
492 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
493 rc = INVALID_OPERATION;
494 result.status = rc;
495 result.request_api = evt;
496 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
497 m_parent->signalAPIResult(&result);
498 }
499 break;
Muhua Li1612f422013-01-03 11:07:39 -0800500 case QCAMERA_SM_EVT_CANCEL_PICTURE:
501 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
502 {
503 // no op needed here
504 ALOGD("%s: No ops for evt(%d) in state(%d)", __func__, evt, m_state);
505 result.status = NO_ERROR;
506 result.request_api = evt;
507 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
508 m_parent->signalAPIResult(&result);
509 }
510 break;
Muhua Li31eaee02012-12-11 08:56:45 -0800511 case QCAMERA_SM_EVT_EVT_INTERNAL:
Muhua Libc9a8082012-11-07 15:51:28 -0800512 case QCAMERA_SM_EVT_EVT_NOTIFY:
513 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
Muhua Lida2c4be2012-11-26 09:14:16 -0800514 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
Shuzhen Wangaa829ce2013-01-09 14:41:49 -0800515 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
Muhua Libc9a8082012-11-07 15:51:28 -0800516 default:
517 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
518 break;
519 }
520
521 return rc;
522}
523
Muhua Lida2c4be2012-11-26 09:14:16 -0800524/*===========================================================================
525 * FUNCTION : procEvtPreviewReadyState
526 *
527 * DESCRIPTION: finite state machine function to handle event in state of
528 * QCAMERA_SM_STATE_PREVIEW_READY.
529 *
530 * PARAMETERS :
531 * @evt : event to be processed
532 * @payload : event payload. Can be NULL if not needed.
533 *
534 * RETURN : int32_t type of status
535 * NO_ERROR -- success
536 * none-zero failure code
537 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800538int32_t QCameraStateMachine::procEvtPreviewReadyState(qcamera_sm_evt_enum_t evt,
539 void *payload)
540{
541 int32_t rc = NO_ERROR;
542 qcamera_api_result_t result;
543 memset(&result, 0, sizeof(qcamera_api_result_t));
544
545 switch (evt) {
546 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
547 {
548 m_parent->setPreviewWindow((struct preview_stream_ops *)payload);
549 if (m_parent->mPreviewWindow != NULL) {
550 rc = m_parent->startPreview();
551 if (rc != NO_ERROR) {
552 m_parent->unpreparePreview();
553 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
554 } else {
555 m_state = QCAMERA_SM_STATE_PREVIEWING;
556 }
557 }
558
559 result.status = rc;
560 result.request_api = evt;
561 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
562 m_parent->signalAPIResult(&result);
563 }
564 break;
565 case QCAMERA_SM_EVT_SET_CALLBACKS:
566 {
567 qcamera_sm_evt_setcb_payload_t *setcbs =
568 (qcamera_sm_evt_setcb_payload_t *)payload;
569 rc = m_parent->setCallBacks(setcbs->notify_cb,
570 setcbs->data_cb,
571 setcbs->data_cb_timestamp,
572 setcbs->get_memory,
573 setcbs->user);
574 result.status = rc;
575 result.request_api = evt;
576 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
577 m_parent->signalAPIResult(&result);
578 }
579 break;
580 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
581 {
582 rc = m_parent->enableMsgType(int32_t(payload));
583 result.status = rc;
584 result.request_api = evt;
585 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
586 m_parent->signalAPIResult(&result);
587 }
588 break;
589 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
590 {
591 rc = m_parent->disableMsgType(int32_t(payload));
592 result.status = rc;
593 result.request_api = evt;
594 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
595 m_parent->signalAPIResult(&result);
596 }
597 break;
598 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
599 {
600 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
601 result.status = rc;
602 result.request_api = evt;
603 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
604 result.enabled = enabled;
605 m_parent->signalAPIResult(&result);
606 }
607 break;
608 case QCAMERA_SM_EVT_SET_PARAMS:
609 {
Muhua Lida2c4be2012-11-26 09:14:16 -0800610 bool needRestart = false;
611 rc = m_parent->updateParameters((char*)payload, needRestart);
612 if (rc == NO_ERROR) {
Muhua Li6d69e932013-01-24 16:39:27 -0800613 if (needRestart) {
614 // need restart preview for parameters to take effect
615 m_parent->unpreparePreview();
616 // commit parameter changes to server
617 m_parent->commitParameterChanges();
618 // prepare preview again
619 rc = m_parent->preparePreview();
620 if (rc != NO_ERROR) {
621 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
622 }
623 } else {
624 rc = m_parent->commitParameterChanges();
625 }
Muhua Lida2c4be2012-11-26 09:14:16 -0800626 }
Muhua Li6d69e932013-01-24 16:39:27 -0800627
Muhua Libc9a8082012-11-07 15:51:28 -0800628 result.status = rc;
629 result.request_api = evt;
630 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
631 m_parent->signalAPIResult(&result);
632 }
633 break;
634 case QCAMERA_SM_EVT_GET_PARAMS:
635 {
636 result.params = m_parent->getParameters();
637 rc = NO_ERROR;
638 result.status = rc;
639 result.request_api = evt;
640 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
641 m_parent->signalAPIResult(&result);
642 }
643 break;
644 case QCAMERA_SM_EVT_PUT_PARAMS:
645 {
646 rc = m_parent->putParameters((char*)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_START_PREVIEW:
654 {
655 // no ops here
656 rc = NO_ERROR;
657 result.status = rc;
658 result.request_api = evt;
659 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
660 m_parent->signalAPIResult(&result);
661 }
662 break;
663 case QCAMERA_SM_EVT_STOP_PREVIEW:
664 {
665 m_parent->unpreparePreview();
666 rc = 0;
667 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
668 result.status = rc;
669 result.request_api = evt;
670 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
671 m_parent->signalAPIResult(&result);
672 }
673 break;
674 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
675 {
676 rc = NO_ERROR;
677 result.status = rc;
678 result.request_api = evt;
679 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
680 result.enabled = 1;
681 m_parent->signalAPIResult(&result);
682 }
683 break;
684 case QCAMERA_SM_EVT_RECORDING_ENABLED:
685 {
686 rc = 0;
687 result.status = rc;
688 result.request_api = evt;
689 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
690 result.enabled = 0;
691 m_parent->signalAPIResult(&result);
692 }
693 break;
694 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
695 {
696 rc = m_parent->storeMetaDataInBuffers(int(payload));
697 result.status = rc;
698 result.request_api = evt;
699 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
700 m_parent->signalAPIResult(&result);
701 }
702 break;
703 case QCAMERA_SM_EVT_DUMP:
704 {
705 rc = m_parent->dump((int)payload);
706 result.status = rc;
707 result.request_api = evt;
708 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
709 m_parent->signalAPIResult(&result);
710 }
711 break;
712 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
713 {
714 rc = m_parent->autoFocus();
715 result.status = rc;
716 result.request_api = evt;
717 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
718 m_parent->signalAPIResult(&result);
719 }
720 break;
721 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
722 {
723 rc = m_parent->cancelAutoFocus();
724 result.status = rc;
725 result.request_api = evt;
726 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
727 m_parent->signalAPIResult(&result);
728 }
729 break;
730 case QCAMERA_SM_EVT_SEND_COMMAND:
731 {
732 qcamera_sm_evt_command_payload_t *cmd_payload =
733 (qcamera_sm_evt_command_payload_t *)payload;
734 rc = m_parent->sendCommand(cmd_payload->cmd,
735 cmd_payload->arg1,
736 cmd_payload->arg2);
737 result.status = rc;
738 result.request_api = evt;
739 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
740 m_parent->signalAPIResult(&result);
741 }
742 break;
743 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
744 case QCAMERA_SM_EVT_START_RECORDING:
745 case QCAMERA_SM_EVT_STOP_RECORDING:
746 case QCAMERA_SM_EVT_TAKE_PICTURE:
747 case QCAMERA_SM_EVT_CANCEL_PICTURE:
748 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
749 case QCAMERA_SM_EVT_RELEASE:
750 {
751 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
752 rc = INVALID_OPERATION;
753 result.status = rc;
754 result.request_api = evt;
755 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
756 m_parent->signalAPIResult(&result);
757 }
758 break;
Muhua Li31eaee02012-12-11 08:56:45 -0800759 case QCAMERA_SM_EVT_EVT_INTERNAL:
Muhua Libc9a8082012-11-07 15:51:28 -0800760 case QCAMERA_SM_EVT_EVT_NOTIFY:
761 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
Muhua Lida2c4be2012-11-26 09:14:16 -0800762 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
Shuzhen Wangaa829ce2013-01-09 14:41:49 -0800763 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
Muhua Libc9a8082012-11-07 15:51:28 -0800764 default:
765 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
766 break;
767 }
768
769 return rc;
770}
771
Muhua Lida2c4be2012-11-26 09:14:16 -0800772/*===========================================================================
773 * FUNCTION : procEvtPreviewingState
774 *
775 * DESCRIPTION: finite state machine function to handle event in state of
776 * QCAMERA_SM_STATE_PREVIEWING.
777 *
778 * PARAMETERS :
779 * @evt : event to be processed
780 * @payload : event payload. Can be NULL if not needed.
781 *
782 * RETURN : int32_t type of status
783 * NO_ERROR -- success
784 * none-zero failure code
785 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -0800786int32_t QCameraStateMachine::procEvtPreviewingState(qcamera_sm_evt_enum_t evt,
787 void *payload)
788{
789 int32_t rc = NO_ERROR;
790 qcamera_api_result_t result;
791 memset(&result, 0, sizeof(qcamera_api_result_t));
792
793 switch (evt) {
794 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
795 {
796 // Error setting preview window during previewing
797 ALOGE("Cannot set preview window when preview is running");
798 rc = INVALID_OPERATION;
799 result.status = rc;
800 result.request_api = evt;
801 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
802 m_parent->signalAPIResult(&result);
803 }
804 break;
805 case QCAMERA_SM_EVT_SET_CALLBACKS:
806 {
807 qcamera_sm_evt_setcb_payload_t *setcbs =
808 (qcamera_sm_evt_setcb_payload_t *)payload;
809 rc = m_parent->setCallBacks(setcbs->notify_cb,
810 setcbs->data_cb,
811 setcbs->data_cb_timestamp,
812 setcbs->get_memory,
813 setcbs->user);
814 result.status = rc;
815 result.request_api = evt;
816 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
817 m_parent->signalAPIResult(&result);
818 }
819 break;
820 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
821 {
822 rc = m_parent->enableMsgType(int32_t(payload));
823 result.status = rc;
824 result.request_api = evt;
825 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
826 m_parent->signalAPIResult(&result);
827 }
828 break;
829 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
830 {
831 rc = m_parent->disableMsgType(int32_t(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_MSG_TYPE_ENABLED:
839 {
840 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
841 result.status = rc;
842 result.request_api = evt;
843 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
844 result.enabled = enabled;
845 m_parent->signalAPIResult(&result);
846 }
847 break;
848 case QCAMERA_SM_EVT_SET_PARAMS:
849 {
Muhua Lida2c4be2012-11-26 09:14:16 -0800850 bool needRestart = false;
851 rc = m_parent->updateParameters((char*)payload, needRestart);
852 if (rc == NO_ERROR) {
853 if (needRestart) {
854 // need restart preview for parameters to take effect
855 // stop preview
856 m_parent->stopPreview();
857 // commit parameter changes to server
Muhua Li66f3b532013-01-23 17:19:05 -0800858 m_parent->commitParameterChanges();
Muhua Lida2c4be2012-11-26 09:14:16 -0800859 // start preview again
Muhua Li66f3b532013-01-23 17:19:05 -0800860 rc = m_parent->preparePreview();
861 if (rc == NO_ERROR) {
862 rc = m_parent->startPreview();
863 if (rc != NO_ERROR) {
864 m_parent->unpreparePreview();
865 }
866 }
867 if (rc != NO_ERROR) {
868 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
869 }
Muhua Lida2c4be2012-11-26 09:14:16 -0800870 } else {
871 rc = m_parent->commitParameterChanges();
872 }
873 }
Muhua Libc9a8082012-11-07 15:51:28 -0800874 result.status = rc;
875 result.request_api = evt;
876 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
877 m_parent->signalAPIResult(&result);
878 }
879 break;
880 case QCAMERA_SM_EVT_GET_PARAMS:
881 {
882 result.params = m_parent->getParameters();
883 rc = NO_ERROR;
884 result.status = rc;
885 result.request_api = evt;
886 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
887 m_parent->signalAPIResult(&result);
888 }
889 break;
890 case QCAMERA_SM_EVT_PUT_PARAMS:
891 {
892 rc = m_parent->putParameters((char*)payload);
893 result.status = rc;
894 result.request_api = evt;
895 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
896 m_parent->signalAPIResult(&result);
897 }
898 break;
899 case QCAMERA_SM_EVT_START_PREVIEW:
900 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
901 {
902 // no ops here
903 ALOGD("%s: Already in previewing, no ops here to start preview", __func__);
904 rc = NO_ERROR;
905 result.status = rc;
906 result.request_api = evt;
907 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
908 m_parent->signalAPIResult(&result);
909 }
910 break;
911 case QCAMERA_SM_EVT_STOP_PREVIEW:
912 {
913 rc = m_parent->stopPreview();
914 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
915 result.status = rc;
916 result.request_api = evt;
917 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
918 m_parent->signalAPIResult(&result);
919 }
920 break;
921 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
922 {
923 rc = NO_ERROR;
924 result.status = rc;
925 result.request_api = evt;
926 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
927 result.enabled = 1;
928 m_parent->signalAPIResult(&result);
929 }
930 break;
931 case QCAMERA_SM_EVT_RECORDING_ENABLED:
932 {
933 rc = NO_ERROR;
934 result.status = rc;
935 result.request_api = evt;
936 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
937 result.enabled = 0;
938 m_parent->signalAPIResult(&result);
939 }
940 break;
941 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
942 {
943 rc = m_parent->storeMetaDataInBuffers(int(payload));
944 result.status = rc;
945 result.request_api = evt;
946 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
947 m_parent->signalAPIResult(&result);
948 }
949 break;
950 case QCAMERA_SM_EVT_DUMP:
951 {
952 rc = m_parent->dump((int)payload);
953 result.status = rc;
954 result.request_api = evt;
955 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
956 m_parent->signalAPIResult(&result);
957 }
958 break;
959 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
960 {
961 rc = m_parent->autoFocus();
962 result.status = rc;
963 result.request_api = evt;
964 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
965 m_parent->signalAPIResult(&result);
966 }
967 break;
968 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
969 {
970 rc = m_parent->cancelAutoFocus();
971 result.status = rc;
972 result.request_api = evt;
973 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
974 m_parent->signalAPIResult(&result);
975 }
976 break;
977 case QCAMERA_SM_EVT_START_RECORDING:
978 {
979 rc = m_parent->startRecording();
980 if (rc == NO_ERROR) {
981 // move state to recording state
982 m_state = QCAMERA_SM_STATE_RECORDING;
983 }
984 result.status = rc;
985 result.request_api = evt;
986 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
987 m_parent->signalAPIResult(&result);
988 }
989 break;
990 case QCAMERA_SM_EVT_TAKE_PICTURE:
991 {
992 rc = m_parent->takePicture();
993 if (rc == NO_ERROR) {
994 // move state to picture taking state
Muhua Li6d69e932013-01-24 16:39:27 -0800995 if (m_parent->isZSLMode()) {
996 m_state = QCAMERA_SM_STATE_PREVIEW_PIC_TAKING;
997 } else {
998 m_state = QCAMERA_SM_STATE_PIC_TAKING;
999 }
Muhua Libc9a8082012-11-07 15:51:28 -08001000 } else {
1001 // move state to preview stopped state
1002 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
1003 }
1004 result.status = rc;
1005 result.request_api = evt;
1006 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1007 m_parent->signalAPIResult(&result);
1008 }
1009 break;
1010 case QCAMERA_SM_EVT_SEND_COMMAND:
1011 {
1012 qcamera_sm_evt_command_payload_t *cmd_payload =
1013 (qcamera_sm_evt_command_payload_t *)payload;
1014 rc = m_parent->sendCommand(cmd_payload->cmd,
1015 cmd_payload->arg1,
1016 cmd_payload->arg2);
1017 result.status = rc;
1018 result.request_api = evt;
1019 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1020 m_parent->signalAPIResult(&result);
1021 }
1022 break;
1023 case QCAMERA_SM_EVT_CANCEL_PICTURE:
1024 case QCAMERA_SM_EVT_STOP_RECORDING:
1025 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
1026 case QCAMERA_SM_EVT_RELEASE:
1027 {
1028 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1029 rc = INVALID_OPERATION;
1030 result.status = rc;
1031 result.request_api = evt;
1032 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1033 m_parent->signalAPIResult(&result);
1034 }
1035 break;
Muhua Li31eaee02012-12-11 08:56:45 -08001036 case QCAMERA_SM_EVT_EVT_INTERNAL:
1037 {
1038 qcamera_sm_internal_evt_payload_t *internal_evt =
1039 (qcamera_sm_internal_evt_payload_t *)payload;
1040 switch (internal_evt->evt_type) {
1041 case QCAMERA_INTERNAL_EVT_FOCUS_UPDATE:
1042 rc = m_parent->processAutoFocusEvent(internal_evt->focus_data);
1043 break;
1044 default:
1045 break;
1046 }
1047 }
1048 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001049 case QCAMERA_SM_EVT_EVT_NOTIFY:
1050 {
1051 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
1052 switch (cam_evt->server_event_type) {
Muhua Libc9a8082012-11-07 15:51:28 -08001053 case CAM_EVENT_TYPE_ZOOM_DONE:
1054 rc = m_parent->processZoomEvent(cam_evt->status);
1055 break;
1056 default:
1057 ALOGD("%s: no handling for server evt (%d) at this state",
1058 __func__, cam_evt->server_event_type);
1059 break;
1060 }
1061 }
1062 break;
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08001063 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
Emilian Peeve1d5acb2013-02-01 11:29:53 -08001064 {
1065 rc = m_parent->updateThermalFPS((cam_fps_range_t *) payload);
1066 }
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08001067 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001068 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
Muhua Lida2c4be2012-11-26 09:14:16 -08001069 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
Muhua Libc9a8082012-11-07 15:51:28 -08001070 default:
1071 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1072 break;
1073 }
1074
1075 return rc;
1076}
1077
Muhua Lida2c4be2012-11-26 09:14:16 -08001078/*===========================================================================
1079 * FUNCTION : procEvtPicTakingState
1080 *
1081 * DESCRIPTION: finite state machine function to handle event in state of
1082 * QCAMERA_SM_STATE_PIC_TAKING.
1083 *
1084 * PARAMETERS :
1085 * @evt : event to be processed
1086 * @payload : event payload. Can be NULL if not needed.
1087 *
1088 * RETURN : int32_t type of status
1089 * NO_ERROR -- success
1090 * none-zero failure code
1091 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -08001092int32_t QCameraStateMachine::procEvtPicTakingState(qcamera_sm_evt_enum_t evt,
1093 void *payload)
1094{
1095 int32_t rc = NO_ERROR;
1096 qcamera_api_result_t result;
1097 memset(&result, 0, sizeof(qcamera_api_result_t));
1098
1099 switch (evt) {
1100 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
1101 {
1102 // Error setting preview window during previewing
1103 ALOGE("Cannot set preview window when preview is running");
1104 rc = INVALID_OPERATION;
1105 result.status = rc;
1106 result.request_api = evt;
1107 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1108 m_parent->signalAPIResult(&result);
1109 }
1110 break;
1111 case QCAMERA_SM_EVT_SET_CALLBACKS:
1112 {
1113 qcamera_sm_evt_setcb_payload_t *setcbs =
1114 (qcamera_sm_evt_setcb_payload_t *)payload;
1115 rc = m_parent->setCallBacks(setcbs->notify_cb,
1116 setcbs->data_cb,
1117 setcbs->data_cb_timestamp,
1118 setcbs->get_memory,
1119 setcbs->user);
1120 result.status = rc;
1121 result.request_api = evt;
1122 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1123 m_parent->signalAPIResult(&result);
1124 }
1125 break;
1126 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
1127 {
1128 rc = m_parent->enableMsgType(int32_t(payload));
1129 result.status = rc;
1130 result.request_api = evt;
1131 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1132 m_parent->signalAPIResult(&result);
1133 }
1134 break;
1135 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
1136 {
1137 rc = m_parent->disableMsgType(int32_t(payload));
1138 result.status = rc;
1139 result.request_api = evt;
1140 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1141 m_parent->signalAPIResult(&result);
1142 }
1143 break;
1144 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
1145 {
1146 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
1147 result.status = rc;
1148 result.request_api = evt;
1149 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1150 result.enabled = enabled;
1151 m_parent->signalAPIResult(&result);
1152 }
1153 break;
1154 case QCAMERA_SM_EVT_SET_PARAMS:
1155 {
Muhua Lida2c4be2012-11-26 09:14:16 -08001156 bool needRestart = false;
1157 rc = m_parent->updateParameters((char*)payload, needRestart);
1158 if (rc == NO_ERROR) {
1159 rc = m_parent->commitParameterChanges();
1160 }
Muhua Libc9a8082012-11-07 15:51:28 -08001161 result.status = rc;
1162 result.request_api = evt;
1163 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1164 m_parent->signalAPIResult(&result);
1165 }
1166 break;
1167 case QCAMERA_SM_EVT_GET_PARAMS:
1168 {
1169 result.params = m_parent->getParameters();
1170 rc = NO_ERROR;
1171 result.status = rc;
1172 result.request_api = evt;
1173 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
1174 m_parent->signalAPIResult(&result);
1175 }
1176 break;
1177 case QCAMERA_SM_EVT_PUT_PARAMS:
1178 {
1179 rc = m_parent->putParameters((char*)payload);
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_STOP_PREVIEW:
1187 {
1188 // no ops, since preview is stopped (normal),
1189 // or preview msg type is disabled (ZSL)
1190 rc = NO_ERROR;
1191 result.status = rc;
1192 result.request_api = evt;
1193 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1194 m_parent->signalAPIResult(&result);
1195 }
1196 break;
1197 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
1198 {
1199 rc = NO_ERROR;
1200 result.status = rc;
1201 result.request_api = evt;
1202 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1203 result.enabled = 0;
1204 m_parent->signalAPIResult(&result);
1205 }
1206 break;
1207 case QCAMERA_SM_EVT_RECORDING_ENABLED:
1208 {
1209 rc = NO_ERROR;
1210 result.status = rc;
1211 result.request_api = evt;
1212 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1213 result.enabled = 0;
1214 m_parent->signalAPIResult(&result);
1215 }
1216 break;
1217 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
1218 {
1219 rc = m_parent->storeMetaDataInBuffers(int(payload));
1220 result.status = rc;
1221 result.request_api = evt;
1222 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1223 m_parent->signalAPIResult(&result);
1224 }
1225 break;
1226 case QCAMERA_SM_EVT_DUMP:
1227 {
1228 rc = m_parent->dump((int)payload);
1229 result.status = rc;
1230 result.request_api = evt;
1231 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1232 m_parent->signalAPIResult(&result);
1233 }
1234 break;
1235 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
1236 {
1237 rc = m_parent->autoFocus();
1238 result.status = rc;
1239 result.request_api = evt;
1240 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1241 m_parent->signalAPIResult(&result);
1242 }
1243 break;
1244 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
1245 {
1246 rc = m_parent->cancelAutoFocus();
1247 result.status = rc;
1248 result.request_api = evt;
1249 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1250 m_parent->signalAPIResult(&result);
1251 }
1252 break;
1253 case QCAMERA_SM_EVT_SEND_COMMAND:
1254 {
1255 qcamera_sm_evt_command_payload_t *cmd_payload =
1256 (qcamera_sm_evt_command_payload_t *)payload;
1257 rc = m_parent->sendCommand(cmd_payload->cmd,
1258 cmd_payload->arg1,
1259 cmd_payload->arg2);
1260 result.status = rc;
1261 result.request_api = evt;
1262 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1263 m_parent->signalAPIResult(&result);
1264 }
1265 break;
1266 case QCAMERA_SM_EVT_CANCEL_PICTURE:
1267 {
1268 rc = m_parent->cancelPicture();
1269 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
1270 result.status = rc;
1271 result.request_api = evt;
1272 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1273 m_parent->signalAPIResult(&result);
1274 }
1275 break;
1276 case QCAMERA_SM_EVT_TAKE_PICTURE:
1277 case QCAMERA_SM_EVT_START_RECORDING:
1278 case QCAMERA_SM_EVT_STOP_RECORDING:
1279 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
1280 case QCAMERA_SM_EVT_START_PREVIEW:
1281 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
1282 case QCAMERA_SM_EVT_RELEASE:
1283 {
1284 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1285 rc = INVALID_OPERATION;
1286 result.status = rc;
1287 result.request_api = evt;
1288 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1289 m_parent->signalAPIResult(&result);
1290 }
1291 break;
Muhua Li31eaee02012-12-11 08:56:45 -08001292 case QCAMERA_SM_EVT_EVT_INTERNAL:
1293 {
1294 qcamera_sm_internal_evt_payload_t *internal_evt =
1295 (qcamera_sm_internal_evt_payload_t *)payload;
1296 switch (internal_evt->evt_type) {
1297 case QCAMERA_INTERNAL_EVT_FOCUS_UPDATE:
1298 rc = m_parent->processAutoFocusEvent(internal_evt->focus_data);
1299 break;
1300 default:
1301 break;
1302 }
1303 }
1304 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001305 case QCAMERA_SM_EVT_EVT_NOTIFY:
1306 {
1307 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
1308 switch (cam_evt->server_event_type) {
Muhua Libc9a8082012-11-07 15:51:28 -08001309 case CAM_EVENT_TYPE_ZOOM_DONE:
1310 rc = m_parent->processZoomEvent(cam_evt->status);
1311 break;
1312 default:
1313 ALOGD("%s: no handling for server evt (%d) at this state",
1314 __func__, cam_evt->server_event_type);
1315 break;
1316 }
1317 }
1318 break;
1319 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
1320 {
1321 qcamera_jpeg_evt_payload_t *jpeg_job =
1322 (qcamera_jpeg_evt_payload_t *)payload;
1323 rc = m_parent->processJpegNotify(jpeg_job);
1324 }
1325 break;
1326 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
1327 {
1328 rc = m_parent->cancelPicture();
1329 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
1330 }
1331 break;
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08001332 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
Muhua Libc9a8082012-11-07 15:51:28 -08001333 default:
1334 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1335 break;
1336 }
1337
1338 return rc;
1339}
1340
Muhua Lida2c4be2012-11-26 09:14:16 -08001341/*===========================================================================
1342 * FUNCTION : procEvtRecordingState
1343 *
1344 * DESCRIPTION: finite state machine function to handle event in state of
1345 * QCAMERA_SM_STATE_RECORDING.
1346 *
1347 * PARAMETERS :
1348 * @evt : event to be processed
1349 * @payload : event payload. Can be NULL if not needed.
1350 *
1351 * RETURN : int32_t type of status
1352 * NO_ERROR -- success
1353 * none-zero failure code
1354 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -08001355int32_t QCameraStateMachine::procEvtRecordingState(qcamera_sm_evt_enum_t evt,
1356 void *payload)
1357{
1358 int32_t rc = NO_ERROR;
1359 qcamera_api_result_t result;
1360 memset(&result, 0, sizeof(qcamera_api_result_t));
1361
1362 switch (evt) {
1363 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
1364 {
1365 // Error setting preview window during previewing
1366 ALOGE("Cannot set preview window when preview is running");
1367 rc = INVALID_OPERATION;
1368 result.status = rc;
1369 result.request_api = evt;
1370 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1371 m_parent->signalAPIResult(&result);
1372 }
1373 break;
1374 case QCAMERA_SM_EVT_SET_CALLBACKS:
1375 {
1376 qcamera_sm_evt_setcb_payload_t *setcbs =
1377 (qcamera_sm_evt_setcb_payload_t *)payload;
1378 rc = m_parent->setCallBacks(setcbs->notify_cb,
1379 setcbs->data_cb,
1380 setcbs->data_cb_timestamp,
1381 setcbs->get_memory,
1382 setcbs->user);
1383 result.status = rc;
1384 result.request_api = evt;
1385 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1386 m_parent->signalAPIResult(&result);
1387 }
1388 break;
1389 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
1390 {
1391 rc = m_parent->enableMsgType(int32_t(payload));
1392 result.status = rc;
1393 result.request_api = evt;
1394 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1395 m_parent->signalAPIResult(&result);
1396 }
1397 break;
1398 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
1399 {
1400 rc = m_parent->disableMsgType(int32_t(payload));
1401 result.status = rc;
1402 result.request_api = evt;
1403 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1404 m_parent->signalAPIResult(&result);
1405 }
1406 break;
1407 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
1408 {
1409 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
1410 result.status = rc;
1411 result.request_api = evt;
1412 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1413 result.enabled = enabled;
1414 m_parent->signalAPIResult(&result);
1415 }
1416 break;
1417 case QCAMERA_SM_EVT_SET_PARAMS:
1418 {
Muhua Lida2c4be2012-11-26 09:14:16 -08001419 bool needRestart = false;
1420 rc = m_parent->updateParameters((char*)payload, needRestart);
1421 if (rc == NO_ERROR) {
1422 if (needRestart) {
1423 // cannot set parameters that requires restart during recording
1424 ALOGE("%s: Cannot set parameters that requires restart during recording",
1425 __func__);
1426 rc = BAD_VALUE;
1427 } else {
1428 rc = m_parent->commitParameterChanges();
1429 }
1430 }
Muhua Libc9a8082012-11-07 15:51:28 -08001431 result.status = rc;
1432 result.request_api = evt;
1433 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1434 m_parent->signalAPIResult(&result);
1435 }
1436 break;
1437 case QCAMERA_SM_EVT_GET_PARAMS:
1438 {
1439 result.params = m_parent->getParameters();
1440 rc = NO_ERROR;
1441 result.status = rc;
1442 result.request_api = evt;
1443 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
1444 m_parent->signalAPIResult(&result);
1445 }
1446 break;
1447 case QCAMERA_SM_EVT_PUT_PARAMS:
1448 {
1449 rc = m_parent->putParameters((char*)payload);
1450 result.status = rc;
1451 result.request_api = evt;
1452 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1453 m_parent->signalAPIResult(&result);
1454 }
1455 break;
1456 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
1457 {
1458 rc = NO_ERROR;
1459 result.status = rc;
1460 result.request_api = evt;
1461 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1462 result.enabled = 0;
1463 m_parent->signalAPIResult(&result);
1464 }
1465 break;
1466 case QCAMERA_SM_EVT_RECORDING_ENABLED:
1467 {
1468 rc = NO_ERROR;
1469 result.status = rc;
1470 result.request_api = evt;
1471 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1472 result.enabled = 1;
1473 m_parent->signalAPIResult(&result);
1474 }
1475 break;
1476 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
1477 {
1478 rc = m_parent->storeMetaDataInBuffers(int(payload));
1479 result.status = rc;
1480 result.request_api = evt;
1481 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1482 m_parent->signalAPIResult(&result);
1483 }
1484 break;
1485 case QCAMERA_SM_EVT_DUMP:
1486 {
1487 rc = m_parent->dump((int)payload);
1488 result.status = rc;
1489 result.request_api = evt;
1490 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1491 m_parent->signalAPIResult(&result);
1492 }
1493 break;
1494 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
1495 {
1496 rc = m_parent->autoFocus();
1497 result.status = rc;
1498 result.request_api = evt;
1499 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1500 m_parent->signalAPIResult(&result);
1501 }
1502 break;
1503 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
1504 {
1505 rc = m_parent->cancelAutoFocus();
1506 result.status = rc;
1507 result.request_api = evt;
1508 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1509 m_parent->signalAPIResult(&result);
1510 }
1511 break;
1512 case QCAMERA_SM_EVT_SEND_COMMAND:
1513 {
1514 qcamera_sm_evt_command_payload_t *cmd_payload =
1515 (qcamera_sm_evt_command_payload_t *)payload;
1516 rc = m_parent->sendCommand(cmd_payload->cmd,
1517 cmd_payload->arg1,
1518 cmd_payload->arg2);
1519 result.status = rc;
1520 result.request_api = evt;
1521 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1522 m_parent->signalAPIResult(&result);
1523 }
1524 break;
1525 case QCAMERA_SM_EVT_TAKE_PICTURE:
1526 {
1527 rc = m_parent->takeLiveSnapshot();
1528 if (rc == 0) {
1529 m_state = QCAMERA_SM_STATE_VIDEO_PIC_TAKING;
1530 }
1531 result.status = rc;
1532 result.request_api = evt;
1533 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1534 m_parent->signalAPIResult(&result);
1535 }
1536 break;
1537 case QCAMERA_SM_EVT_START_RECORDING:
1538 {
1539 // no ops here
1540 ALOGD("%s: already in recording state, no ops for start_recording", __func__);
1541 rc = 0;
1542 result.status = rc;
1543 result.request_api = evt;
1544 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1545 m_parent->signalAPIResult(&result);
1546 }
1547 break;
1548 case QCAMERA_SM_EVT_STOP_RECORDING:
1549 {
1550 rc = m_parent->stopRecording();
1551 m_state = QCAMERA_SM_STATE_PREVIEWING;
1552 result.status = rc;
1553 result.request_api = evt;
1554 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1555 m_parent->signalAPIResult(&result);
1556 }
1557 break;
1558 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
1559 {
1560 rc = m_parent->releaseRecordingFrame((const void *)payload);
1561 result.status = rc;
1562 result.request_api = evt;
1563 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1564 m_parent->signalAPIResult(&result);
1565 }
1566 break;
1567 case QCAMERA_SM_EVT_CANCEL_PICTURE:
1568 case QCAMERA_SM_EVT_START_PREVIEW:
1569 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
1570 case QCAMERA_SM_EVT_STOP_PREVIEW:
1571 case QCAMERA_SM_EVT_RELEASE:
1572 {
1573 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1574 rc = INVALID_OPERATION;
1575 result.status = rc;
1576 result.request_api = evt;
1577 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1578 m_parent->signalAPIResult(&result);
1579 }
1580 break;
Muhua Li31eaee02012-12-11 08:56:45 -08001581 case QCAMERA_SM_EVT_EVT_INTERNAL:
1582 {
1583 qcamera_sm_internal_evt_payload_t *internal_evt =
1584 (qcamera_sm_internal_evt_payload_t *)payload;
1585 switch (internal_evt->evt_type) {
1586 case QCAMERA_INTERNAL_EVT_FOCUS_UPDATE:
1587 rc = m_parent->processAutoFocusEvent(internal_evt->focus_data);
1588 break;
1589 default:
1590 break;
1591 }
1592 }
1593 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001594 case QCAMERA_SM_EVT_EVT_NOTIFY:
1595 {
1596 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
1597 switch (cam_evt->server_event_type) {
Muhua Libc9a8082012-11-07 15:51:28 -08001598 case CAM_EVENT_TYPE_ZOOM_DONE:
1599 rc = m_parent->processZoomEvent(cam_evt->status);
1600 break;
1601 default:
1602 ALOGD("%s: no handling for server evt (%d) at this state",
1603 __func__, cam_evt->server_event_type);
1604 break;
1605 }
1606 }
1607 break;
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08001608 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
Emilian Peeve1d5acb2013-02-01 11:29:53 -08001609 {
1610 rc = m_parent->updateThermalFPS((cam_fps_range_t *) payload);
1611 }
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08001612 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001613 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
Muhua Lida2c4be2012-11-26 09:14:16 -08001614 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
Muhua Libc9a8082012-11-07 15:51:28 -08001615 default:
1616 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1617 break;
1618 }
1619
1620 return rc;
1621}
1622
Muhua Lida2c4be2012-11-26 09:14:16 -08001623/*===========================================================================
1624 * FUNCTION : procEvtVideoPicTakingState
1625 *
1626 * DESCRIPTION: finite state machine function to handle event in state of
1627 * QCAMERA_SM_STATE_VIDEO_PIC_TAKING.
1628 *
1629 * PARAMETERS :
1630 * @evt : event to be processed
1631 * @payload : event payload. Can be NULL if not needed.
1632 *
1633 * RETURN : int32_t type of status
1634 * NO_ERROR -- success
1635 * none-zero failure code
1636 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -08001637int32_t QCameraStateMachine::procEvtVideoPicTakingState(qcamera_sm_evt_enum_t evt,
1638 void *payload)
1639{
1640 int32_t rc = NO_ERROR;
1641 qcamera_api_result_t result;
1642 memset(&result, 0, sizeof(qcamera_api_result_t));
1643
1644 switch (evt) {
1645 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
1646 {
1647 // Error setting preview window during previewing
1648 ALOGE("Cannot set preview window when preview is running");
1649 rc = INVALID_OPERATION;
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_SET_CALLBACKS:
1657 {
1658 qcamera_sm_evt_setcb_payload_t *setcbs =
1659 (qcamera_sm_evt_setcb_payload_t *)payload;
1660 rc = m_parent->setCallBacks(setcbs->notify_cb,
1661 setcbs->data_cb,
1662 setcbs->data_cb_timestamp,
1663 setcbs->get_memory,
1664 setcbs->user);
1665 result.status = rc;
1666 result.request_api = evt;
1667 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1668 m_parent->signalAPIResult(&result);
1669 }
1670 break;
1671 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
1672 {
1673 rc = m_parent->enableMsgType(int32_t(payload));
1674 result.status = rc;
1675 result.request_api = evt;
1676 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1677 m_parent->signalAPIResult(&result);
1678 }
1679 break;
1680 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
1681 {
1682 rc = m_parent->disableMsgType(int32_t(payload));
1683 result.status = rc;
1684 result.request_api = evt;
1685 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1686 m_parent->signalAPIResult(&result);
1687 }
1688 break;
1689 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
1690 {
1691 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
1692 result.status = rc;
1693 result.request_api = evt;
1694 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1695 result.enabled = enabled;
1696 m_parent->signalAPIResult(&result);
1697 }
1698 break;
1699 case QCAMERA_SM_EVT_SET_PARAMS:
1700 {
Muhua Lida2c4be2012-11-26 09:14:16 -08001701 bool needRestart = false;
1702 rc = m_parent->updateParameters((char*)payload, needRestart);
1703 if (rc == NO_ERROR) {
1704 if (needRestart) {
1705 // cannot set parameters that requires restart during recording
1706 ALOGE("%s: Cannot set parameters that requires restart during recording",
1707 __func__);
1708 rc = BAD_VALUE;
1709 } else {
1710 rc = m_parent->commitParameterChanges();
1711 }
1712 }
Muhua Libc9a8082012-11-07 15:51:28 -08001713 result.status = rc;
1714 result.request_api = evt;
1715 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1716 m_parent->signalAPIResult(&result);
1717 }
1718 break;
1719 case QCAMERA_SM_EVT_GET_PARAMS:
1720 {
1721 result.params = m_parent->getParameters();
1722 rc = NO_ERROR;
1723 result.status = rc;
1724 result.request_api = evt;
1725 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
1726 m_parent->signalAPIResult(&result);
1727 }
1728 break;
1729 case QCAMERA_SM_EVT_PUT_PARAMS:
1730 {
1731 rc = m_parent->putParameters((char*)payload);
1732 result.status = rc;
1733 result.request_api = evt;
1734 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1735 m_parent->signalAPIResult(&result);
1736 }
1737 break;
1738 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
1739 {
1740 rc = NO_ERROR;
1741 result.status = rc;
1742 result.request_api = evt;
1743 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1744 result.enabled = 1;
1745 m_parent->signalAPIResult(&result);
1746 }
1747 break;
1748 case QCAMERA_SM_EVT_RECORDING_ENABLED:
1749 {
1750 rc = NO_ERROR;
1751 result.status = rc;
1752 result.request_api = evt;
1753 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1754 result.enabled = 1;
1755 m_parent->signalAPIResult(&result);
1756 }
1757 break;
1758 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
1759 {
1760 rc = m_parent->storeMetaDataInBuffers(int(payload));
1761 result.status = rc;
1762 result.request_api = evt;
1763 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1764 m_parent->signalAPIResult(&result);
1765 }
1766 break;
1767 case QCAMERA_SM_EVT_DUMP:
1768 {
1769 rc = m_parent->dump((int)payload);
1770 result.status = rc;
1771 result.request_api = evt;
1772 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1773 m_parent->signalAPIResult(&result);
1774 }
1775 break;
1776 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
1777 {
1778 rc = m_parent->autoFocus();
1779 result.status = rc;
1780 result.request_api = evt;
1781 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1782 m_parent->signalAPIResult(&result);
1783 }
1784 break;
1785 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
1786 {
1787 rc = m_parent->cancelAutoFocus();
1788 result.status = rc;
1789 result.request_api = evt;
1790 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1791 m_parent->signalAPIResult(&result);
1792 }
1793 break;
1794 case QCAMERA_SM_EVT_SEND_COMMAND:
1795 {
1796 qcamera_sm_evt_command_payload_t *cmd_payload =
1797 (qcamera_sm_evt_command_payload_t *)payload;
1798 rc = m_parent->sendCommand(cmd_payload->cmd,
1799 cmd_payload->arg1,
1800 cmd_payload->arg2);
1801 result.status = rc;
1802 result.request_api = evt;
1803 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1804 m_parent->signalAPIResult(&result);
1805 }
1806 break;
1807 case QCAMERA_SM_EVT_STOP_RECORDING:
1808 {
1809 rc = m_parent->stopRecording();
1810 m_state = QCAMERA_SM_STATE_PREVIEW_PIC_TAKING;
1811 result.status = rc;
1812 result.request_api = evt;
1813 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1814 m_parent->signalAPIResult(&result);
1815 }
1816 break;
1817 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
1818 {
1819 rc = m_parent->releaseRecordingFrame((const void *)payload);
1820 result.status = rc;
1821 result.request_api = evt;
1822 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1823 m_parent->signalAPIResult(&result);
1824 }
1825 break;
1826 case QCAMERA_SM_EVT_CANCEL_PICTURE:
1827 {
1828 rc = m_parent->cancelLiveSnapshot();
1829 m_state = QCAMERA_SM_STATE_RECORDING;
1830 result.status = rc;
1831 result.request_api = evt;
1832 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1833 m_parent->signalAPIResult(&result);
1834 }
1835 break;
1836 case QCAMERA_SM_EVT_START_RECORDING:
1837 case QCAMERA_SM_EVT_START_PREVIEW:
1838 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
1839 case QCAMERA_SM_EVT_STOP_PREVIEW:
1840 case QCAMERA_SM_EVT_TAKE_PICTURE:
1841 case QCAMERA_SM_EVT_RELEASE:
1842 {
1843 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1844 rc = INVALID_OPERATION;
1845 result.status = rc;
1846 result.request_api = evt;
1847 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1848 m_parent->signalAPIResult(&result);
1849 }
1850 break;
Muhua Li31eaee02012-12-11 08:56:45 -08001851 case QCAMERA_SM_EVT_EVT_INTERNAL:
1852 {
1853 qcamera_sm_internal_evt_payload_t *internal_evt =
1854 (qcamera_sm_internal_evt_payload_t *)payload;
1855 switch (internal_evt->evt_type) {
1856 case QCAMERA_INTERNAL_EVT_FOCUS_UPDATE:
1857 rc = m_parent->processAutoFocusEvent(internal_evt->focus_data);
1858 break;
1859 default:
1860 break;
1861 }
1862 }
1863 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001864 case QCAMERA_SM_EVT_EVT_NOTIFY:
1865 {
1866 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
1867 switch (cam_evt->server_event_type) {
Muhua Libc9a8082012-11-07 15:51:28 -08001868 case CAM_EVENT_TYPE_ZOOM_DONE:
1869 rc = m_parent->processZoomEvent(cam_evt->status);
1870 break;
1871 default:
1872 ALOGD("%s: no handling for server evt (%d) at this state",
1873 __func__, cam_evt->server_event_type);
1874 break;
1875 }
1876 }
1877 break;
1878 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
1879 {
1880 qcamera_jpeg_evt_payload_t *jpeg_job =
1881 (qcamera_jpeg_evt_payload_t *)payload;
1882 rc = m_parent->processJpegNotify(jpeg_job);
1883 }
1884 break;
1885 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
1886 {
1887 rc = m_parent->cancelLiveSnapshot();
1888 m_state = QCAMERA_SM_STATE_RECORDING;
1889 }
1890 break;
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08001891 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
Emilian Peeve1d5acb2013-02-01 11:29:53 -08001892 {
1893 rc = m_parent->updateThermalFPS((cam_fps_range_t *) payload);
1894 }
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08001895 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001896 default:
1897 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1898 break;
1899 }
1900
1901 return rc;
1902}
1903
Muhua Lida2c4be2012-11-26 09:14:16 -08001904/*===========================================================================
1905 * FUNCTION : procEvtPreviewPicTakingState
1906 *
1907 * DESCRIPTION: finite state machine function to handle event in state of
1908 * QCAMERA_SM_STATE_PREVIEW_PIC_TAKING.
1909 *
1910 * PARAMETERS :
1911 * @evt : event to be processed
1912 * @payload : event payload. Can be NULL if not needed.
1913 *
1914 * RETURN : int32_t type of status
1915 * NO_ERROR -- success
1916 * none-zero failure code
1917 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -08001918int32_t QCameraStateMachine::procEvtPreviewPicTakingState(qcamera_sm_evt_enum_t evt,
1919 void *payload)
1920{
1921 int32_t rc = NO_ERROR;
1922 qcamera_api_result_t result;
1923 memset(&result, 0, sizeof(qcamera_api_result_t));
1924
1925 switch (evt) {
1926 case QCAMERA_SM_EVT_SET_CALLBACKS:
1927 {
1928 qcamera_sm_evt_setcb_payload_t *setcbs =
1929 (qcamera_sm_evt_setcb_payload_t *)payload;
1930 rc = m_parent->setCallBacks(setcbs->notify_cb,
1931 setcbs->data_cb,
1932 setcbs->data_cb_timestamp,
1933 setcbs->get_memory,
1934 setcbs->user);
1935 result.status = rc;
1936 result.request_api = evt;
1937 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1938 m_parent->signalAPIResult(&result);
1939 }
1940 break;
1941 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
1942 {
1943 rc = m_parent->enableMsgType(int32_t(payload));
1944 result.status = rc;
1945 result.request_api = evt;
1946 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1947 m_parent->signalAPIResult(&result);
1948 }
1949 break;
1950 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
1951 {
1952 rc = m_parent->disableMsgType(int32_t(payload));
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_MSG_TYPE_ENABLED:
1960 {
1961 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
1962 result.status = rc;
1963 result.request_api = evt;
1964 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1965 result.enabled = enabled;
1966 m_parent->signalAPIResult(&result);
1967 }
1968 break;
1969 case QCAMERA_SM_EVT_SET_PARAMS:
1970 {
Muhua Lida2c4be2012-11-26 09:14:16 -08001971 bool needRestart = false;
1972 rc = m_parent->updateParameters((char*)payload, needRestart);
1973 if (rc == NO_ERROR) {
1974 if (needRestart) {
1975 // need restart preview for parameters to take effect
1976 // stop preview
1977 m_parent->stopPreview();
1978 // commit parameter changes to server
Muhua Li66f3b532013-01-23 17:19:05 -08001979 m_parent->commitParameterChanges();
Muhua Lida2c4be2012-11-26 09:14:16 -08001980 // start preview again
Muhua Li66f3b532013-01-23 17:19:05 -08001981 rc = m_parent->preparePreview();
1982 if (rc == NO_ERROR) {
1983 rc = m_parent->startPreview();
1984 if (rc != NO_ERROR) {
1985 m_parent->unpreparePreview();
1986 }
1987 }
1988 if (rc != NO_ERROR) {
1989 m_state = QCAMERA_SM_STATE_PIC_TAKING;
1990 }
Muhua Lida2c4be2012-11-26 09:14:16 -08001991 } else {
1992 rc = m_parent->commitParameterChanges();
1993 }
1994 }
Muhua Libc9a8082012-11-07 15:51:28 -08001995 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_GET_PARAMS:
2002 {
2003 result.params = m_parent->getParameters();
2004 rc = NO_ERROR;
2005 result.status = rc;
2006 result.request_api = evt;
2007 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
2008 m_parent->signalAPIResult(&result);
2009 }
2010 break;
2011 case QCAMERA_SM_EVT_PUT_PARAMS:
2012 {
2013 rc = m_parent->putParameters((char*)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_PREVIEW_ENABLED:
2021 {
2022 rc = NO_ERROR;
2023 result.status = rc;
2024 result.request_api = evt;
2025 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
2026 result.enabled = 1;
2027 m_parent->signalAPIResult(&result);
2028 }
2029 break;
2030 case QCAMERA_SM_EVT_RECORDING_ENABLED:
2031 {
2032 rc = NO_ERROR;
2033 result.status = rc;
2034 result.request_api = evt;
2035 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
2036 result.enabled = 0;
2037 m_parent->signalAPIResult(&result);
2038 }
2039 break;
2040 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
2041 {
2042 rc = m_parent->storeMetaDataInBuffers(int(payload));
2043 result.status = rc;
2044 result.request_api = evt;
2045 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2046 m_parent->signalAPIResult(&result);
2047 }
2048 break;
2049 case QCAMERA_SM_EVT_DUMP:
2050 {
2051 rc = m_parent->dump((int)payload);
2052 result.status = rc;
2053 result.request_api = evt;
2054 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2055 m_parent->signalAPIResult(&result);
2056 }
2057 break;
2058 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
2059 {
2060 rc = m_parent->autoFocus();
2061 result.status = rc;
2062 result.request_api = evt;
2063 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2064 m_parent->signalAPIResult(&result);
2065 }
2066 break;
2067 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
2068 {
2069 rc = m_parent->cancelAutoFocus();
2070 result.status = rc;
2071 result.request_api = evt;
2072 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2073 m_parent->signalAPIResult(&result);
2074 }
2075 break;
2076 case QCAMERA_SM_EVT_SEND_COMMAND:
2077 {
2078 qcamera_sm_evt_command_payload_t *cmd_payload =
2079 (qcamera_sm_evt_command_payload_t *)payload;
2080 rc = m_parent->sendCommand(cmd_payload->cmd,
2081 cmd_payload->arg1,
2082 cmd_payload->arg2);
2083 result.status = rc;
2084 result.request_api = evt;
2085 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2086 m_parent->signalAPIResult(&result);
2087 }
2088 break;
2089 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
2090 {
2091 rc = m_parent->releaseRecordingFrame((const void *)payload);
2092 result.status = rc;
2093 result.request_api = evt;
2094 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2095 m_parent->signalAPIResult(&result);
2096 }
2097 break;
2098 case QCAMERA_SM_EVT_CANCEL_PICTURE:
2099 {
2100 rc = m_parent->cancelLiveSnapshot();
2101 m_state = QCAMERA_SM_STATE_PREVIEWING;
2102 result.status = rc;
2103 result.request_api = evt;
2104 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2105 m_parent->signalAPIResult(&result);
2106 }
2107 break;
2108 case QCAMERA_SM_EVT_STOP_PREVIEW:
2109 {
2110 m_parent->stopChannel(QCAMERA_CH_TYPE_PREVIEW);
2111 m_parent->delChannel(QCAMERA_CH_TYPE_PREVIEW);
2112 m_parent->delChannel(QCAMERA_CH_TYPE_VIDEO);
2113 m_state = QCAMERA_SM_STATE_PIC_TAKING;
2114 rc = NO_ERROR;
2115 result.status = rc;
2116 result.request_api = evt;
2117 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2118 m_parent->signalAPIResult(&result);
2119 }
2120 break;
2121 case QCAMERA_SM_EVT_START_RECORDING:
2122 {
2123 rc = m_parent->stopRecording();
2124 if (rc == NO_ERROR) {
2125 m_state = QCAMERA_SM_STATE_VIDEO_PIC_TAKING;
2126 }
2127 result.status = rc;
2128 result.request_api = evt;
2129 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2130 m_parent->signalAPIResult(&result);
2131 }
2132 break;
2133 case QCAMERA_SM_EVT_STOP_RECORDING:
2134 case QCAMERA_SM_EVT_START_PREVIEW:
2135 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
2136 case QCAMERA_SM_EVT_TAKE_PICTURE:
2137 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
2138 case QCAMERA_SM_EVT_RELEASE:
2139 {
2140 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
2141 rc = INVALID_OPERATION;
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;
Muhua Li31eaee02012-12-11 08:56:45 -08002148 case QCAMERA_SM_EVT_EVT_INTERNAL:
2149 {
2150 qcamera_sm_internal_evt_payload_t *internal_evt =
2151 (qcamera_sm_internal_evt_payload_t *)payload;
2152 switch (internal_evt->evt_type) {
2153 case QCAMERA_INTERNAL_EVT_FOCUS_UPDATE:
2154 rc = m_parent->processAutoFocusEvent(internal_evt->focus_data);
2155 break;
2156 default:
2157 break;
2158 }
2159 }
2160 break;
Muhua Libc9a8082012-11-07 15:51:28 -08002161 case QCAMERA_SM_EVT_EVT_NOTIFY:
2162 {
2163 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
2164 switch (cam_evt->server_event_type) {
Muhua Libc9a8082012-11-07 15:51:28 -08002165 case CAM_EVENT_TYPE_ZOOM_DONE:
2166 rc = m_parent->processZoomEvent(cam_evt->status);
2167 break;
2168 default:
2169 ALOGD("%s: no handling for server evt (%d) at this state",
2170 __func__, cam_evt->server_event_type);
2171 break;
2172 }
2173 }
2174 break;
2175 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
2176 {
2177 qcamera_jpeg_evt_payload_t *jpeg_job =
2178 (qcamera_jpeg_evt_payload_t *)payload;
2179 rc = m_parent->processJpegNotify(jpeg_job);
2180 }
2181 break;
2182 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
2183 {
2184 rc = m_parent->cancelLiveSnapshot();
2185 m_state = QCAMERA_SM_STATE_PREVIEWING;
2186 }
2187 break;
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08002188 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
Emilian Peeve1d5acb2013-02-01 11:29:53 -08002189 {
2190 rc = m_parent->updateThermalFPS((cam_fps_range_t *) payload);
2191 }
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08002192 break;
Muhua Libc9a8082012-11-07 15:51:28 -08002193 default:
2194 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
2195 break;
2196 }
2197
2198 return rc;
2199}
2200
Muhua Lida2c4be2012-11-26 09:14:16 -08002201/*===========================================================================
2202 * FUNCTION : isPreviewRunning
2203 *
2204 * DESCRIPTION: check if preview is in process.
2205 *
2206 * PARAMETERS : None
2207 *
2208 * RETURN : true -- preview running
2209 * false -- preview stopped
2210 *==========================================================================*/
2211bool QCameraStateMachine::isPreviewRunning()
2212{
2213 switch (m_state) {
2214 case QCAMERA_SM_STATE_PREVIEWING:
2215 case QCAMERA_SM_STATE_RECORDING:
2216 case QCAMERA_SM_STATE_VIDEO_PIC_TAKING:
2217 case QCAMERA_SM_STATE_PREVIEW_PIC_TAKING:
2218 return true;
2219 default:
2220 return false;
2221 }
2222}
2223
Shuzhen Wang89635cf2012-12-20 13:47:22 -08002224}; // namespace qcamera