| /* |
| * Copyright 2013, 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 toggle 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 ExynosCameraNode.h |
| * \brief hearder file for ExynosCameraNode |
| * \author Pilsun Jang(pilsun.jang@samsung.com) |
| * \date 2013/6/27 |
| * |
| */ |
| |
| #ifndef EXYNOS_CAMERA_NODE_H__ |
| #define EXYNOS_CAMERA_NODE_H__ |
| |
| #include <stdio.h> |
| #include <string.h> |
| #include <stdlib.h> |
| |
| #include <fcntl.h> |
| #include <unistd.h> |
| #include <errno.h> |
| #include <signal.h> |
| #include <sys/mman.h> |
| #include <sys/time.h> |
| #include <sys/ioctl.h> |
| #include <sys/poll.h> |
| #include <sys/stat.h> |
| #include <sys/types.h> |
| #include <utils/threads.h> |
| |
| #include <videodev2.h> |
| #include <videodev2_exynos_camera.h> |
| #include <linux/vt.h> |
| |
| #include <utils/RefBase.h> |
| #include <utils/String8.h> |
| #include <utils/List.h> |
| #include <utils/Log.h> |
| #include "cutils/properties.h" |
| #include <ion/ion.h> |
| |
| #include "exynos_format.h" |
| #include "ExynosCameraBuffer.h" |
| #include "ExynosRect.h" |
| /* #include "ExynosFrame.h" */ |
| #include "ExynosCameraAutoTimer.h" |
| |
| #include "exynos_v4l2.h" |
| |
| #include "fimc-is-metadata.h" |
| |
| /* #include "ExynosCameraState.h" */ |
| #include "ExynosCameraConfig.h" |
| |
| using namespace android; |
| |
| /* #define EXYNOS_CAMERA_NODE_TRACE */ |
| /* #define EXYNOS_CAMERA_NODE_TRACE_Q_DURATION */ |
| /* #define EXYNOS_CAMERA_NODE_TRACE_DQ_DURATION */ |
| |
| #ifdef EXYNOS_CAMERA_NODE_TRACE |
| #define EXYNOS_CAMERA_NODE_IN() CLOGD("DEBUG(%s[%d]):IN...m_nodeState[%d]", __FUNCTION__, __LINE__, m_nodeState) |
| #define EXYNOS_CAMERA_NODE_OUT() CLOGD("DEBUG(%s[%d]):OUT..m_nodeState[%d]", __FUNCTION__, __LINE__, m_nodeState) |
| #else |
| #define EXYNOS_CAMERA_NODE_IN() ((void *)0) |
| #define EXYNOS_CAMERA_NODE_OUT() ((void *)0) |
| #endif |
| |
| /* ExynosCameraNode |
| * |
| * ingroup Exynos |
| */ |
| |
| /* |
| * Mapping table |
| * |
| * |------------------------------------------------------------------ |
| * | ExynosCamera | ExynosCameraNode | Driver IOCTL |
| * |------------------------------------------------------------------ |
| * | setSize() | setSize() - NONE | S_FMT |
| * | setColorFormat() | setColorFormat() - NONE | S_FMT |
| * | setBufferType() | setBufferTyoe() - NONE | S_FMT |
| * | prepare() | prepare() - m_setInput() | S_INPUT |
| * | | prepare() - m_setFmt() | S_FMT |
| * | reqBuffer() | reqBuffer() - m_reqBuf() | REQ_BUF |
| * | queryBuffer() | queryBuffer() - m_queryBuf() | QUERY_BUF |
| * | setBuffer() | setBuffer() - m_qBuf() | Q_BUF |
| * | getBuffer() | getBuffer() - m_qBuf() | Q_BUF |
| * | putBuffer() | putBuffer() - m_dqBuf() | DQ_BUF |
| * | start() | start() - m_streamOn() | STREAM_ON |
| * | polling() | polling() - m_poll() | POLL |
| * |------------------------------------------------------------------ |
| * | setBufferRef() | | |
| * | getSize() | | |
| * | getColorFormat() | | |
| * | getBufferType() | | |
| * |------------------------------------------------------------------ |
| * |
| */ |
| |
| enum node_request_state { |
| NODE_REQUEST_STATE_BASE = 0, |
| NODE_REQUEST_STATE_READY, |
| NODE_REQUEST_STATE_QBUF_BLOCK, |
| NODE_REQUEST_STATE_QBUF_DONE, |
| NODE_REQUEST_STATE_DQBUF_BLOCK, |
| NODE_REQUEST_STATE_DQBUF_DONE, |
| NODE_REQUEST_STATE_STOPPED, |
| NODE_REQUEST_STATE_INVALID |
| }; |
| |
| class ExynosCameraNodeRequest { |
| public: |
| /* Constructor */ |
| ExynosCameraNodeRequest(); |
| /* Destructor */ |
| virtual ~ExynosCameraNodeRequest(); |
| |
| void setState(enum node_request_state state); |
| enum node_request_state getState(void); |
| |
| void setRequest(unsigned int requestCount); |
| unsigned int getRequest(void); |
| |
| private: |
| unsigned int m_requestCount; |
| enum node_request_state m_requestState; |
| }; |
| |
| #define NODE_PREPARE_SIZE (1) |
| #define NODE_PREPARE_FORMAT (2) |
| #define NODE_PREPARE_BUFFER_TYPE (3) |
| #define NODE_PREPARE_BUFFER_REF (4) |
| #define NODE_PREPARE_COMPLETE (NODE_PREPARE_SIZE | \ |
| NODE_PREPARE_FORMAT | \ |
| NODE_PREPARE_BUFFER_TYPE | \ |
| NODE_PREPARE_BUFFER_REF) |
| |
| #define NODE_INIT_NEGATIVE_VALUE -1 |
| #define NODE_INIT_ZERO_VALUE 0 |
| |
| class ExynosCameraNode { |
| public: |
| enum EXYNOS_CAMERA_NODE_TYPE { |
| NODE_TYPE_BASE = 0, |
| NODE_TYPE_DUMMY = 999, |
| NODE_TYPE_MAX, |
| }; |
| |
| enum EXYNOS_CAMERA_NODE_STATE { |
| NODE_STATE_BASE = 0, |
| NODE_STATE_NONE, |
| NODE_STATE_CREATED, |
| NODE_STATE_OPENED, |
| NODE_STATE_IN_PREPARE, |
| NODE_STATE_RUNNING, |
| NODE_STATE_DESTROYED, |
| NODE_STATE_MAX |
| }; |
| |
| public: |
| /* Constructor */ |
| ExynosCameraNode(); |
| /* Destructor */ |
| virtual ~ExynosCameraNode(); |
| |
| /* Create the instance */ |
| status_t create(); |
| /* Create the instance */ |
| status_t create(const char *nodeName); |
| /* Create the instance */ |
| status_t create(const char *nodeName, int cameraId); |
| /* Create the instance */ |
| status_t create(const char *nodeName, const char *nodeAlias); |
| /* Create the instance */ |
| status_t create(const char *nodeName, int cameraId, int fd); |
| /* Destroy the instance */ |
| status_t destroy(void); |
| |
| /* open Node */ |
| status_t open(int videoNodeNum); |
| /* close Node */ |
| status_t close(void); |
| /* get file descriptor */ |
| status_t getFd(int *fd); |
| /* get name */ |
| char *getName(void); |
| |
| /* set v4l2 color format */ |
| status_t setColorFormat(int v4l2Colorformat, int planesCount, enum YUV_RANGE yuvRange = YUV_FULL_RANGE); |
| /* get v4l2 color format */ |
| status_t getColorFormat(int *v4l2Colorformat, int *planesCount, enum YUV_RANGE *yuvRange = NULL); |
| |
| /* set size */ |
| status_t setSize(int w, int h); |
| /* get size */ |
| status_t getSize(int *w, int *h); |
| |
| /* set id */ |
| status_t setId(int id); |
| |
| /* set memory info */ |
| status_t setBufferType( |
| int bufferCount, |
| enum v4l2_buf_type type, |
| enum v4l2_memory bufferMemoryType); |
| /* get memory info */ |
| status_t getBufferType( |
| int *bufferCount, |
| enum v4l2_buf_type *type, |
| enum v4l2_memory *bufferMemoryType); |
| |
| /* query buffer */ |
| status_t queryBuf(void); |
| /* request buffers */ |
| status_t reqBuffers(void); |
| /* clear buffers */ |
| status_t clrBuffers(void); |
| /* check buffers */ |
| unsigned int reqBuffersCount(void); |
| |
| /* set id */ |
| status_t setControl(unsigned int id, int value); |
| status_t getControl(unsigned int id, int *value); |
| |
| /* polling */ |
| status_t polling(void); |
| |
| /* setInput */ |
| status_t setInput(int sensorId); |
| /* getInput */ |
| int getInput(void); |
| |
| #ifdef SUPPORT_GROUP_MIGRATION |
| /* resetInput */ |
| int resetInput(void); |
| |
| /* get video Num */ |
| int getNodeNum(); |
| #endif |
| |
| /* setCrop */ |
| status_t setCrop(enum v4l2_buf_type type, int x, int y, int w, int h); |
| |
| /* setFormat */ |
| status_t setFormat(void); |
| status_t setFormat(unsigned int bytesPerPlane[]); |
| |
| /* startNode */ |
| status_t start(void); |
| /* stopNode */ |
| status_t stop(void); |
| |
| /* Check if the instance was created */ |
| bool isCreated(void); |
| /* Check if it start */ |
| bool isStarted(void); |
| |
| /* putBuffer */ |
| status_t putBuffer(ExynosCameraBuffer *buf); |
| status_t mapBuffer(ExynosCameraBuffer *buf); |
| |
| /* getBuffer */ |
| status_t getBuffer(ExynosCameraBuffer *buf, int *dqIndex); |
| |
| /* dump the object info */ |
| void dump(void); |
| /* dump state info */ |
| void dumpState(void); |
| /* dump queue info */ |
| void dumpQueue(void); |
| |
| /* set param */ |
| int setParam(struct v4l2_streamparm *stream_parm); |
| void removeItemBufferQ(); |
| |
| private: |
| /* get pixel format */ |
| int m_pixelDepth(void); |
| /* check whether queued on index */ |
| bool m_getFlagQ(int index); |
| /* set queue flag on index */ |
| bool m_setFlagQ(int index, bool toggle); |
| /* polling */ |
| int m_polling(void); |
| |
| /* stream on */ |
| int m_streamOn(void); |
| /* stream off */ |
| int m_streamOff(void); |
| |
| /* set input */ |
| int m_setInput(int id); |
| /* set format */ |
| int m_setFmt(void); |
| /* req buf */ |
| int m_reqBuffers(int *reqCount); |
| /* clear buf */ |
| int m_clrBuffers(int *reqCount); |
| /* set crop */ |
| int m_setCrop(int v4l2BufType, ExynosRect *rect); |
| /* set contorl */ |
| int m_setControl(unsigned int id, int value); |
| /* get contorl */ |
| int m_getControl(unsigned int id, int *value); |
| |
| /* qbuf from src, with metaBuf */ |
| int m_qBuf(ExynosCameraBuffer *buf); |
| int m_mBuf(ExynosCameraBuffer *buf); |
| |
| /* dqbuf */ |
| int m_dqBuf(ExynosCameraBuffer *buf, int *dqIndex); |
| |
| /* Buffer trace */ |
| status_t m_putBufferQ(ExynosCameraBuffer *buf, int *qindex); |
| status_t m_getBufferQ(ExynosCameraBuffer *buf, int *dqindex); |
| bool m_isExistBufferQ(ExynosCameraBuffer *buf); |
| void m_printBufferQ(); |
| void m_removeItemBufferQ(); |
| int m_YUV_RANGE_2_V4L2_COLOR_RANGE(enum YUV_RANGE yuvRange); |
| enum YUV_RANGE m_V4L2_COLOR_RANGE_2_YUV_RANGE(int v4l2ColorRange); |
| |
| /* |
| * thoes member value should be declare in private |
| * but we declare in publuc to support backward compatibility |
| */ |
| public: |
| |
| private: |
| ExynosCameraNodeRequest m_nodeRequest; |
| |
| bool m_flagStart; |
| bool m_flagCreate; |
| |
| char m_name[EXYNOS_CAMERA_NAME_STR_SIZE]; |
| char m_alias[EXYNOS_CAMERA_NAME_STR_SIZE]; |
| |
| int m_cameraId; |
| int m_sensorId; |
| int m_fd; |
| struct v4l2_format m_v4l2Format; |
| struct v4l2_requestbuffers m_v4l2ReqBufs; |
| struct v4l2_crop m_crop; |
| |
| bool m_flagQ[VIDEO_MAX_FRAME]; |
| Mutex m_qLock; |
| |
| bool m_flagStreamOn; |
| /* for reprocessing */ |
| bool m_flagDup; |
| |
| int m_paramSate; |
| mutable Mutex m_nodeStateLock; |
| mutable Mutex m_nodeActionLock; |
| |
| Mutex m_queueBufferListLock; |
| ExynosCameraBuffer m_queueBufferList[MAX_BUFFERS]; |
| |
| /* ExynosCameraState m_nodeStateMgr; */ |
| int m_nodeState; |
| #ifdef SUPPORT_GROUP_MIGRATION |
| int m_nodeNum; |
| #endif |
| enum EXYNOS_CAMERA_NODE_TYPE m_nodeType; |
| List<int> m_dummyIndexQ; |
| |
| #ifdef EXYNOS_CAMERA_NODE_TRACE_Q_DURATION |
| ExynosCameraDurationTimer m_qTimer; |
| #endif |
| |
| #ifdef EXYNOS_CAMERA_NODE_TRACE_DQ_DURATION |
| ExynosCameraDurationTimer m_dqTimer; |
| #endif |
| }; |
| |
| #endif /* EXYNOS_CAMERA_NODE_H__ */ |
| |
| |