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.
21 // Number of buffers _FOR_DOUBLEBUFFERING_MODE_
22 // Use option -double to enable double buffering! (default: single buffer)
47 #include "video_out.h"
48 #include "libmpcodecs/vfcap.h"
49 #include "libmpcodecs/mp_image.h"
53 #include <X11/Xutil.h>
56 #include "x11_common.h"
58 #include "fastmemcpy.h"
62 #include "subopt-helper.h"
64 #include "input/input.h"
67 #include "libavutil/common.h"
69 static const vo_info_t info
= {
72 "Gerd Knorr <kraxel@goldbach.in-berlin.de> and others",
79 #include <X11/extensions/XShm.h>
82 // Note: depends on the inclusion of X11/extensions/XShm.h
83 #include <X11/extensions/Xv.h>
84 #include <X11/extensions/Xvlib.h>
88 XvImageFormatValues
*fo
;
89 unsigned int formats
, adaptors
, xv_format
;
94 int have_visible_image_copy
;
95 int have_next_image_copy
;
96 int unchanged_visible_image
;
97 int unchanged_next_image
;
99 XvImage
*xvimage
[NUM_BUFFERS
+ 1];
100 uint32_t image_width
;
101 uint32_t image_height
;
102 uint32_t image_format
;
104 struct vo_rect src_rect
;
105 struct vo_rect dst_rect
;
106 uint32_t max_width
, max_height
; // zero means: not set
107 int event_fd_registered
; // for uninit called from preinit
109 int osd_objects_drawn
;
110 void (*draw_alpha_fnc
)(void *ctx
, int x0
, int y0
, int w
, int h
,
111 unsigned char *src
, unsigned char *srca
,
114 XShmSegmentInfo Shminfo
[NUM_BUFFERS
+ 1];
119 static void allocate_xvimage(struct vo
*, int);
122 static void fixup_osd_position(struct vo
*vo
, int *x0
, int *y0
, int *w
, int *h
)
124 struct xvctx
*ctx
= vo
->priv
;
125 *x0
+= ctx
->image_width
* (vo
->panscan_x
>> 1)
126 / (vo
->dwidth
+ vo
->panscan_x
);
127 *w
= av_clip(*w
, 0, ctx
->image_width
);
128 *h
= av_clip(*h
, 0, ctx
->image_height
);
129 *x0
= FFMIN(*x0
, ctx
->image_width
- *w
);
130 *y0
= FFMIN(*y0
, ctx
->image_height
- *h
);
133 static void draw_alpha_yv12(void *p
, int x0
, int y0
, int w
, int h
,
134 unsigned char *src
, unsigned char *srca
,
138 struct xvctx
*ctx
= vo
->priv
;
139 fixup_osd_position(vo
, &x0
, &y0
, &w
, &h
);
140 vo_draw_alpha_yv12(w
, h
, src
, srca
, stride
,
141 ctx
->xvimage
[ctx
->current_buf
]->data
+
142 ctx
->xvimage
[ctx
->current_buf
]->offsets
[0] +
143 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0] * y0
+ x0
,
144 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0]);
145 ctx
->osd_objects_drawn
++;
148 static void draw_alpha_yuy2(void *p
, int x0
, int y0
, int w
, int h
,
149 unsigned char *src
, unsigned char *srca
,
153 struct xvctx
*ctx
= vo
->priv
;
154 fixup_osd_position(vo
, &x0
, &y0
, &w
, &h
);
155 vo_draw_alpha_yuy2(w
, h
, src
, srca
, stride
,
156 ctx
->xvimage
[ctx
->current_buf
]->data
+
157 ctx
->xvimage
[ctx
->current_buf
]->offsets
[0] +
158 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0] * y0
+ 2 * x0
,
159 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0]);
160 ctx
->osd_objects_drawn
++;
163 static void draw_alpha_uyvy(void *p
, int x0
, int y0
, int w
, int h
,
164 unsigned char *src
, unsigned char *srca
,
168 struct xvctx
*ctx
= vo
->priv
;
169 fixup_osd_position(vo
, &x0
, &y0
, &w
, &h
);
170 vo_draw_alpha_yuy2(w
, h
, src
, srca
, stride
,
171 ctx
->xvimage
[ctx
->current_buf
]->data
+
172 ctx
->xvimage
[ctx
->current_buf
]->offsets
[0] +
173 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0] * y0
+ 2 * x0
+ 1,
174 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0]);
175 ctx
->osd_objects_drawn
++;
178 static void draw_alpha_null(void *p
, int x0
, int y0
, int w
, int h
,
179 unsigned char *src
, unsigned char *srca
,
185 static void deallocate_xvimage(struct vo
*vo
, int foo
);
187 static void resize(struct vo
*vo
)
189 struct xvctx
*ctx
= vo
->priv
;
191 calc_src_dst_rects(vo
, ctx
->image_width
, ctx
->image_height
, &ctx
->src_rect
,
192 &ctx
->dst_rect
, NULL
, NULL
);
193 struct vo_rect
*dst
= &ctx
->dst_rect
;
194 vo_x11_clearwindow_part(vo
, vo
->x11
->window
, dst
->width
, dst
->height
, 1);
195 vo_xv_draw_colorkey(vo
, dst
->left
, dst
->top
, dst
->width
, dst
->height
);
199 * connect to server, create and map window,
200 * allocate colors and (shared) memory
202 static int config(struct vo
*vo
, uint32_t width
, uint32_t height
,
203 uint32_t d_width
, uint32_t d_height
, uint32_t flags
,
204 char *title
, uint32_t format
)
206 struct vo_x11_state
*x11
= vo
->x11
;
208 XSetWindowAttributes xswa
;
209 XWindowAttributes attribs
;
210 unsigned long xswamask
;
212 struct xvctx
*ctx
= vo
->priv
;
215 ctx
->image_height
= height
;
216 ctx
->image_width
= width
;
217 ctx
->image_format
= format
;
219 if ((ctx
->max_width
!= 0 && ctx
->max_height
!= 0)
220 && (ctx
->image_width
> ctx
->max_width
221 || ctx
->image_height
> ctx
->max_height
)) {
222 mp_tmsg(MSGT_VO
, MSGL_ERR
, "Source image dimensions are too high: %ux%u (maximum is %ux%u)\n",
223 ctx
->image_width
, ctx
->image_height
, ctx
->max_width
,
228 ctx
->visible_buf
= -1;
229 ctx
->have_visible_image_copy
= false;
230 ctx
->have_next_image_copy
= false;
232 /* check image formats */
234 for (i
= 0; i
< ctx
->formats
; i
++) {
235 mp_msg(MSGT_VO
, MSGL_V
, "Xvideo image format: 0x%x (%4.4s) %s\n",
236 ctx
->fo
[i
].id
, (char *) &ctx
->fo
[i
].id
,
237 (ctx
->fo
[i
].format
== XvPacked
) ? "packed" : "planar");
238 if (ctx
->fo
[i
].id
== format
)
239 ctx
->xv_format
= ctx
->fo
[i
].id
;
246 int vm
= flags
& VOFLAG_MODESWITCHING
;
249 ctx
->mode_switched
= 1;
252 XGetWindowAttributes(x11
->display
, DefaultRootWindow(x11
->display
),
254 depth
= attribs
.depth
;
255 if (depth
!= 15 && depth
!= 16 && depth
!= 24 && depth
!= 32)
257 XMatchVisualInfo(x11
->display
, x11
->screen
, depth
, TrueColor
, &vinfo
);
259 xswa
.background_pixel
= 0;
260 if (x11
->xv_ck_info
.method
== CK_METHOD_BACKGROUND
)
261 xswa
.background_pixel
= x11
->xv_colorkey
;
262 xswa
.border_pixel
= 0;
263 xswamask
= CWBackPixel
| CWBorderPixel
;
265 vo_x11_create_vo_window(vo
, &vinfo
, vo
->dx
, vo
->dy
, vo
->dwidth
,
266 vo
->dheight
, flags
, CopyFromParent
, "xv",
268 XChangeWindowAttributes(x11
->display
, x11
->window
, xswamask
, &xswa
);
272 /* Grab the mouse pointer in our window */
274 XGrabPointer(x11
->display
, x11
->window
, True
, 0, GrabModeAsync
,
275 GrabModeAsync
, x11
->window
, None
, CurrentTime
);
276 XSetInputFocus(x11
->display
, x11
->window
, RevertToNone
,
282 mp_msg(MSGT_VO
, MSGL_V
, "using Xvideo port %d for hw scaling\n",
285 switch (ctx
->xv_format
) {
289 ctx
->draw_alpha_fnc
= draw_alpha_yv12
;
293 ctx
->draw_alpha_fnc
= draw_alpha_yuy2
;
296 ctx
->draw_alpha_fnc
= draw_alpha_uyvy
;
299 ctx
->draw_alpha_fnc
= draw_alpha_null
;
302 // In case config has been called before
303 for (i
= 0; i
< ctx
->total_buffers
; i
++)
304 deallocate_xvimage(vo
, i
);
307 vo_doublebuffering
? (vo_directrendering
? NUM_BUFFERS
: 2) : 1;
308 ctx
->total_buffers
= ctx
->num_buffers
+ 1;
310 for (i
= 0; i
< ctx
->total_buffers
; i
++)
311 allocate_xvimage(vo
, i
);
313 ctx
->current_buf
= 0;
314 ctx
->current_ip_buf
= 0;
322 static void allocate_xvimage(struct vo
*vo
, int foo
)
324 struct xvctx
*ctx
= vo
->priv
;
325 struct vo_x11_state
*x11
= vo
->x11
;
327 * allocate XvImages. FIXME: no error checking, without
328 * mit-shm this will bomb... trzing to fix ::atmos
331 if (x11
->display_is_local
&& XShmQueryExtension(x11
->display
))
335 mp_tmsg(MSGT_VO
, MSGL_INFO
, "[VO_XV] Shared memory not supported\nReverting to normal Xv.\n");
337 if (ctx
->Shmem_Flag
) {
339 (XvImage
*) XvShmCreateImage(x11
->display
, x11
->xv_port
,
340 ctx
->xv_format
, NULL
,
341 ctx
->image_width
, ctx
->image_height
,
344 ctx
->Shminfo
[foo
].shmid
= shmget(IPC_PRIVATE
,
345 ctx
->xvimage
[foo
]->data_size
,
347 ctx
->Shminfo
[foo
].shmaddr
= (char *) shmat(ctx
->Shminfo
[foo
].shmid
, 0,
349 ctx
->Shminfo
[foo
].readOnly
= False
;
351 ctx
->xvimage
[foo
]->data
= ctx
->Shminfo
[foo
].shmaddr
;
352 XShmAttach(x11
->display
, &ctx
->Shminfo
[foo
]);
353 XSync(x11
->display
, False
);
354 shmctl(ctx
->Shminfo
[foo
].shmid
, IPC_RMID
, 0);
359 (XvImage
*) XvCreateImage(x11
->display
, x11
->xv_port
,
360 ctx
->xv_format
, NULL
, ctx
->image_width
,
362 ctx
->xvimage
[foo
]->data
= malloc(ctx
->xvimage
[foo
]->data_size
);
363 XSync(x11
->display
, False
);
365 memset(ctx
->xvimage
[foo
]->data
, 128, ctx
->xvimage
[foo
]->data_size
);
369 static void deallocate_xvimage(struct vo
*vo
, int foo
)
371 struct xvctx
*ctx
= vo
->priv
;
373 if (ctx
->Shmem_Flag
) {
374 XShmDetach(vo
->x11
->display
, &ctx
->Shminfo
[foo
]);
375 shmdt(ctx
->Shminfo
[foo
].shmaddr
);
379 free(ctx
->xvimage
[foo
]->data
);
381 XFree(ctx
->xvimage
[foo
]);
383 XSync(vo
->x11
->display
, False
);
387 static inline void put_xvimage(struct vo
*vo
, XvImage
*xvi
)
389 struct xvctx
*ctx
= vo
->priv
;
390 struct vo_x11_state
*x11
= vo
->x11
;
391 struct vo_rect
*src
= &ctx
->src_rect
;
392 struct vo_rect
*dst
= &ctx
->dst_rect
;
394 if (ctx
->Shmem_Flag
) {
395 XvShmPutImage(x11
->display
, x11
->xv_port
, x11
->window
, x11
->vo_gc
, xvi
,
396 src
->left
, src
->top
, src
->width
, src
->height
,
397 dst
->left
, dst
->top
, dst
->width
, dst
->height
,
402 XvPutImage(x11
->display
, x11
->xv_port
, x11
->window
, x11
->vo_gc
, xvi
,
403 src
->left
, src
->top
, src
->width
, src
->height
,
404 dst
->left
, dst
->top
, dst
->width
, dst
->height
);
408 // Only copies luma for planar formats as draw_alpha doesn't change others */
409 static void copy_backup_image(struct vo
*vo
, int dest
, int src
)
411 struct xvctx
*ctx
= vo
->priv
;
413 XvImage
*vb
= ctx
->xvimage
[dest
];
414 XvImage
*cp
= ctx
->xvimage
[src
];
415 memcpy_pic(vb
->data
+ vb
->offsets
[0], cp
->data
+ cp
->offsets
[0],
416 vb
->width
, vb
->height
,
417 vb
->pitches
[0], cp
->pitches
[0]);
420 static void check_events(struct vo
*vo
)
422 struct xvctx
*ctx
= vo
->priv
;
423 int e
= vo_x11_check_events(vo
);
425 if (e
& VO_EVENT_EXPOSE
|| e
& VO_EVENT_RESIZE
)
428 if ((e
& VO_EVENT_EXPOSE
|| e
& VO_EVENT_RESIZE
) && ctx
->is_paused
) {
429 /* did we already draw a buffer */
430 if (ctx
->visible_buf
!= -1) {
431 /* redraw the last visible buffer */
432 put_xvimage(vo
, ctx
->xvimage
[ctx
->visible_buf
]);
437 static void draw_osd(struct vo
*vo
, struct osd_state
*osd
)
439 struct xvctx
*ctx
= vo
->priv
;
441 ctx
->osd_objects_drawn
= 0;
444 ctx
->image_width
* vo
->panscan_x
/ (vo
->dwidth
+
446 ctx
->image_height
, ctx
->draw_alpha_fnc
, vo
);
447 if (ctx
->osd_objects_drawn
)
448 ctx
->unchanged_next_image
= false;
451 static int redraw_osd(struct vo
*vo
, struct osd_state
*osd
)
453 struct xvctx
*ctx
= vo
->priv
;
455 if (ctx
->have_visible_image_copy
)
456 copy_backup_image(vo
, ctx
->visible_buf
, ctx
->num_buffers
);
457 else if (ctx
->unchanged_visible_image
) {
458 copy_backup_image(vo
, ctx
->num_buffers
, ctx
->visible_buf
);
459 ctx
->have_visible_image_copy
= true;
463 int temp
= ctx
->current_buf
;
464 ctx
->current_buf
= ctx
->visible_buf
;
466 ctx
->current_buf
= temp
;
467 put_xvimage(vo
, ctx
->xvimage
[ctx
->visible_buf
]);
471 static void flip_page(struct vo
*vo
)
473 struct xvctx
*ctx
= vo
->priv
;
474 put_xvimage(vo
, ctx
->xvimage
[ctx
->current_buf
]);
476 /* remember the currently visible buffer */
477 ctx
->visible_buf
= ctx
->current_buf
;
479 ctx
->have_visible_image_copy
= ctx
->have_next_image_copy
;
480 ctx
->have_next_image_copy
= false;
481 ctx
->unchanged_visible_image
= ctx
->unchanged_next_image
;
482 ctx
->unchanged_next_image
= false;
484 if (ctx
->num_buffers
> 1) {
485 ctx
->current_buf
= vo_directrendering
? 0 : ((ctx
->current_buf
+ 1) %
487 XFlush(vo
->x11
->display
);
489 XSync(vo
->x11
->display
, False
);
493 static int draw_slice(struct vo
*vo
, uint8_t *image
[], int stride
[], int w
,
496 struct xvctx
*ctx
= vo
->priv
;
498 XvImage
*current_image
= ctx
->xvimage
[ctx
->current_buf
];
500 dst
= current_image
->data
+ current_image
->offsets
[0]
501 + current_image
->pitches
[0] * y
+ x
;
502 memcpy_pic(dst
, image
[0], w
, h
, current_image
->pitches
[0], stride
[0]);
509 dst
= current_image
->data
+ current_image
->offsets
[1]
510 + current_image
->pitches
[1] * y
+ x
;
511 if (ctx
->image_format
!= IMGFMT_YV12
)
512 memcpy_pic(dst
, image
[1], w
, h
, current_image
->pitches
[1], stride
[1]);
514 memcpy_pic(dst
, image
[2], w
, h
, current_image
->pitches
[1], stride
[2]);
516 dst
= current_image
->data
+ current_image
->offsets
[2]
517 + current_image
->pitches
[2] * y
+ x
;
518 if (ctx
->image_format
== IMGFMT_YV12
)
519 memcpy_pic(dst
, image
[1], w
, h
, current_image
->pitches
[1], stride
[1]);
521 memcpy_pic(dst
, image
[2], w
, h
, current_image
->pitches
[1], stride
[2]);
526 static uint32_t draw_image(struct vo
*vo
, mp_image_t
*mpi
)
528 struct xvctx
*ctx
= vo
->priv
;
530 ctx
->have_next_image_copy
= false;
532 if (mpi
->flags
& MP_IMGFLAG_DIRECT
)
534 ctx
->current_buf
= (int) (mpi
->priv
); // hack!
535 else if (mpi
->flags
& MP_IMGFLAG_DRAW_CALLBACK
)
537 else if (mpi
->flags
& MP_IMGFLAG_PLANAR
)
538 draw_slice(vo
, mpi
->planes
, mpi
->stride
, mpi
->w
, mpi
->h
, 0, 0);
539 else if (mpi
->flags
& MP_IMGFLAG_YUV
)
541 memcpy_pic(ctx
->xvimage
[ctx
->current_buf
]->data
+
542 ctx
->xvimage
[ctx
->current_buf
]->offsets
[0], mpi
->planes
[0],
543 mpi
->w
* (mpi
->bpp
/ 8), mpi
->h
,
544 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0], mpi
->stride
[0]);
548 if (ctx
->is_paused
) {
549 copy_backup_image(vo
, ctx
->num_buffers
, ctx
->current_buf
);
550 ctx
->have_next_image_copy
= true;
552 ctx
->unchanged_next_image
= true;
556 static uint32_t get_image(struct xvctx
*ctx
, mp_image_t
*mpi
)
558 // we shouldn't change current_buf unless we do DR!
559 int buf
= ctx
->current_buf
;
561 if (mpi
->type
== MP_IMGTYPE_STATIC
&& ctx
->num_buffers
> 1)
562 return VO_FALSE
; // it is not static
563 if (mpi
->imgfmt
!= ctx
->image_format
)
564 return VO_FALSE
; // needs conversion :(
565 if (mpi
->flags
& MP_IMGFLAG_READABLE
566 && (mpi
->type
== MP_IMGTYPE_IPB
|| mpi
->type
== MP_IMGTYPE_IP
)) {
567 // reference (I/P) frame of IP or IPB:
568 if (ctx
->num_buffers
< 2)
569 return VO_FALSE
; // not enough
570 ctx
->current_ip_buf
^= 1;
571 // for IPB with 2 buffers we can DR only one of the 2 P frames:
572 if (mpi
->type
== MP_IMGTYPE_IPB
&& ctx
->num_buffers
< 3
573 && ctx
->current_ip_buf
)
575 buf
= ctx
->current_ip_buf
;
576 if (mpi
->type
== MP_IMGTYPE_IPB
)
577 ++buf
; // preserve space for B
579 if (mpi
->height
> ctx
->xvimage
[buf
]->height
)
580 return VO_FALSE
; //buffer to small
581 if (mpi
->width
* (mpi
->bpp
/ 8) > ctx
->xvimage
[buf
]->pitches
[0])
582 return VO_FALSE
; //buffer to small
583 if ((mpi
->flags
& (MP_IMGFLAG_ACCEPT_STRIDE
| MP_IMGFLAG_ACCEPT_WIDTH
))
584 || (mpi
->width
* (mpi
->bpp
/ 8) == ctx
->xvimage
[buf
]->pitches
[0])) {
585 ctx
->current_buf
= buf
;
586 XvImage
*current_image
= ctx
->xvimage
[ctx
->current_buf
];
587 mpi
->planes
[0] = current_image
->data
+ current_image
->offsets
[0];
588 mpi
->stride
[0] = current_image
->pitches
[0];
589 mpi
->width
= mpi
->stride
[0] / (mpi
->bpp
/ 8);
590 if (mpi
->flags
& MP_IMGFLAG_PLANAR
) {
591 if (mpi
->flags
& MP_IMGFLAG_SWAPPED
) {
593 mpi
->planes
[1] = current_image
->data
594 + current_image
->offsets
[1];
595 mpi
->planes
[2] = current_image
->data
596 + current_image
->offsets
[2];
597 mpi
->stride
[1] = current_image
->pitches
[1];
598 mpi
->stride
[2] = current_image
->pitches
[2];
601 mpi
->planes
[1] = current_image
->data
602 + current_image
->offsets
[2];
603 mpi
->planes
[2] = current_image
->data
604 + current_image
->offsets
[1];
605 mpi
->stride
[1] = current_image
->pitches
[2];
606 mpi
->stride
[2] = current_image
->pitches
[1];
609 mpi
->flags
|= MP_IMGFLAG_DIRECT
;
610 mpi
->priv
= (void *) ctx
->current_buf
;
616 static int query_format(struct xvctx
*ctx
, uint32_t format
)
619 int flag
= VFCAP_CSP_SUPPORTED
| VFCAP_CSP_SUPPORTED_BY_HW
| VFCAP_HWSCALE_UP
| VFCAP_HWSCALE_DOWN
| VFCAP_OSD
| VFCAP_ACCEPT_STRIDE
; // FIXME! check for DOWN
621 /* check image formats */
622 for (i
= 0; i
< ctx
->formats
; i
++) {
623 if (ctx
->fo
[i
].id
== format
)
624 return flag
; //xv_format = fo[i].id;
629 static void uninit(struct vo
*vo
)
631 struct xvctx
*ctx
= vo
->priv
;
634 ctx
->visible_buf
= -1;
636 XvFreeAdaptorInfo(ctx
->ai
);
642 for (i
= 0; i
< ctx
->total_buffers
; i
++)
643 deallocate_xvimage(vo
, i
);
645 if (ctx
->mode_switched
)
648 if (ctx
->event_fd_registered
)
649 mp_input_rm_key_fd(vo
->input_ctx
, ConnectionNumber(vo
->x11
->display
));
650 // uninit() shouldn't get called unless initialization went past vo_init()
654 static int x11_fd_callback(void *ctx
, int fd
)
658 return mplayer_get_key(vo
->key_fifo
, 0);
661 static int preinit(struct vo
*vo
, const char *arg
)
666 strarg_t ck_src_arg
= { 0, NULL
};
667 strarg_t ck_method_arg
= { 0, NULL
};
668 struct xvctx
*ctx
= talloc_zero(vo
, struct xvctx
);
670 struct vo_x11_state
*x11
= vo
->x11
;
673 const opt_t subopts
[] =
675 /* name arg type arg var test */
676 { "port", OPT_ARG_INT
, &x11
->xv_port
, int_pos
},
677 { "adaptor", OPT_ARG_INT
, &xv_adaptor
, int_non_neg
},
678 { "ck", OPT_ARG_STR
, &ck_src_arg
, xv_test_ck
},
679 { "ck-method", OPT_ARG_STR
, &ck_method_arg
, xv_test_ckm
},
685 /* parse suboptions */
686 if (subopt_parse(arg
, subopts
) != 0) {
690 /* modify colorkey settings according to the given options */
691 xv_setup_colorkeyhandling(vo
, ck_method_arg
.str
, ck_src_arg
.str
);
696 /* check for Xvideo extension */
697 unsigned int ver
, rel
, req
, ev
, err
;
698 if (Success
!= XvQueryExtension(x11
->display
, &ver
, &rel
, &req
, &ev
, &err
)) {
699 mp_tmsg(MSGT_VO
, MSGL_ERR
, "[VO_XV] Sorry, Xv not supported by this X11 version/driver\n[VO_XV] ******** Try with -vo x11 or -vo sdl *********\n");
703 /* check for Xvideo support */
705 XvQueryAdaptors(x11
->display
, DefaultRootWindow(x11
->display
),
706 &ctx
->adaptors
, &ctx
->ai
)) {
707 mp_tmsg(MSGT_VO
, MSGL_ERR
, "[VO_XV] XvQueryAdaptors failed.\n");
715 for (port_found
= 0, i
= 0; !port_found
&& i
< ctx
->adaptors
; i
++) {
716 if ((ctx
->ai
[i
].type
& XvInputMask
)
717 && (ctx
->ai
[i
].type
& XvImageMask
)) {
718 for (xv_p
= ctx
->ai
[i
].base_id
;
719 xv_p
< ctx
->ai
[i
].base_id
+ ctx
->ai
[i
].num_ports
;
721 if (xv_p
== x11
->xv_port
) {
729 if (XvGrabPort(x11
->display
, x11
->xv_port
, CurrentTime
))
732 mp_tmsg(MSGT_VO
, MSGL_WARN
, "[VO_XV] Invalid port parameter, overriding with port 0.\n");
737 for (i
= 0; i
< ctx
->adaptors
&& x11
->xv_port
== 0; i
++) {
738 /* check if adaptor number has been specified */
739 if (xv_adaptor
!= -1 && xv_adaptor
!= i
)
742 if ((ctx
->ai
[i
].type
& XvInputMask
) && (ctx
->ai
[i
].type
& XvImageMask
)) {
743 for (xv_p
= ctx
->ai
[i
].base_id
;
744 xv_p
< ctx
->ai
[i
].base_id
+ ctx
->ai
[i
].num_ports
; ++xv_p
)
745 if (!XvGrabPort(x11
->display
, xv_p
, CurrentTime
)) {
747 mp_msg(MSGT_VO
, MSGL_V
,
748 "[VO_XV] Using Xv Adapter #%d (%s)\n",
752 mp_tmsg(MSGT_VO
, MSGL_WARN
, "[VO_XV] Could not grab port %i.\n",
760 mp_tmsg(MSGT_VO
, MSGL_ERR
,
761 "[VO_XV] Could not find free Xvideo port - maybe another process is already\n"\
762 "[VO_XV] using it. Close all video applications, and try again. If that does\n"\
763 "[VO_XV] not help, see 'mplayer -vo help' for other (non-xv) video out drivers.\n");
765 mp_tmsg(MSGT_VO
, MSGL_ERR
,
766 "[VO_XV] It seems there is no Xvideo support for your video card available.\n"\
767 "[VO_XV] Run 'xvinfo' to verify its Xv support and read\n"\
768 "[VO_XV] DOCS/HTML/en/video.html#xv!\n"\
769 "[VO_XV] See 'mplayer -vo help' for other (non-xv) video out drivers.\n"\
770 "[VO_XV] Try -vo x11.\n");
774 if (!vo_xv_init_colorkey(vo
)) {
775 goto error
; // bail out, colorkey setup failed
777 vo_xv_enable_vsync(vo
);
778 vo_xv_get_max_img_dim(vo
, &ctx
->max_width
, &ctx
->max_height
);
780 ctx
->fo
= XvListImageFormats(x11
->display
, x11
->xv_port
,
781 (int *) &ctx
->formats
);
783 mp_input_add_key_fd(vo
->input_ctx
, ConnectionNumber(x11
->display
), 1,
784 x11_fd_callback
, NULL
, vo
);
785 ctx
->event_fd_registered
= 1;
789 uninit(vo
); // free resources
793 static int control(struct vo
*vo
, uint32_t request
, void *data
)
795 struct xvctx
*ctx
= vo
->priv
;
796 struct vo_x11_state
*x11
= vo
->x11
;
799 return (ctx
->is_paused
= 1);
801 return (ctx
->is_paused
= 0);
802 case VOCTRL_QUERY_FORMAT
:
803 return query_format(ctx
, *((uint32_t *) data
));
804 case VOCTRL_GET_IMAGE
:
805 return get_image(ctx
, data
);
806 case VOCTRL_DRAW_IMAGE
:
807 return draw_image(vo
, data
);
808 case VOCTRL_GET_PANSCAN
:
810 case VOCTRL_FULLSCREEN
:
811 vo_x11_fullscreen(vo
);
812 /* indended, fallthrough to update panscan on fullscreen/windowed switch */
813 case VOCTRL_SET_PANSCAN
:
816 case VOCTRL_SET_EQUALIZER
:
818 struct voctrl_set_equalizer_args
*args
= data
;
819 return vo_xv_set_eq(vo
, x11
->xv_port
, args
->name
, args
->value
);
821 case VOCTRL_GET_EQUALIZER
:
823 struct voctrl_get_equalizer_args
*args
= data
;
824 return vo_xv_get_eq(vo
, x11
->xv_port
, args
->name
, args
->valueptr
);
826 case VOCTRL_SET_YUV_COLORSPACE
:;
827 int given_cspc
= *(int *)data
% 2;
828 return vo_xv_set_eq(vo
, x11
->xv_port
, "bt_709", given_cspc
* 200 - 100);
829 case VOCTRL_GET_YUV_COLORSPACE
:;
831 if (!vo_xv_get_eq(vo
, x11
->xv_port
, "bt_709", &bt709_enabled
))
833 *(int *)data
= bt709_enabled
== 100;
838 case VOCTRL_UPDATE_SCREENINFO
:
839 update_xinerama_info(vo
);
841 case VOCTRL_REDRAW_OSD
:
842 return redraw_osd(vo
, data
);
847 const struct vo_driver video_out_xv
= {
853 .draw_slice
= draw_slice
,
854 .draw_osd
= draw_osd
,
855 .flip_page
= flip_page
,
856 .check_events
= check_events
,