core: add infrastructure to get screenshots from VOs
[mplayer.git] / libvo / video_out.h
blobfd61d9c1a11b6d11f43c7f348aef7c6cb43ce689
1 /*
2 * Copyright (C) Aaron Holtzman - Aug 1999
3 * Strongly modified, most parts rewritten: A'rpi/ESP-team - 2000-2001
4 * (C) MPlayer developers
6 * This file is part of MPlayer.
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.
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.
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.
23 #ifndef MPLAYER_VIDEO_OUT_H
24 #define MPLAYER_VIDEO_OUT_H
26 #include <inttypes.h>
27 #include <stdbool.h>
29 #include "libmpcodecs/img_format.h"
30 #include "mpcommon.h"
32 #define VO_EVENT_EXPOSE 1
33 #define VO_EVENT_RESIZE 2
34 #define VO_EVENT_KEYPRESS 4
35 #define VO_EVENT_REINIT 8
36 #define VO_EVENT_MOVE 16
38 enum mp_voctrl {
39 /* does the device support the required format */
40 VOCTRL_QUERY_FORMAT = 1,
41 /* signal a device reset seek */
42 VOCTRL_RESET,
43 /* used to switch to fullscreen */
44 VOCTRL_FULLSCREEN,
45 /* signal a device pause */
46 VOCTRL_PAUSE,
47 /* start/resume playback */
48 VOCTRL_RESUME,
49 /* libmpcodecs direct rendering */
50 VOCTRL_GET_IMAGE,
51 VOCTRL_DRAW_IMAGE,
52 VOCTRL_SET_SPU_PALETTE,
53 VOCTRL_GET_PANSCAN,
54 VOCTRL_SET_PANSCAN,
55 VOCTRL_SET_EQUALIZER, // struct voctrl_set_equalizer_args
56 VOCTRL_GET_EQUALIZER, // struct voctrl_get_equalizer_args
57 VOCTRL_DUPLICATE_FRAME,
59 VOCTRL_START_SLICE,
61 // Vo can be used by xover
62 VOCTRL_XOVERLAY_SUPPORT,
63 VOCTRL_XOVERLAY_SET_COLORKEY, // mp_colorkey_t
64 VOCTRL_XOVERLAY_SET_WIN,
66 VOCTRL_REDRAW_OSD,
68 VOCTRL_ONTOP,
69 VOCTRL_ROOTWIN,
70 VOCTRL_BORDER,
71 VOCTRL_DRAW_EOSD,
72 VOCTRL_GET_EOSD_RES, // struct mp_eosd_res
74 VOCTRL_SET_DEINTERLACE,
75 VOCTRL_GET_DEINTERLACE,
77 VOCTRL_UPDATE_SCREENINFO,
79 VOCTRL_SET_YUV_COLORSPACE, // struct mp_csp_details
80 VOCTRL_GET_YUV_COLORSPACE, // struct mp_csp_details
82 VOCTRL_SCREENSHOT, // struct voctrl_screenshot_args
85 // VOCTRL_SET_EQUALIZER
86 struct voctrl_set_equalizer_args {
87 const char *name;
88 int value;
91 // VOCTRL_GET_EQUALIZER
92 struct voctrl_get_equalizer_args {
93 const char *name;
94 int *valueptr;
97 // VOCTRL_XOVERLAY_SET_COLORKEY
98 typedef struct {
99 uint32_t x11; // The raw x11 color
100 uint16_t r,g,b;
101 } mp_colorkey_t;
103 // VOCTRL_GET_EOSD_RES
104 typedef struct mp_eosd_res {
105 int w, h; // screen dimensions, including black borders
106 int mt, mb, ml, mr; // borders (top, bottom, left, right)
107 } mp_eosd_res_t;
109 // VOCTRL_SCREENSHOT
110 struct voctrl_screenshot_args {
111 // Will be set to a newly allocated image, that contains the screenshot.
112 // The caller has to free the pointer with free_mp_image().
113 // It is not specified whether the image data is a copy or references the
114 // image data directly.
115 // Is never NULL. (Failure has to be indicated by returning VO_FALSE.)
116 struct mp_image *out_image;
119 typedef struct {
120 int x,y;
121 int w,h;
122 } mp_win_t;
124 #define VO_TRUE 1
125 #define VO_FALSE 0
126 #define VO_ERROR -1
127 #define VO_NOTAVAIL -2
128 #define VO_NOTIMPL -3
130 #define VOFLAG_FULLSCREEN 0x01
131 #define VOFLAG_MODESWITCHING 0x02
132 #define VOFLAG_SWSCALE 0x04
133 #define VOFLAG_FLIPPING 0x08
134 #define VOFLAG_HIDDEN 0x10 //< Use to create a hidden window
135 #define VOFLAG_STEREO 0x20 //< Use to create a stereo-capable window
136 #define VOFLAG_XOVERLAY_SUB_VO 0x10000
138 typedef struct vo_info_s
140 /* driver name ("Matrox Millennium G200/G400" */
141 const char *name;
142 /* short name (for config strings) ("mga") */
143 const char *short_name;
144 /* author ("Aaron Holtzman <aholtzma@ess.engr.uvic.ca>") */
145 const char *author;
146 /* any additional comments */
147 const char *comment;
148 } vo_info_t;
150 struct vo;
151 struct osd_state;
152 struct mp_image;
154 struct vo_driver {
155 // Driver uses new API
156 bool is_new;
157 // Driver buffers or adds (deinterlace) frames and will keep track
158 // of pts values itself
159 bool buffer_frames;
161 // This is set if the driver is not new and contains pointers to
162 // old-API functions to be used instead of the ones below.
163 struct vo_old_functions *old_functions;
165 const vo_info_t *info;
167 * Preinitializes driver (real INITIALIZATION)
168 * arg - currently it's vo_subdevice
169 * returns: zero on successful initialization, non-zero on error.
171 int (*preinit)(struct vo *vo, const char *arg);
173 * Initialize (means CONFIGURE) the display driver.
174 * params:
175 * width,height: image source size
176 * d_width,d_height: size of the requested window size, just a hint
177 * fullscreen: flag, 0=windowd 1=fullscreen, just a hint
178 * title: window title, if available
179 * format: fourcc of pixel format
180 * returns : zero on successful initialization, non-zero on error.
182 int (*config)(struct vo *vo, uint32_t width, uint32_t height,
183 uint32_t d_width, uint32_t d_height, uint32_t fullscreen,
184 char *title, uint32_t format);
187 * Control interface
189 int (*control)(struct vo *vo, uint32_t request, void *data);
191 void (*draw_image)(struct vo *vo, struct mp_image *mpi, double pts);
194 * Get extra frames from the VO, such as those added by VDPAU
195 * deinterlace. Preparing the next such frame if any could be done
196 * automatically by the VO after a previous flip_page(), but having
197 * it as a separate step seems to allow making code more robust.
199 void (*get_buffered_frame)(struct vo *vo, bool eof);
202 * Draw a planar YUV slice to the buffer:
203 * params:
204 * src[3] = source image planes (Y,U,V)
205 * stride[3] = source image planes line widths (in bytes)
206 * w,h = width*height of area to be copied (in Y pixels)
207 * x,y = position at the destination image (in Y pixels)
209 int (*draw_slice)(struct vo *vo, uint8_t *src[], int stride[], int w,
210 int h, int x, int y);
213 * Draws OSD to the screen buffer
215 void (*draw_osd)(struct vo *vo, struct osd_state *osd);
218 * Blit/Flip buffer to the screen. Must be called after each frame!
220 void (*flip_page)(struct vo *vo);
221 void (*flip_page_timed)(struct vo *vo, unsigned int pts_us, int duration);
224 * This func is called after every frames to handle keyboard and
225 * other events. It's called in PAUSE mode too!
227 void (*check_events)(struct vo *vo);
230 * Closes driver. Should restore the original state of the system.
232 void (*uninit)(struct vo *vo);
235 struct vo_old_functions {
236 int (*preinit)(const char *arg);
237 int (*config)(uint32_t width, uint32_t height, uint32_t d_width,
238 uint32_t d_height, uint32_t fullscreen, char *title,
239 uint32_t format);
240 int (*control)(uint32_t request, void *data);
241 int (*draw_frame)(uint8_t *src[]);
242 int (*draw_slice)(uint8_t *src[], int stride[], int w,int h, int x,int y);
243 void (*draw_osd)(void);
244 void (*flip_page)(void);
245 void (*check_events)(void);
246 void (*uninit)(void);
249 struct vo {
250 int config_ok; // Last config call was successful?
251 int config_count; // Total number of successful config calls
253 bool frame_loaded; // Is there a next frame the VO could flip to?
254 double next_pts; // pts value of the next frame if any
255 double next_pts2; // optional pts of frame after that
257 double flip_queue_offset; // queue flip events at most this much in advance
259 const struct vo_driver *driver;
260 void *priv;
261 struct MPOpts *opts;
262 struct vo_x11_state *x11;
263 struct mp_fifo *key_fifo;
264 struct input_ctx *input_ctx;
265 int event_fd; // check_events() should be called when this has input
266 int registered_fd; // set to event_fd when registered in input system
268 // requested position/resolution
269 int dx;
270 int dy;
271 int dwidth;
272 int dheight;
274 int panscan_x;
275 int panscan_y;
276 float panscan_amount;
277 float monitor_aspect;
278 struct aspect_data {
279 int orgw; // real width
280 int orgh; // real height
281 int prew; // prescaled width
282 int preh; // prescaled height
283 int scrw; // horizontal resolution
284 int scrh; // vertical resolution
285 float asp;
286 } aspdat;
289 struct vo *init_best_video_out(struct MPOpts *opts, struct vo_x11_state *x11,
290 struct mp_fifo *key_fifo,
291 struct input_ctx *input_ctx);
292 int vo_config(struct vo *vo, uint32_t width, uint32_t height,
293 uint32_t d_width, uint32_t d_height, uint32_t flags,
294 char *title, uint32_t format);
295 void list_video_out(void);
297 int vo_control(struct vo *vo, uint32_t request, void *data);
298 int vo_draw_image(struct vo *vo, struct mp_image *mpi, double pts);
299 int vo_get_buffered_frame(struct vo *vo, bool eof);
300 void vo_skip_frame(struct vo *vo);
301 int vo_draw_frame(struct vo *vo, uint8_t *src[]);
302 int vo_draw_slice(struct vo *vo, uint8_t *src[], int stride[], int w, int h, int x, int y);
303 void vo_draw_osd(struct vo *vo, struct osd_state *osd);
304 void vo_flip_page(struct vo *vo, unsigned int pts_us, int duration);
305 void vo_check_events(struct vo *vo);
306 void vo_seek_reset(struct vo *vo);
307 void vo_destroy(struct vo *vo);
310 // NULL terminated array of all drivers
311 extern const struct vo_driver *video_out_drivers[];
313 extern int xinerama_screen;
314 extern int xinerama_x;
315 extern int xinerama_y;
317 extern int vo_grabpointer;
318 extern int vo_doublebuffering;
319 extern int vo_directrendering;
320 extern int vo_vsync;
321 extern int vo_fs;
322 extern int vo_fsmode;
323 extern float vo_panscan;
324 extern int vo_adapter_num;
325 extern int vo_refresh_rate;
326 extern int vo_keepaspect;
327 extern int vo_rootwin;
328 extern int vo_border;
330 extern int vo_nomouse_input;
331 extern int enable_mouse_movements;
333 extern int vo_pts;
334 extern float vo_fps;
336 extern char *vo_subdevice;
338 extern int vo_colorkey;
340 extern int64_t WinID;
342 typedef struct {
343 float min;
344 float max;
345 } range_t;
347 float range_max(range_t *r);
348 int in_range(range_t *r, float f);
349 range_t *str2range(char *s);
350 extern char *monitor_hfreq_str;
351 extern char *monitor_vfreq_str;
352 extern char *monitor_dotclock_str;
354 struct mp_keymap {
355 int from;
356 int to;
358 int lookup_keymap_table(const struct mp_keymap *map, int key);
359 struct vo_rect {
360 int left, right, top, bottom, width, height;
362 void calc_src_dst_rects(struct vo *vo, int src_width, int src_height,
363 struct vo_rect *src, struct vo_rect *dst,
364 struct vo_rect *borders, const struct vo_rect *crop);
365 struct input_ctx;
366 void vo_mouse_movement(struct vo *vo, int posx, int posy);
368 static inline int aspect_scaling(void)
370 return vo_keepaspect || vo_fs;
373 #endif /* MPLAYER_VIDEO_OUT_H */