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#define LOG_TAG "QCamera2HWI"
316f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
326f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#include <cutils/properties.h>
336f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#include <hardware/camera.h>
346f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#include <stdlib.h>
356f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#include <utils/Errors.h>
366f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#include <gralloc_priv.h>
376f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
386f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#include "QCamera2HWI.h"
396f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#include "QCameraMem.h"
406f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
416f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#define MAP_TO_DRIVER_COORDINATE(val, base, scale, offset) (val * scale / base + offset)
426f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#define CAMERA_MIN_STREAMING_BUFFERS     3
436f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#define CAMERA_MIN_JPEG_ENCODING_BUFFERS 2
446f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#define CAMERA_MIN_VIDEO_BUFFERS         9
456f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
466f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevnamespace qcamera {
476f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
486f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevcam_capability_t *gCamCapability[MM_CAMERA_MAX_NUM_SENSORS];
496f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevstatic pthread_mutex_t g_camlock = PTHREAD_MUTEX_INITIALIZER;
506f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
516f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevcamera_device_ops_t QCamera2HardwareInterface::mCameraOps = {
526f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    set_preview_window:         QCamera2HardwareInterface::set_preview_window,
536f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    set_callbacks:              QCamera2HardwareInterface::set_CallBacks,
546f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    enable_msg_type:            QCamera2HardwareInterface::enable_msg_type,
556f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    disable_msg_type:           QCamera2HardwareInterface::disable_msg_type,
566f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    msg_type_enabled:           QCamera2HardwareInterface::msg_type_enabled,
576f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
586f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    start_preview:              QCamera2HardwareInterface::start_preview,
596f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    stop_preview:               QCamera2HardwareInterface::stop_preview,
606f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    preview_enabled:            QCamera2HardwareInterface::preview_enabled,
616f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    store_meta_data_in_buffers: QCamera2HardwareInterface::store_meta_data_in_buffers,
626f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
636f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    start_recording:            QCamera2HardwareInterface::start_recording,
646f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    stop_recording:             QCamera2HardwareInterface::stop_recording,
656f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    recording_enabled:          QCamera2HardwareInterface::recording_enabled,
666f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    release_recording_frame:    QCamera2HardwareInterface::release_recording_frame,
676f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
686f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    auto_focus:                 QCamera2HardwareInterface::auto_focus,
696f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    cancel_auto_focus:          QCamera2HardwareInterface::cancel_auto_focus,
706f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
716f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    take_picture:               QCamera2HardwareInterface::take_picture,
726f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    cancel_picture:             QCamera2HardwareInterface::cancel_picture,
736f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
746f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    set_parameters:             QCamera2HardwareInterface::set_parameters,
756f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    get_parameters:             QCamera2HardwareInterface::get_parameters,
766f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    put_parameters:             QCamera2HardwareInterface::put_parameters,
776f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    send_command:               QCamera2HardwareInterface::send_command,
786f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
796f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    release:                    QCamera2HardwareInterface::release,
806f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    dump:                       QCamera2HardwareInterface::dump,
816f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev};
826f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
836f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev/*===========================================================================
846f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * FUNCTION   : set_preview_window
856f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
866f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * DESCRIPTION: set preview window.
876f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
886f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * PARAMETERS :
896f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @device  : ptr to camera device struct
906f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @window  : window ops table
916f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
926f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * RETURN     : int32_t type of status
936f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *              NO_ERROR  -- success
946f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *              none-zero failure code
956f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *==========================================================================*/
966f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevint QCamera2HardwareInterface::set_preview_window(struct camera_device *device,
976f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        struct preview_stream_ops *window)
986f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev{
996f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int rc = NO_ERROR;
1006f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCamera2HardwareInterface *hw =
1016f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        reinterpret_cast<QCamera2HardwareInterface *>(device->priv);
1026f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (!hw) {
1036f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ALOGE("%s: NULL camera device", __func__);
1046f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        return BAD_VALUE;
1056f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
1066f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
1076f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->lockAPI();
1086f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    rc = hw->processAPI(QCAMERA_SM_EVT_SET_PREVIEW_WINDOW, (void *)window);
1096f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (rc == NO_ERROR) {
1106f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        hw->waitAPIResult(QCAMERA_SM_EVT_SET_PREVIEW_WINDOW);
1116f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        rc = hw->m_apiResult.status;
1126f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
1136f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->unlockAPI();
1146f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
1156f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    return rc;
1166f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev}
1176f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
1186f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev/*===========================================================================
1196f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * FUNCTION   : set_CallBacks
1206f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
1216f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * DESCRIPTION: set callbacks for notify and data
1226f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
1236f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * PARAMETERS :
1246f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @device     : ptr to camera device struct
1256f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @notify_cb  : notify cb
1266f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @data_cb    : data cb
1276f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @data_cb_timestamp  : video data cd with timestamp
1286f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @get_memory : ops table for request gralloc memory
1296f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @user       : user data ptr
1306f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
1316f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * RETURN     : none
1326f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *==========================================================================*/
1336f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevvoid QCamera2HardwareInterface::set_CallBacks(struct camera_device *device,
1346f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        camera_notify_callback notify_cb,
1356f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        camera_data_callback data_cb,
1366f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        camera_data_timestamp_callback data_cb_timestamp,
1376f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        camera_request_memory get_memory,
1386f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        void *user)
1396f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev{
1406f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCamera2HardwareInterface *hw =
1416f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        reinterpret_cast<QCamera2HardwareInterface *>(device->priv);
1426f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (!hw) {
1436f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ALOGE("NULL camera device");
1446f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        return;
1456f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
1466f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
1476f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    qcamera_sm_evt_setcb_payload_t payload;
1486f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    payload.notify_cb = notify_cb;
1496f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    payload.data_cb = data_cb;
1506f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    payload.data_cb_timestamp = data_cb_timestamp;
1516f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    payload.get_memory = get_memory;
1526f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    payload.user = user;
1536f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
1546f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->lockAPI();
1556f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t rc = hw->processAPI(QCAMERA_SM_EVT_SET_CALLBACKS, (void *)&payload);
1566f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (rc == NO_ERROR) {
1576f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        hw->waitAPIResult(QCAMERA_SM_EVT_SET_CALLBACKS);
1586f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
1596f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->unlockAPI();
1606f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev}
1616f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
1626f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev/*===========================================================================
1636f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * FUNCTION   : enable_msg_type
1646f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
1656f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * DESCRIPTION: enable certain msg type
1666f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
1676f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * PARAMETERS :
1686f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @device     : ptr to camera device struct
1696f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @msg_type   : msg type mask
1706f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
1716f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * RETURN     : none
1726f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *==========================================================================*/
1736f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevvoid QCamera2HardwareInterface::enable_msg_type(struct camera_device *device, int32_t msg_type)
1746f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev{
1756f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCamera2HardwareInterface *hw =
1766f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        reinterpret_cast<QCamera2HardwareInterface *>(device->priv);
1776f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (!hw) {
1786f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ALOGE("NULL camera device");
1796f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        return;
1806f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
1816f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->lockAPI();
1826f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t rc = hw->processAPI(QCAMERA_SM_EVT_ENABLE_MSG_TYPE, (void *)msg_type);
1836f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (rc == NO_ERROR) {
1846f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        hw->waitAPIResult(QCAMERA_SM_EVT_ENABLE_MSG_TYPE);
1856f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
1866f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->unlockAPI();
1876f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev}
1886f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
1896f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev/*===========================================================================
1906f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * FUNCTION   : disable_msg_type
1916f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
1926f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * DESCRIPTION: disable certain msg type
1936f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
1946f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * PARAMETERS :
1956f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @device     : ptr to camera device struct
1966f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @msg_type   : msg type mask
1976f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
1986f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * RETURN     : none
1996f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *==========================================================================*/
2006f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevvoid QCamera2HardwareInterface::disable_msg_type(struct camera_device *device, int32_t msg_type)
2016f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev{
2026f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCamera2HardwareInterface *hw =
2036f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        reinterpret_cast<QCamera2HardwareInterface *>(device->priv);
2046f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (!hw) {
2056f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ALOGE("NULL camera device");
2066f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        return;
2076f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
2086f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->lockAPI();
2096f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t rc = hw->processAPI(QCAMERA_SM_EVT_DISABLE_MSG_TYPE, (void *)msg_type);
2106f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (rc == NO_ERROR) {
2116f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        hw->waitAPIResult(QCAMERA_SM_EVT_DISABLE_MSG_TYPE);
2126f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
2136f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->unlockAPI();
2146f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev}
2156f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
2166f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev/*===========================================================================
2176f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * FUNCTION   : msg_type_enabled
2186f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
2196f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * DESCRIPTION: if certain msg type is enabled
2206f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
2216f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * PARAMETERS :
2226f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @device     : ptr to camera device struct
2236f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @msg_type   : msg type mask
2246f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
2256f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * RETURN     : 1 -- enabled
2266f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *              0 -- not enabled
2276f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *==========================================================================*/
2286f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevint QCamera2HardwareInterface::msg_type_enabled(struct camera_device *device, int32_t msg_type)
2296f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev{
2306f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int ret = NO_ERROR;
2316f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCamera2HardwareInterface *hw =
2326f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        reinterpret_cast<QCamera2HardwareInterface *>(device->priv);
2336f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (!hw) {
2346f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ALOGE("NULL camera device");
2356f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        return BAD_VALUE;
2366f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
2376f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->lockAPI();
2386f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    ret = hw->processAPI(QCAMERA_SM_EVT_MSG_TYPE_ENABLED, (void *)msg_type);
2396f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (ret == NO_ERROR) {
2406f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        hw->waitAPIResult(QCAMERA_SM_EVT_MSG_TYPE_ENABLED);
2416f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ret = hw->m_apiResult.enabled;
2426f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
2436f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->unlockAPI();
2446f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
2456f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev   return ret;
2466f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev}
2476f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
2486f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev/*===========================================================================
2496f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * FUNCTION   : start_preview
2506f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
2516f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * DESCRIPTION: start preview
2526f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
2536f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * PARAMETERS :
2546f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @device  : ptr to camera device struct
2556f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
2566f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * RETURN     : int32_t type of status
2576f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *              NO_ERROR  -- success
2586f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *              none-zero failure code
2596f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *==========================================================================*/
2606f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevint QCamera2HardwareInterface::start_preview(struct camera_device *device)
2616f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev{
2626f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int ret = NO_ERROR;
2636f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCamera2HardwareInterface *hw =
2646f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        reinterpret_cast<QCamera2HardwareInterface *>(device->priv);
2656f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (!hw) {
2666f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ALOGE("NULL camera device");
2676f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        return BAD_VALUE;
2686f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
269fbe69a7ac63f99c63d50d9abaed766c81d2aab13Muhua Li    ALOGD("[KPI Perf] %s: E", __func__);
2706f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->lockAPI();
2716f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    qcamera_sm_evt_enum_t evt = QCAMERA_SM_EVT_START_PREVIEW;
2726f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (hw->isNoDisplayMode()) {
2736f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        evt = QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW;
2746f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
2756f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    ret = hw->processAPI(evt, NULL);
2766f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (ret == NO_ERROR) {
2776f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        hw->waitAPIResult(evt);
2786f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ret = hw->m_apiResult.status;
2796f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
2806f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->unlockAPI();
281fbe69a7ac63f99c63d50d9abaed766c81d2aab13Muhua Li    ALOGD("[KPI Perf] %s: X", __func__);
2826f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    return ret;
2836f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev}
2846f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
2856f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev/*===========================================================================
2866f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * FUNCTION   : stop_preview
2876f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
2886f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * DESCRIPTION: stop preview
2896f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
2906f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * PARAMETERS :
2916f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @device  : ptr to camera device struct
2926f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
2936f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * RETURN     : none
2946f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *==========================================================================*/
2956f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevvoid QCamera2HardwareInterface::stop_preview(struct camera_device *device)
2966f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev{
2976f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCamera2HardwareInterface *hw =
2986f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        reinterpret_cast<QCamera2HardwareInterface *>(device->priv);
2996f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (!hw) {
3006f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ALOGE("NULL camera device");
3016f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        return;
3026f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
303fbe69a7ac63f99c63d50d9abaed766c81d2aab13Muhua Li    ALOGD("[KPI Perf] %s: E", __func__);
3046f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->lockAPI();
3056f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t ret = hw->processAPI(QCAMERA_SM_EVT_STOP_PREVIEW, NULL);
3066f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (ret == NO_ERROR) {
3076f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        hw->waitAPIResult(QCAMERA_SM_EVT_STOP_PREVIEW);
3086f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
3096f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->unlockAPI();
310fbe69a7ac63f99c63d50d9abaed766c81d2aab13Muhua Li    ALOGD("[KPI Perf] %s: X", __func__);
3116f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev}
3126f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
3136f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev/*===========================================================================
3146f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * FUNCTION   : preview_enabled
3156f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
3166f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * DESCRIPTION: if preview is running
3176f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
3186f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * PARAMETERS :
3196f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @device  : ptr to camera device struct
3206f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
3216f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * RETURN     : 1 -- running
3226f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *              0 -- not running
3236f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *==========================================================================*/
3246f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevint QCamera2HardwareInterface::preview_enabled(struct camera_device *device)
3256f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev{
3266f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int ret = NO_ERROR;
3276f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCamera2HardwareInterface *hw =
3286f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        reinterpret_cast<QCamera2HardwareInterface *>(device->priv);
3296f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (!hw) {
3306f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ALOGE("NULL camera device");
3316f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        return BAD_VALUE;
3326f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
3336f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
3346f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->lockAPI();
3356f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    ret = hw->processAPI(QCAMERA_SM_EVT_PREVIEW_ENABLED, NULL);
3366f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (ret == NO_ERROR) {
3376f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        hw->waitAPIResult(QCAMERA_SM_EVT_PREVIEW_ENABLED);
3386f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ret = hw->m_apiResult.enabled;
3396f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
3406f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->unlockAPI();
3416f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
3426f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    return ret;
3436f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev}
3446f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
3456f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev/*===========================================================================
3466f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * FUNCTION   : store_meta_data_in_buffers
3476f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
3486f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * DESCRIPTION: if need to store meta data in buffers for video frame
3496f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
3506f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * PARAMETERS :
3516f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @device  : ptr to camera device struct
3526f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @enable  : flag if enable
3536f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
3546f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * RETURN     : int32_t type of status
3556f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *              NO_ERROR  -- success
3566f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *              none-zero failure code
3576f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *==========================================================================*/
3586f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevint QCamera2HardwareInterface::store_meta_data_in_buffers(
3596f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev                struct camera_device *device, int enable)
3606f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev{
3616f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int ret = NO_ERROR;
3626f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCamera2HardwareInterface *hw =
3636f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        reinterpret_cast<QCamera2HardwareInterface *>(device->priv);
3646f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (!hw) {
3656f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ALOGE("NULL camera device");
3666f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        return BAD_VALUE;
3676f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
3686f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
3696f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->lockAPI();
3706f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    ret = hw->processAPI(QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS, (void *)enable);
3716f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (ret == NO_ERROR) {
3726f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        hw->waitAPIResult(QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS);
3736f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ret = hw->m_apiResult.status;
3746f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
3756f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->unlockAPI();
3766f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
3776f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    return ret;
3786f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev}
3796f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
3806f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev/*===========================================================================
3816f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * FUNCTION   : start_recording
3826f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
3836f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * DESCRIPTION: start recording
3846f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
3856f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * PARAMETERS :
3866f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @device  : ptr to camera device struct
3876f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
3886f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * RETURN     : int32_t type of status
3896f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *              NO_ERROR  -- success
3906f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *              none-zero failure code
3916f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *==========================================================================*/
3926f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevint QCamera2HardwareInterface::start_recording(struct camera_device *device)
3936f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev{
3946f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int ret = NO_ERROR;
3956f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCamera2HardwareInterface *hw =
3966f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        reinterpret_cast<QCamera2HardwareInterface *>(device->priv);
3976f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (!hw) {
3986f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ALOGE("NULL camera device");
3996f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        return BAD_VALUE;
4006f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
401fbe69a7ac63f99c63d50d9abaed766c81d2aab13Muhua Li    ALOGD("[KPI Perf] %s: E", __func__);
4026f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->lockAPI();
4036f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    ret = hw->processAPI(QCAMERA_SM_EVT_START_RECORDING, NULL);
4046f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (ret == NO_ERROR) {
4056f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        hw->waitAPIResult(QCAMERA_SM_EVT_START_RECORDING);
4066f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ret = hw->m_apiResult.status;
4076f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
4086f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->unlockAPI();
409fbe69a7ac63f99c63d50d9abaed766c81d2aab13Muhua Li    ALOGD("[KPI Perf] %s: X", __func__);
4106f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    return ret;
4116f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev}
4126f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
4136f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev/*===========================================================================
4146f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * FUNCTION   : stop_recording
4156f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
4166f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * DESCRIPTION: stop recording
4176f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
4186f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * PARAMETERS :
4196f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @device  : ptr to camera device struct
4206f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
4216f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * RETURN     : none
4226f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *==========================================================================*/
4236f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevvoid QCamera2HardwareInterface::stop_recording(struct camera_device *device)
4246f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev{
4256f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCamera2HardwareInterface *hw =
4266f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        reinterpret_cast<QCamera2HardwareInterface *>(device->priv);
4276f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (!hw) {
4286f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ALOGE("NULL camera device");
4296f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        return;
4306f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
431fbe69a7ac63f99c63d50d9abaed766c81d2aab13Muhua Li    ALOGD("[KPI Perf] %s: E", __func__);
4326f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->lockAPI();
4336f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t ret = hw->processAPI(QCAMERA_SM_EVT_STOP_RECORDING, NULL);
4346f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (ret == NO_ERROR) {
4356f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        hw->waitAPIResult(QCAMERA_SM_EVT_STOP_RECORDING);
4366f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
4376f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->unlockAPI();
438fbe69a7ac63f99c63d50d9abaed766c81d2aab13Muhua Li    ALOGD("[KPI Perf] %s: X", __func__);
4396f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev}
4406f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
4416f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev/*===========================================================================
4426f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * FUNCTION   : recording_enabled
4436f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
4446f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * DESCRIPTION: if recording is running
4456f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
4466f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * PARAMETERS :
4476f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @device  : ptr to camera device struct
4486f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
4496f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * RETURN     : 1 -- running
4506f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *              0 -- not running
4516f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *==========================================================================*/
4526f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevint QCamera2HardwareInterface::recording_enabled(struct camera_device *device)
4536f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev{
4546f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int ret = NO_ERROR;
4556f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCamera2HardwareInterface *hw =
4566f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        reinterpret_cast<QCamera2HardwareInterface *>(device->priv);
4576f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (!hw) {
4586f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ALOGE("NULL camera device");
4596f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        return BAD_VALUE;
4606f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
4616f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->lockAPI();
4626f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    ret = hw->processAPI(QCAMERA_SM_EVT_RECORDING_ENABLED, NULL);
4636f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (ret == NO_ERROR) {
4646f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        hw->waitAPIResult(QCAMERA_SM_EVT_RECORDING_ENABLED);
4656f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ret = hw->m_apiResult.enabled;
4666f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
4676f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->unlockAPI();
4686f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
4696f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    return ret;
4706f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev}
4716f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
4726f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev/*===========================================================================
4736f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * FUNCTION   : release_recording_frame
4746f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
4756f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * DESCRIPTION: return recording frame back
4766f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
4776f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * PARAMETERS :
4786f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @device  : ptr to camera device struct
4796f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @opaque  : ptr to frame to be returned
4806f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
4816f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * RETURN     : none
4826f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *==========================================================================*/
4836f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevvoid QCamera2HardwareInterface::release_recording_frame(
4846f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev            struct camera_device *device, const void *opaque)
4856f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev{
4866f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCamera2HardwareInterface *hw =
4876f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        reinterpret_cast<QCamera2HardwareInterface *>(device->priv);
4886f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (!hw) {
4896f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ALOGE("NULL camera device");
4906f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        return;
4916f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
492fbe69a7ac63f99c63d50d9abaed766c81d2aab13Muhua Li    ALOGD("%s: E", __func__);
4936f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->lockAPI();
4946f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t ret = hw->processAPI(QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME, (void *)opaque);
4956f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (ret == NO_ERROR) {
4966f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        hw->waitAPIResult(QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME);
4976f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
4986f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->unlockAPI();
499fbe69a7ac63f99c63d50d9abaed766c81d2aab13Muhua Li    ALOGD("%s: X", __func__);
5006f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev}
5016f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
5026f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev/*===========================================================================
5036f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * FUNCTION   : auto_focus
5046f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
5056f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * DESCRIPTION: start auto focus
5066f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
5076f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * PARAMETERS :
5086f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @device  : ptr to camera device struct
5096f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
5106f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * RETURN     : int32_t type of status
5116f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *              NO_ERROR  -- success
5126f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *              none-zero failure code
5136f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *==========================================================================*/
5146f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevint QCamera2HardwareInterface::auto_focus(struct camera_device *device)
5156f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev{
5166f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int ret = NO_ERROR;
5176f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCamera2HardwareInterface *hw =
5186f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        reinterpret_cast<QCamera2HardwareInterface *>(device->priv);
5196f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (!hw) {
5206f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ALOGE("NULL camera device");
5216f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        return BAD_VALUE;
5226f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
523fbe69a7ac63f99c63d50d9abaed766c81d2aab13Muhua Li    ALOGD("[KPI Perf] %s : E", __func__);
5246f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->lockAPI();
5256f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    ret = hw->processAPI(QCAMERA_SM_EVT_START_AUTO_FOCUS, NULL);
5266f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (ret == NO_ERROR) {
5276f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        hw->waitAPIResult(QCAMERA_SM_EVT_START_AUTO_FOCUS);
5286f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ret = hw->m_apiResult.status;
5296f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
5306f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->unlockAPI();
531fbe69a7ac63f99c63d50d9abaed766c81d2aab13Muhua Li    ALOGD("[KPI Perf] %s : X", __func__);
5326f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
5336f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    return ret;
5346f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev}
5356f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
5366f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev/*===========================================================================
5376f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * FUNCTION   : cancel_auto_focus
5386f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
5396f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * DESCRIPTION: cancel auto focus
5406f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
5416f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * PARAMETERS :
5426f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @device  : ptr to camera device struct
5436f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
5446f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * RETURN     : int32_t type of status
5456f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *              NO_ERROR  -- success
5466f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *              none-zero failure code
5476f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *==========================================================================*/
5486f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevint QCamera2HardwareInterface::cancel_auto_focus(struct camera_device *device)
5496f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev{
5506f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int ret = NO_ERROR;
5516f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCamera2HardwareInterface *hw =
5526f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        reinterpret_cast<QCamera2HardwareInterface *>(device->priv);
5536f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (!hw) {
5546f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ALOGE("NULL camera device");
5556f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        return BAD_VALUE;
5566f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
5576f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->lockAPI();
5586f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    ret = hw->processAPI(QCAMERA_SM_EVT_STOP_AUTO_FOCUS, NULL);
5596f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (ret == NO_ERROR) {
5606f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        hw->waitAPIResult(QCAMERA_SM_EVT_STOP_AUTO_FOCUS);
5616f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ret = hw->m_apiResult.status;
5626f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
5636f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->unlockAPI();
5646f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
5656f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    return ret;
5666f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev}
5676f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
5686f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev/*===========================================================================
5696f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * FUNCTION   : take_picture
5706f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
5716f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * DESCRIPTION: take picture
5726f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
5736f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * PARAMETERS :
5746f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @device  : ptr to camera device struct
5756f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
5766f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * RETURN     : int32_t type of status
5776f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *              NO_ERROR  -- success
5786f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *              none-zero failure code
5796f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *==========================================================================*/
5806f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevint QCamera2HardwareInterface::take_picture(struct camera_device *device)
5816f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev{
5826f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int ret = NO_ERROR;
5836f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCamera2HardwareInterface *hw =
5846f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        reinterpret_cast<QCamera2HardwareInterface *>(device->priv);
5856f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (!hw) {
5866f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ALOGE("NULL camera device");
5876f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        return BAD_VALUE;
5886f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
589fbe69a7ac63f99c63d50d9abaed766c81d2aab13Muhua Li    ALOGD("[KPI Perf] %s: E", __func__);
5906f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->lockAPI();
5916f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
5926f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    /* Prepare snapshot in case LED needs to be flashed */
5936f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    ret = hw->processAPI(QCAMERA_SM_EVT_PREPARE_SNAPSHOT, NULL);
5946f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (ret == NO_ERROR) {
5956f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        hw->waitAPIResult(QCAMERA_SM_EVT_PREPARE_SNAPSHOT);
5966f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ret = hw->m_apiResult.status;
5976f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
5986f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
5996f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    /* Regardless what the result value for prepare_snapshot,
6006f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev     * go ahead with capture anyway. Just like the way autofocus
6016f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev     * is handled in capture case. */
6026f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
6036f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    /* capture */
6046f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    ret = hw->processAPI(QCAMERA_SM_EVT_TAKE_PICTURE, NULL);
6056f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (ret == NO_ERROR) {
6066f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        hw->waitAPIResult(QCAMERA_SM_EVT_TAKE_PICTURE);
6076f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ret = hw->m_apiResult.status;
6086f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
6096f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
6106f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->unlockAPI();
611fbe69a7ac63f99c63d50d9abaed766c81d2aab13Muhua Li    ALOGD("[KPI Perf] %s: X", __func__);
6126f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    return ret;
6136f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev}
6146f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
6156f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev/*===========================================================================
6166f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * FUNCTION   : cancel_picture
6176f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
6186f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * DESCRIPTION: cancel current take picture request
6196f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
6206f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * PARAMETERS :
6216f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @device  : ptr to camera device struct
6226f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
6236f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * RETURN     : int32_t type of status
6246f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *              NO_ERROR  -- success
6256f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *              none-zero failure code
6266f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *==========================================================================*/
6276f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevint QCamera2HardwareInterface::cancel_picture(struct camera_device *device)
6286f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev{
6296f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int ret = NO_ERROR;
6306f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCamera2HardwareInterface *hw =
6316f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        reinterpret_cast<QCamera2HardwareInterface *>(device->priv);
6326f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (!hw) {
6336f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ALOGE("NULL camera device");
6346f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        return BAD_VALUE;
6356f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
6366f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->lockAPI();
6376f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    ret = hw->processAPI(QCAMERA_SM_EVT_CANCEL_PICTURE, NULL);
6386f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (ret == NO_ERROR) {
6396f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        hw->waitAPIResult(QCAMERA_SM_EVT_CANCEL_PICTURE);
6406f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ret = hw->m_apiResult.status;
6416f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
6426f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->unlockAPI();
6436f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
6446f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    return ret;
6456f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev}
6466f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
6476f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev/*===========================================================================
6486f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * FUNCTION   : set_parameters
6496f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
6506f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * DESCRIPTION: set camera parameters
6516f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
6526f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * PARAMETERS :
6536f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @device  : ptr to camera device struct
6546f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *   @parms   : string of packed parameters
6556f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
6566f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * RETURN     : int32_t type of status
6576f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *              NO_ERROR  -- success
6586f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *              none-zero failure code
6596f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *==========================================================================*/
6606f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevint QCamera2HardwareInterface::set_parameters(struct camera_device *device,
6616f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev                                              const char *parms)
6626f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev{
6636f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int ret = NO_ERROR;
6646f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCamera2HardwareInterface *hw =
6656f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        reinterpret_cast<QCamera2HardwareInterface *>(device->priv);
6666f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (!hw) {
6676f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ALOGE("NULL camera device");
6686f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        return BAD_VALUE;
6696f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
6706f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->lockAPI();
6716f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    ret = hw->processAPI(QCAMERA_SM_EVT_SET_PARAMS, (void *)parms);
6726f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    if (ret == NO_ERROR) {
6736f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        hw->waitAPIResult(QCAMERA_SM_EVT_SET_PARAMS);
6746f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev        ret = hw->m_apiResult.status;
6756f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    }
6766f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    hw->unlockAPI();
6776f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
6786f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    return ret;
6796f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev}
6806f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
6816f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev/*===========================================================================
682