diff options
author | Jeongmo Yang <jm80.yang@samsung.com> | 2015-08-27 17:16:01 +0900 |
---|---|---|
committer | Jeongmo Yang <jm80.yang@samsung.com> | 2015-09-08 17:08:42 +0900 |
commit | 683943071bff4a18b483e128412214a6c24a345c (patch) | |
tree | dec49387da3e34d428bfadf5ecea0676f15656e5 /camerasrc/src | |
parent | 77ad381f9e6c12dd678e2b38e04740269f7108a1 (diff) | |
download | gst-plugins-camera-n4-683943071bff4a18b483e128412214a6c24a345c.tar.gz gst-plugins-camera-n4-683943071bff4a18b483e128412214a6c24a345c.tar.bz2 gst-plugins-camera-n4-683943071bff4a18b483e128412214a6c24a345c.zip |
Initial releasetizen_3.0.m2.a1_mobile_releasetizen_3.0.m1_mobile_releasesubmit/tizen_mobile/20150909.035934submit/tizen_ivi/20160217.000001submit/tizen_ivi/20160217.000000submit/tizen_common/20160222.141210accepted/tizen/mobile/20150909.055630accepted/tizen/ivi/20160218.022815accepted/tizen/common/20160222.162206tizen_3.0.m1_mobile
Change-Id: Ie94ff53813ecc79a84ebfc1a3da887758bb3af5e
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
Diffstat (limited to 'camerasrc/src')
-rw-r--r-- | camerasrc/src/Makefile.am | 37 | ||||
-rw-r--r-- | camerasrc/src/camerasrc-internal.c | 1009 | ||||
-rw-r--r-- | camerasrc/src/camerasrc.c | 3718 | ||||
-rw-r--r-- | camerasrc/src/gstcamerasrc.c | 3572 | ||||
-rw-r--r-- | camerasrc/src/gstcamerasrccolorbalance.c | 112 | ||||
-rw-r--r-- | camerasrc/src/gstcamerasrccontrol.c | 915 | ||||
-rw-r--r-- | camerasrc/src/include/camerasrc-common.h | 451 | ||||
-rw-r--r-- | camerasrc/src/include/camerasrc-error.h | 140 | ||||
-rw-r--r-- | camerasrc/src/include/camerasrc-internal.h | 65 | ||||
-rw-r--r-- | camerasrc/src/include/camerasrc.h | 1293 | ||||
-rw-r--r-- | camerasrc/src/include/fimc-is-metadata.h | 1473 | ||||
-rw-r--r-- | camerasrc/src/include/gstcamerasrc.h | 180 | ||||
-rw-r--r-- | camerasrc/src/include/gstcamerasrccolorbalance.h | 91 | ||||
-rw-r--r-- | camerasrc/src/include/gstcamerasrccontrol.h | 364 |
14 files changed, 13420 insertions, 0 deletions
diff --git a/camerasrc/src/Makefile.am b/camerasrc/src/Makefile.am new file mode 100644 index 0000000..3c03e45 --- /dev/null +++ b/camerasrc/src/Makefile.am @@ -0,0 +1,37 @@ +# plugindir is set in configure + +plugin_LTLIBRARIES = libgstcamerasrc.la + +# sources used to compile this plug-in +libgstcamerasrc_la_SOURCES = gstcamerasrccontrol.c \ + gstcamerasrccolorbalance.c \ + camerasrc.c \ + camerasrc-internal.c \ + gstcamerasrc.c + +libgstcamerasrc_la_CFLAGS = $(GST_CFLAGS) \ + $(GST_BASE_CFLAGS) \ + $(GST_VIDEO_FLAGS) \ + $(MM_COMMON_CFLAGS) \ + $(MMUTIL_JPEG_CFLAGS) \ + -I$(srcdir)/include \ + $(GST_INTERFACES_CFLAGS) \ + $(TBM_CFLAGS) \ + $(DRM_CFLAGS) \ + $(DRM_EXYNOS_CFLAGS) + +libgstcamerasrc_la_LIBADD = $(GST_LIBS) \ + $(GST_BASE_LIBS) \ + $(GST_VIDEO_LIBS) \ + $(MM_COMMON_LIBS) \ + $(MMUTIL_JPEG_LIBS) \ + -ldl -lpthread -lrt -lm \ + $(GST_INTERFACES_LIBS) \ + $(TBM_LIBS) \ + $(DRM_LIBS) \ + $(DRM_EXYNOS_LIBS) + +libgstcamerasrc_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) + +libgstcamerasrc_la_CPPFLAGS = -I$(srcdir)/include + diff --git a/camerasrc/src/camerasrc-internal.c b/camerasrc/src/camerasrc-internal.c new file mode 100644 index 0000000..ff528bd --- /dev/null +++ b/camerasrc/src/camerasrc-internal.c @@ -0,0 +1,1009 @@ +/* + * camerasrc + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jeongmo Yang <jm80.yang@samsung.com> + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <math.h> +#include "camerasrc-internal.h" + +#define _CAMERASRC_GET_CID(ctrl_id, dev_id) _camerasrc_ctrl_list[dev_id][ctrl_id][CAMERASRC_CTRL_CID_VALUE] + +/* CUSTOM V4L2 CONTROL ID DEFINITIONS (END) */ +static int _camerasrc_ctrl_list[CAMERASRC_DEV_ID_EXTENSION][CAMERASRC_CTRL_NUM][CAMERASRC_CTRL_PROPERTY_NUM] = +{ /* { SUPPORT, MAX_VALUE, MIN_VALUE, CID, CURRENT_VALUE } */ + { /* Primary camera */ + {-1, 4, -4, V4L2_CID_EXPOSURE, 0}, /* Brightness */ + {-1, 3, -3, V4L2_CID_CONTRAST, 0}, /* Contrast */ + {-1, 30, 0, V4L2_CID_ZOOM_ABSOLUTE, 0}, /* Digital zoom */ + {0, -1, -1, -1, -1}, /* Optical zoom */ + {-1, V4L2_WHITE_BALANCE_CLOUDY, V4L2_WHITE_BALANCE_AUTO, V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE, V4L2_WHITE_BALANCE_AUTO}, /* White balance */ + {-1, V4L2_COLORFX_AQUA, V4L2_COLORFX_NONE, V4L2_CID_COLORFX, V4L2_COLORFX_NONE}, /* Colortone */ + {-1, V4L2_SCENE_MODE_TEXT, V4L2_SCENE_MODE_NONE, V4L2_CID_SCENE_MODE, V4L2_SCENE_MODE_NONE}, /* program mode */ + {0, -1, -1, -1, -1}, /* Flip. V4L2_CID_VFLIP/HFLIP */ + {-1, 1, 0, V4L2_CID_IMAGE_STABILIZATION, 0}, /* ANTI_HANDSHAKE */ + {-1, 1, 0, V4L2_CID_WIDE_DYNAMIC_RANGE, 0}, /* WIDE_DYNAMIC_RANGE - AUTO CONTRAST */ + {-1, 3, -3, V4L2_CID_SATURATION, 0}, /* SATURATION */ + {-1, 3, -3, V4L2_CID_SHARPNESS, 0}, /* SHARPNESS */ + {-1, -1, -1, V4L2_CID_ISO_SENSITIVITY, -1}, /* ISO */ + {-1, V4L2_EXPOSURE_METERING_MATRIX, V4L2_EXPOSURE_METERING_AVERAGE, V4L2_CID_EXPOSURE_METERING, V4L2_EXPOSURE_METERING_AVERAGE}, /* PHOTOMETRY */ + }, + { /* Secondary camera */ + {0, -1, -1, V4L2_CID_EXPOSURE, -1}, /* Brightness */ + {0, -1, -1, V4L2_CID_CONTRAST, -1}, /* Contrast */ + {0, -1, -1, V4L2_CID_ZOOM_ABSOLUTE, -1}, /* Digital zoom */ + {0, -1, -1, -1, -1}, /* Optical zoom */ + {0, -1, -1, V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE, -1},/* White balance */ + {0, -1, -1, V4L2_CID_COLORFX, -1}, /* Colortone */ + {0, -1, -1, V4L2_CID_SCENE_MODE, -1}, /* program mode */ + {0, -1, -1, -1, -1}, /* Flip */ + {0, -1, -1, V4L2_CID_WIDE_DYNAMIC_RANGE, -1}, /* ANTI_HANDSHAKE */ + {0, -1, -1, V4L2_CID_WIDE_DYNAMIC_RANGE, -1}, /* WIDE_DYNAMIC_RANGE */ + {0, -1, -1, V4L2_CID_SATURATION, -1}, /* SATURATION */ + {0, -1, -1, V4L2_CID_SHARPNESS, -1}, /* SHARPNESS */ + {0, -1, -1, V4L2_CID_ISO_SENSITIVITY, -1}, /* ISO */ + {0, -1, -1, V4L2_CID_EXPOSURE_METERING, -1}, /* PHOTOMETRY */ + }, +}; + + +/*#define USE_IOCTL_DEBUG*/ +#if defined (USE_IOCTL_DEBUG) +static char* get_request_name(int request, char* res_str) { + switch (request) { + case VIDIOC_QBUF: + sprintf(res_str, "[VIDIOC_QBUF]"); + break; + case VIDIOC_DQBUF: + sprintf(res_str, "[VIDIOC_DQBUF]"); + break; + case VIDIOC_S_INPUT: + sprintf(res_str, "[VIDIOC_S_INPUT]"); + break; + case VIDIOC_G_INPUT: + sprintf(res_str, "[VIDIOC_G_INPUT]"); + break; + case VIDIOC_S_PARM: + sprintf(res_str, "[VIDIOC_S_PARM]"); + break; + case VIDIOC_G_PARM: + sprintf(res_str, "[VIDIOC_G_PARM]"); + break; + case VIDIOC_S_FMT: + sprintf(res_str, "[VIDIOC_S_FMT]"); + break; + case VIDIOC_G_FMT: + sprintf(res_str, "[VIDIOC_G_FMT]"); + break; + case VIDIOC_REQBUFS: + sprintf(res_str, "[VIDIOC_REQBUFS]"); + break; + case VIDIOC_QUERYBUF: + sprintf(res_str, "[VIDIOC_QUERYBUF]"); + break; + case VIDIOC_STREAMON: + sprintf(res_str, "[VIDIOC_STREAMON]"); + break; + case VIDIOC_STREAMOFF: + sprintf(res_str, "[VIDIOC_STREAMOFF]"); + break; + case VIDIOC_S_CTRL: + sprintf(res_str, "[VIDIOC_S_CTRL] "); + break; + case VIDIOC_G_CTRL: + sprintf(res_str, "[VIDIOC_G_CTRL]"); + break; + case VIDIOC_ENUMINPUT: + sprintf(res_str, "[VIDIOC_ENUMINPUT]"); + break; + case VIDIOC_S_JPEGCOMP: + sprintf(res_str, "[VIDIOC_S_JPEGCOMP]"); + break; + case VIDIOC_G_JPEGCOMP: + sprintf(res_str, "[VIDIOC_G_JPEGCOMP]"); + break; + /* Extension */ + case VIDIOC_S_STROBE: + sprintf(res_str, "[VIDIOC_S_STROBE]"); + break; + case VIDIOC_G_STROBE: + sprintf(res_str, "[VIDIOC_G_STROBE]"); + break; + case VIDIOC_S_RECOGNITION: + sprintf(res_str, "[VIDIOC_S_RECOGNITION]"); + break; + case VIDIOC_G_RECOGNITION: + sprintf(res_str, "[VIDIOC_G_RECOGNITION]"); + break; + case VIDIOC_G_EXIF: + sprintf(res_str, "[VIDIOC_G_EXIF]"); + break; + default: + sprintf(res_str, "[UNKNOWN IOCTL(%x)]", request); + break; + } + + return 0; +} + +#define PRINT_IOCTL_INFO(request, arg) {\ + char res_str[255];\ + get_request_name(request, res_str);\ + camsrc_info("[request : %s, argument address : %x]", res_str, arg);\ +} +#else + +#define PRINT_IOCTL_INFO(request, arg) + +#endif + + +#define LOCK(x) {\ + if(0 != pthread_mutex_lock(&(x->mutex))) {\ + camsrc_error("Mutex lock error");\ + camsrc_assert(0);\ + }\ +} + +#define UNLOCK(x) {\ + if(0 != pthread_mutex_unlock(&(x->mutex))) {\ + camsrc_error("Mutex unlock error");\ + camsrc_assert(0);\ + }\ +} + +#define AF_MUT_LOCK(p) {\ + if(0 != pthread_mutex_lock(&(p->af_mutex))) {\ + camsrc_error("AF Mutex locking error");\ + camsrc_assert(0);\ + }\ +} + +#define AF_MUT_UNLOCK(p) {\ + if(0 != pthread_mutex_unlock(&(p->af_mutex))) {\ + camsrc_error("AF Mutex unlocking error");\ + camsrc_assert(0);\ + }\ +} + + +static int _camerasrc_ioctl(camerasrc_handle_t *handle, int fd, int request, void *arg) +{ + int err; + int nAgain = 10; + char err_msg[CAMERASRC_ERRMSG_MAX_LEN] = {'\0',}; + + if (handle == NULL) { + camsrc_error("NULL handle"); + return CAMERASRC_ERR_INVALID_PARAMETER; + } + + if (fd < 0) { + camsrc_error("invalid fd %d", fd); + return CAMERASRC_ERR_INVALID_PARAMETER; + } + + LOCK(handle); + + PRINT_IOCTL_INFO(request, arg); + +again: + do { + err = ioctl (fd, request, arg); + } while (-1 == err && EINTR == errno); + + if (err != 0) { + handle->errnum = errno; + err = errno; + strerror_r(err, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("ioctl[%x] err : %s", request, err_msg); + if (err == EEXIST) { + camsrc_info("EEXIST occured, but can go."); + err = 0; + } else if (err == ENOENT) { + camsrc_info("ENOENT occured, but can go."); + err = 0; +#if defined (ENABLE_Q_ERROR) +#warning "ENABLE_Q_ERROR enabled" + } else if (request == VIDIOC_DQBUF) { + goto DQ_ERROR; + } else if (request == VIDIOC_QBUF) { + goto ENQ_ERROR; +#endif + } else if (err == EINVAL) { + camsrc_error("EINVAL occured, Shutdown"); + UNLOCK(handle); + return CAMERASRC_ERR_INVALID_PARAMETER; + } else if (err == EBUSY) { + camsrc_error("EBUSY occured, Shutdown"); + UNLOCK(handle); + return CAMERASRC_ERR_PRIVILEGE; + } else if (err == ENODEV) { + camsrc_error("ENODEV occured, Shutdown"); + //UNLOCK(handle); + //return CAMERASRC_ERR_UNAVAILABLE_DEVICE; + } else if (err == EAGAIN && nAgain--) { + goto again; + } else { + /* Why does this return SUCCESS? */ + camsrc_error("Unhandled exception occured on IOCTL"); + } + } + + UNLOCK(handle); + + return CAMERASRC_SUCCESS; + +#if defined (ENABLE_Q_ERROR) +DQ_ERROR: + camsrc_error("DQ Frame error occured"); + printf("DQ Frame error occured"); + UNLOCK(handle); + return CAMERASRC_ERR_INTERNAL; + +ENQ_ERROR: + camsrc_error("Q Frame error occured"); + printf("Q Frame error occured"); + UNLOCK(handle); + return CAMERASRC_ERR_INTERNAL; +#endif +} + + +static int _camerasrc_ioctl_with_err(camerasrc_handle_t *handle, int request, void *arg, int *error) +{ + int fd = -1; + int err; + char err_msg[CAMERASRC_ERRMSG_MAX_LEN] = {'\0',}; + + if (handle == NULL) { + camsrc_error("NULL handle"); + return CAMERASRC_ERR_INVALID_PARAMETER; + } + + if (handle->fd_sensor < 0) { + camsrc_error("invalid fd %d", handle->fd_sensor); + return CAMERASRC_ERR_INVALID_PARAMETER; + } + + fd = handle->fd_sensor; + + LOCK(handle); + + *error = 0; + + PRINT_IOCTL_INFO(request, arg); + + do { + err = ioctl (fd, request, arg); + } while (-1 == err && EINTR == errno); + + if (err != 0) { + handle->errnum = errno; + *error = errno; + strerror_r(*error, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("ioctl[%x] err : %s", request, err_msg); + UNLOCK(handle); + return CAMERASRC_ERR_IO_CONTROL; + } + + UNLOCK(handle); + + return CAMERASRC_SUCCESS; +} + + +static int _camerasrc_ioctl_once(camerasrc_handle_t *handle, int request, void *arg) +{ + int fd = -1; + int err = -1; + int nAgain = 10; + char err_msg[CAMERASRC_ERRMSG_MAX_LEN] = {'\0',}; + + if (handle == NULL) { + camsrc_error("NULL handle"); + return CAMERASRC_ERR_INVALID_PARAMETER; + } + + if (handle->fd_sensor < 0) { + camsrc_error("invalid fd %d", handle->fd_sensor); + return CAMERASRC_ERR_INVALID_PARAMETER; + } + + fd = handle->fd_sensor; + + LOCK(handle); + + PRINT_IOCTL_INFO(request, arg); + +again: + err = ioctl (fd, request, arg); + + if (err != 0) { + handle->errnum = errno; + err = errno; + strerror_r(err, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("ioctl[%x] err : %s", request, err_msg); + if (err == EEXIST) { + camsrc_info("EEXIST occured, but can go."); + err = 0; + } else if (err == ENOENT) { + camsrc_info("ENOENT occured, but can go."); + err = 0; +#if defined (ENABLE_Q_ERROR) +#warning "ENABLE_Q_ERROR enabled" + } else if (request == VIDIOC_DQBUF) { + goto DQ_ERROR; + } else if (request == VIDIOC_QBUF) { + goto ENQ_ERROR; +#endif + } else if (err == EINVAL) { + camsrc_error("EINVAL occured, Shutdown"); + UNLOCK(handle); + return CAMERASRC_ERR_INVALID_PARAMETER; + } else if (err == EAGAIN && nAgain--) { + goto again; + } else { + camsrc_error("Unhandled exception occured on IOCTL"); + } + } + + UNLOCK(handle); + + return CAMERASRC_SUCCESS; + +#if defined (ENABLE_Q_ERROR) +DQ_ERROR: + camsrc_error("DQ Frame error occured"); + printf("DQ Frame error occured"); + UNLOCK(handle); + return CAMERASRC_ERR_INTERNAL; + +ENQ_ERROR: + camsrc_error("Q Frame error occured"); + printf("Q Frame error occured"); + UNLOCK(handle); + return CAMERASRC_ERR_INTERNAL; +#endif +} + + +static int _camerasrc_init_autofocusing_mode(camerasrc_handle_t *handle) +{ + int ctrl_id = V4L2_CID_AUTO_FOCUS_RANGE; + int mode; + + camsrc_info("enter"); + + if (!handle) { + camsrc_warning("handle is NULL"); + return CAMERASRC_ERR_NULL_POINTER; + } + + if (handle->cur_dev_id == CAMERASRC_DEV_ID_SECONDARY) { + camsrc_info("secondary camera does not support AF"); + return CAMERASRC_SUCCESS; + } + + if (handle->af_status == CAMERASRC_AUTO_FOCUS_STATUS_ONGOING) { + camsrc_info("Dev BUSY. Init failed."); + return CAMERASRC_ERR_INVALID_STATE; + } + + switch (handle->cur_af_mode) { + case CAMERASRC_AF_MODE_AUTO: + if (handle->cur_af_range == CAMERASRC_AF_RANGE_MACRO) { + mode = V4L2_AUTO_FOCUS_RANGE_MACRO; + camsrc_info("ON AUTOFOCUSING...BY AUTO_MACRO"); + } else { + mode = V4L2_AUTO_FOCUS_RANGE_NORMAL; + camsrc_info("ON AUTOFOCUSING...BY AUTO_NORMAL"); + } + break; + case CAMERASRC_AF_MODE_CONTINUOUS: + if (handle->cur_af_range == CAMERASRC_AF_RANGE_MACRO) { + mode = V4L2_AUTO_FOCUS_RANGE_MACRO; + camsrc_info("ON AUTOFOCUSING...BY CONTINUOUS_MACRO"); + } else { + mode = V4L2_AUTO_FOCUS_RANGE_NORMAL; + camsrc_info("ON AUTOFOCUSING...BY CONTINUOUS_NORMAL"); + } + break; + case CAMERASRC_AF_MODE_TOUCH_AUTO: + if (handle->cur_af_range == CAMERASRC_AF_RANGE_MACRO) { + mode = V4L2_AUTO_FOCUS_RANGE_MACRO; + camsrc_info("ON AUTOFOCUSING...BY TOUCH_AUTO_MACRO"); + } else { + mode = V4L2_AUTO_FOCUS_RANGE_NORMAL; + camsrc_info("ON AUTOFOCUSING...BY TOUCH_AUTO_NORMAL"); + } + break; + case CAMERASRC_AF_MODE_MANUAL: + camsrc_warning("MANUAL focusing is not supported."); + return CAMERASRC_ERR_DEVICE_NOT_SUPPORT; + case CAMERASRC_AF_MODE_PAN: + camsrc_warning("PAN MODE focusing is not supported."); + return CAMERASRC_ERR_DEVICE_NOT_SUPPORT; + default: + camsrc_warning("Unsupported AF mode[%d]", handle->cur_af_mode ); + return CAMERASRC_ERR_DEVICE_NOT_SUPPORT; + } + + GST_WARNING("set focus mode %d", mode); + + SET_CTRL_VAL(ctrl_id, mode); + + return CAMERASRC_SUCCESS; +} + + +static void* _camerasrc_run_autofocusing(camerasrc_handle_t *handle) +{ + int err = 0; + + camsrc_info("enter"); + + while (1) { + AF_MUT_LOCK(handle); + switch (handle->af_cmd) { + case CAMERASRC_AUTO_FOCUS_CMD_START: + { + if (CAMERASRC_STATE(handle) > CAMERASRC_STATE_READY && + handle->cur_dev_id == CAMERASRC_DEV_ID_PRIMARY) { + if (handle->cur_af_mode == CAMERASRC_AF_MODE_CONTINUOUS) { + camsrc_info("AF CMD: CONTINUOUS AF START"); + SET_CTRL_VAL_ERR(V4L2_CID_FOCUS_AUTO, 1, err); + } else { + camsrc_info("AF CMD: NORMAL AF START"); + SET_CTRL_VAL_ERR(V4L2_CID_FOCUS_AUTO, 0, err); + } + CAMERASRC_SET_STATE(handle, CAMERASRC_STATE_PREVIEW); + } else { + camsrc_warning("Invalid state %d or Not PRIMARY camera %d. skip AF:Start command...", + CAMERASRC_STATE(handle), handle->cur_dev_id); + } + + handle->af_status = CAMERASRC_AUTO_FOCUS_STATUS_RELEASED; + handle->af_cmd = CAMERASRC_AUTO_FOCUS_CMD_NULL; + break; + } + case CAMERASRC_AUTO_FOCUS_CMD_STOP: + { + if (handle->cur_dev_id == CAMERASRC_DEV_ID_PRIMARY) { + camsrc_info("AF CMD: CONTINUOUS AF STOP"); + + SET_CTRL_VAL_ERR(V4L2_CID_AUTO_FOCUS_STOP, 1, err); + + camsrc_info("Stopping AF done. err = %d", err); + } else { + camsrc_warning("Not PRIMARY camera. skip AF:Stop command..."); + } + + handle->af_status = CAMERASRC_AUTO_FOCUS_STATUS_RELEASED; + handle->af_cmd = CAMERASRC_AUTO_FOCUS_CMD_NULL; + AF_MUT_UNLOCK(handle); + continue; + } + case CAMERASRC_AUTO_FOCUS_CMD_KILL: + { + camsrc_info("AF CMD:KILL"); + + handle->af_status = CAMERASRC_AUTO_FOCUS_STATUS_RELEASED; + handle->af_cmd = CAMERASRC_AUTO_FOCUS_CMD_NULL; + + AF_MUT_UNLOCK(handle); + goto OUT_OF_LOOP; + } + case CAMERASRC_AUTO_FOCUS_CMD_NULL: + default: + { + char err_msg[CAMERASRC_ERRMSG_MAX_LEN] = {'\0',}; + camsrc_log("AF CMD:NULL...."); + err = pthread_cond_wait(&handle->af_wait_cond, &handle->af_mutex); + if (err) { + strerror_r(err, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("AF CMD pthread_cond_wait - err:(%s)", err_msg); + } + + AF_MUT_UNLOCK(handle); + + continue; + } + } + + AF_MUT_UNLOCK(handle); + usleep(CAMERASRC_AF_INTERVAL); + } + +OUT_OF_LOOP: + camsrc_info("AF thread is finished."); + return NULL; +} + +/* + Because of camerasrc_start_autofocusing() in camsrc-cam.c, _camerasrc_run_autofocusing is needed. + So I use below 'abled' function instead of 'disabled' one, even though the way uses one more thread with quite complex mechanism. + */ +static int _camerasrc_start_autofocusing(camerasrc_handle_t *handle) +{ + int err; + char err_msg[CAMERASRC_ERRMSG_MAX_LEN] = {'\0',}; + camsrc_info("enter"); + + AF_MUT_LOCK(handle); + + handle->af_cmd = CAMERASRC_AUTO_FOCUS_CMD_START; + err = pthread_cond_signal(&handle->af_wait_cond); + if (err) { + strerror_r(err, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_info("AF wait cond err(%s)", err_msg); + } + + AF_MUT_UNLOCK(handle); + + return CAMERASRC_SUCCESS; +} + +static int _camerasrc_stop_autofocusing(camerasrc_handle_t *handle) +{ + int err; + char err_msg[CAMERASRC_ERRMSG_MAX_LEN] = {'\0',}; + + camsrc_info("enter"); + + AF_MUT_LOCK(handle); + + handle->af_cmd = CAMERASRC_AUTO_FOCUS_CMD_STOP; + err = pthread_cond_signal(&handle->af_wait_cond); + if (err) { + strerror_r(err, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_info("AF wait cond err(%s)", err_msg); + } + + AF_MUT_UNLOCK(handle); + + return CAMERASRC_SUCCESS; +} + +static int _camerasrc_destroy_autofocusing(camerasrc_handle_t *handle) +{ + int err; + char err_msg[CAMERASRC_ERRMSG_MAX_LEN] = {'\0',}; + camsrc_info("enter"); + + AF_MUT_LOCK(handle); + + handle->af_cmd = CAMERASRC_AUTO_FOCUS_CMD_KILL; + err = pthread_cond_signal(&handle->af_wait_cond); + if (err) { + strerror_r(err, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_info("AF wait cond err(%s)", err_msg); + } + + AF_MUT_UNLOCK(handle); + + return CAMERASRC_SUCCESS; +} + + +static int _camerasrc_get_autofocusing_result(camerasrc_handle_t *handle) +{ + int err; + int af_result = V4L2_AUTO_FOCUS_STATUS_BUSY; + /* This is used for skipping same result. + Same AF-result is comming many times when focused or failed. */ + static int af_state = 0; + + camsrc_log("enter"); + + GET_CTRL_VAL_ERR(V4L2_CID_FOCUS_AUTO, af_result, err); + + camsrc_log("AF RESULT : 0x%x", af_result); + + switch (af_result) { + case V4L2_AUTO_FOCUS_STATUS_BUSY: + if (af_state != CAMERASRC_AUTO_FOCUS_RESULT_FUCUSING) { + af_state = CAMERASRC_AUTO_FOCUS_RESULT_FUCUSING; + handle->af_cb(handle, CAMERASRC_AUTO_FOCUS_RESULT_FUCUSING, handle->af_usr_data); + camsrc_info("AF Progressing..."); + } + break; + case V4L2_AUTO_FOCUS_STATUS_REACHED: + if (af_state != CAMERASRC_AUTO_FOCUS_RESULT_FOCUSED) { + af_state = CAMERASRC_AUTO_FOCUS_RESULT_FOCUSED; + handle->af_cb(handle, CAMERASRC_AUTO_FOCUS_RESULT_FOCUSED, handle->af_usr_data); + camsrc_info("AF Success"); + } + break; + case V4L2_AUTO_FOCUS_STATUS_FAILED: + if (af_state != CAMERASRC_AUTO_FOCUS_RESULT_FAILED) { + af_state = CAMERASRC_AUTO_FOCUS_RESULT_FAILED; + handle->af_cb(handle, CAMERASRC_AUTO_FOCUS_RESULT_FAILED, handle->af_usr_data); + camsrc_info("AF Fail"); + } + break; + default: + camsrc_warning("unknown AF result : 0x%x", af_result); + break; + } + + + return CAMERASRC_SUCCESS; +} + + +static int _camerasrc_get_frame_data(camerasrc_handle_t *handle, camerasrc_frame_data_t *data) +{ + /*camsrc_info("enter");*/ + if (handle == NULL || data == NULL) { + camsrc_error("NULL pointer"); + return CAMERASRC_ERR_NULL_POINTER; + } + + if (handle->buffer_scp) { + memcpy(&data->buffer, &handle->buffer_scp[data->index], sizeof(camerasrc_buffer_t)); + } else { + camsrc_error("buffer_scp is NULL"); + return CAMERASRC_ERR_NULL_POINTER; + } + + return CAMERASRC_SUCCESS; +} + + +static void _dump_exif_info(camerasrc_exif_t *exif_struct) +{ + camsrc_info("== Dynamic value =="); + camsrc_info("unsigned int exposure_time_numerator = %d", exif_struct->exposure_time_numerator); + camsrc_info("unsigned int exposure_time_denominator = %d", exif_struct->exposure_time_denominator); + camsrc_info("int shutter_speed_numerator = %d", exif_struct->shutter_speed_numerator); + camsrc_info("int shutter_speed_denominator = %d", exif_struct->shutter_speed_denominator); + camsrc_info("int brigtness_numerator = %d", exif_struct->brigtness_numerator); + camsrc_info("int brightness_denominator = %d", exif_struct->brightness_denominator); + camsrc_info("unsigned short int iso = %d", exif_struct->iso); + camsrc_info("unsigned short int flash = %d", exif_struct->flash); + camsrc_info("int metering_mode = %d", exif_struct->metering_mode); + camsrc_info("int exif_image_width = %d", exif_struct->exif_image_width); + camsrc_info("int exif_image_height = %d", exif_struct->exif_image_height); + + camsrc_info("== Fixed value =="); + camsrc_info("int software_used = %d", exif_struct->software_used); + camsrc_info("int focal_len_numerator = %d", exif_struct->focal_len_numerator); + camsrc_info("int focal_len_denominator = %d", exif_struct->focal_len_denominator); + camsrc_info("int aperture_f_num_numerator = %d", exif_struct->aperture_f_num_numerator); + camsrc_info("int aperture_f_num_denominator = %d", exif_struct->aperture_f_num_denominator); + camsrc_info("int aperture_in_APEX = %d", exif_struct->aperture_in_APEX); + camsrc_info("int max_lens_aperture_in_APEX = %d", exif_struct->max_lens_aperture_in_APEX); + camsrc_info("int exposure_bias_in_APEX = %d", exif_struct->exposure_bias_in_APEX); + camsrc_info("int component_configuration = %x", exif_struct->component_configuration); + camsrc_info("int colorspace = %d", exif_struct->colorspace); + + return; +} + + +static int _camerasrc_get_exif_info(camerasrc_handle_t *handle, camerasrc_exif_t *exif_struct) +{ + int photometry_mode = V4L2_EXPOSURE_METERING_AVERAGE; + + if (exif_struct == NULL) { + return CAMERASRC_ERR_INVALID_PARAMETER; + } + + /** + * Dynamic value + **/ + /* exposure time */ + exif_struct->exposure_time_numerator = handle->current_exif.exposure_time.numerator; + exif_struct->exposure_time_denominator = handle->current_exif.exposure_time.denominator; + + /* shutter speed */ + exif_struct->shutter_speed_numerator = handle->current_exif.shutter_speed.numerator; + exif_struct->shutter_speed_denominator = handle->current_exif.shutter_speed.denominator; + + /* brightness */ + exif_struct->brigtness_numerator = handle->current_exif.brightness.numerator; + exif_struct->brightness_denominator = handle->current_exif.brightness.denominator; + + /* iso */ + exif_struct->iso = handle->current_exif.iso_speed_rating; + ISO_APPROXIMATE_VALUE(exif_struct->iso, exif_struct->iso); + + /* flash */ + exif_struct->flash = handle->current_exif.flash; + + /* image size */ + exif_struct->exif_image_width = handle->format_scp.img_size.width; + exif_struct->exif_image_height = handle->format_scp.img_size.height; + + /* Get the value using CID */ + /* Not implemented yet + GET_CTRL_VAL(V4L2_CID_FW_VERSION, exif_struct->software_used); + */ + + /* metering */ + if (handle->cur_dev_id == CAMERASRC_DEV_ID_PRIMARY) { + camsrc_log(" V4L2_CID_EXPOSURE_METERING"); + GET_CTRL_VAL(V4L2_CID_EXPOSURE_METERING, photometry_mode); + PHOTOMETRY_MODE_TO_METERING_MODE(photometry_mode, exif_struct->metering_mode); + } else { + exif_struct->metering_mode = V4L2_EXPOSURE_METERING_AVERAGE; + } + + /** + * Fixed value + **/ + if (handle->cur_dev_id == CAMERASRC_DEV_ID_PRIMARY) { + /* focal length */ + exif_struct->focal_len_numerator = EXIF_DEFAULT_FOCAL_LENGTH_NUMERATOR_REAR; + exif_struct->focal_len_denominator = EXIF_DEFAULT_FOCAL_LENGTH_DENOMINATOR_REAR; + + /* f number */ + exif_struct->aperture_f_num_numerator = EXIF_DEFAULT_FNUMBER_NUMERATOR_REAR; + exif_struct->aperture_f_num_denominator = EXIF_DEFAULT_FNUMBER_DENOMINATOR_REAR; + } else { + /* focal length */ + exif_struct->focal_len_numerator = EXIF_DEFAULT_FOCAL_LENGTH_NUMERATOR_FRONT; + exif_struct->focal_len_denominator = EXIF_DEFAULT_FOCAL_LENGTH_DENOMINATOR_FRONT; + + /* f number */ + exif_struct->aperture_f_num_numerator = EXIF_DEFAULT_FNUMBER_NUMERATOR_FRONT; + exif_struct->aperture_f_num_denominator = EXIF_DEFAULT_FNUMBER_DENOMINATOR_FRONT; + } + + /* aperture value */ + exif_struct->aperture_in_APEX \ + = CAMERASRC_EXIF_APERTURE_VALUE_IN_APEX(exif_struct->aperture_f_num_numerator, exif_struct->aperture_f_num_denominator); + exif_struct->max_lens_aperture_in_APEX = exif_struct->aperture_in_APEX; + + /* exposure bias */ + exif_struct->exposure_bias_in_APEX = exif_struct->aperture_in_APEX \ + + CAMERASRC_EXIF_SHUTTERSPEED_VALUE_IN_APEX(exif_struct->exposure_time_numerator, exif_struct->exposure_time_denominator); + + /* component configuration */ + exif_struct->component_configuration = EXIF_DEFAULT_COMPONENT_CONFIGRATION; + + /* color space */ + exif_struct->colorspace = EXIF_DEFAULT_COLOR_SPACE; + + _dump_exif_info(exif_struct); + + return CAMERASRC_SUCCESS; +} + + +static int _camerasrc_set_cmd(camerasrc_handle_t *handle, _camsrc_cmd_t cmd, void *value) +{ + int err = CAMERASRC_ERR_UNKNOWN; + + switch (cmd) { + case _CAMERASRC_CMD_STROBE_MODE: + { + camerasrc_strobe_mode_t *mode = (camerasrc_strobe_mode_t*)value; + + camsrc_info("[_CAMERASRC_CMD_STROBE_MODE] cmd set value %d", *mode ); + + //SET_CTRL_VAL(V4L2_CID_HW_FLASH_MODE, *mode); + } + break; + case _CAMERASRC_CMD_SHUTTER_SPEED: + /* WRITEME */ + camsrc_info("[_CAMERASRC_CMD_SHUTTER_SPEED] cmd set"); + break; + case _CAMERASRC_CMD_EXPOSURE_VALUE: + camsrc_info("[_CAMERASRC_CMD_EXPOSURE_VALUE] cmd set"); + /* WRITEME */ + break; + case _CAMERASRC_CMD_CTRL: + camsrc_info("[_CAMERASRC_CMD_CTRL] cmd set"); + SET_CTRL_VAL(_CAMERASRC_GET_CID(((_camerasrc_ctrl_t *) value)->cid, handle->cur_dev_id), ((_camerasrc_ctrl_t *) value)->value); + break; + case _CAMERASRC_CMD_AF_CONTROL: + /* WRITEME */ + camsrc_info("[_CAMERASRC_CMD_AF_CONTROL] cmd set(value=%d)", (int)value); + + /* FIXME : Please fix whole AF implementation!!! */ + switch ((int)value) { + case _CAMERASRC_AF_START: + _camerasrc_start_autofocusing(handle); + break; + case _CAMERASRC_AF_STOP: + _camerasrc_stop_autofocusing(handle); + break; + case _CAMERASRC_AF_DESTROY: + _camerasrc_destroy_autofocusing(handle); + break; + case _CAMERASRC_AF_RESULT: + camsrc_info("Not support : SET AF result"); + break; + case _CAMERASRC_AF_RELEASE: + case _CAMERASRC_AF_INIT: + default: + _camerasrc_init_autofocusing_mode(handle); + break; + } + break; + case _CAMERASRC_CMD_AF_AREA: + { + camerasrc_rect_t *rect = (camerasrc_rect_t *)value; + + camsrc_info("[_CAMERASRC_CMD_AF_AREA] cmd set (%d,%d,%dx%d)", + rect->x, rect->y, rect->width, rect->height); +#if 0 + SET_CTRL_VAL(V4L2_CID_FOCUS_AUTO_RECTANGLE_LEFT, rect->x); + SET_CTRL_VAL(V4L2_CID_FOCUS_AUTO_RECTANGLE_TOP, rect->y); + SET_CTRL_VAL(V4L2_CID_FOCUS_AUTO_RECTANGLE_WIDTH, 0);/*rect->width); Not supported */ + SET_CTRL_VAL(V4L2_CID_FOCUS_AUTO_RECTANGLE_HEIGHT, 0);/*rect->height); Not supported */ +#else + camsrc_warning("AF area set is not supported"); +#endif + break; + } + case _CAMERASRC_CMD_FRAME_DATA: + /* WRITEME */ + camsrc_info("[_CAMERASRC_CMD_FRAME_DATA] cmd set"); + break; + case _CAMERASRC_CMD_EXIF_INFO: + /* WRITEME */ + camsrc_info("[_CAMERASRC_CMD_EXIF_INFO] cmd set"); + break; + case _CAMERASRC_CMD_ROTATION: + { + int *rotate = (int *)value; + camsrc_info("[_CAMERASRC_CMD_ROTATION] cmd set : %d", *rotate); + SET_CTRL_VAL(V4L2_CID_ROTATE, (int)*rotate); + } + break; + case _CAMERASRC_CMD_VFLIP: + { + int *vflip = (int *)value; + camsrc_info("[_CAMERASRC_CMD_VFLIP] cmd set : %d", *vflip); + SET_CTRL_VAL(V4L2_CID_VFLIP, (int)*vflip); + } + break; + case _CAMERASRC_CMD_HFLIP: + { + int *hflip = (int *)value; + camsrc_info("[_CAMERASRC_CMD_HFLIP] cmd set : %d", *hflip); + SET_CTRL_VAL(V4L2_CID_HFLIP, (int)*hflip); + } + break; + default: + camsrc_error("[_CAMERASRC_CMD_UNKNOWN] cmd set"); + err = CAMERASRC_ERR_DEVICE_NOT_SUPPORT; + goto ERROR; + } + + return CAMERASRC_SUCCESS; + +ERROR: + camsrc_error("cmd execution error occured"); + + return err; +} + +static int _camerasrc_get_cmd(camerasrc_handle_t *handle, _camsrc_cmd_t cmd, void *value) +{ + int err = CAMERASRC_ERR_UNKNOWN; + + if (!value) { + camsrc_error("value is NULL"); + return CAMERASRC_ERR_NULL_POINTER; + } + + switch (cmd) { + case _CAMERASRC_CMD_STROBE_MODE: + { + camerasrc_strobe_mode_t mode = 0; + + //GET_CTRL_VAL(V4L2_CID_HW_FLASH_MODE, mode); + *((camerasrc_strobe_mode_t*)value) = mode; + + camsrc_info("[_CAMERASRC_CMD_STROBE_MODE] cmd get - %d", mode); + } + break; + case _CAMERASRC_CMD_SHUTTER_SPEED: + /* WRITEME */ + camsrc_info("[_CAMERASRC_CMD_SHUTTER_SPEED] cmd get"); + break; + case _CAMERASRC_CMD_EXPOSURE_VALUE: + /* WRITEME */ + camsrc_info("[_CAMERASRC_CMD_EXPOSURE_VALUE] cmd get"); + break; + case _CAMERASRC_CMD_CTRL: + camsrc_info("[_CAMERASRC_CMD_CTRL] cmd get"); + GET_CTRL_VAL(_CAMERASRC_GET_CID(((_camerasrc_ctrl_t *) value)->cid, handle->cur_dev_id), ((_camerasrc_ctrl_t *) value)->value); + break; + case _CAMERASRC_CMD_AF_CONTROL: + camsrc_log("[_CAMERASRC_CMD_AF_CONTROL] cmd get"); + switch ((int)value) { + case _CAMERASRC_AF_RESULT: + _camerasrc_get_autofocusing_result(handle); + break; + default: + camsrc_info("Not support : GET AF CONTROL [%d]", (int)value); + break; + } + break; + case _CAMERASRC_CMD_AF_AREA: + { + camerasrc_rect_t* rect = (camerasrc_rect_t*)value; +#if 0 + GET_CTRL_VAL(V4L2_CID_FOCUS_AUTO_RECTANGLE_LEFT, rect->x); + GET_CTRL_VAL(V4L2_CID_FOCUS_AUTO_RECTANGLE_TOP, rect->y); + GET_CTRL_VAL(V4L2_CID_FOCUS_AUTO_RECTANGLE_WIDTH, rect->width); + GET_CTRL_VAL(V4L2_CID_FOCUS_AUTO_RECTANGLE_HEIGHT, rect->height); +#else + camsrc_warning("AF area is not supported"); +#endif + camsrc_info("[_CAMERASRC_CMD_AF_AREA] cmd get (%d,%d,%dx%d)", + rect->x, rect->y, rect->width, rect->height); + break; + } + case _CAMERASRC_CMD_FRAME_DATA: + /* WRITEME */ + /*camsrc_info("[_CAMERASRC_CMD_FRAME_DATA] cmd get");*/ + err = _camerasrc_get_frame_data(handle, (camerasrc_frame_data_t*)value); + if (err != CAMERASRC_SUCCESS) { + goto ERROR; + } + break; + case _CAMERASRC_CMD_EXIF_INFO: + camsrc_info("[_CAMERASRC_CMD_EXIF_INFO] cmd get"); + err = _camerasrc_get_exif_info (handle, (camerasrc_exif_t*)value); + if (err != CAMERASRC_SUCCESS) { + goto ERROR; + } + break; + case _CAMERASRC_CMD_ROTATION: + camsrc_info("[_CAMERASRC_CMD_ROTATION] cmd get"); + GET_CTRL_VAL(V4L2_CID_ROTATE, *(int*)value); + break; + case _CAMERASRC_CMD_VFLIP: + camsrc_info("[_CAMERASRC_CMD_VFLIP] cmd get"); + GET_CTRL_VAL(V4L2_CID_VFLIP, *(int*)value); + break; + case _CAMERASRC_CMD_HFLIP: + camsrc_info("[_CAMERASRC_CMD_HFLIP] cmd get"); + GET_CTRL_VAL(V4L2_CID_HFLIP, *(int*)value); + break; + default: + camsrc_error("[_CAMERASRC_CMD_UNKNOWN] cmd get"); + err = CAMERASRC_ERR_DEVICE_NOT_SUPPORT; + goto ERROR; + } + + return CAMERASRC_SUCCESS; + +ERROR: + camsrc_error("cmd execution error occured"); + + return err; +} + +static const CAMERASRC_DEV_DEPENDENT_MISC_FUNC dev_misc_functions = { + ._ioctl = _camerasrc_ioctl, + ._ioctl_once = _camerasrc_ioctl_once, + ._run_autofocusing = _camerasrc_run_autofocusing, + ._set_cmd = _camerasrc_set_cmd, + ._get_cmd = _camerasrc_get_cmd, +}; + +const CAMERASRC_DEV_DEPENDENT_MISC_FUNC *dev_misc_func = &dev_misc_functions; diff --git a/camerasrc/src/camerasrc.c b/camerasrc/src/camerasrc.c new file mode 100644 index 0000000..5a0e836 --- /dev/null +++ b/camerasrc/src/camerasrc.c @@ -0,0 +1,3718 @@ +/* + * camerasrc + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jeongmo Yang <jm80.yang@samsung.com> + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <stdint.h> +#include <unistd.h> +#include <poll.h> +#include <exynos_drm.h> +#include <libdrm/drm.h> +#include <linux/v4l2-subdev.h> + +#include "camerasrc-common.h" +#include "camerasrc-internal.h" +#include "fimc-is-metadata.h" + + +#define S_FMT_COUNT 2 +#define BUF_LEN 64 + +/* + * LOCAL DEFINITIONS + */ +#ifndef EXPORT_API +#define EXPORT_API __attribute__((__visibility__("default"))) +#endif + +#define LOCK(p) {\ + if(0 != pthread_mutex_lock(&(p->mutex))) {\ + camsrc_error("Mutex locking error");\ + camsrc_assert(0);\ + }\ +} + +#define UNLOCK(p) {\ + if(0 != pthread_mutex_unlock(&(p->mutex))) {\ + camsrc_error("Mutex unlocking error");\ + camsrc_assert(0);\ + }\ +} + +/* Extended CID */ +#ifndef V4L2_CID_FIMC_IS_BASE +#define V4L2_CID_FIMC_IS_BASE (V4L2_CTRL_CLASS_CAMERA | 0x1000) +#endif /* V4L2_CID_FIMC_IS_BASE */ +#ifndef V4L2_CID_IS_SET_SETFILE +#define V4L2_CID_IS_SET_SETFILE (V4L2_CID_FIMC_IS_BASE + 51) +#endif /* V4L2_CID_IS_SET_SETFILE */ +#ifndef V4L2_CID_IS_COLOR_RANGE +#define V4L2_CID_IS_COLOR_RANGE (V4L2_CID_FIMC_IS_BASE + 54) +#endif /* V4L2_CID_IS_COLOR_RANGE */ +#ifndef V4L2_CID_IS_MIN_TARGET_FPS +#define V4L2_CID_IS_MIN_TARGET_FPS (V4L2_CID_FIMC_IS_BASE + 55) +#endif /* V4L2_CID_IS_MIN_TARGET_FPS */ +#ifndef V4L2_CID_IS_MAX_TARGET_FPS +#define V4L2_CID_IS_MAX_TARGET_FPS (V4L2_CID_FIMC_IS_BASE + 56) +#endif /* V4L2_CID_IS_MAX_TARGET_FPS */ +#ifndef V4L2_CID_IS_S_STREAM +#define V4L2_CID_IS_S_STREAM (V4L2_CID_FIMC_IS_BASE + 14) +#endif /* V4L2_CID_IS_S_STREAM */ + + +/* FIMC IS NUM */ +#define FIMC_IS_VIDEO_3A1_NUM 14 +#define FIMC_IS_VIDEO_3A1P_NUM 16 +#define FIMC_IS_VIDEO_ISP_NUM 30 +#define FIMC_IS_VIDEO_SCC_NUM 34 +#define FIMC_IS_VIDEO_SCP_NUM 37 + +/* struct camera2_internal_udm */ +#define FIMC_IS_ISP_VS2_INIT 0x003F8CE4 +#define FIMC_IS_ISP_VS2_STEP 0x8350 +#define FIMC_IS_ISP_VS2_RANGE 40 + +/* Magic Number */ +#define METADATA_MAGIC_NUMBER 0x23456789 + +/* GROUP ID */ +#define GRP_SENSOR 0x01 +#define GRP_3AA 0x02 +#define GRP_3AAP 0x03 +#define GRP_ISP 0x04 +#define GRP_DIS 0x05 +#define GRP_SCC 0x06 +#define GRP_SCP 0x07 + + +extern const CAMERASRC_DEV_DEPENDENT_MISC_FUNC *dev_misc_func; + +/** proto type of internal function **/ +static int buf_4k_align(unsigned int buf_size); +static int __camerasrc_open_device(camerasrc_handle_t *p, camerasrc_dev_id_t camera_id); +static void __camerasrc_close_device(camerasrc_handle_t *p); +int _camerasrc_ioctl(camerasrc_handle_t *handle, int fd, int request, void *arg); +int _camerasrc_ioctl_once(camerasrc_handle_t *handle, int request, void *arg); +void *_camerasrc_run_autofocusing(camerasrc_handle_t *handle); +int _camerasrc_ioctl_s_ctrl(camerasrc_handle_t *p, int fd, guint cid, int value); +int _camerasrc_ioctl_g_ctrl(camerasrc_handle_t *p, int fd, guint cid, int *value); +int _camerasrc_ioctl_s_parm(camerasrc_handle_t *p, int fd, int type, int numerator, int denominator); +int _camerasrc_ioctl_s_fmt(camerasrc_handle_t *p, int fd, int type, camerasrc_format_t *format); +int _camerasrc_ioctl_reqbufs(camerasrc_handle_t *p, int fd, guint count, int type, int memory, guint *ret_count); +int _camerasrc_ioctl_qbuf(camerasrc_handle_t *p, int fd, int type, int memory, int idx, camerasrc_buffer_t *buffer); +int _camerasrc_ioctl_dqbuf(camerasrc_handle_t *p, int fd, int type, int memory, int *idx, int num_planes); +int _camerasrc_ioctl_stream(camerasrc_handle_t *p, int fd, int type, int on); + + +/**** A U T O F O C U S I N G F U N C T I O N S ****/ +int _camerasrc_set_autofocusing_area(camerasrc_handle_t *handle, camerasrc_rect_t *rect); +int _camerasrc_get_autofocusing_area(camerasrc_handle_t *handle, camerasrc_rect_t *rect); +int _camerasrc_start_autofocusing(camerasrc_handle_t *handle); +int _camerasrc_stop_autofocusing(camerasrc_handle_t *handle); +int _camerasrc_release_autofocusing(camerasrc_handle_t *handle); +int _camerasrc_destroy_autofocusing(camerasrc_handle_t *handle); +int _camerasrc_init_autofocusing_mode(camerasrc_handle_t *handle); +int _camerasrc_get_autofocusing_result(camerasrc_handle_t *handle); + +int _camerasrc_get_frame_data(camerasrc_handle_t *handle, camerasrc_frame_data_t *data); +int _camerasrc_get_exif_info(camerasrc_handle_t *handle, camerasrc_buffer_t *exif_string); + +static int _camerasrc_set_shot_meta(camerasrc_handle_t *p, unsigned int grpid, int fcount, + unsigned long long timestamp, struct camera2_shot_ext *shot_ext); + + +/* media definitions */ +#define VIDEO_DEVICE_NODE_PRIMARY "/dev/video1" +#define VIDEO_DEVICE_NODE_SECONDARY "/dev/video101" +#define VIDEO_DEVICE_NODE_COMPANION "/dev/video109" +#define VIDEO_DEVICE_NODE_ISP "/dev/video130" +#define VIDEO_DEVICE_NODE_3AA1 "/dev/video114" +#define VIDEO_DEVICE_NODE_3AA1C "/dev/video115" +#define VIDEO_DEVICE_NODE_SCC "/dev/video134" +#define VIDEO_DEVICE_NODE_SCP "/dev/video137" + +#define SENSOR_MARGIN_WIDTH 16 +#define SENSOR_MARGIN_HEIGHT 16 +#define FRONT_SENSOR_SIZE_WIDTH 2560 +#define FRONT_SENSOR_SIZE_HEIGHT 1440 + +#define CAMERASRC_SET_CMD(cmd, value) _camerasrc_set_cmd(handle, cmd, (void*)value); +#define CAMERASRC_GET_CMD(cmd, value) _camerasrc_get_cmd(handle, cmd, (void*)value); + +static int buf_4k_align(unsigned int buf_size) +{ + unsigned int ret; + + if (buf_size & (PAGE_SIZE - 1)) { + camsrc_info("buf_size(0x%08x) is not 4K aligned", buf_size); + ret = buf_size + PAGE_SIZE; + ret &= PAGE_MASK; + } else { + camsrc_info("buf_size(0x%08x) is 4K aligned", buf_size); + ret = buf_size; + } + + return ret; + +} + + +static int _camerasrc_set_cmd(camsrc_handle_t handle, _camsrc_cmd_t cmd, void *value) +{ + camerasrc_handle_t *p = NULL; + int err = CAMERASRC_ERR_UNKNOWN; + + camsrc_info("enter"); + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + if (dev_misc_func->_set_cmd == NULL) { + return CAMERASRC_ERR_DEVICE_NOT_SUPPORT; + } + + err = dev_misc_func->_set_cmd(p, cmd, value); + + return err; +} + +static int _camerasrc_get_cmd(camsrc_handle_t handle, _camsrc_cmd_t cmd, void *value) +{ + camerasrc_handle_t *p = NULL; + int err = CAMERASRC_ERR_UNKNOWN; + + if(handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + if(dev_misc_func->_get_cmd == NULL) + return CAMERASRC_ERR_DEVICE_NOT_SUPPORT; + + err = dev_misc_func->_get_cmd(p, cmd, value); + + return err; +} + + +int camerasrc_extract_exif_info_from_capture_data(camsrc_handle_t handle, camerasrc_capture_data_info *capture_data) +{ + camerasrc_handle_t *p = CAMERASRC_HANDLE(handle); + + if (!p || !capture_data) { + camsrc_error("pointer is NULL"); + return CAMERASRC_ERR_NULL_POINTER; + } + + if (TRUE) { + camsrc_error("set default."); + + p->current_exif.shutter_speed.numerator = 1; + p->current_exif.shutter_speed.denominator = EXIF_DEFAULT_SHUTTER_SPEED_DENOMINATOR; + p->current_exif.exposure_time.numerator = EXIF_DEFAULT_EXPOSURE_TIME_NUMERATOR; + p->current_exif.exposure_time.denominator = 1; + p->current_exif.brightness.numerator = 1; + p->current_exif.brightness.denominator = EXIF_DEFAULT_BRIGHTNESS_DENOMINATOR; + p->current_exif.iso_speed_rating = EXIF_DEFAULT_ISO_SPEED_RATING; + + return CAMERASRC_ERR_NULL_POINTER; + } + + /* flash */ + if (capture_data->flash_activated) { + p->current_exif.flash = TRUE; + } else { + p->current_exif.flash = FALSE; + } + + p->current_exif.shutter_speed.denominator = EXIF_DEFAULT_SHUTTER_SPEED_DENOMINATOR; + p->current_exif.exposure_time.numerator = EXIF_DEFAULT_EXPOSURE_TIME_NUMERATOR; + p->current_exif.brightness.denominator = EXIF_DEFAULT_BRIGHTNESS_DENOMINATOR; + + if (p->cur_dev_id == CAMERASRC_DEV_ID_PRIMARY) { + /* TODO */ + /* shutter speed */ + /* exposure time */ + /* brightness */ + /* iso */ + } else { + /* TODO */ + /* shutter speed */ + /* exposure time */ + /* brightness */ + /* iso */ + } + + camsrc_info("flash %d, shutter_speed %d/%d, exposure_time %d/%d, brightness %d/%d, iso_speed_rating %d", + p->current_exif.flash, + p->current_exif.shutter_speed.numerator, p->current_exif.shutter_speed.denominator, + p->current_exif.exposure_time.numerator, p->current_exif.exposure_time.denominator, + p->current_exif.brightness.numerator, p->current_exif.brightness.denominator, + p->current_exif.iso_speed_rating); + + return CAMERASRC_SUCCESS; +} + + +int camerasrc_get_screennail_buffer(camsrc_handle_t handle, camerasrc_buffer_t *scrnl_buf) +{ + camerasrc_handle_t *p = NULL; + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + if (scrnl_buf == NULL) { + camsrc_error("scrnl_buf is null"); + return CAMERASRC_ERR_INVALID_PARAMETER; + } + + p = CAMERASRC_HANDLE(handle); + + scrnl_buf->planes[0].start = p->scrnl_buf.planes[0].start; + scrnl_buf->planes[0].length = p->scrnl_buf.planes[0].length; + + camsrc_info("screennail ptr[%p],length[%d]", scrnl_buf->planes[0].start, scrnl_buf->planes[0].length); + + return CAMERASRC_SUCCESS; +} + + +int camerasrc_set_shutter_speed(camsrc_handle_t handle, camerasrc_frac_t frac) +{ + return CAMERASRC_SET_CMD(_CAMERASRC_CMD_SHUTTER_SPEED, &frac); +} + + +int camerasrc_get_shutter_speed(camsrc_handle_t handle, camerasrc_frac_t *frac) +{ + return CAMERASRC_GET_CMD(_CAMERASRC_CMD_SHUTTER_SPEED, frac); +} + + +int camerasrc_set_exposure_value(camsrc_handle_t handle, camerasrc_frac_t frac) +{ + return CAMERASRC_SET_CMD(_CAMERASRC_CMD_EXPOSURE_VALUE, &frac); +} + + +int camerasrc_get_exposure_value(camsrc_handle_t handle, camerasrc_frac_t *frac) +{ + return CAMERASRC_GET_CMD(_CAMERASRC_CMD_EXPOSURE_VALUE, frac); +} + + +int camerasrc_set_strobe_mode(camsrc_handle_t handle, camerasrc_strobe_mode_t mode) +{ + return CAMERASRC_SET_CMD(_CAMERASRC_CMD_STROBE_MODE, &mode); +} + + +int camerasrc_get_strobe_mode(camsrc_handle_t handle, camerasrc_strobe_mode_t *mode) +{ + return CAMERASRC_GET_CMD(_CAMERASRC_CMD_STROBE_MODE, mode); +} + + +int camerasrc_set_control(camsrc_handle_t handle, camerasrc_ctrl_t ctrl_id, int value) +{ + _camerasrc_ctrl_t ctrl; + + CLEAR(ctrl); + + ctrl.cid = ctrl_id; + ctrl.value = value; + + return CAMERASRC_SET_CMD(_CAMERASRC_CMD_CTRL, &ctrl); +} + + +int camerasrc_get_control(camsrc_handle_t handle, camerasrc_ctrl_t ctrl_id, int *value) +{ + int err = CAMERASRC_ERR_UNKNOWN; + _camerasrc_ctrl_t ctrl; + + CLEAR(ctrl); + + ctrl.cid = ctrl_id; + + err = CAMERASRC_GET_CMD(_CAMERASRC_CMD_CTRL, &ctrl); + if (err != CAMERASRC_SUCCESS) { + return err; + } + + *value = ctrl.value; + + return err; +} + + +int _camerasrc_ioctl(camerasrc_handle_t *handle, int fd, int request, void *arg) +{ + if (dev_misc_func->_ioctl == NULL) { +#if USE_NOT_SUPPORT_ERR + return CAMERASRC_ERR_DEVICE_NOT_SUPPORT; +#else + return CAMERASRC_SUCCESS; +#endif + } + + return dev_misc_func->_ioctl(handle, fd, request, arg); +} + + +int _camerasrc_ioctl_once(camerasrc_handle_t *handle, int request, void *arg) +{ + if (dev_misc_func->_ioctl_once == NULL) { +#if USE_NOT_SUPPORT_ERR + return CAMERASRC_ERR_DEVICE_NOT_SUPPORT; +#else + return CAMERASRC_SUCCESS; +#endif + } + + return dev_misc_func->_ioctl_once(handle, request, arg); +} + + +void *_camerasrc_run_autofocusing(camerasrc_handle_t *handle) +{ + if (dev_misc_func->_run_autofocusing != NULL) { + dev_misc_func->_run_autofocusing(handle); + } + + return NULL; +} + + +int _camerasrc_ioctl_s_ctrl(camerasrc_handle_t *p, int fd, guint cid, int value) +{ + struct v4l2_control ctrl; + + if (p == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + ctrl.id = cid; + ctrl.value = value; + + return _camerasrc_ioctl(p, fd, VIDIOC_S_CTRL, &ctrl); +} + + +int _camerasrc_ioctl_g_ctrl(camerasrc_handle_t *p, int fd, guint cid, int *value) +{ + int ret = CAMERASRC_SUCCESS; + struct v4l2_control ctrl; + + if (p == NULL || value == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + ctrl.id = cid; + + ret = _camerasrc_ioctl(p, fd, VIDIOC_G_CTRL, &ctrl); + if (ret == CAMERASRC_SUCCESS) { + *value = ctrl.value; + } else { + camsrc_error("VIDIOC_G_CTRL failed. %x", ret); + } + + return ret; +} + + +int _camerasrc_ioctl_s_parm(camerasrc_handle_t *p, int fd, int type, int numerator, int denominator) +{ + struct v4l2_streamparm vstreamparm; + + if (p == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + CLEAR(vstreamparm); + + camsrc_info("ENTER : type %d", type); + + vstreamparm.type = type; + vstreamparm.parm.capture.timeperframe.numerator = numerator; + vstreamparm.parm.capture.timeperframe.denominator = denominator; + + camsrc_info("[FPS] timeperframe.numerator = %d", numerator); + camsrc_info("[FPS] timeperframe.denominator = %d", denominator); + + return _camerasrc_ioctl(p, fd, VIDIOC_S_PARM, &vstreamparm); +} + + +int _camerasrc_ioctl_s_fmt(camerasrc_handle_t *p, int fd, int type, camerasrc_format_t *format) +{ + int i = 0; + int width = 0; + int height = 0; + struct v4l2_format vformat; + char err_msg[CAMERASRC_ERRMSG_MAX_LEN] = {'\0',}; + + if (p == NULL || fd < 0 || format ==NULL) { + camsrc_error("INVALID parameter %p %d %p", p, fd, format); + return CAMERASRC_ERR_INVALID_PARAMETER; + } + + memset(&vformat, 0x0, sizeof(struct v4l2_format)); + + width = format->img_size.width; + height = format->img_size.height; + + camsrc_info("ENTER - type %d, format %d, %dx%d", + type, format->pix_format, width, height); + + vformat.type = type; + vformat.fmt.pix_mp.width = width; + vformat.fmt.pix_mp.height = height; + vformat.fmt.pix_mp.field = V4L2_FIELD_ANY; + vformat.fmt.pix_mp.colorspace = V4L2_COLORSPACE_JPEG; + + switch (format->pix_format) { + case CAMERASRC_PIX_NV12: + vformat.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_NV12; + vformat.fmt.pix_mp.num_planes = 2; + //vformat.fmt.pix_mp.plane_fmt[0].bytesperline = (width * 3) >> 1; + //vformat.fmt.pix_mp.plane_fmt[0].sizeimage = (width * height * 3) >> 1; + break; + case CAMERASRC_PIX_SN12: + vformat.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_NV12M; + vformat.fmt.pix_mp.num_planes = 3; + //vformat.fmt.pix_mp.plane_fmt[0].bytesperline = width; + //vformat.fmt.pix_mp.plane_fmt[0].sizeimage = width * height; + //vformat.fmt.pix_mp.plane_fmt[1].bytesperline = width >> 1; + //vformat.fmt.pix_mp.plane_fmt[1].sizeimage = (width * height) >> 1; + break; + case CAMERASRC_PIX_NV21: + vformat.fmt.pix.pixelformat = V4L2_PIX_FMT_NV21; + vformat.fmt.pix_mp.num_planes = 2; + //vformat.fmt.pix.bytesperline = (width * 3) >> 1; + //vformat.fmt.pix.sizeimage = (width * height * 3) >> 1; + break; + case CAMERASRC_PIX_SN21: + vformat.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_NV21M; + vformat.fmt.pix_mp.num_planes = 3; + //vformat.fmt.pix_mp.plane_fmt[0].bytesperline = width; + //vformat.fmt.pix_mp.plane_fmt[0].sizeimage = width * height; + //vformat.fmt.pix_mp.plane_fmt[1].bytesperline = width >> 1; + //vformat.fmt.pix_mp.plane_fmt[1].sizeimage = (width * height) >> 1; + break; + case CAMERASRC_PIX_SBGGR12: + vformat.fmt.pix.pixelformat = V4L2_PIX_FMT_SBGGR12; + vformat.fmt.pix_mp.num_planes = 2; + //vformat.fmt.pix.bytesperline = ((width + 9) / 10) * 10 * 8 / 5; + //vformat.fmt.pix.sizeimage = vformat.fmt.pix.bytesperline * height; + break; + default: + camsrc_warning("invalid output format = %d, set NV12", format->pix_format); + vformat.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_NV12; + vformat.fmt.pix_mp.num_planes = 2; + //vformat.fmt.pix_mp.plane_fmt[0].bytesperline = (width * 3) >> 1; + //vformat.fmt.pix_mp.plane_fmt[0].sizeimage = (width * height * 3) >> 1; + break; + } + + format->num_planes = vformat.fmt.pix_mp.num_planes; + + camsrc_info("== %d ======================================", i); + camsrc_info("| Request output type = %d", vformat.type); + camsrc_info("| Request output width = %d", vformat.fmt.pix_mp.width); + camsrc_info("| Request output height = %d", vformat.fmt.pix_mp.height); + camsrc_info("| Request output field = %d", vformat.fmt.pix_mp.field); + camsrc_info("| Request output pixel format = %c%c%c%c", + vformat.fmt.pix_mp.pixelformat, vformat.fmt.pix_mp.pixelformat >> 8, + vformat.fmt.pix_mp.pixelformat >> 16, vformat.fmt.pix_mp.pixelformat >> 24); + camsrc_info("| Request output pixel format = %d", vformat.fmt.pix_mp.pixelformat); + camsrc_info("| Request output num planes = %d", vformat.fmt.pix_mp.num_planes); + camsrc_info("==========================================="); + + GST_INFO(" VIDIOC_S_FMT"); + if (CAMERASRC_SUCCESS != _camerasrc_ioctl(p, fd, VIDIOC_S_FMT, &vformat)) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[%d] VIDIOC_S_FMT failed : %s", i, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + camsrc_info("DONE"); + + return CAMERASRC_SUCCESS; +} + + +int _camerasrc_ioctl_reqbufs(camerasrc_handle_t *p, int fd, guint count, int type, int memory, guint *ret_count) +{ + int ret = CAMERASRC_SUCCESS; + struct v4l2_requestbuffers vreq_bufs; + + if (p == NULL) { + camsrc_error("NULL handle"); + return CAMERASRC_ERR_NULL_POINTER; + } + + CLEAR(vreq_bufs); + + vreq_bufs.count = count; + vreq_bufs.type = type; + vreq_bufs.memory = memory; + + camsrc_info("VIDIOC_REQBUFS : count %d, type %d, memory %d", count, type, memory); + + ret = _camerasrc_ioctl(p, fd, VIDIOC_REQBUFS, &vreq_bufs); + + if (ret_count) { + *ret_count = vreq_bufs.count; + } + + camsrc_info("VIDIOC_REQBUFS result : count %d", vreq_bufs.count); + + return ret; +} + + +int _camerasrc_ioctl_qbuf(camerasrc_handle_t *p, int fd, int type, int memory, int idx, camerasrc_buffer_t *buffer) +{ + int ret = CAMERASRC_SUCCESS; + int i = 0; + struct v4l2_plane planes[MAX_PLANE_NUM]; + struct v4l2_buffer lvbuf; + char err_msg[CAMERASRC_ERRMSG_MAX_LEN] = {'\0',}; + + if (p == NULL || buffer == NULL || fd < 0) { + camsrc_error("INVALID parameter %p %p %d", p, buffer, fd); + return CAMERASRC_ERR_INVALID_PARAMETER; + } + + camsrc_debug("ENTER - fd %d, type %d, memory %d, idx %d, buffer %p, planes %d", + fd, type, memory, idx, buffer, buffer->num_planes); + + CLEAR(lvbuf); + CLEAR(planes); + + lvbuf.type = type; + lvbuf.memory = memory; + lvbuf.index = idx; + lvbuf.m.planes = planes; + lvbuf.length = buffer->num_planes; + + for (i = 0 ; i < MAX_PLANE_NUM ; i++) { + if (buffer->planes[i].bo) { + lvbuf.m.planes[i].m.fd = buffer->planes[i].fd; + lvbuf.m.planes[i].length = buffer->planes[i].length; + + camsrc_debug("[index %d] [plane %d] fd %d, length %d", + idx, i, lvbuf.m.planes[i].m.fd, lvbuf.m.planes[i].length); + } else { + break; + } + } + + ret = _camerasrc_ioctl(p, fd, VIDIOC_QBUF, &lvbuf); + if (ret != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("VIDIOC_QBUF failed : %s, fd %d, type %d, memory %d, idx %d, buffer %p", + err_msg, fd, type, memory, idx, buffer); + return CAMERASRC_ERR_IO_CONTROL; + } + + camsrc_debug("DONE"); + + return CAMERASRC_SUCCESS; +} + + +int _camerasrc_ioctl_dqbuf(camerasrc_handle_t *p, int fd, int type, int memory, int *idx, int num_planes) +{ + int ret = CAMERASRC_SUCCESS; + struct v4l2_plane planes[MAX_PLANE_NUM]; + struct v4l2_buffer lvbuf; + char err_msg[CAMERASRC_ERRMSG_MAX_LEN] = {'\0',}; + + if (p == NULL || idx == NULL || fd < 0) { + camsrc_error("INVALID parameter %p %p %d", p, idx, fd); + return CAMERASRC_ERR_INVALID_PARAMETER; + } + + camsrc_debug("ENTER - fd %d, type %d, memory %d, num planes %d", fd, type, memory, num_planes); + + CLEAR(lvbuf); + + lvbuf.type = type; + lvbuf.memory = memory; + lvbuf.m.planes = planes; + lvbuf.length = num_planes; + + ret = _camerasrc_ioctl(p, fd, VIDIOC_DQBUF, &lvbuf); + if (ret != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("VIDIOC_DQBUF failed : %s, fd %d, type %d, memory %d", + err_msg, fd, type, memory); + return CAMERASRC_ERR_IO_CONTROL; + } + + *idx = lvbuf.index; + + camsrc_debug("DONE - index %d", *idx); + + return CAMERASRC_SUCCESS; +} + + +int _camerasrc_ioctl_stream(camerasrc_handle_t *p, int fd, int type, int on) +{ + int ret = CAMERASRC_SUCCESS; + enum v4l2_buf_type vtype; + char err_msg[CAMERASRC_ERRMSG_MAX_LEN] = {'\0',}; + + if (p == NULL || fd < 0) { + camsrc_error("INVALID parameter %p %d", p, fd); + return CAMERASRC_ERR_INVALID_PARAMETER; + } + + camsrc_info("STREAM %d, type %d", on, type); + + vtype = type; + + ret = _camerasrc_ioctl(p, fd, on ? VIDIOC_STREAMON : VIDIOC_STREAMOFF, &vtype); + if (ret != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + if (on) { + camsrc_error("VIDIOC_STREAMON failed[%x] : %s", p->errnum, err_msg); + } else { + camsrc_error("VIDIOC_STREAMOFF failed[%x] : %s", p->errnum, err_msg); + } + return CAMERASRC_ERR_IO_CONTROL; + } + + camsrc_info("DONE"); + + return CAMERASRC_SUCCESS; +} + + +/**** A U T O F O C U S I N G F U N C T I O N S ****/ +int _camerasrc_set_autofocusing_area(camerasrc_handle_t *handle, camerasrc_rect_t *rect) +{ + return CAMERASRC_SET_CMD(_CAMERASRC_CMD_AF_AREA, rect); +} + +int _camerasrc_get_autofocusing_area(camerasrc_handle_t *handle, camerasrc_rect_t *rect) +{ + return CAMERASRC_GET_CMD(_CAMERASRC_CMD_AF_AREA, rect); +} + +int _camerasrc_start_autofocusing(camerasrc_handle_t *handle) +{ + return CAMERASRC_SET_CMD(_CAMERASRC_CMD_AF_CONTROL, _CAMERASRC_AF_START); +} + +int _camerasrc_stop_autofocusing(camerasrc_handle_t *handle) +{ + return CAMERASRC_SET_CMD(_CAMERASRC_CMD_AF_CONTROL, _CAMERASRC_AF_STOP); +} + +int _camerasrc_release_autofocusing(camerasrc_handle_t *handle) +{ + return CAMERASRC_SET_CMD(_CAMERASRC_CMD_AF_CONTROL, _CAMERASRC_AF_RELEASE); +} + +int _camerasrc_destroy_autofocusing(camerasrc_handle_t *handle) +{ + return CAMERASRC_SET_CMD(_CAMERASRC_CMD_AF_CONTROL, _CAMERASRC_AF_DESTROY); +} + +int _camerasrc_init_autofocusing_mode(camerasrc_handle_t *handle) +{ + return CAMERASRC_SET_CMD(_CAMERASRC_CMD_AF_CONTROL, _CAMERASRC_AF_INIT); +} + +int _camerasrc_get_autofocusing_result(camerasrc_handle_t *handle) +{ + return CAMERASRC_GET_CMD(_CAMERASRC_CMD_AF_CONTROL, _CAMERASRC_AF_RESULT); +} + + +int _camerasrc_get_frame_data(camerasrc_handle_t *handle, camerasrc_frame_data_t *data) +{ + return CAMERASRC_GET_CMD(_CAMERASRC_CMD_FRAME_DATA, data); +} + +int _camerasrc_get_exif_info(camerasrc_handle_t *handle, camerasrc_buffer_t *exif_string) +{ + return CAMERASRC_GET_CMD(_CAMERASRC_CMD_EXIF_INFO, exif_string); +} + + +static int __camerasrc_open_device(camerasrc_handle_t *p, camerasrc_dev_id_t camera_id) +{ + int ret = CAMERASRC_ERR_DEVICE_NOT_FOUND; + int ret_ioctl = 0; + int input = 0x0; + char err_msg[CAMERASRC_ERRMSG_MAX_LEN] = {'\0',}; + + camsrc_warning("start - camera id %d", camera_id); + + if (p == NULL) { + camsrc_error("NULL handle"); + return CAMERASRC_ERR_INVALID_PARAMETER; + } + + p->cur_dev_id = camera_id; + + if (camera_id == CAMERASRC_DEV_ID_PRIMARY) { + /* TODO : secondary camera is only enabled now */ + } else { + /* open device nodes and VIDIOC_S_INPUT */ + /* SENSOR */ + p->fd_companion = open(VIDEO_DEVICE_NODE_COMPANION, O_RDWR, 0); + if (p->fd_companion < 0) { + camsrc_error("open failed [%s] : COMPANION", VIDEO_DEVICE_NODE_COMPANION); + goto OPEN_FAILED; + } + + p->fd_sensor = open(VIDEO_DEVICE_NODE_SECONDARY, O_RDWR, 0); + if (p->fd_sensor < 0) { + camsrc_error("open failed [%s] : SENSOR", VIDEO_DEVICE_NODE_SECONDARY); + goto OPEN_FAILED; + } + + input = 0x10; + camsrc_info("[SENSOR] VIDIOC_S_INPUT %d", input); + ret_ioctl = ioctl(p->fd_sensor, VIDIOC_S_INPUT, &input); + if (ret_ioctl < 0) { + camsrc_error("[SENSOR] VIDIOC_S_INPUT failed. SENSOR - input 0x%x", input); + goto OPEN_FAILED; + } + + /* ISP */ + p->fd_isp = open(VIDEO_DEVICE_NODE_ISP, O_RDWR, 0); + if (p->fd_isp < 0) { + camsrc_error("open failed [%s] : ISP", VIDEO_DEVICE_NODE_ISP); + goto OPEN_FAILED; + } + + /* 3AA1 */ + p->fd_3aa1 = open(VIDEO_DEVICE_NODE_3AA1, O_RDWR, 0); + if (p->fd_3aa1 < 0) { + camsrc_error("open failed [%s] : 3AA1", VIDEO_DEVICE_NODE_3AA1); + goto OPEN_FAILED; + } + + input = 0x11010; + camsrc_info("[3AA1 - 1] VIDIOC_S_INPUT %d", input); + ret_ioctl = ioctl(p->fd_3aa1, VIDIOC_S_INPUT, &input); + if (ret_ioctl < 0) { + camsrc_error("[3AA1] VIDIOC_S_INPUT failed. 3AA1 - input 0x%x", input); + goto OPEN_FAILED; + } + + camsrc_info("[3AA1 - 2] VIDIOC_S_INPUT %d", input); + ret_ioctl = ioctl(p->fd_3aa1, VIDIOC_S_INPUT, &input); + if (ret_ioctl < 0) { + camsrc_error("[3AA1] VIDIOC_S_INPUT failed. 3AA1 - input 0x%x", input); + goto OPEN_FAILED; + } + + /* 3AA1C */ + p->fd_3aa1c = open(VIDEO_DEVICE_NODE_3AA1C, O_RDWR, 0); + if (p->fd_3aa1c < 0) { + camsrc_error("open failed [%s] : 3AA1C", VIDEO_DEVICE_NODE_3AA1C); + goto OPEN_FAILED; + } + + input = 0x10010; + camsrc_info("[3AA1C] VIDIOC_S_INPUT %d", input); + ret_ioctl = ioctl(p->fd_3aa1c, VIDIOC_S_INPUT, &input); + if (ret_ioctl < 0) { + camsrc_error("[3AA1C] VIDIOC_S_INPUT failed. 3AA1C - input 0x%x", input); + goto OPEN_FAILED; + } + + /* SCC */ + p->fd_scc = open(VIDEO_DEVICE_NODE_SCC, O_RDWR, 0); + if (p->fd_scc < 0) { + camsrc_error("open failed [%s] : SCC", VIDEO_DEVICE_NODE_SCC); + goto OPEN_FAILED; + } + + input = 0x2210; + camsrc_info("[SCC] VIDIOC_S_INPUT %d", input); + ret_ioctl = ioctl(p->fd_scc, VIDIOC_S_INPUT, &input); + if (ret_ioctl < 0) { + camsrc_error("[SCC] VIDIOC_S_INPUT failed. SCC - input 0x%x", input); + goto OPEN_FAILED; + } + + /* SCP */ + p->fd_scp = open(VIDEO_DEVICE_NODE_SCP, O_RDWR, 0); + if (p->fd_scp < 0) { + camsrc_error("open failed [%s] : SCP", VIDEO_DEVICE_NODE_SCP); + goto OPEN_FAILED; + } + + input = 0x2510; + camsrc_info("[SCP] VIDIOC_S_INPUT %d", input); + ret_ioctl = ioctl(p->fd_scp, VIDIOC_S_INPUT, &input); + if (ret_ioctl < 0) { + camsrc_error("[SCP] VIDIOC_S_INPUT failed. SCP - input 0x%x", input); + goto OPEN_FAILED; + } + } + + camsrc_warning("done"); + + return CAMERASRC_SUCCESS; + +OPEN_FAILED: + /* open failed */ + strerror_r(errno, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + + switch (errno) { + case EBUSY: + ret = CAMERASRC_ERR_DEVICE_BUSY; + break; + case ENOENT: + case ENODEV: + ret = CAMERASRC_ERR_DEVICE_NOT_FOUND; + break; + default: + ret = CAMERASRC_ERR_DEVICE_OPEN; + break; + } + + camsrc_error("Device open fail [%d][%s][ret:0x%x]", errno, err_msg, ret); + + __camerasrc_close_device(p); + + return ret; +} + + +static void __camerasrc_close_device(camerasrc_handle_t *p) +{ + if (!p) { + camsrc_error("handle is NULL"); + return; + } + + camsrc_info("start"); + + /* Disable link media */ + if (p->cur_dev_id == CAMERASRC_DEV_ID_PRIMARY) { + /* TODO : secondary camera is only enabled now */ + } else { + if (p->fd_companion > -1) { + camsrc_info("close fd_companion : %d", p->fd_companion); + close(p->fd_companion); + p->fd_companion = -1; + } + + if (p->fd_sensor > -1) { + camsrc_info("close fd_sensor : %d", p->fd_sensor); + close(p->fd_sensor); + p->fd_sensor = -1; + } + if (p->fd_isp > -1) { + camsrc_info("close fd_isp : %d", p->fd_isp); + close(p->fd_isp); + p->fd_isp = -1; + } + if (p->fd_3aa1 > -1) { + camsrc_info("close fd_3aa1 : %d", p->fd_3aa1); + close(p->fd_3aa1); + p->fd_3aa1 = -1; + } + if (p->fd_3aa1c > -1) { + camsrc_info("close fd_3aa1c : %d", p->fd_3aa1c); + close(p->fd_3aa1c); + p->fd_3aa1c = -1; + } + if (p->fd_scc > -1) { + camsrc_info("close fd_scc : %d", p->fd_scc); + close(p->fd_scc); + p->fd_scc = -1; + } + if (p->fd_scp > -1) { + camsrc_info("close fd_scp : %d", p->fd_scp); + close(p->fd_scp); + p->fd_scp = -1; + } + } + + camsrc_info("done"); + + return; +} + + +static int _camerasrc_initialize_handle(camerasrc_handle_t *handle) +{ +/* + int i = 0; +*/ + camsrc_info("enter"); + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + /* Initialize handle variables */ + handle->buffer_sensor = NULL; + handle->buffer_isp = NULL; + handle->buffer_scc = NULL; + handle->buffer_scp = NULL; + handle->fd_sensor = -1; + handle->fd_isp = -1; + handle->fd_3aa1 = -1; + handle->fd_3aa1c = -1; + handle->fd_scc = -1; + handle->fd_scp = -1; + handle->cur_dev_id = CAMERASRC_DEV_ID_UNKNOWN; + handle->buffer_idx = 0; + handle->af_status = CAMERASRC_AUTO_FOCUS_STATUS_RELEASED; + handle->af_cmd = CAMERASRC_AUTO_FOCUS_CMD_NULL; + handle->cur_af_mode = CAMERASRC_AF_MODE_AUTO; + handle->cur_af_range = CAMERASRC_AF_RANGE_NORMAL; + handle->af_usr_data = NULL; + handle->af_cb = NULL; + handle->first_frame = 1; + handle->request_count = 0; + + CLEAR(handle->queued_buf_list); + CLEAR(handle->format_sensor); + CLEAR(handle->format_3aa1); + CLEAR(handle->format_isp); + CLEAR(handle->format_scc); + CLEAR(handle->format_scp); + + return CAMERASRC_SUCCESS; +} + + +static int _camerasrc_wait_frame_available(camerasrc_handle_t *handle, int timeout) +{ + camerasrc_handle_t *p = handle; + struct pollfd poll_fd; + int r = 0; + + if (p == NULL) { + camsrc_error("NULL handle"); + return CAMERASRC_ERR_NULL_POINTER; + } + + memset(&poll_fd, 0x0, sizeof(struct pollfd)); + + poll_fd.fd = p->fd_scp; + + /* select waiting */ + r = poll(&poll_fd, 1, timeout); + if (-1 == r) { + if (EINTR == errno) { + return CAMERASRC_SUCCESS; + } + camsrc_error("poll() failed."); + + return CAMERASRC_ERR_INTERNAL; + } + + if (r == 0) { + camsrc_error("poll() timeout"); + return CAMERASRC_ERR_DEVICE_WAIT_TIMEOUT; + } + + return CAMERASRC_SUCCESS; +} + + +static int _camerasrc_queue_buffer(camerasrc_handle_t *handle, int buf_index) +{ + camerasrc_handle_t *p = handle; + int ret; + + if (p == NULL) { + camsrc_error("NULL handle"); + return CAMERASRC_ERR_NULL_POINTER; + } + + ret = _camerasrc_ioctl_qbuf(p, + p->fd_scp, + V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, + V4L2_MEMORY_DMABUF, + buf_index, + &p->buffer_scp[buf_index]); + if (ret != CAMERASRC_SUCCESS) { + camsrc_error("_camerasrc_ioctl_qbuf failed"); + return CAMERASRC_ERR_IO_CONTROL; + } + + return CAMERASRC_SUCCESS; +} + + +static int _camerasrc_dequeue_buffer(camerasrc_handle_t *handle, int *buf_index, camerasrc_buffer_t *buffer, camerasrc_buffer_t *thm_buffer) +{ + camerasrc_handle_t *p = handle; + int ret = CAMERASRC_ERR_UNKNOWN; + int buf_index_sensor = 0; + int buf_index_3aa1cap = 0; + int buf_index_3aa1out = 0; + int buf_index_isp = 0; + int buf_index_scc = 0; + int buf_index_scp = 0; + unsigned long long timestamp; + struct camera2_shot_ext *shot_sensor = NULL; + struct camera2_shot_ext *shot_isp = NULL; + struct camera2_shot_ext *shot_scc = NULL; + + if (p->buffer_scp == NULL) { + camsrc_error("buffer is not allocated"); + return CAMERASRC_ERR_ALLOCATION; + } + + /* SENSOR - DQBUF */ + ret = _camerasrc_ioctl_dqbuf(p, + p->fd_sensor, + V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, + V4L2_MEMORY_DMABUF, + &buf_index_sensor, + p->buffer_sensor[0].num_planes); + if (ret != CAMERASRC_SUCCESS) { + camsrc_error("[SENSOR] _camerasrc_ioctl_dqbuf failed"); + return CAMERASRC_ERR_IO_CONTROL; + } + + camsrc_debug("[SENSOR] DQBUF index %d", buf_index_sensor); + + shot_sensor = (struct camera2_shot_ext *)p->buffer_sensor[buf_index_sensor].planes[1].start; + timestamp = shot_sensor->shot.dm.sensor.timeStamp; + handle->request_count++; + + /* SENSOR set shot meta */ + _camerasrc_set_shot_meta(p, GRP_3AA, handle->request_count, timestamp, shot_sensor); + + /* 3AA1 CAPTURE - QBUF */ + ret = _camerasrc_ioctl_qbuf(p, + p->fd_3aa1, + V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, + V4L2_MEMORY_DMABUF, + buf_index_sensor, + &p->buffer_isp[buf_index_sensor]); + if (ret != CAMERASRC_SUCCESS) { + camsrc_error("[3AA1 - CAPTURE] _camerasrc_ioctl_qbuf index %d, failed[%x]", buf_index_sensor, ret); + return CAMERASRC_ERR_IO_CONTROL; + } + + /* 3AA1 OUTPUT - QBUF */ + ret = _camerasrc_ioctl_qbuf(p, + p->fd_3aa1, + V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, + V4L2_MEMORY_DMABUF, + buf_index_sensor, + &p->buffer_sensor[buf_index_sensor]); + if (ret != CAMERASRC_SUCCESS) { + camsrc_error("[3AA1 - OUTPUT] _camerasrc_ioctl_qbuf index %d, failed[%x]", buf_index_sensor, ret); + return CAMERASRC_ERR_IO_CONTROL; + } + + /* 3AA1 CAPTURE - DQBUF */ + ret = _camerasrc_ioctl_dqbuf(p, + p->fd_3aa1, + V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, + V4L2_MEMORY_DMABUF, + &buf_index_3aa1cap, + p->buffer_sensor[0].num_planes); + if (ret != CAMERASRC_SUCCESS) { + camsrc_error("[3AA1 CAPTURE] _camerasrc_ioctl_dqbuf failed"); + return CAMERASRC_ERR_IO_CONTROL; + } + + camsrc_debug("[3AA1 - CAPTURE] DQBUF index %d", buf_index_3aa1cap); + + /* 3AA1 OUTPUT - DQBUF */ + ret = _camerasrc_ioctl_dqbuf(p, + p->fd_3aa1, + V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, + V4L2_MEMORY_DMABUF, + &buf_index_3aa1out, + p->buffer_sensor[0].num_planes); + if (ret != CAMERASRC_SUCCESS) { + camsrc_error("[3AA1 OUTPUT] _camerasrc_ioctl_dqbuf failed"); + return CAMERASRC_ERR_IO_CONTROL; + } + + camsrc_debug("[3AA1 - OUTPUT] DQBUF index %d", buf_index_3aa1out); + + /* SENSOR set shot meta */ + _camerasrc_set_shot_meta(p, GRP_SENSOR, 0, 0, shot_sensor); + + /* SENSOR - QBUF */ + ret = _camerasrc_ioctl_qbuf(p, + p->fd_sensor, + V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, + V4L2_MEMORY_DMABUF, + buf_index_sensor, + &p->buffer_sensor[buf_index_sensor]); + if (ret != CAMERASRC_SUCCESS) { + camsrc_error("[SENSOR] _camerasrc_ioctl_qbuf index %d, failed[%x]", buf_index_sensor, ret); + return CAMERASRC_ERR_IO_CONTROL; + } + + shot_isp = (struct camera2_shot_ext *)p->buffer_isp[buf_index_sensor].planes[1].start; + _camerasrc_set_shot_meta(p, GRP_ISP, handle->request_count, timestamp, shot_isp); + + /* ISP - QBUF */ + ret = _camerasrc_ioctl_qbuf(p, + p->fd_isp, + V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, + V4L2_MEMORY_DMABUF, + buf_index_sensor, + &p->buffer_isp[buf_index_sensor]); + if (ret != CAMERASRC_SUCCESS) { + camsrc_error("[ISP] _camerasrc_ioctl_qbuf index %d, failed[%x]", buf_index_sensor, ret); + return CAMERASRC_ERR_IO_CONTROL; + } + + /* ISP - DQBUF */ + ret = _camerasrc_ioctl_dqbuf(p, + p->fd_isp, + V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, + V4L2_MEMORY_DMABUF, + &buf_index_isp, + p->buffer_isp[0].num_planes); + if (ret != CAMERASRC_SUCCESS) { + camsrc_error("[3AA1 OUTPUT] _camerasrc_ioctl_dqbuf failed"); + return CAMERASRC_ERR_IO_CONTROL; + } + + camsrc_debug("[ISP] DQBUF index %d", buf_index_isp); + + //_camerasrc_wait_frame_available(p, 2000); + + /* SCC - DQBUF */ + ret = _camerasrc_ioctl_dqbuf(p, + p->fd_scc, + V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, + V4L2_MEMORY_DMABUF, + &buf_index_scc, + p->buffer_scc[0].num_planes); + if (ret != CAMERASRC_SUCCESS) { + camsrc_error("[SCC] _camerasrc_ioctl_dqbuf failed"); + return CAMERASRC_ERR_IO_CONTROL; + } + + shot_scc = (struct camera2_shot_ext *)p->buffer_scc[buf_index_scc].planes[1].start; + shot_scc->shot.dm.request.frameCount = handle->request_count; + + /* SCC - QBUF */ + ret = _camerasrc_ioctl_qbuf(p, + p->fd_scc, + V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, + V4L2_MEMORY_DMABUF, + buf_index_scc, + &p->buffer_scc[buf_index_scc]); + if (ret != CAMERASRC_SUCCESS) { + camsrc_error("[SCC] _camerasrc_ioctl_qbuf index %d, failed[%x]", buf_index_scc, ret); + return CAMERASRC_ERR_IO_CONTROL; + } + + /* SCP */ + ret = _camerasrc_ioctl_dqbuf(p, + p->fd_scp, + V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, + V4L2_MEMORY_DMABUF, + &buf_index_scp, + p->buffer_scp[0].num_planes); + if (ret != CAMERASRC_SUCCESS) { + camsrc_error("[SCC] _camerasrc_ioctl_dqbuf failed"); + return CAMERASRC_ERR_IO_CONTROL; + } + + camsrc_debug("SCP DQBUF index : %d", buf_index_scp); + + memcpy(buffer, &p->buffer_scp[buf_index_scp], sizeof(camerasrc_buffer_t)); + + *buf_index = buf_index_scp; + + return CAMERASRC_SUCCESS; +} + +static int _camerasrc_dump_format(camsrc_handle_t handle); + +/**** M A I N O P E R A T I O N ****/ +int camerasrc_create(camsrc_handle_t *phandle) +{ + camerasrc_handle_t *p = NULL; + int err = CAMERASRC_ERR_UNKNOWN; + char err_msg[CAMERASRC_ERRMSG_MAX_LEN] = {'\0',}; + + camsrc_info("enter"); + + if (phandle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = (camerasrc_handle_t *)malloc(sizeof(camerasrc_handle_t)); + if(p == NULL) { + camsrc_error("malloc fail"); + return CAMERASRC_ERR_ALLOCATION; + } + + memset(p, '\0', sizeof(camerasrc_handle_t)); + + /* STATE TO MEANINGFUL STATE */ + p->cur_state = CAMERASRC_STATE_NONE; + CAMERASRC_SET_STATE(p, CAMERASRC_STATE_CREATED); + CAMERASRC_SET_PHASE(p, CAMERASRC_PHASE_NON_RUNNING); + camsrc_info("Transit to non-running phase"); + + /* INIT VARIABLES */ + err = _camerasrc_initialize_handle(p); + if(err != CAMERASRC_SUCCESS) { + camsrc_error("Invalid handle"); + return CAMERASRC_ERR_INVALID_HANDLE; + } + + err = pthread_mutex_init(&(p->mutex), NULL); + if(err) { + strerror_r(err, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_info("Mutex creating status : %s", err_msg); + } + + err = pthread_mutex_init(&(p->af_mutex), NULL); + if(err) { + strerror_r(err, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_info("AF Mutex creating status : %s", err_msg); + } + + err = pthread_cond_init(&(p->af_wait_cond), NULL); + if(err) { + strerror_r(err, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_info("AF Condition creating status : %s", err_msg); + } + + camsrc_info("Thread creation start.."); + err = pthread_create(&p->focusing_thread, NULL, (void*)_camerasrc_run_autofocusing, p); + if(err) { + strerror_r(err, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_info("AF Thread creating status : %s", err_msg); + } + + camsrc_info("Thread creation end.."); + + /* set default focus mode */ + p->cur_af_mode = CAMERASRC_AF_MODE_CONTINUOUS; + p->cur_af_range = CAMERASRC_AF_RANGE_NORMAL; + + *phandle = (camsrc_handle_t)p; + err = CAMERASRC_SUCCESS; + return err; +} + + +int camerasrc_destroy(camsrc_handle_t handle) +{ + camerasrc_handle_t* p = NULL; + int err = CAMERASRC_ERR_UNKNOWN; + char err_msg[CAMERASRC_ERRMSG_MAX_LEN] = {'\0',}; + + camsrc_info("enter"); + + if(handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + if(CAMERASRC_STATE(p) != CAMERASRC_STATE_UNREALIZED) { + camsrc_warning("Invalid state transition"); + } + + /* Remove AF thread */ + _camerasrc_destroy_autofocusing(p); + + camsrc_info("Thread join wait start.."); + err = pthread_join(p->focusing_thread, NULL); + if(err) { + strerror_r(err, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_info("AF Thread join status : %s", err_msg); + } + + camsrc_info("Thread join wait end.."); + + err = pthread_cond_destroy(&p->af_wait_cond); + if(err) { + strerror_r(err, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_info("AF Condition destroying error : %s", err_msg); + } + + err = pthread_mutex_destroy(&(p->af_mutex)); + if(err) { + strerror_r(err, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_info("AF Mutex destroying error : %s", err_msg); + } + + err = pthread_mutex_destroy(&(p->mutex)); + if(err) { + strerror_r(err, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_info("Mutex destroying error : %s", err_msg); + } + + free((void*)p); + handle = NULL; + err = CAMERASRC_SUCCESS; + return err; +} + + +int camerasrc_get_state(camsrc_handle_t handle, camerasrc_state_t* state) +{ + camerasrc_handle_t* p = NULL; + + if(handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + *state = CAMERASRC_STATE(p); + return CAMERASRC_SUCCESS; +} + + +int camerasrc_realize(camsrc_handle_t handle, camerasrc_dev_id_t camera_id, camerasrc_sensor_mode_t mode) +{ + camerasrc_handle_t* p = NULL; + int ret = CAMERASRC_SUCCESS; + + camsrc_info("enter"); + + if(handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + /* STATE OR PHASE CHECKING */ + if(CAMERASRC_STATE(p) == CAMERASRC_STATE_REALIZED) { + return CAMERASRC_SUCCESS; + } + if(CAMERASRC_STATE(p) != CAMERASRC_STATE_CREATED && + CAMERASRC_STATE(p) != CAMERASRC_STATE_UNREALIZED) { + camsrc_warning("Invalid state transition"); + } + + /* Open device */ + ret = __camerasrc_open_device(p, camera_id); + + if (ret == CAMERASRC_SUCCESS) { + CAMERASRC_SET_STATE(p, CAMERASRC_STATE_REALIZED); + } + + return ret; +} + + +int camerasrc_unrealize(camsrc_handle_t handle) +{ + camerasrc_handle_t* p = NULL; + int err = CAMERASRC_ERR_UNKNOWN; + + camsrc_info("enter"); + + if(handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + if(CAMERASRC_STATE(p) == CAMERASRC_STATE_UNREALIZED || + CAMERASRC_STATE(p) == CAMERASRC_STATE_DESTROYED) { + return CAMERASRC_SUCCESS; + } + if(CAMERASRC_STATE(p) != CAMERASRC_STATE_READY) { + camsrc_warning("Invalid state transition"); + } + + __camerasrc_close_device(p); + + CAMERASRC_SET_STATE(p, CAMERASRC_STATE_UNREALIZED); + CAMERASRC_SET_PHASE(p, CAMERASRC_PHASE_NON_RUNNING); + camsrc_info("Transit to non-running phase"); + err = CAMERASRC_SUCCESS; + return err; +} + + +int camerasrc_start(camsrc_handle_t handle) +{ + camerasrc_handle_t* p = NULL; + int err = CAMERASRC_ERR_UNKNOWN; + + camsrc_info("enter"); + + if(handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + /* STATE OR PHASE CHECKING */ + if(CAMERASRC_STATE(p) == CAMERASRC_STATE_READY) { + return CAMERASRC_SUCCESS; + } + if(CAMERASRC_STATE(p) != CAMERASRC_STATE_REALIZED) { + camsrc_warning("Invalid state transition"); + } + + CAMERASRC_SET_STATE(p, CAMERASRC_STATE_READY); + CAMERASRC_SET_PHASE(p, CAMERASRC_PHASE_RUNNING); + + camsrc_info("Transit to running phase"); + err = CAMERASRC_SUCCESS; + return err; +} + + +int camerasrc_get_num_buffer(camsrc_handle_t handle, unsigned int *num_buffer) +{ + camerasrc_handle_t *p = NULL; + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + camerasrc_state_t state = CAMERASRC_STATE_NONE; + camerasrc_get_state(handle, &state); + + switch(state) { + case CAMERASRC_STATE_NONE: + case CAMERASRC_STATE_CREATED: + case CAMERASRC_STATE_REALIZED: + case CAMERASRC_STATE_READY: + case CAMERASRC_STATE_UNREALIZED: + case CAMERASRC_STATE_DESTROYED: + camsrc_warning("Current buffer number not initialized."); + *num_buffer = 0; + break; + case CAMERASRC_STATE_PREVIEW: + case CAMERASRC_STATE_STILL: + case CAMERASRC_STATE_VIDEO: + case CAMERASRC_STATE_AF_IN_PROGRESS: + *num_buffer = p->format_scp.num_buffers; + break; + default: + camsrc_error("Unknown state"); + *num_buffer = -1; + return CAMERASRC_ERR_INVALID_STATE; + } + + return CAMERASRC_SUCCESS; +} + + +int camerasrc_create_buffer(camsrc_handle_t handle) +{ + camerasrc_handle_t *p = NULL; + int ret = CAMERASRC_SUCCESS; + int count = 0; + int plane_index = 0; + int plane_num = 0; + int buffer_size[MAX_PLANE_NUM] = {0,}; + int preview_width = 0; + int preview_height = 0; + int sensor_width = 0; + int sensor_height = 0; + int aligned_width = 0; + int bytes_per_line = 0; + + camsrc_info("enter"); + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + if (p->buffer_sensor || p->buffer_isp || p->buffer_scc || p->buffer_scp) { + camerasrc_destroy_buffer(handle); + } + + preview_width = p->format_scp.img_size.width; + preview_height = p->format_scp.img_size.height; + + memset(&p->format_sensor, 0x0, sizeof(camerasrc_format_t)); + memset(&p->format_isp, 0x0, sizeof(camerasrc_format_t)); + memset(&p->format_scc, 0x0, sizeof(camerasrc_format_t)); + + p->format_sensor.num_buffers = p->format_scp.num_buffers - 6; + p->format_3aa1.num_buffers = p->format_scp.num_buffers - 6; + p->format_isp.num_buffers = p->format_scp.num_buffers - 6; + p->format_scc.num_buffers = p->format_scp.num_buffers - 6; + + /* set sensor resolution */ + sensor_width = FRONT_SENSOR_SIZE_WIDTH + SENSOR_MARGIN_WIDTH; + sensor_height = FRONT_SENSOR_SIZE_HEIGHT + SENSOR_MARGIN_HEIGHT; + + /** + * buffer allocation + */ + /* sensor */ + p->buffer_sensor = (camerasrc_buffer_t *)malloc(sizeof(camerasrc_buffer_t) * p->format_sensor.num_buffers); + if (p->buffer_sensor == NULL) { + camsrc_error("failed to buffer_sensor"); + return CAMERASRC_ERR_ALLOCATION; + } + + memset(p->buffer_sensor, 0x0, sizeof(camerasrc_buffer_t) * p->format_sensor.num_buffers); + + aligned_width = ((sensor_width + 9) / 10) * 10; + bytes_per_line = (aligned_width * 8) / 5; + + buffer_size[0] = bytes_per_line * sensor_height; + buffer_size[1] = SPARE_SIZE; + buffer_size[2] = 0; + buffer_size[3] = 0; + + for (count = 0 ; count < p->format_sensor.num_buffers ; count++) { + p->buffer_sensor[count].num_planes = BAYER_PLANE_COUNT; + for (plane_index = 0 ; plane_index < MAX_PLANE_NUM ; plane_index++) { + if (buffer_size[plane_index] > 0) { + ret = camerasrc_tbm_alloc_buffer(handle, buffer_size[plane_index], + &(p->buffer_sensor[count].planes[plane_index].bo), + &(p->buffer_sensor[count].planes[plane_index].fd), + &(p->buffer_sensor[count].planes[plane_index].start)); + if (ret == FALSE) { + camsrc_error("[sensor] camerasrc_tbm_alloc_buffer failed[%d:%d] : size %d", + count, plane_index, buffer_size[plane_index]); + goto CREATE_BUFFER_FAILED; + } + + p->buffer_sensor[count].planes[plane_index].length = buffer_size[plane_index]; + + camsrc_info("sensor [%d][%d] BUF: bo[%p] fd[%d] addr[%p] size[%d]", + count, plane_index, + p->buffer_sensor[count].planes[plane_index].bo, + p->buffer_sensor[count].planes[plane_index].fd, + p->buffer_sensor[count].planes[plane_index].start, + p->buffer_sensor[count].planes[plane_index].length); + } + } + } + + /* ISP */ + p->buffer_isp = (camerasrc_buffer_t *)malloc(sizeof(camerasrc_buffer_t) * p->format_isp.num_buffers); + if (p->buffer_isp == NULL) { + camsrc_error("failed to buffer_isp"); + goto CREATE_BUFFER_FAILED; + } + + memset(p->buffer_isp, 0x0, sizeof(camerasrc_buffer_t) * p->format_isp.num_buffers); + + for (count = 0 ; count < p->format_isp.num_buffers ; count++) { + p->buffer_isp[count].num_planes = ISP_PLANE_COUNT; + for (plane_index = 0 ; plane_index < MAX_PLANE_NUM ; plane_index++) { + if (buffer_size[plane_index] > 0) { + ret = camerasrc_tbm_alloc_buffer(handle, buffer_size[plane_index], + &(p->buffer_isp[count].planes[plane_index].bo), + &(p->buffer_isp[count].planes[plane_index].fd), + &(p->buffer_isp[count].planes[plane_index].start)); + if (ret == FALSE) { + camsrc_error("[isp] camerasrc_tbm_alloc_buffer failed[%d:%d] : size %d", + count, plane_index, buffer_size[plane_index]); + goto CREATE_BUFFER_FAILED; + } + + p->buffer_isp[count].planes[plane_index].length = buffer_size[plane_index]; + + camsrc_info("isp [%d][%d] BUF: bo[%p] fd[%d] addr[%p] size[%d]", + count, plane_index, + p->buffer_isp[count].planes[plane_index].bo, + p->buffer_isp[count].planes[plane_index].fd, + p->buffer_isp[count].planes[plane_index].start, + p->buffer_isp[count].planes[plane_index].length); + } + } + } + + /* SCC */ + p->buffer_scc = (camerasrc_buffer_t *)malloc(sizeof(camerasrc_buffer_t) * p->format_scc.num_buffers); + if (p->buffer_scc == NULL) { + camsrc_error("failed to buffer_scc"); + goto CREATE_BUFFER_FAILED; + } + + memset(p->buffer_scc, 0x0, sizeof(camerasrc_buffer_t) * p->format_scc.num_buffers); + + for (count = 0 ; count < p->format_scc.num_buffers ; count++) { + p->buffer_scc[count].num_planes = SCC_PLANE_COUNT; + for (plane_index = 0 ; plane_index < MAX_PLANE_NUM ; plane_index++) { + if (buffer_size[plane_index] > 0) { + ret = camerasrc_tbm_alloc_buffer(handle, buffer_size[plane_index], + &(p->buffer_scc[count].planes[plane_index].bo), + &(p->buffer_scc[count].planes[plane_index].fd), + &(p->buffer_scc[count].planes[plane_index].start)); + if (ret == FALSE) { + camsrc_error("[scc] camerasrc_tbm_alloc_buffer failed[%d:%d] : size %d", + count, plane_index, buffer_size[plane_index]); + goto CREATE_BUFFER_FAILED; + } + + p->buffer_scc[count].planes[plane_index].length = buffer_size[plane_index]; + + camsrc_info("scc [%d][%d] BUF: bo[%p] fd[%d] addr[%p] size[%d]", + count, plane_index, + p->buffer_scc[count].planes[plane_index].bo, + p->buffer_scc[count].planes[plane_index].fd, + p->buffer_scc[count].planes[plane_index].start, + p->buffer_scc[count].planes[plane_index].length); + } + } + } + + /* SCP */ + p->buffer_scp = (camerasrc_buffer_t *)malloc(sizeof(camerasrc_buffer_t) * p->format_scp.num_buffers); + if (p->buffer_scp == NULL) { + camsrc_error("failed to buffer_scp"); + goto CREATE_BUFFER_FAILED; + } + + memset(p->buffer_scp, 0x0, sizeof(camerasrc_buffer_t) * p->format_scp.num_buffers); + + switch (p->format_scp.pix_format) { + case CAMERASRC_PIX_YUY2: + buffer_size[0] = buf_4k_align((preview_width * preview_height) << 1); + buffer_size[1] = buf_4k_align(SPARE_SIZE); + buffer_size[2] = 0; + buffer_size[3] = 0; + plane_num = 2; + break; + case CAMERASRC_PIX_YUV420P: + buffer_size[0] = buf_4k_align(preview_width * preview_height); + buffer_size[1] = buf_4k_align((preview_width * preview_height) >> 2); + buffer_size[2] = buffer_size[1]; + buffer_size[3] = buf_4k_align(SPARE_SIZE); + plane_num = 4; + break; + case CAMERASRC_PIX_NV12: + buffer_size[0] = buf_4k_align((preview_width * preview_height * 3) >> 1); + buffer_size[1] = buf_4k_align(SPARE_SIZE); + buffer_size[2] = 0; + buffer_size[3] = 0; + plane_num = 2; + break; + case CAMERASRC_PIX_SN12: + buffer_size[0] = buf_4k_align(preview_width * preview_height); + buffer_size[1] = buf_4k_align((preview_width * preview_height) >> 1); + buffer_size[2] = buf_4k_align(SPARE_SIZE); + buffer_size[3] = 0; + plane_num = 3; + break; + default: + camsrc_warning("invalid output format = %d, set size as NV12M(SN12)", p->format_scp.pix_format); + buffer_size[0] = buf_4k_align(preview_width * preview_height); + buffer_size[1] = buf_4k_align((preview_width * preview_height) >> 1); + buffer_size[2] = buf_4k_align(SPARE_SIZE); + buffer_size[3] = 0; + plane_num = 3; + break; + } + + for (count = 0 ; count < p->format_scp.num_buffers ; count++) { + p->buffer_scp[count].num_planes = plane_num; + for (plane_index = 0 ; plane_index < MAX_PLANE_NUM ; plane_index++) { + if (buffer_size[plane_index] > 0) { + ret = camerasrc_tbm_alloc_buffer(handle, buffer_size[plane_index], + &(p->buffer_scp[count].planes[plane_index].bo), + &(p->buffer_scp[count].planes[plane_index].fd), + &(p->buffer_scp[count].planes[plane_index].start)); + if (ret == FALSE) { + camsrc_error("[scp] camerasrc_tbm_alloc_buffer failed[%d:%d] : size %d", + count, plane_index, buffer_size[plane_index]); + goto CREATE_BUFFER_FAILED; + } + + p->buffer_scp[count].planes[plane_index].length = buffer_size[plane_index]; + + camsrc_info("scp [%d][%d] BUF: bo[%p] fd[%d] addr[%p] size[%d]", + count, plane_index, + p->buffer_scp[count].planes[plane_index].bo, + p->buffer_scp[count].planes[plane_index].fd, + p->buffer_scp[count].planes[plane_index].start, + p->buffer_scp[count].planes[plane_index].length); + } + } + } + + return CAMERASRC_SUCCESS; + +CREATE_BUFFER_FAILED: + camerasrc_destroy_buffer(p); + + return CAMERASRC_ERR_ALLOCATION; +} + + +int camerasrc_destroy_buffer(camsrc_handle_t handle) +{ + camerasrc_handle_t *p = NULL; + int count = 0; + int plane_index = 0; + + camsrc_info("enter"); + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + /* buffer - sensor */ + if (p->buffer_sensor) { + for (count = 0 ; count < p->format_sensor.num_buffers ; count++) { + for (plane_index = 0 ; plane_index < MAX_PLANE_NUM ; plane_index++) { + if (p->buffer_sensor[count].planes[plane_index].bo) { + camsrc_info("[sensor] unref bo %p", p->buffer_sensor[count].planes[plane_index].bo); + tbm_bo_unref(p->buffer_sensor[count].planes[plane_index].bo); + p->buffer_sensor[count].planes[plane_index].bo = NULL; + p->buffer_sensor[count].planes[plane_index].fd = 0; + p->buffer_sensor[count].planes[plane_index].start = NULL; + p->buffer_sensor[count].planes[plane_index].length = 0; + } else { + camsrc_info("[sensor] skip release buffer[%d] plane[%d]", count, plane_index); + } + } + } + + free(p->buffer_sensor); + p->buffer_sensor = NULL; + } else { + camsrc_warning("buffer_sensor is already NULL"); + } + + /* buffer - isp */ + if (p->buffer_isp) { + for (count = 0 ; count < p->format_isp.num_buffers ; count++) { + for (plane_index = 0 ; plane_index < MAX_PLANE_NUM ; plane_index++) { + if (p->buffer_isp[count].planes[plane_index].bo) { + camsrc_info("[isp] unref bo %p", p->buffer_isp[count].planes[plane_index].bo); + tbm_bo_unref(p->buffer_isp[count].planes[plane_index].bo); + p->buffer_isp[count].planes[plane_index].bo = NULL; + p->buffer_isp[count].planes[plane_index].fd = 0; + p->buffer_isp[count].planes[plane_index].start = NULL; + p->buffer_isp[count].planes[plane_index].length = 0; + } else { + camsrc_info("[isp] skip release buffer[%d] plane[%d]", count, plane_index); + } + } + } + + free(p->buffer_isp); + p->buffer_isp = NULL; + } else { + camsrc_warning("buffer_isp is already NULL"); + } + + /* buffer - scc */ + if (p->buffer_scc) { + for (count = 0 ; count < p->format_scc.num_buffers ; count++) { + for (plane_index = 0 ; plane_index < MAX_PLANE_NUM ; plane_index++) { + if (p->buffer_scc[count].planes[plane_index].bo) { + camsrc_info("[scc] unref bo %p", p->buffer_scc[count].planes[plane_index].bo); + tbm_bo_unref(p->buffer_scc[count].planes[plane_index].bo); + p->buffer_scc[count].planes[plane_index].bo = NULL; + p->buffer_scc[count].planes[plane_index].fd = 0; + p->buffer_scc[count].planes[plane_index].start = NULL; + p->buffer_scc[count].planes[plane_index].length = 0; + } else { + camsrc_info("[scc] skip release buffer[%d] plane[%d]", count, plane_index); + } + } + } + + free(p->buffer_scc); + p->buffer_scc = NULL; + } else { + camsrc_warning("buffer_scc is already NULL"); + } + + /* buffer - scp */ + if (p->buffer_scp) { + for (count = 0 ; count < p->format_scp.num_buffers ; count++) { + for (plane_index = 0 ; plane_index < MAX_PLANE_NUM ; plane_index++) { + if (p->buffer_scp[count].planes[plane_index].bo) { + camsrc_info("[scp] unref bo %p", p->buffer_scp[count].planes[plane_index].bo); + tbm_bo_unref(p->buffer_scp[count].planes[plane_index].bo); + p->buffer_scp[count].planes[plane_index].bo = NULL; + p->buffer_scp[count].planes[plane_index].fd = 0; + p->buffer_scp[count].planes[plane_index].start = NULL; + p->buffer_scp[count].planes[plane_index].length = 0; + } else { + camsrc_info("[scp] skip release buffer[%d] plane[%d]", count, plane_index); + } + } + } + + free(p->buffer_scp); + p->buffer_scp = NULL; + } else { + camsrc_warning("buffer_scp is already NULL"); + } + + camsrc_info("done"); + + return CAMERASRC_SUCCESS; +} + + +int camerasrc_start_preview_stream(camsrc_handle_t handle) +{ + camerasrc_handle_t *p = NULL; + int i = 0; + int err = CAMERASRC_ERR_UNKNOWN; + char err_msg[CAMERASRC_ERRMSG_MAX_LEN] = {'\0',}; + + camsrc_info("enter"); + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + /* STATE OR PHASE CHECKING */ + if(CAMERASRC_STATE(p) == CAMERASRC_STATE_PREVIEW) { + camsrc_info("already PREVIEW state. skip this func..."); + return CAMERASRC_SUCCESS; + } + if(CAMERASRC_STATE(p) != CAMERASRC_STATE_READY) { + camsrc_warning("Invalid state transition"); + } + + /* check buffer */ + if (p->buffer_sensor == NULL || p->buffer_isp == NULL || p->buffer_scc == NULL || p->buffer_scp == NULL) { + camsrc_error("buffer is NULL %p %p %p %p", p->buffer_sensor, p->buffer_isp, p->buffer_scc, p->buffer_scp); + return CAMERASRC_ERR_INVALID_STATE; + } + + /* P R E V I E W F O R M A T S E T T I N G */ + if (!(p->format_scp.pix_format == CAMERASRC_PIX_YUV422P || + p->format_scp.pix_format == CAMERASRC_PIX_YUV420P || p->format_scp.pix_format == CAMERASRC_PIX_YV12 || + p->format_scp.pix_format == CAMERASRC_PIX_SN12 || p->format_scp.pix_format == CAMERASRC_PIX_NV12 || + p->format_scp.pix_format == CAMERASRC_PIX_SN21 || p->format_scp.pix_format == CAMERASRC_PIX_NV21 || + p->format_scp.pix_format == CAMERASRC_PIX_UYVY || p->format_scp.pix_format == CAMERASRC_PIX_YUY2)) { + camsrc_error("Invalid output format %d", p->format_scp.pix_format); + return CAMERASRC_ERR_INVALID_FORMAT; + } + + if (p->format_scp.colorspace != CAMERASRC_COL_RAW) { + camsrc_error("Invalid store method."); + return CAMERASRC_ERR_INVALID_PARAMETER; + } + + err = _camerasrc_dump_format(handle); + if (err != CAMERASRC_SUCCESS) { + camsrc_error("Format dump error"); + return err; + } + + if (p->cur_dev_id == CAMERASRC_DEV_ID_PRIMARY) { + /* TODO */ + } else { + int type = 0; + int input = 0; + + /* sensor */ + err = _camerasrc_ioctl_s_ctrl(p, p->fd_sensor, V4L2_CID_IS_MIN_TARGET_FPS, 15); + if (err != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[SENSOR] V4L2_CID_IS_MIN_TARGET_FPS failed[%x] : %s", err, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + camsrc_info("[SENSOR] V4L2_CID_IS_MIN_TARGET_FPS 15 done"); + + err = _camerasrc_ioctl_s_ctrl(p, p->fd_sensor, V4L2_CID_IS_MAX_TARGET_FPS, 30); + if (err != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[SENSOR] V4L2_CID_IS_MAX_TARGET_FPS failed[%x] : %s", err, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + camsrc_info("[SENSOR] V4L2_CID_IS_MAX_TARGET_FPS 30 done"); + + type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; + p->format_sensor.img_size.width = FRONT_SENSOR_SIZE_WIDTH + SENSOR_MARGIN_WIDTH; + p->format_sensor.img_size.height = FRONT_SENSOR_SIZE_HEIGHT + SENSOR_MARGIN_HEIGHT; + p->format_sensor.pix_format = CAMERASRC_PIX_SBGGR12; + + err = _camerasrc_ioctl_s_fmt(p, p->fd_sensor, type, &p->format_sensor); + if (err != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[SENSOR - CAPTURE] _camerasrc_ioctl_s_fmt failed[%x] : %s", err, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + camsrc_info("[SENSOR] S_FMT done"); + + err = _camerasrc_ioctl_reqbufs(p, p->fd_sensor, p->format_sensor.num_buffers, + type, V4L2_MEMORY_DMABUF, &p->format_sensor.num_buffers); + if (err != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[SENSOR - CAPTURE] _camerasrc_ioctl_reqbufs failed[%x] : %s", err, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + p->reqbuf_sensor = TRUE; + + camsrc_info("[SENSOR] REQBUF done. count : %d", p->format_sensor.num_buffers); + + GST_INFO(" preview: _camerasrc_ioctl_s_parm"); + err = _camerasrc_ioctl_s_parm(p, p->fd_sensor, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, 1, 30); + if (err != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("_camerasrc_ioctl_s_parm failed[%x] : %s", err, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + camsrc_info("[SENSOR] S_PARM done"); + + /* 3AA1 - OUTPUT */ + type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; + p->format_3aa1.img_size.width = p->format_sensor.img_size.width; + p->format_3aa1.img_size.height = p->format_sensor.img_size.height; + p->format_3aa1.pix_format = CAMERASRC_PIX_SBGGR12; + + err = _camerasrc_ioctl_s_fmt(p, p->fd_3aa1, type, &p->format_3aa1); + if (err != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[3AA1 - OUTPUT] _camerasrc_ioctl_s_fmt failed[%x] : %s", err, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + camsrc_info("[3AA1 - OUTPUT] S_FMT done"); + + err = _camerasrc_ioctl_reqbufs(p, p->fd_3aa1, p->format_3aa1.num_buffers, + type, V4L2_MEMORY_DMABUF, &p->format_3aa1.num_buffers); + if (err != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[3AA1 - OUTPUT] _camerasrc_ioctl_reqbufs failed[%x] : %s", err, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + p->reqbuf_3aa1_output = TRUE; + + camsrc_info("[3AA1 - OUTPUT] REQBUF done. count : %d", p->format_3aa1.num_buffers); + + /* 3AA1 - CAPTURE */ + type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; + p->format_3aa1.img_size.width = FRONT_SENSOR_SIZE_WIDTH; + p->format_3aa1.img_size.height = FRONT_SENSOR_SIZE_HEIGHT; + + err = _camerasrc_ioctl_s_fmt(p, p->fd_3aa1, type, &p->format_3aa1); + if (err != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[3AA1 - CAPTURE] _camerasrc_ioctl_s_fmt failed[%x] : %s", err, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + camsrc_info("[3AA1 - CAPTURE] S_FMT done"); + + err = _camerasrc_ioctl_reqbufs(p, p->fd_3aa1, p->format_3aa1.num_buffers, + type, V4L2_MEMORY_DMABUF, &p->format_3aa1.num_buffers); + if (err != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[3AA1 - CAPTURE] _camerasrc_ioctl_reqbufs failed[%x] : %s", err, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + p->reqbuf_3aa1_capture = TRUE; + + camsrc_info("[3AA1 - CAPTURE] REQBUF done. count : %d", p->format_3aa1.num_buffers); + + /* ISP */ + input = 0x11010; + camsrc_info("[ISP] VIDIOC_S_INPUT %d", input); + err = ioctl(p->fd_isp, VIDIOC_S_INPUT, &input); + if (err < 0) { + camsrc_error("[ISP] VIDIOC_S_INPUT failed. input 0x%x", input); + return CAMERASRC_ERR_IO_CONTROL; + } + + camsrc_info("[ISP] VIDIOC_S_INPUT done"); + + type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; + p->format_isp.img_size.width = p->format_3aa1.img_size.width; + p->format_isp.img_size.height = p->format_3aa1.img_size.height; + p->format_isp.pix_format = CAMERASRC_PIX_SBGGR12; + + err = _camerasrc_ioctl_s_fmt(p, p->fd_isp, type, &p->format_isp); + if (err != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[ISP - OUTPUT] _camerasrc_ioctl_s_fmt failed[%x] : %s", err, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + camsrc_info("[ISP] S_FMT done"); + + err = _camerasrc_ioctl_reqbufs(p, p->fd_isp, p->format_isp.num_buffers, + type, V4L2_MEMORY_DMABUF, &p->format_isp.num_buffers); + if (err != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[ISP - OUTPUT] _camerasrc_ioctl_reqbufs failed[%x] : %s", err, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + p->reqbuf_isp = TRUE; + + camsrc_info("[ISP] REQBUF done. count : %d", p->format_isp.num_buffers); + + err = _camerasrc_ioctl_s_ctrl(p, p->fd_isp, V4L2_CID_IS_SET_SETFILE, 6); + if (err != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[ISP] V4L2_CID_IS_SET_SETFILE failed[%x] : %s", err, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + camsrc_info("[ISP] IS_SET_SETFILE 6 done"); + + /* SCC */ + type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; + p->format_scc.img_size.width = p->format_3aa1.img_size.width; + p->format_scc.img_size.height = p->format_3aa1.img_size.height; + p->format_scc.pix_format = CAMERASRC_PIX_NV12; + + err = _camerasrc_ioctl_s_fmt(p, p->fd_scc, type, &p->format_scc); + if (err != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[SCC - CAPTURE] _camerasrc_ioctl_s_fmt failed[%x] : %s", err, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + camsrc_info("[SCC] S_FMT done"); + + err = _camerasrc_ioctl_reqbufs(p, p->fd_scc, p->format_scc.num_buffers, + type, V4L2_MEMORY_DMABUF, &p->format_scc.num_buffers); + if (err != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[SCC - CAPTURE] _camerasrc_ioctl_reqbufs failed[%x] : %s", err, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + p->reqbuf_scc = TRUE; + + camsrc_info("[SCC] REQBUF done. count : %d", p->format_scc.num_buffers); + + /* SCP */ + type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; + p->format_scp.pix_format = CAMERASRC_PIX_SN21; /* SN21(NV21M) is only come */ + + err = _camerasrc_ioctl_s_fmt(p, p->fd_scp, type, &p->format_scp); + if (err != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[SCP - CAPTURE] _camerasrc_ioctl_s_fmt failed[%x] : %s", err, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + camsrc_info("[SCP] S_FMT done"); + + err = _camerasrc_ioctl_reqbufs(p, p->fd_scp, p->format_scp.num_buffers, + type, V4L2_MEMORY_DMABUF, &p->format_scp.num_buffers); + if (err != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[SCP - CAPTURE] _camerasrc_ioctl_reqbufs failed[%x] : %s", err, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + p->reqbuf_scp = TRUE; + + camsrc_info("[SCP] REQBUF done. count : %d", p->format_scp.num_buffers); + + err = _camerasrc_ioctl_s_ctrl(p, p->fd_scp, V4L2_CID_IS_COLOR_RANGE, 0); + if (err != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[SCP] V4L2_CID_IS_COLOR_RANGE failed[%x] : %s", err, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + camsrc_info("[SCP] V4L2_CID_IS_COLOR_RANGE done"); + } + + /* QBUF */ + if (p->buffer_sensor) { + err = _camerasrc_set_shot_meta(p, GRP_SENSOR, 0, 0, (struct camera2_shot_ext *)p->buffer_sensor[0].planes[1].start); + if (err != CAMERASRC_SUCCESS) { + camsrc_error("[SENSOR] _camerasrc_set_shot_meta index %d, failed[%x]", i, err); + return err; + } + + for (i = 0 ; i < p->format_sensor.num_buffers ; i++) { + err = _camerasrc_ioctl_qbuf(p, + p->fd_sensor, + V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, + V4L2_MEMORY_DMABUF, + i, + &p->buffer_sensor[i]); + if (err != CAMERASRC_SUCCESS) { + camsrc_error("[SENSOR] _camerasrc_ioctl_qbuf index %d, failed[%x]", i, err); + return CAMERASRC_ERR_IO_CONTROL; + } + } + + camsrc_info("[SENSOR] QBUF done - %d", p->format_sensor.num_buffers); + } + + if (p->buffer_scp) { + for (i = 0 ; i < p->format_scp.num_buffers ; i++) { + err = _camerasrc_set_shot_meta(p, GRP_SCP, i, 0, (struct camera2_shot_ext *)p->buffer_scp[i].planes[2].start); + if (err != CAMERASRC_SUCCESS) { + camsrc_error("[SCP] _camerasrc_set_shot_meta index %d, failed[%x]", i, err); + return err; + } + + err = _camerasrc_ioctl_qbuf(p, + p->fd_scp, + V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, + V4L2_MEMORY_DMABUF, + i, + &p->buffer_scp[i]); + if (err != CAMERASRC_SUCCESS) { + camsrc_error("[SCP] _camerasrc_ioctl_qbuf index %d, failed[%x]", i, err); + return CAMERASRC_ERR_IO_CONTROL; + } + } + + camsrc_info("[SCP] QBUF done - %d", p->format_scp.num_buffers); + } + + /* STREAM ON */ + err = _camerasrc_ioctl_stream(p, p->fd_sensor, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, TRUE); + if (err != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[SENSOR] _camerasrc_ioctl_stream failed[%x] : %s", err, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + p->streamon_sensor = TRUE; + + camsrc_info("[SENSOR] STREAMON done"); + + err = _camerasrc_ioctl_stream(p, p->fd_3aa1, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, TRUE); + if (err != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[3AA1 - CAPTURE] _camerasrc_ioctl_stream failed[%x] : %s", err, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + p->streamon_3aa1_capture = TRUE; + + camsrc_info("[3AA1 - CAPTURE] STREAMON done"); + + err = _camerasrc_ioctl_stream(p, p->fd_3aa1, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, TRUE); + if (err != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[3AA1 - OUTPUT] _camerasrc_ioctl_stream failed[%x] : %s", err, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + p->streamon_3aa1_output = TRUE; + + camsrc_info("[3AA1 - OUTPUT] STREAMON done"); + + err = _camerasrc_ioctl_stream(p, p->fd_scc, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, TRUE); + if (err != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[SCC] _camerasrc_ioctl_stream failed[%x] : %s", err, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + p->streamon_scc = TRUE; + + camsrc_info("[SCC] STREAMON done"); + + err = _camerasrc_ioctl_stream(p, p->fd_scp, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, TRUE); + if (err != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[SCP] _camerasrc_ioctl_stream failed[%x] : %s", err, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + p->streamon_scp = TRUE; + + camsrc_info("[SCP] STREAMON done"); + + err = _camerasrc_ioctl_stream(p, p->fd_isp, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, TRUE); + if (err != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[ISP] _camerasrc_ioctl_stream failed[%x] : %s", err, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + p->streamon_isp = TRUE; + + camsrc_info("[ISP] STREAMON done"); + + if (p->cur_dev_id == CAMERASRC_DEV_ID_SECONDARY) { + err = _camerasrc_ioctl_s_ctrl(p, p->fd_sensor, V4L2_CID_IS_S_STREAM, TRUE); + if (err != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[SENSOR] V4L2_CID_IS_S_STREAM failed[%x] : %s", err, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + p->streamon_sensor_sub = TRUE; + + camsrc_info("[SENSOR] IS_S_STREAM 1 done"); + } + + if (p->buffer_scc) { + for (i = 0 ; i < p->format_scc.num_buffers ; i++) { + err = _camerasrc_set_shot_meta(p, GRP_SCC, i, 0, (struct camera2_shot_ext *)p->buffer_scc[i].planes[1].start); + if (err != CAMERASRC_SUCCESS) { + camsrc_error("[SCC] _camerasrc_set_shot_meta index %d, failed[%x]", i, err); + return err; + } + + err = _camerasrc_ioctl_qbuf(p, + p->fd_scc, + V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, + V4L2_MEMORY_DMABUF, + i, + &p->buffer_scc[i]); + if (err != CAMERASRC_SUCCESS) { + camsrc_error("[SCC] _camerasrc_ioctl_qbuf index %d, failed[%x]", i, err); + return CAMERASRC_ERR_IO_CONTROL; + } + } + + camsrc_info("[SCC] QBUF done - %d", p->format_scc.num_buffers); + } + + CAMERASRC_SET_STATE(p, CAMERASRC_STATE_PREVIEW); + + return CAMERASRC_SUCCESS; +} + + +int camerasrc_stop_stream(camsrc_handle_t handle) +{ + camerasrc_handle_t *p = NULL; + int ret = CAMERASRC_SUCCESS; + char err_msg[CAMERASRC_ERRMSG_MAX_LEN] = {'\0',}; + + camsrc_info("enter"); + + if(handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + if (CAMERASRC_STATE(p) != CAMERASRC_STATE_STILL && + CAMERASRC_STATE(p) != CAMERASRC_STATE_PREVIEW && + CAMERASRC_STATE(p) != CAMERASRC_STATE_VIDEO && + CAMERASRC_STATE(p) != CAMERASRC_STATE_AF_IN_PROGRESS) { + camsrc_warning("Stop stream called [STREAM-NOT-STARTED STATE]"); + } + + camsrc_info("Change to READY state first for preventing to check Q/DQ after stop"); + CAMERASRC_SET_STATE(p, CAMERASRC_STATE_READY); + + LOCK(p); + p->timeperframe.denominator = 0; + p->timeperframe.numerator = 0; + p->first_frame = 1; + UNLOCK(p); + + /* STREAM OFF */ + if (p->cur_dev_id == CAMERASRC_DEV_ID_SECONDARY && + p->streamon_sensor_sub) { + ret = _camerasrc_ioctl_s_ctrl(p, p->fd_sensor, V4L2_CID_IS_S_STREAM, 0); + if (ret != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[SENSOR] V4L2_CID_IS_S_STREAM failed[%x] : %s", ret, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + p->streamon_sensor_sub = FALSE; + + camsrc_info("[SENSOR] V4L2_CID_IS_S_STREAM 0 done"); + } + + if (p->streamon_sensor) { + ret = _camerasrc_ioctl_stream(p, p->fd_sensor, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, FALSE); + if (ret != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[SENSOR] _camerasrc_ioctl_stream failed[%x] : %s", ret, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + p->streamon_sensor = FALSE; + + camsrc_info("[SENSOR] STREAMOFF done"); + } + + if (p->streamon_3aa1_output) { + ret = _camerasrc_ioctl_stream(p, p->fd_3aa1, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, FALSE); + if (ret != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[3AA1 - OUTPUT] _camerasrc_ioctl_stream failed[%x] : %s", ret, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + p->streamon_3aa1_output = FALSE; + + camsrc_info("[3AA1 - OUTPUT] STREAMOFF done"); + } + + if (p->streamon_3aa1_capture) { + ret = _camerasrc_ioctl_stream(p, p->fd_3aa1, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, FALSE); + if (ret != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[3AA1 - CAPTURE] _camerasrc_ioctl_stream failed[%x] : %s", ret, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + p->streamon_3aa1_capture = FALSE; + + camsrc_info("[3AA1 - CAPTURE] STREAMOFF done"); + } + + if (p->streamon_isp) { + ret = _camerasrc_ioctl_stream(p, p->fd_isp, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, FALSE); + if (ret != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[ISP] _camerasrc_ioctl_stream failed[%x] : %s", ret, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + p->streamon_isp = FALSE; + + camsrc_info("[ISP] STREAMOFF done"); + } + + if (p->streamon_scc) { + ret = _camerasrc_ioctl_stream(p, p->fd_scc, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, FALSE); + if (ret != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[SCC] _camerasrc_ioctl_stream failed[%x] : %s", ret, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + p->streamon_scc = FALSE; + + camsrc_info("[SCC] STREAMOFF done"); + } + + if (p->streamon_scp) { + ret = _camerasrc_ioctl_stream(p, p->fd_scp, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, FALSE); + if (ret != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[SCP] _camerasrc_ioctl_stream failed[%x] : %s", ret, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + p->streamon_scp = FALSE; + + camsrc_info("[SCP] STREAMOFF done"); + } + + /** + * REQBUF 0 + */ + /* SENSOR */ + if (p->reqbuf_sensor) { + ret = _camerasrc_ioctl_reqbufs(p, p->fd_sensor, 0, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, V4L2_MEMORY_DMABUF, NULL); + if (ret != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[SENSOR - CAPTURE] _camerasrc_ioctl_reqbufs failed[%x] : %s", ret, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + p->reqbuf_sensor = FALSE; + + camsrc_info("[SENSOR] REQBUF 0 done"); + } + + /* 3AA1 - OUTPUT */ + if (p->reqbuf_3aa1_output) { + ret = _camerasrc_ioctl_reqbufs(p, p->fd_3aa1, 0, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, V4L2_MEMORY_DMABUF, NULL); + if (ret != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[3AA1 - OUTPUT] _camerasrc_ioctl_reqbufs failed[%x] : %s", ret, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + p->reqbuf_3aa1_output = FALSE; + + camsrc_info("[3AA1 - OUTPUT] REQBUF 0 done"); + } + + /* 3AA1 - CAPTURE */ + if (p->reqbuf_3aa1_capture) { + ret = _camerasrc_ioctl_reqbufs(p, p->fd_3aa1, 0, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, V4L2_MEMORY_DMABUF, NULL); + if (ret != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[3AA1 - CAPTURE] _camerasrc_ioctl_reqbufs failed[%x] : %s", ret, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + p->reqbuf_3aa1_capture = FALSE; + + camsrc_info("[3AA1 - CAPTURE] REQBUF 0 done"); + } + + /* ISP */ + if (p->reqbuf_isp) { + ret = _camerasrc_ioctl_reqbufs(p, p->fd_isp, 0, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, V4L2_MEMORY_DMABUF, NULL); + if (ret != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[ISP - OUTPUT] _camerasrc_ioctl_reqbufs failed[%x] : %s", ret, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + p->reqbuf_isp = FALSE; + + camsrc_info("[ISP] REQBUF 0 done"); + } + + /* SCC */ + if (p->reqbuf_scc) { + ret = _camerasrc_ioctl_reqbufs(p, p->fd_isp, 0, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, V4L2_MEMORY_DMABUF, NULL); + if (ret != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[SCC - CAPTURE] _camerasrc_ioctl_reqbufs failed[%x] : %s", ret, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + p->reqbuf_scc = FALSE; + + camsrc_info("[SCC] REQBUF 0 done"); + } + + /* SCP */ + if (p->reqbuf_scp) { + ret = _camerasrc_ioctl_reqbufs(p, p->fd_isp, 0, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, V4L2_MEMORY_DMABUF, NULL); + if (ret != CAMERASRC_SUCCESS) { + strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN); + camsrc_error("[SCP - CAPTURE] _camerasrc_ioctl_reqbufs failed[%x] : %s", ret, err_msg); + return CAMERASRC_ERR_IO_CONTROL; + } + + p->reqbuf_scp = FALSE; + + camsrc_info("[SCP] REQBUF 0 done"); + } + + camsrc_info("VIDIOC_REQBUFS 0 done"); + + return CAMERASRC_SUCCESS; +} + + +int camerasrc_wait_frame_available(camsrc_handle_t handle, int timeout) +{ + camerasrc_handle_t *p = NULL; + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + if (CAMERASRC_STATE(p) != CAMERASRC_STATE_STILL && + CAMERASRC_STATE(p) != CAMERASRC_STATE_PREVIEW && + CAMERASRC_STATE(p) != CAMERASRC_STATE_VIDEO && + CAMERASRC_STATE(p) != CAMERASRC_STATE_AF_IN_PROGRESS) { + camsrc_warning("Invalid state transition" ); + } + + return _camerasrc_wait_frame_available(p, timeout); +} + + +int camerasrc_queue_buffer(camsrc_handle_t handle, int buf_index) +{ + camerasrc_handle_t *p = NULL; + int err = CAMERASRC_ERR_UNKNOWN; + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + if (CAMERASRC_STATE(p) != CAMERASRC_STATE_STILL && + CAMERASRC_STATE(p) != CAMERASRC_STATE_PREVIEW && + CAMERASRC_STATE(p) != CAMERASRC_STATE_VIDEO && + CAMERASRC_STATE(p) != CAMERASRC_STATE_AF_IN_PROGRESS ) { + camsrc_warning("Invalid state transition"); + } + + err = _camerasrc_queue_buffer(p, buf_index); + + return err; +} + + +int camerasrc_dequeue_buffer(camsrc_handle_t handle, int *buf_index, camerasrc_buffer_t *buffer, camerasrc_buffer_t *thm_buffer) +{ + camerasrc_handle_t *p = NULL; + int err = CAMERASRC_ERR_UNKNOWN; + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + if (CAMERASRC_STATE(p) != CAMERASRC_STATE_STILL && + CAMERASRC_STATE(p) != CAMERASRC_STATE_PREVIEW && + CAMERASRC_STATE(p) != CAMERASRC_STATE_VIDEO && + CAMERASRC_STATE(p) != CAMERASRC_STATE_AF_IN_PROGRESS) { + camsrc_warning("Invalid state transition"); + } + + err = _camerasrc_dequeue_buffer(p, buf_index, buffer, thm_buffer); + + return err; +} + + +int camerasrc_read_frame(camsrc_handle_t handle, camerasrc_buffer_t *main_img_buffer, camerasrc_buffer_t *thm_img_buffer, int *buffer_index) +{ + camerasrc_handle_t *p = NULL; + int err = CAMERASRC_ERR_UNKNOWN; + + camsrc_info("ENTER"); + + if (!handle || !main_img_buffer || !thm_img_buffer || !buffer_index) { + camsrc_error("handle(%p)main(%p)thm(%p)index(%p) is null", + handle, main_img_buffer, thm_img_buffer, buffer_index); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + if (CAMERASRC_STATE(p) != CAMERASRC_STATE_STILL && + CAMERASRC_STATE(p) != CAMERASRC_STATE_PREVIEW && + CAMERASRC_STATE(p) != CAMERASRC_STATE_VIDEO && + CAMERASRC_STATE(p) != CAMERASRC_STATE_AF_IN_PROGRESS) { + camsrc_warning("Invalid state transition"); + } + + GST_INFO(" Stillshot select()"); + err = _camerasrc_wait_frame_available(p, CAMERASRC_TIMEOUT_CRITICAL_VALUE); + if (err != CAMERASRC_SUCCESS) { + camsrc_error("Frame waiting error, [%x]", err); + return err; + } + + /* Buffer DQ */ + GST_INFO(" Stillshot VIDIOC_DQBUF"); + err = _camerasrc_dequeue_buffer(p, buffer_index, main_img_buffer, thm_img_buffer); + if (err != CAMERASRC_SUCCESS) { + camsrc_error("Dequeue frame error, [%x]", err); + return err; + } + + camsrc_info("DEQUEUED Index : %d", *buffer_index); + + return CAMERASRC_SUCCESS; +} + + +int camerasrc_set_focused_callback(camsrc_handle_t handle, camerasrc_callback_t cb, void *usr_data) +{ + camerasrc_handle_t *p = NULL; + + camsrc_info("enter"); + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + if (CAMERASRC_STATE(p) != CAMERASRC_STATE_REALIZED && + CAMERASRC_STATE(p) != CAMERASRC_STATE_READY) { + camsrc_warning("Invalid state transition"); + } + + LOCK(p); + p->af_cb = cb; + if (usr_data != NULL) { + p->af_usr_data = usr_data; + } + UNLOCK(p); + + return CAMERASRC_SUCCESS; +} + + +int camerasrc_set_autofocusing_area(camsrc_handle_t handle, camerasrc_rect_t *rect) +{ + camerasrc_handle_t *p = NULL; + int err = CAMERASRC_ERR_UNKNOWN; + + camsrc_info("enter"); + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + if (CAMERASRC_PHASE(p) != CAMERASRC_PHASE_RUNNING) { + camsrc_warning("Invalid state transition"); + } + + err = _camerasrc_set_autofocusing_area(p, rect); + + if (err != CAMERASRC_SUCCESS) { + camsrc_error("Set autofocusing area error"); + return err; + } + + return CAMERASRC_SUCCESS; +} + + +int camerasrc_get_autofocusing_area(camsrc_handle_t handle, camerasrc_rect_t *rect) +{ + camerasrc_handle_t *p = NULL; + int err = CAMERASRC_ERR_UNKNOWN; + + camsrc_info("enter"); + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + if (CAMERASRC_PHASE(p) != CAMERASRC_PHASE_RUNNING) { + camsrc_warning("Invalid state transition"); + } + + err = _camerasrc_get_autofocusing_area(p, rect); + + if (err != CAMERASRC_SUCCESS) { + camsrc_error("Get autofocusing area error"); + return err; + } + + return CAMERASRC_SUCCESS; +} + + +int camerasrc_start_autofocusing(camsrc_handle_t handle) +{ + camerasrc_handle_t *p = NULL; + int err = CAMERASRC_ERR_UNKNOWN; + + camsrc_info("enter"); + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + if (!(CAMERASRC_STATE(p) == CAMERASRC_STATE_PREVIEW || + CAMERASRC_STATE(p) == CAMERASRC_STATE_VIDEO || + CAMERASRC_STATE(p) == CAMERASRC_STATE_AF_IN_PROGRESS)) { + camsrc_error("Invalid state [%d]", CAMERASRC_STATE(p)); + return CAMERASRC_ERR_INVALID_STATE; + } + + /* START AF */ + err = _camerasrc_start_autofocusing(p); + + if (err != CAMERASRC_SUCCESS) { + camsrc_error("Create autofocusing thread error"); + return err; + } + + camsrc_info("Set state to [AF-IN-PROGRESS]!!"); + CAMERASRC_SET_STATE(p, CAMERASRC_STATE_AF_IN_PROGRESS); + + return CAMERASRC_SUCCESS; +} + + +int camerasrc_stop_autofocusing(camsrc_handle_t handle) +{ + camerasrc_handle_t *p = NULL; + int err = CAMERASRC_ERR_UNKNOWN; + + camsrc_info("enter"); + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + if (!(CAMERASRC_STATE(p) == CAMERASRC_STATE_PREVIEW || + CAMERASRC_STATE(p) == CAMERASRC_STATE_VIDEO || + CAMERASRC_STATE(p) == CAMERASRC_STATE_AF_IN_PROGRESS)) { + camsrc_error("Invalid state [%d]", CAMERASRC_STATE(p)); + return CAMERASRC_ERR_INVALID_STATE; + } + + /* STOP AF */ + camsrc_info("AF_STOP called!!"); + err = _camerasrc_stop_autofocusing(p); + if (err != CAMERASRC_SUCCESS) { + camsrc_error("Stop autofocusing error"); + return err; + } + + if (CAMERASRC_STATE(p) > CAMERASRC_STATE_READY) { + camsrc_info("Set state to [PREVIEW] again!!"); + CAMERASRC_SET_STATE(p, CAMERASRC_STATE_PREVIEW); + } else { + camsrc_info("Do not change state"); + } + + return CAMERASRC_SUCCESS; +} + + +int camerasrc_release_autofocusing(camsrc_handle_t handle) +{ + camerasrc_handle_t *p = NULL; + int err = CAMERASRC_ERR_UNKNOWN; + + camsrc_info("enter"); + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + if (CAMERASRC_STATE(p) != CAMERASRC_STATE_PREVIEW && + CAMERASRC_STATE(p) != CAMERASRC_STATE_VIDEO && + CAMERASRC_STATE(p) != CAMERASRC_STATE_AF_IN_PROGRESS) { + return CAMERASRC_SUCCESS; + } + + /* STOP AF */ + camsrc_info("AF_RELEASE called!!"); + err = _camerasrc_release_autofocusing(p); + if (err != CAMERASRC_SUCCESS) { + camsrc_error("Stop autofocusing error"); + return err; + } + + if (CAMERASRC_STATE(p) > CAMERASRC_STATE_READY) { + camsrc_info("Set state to [PREVIEW] again!!"); + CAMERASRC_SET_STATE(p, CAMERASRC_STATE_PREVIEW); + } else { + camsrc_info("Do not change state"); + } + + return CAMERASRC_SUCCESS; +} + + +int camerasrc_init_autofocusing_mode(camsrc_handle_t handle, camerasrc_af_mode_t af_mode, camerasrc_af_scan_range_t af_range) +{ + camerasrc_handle_t *p = NULL; + int err = CAMERASRC_ERR_UNKNOWN; + + camsrc_info("enter"); + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + p->cur_af_mode = af_mode; + p->cur_af_range = af_range; + + if (CAMERASRC_STATE(p) < CAMERASRC_STATE_PREVIEW) { + camsrc_info("Skip focus mode[%d], range[%d], it will be set when start preview", + af_mode, af_range); + return CAMERASRC_SUCCESS; + } + + err = _camerasrc_init_autofocusing_mode(p); + if (err != CAMERASRC_SUCCESS) { + camsrc_error("Init autofocusing mode error"); + return err; + } + + return CAMERASRC_SUCCESS; +} + + +int camerasrc_get_autofocusing_mode(camsrc_handle_t handle, camerasrc_af_mode_t *af_mode, camerasrc_af_scan_range_t *af_range) +{ + camerasrc_handle_t *p = NULL; + + camsrc_info("enter"); + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + if (af_mode) { + *af_mode = p->cur_af_mode; + } + + if (af_range) { + *af_range = p->cur_af_range; + } + + return CAMERASRC_SUCCESS; +} + + +int camerasrc_get_autofocusing_status(camsrc_handle_t handle, camerasrc_auto_focus_status_t *af_status) +{ + camerasrc_handle_t *p = NULL; + + camsrc_info("enter"); + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + if (af_status == NULL) { + camsrc_error("*af_status is NULL"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + *af_status = p->af_status; + + camsrc_info("[camerasrc_get_autofocusing_status] %d", *af_status); + + return CAMERASRC_SUCCESS; +} + + +/**** O U T P U T C O N T R O L O P E R A T I O N ****/ + +int camerasrc_set_timeperframe(camsrc_handle_t handle, camerasrc_frac_t *frac) +{ + camerasrc_handle_t *p = NULL; + + camsrc_info("enter"); + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + if (CAMERASRC_PHASE(p) != CAMERASRC_PHASE_RUNNING) { + camsrc_warning("Invalid phase, but can go"); + } + + camsrc_info("Numerator = %d, Denominator = %d", frac->numerator, frac->denominator); + + LOCK(p); + p->timeperframe.numerator = frac->numerator; + p->timeperframe.denominator = frac->denominator; + UNLOCK(p); + + return CAMERASRC_SUCCESS; +} + + +int camerasrc_set_format(camsrc_handle_t handle, camerasrc_format_t *fmt) +{ + camerasrc_handle_t *p = NULL; + int err = CAMERASRC_ERR_UNKNOWN; + + camsrc_info("enter"); + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + if (CAMERASRC_STATE(p) != CAMERASRC_STATE_READY) { + camsrc_error("Invalid state"); + } + + err = _camerasrc_dump_format(handle); + if (err != CAMERASRC_SUCCESS) { + camsrc_error("Format dump error"); + return err; + } + + memset(&p->format_scp, 0x0, sizeof(camerasrc_format_t)); + + p->format_scp.colorspace = fmt->colorspace; + p->format_scp.bytesperline = fmt->bytesperline; + p->format_scp.img_size.width = fmt->img_size.width; + p->format_scp.img_size.height = fmt->img_size.height; + p->format_scp.capture_size.width = fmt->capture_size.width; + p->format_scp.capture_size.height = fmt->capture_size.height; + p->format_scp.thumb_size.width = fmt->thumb_size.width; + p->format_scp.thumb_size.height= fmt->thumb_size.height; + p->format_scp.pix_format = CAMERASRC_PIX_SN21; + p->format_scp.quality = fmt->quality; + p->format_scp.sizeimage = fmt->sizeimage; + p->format_scp.rotation = fmt->rotation; + p->format_scp.num_buffers = CAMERASRC_PREVIEW_BUFFER_NUM; + + switch (fmt->pix_format) { + case CAMERASRC_PIX_YUV420: + case CAMERASRC_PIX_SN12: + case CAMERASRC_PIX_NV12: + case CAMERASRC_PIX_SN21: + case CAMERASRC_PIX_NV21: + p->format_scp.num_planes = 2; + break; + case CAMERASRC_PIX_YUY2: + case CAMERASRC_PIX_UYVY: + case CAMERASRC_PIX_RGGB8: + case CAMERASRC_PIX_RGGB10: + case CAMERASRC_PIX_RGB565: + p->format_scp.num_planes = 1; + break; + case CAMERASRC_PIX_YUV422P: + case CAMERASRC_PIX_YUV420P: + case CAMERASRC_PIX_YV12: + p->format_scp.num_planes = 3; + break; + default: + p->format_scp.num_planes = 3; + camsrc_error("Invalid output format [%d]", fmt->pix_format); + break; + } + + err = _camerasrc_dump_format(handle); + if (err != CAMERASRC_SUCCESS) { + camsrc_error("Format dump error"); + return err; + } + + camsrc_info("leave"); + + return err; +} + + +int camerasrc_get_format(camsrc_handle_t handle, camerasrc_format_t *fmt) +{ + camerasrc_handle_t *p = NULL; + + camsrc_info("enter"); + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + if (CAMERASRC_PHASE(p) != CAMERASRC_PHASE_RUNNING) { + camsrc_warning("Invalid phase"); + } + + memcpy(fmt, &(p->format_scp), sizeof(camerasrc_format_t)); + + camsrc_info("leave"); + + return CAMERASRC_SUCCESS; +} + + +int camerasrc_get_frame_data(camsrc_handle_t handle, camerasrc_frame_data_t *data) +{ + camerasrc_handle_t *p = NULL; + int err = CAMERASRC_ERR_UNKNOWN; + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + if (CAMERASRC_PHASE(p) != CAMERASRC_PHASE_RUNNING) { + camsrc_warning("Invalid state transition"); + } + + err = _camerasrc_get_frame_data(p, data); + if (err != CAMERASRC_SUCCESS) { + camsrc_error("toggle auto exposure failed"); + return err; + } + + return err; +} + + +static int _camerasrc_dump_format(camsrc_handle_t handle) +{ + camerasrc_handle_t *p = NULL; + + camsrc_info("enter"); + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + camsrc_info("---------FORMAT SETTING DUMP--------"); + camsrc_info("- Image size : %d x %d", p->format_scp.img_size.width, p->format_scp.img_size.height); + camsrc_info("- Capture size : %d x %d", p->format_scp.capture_size.width, p->format_scp.capture_size.height); + camsrc_info("- Thumbnail size : %d x %d", p->format_scp.thumb_size.width, p->format_scp.thumb_size.height); + camsrc_info("- Pixel format : %d", p->format_scp.pix_format); + camsrc_info("- Bytes per line : %d", p->format_scp.bytesperline); + camsrc_info("- Image size in bytes : %d", p->format_scp.sizeimage); + camsrc_info("- Colorspace : %d", p->format_scp.colorspace); + camsrc_info("- Rotation : %d", p->format_scp.rotation); + camsrc_info("------------------------------------"); + + return CAMERASRC_SUCCESS; +} + + +int camerasrc_get_exif_info(camsrc_handle_t handle, camerasrc_exif_t *exif_struct) +{ + camerasrc_handle_t* p = NULL; + int err = CAMERASRC_ERR_UNKNOWN; + + camsrc_info("enter"); + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + if (CAMERASRC_PHASE(p) != CAMERASRC_PHASE_RUNNING) { + camsrc_warning("Invalid state transition"); + } + + err = _camerasrc_get_exif_info(p, (camerasrc_buffer_t*)exif_struct); + if (err != CAMERASRC_SUCCESS) { + camsrc_error("Get exif information string failed"); + } + + return err; +} + + +int camerasrc_set_vflip(camsrc_handle_t handle, int vflip) +{ + camerasrc_handle_t *p = NULL; + + camsrc_info("enter"); + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + p->vflip = vflip; + + if (CAMERASRC_STATE(p) > CAMERASRC_STATE_READY) { + CAMERASRC_SET_CMD(_CAMERASRC_CMD_VFLIP, &(p->vflip)); + } + + camsrc_info("leave - %d", p->vflip); + + return CAMERASRC_SUCCESS; +} + + +int camerasrc_set_hflip(camsrc_handle_t handle, int hflip) +{ + camerasrc_handle_t *p = NULL; + + camsrc_info("enter"); + + if (handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + p->hflip = hflip; + if (CAMERASRC_STATE(p) > CAMERASRC_STATE_READY) { + CAMERASRC_SET_CMD(_CAMERASRC_CMD_HFLIP, &(p->hflip)); + } + + camsrc_info("leave - %d", p->hflip); + + return CAMERASRC_SUCCESS; +} + + +int camerasrc_tbm_init(camsrc_handle_t handle) +{ + camerasrc_handle_t *p = NULL; + + if (handle == NULL) { + camsrc_error("handle is NULL"); + return FALSE; + } + + camsrc_warning("start"); + + p = CAMERASRC_HANDLE(handle); + + if (p->bufmgr) { + camsrc_warning("bufmgr is already created %p", p->bufmgr); + return TRUE; + } + + /* tbm buffer mgr init */ + p->bufmgr = tbm_bufmgr_init(-1); + if (!p->bufmgr) { + camsrc_error("tbm_bufmgr_init failed"); + return FALSE; + } + + camsrc_warning("tbm_bufmgr %p", p->bufmgr); + + return TRUE; +} + + +int camerasrc_tbm_deinit(camsrc_handle_t handle) +{ + camerasrc_handle_t *p = NULL; + + if (handle == NULL) { + camsrc_error("handle is NULL"); + return FALSE; + } + + p = CAMERASRC_HANDLE(handle); + + camsrc_warning("enter - tbm bufmgr %p", p->bufmgr); + + if (p->bufmgr) { + tbm_bufmgr_deinit(p->bufmgr); + p->bufmgr = NULL; + camsrc_warning("release tbm_bufmgr done"); + } + + camsrc_warning("done"); + + return TRUE; +} + + +int camerasrc_tbm_alloc_buffer(camsrc_handle_t handle, int size, tbm_bo *bo, int *dma_buf_fd, unsigned char **vaddr) +{ + camerasrc_handle_t *p = NULL; + tbm_bo bo_alloc = NULL; + tbm_bo_handle bo_handle_fd; + tbm_bo_handle bo_handle_vaddr; + + if (!handle || !bo || !dma_buf_fd || !vaddr) { + camsrc_error("pointer(%p %p %p %p) is NULL", handle, bo, dma_buf_fd, vaddr); + return FALSE; + } + + if (size <= 0) { + camsrc_error("size[%d] is too small", size); + return FALSE; + } + + p = CAMERASRC_HANDLE(handle); + + if (p->bufmgr == NULL) { + camsrc_error("tbm bufmgr is NULL"); + return FALSE; + } + + /* alloc tbm buffer object */ + bo_alloc = tbm_bo_alloc(p->bufmgr, size, TBM_BO_DEFAULT); + if (!bo_alloc) { + camsrc_error("tbm_bo_alloc failed"); + return FALSE; + } + + /* get dmabuf fd */ + bo_handle_fd = tbm_bo_get_handle(bo_alloc, TBM_DEVICE_MM); + if (bo_handle_fd.u32 == 0) { + tbm_bo_unref(bo_alloc); + camsrc_error("tbm_bo_get_handle TBM_DEVICE_MM failed"); + return FALSE; + } + + /* get virtual address */ + bo_handle_vaddr = tbm_bo_get_handle(bo_alloc, TBM_DEVICE_CPU); + if (bo_handle_vaddr.ptr == NULL) { + tbm_bo_unref(bo_alloc); + camsrc_error("tbm_bo_get_handle TBM_DEVICE_CPU failed"); + return FALSE; + } + + *bo = bo_alloc; + *dma_buf_fd = bo_handle_fd.u32; + *vaddr = bo_handle_vaddr.ptr; + + camsrc_warning("bo %p, dmabuf fd %u, vaddr %p, size %d", + *bo, *dma_buf_fd, *vaddr, size); + + return TRUE; +} + + +/* For Query functionalities */ +int camerasrc_read_basic_dev_info(camerasrc_dev_id_t dev_id, camerasrc_caps_info_t* caps_info) +{ + int err = CAMERASRC_ERR_UNKNOWN; + int nread = 0; + char* store_path = NULL; + FILE *fp = NULL; + + camsrc_info("enter"); + + if(dev_id == CAMERASRC_DEV_ID_PRIMARY) + store_path = CAMERASRC_PRIMARY_BASIC_INFO_PATH; + else if (dev_id == CAMERASRC_DEV_ID_SECONDARY) + store_path = CAMERASRC_SECONDARY_BASIC_INFO_PATH; + else + { + camsrc_error("Unsupported device ID"); + return CAMERASRC_ERR_DEVICE_NOT_SUPPORT; + } + + fp = fopen(store_path, "rb"); + if(fp) + { + fseek(fp, 0, SEEK_SET); + nread = fread(caps_info, 1, sizeof(camerasrc_caps_info_t), fp); + camsrc_info("Need to be read : %d / Actual read : %d", sizeof(camerasrc_caps_info_t), nread); + fclose(fp); + } + else + return CAMERASRC_ERR_ALLOCATION; + + err = CAMERASRC_SUCCESS; + camsrc_info("leave"); + return err; +} + + +int camerasrc_read_misc_dev_info(camerasrc_dev_id_t dev_id, camerasrc_ctrl_list_info_t* ctrl_info) +{ + int err = CAMERASRC_ERR_UNKNOWN; + camsrc_info("enter"); + + int nread = 0; + FILE *fp = NULL; + char* store_path = NULL; + + if(dev_id == CAMERASRC_DEV_ID_PRIMARY) + store_path = CAMERASRC_PRIMARY_MISC_INFO_PATH; + else if (dev_id == CAMERASRC_DEV_ID_SECONDARY) + store_path = CAMERASRC_SECONDARY_MISC_INFO_PATH; + else + { + camsrc_error("Unsupported device ID"); + return CAMERASRC_ERR_DEVICE_NOT_SUPPORT; + } + + fp = fopen(store_path, "rb"); + if(fp) + { + fseek(fp, 0, SEEK_SET); + nread = fread(ctrl_info, 1, sizeof(camerasrc_ctrl_list_info_t), fp); + camsrc_info("Need to be read : %d / Actual read : %d", sizeof(camerasrc_ctrl_list_info_t), nread); + fclose(fp); + } + else + return CAMERASRC_ERR_ALLOCATION; + + err = CAMERASRC_SUCCESS; + camsrc_info("leave"); + return err; +} + + +int camerasrc_read_extra_dev_info(camerasrc_dev_id_t dev_id, camerasrc_extra_info_t* extra_info) +{ + int err = CAMERASRC_ERR_UNKNOWN; + camsrc_info("enter"); + + int nread = 0; + FILE *fp = NULL; + char* store_path = NULL; + + if(dev_id == CAMERASRC_DEV_ID_PRIMARY) + store_path = CAMERASRC_PRIMARY_EXTRA_INFO_PATH; + else if (dev_id == CAMERASRC_DEV_ID_SECONDARY) + store_path = CAMERASRC_SECONDARY_EXTRA_INFO_PATH; + else + { + camsrc_error("Unsupported device ID"); + return CAMERASRC_ERR_DEVICE_NOT_SUPPORT; + } + + fp = fopen(store_path, "rb"); + if(fp) + { + fseek(fp, 0, SEEK_SET); + nread = fread(extra_info, 1, sizeof(camerasrc_extra_info_t), fp); + camsrc_info("Need to be read : %d / Actual read : %d", sizeof(camerasrc_extra_info_t), nread); + fclose(fp); + } + else + return CAMERASRC_ERR_ALLOCATION; + + err = CAMERASRC_SUCCESS; + camsrc_info("leave"); + return err; +} + + +int camerasrc_write_basic_dev_info(camsrc_handle_t handle, camerasrc_caps_info_t* caps_info) +{ + camerasrc_handle_t* p = NULL; + char* store_path = NULL; + FILE *fp = NULL; + + camsrc_info("enter"); + + if(handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + int nwrite = 0; + + if(p->cur_dev_id == CAMERASRC_DEV_ID_PRIMARY) + { + camsrc_info("Primary(Mega) camera capabilities info will be written.."); + store_path = CAMERASRC_PRIMARY_BASIC_INFO_PATH; + } + else if (p->cur_dev_id == CAMERASRC_DEV_ID_SECONDARY) + { + camsrc_info("Secondary(VGA) camera capabilities info will be written.."); + store_path = CAMERASRC_SECONDARY_BASIC_INFO_PATH; + } + else + { + camsrc_error("Unsupported device ID"); + return CAMERASRC_ERR_DEVICE_NOT_SUPPORT; + } + camsrc_info("PATH = %s", store_path); + + fp = fopen(store_path, "wb"); + if(fp) + { + fseek(fp, 0, SEEK_SET); + nwrite = fwrite(caps_info, 1, sizeof(camerasrc_caps_info_t), fp); + camsrc_info("Need to be written : %d / Actual written : %d", sizeof(camerasrc_caps_info_t), nwrite); + fclose(fp); + } + else + return CAMERASRC_ERR_ALLOCATION; + + camsrc_info("leave"); + return CAMERASRC_SUCCESS; +} + + +int camerasrc_write_misc_dev_info(camsrc_handle_t handle, camerasrc_ctrl_list_info_t* ctrl_info) +{ + camerasrc_handle_t* p = NULL; + + camsrc_info("enter"); + + if(handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + int nwrite = 0; + FILE *fp = NULL; + + char* store_path = NULL; + + if(p->cur_dev_id == CAMERASRC_DEV_ID_PRIMARY) + { + camsrc_info("Primary(Mega) camera controls info will be written.."); + store_path = CAMERASRC_PRIMARY_MISC_INFO_PATH; + } + else if (p->cur_dev_id == CAMERASRC_DEV_ID_SECONDARY) + { + camsrc_info("Secondary(VGA) camera controls info will be written.."); + store_path = CAMERASRC_SECONDARY_MISC_INFO_PATH; + } + else + { + camsrc_error("Unsupported device ID"); + return CAMERASRC_ERR_DEVICE_NOT_SUPPORT; + } + + fp = fopen(store_path, "wb"); + if(fp) + { + fseek(fp, 0, SEEK_SET); + nwrite = fwrite(ctrl_info, 1, sizeof(camerasrc_ctrl_list_info_t), fp); + camsrc_info("Need to be written : %d / Actual written : %d", sizeof(camerasrc_ctrl_list_info_t), nwrite); + fclose(fp); + } + else + return CAMERASRC_ERR_ALLOCATION; + + camsrc_info("leave"); + return CAMERASRC_SUCCESS; +} + + +int camerasrc_write_extra_dev_info(camsrc_handle_t handle, camerasrc_extra_info_t* extra_info) +{ + camerasrc_handle_t* p = NULL; + + camsrc_info("enter"); + + if(handle == NULL) { + camsrc_error("handle is null"); + return CAMERASRC_ERR_NULL_POINTER; + } + + p = CAMERASRC_HANDLE(handle); + + int nwrite = 0; + FILE *fp = NULL; + + char* store_path = NULL; + + if(p->cur_dev_id == CAMERASRC_DEV_ID_PRIMARY) + { + camsrc_info("Primary(Mega) extra controls info will be written.."); + store_path = CAMERASRC_PRIMARY_EXTRA_INFO_PATH; + } + else if (p->cur_dev_id == CAMERASRC_DEV_ID_SECONDARY) + { + camsrc_info("Secondary(VGA) extra controls info will be written.."); + store_path = CAMERASRC_SECONDARY_EXTRA_INFO_PATH; + } + else + { + camsrc_error("Unsupported device ID"); + return CAMERASRC_ERR_DEVICE_NOT_SUPPORT; + } + + fp = fopen(store_path, "wb"); + if(fp) + { + fseek(fp, 0, SEEK_SET); + nwrite = fwrite(extra_info, 1, sizeof(camerasrc_extra_info_t), fp); + camsrc_info("Need to be written : %d / Actual written : %d", sizeof(camerasrc_extra_info_t), nwrite); + fclose(fp); + } + else + return CAMERASRC_ERR_ALLOCATION; + + camsrc_info("leave"); + return CAMERASRC_SUCCESS; +} + + +static int _camerasrc_set_shot_meta(camerasrc_handle_t *p, unsigned int grpid, int fcount, + unsigned long long timestamp, struct camera2_shot_ext *shot_ext) +{ + if (p == NULL) { + camsrc_error("NULL handle"); + return CAMERASRC_ERR_NULL_POINTER; + } + memset(shot_ext, 0, sizeof(struct camera2_shot_ext)); + + shot_ext->dis_bypass = 1; + shot_ext->dnr_bypass = 1; + shot_ext->fd_bypass = 1; + + shot_ext->shot.ctl.request.metadataMode = METADATA_MODE_FULL; + shot_ext->shot.ctl.lens.aperture = 1.89999998; + shot_ext->shot.ctl.lens.focalLength = 1.60000002; + shot_ext->shot.ctl.lens.opticalStabilizationMode = OPTICAL_STABILIZATION_MODE_STILL; + shot_ext->shot.ctl.sensor.frameDuration = 33333333; + shot_ext->shot.ctl.flash.flashMode = CAM2_FLASH_MODE_OFF; + shot_ext->shot.ctl.noise.mode = PROCESSING_MODE_OFF; + /* Color */ + shot_ext->shot.ctl.color.mode = COLORCORRECTION_MODE_FAST; + /* FIXME: Not working */ + //shot_ext->shot.ctl.color.transform [0] = 1; + //shot_ext->shot.ctl.color.transform [8] = 1; + shot_ext->shot.ctl.color.hue = 3; + shot_ext->shot.ctl.color.saturation = 3; + shot_ext->shot.ctl.color.brightness = 3; + shot_ext->shot.ctl.color.contrast = 3; + + /* Scaler crop region ?*/ + /* aa */ + shot_ext->shot.ctl.aa.captureIntent = AA_CAPTURE_INTENT_CUSTOM; + shot_ext->shot.ctl.aa.mode = AA_CONTROL_USE_SCENE_MODE; + shot_ext->shot.ctl.aa.sceneMode = AA_SCENE_MODE_LLS; + shot_ext->shot.ctl.aa.aeMode = AA_AEMODE_CENTER; + shot_ext->shot.ctl.aa.aeExpCompensation = 5; + /* FIXME : not working */ + //shot_ext->shot.ctl.aa.aeTargetFpsRange[0] = 8; + //shot_ext->shot.ctl.aa.aeTargetFpsRange[1] = 30; + shot_ext->shot.ctl.aa.aeAntibandingMode = AA_AE_ANTIBANDING_AUTO_50HZ; + shot_ext->shot.ctl.aa.awbMode = AA_AWBMODE_WB_AUTO; + /* FIXME : not working */ + //shot_ext->shot.ctl.aa.afRegions[4] = 1000; + shot_ext->shot.ctl.aa.isoMode = AA_ISOMODE_AUTO; + shot_ext->shot.ctl.aa.awbValue = 4; + + if (grpid == GRP_SENSOR) + goto done; + + if (grpid == GRP_3AA) { + shot_ext->node_group.leader.vid = FIMC_IS_VIDEO_3A1_NUM; + shot_ext->node_group.leader.request = 1; + shot_ext->node_group.leader.input.cropRegion[2] = p->format_3aa1.img_size.width; + shot_ext->node_group.leader.input.cropRegion[3] = p->format_3aa1.img_size.height; + shot_ext->node_group.leader.output.cropRegion[2] = p->format_3aa1.img_size.width; + shot_ext->node_group.leader.output.cropRegion[3] = p->format_3aa1.img_size.height; + + shot_ext->node_group.capture[0].vid = FIMC_IS_VIDEO_3A1P_NUM; + shot_ext->node_group.capture[0].request = 1; + shot_ext->node_group.capture[0].input.cropRegion[2] = p->format_3aa1.img_size.width; + shot_ext->node_group.capture[0].input.cropRegion[3] = p->format_3aa1.img_size.height; + shot_ext->node_group.capture[0].output.cropRegion[2] = p->format_3aa1.img_size.width; + shot_ext->node_group.capture[0].output.cropRegion[3] = p->format_3aa1.img_size.height; + } else if (grpid == GRP_ISP) { + shot_ext->node_group.leader.vid = FIMC_IS_VIDEO_ISP_NUM; + shot_ext->node_group.leader.request = 1; + shot_ext->node_group.leader.input.cropRegion[2] = p->format_isp.img_size.width; + shot_ext->node_group.leader.input.cropRegion[3] = p->format_isp.img_size.height; + shot_ext->node_group.leader.output.cropRegion[2] = p->format_isp.img_size.width; + shot_ext->node_group.leader.output.cropRegion[3] = p->format_isp.img_size.height; + + /* SCC */ + shot_ext->node_group.capture[0].vid = FIMC_IS_VIDEO_SCC_NUM; + shot_ext->node_group.capture[0].request = 1; + shot_ext->node_group.capture[0].input.cropRegion[2] = p->format_scc.img_size.width; + shot_ext->node_group.capture[0].input.cropRegion[3] = p->format_scc.img_size.height; + shot_ext->node_group.capture[0].output.cropRegion[2] = p->format_scp.img_size.width; + shot_ext->node_group.capture[0].output.cropRegion[3] = p->format_scp.img_size.height; + + /* SCP */ + shot_ext->node_group.capture[1].vid = FIMC_IS_VIDEO_SCP_NUM; + shot_ext->node_group.capture[1].request = 1; + shot_ext->node_group.capture[1].input.cropRegion[2] = p->format_scp.img_size.width; + shot_ext->node_group.capture[1].input.cropRegion[3] = p->format_scp.img_size.height; + shot_ext->node_group.capture[1].output.cropRegion[2] = p->format_scp.img_size.width; + shot_ext->node_group.capture[1].output.cropRegion[3] = p->format_scp.img_size.height; + + /* + * This is first set of mysterious data : + * if not set firmware reposrt lack of user-defined + * dynamic meta. + * Fisrt netry needs to be non-zero - if it's not + * errors for SCC/SCP/DIS are being reported + * (no target address) so this needs to be somehow + * related to those (I think). + * Same rule (first item non-zero) applies to vendorspecific2 + */ + shot_ext->shot.udm.internal.vendorSpecific1[0] = (uint32_t)~0U; + shot_ext->shot.udm.internal.vendorSpecific1[1] = 0x000B0C00; + if (fcount >= 0) { + shot_ext->shot.udm.internal.vendorSpecific2[0] = (FIMC_IS_ISP_VS2_INIT + + ((fcount - 1) % FIMC_IS_ISP_VS2_RANGE) * FIMC_IS_ISP_VS2_STEP); + } + + shot_ext->shot.udm.bayer.width = 2560; + shot_ext->shot.udm.bayer.height = 1440; + } + + shot_ext->shot.dm.request.metadataMode = METADATA_MODE_NONE; + if (fcount >= 0) { + shot_ext->shot.dm.request.frameCount = fcount; + } + shot_ext->shot.dm.sensor.timeStamp = timestamp; + + camsrc_debug("GRP: %d FCOUNT: %d", grpid, fcount); + +done: + shot_ext->shot.magicNumber = METADATA_MAGIC_NUMBER; + + return CAMERASRC_SUCCESS; +} + + +/* END For Query functionalities */ diff --git a/camerasrc/src/gstcamerasrc.c b/camerasrc/src/gstcamerasrc.c new file mode 100644 index 0000000..ede5df6 --- /dev/null +++ b/camerasrc/src/gstcamerasrc.c @@ -0,0 +1,3572 @@ +/* + * camerasrc + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jeongmo Yang <jm80.yang@samsung.com> + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gst/gst.h> +#include <gst/gstutils.h> +#include <gst/video/video-info.h> +#include <glib-object.h> +#include <unistd.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +#include <mm_error.h> +#include <mm_types.h> +#include <mm_util_jpeg.h> + +#include "gstcamerasrc.h" +#include "gstcamerasrccontrol.h" +#include "gstcamerasrccolorbalance.h" + + +/****************************************************************************** + * Definitions + *******************************************************************************/ +GST_DEBUG_CATEGORY (camerasrc_debug); +#define GST_CAT_DEFAULT camerasrc_debug + +#ifndef YUV422_SIZE +#define YUV422_SIZE(width,height) ( ((width)*(height)) << 1 ) +#endif + +#ifndef YUV420_SIZE +#define YUV420_SIZE(width,height) ( ((width)*(height)*3) >> 1 ) +#endif + +#define ALIGN_SIZE_I420 (1024<<2) +#define ALIGN_SIZE_NV12 (1024<<6) +#define CAMERASRC_ALIGN(addr,size) (((addr)+((size)-1))&(~((size)-1))) + +#if !defined (CLEAR) + #define CLEAR(x) memset(&(x), 0, sizeof(x)) +#endif + +/* Enables */ +#define _ENABLE_CAMERASRC_DEBUG 0 + +/* Local definitions */ +#define _DEFAULT_WIDTH 320 +#define _DEFAULT_HEIGHT 240 +#define _DEFAULT_FPS 30 +#define _DEFAULT_HIGH_SPEED_FPS 0 +#define _DEFAULT_FPS_AUTO FALSE +#define _DEFAULT_PIX_FORMAT CAMERASRC_PIX_SN12 +#define _DEFAULT_PIX_FORMAT_NAME "SN12" +#define _DEFAULT_CAPTURE_FORMAT_NAME "JPEG" +#define _DEFAULT_COLORSPACE CAMERASRC_COL_RAW +#define _DEFAULT_CAMERA_ID CAMERASRC_DEV_ID_PRIMARY + +/* mmap/pad-alloc related definition */ +#define _DEFAULT_BUFFER_COUNT 6 +#define _DEFAULT_DEQUE_WAITINGTIME 200 /* msec */ + +#define _FD_DEFAULT (-1) +#define _FD_MIN (-1) +#define _FD_MAX (1<<15) /* 2^15 == 32768 */ + +#define _DEFAULT_CAP_JPG_QUALITY 95 +#define _DEFAULT_CAP_WIDTH 640 +#define _DEFAULT_CAP_HEIGHT 480 +#define _DEFAULT_CAP_COUNT 1 +#define _DEFAULT_CAP_INTERVAL 0 +#define _DEFAULT_CAP_PROVIDE_EXIF FALSE +#define _DEFAULT_CAP_TPS_NUMERATOR 1 +#define _DEFAULT_CAP_TPS_DENOMINATOR 30 +#define _DEFAULT_KEEPING_BUFFER 0 +#define _DEFAULT_SCRNL_FOURCC GST_MAKE_FOURCC('N','V','1','2') +#define _MAX_TRIAL_WAIT_FRAME 15 +#define _CONTINUOUS_SHOT_MARGIN 17 /* msec */ +#define _PREVIEW_BUFFER_WAIT_TIMEOUT 2000000 /* usec */ +#define _DEFAULT_RAW_DATA_FOURCC "NV12" + +/*FIXME*/ +#define _THUMBNAIL_WIDTH 320 +#define _THUMBNAIL_HEIGHT 240 +#define _THUMBNAIL_DEFAULT_RATIO 1.34 + +#define SAFE_FREE_GQUEUE(gqueue) \ + if (gqueue) { \ + g_queue_free(gqueue); \ + gqueue = NULL; \ + } + +#define MAKE_FOURCC_FROM_STRING(string) ((guint32)(string[0] | (string[1] << 8) | (string[2] << 16) | (string[3] << 24))) + + +/* Enumerations */ +enum { + /*signal*/ + SIGNAL_STILL_CAPTURE, + + /*SIGNAL_REGISTER_TROUBLE,*/ + LAST_SIGNAL +}; + +enum { + ARG_0, + /* camera */ + ARG_CAMERA_HIGH_SPEED_FPS, + ARG_CAMERA_AUTO_FPS, + ARG_CAMERA_ID, + + /* capture */ + ARG_CAMERA_CAPTURE_FOURCC, + ARG_CAMERA_CAPTURE_WIDTH, + ARG_CAMERA_CAPTURE_HEIGHT, + ARG_CAMERA_CAPTURE_INTERVAL, + ARG_CAMERA_CAPTURE_COUNT, + ARG_CAMERA_CAPTURE_JPG_QUALITY, + ARG_CAMERA_CAPTURE_PROVIDE_EXIF, + + /* etc */ + ARG_VFLIP, + ARG_HFLIP, + ARG_NUM, +}; + +enum { + VIDEO_IN_MODE_UNKNOWN, + VIDEO_IN_MODE_PREVIEW, + VIDEO_IN_MODE_VIDEO, + VIDEO_IN_MODE_CAPTURE, +}; + +/* restart preview command */ +enum { + RESTART_PREVIEW_CMD_NORMAL = 0, + RESTART_PREVIEW_CMD_NUM, +}; + + +static void gst_camerasrc_uri_handler_init (gpointer g_iface, gpointer iface_data); + +static guint gst_camerasrc_signals[LAST_SIGNAL] = { 0 }; + +/* Element template variables */ +static GstStaticPadTemplate src_factory = + GST_STATIC_PAD_TEMPLATE("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS("video/x-raw," + "format = (string) { SN21 }, " + "width = (int) [ 1, 4096 ], " + "height = (int) [ 1, 4096 ]; " + "video/x-raw," + "format = (string) { NV21 }, " + "width = (int) [ 1, 4096 ], " + "height = (int) [ 1, 4096 ]; " + "video/x-raw," + "format = (string) { NV12 }, " + "width = (int) [ 1, 4096 ], " + "height = (int) [ 1, 4096 ]; " + "video/x-raw," + "format = (string) { I420 }, " + "width = (int) [ 1, 4096 ], " + "height = (int) [ 1, 4096 ]; " + "video/x-raw," + "format = (string) { YV12 }, " + "width = (int) [ 1, 4096 ], " + "height = (int) [ 1, 4096 ]; ")); + +/* Local static functions */ +static void gst_camerasrc_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); +static void gst_camerasrc_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); + +static gboolean gst_camerasrc_negotiate(GstBaseSrc *basesrc); +static gboolean gst_camerasrc_src_start(GstBaseSrc *src); +static gboolean gst_camerasrc_src_stop(GstBaseSrc *src); +static gboolean gst_camerasrc_start(GstCameraSrc *camerasrc); + +static GstFlowReturn gst_camerasrc_src_create(GstPushSrc *src, GstBuffer **buffer); +static GstFlowReturn gst_camerasrc_read_capture(GstCameraSrc *camerasrc, GstBuffer **buffer, int command); +static GstFlowReturn gst_camerasrc_read_preview(GstCameraSrc *camerasrc, GstBuffer **buffer); +static GstMemory *gst_camerasrc_get_zero_copy_data(GstCameraSrc *camerasrc, guint32 index, guint32 fourcc); +static void gst_camerasrc_buffer_qbuf(GstCameraSrc *camerasrc, int buffer_index); + +static GstStateChangeReturn gst_camerasrc_change_state(GstElement *element, GstStateChange transition); +static GstCaps *gst_camerasrc_get_caps(GstBaseSrc *src, GstCaps *filter); +static gboolean gst_camerasrc_set_caps(GstBaseSrc *src, GstCaps *caps); +static gboolean gst_camerasrc_get_caps_info(GstCameraSrc *camerasrc, GstCaps *caps, guint *size); +static gboolean gst_camerasrc_fill_ctrl_list(GstCameraSrc *camerasrc); +static gboolean gst_camerasrc_empty_ctrl_list(GstCameraSrc *camerasrc); +static void gst_camerasrc_finalize(GObject *object); + +static gboolean gst_camerasrc_get_timeinfo(GstCameraSrc *camerasrc, GstBuffer *buffer); +static gboolean gst_camerasrc_capture_start(GstCameraSrc *camerasrc); +static gboolean gst_camerasrc_capture_stop(GstCameraSrc *camerasrc); +static gboolean gst_camerasrc_jpeg_capture(GstCameraSrc *camerasrc, gint buffer_index, GstCameraBuffer *buffer); +static gboolean gst_camerasrc_emit_capture_signal(GstCameraSrc *camerasrc, + camerasrc_buffer_t *main, + camerasrc_buffer_t *thumb, + camerasrc_buffer_t *scrnl); +static gpointer _gst_camerasrc_capture_thread_func(gpointer data); + +static GstCameraBuffer *gst_camerasrc_buffer_new(GstCameraSrc *camerasrc); +static void gst_camerasrc_buffer_finalize(GstCameraBuffer *buffer); +static void gst_camerasrc_error_handler(GstCameraSrc *camerasrc, int ret); + +/* Util functions */ +static unsigned long gst_get_current_time(void); +static gboolean _gst_camerasrc_get_frame_size(int fourcc, int width, int height, unsigned int *outsize); +static gboolean _gst_camerasrc_get_raw_pixel_info(int fourcc, int *pix_format, int *colorspace); +static gboolean _gst_camerasrc_get_normal_buffer(GstCameraSrc *camerasrc, camerasrc_buffer_t *base_buffer, int width, int height, + GstMemory **new_buffer, unsigned int new_fourcc); +static void _gst_camerasrc_restart_preview(GstCameraSrc *camerasrc); + +#if _ENABLE_CAMERASRC_DEBUG +static int __util_write_file(char *filename, void *data, int size); +#endif /* _ENABLE_CAMERASRC_DEBUG */ +static void _gst_camerasrc_post_message_int(GstCameraSrc *camerasrc, const char *msg_name, const char *field_name, int value); + +GST_IMPLEMENT_CAMERASRC_COLOR_BALANCE_METHODS(GstCameraSrc, gst_camera_src); +GST_IMPLEMENT_CAMERASRC_CONTROL_METHODS(GstCameraSrc, gst_camera_src); + + +/****************************************************************************** + * Implementations + *******************************************************************************/ +static void gst_camerasrc_error_handler(GstCameraSrc *camerasrc, int ret) +{ + switch (ret) { + case CAMERASRC_SUCCESS: + break; + case CAMERASRC_ERR_IO_CONTROL: + GST_ELEMENT_ERROR(camerasrc, RESOURCE, FAILED, ("IO control error"), GST_ERROR_SYSTEM); + break; + case CAMERASRC_ERR_DEVICE_OPEN: + GST_ELEMENT_ERROR(camerasrc, RESOURCE, OPEN_READ_WRITE, ("camera open failed"), GST_ERROR_SYSTEM); + break; + case CAMERASRC_ERR_DEVICE_BUSY: + GST_ELEMENT_ERROR(camerasrc, RESOURCE, BUSY, ("camera device busy"), GST_ERROR_SYSTEM); + break; + case CAMERASRC_ERR_DEVICE_NOT_FOUND: + GST_ELEMENT_ERROR(camerasrc, RESOURCE, NOT_FOUND, ("camera device not found"), GST_ERROR_SYSTEM); + break; + case CAMERASRC_ERR_DEVICE_UNAVAILABLE: + GST_ELEMENT_ERROR(camerasrc, RESOURCE, OPEN_READ, ("camera device unavailable"), GST_ERROR_SYSTEM); + break; + case CAMERASRC_ERR_DEVICE_WAIT_TIMEOUT: + GST_ELEMENT_ERROR(camerasrc, RESOURCE, TOO_LAZY, (("Timeout[live_buffers=%d]"), camerasrc->num_live_buffers), GST_ERROR_SYSTEM); + break; + case CAMERASRC_ERR_DEVICE_NOT_SUPPORT: + GST_ELEMENT_ERROR(camerasrc, RESOURCE, SETTINGS, ("Not supported"), GST_ERROR_SYSTEM); + break; + case CAMERASRC_ERR_ALLOCATION: + GST_ELEMENT_ERROR(camerasrc, RESOURCE, SETTINGS, ("memory allocation failed"), GST_ERROR_SYSTEM); + break; + case CAMERASRC_ERR_SECURITY_SERVICE: + GST_ELEMENT_ERROR(camerasrc, RESOURCE, FAILED, ("Security service failed"), GST_ERROR_SYSTEM); + break; + default: + GST_ELEMENT_ERROR(camerasrc, RESOURCE, SEEK, (("General video device error[ret=%x]"), ret), GST_ERROR_SYSTEM); + break; + } + + return; +} + + +/* VOID:OBJECT,OBJECT,OBJECT (generated by 'glib-genmarshal') */ +#define g_marshal_value_peek_pointer(v) (v)->data[0].v_pointer +#define g_marshal_value_peek_object(v) (v)->data[0].v_pointer +static void +g_cclosure_user_marshal_VOID__OBJECT_OBJECT_OBJECT (GClosure *closure, + GValue *return_value G_GNUC_UNUSED, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint G_GNUC_UNUSED, + gpointer marshal_data) +{ + typedef void (*GMarshalFunc_VOID__OBJECT_OBJECT_OBJECT) (gpointer data1, + gpointer arg_1, + gpointer arg_2, + gpointer arg_3, + gpointer data2); + register GMarshalFunc_VOID__OBJECT_OBJECT_OBJECT callback; + register GCClosure *cc = (GCClosure*) closure; + register gpointer data1, data2; + + g_return_if_fail (n_param_values == 4); + + if (G_CCLOSURE_SWAP_DATA (closure)) + { + data1 = closure->data; + data2 = g_value_peek_pointer (param_values + 0); + } + else + { + data1 = g_value_peek_pointer (param_values + 0); + data2 = closure->data; + } + callback = (GMarshalFunc_VOID__OBJECT_OBJECT_OBJECT) (marshal_data ? marshal_data : cc->callback); + + callback (data1, + g_marshal_value_peek_object (param_values + 1), + g_marshal_value_peek_object (param_values + 2), + g_marshal_value_peek_object (param_values + 3), + data2); +} + +/* use following BOILERPLATE MACRO as _get_type entry */ +G_DEFINE_TYPE_WITH_CODE(GstCameraSrc, gst_camerasrc, GST_TYPE_PUSH_SRC, + G_IMPLEMENT_INTERFACE(GST_TYPE_URI_HANDLER, gst_camerasrc_uri_handler_init) + G_IMPLEMENT_INTERFACE(GST_TYPE_CAMERA_CONTROL, gst_camera_src_control_interface_init) + G_IMPLEMENT_INTERFACE(GST_TYPE_COLOR_BALANCE, gst_camera_src_color_balance_interface_init)); + +static int gst_camerasrc_af_cb(camsrc_handle_t handle, int state, void *usr_param) +{ + GstCameraSrc *camerasrc = (GstCameraSrc *)usr_param; + + _gst_camerasrc_post_message_int(camerasrc, "camerasrc-AF", "focus-state", state); + + return CAMERASRC_SUCCESS; +} + + +static gboolean gst_camerasrc_create(GstCameraSrc *camerasrc) +{ + int ret = 0; + + /* create capture thread */ + g_mutex_lock(&camerasrc->capture_mutex); + + camerasrc->quit_capture_thread = FALSE; + camerasrc->capture_thread = g_thread_new("capture_thread", (GThreadFunc)_gst_camerasrc_capture_thread_func, (gpointer)camerasrc); + + g_mutex_unlock(&camerasrc->capture_mutex); + + if (camerasrc->capture_thread == NULL) { + GST_ERROR("create capture thread failed"); + ret = CAMERASRC_ERR_INTERNAL; + goto _ERROR; + } + + /*create handle*/ + GST_INFO("camerasrc_create"); + ret = camerasrc_create(&(camerasrc->v4l2_handle)); + if (ret != CAMERASRC_SUCCESS) { + GST_ERROR("camerasrc_create() failed. errcode = 0x%08X", ret); + goto _ERROR; + } + + GST_INFO("camerasrc_create() done"); + + /*CAMERASRC CAM: realize*/ + GST_INFO("camerasrc_realize"); + ret = camerasrc_realize(camerasrc->v4l2_handle, camerasrc->camera_id, CAMERASRC_SENSOR_MODE_CAMERA); + if (ret != CAMERASRC_SUCCESS) { + goto _ERROR; + } + + /*CAMERASRC CAM: start*/ + GST_INFO("camerasrc_start"); + ret = camerasrc_start(camerasrc->v4l2_handle); + if (ret != CAMERASRC_SUCCESS) { + GST_ERROR("camerasrc_start() failed. errcode = 0x%x", ret); + goto _ERROR; + } + + if (!gst_camerasrc_fill_ctrl_list(camerasrc)) { + GST_WARNING("Can't fill v4l2 control list."); + } + + return TRUE; + + _ERROR: + gst_camerasrc_error_handler(camerasrc, ret); + + /* release capture thread */ + if (camerasrc->capture_thread) { + g_mutex_lock(&camerasrc->capture_mutex); + + camerasrc->quit_capture_thread = TRUE; + g_cond_signal(&camerasrc->capture_cond); + + g_mutex_unlock(&camerasrc->capture_mutex); + + g_thread_join(camerasrc->capture_thread); + + camerasrc->capture_thread = NULL; + } + + return FALSE; +} + + +static gboolean gst_camerasrc_destroy(GstCameraSrc *camerasrc) +{ + GST_INFO_OBJECT (camerasrc, "ENTERED"); + + if (camerasrc->v4l2_handle) { + /*Empty control list */ + gst_camerasrc_empty_ctrl_list(camerasrc); + + /*CAMERASRC CAM: stop stream*/ + /*CAMERASRC CAM: unrealize*/ + GST_INFO_OBJECT(camerasrc, "camerasrc_unrealize() calling..."); + camerasrc_unrealize(camerasrc->v4l2_handle); + + /*CAMERASRC CAM: destroy*/ + GST_INFO_OBJECT(camerasrc, "camerasrc_destroy() calling..."); + camerasrc_destroy(camerasrc->v4l2_handle); + camerasrc->v4l2_handle = NULL; + GST_INFO_OBJECT(camerasrc, "AV cam destroyed."); + camerasrc->mode = VIDEO_IN_MODE_UNKNOWN; + } + + /* release capture thread */ + if (camerasrc->capture_thread) { + g_mutex_lock(&camerasrc->capture_mutex); + + camerasrc->quit_capture_thread = TRUE; + g_cond_signal(&camerasrc->capture_cond); + + g_mutex_unlock(&camerasrc->capture_mutex); + + g_thread_join(camerasrc->capture_thread); + + camerasrc->capture_thread = NULL; + } + + GST_INFO_OBJECT(camerasrc, "LEAVED"); + + return TRUE; +} + + +static gboolean gst_camerasrc_fill_ctrl_list(GstCameraSrc *camerasrc) +{ + int n = 0; + camerasrc_ctrl_info_t ctrl_info; + + char *camerasrc_ctrl_label[CAMERASRC_CTRL_NUM] = + { + "brightness", /**< label for CAMERASRC_CTRL_BRIGHTNESS */ + "contrast", /**< label for CAMERASRC_CTRL_CONTRAST */ + "digital zoom", /**< label for CAMERASRC_CTRL_DIGITAL_ZOOM */ + "optical zoom", /**< label for CAMERASRC_CTRL_OPTICAL_ZOOM */ + "white balance", /**< label for CAMERASRC_CTRL_WHITE_BALANCE */ + "color tone", /**< label for CAMERASRC_CTRL_COLOR_TONE */ + "program mode", /**< label for CAMERASRC_CTRL_PROGRAM_MODE */ + "flip", /**< label for CAMERASRC_CTRL_FLIP */ + "anti handshake", /**< label for CAMERASRC_CTRL_ANTI_HANDSHAKE */ + "wide dynamic range", /**< label for CAMERASRC_CTRL_WIDE_DYNAMIC_RANGE */ + "saturation", /**< label for CAMERASRC_CTRL_SATURATION */ + "sharpness", /**< label for CAMERASRC_CTRL_SHARPNESS */ + "iso", /**< label for CAMERASRC_CTRL_ISO */ + "photometry", /**< label for CAMERASRC_CTRL_PHOTOMETRY */ + }; + + g_return_val_if_fail(camerasrc, FALSE); + g_return_val_if_fail(camerasrc->v4l2_handle, FALSE); + + GST_DEBUG_OBJECT(camerasrc, "ENTERED"); + + for (n = CAMERASRC_CTRL_BRIGHTNESS ; n < CAMERASRC_CTRL_NUM ; n++) { + GstCameraSrcColorBalanceChannel *camerasrc_color_channel = NULL; + GstColorBalanceChannel *color_channel = NULL; + + GstCamerasrcControlChannel *camerasrc_control_channel = NULL; + GstCameraControlChannel *control_channel = NULL; + + gint channel_type; + + memset(&ctrl_info, 0x0, sizeof(camerasrc_ctrl_info_t)); + /*TODO: queryctrl */ + + switch (n) { + case CAMERASRC_CTRL_BRIGHTNESS: + case CAMERASRC_CTRL_CONTRAST: + case CAMERASRC_CTRL_WHITE_BALANCE: + case CAMERASRC_CTRL_COLOR_TONE: + case CAMERASRC_CTRL_SATURATION: + case CAMERASRC_CTRL_SHARPNESS: + channel_type = INTERFACE_COLOR_BALANCE; + break; + case CAMERASRC_CTRL_DIGITAL_ZOOM: + case CAMERASRC_CTRL_OPTICAL_ZOOM: + case CAMERASRC_CTRL_PROGRAM_MODE: + case CAMERASRC_CTRL_FLIP: + case CAMERASRC_CTRL_ANTI_HANDSHAKE: + case CAMERASRC_CTRL_WIDE_DYNAMIC_RANGE: + channel_type = INTERFACE_CAMERA_CONTROL; + break; + default: + channel_type = INTERFACE_NONE; + continue; + } + + if (channel_type == INTERFACE_COLOR_BALANCE) { + camerasrc_color_channel = g_object_new(GST_TYPE_CAMERASRC_COLOR_BALANCE_CHANNEL, NULL); + color_channel = GST_COLOR_BALANCE_CHANNEL(camerasrc_color_channel); + + color_channel->label = g_strdup((const gchar *)camerasrc_ctrl_label[n]); + camerasrc_color_channel->id = n; + color_channel->min_value = ctrl_info.min; + color_channel->max_value = ctrl_info.max; + + camerasrc->colors = g_list_append(camerasrc->colors, (gpointer)color_channel); + GST_INFO_OBJECT(camerasrc, "Adding Color Balance Channel %s (%x)", + color_channel->label, camerasrc_color_channel->id); + } else { /* if( channel_type == INTERFACE_CAMERA_CONTROL ) */ + camerasrc_control_channel = g_object_new(GST_TYPE_CAMERASRC_CONTROL_CHANNEL, NULL); + control_channel = GST_CAMERA_CONTROL_CHANNEL(camerasrc_control_channel); + + control_channel->label = g_strdup((const gchar *)camerasrc_ctrl_label[n]); + camerasrc_control_channel->id = n; + control_channel->min_value = ctrl_info.min; + control_channel->max_value = ctrl_info.max; + + camerasrc->camera_controls = g_list_append(camerasrc->camera_controls, (gpointer)control_channel); + GST_INFO_OBJECT(camerasrc, "Adding Camera Control Channel %s (%x)", + control_channel->label, camerasrc_control_channel->id); + } + } + + GST_DEBUG_OBJECT(camerasrc, "LEAVED"); + + return TRUE; +} + + +static gboolean gst_camerasrc_empty_ctrl_list(GstCameraSrc *camerasrc) +{ + g_return_val_if_fail(camerasrc, FALSE); + + GST_DEBUG_OBJECT (camerasrc, "ENTERED"); + + g_list_foreach(camerasrc->colors, (GFunc)g_object_unref, NULL); + g_list_free(camerasrc->colors); + camerasrc->colors = NULL; + + g_list_foreach(camerasrc->camera_controls, (GFunc)g_object_unref, NULL); + g_list_free(camerasrc->camera_controls); + camerasrc->camera_controls = NULL; + + GST_DEBUG_OBJECT(camerasrc, "LEAVED"); + + return TRUE; +} + + +static gboolean gst_camerasrc_start(GstCameraSrc *camerasrc) +{ + int ret = 0; + + camerasrc_format_t fmt; + camerasrc_frac_t frac; + + GST_DEBUG_OBJECT(camerasrc, "ENTERED"); + +#ifdef _SPEED_UP_RAW_CAPTURE + /* check if from no stream change capture */ + if (camerasrc->mode == VIDEO_IN_MODE_CAPTURE && + camerasrc->cap_stream_diff == FALSE) { + GST_INFO("keep current stream for preview"); + goto _READY_DONE; + } + + camerasrc->cap_stream_diff = FALSE; +#endif + + /*CAMERASRC CAM: callback*/ + camerasrc_set_focused_callback(camerasrc->v4l2_handle, gst_camerasrc_af_cb, camerasrc); + + CLEAR(fmt); + CLEAR(frac); + + /*CAMERASRC CAM: format*/ + fmt.pix_format = camerasrc->pix_format; + fmt.colorspace = camerasrc->colorspace; + fmt.rotation = camerasrc->rotate; + fmt.quality = camerasrc->cap_jpg_quality; + + /*CAMERASRC CAM: set resolution - Do not care about rotation */ + /* set original preview size */ + CAMERASRC_SET_SIZE_BY_DIMENSION(fmt, camerasrc->width, camerasrc->height); + + /*CAMERASRC CAM: set capture resolution - this is effective if fourcc is ITLV */ + CAMERASRC_SET_CAPTURE_SIZE_BY_DIMENSION(fmt, camerasrc->cap_width, camerasrc->cap_height); + + /*CAMERASRC CAM: set format*/ + GST_INFO_OBJECT(camerasrc, "pix [%dx%d] fps %d, format %d, colorspace %d, rotation %d", + camerasrc->width, camerasrc->height, camerasrc->fps, + fmt.pix_format, fmt.colorspace, fmt.rotation); + ret = camerasrc_set_format(camerasrc->v4l2_handle, &fmt); + if (ret != CAMERASRC_SUCCESS) { + GST_ERROR_OBJECT (camerasrc, "camerasrc_set_format() failed. errcode = 0x%08X", ret); + goto _ERROR; + } + + /*CAMERASRC CAM: set fps*/ + if (camerasrc->fps_auto) { + /*if fps is zero, auto fps mode*/ + frac.numerator = 0; + frac.denominator = 1; + GST_INFO_OBJECT (camerasrc, "FPS auto(%d)", camerasrc->fps_auto); + } else if (camerasrc->high_speed_fps <= 0) { + if (camerasrc->fps <= 0) { + /*if fps is zero, auto fps mode*/ + frac.numerator = 0; + frac.denominator = 1; + } else { + frac.numerator = 1; + frac.denominator = camerasrc->fps; + } + } else { + GST_INFO_OBJECT(camerasrc, "high speed recording(%d)", camerasrc->high_speed_fps); + frac.numerator = 1; + frac.denominator = camerasrc->high_speed_fps; + } + + ret = camerasrc_set_timeperframe(camerasrc->v4l2_handle, &frac); + if (ret != CAMERASRC_SUCCESS) { + GST_ERROR_OBJECT(camerasrc, "camerasrc_set_timeperframe() failed. errcode = 0x%x", ret); + goto _ERROR; + } + + GST_INFO_OBJECT (camerasrc, "camerasrc_set_timeperframe() done"); + + /*CAMERASRC CAM: Set flip*/ + camerasrc_set_vflip(camerasrc->v4l2_handle, camerasrc->vflip); + camerasrc_set_hflip(camerasrc->v4l2_handle, camerasrc->hflip); + + GST_INFO("VFLIP : %d, HFLIP : %d", camerasrc->vflip, camerasrc->hflip); + + ret = camerasrc_get_num_buffer(camerasrc->v4l2_handle, &(camerasrc->buffer_count)); + if (ret != CAMERASRC_SUCCESS) { + GST_ERROR_OBJECT(camerasrc, "camerasrc_get_num_buffer() failed. errcode = 0x%x", ret); + goto _ERROR; + } + + GST_INFO_OBJECT(camerasrc, "buffer number %d", camerasrc->buffer_count); + + if (!camerasrc_tbm_init(camerasrc->v4l2_handle)) { + GST_ERROR_OBJECT(camerasrc, "camerasrc_tbm_init() failed"); + goto _ERROR; + } + + /* create buffer */ + ret = camerasrc_create_buffer(camerasrc->v4l2_handle); + if (ret != CAMERASRC_SUCCESS) { + GST_ERROR_OBJECT(camerasrc, "camerasrc_create_buffer() failed. errcode = 0x%x", ret); + camerasrc->buffer_running = FALSE; + goto _ERROR; + } + + /*CAMERASRC CAM: start video preview*/ + GST_INFO("camerasrc_start_preview_stream"); + ret = camerasrc_start_preview_stream(camerasrc->v4l2_handle); + if (ret != CAMERASRC_SUCCESS) { + GST_ERROR_OBJECT(camerasrc, "camerasrc_start_preview_stream() failed. errcode = 0x%x", ret); + camerasrc->buffer_running = FALSE; + goto _ERROR; + } + + GST_INFO_OBJECT(camerasrc, "camerasrc_start_preview_stream() done"); + + camerasrc->num_live_buffers = 0; + +_READY_DONE: + camerasrc->mode = VIDEO_IN_MODE_PREVIEW; + camerasrc->current_buffer_data_index = (camerasrc->current_buffer_data_index + 1)%10; + camerasrc->buffer_running = TRUE; + + GST_DEBUG_OBJECT(camerasrc, "LEAVED"); + + return TRUE; + +_ERROR: + gst_camerasrc_error_handler(camerasrc, ret); + + /* Stop stream and release GEM */ + camerasrc_stop_stream(camerasrc->v4l2_handle); + camerasrc_destroy_buffer(camerasrc->v4l2_handle); + + camerasrc_tbm_deinit(camerasrc->v4l2_handle); + + GST_DEBUG_OBJECT(camerasrc, "LEAVED"); + + return FALSE; +} + + +static gboolean gst_camerasrc_stop(GstCameraSrc *camerasrc) +{ + GST_DEBUG_OBJECT (camerasrc, "ENTERED"); + + if (camerasrc->v4l2_handle) { + /* CAMERASRC CAM: stop stream */ + /* To guarantee buffers are valid before finishing */ + GMutex *lock_mutex = NULL; + int keeping_buffer_num = 0; + + lock_mutex = &camerasrc->buffer_lock; + + keeping_buffer_num = _DEFAULT_KEEPING_BUFFER; + + g_mutex_lock(lock_mutex); + + while (camerasrc->num_live_buffers > keeping_buffer_num) { + gint64 end_time; + + GST_INFO_OBJECT(camerasrc, "Wait until all live buffers are relased. (Tot=%d, Live=%d)", + camerasrc->buffer_count, camerasrc->num_live_buffers); + + end_time = g_get_monotonic_time () + _PREVIEW_BUFFER_WAIT_TIMEOUT; + + if (!g_cond_wait_until(&camerasrc->buffer_cond, lock_mutex, end_time)) { + GST_ERROR_OBJECT(camerasrc, "Buffer wait timeout[%d usec].(Live=%d) Skip waiting...", + _PREVIEW_BUFFER_WAIT_TIMEOUT, camerasrc->num_live_buffers); + break; + } else { + GST_INFO_OBJECT(camerasrc, "Signal received."); + } + } + + GST_INFO_OBJECT(camerasrc, "Waiting free buffer finished. (Live=%d)", camerasrc->num_live_buffers); + + g_mutex_unlock(lock_mutex); + + camerasrc_stop_stream(camerasrc->v4l2_handle); + + camerasrc_destroy_buffer(camerasrc->v4l2_handle); + + camerasrc->buffer_running = FALSE; + camerasrc->mode = VIDEO_IN_MODE_UNKNOWN; + } + + GST_DEBUG_OBJECT(camerasrc, "LEAVED"); + + return TRUE; +} + + +static gboolean gst_camerasrc_capture_start(GstCameraSrc *camerasrc) +{ + /*CAMERASRC CAM*/ + int ret = 0; + char *pfourcc = NULL; + camerasrc_format_t fmt; + camerasrc_frac_t frac; + + GST_INFO_OBJECT(camerasrc, "ENTERED"); + + if (camerasrc->mode == VIDEO_IN_MODE_PREVIEW) { + /* To guarantee buffers are valid before finishing. */ + GST_INFO("wait for buffer in gst_camerasrc_capture_start"); + + g_mutex_lock(&camerasrc->buffer_lock); + + while (camerasrc->num_live_buffers > _DEFAULT_KEEPING_BUFFER) { + gint64 end_time; + + GST_INFO_OBJECT(camerasrc, "Wait until all live buffers are relased. (Tot=%d, Live=%d)", + camerasrc->buffer_count, camerasrc->num_live_buffers); + + end_time = g_get_monotonic_time() + _PREVIEW_BUFFER_WAIT_TIMEOUT; + + if (!g_cond_wait_until(&camerasrc->buffer_cond, &camerasrc->buffer_lock, end_time)) { + GST_ERROR_OBJECT(camerasrc, "Buffer wait timeout[%d usec].(Live=%d) Skip waiting...", + _PREVIEW_BUFFER_WAIT_TIMEOUT, camerasrc->num_live_buffers); + break; + } else { + GST_INFO_OBJECT(camerasrc, "Signal received."); + } + } + + GST_INFO_OBJECT(camerasrc, "Waiting free buffer is finished. (Live=%d)", camerasrc->num_live_buffers); + + g_mutex_unlock(&camerasrc->buffer_lock); + +#ifdef _SPEED_UP_RAW_CAPTURE + /* Skip restart stream if format/width/height are all same */ + if (MAKE_FOURCC_FROM_STRING(camerasrc->format_name) == camerasrc->cap_fourcc && + camerasrc->width == camerasrc->cap_width && + camerasrc->height == camerasrc->cap_height) { + GST_INFO_OBJECT(camerasrc, "fourcc, width and height is same. skip restart stream..."); + goto _CAPTURE_READY_DONE; + } + + camerasrc->cap_stream_diff = TRUE; +#endif + + /*CAMERASRC CAM: stop stream*/ + GST_INFO_OBJECT(camerasrc, " camerasrc_stop_stream in gst_camerasrc_capture_start"); + + camerasrc_stop_stream(camerasrc->v4l2_handle); + + camerasrc_destroy_buffer(camerasrc->v4l2_handle); + + GST_INFO_OBJECT (camerasrc, "camerasrc_stop_stream() done"); + camerasrc->buffer_running = FALSE; + + pfourcc = (char*)&camerasrc->cap_fourcc; + GST_INFO_OBJECT(camerasrc, "CAPTURE: Size[%dx%d], fourcc(%c%c%c%c) quality[%d] interval[%d] count[%d]", + camerasrc->cap_width, camerasrc->cap_height, + pfourcc[0], pfourcc[1], pfourcc[2], pfourcc[3], + camerasrc->cap_jpg_quality, camerasrc->cap_interval, camerasrc->cap_count); + + /** + * START STILL CAPTURE + */ + memset(&fmt, 0x00, sizeof (camerasrc_format_t)); + + /*CAMERASRC CAM: set format*/ + CAMERASRC_SET_SIZE_BY_DIMENSION(fmt, camerasrc->cap_width, camerasrc->cap_height); + + /*CAMERASRC CAM: set capture resolution - this is effective if fourcc is ITLV */ + CAMERASRC_SET_CAPTURE_SIZE_BY_DIMENSION(fmt, camerasrc->cap_width, camerasrc->cap_height); + + _gst_camerasrc_get_raw_pixel_info(camerasrc->cap_fourcc, &(fmt.pix_format), &(fmt.colorspace)); + fmt.rotation = 0; + + if (camerasrc->cap_fourcc == GST_MAKE_FOURCC('J', 'P', 'E', 'G')) { + fmt.quality = camerasrc->cap_jpg_quality; + } + + /*CAMERASRC CAM: format*/ + ret = camerasrc_set_format(camerasrc->v4l2_handle, &fmt); + if (ret != CAMERASRC_SUCCESS) { + GST_ERROR_OBJECT(camerasrc, "camerasrc_set_format() failed. errcode = 0x%x", ret); + goto _ERROR; + } + + GST_INFO_OBJECT(camerasrc, "camerasrc_set_format done"); + + /* Set TimePerFrame */ + frac.numerator = _DEFAULT_CAP_TPS_NUMERATOR; + if (camerasrc->cap_width > _DEFAULT_CAP_WIDTH) { + frac.denominator = 10; + } else { + frac.denominator = _DEFAULT_CAP_TPS_DENOMINATOR; + } + + ret = camerasrc_set_timeperframe(camerasrc->v4l2_handle, &frac); + if (ret != CAMERASRC_SUCCESS) { + GST_ERROR_OBJECT(camerasrc, "camerasrc_set_timeperframe() failed. errcode = 0x%x", ret); + goto _ERROR; + } + + GST_INFO_OBJECT(camerasrc, "camerasrc_set_timeperframe done"); + + /*CAMERASRC CAM: start stream*/ + GST_INFO_OBJECT(camerasrc, "camerasrc_start_preview_stream"); + ret = camerasrc_start_preview_stream(camerasrc->v4l2_handle); + if (ret != CAMERASRC_SUCCESS) { + GST_ERROR_OBJECT(camerasrc, "camerasrc_start_still_stream() failed. errcode = 0x%x", ret); + goto _ERROR; + } + + GST_INFO_OBJECT(camerasrc, "camerasrc_start_still_stream done"); + + camerasrc->buffer_running = TRUE; + +_CAPTURE_READY_DONE: + + g_mutex_lock(&camerasrc->jpg_mutex); + camerasrc->cap_next_time = gst_get_current_time(); + g_mutex_unlock(&camerasrc->jpg_mutex); + camerasrc->cap_count_current = 0; + + /* end change to capture mode*/ + camerasrc->mode = VIDEO_IN_MODE_CAPTURE; + + GST_INFO_OBJECT(camerasrc, "CAPTURE STARTED!"); + } else { + GST_WARNING_OBJECT(camerasrc, "Wrong state[%d]!", camerasrc->mode); + } + + GST_DEBUG_OBJECT(camerasrc, "LEAVED"); + + return TRUE; + +_ERROR: + gst_camerasrc_error_handler(camerasrc, ret); + + return FALSE; +} + + +static gboolean gst_camerasrc_capture_stop(GstCameraSrc *camerasrc) +{ + GST_DEBUG_OBJECT(camerasrc, "ENTERED"); + + if (camerasrc->mode == VIDEO_IN_MODE_CAPTURE) { + /* To guarantee buffers are valid before finishing */ + GMutex *lock_mutex = NULL; + int keeping_buffer_num = 0; + + /* keep current stream for preview */ + if (strcmp(camerasrc->format_name, "ITLV") == 0 && + camerasrc->cap_fourcc == GST_MAKE_FOURCC('I','T','L','V')) { + GST_INFO("ITLV capture mode"); + return TRUE; + } + + lock_mutex = &camerasrc->buffer_lock; + + keeping_buffer_num = _DEFAULT_KEEPING_BUFFER; + + g_mutex_lock(lock_mutex); + + while (camerasrc->num_live_buffers > keeping_buffer_num) { + gint64 end_time; + + GST_INFO_OBJECT(camerasrc, "Wait until all live buffers are relased. (Tot=%d, Live=%d)", + camerasrc->buffer_count, camerasrc->num_live_buffers); + + end_time = g_get_monotonic_time () + _PREVIEW_BUFFER_WAIT_TIMEOUT; + + if (!g_cond_wait_until(&camerasrc->buffer_cond, lock_mutex, end_time)) { + GST_ERROR_OBJECT(camerasrc, "Buffer wait timeout[%d usec].(Live=%d) Skip waiting...", + _PREVIEW_BUFFER_WAIT_TIMEOUT, camerasrc->num_live_buffers); + break; + } else { + GST_INFO_OBJECT(camerasrc, "Signal received."); + } + } + + GST_INFO_OBJECT(camerasrc, "Waiting free buffer finished. (Live=%d)", camerasrc->num_live_buffers); + + g_mutex_unlock(lock_mutex); + +#ifdef _SPEED_UP_RAW_CAPTURE + if (camerasrc->cap_stream_diff) { + /*CAMERASRC CAM: stop stream*/ + camerasrc_stop_stream(camerasrc->v4l2_handle); + camerasrc->buffer_running = FALSE; + + GST_INFO_OBJECT(camerasrc, "camerasrc_stop_stream() done"); + } else { + GST_INFO_OBJECT(camerasrc, "no need to stop stream(capture format==preview format)"); + } +#else + /*CAMERASRC CAM: stop stream*/ + camerasrc_stop_stream(camerasrc->v4l2_handle); + camerasrc->buffer_running = FALSE; + + GST_INFO_OBJECT(camerasrc, "camerasrc_stop_stream() done"); +#endif + GST_INFO_OBJECT(camerasrc, "CAPTURE STOPPED!"); + } + + GST_DEBUG_OBJECT (camerasrc, "LEAVED"); + + return TRUE; +} + + +static gpointer _gst_camerasrc_capture_thread_func(gpointer data) +{ + int ret = FALSE; + GstCameraSrc *camerasrc = (GstCameraSrc *)data; + camerasrc_capture_data_info *capture_data = NULL; + + /* buffers for captured data */ + camerasrc_buffer_t main_buf; + camerasrc_buffer_t thumb_buf; + camerasrc_buffer_t scrnl_buf; + + if (camerasrc == NULL) { + GST_ERROR("camerasrc is NULL"); + return NULL; + } + + memset(&main_buf, 0x0, sizeof(camerasrc_buffer_t)); + memset(&thumb_buf, 0x0, sizeof(camerasrc_buffer_t)); + memset(&scrnl_buf, 0x0, sizeof(camerasrc_buffer_t)); + + GST_INFO("start capture thread"); + + while (!camerasrc->quit_capture_thread) { + g_mutex_lock(&camerasrc->capture_mutex); + + if (g_queue_is_empty(camerasrc->capture_buffer_list)) { + GST_INFO("buffer list is empty. wait capture signal..."); + g_cond_wait(&camerasrc->capture_cond, &camerasrc->capture_mutex); + GST_INFO("capture signal received"); + + g_mutex_unlock(&camerasrc->capture_mutex); + continue; + } + + capture_data = (camerasrc_capture_data_info *)g_queue_pop_head(camerasrc->capture_buffer_list); + GST_INFO("pop capture_data %p", capture_data); + + g_mutex_unlock(&camerasrc->capture_mutex); + + if (capture_data == NULL) { + GST_WARNING("capture_data is NULL. skip this..."); + continue; + } + + GST_INFO("gst_camerasrc_emit_capture_signal"); + + ret = gst_camerasrc_emit_capture_signal(camerasrc, &main_buf, &thumb_buf, &scrnl_buf); + + GST_INFO("Zero Shutter Lag Capture Done - QBUF index %d, ret %d", capture_data->buffer_index, ret); + + gst_camerasrc_buffer_qbuf(camerasrc, capture_data->buffer_index); + + /* free allocated memory + - main, thumbnail buffer and capture_data + - screennail buffer is NOT allocated memory */ + if (main_buf.planes[0].start) { + free(main_buf.planes[0].start); + main_buf.planes[0].start = NULL; + main_buf.planes[0].length = 0; + } + if (thumb_buf.planes[0].start) { + free(thumb_buf.planes[0].start); + thumb_buf.planes[0].start = NULL; + thumb_buf.planes[0].length = 0; + } + + free(capture_data); + capture_data = NULL; + } + + GST_INFO("quit while loop and clear buffer list..."); + + /* clear buffer list */ + g_mutex_lock(&camerasrc->capture_mutex); + while (!g_queue_is_empty(camerasrc->capture_buffer_list)) { + capture_data = (camerasrc_capture_data_info *)g_queue_pop_head(camerasrc->capture_buffer_list); + if (capture_data) { + gst_camerasrc_buffer_qbuf(camerasrc, capture_data->buffer_index); + free(capture_data); + capture_data = NULL; + } else { + GST_WARNING("capture_data is NULL"); + } + } + g_mutex_unlock(&camerasrc->capture_mutex); + + GST_INFO("quit capture thread"); + + return NULL; +} + + +static GstFlowReturn gst_camerasrc_read_preview(GstCameraSrc *camerasrc, GstBuffer **buffer) +{ + int ret = 0; + int v4l2_buffer_index = 0; + int i = 0; + GstMemory *mem_data = NULL; /* for virtual address */ + GstMemory *mem_zc_data = NULL; /* for zero copy data */ + GstMemory *mem_camerabuf = NULL; /* for camerasrc buffer */ + camerasrc_buffer_t main_buf; + GstCameraBuffer *vid_buf = NULL; + + /* alloc main buffer */ + vid_buf = gst_camerasrc_buffer_new(camerasrc); + + /* check restart preview command */ + if (!g_queue_is_empty(camerasrc->restart_cmd_list)) { + int restart_cmd = (int)g_queue_pop_head(camerasrc->restart_cmd_list); + + GST_INFO("popped cmd : %d", restart_cmd); + + switch (restart_cmd) { + case RESTART_PREVIEW_CMD_NORMAL: + _gst_camerasrc_restart_preview(camerasrc); + + /* send signal for restart waiting thread */ + g_mutex_lock(&camerasrc->restart_mutex); + g_cond_signal(&camerasrc->restart_cond); + GST_INFO("send restart completed signal"); + g_mutex_unlock(&camerasrc->restart_mutex); + break; + default: + GST_WARNING("unknown cmd %d", restart_cmd); + break; + } + } + + GST_LOG_OBJECT(camerasrc, "start SELECT call"); + + for (i = 0 ; i < _MAX_TRIAL_WAIT_FRAME ; i++) { + /* Wait frame */ + //ret = camerasrc_wait_frame_available(camerasrc->v4l2_handle, _DEFAULT_DEQUE_WAITINGTIME); + ret = CAMERASRC_SUCCESS; + if (ret != CAMERASRC_SUCCESS) { + if (ret == CAMERASRC_ERR_DEVICE_WAIT_TIMEOUT && i < (_MAX_TRIAL_WAIT_FRAME - 1)) { + /* wait until any live buffer is finalized if all buffers are LIVE */ + g_mutex_lock(&camerasrc->buffer_lock); + + GST_WARNING_OBJECT(camerasrc, "SELECT TIMEOUT!!! Retry..(live %d)", camerasrc->num_live_buffers); + + if (camerasrc->buffer_count <= camerasrc->num_live_buffers) { + gint64 end_time; + + GST_INFO("All buffers are LIVE. wait buffer finalize..."); + + end_time = g_get_monotonic_time () + _PREVIEW_BUFFER_WAIT_TIMEOUT; + + if (!g_cond_wait_until(&camerasrc->buffer_cond, &camerasrc->buffer_lock, end_time)) { + GST_ERROR_OBJECT(camerasrc, "Buffer wait timeout[%d usec]. Return ERROR", _PREVIEW_BUFFER_WAIT_TIMEOUT); + return GST_FLOW_ERROR; + } else { + GST_INFO("Signal received. Retry..."); + } + } + + GST_INFO_OBJECT(camerasrc, "buffer wait done. current live %d", camerasrc->num_live_buffers); + + g_mutex_unlock(&camerasrc->buffer_lock); + + /* retry waiting */ + continue; + } + + if (ret == CAMERASRC_ERR_DEVICE_UNAVAILABLE) { + GST_ERROR_OBJECT(camerasrc, "register trouble error!! [%x]", ret); + /*g_signal_emit (G_OBJECT (camerasrc), gst_camerasrc_signals[SIGNAL_REGISTER_TROUBLE], (GQuark)NULL);*/ + gst_camerasrc_error_handler(camerasrc, ret); + + return GST_FLOW_ERROR; + } else if (ret == CAMERASRC_ERR_INVALID_STATE && (i < _MAX_TRIAL_WAIT_FRAME - 1)) { + GST_WARNING_OBJECT(camerasrc, "try again..."); + } else { + GST_ERROR_OBJECT(camerasrc, "Frame waiting error[%x]", ret); + gst_camerasrc_error_handler(camerasrc, ret); + + return GST_FLOW_ERROR; + } + } else { + GST_LOG_OBJECT(camerasrc, "select success, do DQBUF"); + break; + } + } + + /* Buffer DQ */ + GST_DEBUG_OBJECT(camerasrc, "camerasrc_dequeue_buffer"); + ret = camerasrc_dequeue_buffer(camerasrc->v4l2_handle, &v4l2_buffer_index, &main_buf, NULL); + if (ret != CAMERASRC_SUCCESS) { + GST_ERROR_OBJECT(camerasrc, "Dequeue frame error[%x]", ret); + gst_camerasrc_error_handler(camerasrc, ret); + + return GST_FLOW_ERROR; + } + + g_mutex_lock(&camerasrc->buffer_lock); + + camerasrc->num_live_buffers++; + + GST_DEBUG_OBJECT(camerasrc, "after : DQBUF (index %d, live bufs %d)", + v4l2_buffer_index, camerasrc->num_live_buffers); + + g_mutex_unlock(&camerasrc->buffer_lock); + + /* set timestamp and duration */ + gst_camerasrc_get_timeinfo(camerasrc, vid_buf->buffer); + + /* set buffer index */ + vid_buf->v4l2_buffer_index = v4l2_buffer_index; + + if (strcmp(camerasrc->format_name, "SN21") == 0) { + /* for physical address */ + mem_zc_data = gst_camerasrc_get_zero_copy_data(camerasrc, + v4l2_buffer_index, + MAKE_FOURCC_FROM_STRING(camerasrc->format_name)); + if (mem_zc_data == NULL) { + GST_ERROR_OBJECT(camerasrc, "failed to get zero copy data"); + ret = CAMERASRC_ERR_INTERNAL; + goto PREVIEW_ERROR; + } + + /* for virtual address - GST_BUFFER_DATA and SIZE */ + mem_data = gst_memory_new_wrapped(0, + main_buf.planes[0].start, + main_buf.planes[0].length, + 0, + main_buf.planes[0].length, + NULL, + NULL); + } else if (strcmp(camerasrc->format_name, "NV12") == 0 || + strcmp(camerasrc->format_name, "NV21") == 0 || + strcmp(camerasrc->format_name, "I420") == 0 || + strcmp(camerasrc->format_name, "YV12") == 0) { + ret = _gst_camerasrc_get_normal_buffer(camerasrc, &main_buf, camerasrc->width, camerasrc->height, + &mem_data, MAKE_FOURCC_FROM_STRING(camerasrc->format_name)); + if (ret == FALSE) { + GST_ERROR_OBJECT(camerasrc, "_gst_camerasrc_get_normal_buffer failed"); + } + } else { + mem_data = gst_memory_new_wrapped(0, + main_buf.planes[0].start, + main_buf.planes[0].length, + 0, + main_buf.planes[0].length, + NULL, + NULL); + } + + /* set data memory */ + if (mem_data) { + gst_buffer_append_memory(vid_buf->buffer, mem_data); + } else { + if (mem_zc_data) { + gst_memory_unref(mem_zc_data); + mem_zc_data = NULL; + } + + GST_ERROR_OBJECT(camerasrc, "no mem_data"); + ret = CAMERASRC_ERR_INTERNAL; + goto PREVIEW_ERROR; + } + + /* set zero copy memory */ + if (mem_zc_data) { + gst_buffer_append_memory(vid_buf->buffer, mem_zc_data); + } + + mem_camerabuf = gst_memory_new_wrapped(GST_MEMORY_FLAG_NOT_MAPPABLE, + vid_buf, + sizeof(*vid_buf), + 0, + sizeof(*vid_buf), + vid_buf, + (GDestroyNotify)gst_camerasrc_buffer_finalize); + + /* set GstCameraBuffer memory */ + if (mem_camerabuf) { + gst_buffer_append_memory(vid_buf->buffer, mem_camerabuf); + } else { + GST_ERROR_OBJECT(camerasrc, "mem_camerabuf failed"); + ret = CAMERASRC_ERR_INTERNAL; + goto PREVIEW_ERROR; + } + + *buffer = vid_buf->buffer; + + if (camerasrc->firsttime) { + camerasrc->firsttime = FALSE; + } + + /*GST_DEBUG_OBJECT(camerasrc, "refcount: %d", GST_OBJECT_REFCOUNT(*buffer));*/ + + return GST_FLOW_OK; + +PREVIEW_ERROR: + if (vid_buf) { + gst_camerasrc_buffer_finalize(vid_buf); + gst_buffer_unref((GstBuffer *)vid_buf); + vid_buf = NULL; + } + + gst_camerasrc_error_handler(camerasrc, ret); + + return GST_FLOW_ERROR; +} + + +static GstFlowReturn gst_camerasrc_read_capture(GstCameraSrc *camerasrc, GstBuffer **buffer, int command) +{ + int ret; + int buffer_index = 0; + unsigned long cur_time; + gboolean is_jpeg = FALSE; + + static gboolean get_stop_command = FALSE; + static gboolean get_stop_multi_command = FALSE; + + GstCameraBuffer *buf = NULL; /*output buffer for preview*/ + GstMapInfo buf_info = GST_MAP_INFO_INIT; /*Output info */ + GstBuffer *gst_buffer = NULL; + GstMemory *buf_memory = NULL; /*Output memory*/ + GstSample *buf_sample1 = NULL; + GstSample *buf_sample2 = NULL; + GstSample *buf_sample3 = NULL; + GstCaps *sample_caps = NULL; + const gchar *string_fourcc = NULL;; + + camerasrc_buffer_t main_buf; /*original size buffer*/ + camerasrc_buffer_t thumb_buf; /*thumbnail size buffer*/ + camerasrc_buffer_t scrnl_buf; /*screennail size buffer*/ + + GST_DEBUG_OBJECT(camerasrc, "ENTERED. Command[%d]", command); + + GST_INFO_OBJECT(camerasrc, "src size[%dx%d], capture size[%dx%d]", + camerasrc->width, camerasrc->height, + camerasrc->cap_width, camerasrc->cap_height ); + + memset(&main_buf, 0x0, sizeof(camerasrc_buffer_t)); + memset(&thumb_buf, 0x0, sizeof(camerasrc_buffer_t)); + memset(&scrnl_buf, 0x0, sizeof(camerasrc_buffer_t)); + + if (command == GST_CAMERA_CONTROL_CAPTURE_COMMAND_STOP) { + get_stop_command = TRUE; + } else if (command == GST_CAMERA_CONTROL_CAPTURE_COMMAND_STOP_MULTISHOT) { + get_stop_multi_command = TRUE; + } + + /* check whether JPEG capture */ + if (camerasrc->cap_fourcc == GST_MAKE_FOURCC('J','P','E','G')) { + is_jpeg = TRUE; + } else { + is_jpeg = FALSE; + } + + GST_INFO_OBJECT(camerasrc, "cnt current:%d, reverse:%d, stop cmd:%d, multi stop cmd:%d", + camerasrc->cap_count_reverse, camerasrc->cap_count_current, + get_stop_command, get_stop_multi_command); + + while (TRUE) { + if (camerasrc->cap_count_reverse == 0 || + (camerasrc->cap_count_current != 0 && (get_stop_command || get_stop_multi_command))) { + g_mutex_lock(&camerasrc->mutex); + + GST_INFO_OBJECT(camerasrc, "Capture finished."); + + GST_INFO(" capture: gst_camerasrc_capture_stop"); + gst_camerasrc_capture_stop(camerasrc); + + GST_INFO(" capture: gst_camerasrc_start"); + gst_camerasrc_start(camerasrc); + + GST_INFO(" capture: one gst_camerasrc_read_preview"); + ret = gst_camerasrc_read_preview(camerasrc, buffer); + + if (get_stop_command == FALSE) { + if (!g_queue_is_empty(camerasrc->capture_cmd_list)) { + command = (int)g_queue_pop_head(camerasrc->capture_cmd_list); + GST_INFO_OBJECT(camerasrc, "Pop command [%d]", command); + if (command == GST_CAMERA_CONTROL_CAPTURE_COMMAND_STOP) { + get_stop_command = TRUE; + } + } + + if (get_stop_command == FALSE) { + GST_INFO_OBJECT(camerasrc, "Start : Wait for Capture stop signal"); + GST_INFO( " capture: wait for cond after image capture"); + g_cond_wait(&camerasrc->cond, &camerasrc->mutex); + GST_INFO_OBJECT(camerasrc, "End : Wait for Capture stop signal"); + } + } + + get_stop_command = FALSE; + get_stop_multi_command = FALSE; + + g_mutex_unlock(&camerasrc->mutex); + + return ret; + } + + GST_INFO(" camerasrc_read_frame:select,DQ"); + ret = camerasrc_read_frame(camerasrc->v4l2_handle, &main_buf, &thumb_buf, &buffer_index); + + if (ret != CAMERASRC_SUCCESS) { + if (ret == CAMERASRC_ERR_DEVICE_UNAVAILABLE) { + GST_ERROR_OBJECT (camerasrc, "Video src device return register trouble error!! [%x]", ret); + /*g_signal_emit (G_OBJECT (camerasrc), gst_camerasrc_signals[SIGNAL_REGISTER_TROUBLE], (GQuark)NULL);*/ + } else { + GST_ERROR_OBJECT (camerasrc, "camerasrc_read_frame() failed. [ret = 0x%08X]", ret); + GST_ERROR_OBJECT (camerasrc, "return GST_FLOW_ERROR"); + /* should stop capture; */ + } + + *buffer = NULL; + gst_camerasrc_error_handler(camerasrc, ret); + + return GST_FLOW_ERROR; + } + + if (is_jpeg) { + /* get screennail buffer */ + camerasrc_get_screennail_buffer(camerasrc->v4l2_handle, &scrnl_buf); + } else { + + } + + GST_INFO("main(%p,%d), thumb(%p,%d), scrnl(%p,%d)", + main_buf.planes[0].start, main_buf.planes[0].length, + thumb_buf.planes[0].start, thumb_buf.planes[0].length, + scrnl_buf.planes[0].start, scrnl_buf.planes[0].length); + +CHECK_CAPTURE_INTERVAL: + /* get shot time */ + cur_time = gst_get_current_time(); + + if (camerasrc->cap_count_reverse > 0 && camerasrc->cap_next_time <= cur_time) { + GST_INFO_OBJECT(camerasrc, "CHECK: reverse capture count: %d, next time:%lu current time:%lu", + camerasrc->cap_count_reverse, camerasrc->cap_next_time, cur_time); + + camerasrc->cap_next_time = cur_time + camerasrc->cap_interval; + camerasrc->cap_count_reverse--; + camerasrc->cap_count_current++; + + /* make buffers for capture callback and display(raw format) */ + if (is_jpeg) { + /* alloc buffer for capture callback */ + GST_INFO_OBJECT (camerasrc, "JPEG CAPTURE MODE"); + + gst_buffer = gst_buffer_new_wrapped_full(0, main_buf.planes[0].start, + main_buf.planes[0].length, + 0, + main_buf.planes[0].length, + NULL, NULL); + + sample_caps = gst_caps_new_simple("image/jpeg", + "width", G_TYPE_INT, camerasrc->cap_width, + "height", G_TYPE_INT, camerasrc->cap_height, + NULL); + + buf_sample1 = gst_sample_new(buf->buffer, sample_caps, NULL, NULL); + + gst_buffer_unref(gst_buffer); + gst_buffer = NULL; + + gst_caps_unref(sample_caps); + sample_caps = NULL; + + if (thumb_buf.planes[0].start) { + gst_buffer = gst_buffer_new_wrapped_full(0, thumb_buf.planes[0].start, + thumb_buf.planes[0].length, + 0, + thumb_buf.planes[0].length, + NULL, NULL); + + sample_caps = gst_caps_new_simple("image/jpeg", + "width", G_TYPE_INT, _THUMBNAIL_WIDTH, + "height", G_TYPE_INT, _THUMBNAIL_HEIGHT, + NULL); + + buf_sample2 = gst_sample_new(buf->buffer, sample_caps, NULL, NULL); + + gst_buffer_unref(gst_buffer); + gst_buffer = NULL; + + gst_caps_unref(sample_caps); + sample_caps = NULL; + } else { + buf_sample2 = NULL; + } + + if (scrnl_buf.planes[0].start) { + gst_buffer = gst_buffer_new_wrapped_full(0, scrnl_buf.planes[0].start, + scrnl_buf.planes[0].length, + 0, + scrnl_buf.planes[0].length, + NULL, NULL); + + string_fourcc = gst_video_format_to_string(gst_video_format_from_fourcc(_DEFAULT_SCRNL_FOURCC)); + + sample_caps = gst_caps_new_simple("video/x-raw", + "format", G_TYPE_STRING, string_fourcc, + "width", G_TYPE_INT, camerasrc->width, + "height", G_TYPE_INT, camerasrc->height, + NULL); + + buf_sample3 = gst_sample_new(buf->buffer, sample_caps, NULL, NULL); + + gst_buffer_unref(gst_buffer); + gst_buffer = NULL; + + gst_caps_unref(sample_caps); + sample_caps = NULL; + + string_fourcc = NULL; + } else { + buf_sample3 = NULL; + } + } else { + camerasrc_capture_data_info capture_data; + + GST_INFO_OBJECT (camerasrc, "RAW or ITLV CAPTURE MODE"); + + /*alloc main buffer*/ + buf = gst_camerasrc_buffer_new(camerasrc);; + if (buf == NULL) { + GST_ERROR_OBJECT(camerasrc, "Buffer alloc failed."); + *buffer = NULL; + gst_camerasrc_error_handler(camerasrc, CAMERASRC_ERR_ALLOCATION); + return GST_FLOW_ERROR; + } + + memset(&capture_data, 0x0, sizeof(camerasrc_capture_data_info)); + + capture_data.buffer_index = buffer_index; + capture_data.make_thumbnail = FALSE; + capture_data.flash_activated = camerasrc->flash_activated; + + GST_INFO(" read_capture:camerasrc_extract_exif_info_from_capture_data"); + camerasrc_extract_exif_info_from_capture_data(camerasrc->v4l2_handle, &capture_data); + + if (camerasrc->cap_fourcc == GST_MAKE_FOURCC('I','T','L','V')) { + /* for virtual address - GST_BUFFER_DATA and SIZE */ + gst_buffer_append_memory(buf->buffer, gst_memory_new_wrapped(0, + camerasrc->buffer_info[buffer_index].vaddr[2], + camerasrc->buffer_info[buffer_index].bytesused, + 0, + camerasrc->buffer_info[buffer_index].bytesused, + NULL, + NULL)); + + /* emit capture signal */ + GST_INFO(" read_capture:gst_camerasrc_emit_capture_signal"); + ret = gst_camerasrc_emit_capture_signal(camerasrc, &main_buf, &thumb_buf, &scrnl_buf); + + /* free allocated memory + - interleaved data capture mode + - main and thumbnail buffer + - screennail buffer is NOT allocated memory */ + if (main_buf.planes[0].start) { + free(main_buf.planes[0].start); + main_buf.planes[0].start = NULL; + main_buf.planes[0].length = 0; + } + if (thumb_buf.planes[0].start) { + free(thumb_buf.planes[0].start); + thumb_buf.planes[0].start = NULL; + thumb_buf.planes[0].length = 0; + } + } else { + if (camerasrc->cap_fourcc == GST_MAKE_FOURCC('N','V','1','2') || + camerasrc->cap_fourcc == GST_MAKE_FOURCC('S','N','1','2') || + camerasrc->cap_fourcc == GST_MAKE_FOURCC('N','V','2','1') || + camerasrc->cap_fourcc == GST_MAKE_FOURCC('S','N','2','1') || + camerasrc->cap_fourcc == GST_MAKE_FOURCC('S','4','2','0') || + camerasrc->cap_fourcc == GST_MAKE_FOURCC('I','4','2','0') || + camerasrc->cap_fourcc == GST_MAKE_FOURCC('Y','V','1','2')) { + ret = _gst_camerasrc_get_normal_buffer(camerasrc, &main_buf, camerasrc->cap_width, camerasrc->cap_height, + &buf_memory, camerasrc->cap_fourcc); + if (ret == FALSE) { + return GST_FLOW_ERROR; + } + gst_buffer_append_memory(buf->buffer, buf_memory); + buf_memory = NULL; + } else { + buf_memory = gst_memory_new_wrapped(0, + main_buf.planes[0].start, + main_buf.planes[0].length, + 0, + main_buf.planes[0].length, + NULL, + NULL); + gst_buffer_append_memory(buf->buffer, buf_memory); + buf_memory = NULL; + } + + string_fourcc = gst_video_format_to_string(gst_video_format_from_fourcc(camerasrc->cap_fourcc)); + + sample_caps = gst_caps_new_simple("video/x-raw", + "format", G_TYPE_STRING, string_fourcc, + "width", G_TYPE_INT, camerasrc->cap_width, + "height", G_TYPE_INT, camerasrc->cap_height, + NULL); + + /* alloc buffer for capture callback */ + buf_sample1 = gst_sample_new(buf->buffer, sample_caps, NULL, NULL); + buf_sample2 = NULL; + buf_sample3 = NULL; + + gst_caps_unref(sample_caps); + sample_caps = NULL; + + string_fourcc = NULL; + } + + /* get meta data */ + if (camerasrc->cap_fourcc == GST_MAKE_FOURCC('I','T','L','V') || + camerasrc->cap_fourcc == GST_MAKE_FOURCC('S','N','1','2') || + camerasrc->cap_fourcc == GST_MAKE_FOURCC('S','T','1','2') || + camerasrc->cap_fourcc == GST_MAKE_FOURCC('S','4','2','0') || + camerasrc->cap_fourcc == GST_MAKE_FOURCC('S','U','Y','V') || + camerasrc->cap_fourcc == GST_MAKE_FOURCC('S','Y','V','Y')) { + gst_buffer_insert_memory(buf->buffer, 0, gst_camerasrc_get_zero_copy_data(camerasrc, buffer_index, camerasrc->cap_fourcc)); + } + + buf->v4l2_buffer_index = buffer_index; + + *buffer = buf->buffer; + gst_buffer_map(*buffer, &buf_info, GST_MAP_READ); + GST_INFO_OBJECT(camerasrc, "BUF for PREVIEW: addr %p size %d, format %c%c%c%c", + buf_info.data, buf_info.maxsize, + camerasrc->cap_fourcc, camerasrc->cap_fourcc>>8, camerasrc->cap_fourcc>>16, camerasrc->cap_fourcc>>24); + gst_buffer_unmap(*buffer, &buf_info); + } + + if (camerasrc->cap_fourcc != GST_MAKE_FOURCC('I','T','L','V')) { + /*call signal*/ + GST_INFO_OBJECT (camerasrc, "CALL: capture callback"); + g_signal_emit(G_OBJECT (camerasrc), + gst_camerasrc_signals[SIGNAL_STILL_CAPTURE], + 0, + buf_sample1, + buf_sample2, + buf_sample3); + GST_INFO_OBJECT (camerasrc, "RETURN: capture callback"); + } + + GST_INFO("fourcc[preview %c%c%c%c,capture %c%c%c%c], size[preview %dx%d, capture %dx%d]", + camerasrc->format_name[0], camerasrc->format_name[1], camerasrc->format_name[2], camerasrc->format_name[3], + camerasrc->cap_fourcc, camerasrc->cap_fourcc>>8, camerasrc->cap_fourcc>>16, camerasrc->cap_fourcc>>24, + camerasrc->width, camerasrc->height, camerasrc->cap_width, camerasrc->cap_height); + + if ((is_jpeg || camerasrc->cap_count == 1 || + MAKE_FOURCC_FROM_STRING(camerasrc->format_name) != camerasrc->cap_fourcc || + camerasrc->width != camerasrc->cap_width || + camerasrc->height != camerasrc->cap_height) && + camerasrc->cap_fourcc != GST_MAKE_FOURCC('I','T','L','V')) { + /* release allocated buffer */ + if (buf) { + g_mutex_lock(&camerasrc->buffer_lock); + camerasrc->num_live_buffers++; + g_mutex_unlock(&camerasrc->buffer_lock); + gst_buffer_map(buf->buffer, &buf_info, GST_MAP_READ); + if (main_buf.planes[0].start != buf_info.data) { + GST_INFO("release allocated buffer"); + } + gst_buffer_unmap(buf->buffer, &buf_info); + gst_buffer_set_size(buf->buffer, 0); + GST_INFO (" refcount = %d",GST_MINI_OBJECT_REFCOUNT_VALUE(GST_MINI_OBJECT_CAST (buf))); + gst_buffer_unref(buf->buffer); + GST_INFO (" refcount = %d",GST_MINI_OBJECT_REFCOUNT_VALUE(GST_MINI_OBJECT_CAST (buf))); + buf = NULL; + *buffer = NULL; + } + + GST_INFO("skip this buffer"); + + /* Queue buffer */ + camerasrc_queue_buffer(camerasrc->v4l2_handle, buffer_index); + } else { + GST_INFO("send buffer to next element"); + g_mutex_lock(&camerasrc->buffer_lock); + camerasrc->num_live_buffers++; + g_mutex_unlock(&camerasrc->buffer_lock); + /*escape loop for passing buffer to videosink*/ + break; + } + } else { + /* check again */ + if (camerasrc->cap_next_time < cur_time + _CONTINUOUS_SHOT_MARGIN) { + GST_DEBUG_OBJECT(camerasrc, "check again time"); + usleep((camerasrc->cap_next_time - cur_time) * 1000); + goto CHECK_CAPTURE_INTERVAL; + } + + if (is_jpeg == FALSE && + camerasrc->cap_fourcc == GST_MAKE_FOURCC('I','T','L','V')) { + /* free allocated memory + - interleaved data capture mode + - main and thumbnail buffer + - screennail buffer is NOT allocated memory */ + if (main_buf.planes[0].start) { + free(main_buf.planes[0].start); + main_buf.planes[0].start = NULL; + main_buf.planes[0].length = 0; + } + if (thumb_buf.planes[0].start) { + free(thumb_buf.planes[0].start); + thumb_buf.planes[0].start = NULL; + thumb_buf.planes[0].length = 0; + } + } + + /* RAW capture buffer should be reach here */ + camerasrc_queue_buffer(camerasrc->v4l2_handle, buffer_index); + + /* Skip passing this buffer */ + *buffer = NULL; + + GST_INFO("send NULL buffer"); + break; + } + } + + GST_DEBUG_OBJECT (camerasrc, "LEAVED"); + + return GST_FLOW_OK; +} + + +static GstFlowReturn gst_camerasrc_read(GstCameraSrc *camerasrc, GstBuffer **buffer) +{ + int command = GST_CAMERA_CONTROL_CAPTURE_COMMAND_NONE; + GstFlowReturn ret = GST_FLOW_OK; + + g_mutex_lock(&camerasrc->mutex); + + if (!g_queue_is_empty(camerasrc->capture_cmd_list)) { + command = (int)g_queue_pop_head(camerasrc->capture_cmd_list); + GST_INFO_OBJECT(camerasrc, "popped cmd : %d", command); + } + + /* Normal Capture Routine */ + if (command == GST_CAMERA_CONTROL_CAPTURE_COMMAND_START) { + GST_DEBUG_OBJECT(camerasrc, "gst_camerasrc_capture_start"); + gst_camerasrc_capture_start(camerasrc); + } + + g_mutex_unlock(&camerasrc->mutex); + + switch (camerasrc->mode) { + case VIDEO_IN_MODE_PREVIEW: + case VIDEO_IN_MODE_VIDEO: + GST_DEBUG_OBJECT(camerasrc, "gst_camerasrc_read_preview"); + ret = gst_camerasrc_read_preview(camerasrc, buffer); + break; + case VIDEO_IN_MODE_CAPTURE: + GST_DEBUG_OBJECT(camerasrc, "gst_camerasrc_read_capture"); + ret = gst_camerasrc_read_capture(camerasrc, buffer, command); + break; + case VIDEO_IN_MODE_UNKNOWN: + default: + ret = GST_FLOW_ERROR; + GST_ERROR_OBJECT (camerasrc, "can't reach statement.[camerasrc->mode=%d]", camerasrc->mode); + break; + } + + if (!buffer || !(*buffer) || !GST_IS_BUFFER(*buffer)) { + /* To avoid seg fault, make dummy buffer. */ + GST_WARNING_OBJECT (camerasrc, "Make a dummy buffer"); + *buffer = gst_buffer_new(); + } + + return ret; +} + + +static void gst_camerasrc_buffer_qbuf(GstCameraSrc *camerasrc, int buffer_index) +{ + int ret = 0; + + if (camerasrc == NULL) { + GST_ERROR("camerasrc is NULL"); + return; + } + + ret = camerasrc_queue_buffer(camerasrc->v4l2_handle, buffer_index); + if (ret != CAMERASRC_SUCCESS) { + GST_ERROR_OBJECT(camerasrc, "QBUF error, [0x%x]", ret); + } else { + GST_LOG_OBJECT(camerasrc, "QBUF : [idx=%d]", buffer_index); + } + + return; +} + + +static void gst_camerasrc_buffer_finalize(GstCameraBuffer *buffer) +{ + int index = 0; + gboolean ret = FALSE; + unsigned long cur_time = 0; + GstCameraSrc *camerasrc = NULL; + camerasrc_capture_data_info *capture_data = NULL; + gboolean capture_done = FALSE; + + camerasrc = buffer->camerasrc; + index = buffer->v4l2_buffer_index; + + GST_DEBUG_OBJECT(camerasrc, "finalizing buffer %p, index %d [%"GST_TIME_FORMAT " dur %"GST_TIME_FORMAT"]", + buffer, index, + GST_TIME_ARGS(GST_BUFFER_TIMESTAMP(buffer->buffer)), + GST_TIME_ARGS(GST_BUFFER_DURATION(buffer->buffer))); + + /* + * Try zero system lag capture when it meets conditions + */ + cur_time = gst_get_current_time(); + + g_mutex_lock(&camerasrc->jpg_mutex); + + if (camerasrc->cap_fourcc == GST_MAKE_FOURCC('J','P','E','G') && + camerasrc->create_jpeg == TRUE && + (camerasrc->cap_count_reverse > 0 && camerasrc->cap_next_time <= cur_time) ) { + + capture_data = (camerasrc_capture_data_info *)malloc(sizeof(camerasrc_capture_data_info)); + if (capture_data) { + memset(capture_data, 0x0, sizeof(camerasrc_capture_data_info)); + + capture_data->buffer_index = index; + capture_data->make_thumbnail = TRUE; + capture_data->flash_activated = camerasrc->flash_activated; + + GST_INFO_OBJECT(camerasrc, "camerasrc_extract_exif_info_from_capture_data"); + camerasrc_extract_exif_info_from_capture_data(camerasrc->v4l2_handle, capture_data); + + free(capture_data); + capture_data = NULL; + } + + GST_INFO_OBJECT(camerasrc, "gst_camerasrc_jpeg_capture"); + ret = gst_camerasrc_jpeg_capture(camerasrc, index, buffer); + if (ret == FALSE) { + GST_ERROR_OBJECT(camerasrc, "gst_camerasrc_jpeg_capture failed"); + gst_camerasrc_error_handler(camerasrc, CAMERASRC_ERR_INTERNAL); + capture_done = FALSE; + } else { + capture_done = TRUE; + } + + if (capture_done) { + if ((--camerasrc->cap_count_reverse) != 0) { + camerasrc->cap_next_time = cur_time + camerasrc->cap_interval; + } else { + camerasrc->cap_next_time = 0; + camerasrc->create_jpeg = FALSE; + } + + GST_INFO_OBJECT(camerasrc, "count %d", camerasrc->cap_count_current); + } + } + + g_mutex_unlock(&camerasrc->jpg_mutex); + + if (camerasrc->buffer_running) { + /* Buffer Q again */ + gst_camerasrc_buffer_qbuf(camerasrc, index); + } else { + GST_INFO_OBJECT(camerasrc, "It is not running. skip QBUF"); + } + + g_mutex_lock(&camerasrc->buffer_lock); + + camerasrc->num_live_buffers--; + + GST_DEBUG_OBJECT(camerasrc, "QBUF : [idx=%d, lvn=%d]", index, camerasrc->num_live_buffers); + + /* send buffer_cond signal for waiting thread */ + g_cond_signal(&camerasrc->buffer_cond); + + g_mutex_unlock(&camerasrc->buffer_lock); + + gst_object_unref(camerasrc); + + free(buffer); + + return; +} + + +G_DEFINE_BOXED_TYPE(GstCameraBuffer, gst_camerasrc_buffer, NULL, gst_camerasrc_buffer_finalize); + +static GstCameraBuffer *gst_camerasrc_buffer_new(GstCameraSrc *camerasrc) +{ + GstCameraBuffer *ret = NULL; + + ret = (GstCameraBuffer *)malloc(sizeof(*ret)); + ret->buffer = gst_buffer_new(); + + GST_LOG_OBJECT(camerasrc, "creating buffer : %p", ret); + + ret->camerasrc = gst_object_ref(GST_OBJECT(camerasrc)); + + return ret; +} + + +static gboolean _gst_camerasrc_NV21_to_I420(GstCameraSrc *camerasrc, unsigned char *src_Y, unsigned char *src_UV, unsigned char **dest, int width, int height) +{ + int i = 0; + int loop_count = 0; + int length_total = 0; + int length_Y = 0; + int length_UV = 0; + unsigned char *result = NULL; + unsigned char *result_U = NULL; + unsigned char *result_V = NULL; + + if (camerasrc == NULL || src_Y == NULL || src_UV == NULL || dest == NULL) { + GST_ERROR_OBJECT(camerasrc, "NULL pointer %p %p %p %p", camerasrc, src_Y, src_UV, dest); + return FALSE; + } + + length_Y = width * height; + length_UV = length_Y >> 1; + length_total = length_Y + length_UV; + + GST_INFO_OBJECT(camerasrc, "%dx%d, length total %d, Y %d, UV %d", + width, height, length_total, length_Y, length_UV); + + result = (unsigned char *)malloc(length_total); + if (result == NULL) { + GST_ERROR_OBJECT(camerasrc, "NULL pointer %p %p %p", src_Y, src_UV, dest); + return FALSE; + } + + GST_INFO_OBJECT(camerasrc, "src Y memcpy start (size %d)", length_Y); + + memcpy(result, src_Y, length_Y); + + GST_INFO_OBJECT(camerasrc, "src Y memcpy done (size %d)", length_Y); + + result_U = result + length_Y; + result_V = result_U + (length_UV >> 1); + loop_count = length_UV >> 1; + + for (i = 0 ; i < loop_count ; i++) { + result_U[i] = src_UV[(i<<1) + 1]; + result_V[i] = src_UV[i<<1]; + } + + *dest = result; + + GST_INFO_OBJECT(camerasrc, "done : %p", *dest); + + if (0) { + FILE *fp_src = NULL; + FILE *fp_dest = NULL; + + fp_src = fopen("/opt/usr/media/NV21.yuv", "wb"); + if (fp_src) { + fwrite(src_Y, 1, length_Y, fp_src); + fwrite(src_UV, 1, length_UV, fp_src); + fclose(fp_src); + fp_src = NULL; + } + + fp_dest = fopen("/opt/usr/media/I420.yuv", "wb"); + if (fp_dest) { + fwrite(result, 1, length_total, fp_dest); + fclose(fp_dest); + fp_dest = NULL; + } + } + + return TRUE; +} + + +static gboolean gst_camerasrc_jpeg_capture(GstCameraSrc *camerasrc, gint buffer_index, GstCameraBuffer *buffer) +{ + int ret = 0; + unsigned char *buffer_I420 = NULL; + unsigned char *jpeg_result = NULL; + int jpeg_size = 0; + + GstCaps *main_caps = NULL; + GstBuffer *main_buffer = NULL; + GstSample *main_sample = NULL; + + camerasrc_frame_data_t frame_data; + + GST_INFO_OBJECT(camerasrc, "Start to encode image"); + + CLEAR(frame_data); + + frame_data.index = buffer_index; + camerasrc_get_frame_data(camerasrc->v4l2_handle, &frame_data); + + if (!_gst_camerasrc_NV21_to_I420(camerasrc, + frame_data.buffer.planes[0].start, + frame_data.buffer.planes[1].start, + &buffer_I420, + camerasrc->width, + camerasrc->height)) { + GST_ERROR_OBJECT(camerasrc, "failed to convert I420"); + return FALSE; + } + + if (buffer_I420 == NULL) { + GST_ERROR_OBJECT(camerasrc, "buffer_I420 is NULL"); + return FALSE; + } + + ret = mm_util_jpeg_encode_to_memory((void **)&jpeg_result, &jpeg_size, + buffer_I420, camerasrc->width, camerasrc->height, + MM_UTIL_JPEG_FMT_YUV420, camerasrc->cap_jpg_quality); + + /* release converted src buffer */ + free(buffer_I420); + buffer_I420 = NULL; + + if (ret != MM_ERROR_NONE || jpeg_result == NULL) { + GST_ERROR_OBJECT(camerasrc, "jpeg encoding failed %p, 0x%x", jpeg_result, ret); + + if (jpeg_result) { + free(jpeg_result); + jpeg_result = NULL; + } + + return FALSE; + } + + /* create gst buffer with jpeg_result */ + main_buffer = gst_buffer_new_wrapped_full(0, jpeg_result, jpeg_size, 0, jpeg_size, NULL, free); + if (main_buffer == NULL) { + GST_ERROR_OBJECT(camerasrc, "gst_buffer_new_wrapped_full failed"); + + free(jpeg_result); + jpeg_result = NULL; + + return FALSE; + } + + /* create caps info */ + main_caps = gst_caps_new_simple("image/jpeg", + "width", G_TYPE_INT, camerasrc->width, + "height", G_TYPE_INT, camerasrc->height, + NULL); + if (main_caps == NULL) { + GST_ERROR_OBJECT(camerasrc, "gst_caps_new_simple failed"); + + free(jpeg_result); + jpeg_result = NULL; + + gst_buffer_unref(main_buffer); + main_buffer = NULL; + + return FALSE; + } + + /* create sample */ + main_sample = gst_sample_new(main_buffer, main_caps, NULL, NULL); + + /* unref gst buffer and caps because their ref count will be increased in gst_sample_new */ + gst_buffer_unref(main_buffer); + main_buffer = NULL; + + gst_caps_unref(main_caps); + main_caps = NULL; + + if (main_sample == NULL) { + GST_ERROR_OBJECT(camerasrc, "gst_sample_new failed"); + return FALSE; + } + + /* signal emit */ + g_signal_emit(G_OBJECT(camerasrc), + gst_camerasrc_signals[SIGNAL_STILL_CAPTURE], + 0, + main_sample, + NULL, + NULL); + + GST_ERROR_OBJECT(camerasrc, "capture signal emit done"); + + return TRUE; +} + + +static gboolean gst_camerasrc_emit_capture_signal(GstCameraSrc *camerasrc, + camerasrc_buffer_t *main, + camerasrc_buffer_t *thumb, + camerasrc_buffer_t *scrnl) +{ + /* GstBuffers for application */ + GstBuffer *buf_cap_signal_main = NULL; + GstBuffer *buf_cap_signal_thumb = NULL; + GstBuffer *buf_cap_signal_scrnl = NULL; + GstCaps *buf_caps_main = NULL; + GstCaps *buf_caps_thumb = NULL; + GstCaps *buf_caps_scrnl = NULL; + GstSample *buf_sample_main = NULL; + GstSample *buf_sample_thumb = NULL; + GstSample *buf_sample_scrnl = NULL; + + if (camerasrc == NULL) { + GST_ERROR("camerasrc is NULL"); + return FALSE; + } + + if (main == NULL || thumb == NULL || scrnl == NULL) { + GST_ERROR_OBJECT(camerasrc, "[main:%p, thumb:%p, scrnl:%p] something is NULL", main, thumb, scrnl); + return FALSE; + } + + /* make GstBuffers with captured data */ + buf_cap_signal_main = gst_buffer_new_wrapped_full(0, main->planes[0].start, main->planes[0].length, 0, main->planes[0].length, NULL, NULL); + GST_INFO("main %p, %d", main->planes[0].start, main->planes[0].length); + buf_caps_main = gst_caps_new_simple("image/jpeg", + "width", G_TYPE_INT, camerasrc->cap_width, + "height", G_TYPE_INT, camerasrc->cap_height, + NULL); + buf_sample_main = gst_sample_new(buf_cap_signal_main, buf_caps_main, NULL, NULL); + + /* thumbnail */ + if (thumb->planes[0].start) { + buf_cap_signal_thumb = gst_buffer_new_wrapped_full(0, thumb->planes[0].start, thumb->planes[0].length, 0, thumb->planes[0].length, NULL, NULL); + buf_caps_thumb = gst_caps_new_simple("image/jpeg", + "width", G_TYPE_INT, thumb->width, + "height", G_TYPE_INT, thumb->height, + NULL); + buf_sample_thumb = gst_sample_new(buf_cap_signal_thumb, buf_caps_thumb, NULL, NULL); + } else { + buf_cap_signal_thumb = NULL; + } + + /* screennail (postview) */ + if (scrnl->planes[0].start) { + buf_cap_signal_scrnl = gst_buffer_new_wrapped_full(0, scrnl->planes[0].start, scrnl->planes[0].length, 0, scrnl->planes[0].length, NULL, NULL); + buf_caps_scrnl = gst_caps_new_simple("video/x-raw", + "format", G_TYPE_STRING, _DEFAULT_RAW_DATA_FOURCC, + "width", G_TYPE_INT, camerasrc->width, + "height", G_TYPE_INT, camerasrc->height, + NULL); + buf_sample_scrnl = gst_sample_new(buf_cap_signal_scrnl, buf_caps_scrnl, NULL, NULL); + } else { + buf_cap_signal_scrnl = NULL; + } + + /* emit capture signal */ + GST_INFO_OBJECT(camerasrc, "Call Capture SIGNAL"); + + g_signal_emit(G_OBJECT (camerasrc), + gst_camerasrc_signals[SIGNAL_STILL_CAPTURE], + 0, + buf_sample_main, + buf_sample_thumb, + buf_sample_scrnl); + + GST_INFO_OBJECT(camerasrc, "Return Capture SIGNAL"); + + return TRUE; +} + + +static GstMemory *gst_camerasrc_get_zero_copy_data(GstCameraSrc *camerasrc, guint32 index, guint32 fourcc) +{ + GstMemory *meta = NULL; + camerasrc_frame_data_t data; + MMVideoBuffer *mm_buf = NULL; + + /*GST_LOG_OBJECT (camerasrc, "index[%d],pix_format[%x]", index, camerasrc->fourcc);*/ + + mm_buf = (MMVideoBuffer *)malloc(sizeof(MMVideoBuffer)); + if (mm_buf == NULL) { + GST_ERROR_OBJECT(camerasrc, "failed to alloc MMVideoBuffer"); + return NULL; + } + + memset(mm_buf, 0x0, sizeof(MMVideoBuffer)); + + mm_buf->type = MM_VIDEO_BUFFER_TYPE_TBM_BO; + + data.index = index; + camerasrc_get_frame_data(camerasrc->v4l2_handle, &data); + + mm_buf->width[0] = camerasrc->width; + mm_buf->height[0] = camerasrc->height; + mm_buf->size[0] = data.buffer.planes[0].length; + mm_buf->data[0] = data.buffer.planes[0].start; + mm_buf->handle.bo[0] = data.buffer.planes[0].bo; + + if (fourcc == GST_MAKE_FOURCC('S','T','1','2')) { + mm_buf->width[1] = camerasrc->width; + mm_buf->height[1] = camerasrc->height >> 1; + mm_buf->size[1] = data.buffer.planes[1].length; + mm_buf->data[1] = data.buffer.planes[1].start; + mm_buf->handle.bo[1] = data.buffer.planes[1].bo; + + mm_buf->stride_width[0] = GST_ROUND_UP_16(mm_buf->width[0]); + mm_buf->stride_height[0] = GST_ROUND_UP_16(mm_buf->height[0]); + mm_buf->stride_width[1] = GST_ROUND_UP_16(mm_buf->width[1]); + mm_buf->stride_height[1] = GST_ROUND_UP_16(mm_buf->height[1]); + } else { + if (fourcc == GST_MAKE_FOURCC('S','N','1','2') || + fourcc == GST_MAKE_FOURCC('S','N','2','1')) { + mm_buf->width[1] = camerasrc->width; + mm_buf->height[1] = camerasrc->height >> 1; + mm_buf->size[1] = data.buffer.planes[1].length; + mm_buf->data[1] = data.buffer.planes[1].start; + mm_buf->handle.bo[1] = data.buffer.planes[1].bo; + } else { + GST_WARNING_OBJECT (camerasrc, "Unknown pixel format."); + } + + mm_buf->stride_width[0] = mm_buf->width[0]; + mm_buf->stride_height[0] = mm_buf->height[0]; + mm_buf->stride_width[1] = mm_buf->width[1]; + mm_buf->stride_height[1] = mm_buf->height[1]; + mm_buf->stride_width[2] = mm_buf->width[2]; + mm_buf->stride_height[2] = mm_buf->height[2]; + } + + GST_LOG_OBJECT(camerasrc, "index[%d],bo Plane0[%p],Plane1[%p],Plane2[%p]", + index, mm_buf->handle.bo[0], mm_buf->handle.bo[1], mm_buf->handle.bo[2]); + + meta = gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, + mm_buf, + sizeof(MMVideoBuffer), + 0, + sizeof(MMVideoBuffer), + mm_buf, + free); + + return meta; +} + + +static gboolean gst_camerasrc_get_timeinfo(GstCameraSrc *camerasrc, GstBuffer *buffer) +{ + int fps_nu = 0; + int fps_de = 0; + GstClock *clock = NULL; + GstClockTime timestamp = GST_CLOCK_TIME_NONE; + GstClockTime duration = GST_CLOCK_TIME_NONE; + + if (!camerasrc || !buffer) { + GST_WARNING_OBJECT (camerasrc, "Invalid pointer [hadle:%p, buffer:%p]", camerasrc, buffer); + return FALSE; + } + + /* timestamps, LOCK to get clock and base time. */ + clock = GST_ELEMENT_CLOCK(camerasrc); + if (clock) { + /* the time now is the time of the clock minus the base time */ + gst_object_ref(clock); + timestamp = gst_clock_get_time(clock) - GST_ELEMENT(camerasrc)->base_time; + gst_object_unref(clock); + + /* if we have a framerate adjust timestamp for frame latency */ + if (camerasrc->fps_auto) { + /* auto fps mode */ + duration = GST_CLOCK_TIME_NONE; + } else { + if (camerasrc->fps <= 0) { + /*if fps is zero, auto fps mode*/ + fps_nu = 0; + fps_de = 1; + } else { + fps_nu = 1; + fps_de = camerasrc->fps; + } + + if (fps_nu > 0 && fps_de > 0) { + duration = gst_util_uint64_scale_int(GST_SECOND, fps_nu, fps_de); + } + } + + /* set default duration if duration is NONE : 30 fps */ + if (duration == GST_CLOCK_TIME_NONE) { + duration = gst_util_uint64_scale_int(GST_SECOND, 1, 30); + } + } else { + /* no clock, can't set timestamps */ + timestamp = GST_CLOCK_TIME_NONE; + } + + GST_BUFFER_TIMESTAMP(buffer) = timestamp; + GST_BUFFER_DURATION(buffer) = duration; +/* + GST_INFO_OBJECT(camerasrc, "[%"GST_TIME_FORMAT" dur %" GST_TIME_FORMAT "]", + GST_TIME_ARGS(GST_BUFFER_TIMESTAMP(buffer)), + GST_TIME_ARGS(GST_BUFFER_DURATION(buffer))); +*/ + return TRUE; +} + + +/* Gstreamer general functions */ +static gboolean gst_camerasrc_src_start(GstBaseSrc *src) +{ + int ret = TRUE; + GstCameraSrc *camerasrc = GST_CAMERA_SRC (src); + + GST_DEBUG_OBJECT(camerasrc, "ENTERED"); + + camerasrc->firsttime = TRUE; + /* 'gst_camerasrc_set_caps' will call gst_camerasrc_start(). So skip to call it. */ + /*ret = gst_camerasrc_start(camerasrc);*/ + + GST_DEBUG_OBJECT(camerasrc, "LEAVED"); + + return ret; +} + + +static gboolean gst_camerasrc_src_stop(GstBaseSrc *src) +{ + int ret = 0; + GstCameraSrc *camerasrc = GST_CAMERA_SRC(src); + + GST_DEBUG_OBJECT (camerasrc, "ENTERED"); + + ret = gst_camerasrc_stop(camerasrc); + + GST_DEBUG_OBJECT(camerasrc, "LEAVED"); + + return ret; +} + + +static GstFlowReturn gst_camerasrc_src_create(GstPushSrc *src, GstBuffer **buffer) +{ + GstCameraSrc *camerasrc = GST_CAMERA_SRC (src); + GstFlowReturn ret; + + GST_LOG_OBJECT(camerasrc, "ENTERED"); + + ret = gst_camerasrc_read(camerasrc, buffer); + + GST_LOG_OBJECT (camerasrc, "LEAVED"); + + return ret; +} + + +static void gst_camerasrc_set_property(GObject *object, guint prop_id, + const GValue *value, GParamSpec *pspec) +{ + int tmp = 0; + GstCameraSrc *camerasrc = NULL; + + g_return_if_fail(GST_IS_CAMERA_SRC(object)); + camerasrc = GST_CAMERA_SRC(object); + + switch (prop_id) { + case ARG_CAMERA_HIGH_SPEED_FPS: + camerasrc->high_speed_fps = g_value_get_int(value); + GST_INFO_OBJECT(camerasrc, "Set HIGH SPEED FPS: %d", camerasrc->high_speed_fps); + break; + case ARG_CAMERA_AUTO_FPS: + camerasrc->fps_auto = g_value_get_boolean(value); + GST_INFO_OBJECT(camerasrc, "Set AUTO_FPS: %d", camerasrc->fps_auto); + break; + case ARG_CAMERA_ID: + camerasrc->camera_id = g_value_get_int(value); + break; + case ARG_CAMERA_CAPTURE_FOURCC: + camerasrc->cap_fourcc = g_value_get_uint(value); + break; + case ARG_CAMERA_CAPTURE_WIDTH: + camerasrc->cap_width = g_value_get_int(value); + GST_INFO_OBJECT(camerasrc, "Set capture width: %d", camerasrc->cap_width); + break; + case ARG_CAMERA_CAPTURE_HEIGHT: + camerasrc->cap_height = g_value_get_int(value); + GST_INFO_OBJECT(camerasrc, "Set capture height: %d", camerasrc->cap_height); + break; + case ARG_CAMERA_CAPTURE_INTERVAL: + camerasrc->cap_interval = g_value_get_int(value); + GST_INFO_OBJECT(camerasrc, "Set capture interval: %d", camerasrc->cap_interval); + break; + case ARG_CAMERA_CAPTURE_COUNT: + tmp = g_value_get_int(value); + camerasrc->cap_count = tmp; + g_mutex_lock(&camerasrc->jpg_mutex); + camerasrc->cap_count_reverse = tmp; + g_mutex_unlock(&camerasrc->jpg_mutex); + GST_INFO_OBJECT(camerasrc, "Set capture count: %d", camerasrc->cap_count_reverse); + break; + case ARG_CAMERA_CAPTURE_JPG_QUALITY: + { + camerasrc->cap_jpg_quality = g_value_get_int(value); + GST_INFO_OBJECT(camerasrc, "Set jpeg quality : %d", camerasrc->cap_jpg_quality); + break; + } + case ARG_VFLIP: + camerasrc->vflip = g_value_get_boolean(value); + GST_INFO_OBJECT(camerasrc, "Set VFLIP : %d", camerasrc->vflip); + break; + case ARG_HFLIP: + camerasrc->hflip = g_value_get_boolean(value); + GST_INFO_OBJECT(camerasrc, "Set HFLIP : %d", camerasrc->hflip); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } + + return; +} + + +static void gst_camerasrc_get_property(GObject *object, guint prop_id, + GValue *value, GParamSpec *pspec) +{ + GstCameraSrc *camerasrc; + + g_return_if_fail(GST_IS_CAMERA_SRC(object)); + camerasrc = GST_CAMERA_SRC(object); + + switch (prop_id) { + case ARG_CAMERA_HIGH_SPEED_FPS: + g_value_set_int(value, camerasrc->high_speed_fps); + break; + case ARG_CAMERA_AUTO_FPS: + g_value_set_boolean(value, camerasrc->fps_auto); + break; + case ARG_CAMERA_ID: + g_value_set_int(value, camerasrc->camera_id); + break; + case ARG_CAMERA_CAPTURE_FOURCC: + g_value_set_uint(value, camerasrc->cap_fourcc); + break; + case ARG_CAMERA_CAPTURE_WIDTH: + g_value_set_int(value, camerasrc->cap_width); + break; + case ARG_CAMERA_CAPTURE_HEIGHT: + g_value_set_int(value, camerasrc->cap_height); + break; + case ARG_CAMERA_CAPTURE_INTERVAL: + g_value_set_int(value, camerasrc->cap_interval); + break; + case ARG_CAMERA_CAPTURE_COUNT: + g_value_set_int(value, camerasrc->cap_count); + break; + case ARG_CAMERA_CAPTURE_JPG_QUALITY: + g_value_set_int(value, camerasrc->cap_jpg_quality); + GST_INFO("GET jpeg compress ratio : %d", camerasrc->cap_jpg_quality); + break; + case ARG_CAMERA_CAPTURE_PROVIDE_EXIF: + g_value_set_boolean(value, camerasrc->cap_provide_exif); + GST_INFO("Is Exif provided? : %d", camerasrc->cap_provide_exif); + break; + case ARG_VFLIP: + g_value_set_boolean(value, camerasrc->vflip); + break; + case ARG_HFLIP: + g_value_set_boolean(value, camerasrc->hflip); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } + + return; +} + + +static GstStateChangeReturn gst_camerasrc_change_state(GstElement *element, GstStateChange transition) +{ + GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS; + GstCameraSrc *camerasrc; + camerasrc = GST_CAMERA_SRC (element); + + switch (transition) { + case GST_STATE_CHANGE_NULL_TO_READY: + GST_INFO_OBJECT(camerasrc, "GST CAMERA SRC: NULL -> READY"); + GST_INFO(" gst_camerasrc_create"); + if (!gst_camerasrc_create(camerasrc)){ + goto statechange_failed; + } + break; + case GST_STATE_CHANGE_READY_TO_PAUSED: + GST_INFO_OBJECT(camerasrc, "GST CAMERA SRC: READY -> PAUSED"); + ret = GST_STATE_CHANGE_NO_PREROLL; + break; + case GST_STATE_CHANGE_PAUSED_TO_PLAYING: + GST_INFO_OBJECT(camerasrc, "GST CAMERA SRC: PAUSED -> PLAYING"); + break; + default: + break; + } + + ret = GST_ELEMENT_CLASS(gst_camerasrc_parent_class)->change_state(element, transition); + if (ret == GST_STATE_CHANGE_FAILURE){ + return ret; + } + + switch (transition) { + case GST_STATE_CHANGE_PLAYING_TO_PAUSED: + GST_INFO_OBJECT(camerasrc, "GST CAMERA SRC: PLAYING -> PAUSED"); + ret = GST_STATE_CHANGE_NO_PREROLL; + break; + case GST_STATE_CHANGE_PAUSED_TO_READY: + GST_INFO_OBJECT(camerasrc, "GST CAMERA SRC: PAUSED -> READY"); + break; + case GST_STATE_CHANGE_READY_TO_NULL: + GST_INFO_OBJECT(camerasrc, "GST CAMERA SRC: READY -> NULL"); + GST_INFO(" gst_camerasrc_destroy"); + if (!gst_camerasrc_destroy(camerasrc)){ + goto statechange_failed; + } + break; + default: + break; + } + + return ret; + + statechange_failed: + /* subclass must post a meaningfull error message */ + GST_ERROR_OBJECT(camerasrc, "state change failed"); + + return GST_STATE_CHANGE_FAILURE; +} + + +static void gst_camerasrc_finalize(GObject *object) +{ + GstCameraSrc *camerasrc = GST_CAMERA_SRC(object); + + GST_INFO("ENTERED"); + + g_cond_clear(&camerasrc->cond); + g_cond_clear(&camerasrc->buffer_cond); + g_cond_clear(&camerasrc->capture_cond); + g_cond_clear(&camerasrc->restart_cond); + g_mutex_clear(&camerasrc->jpg_mutex); + g_mutex_clear(&camerasrc->mutex); + g_mutex_clear(&camerasrc->buffer_lock); + g_mutex_clear(&camerasrc->capture_mutex); + g_mutex_clear(&camerasrc->restart_mutex); + SAFE_FREE_GQUEUE(camerasrc->capture_cmd_list); + SAFE_FREE_GQUEUE(camerasrc->capture_buffer_list); + SAFE_FREE_GQUEUE(camerasrc->restart_cmd_list); + + if (G_OBJECT_CLASS (gst_camerasrc_parent_class)->finalize) + G_OBJECT_CLASS(gst_camerasrc_parent_class)->finalize(object); + + GST_INFO("LEAVED"); + + return; +} + + +void gst_camerasrc_set_capture_command(GstCameraSrc *camerasrc, GstCameraControlCaptureCommand cmd) +{ + gboolean is_zsl = FALSE; + + if (camerasrc == NULL) { + GST_ERROR_OBJECT(camerasrc, "camerasrc is NULL"); + return; + } + + GST_INFO_OBJECT(camerasrc, "ENTERED"); + + g_mutex_lock(&camerasrc->mutex); + + /* Check condition of zero shutter lag routine */ + if (camerasrc->cap_fourcc == GST_MAKE_FOURCC('J','P','E','G')) { + /* Set zero shutter lag mode */ + is_zsl = TRUE; + + if (is_zsl) { + GST_INFO_OBJECT(camerasrc, "Set ZSL mode"); + + g_mutex_lock(&camerasrc->jpg_mutex); + + if (cmd == GST_CAMERA_CONTROL_CAPTURE_COMMAND_START) { + /* capture start */ + camerasrc->create_jpeg = TRUE; + camerasrc->cap_count_current = 0; + camerasrc->cap_next_time = gst_get_current_time(); + } else { + /* capture stop */ + camerasrc->create_jpeg = FALSE; + camerasrc->cap_count_reverse = 0; + camerasrc->cap_next_time = 0; + } + + g_mutex_unlock(&camerasrc->jpg_mutex); + } + } + + /* Do not push command when ZSL mode */ + if (!is_zsl) { + g_queue_push_tail(camerasrc->capture_cmd_list, (gpointer)cmd); + GST_INFO_OBJECT(camerasrc, "ACTION: Push capture command [%d] finished.", cmd); + } + + if (cmd == GST_CAMERA_CONTROL_CAPTURE_COMMAND_STOP) { + g_cond_signal(&camerasrc->cond); + GST_INFO_OBJECT(camerasrc, "Send signal for CAPTURE STOP"); + } + + g_mutex_unlock(&camerasrc->mutex); + + return; +} + + +static gboolean +gst_camerasrc_negotiate (GstBaseSrc * basesrc) +{ + GstCaps *thiscaps; + GstCaps *caps = NULL; + GstCaps *peercaps = NULL; + gboolean result = FALSE; + GstStructure *s; + GstCameraSrc *camerasrc = GST_CAMERA_SRC(basesrc); + + GST_INFO_OBJECT(camerasrc, "ENTERED"); + /* first see what is possible on our source pad */ + thiscaps = gst_pad_query_caps (GST_BASE_SRC_PAD (basesrc), NULL); + GST_DEBUG_OBJECT (basesrc, "caps of src: %" GST_PTR_FORMAT, thiscaps); + + /* nothing or anything is allowed, we're done */ + if (thiscaps == NULL || gst_caps_is_any (thiscaps)) + goto no_nego_needed; + + /* get the peer caps */ + peercaps = gst_pad_peer_query_caps (GST_BASE_SRC_PAD (basesrc), NULL); + GST_DEBUG_OBJECT (basesrc, "caps of peer: %" GST_PTR_FORMAT, peercaps); + //LOG_CAPS (basesrc, peercaps); + if (peercaps && !gst_caps_is_any (peercaps)) { + GstCaps *icaps = NULL; + int i; + + /* Prefer the first caps we are compatible with that the peer proposed */ + for (i = 0; i < gst_caps_get_size (peercaps); i++) { + /* get intersection */ + GstCaps *ipcaps = gst_caps_copy_nth (peercaps, i); + + GST_DEBUG_OBJECT (basesrc, "peer: %" GST_PTR_FORMAT, ipcaps); + icaps = gst_caps_intersect (thiscaps, ipcaps); + gst_caps_unref (ipcaps); + + /*s = gst_caps_get_structure (icaps, 0); + gst_structure_get_fourcc(s, "format", &camerasrc->fourcc); + if ((camerasrc->fourcc == GST_MAKE_FOURCC('S','N','1','2')) || + (camerasrc->fourcc == GST_MAKE_FOURCC('S','T','1','2'))) { + break; + }*/ + if (!gst_caps_is_empty (icaps)) + break; + + gst_caps_unref (icaps); + icaps = NULL; + } + + GST_DEBUG_OBJECT (basesrc, "intersect: %" GST_PTR_FORMAT, icaps); + if (icaps) { + /* If there are multiple intersections pick the one with the smallest + * resolution strictly bigger then the first peer caps */ + if (gst_caps_get_size (icaps) > 1) { + s = gst_caps_get_structure (peercaps, 0); + int best = 0; + int twidth, theight; + int width = G_MAXINT, height = G_MAXINT; + + if (gst_structure_get_int (s, "width", &twidth) + && gst_structure_get_int (s, "height", &theight)) { + + /* Walk the structure backwards to get the first entry of the + * smallest resolution bigger (or equal to) the preferred resolution) + */ + for (i = gst_caps_get_size (icaps) - 1; i >= 0; i--) { + GstStructure *is = gst_caps_get_structure (icaps, i); + int w, h; + + if (gst_structure_get_int (is, "width", &w) + && gst_structure_get_int (is, "height", &h)) { + if (w >= twidth && w <= width && h >= theight && h <= height) { + width = w; + height = h; + best = i; + } + } + } + } + + caps = gst_caps_copy_nth (icaps, best); + gst_caps_unref (icaps); + } else { + caps = icaps; + } + } + gst_caps_unref (thiscaps); + gst_caps_unref (peercaps); + } else { + /* no peer or peer have ANY caps, work with our own caps then */ + caps = thiscaps; + } + if (caps) { + caps = gst_caps_fixate(caps); + + /* now fixate */ + if (!gst_caps_is_empty (caps)) { + GST_DEBUG_OBJECT (basesrc, "fixated to: %" GST_PTR_FORMAT, caps); + + if (gst_caps_is_any (caps)) { + /* hmm, still anything, so element can do anything and + * nego is not needed */ + result = TRUE; + } else if (gst_caps_is_fixed (caps)) { + /* yay, fixed caps, use those then */ + result = gst_camerasrc_set_caps(basesrc, caps); + } + } + gst_caps_unref (caps); + } + return result; + +no_nego_needed: + { + GST_DEBUG_OBJECT (basesrc, "no negotiation needed"); + if (thiscaps) + gst_caps_unref (thiscaps); + return TRUE; + } +} + + +static GstCaps *gst_camerasrc_get_caps(GstBaseSrc *src, GstCaps *filter) +{ + GstCameraSrc *camerasrc = GST_CAMERA_SRC(src); + GstCaps *ret = NULL; + + GST_DEBUG_OBJECT(camerasrc, "ENTERED"); + + if (camerasrc->mode == VIDEO_IN_MODE_UNKNOWN) { + GST_INFO_OBJECT(camerasrc, "Unknown mode. Just return template caps."); + GST_DEBUG_OBJECT(camerasrc, "LEAVED"); + + ret = gst_pad_get_pad_template_caps(GST_BASE_SRC_PAD(camerasrc)); + return filter ? gst_caps_intersect(ret, filter) : gst_caps_copy(ret); + } + + /*FIXME: Using "VIDIOC_ENUM_FMT".*/ + ret = gst_caps_copy(gst_pad_get_pad_template_caps(GST_BASE_SRC_PAD(camerasrc))); + + if (filter != NULL) { + gst_caps_take(&ret, gst_caps_intersect(ret, filter)); + } + + GST_INFO_OBJECT(camerasrc, "probed caps: %p", ret); + GST_DEBUG_OBJECT(camerasrc, "LEAVED"); + + return ret; +} + + +static gboolean _gst_camerasrc_get_raw_pixel_info(int fourcc, int *pix_format, int *colorspace) +{ + switch (fourcc) { + case GST_MAKE_FOURCC('I','4','2','0'): /* V4L2_PIX_FMT_YUV420 */ + case GST_MAKE_FOURCC('S','4','2','0'): + *pix_format = CAMERASRC_PIX_YUV420P; + *colorspace = CAMERASRC_COL_RAW; + break; + case GST_MAKE_FOURCC('Y','V','1','2'): + *pix_format = CAMERASRC_PIX_YV12; + *colorspace = CAMERASRC_COL_RAW; + break; + case GST_MAKE_FOURCC('Y','U','Y','V'): /* V4L2_PIX_FMT_YUYV */ + case GST_MAKE_FOURCC('Y','U','Y','2'): /* V4L2_PIX_FMT_YUYV */ + case GST_MAKE_FOURCC('S','U','Y','V'): + case GST_MAKE_FOURCC('S','U','Y','2'): + *pix_format = CAMERASRC_PIX_YUY2; + *colorspace = CAMERASRC_COL_RAW; + break; + case GST_MAKE_FOURCC('U','Y','V','Y'): /* V4L2_PIX_FMT_UYVY */ + case GST_MAKE_FOURCC('S','Y','V','Y'): /* V4L2_PIX_FMT_UYVY */ + *pix_format = CAMERASRC_PIX_UYVY; + *colorspace = CAMERASRC_COL_RAW; + break; + case GST_MAKE_FOURCC('4','2','2','P'): /* V4L2_PIX_FMT_YUV422P */ + case GST_MAKE_FOURCC('Y','4','2','B'): /* V4L2_PIX_FMT_YUV422P */ + *pix_format = CAMERASRC_PIX_YUV422P; + *colorspace = CAMERASRC_COL_RAW; + break; + case GST_MAKE_FOURCC('N','V','1','2'): /* V4L2_PIX_FMT_NV12 */ + *pix_format = CAMERASRC_PIX_NV12; + *colorspace = CAMERASRC_COL_RAW; + break; + case GST_MAKE_FOURCC('S','N','1','2'): /* V4L2_PIX_FMT_NV12 non-linear */ + *pix_format = CAMERASRC_PIX_SN12; + *colorspace = CAMERASRC_COL_RAW; + break; + case GST_MAKE_FOURCC('J','P','E','G'): + case GST_MAKE_FOURCC('j','p','e','g'): + *pix_format = CAMERASRC_PIX_RGGB8; + *colorspace = CAMERASRC_COL_JPEG; + break; + case GST_MAKE_FOURCC('S','N','2','1'): + *pix_format = CAMERASRC_PIX_SN21; + *colorspace = CAMERASRC_COL_RAW; + break; + case GST_MAKE_FOURCC('N','V','2','1'): + *pix_format = CAMERASRC_PIX_NV21; + *colorspace = CAMERASRC_COL_RAW; + break; + case GST_MAKE_FOURCC('Y','4','1','P'): /* V4L2_PIX_FMT_Y41P */ + case GST_MAKE_FOURCC('Y','4','1','B'): /* V4L2_PIX_FMT_YUV411P */ + default: + /* ERROR */ + *pix_format = CAMERASRC_PIX_NONE; + *colorspace = CAMERASRC_COL_NONE; + break; + } + + return TRUE; +} + + +static gboolean _gst_camerasrc_get_frame_size(int fourcc, int width, int height, unsigned int *outsize) +{ + switch (fourcc) { + case GST_MAKE_FOURCC('I','4','2','0'): /* V4L2_PIX_FMT_YUV420 */ + case GST_MAKE_FOURCC('I','Y','U','V'): + case GST_MAKE_FOURCC('Y','U','1','2'): + case GST_MAKE_FOURCC('Y','V','1','2'): + case GST_MAKE_FOURCC('S','4','2','0'): /* V4L2_PIX_FMT_NV12 tiled non-linear */ + *outsize = GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height); + *outsize += 2 * ((GST_ROUND_UP_8 (width) / 2) * (GST_ROUND_UP_2 (height) / 2)); + break; + case GST_MAKE_FOURCC('Y','U','Y','V'): /* V4L2_PIX_FMT_YUYV */ + case GST_MAKE_FOURCC('Y','U','Y','2'): /* V4L2_PIX_FMT_YUYV */ + case GST_MAKE_FOURCC('S','U','Y','V'): + case GST_MAKE_FOURCC('S','U','Y','2'): + case GST_MAKE_FOURCC('U','Y','V','Y'): /* V4L2_PIX_FMT_UYVY */ + case GST_MAKE_FOURCC('S','Y','V','Y'): /* V4L2_PIX_FMT_UYVY */ + case GST_MAKE_FOURCC('4','2','2','P'): /* V4L2_PIX_FMT_YUV422P */ + case GST_MAKE_FOURCC('Y','4','2','B'): /* V4L2_PIX_FMT_YUV422P */ + case GST_MAKE_FOURCC('Y','4','1','P'): /* V4L2_PIX_FMT_Y41P */ + *outsize = (GST_ROUND_UP_2 (width) * 2) * height; + break; + case GST_MAKE_FOURCC('Y','4','1','B'): /* V4L2_PIX_FMT_YUV411P */ + *outsize = GST_ROUND_UP_4 (width) * height; + *outsize += 2 * ((GST_ROUND_UP_8 (width) / 4) * height); + break; + case GST_MAKE_FOURCC('N','V','1','2'): /* V4L2_PIX_FMT_NV12 */ + case GST_MAKE_FOURCC('N','V','2','1'): /* V4L2_PIX_FMT_NV21 */ + case GST_MAKE_FOURCC('S','N','1','2'): /* V4L2_PIX_FMT_NV12 non-linear */ + case GST_MAKE_FOURCC('S','N','2','1'): /* V4L2_PIX_FMT_NV21 non-linear */ + *outsize = GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height); + *outsize += (GST_ROUND_UP_4 (width) * height) / 2; + break; + case GST_MAKE_FOURCC('J','P','E','G'): + case GST_MAKE_FOURCC('j','p','e','g'): + /* jpeg size can't be calculated here. */ + *outsize = 0; + break; + default: + /* unkown format!! */ + *outsize = 0; + break; + } + + return TRUE; +} + +static gboolean _gst_camerasrc_get_normal_buffer(GstCameraSrc *camerasrc, camerasrc_buffer_t *base_buffer, int width, int height, + GstMemory **new_buffer, unsigned int new_fourcc) +{ + int i = 0; + unsigned int length_buffer = 0; + unsigned int length_new_buffer = 0; + unsigned int length_Y = 0; + unsigned int length_CbCr = 0; + unsigned char *data_new = NULL; + unsigned char *data_new_Cb = NULL; + unsigned char *data_new_Cr = NULL; + + if (camerasrc == NULL || base_buffer == NULL || new_buffer == NULL) { + GST_WARNING_OBJECT(camerasrc, "something is NULL(%p,%p,%p)", + camerasrc, base_buffer, new_buffer); + return FALSE; + } + + length_buffer = base_buffer->planes[0].length + base_buffer->planes[1].length; + + switch (new_fourcc) { + case GST_MAKE_FOURCC('Y','V','1','2'): + length_Y = width * height; + length_CbCr = length_Y >> 1; + + data_new = (unsigned char *)malloc(length_buffer); + if (data_new == NULL) { + GST_ERROR_OBJECT(camerasrc, "New buffer data ALLOC FAILED"); + gst_camerasrc_error_handler(camerasrc, CAMERASRC_ERR_ALLOCATION); + return FALSE; + } + + memcpy(data_new, base_buffer->planes[0].start, length_Y); + + data_new_Cr = data_new + length_Y; + data_new_Cb = data_new_Cr + (length_CbCr >> 1); + + for (i = 0 ; i < length_CbCr ; i += 2) { + data_new_Cr[i>>1] = base_buffer->planes[1].start[i+1]; + data_new_Cb[i>>1] = base_buffer->planes[1].start[i]; + } + + length_new_buffer = length_Y + length_CbCr; + + *new_buffer = gst_memory_new_wrapped(0, + data_new, + length_new_buffer, + 0, + length_new_buffer, + data_new, + free); + + GST_DEBUG_OBJECT(camerasrc, "[%c%c%c%c] Total length(%u), Y(%u), Cr(%u), Cb(%u)", + new_fourcc, new_fourcc>>8, new_fourcc>>16, new_fourcc>>24, + length_new_buffer, length_Y, (length_CbCr>>1), (length_CbCr>>1)); + break; + case GST_MAKE_FOURCC('I','4','2','0'): + length_Y = width * height; + length_CbCr = length_Y >> 1; + + data_new = (unsigned char *)malloc(length_buffer); + if (data_new == NULL) { + GST_ERROR_OBJECT(camerasrc, "New buffer data ALLOC FAILED"); + gst_camerasrc_error_handler(camerasrc, CAMERASRC_ERR_ALLOCATION); + return FALSE; + } + + memcpy(data_new, base_buffer->planes[0].start, length_Y); + + data_new_Cb = data_new + length_Y; + data_new_Cr = data_new_Cb + (length_CbCr>>1); + + for (i = 0 ; i < length_CbCr ; i += 2) { + data_new_Cb[i>>1] = base_buffer->planes[1].start[i+1]; + data_new_Cr[i>>1] = base_buffer->planes[1].start[i]; + } + + length_new_buffer = length_Y + length_CbCr; + + *new_buffer = gst_memory_new_wrapped(0, + data_new, + length_new_buffer, + 0, + length_new_buffer, + data_new, + free); + + GST_DEBUG_OBJECT(camerasrc, "[%c%c%c%c] Total length(%u), Y(%u), Cb(%u), Cr(%u)", + new_fourcc, new_fourcc>>8, new_fourcc>>16, new_fourcc>>24, + length_new_buffer, length_Y, (length_CbCr>>1), (length_CbCr>>1)); + break; + case GST_MAKE_FOURCC('N','V','1','2'): + length_Y = width * height; + length_CbCr = length_Y >> 1; + + data_new = (unsigned char *)malloc(length_buffer); + if (data_new == NULL) { + GST_ERROR_OBJECT(camerasrc, "New buffer data ALLOC FAILED"); + gst_camerasrc_error_handler(camerasrc, CAMERASRC_ERR_ALLOCATION); + return FALSE; + } + + memcpy(data_new, base_buffer->planes[0].start, length_Y); + + data_new_Cb = data_new + length_Y; + + for (i = 0 ; i < length_CbCr ; i += 2) { + data_new_Cb[i] = base_buffer->planes[1].start[i+1]; + data_new_Cb[i+1] = base_buffer->planes[1].start[i]; + } + + length_new_buffer = length_Y + length_CbCr; + + *new_buffer = gst_memory_new_wrapped(0, + data_new, + length_new_buffer, + 0, + length_new_buffer, + data_new, + free); + + GST_DEBUG_OBJECT(camerasrc, "[%c%c%c%c] Total length(%u), Y(%u), CbCr(%u)", + new_fourcc, new_fourcc>>8, new_fourcc>>16, new_fourcc>>24, + length_new_buffer, length_Y, length_CbCr); + break; + case GST_MAKE_FOURCC('N','V','2','1'): + length_Y = width * height; + length_CbCr = length_Y >> 1; + + data_new = (unsigned char *)malloc(length_buffer); + if (data_new == NULL) { + GST_ERROR_OBJECT(camerasrc, "New buffer data ALLOC FAILED"); + gst_camerasrc_error_handler(camerasrc, CAMERASRC_ERR_ALLOCATION); + return FALSE; + } + + memcpy(data_new, base_buffer->planes[0].start, length_Y); + memcpy(data_new + length_Y, base_buffer->planes[1].start, length_CbCr); + + length_new_buffer = length_Y + length_CbCr; + + *new_buffer = gst_memory_new_wrapped(0, + data_new, + length_new_buffer, + 0, + length_new_buffer, + data_new, + free); + + GST_DEBUG_OBJECT(camerasrc, "[%c%c%c%c] Total length(%u), Y(%u), CbCr(%u)", + new_fourcc, new_fourcc>>8, new_fourcc>>16, new_fourcc>>24, + length_new_buffer, length_Y, length_CbCr); + break; + default: + GST_WARNING_OBJECT(camerasrc, "Unknown fourcc(%c%c%c%c)", + new_fourcc, new_fourcc>>8, new_fourcc>>16, new_fourcc>>24); + *new_buffer = NULL; + return FALSE; + } + + GST_DEBUG_OBJECT(camerasrc, "Done."); + + return TRUE; +} + + +/* this function should be called after lock buffer_lock and preview_lock */ +static void _gst_camerasrc_restart_preview(GstCameraSrc *camerasrc) +{ + if (!camerasrc) { + GST_ERROR("handle is NULL"); + return; + } + + GST_INFO("START"); + + /* stop stream */ + GST_INFO("_gst_camerasrc_restart_preview : gst_camerasrc_stop"); + gst_camerasrc_stop(camerasrc); + + /* start stream */ + GST_INFO("_gst_camerasrc_restart_preview : gst_camerasrc_start"); + gst_camerasrc_start(camerasrc); + + GST_INFO("DONE"); + + return; +} + + +static gboolean gst_camerasrc_get_caps_info(GstCameraSrc *camerasrc, GstCaps *caps, guint *size) +{ + gint fps_n = 0; + gint fps_d = 0; + gint w = 0; + gint h = 0; + gint rot = 0; + gchar *caps_string = NULL; + const gchar *mimetype; + GstVideoInfo caps_info; + const gchar *caps_format_name = NULL; + guint32 caps_fourcc = 0; + const GValue *framerate; + GstStructure *structure = NULL; + + GST_INFO_OBJECT(camerasrc, "ENTERED Collect data for given caps.(caps:%p)", caps); + + structure = gst_caps_get_structure(caps, 0); + + if (!gst_structure_get_int(structure, "width", &w)) { + goto _caps_info_failed; + } + + if (!gst_structure_get_int(structure, "height", &h)) { + goto _caps_info_failed; + } + + if (!gst_structure_get_int(structure, "rotate", &rot)) { + GST_WARNING_OBJECT(camerasrc, "Failed to get rotate info in caps. set default 0."); + camerasrc->use_rotate_caps = FALSE; + } else { + GST_INFO_OBJECT(camerasrc, "Succeed to get rotate[%d] info in caps", rot); + camerasrc->use_rotate_caps = TRUE; + } + + /* set default size if there is no capsfilter */ + if (w == 1) { + w = _DEFAULT_WIDTH * 2; + } + + if (h == 1) { + h = _DEFAULT_HEIGHT * 2; + } + + camerasrc->width = w; + camerasrc->height = h; + camerasrc->rotate = rot; + + framerate = gst_structure_get_value(structure, "framerate"); + if (!framerate) { + GST_INFO("Set FPS as default(30/1)"); + + /* set default fps if framerate is not existed in caps */ + fps_n = _DEFAULT_FPS; + fps_d = 1; + } else { + fps_n = gst_value_get_fraction_numerator(framerate); + fps_d = gst_value_get_fraction_denominator(framerate); + + /* numerator and denominator should be bigger than zero */ + if (fps_n <= 0) { + GST_WARNING("numerator of FPS is %d. make it default(30).", fps_n); + fps_n = _DEFAULT_FPS; + } + + if (fps_d <= 0) { + GST_WARNING("denominator of FPS is %d. make it 1.", fps_d); + fps_d = 1; + } + } + + camerasrc->fps = (int)((float)fps_n / (float)fps_d); + + mimetype = gst_structure_get_name (structure); + + *size = 0; + + if (!strcmp(mimetype, "video/x-raw")) { + gst_video_info_init(&caps_info); + if (gst_video_info_from_caps(&caps_info, caps) && + GST_VIDEO_INFO_IS_RGB(&caps_info)) { + switch (GST_VIDEO_FORMAT_INFO_BITS(caps_info.finfo)) { + case 8: /* V4L2_PIX_FMT_RGB332 */ + camerasrc->pix_format = CAMERASRC_PIX_RGGB8; + camerasrc->colorspace = CAMERASRC_COL_RAW; + break; + case 15: /* V4L2_PIX_FMT_RGB555 : V4L2_PIX_FMT_RGB555X */ + camerasrc->pix_format = CAMERASRC_PIX_NONE; + camerasrc->colorspace = CAMERASRC_COL_NONE; + break; + case 16: /* V4L2_PIX_FMT_RGB565 : V4L2_PIX_FMT_RGB565X */ + camerasrc->pix_format = CAMERASRC_PIX_NONE; + camerasrc->colorspace = CAMERASRC_COL_NONE; + break; + case 24: /* V4L2_PIX_FMT_BGR24 : V4L2_PIX_FMT_RGB24 */ + camerasrc->pix_format = CAMERASRC_PIX_NONE; + camerasrc->colorspace = CAMERASRC_COL_NONE; + break; + case 32: /* V4L2_PIX_FMT_BGR32 : V4L2_PIX_FMT_RGB32 */ + camerasrc->pix_format = CAMERASRC_PIX_NONE; + camerasrc->colorspace = CAMERASRC_COL_NONE; + break; + } + } else { + caps_format_name = gst_structure_get_string(structure, "format"); + if (caps_format_name == NULL) { + GST_INFO_OBJECT(camerasrc, "Getting format name is NULL."); + goto _caps_info_failed; + } + + strncpy(camerasrc->format_name, caps_format_name, sizeof(camerasrc->format_name)); + caps_fourcc = MAKE_FOURCC_FROM_STRING(camerasrc->format_name); + _gst_camerasrc_get_frame_size(caps_fourcc, w, h, size); + _gst_camerasrc_get_raw_pixel_info(caps_fourcc, &(camerasrc->pix_format), &(camerasrc->colorspace)); + } + } else if (strcmp(mimetype, "video/x-dv") == 0) { /* V4L2_PIX_FMT_DV */ + camerasrc->pix_format = CAMERASRC_PIX_NONE; + camerasrc->colorspace = CAMERASRC_COL_NONE; + } else if (strcmp(mimetype, "image/jpeg") == 0) { /* V4L2_PIX_FMT_JPEG */ + camerasrc->pix_format = CAMERASRC_PIX_RGGB8; /* default */ + camerasrc->colorspace = CAMERASRC_COL_JPEG; + } + + GST_INFO_OBJECT(camerasrc, "pixformat %d, colorspace %d, size %d", + camerasrc->pix_format, camerasrc->colorspace, *size); + + caps_string = gst_caps_to_string(caps); + if (caps_string) { + GST_INFO_OBJECT(camerasrc, "caps : [%s]", caps_string); + g_free(caps_string); + caps_string = NULL; + } + + return TRUE; + +_caps_info_failed: + GST_INFO_OBJECT(camerasrc, "Failed to get caps info."); + GST_DEBUG_OBJECT(camerasrc, "LEAVED"); + return FALSE; +} + + +static void _gst_camerasrc_post_message_int(GstCameraSrc *camerasrc, const char *msg_name, const char *field_name, int value) +{ + GstMessage *m = NULL; + GstStructure *s = NULL; + + if (!camerasrc || !msg_name || !field_name) { + GST_ERROR("pointer is NULL %p, %p, %p", camerasrc, msg_name, field_name); + return; + } + + GST_INFO("post message [%s] %s %d", msg_name, field_name, value); + + s = gst_structure_new(msg_name, field_name, G_TYPE_INT, value, NULL); + if (s == NULL) { + GST_ERROR("gst_structure_new failed"); + gst_camerasrc_error_handler(camerasrc, CAMERASRC_ERR_ALLOCATION); + return; + } + + m = gst_message_new_element(GST_OBJECT(camerasrc), s); + if (m == NULL) { + GST_ERROR("gst_message_new_element failed"); + gst_camerasrc_error_handler(camerasrc, CAMERASRC_ERR_ALLOCATION); + return; + } + + gst_element_post_message(GST_ELEMENT(camerasrc), m); + + return; +} + + +static gboolean gst_camerasrc_set_caps(GstBaseSrc *src, GstCaps *caps) +{ + guint size; + GstCameraSrc *camerasrc = NULL; + gboolean res = FALSE; + + camerasrc = GST_CAMERA_SRC(src); + + GST_INFO_OBJECT(camerasrc, "ENTERED"); + + if (camerasrc->mode == VIDEO_IN_MODE_PREVIEW || + camerasrc->mode == VIDEO_IN_MODE_VIDEO) { + GST_INFO_OBJECT(camerasrc, "Proceed set_caps"); + GST_INFO(" gst_camerasrc_stop"); + if (!gst_camerasrc_stop(camerasrc)) { + GST_INFO_OBJECT(camerasrc, "Cam sensor stop failed."); + } + } else if (camerasrc->mode == VIDEO_IN_MODE_CAPTURE) { + GST_ERROR_OBJECT(camerasrc, "A mode of avsystem camera is capture. Not to proceed set_caps."); + GST_DEBUG_OBJECT(camerasrc, "LEAVED"); + return FALSE; + } else { + GST_INFO_OBJECT(camerasrc, "A mode of avsystem camera is unknown[%d]. Proceed set_caps.", camerasrc->mode); + } + + /* we want our own v4l2 type of fourcc codes */ + if (!gst_camerasrc_get_caps_info(camerasrc, caps, &size)) { + GST_INFO_OBJECT(camerasrc, "can't get capture information from caps %p", caps); + return FALSE; + } + + GST_INFO(" gst_camerasrc_start"); + if (!gst_camerasrc_start(camerasrc)) { + GST_INFO_OBJECT (camerasrc, "Cam sensor start failed."); + } + + res = gst_pad_push_event (GST_BASE_SRC_PAD (src), gst_event_new_caps (caps)); + + GST_INFO_OBJECT (camerasrc, "LEAVED"); + + return res; +} + + +static void gst_camerasrc_class_init(GstCameraSrcClass *klass) +{ + GST_DEBUG_CATEGORY_INIT(camerasrc_debug, "camerasrc", 0, "camerasrc element"); + + GObjectClass *gobject_class; + GstElementClass *element_class; + GstBaseSrcClass *basesrc_class; + GstPushSrcClass *pushsrc_class; + + GST_DEBUG("ENTERED"); + + gobject_class = G_OBJECT_CLASS(klass); + element_class = GST_ELEMENT_CLASS(klass); + basesrc_class = GST_BASE_SRC_CLASS(klass); + pushsrc_class = GST_PUSH_SRC_CLASS(klass); + + gobject_class->set_property = gst_camerasrc_set_property; + gobject_class->get_property = gst_camerasrc_get_property; + gobject_class->finalize = gst_camerasrc_finalize; + element_class->change_state = gst_camerasrc_change_state; + gst_element_class_add_pad_template(element_class, gst_static_pad_template_get (&src_factory)); + gst_element_class_set_static_metadata(element_class, + "Camera Source GStreamer Plug-in", + "Source/Video", + "camera src for videosrc based GStreamer Plug-in", + "Jeongmo Yang <jm80.yang@samsung.com>"); + basesrc_class->start = gst_camerasrc_src_start; + basesrc_class->stop = gst_camerasrc_src_stop; + basesrc_class->get_caps = gst_camerasrc_get_caps; + basesrc_class->set_caps = gst_camerasrc_set_caps; + basesrc_class->negotiate = gst_camerasrc_negotiate; + pushsrc_class->create = gst_camerasrc_src_create; + + g_object_class_install_property(gobject_class, ARG_CAMERA_HIGH_SPEED_FPS, + g_param_spec_int("high-speed-fps", "Fps for high speed recording", + "If this value is 0, the element doesn't activate high speed recording.", + 0, G_MAXINT, _DEFAULT_HIGH_SPEED_FPS, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property(gobject_class, ARG_CAMERA_AUTO_FPS, + g_param_spec_boolean("fps-auto", "FPS Auto", + "Field for auto fps setting", + _DEFAULT_FPS_AUTO, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property(gobject_class, ARG_CAMERA_ID, + g_param_spec_int("camera-id", "index number of camera to activate", + "index number of camera to activate", + _FD_MIN, _FD_MAX, 0, + G_PARAM_READWRITE)); + + /*Capture*/ + g_object_class_install_property(gobject_class, ARG_CAMERA_CAPTURE_FOURCC, + g_param_spec_uint("capture-fourcc", "Capture format", + "Fourcc value for capture format", + 0, G_MAXUINT, 0, + G_PARAM_READWRITE)); + + g_object_class_install_property(gobject_class, ARG_CAMERA_CAPTURE_WIDTH, + g_param_spec_int("capture-width", "Capture width", + "Width for camera size to capture", + 0, G_MAXINT, _DEFAULT_CAP_WIDTH, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property(gobject_class, ARG_CAMERA_CAPTURE_HEIGHT, + g_param_spec_int("capture-height", "Capture height", + "Height for camera size to capture", + 0, G_MAXINT, _DEFAULT_CAP_HEIGHT, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property(gobject_class, ARG_CAMERA_CAPTURE_INTERVAL, + g_param_spec_int("capture-interval", "Capture interval", + "Interval time to capture (millisecond)", + 0, G_MAXINT, _DEFAULT_CAP_INTERVAL, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property(gobject_class, ARG_CAMERA_CAPTURE_COUNT, + g_param_spec_int("capture-count", "Capture count", + "Capture conut for multishot", + 1, G_MAXINT, _DEFAULT_CAP_COUNT, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property(gobject_class, ARG_CAMERA_CAPTURE_JPG_QUALITY, + g_param_spec_int("capture-jpg-quality", "JPEG Capture compress ratio", + "Quality of capture image compress ratio", + 1, 100, _DEFAULT_CAP_JPG_QUALITY, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property(gobject_class, ARG_CAMERA_CAPTURE_PROVIDE_EXIF, + g_param_spec_boolean("provide-exif", "Whether EXIF is provided", + "Does capture provide EXIF?", + _DEFAULT_CAP_PROVIDE_EXIF, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property(gobject_class, ARG_VFLIP, + g_param_spec_boolean("vflip", "Flip vertically", + "Flip camera input vertically", + 0, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property(gobject_class, ARG_HFLIP, + g_param_spec_boolean("hflip", "Flip horizontally", + "Flip camera input horizontally", + 0, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + /** + * GstCameraSrc::still-capture: + * @camerasrc: the camerasrc instance + * @buffer: the buffer that will be pushed - Main + * @buffer: the buffer that will be pushed - Thumbnail + * @buffer: the buffer that will be pushed - Screennail + * + * This signal gets emitted before sending the buffer. + */ + gst_camerasrc_signals[SIGNAL_STILL_CAPTURE] = + g_signal_new("still-capture", + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(GstCameraSrcClass, still_capture), + NULL, + NULL, + g_cclosure_user_marshal_VOID__OBJECT_OBJECT_OBJECT, + G_TYPE_NONE, + 3, /* Number of parameter */ + GST_TYPE_SAMPLE, /* Main image buffer */ + GST_TYPE_SAMPLE, /* Thumbnail image buffer */ + GST_TYPE_SAMPLE); /* Screennail image buffer */ + + GST_DEBUG("LEAVED"); + + return; +} + + +static void gst_camerasrc_init(GstCameraSrc *camerasrc) +{ + GST_INFO("ENTERED"); + + camerasrc->v4l2_handle = NULL; + camerasrc->mode = VIDEO_IN_MODE_UNKNOWN; + camerasrc->firsttime = TRUE; + camerasrc->main_buf_sz = 0; + camerasrc->cap_count_current = -1; + camerasrc->cap_count_reverse = _DEFAULT_CAP_COUNT; + camerasrc->cap_next_time = 0UL; + camerasrc->capture_cmd_list = g_queue_new(); + camerasrc->restart_cmd_list = g_queue_new(); + + /*camera*/ + camerasrc->width = _DEFAULT_WIDTH; + camerasrc->height = _DEFAULT_HEIGHT; + camerasrc->fps = _DEFAULT_FPS; + camerasrc->rotate = 0; + camerasrc->use_rotate_caps = FALSE; + camerasrc->high_speed_fps = _DEFAULT_HIGH_SPEED_FPS; + camerasrc->fps_auto = _DEFAULT_FPS_AUTO; + camerasrc->pix_format = _DEFAULT_PIX_FORMAT; + camerasrc->colorspace = _DEFAULT_COLORSPACE; + strcpy(camerasrc->format_name, _DEFAULT_PIX_FORMAT_NAME); + camerasrc->num_live_buffers = 0; + camerasrc->buffer_count = _DEFAULT_BUFFER_COUNT; + camerasrc->buffer_running = FALSE; + camerasrc->bfirst = TRUE; + camerasrc->pad_alloc_list = g_queue_new (); + camerasrc->current_buffer_data_index = 0; + camerasrc->vflip = FALSE; + camerasrc->hflip = FALSE; + camerasrc->camera_id = _DEFAULT_CAMERA_ID; + + /*capture*/ + camerasrc->cap_fourcc = MAKE_FOURCC_FROM_STRING(_DEFAULT_CAPTURE_FORMAT_NAME); + camerasrc->cap_width = _DEFAULT_CAP_WIDTH; + camerasrc->cap_height = _DEFAULT_CAP_HEIGHT; + camerasrc->cap_interval = _DEFAULT_CAP_INTERVAL; + camerasrc->cap_count = _DEFAULT_CAP_COUNT; + camerasrc->cap_jpg_quality = _DEFAULT_CAP_JPG_QUALITY; + camerasrc->cap_provide_exif = _DEFAULT_CAP_PROVIDE_EXIF; + camerasrc->create_jpeg = FALSE; + + camerasrc->first_invokation = TRUE; + camerasrc->flash_activated = FALSE; + + camerasrc->capture_buffer_list = g_queue_new (); + camerasrc->capture_thread = NULL; + camerasrc->quit_capture_thread = FALSE; + camerasrc->buffer_info = NULL; + camerasrc->flush_cache = TRUE; + + g_mutex_init(&camerasrc->mutex); + g_mutex_init(&camerasrc->buffer_lock); + g_mutex_init(&camerasrc->pad_alloc_mutex); + g_mutex_init(&camerasrc->jpg_mutex); + g_mutex_init(&camerasrc->capture_mutex); + g_mutex_init(&camerasrc->restart_mutex); + g_cond_init(&camerasrc->cond); + g_cond_init(&camerasrc->buffer_cond); + g_cond_init(&camerasrc->capture_cond); + g_cond_init(&camerasrc->restart_cond); + +#ifdef _SPEED_UP_RAW_CAPTURE + camerasrc->cap_stream_diff = FALSE; +#endif /* _SPEED_UP_RAW_CAPTURE */ + + /* we operate in time */ + gst_base_src_set_format(GST_BASE_SRC(camerasrc), GST_FORMAT_TIME); + gst_base_src_set_live(GST_BASE_SRC(camerasrc), TRUE); + gst_base_src_set_do_timestamp(GST_BASE_SRC(camerasrc), TRUE); + + GST_INFO("LEAVED"); + + return; +} + + +static unsigned long gst_get_current_time(void) +{ + struct timeval lc_time; + + gettimeofday(&lc_time, NULL); + + return ((unsigned long)(lc_time.tv_sec * 1000L) + (unsigned long)(lc_time.tv_usec / 1000L)); +} + + +#if _ENABLE_CAMERASRC_DEBUG +#include <stdio.h> +static int __util_write_file(char *filename, void *data, int size) +{ + FILE *fp = NULL; + + fp = fopen(filename, "wb"); + if (!fp) { + return FALSE; + } + + fwrite(data, 1, size, fp); + fclose(fp); + + return TRUE; +} +#endif + + +static gboolean plugin_init(GstPlugin *plugin) +{ + gboolean error; + + error = gst_element_register(plugin, "camerasrc", GST_RANK_PRIMARY + 100, GST_TYPE_CAMERA_SRC); + + return error; +} + + +GST_PLUGIN_DEFINE(GST_VERSION_MAJOR, + GST_VERSION_MINOR, + camerasrc, + "Camera source plug-in", + plugin_init, + PACKAGE_VERSION, + "LGPL", + "Samsung Electronics Co", + "http://www.samsung.com") + +/* GstURIHandler interface */ +static GstURIType +gst_camerasrc_uri_get_type (GType type) +{ + return GST_URI_SRC; +} + +static const gchar * const* +gst_camerasrc_uri_get_protocols (GType type) +{ + static const gchar *protocols[] = { "camera", NULL }; + return protocols; +} + +static gchar * +gst_camerasrc_uri_get_uri (GstURIHandler * handler) +{ + return strdup("camera://0"); +} + +static gboolean +gst_camerasrc_uri_set_uri (GstURIHandler * handler, const gchar * uri, GError **error) +{ + GstCameraSrc *camerasrc = GST_CAMERA_SRC (handler); + const gchar *device = "0"; + if (strcmp (uri, "camera://") != 0) { + device = uri + 9; + } + g_object_set (camerasrc, "camera-id", atoi(device), NULL); + + return TRUE; +} + + +static void +gst_camerasrc_uri_handler_init (gpointer g_iface, gpointer iface_data) +{ + GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface; + + iface->get_type = gst_camerasrc_uri_get_type; + iface->get_protocols = gst_camerasrc_uri_get_protocols; + iface->get_uri = gst_camerasrc_uri_get_uri; + iface->set_uri = gst_camerasrc_uri_set_uri; +} +/* EOF */ diff --git a/camerasrc/src/gstcamerasrccolorbalance.c b/camerasrc/src/gstcamerasrccolorbalance.c new file mode 100644 index 0000000..4f14ab1 --- /dev/null +++ b/camerasrc/src/gstcamerasrccolorbalance.c @@ -0,0 +1,112 @@ +/* + * camerasrc + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jeongmo Yang <jm80.yang@samsung.com> + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gst/gst.h> +#include "gstcamerasrccolorbalance.h" + +G_DEFINE_TYPE( GstCameraSrcColorBalanceChannel, + gst_camerasrc_color_balance_channel, + GST_TYPE_COLOR_BALANCE_CHANNEL ); + +#ifndef GST_CAT_DEFAULT +GST_DEBUG_CATEGORY_EXTERN(camerasrc_debug); +#define GST_CAT_DEFAULT camerasrc_debug +#endif /* GST_CAT_DEFAULT */ + + +static void +gst_camerasrc_color_balance_channel_class_init( GstCameraSrcColorBalanceChannelClass* klass ) +{ +} + +static void +gst_camerasrc_color_balance_channel_init( GstCameraSrcColorBalanceChannel* camerasrc_color_channel) +{ + camerasrc_color_channel->id = (guint32) - 1; +} + +static G_GNUC_UNUSED gboolean +gst_camerasrc_color_balance_contains_channel( GstCameraSrc* camerasrc, GstCameraSrcColorBalanceChannel* camerasrc_color_channel ) +{ + const GList *item; + + for( item = camerasrc->colors ; item != NULL ; item = item->next ) + { + if (item->data == camerasrc_color_channel) + return TRUE; + } + + return FALSE; +} + +const GList * +gst_camerasrc_color_balance_list_channels( GstCameraSrc* camerasrc ) +{ + return camerasrc->colors; +} + +void +gst_camerasrc_color_balance_set_value( GstCameraSrc* camerasrc, GstColorBalanceChannel* color_channel, gint value ) +{ + int error = CAMERASRC_ERR_UNKNOWN; + + GstCameraSrcColorBalanceChannel *camerasrc_color_channel = GST_CAMERASRC_COLOR_BALANCE_CHANNEL( color_channel ); + + /* assert that we're opened and that we're using a known item */ + g_return_if_fail( camerasrc ); + g_return_if_fail( gst_camerasrc_color_balance_contains_channel( camerasrc, camerasrc_color_channel ) ); + + error = camerasrc_set_control( camerasrc->v4l2_handle, camerasrc_color_channel->id, value ); + + if( error != CAMERASRC_SUCCESS ) + { + GST_WARNING("Failed to Set ColorBalance[%s],value[%d]", camerasrc_color_channel->parent.label, value); + } +} + +gint +gst_camerasrc_color_balance_get_value( GstCameraSrc* camerasrc, GstColorBalanceChannel* color_channel ) +{ + int error, value; + GstCameraSrcColorBalanceChannel *camerasrc_color_channel = GST_CAMERASRC_COLOR_BALANCE_CHANNEL( color_channel ); + + /* assert that we're opened and that we're using a known item */ + g_return_val_if_fail( camerasrc, FALSE ); + g_return_val_if_fail( gst_camerasrc_color_balance_contains_channel( camerasrc, camerasrc_color_channel ), FALSE ); + + error = camerasrc_get_control( camerasrc->v4l2_handle, camerasrc_color_channel->id, &value ); + + if( error != CAMERASRC_SUCCESS ) + { + GST_WARNING("Failed to Get ColorBalance[%s].", camerasrc_color_channel->parent.label); + return FALSE; + } + + return value; +} + + diff --git a/camerasrc/src/gstcamerasrccontrol.c b/camerasrc/src/gstcamerasrccontrol.c new file mode 100644 index 0000000..deac43a --- /dev/null +++ b/camerasrc/src/gstcamerasrccontrol.c @@ -0,0 +1,915 @@ +/* + * camerasrc + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jeongmo Yang <jm80.yang@samsung.com> + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gst/gst.h> +#include "gstcamerasrccontrol.h" +#include "camerasrc-common.h" + +#define gst_camerasrc_debug(fmt, args...) GST_INFO(fmt, ##args) + +#define CAMERA_CONTROL_AF_STOP_TOTALTIME 2000000 +#define CAMERA_CONTROL_AF_STOP_INTERVAL 20000 + +/** + * Enumeration of Wide Dynamic Range + */ +enum { + CAMERA_CONTROL_WDR_OFF = 1, + CAMERA_CONTROL_WDR_ON, + CAMERA_CONTROL_WDR_AUTO, +}; + +G_DEFINE_TYPE(GstCamerasrcControlChannel, + gst_camerasrc_control_channel, + GST_TYPE_CAMERA_CONTROL_CHANNEL); + +static void gst_camerasrc_control_channel_class_init(GstCamerasrcControlChannelClass *klass) +{ + gst_camerasrc_debug("class init"); +} + +static void gst_camerasrc_control_channel_init(GstCamerasrcControlChannel *control_channel) +{ + gst_camerasrc_debug("channel init"); + + control_channel->id = (guint32) - 1; +} + +static G_GNUC_UNUSED gboolean gst_camerasrc_control_contains_channel(GstCameraSrc *camerasrc, + GstCamerasrcControlChannel *camerasrc_control_channel) +{ + gst_camerasrc_debug("contains channel"); + + const GList *item; + + for (item = camerasrc->camera_controls ; item != NULL ; item = item->next) { + if (item->data == camerasrc_control_channel) { + return TRUE; + } + } + + return FALSE; +} + +const GList *gst_camerasrc_control_list_channels(GstCameraSrc *camerasrc) +{ + gst_camerasrc_debug("list channels"); + + return camerasrc->camera_controls; +} + +gboolean gst_camerasrc_control_set_value(GstCameraSrc *camerasrc, GstCameraControlChannel *control_channel, gint value) +{ + gst_camerasrc_debug("set value : %d", value); + + int error = CAMERASRC_ERROR; + + GstCamerasrcControlChannel *camerasrc_control_channel = GST_CAMERASRC_CONTROL_CHANNEL(control_channel); + + g_return_val_if_fail(camerasrc, FALSE); + g_return_val_if_fail(gst_camerasrc_control_contains_channel(camerasrc, camerasrc_control_channel), FALSE); + + error = camerasrc_set_control(camerasrc->v4l2_handle, camerasrc_control_channel->id, value); + + if (error != CAMERASRC_SUCCESS) { + gst_camerasrc_debug("Failed to set value. Ctrl-id [%d], value [%d], err code [%d]", camerasrc_control_channel->id, value, error); + return FALSE; + } + + return TRUE; +} + +gboolean gst_camerasrc_control_get_value(GstCameraSrc *camerasrc, GstCameraControlChannel *control_channel, gint *value) +{ + gst_camerasrc_debug("get value"); + + int error = CAMERASRC_ERROR; + + GstCamerasrcControlChannel *camerasrc_control_channel = GST_CAMERASRC_CONTROL_CHANNEL(control_channel); + + g_return_val_if_fail(camerasrc, FALSE); + g_return_val_if_fail(gst_camerasrc_control_contains_channel(camerasrc, camerasrc_control_channel), FALSE); + + error = camerasrc_get_control(camerasrc->v4l2_handle, camerasrc_control_channel->id, value); + + if (error != CAMERASRC_SUCCESS) { + gst_camerasrc_debug("Failed to get control value. Ctrl-id [%d], err code[%x]", camerasrc_control_channel->id, error); + return FALSE; + } + + return TRUE; +} + +gboolean gst_camerasrc_control_set_exposure(GstCameraSrc *camerasrc, gint type, gint value1, gint value2) +{ + gst_camerasrc_debug("set exposure"); + + int error = CAMERASRC_ERROR; + camerasrc_frac_t frac; + + g_return_val_if_fail(camerasrc, FALSE); + + /* TODO : F number */ + switch (type) { + case GST_CAMERA_CONTROL_F_NUMBER: + error = CAMERASRC_SUCCESS; + break; + case GST_CAMERA_CONTROL_SHUTTER_SPEED: + frac.numerator = value1; + frac.denominator = value2; + gst_camerasrc_debug(" camerasrc_set_shutter_speed"); + error = camerasrc_set_shutter_speed(camerasrc->v4l2_handle, frac); + break; + case GST_CAMERA_CONTROL_ISO: + gst_camerasrc_debug(" camerasrc_set_iso_value"); + error = camerasrc_set_control(camerasrc->v4l2_handle, CAMERASRC_CTRL_ISO, value1); + break; + case GST_CAMERA_CONTROL_PROGRAM_MODE: + gst_camerasrc_debug(" camerasrc_set_control"); + error = camerasrc_set_control(camerasrc->v4l2_handle, CAMERASRC_CTRL_PROGRAM_MODE, value1); + break; + case GST_CAMERA_CONTROL_EXPOSURE_MODE: + gst_camerasrc_debug(" camerasrc_set_exposure_mode"); + error = camerasrc_set_control(camerasrc->v4l2_handle, CAMERASRC_CTRL_PHOTOMETRY, value1); + break; + case GST_CAMERA_CONTROL_EXPOSURE_VALUE: + frac.numerator = value1; + frac.denominator = value2; + gst_camerasrc_debug(" camerasrc_set_exposure_value"); + error = camerasrc_set_exposure_value(camerasrc->v4l2_handle, frac); + break; + default: + gst_camerasrc_debug("Not supported type."); + return FALSE; + } + + if (error != CAMERASRC_SUCCESS) { + gst_camerasrc_debug("Failed to set exposure. Type[%d],value1[%d],value2[%d],err code[%x]", type, value1, value2, error); + return FALSE; + } + + return TRUE; +} + +gboolean gst_camerasrc_control_get_exposure(GstCameraSrc *camerasrc, gint type, gint *value1, gint *value2) +{ + gst_camerasrc_debug("get exposure"); + + int error = CAMERASRC_ERROR; + camerasrc_frac_t frac; + + g_return_val_if_fail(camerasrc, FALSE); + + /* TODO : F number */ + switch (type) { + case GST_CAMERA_CONTROL_F_NUMBER: + break; + case GST_CAMERA_CONTROL_SHUTTER_SPEED: + error = camerasrc_get_shutter_speed(camerasrc->v4l2_handle, &frac); + if (error == CAMERASRC_SUCCESS) { + *value1 = frac.numerator; + *value2 = frac.denominator; + } + break; + case GST_CAMERA_CONTROL_ISO: + error = camerasrc_get_control(camerasrc->v4l2_handle, CAMERASRC_CTRL_ISO, value1); + break; + case GST_CAMERA_CONTROL_PROGRAM_MODE: + error = camerasrc_get_control(camerasrc->v4l2_handle, CAMERASRC_CTRL_PROGRAM_MODE, value1); + break; + case GST_CAMERA_CONTROL_EXPOSURE_MODE: + error = camerasrc_get_control(camerasrc->v4l2_handle, CAMERASRC_CTRL_PHOTOMETRY, value1); + break; + case GST_CAMERA_CONTROL_EXPOSURE_VALUE: + error = camerasrc_get_exposure_value(camerasrc->v4l2_handle, &frac); + if (error == CAMERASRC_SUCCESS) { + *value1 = frac.numerator; + *value2 = frac.denominator; + } + break; + default: + gst_camerasrc_debug("Not supported type."); + return FALSE; + } + + if (error != CAMERASRC_SUCCESS) { + gst_camerasrc_debug("Failed to get exposure. Type [%d]", type); + return FALSE; + } + + return TRUE; +} + +gboolean gst_camerasrc_control_set_capture_mode(GstCameraSrc *camerasrc, gint type, gint value) +{ + /* TODO : single/multishot select(capture mode), output mode, frame count, JPEG quality */ + + gst_camerasrc_debug("set capture mode"); + + int error = CAMERASRC_ERROR; + + g_return_val_if_fail(camerasrc, FALSE); + + switch (type) { + case GST_CAMERA_CONTROL_CAPTURE_MODE: + break; + case GST_CAMERA_CONTROL_OUTPUT_MODE: + break; + case GST_CAMERA_CONTROL_FRAME_COUNT: + break; + case GST_CAMERA_CONTROL_JPEG_QUALITY: + break; + default: + gst_camerasrc_debug("Not supported type."); + return FALSE; + } + + if (error != CAMERASRC_SUCCESS) { + gst_camerasrc_debug("Failed to set capture mode. Type[%d],value[%d],err code[%x]", type, value, error); + return FALSE; + } + + return TRUE; +} + +gboolean gst_camerasrc_control_get_capture_mode(GstCameraSrc *camerasrc, gint type, gint *value) +{ + /* TODO : single/multishot select(capture mode), output mode, frame count, JPEG quality */ + + gst_camerasrc_debug("get capture mode"); + + int error = CAMERASRC_ERROR; + + g_return_val_if_fail(camerasrc, FALSE); + + switch (type) { + case GST_CAMERA_CONTROL_CAPTURE_MODE: + break; + case GST_CAMERA_CONTROL_OUTPUT_MODE: + break; + case GST_CAMERA_CONTROL_FRAME_COUNT: + break; + case GST_CAMERA_CONTROL_JPEG_QUALITY: + break; + default: + gst_camerasrc_debug("Not supported type."); + return FALSE; + } + + if (error != CAMERASRC_SUCCESS) { + gst_camerasrc_debug("Failed to set capture mode. Type[%d],err code[%x]", type, error); + return FALSE; + } + + return TRUE; +} + +gboolean gst_camerasrc_control_set_strobe(GstCameraSrc *camerasrc, gint type, gint value) +{ + gst_camerasrc_debug("set strobe"); + + int error = CAMERASRC_ERROR; + + g_return_val_if_fail(camerasrc, FALSE); + + switch (type) { + case GST_CAMERA_CONTROL_STROBE_MODE: + error = camerasrc_set_strobe_mode(camerasrc->v4l2_handle, value); + break; + case GST_CAMERA_CONTROL_STROBE_CONTROL: + case GST_CAMERA_CONTROL_STROBE_CAPABILITIES: + case GST_CAMERA_CONTROL_STROBE_STATUS: + case GST_CAMERA_CONTROL_STROBE_EV: + default: + gst_camerasrc_debug("Not supported type[%d], return CAMERASRC_ERR_DEVICE_NOT_SUPPORT.", type); + error = CAMERASRC_ERR_DEVICE_NOT_SUPPORT; + break; + } + + if (error != CAMERASRC_SUCCESS) { + gst_camerasrc_debug("Failed to set strobe. Type[%d],value[%d],err code[%x]", type, value, error); + return FALSE; + } + + gst_camerasrc_debug("Succeed to set strobe. Type[%d],value[%d]", type, value); + + return TRUE; +} + +gboolean gst_camerasrc_control_get_strobe(GstCameraSrc *camerasrc, gint type, gint *value) +{ + gst_camerasrc_debug("get strobe"); + + int error = CAMERASRC_ERROR; + + g_return_val_if_fail(camerasrc, FALSE); + + switch (type) { + case GST_CAMERA_CONTROL_STROBE_MODE: + error = camerasrc_get_strobe_mode(camerasrc->v4l2_handle, (camerasrc_strobe_mode_t *)value); + break; + case GST_CAMERA_CONTROL_STROBE_CONTROL: + case GST_CAMERA_CONTROL_STROBE_CAPABILITIES: + case GST_CAMERA_CONTROL_STROBE_STATUS: + case GST_CAMERA_CONTROL_STROBE_EV: + default: + gst_camerasrc_debug("Not supported type[%d].", type); + error = CAMERASRC_ERR_DEVICE_NOT_SUPPORT; + break; + } + + if (error != CAMERASRC_SUCCESS) { + gst_camerasrc_debug("Failed to get strobe. Type[%d],err code[%x]", type, error); + return FALSE; + } + + return TRUE; +} + +gboolean gst_camerasrc_control_set_detect(GstCameraSrc *camerasrc, gint type, gint value) +{ + gst_camerasrc_debug("set detect"); + + int error = CAMERASRC_ERROR; + + g_return_val_if_fail(camerasrc, FALSE); + + /* TODO */ + switch (type) { + case GST_CAMERA_CONTROL_FACE_DETECT_MODE: + break; + case GST_CAMERA_CONTROL_FACE_DETECT_NUMBER: + break; + case GST_CAMERA_CONTROL_FACE_FOCUS_SELECT: + break; + case GST_CAMERA_CONTROL_FACE_SELECT_NUMBER: + break; + case GST_CAMERA_CONTROL_FACE_DETECT_STATUS: + break; + default: + gst_camerasrc_debug("Not supported type."); + return FALSE; + } + + if (error != CAMERASRC_SUCCESS) { + gst_camerasrc_debug("Failed to set detect. Type[%d],value[%d],err code[%x]", type, value, error); + return FALSE; + } + + return error; +} + +gboolean gst_camerasrc_control_get_detect(GstCameraSrc *camerasrc, gint type, gint *value) +{ + gst_camerasrc_debug("get detect"); + + int error = CAMERASRC_ERROR; + + g_return_val_if_fail(camerasrc, FALSE); + + /* TODO : detection number, focus select, select number, detect status */ + switch (type) { + case GST_CAMERA_CONTROL_FACE_DETECT_MODE: + break; + case GST_CAMERA_CONTROL_FACE_DETECT_NUMBER: + break; + case GST_CAMERA_CONTROL_FACE_FOCUS_SELECT: + break; + case GST_CAMERA_CONTROL_FACE_SELECT_NUMBER: + break; + case GST_CAMERA_CONTROL_FACE_DETECT_STATUS: + break; + default: + gst_camerasrc_debug("Not supported type."); + return FALSE; + } + + if (error != CAMERASRC_SUCCESS) { + gst_camerasrc_debug("Failed to get detect. Type[%d],err code[%x]", type, error); + return FALSE; + } + + return error; +} + +gboolean gst_camerasrc_control_set_zoom(GstCameraSrc *camerasrc, gint type, gint value) +{ + gst_camerasrc_debug("set zoom"); + + int error = CAMERASRC_ERROR; + + g_return_val_if_fail(camerasrc, FALSE); + + switch (type) { + case GST_CAMERA_CONTROL_DIGITAL_ZOOM: + error = camerasrc_set_control (camerasrc->v4l2_handle, CAMERASRC_CTRL_DIGITAL_ZOOM, value); + break; + case GST_CAMERA_CONTROL_OPTICAL_ZOOM: + error = camerasrc_set_control (camerasrc->v4l2_handle, CAMERASRC_CTRL_OPTICAL_ZOOM, value); + break; + default: + gst_camerasrc_debug("Not supported type."); + return FALSE; + } + + if (error != CAMERASRC_SUCCESS) { + gst_camerasrc_debug("Failed to set zoom. Type[%d],value[%d],err code[%x]", type, value, error); + return FALSE; + } + + return TRUE; +} + +gboolean gst_camerasrc_control_get_zoom(GstCameraSrc *camerasrc, gint type, gint *value) +{ + gst_camerasrc_debug("get zoom"); + + int error = CAMERASRC_ERROR; + + g_return_val_if_fail(camerasrc, FALSE); + + switch (type) { + case GST_CAMERA_CONTROL_DIGITAL_ZOOM: + error = camerasrc_get_control(camerasrc->v4l2_handle, CAMERASRC_CTRL_DIGITAL_ZOOM, value); + break; + case GST_CAMERA_CONTROL_OPTICAL_ZOOM: + error = camerasrc_get_control(camerasrc->v4l2_handle, CAMERASRC_CTRL_OPTICAL_ZOOM, value); + break; + default: + gst_camerasrc_debug("Not supported type."); + return FALSE; + } + + if (error != CAMERASRC_SUCCESS) { + gst_camerasrc_debug("Failed to get zoom. Type[%d],err code[%x]", type, error); + return FALSE; + } + + return TRUE; +} + +gboolean gst_camerasrc_control_set_focus(GstCameraSrc *camerasrc, gint focus_mode, gint focus_range) +{ + gst_camerasrc_debug("set focus"); + + int error = CAMERASRC_ERROR; + + g_return_val_if_fail(camerasrc, FALSE); + + error = camerasrc_init_autofocusing_mode(camerasrc->v4l2_handle, focus_mode, focus_range); + + if (error != CAMERASRC_SUCCESS) { + gst_camerasrc_debug("Failed to set AF mode."); + return FALSE; + } + + return TRUE; +} + +gboolean gst_camerasrc_control_get_focus(GstCameraSrc *camerasrc, gint *focus_mode, gint *focus_range) +{ + gst_camerasrc_debug("get focus"); + + int error = CAMERASRC_ERROR; + + g_return_val_if_fail(camerasrc, FALSE); + + error = camerasrc_get_autofocusing_mode(camerasrc->v4l2_handle, (camerasrc_af_mode_t *)focus_mode, (camerasrc_af_scan_range_t *)focus_range); + + if (error != CAMERASRC_SUCCESS) { + gst_camerasrc_debug("Failed to get AF mode."); + return FALSE; + } + + return TRUE; +} + +gboolean gst_camerasrc_control_start_auto_focus(GstCameraSrc *camerasrc) +{ + gst_camerasrc_debug("start auto focus"); + + int error = CAMERASRC_ERROR; + + g_return_val_if_fail(camerasrc, FALSE); + + error = camerasrc_start_autofocusing(camerasrc->v4l2_handle); + + if (error != CAMERASRC_SUCCESS) { + gst_camerasrc_debug("Failed to start AF. error[%x]", error); + return FALSE; + } else { + gst_camerasrc_debug("Succeeded to start AF."); + return TRUE; + } +} + +gboolean gst_camerasrc_control_stop_auto_focus(GstCameraSrc *camerasrc) +{ + gst_camerasrc_debug("stop auto focus"); + + int error = CAMERASRC_ERROR; + int try_count = 0; + camerasrc_auto_focus_status_t af_status = CAMERASRC_AUTO_FOCUS_STATUS_RELEASED; + + g_return_val_if_fail(camerasrc, FALSE); + + error = camerasrc_stop_autofocusing(camerasrc->v4l2_handle); + if (error != CAMERASRC_SUCCESS) { + gst_camerasrc_debug("Failed to stop autofocus."); + return FALSE; + } + + while (try_count++ < CAMERA_CONTROL_AF_STOP_TOTALTIME / CAMERA_CONTROL_AF_STOP_INTERVAL) { + error = camerasrc_get_autofocusing_status(camerasrc->v4l2_handle, &af_status); + if (error != CAMERASRC_SUCCESS) { + gst_camerasrc_debug("Failed to get af status.(%x)", error); + return FALSE; + } + + if (af_status == CAMERASRC_AUTO_FOCUS_STATUS_RELEASED) { + gst_camerasrc_debug("AF Stop done. try count[%d]", try_count); + break; + } + + usleep(CAMERA_CONTROL_AF_STOP_INTERVAL); + } + + return TRUE; +} + +gboolean gst_camerasrc_control_set_focus_level(GstCameraSrc *camerasrc, gint focus_level) +{ + /* TODO : */ + + gst_camerasrc_debug("Not support"); + return FALSE; +} + +gboolean gst_camerasrc_control_get_focus_level(GstCameraSrc *camerasrc, gint *focus_level) +{ + /* TODO : */ + + gst_camerasrc_debug("Not support"); + return FALSE; +} + +gboolean gst_camerasrc_control_set_auto_focus_area(GstCameraSrc *camerasrc, GstCameraControlRectType rect) +{ + gst_camerasrc_debug("set auto focus area"); + + int error = CAMERASRC_ERROR; + camerasrc_rect_t camerasrc_rect = { 0, 0, 0, 0 }; + + g_return_val_if_fail(camerasrc, FALSE); + + if (camerasrc->camera_id == CAMERASRC_DEV_ID_SECONDARY) { + GST_INFO_OBJECT(camerasrc, "It's secondary camera. Skip setting..."); + return TRUE; + } + + camerasrc_rect.x = rect.x; + camerasrc_rect.y = rect.y; + camerasrc_rect.width = rect.width; + camerasrc_rect.height = rect.height; + + GST_INFO_OBJECT(camerasrc, "Set AF area %d,%d,%dx%d", + camerasrc_rect.x, camerasrc_rect.y, + camerasrc_rect.width, camerasrc_rect.height); + + error = camerasrc_set_autofocusing_area(camerasrc->v4l2_handle, &camerasrc_rect); + + if (error != CAMERASRC_SUCCESS) { + GST_ERROR_OBJECT(camerasrc, "Failed to set auto focus area."); + return FALSE; + } + + return TRUE; +} + +gboolean gst_camerasrc_control_get_auto_focus_area(GstCameraSrc *camerasrc, GstCameraControlRectType *rect) +{ + gst_camerasrc_debug("get auto focus area"); + + int error = CAMERASRC_ERROR; + camerasrc_rect_t camerasrc_rect = { 0, 0, 0, 0 }; + + g_return_val_if_fail(camerasrc, FALSE); + g_return_val_if_fail(rect, FALSE); + + error = camerasrc_get_autofocusing_area(camerasrc->v4l2_handle, &camerasrc_rect); + + if (error != CAMERASRC_SUCCESS) { + gst_camerasrc_debug("Failed to get auto focus area."); + + rect->x = rect->y = -1; + rect->width = rect->height = -1; + + return FALSE; + } + + rect->x = camerasrc_rect.x; + rect->y = camerasrc_rect.y; + rect->width = camerasrc_rect.width; + rect->height = camerasrc_rect.height; + + return TRUE; +} + +gboolean gst_camerasrc_control_set_wdr(GstCameraSrc *camerasrc, gint value) +{ + gst_camerasrc_debug("set wdr"); + + int error = CAMERASRC_ERROR; + + g_return_val_if_fail(camerasrc, FALSE); + + error = camerasrc_set_control(camerasrc->v4l2_handle, CAMERASRC_CTRL_WIDE_DYNAMIC_RANGE, value); + if (error != CAMERASRC_SUCCESS) { + gst_camerasrc_debug("Failed to set wdr. value[%d],err code[%x]", value, error); + return FALSE; + } + + return TRUE; +} + +gboolean gst_camerasrc_control_get_wdr(GstCameraSrc *camerasrc, gint *value) +{ + gst_camerasrc_debug("get wdr"); + + int error = CAMERASRC_ERROR; + + g_return_val_if_fail(camerasrc, FALSE); + + error = camerasrc_get_control (camerasrc->v4l2_handle, CAMERASRC_CTRL_WIDE_DYNAMIC_RANGE, value); + + if (error != CAMERASRC_SUCCESS) { + gst_camerasrc_debug("Failed to get wdr. err code[%x]", error); + return FALSE; + } + + return TRUE; +} + +gboolean gst_camerasrc_control_set_ahs(GstCameraSrc *camerasrc, gint value) +{ + gst_camerasrc_debug("set ahs"); + + int error = CAMERASRC_ERROR; + + g_return_val_if_fail(camerasrc, FALSE); + + error = camerasrc_set_control (camerasrc->v4l2_handle, CAMERASRC_CTRL_ANTI_HANDSHAKE, value); + + if (error != CAMERASRC_SUCCESS) { + gst_camerasrc_debug("Failed to set ahs. value[%d],err code[%x]", value, error); + return FALSE; + } + + return TRUE; +} + +gboolean gst_camerasrc_control_get_ahs(GstCameraSrc *camerasrc, gint *value) +{ + gst_camerasrc_debug("get ahs"); + + int error = CAMERASRC_ERROR; + + g_return_val_if_fail(camerasrc, FALSE); + + error = camerasrc_get_control (camerasrc->v4l2_handle, CAMERASRC_CTRL_ANTI_HANDSHAKE, value); + + if (error != CAMERASRC_SUCCESS) { + gst_camerasrc_debug("Failed to get ahs. err code[%x]", error); + return FALSE; + } + + return TRUE; +} + + +gboolean gst_camerasrc_control_get_exif_info(GstCameraSrc *camerasrc, GstCameraControlExifInfo *info) +{ + gst_camerasrc_debug("get exif info"); + + int error = CAMERASRC_ERROR; + camerasrc_exif_t exif_struct; + + g_return_val_if_fail(camerasrc, FALSE); + + error = camerasrc_get_exif_info(camerasrc->v4l2_handle, &exif_struct); + + if (error != CAMERASRC_SUCCESS) { + gst_camerasrc_debug("Failed to get exif info. err code[%x]", error); + return FALSE; + } + + /* Dynamic value */ + info->exposure_time_numerator = exif_struct.exposure_time_numerator; + info->exposure_time_denominator = exif_struct.exposure_time_denominator; + info->shutter_speed_numerator = exif_struct.shutter_speed_numerator; + info->shutter_speed_denominator = exif_struct.shutter_speed_denominator; + info->brigtness_numerator = exif_struct.brigtness_numerator; + info->brightness_denominator = exif_struct.brightness_denominator; + info->iso = exif_struct.iso; + info->flash = exif_struct.flash; + info->metering_mode = exif_struct.metering_mode; + info->exif_image_width = exif_struct.exif_image_width; + info->exif_image_height = exif_struct.exif_image_height; + info->software_used = exif_struct.software_used; + info->exposure_bias_in_APEX = exif_struct.exposure_bias_in_APEX; + + /* Fixed value */ + info->component_configuration = exif_struct.component_configuration; + info->colorspace = exif_struct.colorspace; + info->max_lens_aperture_in_APEX = exif_struct.max_lens_aperture_in_APEX; + + info->focal_len_numerator = exif_struct.focal_len_numerator; + info->focal_len_denominator = exif_struct.focal_len_denominator; + info->aperture_f_num_numerator = exif_struct.aperture_f_num_numerator; + info->aperture_f_num_denominator = exif_struct.aperture_f_num_denominator; + info->aperture_in_APEX = exif_struct.aperture_in_APEX; + + return TRUE; +} + +gboolean gst_camerasrc_control_get_basic_dev_info (GstCameraSrc *camerasrc, gint dev_id, GstCameraControlCapsInfoType *info) +{ + gst_camerasrc_debug("get basic dev info"); + + int error = CAMERASRC_ERROR; + + g_return_val_if_fail(camerasrc, FALSE); + + /** + * Just implementation issue, but at this time, we assume + * GstCameraControlCapsInfoType is exactly same with camerasrc_caps_info_t + * For performance. + * Here is plugin code. we can do like this? + */ +#if 1 + error = camerasrc_read_basic_dev_info(dev_id, (camerasrc_caps_info_t*)info); + if (error != CAMERASRC_SUCCESS) { + return FALSE; + } +#else + int i, j, k; + camerasrc_caps_info_t caps_info; + + error = camerasrc_read_basic_dev_info(dev_id, &caps_info); + if (error != CAMERASRC_SUCCESS) { + return FALSE; + } + + if (caps_info.num_fmt_desc != 0) { + info->num_fmt_desc = caps_info.num_fmt_desc; + for (i = 0 ; i < caps_info.num_fmt_desc ; i++) { + if (caps_info.fmt_desc[i].num_resolution != 0) { + info->fmt_desc[i].fcc = caps_info.fmt_desc[i].fcc; + info->fmt_desc[i].num_resolution = caps_info.fmt_desc[i].num_resolution; + for (j = 0 ; j < caps_info.fmt_desc[i].num_resolution ; j++) { + if (caps_info.fmt_desc[i].resolutions[j].num_avail_tpf != 0) { + info->fmt_desc[i].resolutions[j].w = caps_info.fmt_desc[i].resolutions[j].w; + info->fmt_desc[i].resolutions[j].h = caps_info.fmt_desc[i].resolutions[j].h; + info->fmt_desc[i].resolutions[j].num_avail_tpf = caps_info.fmt_desc[i].resolutions[j].num_avail_tpf; + for (k = 0 ; k < caps_info.fmt_desc[i].resolutions[j].num_avail_tpf ; k++) { + info->fmt_desc[i].resolutions[j].tpf[k].num = caps_info.fmt_desc[i].resolutions[j].tpf[k].num; + info->fmt_desc[i].resolutions[j].tpf[k].den = caps_info.fmt_desc[i].resolutions[j].tpf[k].den; + } + } else { + /* No available timeperframe */ + return FALSE; + } + } + } else { + /* No available resolution set */ + return FALSE; + } + } + } else { + /* No available image format(fourcc) */ + return FALSE; + } +#endif + return TRUE; +} + +gboolean gst_camerasrc_control_get_misc_dev_info(GstCameraSrc *camerasrc, gint dev_id, GstCameraControlCtrlListInfoType *info) +{ + gst_camerasrc_debug("get misc dev info"); + + int error = CAMERASRC_ERROR; + + g_return_val_if_fail(camerasrc, FALSE); + + /** + * Just implementation issue, but at this time, we assume + * GstCameraControlCtrlListInfoType is exactly same with camerasrc_ctrl_list_info_t + * For performance. + * Here is plugin code. we can do like this? + */ +#if 1 + error = camerasrc_read_misc_dev_info(dev_id, (camerasrc_ctrl_list_info_t*)info); + if (error != CAMERASRC_SUCCESS) { + return FALSE; + } +#else + int i, j; + camerasrc_ctrl_list_info_t ctrl_info; + + error = camerasrc_read_misc_dev_info(dev_id, &ctrl_info); + if (error != CAMERASRC_SUCCESS) { + return FALSE; + } + + if (ctrl_info.num_ctrl_list_info != 0) { + info->num_ctrl_list_info = ctrl_info.num_ctrl_list_info; + for (i = 0 ; i < ctrl_info.num_ctrl_list_info ; i++) { + info->ctrl_info[i].camerasrc_ctrl_id = ctrl_info.ctrl_info[i].camerasrc_ctrl_id; + info->ctrl_info[i].v4l2_ctrl_id = ctrl_info.ctrl_info[i].v4l2_ctrl_id; + info->ctrl_info[i].ctrl_type = ctrl_info.ctrl_info[i].ctrl_type; + info->ctrl_info[i].max = ctrl_info.ctrl_info[i].max; + info->ctrl_info[i].min = ctrl_info.ctrl_info[i].min; + info->ctrl_info[i].step = ctrl_info.ctrl_info[i].step; + info->ctrl_info[i].default_val = ctrl_info.ctrl_info[i].default_val; + info->ctrl_info[i].num_ctrl_menu = ctrl_info.ctrl_info[i].num_ctrl_menu; + + memcpy(info->ctrl_info[i].ctrl_name,ctrl_info.ctrl_info[i].ctrl_name,MAX_SZ_CTRL_NAME_STRING); + + if (ctrl_info.ctrl_info[i].ctrl_type == CTRL_TYPE_ARRAY && ctrl_info.ctrl_info[i].num_ctrl_menu != 0) { + for (j = 0 ; j < ctrl_info.ctrl_info[i].num_ctrl_menu ; j++) { + info->ctrl_info[i].ctrl_menu[j].menu_index = ctrl_info.ctrl_info[i].ctrl_menu[j].menu_index; + memcpy(info->ctrl_info[i].ctrl_menu[j].menu_name, ctrl_info.ctrl_info[i].ctrl_menu[j].menu_name, MAX_SZ_CTRL_NAME_STRING); + } + } else { + /* Not a menu type or not available menus */ + return FALSE; + } + } + } else { + /* Not avaliable controls */ + return FALSE; + } +#endif + return TRUE; +} + +gboolean gst_camerasrc_control_get_extra_dev_info(GstCameraSrc *camerasrc, gint dev_id, GstCameraControlExtraInfoType *info) +{ + int error = CAMERASRC_ERROR; + + g_return_val_if_fail(camerasrc, FALSE); + + gst_camerasrc_debug("get extra dev info"); + + /** + * Just implementation issue, but at this time, we assume + * GstCameraControlCtrlListInfoType is exactly same with camerasrc_ctrl_list_info_t + * For performance. + * Here is plugin code. we can do like this? + */ + + error = camerasrc_read_extra_dev_info(dev_id, (camerasrc_extra_info_t*)info); + if (error != CAMERASRC_SUCCESS) { + return FALSE; + } + + return TRUE; +} + +void gst_camerasrc_control_set_capture_command(GstCameraSrc *camerasrc, GstCameraControlCaptureCommand cmd) +{ + gst_camerasrc_debug("set capture command"); + + if (camerasrc == NULL) { + gst_camerasrc_debug("camerasrc is NULL"); + return; + } + + gst_camerasrc_set_capture_command(camerasrc, cmd); + + return; +} diff --git a/camerasrc/src/include/camerasrc-common.h b/camerasrc/src/include/camerasrc-common.h new file mode 100644 index 0000000..39da122 --- /dev/null +++ b/camerasrc/src/include/camerasrc-common.h @@ -0,0 +1,451 @@ +/* + * camerasrc + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jeongmo Yang <jm80.yang@samsung.com> + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __CAMERASRC_COMMON_H__ +#define __CAMERASRC_COMMON_H__ + +#include <stdio.h> +#include <malloc.h> +#include <pthread.h> +#include <errno.h> /*EXXX*/ +#include <sys/ioctl.h> /*ioctl*/ +#include <string.h> /*memcpy*/ + +#include <sys/types.h> /*open*/ +#include <sys/stat.h> +#include <fcntl.h> + +#include <unistd.h> /*mmap*/ +#include <sys/mman.h> /*alloc series, free..*/ +#include <sys/time.h> /*gettimeofday*/ +#include <math.h> /*log2*/ +#include <gst/gst.h> + +#undef __ASM_ARM_TYPES_H +#undef __ASSEMBLY_ +#undef _I386_TYPES_H + +#include <asm/types.h> +#include <linux/videodev2.h> /* V4L2 APIs */ +#include <linux/media.h> + +#include "camerasrc.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * Memory utility definitions + */ +#if !defined (PAGE_SHIFT) + #define PAGE_SHIFT sysconf(_SC_PAGESIZE) +#endif +#if !defined (PAGE_SIZE) + #define PAGE_SIZE (1UL << PAGE_SHIFT) +#endif +#if !defined (PAGE_MASK) + #define PAGE_MASK (~(PAGE_SIZE-1)) +#endif + +#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK) +#define CLEAR(x) memset (&(x), 0, sizeof (x)) + +#define CAMERASRC_MAX_WIDTH 2560 +#define CAMERASRC_MAX_HEIGHT 1920 +#define CAMERASRC_CID_NOT_SUPPORT -1 +#define CAMERASRC_USRPTR_MAX_BUFFER_NUM 12 +#define CAMERASRC_ERRMSG_MAX_LEN 128 +#define CAMERASRC_PRIMARY_BASIC_INFO_PATH "/tmp/.camprimarybasicinfo" +#define CAMERASRC_PRIMARY_MISC_INFO_PATH "/tmp/.camprimarymiscinfo" +#define CAMERASRC_PRIMARY_EXTRA_INFO_PATH "/tmp/.camprimaryextrainfo" +#define CAMERASRC_SECONDARY_BASIC_INFO_PATH "/tmp/.camsecondarybasicinfo" +#define CAMERASRC_SECONDARY_MISC_INFO_PATH "/tmp/.camsecondarymiscinfo" +#define CAMERASRC_SECONDARY_EXTRA_INFO_PATH "/tmp/.camsecondaryextrainfo" +#define CAMERASRC_MAX_IMAGE_BUFFER_PLANES 3 + +//#define USE_OPEN_CHK /*< Using open check with temporary file */ +#define USE_SENSOR_MODE 0 +/*#define USE_SKIP_FRAME*/ /*< Skip frame toggle */ +/*#define USE_IOCTL_DEBUG*/ /*< For debugging ioctl name, argument, address, etc */ +/*#define USE_FRAME_COPY_BOUNDARY_CHECK*/ /*< Copy boundary checks occurs seg fault when overrun */ +/*#define USE_SKIP_FRAME_AT_RAW_FRAME*/ /*< In pumping raw frame, initial 2-3 frames are darker. so skip it */ +/*#define USE_CAMERASRC_FRAME_DUMP*/ /*< Debug system annoying me. Use printf!!!! */ +/*#define USE_USERPTR_DEBUG*/ +/*#define ENABLE_Q_ERROR*/ + +#ifndef GST_CAT_DEFAULT +GST_DEBUG_CATEGORY_EXTERN(camerasrc_debug); +#define GST_CAT_DEFAULT camerasrc_debug +#endif /* GST_CAT_DEFAULT */ + + +#define camsrc_log(msg, args...) GST_LOG(msg, ##args) +#define camsrc_debug(msg, args...) GST_DEBUG(msg, ##args) +#define camsrc_info(msg, args...) GST_INFO(msg, ##args) +#define camsrc_warning(msg, args...) GST_WARNING(msg, ##args) +#define camsrc_error(msg, args...) GST_ERROR(msg, ##args) +#define camsrc_critical(msg, args...) GST_ERROR(msg, ##args) +#define camsrc_assert(condition) { \ + if (!(condition)) { \ + GST_ERROR("failed [%s]", #condition); \ + } \ +} + +#define SET_CTRL_VAL(cid, in_value) {\ + int err = CAMERASRC_ERR_UNKNOWN;\ + struct v4l2_control control;\ + control.id = cid;\ + control.value = in_value;\ + camsrc_log("[VIDIOC_S_CTRL] >> [%x] request with value %d", cid, in_value); \ + err = _camerasrc_ioctl(handle, handle->fd_sensor, VIDIOC_S_CTRL, &control);\ + if(err != CAMERASRC_SUCCESS) {\ + return err;\ + }\ +} + +#define GET_CTRL_VAL(cid, ret_value) {\ + int err = CAMERASRC_ERR_UNKNOWN;\ + struct v4l2_control control;\ + control.id = cid;\ + err = _camerasrc_ioctl(handle, handle->fd_sensor, VIDIOC_G_CTRL, &control);\ + if(err != CAMERASRC_SUCCESS) {\ + return err;\ + }\ + ret_value = control.value;\ + camsrc_log("[VIDIOC_G_CTRL] << [%x] request with value %d", cid, ret_value); \ +} + +#define SET_CTRL_VAL_ERR(cid, in_value, err) {\ + struct v4l2_control control;\ + control.id = cid;\ + control.value = in_value;\ + camsrc_log("[VIDIOC_S_CTRL] >> [%x] request with value %d", cid, in_value); \ + _camerasrc_ioctl_with_err(handle, VIDIOC_S_CTRL, &control, &err);\ +} + +#define GET_CTRL_VAL_ERR(cid, ret_value, err) {\ + struct v4l2_control control;\ + control.id = cid;\ + _camerasrc_ioctl_with_err(handle, VIDIOC_G_CTRL, &control, &err);\ + ret_value = control.value;\ + camsrc_log("[VIDIOC_G_CTRL] << [%x] request with value %d", cid, ret_value); \ +} + +/* + * Values for internal + */ +enum camerasrc_op_mode_t { + CAMERASRC_OP_PREVIEW = 0, + CAMERASRC_OP_CAPTURE, + CAMERASRC_OP_VIDEO, + CAMERASRC_OP_REGISTER_VALUE, + CAMERASRC_OP_NUM, +}; + +/* + * Values for internal + */ +enum camerasrc_ctrl_property_t{ + CAMERASRC_CTRL_SUPPORT = 0, + CAMERASRC_CTRL_MAX_VALUE, + CAMERASRC_CTRL_MIN_VALUE, + CAMERASRC_CTRL_CID_VALUE, + CAMERASRC_CTRL_CURRENT_VALUE, + CAMERASRC_CTRL_PROPERTY_NUM, +}; + +/* + * Values for internal + */ +enum camerasrc_quality_t{ + CAMERASRC_QUALITY_NORMAL = 0, + CAMERASRC_QUALITY_HIGH, + CAMERASRC_QUALITY_NUM, +}; + +enum camerasrc_dev_recog_t{ + CAMERASRC_DEV_RECOG_ID = 0, + CAMERASRC_DEV_RECOG_INDEX, + CAMERASRC_DEV_RECOG_NUM, +}; + +/** + * Phase, camerasrc consist of two phase, running and non-running. + */ +typedef enum { + CAMERASRC_PHASE_RUNNING = 0, + CAMERASRC_PHASE_NON_RUNNING, + CAMERASRC_PHASE_NUM, +} _camerasrc_phase_t; + +typedef enum { + CAMERASRC_MISC_STILL_SIGNAL = 0, + CAMERASRC_MISC_SKIP_FRAME, + CAMERASRC_MISC_FUNC_NUM, +} _camerasrc_misc_func_t; + +typedef enum{ + _CAMERASRC_CMD_AF_CONTROL = 0, + _CAMERASRC_CMD_AF_AREA, + _CAMERASRC_CMD_STROBE_MODE, + _CAMERASRC_CMD_SHUTTER_SPEED, + _CAMERASRC_CMD_EXPOSURE_VALUE, + _CAMERASRC_CMD_FRAME_DATA, + _CAMERASRC_CMD_EXIF_INFO, + _CAMERASRC_CMD_CTRL, + _CAMERASRC_CMD_ROTATION, + _CAMERASRC_CMD_VFLIP, + _CAMERASRC_CMD_HFLIP, + _CAMERASRC_CMD_NUM, +}_camsrc_cmd_t; + +typedef struct{ + int cid; + int value; +} _camerasrc_ctrl_t; + +enum { + _CAMERASRC_AF_START = 0, + _CAMERASRC_AF_STOP, + _CAMERASRC_AF_RELEASE, + _CAMERASRC_AF_INIT, + _CAMERASRC_AF_DESTROY, + _CAMERASRC_AF_RESULT, +}; + +// U T I L I T Y D E F I N I T I O N +/** + * Utility definitions + */ +#define CAMERASRC_SET_STATE(handle, state) { \ + handle->prev_state = handle->cur_state; \ + handle->cur_state = state; \ + camsrc_info("Set state [%d] -> [%d]", handle->prev_state, handle->cur_state); \ +} +#define CAMERASRC_SET_PHASE(handle, phase) handle->cur_phase = phase; +#define CAMERASRC_STATE(handle) (handle->cur_state) +#define CAMERASRC_PREV_STREAM_STATE(handle) -1 +#define CAMERASRC_PHASE(handle) (handle->cur_phase) +#define CAMERASRC_HANDLE(handle) ((camerasrc_handle_t*) handle) +#define CAMERASRC_CURRENT_DEV_ID(handle) (handle->dev_id) + +#define YUV422_SIZE(handle) ((handle->format.img_size.dim.height * handle->format.img_size.dim.width) << 1) +#define YUV420_SIZE(handle) ((handle->format.img_size.dim.height * handle->format.img_size.dim.width * 3) >> 1) +#define RGB565_SIZE(handle) ((handle->format.img_size.dim.height * handle->format.img_size.dim.width) << 1) + +#define ISO_APPROXIMATE_VALUE(iso_in, iso_approximated) { \ + if(iso_in > 8.909 && iso_in <= 11.22) iso_approximated = 10; \ + else if(iso_in > 11.22 && iso_in <= 14.14) iso_approximated = 12; \ + else if(iso_in > 14.14 && iso_in <= 17.82) iso_approximated = 16; \ + else if(iso_in > 17.82 && iso_in <= 22.45) iso_approximated = 20; \ + else if(iso_in > 22.45 && iso_in <= 28.28) iso_approximated = 25; \ + else if(iso_in > 28.28 && iso_in <= 35.64) iso_approximated = 32; \ + else if(iso_in > 35.64 && iso_in <= 44.90) iso_approximated = 40; \ + else if(iso_in > 44.90 && iso_in <= 56.57) iso_approximated = 50; \ + else if(iso_in > 56.57 && iso_in <= 71.27) iso_approximated = 64; \ + else if(iso_in > 71.27 && iso_in <= 89.09) iso_approximated = 80; \ + else if(iso_in > 89.09 && iso_in <= 112.2) iso_approximated = 100; \ + else if(iso_in > 112.2 && iso_in <= 141.4) iso_approximated = 125; \ + else if(iso_in > 141.4 && iso_in <= 178.2) iso_approximated = 160; \ + else if(iso_in > 178.2 && iso_in <= 224.5) iso_approximated = 200; \ + else if(iso_in > 224.5 && iso_in <= 282.8) iso_approximated = 250; \ + else if(iso_in > 282.8 && iso_in <= 356.4) iso_approximated = 320; \ + else if(iso_in > 356.4 && iso_in <= 449.0) iso_approximated = 400; \ + else if(iso_in > 449.0 && iso_in <= 565.7) iso_approximated = 500; \ + else if(iso_in > 565.7 && iso_in <= 712.7) iso_approximated = 640; \ + else if(iso_in > 712.7 && iso_in <= 890.9) iso_approximated = 800; \ + else if(iso_in > 890.9 && iso_in <= 1122) iso_approximated = 1000; \ + else if(iso_in > 1122 && iso_in <= 1414) iso_approximated = 1250; \ + else if(iso_in > 1414 && iso_in <= 1782) iso_approximated = 1600; \ + else if(iso_in > 1782 && iso_in <= 2245) iso_approximated = 2000; \ + else if(iso_in > 2245 && iso_in <= 2828) iso_approximated = 2500; \ + else if(iso_in > 2828 && iso_in <= 3564) iso_approximated = 3200; \ + else if(iso_in > 3564 && iso_in <= 4490) iso_approximated = 4000; \ + else if(iso_in > 4490 && iso_in <= 5657) iso_approximated = 5000; \ + else if(iso_in > 5657 && iso_in <= 7127) iso_approximated = 6400; \ + else if(iso_in > 7127 && iso_in <= 8909) iso_approximated = 8000; \ + else { \ + camsrc_warning("Invalid parameter(Maybe kernel failure).. give default value, 100");\ + iso_approximated = 100;\ + }\ +} + +#define PHOTOMETRY_MODE_TO_METERING_MODE(photometry_mode, metering_mode) { \ + if(photometry_mode == V4L2_EXPOSURE_METERING_MATRIX) metering_mode = 1; \ + else if (photometry_mode == V4L2_EXPOSURE_METERING_CENTER_WEIGHTED) metering_mode = 2; \ + else if (photometry_mode == V4L2_EXPOSURE_METERING_SPOT) metering_mode = 3; \ + else metering_mode = 1; \ +} + +#define CAMERASRC_EXIF_SHUTTERSPEED_VALUE_IN_APEX(NUM, DEN) (int)(-(log2((double)((double)NUM/(double)DEN)))) +#define CAMERASRC_EXIF_APERTURE_VALUE_IN_APEX(NUM, DEN) (int)(2 * (log2((double)((double)NUM/(double)DEN))) + 0.5) + +/* for media device */ +#define LENGTH_DEV_NAME 32 + +typedef struct _media_entity_t media_entity_t; +typedef struct _media_pad_t media_pad_t; +typedef struct _media_link_t media_link_t; +typedef struct _media_device_t media_device_t; + +struct _media_entity_t { + media_device_t *media; + struct media_entity_desc info; + media_pad_t *pads; + media_link_t *links; + unsigned int max_links; + unsigned int num_links; + char devname[LENGTH_DEV_NAME]; + int fd; + __u32 padding[6]; +}; + +struct _media_pad_t { + media_entity_t *entity; + __u32 index; + __u32 flags; + __u32 padding[3]; +}; + +struct _media_link_t { + media_pad_t *source; + media_pad_t *sink; + media_link_t *twin; + __u32 flags; + __u32 padding[3]; +}; + +struct _media_device_t { + int fd; + media_entity_t *entities; + unsigned int entities_count; + void (*debug_handler)(void *, ...); + void *debug_priv; + __u32 padding[6]; +}; + + +typedef void *(*camerasrc_signal_func_t) (camsrc_handle_t handle); +typedef int (*camerasrc_skip_frame_func_t) (camsrc_handle_t handle, long int timeout, int skip_frame); + +typedef struct _camerasrc_handle_t { + /* device information */ + int cur_dev_id; + int errnum; + + /* fd list */ + int fd_companion; + int fd_sensor; + int fd_isp; + int fd_3aa1; + int fd_3aa1c; + int fd_scc; + int fd_scp; + + int streamon_sensor; + int streamon_3aa1_output; + int streamon_3aa1_capture; + int streamon_isp; + int streamon_scc; + int streamon_scp; + int streamon_sensor_sub; + + int reqbuf_sensor; + int reqbuf_3aa1_output; + int reqbuf_3aa1_capture; + int reqbuf_isp; + int reqbuf_scc; + int reqbuf_scp; + + int request_count; + + /* state information */ + int prev_stream_state; + int prev_state; + int cur_state; + int cur_phase; + + /* image format information */ + int is_highquality; + camerasrc_format_t format_sensor; + camerasrc_format_t format_3aa1; + camerasrc_format_t format_isp; + camerasrc_format_t format_scc; + camerasrc_format_t format_scp; + + /* buffer information */ + guint buffer_idx; + guint queued_buffer_count; + int first_frame; + struct v4l2_buffer queued_buf_list[CAMERASRC_USRPTR_MAX_BUFFER_NUM]; + camerasrc_buffer_t *buffer_sensor; + camerasrc_buffer_t *buffer_isp; + camerasrc_buffer_t *buffer_scc; + camerasrc_buffer_t *buffer_scp; + camerasrc_buffer_t scrnl_buf; /* screennail buffer of captured JPEG image */ + + /* autofocusing information */ + camerasrc_af_mode_t cur_af_mode; + camerasrc_af_scan_range_t cur_af_range; + camerasrc_callback_t af_cb; + pthread_t focusing_thread; + pthread_cond_t af_wait_cond; + camerasrc_auto_focus_status_t af_status; + camerasrc_auto_focus_cmd_t af_cmd; + int af_dev_val; + void *af_usr_data; + + /* Jpg Still information */ + camerasrc_exif_info_t current_exif; /* EXIF info of current captured image */ + + /* fps */ + camerasrc_frac_t timeperframe; + + /* flip */ + int vflip; + int hflip; + + /* thread safe mechanism */ + pthread_mutex_t mutex; + pthread_mutex_t af_mutex; + pthread_cond_t cond; + + /* TBM */ + tbm_bufmgr bufmgr; +} camerasrc_handle_t; + +typedef struct { + int (*_ioctl) (camerasrc_handle_t *handle, int fd, int request, void *arg); + int (*_ioctl_once) (camerasrc_handle_t *handle, int request, void *arg); + void *(*_run_autofocusing) (camerasrc_handle_t *handle); + int (*_set_cmd) (camerasrc_handle_t *handle, _camsrc_cmd_t cmd, void *value); + int (*_get_cmd) (camerasrc_handle_t *handle, _camsrc_cmd_t cmd, void *value); +} CAMERASRC_DEV_DEPENDENT_MISC_FUNC; + +#ifdef __cplusplus +} +#endif + +#endif /*__CAMERASRC_COMMON_H__*/ diff --git a/camerasrc/src/include/camerasrc-error.h b/camerasrc/src/include/camerasrc-error.h new file mode 100644 index 0000000..4ea8c7f --- /dev/null +++ b/camerasrc/src/include/camerasrc-error.h @@ -0,0 +1,140 @@ +/* + * camerasrc + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jeongmo Yang <jm80.yang@samsung.com> + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __CAMERASRC_ERROR_H__ +#define __CAMERASRC_ERROR_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * CAMSRC CLASS + */ +#define CAMERASRC_SUCCESS (0x00000000) /**< No Error */ +#define CAMERASRC_ERROR (0x80000000) /**< Error Class */ +#define CAMERASRC_WARING (0x70000000) /**< Waring Class */ + +/* + * Detail enumeration + */ +enum { + CAMSRC_IN_UNKNOWN = 0, + CAMSRC_IN_PARAMETER, + CAMSRC_IN_HANDLE, + CAMSRC_IN_POINTER, + CAMSRC_IN_VALUE, + CAMSRC_IN_OVERRUN, + CAMSRC_IN_UNDERRUN, + CAMSRC_IN_RANGE_OVER, + CAMSRC_IN_RANGE_UNDER, + CAMSRC_IN_MODE, + CAMSRC_IN_FORMAT, + CAMSRC_IN_CHANNEL, + CAMSRC_IN_SAMPLERATE, + CAMSRC_IN_LAYER, + CAMSRC_IN_ROTATE, + CAMSRC_IN_ALLOC, + CAMSRC_IN_INTERNAL, + /*Extra state for camera*/ + CAMSRC_IN_IO_CONTROL, + CAMSRC_IN_DEVICE_OPEN, + CAMSRC_IN_DEVICE_BUSY, + CAMSRC_IN_DEVICE_NOT_FOUND, + CAMSRC_IN_DEVICE_REGISTER_TROUBLE, + CAMSRC_IN_WAIT_RES, + CAMSRC_IN_SUPPORT, + CAMSRC_IN_STATE, + CAMSRC_IN_PRIVILEGE, + CAMSRC_IN_SECURITY_SERVICE, +}; + +/* + * CAMERASRC_WARNING + */ +#define CAMERASRC_WAR_INVALID_PARAMETER (CAMERASRC_WARING | CAMSRC_IN_PARAMETER) +#define CAMERASRC_WAR_INVALID_HANDLE (CAMERASRC_WARING | CAMSRC_IN_HANDLE) +#define CAMERASRC_WAR_INVALID_VALUE (CAMERASRC_WARING | CAMSRC_IN_VALUE) +#define CAMERASRC_WAR_INVALID_MODE (CAMERASRC_WARING | CAMSRC_IN_MODE) +#define CAMERASRC_WAR_INVALID_FORMAT (CAMERASRC_WARING | CAMSRC_IN_FORMAT) +#define CAMERASRC_WAR_INVALID_CHANNEL (CAMERASRC_WARING | CAMSRC_IN_CHANNEL) +#define CAMERASRC_WAR_INVALID_SAMPLERATE (CAMERASRC_WARING | CAMSRC_IN_SAMPLERATE) +#define CAMERASRC_WAR_INVALID_LAYER (CAMERASRC_WARING | CAMSRC_IN_LAYER) +#define CAMERASRC_WAR_INVALID_ROTATE (CAMERASRC_WARING | CAMSRC_IN_ROTATE) +#define CAMERASRC_WAR_NULL_POINTER (CAMERASRC_WARING | CAMSRC_IN_POINTER) +#define CAMERASRC_WAR_UNDERRUN (CAMERASRC_WARING | CAMSRC_IN_UNDERRUN) +#define CAMERASRC_WAR_OVERRUN (CAMERASRC_WARING | CAMSRC_IN_OVERRUN) +#define CAMERASRC_WAR_RANGE_OVER (CAMERASRC_WARING | CAMSRC_IN_RANGE_OVER) +#define CAMERASRC_WAR_RANGE_UNDER (CAMERASRC_WARING | CAMSRC_IN_RANGE_UNDER) +#define CAMERASRC_WAR_ALLOCATION (CAMERASRC_WARING | CAMSRC_IN_ALLOC) +#define CAMERASRC_WAR_INTERNAL (CAMERASRC_WARING | CAMSRC_IN_INTERNAL) +/*Extra warning for camera*/ +#define CAMERASRC_WAR_IO_CONTROL (CAMERASRC_WARING | CAMSRC_IN_IO_CONTROL) +#define CAMERASRC_WAR_DEVICE_OPEN (CAMERASRC_WARING | CAMSRC_IN_DEVICE_OPEN) +#define CAMERASRC_WAR_DEVICE_BUSY (CAMERASRC_WARING | CAMSRC_IN_DEVICE_BUSY) +#define CAMERASRC_WAR_DEVICE_NOT_FOUND (CAMERASRC_WARING | CAMSRC_IN_DEVICE_NOT_FOUND) +#define CAMERASRC_WAR_DEVICE_UNAVAILABLE (CAMERASRC_WARING | CAMSRC_IN_DEVICE_REGISTER_TROUBLE) +#define CAMERASRC_WAR_DEVICE_WAIT_TIMEOUT (CAMERASRC_WARING | CAMSRC_IN_WAIT_RES) +#define CAMERASRC_WAR_DEVICE_NOT_SUPPORT (CAMERASRC_WARING | CAMSRC_IN_SUPPORT) +#define CAMERASRC_WAR_INVALID_STATE_TRANSITION (CAMERASRC_WARING | CAMSRC_IN_STATE) + +/** + * CAMERASRC_ERROR + */ +#define CAMERASRC_ERR_INVALID_PARAMETER (CAMERASRC_ERROR | CAMSRC_IN_PARAMETER) +#define CAMERASRC_ERR_INVALID_HANDLE (CAMERASRC_ERROR | CAMSRC_IN_HANDLE) +#define CAMERASRC_ERR_INVALID_VALUE (CAMERASRC_ERROR | CAMSRC_IN_VALUE) +#define CAMERASRC_ERR_INVALID_MODE (CAMERASRC_ERROR | CAMSRC_IN_MODE) +#define CAMERASRC_ERR_INVALID_FORMAT (CAMERASRC_ERROR | CAMSRC_IN_FORMAT) +#define CAMERASRC_ERR_INVALID_CHANNEL (CAMERASRC_ERROR | CAMSRC_IN_CHANNEL) +#define CAMERASRC_ERR_INVALID_SAMPLERATE (CAMERASRC_ERROR | CAMSRC_IN_SAMPLERATE) +#define CAMERASRC_ERR_INVALID_LAYER (CAMERASRC_ERROR | CAMSRC_IN_LAYER) +#define CAMERASRC_ERR_INVALID_ROTATE (CAMERASRC_ERROR | CAMSRC_IN_ROTATE) +#define CAMERASRC_ERR_NULL_POINTER (CAMERASRC_ERROR | CAMSRC_IN_POINTER) +#define CAMERASRC_ERR_UNDERRUN (CAMERASRC_ERROR | CAMSRC_IN_UNDERRUN) +#define CAMERASRC_ERR_OVERRUN (CAMERASRC_ERROR | CAMSRC_IN_OVERRUN) +#define CAMERASRC_ERR_RANGE_OVER (CAMERASRC_ERROR | CAMSRC_IN_RANGE_OVER) +#define CAMERASRC_ERR_RANGE_UNDER (CAMERASRC_ERROR | CAMSRC_IN_RANGE_UNDER) +#define CAMERASRC_ERR_ALLOCATION (CAMERASRC_ERROR | CAMSRC_IN_ALLOC) +#define CAMERASRC_ERR_INTERNAL (CAMERASRC_ERROR | CAMSRC_IN_INTERNAL) +#define CAMERASRC_ERR_UNKNOWN (CAMERASRC_ERROR | CAMSRC_IN_UNKNOWN) /**< unknown error */ +/*Extra warning for camera*/ +#define CAMERASRC_ERR_IO_CONTROL (CAMERASRC_ERROR | CAMSRC_IN_IO_CONTROL) +#define CAMERASRC_ERR_DEVICE_OPEN (CAMERASRC_ERROR | CAMSRC_IN_DEVICE_OPEN) +#define CAMERASRC_ERR_DEVICE_BUSY (CAMERASRC_ERROR | CAMSRC_IN_DEVICE_BUSY) +#define CAMERASRC_ERR_DEVICE_NOT_FOUND (CAMERASRC_ERROR | CAMSRC_IN_DEVICE_NOT_FOUND) +#define CAMERASRC_ERR_DEVICE_UNAVAILABLE (CAMERASRC_ERROR | CAMSRC_IN_DEVICE_REGISTER_TROUBLE) +#define CAMERASRC_ERR_DEVICE_WAIT_TIMEOUT (CAMERASRC_ERROR | CAMSRC_IN_WAIT_RES) +#define CAMERASRC_ERR_DEVICE_NOT_SUPPORT (CAMERASRC_ERROR | CAMSRC_IN_SUPPORT) +#define CAMERASRC_ERR_INVALID_STATE (CAMERASRC_ERROR | CAMSRC_IN_STATE) +#define CAMERASRC_ERR_PRIVILEGE (CAMERASRC_ERROR | CAMSRC_IN_PRIVILEGE) +#define CAMERASRC_ERR_SECURITY_SERVICE (CAMERASRC_ERROR | CAMSRC_IN_SECURITY_SERVICE) + + +#define CAMERASRC_IS_FAIL(_A_) (CAMERASRC_ERROR & (_A_)) + +#ifdef __cplusplus +} +#endif + +#endif /* __CAMERASRC_ERROR_H__ */ diff --git a/camerasrc/src/include/camerasrc-internal.h b/camerasrc/src/include/camerasrc-internal.h new file mode 100644 index 0000000..863aebc --- /dev/null +++ b/camerasrc/src/include/camerasrc-internal.h @@ -0,0 +1,65 @@ +/* + * camerasrc + * + * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jeongmo Yang <jm80.yang@samsung.com> + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __CAMERASRC_INTERNAL_H__ +#define __CAMERASRC_INTERNAL_H__ + +#include "camerasrc-common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Video 4 linux control ID definitions (Extended by kernel team) + * extended pixel format for V4l2 + */ + + +/** + * Miscellaneous camera-dependent definitions + */ +#define CAMERASRC_AF_INTERVAL 20000 +#define CAMERASRC_TIMEOUT_CRITICAL_VALUE 3000 + +/* EXIF */ +#define EXIF_DEFAULT_SHUTTER_SPEED_DENOMINATOR 256 +#define EXIF_DEFAULT_EXPOSURE_TIME_NUMERATOR 1 +#define EXIF_DEFAULT_BRIGHTNESS_DENOMINATOR 256 +#define EXIF_DEFAULT_ISO_SPEED_RATING 100 +#define EXIF_DEFAULT_FNUMBER_NUMERATOR_REAR 26 +#define EXIF_DEFAULT_FNUMBER_DENOMINATOR_REAR 10 +#define EXIF_DEFAULT_FNUMBER_NUMERATOR_FRONT 28 +#define EXIF_DEFAULT_FNUMBER_DENOMINATOR_FRONT 10 +#define EXIF_DEFAULT_FOCAL_LENGTH_NUMERATOR_REAR 37 +#define EXIF_DEFAULT_FOCAL_LENGTH_DENOMINATOR_REAR 10 +#define EXIF_DEFAULT_FOCAL_LENGTH_NUMERATOR_FRONT 273 +#define EXIF_DEFAULT_FOCAL_LENGTH_DENOMINATOR_FRONT 100 +#define EXIF_DEFAULT_COLOR_SPACE 1 +#define EXIF_DEFAULT_COMPONENT_CONFIGRATION (0x00000000) | (0x00000001) | (0x00000002 << 8) | (0x00000003 << 16) /* Y Cb Cr - */ + +#ifdef __cplusplus +} +#endif + +#endif /*__CAMERASRC_INTERNAL_H__*/ diff --git a/camerasrc/src/include/camerasrc.h b/camerasrc/src/include/camerasrc.h new file mode 100644 index 0000000..6608193 --- /dev/null +++ b/camerasrc/src/include/camerasrc.h @@ -0,0 +1,1293 @@ +/* + * camerasrc + * + * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jeongmo Yang <jm80.yang@samsung.com> + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __CAMERASRC_H__ +#define __CAMERASRC_H__ + +#include <stdint.h> /* to use uint64_t */ +#include <camerasrc-error.h> +#include <gst/video/cameracontrol.h> + +/* for Tizen Buffer Manager */ +#include <exynos_drm.h> +#include <tbm_bufmgr.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#define MAX_FACE_NUM 16 +#define MAX_PLANE_NUM 4 +#define CAMERASRC_PREVIEW_BUFFER_NUM 12 /* number of request buffer when preview */ +#define CAMERASRC_VIDEO_BUFFER_NUM 7 +#define CAMERASRC_STILL_BUFFER_NUM 1 + +#define SPARE_SIZE (2*16 * 1024) +#define BAYER_PLANE_COUNT 2 +#define ISP_PLANE_COUNT 2 +#define SCC_PLANE_COUNT 2 + +/** + * Type definition of av camera src handle. + */ +typedef void *camsrc_handle_t; + + +/* ENUMERATION DEFINITIONS */ +/*! @enum camerasrc_state_t + * @brief Enumeration type for state transition + */ +typedef enum { + CAMERASRC_STATE_NONE = 0, + CAMERASRC_STATE_CREATED, + CAMERASRC_STATE_REALIZED, + CAMERASRC_STATE_READY, + CAMERASRC_STATE_PREVIEW, + CAMERASRC_STATE_STILL, + CAMERASRC_STATE_VIDEO, + CAMERASRC_STATE_UNREALIZED, + CAMERASRC_STATE_DESTROYED, + CAMERASRC_STATE_AF_IN_PROGRESS, +}camerasrc_state_t; + +/*! @enum camerasrc_dev_id_t + * @brief Enumeration type for camera device ID + * + * Devices will be managed by this IDs. (Independent with device index of V4L2) + */ +typedef enum { + CAMERASRC_DEV_ID_PRIMARY, /**< Higher resolution camera*/ + CAMERASRC_DEV_ID_SECONDARY, /**< Lower resolution camera*/ + CAMERASRC_DEV_ID_EXTENSION, /**< reserved for extension*/ + CAMERASRC_DEV_ID_UNKNOWN, /**< reserved for extension*/ + CAMERASRC_DEV_ID_NUM, /**< Number of IDs*/ +}camerasrc_dev_id_t; + +typedef enum { + CAMERASRC_COLOR_VIOLET = 0, + CAMERASRC_COLOR_PURPLE, + CAMERASRC_COLOR_MAGENTA_1, + CAMERASRC_COLOR_MAGENTA_2, + CAMERASRC_COLOR_RED_1, + CAMERASRC_COLOR_RED_2, + CAMERASRC_COLOR_BROWN, + CAMERASRC_COLOR_YELLOW, + CAMERASRC_COLOR_GREEN_1, + CAMERASRC_COLOR_GREEN_2, + CAMERASRC_COLOR_GREEN_3, + CAMERASRC_COLOR_GREEN_4, + CAMERASRC_COLOR_COBALT_BLUE, + CAMERASRC_COLOR_CYAN, + CAMERASRC_COLOR_BLUE_1, + CAMERASRC_COLOR_BLUE_2, + CAMERASRC_COLOR_GRAY, + CAMERASRC_COLOR_NUM, +}camerasrc_color_t; + +typedef enum { + CAMERASRC_PARTCOLOR_MODE_NONE = 0, + CAMERASRC_PARTCOLOR_MODE_SWAP, + CAMERASRC_PARTCOLOR_MODE_ACCENT, + CAMERASRC_PARTCOLOR_MODE_NUM, +}camerasrc_partcolor_mode_t; + +/*! @enum camerasrc_ctrl_t + * @brief Enumeration type for camera controls + * + * Special control entries for camera effects + * + * @remark Strobo can be controlled by this entry and ::camerasrc_set_strobo_status + */ +typedef enum { + CAMERASRC_CTRL_BRIGHTNESS = 0, /**< Brightness control entry*/ + CAMERASRC_CTRL_CONTRAST, /**< Contrast control entry*/ + CAMERASRC_CTRL_DIGITAL_ZOOM, /**< Digital zoom control entry*/ + CAMERASRC_CTRL_OPTICAL_ZOOM, /**< Optical zoom control entry*/ + CAMERASRC_CTRL_WHITE_BALANCE, /**< White balance control entry*/ + CAMERASRC_CTRL_COLOR_TONE, /**< Color tone control entry*/ + CAMERASRC_CTRL_PROGRAM_MODE, /**< Program mode control entry*/ + CAMERASRC_CTRL_FLIP, /**< Flip control entry*/ + CAMERASRC_CTRL_ANTI_HANDSHAKE, /**< Anti-handshake control, 0:OFF / 1:ON / 2:AUTO / 3:MOVIE */ + CAMERASRC_CTRL_WIDE_DYNAMIC_RANGE, /**< wide dynamic control, 0:OFF / 1:ON / 2:AUTO */ + CAMERASRC_CTRL_SATURATION, /**< Saturation value control */ + CAMERASRC_CTRL_SHARPNESS, /**< Sharpness value control */ + CAMERASRC_CTRL_ISO, /**< Sensor sensitivity*/ + CAMERASRC_CTRL_PHOTOMETRY, /**< Exposure mode*/ + CAMERASRC_CTRL_NUM, /**< Number of Controls*/ +}camerasrc_ctrl_t; + +/*! @enum camerasrc_af_mode_t + * @brief AF operation mode + */ +typedef enum { + CAMERASRC_AF_MODE_AUTO = 0, /**< Auto Focus */ + CAMERASRC_AF_MODE_MANUAL, /**< Manual Focus */ + CAMERASRC_AF_MODE_PAN, /**< Pan Focus */ + CAMERASRC_AF_MODE_TOUCH_AUTO, /**< Touch Auto Focus */ + CAMERASRC_AF_MODE_CONTINUOUS, /**< Continuous Focus */ + CAMERASRC_AF_MODE_NUM, /**< Number of AF modes */ +}camerasrc_af_mode_t; + +/*! @enum camerasrc_af_scan_range_t + * @brief AF scan range + * AF scan range + */ +typedef enum { + CAMERASRC_AF_RANGE_NORMAL = 0, /**< Scan autofocus in normal range */ + CAMERASRC_AF_RANGE_MACRO, /**< Scan autofocus in macro range(close distance) */ + CAMERASRC_AF_RANGE_FULL, /**< Scan autofocus in full range(all range scan, limited by dev spec) */ + CAMERASRC_AF_RANGE_NUM, /**< Number of AF range types */ +}camerasrc_af_scan_range_t; + +/*! @enum camerasrc_resol_name_t + * @brief Enumeration type of resolution settings based on traditional resolution name + * Means pixel order of contents. + * @remark In the Grandprix, only YUV422P & RGGB8 is used + */ +typedef enum { + CAMERASRC_RESOL_QQCIF = 0, /**< 88 x 72 */ + CAMERASRC_RESOL_QQVGA, /**< 160 x 120 */ + CAMERASRC_RESOL_QCIF, /**< 176 x 144 */ + CAMERASRC_RESOL_QVGA, /**< 320 x 240 */ + CAMERASRC_RESOL_CIF, /**< 352 x 288 */ + CAMERASRC_RESOL_VGA, /**< 640 x 480 */ + CAMERASRC_RESOL_WVGA, /**< 800 x 480 */ + CAMERASRC_RESOL_SVGA, /**< 800 x 600 */ + CAMERASRC_RESOL_WSXGA, /**< 1280 x 960 (1M) */ + CAMERASRC_RESOL_UXGA, /**< 1600 x 1200 (2M) */ + CAMERASRC_RESOL_QXGA, /**< 2048 x 1536 (3M) */ + CAMERASRC_RESOL_WQSXGA, /**< 2560 x 1920 (5M) */ + CAMERASRC_RESOL_720P, /**< 1280 x 720 (720P) */ + CAMERASRC_RESOL_WQVGA, /**< 400 x 240 */ + CAMERASRC_RESOL_RQVGA, /**< 240 x 320 */ + CAMERASRC_RESOL_RWQVGA, /**< 240 x 400 */ + CAMERASRC_RESOL_QVGA_60FPS, /**< 320 x 240 60FPS(Slow motion I) */ + CAMERASRC_RESOL_QVGA_120FPS, /**< 320 x 240 60FPS(Slow motion II) */ + CAMERASRC_RESOL_NUM, +}camerasrc_resol_name_t; + +/*! @enum camerasrc_pix_format_t + * @brief Means order of pixel of contents + * Means pixel order of contents. + * @remark In the Grandprix, only YUV422P & RGGB8 is used + */ +typedef enum { + CAMERASRC_PIX_NONE = -1, /**< Default value or Not supported */ + CAMERASRC_PIX_YUV422P = 0, /**< Pixel format like YYYYYYYYUUUUVVVV*/ + CAMERASRC_PIX_YUV420P, /**< Pixel format like YYYYYYYYUUVV*/ + CAMERASRC_PIX_YUV420, /**< Pixel format like YYYYYYYYUVUV*/ + CAMERASRC_PIX_SN12, /**< YUV420 (interleaved, non-linear) */ + CAMERASRC_PIX_YUY2, /**< YUV 4:2:2 as for UYVY but with different component ordering within the u_int32 macropixel */ + CAMERASRC_PIX_RGGB8, /**< Raw RGB Pixel format like CCD order, a pixel consists of 8 bits, Actually means JPEG + JPEG image output */ + CAMERASRC_PIX_RGGB10, /**< Raw RGB Pixel format like CCD order, a pixel consists of 10 bits, Actually means JPEG + YUV image output */ + CAMERASRC_PIX_RGB565, /**< Raw RGB Pixel format like CCD order, a pixel consists of 10 bits, Actually means JPEG + YUV image output */ + CAMERASRC_PIX_SBGGR12, /**< Bayer RGB format : 12 BGBG.. GRGR.. : V4L2_PIX_FMT_SBGGR12 */ + CAMERASRC_PIX_UYVY, /**< YUV 4:2:2 */ + CAMERASRC_PIX_NV12, /**< YUV 4:2:0, 8-bit Y plane followed by an interleaved U/V plane with 2x2 subsampling */ + CAMERASRC_PIX_SN21, /**< YUV420 (interleaved V/U plane, non-linear) */ + CAMERASRC_PIX_NV21, /**< YUV 4:2:0, 8-bit Y plane followed by an interleaved V/U plane with 2x2 subsampling */ + CAMERASRC_PIX_YV12, /**< Pixel format like YYYYYYYYVVUU */ + CAMERASRC_PIX_NUM, /**< Number of pixel formats*/ +}camerasrc_pix_format_t; + +/*! @enum camerasrc_colorspace_t + * @brief Means stored order or compressed status of image. + * Means stored order or compressed status of image. supplements of camerasrc_pix_format_t + * + * @note RAW means RGB/YUV pixel data, JPEG means compressed JPG file with marker information(header) + */ +typedef enum { + CAMERASRC_COL_NONE = -1, /**< Default value or Not supported */ + CAMERASRC_COL_RAW, /**< Non-compressed RGB/YUV pixel data*/ + CAMERASRC_COL_JPEG, /**< Compressed jpg data*/ + CAMERASRC_COL_NUM, /**< Number of colorspace data*/ +}camerasrc_colorspace_t; + +/*! @enum camerasrc_auto_focus_status_t + * @brief AF status + * AF status + */ +typedef enum { + CAMERASRC_AUTO_FOCUS_STATUS_RELEASED, /**< AF status released */ + CAMERASRC_AUTO_FOCUS_STATUS_ONGOING, /**< AF in progress */ + CAMERASRC_AUTO_FOCUS_STATUS_NUM, /**< Number of AF status*/ +}camerasrc_auto_focus_status_t; + +/*! @enum camerasrc_auto_focus_cmd_t + * @brief AF status + * AF status + */ +typedef enum { + CAMERASRC_AUTO_FOCUS_CMD_NULL, /**< Null command */ + CAMERASRC_AUTO_FOCUS_CMD_START, /**< Start AF */ + CAMERASRC_AUTO_FOCUS_CMD_STOP, /**< Stop AF */ + CAMERASRC_AUTO_FOCUS_CMD_KILL, /**< Kill AF thread */ + CAMERASRC_AUTO_FOCUS_CMD_NUM, /**< Number of AF command*/ +}camerasrc_auto_focus_cmd_t; + +/*! @enum camerasrc_auto_focus_result_t + * @brief AF status + * AF status + */ +typedef enum { + CAMERASRC_AUTO_FOCUS_RESULT_RESTART = 0, /**< AF Restart */ + CAMERASRC_AUTO_FOCUS_RESULT_FUCUSING, /**< AF Focusing */ + CAMERASRC_AUTO_FOCUS_RESULT_FOCUSED, /**< AF Focused */ + CAMERASRC_AUTO_FOCUS_RESULT_FAILED, /**< AF failed */ + CAMERASRC_AUTO_FOCUS_RESULT_NUM, /**< Number of AF result */ +}camerasrc_auto_focus_result_t; + +/*! @enum camerasrc_ae_lock_t + * @brief + */ +typedef enum { + CAMERASRC_AE_LOCK = 0, + CAMERASRC_AE_UNLOCK, + CAMERASRC_AE_NUM, +}camerasrc_ae_lock_t; + +/*! @enum camerasrc_io_method_t + * @brief + */ +typedef enum { + CAMERASRC_IO_METHOD_READ= 0, + CAMERASRC_IO_METHOD_MMAP, + CAMERASRC_IO_METHOD_USRPTR, + CAMERASRC_IO_METHOD_DMABUF, + CAMERASRC_IO_METHOD_NUM, +}camerasrc_io_method_t; + +/*! @enum camerasrc_sensor_mode_t + * @brief + */ +typedef enum { + CAMERASRC_SENSOR_MODE_CAMERA = 0, + CAMERASRC_SENSOR_MODE_MOVIE, +} camerasrc_sensor_mode_t; + +/*! @enum camerasrc_buffer_queued_status + * @brief + */ +typedef enum { + CAMERASRC_BUFFER_QUEUED = 0, + CAMERASRC_BUFFER_DEQUEUED = 1, +}camerasrc_buffer_queued_status; + +/* STRUCTURE DEFINITIONS */ + +typedef struct _camerasrc_rect_t { + int x; + int y; + int width; + int height; +} camerasrc_rect_t; + +/*! @struct camsrc_frac_t + * @brief Time per frame or frame per second will be expressed by this structure + * Time per frame or frame per second will be expressed by this structure + */ +typedef struct _camerasrc_frac_t { + int numerator; /**< Upper number of fraction*/ + int denominator; /**< Lower number of fraction*/ +} camerasrc_frac_t; + +/*! @struct camsrc_exif_info_t + * @brief EXIF information in captured image when preview format is Interleaved data + * EXIF information in captured image when preview format is Interleaved data + */ +typedef struct _camerasrc_exif_info_t { + int flash; /**< Flash */ + int iso_speed_rating; /**< ISO Speed Raring */ + camerasrc_frac_t shutter_speed; /**< Shutter Speed */ + camerasrc_frac_t exposure_time; /**< Exposure Time */ + camerasrc_frac_t brightness; /**< Brightness */ +} camerasrc_exif_info_t; + +/*! @struct camerasrc_buffer_t + * @brief data buffer + * Image data buffer + */ +typedef struct _camerasrc_buffer_t { + /* Supports for Planes & DMA-buf */ + struct { + unsigned int length; /**< Size of stored data */ + unsigned char *start; /**< Start address of data */ + int fd; /**< dmabuf-fd */ + tbm_bo bo; /**< tbm buffer object */ + } planes[MAX_PLANE_NUM]; /**< planes: SCMN_IMGB_MAX_PLANE */ + int num_planes; + int width; /**< width of image */ + int height; /**< height of image */ +} camerasrc_buffer_t; + + + +/*! @struct camerasrc_usr_buf_t + * @brief data buffer set to present usrptr buffer to camsrctem + * Image data buffer set + */ +typedef struct { + camerasrc_buffer_t* present_buffer; + unsigned int num_buffer; +} camerasrc_usr_buf_t; + +/*! @struct camerasrc_dimension_t + * @brief For non-regular size resolution + * width and height can be set independently + */ +typedef struct _camerasrc_dimension_t { + int width; + int height; +} camerasrc_dimension_t; + +/*! @union camerasrc_size_t + * @brief Size can be expressed by resolution name(predefined) and dimension(x, y) + */ + +/*! @struct camerasrc_format_t + * @brief Format description structure + * in/output format description structure just like v4l2_format + */ +typedef struct _camerasrc_format_t { + camerasrc_dimension_t img_size; /**< Image size */ + camerasrc_dimension_t capture_size; /**< Capture size */ + camerasrc_dimension_t thumb_size; /**< Thumbnail size */ + camerasrc_pix_format_t pix_format; /**< Pixel format */ + int num_planes; /**< bytes per a line*/ + int bytesperline; /**< bytes per a line*/ + int sizeimage; /**< size of whole image*/ + camerasrc_colorspace_t colorspace; /**< stored status of image*/ + unsigned int quality; /**< jpeg compress ratio*/ + int rotation; /**< Rotation angle of camera input */ + guint num_buffers; /**< Number of buffers */ +} camerasrc_format_t; + +typedef struct _camerasrc_ctrl_query_t { + int support; /**<1: support, 0: Not support, -1: extra support(Non v4l2)*/ + int max; /**<Integer max value(includes enums)*/ + int min; /**<Integer min value(includes enums)*/ +}camerasrc_ctrl_query_t; + +typedef struct _camerasrc_exif_t { + /* Dynamic value */ + unsigned int exposure_time_numerator; /**< Exposure time, given in seconds */ + unsigned int exposure_time_denominator; + int shutter_speed_numerator; /**< Shutter speed, given in APEX(Additive System Photographic Exposure) */ + int shutter_speed_denominator; + int brigtness_numerator; /**< Value of brightness, before firing flash, given in APEX value */ + int brightness_denominator; + unsigned short int iso; /**< Sensitivity value of sensor */ + unsigned short int flash; /**< Whether flash is fired(1) or not(0) */ + int metering_mode; /**< metering mode in EXIF 2.2 */ + int exif_image_width; /**< Size of image */ + int exif_image_height; + int exposure_bias_in_APEX; /**< Exposure bias in APEX standard */ + int software_used; /**< Firmware S/W version */ + int focal_len_numerator; /**< Lens focal length (f = 4.5mm) */ + int focal_len_denominator; + int aperture_f_num_numerator; /**< Aperture value (f_num = 2.8) */ + int aperture_f_num_denominator; + int aperture_in_APEX; /**< Aperture value in APEX standard */ + int max_lens_aperture_in_APEX; /**< Max aperture value in APEX standard */ + + /* Fixed value */ + int component_configuration; /**< color components arrangement (YCbCr = 1230) */ + int colorspace; /**< colorspace information (sRGB=1) */ +}camerasrc_exif_t; + +typedef struct _camerasrc_frame_data_t { + int index; + camerasrc_buffer_t buffer; +}camerasrc_frame_data_t; + +typedef struct _camerasrc_capture_data_info { + int buffer_index; + gboolean make_thumbnail; + gboolean flash_activated; +} camerasrc_capture_data_info; + +/* JPEG/YUV interleaved data */ +#define INTERLEAVED_JPEG_MAX_SIZE (1024*1024*6) /* 6 Mbyte */ + +/* For Query functionalities + For Querying capabilities */ +/*! Use static size of structures for querying because of performance + */ + +#define MAX_NUM_FMT_DESC 32 +#define MAX_NUM_RESOLUTION 32 +#define MAX_NUM_AVAILABLE_TPF 16 +#define MAX_NUM_AVAILABLE_FPS 16 +#define MAX_NUM_CTRL_LIST_INFO 64 +#define MAX_NUM_CTRL_MENU 64 +#define MAX_SZ_CTRL_NAME_STRING 32 +#define MAX_SZ_DEV_NAME_STRING 32 + +enum{ + CAMERASRC_FCC_USE_NONE = 0x00000001, + CAMERASRC_FCC_USE_REC_PREVIEW = 0x00000010, + CAMERASRC_FCC_USE_CAP_PREVIEW = 0x00000100, + CAMERASRC_FCC_USE_RECORDING = 0x00001000, + CAMERASRC_FCC_USE_NORMAL_CAPTURE = 0x00010000, + CAMERASRC_FCC_USE_CONT_CAPTURE = 0x00100000, + CAMERASRC_FCC_USE_NUM = 6, +}; + +/*! @struct camerasrc_tpf_frac_t + * @brief For timeperframe as fraction type + * Elapse time consumed by one frame, reverse of FPS + */ +typedef struct { + int num; + int den; +}camerasrc_tpf_frac_t; + +/*! @struct camerasrc_resolution_t + * @brief For querying supported resolutions + */ +typedef struct { + int w; + int h; + + /* Available time per frame(tpf) as each pixelformat */ + int num_avail_tpf; + camerasrc_tpf_frac_t tpf[MAX_NUM_AVAILABLE_TPF]; +} camerasrc_resolution_t; + +/*! @struct camerasrc_fmt_desc_t + * @brief For querying supported format type + */ +typedef struct { + /* fourcc name of each pixelformat */ + unsigned int fcc; + int fcc_use; + + /* Available resolutions as each pixelformat */ + int num_resolution; + camerasrc_resolution_t resolutions[MAX_NUM_RESOLUTION]; +} camerasrc_fmt_desc_t; + +/*! @struct camerasrc_caps_info_t + * @brief For querying image input capabilities + */ +typedef struct { + char dev_name[MAX_SZ_DEV_NAME_STRING]; + camerasrc_dev_id_t input_id; + int num_fmt_desc; + camerasrc_fmt_desc_t fmt_desc[MAX_NUM_FMT_DESC]; + + int num_preview_resolution; + int preview_resolution_width[MAX_NUM_RESOLUTION]; + int preview_resolution_height[MAX_NUM_RESOLUTION]; + + int num_capture_resolution; + int capture_resolution_width[MAX_NUM_RESOLUTION]; + int capture_resolution_height[MAX_NUM_RESOLUTION]; + + int num_preview_fmt; + unsigned int preview_fmt[MAX_NUM_FMT_DESC]; + + int num_capture_fmt; + unsigned int capture_fmt[MAX_NUM_FMT_DESC]; + + int num_fps; + camerasrc_frac_t fps[MAX_NUM_AVAILABLE_FPS]; +} camerasrc_caps_info_t; + +/* For Querying controls */ +enum { + CTRL_TYPE_RANGE = 0, /**< Integer, range type */ + CTRL_TYPE_BOOL, /**< Boolean type, 1 equals positive and 0 is negative */ + CTRL_TYPE_ARRAY, /**< Array type, also called menu type. each integer(enumeration) value can be set */ + CTRL_TYPE_UNKNOWN, /**< Unknown type, for error control */ + CTRL_TYPE_NUM, +}; + +/*! @struct camerasrc_ctrl_menu_t + * @brief For querying menu of specified controls + */ +typedef struct { + int menu_index; /**< What number is used for accessing this menu */ + char menu_name[MAX_SZ_CTRL_NAME_STRING]; /**< name of each menu */ +}camerasrc_ctrl_menu_t; + +/*! @struct camerasrc_ctrl_info_t + * @brief For querying controls detail + */ +typedef struct { + camerasrc_ctrl_t camsrc_ctrl_id; /**< camsrc camera control ID for controlling this */ + int v4l2_ctrl_id; /**< v4l2 ctrl id, user not need to use this. see @struct camerasrc_ctrl_t */ + int ctrl_type; /**< Type of this control */ + char ctrl_name[MAX_SZ_CTRL_NAME_STRING]; /**< Name of this control */ + int min; /**< minimum value */ + int max; /**< maximum value */ + int step; /**< unit of the values */ + int default_val; /**< Default value of the array or range */ + int num_ctrl_menu; /**< In the case of array type control, number of supported menu information */ + camerasrc_ctrl_menu_t ctrl_menu[MAX_NUM_CTRL_MENU]; /**< @struct camerasrc_ctrl_menu_t for detailed each menu information*/ +} camerasrc_ctrl_info_t; + +/*! @struct camerasrc_ctrl_list_info_t + * @brief For querying controls + */ +typedef struct { + int num_ctrl_list_info; /**< Number of supported controls */ + camerasrc_ctrl_info_t ctrl_info[MAX_NUM_CTRL_LIST_INFO]; /**< @struct camerasrc_ctrl_info_t for each control information */ +} camerasrc_ctrl_list_info_t; + + +/* capabilities field */ +#define CAMERASRC_STROBE_CAP_NONE 0x0000 /* No strobe supported */ +#define CAMERASRC_STROBE_CAP_OFF 0x0001 /* Always flash off mode */ +#define CAMERASRC_STROBE_CAP_ON 0x0002 /* Always use flash light mode */ +#define CAMERASRC_STROBE_CAP_AUTO 0x0004 /* Flashlight works automatic */ +#define CAMERASRC_STROBE_CAP_REDEYE 0x0008 /* Red-eye reduction */ +#define CAMERASRC_STROBE_CAP_SLOWSYNC 0x0010 /* Slow sync */ +#define CAMERASRC_STROBE_CAP_FRONT_CURTAIN 0x0020 /* Front curtain */ +#define CAMERASRC_STROBE_CAP_REAR_CURTAIN 0x0040 /* Rear curtain */ +#define CAMERASRC_STROBE_CAP_PERMANENT 0x0080 /* keep turned on until turning off */ +#define CAMERASRC_STROBE_CAP_EXTERNAL 0x0100 /* use external strobe */ + +typedef struct _camerasrc_extra_info_t{ + unsigned int strobe_caps; /**< Use above caps field */ + unsigned int detection_caps; /**< Just boolean */ + unsigned int reserved[4]; +} camerasrc_extra_info_t; +/* END For Query functionalities */ + +/*! @def CAMERASRC_SET_SIZE_BY_DIMENSION + * @brief Set image size + */ +#define CAMERASRC_SET_SIZE_BY_DIMENSION(format, img_width, img_height) { \ + format.img_size.width = img_width; \ + format.img_size.height = img_height; \ +} + +/*! @def CAMERASRC_SET_CAPTURE_SIZE_BY_DIMENSION + * @brief Set captured image size + */ +#define CAMERASRC_SET_CAPTURE_SIZE_BY_DIMENSION(format, img_width, img_height) { \ + format.capture_size.width = img_width; \ + format.capture_size.height = img_height; \ +} + + +/* CALLBACK DEFINITIONS */ +/*! @typedef camerasrc_callback_t + * @brief Called back when auto-focusing returns + * This callback will be called when the lens properly auto-focused + */ +typedef int (*camerasrc_callback_t) (camsrc_handle_t handle, int state, void* usr_data); + + +/* FUNCTION DEFINITIONS */ + +/**** M A I N O P E R A T I O N ****/ + +/** + * allocate the handle, set initial state & settings + * + * @param[in] phandle ::camsrc_handle_t camerasrc context handle to be created + * @return Success on CAMERASRC_ERR_NONE or returns with ::camerasrc_error_t code + * @see camerasrc_destroy + * @note State transition : [CAMERASRC_STATE_NONE] => [CAMERASRC_STATE_CREATED] + * Phase description : Non-running phase + */ +int camerasrc_create(camsrc_handle_t *phandle); + +/** + * proceed fd close, other finalization routines + * + * @param[in] handle ::camsrc_handle_t camerasrc context handle + * + * @return Success on CAMERASRC_ERR_NONE or returns with ::camerasrc_error_t code + * + * @see <camerasrc_create> + * + * @note State transition : [CAMERASRC_STATE_UNREALIZED] => [CAMERASRC_STATE_DESTROYED] + * Phase description : Non-running phase + */ +int camerasrc_destroy(camsrc_handle_t handle); + +/** + * Get the state of camerasrc context handle + * + * @param[in] handle ::camsrc_handle_t camerasrc context handle + * @param[out] state ::camerasrc_state_t camerasrc context current state + * @return Success on CAMERASRC_ERR_NONE or returns with ::camerasrc_error_t code + * + */ +int camerasrc_get_state(camsrc_handle_t handle, camerasrc_state_t* state); + +/** + * Allocate the device context handle, open device node and do the miscellaneous settings + * + * @param[in] handle ::camerasrc_handle_t camerasrc context handle + * @param[in] camera_id ::Camera ID currently set + * @param[in] mode ::Camera or Video + * @return Success on ::camerasrc_handle_t or returns NULL code, and displays debug message + * @see camerasrc_unrealize + * @note State transition : [CAMERASRC_STATE_CREATED] => [CAMERASRC_STATE_REALIZED] + * Phase description : Non-running phase + * device name can be dependent on kernel module + */ +int camerasrc_realize(camsrc_handle_t handle, camerasrc_dev_id_t camera_id, camerasrc_sensor_mode_t mode); + +/** + * Deallocate the device structure of buffers, close device + * + * @param[in] handle ::camerasrc_handle_t camerasrc context handle + * @return Success on ::camerasrc_handle_t or returns NULL code, and displays debug message + * @see camerasrc_realize + * @note State transition : [CAMERASRC_STATE_READY] => [CAMERASRC_STATE_UNREALIZED] + * Phase description : Transit to Non-running phase + */ +int camerasrc_unrealize(camsrc_handle_t handle); + +/** + * Prepare Handle to be ready to capture + * Can change settings like below at this state + * - camera device ID setting + * - color format setting + * - image size setting + * - image storing method + * + * @param[in] handle ::camerasrc_handle_t camerasrc context handle + * @return Success on ::camerasrc_handle_t or returns NULL code, and displays debug message + * @see camerasrc_stop + * @note State transition : [CAMERASRC_STATE_REALIZED] => [CAMERASRC_STATE_READY] + * Phase description : Running phase + */ +int camerasrc_start(camsrc_handle_t handle); + +/** + * Get total number of buffer which managed in camerasrc currently. + * If this called, it will return default number of buffer in MMAP mode. + * but use this API after calling ::camerasrc_present_usr_buffer , It will + * return User specfied buffer number. + * + * @param[in] handle ::camsrc_handle_t camerasrc context handle + * @param[in] num_buffer Number of buffer that's managed in camerasrc currently + * @return Success on ::camsrc_handle_t or returns NULL code, and displays debug message + * @see camerasrc_io_method_t + * + */ +int camerasrc_get_num_buffer(camsrc_handle_t handle, unsigned int* num_buffer); + +/** + * Inner ring buffer start refreshing. refresh process occurs asynchronously, and + * ::camerasrc_wait_frame_available function can anounce when it is available. + * + * Camera is grabbing low quality, high speed frame + * - Can attempt the [AF] state only at this state + * - preview frames are always automatically fed + * + * @param[in] handle ::camerasrc_handle_t camerasrc context handle + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error_t error code + * @note State transition : [CAMERASRC_STATE_READY] => [CAMERASRC_STATE_PREVIEW] + * Phase description : Running phase + */ +int camerasrc_start_preview_stream(camsrc_handle_t handle); + +int camerasrc_create_buffer(camsrc_handle_t handle); +int camerasrc_destroy_buffer(camsrc_handle_t handle); + +/** + * Stop frame refreshing. Ring buffers don't be refreshed any more + * + * @param[in] handle ::camerasrc_handle_t camerasrc context handle + * @return Success on ::camerasrc_handle_t or returns NULL code, and displays debug message + * @see camerasrc_stop + * @note State transition : [CAMERASRC_STATE_STILL/PREVIEW/VIDEO] => [CAMERASRC_STATE_READY] + * Phase description : Running phase + */ +int camerasrc_stop_stream(camsrc_handle_t handle); + +/** + * non-busy waiting function for image frame available + * + * @param[in] handle ::camsrc_handle_t camerasrc context handle + * @param[in] timeout ::int timeout + * @return Success on ::camsrc_handle_t or returns NULL code, and displays debug message + * + */ +int camerasrc_wait_frame_available(camsrc_handle_t handle, int timeout); + +/** + * Queue(in user space, almost same with free buffer) buffer to dev's ring buffer + * + * @param[in] handle ::camerasrc_handle_t camerasrc context handle + * @param[in] buf_index ::int index of buffer + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error_t error code + * + */ +int camerasrc_queue_buffer(camsrc_handle_t handle, int buf_index); + +/** + * Dequeue(Pop) buffer from v4l2 driver to usr space. + * + * @param[in] handle ::camsrc_handle_t camerasrc context handle + * @param[out] buf_index main buffer index number to be dequeued. + * @param[out] buffer main image buffer + * @param[out] thm_buffer thumbnail image buffer + * @return Success on ::camsrc_handle_t or returns NULL code, and displays debug message + * + */ +int camerasrc_dequeue_buffer(camsrc_handle_t handle, int *buf_index, camerasrc_buffer_t *buffer, camerasrc_buffer_t *thm_buffer); + +/** + * Read frame from camera device. + * + * @param[in] handle ::camsrc_handle_t camerasrc context handle + * @param[out] buffer ::camerasrc_buffer_t main image buffer to be get. + * @param[out] thm_buffer ::camerasrc_buffer_t thumbnail image buffer to be get. + * @param[out] buffer_index ::int v4l2 buffer index. + * @note if thm_buffer is NULL, thumbnail image will be discarded + * + */ +int camerasrc_read_frame(camsrc_handle_t handle, camerasrc_buffer_t *main_img_buffer, camerasrc_buffer_t *thm_img_buffer, int *buffer_index); + +/** + * Get screennail buffer + * + * @param[in] handle ::camsrc_handle_t camerasrc context handle + * @param[out] scrnl_buf ::camerasrc_buffer_t screennail buffer to be gotten + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error_t error code + */ +int camerasrc_get_screennail_buffer(camsrc_handle_t handle, camerasrc_buffer_t *scrnl_buf); + +/** + * Set autofocus callback. ::camerasrc_callback_t type defined function can be set + * + * @param[in] handle ::camerasrc_handle_t camerasrc context handle + * @param[in] cb ::camerasrc_callback_t callback after focusing over + * @param[in] use_data ::void * user data pointer that will be passed to callback + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error_t error code + * @note Callback function can be set on READY or REALIZED state + * + */ +int camerasrc_set_focused_callback(camsrc_handle_t handle, camerasrc_callback_t cb, void *usr_data); + +/** + * Set autofocusing area. autofocusing will be performed refer this rect of the preview + * + * @param[in] handle ::camsrc_handle_t camerasrc context handle + * @param[in] rect ::camerasrc_rect_t rectangle area for auto focusing + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error_t error code + */ +int camerasrc_set_autofocusing_area(camsrc_handle_t handle, camerasrc_rect_t* rect); + +/** + * Get autofocusing area. + * + * @param[in] handle ::camsrc_handle_t camerasrc context handle + * @param[out] rect ::camerasrc_rect_t rectangle area for auto focusing + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error_t error code + */ +int camerasrc_get_autofocusing_area(camsrc_handle_t handle, camerasrc_rect_t* rect); + +/** + * Start auto focusing with ::camerasrc_af_mode. After ::interval time, call the callback + * function with ::camerasrc_af_status value. + * Auto-focus is in progress. Cant return preview state + * before time-out, success, call camerasrc_autofocus_stop + * - If focused, focus status will be locked at preview state + * + * @param[in] handle ::camerasrc_handle_t camerasrc context handle + * @param[in] af_mode Auto focusing operation mode see ::camerasrc_af_mode + * @param[in] interval interval time in millisecond + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error_t error code + * @note State transition : [CAMERASRC_STATE_PREVIEW] => [CAMERASRC_STATE_AF_IN_PROGRESS] + * Phase description : Running phase + */ +int camerasrc_start_autofocusing(camsrc_handle_t handle); + +/** + * Stop auto focusing + * + * @param[in] handle ::camerasrc_handle_t camerasrc context handle + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error_t error code + * @note State transition : [CAMERASRC_STATE_AF_IN_PROGRESS] => [CAMERASRC_STATE_PREVIEW] + * Phase description : Running phase + */ +int camerasrc_stop_autofocusing(camsrc_handle_t handle); + +/** + * Release auto focusing + * + * @param[in] handle ::camerasrc_handle_t camerasrc context handle + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error_t error code + * @note State transition : [CAMERASRC_STATE_AF_IN_PROGRESS] => [CAMERASRC_STATE_PREVIEW] + * Phase description : Running phase + */ +int camerasrc_release_autofocusing(camsrc_handle_t handle); + +/** + * Initialize auto focusing mode to specified focal length + * + * @param[in] handle ::camsrc_handle_t camerasrc context handle + * @param[in] af_mode ::camerasrc_af_mode_t Auto focusing mode + * @param[in] af_range ::camerasrc_af_scan_range_t Auto focusing range + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error_t error code + */ +int camerasrc_init_autofocusing_mode(camsrc_handle_t handle, camerasrc_af_mode_t af_mode, camerasrc_af_scan_range_t af_range); + +/** + * Get current auto focusing mode + * + * @param[in] handle ::camsrc_handle_t camerasrc context handle + * @param[out] af_mode ::camerasrc_af_mode_t Auto focusing mode + * @param[out] af_range ::camerasrc_af_scan_range_t Auto focusing range + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error_t error code + */ +int camerasrc_get_autofocusing_mode(camsrc_handle_t handle, camerasrc_af_mode_t* af_mode, camerasrc_af_scan_range_t* af_range); + +/** + * Get current auto focusing status + * + * @param[in] handle ::camsrc_handle_t camerasrc context handle + * @param[out] af_status ::camerasrc_auto_focus_status_t Auto focusing status + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error_t error code + * + */ +int camerasrc_get_autofocusing_status(camsrc_handle_t handle, camerasrc_auto_focus_status_t* af_status); + + +/**** E F F E C T C O N T R O L O P E R A T I O N ****/ + +/** + * Control miscellaneous settings through ::camerasrc_ctrl_t IDs + * + * @param[in] handle ::camsrc_handle_t camerasrc context handle + * @param[in] ctrl_id control ID to be checked + * @param[in] value value to be set + * @return Success on CAMERASRC_ERR_NONE or returns with ::camerasrc_error_t error code + * @note This function is only effective at CAMERASRC_STATE_READY + */ +int camerasrc_set_control(camsrc_handle_t handle, camerasrc_ctrl_t ctrl_id, int value); + +/** + * Get the value of miscellaneous settings through ::camerasrc_ctrl_t IDs + * + * @param[in] handle ::camsrc_handle_t camerasrc context handle + * @param[in] ctrl_id control ID to be checked + * @param[out] value value to be stored + * @return Success on CAMERASRC_ERR_NONE or returns with ::camerasrc_error_t error code + * @note This function is only effective at CAMERASRC_STATE_READY + */ +int camerasrc_get_control(camsrc_handle_t handle, camerasrc_ctrl_t ctrl_id, int* value); + +/**** O U T P U T C O N T R O L O P E R A T I O N ****/ + +/** + * Control frame refresh rate setting + * + * @param[in] handle ::camerasrc_handle_t camerasrc context handle + * @param[in] frac ::camsrc_frac_t time per frame + * @return Success on CAMERASRC_ERR_NONE or returns with ::camerasrc_error_t error code + * @note This function is only effective at CAMERASRC_STATE_READY + */ +int camerasrc_set_timeperframe(camsrc_handle_t handle, camerasrc_frac_t* frac); + +/** + * Set output format of camera device just like ioctl VIDIOC_S_FMT + * + * @param[in] handle ::camerasrc_handle_t camerasrc context handle + * @param[in] fmt ::camerasrc_format_t output format description to be set + * @return Success on CAMERASRC_ERR_NONE or returns with ::camerasrc_error_t error code + * @note This function is only effective at CAMERASRC_STATE_READY. + * device dependent function. + */ +int camerasrc_set_format(camsrc_handle_t handle, camerasrc_format_t* fmt); + +/** + * Get output format of camera device just like ioctl VIDIOC_G_FMT + * + * @param[in] handle ::camerasrc_handle_t camerasrc context handle + * @param[in] fmt ::camerasrc_format_t output format description to be set + * @return Success on CAMERASRC_ERR_NONE or returns with ::camerasrc_error_t error code + * @note This function is only effective at CAMERASRC_PHASE_RUNNING + */ +int camerasrc_get_format(camsrc_handle_t handle, camerasrc_format_t* fmt); + +/** + * Get data of frame + * + * @param[in] handle ::camsrc_handle_t handle + * @param[in] data ::camerasrc_frame_data_t data + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error error code + */ +int camerasrc_get_frame_data(camsrc_handle_t handle, camerasrc_frame_data_t *data); + +/**** S H U T T E R S P E E D & A P E R T U R E M O D U L A T I O N ****/ +/** + * Get exif string to be combined with jpg image from camerasrc + * + * @param[in] handle ::camsrc_handle_t handle + * @param[out] exif_string exif information string + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error error code + */ +int camerasrc_get_exif_info(camsrc_handle_t handle, camerasrc_exif_t* exif_struct); + +/** + * Set vflip to camera driver + + * @param[in] handle ::camsrc_handle_t handle + * @param[in] vflip ::int vflip + * @return Success on CAMERASRC_ERR_NONE or returns with ::camerasrc_error_t error code + */ +int camerasrc_set_vflip(camsrc_handle_t handle, int vflip); + +/** + * Set hflip to camera driver + + * @param[in] handle ::camsrc_handle_t handle + * @param[in] hflip ::int hflip + * @return Success on CAMERASRC_ERR_NONE or returns with ::camerasrc_error_t error code + */ +int camerasrc_set_hflip(camsrc_handle_t handle, int hflip); + + +/* W I L L B E D E P R E C A T E D */ + +/*! @enum camerasrc_colortone_t + * @brief Enumeration type for camera colortone + * + * Colortone entries for camera effects. This can be used with CAMERASRC_CTRL_COLOR_TONE + * This values are defined for utility. It's dependent on the device/camera module. + */ +typedef enum { + CAMERASRC_COLORTONE_NONE = 0, + CAMERASRC_COLORTONE_NEGATIVE, + CAMERASRC_COLORTONE_SOLARIZATION_1, + CAMERASRC_COLORTONE_SOLARIZATION_2, + CAMERASRC_COLORTONE_SOLARIZATION_3, + CAMERASRC_COLORTONE_SOLARIZATION_4, + CAMERASRC_COLORTONE_EMBOSS, + CAMERASRC_COLORTONE_OUTLINE, + CAMERASRC_COLORTONE_AQUA, + CAMERASRC_COLORTONE_SEPHIA, + CAMERASRC_COLORTONE_GRAY, + CAMERASRC_COLORTONE_B_N_W, + CAMERASRC_COLORTONE_RED, + CAMERASRC_COLORTONE_GREEN, + CAMERASRC_COLORTONE_BLUE, + CAMERASRC_COLORTONE_ANTIQUE, + CAMERASRC_COLORTONE_SKETCH1, + CAMERASRC_COLORTONE_SKETCH2, + CAMERASRC_COLORTONE_SKETCH3, + CAMERASRC_COLORTONE_SKETCH4, + CAMERASRC_COLORTONE_NUM, +}camerasrc_colortone_t; + +/*! @enum camerasrc_program_mode_t + * @brief Enumeration type for preset program mode + * + * WRITEME + */ +typedef enum { + CAMERASRC_PROGRAM_MODE_NORMAL = 0, + CAMERASRC_PROGRAM_MODE_PORTRAIT, + CAMERASRC_PROGRAM_MODE_LANDSCAPE, + CAMERASRC_PROGRAM_MODE_SPORTS, + CAMERASRC_PROGRAM_MODE_PARTY_N_INDOOR, + CAMERASRC_PROGRAM_MODE_BEACH_N_INDOOR, + CAMERASRC_PROGRAM_MODE_SUNSET, + CAMERASRC_PROGRAM_MODE_DUSK_N_DAWN, + CAMERASRC_PROGRAM_MODE_FALL_COLOR, + CAMERASRC_PROGRAM_MODE_NIGHT_SCENE, + CAMERASRC_PROGRAM_MODE_FIREWORK, + CAMERASRC_PROGRAM_MODE_TEXT, + CAMERASRC_PROGRAM_MODE_SHOW_WINDOW, + CAMERASRC_PROGRAM_MODE_CANDLE_LIGHT, + CAMERASRC_PROGRAM_MODE_BACK_LIGHT, + CAMERASRC_PROGRAM_MODE_NUM, +}camerasrc_program_mode_t; + +/*! @enum camerasrc_whitebalance_t + * @brief Enumeration type for preset whitebalance + * + * WRITEME + */ +typedef enum { + CAMERASRC_WHITEBALANCE_AUTO = 0, + CAMERASRC_WHITEBALANCE_INCANDESCENT, + CAMERASRC_WHITEBALANCE_FLUORESCENT, + CAMERASRC_WHITEBALANCE_DAYLIGHT, + CAMERASRC_WHITEBALANCE_CLOUDY, + CAMERASRC_WHITEBALANCE_SHADE, + CAMERASRC_WHITEBALANCE_HORIZON, + CAMERASRC_WHITEBALANCE_FLASH, + CAMERASRC_WHITEBALANCE_CUSTOM, + CAMERASRC_WHITEBALANCE_NUM, +}camerasrc_whitebalance_t; + +/** + * Enumerations for flip. + */ +typedef enum { + CAMERASRC_FILP_NONE = 0, /**< Not flipped */ + CAMERASRC_FILP_VERTICAL, /**< Flip vertically */ + CAMERASRC_FILP_HORIZONTAL, /**< Flip horizontally */ + CAMERASRC_FILP_NUM, /**< Number of flip status */ +}camerasrc_flip_t; + +/*! @enum camerasrc_strobo_status_t + * @brief strobo status + * strobo status + */ +typedef enum { + CAMERASRC_STROBO_STATUS_BANNED = 0, /**< strobo off*/ + CAMERASRC_STROBO_STATUS_FORCE_ON, /**< strobo on.*/ + CAMERASRC_STROBO_STATUS_AUTO, /**< control strobo automatically*/ + CAMERASRC_STROBO_STATUS_MOVIE_ON, /**< control strobo automatically*/ + CAMERASRC_STROBO_STATUS_NUM, /**< Number of AF status*/ +}camerasrc_strobo_status_t; +/*! @enum camerasrc_strobe_mode_t + * @brief strobe mode + * strobe mode + */ +typedef enum { + CAMERASRC_STROBE_MODE_OFF = 1, /**< off */ + CAMERASRC_STROBE_MODE_AUTO, /**< auto */ + CAMERASRC_STROBE_MODE_ON, /**< on */ + CAMERASRC_STROBE_MODE_PERMANENT, /**< permanent */ + CAMERASRC_STROBE_MODE_NUM, /**< Number of strobe mode */ +}camerasrc_strobe_mode_t; + +/*! @enum camerasrc_ae_mode_t + * @brief Auto exposure mode + * Auto exposure operation mode + */ +typedef enum { + CAMERASRC_AE_MODE_OFF = 0, + CAMERASRC_AE_MODE_ALL, + CAMERASRC_AE_MODE_CENTER_WEIGHTED_AVR_1, + CAMERASRC_AE_MODE_CENTER_WEIGHTED_AVR_2, + CAMERASRC_AE_MODE_CENTER_WEIGHTED_AVR_3, + CAMERASRC_AE_MODE_SPOT_1, + CAMERASRC_AE_MODE_SPOT_2, + CAMERASRC_AE_MODE_CUSTOM_1, + CAMERASRC_AE_MODE_CUSTOM_2, +} camerasrc_ae_mode_t; + +/*! @enum camerasrc_iso_t + * @brief Reserved iso number in definition + * Traditionally predefined ISO values + */ +typedef enum { + CAMERASRC_ISO_AUTO = 0, + CAMERASRC_ISO_50, + CAMERASRC_ISO_100, + CAMERASRC_ISO_200, + CAMERASRC_ISO_400, + CAMERASRC_ISO_800, + CAMERASRC_ISO_1600, + CAMERASRC_ISO_3200, +} camerasrc_iso_t; + + +/** + * Set the mode of strobe + * + * @param[in] handle ::camsrc_handle_t handle + * @param[in] mode ::camerasrc_strobe_mode_t mode of strobe + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error error code + */ +int camerasrc_set_strobe_mode(camsrc_handle_t handle, camerasrc_strobe_mode_t mode); + +/** + * Get the mode of strobe + * + * @param[in] handle ::camsrc_handle_t handle + * @param[out] mode ::camerasrc_strobe_mode_t mode of strobe + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error error code + */ +int camerasrc_get_strobe_mode(camsrc_handle_t handle, camerasrc_strobe_mode_t* mode); + +/** + * Set the mode of auto-exposure processing + * + * @param[in] handle ::camsrc_handle_t handle + * @param[in] ae_mode ::camerasrc_ae_mode_t AE mode to be set + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error error code + */ +int camerasrc_set_exposure_mode(camsrc_handle_t handle, camerasrc_ae_mode_t ae_mode); + +/** + * Get the mode of auto-exposure processing + * + * @param[in] handle ::camsrc_handle_t handle + * @param[out] ae_mode ::camerasrc_ae_mode_t AE mode to be got + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error error code + */ +int camerasrc_get_exposure_mode(camsrc_handle_t handle, camerasrc_ae_mode_t* ae_mode); + +/** + * Set the shutter speed + * + * @param[in] handle ::camsrc_handle_t handle + * @param[in] frac ::camerasrc_frac_t shutter speed to be set + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error error code + */ +int camerasrc_set_shutter_speed(camsrc_handle_t handle, camerasrc_frac_t frac); + +/** + * Get the shutter speed + * + * @param[in] handle ::camsrc_handle_t handle + * @param[out] frac ::camerasrc_frac_t shutter speed to be got + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error error code + */ +int camerasrc_get_shutter_speed(camsrc_handle_t handle, camerasrc_frac_t* frac); + +/** + * Set the exposure value + * + * @param[in] handle ::camsrc_handle_t handle + * @param[in] frac ::camerasrc_frac_t exposure value to be set + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error error code + */ +int camerasrc_set_exposure_value(camsrc_handle_t handle, camerasrc_frac_t frac); + +/** + * Get the exposure value + * + * @param[in] handle ::camsrc_handle_t handle + * @param[out] frac ::camerasrc_frac_t exposure value to be got + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error error code + */ +int camerasrc_get_exposure_value(camsrc_handle_t handle, camerasrc_frac_t* frac); + +/** + * Extract EXIF info of current captured image + * + * @param[in] handle ::camsrc_handle_t handle + * @param[in] capture_data ::camerasrc_capture_data_info * pointer of capture data information + * @return Success on CAMERASRC_ERR_NONE or returns with ::camerasrc_error error code + */ +int camerasrc_extract_exif_info_from_capture_data(camsrc_handle_t handle, camerasrc_capture_data_info *capture_data); + + +/*------------------- + * For TBM control * + -------------------*/ +/** + * Initialize Tizen Buffer Manager + * + * @param[in] handle ::camsrc_handle_t handle + * @return Success on TRUE or returns FALSE + */ +int camerasrc_tbm_init(camsrc_handle_t handle); + +/** + * Deinitialize Tizen Buffer Manager + * + * @param[in] handle ::camsrc_handle_t handle + * @return Success on TRUE or returns FALSE + */ +int camerasrc_tbm_deinit(camsrc_handle_t handle); + +/** + * Memory allocation function for TBM + * + * @param[in] handle ::camsrc_handle_t handle + * @param[in] size ::int size + * @param[out] bo ::TBM buffer object of allocated memory + * @param[out] dma_buf_fd ::dmabuf fd of allocated memory + * @param[out] vaddr ::virtual address of allocated memory + * @return Success on TRUE or returns FALSE + */ +int camerasrc_tbm_alloc_buffer(camsrc_handle_t handle, int size, tbm_bo *bo, int *dma_buf_fd, unsigned char **vaddr); + +/* For Query functionalities */ +/** + * Query basic device info of device + * + * @param[in] handle ::camsrc_handle_t handle + * @param[out] camerasrc_caps_info_t device information structure + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error error code + */ +int camerasrc_read_basic_dev_info(camerasrc_dev_id_t dev_id, camerasrc_caps_info_t* caps_info); + +/** + * Query miscellaneous device info(effect, WB, preset values, etc.) of device + * + * @param[in] handle ::camsrc_handle_t handle + * @param[out] camerasrc_ctrl_list_info_t device capabilities structure + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error error code + */ +int camerasrc_read_misc_dev_info(camerasrc_dev_id_t dev_id, camerasrc_ctrl_list_info_t* ctrl_info); + +/** + * Query extra device info(face detection, strobe, etc.) of device + * + * @param[in] handle ::camsrc_handle_t handle + * @param[out] camerasrc_extra_info_t device capabilities structure + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error error code + */ +int camerasrc_read_extra_dev_info(camerasrc_dev_id_t dev_id, camerasrc_extra_info_t* extra_info); + +/** + * Record miscellaneous device info(effect, WB, preset values, etc.) of device + * + * @param[in] handle ::camsrc_handle_t handle + * @param[in] camerasrc_ctrl_list_info_t device capabilities structure + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error error code + */ +int camerasrc_write_basic_dev_info(camsrc_handle_t handle, camerasrc_caps_info_t* caps_info); + +/** + * Record miscellaneous device info(effect, WB, preset values, etc.) of device + * + * @param[in] handle ::camsrc_handle_t handle + * @param[in] camerasrc_ctrl_list_info_t device capabilities structure + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error error code + */ +int camerasrc_write_misc_dev_info(camsrc_handle_t handle, camerasrc_ctrl_list_info_t* ctrl_info); + +/** + * Record extra device info(face detection, strobe, etc.) of device + * + * @param[in] handle ::camsrc_handle_t handle + * @param[out] camerasrc_extra_info_t device capabilities structure + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error error code + */ +int camerasrc_write_extra_dev_info(camsrc_handle_t handle, camerasrc_extra_info_t* extra_info); + +/** + * Query to device driver about miscellaneous device info(effect, WB, preset values, etc.) of device + * + * @param[in] handle ::camsrc_handle_t handle + * @param[out] camerasrc_ctrl_list_info_t device capabilities structure + * @return Success(Support) on CAMERASRC_ERR_NONE or returns with ::camerasrc_error error code + */ +int camerasrc_query_misc_dev_info(camsrc_handle_t handle, camerasrc_ctrl_list_info_t* ctrl_list_info); + +/* END For Query functionalities */ + +#ifdef __cplusplus +} +#endif + +#endif /*__CAMERASRC_H__*/ diff --git a/camerasrc/src/include/fimc-is-metadata.h b/camerasrc/src/include/fimc-is-metadata.h new file mode 100644 index 0000000..eb657f0 --- /dev/null +++ b/camerasrc/src/include/fimc-is-metadata.h @@ -0,0 +1,1473 @@ +/* Copyright (c) 2011 Samsung Electronics Co, Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + + * + + * Alternatively, Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + + */ + +#ifndef FIMC_IS_METADATA_H_ +#define FIMC_IS_METADATA_H_ + +#ifndef _LINUX_TYPES_H +#error Incorrect definition of int64_t for aarch64 +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef signed short int16_t; +typedef signed int int32_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; +#endif + +struct rational { + uint32_t num; + uint32_t den; +}; + +#define CAMERA2_MAX_AVAILABLE_MODE 21 +#define CAMERA2_MAX_FACES 16 +#define CAMERA2_MAX_VENDER_LENGTH 400 +#define CAPTURE_NODE_MAX 2 +#define CAMERA2_MAX_PDAF_MULTIROI_COLUMN 9 +#define CAMERA2_MAX_PDAF_MULTIROI_ROW 5 + +#define OPEN_MAGIC_NUMBER 0x01020304 +#define SHOT_MAGIC_NUMBER 0x23456789 + +/* + *controls/dynamic metadata +*/ + +/* android.request */ + +enum metadata_mode { + METADATA_MODE_NONE, + METADATA_MODE_FULL +}; + +struct camera2_request_ctl { + uint32_t id; + enum metadata_mode metadataMode; + uint8_t outputStreams[16]; + uint32_t frameCount; + uint32_t requestCount; +}; + +struct camera2_request_dm { + uint32_t id; + enum metadata_mode metadataMode; + uint32_t frameCount; + uint32_t requestCount; +}; + +struct camera2_entry_ctl { + /** \brief + per-frame control for entry control + \remarks + low parameter is 0bit ~ 31bit flag + high parameter is 32bit ~ 63bit flag + */ + uint32_t lowIndexParam; + uint32_t highIndexParam; + uint32_t parameter[2048]; +}; + +struct camera2_entry_dm { + uint32_t lowIndexParam; + uint32_t highIndexParam; +}; + +/* android.lens */ + +enum optical_stabilization_mode { + OPTICAL_STABILIZATION_MODE_OFF = 1, + OPTICAL_STABILIZATION_MODE_ON = 2, + OPTICAL_STABILIZATION_MODE_STILL = 3, // Still mode + OPTICAL_STABILIZATION_MODE_STILL_ZOOM = 4, // Still Zoom mode + OPTICAL_STABILIZATION_MODE_VIDEO = 5, // Recording mode + OPTICAL_STABILIZATION_MODE_SINE_X = 6, // factory mode x + OPTICAL_STABILIZATION_MODE_SINE_Y = 7, // factory mode y + OPTICAL_STABILIZATION_MODE_CENTERING = 8 // Centering mode +}; + +enum lens_facing { + LENS_FACING_BACK, + LENS_FACING_FRONT +}; + +struct camera2_lens_ctl { + uint32_t focusDistance; + float aperture; + float focalLength; + float filterDensity; + enum optical_stabilization_mode opticalStabilizationMode; + +}; + +struct camera2_lens_dm { + uint32_t focusDistance; + float aperture; + float focalLength; + float filterDensity; + enum optical_stabilization_mode opticalStabilizationMode; + float focusRange[2]; +}; + +struct camera2_lens_sm { + float minimumFocusDistance; + float hyperfocalDistance; + float availableFocalLength[2]; + float availableApertures; + /*assuming 1 aperture*/ + float availableFilterDensities; + /*assuming 1 ND filter value*/ + enum optical_stabilization_mode availableOpticalStabilization; + /*assuming 1*/ + uint32_t shadingMapSize; + float shadingMap[3][40][30]; + uint32_t geometricCorrectionMapSize; + float geometricCorrectionMap[2][3][40][30]; + enum lens_facing facing; + float position[2]; +}; + +/* android.sensor */ + +enum sensor_colorfilterarrangement { + SENSOR_COLORFILTERARRANGEMENT_RGGB, + SENSOR_COLORFILTERARRANGEMENT_GRBG, + SENSOR_COLORFILTERARRANGEMENT_GBRG, + SENSOR_COLORFILTERARRANGEMENT_BGGR, + SENSOR_COLORFILTERARRANGEMENT_RGB +}; + +enum sensor_ref_illuminant { + SENSOR_ILLUMINANT_DAYLIGHT = 1, + SENSOR_ILLUMINANT_FLUORESCENT = 2, + SENSOR_ILLUMINANT_TUNGSTEN = 3, + SENSOR_ILLUMINANT_FLASH = 4, + SENSOR_ILLUMINANT_FINE_WEATHER = 9, + SENSOR_ILLUMINANT_CLOUDY_WEATHER = 10, + SENSOR_ILLUMINANT_SHADE = 11, + SENSOR_ILLUMINANT_DAYLIGHT_FLUORESCENT = 12, + SENSOR_ILLUMINANT_DAY_WHITE_FLUORESCENT = 13, + SENSOR_ILLUMINANT_COOL_WHITE_FLUORESCENT = 14, + SENSOR_ILLUMINANT_WHITE_FLUORESCENT = 15, + SENSOR_ILLUMINANT_STANDARD_A = 17, + SENSOR_ILLUMINANT_STANDARD_B = 18, + SENSOR_ILLUMINANT_STANDARD_C = 19, + SENSOR_ILLUMINANT_D55 = 20, + SENSOR_ILLUMINANT_D65 = 21, + SENSOR_ILLUMINANT_D75 = 22, + SENSOR_ILLUMINANT_D50 = 23, + SENSOR_ILLUMINANT_ISO_STUDIO_TUNGSTEN = 24 +}; + +struct camera2_sensor_ctl { + /* unit : nano */ + uint64_t exposureTime; + /* unit : nano(It's min frame duration */ + uint64_t frameDuration; + /* unit : percent(need to change ISO value?) */ + uint32_t sensitivity; +}; + +struct camera2_sensor_dm { + uint64_t exposureTime; + uint64_t frameDuration; + uint32_t sensitivity; + uint64_t timeStamp; + uint32_t analogGain; + uint32_t digitalGain; +}; + +struct camera2_sensor_sm { + uint32_t exposureTimeRange[2]; + uint32_t maxFrameDuration; + /* list of available sensitivities. */ + uint32_t availableSensitivities[10]; + enum sensor_colorfilterarrangement colorFilterArrangement; + float physicalSize[2]; + uint32_t pixelArraySize[2]; + uint32_t activeArraySize[4]; + uint32_t whiteLevel; + uint32_t blackLevelPattern[4]; + struct rational colorTransform1[9]; + struct rational colorTransform2[9]; + enum sensor_ref_illuminant referenceIlluminant1; + enum sensor_ref_illuminant referenceIlluminant2; + struct rational forwardMatrix1[9]; + struct rational forwardMatrix2[9]; + struct rational calibrationTransform1[9]; + struct rational calibrationTransform2[9]; + struct rational baseGainFactor; + uint32_t maxAnalogSensitivity; + float noiseModelCoefficients[2]; + uint32_t orientation; +}; + + + +/* android.flash */ + +enum flash_mode { + CAM2_FLASH_MODE_OFF = 1, + CAM2_FLASH_MODE_SINGLE, + CAM2_FLASH_MODE_TORCH, + CAM2_FLASH_MODE_BEST +}; + +enum capture_state { + CAPTURE_STATE_NONE = 0, + CAPTURE_STATE_FLASH = 1, + CAPTURE_STATE_HDR_DARK = 12, + CAPTURE_STATE_HDR_NORMAL = 13, + CAPTURE_STATE_HDR_BRIGHT = 14, + CAPTURE_STATE_ZSL_LIKE = 20, +}; + +struct camera2_flash_ctl { + enum flash_mode flashMode; + uint32_t firingPower; + uint64_t firingTime; +}; + +struct camera2_flash_dm { + enum flash_mode flashMode; + /*10 is max power*/ + uint32_t firingPower; + /*unit : microseconds*/ + uint64_t firingTime; + /*1 : stable, 0 : unstable*/ + uint32_t firingStable; + /*1 : success, 0 : fail*/ + uint32_t decision; + /*0: None, 1 : pre, 2 : main flash ready*/ + uint32_t flashReady; + /*0: None, 1 : pre, 2 : main flash off ready*/ + uint32_t flashOffReady; +}; + +struct camera2_flash_sm { + uint32_t available; + uint64_t chargeDuration; +}; + + +/* android.hotpixel */ + +enum processing_mode { + PROCESSING_MODE_OFF = 1, + PROCESSING_MODE_FAST, + PROCESSING_MODE_HIGH_QUALITY +}; + + +struct camera2_hotpixel_ctl { + enum processing_mode mode; +}; + +struct camera2_hotpixel_dm { + enum processing_mode mode; +}; + + + +/* android.demosaic */ + +struct camera2_demosaic_ctl { + enum processing_mode mode; +}; + +struct camera2_demosaic_dm { + enum processing_mode mode; +}; + + + +/* android.noiseReduction */ + +struct camera2_noisereduction_ctl { + enum processing_mode mode; + uint32_t strength; +}; + +struct camera2_noisereduction_dm { + enum processing_mode mode; + uint32_t strength; +}; + + + +/* android.shading */ + +struct camera2_shading_ctl { + enum processing_mode mode; +}; + +struct camera2_shading_dm { + enum processing_mode mode; +}; + + + +/* android.geometric */ + +struct camera2_geometric_ctl { + enum processing_mode mode; +}; + +struct camera2_geometric_dm { + enum processing_mode mode; +}; + + + +/* android.colorCorrection */ + +enum colorcorrection_mode { + COLORCORRECTION_MODE_FAST = 1, + COLORCORRECTION_MODE_HIGH_QUALITY, + COLORCORRECTION_MODE_TRANSFORM_MATRIX, + COLORCORRECTION_MODE_EFFECT_MONO, + COLORCORRECTION_MODE_EFFECT_NEGATIVE, + COLORCORRECTION_MODE_EFFECT_SOLARIZE, + COLORCORRECTION_MODE_EFFECT_SEPIA, + COLORCORRECTION_MODE_EFFECT_POSTERIZE, + COLORCORRECTION_MODE_EFFECT_WHITEBOARD, + COLORCORRECTION_MODE_EFFECT_BLACKBOARD, + COLORCORRECTION_MODE_EFFECT_AQUA, + COLORCORRECTION_MODE_EFFECT_EMBOSS, + COLORCORRECTION_MODE_EFFECT_EMBOSS_MONO, + COLORCORRECTION_MODE_EFFECT_SKETCH, + COLORCORRECTION_MODE_EFFECT_RED_YELLOW_POINT, + COLORCORRECTION_MODE_EFFECT_GREEN_POINT, + COLORCORRECTION_MODE_EFFECT_BLUE_POINT, + COLORCORRECTION_MODE_EFFECT_MAGENTA_POINT, + COLORCORRECTION_MODE_EFFECT_WARM_VINTAGE, + COLORCORRECTION_MODE_EFFECT_COLD_VINTAGE, + COLORCORRECTION_MODE_EFFECT_WASHED, + COLORCORRECTION_MODE_EFFECT_BEAUTY_FACE, + TOTAOCOUNT_COLORCORRECTION_MODE_EFFECT +}; + + +struct camera2_colorcorrection_ctl { + enum colorcorrection_mode mode; + float transform[9]; + uint32_t hue; + uint32_t saturation; + uint32_t brightness; + uint32_t contrast; +}; + +struct camera2_colorcorrection_dm { + enum colorcorrection_mode mode; + float transform[9]; + uint32_t hue; + uint32_t saturation; + uint32_t brightness; + uint32_t contrast; +}; + +struct camera2_colorcorrection_sm { + /*assuming 10 supported modes*/ + uint8_t availableModes[CAMERA2_MAX_AVAILABLE_MODE]; + uint32_t hueRange[2]; + uint32_t saturationRange[2]; + uint32_t brightnessRange[2]; + uint32_t contrastRange[2]; +}; + + +/* android.tonemap */ + +enum tonemap_mode { + TONEMAP_MODE_FAST = 1, + TONEMAP_MODE_HIGH_QUALITY, + TONEMAP_MODE_CONTRAST_CURVE +}; + +struct camera2_tonemap_ctl { + enum tonemap_mode mode; + /* assuming maxCurvePoints = 64 */ + float curveRed[64]; + float curveGreen[64]; + float curveBlue[64]; +}; + +struct camera2_tonemap_dm { + enum tonemap_mode mode; + /* assuming maxCurvePoints = 64 */ + float curveRed[64]; + float curveGreen[64]; + float curveBlue[64]; +}; + +struct camera2_tonemap_sm { + uint32_t maxCurvePoints; +}; + +/* android.edge */ + +struct camera2_edge_ctl { + enum processing_mode mode; + uint32_t strength; +}; + +struct camera2_edge_dm { + enum processing_mode mode; + uint32_t strength; +}; + + + +/* android.scaler */ + +enum scaler_availableformats { + SCALER_FORMAT_BAYER_RAW, + SCALER_FORMAT_YV12, + SCALER_FORMAT_NV21, + SCALER_FORMAT_JPEG, + SCALER_FORMAT_UNKNOWN +}; + +struct camera2_scaler_ctl { + uint32_t cropRegion[4]; + uint32_t orientation; +}; + +struct camera2_scaler_dm { + uint32_t cropRegion[4]; + uint32_t orientation; +}; + +struct camera2_scaler_sm { + enum scaler_availableformats availableFormats[4]; + /*assuming # of availableFormats = 4*/ + uint32_t availableRawSizes; + uint64_t availableRawMinDurations; + /* needs check */ + uint32_t availableProcessedSizes[8]; + uint64_t availableProcessedMinDurations[8]; + uint32_t availableJpegSizes[8][2]; + uint64_t availableJpegMinDurations[8]; + uint32_t availableMaxDigitalZoom[8]; +}; + +/* android.jpeg */ +struct camera2_jpeg_ctl { + uint32_t quality; + uint32_t thumbnailSize[2]; + uint32_t thumbnailQuality; + double gpsCoordinates[3]; + uint32_t gpsProcessingMethod; + uint64_t gpsTimestamp; + uint32_t orientation; +}; + +struct camera2_jpeg_dm { + uint32_t quality; + uint32_t thumbnailSize[2]; + uint32_t thumbnailQuality; + double gpsCoordinates[3]; + uint32_t gpsProcessingMethod; + uint64_t gpsTimestamp; + uint32_t orientation; +}; + +struct camera2_jpeg_sm { + uint32_t availableThumbnailSizes[8][2]; + uint32_t maxSize; + /*assuming supported size=8*/ +}; + + + +/* android.statistics */ + +enum facedetect_mode { + FACEDETECT_MODE_OFF = 1, + FACEDETECT_MODE_SIMPLE, + FACEDETECT_MODE_FULL +}; + +enum stats_mode { + STATS_MODE_OFF = 1, + STATS_MODE_ON +}; + +enum stats_lowlightmode { + STATE_LLS_LEVEL_ZSL = 0, + STATE_LLS_LEVEL_LOW = 1, + STATE_LLS_LEVEL_HIGH = 2, + STATE_LLS_LEVEL_SIS = 3, + STATE_LLS_LEVEL_ZSL_LIKE = 4, + STATE_LLS_LEVEL_ZSL_FLASH = 16, +}; + +struct camera2_stats_ctl { + enum facedetect_mode faceDetectMode; + enum stats_mode histogramMode; + enum stats_mode sharpnessMapMode; +}; + + +struct camera2_stats_dm { + enum facedetect_mode faceDetectMode; + uint32_t faceRectangles[CAMERA2_MAX_FACES][4]; + uint8_t faceScores[CAMERA2_MAX_FACES]; + uint32_t faceLandmarks[CAMERA2_MAX_FACES][6]; + uint32_t faceIds[CAMERA2_MAX_FACES]; +/* PAYTON_CHECK_20120712 : histogram_mode -> stats_mode */ + enum stats_mode histogramMode; +/* [hj529.kim, 2012/07/19] androd.statistics.histogram */ + uint32_t histogram[3 * 256]; +/* PAYTON_CHECK_20120712 : sharpnessmap_mode -> stats_mode */ + enum stats_mode sharpnessMapMode; + /*sharpnessMap*/ + enum stats_lowlightmode LowLightMode; + uint32_t lls_tuning_set_index; + uint32_t lls_brightness_index; +}; + + +struct camera2_stats_sm { + uint8_t availableFaceDetectModes[CAMERA2_MAX_AVAILABLE_MODE]; + /*assuming supported modes = 3;*/ + uint32_t maxFaceCount; + uint32_t histogramBucketCount; + uint32_t maxHistogramCount; + uint32_t sharpnessMapSize[2]; + uint32_t maxSharpnessMapValue; +}; + +/* android.control */ + +enum aa_capture_intent { + AA_CAPTURE_INTENT_CUSTOM = 0, + AA_CAPTURE_INTENT_PREVIEW, + AA_CAPTURE_INTENT_STILL_CAPTURE, + AA_CAPTURE_INTENT_VIDEO_RECORD, + AA_CAPTURE_INTENT_VIDEO_SNAPSHOT, + AA_CAPTURE_INTENT_ZERO_SHUTTER_LAG, + AA_CAPTURE_INTENT_STILL_CAPTURE_OIS_SINGLE, + AA_CAPTURE_INTENT_STILL_CAPTURE_OIS_MULTI +}; + +enum aa_mode { + AA_CONTROL_OFF = 1, + AA_CONTROL_AUTO, + AA_CONTROL_USE_SCENE_MODE +}; + +enum aa_scene_mode { + AA_SCENE_MODE_UNSUPPORTED = 1, + AA_SCENE_MODE_FACE_PRIORITY, + AA_SCENE_MODE_ACTION, + AA_SCENE_MODE_PORTRAIT, + AA_SCENE_MODE_LANDSCAPE, + AA_SCENE_MODE_NIGHT, + AA_SCENE_MODE_NIGHT_PORTRAIT, + AA_SCENE_MODE_THEATRE, + AA_SCENE_MODE_BEACH, + AA_SCENE_MODE_SNOW, + AA_SCENE_MODE_SUNSET, + AA_SCENE_MODE_STEADYPHOTO, + AA_SCENE_MODE_FIREWORKS, + AA_SCENE_MODE_SPORTS, + AA_SCENE_MODE_PARTY, + AA_SCENE_MODE_CANDLELIGHT, + AA_SCENE_MODE_BARCODE, + AA_SCENE_MODE_NIGHT_CAPTURE, + AA_SCENE_MODE_ANTISHAKE, + AA_SCENE_MODE_HDR, + AA_SCENE_MODE_LLS, + AA_SCENE_MODE_FDAE, + AA_SCENE_MODE_DUAL, + AA_SCENE_MODE_DRAMA, + AA_SCENE_MODE_ANIMATED, + AA_SCENE_MODE_PANORAMA, + AA_SCENE_MODE_GOLF, + AA_SCENE_MODE_PREVIEW, + AA_SCENE_MODE_VIDEO, + AA_SCENE_MODE_SLOWMOTION_2, + AA_SCENE_MODE_SLOWMOTION_4_8, + AA_SCENE_MODE_DUAL_PREVIEW, + AA_SCENE_MODE_DUAL_VIDEO, + AA_SCENE_MODE_120_PREVIEW, + AA_SCENE_MODE_LIGHT_TRACE +}; + +enum aa_effect_mode { + AA_EFFECT_OFF = 1, + AA_EFFECT_MONO, + AA_EFFECT_NEGATIVE, + AA_EFFECT_SOLARIZE, + AA_EFFECT_SEPIA, + AA_EFFECT_POSTERIZE, + AA_EFFECT_WHITEBOARD, + AA_EFFECT_BLACKBOARD, + AA_EFFECT_AQUA +}; + +enum aa_aemode { + AA_AEMODE_OFF = 1, + AA_AEMODE_LOCKED, + AA_AEMODE_CENTER, + AA_AEMODE_AVERAGE, + AA_AEMODE_MATRIX, + AA_AEMODE_SPOT, + AA_AEMODE_CENTER_TOUCH, + AA_AEMODE_AVERAGE_TOUCH, + AA_AEMODE_MATRIX_TOUCH, + AA_AEMODE_SPOT_TOUCH +}; + +enum aa_ae_flashmode { + /*all flash control stop*/ + AA_FLASHMODE_OFF = 1, + /*flash start*/ + AA_FLASHMODE_START, + /*flash cancle*/ + AA_FLASHMODE_CANCLE, + /*internal 3A can control flash*/ + AA_FLASHMODE_ON, + /*internal 3A can do auto flash algorithm*/ + AA_FLASHMODE_AUTO, + /*internal 3A can fire flash by auto result*/ + AA_FLASHMODE_CAPTURE, + /*internal 3A can control flash forced*/ + AA_FLASHMODE_ON_ALWAYS +}; + +enum aa_ae_antibanding_mode { + AA_AE_ANTIBANDING_OFF = 1, + AA_AE_ANTIBANDING_50HZ, + AA_AE_ANTIBANDING_60HZ, + AA_AE_ANTIBANDING_AUTO, + AA_AE_ANTIBANDING_AUTO_50HZ, /*50Hz + Auto*/ + AA_AE_ANTIBANDING_AUTO_60HZ /*60Hz + Auto*/ +}; + +enum aa_awbmode { + AA_AWBMODE_OFF = 1, + AA_AWBMODE_LOCKED, + AA_AWBMODE_WB_AUTO, + AA_AWBMODE_WB_INCANDESCENT, + AA_AWBMODE_WB_FLUORESCENT, + AA_AWBMODE_WB_WARM_FLUORESCENT, + AA_AWBMODE_WB_DAYLIGHT, + AA_AWBMODE_WB_CLOUDY_DAYLIGHT, + AA_AWBMODE_WB_TWILIGHT, + AA_AWBMODE_WB_SHADE +}; + +enum aa_afmode { + /* These modes are adjusted immediatly */ + AA_AFMODE_OFF = 1, + AA_AFMODE_SLEEP, + AA_AFMODE_INFINITY, + AA_AFMODE_MACRO, + AA_AFMODE_DELAYED_OFF, + + /* Single AF. These modes are adjusted when afTrigger is changed from 0 to 1 */ + AA_AFMODE_AUTO = 11, + AA_AFMODE_AUTO_MACRO, + AA_AFMODE_AUTO_VIDEO, + AA_AFMODE_AUTO_FACE, + + /* Continuous AF. These modes are adjusted when afTrigger is changed from 0 to 1 */ + AA_AFMODE_CONTINUOUS_PICTURE = 21, + AA_AFMODE_CONTINUOUS_VIDEO, + AA_AFMODE_CONTINUOUS_PICTURE_FACE, + + /* Special modes for PDAF */ + AA_AFMODE_PDAF_OUTFOCUSING = 31, + AA_AFMODE_PDAF_OUTFOCUSING_FACE, + AA_AFMODE_PDAF_OUTFOCUSING_CONTINUOUS_PICTURE, + AA_AFMODE_PDAF_OUTFOCUSING_CONTINUOUS_PICTURE_FACE, + + /* Not supported yet */ + AA_AFMODE_EDOF = 41, +}; + +/* camera2_aa_ctl.afRegions[4] */ +enum aa_afmode_ext { + AA_AFMODE_EXT_OFF = 1000, + /* Increase macro range for special app */ + AA_AFMODE_EXT_ADVANCED_MACRO_FOCUS = 1001, + /* Set AF region for OCR */ + AA_AFMODE_EXT_FOCUS_LOCATION = 1002, +}; + +enum aa_afstate { + AA_AFSTATE_INACTIVE = 1, + AA_AFSTATE_PASSIVE_SCAN, + AA_AFSTATE_ACTIVE_SCAN, + AA_AFSTATE_AF_ACQUIRED_FOCUS, + AA_AFSTATE_AF_FAILED_FOCUS +}; + +enum ae_state { + AE_STATE_INACTIVE = 1, + AE_STATE_SEARCHING, + AE_STATE_CONVERGED, + AE_STATE_LOCKED, + AE_STATE_FLASH_REQUIRED, + AE_STATE_PRECAPTURE +}; + +enum awb_state { + AWB_STATE_INACTIVE = 1, + AWB_STATE_SEARCHING, + AWB_STATE_CONVERGED, + AWB_STATE_LOCKED +}; + +enum aa_isomode { + AA_ISOMODE_AUTO = 1, + AA_ISOMODE_MANUAL, +}; + +struct camera2_aa_ctl { + enum aa_capture_intent captureIntent; + enum aa_mode mode; + /*enum aa_effect_mode effectMode;*/ + enum aa_scene_mode sceneMode; + uint32_t videoStabilizationMode; + enum aa_aemode aeMode; + uint32_t aeRegions[5]; + /*5 per region(x1,y1,x2,y2,weight). currently assuming 1 region.*/ + int32_t aeExpCompensation; + uint32_t aeTargetFpsRange[2]; + enum aa_ae_antibanding_mode aeAntibandingMode; + enum aa_ae_flashmode aeflashMode; + enum aa_awbmode awbMode; + uint32_t awbRegions[5]; + /*5 per region(x1,y1,x2,y2,weight). currently assuming 1 region.*/ + enum aa_afmode afMode; + uint32_t afRegions[5]; + /*5 per region(x1,y1,x2,y2,weight). currently assuming 1 region.*/ + uint32_t afTrigger; + enum aa_isomode isoMode; + uint32_t isoValue; + int32_t awbValue; + uint32_t reserved[10]; +}; + +struct camera2_aa_dm { + enum aa_mode mode; + enum aa_effect_mode effectMode; + enum aa_scene_mode sceneMode; + uint32_t videoStabilizationMode; + enum aa_aemode aeMode; + /*needs check*/ + uint32_t aeRegions[5]; + /*5 per region(x1,y1,x2,y2,weight). currently assuming 1 region.*/ + enum ae_state aeState; + enum aa_ae_flashmode aeflashMode; + /*needs check*/ + enum aa_awbmode awbMode; + uint32_t awbRegions[5]; + enum awb_state awbState; + /*5 per region(x1,y1,x2,y2,weight). currently assuming 1 region.*/ + enum aa_afmode afMode; + uint32_t afRegions[5]; + /*5 per region(x1,y1,x2,y2,weight). currently assuming 1 region*/ + enum aa_afstate afState; + enum aa_isomode isoMode; + uint32_t isoValue; + uint32_t reserved[10]; +}; + +struct camera2_aa_sm { + uint8_t availableSceneModes[CAMERA2_MAX_AVAILABLE_MODE]; + uint8_t availableEffects[CAMERA2_MAX_AVAILABLE_MODE]; + /*assuming # of available scene modes = 10*/ + uint32_t maxRegions; + uint8_t aeAvailableModes[CAMERA2_MAX_AVAILABLE_MODE]; + /*assuming # of available ae modes = 8*/ + struct rational aeCompensationStep; + int32_t aeCompensationRange[2]; + uint32_t aeAvailableTargetFpsRanges[CAMERA2_MAX_AVAILABLE_MODE][2]; + uint8_t aeAvailableAntibandingModes[CAMERA2_MAX_AVAILABLE_MODE]; + uint8_t awbAvailableModes[CAMERA2_MAX_AVAILABLE_MODE]; + /*assuming # of awbAvailableModes = 10*/ + uint8_t afAvailableModes[CAMERA2_MAX_AVAILABLE_MODE]; + /*assuming # of afAvailableModes = 4*/ + uint8_t availableVideoStabilizationModes[4]; + /*assuming # of availableVideoStabilizationModes = 4*/ + uint32_t isoRange[2]; +}; + +struct camera2_lens_usm { + /** Frame delay between sending command and applying frame data */ + uint32_t focusDistanceFrameDelay; +}; + +struct camera2_sensor_usm { + /** Frame delay between sending command and applying frame data */ + uint32_t exposureTimeFrameDelay; + uint32_t frameDurationFrameDelay; + uint32_t sensitivityFrameDelay; +}; + +struct camera2_flash_usm { + /** Frame delay between sending command and applying frame data */ + uint32_t flashModeFrameDelay; + uint32_t firingPowerFrameDelay; + uint64_t firingTimeFrameDelay; +}; + +struct camera2_ctl { + struct camera2_request_ctl request; + struct camera2_lens_ctl lens; + struct camera2_sensor_ctl sensor; + struct camera2_flash_ctl flash; + struct camera2_hotpixel_ctl hotpixel; + struct camera2_demosaic_ctl demosaic; + struct camera2_noisereduction_ctl noise; + struct camera2_shading_ctl shading; + struct camera2_geometric_ctl geometric; + struct camera2_colorcorrection_ctl color; + struct camera2_tonemap_ctl tonemap; + struct camera2_edge_ctl edge; + struct camera2_scaler_ctl scaler; + struct camera2_jpeg_ctl jpeg; + struct camera2_stats_ctl stats; + struct camera2_aa_ctl aa; + struct camera2_entry_ctl entry; +}; + +struct camera2_dm { + struct camera2_request_dm request; + struct camera2_lens_dm lens; + struct camera2_sensor_dm sensor; + struct camera2_flash_dm flash; + struct camera2_hotpixel_dm hotpixel; + struct camera2_demosaic_dm demosaic; + struct camera2_noisereduction_dm noise; + struct camera2_shading_dm shading; + struct camera2_geometric_dm geometric; + struct camera2_colorcorrection_dm color; + struct camera2_tonemap_dm tonemap; + struct camera2_edge_dm edge; + struct camera2_scaler_dm scaler; + struct camera2_jpeg_dm jpeg; + struct camera2_stats_dm stats; + struct camera2_aa_dm aa; + struct camera2_entry_dm entry; +}; + +struct camera2_sm { + struct camera2_lens_sm lens; + struct camera2_sensor_sm sensor; + struct camera2_flash_sm flash; + struct camera2_colorcorrection_sm color; + struct camera2_tonemap_sm tonemap; + struct camera2_scaler_sm scaler; + struct camera2_jpeg_sm jpeg; + struct camera2_stats_sm stats; + struct camera2_aa_sm aa; + + /** User-defined(ispfw specific) static metadata. */ + struct camera2_lens_usm lensUd; + struct camera2_sensor_usm sensorUd; + struct camera2_flash_usm flashUd; +}; + +/** \brief + User-defined control for lens. +*/ +struct camera2_lens_uctl { + struct camera2_lens_ctl ctl; + + /** It depends by posSize */ + uint32_t pos; + /** It depends by af algorithm(AF pos bit. normally 8 or 9 or 10) */ + uint32_t posSize; + /** It depends by af algorithm */ + uint32_t direction; + /** Some actuator support slew rate control. */ + uint32_t slewRate; +}; + +/** \brief + User-defined metadata for lens. +*/ +struct camera2_lens_udm { + /** It depends by posSize */ + uint32_t pos; + /** It depends by af algorithm(AF pos bit. normally 8 or 9 or 10) */ + uint32_t posSize; + /** It depends by af algorithm */ + uint32_t direction; + /** Some actuator support slew rate control. */ + uint32_t slewRate; +}; + +/** \brief + User-defined metadata for ae. +*/ +struct camera2_ae_udm { + /** vendor specific length */ + uint32_t vsLength; + /** vendor specific data array */ + uint32_t vendorSpecific[CAMERA2_MAX_VENDER_LENGTH]; +}; + +/** \brief + User-defined metadata for awb. +*/ +struct camera2_awb_udm { + /** vendor specific length */ + uint32_t vsLength; + /** vendor specific data array */ + uint32_t vendorSpecific[CAMERA2_MAX_VENDER_LENGTH]; +}; + +/** \brief + User-defined metadata for af. +*/ +struct camera2_af_udm { + /** vendor specific length */ + uint32_t vsLength; + /** vendor specific data array */ + uint32_t vendorSpecific[CAMERA2_MAX_VENDER_LENGTH]; + int32_t lensPositionInfinity; + int32_t lensPositionMacro; + int32_t lensPositionCurrent; +}; + +/** \brief + User-defined metadata for anti-shading. +*/ +struct camera2_as_udm { + /** vendor specific length */ + uint32_t vsLength; + /** vendor specific data array */ + uint32_t vendorSpecific[CAMERA2_MAX_VENDER_LENGTH]; +}; + +/** \brief + User-defined metadata for anti-shading. +*/ +struct camera2_ipc_udm { + /** vendor specific length */ + uint32_t vsLength; + /** vendor specific data array */ + uint32_t vendorSpecific[CAMERA2_MAX_VENDER_LENGTH]; +}; + +/** \brief + User-defined metadata for aa. +*/ +struct camera2_internal_udm { + /** vendor specific data array */ + uint32_t vendorSpecific1[CAMERA2_MAX_VENDER_LENGTH]; + uint32_t vendorSpecific2[CAMERA2_MAX_VENDER_LENGTH]; + /* + * vendorSpecific2[0] : info + * vendorSpecific2[100] : 0:sirc 1:cml + * vendorSpecific2[101] : cml exposure + * vendorSpecific2[102] : cml iso(gain) + * vendorSpecific2[103] : cml Bv + */ +}; + +/** \brief + User-defined control for sensor. +*/ +struct camera2_sensor_uctl { + struct camera2_sensor_ctl ctl; + /** Dynamic frame duration. + This feature is decided to max. value between + 'sensor.exposureTime'+alpha and 'sensor.frameDuration'. + */ + uint64_t dynamicFrameDuration; + uint32_t analogGain; + uint32_t digitalGain; + uint64_t longExposureTime; /* For supporting WDR */ + uint64_t shortExposureTime; + uint32_t longAnalogGain; + uint32_t shortAnalogGain; + uint32_t longDigitalGain; + uint32_t shortDigitalGain; +}; + +struct camera2_scaler_uctl { + /** \brief + target address for next frame. + \remarks + [0] invalid address, stop + [others] valid address + */ + uint32_t sccTargetAddress[4]; + uint32_t scpTargetAddress[4]; + uint32_t disTargetAddress[4]; + uint32_t taapTargetAddress[4]; /* 3AA preview DMA */ + uint32_t taacTargetAddress[4]; /* 3AA capture DMA */ + uint32_t orientation; +}; + +struct camera2_flash_uctl { + struct camera2_flash_ctl ctl; +}; + +struct camera2_bayer_uctl { + struct camera2_scaler_ctl ctl; +}; + +enum companion_drc_mode { + COMPANION_DRC_OFF = 1, + COMPANION_DRC_ON, +}; + +enum companion_wdr_mode { + COMPANION_WDR_OFF = 1, + COMPANION_WDR_ON, +}; + +enum companion_paf_mode { + COMPANION_PAF_OFF = 1, + COMPANION_PAF_ON, +}; + +enum companion_bypass_mode { + COMPANION_FULL_BYPASS_OFF = 1, + COMPANION_FULL_BYPASS_ON, +}; + +enum companion_lsc_mode { + COMPANION_LSC_OFF = 1, + COMPANION_LSC_ON, +}; + +struct camera2_companion_uctl { + enum companion_drc_mode drc_mode; + enum companion_wdr_mode wdr_mode; + enum companion_paf_mode paf_mode; +}; + +struct camera2_bayer_udm { + uint32_t width; + uint32_t height; +}; + +struct camera2_pdaf_single_result { + uint16_t mode; + uint16_t goalPos; + uint16_t reliability; + uint16_t currentPos; +}; + +struct camera2_pdaf_multi_result { + uint16_t mode; + uint16_t goalPos; + uint16_t reliability; +}; + +struct camera2_pdaf_udm { + uint16_t numCol; /* width of PDAF map, 0 means no multi PDAF data */ + uint16_t numRow; /* height of PDAF map, 0 means no multi PDAF data */ + struct camera2_pdaf_multi_result multiResult[CAMERA2_MAX_PDAF_MULTIROI_COLUMN][CAMERA2_MAX_PDAF_MULTIROI_ROW]; + struct camera2_pdaf_single_result singleResult; + uint16_t lensPosResolution; /* 1023(unsigned 10bit) */ +}; + +struct camera2_companion_udm { + enum companion_drc_mode drc_mode; + enum companion_wdr_mode wdr_mode; + enum companion_paf_mode paf_mode; + struct camera2_pdaf_udm pdaf; +}; + +/** \brief + User-defined control area. + \remarks + sensor, lens, flash category is empty value. + It should be filled by a5 for SET_CAM_CONTROL command. + Other category is filled already from host. +*/ +struct camera2_uctl { + /** \brief + Set sensor, lens, flash control for next frame. + \remarks + This flag can be combined. + [0 bit] lens + [1 bit] sensor + [2 bit] flash + */ + uint32_t uUpdateBitMap; + + /** For debugging */ + uint32_t uFrameNumber; + + /** ispfw specific control(user-defined) of lens. */ + struct camera2_lens_uctl lensUd; + /** ispfw specific control(user-defined) of sensor. */ + struct camera2_sensor_uctl sensorUd; + /** ispfw specific control(user-defined) of flash. */ + struct camera2_flash_uctl flashUd; + + struct camera2_scaler_uctl scalerUd; + /** ispfw specific control(user-defined) of Bcrop1. */ + struct camera2_bayer_uctl bayerUd; + struct camera2_companion_uctl companionUd; + uint32_t reserved[10]; +}; + +struct camera2_udm { + struct camera2_lens_udm lens; + struct camera2_ae_udm ae; + struct camera2_awb_udm awb; + struct camera2_af_udm af; + struct camera2_as_udm as; + struct camera2_ipc_udm ipc; + /* KJ_121129 : Add udm for sirc sdk. */ + struct camera2_internal_udm internal; + /* Add udm for bayer down size. */ + struct camera2_bayer_udm bayer; + struct camera2_companion_udm companion; + uint32_t reserved[10]; +}; + +struct camera2_shot { + /*google standard area*/ + struct camera2_ctl ctl; + struct camera2_dm dm; + /*user defined area*/ + struct camera2_uctl uctl; + struct camera2_udm udm; + /*magic : 23456789*/ + uint32_t magicNumber; +}; + +struct camera2_node_input { + /** \brief + intput crop region + \remarks + [0] x axis + [1] y axie + [2] width + [3] height + */ + uint32_t cropRegion[4]; +}; + +struct camera2_node_output { + /** \brief + output crop region + \remarks + [0] x axis + [1] y axie + [2] width + [3] height + */ + uint32_t cropRegion[4]; +}; + +struct camera2_node { + /** \brief + video node id + \remarks + [x] video node id + */ + uint32_t vid; + + /** \brief + stream control + \remarks + [0] disable stream out + [1] enable stream out + */ + uint32_t request; + + struct camera2_node_input input; + struct camera2_node_output output; +}; + +struct camera2_node_group { + /** \brief + output device node + \remarks + this node can pull in image + */ + struct camera2_node leader; + + /** \brief + capture node list + \remarks + this node can get out image + 3AAC, 3AAP, SCC, SCP, VDISC + */ + struct camera2_node capture[CAPTURE_NODE_MAX]; +}; + +/** \brief + Structure for interfacing between HAL and driver. +*/ +struct camera2_shot_ext { + /* + * --------------------------------------------------------------------- + * HAL Control Part + * --------------------------------------------------------------------- + */ + + /** \brief + setfile change + \remarks + [x] mode for setfile + */ + uint32_t setfile; + + /** \brief + node group control + \remarks + per frame control + */ + struct camera2_node_group node_group; + + /** \brief + post processing control(DRC) + \remarks + [0] bypass off + [1] bypass on + */ + uint32_t drc_bypass; + + /** \brief + post processing control(DIS) + \remarks + [0] bypass off + [1] bypass on + */ + uint32_t dis_bypass; + + /** \brief + post processing control(3DNR) + \remarks + [0] bypass off + [1] bypass on + */ + uint32_t dnr_bypass; + + /** \brief + post processing control(FD) + \remarks + [0] bypass off + [1] bypass on + */ + uint32_t fd_bypass; + + /* + * --------------------------------------------------------------------- + * DRV Control Part + * --------------------------------------------------------------------- + */ + + /** \brief + requested frames state. + driver return the information everytime + when dequeue is requested. + \remarks + [X] count + */ + uint32_t free_cnt; + uint32_t request_cnt; + uint32_t process_cnt; + uint32_t complete_cnt; + + /* reserved for future */ + uint32_t reserved[15]; + + /** \brief + processing time debugging + \remarks + taken time(unit : struct timeval) + [0][x] flite start + [1][x] flite end + [2][x] DRV Shot + [3][x] DRV Shot done + [4][x] DRV Meta done + */ + uint32_t timeZone[10][2]; + + /* + * --------------------------------------------------------------------- + * Camera API + * --------------------------------------------------------------------- + */ + + struct camera2_shot shot; +}; + +/** \brief + stream structure for scaler. +*/ +struct camera2_stream { + /** \brief + this address for verifying conincidence of index and address + \remarks + [X] kernel virtual address for this buffer + */ + uint32_t address; + + /** \brief + this frame count is from FLITE through dm.request.fcount, + this count increases every frame end. initial value is 1. + \remarks + [X] frame count + */ + uint32_t fcount; + + /** \brief + this request count is from HAL through ctl.request.fcount, + this count is the unique. + \remarks + [X] request count + */ + uint32_t rcount; + + /** \brief + frame index of isp framemgr. + this value is for driver internal debugging + \remarks + [X] frame index + */ + uint32_t findex; + + /** \brief + frame validation of isp framemgr. + this value is for driver and HAL internal debugging + \remarks + [X] frame valid + */ + uint32_t fvalid; + + /** \brief + output crop region + this value mean the output image places the axis of memory space + \remarks + [0] crop x axis + [1] crop y axis + [2] width + [3] height + */ + uint32_t input_crop_region[4]; + uint32_t output_crop_region[4]; +}; + +#define CAM_LENS_CMD (0x1 << 0x0) +#define CAM_SENSOR_CMD (0x1 << 0x1) +#define CAM_FLASH_CMD (0x1 << 0x2) + +/* typedefs below are for firmware sources */ + +typedef enum metadata_mode metadata_mode_t; +typedef struct camera2_request_ctl camera2_request_ctl_t; +typedef struct camera2_request_dm camera2_request_dm_t; +typedef enum optical_stabilization_mode optical_stabilization_mode_t; +typedef enum lens_facing lens_facing_t; +typedef struct camera2_entry_ctl camera2_entry_ctl_t; +typedef struct camera2_entry_dm camera2_entry_dm_t; +typedef struct camera2_lens_ctl camera2_lens_ctl_t; +typedef struct camera2_lens_dm camera2_lens_dm_t; +typedef struct camera2_lens_sm camera2_lens_sm_t; +typedef enum sensor_colorfilterarrangement sensor_colorfilterarrangement_t; +typedef enum sensor_ref_illuminant sensor_ref_illuminant_t; +typedef struct camera2_sensor_ctl camera2_sensor_ctl_t; +typedef struct camera2_sensor_dm camera2_sensor_dm_t; +typedef struct camera2_sensor_sm camera2_sensor_sm_t; +typedef enum flash_mode flash_mode_t; +typedef struct camera2_flash_ctl camera2_flash_ctl_t; +typedef struct camera2_flash_dm camera2_flash_dm_t; +typedef struct camera2_flash_sm camera2_flash_sm_t; +typedef enum processing_mode processing_mode_t; +typedef struct camera2_hotpixel_ctl camera2_hotpixel_ctl_t; +typedef struct camera2_hotpixel_dm camera2_hotpixel_dm_t; + +typedef struct camera2_demosaic_ctl camera2_demosaic_ctl_t; +typedef struct camera2_demosaic_dm camera2_demosaic_dm_t; +typedef struct camera2_noisereduction_ctl camera2_noisereduction_ctl_t; +typedef struct camera2_noisereduction_dm camera2_noisereduction_dm_t; +typedef struct camera2_shading_ctl camera2_shading_ctl_t; +typedef struct camera2_shading_dm camera2_shading_dm_t; +typedef struct camera2_geometric_ctl camera2_geometric_ctl_t; +typedef struct camera2_geometric_dm camera2_geometric_dm_t; +typedef enum colorcorrection_mode colorcorrection_mode_t; +typedef struct camera2_colorcorrection_ctl camera2_colorcorrection_ctl_t; +typedef struct camera2_colorcorrection_dm camera2_colorcorrection_dm_t; +typedef struct camera2_colorcorrection_sm camera2_colorcorrection_sm_t; +typedef enum tonemap_mode tonemap_mode_t; +typedef struct camera2_tonemap_ctl camera2_tonemap_ctl_t; +typedef struct camera2_tonemap_dm camera2_tonemap_dm_t; +typedef struct camera2_tonemap_sm camera2_tonemap_sm_t; + +typedef struct camera2_edge_ctl camera2_edge_ctl_t; +typedef struct camera2_edge_dm camera2_edge_dm_t; +typedef enum scaler_availableformats scaler_availableformats_t; +typedef struct camera2_scaler_ctl camera2_scaler_ctl_t; +typedef struct camera2_scaler_dm camera2_scaler_dm_t; +typedef struct camera2_jpeg_ctl camera2_jpeg_ctl_t; +typedef struct camera2_jpeg_dm camera2_jpeg_dm_t; +typedef struct camera2_jpeg_sm camera2_jpeg_sm_t; +typedef enum facedetect_mode facedetect_mode_t; +typedef enum stats_mode stats_mode_t; +typedef struct camera2_stats_ctl camera2_stats_ctl_t; +typedef struct camera2_stats_dm camera2_stats_dm_t; +typedef struct camera2_stats_sm camera2_stats_sm_t; +typedef enum aa_capture_intent aa_capture_intent_t; +typedef enum aa_mode aa_mode_t; +typedef enum aa_scene_mode aa_scene_mode_t; +typedef enum aa_effect_mode aa_effect_mode_t; +typedef enum aa_aemode aa_aemode_t; +typedef enum aa_ae_antibanding_mode aa_ae_antibanding_mode_t; +typedef enum aa_awbmode aa_awbmode_t; +typedef enum aa_afmode aa_afmode_t; +typedef enum aa_afstate aa_afstate_t; +typedef struct camera2_aa_ctl camera2_aa_ctl_t; +typedef struct camera2_aa_dm camera2_aa_dm_t; +typedef struct camera2_aa_sm camera2_aa_sm_t; +typedef struct camera2_lens_usm camera2_lens_usm_t; +typedef struct camera2_sensor_usm camera2_sensor_usm_t; +typedef struct camera2_flash_usm camera2_flash_usm_t; +typedef struct camera2_ctl camera2_ctl_t; +typedef struct camera2_uctl camera2_uctl_t; +typedef struct camera2_dm camera2_dm_t; +typedef struct camera2_sm camera2_sm_t; + +typedef struct camera2_scaler_sm camera2_scaler_sm_t; +typedef struct camera2_scaler_uctl camera2_scaler_uctl_t; + +typedef struct camera2_sensor_uctl camera2_sensor_uctl_t; +typedef struct camera2_lens_uctl camera2_lens_uctl_t; +typedef struct camera2_lens_udm camera2_lens_udm_t; + +typedef struct camera2_ae_udm camera2_ae_udm_t; +typedef struct camera2_awb_udm camera2_awb_udm_t; +typedef struct camera2_af_udm camera2_af_udm_t; +typedef struct camera2_as_udm camera2_as_udm_t; +typedef struct camera2_ipc_udm camera2_ipc_udm_t; +typedef struct camera2_internal_udm camera2_internal_udm_t; + +typedef struct camera2_flash_uctl camera2_flash_uctl_t; + +typedef struct camera2_shot camera2_shot_t; + +#endif diff --git a/camerasrc/src/include/gstcamerasrc.h b/camerasrc/src/include/gstcamerasrc.h new file mode 100644 index 0000000..425c4dc --- /dev/null +++ b/camerasrc/src/include/gstcamerasrc.h @@ -0,0 +1,180 @@ +/* + * camerasrc + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jeongmo Yang <jm80.yang@samsung.com> + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __GSTCAMERASRC_H__ +#define __GSTCAMERASRC_H__ + +#include <gst/gst.h> +#include <gst/base/gstpushsrc.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <pthread.h> + +#include <gst/video/colorbalance.h> +#include <gst/video/cameracontrol.h> +#include <gst/video/video-format.h> + +#include "camerasrc.h" + +#ifndef _SPEED_UP_RAW_CAPTURE +#define _SPEED_UP_RAW_CAPTURE +#endif /* _SPEED_UP_RAW_CAPTURE */ + +G_BEGIN_DECLS +#define GST_TYPE_CAMERA_SRC (gst_camerasrc_get_type()) +#define GST_CAMERA_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_CAMERA_SRC,GstCameraSrc)) +#define GST_CAMERA_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_CAMERA_SRC,GstCameraSrcClass)) +#define GST_IS_CAMERA_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_CAMERA_SRC)) +#define GST_IS_CAMERA_SRC_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_CAMERA_SRC)) + + +#define FORMAT_NAME_LENGTH 10 + + +typedef struct _GstCameraSrc GstCameraSrc; +typedef struct _GstCameraSrcClass GstCameraSrcClass; +typedef struct _GstCameraBuffer GstCameraBuffer; +typedef struct _BufferInfo BufferInfo; + +/* global info */ +struct _GstCameraBuffer { + GstBuffer *buffer; + int v4l2_buffer_index; + GstCameraSrc *camerasrc; +}; + +struct _BufferInfo { + unsigned char *vaddr[MAX_PLANE_NUM]; + uint64_t size[MAX_PLANE_NUM]; + int dma_buf_fd[MAX_PLANE_NUM]; + tbm_bo bo[MAX_PLANE_NUM]; + unsigned int bytesused; +}; + +struct _GstCameraSrc +{ + GstPushSrc element; + + /*private*/ + void *v4l2_handle; /**< video4linux2 handle */ + int mode; + gboolean vflip; /**< flip camera input vertically */ + gboolean hflip; /**< flip camera input horizontally */ + gboolean firsttime; + + int main_buf_sz; + int cap_count_current; /**< current capture count */ + int cap_count_reverse; /**< current capture count (reverse counting) */ + unsigned long cap_next_time; /**< next shot time for capture */ + GQueue *capture_cmd_list; /**< Command list(Start capture, Stop capture) queue */ + + GCond cond; + GMutex mutex; + + /*camera property*/ + int width; /**< Width */ + int height; /**< Height */ + int fps; /**< Video source fps */ + + gchar format_name[FORMAT_NAME_LENGTH]; /**< Format name */ + int pix_format; /**< Image format of video source */ + int colorspace; /**< Colorspace of video source */ + int high_speed_fps; /**< Video source fps for high speed recording */ + gboolean fps_auto; /**< Auto Video source fps */ + + int camera_id; + int rotate; /**< Video source rotate */ + gboolean use_rotate_caps; /**< Use or not rotate value in caps */ + + GCond buffer_cond; /**< condition for buffer control */ + GMutex buffer_lock; /**< lock for buffer control */ + gboolean buffer_running; /**< with lock */ + gint num_live_buffers; /**< with lock */ + guint buffer_count; + gboolean bfirst; /**< temp */ +#ifdef _SPEED_UP_RAW_CAPTURE + gboolean cap_stream_diff; /**< whether preview and capture streams are different each other */ +#endif + GQueue *pad_alloc_list; + GMutex pad_alloc_mutex; + gint current_buffer_data_index; + gboolean first_invokation; + + /* Colorbalance , CameraControl interface */ + GList *colors; + GList *camera_controls; + + + /*capture property*/ + guint32 cap_fourcc; /**< gstreamer fourcc value(GST_MAKE_FOURCC format) for raw capturing */ + int cap_width; /**< Capture width */ + int cap_height; /**< Capture height */ + int cap_interval; /**< Capture interval */ + int cap_count; /**< Capture count */ + int cap_jpg_quality; /**< Capture quality for jpg compress ratio */ + gboolean cap_provide_exif; /**< Is exif provided? */ + gboolean flash_activated; /**< Is flash activated when AF? - this can be used in case of zero shutter lag capture */ + gboolean is_hybrid_running; /**< Is Hybrid mode running? */ + gboolean is_hybrid_capture; /**< Is Hybrid mode capture frame? */ + + BufferInfo *buffer_info; /**< Buffer info - fd, vaddr, tbm_bo, size */ + + /*etc property*/ + gboolean create_jpeg; + GMutex jpg_mutex; + GCond capture_cond; /**< cond for capture thread */ + GMutex capture_mutex; /**< mutex for capture thread */ + GQueue *capture_buffer_list; /**< queue for buffer to capture */ + GThread *capture_thread; /**< capture thread */ + gboolean quit_capture_thread; /**< flag to quit capture thread */ + GQueue *restart_cmd_list; /**< command list for restarting preview */ + gboolean flush_cache; /**< flush cache after YUV buffer is copied */ + GMutex restart_mutex; /**< mutex for preview restart */ + GCond restart_cond; /**< cond for preview restart */ +}; + +struct _GstCameraSrcClass { + GstPushSrcClass parent_class; + /* signals */ + void (*still_capture) (GstElement *element, GstBuffer *main, GstBuffer *sub, GstBuffer *scrnl); + void (*nego_complete) (GstElement *element); + void (*register_trouble) (GstElement *element); +}; + +typedef enum { + INTERFACE_NONE, + INTERFACE_COLOR_BALANCE, + INTERFACE_CAMERA_CONTROL, +} GstInterfaceType; + + +void gst_camerasrc_set_capture_command(GstCameraSrc* camerasrc, GstCameraControlCaptureCommand cmd); + + +GType gst_camerasrc_get_type(void); + +G_END_DECLS + +#endif /* __GSTCAMERASRC_H__ */ diff --git a/camerasrc/src/include/gstcamerasrccolorbalance.h b/camerasrc/src/include/gstcamerasrccolorbalance.h new file mode 100644 index 0000000..2fc9a7e --- /dev/null +++ b/camerasrc/src/include/gstcamerasrccolorbalance.h @@ -0,0 +1,91 @@ +/* + * camerasrc + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jeongmo Yang <jm80.yang@samsung.com> + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __GST_CAMERASRC_COLOR_BALANCE_H__ +#define __GST_CAMERASRC_COLOR_BALANCE_H__ + +#include <gst/gst.h> +#include <gst/video/colorbalance.h> +#include "gstcamerasrc.h" + +G_BEGIN_DECLS + +#define GST_TYPE_CAMERASRC_COLOR_BALANCE_CHANNEL (gst_camerasrc_color_balance_channel_get_type ()) +#define GST_CAMERASRC_COLOR_BALANCE_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_CAMERASRC_COLOR_BALANCE_CHANNEL, GstCameraSrcColorBalanceChannel)) +#define GST_CAMERASRC_COLOR_BALANCE_CHANNEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_CAMERASRC_COLOR_BALANCE_CHANNEL, GstCameraSrcColorBalanceChannelClass)) +#define GST_IS_CAMERASRC_COLOR_BALANCE_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_CAMERASRC_COLOR_BALANCE_CHANNEL)) +#define GST_IS_CAMERASRC_COLOR_BALANCE_CHANNEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_CAMERASRC_COLOR_BALANCE_CHANNEL)) + +typedef struct _GstCameraSrcColorBalanceChannel { + GstColorBalanceChannel parent; + + guint32 id; +} GstCameraSrcColorBalanceChannel; + +typedef struct _GstCameraSrcColorBalanceChannelClass { + GstColorBalanceChannelClass parent; +} GstCameraSrcColorBalanceChannelClass; + +GType gst_camerasrc_color_balance_channel_get_type( void ); + +const GList *gst_camerasrc_color_balance_list_channels( GstCameraSrc* camerasrc ); +void gst_camerasrc_color_balance_set_value( GstCameraSrc* camerasrc, GstColorBalanceChannel* color_channel, gint value ); +gint gst_camerasrc_color_balance_get_value( GstCameraSrc* camerasrc, GstColorBalanceChannel* color_channel ); + +#define GST_IMPLEMENT_CAMERASRC_COLOR_BALANCE_METHODS( Type, interface_as_function ) \ + \ +static const GList* \ +interface_as_function ## _color_balance_list_channels( GstColorBalance* balance ) \ +{ \ + Type *this = (Type*) balance; \ + return gst_camerasrc_color_balance_list_channels( this ); \ +} \ + \ +static void \ +interface_as_function ## _color_balance_set_value( GstColorBalance* balance, \ + GstColorBalanceChannel* color_channel, \ + gint value ) \ +{ \ + Type *this = (Type*) balance; \ + return gst_camerasrc_color_balance_set_value( this, color_channel, value ); \ +} \ + \ +static gint \ +interface_as_function ## _color_balance_get_value( GstColorBalance* balance, \ + GstColorBalanceChannel* color_channel )\ +{ \ + Type *this = (Type*) balance; \ + return gst_camerasrc_color_balance_get_value( this, color_channel ); \ +} \ + \ +void \ +interface_as_function ## _color_balance_interface_init( GstColorBalanceInterface* klass ) \ +{ \ + /* default virtual functions */ \ + klass->list_channels = interface_as_function ## _color_balance_list_channels; \ + klass->set_value = interface_as_function ## _color_balance_set_value; \ + klass->get_value = interface_as_function ## _color_balance_get_value; \ +} + +#endif /* __GST_CAMERASRC_COLOR_BALANCE_H__ */ + diff --git a/camerasrc/src/include/gstcamerasrccontrol.h b/camerasrc/src/include/gstcamerasrccontrol.h new file mode 100644 index 0000000..bd420b9 --- /dev/null +++ b/camerasrc/src/include/gstcamerasrccontrol.h @@ -0,0 +1,364 @@ +/* + * camerasrc + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jeongmo Yang <jm80.yang@samsung.com> + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __GST_CAMERASRC_CONTROL_H__ +#define __GST_CAMERASRC_CONTROL_H__ + +#include <gst/gst.h> +#include <gst/video/cameracontrol.h> +#include "gstcamerasrc.h" + +G_BEGIN_DECLS + +#define GST_TYPE_CAMERASRC_CONTROL_CHANNEL (gst_camerasrc_control_channel_get_type ()) +#define GST_CAMERASRC_CONTROL_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_CAMERASRC_CONTROL_CHANNEL, GstCamerasrcControlChannel)) +#define GST_CAMERASRC_CONTROL_CHANNEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_CAMERASRC_CONTROL_CHANNEL, GstCamerasrcControlChannelClass)) +#define GST_IS_CAMERASRC_CONTROL_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_CAMERASRC_CONTROL_CHANNEL)) +#define GST_IS_CAMERASRC_CONTROL_CHANNEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_CAMERASRC_CONTROL_CHANNEL)) + +typedef struct _GstCamerasrcControlChannel { + GstCameraControlChannel parent; + guint32 id; +} GstCamerasrcControlChannel; + +typedef struct _GstCamerasrcControlChannelClass { + GstCameraControlChannelClass parent; +} GstCamerasrcControlChannelClass; + +GType gst_camerasrc_control_channel_get_type(void); + +const GList*gst_camerasrc_control_list_channels(GstCameraSrc *camera_src); + +gboolean gst_camerasrc_control_set_value (GstCameraSrc *camera_src, GstCameraControlChannel *control_channel, gint value); +gboolean gst_camerasrc_control_get_value (GstCameraSrc *camera_src, GstCameraControlChannel *control_channel, gint *value); +gboolean gst_camerasrc_control_set_exposure (GstCameraSrc *camera_src, gint type, gint value1, gint value2); +gboolean gst_camerasrc_control_get_exposure (GstCameraSrc *camera_src, gint type, gint *value1, gint *value2); +gboolean gst_camerasrc_control_set_capture_mode (GstCameraSrc *camera_src, gint type, gint value); +gboolean gst_camerasrc_control_get_capture_mode (GstCameraSrc *camera_src, gint type, gint *value); +gboolean gst_camerasrc_control_set_strobe (GstCameraSrc *camera_src, gint type, gint value); +gboolean gst_camerasrc_control_get_strobe (GstCameraSrc *camera_src, gint type, gint *value); +gboolean gst_camerasrc_control_set_detect (GstCameraSrc *camera_src, gint type, gint value); +gboolean gst_camerasrc_control_get_detect (GstCameraSrc *camera_src, gint type, gint *value); +gboolean gst_camerasrc_control_set_zoom (GstCameraSrc *camera_src, gint type, gint value); +gboolean gst_camerasrc_control_get_zoom (GstCameraSrc *camera_src, gint type, gint *value); +gboolean gst_camerasrc_control_set_focus (GstCameraSrc *camera_src, gint mode, gint range); +gboolean gst_camerasrc_control_get_focus (GstCameraSrc *camera_src, gint *mode, gint *range); +gboolean gst_camerasrc_control_start_auto_focus (GstCameraSrc *camera_src); +gboolean gst_camerasrc_control_stop_auto_focus (GstCameraSrc *camera_src); +gboolean gst_camerasrc_control_set_focus_level (GstCameraSrc *camera_src, gint manual_level); +gboolean gst_camerasrc_control_get_focus_level (GstCameraSrc *camera_src, gint *manual_level); +gboolean gst_camerasrc_control_set_auto_focus_area(GstCameraSrc *camera_src, GstCameraControlRectType rect); +gboolean gst_camerasrc_control_get_auto_focus_area(GstCameraSrc *camera_src, GstCameraControlRectType *rect); +gboolean gst_camerasrc_control_set_wdr (GstCameraSrc *camera_src, gint value); +gboolean gst_camerasrc_control_get_wdr (GstCameraSrc *camera_src, gint *value); +gboolean gst_camerasrc_control_set_ahs (GstCameraSrc *camera_src, gint value); +gboolean gst_camerasrc_control_get_ahs (GstCameraSrc *camera_src, gint *value); +gboolean gst_camerasrc_control_get_exif_info (GstCameraSrc *camera_src, GstCameraControlExifInfo *info); +gboolean gst_camerasrc_control_get_basic_dev_info (GstCameraSrc *camera_src, gint dev_id, GstCameraControlCapsInfoType *info); +gboolean gst_camerasrc_control_get_misc_dev_info (GstCameraSrc *camera_src, gint dev_id, GstCameraControlCtrlListInfoType *info); +gboolean gst_camerasrc_control_get_extra_dev_info (GstCameraSrc *camera_src, gint dev_id, GstCameraControlExtraInfoType *info); +void gst_camerasrc_control_set_capture_command(GstCameraSrc *camera_src, GstCameraControlCaptureCommand cmd); + +#define GST_IMPLEMENT_CAMERASRC_CONTROL_METHODS(Type, interface_as_function) \ + \ +static const GList* \ +interface_as_function ## _control_list_channels(GstCameraControl *control) \ +{ \ + Type *this = (Type *) control; \ + return gst_camerasrc_control_list_channels(this); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_set_value(GstCameraControl *control, \ + GstCameraControlChannel *control_channel, int value) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_set_value(this, control_channel, value); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_get_value(GstCameraControl *control, \ + GstCameraControlChannel *control_channel, int *value) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_get_value(this, control_channel, value); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_set_exposure(GstCameraControl *control, \ + gint type, gint value1, gint value2) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_set_exposure(this, type, value1, value2); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_get_exposure(GstCameraControl *control, \ + gint type, gint *value1, gint *value2) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_get_exposure(this, type, value1, value2); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_set_capture_mode(GstCameraControl *control, \ + gint type, gint value) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_set_capture_mode(this, type, value); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_get_capture_mode(GstCameraControl *control, \ + gint type, gint *value) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_get_capture_mode(this, type, value); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_set_strobe(GstCameraControl *control, \ + gint type, gint value) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_set_strobe(this, type, value); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_get_strobe(GstCameraControl *control, \ + gint type, gint *value) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_get_strobe(this, type, value); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_set_detect(GstCameraControl *control, \ + gint type, gint value) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_set_detect(this, type, value); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_get_detect(GstCameraControl *control, \ + gint type, gint *value) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_get_detect(this, type, value); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_set_zoom(GstCameraControl *control, \ + gint type, gint value) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_set_zoom(this, type, value); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_get_zoom(GstCameraControl *control, \ + gint type, gint *value) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_get_zoom(this, type, value); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_set_focus(GstCameraControl *control, \ + gint focus_mode, gint focus_range) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_set_focus(this, focus_mode, focus_range); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_get_focus(GstCameraControl *control, \ + gint *focus_mode, gint *focus_range) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_get_focus(this, focus_mode, focus_range); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_start_auto_focus(GstCameraControl *control) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_start_auto_focus(this); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_stop_auto_focus(GstCameraControl *control) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_stop_auto_focus(this); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_set_focus_level(GstCameraControl *control, \ + gint focus_level) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_set_focus_level(this, focus_level); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_get_focus_level(GstCameraControl *control, \ + gint *focus_level) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_get_focus_level(this, focus_level); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_set_auto_focus_area(GstCameraControl *control, \ + GstCameraControlRectType rect) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_set_auto_focus_area(this, rect); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_get_auto_focus_area(GstCameraControl *control, \ + GstCameraControlRectType *rect) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_get_auto_focus_area(this, rect); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_set_wdr(GstCameraControl *control, \ + gint value) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_set_wdr(this, value); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_get_wdr(GstCameraControl *control, \ + gint *value) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_get_wdr(this, value); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_set_ahs(GstCameraControl *control, \ + gint value) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_set_ahs(this, value); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_get_ahs(GstCameraControl *control, \ + gint *value) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_get_ahs(this, value); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_get_exif_info(GstCameraControl *control, \ + GstCameraControlExifInfo *info) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_get_exif_info(this, info); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_get_basic_dev_info(GstCameraControl *control, \ + gint dev_id, \ + GstCameraControlCapsInfoType *info) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_get_basic_dev_info(this, dev_id, info); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_get_misc_dev_info(GstCameraControl *control, \ + gint dev_id, \ + GstCameraControlCtrlListInfoType *info) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_get_misc_dev_info(this, dev_id, info); \ +} \ + \ +static gboolean \ +interface_as_function ## _control_get_extra_dev_info(GstCameraControl *control, \ + gint dev_id, \ + GstCameraControlExtraInfoType *info) \ +{ \ + Type *this = (Type *)control; \ + return gst_camerasrc_control_get_extra_dev_info(this, dev_id, info); \ +} \ + \ +static void \ +interface_as_function ## _control_set_capture_command(GstCameraControl *control, \ + GstCameraControlCaptureCommand cmd) \ +{ \ + Type *this = (Type *)control; \ + gst_camerasrc_control_set_capture_command(this, cmd); \ + return; \ +} \ + \ +void \ +interface_as_function ## _control_interface_init(GstCameraControlClass *klass) \ +{ \ + GST_CAMERA_CONTROL_TYPE(klass) = GST_CAMERA_CONTROL_HARDWARE; \ + \ + /* default virtual functions */ \ + klass->list_channels = interface_as_function ## _control_list_channels; \ + klass->set_value = interface_as_function ## _control_set_value; \ + klass->get_value = interface_as_function ## _control_get_value; \ + klass->set_exposure = interface_as_function ## _control_set_exposure; \ + klass->get_exposure = interface_as_function ## _control_get_exposure; \ + klass->set_capture_mode = interface_as_function ## _control_set_capture_mode; \ + klass->get_capture_mode = interface_as_function ## _control_get_capture_mode; \ + klass->set_strobe = interface_as_function ## _control_set_strobe; \ + klass->get_strobe = interface_as_function ## _control_get_strobe; \ + klass->set_detect = interface_as_function ## _control_set_detect; \ + klass->get_detect = interface_as_function ## _control_get_detect; \ + klass->set_zoom = interface_as_function ## _control_set_zoom; \ + klass->get_zoom = interface_as_function ## _control_get_zoom; \ + klass->set_focus = interface_as_function ## _control_set_focus; \ + klass->get_focus = interface_as_function ## _control_get_focus; \ + klass->start_auto_focus = interface_as_function ## _control_start_auto_focus; \ + klass->stop_auto_focus = interface_as_function ## _control_stop_auto_focus; \ + klass->set_focus_level = interface_as_function ## _control_set_focus_level; \ + klass->get_focus_level = interface_as_function ## _control_get_focus_level; \ + klass->set_auto_focus_area = interface_as_function ## _control_set_auto_focus_area; \ + klass->get_auto_focus_area = interface_as_function ## _control_get_auto_focus_area; \ + klass->set_wdr = interface_as_function ## _control_set_wdr; \ + klass->get_wdr = interface_as_function ## _control_get_wdr; \ + klass->set_ahs = interface_as_function ## _control_set_ahs; \ + klass->get_ahs = interface_as_function ## _control_get_ahs; \ + klass->get_exif_info = interface_as_function ## _control_get_exif_info; \ + klass->get_basic_dev_info = interface_as_function ## _control_get_basic_dev_info; \ + klass->get_misc_dev_info = interface_as_function ## _control_get_misc_dev_info; \ + klass->get_extra_dev_info = interface_as_function ## _control_get_extra_dev_info; \ + klass->set_capture_command = interface_as_function ## _control_set_capture_command; \ + \ +} + +#endif /* __GST_CAMERASRC_CONTROL_H__ */ |