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_JPEG_ENCODER_FOR_CAMERA_H__
22 #define __HARDWARE_EXYNOS_JPEG_ENCODER_FOR_CAMERA_H__
26 #include "ExynosExif.h"
27 #include "ExynosJpegApi.h"
29 class CLibCSC
; // defined in libhwjpeg/hwjpeg-libcsc.h
30 class CAppMarkerWriter
; // defined in libhwjpeg/AppMarkerWriter.h
32 class ExynosJpegEncoderForCamera
: public ExynosJpegEncoder
{
34 STATE_THUMBSIZE_CHANGED
= STATE_BASE_MAX
<< 0,
35 STATE_HWFC_ENABLED
= STATE_BASE_MAX
<< 1,
36 STATE_NO_CREATE_THUMBIMAGE
= STATE_BASE_MAX
<< 2,
37 STATE_NO_BTBCOMP
= STATE_BASE_MAX
<< 3,
40 CHWJpegCompressor
*m_phwjpeg4thumb
;
43 int m_fdIONThumbImgBuffer
;
44 char *m_pIONThumbImgBuffer
;
45 size_t m_szIONThumbImgBuffer
;
46 char *m_pIONThumbJpegBuffer
;
47 size_t m_szIONThumbJpegBuffer
;
56 * The following four placeholders and size vairables are used
57 * by asynchronous(non-blocking) compression
62 char m_fThumbBufferType
;
65 char *m_pThumbnailImageBuffer
[3]; // checkInBufType() == JPEG_BUF_TYPE_USER_PTR
66 int m_fdThumbnailImageBuffer
[3]; // checkInBufType() == JPEG_BUF_TYPE_DMA_BUF
68 size_t m_szThumbnailImageLen
[3];
70 CAppMarkerWriter
*m_pAppWriter
;
72 pthread_t m_threadWorker
;
74 bool AllocThumbBuffer(int v4l2Format
); /* For single compression */
75 bool AllocThumbJpegBuffer(); /* For BTB compression */
76 bool GenerateThumbnailImage();
77 size_t CompressThumbnail();
78 size_t CompressThumbnailOnly(size_t limit
, int quality
, unsigned int v4l2Format
, int src_buftype
);
79 size_t RemoveTrailingDummies(char *base
, size_t len
);
80 ssize_t
FinishCompression(size_t mainlen
, size_t thumblen
);
81 bool ProcessExif(char *base
, size_t limit
, exif_attribute_t
*exifInfo
, debug_attribute_t
*debuginfo
);
82 static void *tCompressThumbnail(void *p
);
83 bool PrepareCompression(bool thumbnail
);
85 // IsThumbGenerationNeeded - true if thumbnail image needed to be generated from the main image
86 // It also implies that a worker thread is generated to generate thumbnail concurrently.
87 inline bool IsThumbGenerationNeeded() { return !TestState(STATE_NO_CREATE_THUMBIMAGE
); }
88 inline void NoThumbGenerationNeeded() { SetState(STATE_NO_CREATE_THUMBIMAGE
); }
89 inline void ThumbGenerationNeeded() { ClearState(STATE_NO_CREATE_THUMBIMAGE
); }
91 inline bool IsBTBCompressionSupported() {
92 return !!(GetDeviceCapabilities() & V4L2_CAP_EXYNOS_JPEG_B2B_COMPRESSION
) &&
93 !TestState(STATE_NO_BTBCOMP
);
96 virtual bool EnsureFormatIsApplied();
98 ExynosJpegEncoderForCamera(bool bBTBComp
= true);
99 virtual ~ExynosJpegEncoderForCamera();
101 int encode(int *size
, exif_attribute_t
*exifInfo
, char** pcJpegBuffer
, debug_attribute_t
*debugInfo
= 0);
102 int setInBuf2(int *piBuf
, int *iSize
);
103 int setInBuf2(char **pcBuf
, int *iSize
);
104 int setThumbnailSize(int w
, int h
);
105 int setThumbnailQuality(int quality
);
107 void setExtScalerNum(int csc_hwscaler_id
) { m_iHWScalerID
= csc_hwscaler_id
; }
110 SetState(STATE_HWFC_ENABLED
);
111 GetCompressor().SetAuxFlags(EXYNOS_HWJPEG_AUXOPT_ENABLE_HWFC
);
114 GetCompressor().ClearAuxFlags(EXYNOS_HWJPEG_AUXOPT_ENABLE_HWFC
);
115 ClearState(STATE_HWFC_ENABLED
);
118 ssize_t
WaitForCompression();
120 size_t GetThumbnailImage(char *buffer
, size_t buflen
);
122 virtual int destroy(void);
125 #endif //__HARDWARE_EXYNOS_JPEG_ENCODER_FOR_CAMERA_H__
127 #endif //USES_UNIVERSAL_LIBHWJPEG