2 * Copyright Samsung Electronics Co.,LTD.
3 * Copyright (C) 2015 The Android Open Source Project
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 // To prevent build conflict with the previous libhwjpeg
19 #ifdef USES_UNIVERSAL_LIBHWJPEG
21 #ifndef __HARDWARE_EXYNOS_EXYNOS_JPEG_API_H__
22 #define __HARDWARE_EXYNOS_EXYNOS_JPEG_API_H__
24 // Exynos HAL defines another version of videodev2 apart from the original one
25 // This prevents conflict from the Exynos HAL from the original videodev2.h
28 #include <linux/videodev2.h>
32 #include <exynos-hwjpeg.h>
35 #define JPEG_CACHE_ON 1
38 #define JPEG_BUF_TYPE_USER_PTR 1
39 #define JPEG_BUF_TYPE_DMA_BUF 2
41 // CUSTOM V4L2 4CC FORMATS FOR LEGACY JPEG LIBRARY AND DRIVERS
42 #ifndef V4L2_PIX_FMT_JPEG_444
43 #define V4L2_PIX_FMT_JPEG_444 v4l2_fourcc('J', 'P', 'G', '4')
45 #ifndef V4L2_PIX_FMT_JPEG_422
46 #define V4L2_PIX_FMT_JPEG_422 v4l2_fourcc('J', 'P', 'G', '2')
48 #ifndef V4L2_PIX_FMT_JPEG_420
49 #define V4L2_PIX_FMT_JPEG_420 v4l2_fourcc('J', 'P', 'G', '0')
51 #ifndef V4L2_PIX_FMT_JPEG_GRAY
52 #define V4L2_PIX_FMT_JPEG_GRAY v4l2_fourcc('J', 'P', 'G', 'G')
54 #ifndef V4L2_PIX_FMT_JPEG_422V
55 #define V4L2_PIX_FMT_JPEG_422V v4l2_fourcc('J', 'P', 'G', '5')
57 #ifndef V4L2_PIX_FMT_JPEG_411
58 #define V4L2_PIX_FMT_JPEG_411 v4l2_fourcc('J', 'P', 'G', '1')
61 class ExynosJpegEncoder
{
63 * ExynosJpedgEncoder class is actually a derived class of
64 * CHWJpegV4L2Compressor. But it is not derived from CHWJpegV4L2Compressor
65 * because it has a lot of virtual functions which require extra memory for
66 * vtables. Moreover, ExynosJpegEncoder class implements no virtual function
67 * of CHWJpegV4L2Compressor.
69 CHWJpegV4L2Compressor m_hwjpeg
;
74 unsigned int m_uiState
;
83 bool __EnsureFormatIsApplied();
86 STATE_SIZE_CHANGED
= 1 << 0,
87 STATE_PIXFMT_CHANGED
= 1 << 1,
88 STATE_BASE_MAX
= 1 << 16,
91 unsigned int GetDeviceCapabilities() { return m_hwjpeg
.GetDeviceCapabilities(); }
92 CHWJpegCompressor
&GetCompressor() { return m_hwjpeg
; }
93 unsigned int GetHWDelay() { return m_hwjpeg
.GetHWDelay(); }
95 void SetState(unsigned int state
) { m_uiState
|= state
; }
96 void ClearState(unsigned int state
) { m_uiState
&= ~state
; }
97 bool TestState(unsigned int state
) { return (m_uiState
& state
) == state
; }
98 bool TestStateEither(unsigned int state
) { return (m_uiState
& state
) != 0; }
100 virtual bool EnsureFormatIsApplied() { return __EnsureFormatIsApplied(); }
102 ExynosJpegEncoder(): m_hwjpeg(),
103 m_iInBufType(JPEG_BUF_TYPE_USER_PTR
), m_iOutBufType(JPEG_BUF_TYPE_USER_PTR
), m_uiState(0),
104 m_nQFactor(0), m_nWidth(0), m_nHeight(0), m_v4l2Format(0), m_jpegFormat(0), m_nStreamSize(0)
106 /* To detect setInBuf() call without format setting */
107 SetState(STATE_SIZE_CHANGED
| STATE_PIXFMT_CHANGED
);
109 virtual ~ExynosJpegEncoder() { destroy(); }
111 // Return 0 on success, -1 on error
112 int flagCreate() { return m_hwjpeg
.Okay() ? 0 : -1; }
113 virtual int create(void) { return flagCreate(); }
114 virtual int destroy(void) { return 0; }
115 int updateConfig(void) { return 0; }
116 int setCache(int val __unused
) { return 0; }
118 void *getJpegConfig() { return reinterpret_cast<void *>(this); }
119 int setJpegConfig(void* pConfig
);
121 int checkInBufType(void) { return m_iInBufType
; }
122 int checkOutBufType(void) { return m_iOutBufType
; }
124 int getInBuf(int *piBuf
, int *piInputSize
, int iSize
);
125 int getOutBuf(int *piBuf
, int *piOutputSize
);
126 int getInBuf(char **pcBuf
, int *piInputSize
, int iSize
);
127 int getOutBuf(char **pcBuf
, int *piOutputSize
);
129 int setInBuf(int *piBuf
, int *iSize
);
130 int setOutBuf(int iBuf
, int iSize
);
131 int setInBuf(char **pcBuf
, int *iSize
);
132 int setOutBuf(char *pcBuf
, int iSize
);
134 int getSize(int *piWidth
, int *piHeight
) {
136 *piHeight
= m_nHeight
;
140 int setSize(int iW
, int iH
) {
141 if ((m_nWidth
!= iW
) || (m_nHeight
!= iH
)) {
144 SetState(STATE_SIZE_CHANGED
);
149 int setJpegFormat(int iV4l2JpegFormat
);
150 int getColorFormat(void) { return m_v4l2Format
; }
151 int setColorFormat(int iV4l2ColorFormat
) {
152 if (iV4l2ColorFormat
!= m_v4l2Format
) {
153 m_v4l2Format
= iV4l2ColorFormat
;
154 SetState(STATE_PIXFMT_CHANGED
);
159 int setQuality(int iQuality
) {
160 if (m_nQFactor
!= iQuality
) {
161 if (!m_hwjpeg
.SetQuality(static_cast<unsigned int>(iQuality
)))
163 m_nQFactor
= iQuality
;
168 int setQuality(const unsigned char q_table
[]);
170 int setColorBufSize(int *piBufSize
, int iSize
);
171 int getJpegSize(void) { return m_nStreamSize
; }
174 if (!__EnsureFormatIsApplied())
177 m_nStreamSize
= static_cast<int>(m_hwjpeg
.Compress());
178 return (m_nStreamSize
< 0) ? -1 : 0;
183 #endif //__HARDWARE_EXYNOS_EXYNOS_JPEG_API_H__
185 #endif //USES_UNIVERSAL_LIBHWJPEG