codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [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 __SEC_JPG_CODEC_HAL_H__ |
| 19 | #define __SEC_JPG_CODEC_HAL_H__ |
| 20 | |
| 21 | #include "videodev2.h" |
| 22 | |
| 23 | #define JPEG_DEC_NODE "/dev/video11" |
| 24 | #define JPEG_ENC_NODE "/dev/video12" |
| 25 | |
| 26 | #define JPEG_MAX_PLANE_CNT (3) |
| 27 | #define JPEG_BYTE_ALIGN (32) |
| 28 | |
| 29 | #define MAX_JPG_WIDTH 8192 |
| 30 | #define MAX_JPG_HEIGHT 8192 |
| 31 | |
| 32 | #define JPEG_CACHE_OFF (0) |
| 33 | #define JPEG_CACHE_ON (1) |
| 34 | |
| 35 | class SecJpegCodecHal { |
| 36 | public: |
| 37 | ; |
| 38 | SecJpegCodecHal(); |
| 39 | virtual ~SecJpegCodecHal(); |
| 40 | |
| 41 | enum ERROR_JPEG_HAL { |
| 42 | ERROR_JPEG_DEVICE_ALREADY_CREATE = -0x100, |
| 43 | ERROR_CANNOT_OPEN_JPEG_DEVICE, |
| 44 | ERROR_JPEG_DEVICE_ALREADY_CLOSED, |
| 45 | ERROR_JPEG_DEVICE_ALREADY_DESTROY, |
| 46 | ERROR_JPEG_DEVICE_NOT_CREATE_YET, |
| 47 | ERROR_INVALID_COLOR_FORMAT, |
| 48 | ERROR_INVALID_JPEG_FORMAT, |
| 49 | ERROR_INVALID_IMAGE_SIZE, |
| 50 | ERROR_JPEG_CONFIG_POINTER_NULL, |
| 51 | ERROR_INVALID_JPEG_CONFIG, |
| 52 | ERROR_IN_BUFFER_CREATE_FAIL, |
| 53 | ERROR_OUT_BUFFER_CREATE_FAIL, |
| 54 | ERROR_EXCUTE_FAIL, |
| 55 | ERROR_JPEG_SIZE_TOO_SMALL, |
| 56 | ERROR_CANNOT_CHANGE_CACHE_SETTING, |
| 57 | ERROR_SIZE_NOT_SET_YET, |
| 58 | ERROR_BUFFR_IS_NULL, |
| 59 | ERROR_BUFFER_TOO_SMALL, |
| 60 | ERROR_GET_SIZE_FAIL, |
| 61 | ERROR_REQBUF_FAIL, |
| 62 | ERROR_INVALID_V4l2_BUF_TYPE = -0x80, |
| 63 | ERROR_MMAP_FAILED, |
| 64 | ERROR_FAIL, |
| 65 | ERROR_NONE = 0 |
| 66 | }; |
| 67 | |
| 68 | enum MODE { |
| 69 | MODE_ENCODE = 0, |
| 70 | MODE_DECODE |
| 71 | }; |
| 72 | |
| 73 | struct BUFFER{ |
| 74 | int numOfPlanes; |
| 75 | char *addr[JPEG_MAX_PLANE_CNT]; |
| 76 | int size[JPEG_MAX_PLANE_CNT]; |
| 77 | }; |
| 78 | |
| 79 | struct BUF_INFO{ |
| 80 | int numOfPlanes; |
| 81 | enum v4l2_memory memory; |
| 82 | enum v4l2_buf_type buf_type; |
| 83 | int reserved[4]; |
| 84 | }; |
| 85 | |
| 86 | struct PIX_FMT{ |
| 87 | int in_fmt; |
| 88 | int out_fmt; |
| 89 | int reserved[4]; |
| 90 | }; |
| 91 | |
| 92 | struct CONFIG{ |
| 93 | int mode; |
| 94 | int enc_qual; |
| 95 | |
| 96 | int width; |
| 97 | int height; |
| 98 | int scaled_width; |
| 99 | int scaled_height; |
| 100 | |
| 101 | int numOfPlanes; |
| 102 | |
| 103 | int sizeJpeg; |
| 104 | |
| 105 | union { |
| 106 | PIX_FMT enc_fmt; |
| 107 | PIX_FMT dec_fmt; |
| 108 | } pix; |
| 109 | |
| 110 | int reserved[8]; |
| 111 | }; |
| 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); |
| 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 | |
| 142 | class SecJpegEncoderHal : SecJpegCodecHal { |
| 143 | public: |
| 144 | ; |
| 145 | SecJpegEncoderHal(); |
| 146 | virtual ~SecJpegEncoderHal(); |
| 147 | |
| 148 | enum QUALITY { |
| 149 | QUALITY_LEVEL_1 = 0, /* high */ |
| 150 | QUALITY_LEVEL_2, |
| 151 | QUALITY_LEVEL_3, |
| 152 | QUALITY_LEVEL_4, /* low */ |
| 153 | }; |
| 154 | |
| 155 | int create(void); |
| 156 | int destroy(void); |
| 157 | |
| 158 | int setSize(int iW, int iH); |
| 159 | |
| 160 | int setJpegConfig(void* pConfig); |
| 161 | void *getJpegConfig(void); |
| 162 | |
| 163 | |
| 164 | char **getInBuf(int *piInputSize); |
| 165 | char *getOutBuf(int *piOutputSize); |
| 166 | |
| 167 | int setCache(int iValue); |
| 168 | |
| 169 | int setInBuf(char **pcBuf, int *iSize); |
| 170 | int setOutBuf(char *pcBuf, int iSize); |
| 171 | |
| 172 | int getSize(int *piWidth, int *piHeight); |
| 173 | int setColorFormat(int iV4l2ColorFormat); |
| 174 | int setJpegFormat(int iV4l2JpegFormat); |
| 175 | int updateConfig(void); |
| 176 | |
| 177 | int setQuality(int iQuality); |
| 178 | int getJpegSize(void); |
| 179 | |
| 180 | int encode(void); |
| 181 | }; |
| 182 | |
| 183 | class SecJpegDecoderHal : SecJpegCodecHal { |
| 184 | public: |
| 185 | ; |
| 186 | SecJpegDecoderHal(); |
| 187 | virtual ~SecJpegDecoderHal(); |
| 188 | |
| 189 | int create(void); |
| 190 | int destroy(void); |
| 191 | |
| 192 | int setSize(int iW, int iH); |
| 193 | |
| 194 | int setJpegConfig(void* pConfig); |
| 195 | void *getJpegConfig(void); |
| 196 | |
| 197 | |
| 198 | char *getInBuf(int *piInputSize); |
| 199 | char **getOutBuf(int *piOutputSize); |
| 200 | |
| 201 | int setCache(int iValue); |
| 202 | |
| 203 | int setInBuf(char *pcBuf, int iSize); |
| 204 | int setOutBuf(char **pcBuf, int *iSize); |
| 205 | |
| 206 | int getSize(int *piWidth, int *piHeight); |
| 207 | int setColorFormat(int iV4l2ColorFormat); |
| 208 | int setJpegFormat(int iV4l2JpegFormat); |
| 209 | int updateConfig(void); |
| 210 | |
| 211 | int setScaledSize(int iW, int iH); |
| 212 | int setJpegSize(int iJpegSize); |
| 213 | |
| 214 | int decode(void); |
| 215 | }; |
| 216 | |
| 217 | #endif /* __SEC_JPG_CODEC_HAL_H__ */ |