Jiho Chang | 20c5168 | 2012-03-24 05:37:21 +0900 | [diff] [blame] | 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" |
Jiho Chang | 234f72f | 2012-04-26 12:59:36 -0700 | [diff] [blame] | 22 | #include "videodev2_exynos_media.h" |
Jiho Chang | 20c5168 | 2012-03-24 05:37:21 +0900 | [diff] [blame] | 23 | |
| 24 | //#define JPEG_DEC_BYTE_ALIGN (8) |
| 25 | |
| 26 | #define JPEG_CACHE_OFF (0) |
| 27 | #define JPEG_CACHE_ON (1) |
| 28 | |
| 29 | class ExynosJpegBase { |
| 30 | public: |
| 31 | ; |
| 32 | #define JPEG_MAX_PLANE_CNT (3) |
| 33 | ExynosJpegBase(); |
| 34 | virtual ~ExynosJpegBase(); |
| 35 | |
| 36 | enum ERROR_JPEG_HAL { |
| 37 | ERROR_JPEG_DEVICE_ALREADY_CREATE = -0x100, |
| 38 | ERROR_INVALID_JPEG_MODE, |
| 39 | ERROR_CANNOT_OPEN_JPEG_DEVICE, |
| 40 | ERROR_JPEG_DEVICE_ALREADY_CLOSED, |
| 41 | ERROR_JPEG_DEVICE_ALREADY_DESTROY, |
| 42 | ERROR_JPEG_DEVICE_NOT_CREATE_YET, |
| 43 | ERROR_INVALID_COLOR_FORMAT, |
| 44 | ERROR_INVALID_JPEG_FORMAT, |
| 45 | ERROR_INVALID_IMAGE_SIZE, |
| 46 | ERROR_JPEG_CONFIG_POINTER_NULL, |
| 47 | ERROR_INVALID_JPEG_CONFIG, |
| 48 | ERROR_IN_BUFFER_CREATE_FAIL, |
| 49 | ERROR_OUT_BUFFER_CREATE_FAIL, |
| 50 | ERROR_EXCUTE_FAIL, |
| 51 | ERROR_JPEG_SIZE_TOO_SMALL, |
| 52 | ERROR_CANNOT_CHANGE_CACHE_SETTING, |
| 53 | ERROR_SIZE_NOT_SET_YET, |
| 54 | ERROR_BUFFR_IS_NULL, |
| 55 | ERROR_BUFFER_TOO_SMALL, |
| 56 | ERROR_GET_SIZE_FAIL, |
| 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 | char *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_v4l2Querybuf(int iFd, struct BUF_INFO *pstBufInfo, struct BUFFER *pstBuf); |
| 134 | int t_v4l2Qbuf(int iFd, struct BUF_INFO *pstBufInfo, struct BUFFER *pstBuf); |
| 135 | int t_v4l2Dqbuf(int iFd, enum v4l2_buf_type eType, enum v4l2_memory eMemory, int iNumPlanes); |
| 136 | int t_v4l2StreamOn(int iFd, enum v4l2_buf_type eType); |
| 137 | int t_v4l2StreamOff(int iFd, enum v4l2_buf_type eType); |
| 138 | int t_v4l2SetCtrl(int iFd, int iCid, int iValue); |
| 139 | int t_v4l2GetCtrl(int iFd, int iCid); |
| 140 | |
| 141 | int create(enum MODE eMode); |
| 142 | int destroy(int iInBufs, int iOutBufs); |
| 143 | int setJpegConfig(enum MODE eMode, void *pConfig); |
| 144 | int setColorFormat(enum MODE eMode, int iV4l2ColorFormat); |
| 145 | int setJpegFormat(enum MODE eMode, int iV4l2JpegFormat); |
| 146 | int getBuf(struct BUFFER *pstBuf, char **pcBuf, int *piInputSize, int iPlaneNum); |
| 147 | int setBuf(struct BUFFER *pstBuf, char **pcBuf, int *iSize, int iPlaneNum); |
| 148 | int updateConfig(enum MODE eMode, int iInBufs, int iOutBufs, int iInBufPlanes, int iOutBufPlanes); |
| 149 | int excute(int iInBufPlanes, int iOutBufPlanes); |
| 150 | }; |
| 151 | |
| 152 | //! ExynosJpegEncoder class |
| 153 | /*! |
| 154 | * \ingroup Exynos |
| 155 | */ |
| 156 | class ExynosJpegEncoder : public ExynosJpegBase { |
| 157 | public: |
| 158 | ; |
| 159 | ExynosJpegEncoder(); |
| 160 | virtual ~ExynosJpegEncoder(); |
| 161 | |
| 162 | enum QUALITY { |
| 163 | QUALITY_LEVEL_1 = 0, /* high */ |
| 164 | QUALITY_LEVEL_2, |
| 165 | QUALITY_LEVEL_3, |
| 166 | QUALITY_LEVEL_4, /* low */ |
| 167 | }; |
| 168 | |
| 169 | int create(void); |
| 170 | int destroy(void); |
| 171 | |
| 172 | int setJpegConfig(void* pConfig); |
| 173 | |
| 174 | char **getInBuf(int *piInputSize); |
| 175 | char *getOutBuf(int *piOutputSize); |
| 176 | |
| 177 | int setInBuf(char **pcBuf, int *iSize); |
| 178 | int setOutBuf(char *pcBuf, int iSize); |
| 179 | |
| 180 | int getSize(int *piWidth, int *piHeight); |
| 181 | int setColorFormat(int iV4l2ColorFormat); |
| 182 | int setJpegFormat(int iV4l2JpegFormat); |
| 183 | int updateConfig(void); |
| 184 | |
| 185 | int setQuality(int iQuality); |
| 186 | int getJpegSize(void); |
| 187 | |
| 188 | int encode(void); |
| 189 | }; |
| 190 | |
| 191 | //! ExynosJpegDecoder class |
| 192 | /*! |
| 193 | * \ingroup Exynos |
| 194 | */ |
| 195 | class ExynosJpegDecoder : public ExynosJpegBase { |
| 196 | public: |
| 197 | ; |
| 198 | ExynosJpegDecoder(); |
| 199 | virtual ~ExynosJpegDecoder(); |
| 200 | |
| 201 | int create(void); |
| 202 | int destroy(void); |
| 203 | |
| 204 | int setJpegConfig(void* pConfig); |
| 205 | |
| 206 | char *getInBuf(int *piInputSize); |
| 207 | char **getOutBuf(int *piOutputSize); |
| 208 | |
| 209 | int setInBuf(char *pcBuf, int iSize); |
| 210 | int setOutBuf(char **pcBuf, int *iSize); |
| 211 | |
| 212 | int getSize(int *piWidth, int *piHeight); |
| 213 | int setColorFormat(int iV4l2ColorFormat); |
| 214 | int setJpegFormat(int iV4l2JpegFormat); |
| 215 | int updateConfig(void); |
| 216 | |
| 217 | int setScaledSize(int iW, int iH); |
| 218 | int setJpegSize(int iJpegSize); |
| 219 | |
| 220 | int decode(void); |
| 221 | }; |
| 222 | |
| 223 | #endif /* __EXYNOS_JPEG_BASE_H__ */ |