video: default to colorspace/range from libavcodec
[mplayer.git] / libvo / video_out.h
blob10a3891b7b9df5f816f4af1691a80f9ede096086
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_NEWFRAME,
67 VOCTRL_SKIPFRAME,
68 VOCTRL_REDRAW_FRAME,
70 VOCTRL_ONTOP,
71 VOCTRL_ROOTWIN,
72 VOCTRL_BORDER,
73 VOCTRL_DRAW_EOSD,
74 VOCTRL_GET_EOSD_RES, // struct mp_eosd_res
76 VOCTRL_SET_DEINTERLACE,
77 VOCTRL_GET_DEINTERLACE,
79 VOCTRL_UPDATE_SCREENINFO,
81 VOCTRL_SET_YUV_COLORSPACE, // struct mp_csp_details
82 VOCTRL_GET_YUV_COLORSPACE, // struct mp_csp_details
84 VOCTRL_SCREENSHOT, // struct voctrl_screenshot_args
87 // VOCTRL_SET_EQUALIZER
88 struct voctrl_set_equalizer_args {
89 const char *name;
90 int value;
93 // VOCTRL_GET_EQUALIZER
94 struct voctrl_get_equalizer_args {
95 const char *name;
96 int *valueptr;
99 // VOCTRL_XOVERLAY_SET_COLORKEY
100 typedef struct {
101 uint32_t x11; // The raw x11 color
102 uint16_t r,g,b;
103 } mp_colorkey_t;
105 // VOCTRL_GET_EOSD_RES
106 typedef struct mp_eosd_res {
107 int w, h; // screen dimensions, including black borders
108 int mt, mb, ml, mr; // borders (top, bottom, left, right)
109 } mp_eosd_res_t;
111 // VOCTRL_SCREENSHOT
112 struct voctrl_screenshot_args {
113 // 0: Save image of the currently displayed video frame, in original
114 // resolution.
115 // 1: Save full screenshot of the window. Should contain OSD, EOSD, and the
116 // scaled video.
117 // The value of this variable can be ignored if only a single method is
118 // implemented.
119 int full_window;
120 // Will be set to a newly allocated image, that contains the screenshot.
121 // The caller has to free the pointer with free_mp_image().
122 // It is not specified whether the image data is a copy or references the
123 // image data directly.
124 // Is never NULL. (Failure has to be indicated by returning VO_FALSE.)
125 struct mp_image *out_image;
128 typedef struct {
129 int x,y;
130 int w,h;
131 } mp_win_t;
133 #define VO_TRUE 1
134 #define VO_FALSE 0
135 #define VO_ERROR -1
136 #define VO_NOTAVAIL -2
137 #define VO_NOTIMPL -3
139 #define VOFLAG_FULLSCREEN 0x01
140 #define VOFLAG_MODESWITCHING 0x02
141 #define VOFLAG_SWSCALE 0x04
142 #define VOFLAG_FLIPPING 0x08
143 #define VOFLAG_HIDDEN 0x10 //< Use to create a hidden window
144 #define VOFLAG_STEREO 0x20 //< Use to create a stereo-capable window
145 #define VOFLAG_XOVERLAY_SUB_VO 0x10000
147 typedef struct vo_info_s
149 /* driver name ("Matrox Millennium G200/G400" */
150 const char *name;
151 /* short name (for config strings) ("mga") */
152 const char *short_name;
153 /* author ("Aaron Holtzman <aholtzma@ess.engr.uvic.ca>") */
154 const char *author;
155 /* any additional comments */
156 const char *comment;
157 } vo_info_t;
159 struct vo;
160 struct osd_state;
161 struct mp_image;
163 struct vo_driver {
164 // Driver uses new API
165 bool is_new;
166 // Driver buffers or adds (deinterlace) frames and will keep track
167 // of pts values itself
168 bool buffer_frames;
170 // This is set if the driver is not new and contains pointers to
171 // old-API functions to be used instead of the ones below.
172 struct vo_old_functions *old_functions;
174 const vo_info_t *info;
176 * Preinitializes driver (real INITIALIZATION)
177 * arg - currently it's vo_subdevice
178 * returns: zero on successful initialization, non-zero on error.
180 int (*preinit)(struct vo *vo, const char *arg);
182 * Initialize (means CONFIGURE) the display driver.
183 * params:
184 * width,height: image source size
185 * d_width,d_height: size of the requested window size, just a hint
186 * fullscreen: flag, 0=windowd 1=fullscreen, just a hint
187 * title: window title, if available
188 * format: fourcc of pixel format
189 * returns : zero on successful initialization, non-zero on error.
191 int (*config)(struct vo *vo, uint32_t width, uint32_t height,
192 uint32_t d_width, uint32_t d_height, uint32_t fullscreen,
193 uint32_t format);
196 * Control interface
198 int (*control)(struct vo *vo, uint32_t request, void *data);
200 void (*draw_image)(struct vo *vo, struct mp_image *mpi, double pts);
203 * Get extra frames from the VO, such as those added by VDPAU
204 * deinterlace. Preparing the next such frame if any could be done
205 * automatically by the VO after a previous flip_page(), but having
206 * it as a separate step seems to allow making code more robust.
208 void (*get_buffered_frame)(struct vo *vo, bool eof);
211 * Draw a planar YUV slice to the buffer:
212 * params:
213 * src[3] = source image planes (Y,U,V)
214 * stride[3] = source image planes line widths (in bytes)
215 * w,h = width*height of area to be copied (in Y pixels)
216 * x,y = position at the destination image (in Y pixels)
218 int (*draw_slice)(struct vo *vo, uint8_t *src[], int stride[], int w,
219 int h, int x, int y);
222 * Draws OSD to the screen buffer
224 void (*draw_osd)(struct vo *vo, struct osd_state *osd);
227 * Blit/Flip buffer to the screen. Must be called after each frame!
229 void (*flip_page)(struct vo *vo);
230 void (*flip_page_timed)(struct vo *vo, unsigned int pts_us, int duration);
233 * This func is called after every frames to handle keyboard and
234 * other events. It's called in PAUSE mode too!
236 void (*check_events)(struct vo *vo);
239 * Closes driver. Should restore the original state of the system.
241 void (*uninit)(struct vo *vo);
243 // Size of private struct for automatic allocation
244 int privsize;
246 // List of options to parse into priv struct (requires privsize to be set)
247 const struct m_option *options;
250 struct vo_old_functions {
251 int (*preinit)(const char *arg);
252 int (*config)(uint32_t width, uint32_t height, uint32_t d_width,
253 uint32_t d_height, uint32_t fullscreen, char *title,
254 uint32_t format);
255 int (*control)(uint32_t request, void *data);
256 int (*draw_frame)(uint8_t *src[]);
257 int (*draw_slice)(uint8_t *src[], int stride[], int w,int h, int x,int y);
258 void (*draw_osd)(void);
259 void (*flip_page)(void);
260 void (*check_events)(void);
261 void (*uninit)(void);
264 struct vo {
265 int config_ok; // Last config call was successful?
266 int config_count; // Total number of successful config calls
268 bool frame_loaded; // Is there a next frame the VO could flip to?
269 struct mp_image *waiting_mpi;
270 double next_pts; // pts value of the next frame if any
271 double next_pts2; // optional pts of frame after that
272 bool want_redraw; // visible frame wrong (window resize), needs refresh
273 bool redrawing; // between redrawing frame and flipping it
274 bool hasframe; // >= 1 frame has been drawn, so redraw is possible
276 double flip_queue_offset; // queue flip events at most this much in advance
278 const struct vo_driver *driver;
279 void *priv;
280 struct MPOpts *opts;
281 struct vo_x11_state *x11;
282 struct mp_fifo *key_fifo;
283 struct input_ctx *input_ctx;
284 int event_fd; // check_events() should be called when this has input
285 int registered_fd; // set to event_fd when registered in input system
287 // requested position/resolution
288 int dx;
289 int dy;
290 int dwidth;
291 int dheight;
293 int panscan_x;
294 int panscan_y;
295 float panscan_amount;
296 float monitor_aspect;
297 struct aspect_data {
298 int orgw; // real width
299 int orgh; // real height
300 int prew; // prescaled width
301 int preh; // prescaled height
302 int scrw; // horizontal resolution
303 int scrh; // vertical resolution
304 float asp;
305 } aspdat;
308 struct vo *init_best_video_out(struct MPOpts *opts, struct vo_x11_state *x11,
309 struct mp_fifo *key_fifo,
310 struct input_ctx *input_ctx);
311 int vo_config(struct vo *vo, uint32_t width, uint32_t height,
312 uint32_t d_width, uint32_t d_height, uint32_t flags,
313 uint32_t format);
314 void list_video_out(void);
316 int vo_control(struct vo *vo, uint32_t request, void *data);
317 int vo_draw_image(struct vo *vo, struct mp_image *mpi, double pts);
318 int vo_redraw_frame(struct vo *vo);
319 int vo_get_buffered_frame(struct vo *vo, bool eof);
320 void vo_skip_frame(struct vo *vo);
321 int vo_draw_frame(struct vo *vo, uint8_t *src[]);
322 int vo_draw_slice(struct vo *vo, uint8_t *src[], int stride[], int w, int h, int x, int y);
323 void vo_new_frame_imminent(struct vo *vo);
324 void vo_draw_osd(struct vo *vo, struct osd_state *osd);
325 void vo_flip_page(struct vo *vo, unsigned int pts_us, int duration);
326 void vo_check_events(struct vo *vo);
327 void vo_seek_reset(struct vo *vo);
328 void vo_destroy(struct vo *vo);
330 const char *vo_get_window_title(struct vo *vo);
332 // NULL terminated array of all drivers
333 extern const struct vo_driver *video_out_drivers[];
335 extern int xinerama_screen;
336 extern int xinerama_x;
337 extern int xinerama_y;
339 extern int vo_grabpointer;
340 extern int vo_doublebuffering;
341 extern int vo_directrendering;
342 extern int vo_vsync;
343 extern int vo_fs;
344 extern int vo_fsmode;
345 extern float vo_panscan;
346 extern int vo_adapter_num;
347 extern int vo_refresh_rate;
348 extern int vo_keepaspect;
349 extern int vo_rootwin;
350 extern int vo_border;
352 extern int vo_nomouse_input;
353 extern int enable_mouse_movements;
355 extern int vo_pts;
356 extern float vo_fps;
358 extern char *vo_subdevice;
360 extern int vo_colorkey;
362 extern int64_t WinID;
364 typedef struct {
365 float min;
366 float max;
367 } range_t;
369 float range_max(range_t *r);
370 int in_range(range_t *r, float f);
371 range_t *str2range(char *s);
372 extern char *monitor_hfreq_str;
373 extern char *monitor_vfreq_str;
374 extern char *monitor_dotclock_str;
376 struct mp_keymap {
377 int from;
378 int to;
380 int lookup_keymap_table(const struct mp_keymap *map, int key);
381 struct vo_rect {
382 int left, right, top, bottom, width, height;
384 void calc_src_dst_rects(struct vo *vo, int src_width, int src_height,
385 struct vo_rect *src, struct vo_rect *dst,
386 struct vo_rect *borders, const struct vo_rect *crop);
387 void vo_mouse_movement(struct vo *vo, int posx, int posy);
389 static inline int aspect_scaling(void)
391 return vo_keepaspect || vo_fs;
394 #endif /* MPLAYER_VIDEO_OUT_H */