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.
28 //#include <sys/mman.h>
33 #include "video_out.h"
36 #include "old_vo_wrapper.h"
41 #include "osdep/shmem.h"
43 #include "x11_common.h"
46 int xinerama_screen
= -1;
50 int vo_nomouse_input
= 0;
51 int vo_grabpointer
= 1;
52 int vo_doublebuffering
= 1;
56 float vo_panscan
= 0.0f
;
58 int vo_refresh_rate
=0;
64 int vo_pts
=0; // for hw decoding
67 char *vo_subdevice
= NULL
;
68 int vo_directrendering
=0;
70 int vo_colorkey
= 0x0000ff00; // default colorkey is green
71 // (0xff000000 means that colorkey has been disabled)
73 // name to be used instead of the vo's default
75 // title to be applied to movie window
79 // Externally visible list of all vo drivers
81 extern struct vo_driver video_out_mga
;
82 extern struct vo_driver video_out_xmga
;
83 extern struct vo_driver video_out_x11
;
84 extern struct vo_driver video_out_xover
;
85 extern struct vo_driver video_out_xvmc
;
86 extern struct vo_driver video_out_vdpau
;
87 extern struct vo_driver video_out_xv
;
88 extern struct vo_driver video_out_gl
;
89 extern struct vo_driver video_out_gl2
;
90 extern struct vo_driver video_out_matrixview
;
91 extern struct vo_driver video_out_dga
;
92 extern struct vo_driver video_out_sdl
;
93 extern struct vo_driver video_out_3dfx
;
94 extern struct vo_driver video_out_tdfxfb
;
95 extern struct vo_driver video_out_s3fb
;
96 extern struct vo_driver video_out_wii
;
97 extern struct vo_driver video_out_null
;
98 extern struct vo_driver video_out_zr
;
99 extern struct vo_driver video_out_zr2
;
100 extern struct vo_driver video_out_bl
;
101 extern struct vo_driver video_out_fbdev
;
102 extern struct vo_driver video_out_fbdev2
;
103 extern struct vo_driver video_out_svga
;
104 extern struct vo_driver video_out_png
;
105 extern struct vo_driver video_out_ggi
;
106 extern struct vo_driver video_out_aa
;
107 extern struct vo_driver video_out_caca
;
108 extern struct vo_driver video_out_mpegpes
;
109 extern struct vo_driver video_out_yuv4mpeg
;
110 extern struct vo_driver video_out_direct3d
;
111 extern struct vo_driver video_out_directx
;
112 extern struct vo_driver video_out_kva
;
113 extern struct vo_driver video_out_dxr2
;
114 extern struct vo_driver video_out_dxr3
;
115 extern struct vo_driver video_out_ivtv
;
116 extern struct vo_driver video_out_v4l2
;
117 extern struct vo_driver video_out_jpeg
;
118 extern struct vo_driver video_out_gif89a
;
119 extern struct vo_driver video_out_vesa
;
120 extern struct vo_driver video_out_directfb
;
121 extern struct vo_driver video_out_dfbmga
;
122 extern struct vo_driver video_out_xvidix
;
123 extern struct vo_driver video_out_winvidix
;
124 extern struct vo_driver video_out_cvidix
;
125 extern struct vo_driver video_out_tdfx_vid
;
126 extern struct vo_driver video_out_xvr100
;
127 extern struct vo_driver video_out_tga
;
128 extern struct vo_driver video_out_corevideo
;
129 extern struct vo_driver video_out_quartz
;
130 extern struct vo_driver video_out_pnm
;
131 extern struct vo_driver video_out_md5sum
;
133 const struct vo_driver
*video_out_drivers
[] =
138 #ifdef CONFIG_TDFX_VID
141 #ifdef CONFIG_DIRECTX
144 #ifdef CONFIG_DIRECT3D
150 #ifdef CONFIG_COREVIDEO
151 &video_out_corevideo
,
188 #ifdef CONFIG_MATRIXVIEW
189 &video_out_matrixview
,
204 #ifdef CONFIG_SVGALIB
222 #ifdef CONFIG_V4L2_DECODER
235 #ifdef CONFIG_DIRECTFB
245 #if defined(__MINGW32__) || defined(__CYGWIN__)
251 // should not be auto-selected
256 #ifdef CONFIG_YUV4MPEG
281 static int vo_preinit(struct vo
*vo
, const char *arg
)
283 return vo
->driver
->preinit(vo
, arg
);
286 int vo_control(struct vo
*vo
, uint32_t request
, void *data
)
288 return vo
->driver
->control(vo
, request
, data
);
291 // Return -1 if driver appears not to support a draw_image interface,
292 // 0 otherwise (whether the driver actually drew something or not).
293 int vo_draw_image(struct vo
*vo
, struct mp_image
*mpi
, double pts
)
297 if (vo
->driver
->buffer_frames
) {
298 vo
->driver
->draw_image(vo
, mpi
, pts
);
301 vo
->frame_loaded
= true;
303 if (vo_control(vo
, VOCTRL_DRAW_IMAGE
, mpi
) == VO_NOTIMPL
)
308 int vo_get_buffered_frame(struct vo
*vo
, bool eof
)
312 if (vo
->frame_loaded
)
314 if (!vo
->driver
->buffer_frames
)
316 vo
->driver
->get_buffered_frame(vo
, eof
);
317 return vo
->frame_loaded
? 0 : -1;
320 int vo_draw_frame(struct vo
*vo
, uint8_t *src
[])
322 assert(!vo
->driver
->is_new
);
325 return old_vo_draw_frame(vo
, src
);
328 int vo_draw_slice(struct vo
*vo
, uint8_t *src
[], int stride
[], int w
, int h
, int x
, int y
)
330 return vo
->driver
->draw_slice(vo
, src
, stride
, w
, h
, x
, y
);
333 void vo_draw_osd(struct vo
*vo
, struct osd_state
*osd
)
337 vo
->driver
->draw_osd(vo
, osd
);
340 void vo_flip_page(struct vo
*vo
, unsigned int pts_us
, int duration
)
344 vo
->frame_loaded
= false;
345 vo
->next_pts
= MP_NOPTS_VALUE
;
346 if (vo
->driver
->flip_page_timed
)
347 vo
->driver
->flip_page_timed(vo
, pts_us
, duration
);
349 vo
->driver
->flip_page(vo
);
352 void vo_check_events(struct vo
*vo
)
356 vo
->driver
->check_events(vo
);
359 void vo_seek_reset(struct vo
*vo
)
361 vo_control(vo
, VOCTRL_RESET
, NULL
);
362 vo
->frame_loaded
= false;
365 void vo_destroy(struct vo
*vo
)
367 vo
->driver
->uninit(vo
);
371 void list_video_out(void)
374 mp_tmsg(MSGT_CPLAYER
, MSGL_INFO
, "Available video output drivers:\n");
375 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_OUTPUTS\n");
376 while (video_out_drivers
[i
]) {
377 const vo_info_t
*info
= video_out_drivers
[i
++]->info
;
378 mp_msg(MSGT_GLOBAL
, MSGL_INFO
,"\t%s\t%s\n", info
->short_name
, info
->name
);
380 mp_msg(MSGT_GLOBAL
, MSGL_INFO
,"\n");
383 struct vo
*init_best_video_out(struct MPOpts
*opts
, struct vo_x11_state
*x11
,
384 struct mp_fifo
*key_fifo
,
385 struct input_ctx
*input_ctx
)
387 char **vo_list
= opts
->video_driver_list
;
389 struct vo
*vo
= talloc_ptrtype(NULL
, vo
);
390 struct vo initial_values
= {
393 .key_fifo
= key_fifo
,
394 .input_ctx
= input_ctx
,
396 // first try the preferred drivers, with their optional subdevice param:
397 if (vo_list
&& vo_list
[0])
398 while (vo_list
[0][0]) {
399 char *name
= strdup(vo_list
[0]);
400 vo_subdevice
= strchr(name
,':');
401 if (!strcmp(name
, "pgm"))
402 mp_tmsg(MSGT_CPLAYER
, MSGL_ERR
, "The pgm video output driver has been replaced by -vo pnm:pgmyuv.\n");
403 if (!strcmp(name
, "md5"))
404 mp_tmsg(MSGT_CPLAYER
, MSGL_ERR
, "The md5 video output driver has been replaced by -vo md5sum.\n");
409 for (i
= 0; video_out_drivers
[i
]; i
++) {
410 const struct vo_driver
*video_driver
= video_out_drivers
[i
];
411 const vo_info_t
*info
= video_driver
->info
;
412 if (!strcmp(info
->short_name
, name
)) {
413 // name matches, try it
414 *vo
= initial_values
;
415 vo
->driver
= video_driver
;
416 if (!vo_preinit(vo
, vo_subdevice
)) {
418 return vo
; // success!
420 talloc_free_children(vo
);
427 return NULL
; // do NOT fallback to others
429 // now try the rest...
431 for (i
= 0; video_out_drivers
[i
]; i
++) {
432 const struct vo_driver
*video_driver
= video_out_drivers
[i
];
433 *vo
= initial_values
;
434 vo
->driver
= video_driver
;
435 if (!vo_preinit(vo
, vo_subdevice
))
436 return vo
; // success!
437 talloc_free_children(vo
);
443 int vo_config(struct vo
*vo
, uint32_t width
, uint32_t height
,
444 uint32_t d_width
, uint32_t d_height
, uint32_t flags
,
445 char *title
, uint32_t format
)
447 struct MPOpts
*opts
= vo
->opts
;
449 aspect_save_orig(vo
, width
, height
);
450 aspect_save_prescale(vo
, d_width
, d_height
);
452 if (vo_control(vo
, VOCTRL_UPDATE_SCREENINFO
, NULL
) == VO_TRUE
) {
453 aspect(vo
, &d_width
, &d_height
, A_NOZOOM
);
454 vo
->dx
= (int)(opts
->vo_screenwidth
- d_width
) / 2;
455 vo
->dy
= (int)(opts
->vo_screenheight
- d_height
) / 2;
456 geometry(&vo
->dx
, &vo
->dy
, &d_width
, &d_height
,
457 opts
->vo_screenwidth
, opts
->vo_screenheight
);
458 vo
->dx
+= xinerama_x
;
459 vo
->dy
+= xinerama_y
;
460 vo
->dwidth
= d_width
;
461 vo
->dheight
= d_height
;
464 int ret
= vo
->driver
->config(vo
, width
, height
, d_width
, d_height
, flags
,
466 vo
->config_ok
= (ret
== 0);
467 vo
->config_count
+= vo
->config_ok
;
472 * \brief lookup an integer in a table, table must have 0 as the last key
473 * \param key key to search for
474 * \result translation corresponding to key or "to" value of last mapping
477 int lookup_keymap_table(const struct keymap
*map
, int key
) {
478 while (map
->from
&& map
->from
!= key
) map
++;
483 * \brief helper function for the kind of panscan-scaling that needs a source
484 * and destination rectangle like Direct3D and VDPAU
486 static void src_dst_split_scaling(int src_size
, int dst_size
, int scaled_src_size
,
487 int *src_start
, int *src_end
, int *dst_start
, int *dst_end
) {
488 if (scaled_src_size
> dst_size
) {
489 int border
= src_size
* (scaled_src_size
- dst_size
) / scaled_src_size
;
490 // round to a multiple of 2, this is at least needed for vo_direct3d and ATI cards
491 border
= (border
/ 2 + 1) & ~1;
493 *src_end
= src_size
- border
;
499 *dst_start
= (dst_size
- scaled_src_size
) / 2;
500 *dst_end
= *dst_start
+ scaled_src_size
;
505 * Calculate the appropriate source and destination rectangle to
506 * get a correctly scaled picture, including pan-scan.
507 * Can be extended to take future cropping support into account.
509 * \param crop specifies the cropping border size in the left, right, top and bottom members, may be NULL
510 * \param borders the border values as e.g. EOSD (ASS) and properly placed DVD highlight support requires,
511 * may be NULL and only left and top are currently valid.
513 void calc_src_dst_rects(struct vo
*vo
, int src_width
, int src_height
,
514 struct vo_rect
*src
, struct vo_rect
*dst
,
515 struct vo_rect
*borders
, const struct vo_rect
*crop
)
517 static const struct vo_rect no_crop
= {0, 0, 0, 0, 0, 0};
518 int scaled_width
= 0;
519 int scaled_height
= 0;
520 if (!crop
) crop
= &no_crop
;
521 src_width
-= crop
->left
+ crop
->right
;
522 src_height
-= crop
->top
+ crop
->bottom
;
523 if (src_width
< 2) src_width
= 2;
524 if (src_height
< 2) src_height
= 2;
525 dst
->left
= 0; dst
->right
= vo
->dwidth
;
526 dst
->top
= 0; dst
->bottom
= vo
->dheight
;
527 src
->left
= 0; src
->right
= src_width
;
528 src
->top
= 0; src
->bottom
= src_height
;
530 borders
->left
= 0; borders
->top
= 0;
532 if (aspect_scaling()) {
533 aspect(vo
, &scaled_width
, &scaled_height
, A_WINZOOM
);
534 panscan_calc_windowed(vo
);
535 scaled_width
+= vo
->panscan_x
;
536 scaled_height
+= vo
->panscan_y
;
538 borders
->left
= (vo
->dwidth
- scaled_width
) / 2;
539 borders
->top
= (vo
->dheight
- scaled_height
) / 2;
541 src_dst_split_scaling(src_width
, vo
->dwidth
, scaled_width
,
542 &src
->left
, &src
->right
, &dst
->left
, &dst
->right
);
543 src_dst_split_scaling(src_height
, vo
->dheight
, scaled_height
,
544 &src
->top
, &src
->bottom
, &dst
->top
, &dst
->bottom
);
546 src
->left
+= crop
->left
; src
->right
+= crop
->left
;
547 src
->top
+= crop
->top
; src
->bottom
+= crop
->top
;
548 src
->width
= src
->right
- src
->left
;
549 src
->height
= src
->bottom
- src
->top
;
550 dst
->width
= dst
->right
- dst
->left
;
551 dst
->height
= dst
->bottom
- dst
->top
;
554 #if defined(CONFIG_FBDEV) || defined(CONFIG_VESA)
555 /* Borrowed from vo_fbdev.c
556 Monitor ranges related functions*/
558 char *monitor_hfreq_str
= NULL
;
559 char *monitor_vfreq_str
= NULL
;
560 char *monitor_dotclock_str
= NULL
;
562 float range_max(range_t
*r
)
566 for (/* NOTHING */; (r
->min
!= -1 && r
->max
!= -1); r
++)
567 if (max
< r
->max
) max
= r
->max
;
572 int in_range(range_t
*r
, float f
)
574 for (/* NOTHING */; (r
->min
!= -1 && r
->max
!= -1); r
++)
575 if (f
>= r
->min
&& f
<= r
->max
)
580 range_t
*str2range(char *s
)
582 float tmp_min
, tmp_max
;
583 char *endptr
= s
; // to start the loop
589 for (i
= 0; *endptr
; i
++) {
592 if (!(r
= (range_t
*) realloc(r
, sizeof(*r
) * (i
+ 2)))) {
593 mp_msg(MSGT_GLOBAL
, MSGL_WARN
,"can't realloc 'r'\n");
596 tmp_min
= strtod(s
, &endptr
);
597 if (*endptr
== 'k' || *endptr
== 'K') {
600 } else if (*endptr
== 'm' || *endptr
== 'M') {
601 tmp_min
*= 1000000.0;
604 if (*endptr
== '-') {
605 tmp_max
= strtod(endptr
+ 1, &endptr
);
606 if (*endptr
== 'k' || *endptr
== 'K') {
609 } else if (*endptr
== 'm' || *endptr
== 'M') {
610 tmp_max
*= 1000000.0;
613 if (*endptr
!= ',' && *endptr
)
615 } else if (*endptr
== ',' || !*endptr
) {
621 if (r
[i
].min
< 0 || r
[i
].max
< 0)
625 r
[i
].min
= r
[i
].max
= -1;
633 /* Borrowed from vo_fbdev.c END */