2 * libvo common functions, variables used by many/all drivers.
4 * This file is part of MPlayer.
6 * MPlayer is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * MPlayer is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 //#include <sys/mman.h>
31 #include "video_out.h"
38 #include "osdep/shmem.h"
40 #include "x11_common.h"
43 int xinerama_screen
= -1;
47 int vo_nomouse_input
= 0;
48 int vo_grabpointer
= 1;
49 int vo_doublebuffering
= 1;
53 float vo_panscan
= 0.0f
;
55 int vo_refresh_rate
=0;
61 int vo_pts
=0; // for hw decoding
64 char *vo_subdevice
= NULL
;
65 int vo_directrendering
=0;
67 int vo_colorkey
= 0x0000ff00; // default colorkey is green
68 // (0xff000000 means that colorkey has been disabled)
71 // Externally visible list of all vo drivers
73 extern struct vo_driver video_out_mga
;
74 extern struct vo_driver video_out_xmga
;
75 extern struct vo_driver video_out_x11
;
76 extern struct vo_driver video_out_xover
;
77 extern struct vo_driver video_out_xvmc
;
78 extern struct vo_driver video_out_xv
;
79 extern struct vo_driver video_out_gl
;
80 extern struct vo_driver video_out_gl2
;
81 extern struct vo_driver video_out_dga
;
82 extern struct vo_driver video_out_sdl
;
83 extern struct vo_driver video_out_3dfx
;
84 extern struct vo_driver video_out_tdfxfb
;
85 extern struct vo_driver video_out_s3fb
;
86 extern struct vo_driver video_out_wii
;
87 extern struct vo_driver video_out_null
;
88 extern struct vo_driver video_out_zr
;
89 extern struct vo_driver video_out_zr2
;
90 extern struct vo_driver video_out_bl
;
91 extern struct vo_driver video_out_fbdev
;
92 extern struct vo_driver video_out_fbdev2
;
93 extern struct vo_driver video_out_svga
;
94 extern struct vo_driver video_out_png
;
95 extern struct vo_driver video_out_ggi
;
96 extern struct vo_driver video_out_aa
;
97 extern struct vo_driver video_out_caca
;
98 extern struct vo_driver video_out_mpegpes
;
99 extern struct vo_driver video_out_yuv4mpeg
;
100 extern struct vo_driver video_out_direct3d
;
101 extern struct vo_driver video_out_directx
;
102 extern struct vo_driver video_out_dxr2
;
103 extern struct vo_driver video_out_dxr3
;
104 extern struct vo_driver video_out_ivtv
;
105 extern struct vo_driver video_out_v4l2
;
106 extern struct vo_driver video_out_jpeg
;
107 extern struct vo_driver video_out_gif89a
;
108 extern struct vo_driver video_out_vesa
;
109 extern struct vo_driver video_out_directfb
;
110 extern struct vo_driver video_out_dfbmga
;
111 extern struct vo_driver video_out_xvidix
;
112 extern struct vo_driver video_out_winvidix
;
113 extern struct vo_driver video_out_cvidix
;
114 extern struct vo_driver video_out_tdfx_vid
;
115 extern struct vo_driver video_out_xvr100
;
116 extern struct vo_driver video_out_tga
;
117 extern struct vo_driver video_out_macosx
;
118 extern struct vo_driver video_out_quartz
;
119 extern struct vo_driver video_out_pnm
;
120 extern struct vo_driver video_out_md5sum
;
122 const struct vo_driver
*video_out_drivers
[] =
127 #ifdef CONFIG_TDFX_VID
130 #ifdef CONFIG_DIRECTX
133 #ifdef CONFIG_DIRECT3D
136 #ifdef CONFIG_COREVIDEO
184 #ifdef CONFIG_SVGALIB
202 #ifdef CONFIG_V4L2_DECODER
215 #ifdef CONFIG_DIRECTFB
225 #if defined(__MINGW32__) || defined(__CYGWIN__)
231 // should not be auto-selected
236 #ifdef CONFIG_YUV4MPEG
261 static int vo_preinit(struct vo
*vo
, const char *arg
)
263 return vo
->driver
->preinit(vo
, arg
);
266 int vo_control(struct vo
*vo
, uint32_t request
, void *data
)
268 return vo
->driver
->control(vo
, request
, data
);
271 int vo_draw_frame(struct vo
*vo
, uint8_t *src
[])
275 return vo
->driver
->draw_frame(vo
, src
);
278 int vo_draw_slice(struct vo
*vo
, uint8_t *src
[], int stride
[], int w
, int h
, int x
, int y
)
280 return vo
->driver
->draw_slice(vo
, src
, stride
, w
, h
, x
, y
);
283 void vo_draw_osd(struct vo
*vo
, struct osd_state
*osd
)
287 vo
->driver
->draw_osd(vo
, osd
);
290 void vo_flip_page(struct vo
*vo
)
294 vo
->driver
->flip_page(vo
);
297 void vo_check_events(struct vo
*vo
)
301 vo
->driver
->check_events(vo
);
304 void vo_destroy(struct vo
*vo
)
306 vo
->driver
->uninit(vo
);
310 void list_video_out(void)
313 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableVideoOutputDrivers
);
314 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_OUTPUTS\n");
315 while (video_out_drivers
[i
]) {
316 const vo_info_t
*info
= video_out_drivers
[i
++]->info
;
317 mp_msg(MSGT_GLOBAL
, MSGL_INFO
,"\t%s\t%s\n", info
->short_name
, info
->name
);
319 mp_msg(MSGT_GLOBAL
, MSGL_INFO
,"\n");
322 struct vo
*init_best_video_out(struct MPOpts
*opts
, struct vo_x11_state
*x11
,
323 struct mp_fifo
*key_fifo
,
324 struct input_ctx
*input_ctx
)
326 char **vo_list
= opts
->video_driver_list
;
328 struct vo
*vo
= talloc_ptrtype(NULL
, vo
);
329 struct vo initial_values
= {
332 .key_fifo
= key_fifo
,
333 .input_ctx
= input_ctx
,
335 // first try the preferred drivers, with their optional subdevice param:
336 if (vo_list
&& vo_list
[0])
337 while (vo_list
[0][0]) {
338 char *name
= strdup(vo_list
[0]);
339 vo_subdevice
= strchr(name
,':');
340 if (!strcmp(name
, "pgm"))
341 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_VO_PGM_HasBeenReplaced
);
342 if (!strcmp(name
, "md5"))
343 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_VO_MD5_HasBeenReplaced
);
348 for (i
= 0; video_out_drivers
[i
]; i
++) {
349 const struct vo_driver
*video_driver
= video_out_drivers
[i
];
350 const vo_info_t
*info
= video_driver
->info
;
351 if (!strcmp(info
->short_name
, name
)) {
352 // name matches, try it
353 *vo
= initial_values
;
354 vo
->driver
= video_driver
;
355 if (!vo_preinit(vo
, vo_subdevice
)) {
357 return vo
; // success!
365 return NULL
; // do NOT fallback to others
367 // now try the rest...
369 for (i
= 0; video_out_drivers
[i
]; i
++) {
370 const struct vo_driver
*video_driver
= video_out_drivers
[i
];
371 *vo
= initial_values
;
372 vo
->driver
= video_driver
;
373 if (!vo_preinit(vo
, vo_subdevice
))
374 return vo
; // success!
380 int vo_config(struct vo
*vo
, uint32_t width
, uint32_t height
,
381 uint32_t d_width
, uint32_t d_height
, uint32_t flags
,
382 char *title
, uint32_t format
)
384 struct MPOpts
*opts
= vo
->opts
;
386 aspect_save_orig(vo
, width
, height
);
387 aspect_save_prescale(vo
, d_width
, d_height
);
389 if (vo_control(vo
, VOCTRL_UPDATE_SCREENINFO
, NULL
) == VO_TRUE
) {
390 aspect(vo
, &d_width
, &d_height
, A_NOZOOM
);
391 vo
->dx
= (int)(opts
->vo_screenwidth
- d_width
) / 2;
392 vo
->dy
= (int)(opts
->vo_screenheight
- d_height
) / 2;
393 geometry(&vo
->dx
, &vo
->dy
, &d_width
, &d_height
,
394 opts
->vo_screenwidth
, opts
->vo_screenheight
);
395 vo
->dx
+= xinerama_x
;
396 vo
->dy
+= xinerama_y
;
397 vo
->dwidth
= d_width
;
398 vo
->dheight
= d_height
;
401 int ret
= vo
->driver
->config(vo
, width
, height
, d_width
, d_height
, flags
,
403 vo
->config_ok
= (ret
== 0);
404 vo
->config_count
+= vo
->config_ok
;
409 * \brief lookup an integer in a table, table must have 0 as the last key
410 * \param key key to search for
411 * \result translation corresponding to key or "to" value of last mapping
414 int lookup_keymap_table(const struct keymap
*map
, int key
) {
415 while (map
->from
&& map
->from
!= key
) map
++;
419 #if defined(CONFIG_FBDEV) || defined(CONFIG_VESA)
420 /* Borrowed from vo_fbdev.c
421 Monitor ranges related functions*/
423 char *monitor_hfreq_str
= NULL
;
424 char *monitor_vfreq_str
= NULL
;
425 char *monitor_dotclock_str
= NULL
;
427 float range_max(range_t
*r
)
431 for (/* NOTHING */; (r
->min
!= -1 && r
->max
!= -1); r
++)
432 if (max
< r
->max
) max
= r
->max
;
437 int in_range(range_t
*r
, float f
)
439 for (/* NOTHING */; (r
->min
!= -1 && r
->max
!= -1); r
++)
440 if (f
>= r
->min
&& f
<= r
->max
)
445 range_t
*str2range(char *s
)
447 float tmp_min
, tmp_max
;
448 char *endptr
= s
; // to start the loop
454 for (i
= 0; *endptr
; i
++) {
457 if (!(r
= (range_t
*) realloc(r
, sizeof(*r
) * (i
+ 2)))) {
458 mp_msg(MSGT_GLOBAL
, MSGL_WARN
,"can't realloc 'r'\n");
461 tmp_min
= strtod(s
, &endptr
);
462 if (*endptr
== 'k' || *endptr
== 'K') {
465 } else if (*endptr
== 'm' || *endptr
== 'M') {
466 tmp_min
*= 1000000.0;
469 if (*endptr
== '-') {
470 tmp_max
= strtod(endptr
+ 1, &endptr
);
471 if (*endptr
== 'k' || *endptr
== 'K') {
474 } else if (*endptr
== 'm' || *endptr
== 'M') {
475 tmp_max
*= 1000000.0;
478 if (*endptr
!= ',' && *endptr
)
480 } else if (*endptr
== ',' || !*endptr
) {
486 if (r
[i
].min
< 0 || r
[i
].max
< 0)
490 r
[i
].min
= r
[i
].max
= -1;
498 /* Borrowed from vo_fbdev.c END */