16f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev/* Copyright (c) 2012-2013, The Linux Foundataion. All rights reserved.
26f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
36f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * Redistribution and use in source and binary forms, with or without
46f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * modification, are permitted provided that the following conditions are
56f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * met:
66f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *     * Redistributions of source code must retain the above copyright
76f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *       notice, this list of conditions and the following disclaimer.
86f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *     * Redistributions in binary form must reproduce the above
96f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *       copyright notice, this list of conditions and the following
106f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *       disclaimer in the documentation and/or other materials provided
116f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *       with the distribution.
126f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *     * Neither the name of The Linux Foundation nor the names of its
136f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *       contributors may be used to endorse or promote products derived
146f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *       from this software without specific prior written permission.
156f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
166f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
176f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
186f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
196f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
206f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
216f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
226f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
236f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
246f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
256f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
266f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
286f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev */
296f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
306f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#ifndef __QCAMERA_STATEMACHINE_H__
316f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#define __QCAMERA_STATEMACHINE_H__
326f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
336f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#include <pthread.h>
346f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
356f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#include <cam_semaphore.h>
366f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevextern "C" {
376f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#include <mm_camera_interface.h>
386f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev}
396f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
406f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#include "QCameraQueue.h"
416f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#include "QCameraChannel.h"
426f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
436f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevnamespace qcamera {
446f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
456f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevclass QCamera2HardwareInterface;
466f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
476f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevtypedef enum {
486f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    /*******BEGIN OF: API EVT*********/
496f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_SET_PREVIEW_WINDOW = 1,   // set preview window
506f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_SET_CALLBACKS,            // set callbacks
516f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_ENABLE_MSG_TYPE,          // enable msg type
526f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_DISABLE_MSG_TYPE,         // disable msg type
536f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_MSG_TYPE_ENABLED,         // query certain msg type is enabled
546f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
556f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_SET_PARAMS,               // set parameters
566f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_GET_PARAMS,               // get parameters
576f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_PUT_PARAMS,               // put parameters, release param buf
586f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
596f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_START_PREVIEW,            // start preview (zsl, camera mode, camcorder mode)
606f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW,  // start no display preview (zsl, camera mode, camcorder mode)
616f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_STOP_PREVIEW,             // stop preview (zsl, camera mode, camcorder mode)
626f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_PREVIEW_ENABLED,          // query if preview is running
636f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
646f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS,   // request to store meta data in video buffers
656f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_START_RECORDING,          // start recording
666f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_STOP_RECORDING,           // stop recording
676f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_RECORDING_ENABLED,        // query if recording is running
686f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME,  // release recording frame
696f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
706f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_PREPARE_SNAPSHOT,         // prepare snapshot in case LED needs to be flashed
716f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_TAKE_PICTURE,             // take picutre (zsl, regualr capture, live snapshot
726f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_CANCEL_PICTURE,           // cancel picture
736f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
746f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_START_AUTO_FOCUS,         // start auto focus
756f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_STOP_AUTO_FOCUS,          // stop auto focus
766f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_SEND_COMMAND,             // send command
776f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
786f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_RELEASE,                  // release camera resource
796f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_DUMP,                     // dump
806f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_REG_FACE_IMAGE,           // register a face image in imaging lib
816f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    /*******END OF: API EVT*********/
826f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
836f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_EVT_INTERNAL,             // internal evt notify
846f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_EVT_NOTIFY,               // evt notify from server
856f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_JPEG_EVT_NOTIFY,          // evt notify from jpeg
866f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_SNAPSHOT_DONE,            // internal evt that snapshot is done
876f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_THERMAL_NOTIFY,           // evt notify from thermal daemon
886f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_SM_EVT_MAX
896f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev} qcamera_sm_evt_enum_t;
906f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
916f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevtypedef enum {
926f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_API_RESULT_TYPE_DEF,             // default type, no additional info
936f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_API_RESULT_TYPE_ENABLE_FLAG,     // msg_enabled, preview_enabled, recording_enabled
946f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_API_RESULT_TYPE_PARAMS,          // returned parameters in string
956f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_API_RESULT_TYPE_HANDLE,          // returned handle in int
966f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_API_RESULT_TYPE_MAX
976f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev} qcamera_api_result_type_t;
986f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
996f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevtypedef struct {
1006f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t status;                          // api call status
1016f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    qcamera_sm_evt_enum_t request_api;       // api evt requested
1026f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    qcamera_api_result_type_t result_type;   // result type
1036f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    union {
1046f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        int enabled;                          // result_type == QCAMERA_API_RESULT_TYPE_ENABLE_FLAG
1056f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        char *params;                         // result_type == QCAMERA_API_RESULT_TYPE_PARAMS
1066f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        int handle;                           // result_type ==QCAMERA_API_RESULT_TYPE_HANDLE
1076f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    };
1086f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev} qcamera_api_result_t;
1096f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
1106f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev// definition for payload type of setting callback
1116f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevtypedef struct {
1126f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    camera_notify_callback notify_cb;
1136f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    camera_data_callback data_cb;
1146f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    camera_data_timestamp_callback data_cb_timestamp;
1156f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    camera_request_memory get_memory;
1166f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    void *user;
1176f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev} qcamera_sm_evt_setcb_payload_t;
1186f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
1196f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev// definition for payload type of sending command
1206f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevtypedef struct {
1216f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t cmd;
1226f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t arg1;
1236f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t arg2;
1246f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev} qcamera_sm_evt_command_payload_t;
1256f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
1266f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev// definition for payload type of sending command
1276f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevtypedef struct {
1286f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    void *img_ptr;
1296f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    cam_pp_offline_src_config_t *config;
1306f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev} qcamera_sm_evt_reg_face_payload_t;
1316f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
1326f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevtypedef enum {
1336f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_INTERNAL_EVT_FOCUS_UPDATE,       // focus updating result
1346f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_INTERNAL_EVT_PREP_SNAPSHOT_DONE, // prepare snapshot done
1356f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCAMERA_INTERNAL_EVT_MAX
1366f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev} qcamera_internal_evt_type_t;
1376f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
1386f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevtypedef struct {
1396f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    qcamera_internal_evt_type_t evt_type;
1406f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    union {
1416f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        cam_auto_focus_data_t focus_data;
1426f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        cam_prep_snapshot_state_t prep_snapshot_state;
1436f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    };
1446f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev} qcamera_sm_internal_evt_payload_t;
1456f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
1466f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevclass QCameraStateMachine
1476f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev{
1486f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevpublic:
1496f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCameraStateMachine(QCamera2HardwareInterface *ctrl);
1506f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    virtual ~QCameraStateMachine();
1516f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t procAPI(qcamera_sm_evt_enum_t evt, void *api_payload);
1526f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t procEvt(qcamera_sm_evt_enum_t evt, void *evt_payload);
1536f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
1546f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    bool isPreviewRunning(); // check if preview is running
1556f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
1566f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevprivate:
1576f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    typedef enum {
1586f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        QCAMERA_SM_STATE_PREVIEW_STOPPED,          // preview is stopped
1596f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        QCAMERA_SM_STATE_PREVIEW_READY,            // preview started but preview window is not set yet
1606f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        QCAMERA_SM_STATE_PREVIEWING,               // previewing
1616f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        QCAMERA_SM_STATE_PREPARE_SNAPSHOT,         // prepare snapshot in case aec estimation is
1626f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev                                                   // needed for LED flash
1636f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        QCAMERA_SM_STATE_PIC_TAKING,               // taking picture (preview stopped)
1646f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        QCAMERA_SM_STATE_RECORDING,                // recording (preview running)
1656f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        QCAMERA_SM_STATE_VIDEO_PIC_TAKING,         // taking live snapshot during recording (preview running)
1666f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        QCAMERA_SM_STATE_PREVIEW_PIC_TAKING        // taking ZSL/live snapshot (recording stopped but preview running)
1676f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    } qcamera_state_enum_t;
1686f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
1696f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    typedef enum
1706f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    {
1716f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        QCAMERA_SM_CMD_TYPE_API,                   // cmd from API
1726f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        QCAMERA_SM_CMD_TYPE_EVT,                   // cmd from mm-camera-interface/mm-jpeg-interface event
1736f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        QCAMERA_SM_CMD_TYPE_EXIT,                  // cmd for exiting statemachine cmdThread
1746f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        QCAMERA_SM_CMD_TYPE_MAX
1756f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    } qcamera_sm_cmd_type_t;
1766f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
1776f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    typedef struct {
1786f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        qcamera_sm_cmd_type_t cmd;                  // cmd type (where it comes from)
1796f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        qcamera_sm_evt_enum_t evt;                  // event type
1806f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        void *evt_payload;                          // ptr to payload
1816f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    } qcamera_sm_cmd_t;
1826f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
1836f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t stateMachine(qcamera_sm_evt_enum_t evt, void *payload);
1846f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t procEvtPreviewStoppedState(qcamera_sm_evt_enum_t evt, void *payload);
1856f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t procEvtPreviewReadyState(qcamera_sm_evt_enum_t evt, void *payload);
1866f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t procEvtPreviewingState(qcamera_sm_evt_enum_t evt, void *payload);
1876f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t procEvtPrepareSnapshotState(qcamera_sm_evt_enum_t evt, void *payload);
1886f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t procEvtPicTakingState(qcamera_sm_evt_enum_t evt, void *payload);
1896f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t procEvtRecordingState(qcamera_sm_evt_enum_t evt, void *payload);
1906f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t procEvtVideoPicTakingState(qcamera_sm_evt_enum_t evt, void *payload);
1916f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t procEvtPreviewPicTakingState(qcamera_sm_evt_enum_t evt, void *payload);
1926f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
1936f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    // main statemachine process routine
1946f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    static void *smEvtProcRoutine(void *data);
1956f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
1966f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCamera2HardwareInterface *m_parent;  // ptr to HWI
1976f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    qcamera_state_enum_t m_state;         // statemachine state
1986f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCameraQueue api_queue;               // cmd queue for APIs
1996f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCameraQueue evt_queue;               // cmd queue for evt from mm-camera-intf/mm-jpeg-intf
2006f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    pthread_t cmd_pid;                    // cmd thread ID
2016f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    cam_semaphore_t cmd_sem;              // semaphore for cmd thread
2026f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
2036f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev};
2046f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
2056f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev}; // namespace qcamera
2066f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
2076f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#endif /* __QCAMERA_STATEMACHINE_H__ */
208