Rear camera fixes 25/160525/7
authorSylwester Nawrocki <s.nawrocki@samsung.com>
Fri, 30 Jun 2017 08:58:22 +0000 (10:58 +0200)
committerSylwester Nawrocki <s.nawrocki@samsung.com>
Thu, 23 Nov 2017 16:48:43 +0000 (17:48 +0100)
 - Added separate thread for the Sensor/3AA/ISP pipeline
 - Added poll() call before SCP buffer dequeueing

 - Added copying of metadata from 3AA output to ISP output
   buffers

 - Added high FPS/low resolution start sequence for rear
   camera (currently commented out)

 - Removed unused code, rear camera close sequence improvement

The front and the rear camera are working properly, front camera
currently needs 'sync=no' option to gst-launch to avoid low frame
rate.

Length of SCP buffer queue for front camera has been decreased
to minimize lagging.

TODO:
 - ioctl locking needs to be revisited,
 - buffer sizes in camerasrc_create_buffer() need to be corrected
 - proper error handling within the ISP thread needs to be added

Change-Id: If6c8631c93ba6130a07360404df12d5466a20aca
Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
camerasrc/src/camerasrc-internal.c
camerasrc/src/camerasrc.c
camerasrc/src/include/camerasrc-common.h
camerasrc/src/include/camerasrc-internal.h
camerasrc/src/include/camerasrc.h

index 622790c8a5e818748f9408afc4c23a667ef361a3..2aed564dee3e323ba728b6c34dcfaf586cbc5445 100644 (file)
@@ -200,8 +200,6 @@ static int _camerasrc_ioctl(camerasrc_handle_t *handle, int fd, int request, voi
                return CAMERASRC_ERR_INVALID_PARAMETER;
        }
 
-       LOCK(handle);
-
        PRINT_IOCTL_INFO(request, arg);
 
 again:
@@ -210,7 +208,9 @@ again:
        } while (-1 == err && EINTR == errno);
 
        if (err != 0) {
+               LOCK(handle);
                handle->errnum = errno;
+               UNLOCK(handle);
                err = errno;
                strerror_r(err, err_msg, CAMERASRC_ERRMSG_MAX_LEN);
                camsrc_error("ioctl[%x] err : %s", request, err_msg);
@@ -229,15 +229,13 @@ again:
 #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;
@@ -247,21 +245,17 @@ again:
                }
        }
 
-       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
 }
index 2b0926a5c8dd7d02e4fe26126bd6c65578403441..65582a238130ebfd37f75ceae06dd5a9dee401ba 100644 (file)
 #include <stdint.h>
 #include <unistd.h>
 #include <poll.h>
+#include <time.h>
 #include <exynos_drm.h>
 #include <libdrm/drm.h>
 #include <linux/v4l2-subdev.h>
 #include <linux/fimc-is-metadata.h>
+#include <stdbool.h>
 
 #include "camerasrc-common.h"
 #include "camerasrc-internal.h"
@@ -37,6 +39,8 @@
 #define BUF_LEN                         64
 #define META_PLANE_SIZE                 32768
 
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+
 /*
  * LOCAL DEFINITIONS
  */
 #define GRP_SCC                0x06
 #define GRP_SCP                0x07
 
-/* struct camera2_internal_udm */
-/* #define FIMC_IS_ISP_VS2_INIT        0x003F8CE4 */
-#define FIMC_IS_ISP_VS2_INIT_R  0x0044BC0C
-/* #define FIMC_IS_ISP_VS2_INIT_R  0x004438BC */
-/* #define FIMC_IS_ISP_VS2_INIT_R  0x00453F5C */
+#define PRIMARY_SENSOR_WIDTH_1                 5328
+#define PRIMARY_SENSOR_WIDTH_2                 4000
+#define PRIMARY_SENSOR_HEIGHT                  3000
+
+#define FIMC_IS_BAYER_IMG_WIDTH                        2560
+#define FIMC_IS_BAYER_IMG_HEIGHT               1440
 
-#define FIMC_IS_ISP_VS2_STEP   0x8350
-#define FIMC_IS_ISP_VS2_RANGE  40
+#define FIMC_IS_REAR_SENSOR_NUM_BUFFERS                5
+#define FIMC_IS_REAR_3AA0_NUM_BUFFERS          10
+#define FIMC_IS_REAR_ISP_NUM_BUFFERS           5
+#define FIMC_IS_REAR_SCC_NUM_BUFFERS           4
+#define FIMC_IS_REAR_SCP_NUM_BUFFERS           4
 
-#define PRIMARY_SENSOR_WIDTH_1 5328
-#define PRIMARY_SENSOR_WIDTH_2 4000
-#define PRIMARY_SENSOR_HEIGHT  3000
+#define FIMC_IS_FRONT_3AA1_NUM_BUFFERS         5
 
 extern const CAMERASRC_DEV_DEPENDENT_MISC_FUNC *dev_misc_func;
 
@@ -176,6 +182,34 @@ static int _camerasrc_get_device_type_string(camerasrc_handle_t *p, int fd, int
 #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 do_exit = 0; // temporary !!
+
+void __print_time(const char *str, struct timeval *last_tv)
+{
+       static int id;
+       struct timeval tv;
+
+       gettimeofday(&tv, NULL);
+
+       unsigned long t1, t2;
+       t1 = (tv.tv_sec * 1000) +  tv.tv_usec/1000;
+       t2 = (last_tv->tv_sec * 1000) +  last_tv->tv_usec/1000;
+
+       printf("%s[%d] time: %lu. diff: %lu ms\n",
+              str, id++, t1, t1 - t2);
+
+       *last_tv = tv;
+}
+
+
+void __print_timestamp(const char *label, int line, struct timeval *last_tv)
+{
+       char str[100];
+
+       snprintf(str, sizeof(str), "%s:%d ", label, line);
+       __print_time(str, last_tv);
+}
+
 static int buf_4k_align(unsigned int buf_size)
 {
        unsigned int ret;
@@ -481,6 +515,8 @@ int _camerasrc_ioctl_s_ctrl(camerasrc_handle_t *p, int fd, guint cid, int value)
        ctrl.id = cid;
        ctrl.value = value;
 
+       camsrc_info("S_CTRL(%#x, %#x)", cid, value );
+
        return _camerasrc_ioctl(p, fd, VIDIOC_S_CTRL, &ctrl);
 }
 
@@ -729,10 +765,10 @@ int _camerasrc_ioctl_qbuf(camerasrc_handle_t *p, int fd, int type, int memory, i
 
 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;
+       struct v4l2_plane planes[MAX_PLANE_NUM] = {};
+       struct v4l2_buffer lvbuf = {};
        char err_msg[CAMERASRC_ERRMSG_MAX_LEN] = {'\0',};
+       int ret;
 
        if (p == NULL || idx == NULL || fd < 0) {
                camsrc_error("INVALID parameter %p %p %d", p, idx, fd);
@@ -741,8 +777,6 @@ int _camerasrc_ioctl_dqbuf(camerasrc_handle_t *p, int fd, int type, int memory,
 
        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;
@@ -879,6 +913,7 @@ static int __camerasrc_open_device(camerasrc_handle_t *p, camerasrc_dev_id_t cam
                        camsrc_error("open failed [%s] : SENSOR", VIDEO_DEVICE_NODE_PRIMARY);
                        goto OPEN_FAILED;
                }
+               camsrc_info("Opened SENSOR, fd %d", p->fd_sensor);
 
                input = 0x68;
                camsrc_info("[SENSOR] VIDIOC_S_INPUT 0x%x", input);
@@ -894,6 +929,7 @@ static int __camerasrc_open_device(camerasrc_handle_t *p, camerasrc_dev_id_t cam
                        camsrc_error("open failed [%s] : ISP", VIDEO_DEVICE_NODE_ISP);
                        goto OPEN_FAILED;
                }
+               camsrc_info("Opened ISP, fd %d", p->fd_isp);
 
                input = 0xC68;
                camsrc_info("[ISP] VIDIOC_S_INPUT 0x%x", input);
@@ -909,6 +945,7 @@ static int __camerasrc_open_device(camerasrc_handle_t *p, camerasrc_dev_id_t cam
                        camsrc_error("open failed [%s] : 3AA0", VIDEO_DEVICE_NODE_3AA0);
                        goto OPEN_FAILED;
                }
+               camsrc_info("Opened 3AA0, fd %d", p->fd_3aa0);
 
                input = 0x01000068;
                camsrc_info("[3AA0] VIDIOC_S_INPUT 0x%x", input);
@@ -932,6 +969,7 @@ static int __camerasrc_open_device(camerasrc_handle_t *p, camerasrc_dev_id_t cam
                        camsrc_error("open failed [%s] : 3AA0C", VIDEO_DEVICE_NODE_3AA0C);
                        goto OPEN_FAILED;
                }
+               camsrc_info("Opened 3AA0C, fd %d", p->fd_3aa0c);
 
                input = 104;
                camsrc_info("[3AA0C] VIDIOC_S_INPUT 0x%x", input);
@@ -947,6 +985,7 @@ static int __camerasrc_open_device(camerasrc_handle_t *p, camerasrc_dev_id_t cam
                        camsrc_error("open failed [%s] : SCC", VIDEO_DEVICE_NODE_SCC);
                        goto OPEN_FAILED;
                }
+               camsrc_info("Opened SCC, fd %d", p->fd_scc);
 
                input = 8808;
                camsrc_info("[SCC] VIDIOC_S_INPUT 0x%x", input);
@@ -962,6 +1001,7 @@ static int __camerasrc_open_device(camerasrc_handle_t *p, camerasrc_dev_id_t cam
                        camsrc_error("open failed [%s] : SCP", VIDEO_DEVICE_NODE_SCP);
                        goto OPEN_FAILED;
                }
+               camsrc_info("Opened SCP, fd %d", p->fd_scp);
 
                input = 9576;
                camsrc_info("[SCP] VIDIOC_S_INPUT 0x%x", input);
@@ -1110,6 +1150,11 @@ static void __camerasrc_close_device(camerasrc_handle_t *p)
                close(p->fd_sensor);
                p->fd_sensor = -1;
        }
+       if (p->fd_3aa0c > -1) {
+               camsrc_info("close fd_3aa0c : %d", p->fd_3aa0c);
+               close(p->fd_3aa0c);
+               p->fd_3aa0c = -1;
+       }
        if (p->fd_isp > -1) {
                camsrc_info("close fd_isp : %d", p->fd_isp);
                close(p->fd_isp);
@@ -1120,11 +1165,17 @@ static void __camerasrc_close_device(camerasrc_handle_t *p)
                close(p->fd_3aa0);
                p->fd_3aa0 = -1;
        }
-       if (p->fd_3aa0c > -1) {
-               camsrc_info("close fd_3aa0c : %d", p->fd_3aa0c);
-               close(p->fd_3aa0c);
-               p->fd_3aa0c = -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;
        }
+
        if (p->fd_3aa1 > -1) {
                camsrc_info("close fd_3aa1 : %d", p->fd_3aa1);
                close(p->fd_3aa1);
@@ -1186,6 +1237,11 @@ static int _camerasrc_initialize_handle(camerasrc_handle_t *handle)
        handle->first_frame = 1;
        handle->frame_count = 0;
        handle->request_count = 0;
+       handle->qbuf_count_sensor = 0;
+       handle->qbuf_count_3aa_out = 0;
+       handle->qbuf_count_3aa_cap = 0;
+       handle->qbuf_count_isp = 0;
+       handle->qbuf_count_scp = 0;
 
        CLEAR(handle->queued_buf_list);
        CLEAR(handle->format_sensor);
@@ -1236,6 +1292,7 @@ static int _camerasrc_wait_frame_available(camerasrc_handle_t *handle, int timeo
 static int _camerasrc_queue_buffer(camerasrc_handle_t *handle, int buf_index)
 {
        camerasrc_handle_t *p = handle;
+       struct camera2_stream *stream;
        int ret;
 
        if (p == NULL) {
@@ -1243,297 +1300,461 @@ static int _camerasrc_queue_buffer(camerasrc_handle_t *handle, int buf_index)
                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]);
+       stream = (struct camera2_stream *)p->buffer_scp[buf_index].planes[2].start;
+
+       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;
        }
 
+       camsrc_debug("[SCP] QBUF done, buf_index: %d, req_count: %d",
+                    buf_index, stream->fcount);
+       p->qbuf_count_scp++;
+
        return CAMERASRC_SUCCESS;
 }
 
 
-static int _camerasrc_dequeue_buffer(camerasrc_handle_t *handle, int *buf_index, camerasrc_buffer_t *buffer, camerasrc_buffer_t *thm_buffer)
+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;
+       struct pollfd pfd = { .fd = p->fd_scp, .events = POLLIN };
        int ret = CAMERASRC_ERR_UNKNOWN;
-       int buf_index_sensor = 0;
-       int buf_index_3aa_cap = 0;
-       int buf_index_3aa_out = 0;
-       int buf_index_isp = 0;
-       int buf_index_scc = 0;
        int buf_index_scp = 0;
-       unsigned long long timestamp = 0;
-       struct camera2_shot_ext *shot_sensor = NULL;
-       struct camera2_shot_ext *shot_isp = NULL;
-       struct camera2_shot_ext *shot_scc = NULL;
-       struct camera2_shot_ext *shot_3aa = NULL;
 
        if (p->buffer_scp == NULL) {
                camsrc_error("buffer is not allocated");
                return CAMERASRC_ERR_ALLOCATION;
        }
 
-_DQ_AGAIN:
-       /* 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);
+       do {
+               ret = poll(&pfd, 1, CAMERASRC_TIMEOUT_SCP_POLL);
+               if (ret < 0) {
+                       ret = errno;
+                       camsrc_error("[SCP] poll failed: %d", ret);
+                       return CAMERASRC_ERR_IO_CONTROL;
+               }
+
+       } while (!(pfd.revents & (POLLIN | POLLERR | POLLHUP)));
+
+       if (pfd.revents & (POLLERR | POLLHUP))
+               return CAMERASRC_ERR_IO_CONTROL;
+
+       camsrc_debug("[SCP] trying DQBUF...");
+
+       /* 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("[SENSOR] _camerasrc_ioctl_dqbuf failed");
+               camsrc_error("[SCP] _camerasrc_ioctl_dqbuf failed");
                return CAMERASRC_ERR_IO_CONTROL;
        }
 
-       shot_sensor = (struct camera2_shot_ext *)p->buffer_sensor[buf_index_sensor].planes[1].start;
-       timestamp = shot_sensor->shot.dm.sensor.timeStamp;
-       p->frame_count = shot_sensor->shot.dm.request.frameCount;
+       camsrc_debug("[SCP] DQBUF done, index: %d, buf_count: %d",
+                    buf_index_scp, p->scp_buf_count++);
+       p->qbuf_count_scp--;
 
-       camsrc_debug("[SENSOR] DQBUF index %d, frame count %d", buf_index_sensor, p->frame_count);
+       memcpy(buffer, &p->buffer_scp[buf_index_scp], sizeof(camerasrc_buffer_t));
 
-       p->request_count++;
+       *buf_index = buf_index_scp;
 
-       if (p->cur_dev_id == CAMERASRC_DEV_ID_PRIMARY) {
-               /* 3AA0 CAPTURE - DQBUF */
-               ret = _camerasrc_ioctl_dqbuf(p,
-                       p->fd_3aa0,
-                       V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
-                       V4L2_MEMORY_DMABUF,
-                       &buf_index_3aa_cap,
-                       p->buffer_isp[0].num_planes);
-               if (ret != CAMERASRC_SUCCESS) {
-                       camsrc_error("[3AA0 CAPTURE] _camerasrc_ioctl_dqbuf failed");
-                       return CAMERASRC_ERR_IO_CONTROL;
-               }
+       return CAMERASRC_SUCCESS;
+}
 
-               camsrc_debug("[3AA0 - CAPTURE] DQBUF index %d", buf_index_3aa_cap);
+static void *_camerasrc_front_isp_thread_func(void *arg)
+{
+       camerasrc_handle_t *p = arg;
+       struct camera2_shot_ext *shot_sensor;
+       struct camera2_shot_ext *shot_isp;
+       /* struct timeval last_tv = {}; */
+       unsigned long long timestamp = 0;
+       int ret = CAMERASRC_ERR_UNKNOWN;
+       int num_isp_buf_queued = 0;
+       int buf_index_sensor = 0;
+       int buf_index_3aa_cap = 0;
+       int buf_index_3aa_out = 0;
+       int buf_index_isp = 0;
 
-               /* 3AA0 OUTPUT - DQBUF */
-               ret = _camerasrc_ioctl_dqbuf(p,
-                       p->fd_3aa0,
-                       V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
-                       V4L2_MEMORY_DMABUF,
-                       &buf_index_3aa_out,
-                       p->buffer_ta[0].num_planes);
+       /* __print_timestamp(__func__, __LINE__, &last_tv); */
+
+       while (!do_exit) {
+               /* 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("[3AA0 OUTPUT] _camerasrc_ioctl_dqbuf failed");
-                       return CAMERASRC_ERR_IO_CONTROL;
+                       camsrc_error("[SENSOR] _camerasrc_ioctl_dqbuf failed");
+                       break;
                }
 
-               camsrc_debug("[3AA0 - OUTPUT] DQBUF index %d", buf_index_3aa_out);
-       } else {
-               /* SENSOR set shot meta */
+               shot_sensor = (struct camera2_shot_ext *)p->buffer_sensor[buf_index_sensor].planes[1].start;
+               timestamp = shot_sensor->shot.dm.sensor.timeStamp;
+               p->frame_count = shot_sensor->shot.dm.request.frameCount;
+
+               camsrc_debug("[SENSOR] DQBUF index %d, frame count %d", buf_index_sensor, p->frame_count);
+
+               p->request_count++;
+
+               /* Set 3AA metadata */
                _camerasrc_set_shot_meta(p, GRP_3AA, p->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]);
+               /* Queue 3AA1 capture buffer (empty) */
+               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;
+                       break;
                }
 
-               /* 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]);
+               /* Queue 3AA1 output buffer (from sensor) */
+               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;
+                       break;
                }
 
                /* 3AA1 CAPTURE - DQBUF */
-               ret = _camerasrc_ioctl_dqbuf(p,
-                       p->fd_3aa1,
-                       V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
-                       V4L2_MEMORY_DMABUF,
-                       &buf_index_3aa_cap,
-                       p->buffer_sensor[0].num_planes);
+               ret = _camerasrc_ioctl_dqbuf(p, p->fd_3aa1,
+                               V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
+                               V4L2_MEMORY_DMABUF,
+                               &buf_index_3aa_cap,
+                               p->buffer_sensor[0].num_planes);
                if (ret != CAMERASRC_SUCCESS) {
                        camsrc_error("[3AA1 CAPTURE] _camerasrc_ioctl_dqbuf failed");
-                       return CAMERASRC_ERR_IO_CONTROL;
+                       break;
                }
 
                camsrc_debug("[3AA1 - CAPTURE] DQBUF index %d", buf_index_3aa_cap);
 
                /* 3AA1 OUTPUT - DQBUF */
-               ret = _camerasrc_ioctl_dqbuf(p,
-                       p->fd_3aa1,
-                       V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
-                       V4L2_MEMORY_DMABUF,
-                       &buf_index_3aa_out,
-                       p->buffer_sensor[0].num_planes);
+               ret = _camerasrc_ioctl_dqbuf(p, p->fd_3aa1,
+                               V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
+                               V4L2_MEMORY_DMABUF,
+                               &buf_index_3aa_out,
+                               p->buffer_sensor[0].num_planes);
                if (ret != CAMERASRC_SUCCESS) {
                        camsrc_error("[3AA1 OUTPUT] _camerasrc_ioctl_dqbuf failed");
-                       return CAMERASRC_ERR_IO_CONTROL;
+                       break;
                }
 
                camsrc_debug("[3AA1 - OUTPUT] DQBUF index %d", buf_index_3aa_out);
 
+               if (num_isp_buf_queued > 0) {
+                       /* 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");
+                               break;
+                       }
+
+                       num_isp_buf_queued--;
+                       camsrc_debug("[ISP] DQBUF index %d", buf_index_isp);
+               }
+
+               buf_index_isp = buf_index_3aa_cap;
+
+               shot_isp = (struct camera2_shot_ext *)p->buffer_isp[buf_index_isp].planes[1].start;
+#if 0
+               shot_3aa = (struct camera2_shot_ext *)p->buffer_sensor[buf_index_3aa_out].planes[1].start;
+               memcpy(&shot_isp->shot.ctl, &shot_3aa->shot.ctl, sizeof(struct camera2_ctl)
+                                                               - sizeof(struct camera2_entry_ctl));
+               memcpy(&shot_isp->shot.udm, &shot_3aa->shot.udm, sizeof(struct camera2_udm));
+               memcpy(&shot_isp->shot.dm, &shot_3aa->shot.dm, sizeof(struct camera2_dm));
+#endif
+               _camerasrc_set_shot_meta(p, GRP_ISP, p->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_isp,
+                                       &p->buffer_isp[buf_index_isp]);
+               if (ret != CAMERASRC_SUCCESS) {
+                       camsrc_error("[ISP] _camerasrc_ioctl_qbuf index %d, failed[%x]",
+                                    buf_index_3aa_cap, ret);
+                       break;
+               }
+
+               num_isp_buf_queued++;
+
+               camsrc_debug("[ISP] QBUF index %d", buf_index_isp);
+
                /* SENSOR set shot meta */
-               _camerasrc_set_shot_meta(p, GRP_SENSOR, 0, 0, shot_sensor);
+               _camerasrc_set_shot_meta2(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);
+                       break;
+               }
+
+               camsrc_debug("[SENSOR] QBUF index %d", buf_index_sensor);
        }
 
-       shot_isp = (struct camera2_shot_ext *)p->buffer_isp[buf_index_3aa_cap].planes[1].start;
+       return NULL;
+}
 
-       if (p->cur_dev_id == CAMERASRC_DEV_ID_PRIMARY)
-               _camerasrc_set_shot_meta2(p, GRP_ISP, p->frame_count, timestamp, shot_isp);
-       else
-               _camerasrc_set_shot_meta(p, GRP_ISP, p->request_count, timestamp, shot_isp);
 
-       if (p->cur_dev_id != CAMERASRC_DEV_ID_PRIMARY || !p->first_frame) {
-               /* ISP - DQBUF */
+void *_camerasrc_rear_isp_thread_func(void *arg)
+{
+       camerasrc_handle_t *p = arg;
+       struct camera2_shot_ext *shot_sensor;
+       struct camera2_shot_ext *shot_isp;
+       struct camera2_shot_ext *shot_3aa;
+       /* struct timeval last_tv = {}; */
+       int buf_index_sensor = 0;
+       int buf_index_3aa_cap = 0;
+       int buf_index_3aa_out = 0;
+       int buf_index_isp = 0;
+       int isp_buf_count = 0;
+       int sensor_buf_count = 0;
+       int ret;
+
+       /* __print_timestamp(__func__, __LINE__, &last_tv); */
+
+       while (!do_exit) {
                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);
+                                            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("[3AA1 OUTPUT] _camerasrc_ioctl_dqbuf failed");
-                       return CAMERASRC_ERR_IO_CONTROL;
+                       /* TODO: save the ISP thread error status for reference in the main thread */
+                       camsrc_error("[SENSOR] _camerasrc_ioctl_dqbuf failed");
+                       break;
                }
 
-               camsrc_debug("[ISP] DQBUF index %d", buf_index_isp);
-       } else {
-               camsrc_warning("primary camera first frame");
-       }
+               p->qbuf_count_sensor--;
+               sensor_buf_count++;
 
-       /* ISP - QBUF */
-       ret = _camerasrc_ioctl_qbuf(p,
-               p->fd_isp,
-               V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
-               V4L2_MEMORY_DMABUF,
-               buf_index_3aa_cap,
-               &p->buffer_isp[buf_index_3aa_cap]);
-       if (ret != CAMERASRC_SUCCESS) {
-               camsrc_error("[ISP] _camerasrc_ioctl_qbuf index %d, failed[%x]", buf_index_3aa_cap, ret);
-               return CAMERASRC_ERR_IO_CONTROL;
-       }
+               shot_sensor = (struct camera2_shot_ext *)p->buffer_sensor[buf_index_sensor].planes[1].start;
 
-       camsrc_debug("[ISP] QBUF index %d", buf_index_3aa_cap);
 
-       /* SENSOR set shot meta */
-       _camerasrc_set_shot_meta2(p, GRP_SENSOR, 0, 0, shot_sensor);
+               /* 3AA0 Capture DQBUF */
+               ret = _camerasrc_ioctl_dqbuf(p,
+                                             p->fd_3aa0,
+                                             V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
+                                             V4L2_MEMORY_DMABUF,
+                                             &buf_index_3aa_cap,
+                                             p->buffer_isp[0].num_planes);
+               if (ret != CAMERASRC_SUCCESS) {
+                       camsrc_error("[3AA0 CAPTURE] _camerasrc_ioctl_dqbuf failed");
+                       break;
+               }
+               p->qbuf_count_3aa_cap--;
 
-       /* 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;
-       }
+               camsrc_debug("[3AA0 - CAPTURE] DQBUF index %d", buf_index_3aa_cap);
 
-       camsrc_debug("[SENSOR] QBUF index %d", buf_index_sensor);
+               /* 3AA0 Output - DQBUF */
+               ret = _camerasrc_ioctl_dqbuf(p,
+                                            p->fd_3aa0,
+                                            V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
+                                            V4L2_MEMORY_DMABUF,
+                                            &buf_index_3aa_out,
+                                            p->buffer_ta[0].num_planes);
+               if (ret != CAMERASRC_SUCCESS) {
+                       camsrc_error("[3AA0 OUTPUT] _camerasrc_ioctl_dqbuf failed");
+                       break;
+               }
+               p->qbuf_count_3aa_out--;
 
-       //_camerasrc_wait_frame_available(p, 2000);
+               camsrc_debug("[3AA0 - OUTPUT] DQBUF index %d", buf_index_3aa_out);
 
-       if (p->cur_dev_id == CAMERASRC_DEV_ID_PRIMARY) {
+               shot_isp = (struct camera2_shot_ext *)p->buffer_isp[buf_index_3aa_cap].planes[1].start;
+
+               if (p->qbuf_count_isp > 2) {
+                       /* 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");
+                               break;
+                       }
+                       p->qbuf_count_isp--;
+
+                       isp_buf_count++;
+                       //__print_timestamp("ISP dqbuf done", __LINE__, &last_tv);
+                       camsrc_debug("[ISP] DQBUF index %d. %d buffers dequeued",
+                                    buf_index_isp, isp_buf_count);
+               } else {
+                       camsrc_warning("primary camera first frame");
+               }
+
+               /* Set ISP metadata */
                shot_3aa = (struct camera2_shot_ext *)p->buffer_ta[buf_index_3aa_out].planes[1].start;
 
-               /* set 3AA0 meta */
-               _camerasrc_set_shot_meta2(p, GRP_3AA, p->frame_count, 0, shot_3aa);
+               memcpy(&shot_isp->shot.ctl, &shot_3aa->shot.ctl, sizeof(struct camera2_ctl) - sizeof(struct camera2_entry_ctl));
+               memcpy(&shot_isp->shot.udm, &shot_3aa->shot.udm, sizeof(struct camera2_udm));
+               memcpy(&shot_isp->shot.dm, &shot_3aa->shot.dm, sizeof(struct camera2_dm));
 
-               /* 3AA0 OUTPUT - QBUF */
-               ret = _camerasrc_ioctl_qbuf(p,
-                       p->fd_3aa0,
-                       V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
-                       V4L2_MEMORY_DMABUF,
-                       buf_index_3aa_out,
-                       &p->buffer_ta[buf_index_3aa_out]);
+               memset(&shot_isp->node_group, 0x0, sizeof(shot_isp->node_group));
+
+               shot_isp->node_group.leader.vid = FIMC_IS_VIDEO_ISP_NUM;
+               shot_isp->node_group.leader.request = 1;
+               shot_isp->node_group.leader.input.cropRegion[2] = FIMC_IS_BAYER_IMG_WIDTH;
+               shot_isp->node_group.leader.input.cropRegion[3] = FIMC_IS_BAYER_IMG_HEIGHT;
+
+               shot_isp->node_group.leader.output.cropRegion[2] = FIMC_IS_BAYER_IMG_WIDTH;
+               shot_isp->node_group.leader.output.cropRegion[3] = FIMC_IS_BAYER_IMG_HEIGHT;
+
+               /* SCP */
+               shot_isp->node_group.capture[0].vid = FIMC_IS_VIDEO_SCP_NUM;
+               shot_isp->node_group.capture[0].request = 1;
+               shot_isp->node_group.capture[0].input.cropRegion[2] = p->format_scp.img_size.width;
+               shot_isp->node_group.capture[0].input.cropRegion[3] = p->format_scp.img_size.height;
+
+               shot_isp->node_group.capture[0].output.cropRegion[2] = p->format_scp.img_size.width;
+               shot_isp->node_group.capture[0].output.cropRegion[3] = p->format_scp.img_size.height;
+
+               shot_isp->setfile = shot_3aa->setfile;
+               shot_isp->drc_bypass = shot_3aa->drc_bypass;
+               shot_isp->dis_bypass = shot_3aa->dis_bypass;
+               shot_isp->dnr_bypass = shot_3aa->dnr_bypass;
+               shot_isp->fd_bypass = shot_3aa->fd_bypass;
+
+               shot_isp->shot.uctl.companionUd.wdr_mode = shot_3aa->shot.uctl.companionUd.wdr_mode;
+               shot_isp->shot.dm.request.frameCount = shot_3aa->shot.dm.request.frameCount;
+               shot_isp->shot.magicNumber= shot_3aa->shot.magicNumber;
+
+               /* Queue 3AA processed buffer to ISP */
+
+               ret = _camerasrc_ioctl_qbuf(p, p->fd_isp,
+                                       V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
+                                       V4L2_MEMORY_DMABUF,
+                                       buf_index_3aa_cap,
+                                       &p->buffer_isp[buf_index_3aa_cap]);
                if (ret != CAMERASRC_SUCCESS) {
-                       camsrc_error("[3AA0 - OUTPUT] _camerasrc_ioctl_qbuf index %d, failed[%x]", buf_index_3aa_cap, ret);
-                       return CAMERASRC_ERR_IO_CONTROL;
+                       camsrc_error("[ISP] _camerasrc_ioctl_qbuf index %d, failed[%x]",
+                                       buf_index_3aa_cap, ret);
+                       /* FIXME: error handling */
+                       break;
                }
+               p->qbuf_count_isp++;
+               camsrc_debug("[ISP] QBUF index %d", buf_index_3aa_cap);
 
-               camsrc_debug("[3AA - OUTPUT] QBUF index %d", buf_index_3aa_out);
 
-               /* 3AA0 CAPTURE - QBUF */
+               /* Queue buffer back to the sensor video node */
+               _camerasrc_set_shot_meta2(p, GRP_SENSOR, 0, 0, shot_sensor);
+
+               /* SENSOR - QBUF */
                ret = _camerasrc_ioctl_qbuf(p,
-                       p->fd_3aa0,
-                       V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
-                       V4L2_MEMORY_DMABUF,
-                       buf_index_3aa_cap,
-                       &p->buffer_isp[buf_index_3aa_cap]);
+                                           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("[3AA0 - CAPTURE] _camerasrc_ioctl_qbuf index %d, failed[%x]", buf_index_3aa_cap, ret);
-                       return CAMERASRC_ERR_IO_CONTROL;
+                       camsrc_error("[SENSOR] _camerasrc_ioctl_qbuf index %d, failed[%x]",
+                                    buf_index_sensor, ret);
+                       break;
                }
 
-               camsrc_debug("[3AA - CAPTURE] QBUF index %d", buf_index_3aa_cap);
-       } else {
-               /* 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);
+               p->qbuf_count_sensor++;
+
+               shot_3aa = (struct camera2_shot_ext *)p->buffer_ta[buf_index_3aa_out].planes[1].start;
+               _camerasrc_set_shot_meta2(p, GRP_3AA, 0, 0, shot_3aa);
+
+               /* 3AA0 OUTPUT - QBUF */
+               ret = _camerasrc_ioctl_qbuf(p,
+                                       p->fd_3aa0,
+                                       V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
+                                       V4L2_MEMORY_DMABUF,
+                                       buf_index_3aa_out,
+                                       &p->buffer_ta[buf_index_3aa_out]);
+
                if (ret != CAMERASRC_SUCCESS) {
-                       camsrc_error("[SCC] _camerasrc_ioctl_dqbuf failed");
-                       return CAMERASRC_ERR_IO_CONTROL;
+                       camsrc_error("[3AA0 - OUTPUT] _camerasrc_ioctl_qbuf index %d, failed[%x]",
+                               buf_index_3aa_cap, ret);
+                       break;
                }
+               p->qbuf_count_3aa_out++;
 
-               shot_scc = (struct camera2_shot_ext *)p->buffer_scc[buf_index_scc].planes[1].start;
-               shot_scc->shot.dm.request.frameCount = p->request_count;
+               camsrc_debug("[3AA - OUTPUT] QBUF index %d", buf_index_3aa_out);
 
-               /* SCC - QBUF */
+               /* 3AA0 CAPTURE - 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]);
+                                       p->fd_3aa0,
+                                       V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
+                                       V4L2_MEMORY_DMABUF,
+                                       buf_index_3aa_cap,
+                                       &p->buffer_isp[buf_index_3aa_cap]);
                if (ret != CAMERASRC_SUCCESS) {
-                       camsrc_error("[SCC] _camerasrc_ioctl_qbuf index %d, failed[%x]", buf_index_scc, ret);
-                       return CAMERASRC_ERR_IO_CONTROL;
+                       camsrc_error("[3AA0 - CAPTURE] _camerasrc_ioctl_qbuf index %d, failed[%x]",
+                                    buf_index_3aa_cap, ret);
+                       break;
                }
-       }
+               p->qbuf_count_3aa_cap++;
 
-       if (p->first_frame) {
-               p->first_frame = 0;
-               camsrc_warning("DQ again...");
-               goto _DQ_AGAIN;
-       }
+               camsrc_debug("[3AA - CAPTURE] QBUF index %d", buf_index_3aa_cap);
+               camsrc_debug("[Sensor] buffer count: %d\n", sensor_buf_count);
 
-       /* 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;
+               /* FIXME: This delay prevents the tearing issue */
+               g_usleep((G_USEC_PER_SEC / CAMERASRC_PRIMARY_FRAME_RATE) + 1);
        }
 
+       /* Dequeue any remaining sensor and 3AA buffers from the driver */
+       while (p->qbuf_count_sensor--) {
+               _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);
+       }
 
-       camsrc_debug("[SCP] DQBUF index : %d", buf_index_scp);
 
-       memcpy(buffer, &p->buffer_scp[buf_index_scp], sizeof(camerasrc_buffer_t));
+       while (p->qbuf_count_3aa_out--) {
+               _camerasrc_ioctl_dqbuf(p, p->fd_3aa0,
+                                      V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
+                                      V4L2_MEMORY_DMABUF,
+                                      &buf_index_3aa_out,
+                                      p->buffer_ta[0].num_planes);
+       }
 
-       *buf_index = buf_index_scp;
+       while (p->qbuf_count_3aa_cap-- > 1) {
+               _camerasrc_ioctl_dqbuf(p, p->fd_3aa0,
+                                      V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
+                                      V4L2_MEMORY_DMABUF,
+                                      &buf_index_3aa_cap,
+                                      p->buffer_isp[0].num_planes);
+       }
 
-       return CAMERASRC_SUCCESS;
+       return NULL;
 }
 
 static int _camerasrc_dump_format(camsrc_handle_t handle);
@@ -1591,14 +1812,14 @@ int camerasrc_create(camsrc_handle_t *phandle)
                camsrc_info("AF Condition creating status : %s", err_msg);
        }
 
-       camsrc_info("Thread creation start..");
+       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..");
+       camsrc_info("Thread creation end.");
 
        /* set default focus mode */
        p->cur_af_mode = CAMERASRC_AF_MODE_CONTINUOUS;
@@ -1822,10 +2043,9 @@ int camerasrc_get_num_buffer(camsrc_handle_t handle, unsigned int *num_buffer)
 static int _camerasrc_allocate_device_buffer(camsrc_handle_t handle, camerasrc_buffer_t **device_buffer,
        camerasrc_format_t *device_format, int buffer_size[], int num_planes)
 {
-       int buffer_struct_size = 0;
-       int buffer_index = 0;
-       int plane_index = 0;
-       camerasrc_buffer_t *device_buffer_new = NULL;
+       camerasrc_buffer_t *device_buffer_new;
+       int buffer_index;
+       int plane_index;
 
        if (!handle || !device_buffer || !device_format) {
                camsrc_error("NULL ptr %p %p %p", handle, device_buffer, device_format);
@@ -1834,36 +2054,35 @@ static int _camerasrc_allocate_device_buffer(camsrc_handle_t handle, camerasrc_b
 
        camsrc_info("num buffers %d", device_format->num_buffers);
 
-       buffer_struct_size  = sizeof(camerasrc_buffer_t) * device_format->num_buffers;
-
-       device_buffer_new = (camerasrc_buffer_t *)malloc(buffer_struct_size);
+       device_buffer_new = calloc(device_format->num_buffers, sizeof(camerasrc_buffer_t));
        if (!device_buffer_new) {
-               camsrc_error("failed to alloc device buffer");
+               camsrc_error("failed to allocate device buffer");
                return CAMERASRC_ERR_ALLOCATION;
        }
 
-       memset(device_buffer_new, 0x0, buffer_struct_size);
-
        for (buffer_index = 0 ; buffer_index < device_format->num_buffers ; buffer_index++) {
                device_buffer_new[buffer_index].num_planes = num_planes;
                for (plane_index = 0 ; plane_index < num_planes ; plane_index++) {
+
+                       camerasrc_buffer_t *buf = &device_buffer_new[buffer_index];
+
                        if (!camerasrc_tbm_alloc_buffer(handle, buffer_size[plane_index],
-                               &(device_buffer_new[buffer_index].planes[plane_index].bo),
-                               &(device_buffer_new[buffer_index].planes[plane_index].fd),
-                               &(device_buffer_new[buffer_index].planes[plane_index].start))) {
+                                                       &buf->planes[plane_index].bo,
+                                                       &buf->planes[plane_index].fd,
+                                                       &buf->planes[plane_index].start)) {
                                camsrc_error("camerasrc_tbm_alloc_buffer failed[%d:%d] : size %d",
                                        buffer_index, plane_index, buffer_size[plane_index]);
                                goto _ALLOC_FAILED;
                        }
 
-                       device_buffer_new[buffer_index].planes[plane_index].length = buffer_size[plane_index];
+                       buf->planes[plane_index].length = buffer_size[plane_index];
 
                        camsrc_info("buffer [%d][%d] BUF: bo[%p] fd[%d] addr[%p] size[%d]",
                                buffer_index, plane_index,
-                               device_buffer_new[buffer_index].planes[plane_index].bo,
-                               device_buffer_new[buffer_index].planes[plane_index].fd,
-                               device_buffer_new[buffer_index].planes[plane_index].start,
-                               device_buffer_new[buffer_index].planes[plane_index].length);
+                               buf->planes[plane_index].bo,
+                               buf->planes[plane_index].fd,
+                               buf->planes[plane_index].start,
+                               buf->planes[plane_index].length);
                }
        }
 
@@ -1948,27 +2167,12 @@ int camerasrc_create_buffer(camsrc_handle_t handle)
        preview_width = p->format_scp.img_size.width;
        preview_height = p->format_scp.img_size.height;
 
-       p->format_3aa1.num_buffers = p->format_scp.num_buffers - 6;
+       p->format_3aa1.num_buffers = FIMC_IS_FRONT_3AA1_NUM_BUFFERS;
 
        /**
         * buffer allocation
         */
        if (p->cur_dev_id == CAMERASRC_DEV_ID_PRIMARY) {
-               /* SENSOR */
-               camsrc_warning("buffer_sensor allocation");
-
-               buffer_size[0] = 25584000; /* for 5328x3000 */
-               buffer_size[1] = META_PLANE_SIZE;
-               buffer_size[2] = 0;
-               buffer_size[3] = 0;
-
-               p->format_sensor.num_buffers = 5;
-
-               if (_camerasrc_allocate_device_buffer(handle, &p->buffer_sensor, &p->format_sensor, buffer_size, 2) != CAMERASRC_SUCCESS) {
-                       camsrc_error("alloc buffer_sensor failed");
-                       goto CREATE_BUFFER_FAILED;
-               }
-
                /* TA */
                camsrc_warning("buffer_ta allocation");
 
@@ -1977,7 +2181,7 @@ int camerasrc_create_buffer(camsrc_handle_t handle)
                buffer_size[2] = 0;
                buffer_size[3] = 0;
 
-               p->format_ta.num_buffers = 5;
+               p->format_ta.num_buffers = 10;
 
                if (_camerasrc_allocate_device_buffer(handle, &p->buffer_ta, &p->format_ta, buffer_size, 2) != CAMERASRC_SUCCESS) {
                        camsrc_error("alloc buffer_ta failed");
@@ -2002,8 +2206,8 @@ int camerasrc_create_buffer(camsrc_handle_t handle)
                /* SCP */
                camsrc_warning("buffer_scp allocation");
 
-               buffer_size[0] = preview_width * preview_height;//2089216;
-               buffer_size[1] = buffer_size[0] >> 1;//1044736;
+               buffer_size[0] = 2089216; //preview_width * preview_height;//2089216;
+               buffer_size[1] = 1044736; //buffer_size[0] >> 1;//1044736;
                buffer_size[2] = META_PLANE_SIZE;
                buffer_size[3] = 0;
 
@@ -2011,6 +2215,21 @@ int camerasrc_create_buffer(camsrc_handle_t handle)
                        camsrc_error("alloc buffer_scp failed");
                        goto CREATE_BUFFER_FAILED;
                }
+
+               /* SENSOR */
+               camsrc_warning("buffer_sensor allocation");
+
+               buffer_size[0] = 25584000; /* for 5328x3000 */
+               buffer_size[1] = META_PLANE_SIZE;
+               buffer_size[2] = 0;
+               buffer_size[3] = 0;
+
+               p->format_sensor.num_buffers = 5;
+
+               if (_camerasrc_allocate_device_buffer(handle, &p->buffer_sensor, &p->format_sensor, buffer_size, 2) != CAMERASRC_SUCCESS) {
+                       camsrc_error("alloc buffer_sensor failed");
+                       goto CREATE_BUFFER_FAILED;
+               }
        } else {
                /* set sensor resolution */
                sensor_width = FRONT_SENSOR_SIZE_WIDTH + SENSOR_MARGIN_WIDTH;
@@ -2025,7 +2244,7 @@ int camerasrc_create_buffer(camsrc_handle_t handle)
                buffer_size[2] = 0;
                buffer_size[3] = 0;
 
-               p->format_sensor.num_buffers = p->format_scp.num_buffers - 6;
+               p->format_sensor.num_buffers = FIMC_IS_REAR_SENSOR_NUM_BUFFERS;
 
                if (_camerasrc_allocate_device_buffer(handle, &p->buffer_sensor, &p->format_sensor, buffer_size, 2) != CAMERASRC_SUCCESS) {
                        camsrc_error("alloc buffer_sensor failed");
@@ -2033,7 +2252,7 @@ int camerasrc_create_buffer(camsrc_handle_t handle)
                }
 
                /* ISP */
-               p->format_isp.num_buffers = p->format_scp.num_buffers - 6;
+               p->format_isp.num_buffers = FIMC_IS_REAR_ISP_NUM_BUFFERS;
 
                if (_camerasrc_allocate_device_buffer(handle, &p->buffer_isp, &p->format_isp, buffer_size, 2) != CAMERASRC_SUCCESS) {
                        camsrc_error("alloc buffer_isp failed");
@@ -2041,7 +2260,7 @@ int camerasrc_create_buffer(camsrc_handle_t handle)
                }
 
                /* SCC */
-               p->format_scc.num_buffers = p->format_scp.num_buffers - 6;
+               p->format_scc.num_buffers = FIMC_IS_REAR_SCC_NUM_BUFFERS;
 
                if (_camerasrc_allocate_device_buffer(handle, &p->buffer_scc, &p->format_scc, buffer_size, 2) != CAMERASRC_SUCCESS) {
                        camsrc_error("alloc buffer_scc failed");
@@ -2197,7 +2416,8 @@ int camerasrc_start_preview_stream(camsrc_handle_t handle)
 
        if (p->cur_dev_id == CAMERASRC_DEV_ID_PRIMARY) {
                /* FPS */
-               err = _camerasrc_ioctl_s_parm(p, p->fd_sensor, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, 1, 30);
+               err = _camerasrc_ioctl_s_parm(p, p->fd_sensor, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, 1,
+                                             CAMERASRC_PRIMARY_FRAME_RATE);
                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);
@@ -2272,7 +2492,7 @@ int camerasrc_start_preview_stream(camsrc_handle_t handle)
                }
 
                /* 3AA0_OUTPUT reqbufs */
-               p->format_3aa0.num_buffers = 5;
+               p->format_3aa0.num_buffers = FIMC_IS_REAR_3AA0_NUM_BUFFERS;
                type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
                err = _camerasrc_ioctl_reqbufs(p, p->fd_3aa0, p->format_3aa0.num_buffers,
                                               type, V4L2_MEMORY_DMABUF, &p->format_3aa0.num_buffers);
@@ -2588,39 +2808,13 @@ int camerasrc_start_preview_stream(camsrc_handle_t handle)
                camsrc_info("[SCP] V4L2_CID_IS_COLOR_RANGE done");
        }
 
-       /* QBUF */
-       if (p->buffer_scp) {
-               for (i = 0 ; i < p->format_scp.num_buffers ; i++) {
-                       if (p->cur_dev_id == CAMERASRC_DEV_ID_PRIMARY) {
-                               err = _camerasrc_set_shot_meta2(p, GRP_SCP, i, 0, (struct camera2_shot_ext *)p->buffer_scp[i].planes[2].start);
-                       } else {
-                               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);
-       }
-
        if (p->buffer_sensor) {
                if (p->cur_dev_id == CAMERASRC_DEV_ID_PRIMARY) {
-                       err = _camerasrc_set_shot_meta2(p, GRP_SENSOR, 0, 0, (struct camera2_shot_ext *)p->buffer_sensor[0].planes[1].start);
+                       err = _camerasrc_set_shot_meta2(p, GRP_SENSOR, 0, 0,
+                                               (struct camera2_shot_ext *)p->buffer_sensor[0].planes[1].start);
                } else {
-                       err = _camerasrc_set_shot_meta(p, GRP_SENSOR, 0, 0, (struct camera2_shot_ext *)p->buffer_sensor[0].planes[1].start);
+                       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) {
@@ -2628,7 +2822,7 @@ int camerasrc_start_preview_stream(camsrc_handle_t handle)
                        return err;
                }
 
-               for (i = 0 ; i < p->format_sensor.num_buffers ; i++) {
+               for (i = 0 ; i < p->format_sensor.num_buffers; i++) {
                        err = _camerasrc_ioctl_qbuf(p,
                                p->fd_sensor,
                                V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
@@ -2639,11 +2833,46 @@ int camerasrc_start_preview_stream(camsrc_handle_t handle)
                                camsrc_error("[SENSOR] _camerasrc_ioctl_qbuf index %d, failed[%x]", i, err);
                                return CAMERASRC_ERR_IO_CONTROL;
                        }
+                       p->qbuf_count_sensor++;
                }
 
                camsrc_info("[SENSOR] QBUF done - %d", p->format_sensor.num_buffers);
        }
 
+       /* QBUF */
+       if (p->buffer_scp) {
+               camsrc_info("[SCP] queueing %d buffers...", p->format_scp.num_buffers);
+
+               for (i = 0 ; i < p->format_scp.num_buffers; i++) {
+                       if (p->cur_dev_id == CAMERASRC_DEV_ID_PRIMARY) {
+                               err = _camerasrc_set_shot_meta2(p, GRP_SCP, 0, 0,
+                                                       (struct camera2_shot_ext *)p->buffer_scp[i].planes[2].start);
+                       } else {
+                               err = _camerasrc_set_shot_meta(p, GRP_SCP, 0, 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;
+                       }
+
+                       p->qbuf_count_scp++;
+               }
+
+               camsrc_info("[SCP] QBUF done - %d buffers", 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) {
@@ -2739,8 +2968,10 @@ int camerasrc_start_preview_stream(camsrc_handle_t handle)
 
        if (p->cur_dev_id == CAMERASRC_DEV_ID_PRIMARY) {
                /* 3AA buffers qbuf */
-               for (i = 0 ; i < p->format_3aa0.num_buffers ; i++) {
-                       err = _camerasrc_set_shot_meta2(p, GRP_3AA, 0, 0, (struct camera2_shot_ext *)p->buffer_ta[i].planes[1].start);
+               for (i = 0 ; i < p->format_isp.num_buffers; i++) {
+                       struct camera2_shot_ext *shot_3aa = (struct camera2_shot_ext *)p->buffer_ta[i].planes[1].start;
+
+                       err = _camerasrc_set_shot_meta2(p, GRP_3AA, 0, 0, shot_3aa);
                        if (err != CAMERASRC_SUCCESS) {
                                camsrc_error("[TA] _camerasrc_set_shot_meta index %d, failed[%x]", i, err);
                                return err;
@@ -2757,6 +2988,10 @@ int camerasrc_start_preview_stream(camsrc_handle_t handle)
                                return CAMERASRC_ERR_IO_CONTROL;
                        }
 
+                       p->qbuf_count_3aa_out++;
+
+                       camsrc_info("[3AA0] OUTPUT buffer %d queued", i);
+
                        err = _camerasrc_ioctl_qbuf(p,
                                p->fd_3aa0,
                                V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
@@ -2767,8 +3002,16 @@ int camerasrc_start_preview_stream(camsrc_handle_t handle)
                                camsrc_error("[3AA0_CAPTURE - ISP] _camerasrc_ioctl_qbuf index %d, failed[%x]", i, err);
                                return CAMERASRC_ERR_IO_CONTROL;
                        }
+
+                       p->qbuf_count_3aa_cap++;
+
+                       camsrc_info("[3AA0] CAPTURE buffer %d queued", i);
                }
 
+               p->request_count = i + 1;
+
+               camsrc_info("request_count: %d", p->request_count);
+
                /* sensor s_ctrl */
                err = _camerasrc_ioctl_s_ctrl(p, p->fd_sensor, 0x9a100e, 1);
                if (err != CAMERASRC_SUCCESS) {
@@ -2776,6 +3019,8 @@ int camerasrc_start_preview_stream(camsrc_handle_t handle)
                        camsrc_error("[SENSOR] S_CTRL 0x9a100e -> 1 failed[%x] : %s", err, err_msg);
                        return CAMERASRC_ERR_IO_CONTROL;
                }
+
+               camsrc_info("[SENSOR] S_CTRL(0x9a100e, 1) done");
        } else {
                err = _camerasrc_ioctl_s_ctrl(p, p->fd_sensor, V4L2_CID_IS_S_STREAM, TRUE);
                if (err != CAMERASRC_SUCCESS) {
@@ -2812,6 +3057,18 @@ int camerasrc_start_preview_stream(camsrc_handle_t handle)
                }
        }
 
+       camsrc_info("Creating ISP thread...\n");
+
+       if (p->cur_dev_id == CAMERASRC_DEV_ID_PRIMARY)
+               err = pthread_create(&p->isp_thread, NULL, _camerasrc_rear_isp_thread_func, p);
+       else
+               err = pthread_create(&p->isp_thread, NULL, _camerasrc_front_isp_thread_func, p);
+       if (err) {
+               /* TODO: Error handling */
+               camsrc_error("[ISP] Failed to create the ISP thread");
+               return CAMERASRC_ERR_IO_CONTROL;
+       }
+
        CAMERASRC_SET_STATE(p, CAMERASRC_STATE_PREVIEW);
 
        return CAMERASRC_SUCCESS;
@@ -2849,6 +3106,12 @@ int camerasrc_stop_stream(camsrc_handle_t handle)
        p->first_frame = 1;
        UNLOCK(p);
 
+       camsrc_info("Stopping streaming and releasing buffers...");
+
+       /* FIXME */
+       do_exit = 1;
+       pthread_join(p->isp_thread, 0);
+
        /* STREAM OFF */
        if (p->cur_dev_id == CAMERASRC_DEV_ID_PRIMARY) {
                /* sensor s_ctrl */
@@ -2859,7 +3122,7 @@ int camerasrc_stop_stream(camsrc_handle_t handle)
                        return CAMERASRC_ERR_IO_CONTROL;
                }
        } else if (p->cur_dev_id == CAMERASRC_DEV_ID_SECONDARY &&
-           p->streamon_sensor_sub) {
+                  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);
@@ -2872,6 +3135,8 @@ int camerasrc_stop_stream(camsrc_handle_t handle)
                camsrc_info("[SENSOR] V4L2_CID_IS_S_STREAM 0 done");
        }
 
+       /* Disable streaming and free video buffers */
+
        if (p->streamon_sensor) {
                ret = _camerasrc_ioctl_stream(p, p->fd_sensor, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, FALSE);
                if (ret != CAMERASRC_SUCCESS) {
@@ -2885,34 +3150,86 @@ int camerasrc_stop_stream(camsrc_handle_t handle)
                camsrc_info("[SENSOR] STREAMOFF done");
        }
 
+       /* 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");
+       }
+
+       ret = _camerasrc_ioctl_s_ctrl(p, p->fd_3aa0, 0x9a1032, 4096);
+       if (ret != CAMERASRC_SUCCESS)
+               camsrc_error("[3AA0] _camerasrc_ioctl_s_ctrl failed[%x]", ret);
+
+       ret = _camerasrc_ioctl_s_ctrl(p, p->fd_3aa0, 0x9a1032, 4096);
+       if (ret != CAMERASRC_SUCCESS)
+               camsrc_error("[3AA0] _camerasrc_ioctl_s_ctrl failed[%x]", ret);
+
+       ret = _camerasrc_ioctl_s_ctrl(p, p->fd_isp, 0x9a1032, 4096);
+       if (ret != CAMERASRC_SUCCESS)
+               camsrc_error("[ISP] _camerasrc_ioctl_s_ctrl failed[%x]", ret);
+
+       /* 3AA0 - OUTPUT */
        if (p->streamon_3aa0_output) {
-#if 0
                ret = _camerasrc_ioctl_stream(p, p->fd_3aa0, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, FALSE);
                if (ret != CAMERASRC_SUCCESS) {
                        strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN);
                        camsrc_error("[3AA0 - OUTPUT] _camerasrc_ioctl_stream failed[%x] : %s", ret, err_msg);
                        return CAMERASRC_ERR_IO_CONTROL;
                }
-#endif
+
                p->streamon_3aa0_output = FALSE;
 
                camsrc_info("[3AA0 - OUTPUT] STREAMOFF done");
        }
 
+       if (p->reqbuf_3aa0_output) {
+               ret = _camerasrc_ioctl_reqbufs(p, p->fd_3aa0, 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("[3AA0 - OUTPUT] _camerasrc_ioctl_reqbufs failed[%x] : %s", ret, err_msg);
+                       return CAMERASRC_ERR_IO_CONTROL;
+               }
+
+               p->reqbuf_3aa0_output = FALSE;
+
+               camsrc_info("[3AA0 - OUTPUT] REQBUF 0 done");
+       }
+
+       /* 3AA0 - CAPTURE */
        if (p->streamon_3aa0_capture) {
-#if 0
                ret = _camerasrc_ioctl_stream(p, p->fd_3aa0, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, FALSE);
                if (ret != CAMERASRC_SUCCESS) {
                        strerror_r(p->errnum, err_msg, CAMERASRC_ERRMSG_MAX_LEN);
                        camsrc_error("[3AA0 - CAPTURE] _camerasrc_ioctl_stream failed[%x] : %s", ret, err_msg);
                        return CAMERASRC_ERR_IO_CONTROL;
                }
-#endif
+
                p->streamon_3aa0_capture = FALSE;
 
                camsrc_info("[3AA0 - CAPTURE] STREAMOFF done");
        }
 
+       if (p->reqbuf_3aa0_capture) {
+               ret = _camerasrc_ioctl_reqbufs(p, p->fd_3aa0, 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("[3AA0 - CAPTURE] _camerasrc_ioctl_reqbufs failed[%x] : %s", ret, err_msg);
+                       return CAMERASRC_ERR_IO_CONTROL;
+               }
+
+               p->reqbuf_3aa0_capture = FALSE;
+
+               camsrc_info("[3AA0 - CAPTURE] REQBUF 0 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) {
@@ -2952,6 +3269,19 @@ int camerasrc_stop_stream(camsrc_handle_t handle)
                camsrc_info("[ISP] STREAMOFF done");
        }
 
+       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");
+       }
+
        if (p->streamon_scc) {
                ret = _camerasrc_ioctl_stream(p, p->fd_scc, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, FALSE);
                if (ret != CAMERASRC_SUCCESS) {
@@ -2978,23 +3308,6 @@ int camerasrc_stop_stream(camsrc_handle_t handle)
                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);
@@ -3009,34 +3322,6 @@ int camerasrc_stop_stream(camsrc_handle_t handle)
                camsrc_info("[3AA1 - OUTPUT] REQBUF 0 done");
        }
 
-       /* 3AA0 - CAPTURE */
-       if (p->reqbuf_3aa0_capture) {
-               ret = _camerasrc_ioctl_reqbufs(p, p->fd_3aa0, 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("[3AA0 - CAPTURE] _camerasrc_ioctl_reqbufs failed[%x] : %s", ret, err_msg);
-                       return CAMERASRC_ERR_IO_CONTROL;
-               }
-
-               p->reqbuf_3aa0_capture = FALSE;
-
-               camsrc_info("[3AA0 - CAPTURE] REQBUF 0 done");
-       }
-
-       /* 3AA0 - OUTPUT */
-       if (p->reqbuf_3aa0_output) {
-               ret = _camerasrc_ioctl_reqbufs(p, p->fd_3aa0, 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("[3AA0 - OUTPUT] _camerasrc_ioctl_reqbufs failed[%x] : %s", ret, err_msg);
-                       return CAMERASRC_ERR_IO_CONTROL;
-               }
-
-               p->reqbuf_3aa0_output = FALSE;
-
-               camsrc_info("[3AA0 - 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);
@@ -3051,23 +3336,23 @@ int camerasrc_stop_stream(camsrc_handle_t handle)
                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);
+       /* 3AA0C */
+       if (p->reqbuf_3aa0c_capture) {
+               ret = _camerasrc_ioctl_reqbufs(p, p->fd_3aa0c, 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("[ISP - OUTPUT] _camerasrc_ioctl_reqbufs failed[%x] : %s", ret, err_msg);
+                       camsrc_error("[3AA0C - CAPTURE] _camerasrc_ioctl_reqbufs failed[%x] : %s", ret, err_msg);
                        return CAMERASRC_ERR_IO_CONTROL;
                }
 
-               p->reqbuf_isp = FALSE;
+               p->reqbuf_3aa0c_capture = FALSE;
 
-               camsrc_info("[ISP] REQBUF 0 done");
+               camsrc_info("[3AA0C] 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);
+               ret = _camerasrc_ioctl_reqbufs(p, p->fd_scc, 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);
@@ -3079,23 +3364,9 @@ int camerasrc_stop_stream(camsrc_handle_t handle)
                camsrc_info("[SCC] REQBUF 0 done");
        }
 
-       /* 3AA0C */
-       if (p->reqbuf_3aa0c_capture) {
-               ret = _camerasrc_ioctl_reqbufs(p, p->fd_3aa0c, 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("[3AA0C - CAPTURE] _camerasrc_ioctl_reqbufs failed[%x] : %s", ret, err_msg);
-                       return CAMERASRC_ERR_IO_CONTROL;
-               }
-
-               p->reqbuf_3aa0c_capture = FALSE;
-
-               camsrc_info("[3AA0C] 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);
+               ret = _camerasrc_ioctl_reqbufs(p, p->fd_scp, 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);
@@ -3583,8 +3854,8 @@ int camerasrc_set_format(camsrc_handle_t handle, camerasrc_format_t *fmt)
        p->format_scp.sizeimage = fmt->sizeimage;
        p->format_scp.rotation = fmt->rotation;
 
-       p->format_isp.img_size.width = fmt->img_size.width;
-       p->format_isp.img_size.height = fmt->img_size.height;
+       p->format_isp.img_size.width = FIMC_IS_BAYER_IMG_WIDTH;
+       p->format_isp.img_size.height = FIMC_IS_BAYER_IMG_HEIGHT;
 
        if (p->cur_dev_id == CAMERASRC_DEV_ID_PRIMARY) {
                if (fmt->img_size.width == fmt->img_size.height)
@@ -3596,7 +3867,7 @@ int camerasrc_set_format(camsrc_handle_t handle, camerasrc_format_t *fmt)
 
                p->format_sensor.img_size.height = PRIMARY_SENSOR_HEIGHT;
 
-               p->format_scp.num_buffers = CAMERASRC_PREVIEW_BUFFER_NUM_PRIMARY;
+               p->format_scp.num_buffers = FIMC_IS_REAR_SCP_NUM_BUFFERS;
        } else {
                p->format_scp.num_buffers = CAMERASRC_PREVIEW_BUFFER_NUM_SECONDARY;
        }
@@ -4174,16 +4445,18 @@ int camerasrc_write_extra_dev_info(camsrc_handle_t handle, camerasrc_extra_info_
 static int _camerasrc_set_shot_meta2(camerasrc_handle_t *p, unsigned int grpid, int fcount,
                                     unsigned long long timestamp, struct camera2_shot_ext *shot_ext)
 {
-       const unsigned int width = 2560;
-       const unsigned int height = 1440;
+       unsigned int width = FIMC_IS_BAYER_IMG_WIDTH;
+       unsigned int height = FIMC_IS_BAYER_IMG_HEIGHT;
 
        if (!p || !shot_ext) {
                camsrc_error("NULL handle %p %p", p, shot_ext);
                return CAMERASRC_ERR_NULL_POINTER;
        }
 
-       if (grpid != GRP_ISP)
-               memset(shot_ext, 0, sizeof(struct camera2_shot_ext));
+       if (grpid == GRP_ISP)
+               return CAMERASRC_SUCCESS;
+
+       memset(shot_ext, 0, sizeof(struct camera2_shot_ext));
 
        shot_ext->drc_bypass    = 1;
        shot_ext->dis_bypass    = 1;
@@ -4201,6 +4474,8 @@ static int _camerasrc_set_shot_meta2(camerasrc_handle_t *p, unsigned int grpid,
        shot_ext->shot.ctl.flash.flashMode = CAM2_FLASH_MODE_OFF;
        shot_ext->shot.ctl.noise.mode = PROCESSING_MODE_OFF;
 
+       shot_ext->shot.ctl.edge.mode = PROCESSING_MODE_OFF;
+
        shot_ext->shot.ctl.tonemap.mode = TONEMAP_MODE_FAST;
        shot_ext->shot.ctl.tonemap.curveGreen[1] = 1;
        shot_ext->shot.ctl.tonemap.curveGreen[2] = 1;
@@ -4216,6 +4491,7 @@ static int _camerasrc_set_shot_meta2(camerasrc_handle_t *p, unsigned int grpid,
        shot_ext->shot.ctl.color.brightness = 3;
        shot_ext->shot.ctl.color.contrast = 3;
 
+       /* stats */
        shot_ext->shot.ctl.stats.faceDetectMode = FACEDETECT_MODE_OFF;
        shot_ext->shot.ctl.stats.histogramMode  = STATS_MODE_OFF;
        shot_ext->shot.ctl.stats.sharpnessMapMode = STATS_MODE_OFF;
@@ -4245,30 +4521,36 @@ static int _camerasrc_set_shot_meta2(camerasrc_handle_t *p, unsigned int grpid,
 
        shot_ext->shot.dm.edge.mode = PROCESSING_MODE_OFF;
 
+       shot_ext->shot.ctl.stats.faceDetectMode = FACEDETECT_MODE_OFF;
+       shot_ext->shot.ctl.stats.histogramMode = STATS_MODE_OFF;
+       shot_ext->shot.ctl.stats.sharpnessMapMode = STATS_MODE_OFF;
+
        if (grpid == GRP_3AA) {
                shot_ext->setfile = 0;
-
+#if 1
                shot_ext->node_group.leader.vid = FIMC_IS_VIDEO_3A0_NUM;
                shot_ext->node_group.leader.request = 1;
-               shot_ext->node_group.leader.input.cropRegion[0] = 4;
-               shot_ext->node_group.leader.input.cropRegion[1] = 2;
-               shot_ext->node_group.leader.input.cropRegion[2] = width + 88; /* 2648 */
-               shot_ext->node_group.leader.input.cropRegion[3] = height + 50; /* 1490 */
-               shot_ext->node_group.leader.output.cropRegion[0] = 4;
-               shot_ext->node_group.leader.output.cropRegion[1] = 2;
-               shot_ext->node_group.leader.output.cropRegion[2] = width + 88; /* 2648 */
-               shot_ext->node_group.leader.output.cropRegion[3] = height + 50; /* 1490 */
-
+               shot_ext->node_group.leader.input.cropRegion[0] = 0;
+               shot_ext->node_group.leader.input.cropRegion[1] = 0;
+               shot_ext->node_group.leader.input.cropRegion[2] = width + 88;  /* 2648 */
+               shot_ext->node_group.leader.input.cropRegion[3] = height + 50; /* 1490 */;
+               shot_ext->node_group.leader.output.cropRegion[0] = 0;
+               shot_ext->node_group.leader.output.cropRegion[1] = 0;
+               shot_ext->node_group.leader.output.cropRegion[2] = width + 88;  /* 2648 */
+               shot_ext->node_group.leader.output.cropRegion[3] = height + 50; /* 1490 */;
+#endif
+#if 1
                shot_ext->node_group.capture[1].vid = FIMC_IS_VIDEO_3A0P_NUM;
                shot_ext->node_group.capture[1].request = 1;
                shot_ext->node_group.capture[1].input.cropRegion[0] = 0;
                shot_ext->node_group.capture[1].input.cropRegion[1] = 0;
-               shot_ext->node_group.capture[1].input.cropRegion[2] = width + 88; /* 2648 */
-               shot_ext->node_group.capture[1].input.cropRegion[3] = height + 50; /* 1490 */
+               shot_ext->node_group.capture[1].input.cropRegion[2] = width + 88;  /* 2648 */
+               shot_ext->node_group.capture[1].input.cropRegion[3] = height + 50; /* 1490 */;
                shot_ext->node_group.capture[1].output.cropRegion[0] = 0;
                shot_ext->node_group.capture[1].output.cropRegion[1] = 0;
                shot_ext->node_group.capture[1].output.cropRegion[2] = width;
                shot_ext->node_group.capture[1].output.cropRegion[3] = height;
+#endif
 #if 0
                /* FIXME: is this needed? */
                shot_ext->shot.ctl.scaler.cropRegion[0] = 0x3f800000;
@@ -4276,133 +4558,21 @@ static int _camerasrc_set_shot_meta2(camerasrc_handle_t *p, unsigned int grpid,
                shot_ext->shot.ctl.scaler.cropRegion[2] = width;
                shot_ext->shot.ctl.scaler.cropRegion[3] = height;
 #endif
-               shot_ext->shot.ctl.aa.aeTargetFpsRange[0] = 10;
-               shot_ext->shot.ctl.aa.aeTargetFpsRange[1] = 30;
-
-       } else if (grpid == GRP_ISP) {
-               shot_ext->setfile = 0;
-
-               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[0] = 0;
-               shot_ext->node_group.leader.input.cropRegion[1] = 0;
-               shot_ext->node_group.leader.input.cropRegion[2] = width;
-               shot_ext->node_group.leader.input.cropRegion[3] = height;
-
-               shot_ext->node_group.leader.output.cropRegion[0] = 0;
-               shot_ext->node_group.leader.output.cropRegion[1] = 0;
-               shot_ext->node_group.leader.output.cropRegion[2] = width;
-               shot_ext->node_group.leader.output.cropRegion[3] = height;
-#if 0
-               /* 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[0] = 0;
-               shot_ext->node_group.capture[0].input.cropRegion[1] = 0;
-               shot_ext->node_group.capture[0].input.cropRegion[2] = 2560;
-               shot_ext->node_group.capture[0].input.cropRegion[3] = 1440;
-               shot_ext->node_group.capture[0].output.cropRegion[0] = 0;
-               shot_ext->node_group.capture[0].output.cropRegion[1] = 0;
-               shot_ext->node_group.capture[0].output.cropRegion[2] = 1920;
-               shot_ext->node_group.capture[0].output.cropRegion[3] = 1080;
-#endif
-               /* SCP */
-               shot_ext->node_group.capture[0].vid = FIMC_IS_VIDEO_SCP_NUM;
-               shot_ext->node_group.capture[0].request = 1;
-               shot_ext->node_group.capture[0].input.cropRegion[0] = 0;
-               shot_ext->node_group.capture[0].input.cropRegion[1] = 0;
-               shot_ext->node_group.capture[0].input.cropRegion[2] = 1920;
-               shot_ext->node_group.capture[0].input.cropRegion[3] = 1080;
-
-               shot_ext->node_group.capture[0].output.cropRegion[0] = 0;
-               shot_ext->node_group.capture[0].output.cropRegion[1] = 0;
-               shot_ext->node_group.capture[0].output.cropRegion[2] = 1920;
-               shot_ext->node_group.capture[0].output.cropRegion[3] = 1080;
-               /*
-                * First entry needs to be non-zero - if it's not errors for
-                * SCC/SCP/DIS are being reported (no target address).
-                * Same rule (first item non-zero) applies to vendorSpecific2[].
-                */
-               shot_ext->shot.udm.internal.vendorSpecific1[0] = 2;
-               shot_ext->shot.udm.internal.vendorSpecific1[1] = 0x000b0c00;
-               //shot_ext->shot.udm.internal.vendorSpecific1[2] = 0x52ae3000;
-
-               shot_ext->shot.udm.internal.vendorSpecific2[0] =
-                       (FIMC_IS_ISP_VS2_INIT_R +
-                       ((fcount - 1) % FIMC_IS_ISP_VS2_RANGE) * FIMC_IS_ISP_VS2_STEP);
-
-               shot_ext->shot.udm.bayer.width = width;
-               shot_ext->shot.udm.bayer.height = height;
-
-               shot_ext->shot.udm.companion.drc_mode = COMPANION_DRC_ON;
-               shot_ext->shot.udm.companion.wdr_mode = COMPANION_WDR_OFF;
-               shot_ext->shot.udm.companion.paf_mode = COMPANION_PAF_ON;
-
-               shot_ext->shot.udm.companion.pdaf.lensPosResolution = 0x3ff;
-
-               shot_ext->shot.dm.hotpixel.mode = PROCESSING_MODE_FAST;
-               shot_ext->shot.dm.demosaic.mode = PROCESSING_MODE_FAST;
-               shot_ext->shot.dm.noise.mode = PROCESSING_MODE_OFF;
-               shot_ext->shot.dm.shading.mode = PROCESSING_MODE_FAST;
-
-               shot_ext->shot.dm.color.mode = COLORCORRECTION_MODE_FAST;
-#if 0
-               shot_ext->shot.dm.color.transform[0] = 1.95095313;
-               shot_ext->shot.dm.color.transform[1] = -0.973571777;
-               shot_ext->shot.dm.color.transform[2] = 0.0226186104;
-               shot_ext->shot.dm.color.transform[3] = -0.257125854;
-               shot_ext->shot.dm.color.transform[4] = 1.34063721;
-               shot_ext->shot.dm.color.transform[5] = -0.0835113525;
-               shot_ext->shot.dm.color.transform[6] = 0.0106252059;
-               shot_ext->shot.dm.color.transform[7] = -0.997131407;
-               shot_ext->shot.dm.color.transform[8] = 1.98650622;
-#endif
-               shot_ext->shot.dm.color.hue = 3;
-               shot_ext->shot.dm.color.saturation = 3;
-               shot_ext->shot.dm.color.brightness = 3;
-               shot_ext->shot.dm.color.contrast = 3;
-
-               shot_ext->shot.dm.edge.mode = PROCESSING_MODE_OFF;
-
-               shot_ext->shot.dm.aa.mode = AA_CONTROL_USE_SCENE_MODE;
-               shot_ext->shot.dm.aa.sceneMode = AA_SCENE_MODE_LLS;
-               shot_ext->shot.dm.aa.aeMode = AA_AEMODE_CENTER;
-               shot_ext->shot.dm.aa.aeState = AE_STATE_CONVERGED;
-               shot_ext->shot.dm.aa.aeflashMode = AA_FLASHMODE_OFF;
-               shot_ext->shot.dm.aa.awbMode = AA_AWBMODE_WB_AUTO;
-               shot_ext->shot.dm.aa.awbRegions[2] = 2647;
-               shot_ext->shot.dm.aa.awbRegions[3] = 1489;
-               shot_ext->shot.dm.aa.awbRegions[4] = 100;
-               shot_ext->shot.dm.aa.afState = AA_AFSTATE_INACTIVE;
-               shot_ext->shot.dm.aa.isoMode = AA_ISOMODE_AUTO;
-               shot_ext->shot.dm.aa.isoValue = 320;
-
-               shot_ext->shot.uctl.companionUd.wdr_mode = COMPANION_WDR_OFF;
-#if 0
-               // scpTargetAddress = {0x56100000, 0x80200000, 0xa0000000, 0x0}
-               unsigned int adr[] = {
-                       0x51b3c000,
-                       0x51835000,
-                       0x5152e000,
-               };
-
-               shot_ext->shot.uctl.scalerUd.scpTargetAddress[0] = adr[fcount % 2];
-               //shot_ext->shot.uctl.scalerUd.scpTargetAddress[1] = 0x80200000;
-               //shot_ext->shot.uctl.scalerUd.scpTargetAddress[2] = 0xa0000000;
-               //shot_ext->shot.uctl.scalerUd.scpTargetAddress[3] = 0;
-#endif
-               shot_ext->shot.uctl.scalerUd.orientation = 0x5d;
-
-               shot_ext->shot.dm.entry.lowIndexParam = 0;
-               shot_ext->shot.dm.entry.highIndexParam = 0;
-               shot_ext->shot.ctl.entry.lowIndexParam = 0;
-               shot_ext->shot.ctl.entry.highIndexParam = 0;
+//             shot_ext->shot.ctl.aa.aeTargetFpsRange[0] = 10;
+//             shot_ext->shot.ctl.aa.aeTargetFpsRange[1] = 30;
        }
 
        if (grpid != GRP_SENSOR) {
                shot_ext->shot.dm.request.metadataMode = METADATA_MODE_NONE;
                shot_ext->shot.dm.request.frameCount = fcount;
                shot_ext->shot.dm.sensor.timeStamp = timestamp;
+
+//             shot_ext->shot.dm.entry.lowIndexParam = 0;
+//             shot_ext->shot.dm.entry.highIndexParam = 0;
+
+//             shot_ext->shot.ctl.entry.lowIndexParam = 0;
+//             shot_ext->shot.ctl.entry.highIndexParam = 0;
+
        }
 
        camsrc_debug("grpid: %d fcount: %d", grpid, fcount);
@@ -4484,7 +4654,8 @@ static int _camerasrc_set_shot_meta(camerasrc_handle_t *p, unsigned int grpid, i
                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;
-
+#if 0
+               /* Disable SCC stream as it is currently not used anyway */
                /* SCC */
                shot_ext->node_group.capture[0].vid = FIMC_IS_VIDEO_SCC_NUM;
                shot_ext->node_group.capture[0].request = 1;
@@ -4492,7 +4663,7 @@ static int _camerasrc_set_shot_meta(camerasrc_handle_t *p, unsigned int grpid, i
                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;
-
+#endif
                /* SCP */
                shot_ext->node_group.capture[1].vid = FIMC_IS_VIDEO_SCP_NUM;
                shot_ext->node_group.capture[1].request = 1;
@@ -4511,8 +4682,8 @@ static int _camerasrc_set_shot_meta(camerasrc_handle_t *p, unsigned int grpid, i
                shot_ext->shot.udm.internal.vendorSpecific1[0] = (uint32_t)~0U;
                shot_ext->shot.udm.internal.vendorSpecific1[1] = 0x000B0C00;
 
-               shot_ext->shot.udm.bayer.width = 2560;
-               shot_ext->shot.udm.bayer.height = 1440;
+               shot_ext->shot.udm.bayer.width = FIMC_IS_BAYER_IMG_WIDTH;
+               shot_ext->shot.udm.bayer.height = FIMC_IS_BAYER_IMG_HEIGHT;
        }
 
        shot_ext->shot.dm.request.metadataMode = METADATA_MODE_NONE;
index 4204b54ab9a3b7de5ad673d806262520b3b7fbf5..07e0838eb4667657a9ac0eff82f3fc32582f47d6 100644 (file)
@@ -394,8 +394,14 @@ typedef struct _camerasrc_handle_t {
        int reqbuf_scc;
        int reqbuf_scp;
 
-       int frame_count;
-       int request_count;
+       int qbuf_count_sensor;
+       int qbuf_count_3aa_out;
+       int qbuf_count_3aa_cap;
+       int qbuf_count_isp;
+       int qbuf_count_scp;
+
+       unsigned int frame_count;
+       unsigned int request_count;
 
        /* state information */
        int prev_stream_state;
@@ -426,6 +432,8 @@ typedef struct _camerasrc_handle_t {
        camerasrc_buffer_t *buffer_scp;
        camerasrc_buffer_t scrnl_buf;  /* screennail buffer of captured JPEG image */
 
+       int scp_buf_count;
+
        /* autofocusing information */
        camerasrc_af_mode_t cur_af_mode;
        camerasrc_af_scan_range_t cur_af_range;
@@ -437,6 +445,10 @@ typedef struct _camerasrc_handle_t {
        int af_dev_val;
        void *af_usr_data;
 
+       /* ISP thread data */
+       pthread_t isp_thread;
+       int isp_thread_run;
+
        /* Jpg Still information */
        camerasrc_exif_info_t current_exif;     /* EXIF info of current captured image */
 
@@ -454,6 +466,7 @@ typedef struct _camerasrc_handle_t {
 
        /* TBM */
        tbm_bufmgr bufmgr;
+
 } camerasrc_handle_t;
 
 typedef struct {
index 863aebc9457e57287381656ded65c65d6052f81c..f3bbf900252711fbfe0a3ac39e0b94ec5102ff3e 100644 (file)
@@ -41,6 +41,7 @@ extern "C" {
  */
 #define CAMERASRC_AF_INTERVAL                   20000
 #define CAMERASRC_TIMEOUT_CRITICAL_VALUE        3000
+#define CAMERASRC_TIMEOUT_SCP_POLL             3
 
 /* EXIF */
 #define EXIF_DEFAULT_SHUTTER_SPEED_DENOMINATOR       256
index 18cf766a4ca9733706052236ccdf9e4f6e0a3eaf..922f15ddddc2507971b76e9dec5b27556c6a07e7 100644 (file)
@@ -38,8 +38,8 @@ extern "C" {
 
 #define MAX_FACE_NUM                            16
 #define MAX_PLANE_NUM                           4
-#define CAMERASRC_PREVIEW_BUFFER_NUM_PRIMARY    9       /* number of request buffer when preview */
-#define CAMERASRC_PREVIEW_BUFFER_NUM_SECONDARY  12      /* number of request buffer when preview */
+#define CAMERASRC_PREVIEW_BUFFER_NUM_PRIMARY    4       /* number of request buffer when preview */
+#define CAMERASRC_PREVIEW_BUFFER_NUM_SECONDARY  4      /* number of request buffer when preview */
 #define CAMERASRC_VIDEO_BUFFER_NUM              7
 #define CAMERASRC_STILL_BUFFER_NUM              1
 
@@ -48,6 +48,8 @@ extern "C" {
 #define ISP_PLANE_COUNT                         2
 #define SCC_PLANE_COUNT                         2
 
+#define CAMERASRC_PRIMARY_FRAME_RATE           30
+
 /**
  * Type definition of av camera src handle.
  */
@@ -329,7 +331,7 @@ typedef struct _camerasrc_exif_info_t {
  *  Image data buffer
  */
 typedef struct _camerasrc_buffer_t {
-       /* Supports for Planes & DMA-buf */
+       /* Support for Planes & DMA-buf */
        struct {
                unsigned int length;    /**< Size of stored data */
                unsigned char *start;   /**< Start address of data */
@@ -339,6 +341,7 @@ typedef struct _camerasrc_buffer_t {
        int num_planes;
        int width;                                      /**< width of image */
        int height;                                     /**< height of image */
+       gboolean queued;
 } camerasrc_buffer_t;