2 * Copyright@ Samsung Electronics Co. LTD
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef LIBGSCALER_OBJ_H_
18 #define LIBGSCALER_OBJ_H_
24 #include <sys/types.h>
25 #include <sys/ioctl.h>
26 #include <linux/videodev2.h>
34 #include <linux/videodev2_exynos_media.h>
35 #include <exynos_gscaler.h>
37 #include <exynos_format.h>
38 #include <exynos_v4l2.h>
40 #include <exynos_scaler.h>
41 #include <exynos_log.h>
43 #define NUM_OF_GSC_PLANES (3)
44 #define MAX_BUFFERS_GSCALER_OUT (10)
45 #define MAX_BUFFERS_GSCALER_CAP (1)
46 #define GSCALER_SUBDEV_PAD_SINK (0)
47 #define GSCALER_SUBDEV_PAD_SOURCE (1)
48 #define MIXER_V_SUBDEV_PAD_SINK (0)
49 #define MIXER_V_SUBDEV_PAD_SOURCE (3)
50 #define FIMD_SUBDEV_PAD_SINK (0)
51 #define DECON_TV_WB_PAD (0)
52 #define MAX_BUFFERS (6)
54 #define NUM_OF_GSC_HW (4)
55 #define NODE_NUM_GSC_0 (23)
56 #define NODE_NUM_GSC_1 (26)
57 #define NODE_NUM_GSC_2 (29)
58 #define NODE_NUM_GSC_3 (32)
60 #define PFX_NODE_GSC "/dev/video"
61 #define PFX_NODE_MEDIADEV "/dev/media"
62 #define PFX_MXR_ENTITY "s5p-mixer%d"
63 #define PFX_FIMD_ENTITY "s3c-fb-window%d"
65 #define PFX_GSC_VIDEODEV_ENTITY0 "13c00000.gsc.output"
66 #define PFX_GSC_VIDEODEV_ENTITY1 "13c10000.gsc.output"
67 #define PFX_GSC_VIDEODEV_ENTITY2 "13c20000.gsc.output"
69 #define PFX_GSC_VIDEODEV_ENTITY "exynos-gsc.%d.output"
71 #define PFX_GSC_CAPTURE_ENTITY "13c20000.gsc.capture"
72 #define PFX_GSC_SUBDEV_ENTITY "exynos-gsc-sd.%d"
73 #define PFX_SUB_DEV "/dev/v4l-subdev%d"
74 #define GSC_WB_SD_NAME "gsc-wb-sd"
75 #define DEX_WB_SD_NAME "dex-wb-sd"
76 #define GSC_VD_PAD_SOURCE 0
77 #define GSC_SD_PAD_SINK 0
78 #define GSC_SD_PAD_SOURCE 1
79 #define GSC_OUT_PAD_SINK 0
80 #define WB_PATH_FORMAT 0x100D;
82 #define GSC_MIN_SRC_W_SIZE (64)
83 #define GSC_MIN_SRC_H_SIZE (32)
84 #define GSC_MIN_DST_W_SIZE (32)
85 #define GSC_MIN_DST_H_SIZE (16)
87 #define MAX_GSC_WAITING_TIME_FOR_TRYLOCK (16000) // 16msec
88 #define GSC_WAITING_TIME_FOR_TRYLOCK (8000) // 8msec
90 typedef struct GscalerInfo {
93 unsigned int crop_left;
94 unsigned int crop_top;
95 unsigned int crop_width;
96 unsigned int crop_height;
97 unsigned int v4l2_colorformat;
98 unsigned int mode_drm;
99 unsigned int cacheable;
108 struct v4l2_format format;
109 struct v4l2_crop crop;
111 enum v4l2_memory mem_type;
112 enum v4l2_buf_type buf_type;
113 void *addr[NUM_OF_GSC_PLANES];
114 struct v4l2_plane planes[NUM_OF_GSC_PLANES];
116 struct v4l2_buffer buffer;
122 struct media_device *media0;
123 struct media_device *media1;
124 struct media_entity *gsc_sd_entity;
125 struct media_entity *gsc_vd_entity;
126 struct media_entity *sink_sd_entity;
133 exynos_mpp_img src_img;
134 exynos_mpp_img dst_img;
139 bool protection_enabled;
142 unsigned int eq_auto; /* 0: user, 1: auto */
143 unsigned int range_full; /* 0: narrow, 1: full */
144 unsigned int v4l2_colorspace; /* 1: 601, 3: 709, see csc.h or videodev2.h */
147 void __InitMembers(int __mode, int __out_mode, int __gsc_id,int __allow_drm)
149 memset(&mdev, 0, sizeof(mdev));
153 out_mode = __out_mode;
155 allow_drm = __allow_drm;
160 memset(&src_info, 0, sizeof(GscInfo));
161 memset(&dst_info, 0, sizeof(GscInfo));
162 memset(&src_img, 0, sizeof(exynos_mpp_img));
163 memset(&dst_img, 0, sizeof(exynos_mpp_img));
165 protection_enabled = false;
167 src_info.buf.buf_type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
168 dst_info.buf.buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
169 eq_auto = 0; /* user mode */
170 range_full = 0; /* narrow */
171 v4l2_colorspace = 1; /* SMPTE170M (601) */
172 __InitMembers(__mode, 0, 0, 0);
174 CGscaler(int __mode, int __out_mode, int __gsc_id, int __allow_drm)
176 memset(&src_info, 0, sizeof(GscInfo));
177 memset(&dst_info, 0, sizeof(GscInfo));
178 memset(&src_img, 0, sizeof(exynos_mpp_img));
179 memset(&dst_img, 0, sizeof(exynos_mpp_img));
180 protection_enabled = false;
182 src_info.buf.buf_type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
183 dst_info.buf.buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
184 eq_auto = 0; /* user mode */
185 range_full = 0; /* narrow */
186 v4l2_colorspace = 1; /* SMPTE170M (601) */
187 __InitMembers(__mode, __out_mode, __gsc_id, __allow_drm);
192 ALOGD("%s", __func__);
194 virtual int ConfigMpp(void *handle, exynos_mpp_img *src,
195 exynos_mpp_img *dst);
196 virtual int ConfigBlendMpp(void *handle, exynos_mpp_img *src,
198 SrcBlendInfo *srcblendinfo);
199 virtual int RunMpp(void *handle, exynos_mpp_img *src,
200 exynos_mpp_img *dst);
201 virtual int StopMpp(void *handle);
202 virtual void DestroyMpp(void *handle);
203 virtual int SetCSCProperty(void *handle, unsigned int eqAuto,
204 unsigned int fullRange, unsigned int colorspace);
205 virtual int FreeMpp(void *handle);
206 virtual int SetInputCrop(void *handle, exynos_mpp_img *src, exynos_mpp_img *dst);
207 bool m_gsc_find_and_create(void *handle);
208 bool m_gsc_out_destroy(void *handle);
209 bool m_gsc_cap_destroy(void *handle);
210 bool m_gsc_m2m_destroy(void *handle);
211 int m_gsc_m2m_create(int dev);
212 int m_gsc_output_create(void *handle, int dev_num, int out_mode);
213 int m_gsc_capture_create(void *handle, int dev_num, int out_mode);
214 int m_gsc_out_stop(void *handle);
215 int m_gsc_cap_stop(void *handle);
216 int m_gsc_m2m_stop(void *handle);
217 int m_gsc_m2m_run_core(void *handle);
218 int m_gsc_m2m_wait_frame_done(void *handle);
219 int m_gsc_m2m_config(void *handle,
220 exynos_mpp_img *src_img, exynos_mpp_img *dst_img);
221 int m_gsc_out_config(void *handle,
222 exynos_mpp_img *src_img, exynos_mpp_img *dst_img);
223 int m_gsc_cap_config(void *handle,
224 exynos_mpp_img *src_img, exynos_mpp_img *dst_img);
225 int m_gsc_m2m_run(void *handle,
226 exynos_mpp_img *src_img, exynos_mpp_img *dst_img);
227 int m_gsc_out_run(void *handle, exynos_mpp_img *src_img);
228 int m_gsc_cap_run(void *handle, exynos_mpp_img *dst_img);
229 static bool m_gsc_set_format(int fd, GscInfo *info);
230 static unsigned int m_gsc_get_plane_count(int v4l_pixel_format);
231 static bool m_gsc_set_addr(int fd, GscInfo *info);
232 static unsigned int m_gsc_get_plane_size(
233 unsigned int *plane_size, unsigned int width,
234 unsigned int height, int v4l_pixel_format);
235 static bool m_gsc_check_src_size(unsigned int *w, unsigned int *h,
236 unsigned int *crop_x, unsigned int *crop_y,
237 unsigned int *crop_w, unsigned int *crop_h,
238 int v4l2_colorformat, bool rotation);
239 static bool m_gsc_check_dst_size(unsigned int *w, unsigned int *h,
240 unsigned int *crop_x, unsigned int *crop_y,
241 unsigned int *crop_w, unsigned int *crop_h,
242 int v4l2_colorformat, int rotation);
243 static int m_gsc_multiple_of_n(int number, int N);
244 static void rotateValueHAL2GSC(unsigned int transform,
245 unsigned int *rotate, unsigned int *hflip, unsigned int *vflip);
246 static bool tmp_get_plane_size(int V4L2_PIX,
247 unsigned int * size, unsigned int width, unsigned int height, int src_planes);
250 inline CGscaler *GetGscaler(void* handle)
252 if (handle == NULL) {
253 ALOGE("%s::NULL Scaler handle", __func__);
257 CGscaler *gsc = reinterpret_cast<CGscaler *>(handle);