Removed build warnings
[platform/adaptation/ap_samsung/libexynos-common.git] / libgscaler / libgscaler_obj.h
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 #include <sys/types.h>
25 #include <sys/ioctl.h>
26 #include <linux/videodev2.h>
27 #include <fcntl.h>
28 #include <stdbool.h>
29 #include <string.h>
30 #include <unistd.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <time.h>
34 #include <linux/videodev2_exynos_media.h>
35 #include <exynos_gscaler.h>
36
37 #include <exynos_format.h>
38 #include <exynos_v4l2.h>
39
40 #include <exynos_scaler.h>
41 #include <exynos_log.h>
42
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)
53
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)
59
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"
64 #if defined(USES_DT)
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"
68 #else
69 #define PFX_GSC_VIDEODEV_ENTITY   "exynos-gsc.%d.output"
70 #endif
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;
81
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)
86
87 #define MAX_GSC_WAITING_TIME_FOR_TRYLOCK (16000) // 16msec
88 #define GSC_WAITING_TIME_FOR_TRYLOCK      (8000) //  8msec
89
90 typedef struct GscalerInfo {
91     unsigned int width;
92     unsigned int height;
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;
100     int rotation;
101     int flip_horizontal;
102     int flip_vertical;
103     int qbuf_cnt;
104     int acquireFenceFd;
105     int releaseFenceFd;
106     bool stream_on;
107     bool dirty;
108     struct v4l2_format format;
109     struct v4l2_crop crop;
110     struct Buffer_Info {
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];
115         bool buffer_queued;
116         struct v4l2_buffer buffer;
117         int buf_idx;
118     }buf;
119 }GscInfo;
120
121 struct MediaDevice {
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;
127 };
128
129 class CGscaler {
130 public:
131     GscInfo src_info;
132     GscInfo dst_info;
133     exynos_mpp_img src_img;
134     exynos_mpp_img dst_img;
135     MediaDevice mdev;
136     int out_mode;
137     int gsc_id;
138     bool allow_drm;
139     bool protection_enabled;
140     int gsc_fd;
141     int mode;
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 */
145     void *scaler;
146
147     void __InitMembers(int __mode, int __out_mode, int __gsc_id,int __allow_drm)
148     {
149         memset(&mdev, 0, sizeof(mdev));
150         scaler = NULL;
151
152         mode = __mode;
153         out_mode = __out_mode;
154         gsc_id = __gsc_id;
155         allow_drm = __allow_drm;
156     }
157
158     CGscaler(int __mode)
159     {
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));
164         mode = __mode;
165         protection_enabled = false;
166         gsc_fd = -1;
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);
173     }
174     CGscaler(int __mode, int __out_mode, int __gsc_id, int __allow_drm)
175     {
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;
181         gsc_fd = -1;
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);
188     }
189
190     virtual ~CGscaler()
191     {
192         ALOGD("%s", __func__);
193     }
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,
197                                               exynos_mpp_img *dst,
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);
248 };
249
250 inline CGscaler *GetGscaler(void* handle)
251 {
252     if (handle == NULL) {
253         ALOGE("%s::NULL Scaler handle", __func__);
254         return NULL;
255     }
256
257     CGscaler *gsc = reinterpret_cast<CGscaler *>(handle);
258
259     return gsc;
260 }
261 #ifdef __cplusplus
262 }
263 #endif
264
265 #endif