Commit | Line | Data |
---|---|---|
5763fb39 T |
1 | /* |
2 | * Copyright Samsung Electronics Co.,LTD. | |
3 | * Copyright (C) 2015 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 | // To prevent build conflict with the previous libhwjpeg | |
19 | #ifdef USES_UNIVERSAL_LIBHWJPEG | |
20 | ||
21 | #ifndef __HARDWARE_EXYNOS_JPEG_ENCODER_FOR_CAMERA_H__ | |
22 | #define __HARDWARE_EXYNOS_JPEG_ENCODER_FOR_CAMERA_H__ | |
23 | ||
24 | #include <pthread.h> | |
25 | ||
26 | #include "ExynosExif.h" | |
27 | #include "ExynosJpegApi.h" | |
28 | ||
29 | class CLibCSC; // defined in libhwjpeg/hwjpeg-libcsc.h | |
30 | class CAppMarkerWriter; // defined in libhwjpeg/AppMarkerWriter.h | |
31 | ||
32 | class ExynosJpegEncoderForCamera: public ExynosJpegEncoder { | |
33 | enum { | |
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, | |
38 | }; | |
39 | ||
40 | CHWJpegCompressor *m_phwjpeg4thumb; | |
41 | CLibCSC *m_pLibCSC; | |
42 | int m_fdIONClient; | |
43 | int m_fdIONThumbImgBuffer; | |
44 | char *m_pIONThumbImgBuffer; | |
45 | size_t m_szIONThumbImgBuffer; | |
46 | char *m_pIONThumbJpegBuffer; | |
47 | size_t m_szIONThumbJpegBuffer; | |
48 | ||
49 | int m_nThumbWidth; | |
50 | int m_nThumbHeight; | |
5763fb39 T |
51 | int m_nThumbQuality; |
52 | ||
53 | int m_iHWScalerID; | |
54 | ||
55 | /* | |
56 | * The following four placeholders and size vairables are used | |
57 | * by asynchronous(non-blocking) compression | |
58 | */ | |
59 | char *m_pStreamBase; | |
60 | size_t m_nStreamSize; | |
61 | ||
62 | char m_fThumbBufferType; | |
63 | ||
64 | union { | |
65 | char *m_pThumbnailImageBuffer[3]; // checkInBufType() == JPEG_BUF_TYPE_USER_PTR | |
66 | int m_fdThumbnailImageBuffer[3]; // checkInBufType() == JPEG_BUF_TYPE_DMA_BUF | |
67 | }; | |
68 | size_t m_szThumbnailImageLen[3]; | |
69 | ||
70 | CAppMarkerWriter *m_pAppWriter; | |
71 | ||
72 | pthread_t m_threadWorker; | |
73 | ||
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); | |
84 | ||
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); } | |
90 | ||
91 | inline bool IsBTBCompressionSupported() { | |
92 | return !!(GetDeviceCapabilities() & V4L2_CAP_EXYNOS_JPEG_B2B_COMPRESSION) && | |
93 | !TestState(STATE_NO_BTBCOMP); | |
94 | } | |
95 | protected: | |
96 | virtual bool EnsureFormatIsApplied(); | |
97 | public: | |
98 | ExynosJpegEncoderForCamera(bool bBTBComp = true); | |
99 | virtual ~ExynosJpegEncoderForCamera(); | |
100 | ||
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); | |
106 | ||
107 | void setExtScalerNum(int csc_hwscaler_id) { m_iHWScalerID = csc_hwscaler_id; } | |
108 | ||
109 | void EnableHWFC() { | |
110 | SetState(STATE_HWFC_ENABLED); | |
111 | GetCompressor().SetAuxFlags(EXYNOS_HWJPEG_AUXOPT_ENABLE_HWFC); | |
112 | } | |
113 | void DisableHWFC() { | |
114 | GetCompressor().ClearAuxFlags(EXYNOS_HWJPEG_AUXOPT_ENABLE_HWFC); | |
115 | ClearState(STATE_HWFC_ENABLED); | |
116 | } | |
117 | ||
118 | ssize_t WaitForCompression(); | |
119 | ||
120 | size_t GetThumbnailImage(char *buffer, size_t buflen); | |
121 | ||
122 | virtual int destroy(void); | |
123 | }; | |
124 | ||
125 | #endif //__HARDWARE_EXYNOS_JPEG_ENCODER_FOR_CAMERA_H__ | |
126 | ||
127 | #endif //USES_UNIVERSAL_LIBHWJPEG |