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_vdpau
;
79 extern struct vo_driver video_out_xv
;
80 extern struct vo_driver video_out_gl
;
81 extern struct vo_driver video_out_gl2
;
82 extern struct vo_driver video_out_dga
;
83 extern struct vo_driver video_out_sdl
;
84 extern struct vo_driver video_out_3dfx
;
85 extern struct vo_driver video_out_tdfxfb
;
86 extern struct vo_driver video_out_s3fb
;
87 extern struct vo_driver video_out_wii
;
88 extern struct vo_driver video_out_null
;
89 extern struct vo_driver video_out_zr
;
90 extern struct vo_driver video_out_zr2
;
91 extern struct vo_driver video_out_bl
;
92 extern struct vo_driver video_out_fbdev
;
93 extern struct vo_driver video_out_fbdev2
;
94 extern struct vo_driver video_out_svga
;
95 extern struct vo_driver video_out_png
;
96 extern struct vo_driver video_out_ggi
;
97 extern struct vo_driver video_out_aa
;
98 extern struct vo_driver video_out_caca
;
99 extern struct vo_driver video_out_mpegpes
;
100 extern struct vo_driver video_out_yuv4mpeg
;
101 extern struct vo_driver video_out_direct3d
;
102 extern struct vo_driver video_out_directx
;
103 extern struct vo_driver video_out_dxr2
;
104 extern struct vo_driver video_out_dxr3
;
105 extern struct vo_driver video_out_ivtv
;
106 extern struct vo_driver video_out_v4l2
;
107 extern struct vo_driver video_out_jpeg
;
108 extern struct vo_driver video_out_gif89a
;
109 extern struct vo_driver video_out_vesa
;
110 extern struct vo_driver video_out_directfb
;
111 extern struct vo_driver video_out_dfbmga
;
112 extern struct vo_driver video_out_xvidix
;
113 extern struct vo_driver video_out_winvidix
;
114 extern struct vo_driver video_out_cvidix
;
115 extern struct vo_driver video_out_tdfx_vid
;
116 extern struct vo_driver video_out_xvr100
;
117 extern struct vo_driver video_out_tga
;
118 extern struct vo_driver video_out_macosx
;
119 extern struct vo_driver video_out_quartz
;
120 extern struct vo_driver video_out_pnm
;
121 extern struct vo_driver video_out_md5sum
;
123 const struct vo_driver
*video_out_drivers
[] =
128 #ifdef CONFIG_TDFX_VID
131 #ifdef CONFIG_DIRECTX
134 #ifdef CONFIG_DIRECT3D
137 #ifdef CONFIG_COREVIDEO
188 #ifdef CONFIG_SVGALIB
206 #ifdef CONFIG_V4L2_DECODER
219 #ifdef CONFIG_DIRECTFB
229 #if defined(__MINGW32__) || defined(__CYGWIN__)
235 // should not be auto-selected
240 #ifdef CONFIG_YUV4MPEG
265 static int vo_preinit(struct vo
*vo
, const char *arg
)
267 return vo
->driver
->preinit(vo
, arg
);
270 int vo_control(struct vo
*vo
, uint32_t request
, void *data
)
272 return vo
->driver
->control(vo
, request
, data
);
275 int vo_draw_frame(struct vo
*vo
, uint8_t *src
[])
279 return vo
->driver
->draw_frame(vo
, src
);
282 int vo_draw_slice(struct vo
*vo
, uint8_t *src
[], int stride
[], int w
, int h
, int x
, int y
)
284 return vo
->driver
->draw_slice(vo
, src
, stride
, w
, h
, x
, y
);
287 void vo_draw_osd(struct vo
*vo
, struct osd_state
*osd
)
291 vo
->driver
->draw_osd(vo
, osd
);
294 void vo_flip_page(struct vo
*vo
)
298 vo
->driver
->flip_page(vo
);
301 void vo_check_events(struct vo
*vo
)
305 vo
->driver
->check_events(vo
);
308 void vo_destroy(struct vo
*vo
)
310 vo
->driver
->uninit(vo
);
314 void list_video_out(void)
317 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableVideoOutputDrivers
);
318 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_OUTPUTS\n");
319 while (video_out_drivers
[i
]) {
320 const vo_info_t
*info
= video_out_drivers
[i
++]->info
;
321 mp_msg(MSGT_GLOBAL
, MSGL_INFO
,"\t%s\t%s\n", info
->short_name
, info
->name
);
323 mp_msg(MSGT_GLOBAL
, MSGL_INFO
,"\n");
326 struct vo
*init_best_video_out(struct MPOpts
*opts
, struct vo_x11_state
*x11
,
327 struct mp_fifo
*key_fifo
,
328 struct input_ctx
*input_ctx
)
330 char **vo_list
= opts
->video_driver_list
;
332 struct vo
*vo
= talloc_ptrtype(NULL
, vo
);
333 struct vo initial_values
= {
336 .key_fifo
= key_fifo
,
337 .input_ctx
= input_ctx
,
339 // first try the preferred drivers, with their optional subdevice param:
340 if (vo_list
&& vo_list
[0])
341 while (vo_list
[0][0]) {
342 char *name
= strdup(vo_list
[0]);
343 vo_subdevice
= strchr(name
,':');
344 if (!strcmp(name
, "pgm"))
345 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_VO_PGM_HasBeenReplaced
);
346 if (!strcmp(name
, "md5"))
347 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_VO_MD5_HasBeenReplaced
);
352 for (i
= 0; video_out_drivers
[i
]; i
++) {
353 const struct vo_driver
*video_driver
= video_out_drivers
[i
];
354 const vo_info_t
*info
= video_driver
->info
;
355 if (!strcmp(info
->short_name
, name
)) {
356 // name matches, try it
357 *vo
= initial_values
;
358 vo
->driver
= video_driver
;
359 if (!vo_preinit(vo
, vo_subdevice
)) {
361 return vo
; // success!
369 return NULL
; // do NOT fallback to others
371 // now try the rest...
373 for (i
= 0; video_out_drivers
[i
]; i
++) {
374 const struct vo_driver
*video_driver
= video_out_drivers
[i
];
375 *vo
= initial_values
;
376 vo
->driver
= video_driver
;
377 if (!vo_preinit(vo
, vo_subdevice
))
378 return vo
; // success!
384 int vo_config(struct vo
*vo
, uint32_t width
, uint32_t height
,
385 uint32_t d_width
, uint32_t d_height
, uint32_t flags
,
386 char *title
, uint32_t format
)
388 struct MPOpts
*opts
= vo
->opts
;
390 aspect_save_orig(vo
, width
, height
);
391 aspect_save_prescale(vo
, d_width
, d_height
);
393 if (vo_control(vo
, VOCTRL_UPDATE_SCREENINFO
, NULL
) == VO_TRUE
) {
394 aspect(vo
, &d_width
, &d_height
, A_NOZOOM
);
395 vo
->dx
= (int)(opts
->vo_screenwidth
- d_width
) / 2;
396 vo
->dy
= (int)(opts
->vo_screenheight
- d_height
) / 2;
397 geometry(&vo
->dx
, &vo
->dy
, &d_width
, &d_height
,
398 opts
->vo_screenwidth
, opts
->vo_screenheight
);
399 vo
->dx
+= xinerama_x
;
400 vo
->dy
+= xinerama_y
;
401 vo
->dwidth
= d_width
;
402 vo
->dheight
= d_height
;
405 int ret
= vo
->driver
->config(vo
, width
, height
, d_width
, d_height
, flags
,
407 vo
->config_ok
= (ret
== 0);
408 vo
->config_count
+= vo
->config_ok
;
413 * \brief lookup an integer in a table, table must have 0 as the last key
414 * \param key key to search for
415 * \result translation corresponding to key or "to" value of last mapping
418 int lookup_keymap_table(const struct keymap
*map
, int key
) {
419 while (map
->from
&& map
->from
!= key
) map
++;
424 * \brief helper function for the kind of panscan-scaling that needs a source
425 * and destination rectangle like Direct3D and VDPAU
427 static void src_dst_split_scaling(int src_size
, int dst_size
, int scaled_src_size
,
428 int *src_start
, int *src_end
, int *dst_start
, int *dst_end
) {
429 if (scaled_src_size
> dst_size
) {
430 int border
= src_size
* (scaled_src_size
- dst_size
) / scaled_src_size
;
431 // round to a multiple of 2, this is at least needed for vo_direct3d and ATI cards
432 border
= (border
/ 2 + 1) & ~1;
434 *src_end
= src_size
- border
;
440 *dst_start
= (dst_size
- scaled_src_size
) / 2;
441 *dst_end
= *dst_start
+ scaled_src_size
;
446 * Calculate the appropriate source and destination rectangle to
447 * get a correctly scaled picture, including pan-scan.
448 * Can be extended to take future cropping support into account.
450 * \param crop specifies the cropping border size in the left, right, top and bottom members, may be NULL
451 * \param borders the border values as e.g. EOSD (ASS) and properly placed DVD highlight support requires,
452 * may be NULL and only left and top are currently valid.
454 void calc_src_dst_rects(struct vo
*vo
, int src_width
, int src_height
,
455 struct vo_rect
*src
, struct vo_rect
*dst
,
456 struct vo_rect
*borders
, const struct vo_rect
*crop
)
458 static const struct vo_rect no_crop
= {0, 0, 0, 0, 0, 0};
459 int scaled_width
= 0;
460 int scaled_height
= 0;
461 if (!crop
) crop
= &no_crop
;
462 src_width
-= crop
->left
+ crop
->right
;
463 src_height
-= crop
->top
+ crop
->bottom
;
464 if (src_width
< 2) src_width
= 2;
465 if (src_height
< 2) src_height
= 2;
466 dst
->left
= 0; dst
->right
= vo
->dwidth
;
467 dst
->top
= 0; dst
->bottom
= vo
->dheight
;
468 src
->left
= 0; src
->right
= src_width
;
469 src
->top
= 0; src
->bottom
= src_height
;
471 borders
->left
= 0; borders
->top
= 0;
474 aspect(vo
, &scaled_width
, &scaled_height
, A_ZOOM
);
476 scaled_width
+= vo
->panscan_x
;
477 scaled_height
+= vo
->panscan_y
;
479 borders
->left
= (vo
->dwidth
- scaled_width
) / 2;
480 borders
->top
= (vo
->dheight
- scaled_height
) / 2;
482 src_dst_split_scaling(src_width
, vo
->dwidth
, scaled_width
,
483 &src
->left
, &src
->right
, &dst
->left
, &dst
->right
);
484 src_dst_split_scaling(src_height
, vo
->dheight
, scaled_height
,
485 &src
->top
, &src
->bottom
, &dst
->top
, &dst
->bottom
);
487 src
->left
+= crop
->left
; src
->right
+= crop
->left
;
488 src
->top
+= crop
->top
; src
->bottom
+= crop
->top
;
489 src
->width
= src
->right
- src
->left
;
490 src
->height
= src
->bottom
- src
->top
;
491 dst
->width
= dst
->right
- dst
->left
;
492 dst
->height
= dst
->bottom
- dst
->top
;
495 #if defined(CONFIG_FBDEV) || defined(CONFIG_VESA)
496 /* Borrowed from vo_fbdev.c
497 Monitor ranges related functions*/
499 char *monitor_hfreq_str
= NULL
;
500 char *monitor_vfreq_str
= NULL
;
501 char *monitor_dotclock_str
= NULL
;
503 float range_max(range_t
*r
)
507 for (/* NOTHING */; (r
->min
!= -1 && r
->max
!= -1); r
++)
508 if (max
< r
->max
) max
= r
->max
;
513 int in_range(range_t
*r
, float f
)
515 for (/* NOTHING */; (r
->min
!= -1 && r
->max
!= -1); r
++)
516 if (f
>= r
->min
&& f
<= r
->max
)
521 range_t
*str2range(char *s
)
523 float tmp_min
, tmp_max
;
524 char *endptr
= s
; // to start the loop
530 for (i
= 0; *endptr
; i
++) {
533 if (!(r
= (range_t
*) realloc(r
, sizeof(*r
) * (i
+ 2)))) {
534 mp_msg(MSGT_GLOBAL
, MSGL_WARN
,"can't realloc 'r'\n");
537 tmp_min
= strtod(s
, &endptr
);
538 if (*endptr
== 'k' || *endptr
== 'K') {
541 } else if (*endptr
== 'm' || *endptr
== 'M') {
542 tmp_min
*= 1000000.0;
545 if (*endptr
== '-') {
546 tmp_max
= strtod(endptr
+ 1, &endptr
);
547 if (*endptr
== 'k' || *endptr
== 'K') {
550 } else if (*endptr
== 'm' || *endptr
== 'M') {
551 tmp_max
*= 1000000.0;
554 if (*endptr
!= ',' && *endptr
)
556 } else if (*endptr
== ',' || !*endptr
) {
562 if (r
[i
].min
< 0 || r
[i
].max
< 0)
566 r
[i
].min
= r
[i
].max
= -1;
574 /* Borrowed from vo_fbdev.c END */