Commit | Line | Data |
---|---|---|
5763fb39 T |
1 | /* |
2 | * Copyright@ Samsung Electronics Co. LTD | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | ||
17 | #ifndef LIBGSCALER_OBJ_H_ | |
18 | #define LIBGSCALER_OBJ_H_ | |
19 | ||
20 | #ifdef __cplusplus | |
21 | extern "C" { | |
22 | #endif | |
23 | ||
24 | //#define LOG_NDEBUG 0 | |
25 | #define LOG_TAG "libexynosgscaler" | |
26 | #include <cutils/log.h> | |
27 | ||
28 | #include <sys/types.h> | |
29 | #include <sys/ioctl.h> | |
a4e95a20 | 30 | #include <linux/videodev2.h> |
5763fb39 T |
31 | #include <fcntl.h> |
32 | #include <stdbool.h> | |
33 | #include <string.h> | |
34 | #include <unistd.h> | |
35 | #include <stdio.h> | |
36 | #include <stdlib.h> | |
37 | #include <time.h> | |
38 | #include <system/graphics.h> | |
a4e95a20 | 39 | #include <linux/videodev2_exynos_media.h> |
5763fb39 T |
40 | #include "exynos_gscaler.h" |
41 | ||
42 | #include "exynos_format.h" | |
43 | #include "exynos_v4l2.h" | |
44 | #include "LibMpp.h" | |
45 | ||
46 | #include "exynos_scaler.h" | |
47 | ||
48 | #define NUM_OF_GSC_PLANES (3) | |
49 | #define MAX_BUFFERS_GSCALER_OUT (10) | |
50 | #define MAX_BUFFERS_GSCALER_CAP (1) | |
51 | #define GSCALER_SUBDEV_PAD_SINK (0) | |
52 | #define GSCALER_SUBDEV_PAD_SOURCE (1) | |
53 | #define MIXER_V_SUBDEV_PAD_SINK (0) | |
54 | #define MIXER_V_SUBDEV_PAD_SOURCE (3) | |
55 | #define FIMD_SUBDEV_PAD_SINK (0) | |
56 | #define DECON_TV_WB_PAD (0) | |
57 | #define MAX_BUFFERS (6) | |
58 | ||
59 | #define NUM_OF_GSC_HW (4) | |
60 | #define NODE_NUM_GSC_0 (23) | |
61 | #define NODE_NUM_GSC_1 (26) | |
62 | #define NODE_NUM_GSC_2 (29) | |
63 | #define NODE_NUM_GSC_3 (32) | |
64 | ||
65 | #define PFX_NODE_GSC "/dev/video" | |
66 | #define PFX_NODE_MEDIADEV "/dev/media" | |
67 | #define PFX_MXR_ENTITY "s5p-mixer%d" | |
68 | #define PFX_FIMD_ENTITY "s3c-fb-window%d" | |
69 | #if defined(USES_DT) | |
70 | #define PFX_GSC_VIDEODEV_ENTITY0 "13c00000.gsc.output" | |
71 | #define PFX_GSC_VIDEODEV_ENTITY1 "13c10000.gsc.output" | |
72 | #define PFX_GSC_VIDEODEV_ENTITY2 "13c20000.gsc.output" | |
73 | #else | |
74 | #define PFX_GSC_VIDEODEV_ENTITY "exynos-gsc.%d.output" | |
75 | #endif | |
76 | #define PFX_GSC_CAPTURE_ENTITY "13c20000.gsc.capture" | |
77 | #define PFX_GSC_SUBDEV_ENTITY "exynos-gsc-sd.%d" | |
78 | #define PFX_SUB_DEV "/dev/v4l-subdev%d" | |
79 | #define GSC_WB_SD_NAME "gsc-wb-sd" | |
80 | #define DEX_WB_SD_NAME "dex-wb-sd" | |
81 | #define GSC_VD_PAD_SOURCE 0 | |
82 | #define GSC_SD_PAD_SINK 0 | |
83 | #define GSC_SD_PAD_SOURCE 1 | |
84 | #define GSC_OUT_PAD_SINK 0 | |
85 | #define WB_PATH_FORMAT 0x100D; | |
86 | ||
87 | #define GSC_MIN_SRC_W_SIZE (64) | |
88 | #define GSC_MIN_SRC_H_SIZE (32) | |
89 | #define GSC_MIN_DST_W_SIZE (32) | |
90 | #define GSC_MIN_DST_H_SIZE (16) | |
91 | ||
92 | #define MAX_GSC_WAITING_TIME_FOR_TRYLOCK (16000) // 16msec | |
93 | #define GSC_WAITING_TIME_FOR_TRYLOCK (8000) // 8msec | |
94 | ||
95 | typedef struct GscalerInfo { | |
96 | unsigned int width; | |
97 | unsigned int height; | |
98 | unsigned int crop_left; | |
99 | unsigned int crop_top; | |
100 | unsigned int crop_width; | |
101 | unsigned int crop_height; | |
102 | unsigned int v4l2_colorformat; | |
103 | unsigned int mode_drm; | |
104 | unsigned int cacheable; | |
105 | int rotation; | |
106 | int flip_horizontal; | |
107 | int flip_vertical; | |
108 | int qbuf_cnt; | |
109 | int acquireFenceFd; | |
110 | int releaseFenceFd; | |
111 | bool stream_on; | |
112 | bool dirty; | |
113 | struct v4l2_format format; | |
114 | struct v4l2_crop crop; | |
115 | struct Buffer_Info { | |
116 | enum v4l2_memory mem_type; | |
117 | enum v4l2_buf_type buf_type; | |
118 | void *addr[NUM_OF_GSC_PLANES]; | |
119 | struct v4l2_plane planes[NUM_OF_GSC_PLANES]; | |
120 | bool buffer_queued; | |
121 | struct v4l2_buffer buffer; | |
122 | int buf_idx; | |
123 | }buf; | |
124 | }GscInfo; | |
125 | ||
126 | struct MediaDevice { | |
127 | struct media_device *media0; | |
128 | struct media_device *media1; | |
129 | struct media_entity *gsc_sd_entity; | |
130 | struct media_entity *gsc_vd_entity; | |
131 | struct media_entity *sink_sd_entity; | |
132 | }; | |
133 | ||
134 | class CGscaler : public LibMpp { | |
135 | public: | |
136 | GscInfo src_info; | |
137 | GscInfo dst_info; | |
138 | exynos_mpp_img src_img; | |
139 | exynos_mpp_img dst_img; | |
140 | MediaDevice mdev; | |
141 | int out_mode; | |
142 | int gsc_id; | |
143 | bool allow_drm; | |
144 | bool protection_enabled; | |
145 | int gsc_fd; | |
146 | int mode; | |
147 | unsigned int eq_auto; /* 0: user, 1: auto */ | |
148 | unsigned int range_full; /* 0: narrow, 1: full */ | |
149 | unsigned int v4l2_colorspace; /* 1: 601, 3: 709, see csc.h or videodev2.h */ | |
150 | void *scaler; | |
151 | ||
152 | void __InitMembers(int __mode, int __out_mode, int __gsc_id,int __allow_drm) | |
153 | { | |
154 | memset(&mdev, 0, sizeof(mdev)); | |
155 | scaler = NULL; | |
156 | ||
157 | mode = __mode; | |
158 | out_mode = __out_mode; | |
159 | gsc_id = __gsc_id; | |
160 | allow_drm = __allow_drm; | |
161 | } | |
162 | ||
163 | CGscaler(int __mode) | |
164 | { | |
165 | memset(&src_info, 0, sizeof(GscInfo)); | |
166 | memset(&dst_info, 0, sizeof(GscInfo)); | |
167 | memset(&src_img, 0, sizeof(exynos_mpp_img)); | |
168 | memset(&dst_img, 0, sizeof(exynos_mpp_img)); | |
169 | mode = __mode; | |
170 | protection_enabled = false; | |
171 | gsc_fd = -1; | |
172 | src_info.buf.buf_type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | |
173 | dst_info.buf.buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | |
174 | eq_auto = 0; /* user mode */ | |
175 | range_full = 0; /* narrow */ | |
176 | v4l2_colorspace = 1; /* SMPTE170M (601) */ | |
177 | __InitMembers(__mode, 0, 0, 0); | |
178 | } | |
179 | CGscaler(int __mode, int __out_mode, int __gsc_id, int __allow_drm) | |
180 | { | |
181 | memset(&src_info, 0, sizeof(GscInfo)); | |
182 | memset(&dst_info, 0, sizeof(GscInfo)); | |
183 | memset(&src_img, 0, sizeof(exynos_mpp_img)); | |
184 | memset(&dst_img, 0, sizeof(exynos_mpp_img)); | |
185 | protection_enabled = false; | |
186 | gsc_fd = -1; | |
187 | src_info.buf.buf_type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | |
188 | dst_info.buf.buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | |
189 | eq_auto = 0; /* user mode */ | |
190 | range_full = 0; /* narrow */ | |
191 | v4l2_colorspace = 1; /* SMPTE170M (601) */ | |
192 | __InitMembers(__mode, __out_mode, __gsc_id, __allow_drm); | |
193 | } | |
194 | ||
195 | ~CGscaler() | |
196 | { | |
197 | ALOGD("%s", __func__); | |
198 | } | |
199 | virtual int ConfigMpp(void *handle, exynos_mpp_img *src, | |
200 | exynos_mpp_img *dst); | |
201 | virtual int ConfigBlendMpp(void *handle, exynos_mpp_img *src, | |
202 | exynos_mpp_img *dst, | |
203 | SrcBlendInfo *srcblendinfo); | |
204 | virtual int RunMpp(void *handle, exynos_mpp_img *src, | |
205 | exynos_mpp_img *dst); | |
206 | virtual int StopMpp(void *handle); | |
207 | virtual void DestroyMpp(void *handle); | |
208 | virtual int SetCSCProperty(void *handle, unsigned int eqAuto, | |
209 | unsigned int fullRange, unsigned int colorspace); | |
210 | virtual int FreeMpp(void *handle); | |
211 | virtual int SetInputCrop(void *handle, exynos_mpp_img *src, exynos_mpp_img *dst); | |
212 | bool m_gsc_find_and_create(void *handle); | |
213 | bool m_gsc_out_destroy(void *handle); | |
214 | bool m_gsc_cap_destroy(void *handle); | |
215 | bool m_gsc_m2m_destroy(void *handle); | |
216 | int m_gsc_m2m_create(int dev); | |
217 | int m_gsc_output_create(void *handle, int dev_num, int out_mode); | |
218 | int m_gsc_capture_create(void *handle, int dev_num, int out_mode); | |
219 | int m_gsc_out_stop(void *handle); | |
220 | int m_gsc_cap_stop(void *handle); | |
221 | int m_gsc_m2m_stop(void *handle); | |
222 | int m_gsc_m2m_run_core(void *handle); | |
223 | int m_gsc_m2m_wait_frame_done(void *handle); | |
224 | int m_gsc_m2m_config(void *handle, | |
225 | exynos_mpp_img *src_img, exynos_mpp_img *dst_img); | |
226 | int m_gsc_out_config(void *handle, | |
227 | exynos_mpp_img *src_img, exynos_mpp_img *dst_img); | |
228 | int m_gsc_cap_config(void *handle, | |
229 | exynos_mpp_img *src_img, exynos_mpp_img *dst_img); | |
230 | int m_gsc_m2m_run(void *handle, | |
231 | exynos_mpp_img *src_img, exynos_mpp_img *dst_img); | |
232 | int m_gsc_out_run(void *handle, exynos_mpp_img *src_img); | |
233 | int m_gsc_cap_run(void *handle, exynos_mpp_img *dst_img); | |
234 | static bool m_gsc_set_format(int fd, GscInfo *info); | |
235 | static unsigned int m_gsc_get_plane_count(int v4l_pixel_format); | |
236 | static bool m_gsc_set_addr(int fd, GscInfo *info); | |
237 | static unsigned int m_gsc_get_plane_size( | |
238 | unsigned int *plane_size, unsigned int width, | |
239 | unsigned int height, int v4l_pixel_format); | |
240 | static bool m_gsc_check_src_size(unsigned int *w, unsigned int *h, | |
241 | unsigned int *crop_x, unsigned int *crop_y, | |
242 | unsigned int *crop_w, unsigned int *crop_h, | |
243 | int v4l2_colorformat, bool rotation); | |
244 | static bool m_gsc_check_dst_size(unsigned int *w, unsigned int *h, | |
245 | unsigned int *crop_x, unsigned int *crop_y, | |
246 | unsigned int *crop_w, unsigned int *crop_h, | |
247 | int v4l2_colorformat, int rotation); | |
248 | static int m_gsc_multiple_of_n(int number, int N); | |
249 | static void rotateValueHAL2GSC(unsigned int transform, | |
250 | unsigned int *rotate, unsigned int *hflip, unsigned int *vflip); | |
251 | static bool tmp_get_plane_size(int V4L2_PIX, | |
252 | unsigned int * size, unsigned int width, unsigned int height, int src_planes); | |
253 | }; | |
254 | ||
255 | inline CGscaler *GetGscaler(void* handle) | |
256 | { | |
257 | if (handle == NULL) { | |
258 | ALOGE("%s::NULL Scaler handle", __func__); | |
259 | return NULL; | |
260 | } | |
261 | ||
262 | CGscaler *gsc = reinterpret_cast<CGscaler *>(handle); | |
263 | ||
264 | return gsc; | |
265 | } | |
266 | #ifdef __cplusplus | |
267 | } | |
268 | #endif | |
269 | ||
270 | #endif |