Home | History | Annotate | Download | only in include
      1 /*
      2  * Copyright Samsung Electronics Co.,LTD.
      3  * Copyright (C) 2011 The Android Open Source Project
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 #ifndef __EXYNOS_JPEG_BASE_H__
     19 #define __EXYNOS_JPEG_BASE_H__
     20 
     21 #include "videodev2.h"
     22 #include "videodev2_exynos_media.h"
     23 
     24 #define JPEG_CACHE_OFF (0)
     25 #define JPEG_CACHE_ON (1)
     26 #define KERNEL_33_JPEG_API (1)
     27 
     28 class ExynosJpegBase {
     29 public:
     30     ;
     31     #define JPEG_MAX_PLANE_CNT          (3)
     32     ExynosJpegBase();
     33     virtual ~ExynosJpegBase();
     34 
     35     enum ERROR_JPEG_HAL {
     36         ERROR_JPEG_DEVICE_ALREADY_CREATE = -0x100,
     37         ERROR_INVALID_JPEG_MODE,
     38         ERROR_CANNOT_OPEN_JPEG_DEVICE,
     39         ERROR_JPEG_DEVICE_ALREADY_CLOSED,
     40         ERROR_JPEG_DEVICE_ALREADY_DESTROY,
     41         ERROR_JPEG_DEVICE_NOT_CREATE_YET,
     42         ERROR_INVALID_COLOR_FORMAT,
     43         ERROR_INVALID_JPEG_FORMAT,
     44         ERROR_INVALID_IMAGE_SIZE,
     45         ERROR_JPEG_CONFIG_POINTER_NULL,
     46         ERROR_INVALID_JPEG_CONFIG,
     47         ERROR_IN_BUFFER_CREATE_FAIL,
     48         ERROR_OUT_BUFFER_CREATE_FAIL,
     49         ERROR_EXCUTE_FAIL,
     50         ERROR_JPEG_SIZE_TOO_SMALL,
     51         ERROR_CANNOT_CHANGE_CACHE_SETTING,
     52         ERROR_SIZE_NOT_SET_YET,
     53         ERROR_BUFFR_IS_NULL,
     54         ERROR_BUFFER_TOO_SMALL,
     55         ERROR_GET_SIZE_FAIL,
     56         ERROR_BUF_NOT_SET_YET,
     57         ERROR_REQBUF_FAIL,
     58         ERROR_INVALID_V4l2_BUF_TYPE = -0x80,
     59         ERROR_MMAP_FAILED,
     60         ERROR_FAIL,
     61         ERROR_NONE = 0
     62     };
     63 
     64     enum MODE {
     65         MODE_ENCODE = 0,
     66         MODE_DECODE
     67     };
     68 
     69     struct BUFFER{
     70         int     numOfPlanes;
     71         int     addr[JPEG_MAX_PLANE_CNT];
     72         int     size[JPEG_MAX_PLANE_CNT];
     73     };
     74 
     75     struct BUF_INFO{
     76         int                 numOfPlanes;
     77         enum v4l2_memory    memory;
     78         enum v4l2_buf_type  buf_type;
     79         int                 reserved[4];
     80     };
     81 
     82     struct PIX_FMT{
     83         int in_fmt;
     84         int out_fmt;
     85         int reserved[4];
     86     };
     87 
     88     struct CONFIG{
     89         int               mode;
     90         int               enc_qual;
     91 
     92         int               width;
     93         int               height;
     94         int               scaled_width;
     95         int               scaled_height;
     96 
     97         int               numOfPlanes;
     98 
     99         int               sizeJpeg;
    100 
    101         union {
    102             PIX_FMT enc_fmt;
    103             PIX_FMT dec_fmt;
    104         } pix;
    105 
    106         int              reserved[8];
    107     };
    108 
    109     int setSize(int iW, int iH);
    110     int setCache(int iValue);
    111     void *getJpegConfig(void);
    112 
    113 protected:
    114     // variables
    115     bool t_bFlagCreate;
    116     bool t_bFlagCreateInBuf;
    117     bool t_bFlagCreateOutBuf;
    118     bool t_bFlagExcute;
    119 
    120     int t_iPlaneNum;
    121 
    122     int t_iJpegFd;
    123     struct CONFIG t_stJpegConfig;
    124     struct BUFFER t_stJpegInbuf;
    125     struct BUFFER t_stJpegOutbuf;
    126 
    127     //functions
    128     int t_v4l2Querycap(int iFd);
    129     int t_v4l2SetJpegcomp(int iFd, int iQuality);
    130     int t_v4l2SetFmt(int iFd, enum v4l2_buf_type eType, struct CONFIG *pstConfig);
    131     int t_v4l2GetFmt(int iFd, enum v4l2_buf_type eType, struct CONFIG *pstConfig);
    132     int t_v4l2Reqbufs(int iFd, int iBufCount, struct BUF_INFO *pstBufInfo);
    133     int t_v4l2Qbuf(int iFd, struct BUF_INFO *pstBufInfo, struct BUFFER *pstBuf);
    134     int t_v4l2Dqbuf(int iFd, enum v4l2_buf_type eType, enum v4l2_memory eMemory, int iNumPlanes);
    135     int t_v4l2StreamOn(int iFd, enum v4l2_buf_type eType);
    136     int t_v4l2StreamOff(int iFd, enum v4l2_buf_type eType);
    137     int t_v4l2SetCtrl(int iFd, int iCid, int iValue);
    138     int t_v4l2GetCtrl(int iFd, int iCid);
    139 
    140     int create(enum MODE eMode);
    141     int destroy(int iInBufs, int iOutBufs);
    142     int setJpegConfig(enum MODE eMode, void *pConfig);
    143     int setColorFormat(enum MODE eMode, int iV4l2ColorFormat);
    144     int setJpegFormat(enum MODE eMode, int iV4l2JpegFormat);
    145     int setColorBufSize(enum MODE eMode, int *piBufSize, int iSize);
    146     int setColorBufSize(int iFormat, int *piBufSize, int iSize, int width, int height);
    147     int getBuf(bool bCreateBuf, struct BUFFER *pstBuf, int *piBuf, int *iBufSize, int iSize, int iPlaneNum);
    148     int setBuf(struct BUFFER *pstBuf, int *piBuf, int *iSize, int iPlaneNum);
    149     int updateConfig(enum MODE eMode, int iInBufs, int iOutBufs, int iInBufPlanes, int iOutBufPlanes);
    150     int execute(int iInBufPlanes, int iOutBufPlanes);
    151 };
    152 
    153 //! ExynosJpegEncoder class
    154 /*!
    155  * \ingroup Exynos
    156  */
    157 class ExynosJpegEncoder : public ExynosJpegBase {
    158 public:
    159     ;
    160     ExynosJpegEncoder();
    161     virtual ~ExynosJpegEncoder();
    162 
    163     enum QUALITY {
    164         QUALITY_LEVEL_1 = 0,    /* high */
    165         QUALITY_LEVEL_2,
    166         QUALITY_LEVEL_3,
    167         QUALITY_LEVEL_4,        /* low */
    168     };
    169 
    170     int     create(void);
    171     int     destroy(void);
    172 
    173     int     setJpegConfig(void* pConfig);
    174 
    175     int     getInBuf(int *piBuf, int *piInputSize, int iSize);
    176     int     getOutBuf(int *piBuf, int *piOutputSize);
    177 
    178     int     setInBuf(int *piBuf, int *iSize);
    179     int     setOutBuf(int iBuf, int iSize);
    180 
    181     int     getSize(int *piWidth, int *piHeight);
    182     int     getColorFormat(void);
    183     int     setColorFormat(int iV4l2ColorFormat);
    184     int     setJpegFormat(int iV4l2JpegFormat);
    185     int     setColorBufSize(int *piBufSize, int iSize);
    186     int     updateConfig(void);
    187 
    188     int     setQuality(int iQuality);
    189     int     getJpegSize(void);
    190 
    191     int     encode(void);
    192 };
    193 
    194 //! ExynosJpegDecoder class
    195 /*!
    196  * \ingroup Exynos
    197  */
    198 class ExynosJpegDecoder : public ExynosJpegBase {
    199 public:
    200     ;
    201     ExynosJpegDecoder();
    202     virtual ~ExynosJpegDecoder();
    203 
    204     int     create(void);
    205     int     destroy(void);
    206 
    207     int     setJpegConfig(void* pConfig);
    208 
    209     int     getInBuf(int *piBuf, int *piInputSize);
    210     int     getOutBuf(int *picBuf, int *piOutputSize, int iSize);
    211 
    212     int     setInBuf(int iBuf, int iSize);
    213     int     setOutBuf(int *piBuf, int *iSize);
    214 
    215     int     getSize(int *piWidth, int *piHeight);
    216     int     setColorFormat(int iV4l2ColorFormat);
    217     int     setJpegFormat(int iV4l2JpegFormat);
    218     int     updateConfig(void);
    219 
    220     int setScaledSize(int iW, int iH);
    221     int setJpegSize(int iJpegSize);
    222 
    223     int  decode(void);
    224 #ifdef WA_BLOCKING_ARTIFACT
    225 private:
    226     void reduceBlockingArtifact(unsigned char *addr, int iColor, int width, int height);
    227 #endif
    228 };
    229 
    230 #endif /* __EXYNOS_JPEG_BASE_H__ */
    231