blob: daa6c6e245c9a33a26d1b153c24b6ae553e3fa8d [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:
1064 //TODO: Adjust FPS.
1065 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001066 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
Muhua Lida2c4be2012-11-26 09:14:16 -08001067 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
Muhua Libc9a8082012-11-07 15:51:28 -08001068 default:
1069 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1070 break;
1071 }
1072
1073 return rc;
1074}
1075
Muhua Lida2c4be2012-11-26 09:14:16 -08001076/*===========================================================================
1077 * FUNCTION : procEvtPicTakingState
1078 *
1079 * DESCRIPTION: finite state machine function to handle event in state of
1080 * QCAMERA_SM_STATE_PIC_TAKING.
1081 *
1082 * PARAMETERS :
1083 * @evt : event to be processed
1084 * @payload : event payload. Can be NULL if not needed.
1085 *
1086 * RETURN : int32_t type of status
1087 * NO_ERROR -- success
1088 * none-zero failure code
1089 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -08001090int32_t QCameraStateMachine::procEvtPicTakingState(qcamera_sm_evt_enum_t evt,
1091 void *payload)
1092{
1093 int32_t rc = NO_ERROR;
1094 qcamera_api_result_t result;
1095 memset(&result, 0, sizeof(qcamera_api_result_t));
1096
1097 switch (evt) {
1098 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
1099 {
1100 // Error setting preview window during previewing
1101 ALOGE("Cannot set preview window when preview is running");
1102 rc = INVALID_OPERATION;
1103 result.status = rc;
1104 result.request_api = evt;
1105 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1106 m_parent->signalAPIResult(&result);
1107 }
1108 break;
1109 case QCAMERA_SM_EVT_SET_CALLBACKS:
1110 {
1111 qcamera_sm_evt_setcb_payload_t *setcbs =
1112 (qcamera_sm_evt_setcb_payload_t *)payload;
1113 rc = m_parent->setCallBacks(setcbs->notify_cb,
1114 setcbs->data_cb,
1115 setcbs->data_cb_timestamp,
1116 setcbs->get_memory,
1117 setcbs->user);
1118 result.status = rc;
1119 result.request_api = evt;
1120 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1121 m_parent->signalAPIResult(&result);
1122 }
1123 break;
1124 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
1125 {
1126 rc = m_parent->enableMsgType(int32_t(payload));
1127 result.status = rc;
1128 result.request_api = evt;
1129 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1130 m_parent->signalAPIResult(&result);
1131 }
1132 break;
1133 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
1134 {
1135 rc = m_parent->disableMsgType(int32_t(payload));
1136 result.status = rc;
1137 result.request_api = evt;
1138 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1139 m_parent->signalAPIResult(&result);
1140 }
1141 break;
1142 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
1143 {
1144 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
1145 result.status = rc;
1146 result.request_api = evt;
1147 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1148 result.enabled = enabled;
1149 m_parent->signalAPIResult(&result);
1150 }
1151 break;
1152 case QCAMERA_SM_EVT_SET_PARAMS:
1153 {
Muhua Lida2c4be2012-11-26 09:14:16 -08001154 bool needRestart = false;
1155 rc = m_parent->updateParameters((char*)payload, needRestart);
1156 if (rc == NO_ERROR) {
1157 rc = m_parent->commitParameterChanges();
1158 }
Muhua Libc9a8082012-11-07 15:51:28 -08001159 result.status = rc;
1160 result.request_api = evt;
1161 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1162 m_parent->signalAPIResult(&result);
1163 }
1164 break;
1165 case QCAMERA_SM_EVT_GET_PARAMS:
1166 {
1167 result.params = m_parent->getParameters();
1168 rc = NO_ERROR;
1169 result.status = rc;
1170 result.request_api = evt;
1171 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
1172 m_parent->signalAPIResult(&result);
1173 }
1174 break;
1175 case QCAMERA_SM_EVT_PUT_PARAMS:
1176 {
1177 rc = m_parent->putParameters((char*)payload);
1178 result.status = rc;
1179 result.request_api = evt;
1180 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1181 m_parent->signalAPIResult(&result);
1182 }
1183 break;
1184 case QCAMERA_SM_EVT_STOP_PREVIEW:
1185 {
1186 // no ops, since preview is stopped (normal),
1187 // or preview msg type is disabled (ZSL)
1188 rc = NO_ERROR;
1189 result.status = rc;
1190 result.request_api = evt;
1191 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1192 m_parent->signalAPIResult(&result);
1193 }
1194 break;
1195 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
1196 {
1197 rc = NO_ERROR;
1198 result.status = rc;
1199 result.request_api = evt;
1200 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1201 result.enabled = 0;
1202 m_parent->signalAPIResult(&result);
1203 }
1204 break;
1205 case QCAMERA_SM_EVT_RECORDING_ENABLED:
1206 {
1207 rc = NO_ERROR;
1208 result.status = rc;
1209 result.request_api = evt;
1210 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1211 result.enabled = 0;
1212 m_parent->signalAPIResult(&result);
1213 }
1214 break;
1215 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
1216 {
1217 rc = m_parent->storeMetaDataInBuffers(int(payload));
1218 result.status = rc;
1219 result.request_api = evt;
1220 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1221 m_parent->signalAPIResult(&result);
1222 }
1223 break;
1224 case QCAMERA_SM_EVT_DUMP:
1225 {
1226 rc = m_parent->dump((int)payload);
1227 result.status = rc;
1228 result.request_api = evt;
1229 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1230 m_parent->signalAPIResult(&result);
1231 }
1232 break;
1233 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
1234 {
1235 rc = m_parent->autoFocus();
1236 result.status = rc;
1237 result.request_api = evt;
1238 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1239 m_parent->signalAPIResult(&result);
1240 }
1241 break;
1242 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
1243 {
1244 rc = m_parent->cancelAutoFocus();
1245 result.status = rc;
1246 result.request_api = evt;
1247 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1248 m_parent->signalAPIResult(&result);
1249 }
1250 break;
1251 case QCAMERA_SM_EVT_SEND_COMMAND:
1252 {
1253 qcamera_sm_evt_command_payload_t *cmd_payload =
1254 (qcamera_sm_evt_command_payload_t *)payload;
1255 rc = m_parent->sendCommand(cmd_payload->cmd,
1256 cmd_payload->arg1,
1257 cmd_payload->arg2);
1258 result.status = rc;
1259 result.request_api = evt;
1260 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1261 m_parent->signalAPIResult(&result);
1262 }
1263 break;
1264 case QCAMERA_SM_EVT_CANCEL_PICTURE:
1265 {
1266 rc = m_parent->cancelPicture();
1267 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
1268 result.status = rc;
1269 result.request_api = evt;
1270 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1271 m_parent->signalAPIResult(&result);
1272 }
1273 break;
1274 case QCAMERA_SM_EVT_TAKE_PICTURE:
1275 case QCAMERA_SM_EVT_START_RECORDING:
1276 case QCAMERA_SM_EVT_STOP_RECORDING:
1277 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
1278 case QCAMERA_SM_EVT_START_PREVIEW:
1279 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
1280 case QCAMERA_SM_EVT_RELEASE:
1281 {
1282 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1283 rc = INVALID_OPERATION;
1284 result.status = rc;
1285 result.request_api = evt;
1286 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1287 m_parent->signalAPIResult(&result);
1288 }
1289 break;
Muhua Li31eaee02012-12-11 08:56:45 -08001290 case QCAMERA_SM_EVT_EVT_INTERNAL:
1291 {
1292 qcamera_sm_internal_evt_payload_t *internal_evt =
1293 (qcamera_sm_internal_evt_payload_t *)payload;
1294 switch (internal_evt->evt_type) {
1295 case QCAMERA_INTERNAL_EVT_FOCUS_UPDATE:
1296 rc = m_parent->processAutoFocusEvent(internal_evt->focus_data);
1297 break;
1298 default:
1299 break;
1300 }
1301 }
1302 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001303 case QCAMERA_SM_EVT_EVT_NOTIFY:
1304 {
1305 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
1306 switch (cam_evt->server_event_type) {
Muhua Libc9a8082012-11-07 15:51:28 -08001307 case CAM_EVENT_TYPE_ZOOM_DONE:
1308 rc = m_parent->processZoomEvent(cam_evt->status);
1309 break;
1310 default:
1311 ALOGD("%s: no handling for server evt (%d) at this state",
1312 __func__, cam_evt->server_event_type);
1313 break;
1314 }
1315 }
1316 break;
1317 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
1318 {
1319 qcamera_jpeg_evt_payload_t *jpeg_job =
1320 (qcamera_jpeg_evt_payload_t *)payload;
1321 rc = m_parent->processJpegNotify(jpeg_job);
1322 }
1323 break;
1324 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
1325 {
1326 rc = m_parent->cancelPicture();
1327 m_state = QCAMERA_SM_STATE_PREVIEW_STOPPED;
1328 }
1329 break;
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08001330 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
Muhua Libc9a8082012-11-07 15:51:28 -08001331 default:
1332 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1333 break;
1334 }
1335
1336 return rc;
1337}
1338
Muhua Lida2c4be2012-11-26 09:14:16 -08001339/*===========================================================================
1340 * FUNCTION : procEvtRecordingState
1341 *
1342 * DESCRIPTION: finite state machine function to handle event in state of
1343 * QCAMERA_SM_STATE_RECORDING.
1344 *
1345 * PARAMETERS :
1346 * @evt : event to be processed
1347 * @payload : event payload. Can be NULL if not needed.
1348 *
1349 * RETURN : int32_t type of status
1350 * NO_ERROR -- success
1351 * none-zero failure code
1352 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -08001353int32_t QCameraStateMachine::procEvtRecordingState(qcamera_sm_evt_enum_t evt,
1354 void *payload)
1355{
1356 int32_t rc = NO_ERROR;
1357 qcamera_api_result_t result;
1358 memset(&result, 0, sizeof(qcamera_api_result_t));
1359
1360 switch (evt) {
1361 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
1362 {
1363 // Error setting preview window during previewing
1364 ALOGE("Cannot set preview window when preview is running");
1365 rc = INVALID_OPERATION;
1366 result.status = rc;
1367 result.request_api = evt;
1368 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1369 m_parent->signalAPIResult(&result);
1370 }
1371 break;
1372 case QCAMERA_SM_EVT_SET_CALLBACKS:
1373 {
1374 qcamera_sm_evt_setcb_payload_t *setcbs =
1375 (qcamera_sm_evt_setcb_payload_t *)payload;
1376 rc = m_parent->setCallBacks(setcbs->notify_cb,
1377 setcbs->data_cb,
1378 setcbs->data_cb_timestamp,
1379 setcbs->get_memory,
1380 setcbs->user);
1381 result.status = rc;
1382 result.request_api = evt;
1383 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1384 m_parent->signalAPIResult(&result);
1385 }
1386 break;
1387 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
1388 {
1389 rc = m_parent->enableMsgType(int32_t(payload));
1390 result.status = rc;
1391 result.request_api = evt;
1392 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1393 m_parent->signalAPIResult(&result);
1394 }
1395 break;
1396 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
1397 {
1398 rc = m_parent->disableMsgType(int32_t(payload));
1399 result.status = rc;
1400 result.request_api = evt;
1401 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1402 m_parent->signalAPIResult(&result);
1403 }
1404 break;
1405 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
1406 {
1407 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
1408 result.status = rc;
1409 result.request_api = evt;
1410 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1411 result.enabled = enabled;
1412 m_parent->signalAPIResult(&result);
1413 }
1414 break;
1415 case QCAMERA_SM_EVT_SET_PARAMS:
1416 {
Muhua Lida2c4be2012-11-26 09:14:16 -08001417 bool needRestart = false;
1418 rc = m_parent->updateParameters((char*)payload, needRestart);
1419 if (rc == NO_ERROR) {
1420 if (needRestart) {
1421 // cannot set parameters that requires restart during recording
1422 ALOGE("%s: Cannot set parameters that requires restart during recording",
1423 __func__);
1424 rc = BAD_VALUE;
1425 } else {
1426 rc = m_parent->commitParameterChanges();
1427 }
1428 }
Muhua Libc9a8082012-11-07 15:51:28 -08001429 result.status = rc;
1430 result.request_api = evt;
1431 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1432 m_parent->signalAPIResult(&result);
1433 }
1434 break;
1435 case QCAMERA_SM_EVT_GET_PARAMS:
1436 {
1437 result.params = m_parent->getParameters();
1438 rc = NO_ERROR;
1439 result.status = rc;
1440 result.request_api = evt;
1441 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
1442 m_parent->signalAPIResult(&result);
1443 }
1444 break;
1445 case QCAMERA_SM_EVT_PUT_PARAMS:
1446 {
1447 rc = m_parent->putParameters((char*)payload);
1448 result.status = rc;
1449 result.request_api = evt;
1450 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1451 m_parent->signalAPIResult(&result);
1452 }
1453 break;
1454 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
1455 {
1456 rc = NO_ERROR;
1457 result.status = rc;
1458 result.request_api = evt;
1459 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1460 result.enabled = 0;
1461 m_parent->signalAPIResult(&result);
1462 }
1463 break;
1464 case QCAMERA_SM_EVT_RECORDING_ENABLED:
1465 {
1466 rc = NO_ERROR;
1467 result.status = rc;
1468 result.request_api = evt;
1469 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1470 result.enabled = 1;
1471 m_parent->signalAPIResult(&result);
1472 }
1473 break;
1474 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
1475 {
1476 rc = m_parent->storeMetaDataInBuffers(int(payload));
1477 result.status = rc;
1478 result.request_api = evt;
1479 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1480 m_parent->signalAPIResult(&result);
1481 }
1482 break;
1483 case QCAMERA_SM_EVT_DUMP:
1484 {
1485 rc = m_parent->dump((int)payload);
1486 result.status = rc;
1487 result.request_api = evt;
1488 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1489 m_parent->signalAPIResult(&result);
1490 }
1491 break;
1492 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
1493 {
1494 rc = m_parent->autoFocus();
1495 result.status = rc;
1496 result.request_api = evt;
1497 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1498 m_parent->signalAPIResult(&result);
1499 }
1500 break;
1501 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
1502 {
1503 rc = m_parent->cancelAutoFocus();
1504 result.status = rc;
1505 result.request_api = evt;
1506 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1507 m_parent->signalAPIResult(&result);
1508 }
1509 break;
1510 case QCAMERA_SM_EVT_SEND_COMMAND:
1511 {
1512 qcamera_sm_evt_command_payload_t *cmd_payload =
1513 (qcamera_sm_evt_command_payload_t *)payload;
1514 rc = m_parent->sendCommand(cmd_payload->cmd,
1515 cmd_payload->arg1,
1516 cmd_payload->arg2);
1517 result.status = rc;
1518 result.request_api = evt;
1519 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1520 m_parent->signalAPIResult(&result);
1521 }
1522 break;
1523 case QCAMERA_SM_EVT_TAKE_PICTURE:
1524 {
1525 rc = m_parent->takeLiveSnapshot();
1526 if (rc == 0) {
1527 m_state = QCAMERA_SM_STATE_VIDEO_PIC_TAKING;
1528 }
1529 result.status = rc;
1530 result.request_api = evt;
1531 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1532 m_parent->signalAPIResult(&result);
1533 }
1534 break;
1535 case QCAMERA_SM_EVT_START_RECORDING:
1536 {
1537 // no ops here
1538 ALOGD("%s: already in recording state, no ops for start_recording", __func__);
1539 rc = 0;
1540 result.status = rc;
1541 result.request_api = evt;
1542 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1543 m_parent->signalAPIResult(&result);
1544 }
1545 break;
1546 case QCAMERA_SM_EVT_STOP_RECORDING:
1547 {
1548 rc = m_parent->stopRecording();
1549 m_state = QCAMERA_SM_STATE_PREVIEWING;
1550 result.status = rc;
1551 result.request_api = evt;
1552 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1553 m_parent->signalAPIResult(&result);
1554 }
1555 break;
1556 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
1557 {
1558 rc = m_parent->releaseRecordingFrame((const void *)payload);
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_CANCEL_PICTURE:
1566 case QCAMERA_SM_EVT_START_PREVIEW:
1567 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
1568 case QCAMERA_SM_EVT_STOP_PREVIEW:
1569 case QCAMERA_SM_EVT_RELEASE:
1570 {
1571 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1572 rc = INVALID_OPERATION;
1573 result.status = rc;
1574 result.request_api = evt;
1575 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1576 m_parent->signalAPIResult(&result);
1577 }
1578 break;
Muhua Li31eaee02012-12-11 08:56:45 -08001579 case QCAMERA_SM_EVT_EVT_INTERNAL:
1580 {
1581 qcamera_sm_internal_evt_payload_t *internal_evt =
1582 (qcamera_sm_internal_evt_payload_t *)payload;
1583 switch (internal_evt->evt_type) {
1584 case QCAMERA_INTERNAL_EVT_FOCUS_UPDATE:
1585 rc = m_parent->processAutoFocusEvent(internal_evt->focus_data);
1586 break;
1587 default:
1588 break;
1589 }
1590 }
1591 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001592 case QCAMERA_SM_EVT_EVT_NOTIFY:
1593 {
1594 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
1595 switch (cam_evt->server_event_type) {
Muhua Libc9a8082012-11-07 15:51:28 -08001596 case CAM_EVENT_TYPE_ZOOM_DONE:
1597 rc = m_parent->processZoomEvent(cam_evt->status);
1598 break;
1599 default:
1600 ALOGD("%s: no handling for server evt (%d) at this state",
1601 __func__, cam_evt->server_event_type);
1602 break;
1603 }
1604 }
1605 break;
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08001606 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
1607 //TODO: Adjust FPS
1608 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001609 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
Muhua Lida2c4be2012-11-26 09:14:16 -08001610 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
Muhua Libc9a8082012-11-07 15:51:28 -08001611 default:
1612 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1613 break;
1614 }
1615
1616 return rc;
1617}
1618
Muhua Lida2c4be2012-11-26 09:14:16 -08001619/*===========================================================================
1620 * FUNCTION : procEvtVideoPicTakingState
1621 *
1622 * DESCRIPTION: finite state machine function to handle event in state of
1623 * QCAMERA_SM_STATE_VIDEO_PIC_TAKING.
1624 *
1625 * PARAMETERS :
1626 * @evt : event to be processed
1627 * @payload : event payload. Can be NULL if not needed.
1628 *
1629 * RETURN : int32_t type of status
1630 * NO_ERROR -- success
1631 * none-zero failure code
1632 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -08001633int32_t QCameraStateMachine::procEvtVideoPicTakingState(qcamera_sm_evt_enum_t evt,
1634 void *payload)
1635{
1636 int32_t rc = NO_ERROR;
1637 qcamera_api_result_t result;
1638 memset(&result, 0, sizeof(qcamera_api_result_t));
1639
1640 switch (evt) {
1641 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
1642 {
1643 // Error setting preview window during previewing
1644 ALOGE("Cannot set preview window when preview is running");
1645 rc = INVALID_OPERATION;
1646 result.status = rc;
1647 result.request_api = evt;
1648 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1649 m_parent->signalAPIResult(&result);
1650 }
1651 break;
1652 case QCAMERA_SM_EVT_SET_CALLBACKS:
1653 {
1654 qcamera_sm_evt_setcb_payload_t *setcbs =
1655 (qcamera_sm_evt_setcb_payload_t *)payload;
1656 rc = m_parent->setCallBacks(setcbs->notify_cb,
1657 setcbs->data_cb,
1658 setcbs->data_cb_timestamp,
1659 setcbs->get_memory,
1660 setcbs->user);
1661 result.status = rc;
1662 result.request_api = evt;
1663 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1664 m_parent->signalAPIResult(&result);
1665 }
1666 break;
1667 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
1668 {
1669 rc = m_parent->enableMsgType(int32_t(payload));
1670 result.status = rc;
1671 result.request_api = evt;
1672 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1673 m_parent->signalAPIResult(&result);
1674 }
1675 break;
1676 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
1677 {
1678 rc = m_parent->disableMsgType(int32_t(payload));
1679 result.status = rc;
1680 result.request_api = evt;
1681 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1682 m_parent->signalAPIResult(&result);
1683 }
1684 break;
1685 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
1686 {
1687 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
1688 result.status = rc;
1689 result.request_api = evt;
1690 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1691 result.enabled = enabled;
1692 m_parent->signalAPIResult(&result);
1693 }
1694 break;
1695 case QCAMERA_SM_EVT_SET_PARAMS:
1696 {
Muhua Lida2c4be2012-11-26 09:14:16 -08001697 bool needRestart = false;
1698 rc = m_parent->updateParameters((char*)payload, needRestart);
1699 if (rc == NO_ERROR) {
1700 if (needRestart) {
1701 // cannot set parameters that requires restart during recording
1702 ALOGE("%s: Cannot set parameters that requires restart during recording",
1703 __func__);
1704 rc = BAD_VALUE;
1705 } else {
1706 rc = m_parent->commitParameterChanges();
1707 }
1708 }
Muhua Libc9a8082012-11-07 15:51:28 -08001709 result.status = rc;
1710 result.request_api = evt;
1711 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1712 m_parent->signalAPIResult(&result);
1713 }
1714 break;
1715 case QCAMERA_SM_EVT_GET_PARAMS:
1716 {
1717 result.params = m_parent->getParameters();
1718 rc = NO_ERROR;
1719 result.status = rc;
1720 result.request_api = evt;
1721 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
1722 m_parent->signalAPIResult(&result);
1723 }
1724 break;
1725 case QCAMERA_SM_EVT_PUT_PARAMS:
1726 {
1727 rc = m_parent->putParameters((char*)payload);
1728 result.status = rc;
1729 result.request_api = evt;
1730 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1731 m_parent->signalAPIResult(&result);
1732 }
1733 break;
1734 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
1735 {
1736 rc = NO_ERROR;
1737 result.status = rc;
1738 result.request_api = evt;
1739 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1740 result.enabled = 1;
1741 m_parent->signalAPIResult(&result);
1742 }
1743 break;
1744 case QCAMERA_SM_EVT_RECORDING_ENABLED:
1745 {
1746 rc = NO_ERROR;
1747 result.status = rc;
1748 result.request_api = evt;
1749 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1750 result.enabled = 1;
1751 m_parent->signalAPIResult(&result);
1752 }
1753 break;
1754 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
1755 {
1756 rc = m_parent->storeMetaDataInBuffers(int(payload));
1757 result.status = rc;
1758 result.request_api = evt;
1759 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1760 m_parent->signalAPIResult(&result);
1761 }
1762 break;
1763 case QCAMERA_SM_EVT_DUMP:
1764 {
1765 rc = m_parent->dump((int)payload);
1766 result.status = rc;
1767 result.request_api = evt;
1768 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1769 m_parent->signalAPIResult(&result);
1770 }
1771 break;
1772 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
1773 {
1774 rc = m_parent->autoFocus();
1775 result.status = rc;
1776 result.request_api = evt;
1777 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1778 m_parent->signalAPIResult(&result);
1779 }
1780 break;
1781 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
1782 {
1783 rc = m_parent->cancelAutoFocus();
1784 result.status = rc;
1785 result.request_api = evt;
1786 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1787 m_parent->signalAPIResult(&result);
1788 }
1789 break;
1790 case QCAMERA_SM_EVT_SEND_COMMAND:
1791 {
1792 qcamera_sm_evt_command_payload_t *cmd_payload =
1793 (qcamera_sm_evt_command_payload_t *)payload;
1794 rc = m_parent->sendCommand(cmd_payload->cmd,
1795 cmd_payload->arg1,
1796 cmd_payload->arg2);
1797 result.status = rc;
1798 result.request_api = evt;
1799 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1800 m_parent->signalAPIResult(&result);
1801 }
1802 break;
1803 case QCAMERA_SM_EVT_STOP_RECORDING:
1804 {
1805 rc = m_parent->stopRecording();
1806 m_state = QCAMERA_SM_STATE_PREVIEW_PIC_TAKING;
1807 result.status = rc;
1808 result.request_api = evt;
1809 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1810 m_parent->signalAPIResult(&result);
1811 }
1812 break;
1813 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
1814 {
1815 rc = m_parent->releaseRecordingFrame((const void *)payload);
1816 result.status = rc;
1817 result.request_api = evt;
1818 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1819 m_parent->signalAPIResult(&result);
1820 }
1821 break;
1822 case QCAMERA_SM_EVT_CANCEL_PICTURE:
1823 {
1824 rc = m_parent->cancelLiveSnapshot();
1825 m_state = QCAMERA_SM_STATE_RECORDING;
1826 result.status = rc;
1827 result.request_api = evt;
1828 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1829 m_parent->signalAPIResult(&result);
1830 }
1831 break;
1832 case QCAMERA_SM_EVT_START_RECORDING:
1833 case QCAMERA_SM_EVT_START_PREVIEW:
1834 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
1835 case QCAMERA_SM_EVT_STOP_PREVIEW:
1836 case QCAMERA_SM_EVT_TAKE_PICTURE:
1837 case QCAMERA_SM_EVT_RELEASE:
1838 {
1839 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1840 rc = INVALID_OPERATION;
1841 result.status = rc;
1842 result.request_api = evt;
1843 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1844 m_parent->signalAPIResult(&result);
1845 }
1846 break;
Muhua Li31eaee02012-12-11 08:56:45 -08001847 case QCAMERA_SM_EVT_EVT_INTERNAL:
1848 {
1849 qcamera_sm_internal_evt_payload_t *internal_evt =
1850 (qcamera_sm_internal_evt_payload_t *)payload;
1851 switch (internal_evt->evt_type) {
1852 case QCAMERA_INTERNAL_EVT_FOCUS_UPDATE:
1853 rc = m_parent->processAutoFocusEvent(internal_evt->focus_data);
1854 break;
1855 default:
1856 break;
1857 }
1858 }
1859 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001860 case QCAMERA_SM_EVT_EVT_NOTIFY:
1861 {
1862 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
1863 switch (cam_evt->server_event_type) {
Muhua Libc9a8082012-11-07 15:51:28 -08001864 case CAM_EVENT_TYPE_ZOOM_DONE:
1865 rc = m_parent->processZoomEvent(cam_evt->status);
1866 break;
1867 default:
1868 ALOGD("%s: no handling for server evt (%d) at this state",
1869 __func__, cam_evt->server_event_type);
1870 break;
1871 }
1872 }
1873 break;
1874 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
1875 {
1876 qcamera_jpeg_evt_payload_t *jpeg_job =
1877 (qcamera_jpeg_evt_payload_t *)payload;
1878 rc = m_parent->processJpegNotify(jpeg_job);
1879 }
1880 break;
1881 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
1882 {
1883 rc = m_parent->cancelLiveSnapshot();
1884 m_state = QCAMERA_SM_STATE_RECORDING;
1885 }
1886 break;
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08001887 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
1888 //TODO: Adjust FPS.
1889 break;
Muhua Libc9a8082012-11-07 15:51:28 -08001890 default:
1891 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
1892 break;
1893 }
1894
1895 return rc;
1896}
1897
Muhua Lida2c4be2012-11-26 09:14:16 -08001898/*===========================================================================
1899 * FUNCTION : procEvtPreviewPicTakingState
1900 *
1901 * DESCRIPTION: finite state machine function to handle event in state of
1902 * QCAMERA_SM_STATE_PREVIEW_PIC_TAKING.
1903 *
1904 * PARAMETERS :
1905 * @evt : event to be processed
1906 * @payload : event payload. Can be NULL if not needed.
1907 *
1908 * RETURN : int32_t type of status
1909 * NO_ERROR -- success
1910 * none-zero failure code
1911 *==========================================================================*/
Muhua Libc9a8082012-11-07 15:51:28 -08001912int32_t QCameraStateMachine::procEvtPreviewPicTakingState(qcamera_sm_evt_enum_t evt,
1913 void *payload)
1914{
1915 int32_t rc = NO_ERROR;
1916 qcamera_api_result_t result;
1917 memset(&result, 0, sizeof(qcamera_api_result_t));
1918
1919 switch (evt) {
1920 case QCAMERA_SM_EVT_SET_CALLBACKS:
1921 {
1922 qcamera_sm_evt_setcb_payload_t *setcbs =
1923 (qcamera_sm_evt_setcb_payload_t *)payload;
1924 rc = m_parent->setCallBacks(setcbs->notify_cb,
1925 setcbs->data_cb,
1926 setcbs->data_cb_timestamp,
1927 setcbs->get_memory,
1928 setcbs->user);
1929 result.status = rc;
1930 result.request_api = evt;
1931 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1932 m_parent->signalAPIResult(&result);
1933 }
1934 break;
1935 case QCAMERA_SM_EVT_ENABLE_MSG_TYPE:
1936 {
1937 rc = m_parent->enableMsgType(int32_t(payload));
1938 result.status = rc;
1939 result.request_api = evt;
1940 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1941 m_parent->signalAPIResult(&result);
1942 }
1943 break;
1944 case QCAMERA_SM_EVT_DISABLE_MSG_TYPE:
1945 {
1946 rc = m_parent->disableMsgType(int32_t(payload));
1947 result.status = rc;
1948 result.request_api = evt;
1949 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1950 m_parent->signalAPIResult(&result);
1951 }
1952 break;
1953 case QCAMERA_SM_EVT_MSG_TYPE_ENABLED:
1954 {
1955 int enabled = m_parent->msgTypeEnabled(int32_t(payload));
1956 result.status = rc;
1957 result.request_api = evt;
1958 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
1959 result.enabled = enabled;
1960 m_parent->signalAPIResult(&result);
1961 }
1962 break;
1963 case QCAMERA_SM_EVT_SET_PARAMS:
1964 {
Muhua Lida2c4be2012-11-26 09:14:16 -08001965 bool needRestart = false;
1966 rc = m_parent->updateParameters((char*)payload, needRestart);
1967 if (rc == NO_ERROR) {
1968 if (needRestart) {
1969 // need restart preview for parameters to take effect
1970 // stop preview
1971 m_parent->stopPreview();
1972 // commit parameter changes to server
Muhua Li66f3b532013-01-23 17:19:05 -08001973 m_parent->commitParameterChanges();
Muhua Lida2c4be2012-11-26 09:14:16 -08001974 // start preview again
Muhua Li66f3b532013-01-23 17:19:05 -08001975 rc = m_parent->preparePreview();
1976 if (rc == NO_ERROR) {
1977 rc = m_parent->startPreview();
1978 if (rc != NO_ERROR) {
1979 m_parent->unpreparePreview();
1980 }
1981 }
1982 if (rc != NO_ERROR) {
1983 m_state = QCAMERA_SM_STATE_PIC_TAKING;
1984 }
Muhua Lida2c4be2012-11-26 09:14:16 -08001985 } else {
1986 rc = m_parent->commitParameterChanges();
1987 }
1988 }
Muhua Libc9a8082012-11-07 15:51:28 -08001989 result.status = rc;
1990 result.request_api = evt;
1991 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
1992 m_parent->signalAPIResult(&result);
1993 }
1994 break;
1995 case QCAMERA_SM_EVT_GET_PARAMS:
1996 {
1997 result.params = m_parent->getParameters();
1998 rc = NO_ERROR;
1999 result.status = rc;
2000 result.request_api = evt;
2001 result.result_type = QCAMERA_API_RESULT_TYPE_PARAMS;
2002 m_parent->signalAPIResult(&result);
2003 }
2004 break;
2005 case QCAMERA_SM_EVT_PUT_PARAMS:
2006 {
2007 rc = m_parent->putParameters((char*)payload);
2008 result.status = rc;
2009 result.request_api = evt;
2010 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2011 m_parent->signalAPIResult(&result);
2012 }
2013 break;
2014 case QCAMERA_SM_EVT_PREVIEW_ENABLED:
2015 {
2016 rc = NO_ERROR;
2017 result.status = rc;
2018 result.request_api = evt;
2019 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
2020 result.enabled = 1;
2021 m_parent->signalAPIResult(&result);
2022 }
2023 break;
2024 case QCAMERA_SM_EVT_RECORDING_ENABLED:
2025 {
2026 rc = NO_ERROR;
2027 result.status = rc;
2028 result.request_api = evt;
2029 result.result_type = QCAMERA_API_RESULT_TYPE_ENABLE_FLAG;
2030 result.enabled = 0;
2031 m_parent->signalAPIResult(&result);
2032 }
2033 break;
2034 case QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS:
2035 {
2036 rc = m_parent->storeMetaDataInBuffers(int(payload));
2037 result.status = rc;
2038 result.request_api = evt;
2039 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2040 m_parent->signalAPIResult(&result);
2041 }
2042 break;
2043 case QCAMERA_SM_EVT_DUMP:
2044 {
2045 rc = m_parent->dump((int)payload);
2046 result.status = rc;
2047 result.request_api = evt;
2048 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2049 m_parent->signalAPIResult(&result);
2050 }
2051 break;
2052 case QCAMERA_SM_EVT_START_AUTO_FOCUS:
2053 {
2054 rc = m_parent->autoFocus();
2055 result.status = rc;
2056 result.request_api = evt;
2057 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2058 m_parent->signalAPIResult(&result);
2059 }
2060 break;
2061 case QCAMERA_SM_EVT_STOP_AUTO_FOCUS:
2062 {
2063 rc = m_parent->cancelAutoFocus();
2064 result.status = rc;
2065 result.request_api = evt;
2066 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2067 m_parent->signalAPIResult(&result);
2068 }
2069 break;
2070 case QCAMERA_SM_EVT_SEND_COMMAND:
2071 {
2072 qcamera_sm_evt_command_payload_t *cmd_payload =
2073 (qcamera_sm_evt_command_payload_t *)payload;
2074 rc = m_parent->sendCommand(cmd_payload->cmd,
2075 cmd_payload->arg1,
2076 cmd_payload->arg2);
2077 result.status = rc;
2078 result.request_api = evt;
2079 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2080 m_parent->signalAPIResult(&result);
2081 }
2082 break;
2083 case QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME:
2084 {
2085 rc = m_parent->releaseRecordingFrame((const void *)payload);
2086 result.status = rc;
2087 result.request_api = evt;
2088 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2089 m_parent->signalAPIResult(&result);
2090 }
2091 break;
2092 case QCAMERA_SM_EVT_CANCEL_PICTURE:
2093 {
2094 rc = m_parent->cancelLiveSnapshot();
2095 m_state = QCAMERA_SM_STATE_PREVIEWING;
2096 result.status = rc;
2097 result.request_api = evt;
2098 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2099 m_parent->signalAPIResult(&result);
2100 }
2101 break;
2102 case QCAMERA_SM_EVT_STOP_PREVIEW:
2103 {
2104 m_parent->stopChannel(QCAMERA_CH_TYPE_PREVIEW);
2105 m_parent->delChannel(QCAMERA_CH_TYPE_PREVIEW);
2106 m_parent->delChannel(QCAMERA_CH_TYPE_VIDEO);
2107 m_state = QCAMERA_SM_STATE_PIC_TAKING;
2108 rc = NO_ERROR;
2109 result.status = rc;
2110 result.request_api = evt;
2111 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2112 m_parent->signalAPIResult(&result);
2113 }
2114 break;
2115 case QCAMERA_SM_EVT_START_RECORDING:
2116 {
2117 rc = m_parent->stopRecording();
2118 if (rc == NO_ERROR) {
2119 m_state = QCAMERA_SM_STATE_VIDEO_PIC_TAKING;
2120 }
2121 result.status = rc;
2122 result.request_api = evt;
2123 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2124 m_parent->signalAPIResult(&result);
2125 }
2126 break;
2127 case QCAMERA_SM_EVT_STOP_RECORDING:
2128 case QCAMERA_SM_EVT_START_PREVIEW:
2129 case QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW:
2130 case QCAMERA_SM_EVT_TAKE_PICTURE:
2131 case QCAMERA_SM_EVT_SET_PREVIEW_WINDOW:
2132 case QCAMERA_SM_EVT_RELEASE:
2133 {
2134 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
2135 rc = INVALID_OPERATION;
2136 result.status = rc;
2137 result.request_api = evt;
2138 result.result_type = QCAMERA_API_RESULT_TYPE_DEF;
2139 m_parent->signalAPIResult(&result);
2140 }
2141 break;
Muhua Li31eaee02012-12-11 08:56:45 -08002142 case QCAMERA_SM_EVT_EVT_INTERNAL:
2143 {
2144 qcamera_sm_internal_evt_payload_t *internal_evt =
2145 (qcamera_sm_internal_evt_payload_t *)payload;
2146 switch (internal_evt->evt_type) {
2147 case QCAMERA_INTERNAL_EVT_FOCUS_UPDATE:
2148 rc = m_parent->processAutoFocusEvent(internal_evt->focus_data);
2149 break;
2150 default:
2151 break;
2152 }
2153 }
2154 break;
Muhua Libc9a8082012-11-07 15:51:28 -08002155 case QCAMERA_SM_EVT_EVT_NOTIFY:
2156 {
2157 mm_camera_event_t *cam_evt = (mm_camera_event_t *)payload;
2158 switch (cam_evt->server_event_type) {
Muhua Libc9a8082012-11-07 15:51:28 -08002159 case CAM_EVENT_TYPE_ZOOM_DONE:
2160 rc = m_parent->processZoomEvent(cam_evt->status);
2161 break;
2162 default:
2163 ALOGD("%s: no handling for server evt (%d) at this state",
2164 __func__, cam_evt->server_event_type);
2165 break;
2166 }
2167 }
2168 break;
2169 case QCAMERA_SM_EVT_JPEG_EVT_NOTIFY:
2170 {
2171 qcamera_jpeg_evt_payload_t *jpeg_job =
2172 (qcamera_jpeg_evt_payload_t *)payload;
2173 rc = m_parent->processJpegNotify(jpeg_job);
2174 }
2175 break;
2176 case QCAMERA_SM_EVT_SNAPSHOT_DONE:
2177 {
2178 rc = m_parent->cancelLiveSnapshot();
2179 m_state = QCAMERA_SM_STATE_PREVIEWING;
2180 }
2181 break;
Shuzhen Wangaa829ce2013-01-09 14:41:49 -08002182 case QCAMERA_SM_EVT_THERMAL_NOTIFY:
2183 //TODO: Adjust FPS
2184 break;
Muhua Libc9a8082012-11-07 15:51:28 -08002185 default:
2186 ALOGE("%s: cannot handle evt(%d) in state(%d)", __func__, evt, m_state);
2187 break;
2188 }
2189
2190 return rc;
2191}
2192
Muhua Lida2c4be2012-11-26 09:14:16 -08002193/*===========================================================================
2194 * FUNCTION : isPreviewRunning
2195 *
2196 * DESCRIPTION: check if preview is in process.
2197 *
2198 * PARAMETERS : None
2199 *
2200 * RETURN : true -- preview running
2201 * false -- preview stopped
2202 *==========================================================================*/
2203bool QCameraStateMachine::isPreviewRunning()
2204{
2205 switch (m_state) {
2206 case QCAMERA_SM_STATE_PREVIEWING:
2207 case QCAMERA_SM_STATE_RECORDING:
2208 case QCAMERA_SM_STATE_VIDEO_PIC_TAKING:
2209 case QCAMERA_SM_STATE_PREVIEW_PIC_TAKING:
2210 return true;
2211 default:
2212 return false;
2213 }
2214}
2215
Shuzhen Wang89635cf2012-12-20 13:47:22 -08002216}; // namespace qcamera