/*
 * Copyright (C) 2008 The Android Open Source Project
 * Copyright@ Samsung Electronics Co. LTD
 *
 * 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.
 */

/*!
 * \file      SecFimc.cpp
 * \brief     source file for Fimc HAL MODULE
 * \author    Hyunkyung, Kim(hk310.kim@samsung.com)
 * \date      2010/10/13
 *
 * <b>Revision History: </b>
 * - 2010/10/13 : Hyunkyung, Kim(hk310.kim@samsung.com) \n
 *   Initial version
 *
 * - 2011/11/15 : Sunmi, Lee(carrotsm.lee@samsung.com) \n
 *   Adjust V4L2 architecture \n
 */

#define LOG_TAG "libfimc"
#include <cutils/log.h>

#include "SecFimc.h"

#define  FIMC2_DEV_NAME  "/dev/video2"

//#define DEBUG_LIB_FIMC

#ifdef BOARD_USE_V4L2
#define V4L2_BUF_TYPE_OUTPUT  V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
#define V4L2_BUF_TYPE_CAPTURE V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
#define V4L2_ROTATE           V4L2_CID_ROTATE
#else
#define V4L2_BUF_TYPE_OUTPUT  V4L2_BUF_TYPE_VIDEO_OUTPUT
#define V4L2_BUF_TYPE_CAPTURE V4L2_BUF_TYPE_VIDEO_CAPTURE
#define V4L2_ROTATE           V4L2_CID_ROTATION
#endif

#define V4L2_BUF_TYPE_SRC    V4L2_BUF_TYPE_OUTPUT
#define V4L2_MEMORY_TYPE_SRC V4L2_MEMORY_USERPTR
#ifdef BOARD_USE_V4L2
#define V4L2_BUF_TYPE_DST    V4L2_BUF_TYPE_CAPTURE
#define V4L2_MEMORY_TYPE_DST V4L2_MEMORY_MMAP
#else
#define V4L2_BUF_TYPE_DST    V4L2_BUF_TYPE_VIDEO_OVERLAY
#define V4L2_MEMORY_TYPE_DST V4L2_MEMORY_USERPTR
#endif

struct yuv_fmt_list yuv_list[] = {
    { "V4L2_PIX_FMT_NV12",      "YUV420/2P/LSB_CBCR",   V4L2_PIX_FMT_NV12,      12, 2 },
#ifdef BOARD_USE_V4L2
    { "V4L2_PIX_FMT_NV12M",     "YUV420/2P/LSB_CBCR",   V4L2_PIX_FMT_NV12M,     12, 2 },
    { "V4L2_PIX_FMT_NV12MT",    "YUV420/2P/LSB_CBCR",   V4L2_PIX_FMT_NV12MT,    12, 2 },
#endif
    { "V4L2_PIX_FMT_NV12T",     "YUV420/2P/LSB_CBCR",   V4L2_PIX_FMT_NV12T,     12, 2 },
    { "V4L2_PIX_FMT_NV21",      "YUV420/2P/LSB_CRCB",   V4L2_PIX_FMT_NV21,      12, 2 },
    { "V4L2_PIX_FMT_NV21X",     "YUV420/2P/MSB_CBCR",   V4L2_PIX_FMT_NV21X,     12, 2 },
    { "V4L2_PIX_FMT_NV12X",     "YUV420/2P/MSB_CRCB",   V4L2_PIX_FMT_NV12X,     12, 2 },
#ifdef BOARD_USE_V4L2
    { "V4L2_PIX_FMT_YUV420M",   "YUV420/3P",            V4L2_PIX_FMT_YUV420M,   12, 3 },
#endif
    { "V4L2_PIX_FMT_YUV420",    "YUV420/3P",            V4L2_PIX_FMT_YUV420,    12, 3 },
    { "V4L2_PIX_FMT_YUYV",      "YUV422/1P/YCBYCR",     V4L2_PIX_FMT_YUYV,      16, 1 },
    { "V4L2_PIX_FMT_YVYU",      "YUV422/1P/YCRYCB",     V4L2_PIX_FMT_YVYU,      16, 1 },
    { "V4L2_PIX_FMT_UYVY",      "YUV422/1P/CBYCRY",     V4L2_PIX_FMT_UYVY,      16, 1 },
    { "V4L2_PIX_FMT_VYUY",      "YUV422/1P/CRYCBY",     V4L2_PIX_FMT_VYUY,      16, 1 },
    { "V4L2_PIX_FMT_UV12",      "YUV422/2P/LSB_CBCR",   V4L2_PIX_FMT_NV16,      16, 2 },
    { "V4L2_PIX_FMT_UV21",      "YUV422/2P/LSB_CRCB",   V4L2_PIX_FMT_NV61,      16, 2 },
    { "V4L2_PIX_FMT_UV12X",     "YUV422/2P/MSB_CBCR",   V4L2_PIX_FMT_NV16X,     16, 2 },
    { "V4L2_PIX_FMT_UV21X",     "YUV422/2P/MSB_CRCB",   V4L2_PIX_FMT_NV61X,     16, 2 },
    { "V4L2_PIX_FMT_YUV422P",   "YUV422/3P",            V4L2_PIX_FMT_YUV422P,   16, 3 },
};

#ifdef BOARD_USE_V4L2
void dump_pixfmt_mp(struct v4l2_pix_format_mplane *pix_mp)
{
    ALOGI("w: %d", pix_mp->width);
    ALOGI("h: %d", pix_mp->height);
    ALOGI("color: %x", pix_mp->colorspace);

    switch (pix_mp->pixelformat) {
    case V4L2_PIX_FMT_YUYV:
        ALOGI ("YUYV");
        break;
    case V4L2_PIX_FMT_UYVY:
        ALOGI ("UYVY");
        break;
    case V4L2_PIX_FMT_RGB565:
        ALOGI ("RGB565");
        break;
    case V4L2_PIX_FMT_RGB565X:
        ALOGI ("RGB565X");
        break;
    default:
        ALOGI("not supported");
    }
}
#endif

void dump_pixfmt(struct v4l2_pix_format *pix)
{
    ALOGI("w: %d", pix->width);
    ALOGI("h: %d", pix->height);
    ALOGI("color: %x", pix->colorspace);

    switch (pix->pixelformat) {
    case V4L2_PIX_FMT_YUYV:
        ALOGI ("YUYV");
        break;
    case V4L2_PIX_FMT_UYVY:
        ALOGI ("UYVY");
        break;
    case V4L2_PIX_FMT_RGB565:
        ALOGI ("RGB565");
        break;
    case V4L2_PIX_FMT_RGB565X:
        ALOGI ("RGB565X");
        break;
    default:
        ALOGI("not supported");
    }
}

void dump_crop(struct v4l2_crop *crop)
{
    ALOGI("crop l: %d", crop->c.left);
    ALOGI("crop t: %d", crop->c.top);
    ALOGI("crop w: %d", crop->c.width);
    ALOGI("crop h: %d", crop->c.height);
}

void dump_window(struct v4l2_window *win)
{
    ALOGI("window l: %d", win->w.left);
    ALOGI("window t: %d", win->w.top);
    ALOGI("window w: %d", win->w.width);
    ALOGI("window h: %d", win->w.height);
}

void v4l2_overlay_dump_state(int fd)
{
    struct v4l2_format format;
    struct v4l2_crop crop;

    format.type = V4L2_BUF_TYPE_OUTPUT;
    if (ioctl(fd, VIDIOC_G_FMT, &format) < 0)
        return;

    ALOGI("dumping driver state:");
#ifdef BOARD_USE_V4L2
    dump_pixfmt_mp(&format.fmt.pix_mp);
#else
    dump_pixfmt(&format.fmt.pix);
#endif

    crop.type = format.type;
    if (ioctl(fd, VIDIOC_G_CROP, &crop) < 0)
        return;

    ALOGI("input window(crop):");
    dump_crop(&crop);

    crop.type = V4L2_BUF_TYPE_CAPTURE;
    if (ioctl(fd, VIDIOC_G_CROP, &crop) < 0)
        return;

    ALOGI("output crop:");
    dump_crop(&crop);

}

int fimc_v4l2_query_buf(int fd, SecBuffer *secBuf, enum v4l2_buf_type type, enum v4l2_memory memory, int buf_index, int num_plane)
{
    struct v4l2_buffer buf;
    memset(&buf, 0, sizeof(struct v4l2_buffer));

#ifdef BOARD_USE_V4L2
    struct v4l2_plane   planes[MAX_PLANES];
    for (int i = 0; i < MAX_PLANES; i++)
        memset(&planes[i], 0, sizeof(struct v4l2_plane));
#endif

    if (MAX_DST_BUFFERS <= buf_index || MAX_PLANES <= num_plane) {
        ALOGE("%s::exceed MAX! : buf_index=%d, num_plane=%d", __func__, buf_index, num_plane);
        return -1;
    }

    buf.type   = type;
    buf.memory = V4L2_MEMORY_MMAP;
    buf.index  = buf_index;
#ifdef BOARD_USE_V4L2
    buf.m.planes = planes;
    buf.length   = num_plane;
#endif

    if (ioctl(fd, VIDIOC_QUERYBUF, &buf) < 0) {
        ALOGE("%s::VIDIOC_QUERYBUF failed, plane_cnt=%d", __func__, buf.length);
        return -1;
    }

#ifdef BOARD_USE_V4L2
    for (int i = 0; i < num_plane; i++) {
        secBuf->phys.extP[i] = (unsigned int)buf.m.planes[i].cookie;
        secBuf->size.extS[i] = buf.m.planes[i].length;

        if ((secBuf->virt.extP[i] = (char *)mmap(0, buf.m.planes[i].length,
                 PROT_READ | PROT_WRITE, MAP_SHARED, fd, buf.m.planes[i].m.mem_offset)) < 0) {
            ALOGE("%s::mmap failed", __func__);
            ALOGE("%s::Offset = 0x%x", __func__, buf.m.planes[i].m.mem_offset);
            ALOGE("%s::Legnth = %d"  , __func__, buf.m.planes[i].length);
            ALOGE("%s::vaddr[%d][%d] = 0x%x", __func__, buf_index, i, (unsigned int)secBuf->virt.extP[i]);
            ALOGE("%s::paddr[%d][%d] = 0x%x", __func__, buf_index, i, (unsigned int)secBuf->phys.extP[i]);
            return -1;
        }
    }
#else
    secBuf->size.s = buf.length;

    if ((secBuf->virt.p = (char *)mmap(0, buf.length,
            PROT_READ | PROT_WRITE, MAP_SHARED, fd, buf.m.offset)) < 0) {
            ALOGE("%s::mmap failed", __func__);
        return -1;
    }
    ALOGI("%s::buffers[%d] vaddr = 0x%x", __func__, buf_index, (unsigned int)secBuf->virt.p);
#endif

    return 0;
}

int fimc_v4l2_req_buf(int fd, unsigned int num_bufs, enum v4l2_buf_type type, enum v4l2_memory memory)
{
    struct v4l2_requestbuffers reqbuf;

    reqbuf.type   = type;
    reqbuf.memory = memory;
    reqbuf.count  = num_bufs;

    if (ioctl(fd, VIDIOC_REQBUFS, &reqbuf) < 0) {
        ALOGE("%s::VIDIOC_REQBUFS failed", __func__);
        return -1;
    }

#ifdef DEBUG_LIB_FIMC
    ALOGI("%d buffers allocated %d requested", reqbuf.count, 4);
#endif

    if (reqbuf.count < num_bufs) {
        ALOGE("%s::VIDIOC_REQBUFS failed ((reqbuf.count(%d) < num_bufs(%d))",
            __func__, reqbuf.count, num_bufs);
        return -1;
    }

    return 0;
}

int fimc_v4l2_s_ctrl(int fd, int id, int value)
{
    struct v4l2_control vc;
    vc.id    = id;
    vc.value = value;

    if (ioctl(fd, VIDIOC_S_CTRL, &vc) < 0) {
        ALOGE("%s::VIDIOC_S_CTRL (id=%d,value=%d) failed", __func__, id, value);
        return -1;
    }

    return 0;
}

int fimc_v4l2_set_fmt(int fd, enum v4l2_buf_type type, enum v4l2_field field, s5p_fimc_img_info *img_info, unsigned int addr)
{
    struct v4l2_framebuffer fbuf;
    struct v4l2_format      fmt;
    struct v4l2_crop        crop;
    struct fimc_buf         fimc_dst_buf;
    struct v4l2_control     vc;

    fmt.type = type;
    if (ioctl(fd, VIDIOC_G_FMT, &fmt) < 0) {
        ALOGE("%s::VIDIOC_G_FMT failed", __func__);
        return -1;
    }

    switch (fmt.type) {
    case V4L2_BUF_TYPE_VIDEO_OUTPUT:
    case V4L2_BUF_TYPE_VIDEO_CAPTURE:
        fmt.fmt.pix.width       = img_info->full_width;
        fmt.fmt.pix.height      = img_info->full_height;
        fmt.fmt.pix.pixelformat = img_info->color_space;
        fmt.fmt.pix.field       = field;
        break;
#ifdef BOARD_USE_V4L2
    case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
    case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
        fmt.fmt.pix_mp.width       = img_info->full_width;
        fmt.fmt.pix_mp.height      = img_info->full_height;
        fmt.fmt.pix_mp.pixelformat = img_info->color_space;
        fmt.fmt.pix_mp.field       = field;
        fmt.fmt.pix_mp.num_planes  = img_info->planes;
        break;
#endif
    case V4L2_BUF_TYPE_VIDEO_OVERLAY:
        if (ioctl(fd, VIDIOC_G_FBUF, &fbuf) < 0) {
            ALOGE("%s::VIDIOC_G_FBUF failed", __func__);
            return -1;
        }

        fbuf.base            = (void *)addr;
        fbuf.fmt.width       = img_info->full_width;
        fbuf.fmt.height      = img_info->full_height;
        fbuf.fmt.pixelformat = img_info->color_space;

        if (ioctl(fd, VIDIOC_S_FBUF, &fbuf) < 0) {
            ALOGE("%s::VIDIOC_S_FBUF (w=%d, h=%d, color=%d) failed",
                __func__,
                img_info->full_width,
                img_info->full_height,
                img_info->color_space);
            return -1;
        }

        fimc_dst_buf.base[0] = (unsigned int)img_info->buf_addr_phy_rgb_y;
        fimc_dst_buf.base[1] = (unsigned int)img_info->buf_addr_phy_cb;
        fimc_dst_buf.base[2] = (unsigned int)img_info->buf_addr_phy_cr;

        vc.id    = V4L2_CID_DST_INFO;
        vc.value = (unsigned int)&fimc_dst_buf.base[0];

        if (ioctl(fd, VIDIOC_S_CTRL, &vc) < 0) {
            ALOGE("%s::VIDIOC_S_CTRL (id=%d,value=%d) failed", __func__, vc.id, vc.value);
            return -1;
        }

        fmt.fmt.win.w.left        = img_info->start_x;
        fmt.fmt.win.w.top         = img_info->start_y;
        fmt.fmt.win.w.width       = img_info->width;
        fmt.fmt.win.w.height      = img_info->height;
        break;
    default:
        ALOGE("invalid buffer type");
        return -1;
        break;
    }

    if (ioctl(fd, VIDIOC_S_FMT, &fmt) < 0) {
        ALOGE("%s::VIDIOC_S_FMT failed", __func__);
        return -1;
    }

    if (fmt.type != V4L2_BUF_TYPE_VIDEO_OVERLAY) {
        crop.type     = type;
        crop.c.left   = img_info->start_x;
        crop.c.top    = img_info->start_y;
        crop.c.width  = img_info->width;
        crop.c.height = img_info->height;

        if (ioctl(fd, VIDIOC_S_CROP, &crop) < 0) {
            ALOGE("%s::VIDIOC_S_CROP (x=%d, y=%d, w=%d, h=%d) failed",
                __func__,
                img_info->start_x,
                img_info->start_y,
                img_info->width,
                img_info->height);
            return -1;
        }
    }

    return 0;
}

int fimc_v4l2_stream_on(int fd, enum v4l2_buf_type type)
{
    if (ioctl(fd, VIDIOC_STREAMON, &type) < 0) {
        ALOGE("%s::VIDIOC_STREAMON failed", __func__);
        return -1;
    }

    return 0;
}

int fimc_v4l2_queue(int fd, SecBuffer *secBuf, enum v4l2_buf_type type, enum v4l2_memory memory, int index, int num_plane)
{
    struct v4l2_buffer buf;
    memset(&buf, 0, sizeof(struct v4l2_buffer));

#ifdef BOARD_USE_V4L2
    struct v4l2_plane   planes[MAX_PLANES];
    for (int i = 0; i < MAX_PLANES; i++)
        memset(&planes[i], 0, sizeof(struct v4l2_plane));
#else
    struct fimc_buf fimcbuf;
#endif

    buf.type     = type;
    buf.memory   = memory;
    buf.length   = num_plane;
    buf.index    = index;
#ifdef BOARD_USE_V4L2
    buf.m.planes = planes;

    for (unsigned int i = 0; i < buf.length; i++) {
        buf.m.planes[i].length = secBuf->size.extS[i];
        buf.m.planes[i].m.userptr = (unsigned long)secBuf->phys.extP[i];
    }
#else
    for (int i = 0; i < 3 ; i++) {
        fimcbuf.base[i]   = secBuf->phys.extP[i];
        fimcbuf.length[i] = secBuf->size.extS[i];
    }

    buf.m.userptr = (unsigned long)(&fimcbuf);
    //buf.m.userptr = secBuf->phys.p;
#endif

    if (ioctl(fd, VIDIOC_QBUF, &buf) < 0) {
        ALOGE("%s::VIDIOC_QBUF failed", __func__);
        return -1;
    }

    return 0;
}

int fimc_v4l2_dequeue(int fd, enum v4l2_buf_type type, enum v4l2_memory memory, int *index, int num_plane)
{
    struct v4l2_buffer buf;
    memset(&buf, 0, sizeof(struct v4l2_buffer));

#ifdef BOARD_USE_V4L2
    struct v4l2_plane   planes[MAX_PLANES];
    for (int i = 0; i < MAX_PLANES; i++)
        memset(&planes[i], 0, sizeof(struct v4l2_plane));
#endif

    buf.type     = type;
    buf.memory   = memory;
    buf.length   = num_plane;
#ifdef BOARD_USE_V4L2
    buf.m.planes = planes;
#endif
    if (ioctl(fd, VIDIOC_DQBUF, &buf) < 0) {
        ALOGE("%s::VIDIOC_DQBUF failed", __func__);
        return -1;
    }
    *index = buf.index;

    return 0;
}

int fimc_v4l2_stream_off(int fd, enum v4l2_buf_type type)
{
    if (ioctl(fd, VIDIOC_STREAMOFF, &type) < 0) {
        ALOGE("%s::VIDIOC_STREAMOFF failed", __func__);
        return -1;
    }

    return 0;
}

int fimc_v4l2_clr_buf(int fd, enum v4l2_buf_type type, enum v4l2_memory memory)
{
    struct v4l2_requestbuffers req;

    req.count   = 0;
    req.type    = type;
    req.memory  = memory;

    if (ioctl(fd, VIDIOC_REQBUFS, &req) < 0) {
        ALOGE("%s::VIDIOC_REQBUFS", __func__);
        return -1;
    }

    return 0;
}

static inline int multipleOfN(int number, int N)
{
    int result = number;
    switch (N) {
    case 1:
    case 2:
    case 4:
    case 8:
    case 16:
    case 32:
    case 64:
    case 128:
    case 256:
        result = (number - (number & (N-1)));
        break;
    default:
        result = number - (number % N);
        break;
    }
    return result;
}

extern "C" SecFimc* create_instance()
{
    return new SecFimc;
}

extern "C" void destroy_instance(SecFimc* handle)
{
    if (handle != NULL)
        delete handle;
}

SecFimc::SecFimc()
:   mFlagCreate(false)
{
    memset(&mFimcCap, 0, sizeof(struct v4l2_capability));
    memset(&mS5pFimc, 0, sizeof(s5p_fimc_t));

    mRotVal = 0;
    mRealDev = -1;
    mNumOfBuf = 0;
    mHwVersion = 0;
    mGlobalAlpha = 0x0;
    mFlagStreamOn = false;
    mFlagSetSrcParam = false;
    mFlagSetDstParam = false;
    mFlagGlobalAlpha = false;
    mFlagLocalAlpha = false;
    mFlagColorKey = false;
    mFimcMode = 0;
    mFd = 0;
    mDev = 0;
    mColorKey = 0x0;
}

SecFimc::~SecFimc()
{
    if (mFlagCreate == true) {
        ALOGE("%s::this is not Destroyed fail", __func__);
        if (destroy() == false)
            ALOGE("%s::destroy failed", __func__);
    }
}

bool SecFimc::create(enum DEV dev, enum MODE mode, int numOfBuf)
{
    if (mFlagCreate == true) {
        ALOGE("%s::Already Created fail", __func__);
        return false;
    }

    char node[20];
    struct v4l2_format  fmt;
    struct v4l2_control vc;
    SecBuffer zeroBuf;

    mDev = dev;
    mRealDev = dev;

    switch (mode) {
    case MODE_SINGLE_BUF:
        mFimcMode = FIMC_OVLY_NONE_SINGLE_BUF;
        break;
    case MODE_MULTI_BUF:
        mFimcMode = FIMC_OVLY_NONE_MULTI_BUF;
        break;
    case MODE_DMA_AUTO:
        mFimcMode = FIMC_OVLY_DMA_AUTO;
        break;
    default:
        ALOGE("%s::Invalid mode(%d) fail", __func__, mode);
        mFimcMode = FIMC_OVLY_NOT_FIXED;
        goto err;
        break;
    }

    mNumOfBuf = numOfBuf;

    for (int i = 0; i < MAX_DST_BUFFERS; i++)
        mDstBuffer[i] = zeroBuf;

#ifdef BOARD_USE_V4L2
    switch(mDev) {
    case DEV_0:
        mRealDev = 0;
        break;
    case DEV_1:
        mRealDev = 2;
        break;
    case DEV_2:
        mRealDev = 4;
        break;
    case DEV_3:
        mRealDev = 5;
        break;
    default:
        ALOGE("%s::invalid mDev(%d)", __func__, mDev);
        goto err;
        break;
    }
#endif

    sprintf(node, "%s%d", PFX_NODE_FIMC, (int)mRealDev);

    mFd = open(node, O_RDWR);
    if (mFd < 0) {
        ALOGE("%s::open(%s) failed", __func__, node);
        mFd = 0;
        goto err;
    }

    /* check capability */
    if (ioctl(mFd, VIDIOC_QUERYCAP, &mFimcCap) < 0) {
        ALOGE("%s::VIDIOC_QUERYCAP failed", __func__);
        goto err;
    }

    if (!(mFimcCap.capabilities & V4L2_CAP_STREAMING)) {
        ALOGE("%s::%s has no streaming support", __func__, node);
        goto err;
    }

#ifdef BOARD_USE_V4L2
    if (!(mFimcCap.capabilities & V4L2_CAP_VIDEO_OUTPUT_MPLANE)) {
        ALOGE("%s::%s is no video output mplane", __func__, node);
        goto err;
    }

    if (!(mFimcCap.capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE)) {
        ALOGE("%s::%s is no video capture mplane", __func__, node);
        goto err;
    }
#else
    if (!(mFimcCap.capabilities & V4L2_CAP_VIDEO_OUTPUT)) {
        ALOGE("%s::%s is no video output", __func__, node);
        goto err;
    }

    fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
    if (ioctl(mFd, VIDIOC_G_FMT, &fmt) < 0) {
        ALOGE("%s::VIDIOC_G_FMT failed", __func__);
        goto err;
    }

    vc.id = V4L2_CID_RESERVED_MEM_BASE_ADDR;
    vc.value = 0;
    if (ioctl(mFd, VIDIOC_G_CTRL, &vc) < 0) {
        ALOGE("%s::VIDIOC_G_CTRL - V4L2_CID_RESERVED_MEM_BAES_ADDR", __func__);
        goto err;
    }

    mDstBuffer[0].phys.p = (unsigned int)vc.value;

    mS5pFimc.out_buf.phys_addr = (void *)mDstBuffer[0].phys.p;

    vc.id    = V4L2_CID_FIMC_VERSION;
    vc.value = 0;
    if (ioctl(mFd, VIDIOC_G_CTRL, &vc) < 0) {
        ALOGE("%s::VIDIOC_G_CTRL - V4L2_CID_FIMC_VERSION failed, FIMC version is set with default", __func__);
        vc.value = 0x43;
    }

    mHwVersion = vc.value;

    vc.id = V4L2_CID_OVLY_MODE;
    vc.value = mFimcMode;
    if (ioctl(mFd, VIDIOC_S_CTRL, &vc) < 0) {
        ALOGE("%s::VIDIOC_S_CTRL - V4L2_CID_OVLY_MODE failed", __func__);
        goto err;
    }
#endif

    mFlagCreate = true;

    return true;

err :
    if (0 < mFd)
        close(mFd);
    mFd = 0;

    return false;
}

bool SecFimc::destroy()
{
    s5p_fimc_params_t *params = &(mS5pFimc.params);

    if (mFlagCreate == false) {
        ALOGE("%s::Already Destroyed fail", __func__);
        return false;
    }

    if (mFlagStreamOn == true) {
        if (fimc_v4l2_stream_off(mFd, V4L2_BUF_TYPE_SRC) < 0) {
            ALOGE("%s::fimc_v4l2_stream_off() failed", __func__);
            return false;
        }
#ifdef BOARD_USE_V4L2
        if (fimc_v4l2_stream_off(mFd, V4L2_BUF_TYPE_DST) < 0) {
            ALOGE("%s::fimc_v4l2_stream_off() failed", __func__);
            return false;
        }
#endif
        mFlagStreamOn = false;
    }

    if (fimc_v4l2_clr_buf(mFd, V4L2_BUF_TYPE_SRC, V4L2_MEMORY_TYPE_SRC) < 0) {
        ALOGE("%s::fimc_v4l2_clr_buf()[src] failed", __func__);
        return false;
    }

#ifdef BOARD_USE_V4L2
    if (fimc_v4l2_clr_buf(mFd, V4L2_BUF_TYPE_DST, V4L2_MEMORY_TYPE_DST) < 0) {
        ALOGE("%s::fimc_v4l2_clr_buf()[dst] failed", __func__);
        return false;
    }
#endif
    if (mS5pFimc.out_buf.phys_addr != NULL) {
        mS5pFimc.out_buf.phys_addr = NULL;
        mS5pFimc.out_buf.length = 0;
    }

    if (0 < mFd)
        close(mFd);
    mFd = 0;

    mFlagCreate = false;

    return true;
}

bool SecFimc::flagCreate(void)
{
    return mFlagCreate;
}

int SecFimc::getFd(void)
{
    return mFd;
}

SecBuffer * SecFimc::getMemAddr(int index)
{
    if (mFlagCreate == false) {
        ALOGE("%s::Not yet created", __func__);
        return false;
    }

    return &mDstBuffer[index];
}

int SecFimc::getHWVersion(void)
{
    if (mFlagCreate == false) {
        ALOGE("%s::Not yet created", __func__);
        return false;
    }

    return mHwVersion;
}

bool SecFimc::setSrcParams(unsigned int width, unsigned int height,
                           unsigned int cropX, unsigned int cropY,
                           unsigned int *cropWidth, unsigned int *cropHeight,
                           int colorFormat,
                           bool forceChange)
{
#ifdef DEBUG_LIB_FIMC
    ALOGD("%s", __func__);
#endif

    if (mFlagCreate == false) {
        ALOGE("%s::Not yet created", __func__);
        return false;
    }

    int v4l2ColorFormat = HAL_PIXEL_FORMAT_2_V4L2_PIX(colorFormat);
    if (v4l2ColorFormat < 0) {
        ALOGE("%s::not supported color format", __func__);
        return false;
    }

    s5p_fimc_params_t *params = &(mS5pFimc.params);

    unsigned int fimcWidth  = *cropWidth;
    unsigned int fimcHeight = *cropHeight;
    int src_planes = m_getYuvPlanes(v4l2ColorFormat);

    m_checkSrcSize(width, height,
                   cropX, cropY,
                   &fimcWidth, &fimcHeight,
                   v4l2ColorFormat,
                   false);

    if (fimcWidth != *cropWidth || fimcHeight != *cropHeight) {
        if (forceChange == true) {
#ifdef DEBUG_LIB_FIMC
            ALOGD("size is changed from [w = %d, h= %d] to [w = %d, h = %d]",
                    *cropWidth, *cropHeight, fimcWidth, fimcHeight);
#endif
        } else {
            ALOGE("%s::invalid source params", __func__);
            return false;
        }
    }

    if (   (params->src.full_width == width)
        && (params->src.full_height == height)
        && (params->src.start_x == cropX)
        && (params->src.start_y == cropY)
        && (params->src.width == fimcWidth)
        && (params->src.height == fimcHeight)
        && (params->src.color_space == (unsigned int)v4l2ColorFormat))
        return true;

    params->src.full_width  = width;
    params->src.full_height = height;
    params->src.start_x     = cropX;
    params->src.start_y     = cropY;
    params->src.width       = fimcWidth;
    params->src.height      = fimcHeight;
    params->src.color_space = v4l2ColorFormat;
    src_planes = (src_planes == -1) ? 1 : src_planes;

    if (mFlagSetSrcParam == true) {
        if (fimc_v4l2_clr_buf(mFd, V4L2_BUF_TYPE_SRC, V4L2_MEMORY_TYPE_SRC) < 0) {
            ALOGE("%s::fimc_v4l2_clr_buf_src() failed", __func__);
            return false;
        }
    }

    if (fimc_v4l2_set_fmt(mFd, V4L2_BUF_TYPE_SRC, V4L2_FIELD_NONE, &(params->src), 0) < 0) {
        ALOGE("%s::fimc_v4l2_set_fmt()[src] failed", __func__);
        return false;
    }

    if (fimc_v4l2_req_buf(mFd, 1, V4L2_BUF_TYPE_SRC, V4L2_MEMORY_TYPE_SRC) < 0) {
        ALOGE("%s::fimc_v4l2_req_buf()[src] failed", __func__);
        return false;
    }

    *cropWidth  = fimcWidth;
    *cropHeight = fimcHeight;

    mFlagSetSrcParam = true;
    return true;
}

bool SecFimc::getSrcParams(unsigned int *width, unsigned int *height,
                           unsigned int *cropX, unsigned int *cropY,
                           unsigned int *cropWidth, unsigned int *cropHeight,
                           int *colorFormat)
{
    struct v4l2_format fmt;
    struct v4l2_crop crop;

    fmt.type = V4L2_BUF_TYPE_SRC;

    if (ioctl(mFd, VIDIOC_G_FMT, &fmt) < 0) {
        ALOGE("%s::VIDIOC_G_FMT(fmt.type : %d) failed", __func__, fmt.type);
        return false;
    }

    switch (fmt.type) {
    case V4L2_BUF_TYPE_VIDEO_OUTPUT:
    case V4L2_BUF_TYPE_VIDEO_CAPTURE:
    case V4L2_BUF_TYPE_VIDEO_OVERLAY:
        *width       = fmt.fmt.pix.width;
        *height      = fmt.fmt.pix.height;
        *colorFormat = fmt.fmt.pix.pixelformat;
        break;
#ifdef BOARD_USE_V4L2
    case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
    case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
        *width       = fmt.fmt.pix_mp.width;
        *height      = fmt.fmt.pix_mp.height;
        *colorFormat = fmt.fmt.pix_mp.pixelformat;
        break;
#endif
    default:
        ALOGE("%s::Invalid buffer type", __func__);
        return false;
        break;
    }

    crop.type = V4L2_BUF_TYPE_SRC;
    if (ioctl(mFd, VIDIOC_G_CROP, &crop) < 0) {
        ALOGE("%s::VIDIOC_G_CROP failed", __func__);
        return false;
    }

    *cropX = crop.c.left;
    *cropY = crop.c.top;
    *cropWidth = crop.c.width;
    *cropHeight = crop.c.height;

    return true;
}

bool SecFimc::setSrcAddr(unsigned int physYAddr,
                         unsigned int physCbAddr,
                         unsigned int physCrAddr,
                         int colorFormat)
{
#ifdef DEBUG_LIB_FIMC
    ALOGD("%s", __func__);
#endif

    if (mFlagCreate == false) {
        ALOGE("%s::Not yet created", __func__);
        return false;
    }

    s5p_fimc_params_t *params = &(mS5pFimc.params);
    int src_planes = m_getYuvPlanes(params->src.color_space);
    int src_bpp = m_getYuvBpp(params->src.color_space);
    unsigned int frame_size = params->src.full_width * params->src.full_height;
    src_planes = (src_planes == -1) ? 1 : src_planes;

    mSrcBuffer.phys.extP[0] = physYAddr;

    if (colorFormat == HAL_PIXEL_FORMAT_YV12) {
        mSrcBuffer.phys.extP[1] = physCrAddr;
        mSrcBuffer.phys.extP[2] = physCbAddr;
    } else {
        mSrcBuffer.phys.extP[1] = physCbAddr;
        mSrcBuffer.phys.extP[2] = physCrAddr;
    }

    if (2 <= src_planes &&  mSrcBuffer.phys.extP[1] == 0)
        mSrcBuffer.phys.extP[1] = mSrcBuffer.phys.extP[0] + frame_size;

    if (3 == src_planes &&  mSrcBuffer.phys.extP[2] == 0) {
        if (colorFormat == HAL_PIXEL_FORMAT_YV12) {
            if (12 == src_bpp)
                mSrcBuffer.phys.extP[1] = mSrcBuffer.phys.extP[2] + (frame_size >> 2);
            else
                mSrcBuffer.phys.extP[1] = mSrcBuffer.phys.extP[2] + (frame_size >> 1);
        } else {
            if (12 == src_bpp)
                mSrcBuffer.phys.extP[2] = mSrcBuffer.phys.extP[1] + (frame_size >> 2);
            else
                mSrcBuffer.phys.extP[2] = mSrcBuffer.phys.extP[1] + (frame_size >> 1);
        }
    }

    return true;
}

bool SecFimc::setDstParams(unsigned int width, unsigned int height,
                           unsigned int cropX, unsigned int cropY,
                           unsigned int *cropWidth, unsigned int *cropHeight,
                           int colorFormat,
                           bool forceChange)
{
#ifdef DEBUG_LIB_FIMC
    ALOGD("%s", __func__);
#endif

    if (mFlagCreate == false) {
        ALOGE("%s::Not yet created", __func__);
        return false;
    }

    int v4l2ColorFormat = HAL_PIXEL_FORMAT_2_V4L2_PIX(colorFormat);
    if (v4l2ColorFormat < 0) {
        ALOGE("%s::not supported color format", __func__);
        return false;
    }

    s5p_fimc_params_t *params = &(mS5pFimc.params);

    unsigned int fimcWidth  = *cropWidth;
    unsigned int fimcHeight = *cropHeight;
    int dst_planes = m_getYuvPlanes(v4l2ColorFormat);

    m_checkDstSize(width, height,
                   cropX, cropY,
                   &fimcWidth, &fimcHeight,
                   v4l2ColorFormat,
                   mRotVal,
                   true);

    if (fimcWidth != *cropWidth || fimcHeight != *cropHeight) {
        if (forceChange == true) {
#ifdef DEBUG_LIB_FIMC
            ALOGD("size is changed from [w = %d, h= %d] to [w = %d, h = %d]",
                    *cropWidth, *cropHeight, fimcWidth, fimcHeight);
#endif
        } else {
            ALOGE("%s::Invalid destination params", __func__);
            return false;
        }
    }

    if (90 == mRotVal || 270 == mRotVal) {
        params->dst.full_width  = height;
        params->dst.full_height = width;

        if (90 == mRotVal) {
            params->dst.start_x     = cropY;
            params->dst.start_y     = width - (cropX + fimcWidth);
        } else {
            params->dst.start_x = height - (cropY + fimcHeight);
            params->dst.start_y = cropX;
        }

        params->dst.width       = fimcHeight;
        params->dst.height      = fimcWidth;

        if (0x50 != mHwVersion)
            params->dst.start_y     += (fimcWidth - params->dst.height);

    } else {
        params->dst.full_width  = width;
        params->dst.full_height = height;

        if (180 == mRotVal) {
            params->dst.start_x = width - (cropX + fimcWidth);
            params->dst.start_y = height - (cropY + fimcHeight);
        } else {
            params->dst.start_x     = cropX;
            params->dst.start_y     = cropY;
        }

        params->dst.width       = fimcWidth;
        params->dst.height      = fimcHeight;
    }
    params->dst.color_space = v4l2ColorFormat;
    dst_planes = (dst_planes == -1) ? 1 : dst_planes;

#ifdef BOARD_USE_V4L2
    if (mFlagSetDstParam == true) {
        if (fimc_v4l2_clr_buf(mFd, V4L2_BUF_TYPE_DST, V4L2_MEMORY_TYPE_DST) < 0) {
            ALOGE("%s::fimc_v4l2_clr_buf_dst() failed", __func__);
            return false;
        }
    }
#endif

    if (fimc_v4l2_s_ctrl(mFd, V4L2_ROTATE, mRotVal) < 0) {
        ALOGE("%s::fimc_v4l2_s_ctrl(V4L2_ROTATE)", __func__);
        return false;
    }

    if (fimc_v4l2_set_fmt(mFd, V4L2_BUF_TYPE_DST, V4L2_FIELD_ANY, &(params->dst), (unsigned int)mS5pFimc.out_buf.phys_addr) < 0) {
        ALOGE("%s::fimc_v4l2_set_fmt()[dst] failed", __func__);
        return false;
    }

#ifdef BOARD_USE_V4L2
    if (fimc_v4l2_req_buf(mFd, mNumOfBuf, V4L2_BUF_TYPE_DST, V4L2_MEMORY_TYPE_DST) < 0) {
        ALOGE("%s::fimc_v4l2_req_buf()[dst] failed", __func__);
        return false;
    }

    for (int i = 0; i < mNumOfBuf; i++) {
        if (fimc_v4l2_query_buf(mFd, &(mDstBuffer[i]),
                           V4L2_BUF_TYPE_DST, V4L2_MEMORY_TYPE_DST, i, dst_planes) < 0) {
            ALOGE("%s::fimc_v4l2_query_buf() failed", __func__);
        }
    }
#endif

    *cropWidth  = fimcWidth;
    *cropHeight = fimcHeight;

    mFlagSetDstParam = true;
    return true;
}

bool SecFimc::getDstParams(unsigned int *width, unsigned int *height,
                           unsigned int *cropX, unsigned int *cropY,
                           unsigned int *cropWidth, unsigned int *cropHeight,
                           int *colorFormat)
{
    struct v4l2_framebuffer fbuf;
    struct v4l2_format      fmt;
    struct v4l2_crop        crop;

    fmt.type = V4L2_BUF_TYPE_DST;
    if (ioctl(mFd, VIDIOC_G_FMT, &fmt) < 0) {
        ALOGE("%s::VIDIOC_G_FMT(fmt.type : %d) failed", __func__, fmt.type);
        return false;
    }
    switch (fmt.type) {
    case V4L2_BUF_TYPE_VIDEO_OUTPUT:
    case V4L2_BUF_TYPE_VIDEO_CAPTURE:
        *width       = fmt.fmt.pix.width;
        *height      = fmt.fmt.pix.height;
        *colorFormat = fmt.fmt.pix.pixelformat;
        break;
#ifdef BOARD_USE_V4L2
    case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
    case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
        *width       = fmt.fmt.pix_mp.width;
        *height      = fmt.fmt.pix_mp.height;
        *colorFormat = fmt.fmt.pix_mp.pixelformat;
        break;
#endif
    case V4L2_BUF_TYPE_VIDEO_OVERLAY:
        *cropX = fmt.fmt.win.w.left;
        *cropY = fmt.fmt.win.w.top;
        *cropWidth = fmt.fmt.win.w.width;
        *cropHeight = fmt.fmt.win.w.height;

        if (ioctl(mFd, VIDIOC_G_FBUF, &fbuf) < 0) {
            ALOGE("%s::VIDIOC_G_FBUF failed", __func__);
            return false;
        }

        *width       = fbuf.fmt.width;
        *height      = fbuf.fmt.height;
        *colorFormat = fbuf.fmt.pixelformat;
        break;
    default:
        ALOGE("%s::Invalid buffer type", __func__);
        return false;
        break;
    }

    if (fmt.type != V4L2_BUF_TYPE_VIDEO_OVERLAY) {

        crop.type = V4L2_BUF_TYPE_DST;
        if (ioctl(mFd, VIDIOC_G_CROP, &crop) < 0) {
            ALOGE("%s::VIDIOC_G_CROP(crop.type : %d) failed", __func__, crop.type);
            return false;
        }

        *cropX = crop.c.left;
        *cropY = crop.c.top;
        *cropWidth = crop.c.width;
        *cropHeight = crop.c.height;
    }

    return true;
}

bool SecFimc::setDstAddr(unsigned int physYAddr, unsigned int physCbAddr, unsigned int physCrAddr, int buf_index)
{
#ifdef DEBUG_LIB_FIMC
    ALOGD("%s", __func__);
#endif

    s5p_fimc_params_t *params = &(mS5pFimc.params);

    if (mFlagCreate == false) {
        ALOGE("%s::Not yet created", __func__);
        return false;
    }

    mS5pFimc.out_buf.phys_addr = (void *)physYAddr;

    mDstBuffer[buf_index].phys.extP[0] = physYAddr;
    mDstBuffer[buf_index].phys.extP[1] = physCbAddr;
    mDstBuffer[buf_index].phys.extP[2] = physCrAddr;

#ifdef BOARD_USE_V4L2
    if (physYAddr != 0)
        mS5pFimc.use_ext_out_mem = 1;
#else
    params->dst.buf_addr_phy_rgb_y = physYAddr;
    params->dst.buf_addr_phy_cb    = physCbAddr;
    params->dst.buf_addr_phy_cr    = physCrAddr;

    if ((physYAddr != 0)
        && ((unsigned int)mS5pFimc.out_buf.phys_addr != mDstBuffer[0].phys.p))
        mS5pFimc.use_ext_out_mem = 1;

    if (fimc_v4l2_s_ctrl(mFd, V4L2_ROTATE, mRotVal) < 0) {
        ALOGE("%s::fimc_v4l2_s_ctrl(V4L2_ROTATE)", __func__);
        return false;
    }

    if (fimc_v4l2_set_fmt(mFd, V4L2_BUF_TYPE_DST, V4L2_FIELD_ANY, &(params->dst), (unsigned int)mS5pFimc.out_buf.phys_addr) < 0) {
        ALOGE("%s::fimc_v4l2_set_fmt()[dst] failed", __func__);
        return false;
    }
#endif

    return true;
}

bool SecFimc::setRotVal(unsigned int rotVal)
{
    struct v4l2_control vc;

    if (mFlagCreate == false) {
        ALOGE("%s::Not yet created", __func__);
        return false;
    }

    if (fimc_v4l2_s_ctrl(mFd, V4L2_ROTATE, rotVal) < 0) {
        ALOGE("%s::fimc_v4l2_s_ctrl(V4L2_ROTATE) failed", __func__);
        return false;
    }

    mRotVal = rotVal;
    return true;
}

bool SecFimc::setGlobalAlpha(bool enable, int alpha)
{
    struct v4l2_framebuffer fbuf;
    struct v4l2_format fmt;

    if (mFlagCreate == false) {
        ALOGE("%s::Not yet created", __func__);
        return false;
    }

    if (mFlagStreamOn == true) {
        ALOGE("%s::mFlagStreamOn == true", __func__);
        return false;
    }

    if (mFlagGlobalAlpha == enable && mGlobalAlpha == alpha)
        return true;

    memset(&fbuf, 0, sizeof(fbuf));

    if (ioctl(mFd, VIDIOC_G_FBUF, &fbuf) < 0) {
        ALOGE("%s::VIDIOC_G_FBUF failed", __func__);
        return false;
    }

    if (enable)
        fbuf.flags |= V4L2_FBUF_FLAG_GLOBAL_ALPHA;
    else
        fbuf.flags &= ~V4L2_FBUF_FLAG_GLOBAL_ALPHA;

    if (ioctl(mFd, VIDIOC_S_FBUF, &fbuf) < 0) {
        ALOGE("%s::VIDIOC_S_FBUF failed", __func__);
        return false;
    }

    if (enable) {
        memset(&fmt, 0, sizeof(fmt));
        fmt.type = V4L2_BUF_TYPE_VIDEO_OVERLAY;

        if (ioctl(mFd, VIDIOC_G_FMT, &fmt) < 0) {
            ALOGE("%s::VIDIOC_G_FMT failed", __func__);
            return false;
        }

        fmt.fmt.win.global_alpha = alpha & 0xFF;
        if (ioctl(mFd, VIDIOC_S_FMT, &fmt) < 0) {
            ALOGE("%s::VIDIOC_S_FMT failed", __func__);
            return false;
        }
    }

    mFlagGlobalAlpha = enable;
    mGlobalAlpha     = alpha;

    return true;

}

bool SecFimc::setLocalAlpha(bool enable)
{
    if (mFlagCreate == false) {
        ALOGE("%s::Not yet created", __func__);
        return false;
    }

    if (mFlagStreamOn == true) {
        ALOGE("%s::mFlagStreamOn == true", __func__);
        return false;
    }

    if (mFlagLocalAlpha == enable)
        return true;

    return true;
}

bool SecFimc::setColorKey(bool enable, int colorKey)
{
    struct v4l2_framebuffer fbuf;
    struct v4l2_format fmt;

    if (mFlagCreate == false) {
        ALOGE("%s::Not yet created", __func__);
        return false;
    }

    if (mFlagStreamOn == true) {
        ALOGE("%s::mFlagStreamOn == true", __func__);
        return false;
    }

    if (mFlagColorKey == enable && mColorKey == colorKey)
        return true;

    memset(&fbuf, 0, sizeof(fbuf));

    if (ioctl(mFd, VIDIOC_G_FBUF, &fbuf) < 0) {
        ALOGE("%s::VIDIOC_G_FBUF failed", __func__);
        return false;
    }

    if (enable)
        fbuf.flags |= V4L2_FBUF_FLAG_CHROMAKEY;
    else
        fbuf.flags &= ~V4L2_FBUF_FLAG_CHROMAKEY;

    if (ioctl(mFd, VIDIOC_S_FBUF, &fbuf) < 0) {
        ALOGE("%s::VIDIOC_S_FBUF failed", __func__);
        return false;
    }

    if (enable) {
        memset(&fmt, 0, sizeof(fmt));
        fmt.type = V4L2_BUF_TYPE_VIDEO_OVERLAY;

        if (ioctl(mFd, VIDIOC_G_FMT, &fmt) < 0) {
            ALOGE("%s::VIDIOC_G_FMT failed", __func__);
            return false;
        }

        fmt.fmt.win.chromakey = colorKey & 0xFFFFFF;

        if (ioctl(mFd, VIDIOC_S_FMT, &fmt) < 0)
            ALOGE("%s::VIDIOC_S_FMT failed", __func__);
    }
    mFlagColorKey = enable;
    mColorKey = colorKey;
    return true;
}

bool SecFimc::draw(int src_index, int dst_index)
{
#ifdef DEBUG_LIB_FIMC
    ALOGD("%s", __func__);
#endif

    if (mFlagCreate == false) {
        ALOGE("%s::Not yet created", __func__);
        return false;
    }

    if (mFlagSetSrcParam == false) {
        ALOGE("%s::mFlagSetSrcParam == false fail", __func__);
        return false;
    }

    if (mFlagSetDstParam == false) {
        ALOGE("%s::mFlagSetDstParam == false fail", __func__);
        return false;
    }

    s5p_fimc_params_t *params = &(mS5pFimc.params);
    bool flagStreamOn = false;
    int src_planes = m_getYuvPlanes(params->src.color_space);
    int dst_planes = m_getYuvPlanes(params->dst.color_space);
    src_planes  = (src_planes == -1) ? 1 : src_planes;
    dst_planes  = (dst_planes == -1) ? 1 : dst_planes;

#ifdef BOARD_USE_V4L2
    if (mFlagStreamOn == false) {
        if (m_streamOn() == false) {
            ALOGE("%s::m_streamOn failed", __func__);
            return false;
        }
        mFlagStreamOn = true;
    }
    if (fimc_v4l2_dequeue(mFd, V4L2_BUF_TYPE_DST, V4L2_MEMORY_TYPE_DST, &dst_index, dst_planes) < 0) {
        ALOGE("%s::fimc_v4l2_dequeue[dst](mNumOfBuf : %d) failed", __func__, mNumOfBuf);
        return false;
    }

    if (fimc_v4l2_dequeue(mFd, V4L2_BUF_TYPE_SRC, V4L2_MEMORY_TYPE_SRC, &src_index, src_planes) < 0) {
        ALOGE("%s::fimc_v4l2_dequeue[src](mNumOfBuf : %d) failed", __func__, mNumOfBuf);
        return false;
    }

    if (fimc_v4l2_queue(mFd, &(mSrcBuffer), V4L2_BUF_TYPE_SRC, V4L2_MEMORY_TYPE_SRC, src_index, src_planes) < 0) {
        ALOGE("%s::fimc_v4l2_queue[src](index : %d) (mNumOfBuf : %d) failed", __func__, 0, mNumOfBuf);
        return false;
    }

    if (fimc_v4l2_queue(mFd, &(mDstBuffer[dst_index]), V4L2_BUF_TYPE_DST, V4L2_MEMORY_TYPE_DST, dst_index, dst_planes) < 0) {
        ALOGE("%s::fimc_v4l2_queue[dst](index : %d) (mNumOfBuf : %d) failed", __func__, dst_index, mNumOfBuf);
        return false;
    }
#else
    if (fimc_v4l2_stream_on(mFd, V4L2_BUF_TYPE_SRC) < 0) {
        ALOGE("%s::fimc_v4l2_stream_on() failed", __func__);
        goto err;
    }

    flagStreamOn = true;

    if (fimc_v4l2_queue(mFd, &(mSrcBuffer), V4L2_BUF_TYPE_SRC, V4L2_MEMORY_TYPE_SRC, src_index, src_planes) < 0) {
        ALOGE("%s::fimc_v4l2_queue(index : %d) (mNumOfBuf : %d) failed", __func__, 0, mNumOfBuf);
        goto err;
    }

    if (fimc_v4l2_dequeue(mFd, V4L2_BUF_TYPE_SRC, V4L2_MEMORY_TYPE_SRC, &src_index, src_planes) < 0) {
        ALOGE("%s::fimc_v4l2_dequeue (mNumOfBuf : %d) failed", __func__, mNumOfBuf);
        goto err;
    }
#endif

err :
#ifndef BOARD_USE_V4L2
    if (flagStreamOn == true) {
        if (fimc_v4l2_stream_off(mFd, V4L2_BUF_TYPE_SRC) < 0) {
            ALOGE("%s::fimc_v4l2_stream_off() failed", __func__);
            return false;
        }
    }
#endif

    return true;
}

bool SecFimc::m_streamOn()
{
#ifdef DEBUG_LIB_FIMC
    ALOGD("%s", __func__);
#endif

#ifdef BOARD_USE_V4L2
    s5p_fimc_params_t *params = &(mS5pFimc.params);
    int src_planes = m_getYuvPlanes(params->src.color_space);
    int dst_planes = m_getYuvPlanes(params->dst.color_space);
    src_planes = (src_planes == -1) ? 1 : src_planes;
    dst_planes = (dst_planes == -1) ? 1 : dst_planes;

    if (params->src.color_space == V4L2_PIX_FMT_RGB32) {
        mSrcBuffer.size.extS[0] = params->src.full_height * params->src.full_width * 4;

    } else if (   (params->src.color_space == V4L2_PIX_FMT_NV12MT)
               || (params->src.color_space == V4L2_PIX_FMT_NV12M)) {
        mSrcBuffer.size.extS[0] = params->src.full_height * params->src.full_width;
        mSrcBuffer.size.extS[1] = params->src.full_height * params->src.full_width / 2;
    } else if (   (params->src.color_space == V4L2_PIX_FMT_YUV420)
               || (params->src.color_space == V4L2_PIX_FMT_YUV420M)) {
        mSrcBuffer.size.extS[0] = params->src.full_height * params->src.full_width;
        mSrcBuffer.size.extS[1] = params->src.full_height * params->src.full_width / 4;
        mSrcBuffer.size.extS[2] = params->src.full_height * params->src.full_width / 4;
    } else {
        mSrcBuffer.size.extS[0] = params->src.full_height * params->src.full_width * 2;
    }

    if (fimc_v4l2_queue(mFd, &(mSrcBuffer), V4L2_BUF_TYPE_SRC, V4L2_MEMORY_TYPE_SRC, 0, src_planes) < 0) {
        ALOGE("%s::fimc_v4l2_queue(index : %d) (mSrcBufNum : %d) failed", __func__, 0, 1);
        return false;
    }

    for (int i = 0; i < mNumOfBuf; i++) {
        if (fimc_v4l2_queue(mFd, &(mDstBuffer[i]),
                           V4L2_BUF_TYPE_DST, V4L2_MEMORY_TYPE_DST, i, dst_planes) < 0) {
            ALOGE("%s::fimc_v4l2_queue(index : %d) (mDstBufNum : %d) failed", __func__, i, mNumOfBuf);
            return false;
        }
    }
#endif
    if (fimc_v4l2_stream_on(mFd, V4L2_BUF_TYPE_SRC) < 0) {
        ALOGE("%s::fimc_v4l2_stream_on() failed", __func__);
        return false;
    }

#ifdef BOARD_USE_V4L2
    if (fimc_v4l2_stream_on(mFd, V4L2_BUF_TYPE_DST) < 0) {
        ALOGE("%s::fimc_v4l2_stream_on() failed", __func__);
        return false;
    }
#endif
    return true;
}

bool SecFimc::m_checkSrcSize(unsigned int width, unsigned int height,
                             unsigned int cropX, unsigned int cropY,
                             unsigned int *cropWidth, unsigned int *cropHeight,
                             int colorFormat,
                             bool forceChange)
{
    bool ret = true;

    if (8 <= height && *cropHeight < 8) {
        if (forceChange)
            *cropHeight = 8;
        ret = false;
    }

    if (16 <= width && *cropWidth < 16) {
        if (forceChange)
            *cropWidth = 16;
        ret = false;
    }

    if (0x50 == mHwVersion) {
        if (colorFormat == V4L2_PIX_FMT_YUV422P) {
            if (*cropHeight % 2 != 0) {
                if (forceChange)
                    *cropHeight = multipleOfN(*cropHeight, 2);
                ret = false;
            }
            if (*cropWidth % 2 != 0) {
                if (forceChange)
                    *cropWidth = multipleOfN(*cropWidth, 2);
                ret = false;
            }
        }
    } else {
        if (height < 8)
            return false;

        if (width % 16 != 0)
            return false;

        if (*cropWidth % 16 != 0) {
            if (forceChange)
                *cropWidth = multipleOfN(*cropWidth, 16);
            ret = false;
        }
    }

    return ret;
}

bool SecFimc::m_checkDstSize(unsigned int width, unsigned int height,
                             unsigned int cropX, unsigned int cropY,
                             unsigned int *cropWidth, unsigned int *cropHeight,
                             int colorFormat, int rotVal,  bool forceChange)
{
    bool ret = true;
    unsigned int rotWidth;
    unsigned int rotHeight;
    unsigned int *rotCropWidth;
    unsigned int *rotCropHeight;

    if (rotVal == 90 || rotVal == 270) {
        rotWidth = height;
        rotHeight = width;
        rotCropWidth = cropHeight;
        rotCropHeight = cropWidth;
    } else {
        rotWidth = width;
        rotHeight = height;
        rotCropWidth = cropWidth;
        rotCropHeight = cropHeight;
    }

    if (rotHeight < 8)
        return false;

    if (rotWidth % 8 != 0)
        return false;

    switch (colorFormat) {
    case V4L2_PIX_FMT_NV21:
    case V4L2_PIX_FMT_NV12:
    case V4L2_PIX_FMT_NV12T:
#ifdef BOARD_USE_V4L2
    case V4L2_PIX_FMT_NV12M:
    case V4L2_PIX_FMT_NV12MT:
    case V4L2_PIX_FMT_YUV420M:
#endif
    case V4L2_PIX_FMT_YUV420:
        if (*rotCropHeight % 2 != 0) {
            if (forceChange)
                *rotCropHeight = multipleOfN(*rotCropHeight, 2);
            ret = false;
        }
    }
    return ret;
}

int SecFimc::m_widthOfFimc(int v4l2ColorFormat, int width)
{
    int newWidth = width;

    if (0x50 == mHwVersion) {
        switch (v4l2ColorFormat) {
        /* 422 1/2/3 plane */
        case V4L2_PIX_FMT_YUYV:
        case V4L2_PIX_FMT_UYVY:
        case V4L2_PIX_FMT_NV61:
        case V4L2_PIX_FMT_NV16:
        case V4L2_PIX_FMT_YUV422P:
        /* 420 2/3 plane */
        case V4L2_PIX_FMT_NV21:
        case V4L2_PIX_FMT_NV12:
        case V4L2_PIX_FMT_NV12T:
#ifdef BOARD_USE_V4L2
        case V4L2_PIX_FMT_NV12MT:
        case V4L2_PIX_FMT_YUV420M:
#endif
        case V4L2_PIX_FMT_YUV420:

            newWidth = multipleOfN(width, 2);
            break;
        default :
            break;
        }
    } else {
        switch (v4l2ColorFormat) {
        case V4L2_PIX_FMT_RGB565:
            newWidth = multipleOfN(width, 8);
            break;
        case V4L2_PIX_FMT_RGB32:
            newWidth = multipleOfN(width, 4);
            break;
        case V4L2_PIX_FMT_YUYV:
        case V4L2_PIX_FMT_UYVY:
            newWidth = multipleOfN(width, 4);
            break;
        case V4L2_PIX_FMT_NV61:
        case V4L2_PIX_FMT_NV16:
            newWidth = multipleOfN(width, 8);
            break;
        case V4L2_PIX_FMT_YUV422P:
            newWidth = multipleOfN(width, 16);
            break;
        case V4L2_PIX_FMT_NV21:
        case V4L2_PIX_FMT_NV12:
        case V4L2_PIX_FMT_NV12T:
#ifdef BOARD_USE_V4L2
        case V4L2_PIX_FMT_NV12MT:
#endif
            newWidth = multipleOfN(width, 8);
            break;
#ifdef BOARD_USE_V4L2
        case V4L2_PIX_FMT_YUV420M:
#endif
        case V4L2_PIX_FMT_YUV420:
            newWidth = multipleOfN(width, 16);
            break;
        default :
            break;
        }
    }
    return newWidth;
}

int SecFimc::m_heightOfFimc(int v4l2ColorFormat, int height)
{
    int newHeight = height;

    switch (v4l2ColorFormat) {
    case V4L2_PIX_FMT_NV21:
    case V4L2_PIX_FMT_NV12:
    case V4L2_PIX_FMT_NV12T:
#ifdef BOARD_USE_V4L2
    case V4L2_PIX_FMT_NV12MT:
    case V4L2_PIX_FMT_YUV420M:
#endif
    case V4L2_PIX_FMT_YUV420:
        newHeight = multipleOfN(height, 2);
        break;
    default :
        break;
    }
    return newHeight;
}

int SecFimc::m_getYuvBpp(unsigned int fmt)
{
    int i, sel = -1;

    for (i = 0; i < (int)(sizeof(yuv_list) / sizeof(struct yuv_fmt_list)); i++) {
        if (yuv_list[i].fmt == fmt) {
            sel = i;
            break;
        }
    }

    if (sel == -1)
        return sel;
    else
        return yuv_list[sel].bpp;
}

int SecFimc::m_getYuvPlanes(unsigned int fmt)
{
    int i, sel = -1;

    for (i = 0; i < (int)(sizeof(yuv_list) / sizeof(struct yuv_fmt_list)); i++) {
        if (yuv_list[i].fmt == fmt) {
            sel = i;
            break;
        }
    }

    if (sel == -1)
        return sel;
    else
        return yuv_list[sel].planes;
}
