Add option pointer to vo struct
[mplayer.git] / libvo / video_out.c
blob65e83e299acc3bf0591b5cb0afed4d4a0263bc49
2 /* this file contains libvo's common functions, variables used by
3 many/all drivers. */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
9 #include <unistd.h>
10 //#include <sys/mman.h>
12 #include "config.h"
13 #include "options.h"
14 #include "video_out.h"
15 #include "aspect.h"
16 #include "geometry.h"
18 #include "mp_msg.h"
19 #include "help_mp.h"
21 #include "osdep/shmem.h"
23 //int vo_flags=0;
25 int xinerama_screen = -1;
26 int xinerama_x;
27 int xinerama_y;
29 // currect resolution/bpp on screen: (should be autodetected by vo_init())
30 int vo_depthonscreen=0;
31 int vo_screenwidth=0;
32 int vo_screenheight=0;
34 int vo_config_count=0;
36 // requested resolution/bpp: (-x -y -bpp options)
37 int vo_dx=0;
38 int vo_dy=0;
39 int vo_dwidth=0;
40 int vo_dheight=0;
41 int vo_dbpp=0;
43 int vo_nomouse_input = 0;
44 int vo_grabpointer = 1;
45 int vo_doublebuffering = 1;
46 int vo_vsync = 0;
47 int vo_fs = 0;
48 int vo_fsmode = 0;
49 float vo_panscan = 0.0f;
50 int vo_ontop = 0;
51 int vo_adapter_num=0;
52 int vo_refresh_rate=0;
53 int vo_keepaspect=1;
54 int vo_rootwin=0;
55 int vo_border=1;
56 int WinID = -1;
58 int vo_pts=0; // for hw decoding
59 float vo_fps=0;
61 char *vo_subdevice = NULL;
62 int vo_directrendering=0;
64 int vo_colorkey = 0x0000ff00; // default colorkey is green
65 // (0xff000000 means that colorkey has been disabled)
68 // Externally visible list of all vo drivers
70 extern struct vo_driver video_out_mga;
71 extern struct vo_driver video_out_xmga;
72 extern struct vo_driver video_out_x11;
73 extern struct vo_driver video_out_xover;
74 extern struct vo_driver video_out_xvmc;
75 extern struct vo_driver video_out_xv;
76 extern struct vo_driver video_out_gl;
77 extern struct vo_driver video_out_gl2;
78 extern struct vo_driver video_out_dga;
79 extern struct vo_driver video_out_sdl;
80 extern struct vo_driver video_out_3dfx;
81 extern struct vo_driver video_out_tdfxfb;
82 extern struct vo_driver video_out_s3fb;
83 extern struct vo_driver video_out_null;
84 extern struct vo_driver video_out_zr;
85 extern struct vo_driver video_out_zr2;
86 extern struct vo_driver video_out_bl;
87 extern struct vo_driver video_out_fbdev;
88 extern struct vo_driver video_out_fbdev2;
89 extern struct vo_driver video_out_svga;
90 extern struct vo_driver video_out_png;
91 extern struct vo_driver video_out_ggi;
92 extern struct vo_driver video_out_aa;
93 extern struct vo_driver video_out_caca;
94 extern struct vo_driver video_out_mpegpes;
95 extern struct vo_driver video_out_yuv4mpeg;
96 extern struct vo_driver video_out_directx;
97 extern struct vo_driver video_out_dxr2;
98 extern struct vo_driver video_out_dxr3;
99 extern struct vo_driver video_out_ivtv;
100 extern struct vo_driver video_out_v4l2;
101 extern struct vo_driver video_out_jpeg;
102 extern struct vo_driver video_out_gif89a;
103 extern struct vo_driver video_out_vesa;
104 extern struct vo_driver video_out_directfb;
105 extern struct vo_driver video_out_dfbmga;
106 extern struct vo_driver video_out_xvidix;
107 extern struct vo_driver video_out_winvidix;
108 extern struct vo_driver video_out_cvidix;
109 extern struct vo_driver video_out_tdfx_vid;
110 extern struct vo_driver video_out_xvr100;
111 extern struct vo_driver video_out_tga;
112 extern struct vo_driver video_out_macosx;
113 extern struct vo_driver video_out_quartz;
114 extern struct vo_driver video_out_pnm;
115 extern struct vo_driver video_out_md5sum;
117 const struct vo_driver *video_out_drivers[] =
119 #ifdef HAVE_XVR100
120 &video_out_xvr100,
121 #endif
122 #ifdef HAVE_TDFX_VID
123 &video_out_tdfx_vid,
124 #endif
125 #ifdef HAVE_DIRECTX
126 &video_out_directx,
127 #endif
128 #ifdef HAVE_COREVIDEO
129 &video_out_macosx,
130 #endif
131 #ifdef HAVE_QUARTZ
132 &video_out_quartz,
133 #endif
134 #ifdef HAVE_XMGA
135 &video_out_xmga,
136 #endif
137 #ifdef HAVE_MGA
138 &video_out_mga,
139 #endif
140 #ifdef HAVE_TDFXFB
141 &video_out_tdfxfb,
142 #endif
143 #ifdef HAVE_S3FB
144 &video_out_s3fb,
145 #endif
146 #ifdef HAVE_3DFX
147 &video_out_3dfx,
148 #endif
149 #ifdef HAVE_XV
150 &video_out_xv,
151 #endif
152 #ifdef HAVE_X11
153 &video_out_x11,
154 &video_out_xover,
155 #endif
156 #ifdef HAVE_GL
157 &video_out_gl,
158 &video_out_gl2,
159 #endif
160 #ifdef HAVE_DGA
161 &video_out_dga,
162 #endif
163 #ifdef HAVE_SDL
164 &video_out_sdl,
165 #endif
166 #ifdef HAVE_GGI
167 &video_out_ggi,
168 #endif
169 #ifdef HAVE_FBDEV
170 &video_out_fbdev,
171 &video_out_fbdev2,
172 #endif
173 #ifdef HAVE_SVGALIB
174 &video_out_svga,
175 #endif
176 #ifdef HAVE_AA
177 &video_out_aa,
178 #endif
179 #ifdef HAVE_CACA
180 &video_out_caca,
181 #endif
182 #ifdef HAVE_DXR2
183 &video_out_dxr2,
184 #endif
185 #ifdef HAVE_DXR3
186 &video_out_dxr3,
187 #endif
188 #ifdef HAVE_IVTV
189 &video_out_ivtv,
190 #endif
191 #ifdef HAVE_V4L2_DECODER
192 &video_out_v4l2,
193 #endif
194 #ifdef HAVE_ZR
195 &video_out_zr,
196 &video_out_zr2,
197 #endif
198 #ifdef HAVE_BL
199 &video_out_bl,
200 #endif
201 #ifdef HAVE_VESA
202 &video_out_vesa,
203 #endif
204 #ifdef HAVE_DIRECTFB
205 &video_out_directfb,
206 #endif
207 #ifdef HAVE_DFBMGA
208 &video_out_dfbmga,
209 #endif
210 #ifdef CONFIG_VIDIX
211 #ifdef HAVE_X11
212 &video_out_xvidix,
213 #endif
214 #ifdef WIN32
215 &video_out_winvidix,
216 #endif
217 &video_out_cvidix,
218 #endif
219 &video_out_null,
220 // should not be auto-selected
221 #ifdef HAVE_XVMC
222 &video_out_xvmc,
223 #endif
224 &video_out_mpegpes,
225 &video_out_yuv4mpeg,
226 #ifdef HAVE_PNG
227 &video_out_png,
228 #endif
229 #ifdef HAVE_JPEG
230 &video_out_jpeg,
231 #endif
232 #ifdef HAVE_GIF
233 &video_out_gif89a,
234 #endif
235 #ifdef HAVE_TGA
236 &video_out_tga,
237 #endif
238 #ifdef HAVE_PNM
239 &video_out_pnm,
240 #endif
241 #ifdef HAVE_MD5SUM
242 &video_out_md5sum,
243 #endif
244 NULL
248 static int vo_preinit(struct vo *vo, const char *arg)
250 return vo->driver->preinit(vo, arg);
253 int vo_control(struct vo *vo, uint32_t request, void *data)
255 return vo->driver->control(vo, request, data);
258 int vo_draw_frame(struct vo *vo, uint8_t *src[])
260 return vo->driver->draw_frame(vo, src);
263 int vo_draw_slice(struct vo *vo, uint8_t *src[], int stride[], int w, int h, int x, int y)
265 return vo->driver->draw_slice(vo, src, stride, w, h, x, y);
268 void vo_draw_osd(struct vo *vo)
270 vo->driver->draw_osd(vo);
273 void vo_flip_page(struct vo *vo)
275 vo->driver->flip_page(vo);
278 void vo_check_events(struct vo *vo)
280 vo->driver->check_events(vo);
283 void vo_destroy(struct vo *vo)
285 vo->driver->uninit(vo);
286 free(vo);
289 void list_video_out(void)
291 int i = 0;
292 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableVideoOutputDrivers);
293 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_OUTPUTS\n");
294 while (video_out_drivers[i]) {
295 const vo_info_t *info = video_out_drivers[i++]->info;
296 mp_msg(MSGT_GLOBAL, MSGL_INFO,"\t%s\t%s\n", info->short_name, info->name);
298 mp_msg(MSGT_GLOBAL, MSGL_INFO,"\n");
301 struct vo *init_best_video_out(struct MPOpts *opts)
303 char **vo_list = opts->video_driver_list;
304 int i;
305 struct vo *vo = malloc(sizeof *vo);
306 // first try the preferred drivers, with their optional subdevice param:
307 if (vo_list && vo_list[0])
308 while (vo_list[0][0]) {
309 char *name = strdup(vo_list[0]);
310 vo_subdevice = strchr(name,':');
311 if (!strcmp(name, "pgm"))
312 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_VO_PGM_HasBeenReplaced);
313 if (!strcmp(name, "md5"))
314 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_VO_MD5_HasBeenReplaced);
315 if (vo_subdevice) {
316 vo_subdevice[0] = 0;
317 ++vo_subdevice;
319 for (i = 0; video_out_drivers[i]; i++) {
320 const struct vo_driver *video_driver = video_out_drivers[i];
321 const vo_info_t *info = video_driver->info;
322 if (!strcmp(info->short_name, name)) {
323 // name matches, try it
324 *vo = (struct vo){.opts = opts};
325 vo->driver = video_driver;
326 if (!vo_preinit(vo, vo_subdevice)) {
327 free(name);
328 return vo; // success!
332 // continue...
333 free(name);
334 ++vo_list;
335 if (!(vo_list[0]))
336 return NULL; // do NOT fallback to others
338 // now try the rest...
339 vo_subdevice = NULL;
340 for (i = 0; video_out_drivers[i]; i++) {
341 const struct vo_driver *video_driver = video_out_drivers[i];
342 *vo = (struct vo){.opts = opts};
343 vo->driver = video_driver;
344 if (!vo_preinit(vo, vo_subdevice))
345 return vo; // success!
347 free(vo);
348 return NULL;
351 int vo_config(struct vo *vo, uint32_t width, uint32_t height,
352 uint32_t d_width, uint32_t d_height, uint32_t flags,
353 char *title, uint32_t format)
355 panscan_init();
356 aspect_save_orig(width, height);
357 aspect_save_prescale(d_width, d_height);
359 if (vo_control(vo, VOCTRL_UPDATE_SCREENINFO, NULL) == VO_TRUE) {
360 aspect(&d_width, &d_height, A_NOZOOM);
361 vo_dx = (int)(vo_screenwidth - d_width) / 2;
362 vo_dy = (int)(vo_screenheight - d_height) / 2;
363 geometry(&vo_dx, &vo_dy, &d_width, &d_height,
364 vo_screenwidth, vo_screenheight);
365 vo_dx += xinerama_x;
366 vo_dy += xinerama_y;
367 vo_dwidth = d_width;
368 vo_dheight = d_height;
371 return vo->driver->config(vo, width, height, d_width, d_height, flags,
372 title, format);
375 #if defined(HAVE_FBDEV)||defined(HAVE_VESA)
376 /* Borrowed from vo_fbdev.c
377 Monitor ranges related functions*/
379 char *monitor_hfreq_str = NULL;
380 char *monitor_vfreq_str = NULL;
381 char *monitor_dotclock_str = NULL;
383 float range_max(range_t *r)
385 float max = 0;
387 for (/* NOTHING */; (r->min != -1 && r->max != -1); r++)
388 if (max < r->max) max = r->max;
389 return max;
393 int in_range(range_t *r, float f)
395 for (/* NOTHING */; (r->min != -1 && r->max != -1); r++)
396 if (f >= r->min && f <= r->max)
397 return 1;
398 return 0;
401 range_t *str2range(char *s)
403 float tmp_min, tmp_max;
404 char *endptr = s; // to start the loop
405 range_t *r = NULL;
406 int i;
408 if (!s)
409 return NULL;
410 for (i = 0; *endptr; i++) {
411 if (*s == ',')
412 goto out_err;
413 if (!(r = (range_t *) realloc(r, sizeof(*r) * (i + 2)))) {
414 mp_msg(MSGT_GLOBAL, MSGL_WARN,"can't realloc 'r'\n");
415 return NULL;
417 tmp_min = strtod(s, &endptr);
418 if (*endptr == 'k' || *endptr == 'K') {
419 tmp_min *= 1000.0;
420 endptr++;
421 } else if (*endptr == 'm' || *endptr == 'M') {
422 tmp_min *= 1000000.0;
423 endptr++;
425 if (*endptr == '-') {
426 tmp_max = strtod(endptr + 1, &endptr);
427 if (*endptr == 'k' || *endptr == 'K') {
428 tmp_max *= 1000.0;
429 endptr++;
430 } else if (*endptr == 'm' || *endptr == 'M') {
431 tmp_max *= 1000000.0;
432 endptr++;
434 if (*endptr != ',' && *endptr)
435 goto out_err;
436 } else if (*endptr == ',' || !*endptr) {
437 tmp_max = tmp_min;
438 } else
439 goto out_err;
440 r[i].min = tmp_min;
441 r[i].max = tmp_max;
442 if (r[i].min < 0 || r[i].max < 0)
443 goto out_err;
444 s = endptr + 1;
446 r[i].min = r[i].max = -1;
447 return r;
448 out_err:
449 if (r)
450 free(r);
451 return NULL;
454 /* Borrowed from vo_fbdev.c END */
455 #endif