1 /*
2  * Copyright (C) Aaron Holtzman - Aug 1999
3  * Strongly modified, most parts rewritten: A'rpi/ESP-team - 2000-2001
4  * (C) MPlayer developers
5  *
6  * This file is part of MPlayer.
7  *
8  * MPlayer is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * MPlayer is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with MPlayer; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #ifndef MPLAYER_VIDEO_OUT_H
24 #define MPLAYER_VIDEO_OUT_H
25 
26 #include <inttypes.h>
27 #include <stdarg.h>
28 
29 //#include "sub/font_load.h"
30 #include "libmpcodecs/img_format.h"
31 //#include "vidix/vidix.h"
32 
33 
34 #define ROTATE(t, x, y) do { \
35   t rot_tmp = x; \
36   x = y; \
37   y = -rot_tmp; \
38 } while(0)
39 
40 #define VO_EVENT_EXPOSE 1
41 #define VO_EVENT_RESIZE 2
42 #define VO_EVENT_KEYPRESS 4
43 #define VO_EVENT_REINIT 8
44 #define VO_EVENT_MOVE 16
45 #define VO_EVENT_MOUSE 32
46 
47 /* Obsolete: VOCTRL_QUERY_VAA 1 */
48 /* does the device support the required format */
49 #define VOCTRL_QUERY_FORMAT 2
50 /* signal a device reset seek */
51 #define VOCTRL_RESET 3
52 /* true if vo driver can use GUI created windows */
53 #define VOCTRL_GUISUPPORT 4
54 /* used to switch to fullscreen */
55 #define VOCTRL_FULLSCREEN 5
56 /* signal a device pause */
57 #define VOCTRL_PAUSE 7
58 /* start/resume playback */
59 #define VOCTRL_RESUME 8
60 /* libmpcodecs direct rendering: */
61 #define VOCTRL_GET_IMAGE 9
62 #define VOCTRL_DRAW_IMAGE 13
63 #define VOCTRL_SET_SPU_PALETTE 14
64 /* decoding ahead: */
65 #define VOCTRL_GET_NUM_FRAMES 10
66 #define VOCTRL_GET_FRAME_NUM  11
67 #define VOCTRL_SET_FRAME_NUM  12
68 #define VOCTRL_GET_PANSCAN 15
69 #define VOCTRL_SET_PANSCAN 16
70 /* equalizer controls */
71 #define VOCTRL_SET_EQUALIZER 17
72 #define VOCTRL_GET_EQUALIZER 18
73 /* Frame duplication */
74 #define VOCTRL_DUPLICATE_FRAME 20
75 // ... 21
76 #define VOCTRL_START_SLICE 21
77 
78 #define VOCTRL_ONTOP 25
79 #define VOCTRL_ROOTWIN 26
80 #define VOCTRL_BORDER 27
81 #define VOCTRL_DRAW_EOSD 28
82 #define VOCTRL_GET_EOSD_RES 29
83 
84 #define VOCTRL_SET_DEINTERLACE 30
85 #define VOCTRL_GET_DEINTERLACE 31
86 
87 #define VOCTRL_UPDATE_SCREENINFO 32
88 
89 // Vo can be used by xover
90 #define VOCTRL_XOVERLAY_SUPPORT 22
91 
92 #define VOCTRL_XOVERLAY_SET_COLORKEY 24
93 typedef struct {
94   uint32_t x11; // The raw x11 color
95   uint16_t r,g,b;
96 } mp_colorkey_t;
97 
98 #define VOCTRL_XOVERLAY_SET_WIN 23
99 typedef struct {
100   int x,y;
101   int w,h;
102 } mp_win_t;
103 
104 #define VO_TRUE      1
105 #define VO_FALSE     0
106 #define VO_ERROR    -1
107 #define VO_NOTAVAIL -2
108 #define VO_NOTIMPL  -3
109 
110 #define VOFLAG_FULLSCREEN         0x01
111 #define VOFLAG_MODESWITCHING      0x02
112 #define VOFLAG_SWSCALE            0x04
113 #define VOFLAG_FLIPPING           0x08
114 #define VOFLAG_HIDDEN             0x10  //< Use to create a hidden window
115 #define VOFLAG_STEREO             0x20  //< Use to create a stereo-capable window
116 #define VOFLAG_DEPTH              0x40  //< Request a depth buffer
117 #define VOFLAG_XOVERLAY_SUB_VO 0x10000
118 
119 typedef struct vo_info_s
120 {
121     /* driver name ("Matrox Millennium G200/G400" */
122     const char *name;
123     /* short name (for config strings) ("mga") */
124     const char *short_name;
125     /* author ("Aaron Holtzman <aholtzma@ess.engr.uvic.ca>") */
126     const char *author;
127     /* any additional comments */
128     const char *comment;
129 } vo_info_t;
130 
131 typedef struct vo_functions_s
132 {
133     const vo_info_t *info;
134     /*
135      * Preinitializes driver (real INITIALIZATION)
136      *   arg - currently it's vo_subdevice
137      *   returns: zero on successful initialization, non-zero on error.
138      */
139     int (*preinit)(const char *arg);
140     /*
141      * Initialize (means CONFIGURE) the display driver.
142      * params:
143      *   width,height: image source size
144      *   d_width,d_height: size of the requested window size, just a hint
145      *   fullscreen: flag, 0=windowd 1=fullscreen, just a hint
146      *   title: window title, if available
147      *   format: fourcc of pixel format
148      * returns : zero on successful initialization, non-zero on error.
149      */
150     int (*config)(uint32_t width, uint32_t height, uint32_t d_width,
151                   uint32_t d_height, uint32_t fullscreen, char *title,
152                   uint32_t format);
153 
154     /*
155      * Control interface
156      */
157     int (*control)(uint32_t request, void *data);
158 
159     /*
160      * Display a new RGB/BGR frame of the video to the screen.
161      * params:
162      *   src[0] - pointer to the image
163      */
164     int (*draw_frame)(uint8_t *src[]);
165 
166     /*
167      * Draw a planar YUV slice to the buffer:
168      * params:
169      *   src[3] = source image planes (Y,U,V)
170      *   stride[3] = source image planes line widths (in bytes)
171      *   w,h = width*height of area to be copied (in Y pixels)
172      *   x,y = position at the destination image (in Y pixels)
173      */
174     int (*draw_slice)(uint8_t *src[], int stride[], int w,int h, int x,int y);
175 
176     /*
177      * Draws OSD to the screen buffer
178      */
179     void (*draw_osd)(void);
180 
181     /*
182      * Blit/Flip buffer to the screen. Must be called after each frame!
183      */
184     void (*flip_page)(void);
185 
186     /*
187      * This func is called after every frames to handle keyboard and
188      * other events. It's called in PAUSE mode too!
189      */
190     void (*check_events)(void);
191 
192     /*
193      * Closes driver. Should restore the original state of the system.
194      */
195     void (*uninit)(void);
196 } vo_functions_t;
197 
198 const vo_functions_t* init_best_video_out(char** vo_list);
199 int config_video_out(const vo_functions_t *vo, uint32_t width, uint32_t height,
200                      uint32_t d_width, uint32_t d_height, uint32_t flags,
201                      char *title, uint32_t format);
202 void list_video_out(void);
203 
204 // NULL terminated array of all drivers
205 extern const vo_functions_t* const video_out_drivers[];
206 
207 extern int vo_flags;
208 
209 extern int vo_config_count;
210 
211 extern int xinerama_screen;
212 extern int xinerama_x;
213 extern int xinerama_y;
214 
215 // correct resolution/bpp on screen:  (should be autodetected by vo_init())
216 extern int vo_depthonscreen;
217 extern int vo_screenwidth;
218 extern int vo_screenheight;
219 
220 // requested resolution/bpp:  (-x -y -bpp options)
221 extern int vo_dx;
222 extern int vo_dy;
223 extern int vo_dwidth;
224 extern int vo_dheight;
225 extern int vo_dbpp;
226 
227 extern int vo_grabpointer;
228 extern int vo_doublebuffering;
229 extern int vo_directrendering;
230 extern int vo_vsync;
231 extern int vo_fs;
232 extern int vo_fsmode;
233 extern float vo_panscan;
234 extern float vo_border_pos_x;
235 extern float vo_border_pos_y;
236 extern int vo_fs_border_l;
237 extern int vo_fs_border_r;
238 extern int vo_fs_border_t;
239 extern int vo_fs_border_b;
240 extern int vo_rotate;
241 extern int vo_adapter_num;
242 extern int vo_refresh_rate;
243 extern int vo_keepaspect;
244 extern int vo_rootwin;
245 extern int vo_ontop;
246 extern int vo_border;
247 
248 extern int vo_gamma_gamma;
249 extern int vo_gamma_brightness;
250 extern int vo_gamma_saturation;
251 extern int vo_gamma_contrast;
252 extern int vo_gamma_hue;
253 extern int vo_gamma_red_intensity;
254 extern int vo_gamma_green_intensity;
255 extern int vo_gamma_blue_intensity;
256 
257 extern int vo_nomouse_input;
258 extern int enable_mouse_movements;
259 
260 extern int vo_pts;
261 extern float vo_fps;
262 
263 extern char *vo_subdevice;
264 
265 extern int vo_colorkey;
266 
267 extern char *vo_winname;
268 extern char *vo_wintitle;
269 
270 extern int64_t WinID;
271 
272 typedef struct {
273         float min;
274         float max;
275         } range_t;
276 
277 float range_max(range_t *r);
278 int in_range(range_t *r, float f);
279 range_t *str2range(char *s);
280 extern char *monitor_hfreq_str;
281 extern char *monitor_vfreq_str;
282 extern char *monitor_dotclock_str;
283 
284 struct mp_keymap {
285   int from;
286   int to;
287 };
288 int lookup_keymap_table(const struct mp_keymap *map, int key);
289 struct vo_rect {
290   int left, right, top, bottom, width, height;
291 };
292 void calc_src_dst_rects(int src_width, int src_height, struct vo_rect *src, struct vo_rect *dst,
293                         struct vo_rect *borders, const struct vo_rect *crop);
294 void vo_mouse_movement(int posx, int posy);
295 
pixel_stride(unsigned fmt)296 static inline int pixel_stride(unsigned fmt) {
297     if (IMGFMT_IS_RGB(fmt))
298         return (IMGFMT_RGB_DEPTH(fmt) + 7) / 8;
299     if (IMGFMT_IS_BGR(fmt))
300         return (IMGFMT_BGR_DEPTH(fmt) + 7) / 8;
301     if (fmt == IMGFMT_YUY2 || fmt == IMGFMT_UYVY)
302         return 2;
303     return IMGFMT_IS_YUVP16(fmt) ? 2 : 1;
304 }
305 
aspect_scaling(void)306 static inline int aspect_scaling(void)
307 {
308   return vo_fs || vo_keepaspect;
309 }
310 
apply_border_pos(int full,int part,float pos)311 static inline int apply_border_pos(int full, int part, float pos) {
312   if (pos >= 0.0 && pos <= 1.0) {
313     return pos*(full - part);
314   }
315   if (pos < 0)
316     return pos * part;
317   return full - part + (pos - 1) * part;
318 }
319 
320 #endif /* MPLAYER_VIDEO_OUT_H */
321