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