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)
48 #include "video_out.h"
49 #include "libmpcodecs/vfcap.h"
50 #include "libmpcodecs/mp_image.h"
54 #include <X11/Xutil.h>
57 #include "x11_common.h"
59 #include "fastmemcpy.h"
63 #include "subopt-helper.h"
65 #include "input/input.h"
68 #include "libavutil/common.h"
70 static const vo_info_t info
= {
73 "Gerd Knorr <kraxel@goldbach.in-berlin.de> and others",
80 #include <X11/extensions/XShm.h>
83 // Note: depends on the inclusion of X11/extensions/XShm.h
84 #include <X11/extensions/Xv.h>
85 #include <X11/extensions/Xvlib.h>
89 XvImageFormatValues
*fo
;
90 unsigned int formats
, adaptors
, xv_format
;
95 int have_visible_image_copy
;
96 int have_next_image_copy
;
97 int unchanged_visible_image
;
98 int unchanged_next_image
;
100 XvImage
*xvimage
[NUM_BUFFERS
+ 1];
101 uint32_t image_width
;
102 uint32_t image_height
;
103 uint32_t image_format
;
105 struct vo_rect src_rect
;
106 struct vo_rect dst_rect
;
107 uint32_t max_width
, max_height
; // zero means: not set
108 int event_fd_registered
; // for uninit called from preinit
110 int osd_objects_drawn
;
111 void (*draw_alpha_fnc
)(void *ctx
, int x0
, int y0
, int w
, int h
,
112 unsigned char *src
, unsigned char *srca
,
115 XShmSegmentInfo Shminfo
[NUM_BUFFERS
+ 1];
120 static void allocate_xvimage(struct vo
*, int);
123 static void draw_alpha_yv12(void *p
, int x0
, int y0
, int w
, int h
,
124 unsigned char *src
, unsigned char *srca
,
128 struct xvctx
*ctx
= vo
->priv
;
129 x0
+= ctx
->image_width
* (vo
->panscan_x
>> 1)
130 / (vo
->dwidth
+ vo
->panscan_x
);
131 vo_draw_alpha_yv12(w
, h
, src
, srca
, stride
,
132 ctx
->xvimage
[ctx
->current_buf
]->data
+
133 ctx
->xvimage
[ctx
->current_buf
]->offsets
[0] +
134 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0] * y0
+ x0
,
135 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0]);
136 ctx
->osd_objects_drawn
++;
139 static void draw_alpha_yuy2(void *p
, int x0
, int y0
, int w
, int h
,
140 unsigned char *src
, unsigned char *srca
,
144 struct xvctx
*ctx
= vo
->priv
;
145 x0
+= ctx
->image_width
* (vo
->panscan_x
>> 1)
146 / (vo
->dwidth
+ vo
->panscan_x
);
147 vo_draw_alpha_yuy2(w
, h
, src
, srca
, stride
,
148 ctx
->xvimage
[ctx
->current_buf
]->data
+
149 ctx
->xvimage
[ctx
->current_buf
]->offsets
[0] +
150 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0] * y0
+ 2 * x0
,
151 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0]);
152 ctx
->osd_objects_drawn
++;
155 static void draw_alpha_uyvy(void *p
, int x0
, int y0
, int w
, int h
,
156 unsigned char *src
, unsigned char *srca
,
160 struct xvctx
*ctx
= vo
->priv
;
161 x0
+= ctx
->image_width
* (vo
->panscan_x
>> 1)
162 / (vo
->dwidth
+ vo
->panscan_x
);
163 vo_draw_alpha_yuy2(w
, h
, src
, srca
, stride
,
164 ctx
->xvimage
[ctx
->current_buf
]->data
+
165 ctx
->xvimage
[ctx
->current_buf
]->offsets
[0] +
166 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0] * y0
+ 2 * x0
+ 1,
167 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0]);
168 ctx
->osd_objects_drawn
++;
171 static void draw_alpha_null(void *p
, int x0
, int y0
, int w
, int h
,
172 unsigned char *src
, unsigned char *srca
,
178 static void deallocate_xvimage(struct vo
*vo
, int foo
);
180 static void resize(struct vo
*vo
)
182 struct xvctx
*ctx
= vo
->priv
;
184 calc_src_dst_rects(vo
, ctx
->image_width
, ctx
->image_height
, &ctx
->src_rect
,
185 &ctx
->dst_rect
, NULL
, NULL
);
186 struct vo_rect
*dst
= &ctx
->dst_rect
;
187 vo_x11_clearwindow_part(vo
, vo
->x11
->window
, dst
->width
, dst
->height
, 1);
188 vo_xv_draw_colorkey(vo
, dst
->left
, dst
->top
, dst
->width
, dst
->height
);
192 * connect to server, create and map window,
193 * allocate colors and (shared) memory
195 static int config(struct vo
*vo
, uint32_t width
, uint32_t height
,
196 uint32_t d_width
, uint32_t d_height
, uint32_t flags
,
197 char *title
, uint32_t format
)
199 struct vo_x11_state
*x11
= vo
->x11
;
201 XSetWindowAttributes xswa
;
202 XWindowAttributes attribs
;
203 unsigned long xswamask
;
205 struct xvctx
*ctx
= vo
->priv
;
208 ctx
->image_height
= height
;
209 ctx
->image_width
= width
;
210 ctx
->image_format
= format
;
212 if ((ctx
->max_width
!= 0 && ctx
->max_height
!= 0)
213 && (ctx
->image_width
> ctx
->max_width
214 || ctx
->image_height
> ctx
->max_height
)) {
215 mp_tmsg(MSGT_VO
, MSGL_ERR
, "Source image dimensions are too high: %ux%u (maximum is %ux%u)\n",
216 ctx
->image_width
, ctx
->image_height
, ctx
->max_width
,
221 ctx
->visible_buf
= -1;
222 ctx
->have_visible_image_copy
= false;
223 ctx
->have_next_image_copy
= false;
225 /* check image formats */
227 for (i
= 0; i
< ctx
->formats
; i
++) {
228 mp_msg(MSGT_VO
, MSGL_V
, "Xvideo image format: 0x%x (%4.4s) %s\n",
229 ctx
->fo
[i
].id
, (char *) &ctx
->fo
[i
].id
,
230 (ctx
->fo
[i
].format
== XvPacked
) ? "packed" : "planar");
231 if (ctx
->fo
[i
].id
== format
)
232 ctx
->xv_format
= ctx
->fo
[i
].id
;
239 int vm
= flags
& VOFLAG_MODESWITCHING
;
242 ctx
->mode_switched
= 1;
245 XGetWindowAttributes(x11
->display
, DefaultRootWindow(x11
->display
),
247 depth
= attribs
.depth
;
248 if (depth
!= 15 && depth
!= 16 && depth
!= 24 && depth
!= 32)
250 XMatchVisualInfo(x11
->display
, x11
->screen
, depth
, TrueColor
, &vinfo
);
252 xswa
.background_pixel
= 0;
253 if (x11
->xv_ck_info
.method
== CK_METHOD_BACKGROUND
)
254 xswa
.background_pixel
= x11
->xv_colorkey
;
255 xswa
.border_pixel
= 0;
256 xswamask
= CWBackPixel
| CWBorderPixel
;
258 vo_x11_create_vo_window(vo
, &vinfo
, vo
->dx
, vo
->dy
, vo
->dwidth
,
259 vo
->dheight
, flags
, CopyFromParent
, "xv",
261 XChangeWindowAttributes(x11
->display
, x11
->window
, xswamask
, &xswa
);
265 /* Grab the mouse pointer in our window */
267 XGrabPointer(x11
->display
, x11
->window
, True
, 0, GrabModeAsync
,
268 GrabModeAsync
, x11
->window
, None
, CurrentTime
);
269 XSetInputFocus(x11
->display
, x11
->window
, RevertToNone
,
275 mp_msg(MSGT_VO
, MSGL_V
, "using Xvideo port %d for hw scaling\n",
278 switch (ctx
->xv_format
) {
282 ctx
->draw_alpha_fnc
= draw_alpha_yv12
;
286 ctx
->draw_alpha_fnc
= draw_alpha_yuy2
;
289 ctx
->draw_alpha_fnc
= draw_alpha_uyvy
;
292 ctx
->draw_alpha_fnc
= draw_alpha_null
;
295 // In case config has been called before
296 for (i
= 0; i
< ctx
->total_buffers
; i
++)
297 deallocate_xvimage(vo
, i
);
300 vo_doublebuffering
? (vo_directrendering
? NUM_BUFFERS
: 2) : 1;
301 ctx
->total_buffers
= ctx
->num_buffers
+ 1;
303 for (i
= 0; i
< ctx
->total_buffers
; i
++)
304 allocate_xvimage(vo
, i
);
306 ctx
->current_buf
= 0;
307 ctx
->current_ip_buf
= 0;
315 static void allocate_xvimage(struct vo
*vo
, int foo
)
317 struct xvctx
*ctx
= vo
->priv
;
318 struct vo_x11_state
*x11
= vo
->x11
;
320 * allocate XvImages. FIXME: no error checking, without
321 * mit-shm this will bomb... trzing to fix ::atmos
324 if (x11
->display_is_local
&& XShmQueryExtension(x11
->display
))
328 mp_tmsg(MSGT_VO
, MSGL_INFO
, "[VO_XV] Shared memory not supported\nReverting to normal Xv.\n");
330 if (ctx
->Shmem_Flag
) {
332 (XvImage
*) XvShmCreateImage(x11
->display
, x11
->xv_port
,
333 ctx
->xv_format
, NULL
,
334 ctx
->image_width
, ctx
->image_height
,
337 ctx
->Shminfo
[foo
].shmid
= shmget(IPC_PRIVATE
,
338 ctx
->xvimage
[foo
]->data_size
,
340 ctx
->Shminfo
[foo
].shmaddr
= (char *) shmat(ctx
->Shminfo
[foo
].shmid
, 0,
342 ctx
->Shminfo
[foo
].readOnly
= False
;
344 ctx
->xvimage
[foo
]->data
= ctx
->Shminfo
[foo
].shmaddr
;
345 XShmAttach(x11
->display
, &ctx
->Shminfo
[foo
]);
346 XSync(x11
->display
, False
);
347 shmctl(ctx
->Shminfo
[foo
].shmid
, IPC_RMID
, 0);
352 (XvImage
*) XvCreateImage(x11
->display
, x11
->xv_port
,
353 ctx
->xv_format
, NULL
, ctx
->image_width
,
355 ctx
->xvimage
[foo
]->data
= malloc(ctx
->xvimage
[foo
]->data_size
);
356 XSync(x11
->display
, False
);
358 memset(ctx
->xvimage
[foo
]->data
, 128, ctx
->xvimage
[foo
]->data_size
);
362 static void deallocate_xvimage(struct vo
*vo
, int foo
)
364 struct xvctx
*ctx
= vo
->priv
;
366 if (ctx
->Shmem_Flag
) {
367 XShmDetach(vo
->x11
->display
, &ctx
->Shminfo
[foo
]);
368 shmdt(ctx
->Shminfo
[foo
].shmaddr
);
372 free(ctx
->xvimage
[foo
]->data
);
374 XFree(ctx
->xvimage
[foo
]);
376 XSync(vo
->x11
->display
, False
);
380 static inline void put_xvimage(struct vo
*vo
, XvImage
*xvi
)
382 struct xvctx
*ctx
= vo
->priv
;
383 struct vo_x11_state
*x11
= vo
->x11
;
384 struct vo_rect
*src
= &ctx
->src_rect
;
385 struct vo_rect
*dst
= &ctx
->dst_rect
;
387 if (ctx
->Shmem_Flag
) {
388 XvShmPutImage(x11
->display
, x11
->xv_port
, x11
->window
, x11
->vo_gc
, xvi
,
389 src
->left
, src
->top
, src
->width
, src
->height
,
390 dst
->left
, dst
->top
, dst
->width
, dst
->height
,
395 XvPutImage(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
);
401 // Only copies luma for planar formats as draw_alpha doesn't change others */
402 static void copy_backup_image(struct vo
*vo
, int dest
, int src
)
404 struct xvctx
*ctx
= vo
->priv
;
406 XvImage
*vb
= ctx
->xvimage
[dest
];
407 XvImage
*cp
= ctx
->xvimage
[src
];
408 memcpy_pic(vb
->data
+ vb
->offsets
[0], cp
->data
+ cp
->offsets
[0],
409 vb
->width
, vb
->height
,
410 vb
->pitches
[0], cp
->pitches
[0]);
413 static void check_events(struct vo
*vo
)
415 struct xvctx
*ctx
= vo
->priv
;
416 int e
= vo_x11_check_events(vo
);
418 if (e
& VO_EVENT_EXPOSE
|| e
& VO_EVENT_RESIZE
)
421 if ((e
& VO_EVENT_EXPOSE
|| e
& VO_EVENT_RESIZE
) && ctx
->is_paused
) {
422 /* did we already draw a buffer */
423 if (ctx
->visible_buf
!= -1) {
424 /* redraw the last visible buffer */
425 put_xvimage(vo
, ctx
->xvimage
[ctx
->visible_buf
]);
430 static void draw_osd(struct vo
*vo
, struct osd_state
*osd
)
432 struct xvctx
*ctx
= vo
->priv
;
434 ctx
->osd_objects_drawn
= 0;
437 ctx
->image_width
* vo
->panscan_x
/ (vo
->dwidth
+
439 ctx
->image_height
, ctx
->draw_alpha_fnc
, vo
);
440 if (ctx
->osd_objects_drawn
)
441 ctx
->unchanged_next_image
= false;
444 static int redraw_osd(struct vo
*vo
, struct osd_state
*osd
)
446 struct xvctx
*ctx
= vo
->priv
;
448 if (ctx
->have_visible_image_copy
)
449 copy_backup_image(vo
, ctx
->visible_buf
, ctx
->num_buffers
);
450 else if (ctx
->unchanged_visible_image
) {
451 copy_backup_image(vo
, ctx
->num_buffers
, ctx
->visible_buf
);
452 ctx
->have_visible_image_copy
= true;
456 int temp
= ctx
->current_buf
;
457 ctx
->current_buf
= ctx
->visible_buf
;
459 ctx
->current_buf
= temp
;
460 put_xvimage(vo
, ctx
->xvimage
[ctx
->visible_buf
]);
464 static void flip_page(struct vo
*vo
)
466 struct xvctx
*ctx
= vo
->priv
;
467 put_xvimage(vo
, ctx
->xvimage
[ctx
->current_buf
]);
469 /* remember the currently visible buffer */
470 ctx
->visible_buf
= ctx
->current_buf
;
472 ctx
->have_visible_image_copy
= ctx
->have_next_image_copy
;
473 ctx
->have_next_image_copy
= false;
474 ctx
->unchanged_visible_image
= ctx
->unchanged_next_image
;
475 ctx
->unchanged_next_image
= false;
477 if (ctx
->num_buffers
> 1) {
478 ctx
->current_buf
= vo_directrendering
? 0 : ((ctx
->current_buf
+ 1) %
480 XFlush(vo
->x11
->display
);
482 XSync(vo
->x11
->display
, False
);
486 static int draw_slice(struct vo
*vo
, uint8_t *image
[], int stride
[], int w
,
489 struct xvctx
*ctx
= vo
->priv
;
491 XvImage
*current_image
= ctx
->xvimage
[ctx
->current_buf
];
493 dst
= current_image
->data
+ current_image
->offsets
[0]
494 + current_image
->pitches
[0] * y
+ x
;
495 memcpy_pic(dst
, image
[0], w
, h
, current_image
->pitches
[0], stride
[0]);
502 dst
= current_image
->data
+ current_image
->offsets
[1]
503 + current_image
->pitches
[1] * y
+ x
;
504 if (ctx
->image_format
!= IMGFMT_YV12
)
505 memcpy_pic(dst
, image
[1], w
, h
, current_image
->pitches
[1], stride
[1]);
507 memcpy_pic(dst
, image
[2], w
, h
, current_image
->pitches
[1], stride
[2]);
509 dst
= current_image
->data
+ current_image
->offsets
[2]
510 + current_image
->pitches
[2] * 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]);
519 static uint32_t draw_image(struct vo
*vo
, mp_image_t
*mpi
)
521 struct xvctx
*ctx
= vo
->priv
;
523 ctx
->have_next_image_copy
= false;
525 if (mpi
->flags
& MP_IMGFLAG_DIRECT
)
527 ctx
->current_buf
= (int) (mpi
->priv
); // hack!
528 else if (mpi
->flags
& MP_IMGFLAG_DRAW_CALLBACK
)
530 else if (mpi
->flags
& MP_IMGFLAG_PLANAR
)
531 draw_slice(vo
, mpi
->planes
, mpi
->stride
, mpi
->w
, mpi
->h
, 0, 0);
532 else if (mpi
->flags
& MP_IMGFLAG_YUV
)
534 memcpy_pic(ctx
->xvimage
[ctx
->current_buf
]->data
+
535 ctx
->xvimage
[ctx
->current_buf
]->offsets
[0], mpi
->planes
[0],
536 mpi
->w
* (mpi
->bpp
/ 8), mpi
->h
,
537 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0], mpi
->stride
[0]);
541 if (ctx
->is_paused
) {
542 copy_backup_image(vo
, ctx
->num_buffers
, ctx
->current_buf
);
543 ctx
->have_next_image_copy
= true;
545 ctx
->unchanged_next_image
= true;
549 static uint32_t get_image(struct xvctx
*ctx
, mp_image_t
*mpi
)
551 // we shouldn't change current_buf unless we do DR!
552 int buf
= ctx
->current_buf
;
554 if (mpi
->type
== MP_IMGTYPE_STATIC
&& ctx
->num_buffers
> 1)
555 return VO_FALSE
; // it is not static
556 if (mpi
->imgfmt
!= ctx
->image_format
)
557 return VO_FALSE
; // needs conversion :(
558 if (mpi
->flags
& MP_IMGFLAG_READABLE
559 && (mpi
->type
== MP_IMGTYPE_IPB
|| mpi
->type
== MP_IMGTYPE_IP
)) {
560 // reference (I/P) frame of IP or IPB:
561 if (ctx
->num_buffers
< 2)
562 return VO_FALSE
; // not enough
563 ctx
->current_ip_buf
^= 1;
564 // for IPB with 2 buffers we can DR only one of the 2 P frames:
565 if (mpi
->type
== MP_IMGTYPE_IPB
&& ctx
->num_buffers
< 3
566 && ctx
->current_ip_buf
)
568 buf
= ctx
->current_ip_buf
;
569 if (mpi
->type
== MP_IMGTYPE_IPB
)
570 ++buf
; // preserve space for B
572 if (mpi
->height
> ctx
->xvimage
[buf
]->height
)
573 return VO_FALSE
; //buffer to small
574 if (mpi
->width
* (mpi
->bpp
/ 8) > ctx
->xvimage
[buf
]->pitches
[0])
575 return VO_FALSE
; //buffer to small
576 if ((mpi
->flags
& (MP_IMGFLAG_ACCEPT_STRIDE
| MP_IMGFLAG_ACCEPT_WIDTH
))
577 || (mpi
->width
* (mpi
->bpp
/ 8) == ctx
->xvimage
[buf
]->pitches
[0])) {
578 ctx
->current_buf
= buf
;
579 XvImage
*current_image
= ctx
->xvimage
[ctx
->current_buf
];
580 mpi
->planes
[0] = current_image
->data
+ current_image
->offsets
[0];
581 mpi
->stride
[0] = current_image
->pitches
[0];
582 mpi
->width
= mpi
->stride
[0] / (mpi
->bpp
/ 8);
583 if (mpi
->flags
& MP_IMGFLAG_PLANAR
) {
584 if (mpi
->flags
& MP_IMGFLAG_SWAPPED
) {
586 mpi
->planes
[1] = current_image
->data
587 + current_image
->offsets
[1];
588 mpi
->planes
[2] = current_image
->data
589 + current_image
->offsets
[2];
590 mpi
->stride
[1] = current_image
->pitches
[1];
591 mpi
->stride
[2] = current_image
->pitches
[2];
594 mpi
->planes
[1] = current_image
->data
595 + current_image
->offsets
[2];
596 mpi
->planes
[2] = current_image
->data
597 + current_image
->offsets
[1];
598 mpi
->stride
[1] = current_image
->pitches
[2];
599 mpi
->stride
[2] = current_image
->pitches
[1];
602 mpi
->flags
|= MP_IMGFLAG_DIRECT
;
603 mpi
->priv
= (void *) ctx
->current_buf
;
609 static int query_format(struct xvctx
*ctx
, uint32_t format
)
612 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
614 /* check image formats */
615 for (i
= 0; i
< ctx
->formats
; i
++) {
616 if (ctx
->fo
[i
].id
== format
)
617 return flag
; //xv_format = fo[i].id;
622 static void uninit(struct vo
*vo
)
624 struct xvctx
*ctx
= vo
->priv
;
627 ctx
->visible_buf
= -1;
629 XvFreeAdaptorInfo(ctx
->ai
);
635 for (i
= 0; i
< ctx
->total_buffers
; i
++)
636 deallocate_xvimage(vo
, i
);
638 if (ctx
->mode_switched
)
641 if (ctx
->event_fd_registered
)
642 mp_input_rm_key_fd(vo
->input_ctx
, ConnectionNumber(vo
->x11
->display
));
643 // uninit() shouldn't get called unless initialization went past vo_init()
647 static int x11_fd_callback(void *ctx
, int fd
)
651 return mplayer_get_key(vo
->key_fifo
, 0);
654 static int preinit(struct vo
*vo
, const char *arg
)
659 strarg_t ck_src_arg
= { 0, NULL
};
660 strarg_t ck_method_arg
= { 0, NULL
};
661 struct xvctx
*ctx
= talloc_zero(vo
, struct xvctx
);
663 struct vo_x11_state
*x11
= vo
->x11
;
666 const opt_t subopts
[] =
668 /* name arg type arg var test */
669 { "port", OPT_ARG_INT
, &x11
->xv_port
, int_pos
},
670 { "adaptor", OPT_ARG_INT
, &xv_adaptor
, int_non_neg
},
671 { "ck", OPT_ARG_STR
, &ck_src_arg
, xv_test_ck
},
672 { "ck-method", OPT_ARG_STR
, &ck_method_arg
, xv_test_ckm
},
678 /* parse suboptions */
679 if (subopt_parse(arg
, subopts
) != 0) {
683 /* modify colorkey settings according to the given options */
684 xv_setup_colorkeyhandling(vo
, ck_method_arg
.str
, ck_src_arg
.str
);
689 /* check for Xvideo extension */
690 unsigned int ver
, rel
, req
, ev
, err
;
691 if (Success
!= XvQueryExtension(x11
->display
, &ver
, &rel
, &req
, &ev
, &err
)) {
692 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");
696 /* check for Xvideo support */
698 XvQueryAdaptors(x11
->display
, DefaultRootWindow(x11
->display
),
699 &ctx
->adaptors
, &ctx
->ai
)) {
700 mp_tmsg(MSGT_VO
, MSGL_ERR
, "[VO_XV] XvQueryAdaptors failed.\n");
708 for (port_found
= 0, i
= 0; !port_found
&& i
< ctx
->adaptors
; i
++) {
709 if ((ctx
->ai
[i
].type
& XvInputMask
)
710 && (ctx
->ai
[i
].type
& XvImageMask
)) {
711 for (xv_p
= ctx
->ai
[i
].base_id
;
712 xv_p
< ctx
->ai
[i
].base_id
+ ctx
->ai
[i
].num_ports
;
714 if (xv_p
== x11
->xv_port
) {
722 if (XvGrabPort(x11
->display
, x11
->xv_port
, CurrentTime
))
725 mp_tmsg(MSGT_VO
, MSGL_WARN
, "[VO_XV] Invalid port parameter, overriding with port 0.\n");
730 for (i
= 0; i
< ctx
->adaptors
&& x11
->xv_port
== 0; i
++) {
731 /* check if adaptor number has been specified */
732 if (xv_adaptor
!= -1 && xv_adaptor
!= i
)
735 if ((ctx
->ai
[i
].type
& XvInputMask
) && (ctx
->ai
[i
].type
& XvImageMask
)) {
736 for (xv_p
= ctx
->ai
[i
].base_id
;
737 xv_p
< ctx
->ai
[i
].base_id
+ ctx
->ai
[i
].num_ports
; ++xv_p
)
738 if (!XvGrabPort(x11
->display
, xv_p
, CurrentTime
)) {
740 mp_msg(MSGT_VO
, MSGL_V
,
741 "[VO_XV] Using Xv Adapter #%d (%s)\n",
745 mp_tmsg(MSGT_VO
, MSGL_WARN
, "[VO_XV] Could not grab port %i.\n",
753 mp_tmsg(MSGT_VO
, MSGL_ERR
,
754 "[VO_XV] Could not find free Xvideo port - maybe another process is already\n"\
755 "[VO_XV] using it. Close all video applications, and try again. If that does\n"\
756 "[VO_XV] not help, see 'mplayer -vo help' for other (non-xv) video out drivers.\n");
758 mp_tmsg(MSGT_VO
, MSGL_ERR
,
759 "[VO_XV] It seems there is no Xvideo support for your video card available.\n"\
760 "[VO_XV] Run 'xvinfo' to verify its Xv support and read\n"\
761 "[VO_XV] DOCS/HTML/en/video.html#xv!\n"\
762 "[VO_XV] See 'mplayer -vo help' for other (non-xv) video out drivers.\n"\
763 "[VO_XV] Try -vo x11.\n");
767 if (!vo_xv_init_colorkey(vo
)) {
768 goto error
; // bail out, colorkey setup failed
770 vo_xv_enable_vsync(vo
);
771 vo_xv_get_max_img_dim(vo
, &ctx
->max_width
, &ctx
->max_height
);
773 ctx
->fo
= XvListImageFormats(x11
->display
, x11
->xv_port
,
774 (int *) &ctx
->formats
);
776 mp_input_add_key_fd(vo
->input_ctx
, ConnectionNumber(x11
->display
), 1,
777 x11_fd_callback
, NULL
, vo
);
778 ctx
->event_fd_registered
= 1;
782 uninit(vo
); // free resources
786 static int control(struct vo
*vo
, uint32_t request
, void *data
)
788 struct xvctx
*ctx
= vo
->priv
;
789 struct vo_x11_state
*x11
= vo
->x11
;
792 return (ctx
->is_paused
= 1);
794 return (ctx
->is_paused
= 0);
795 case VOCTRL_QUERY_FORMAT
:
796 return query_format(ctx
, *((uint32_t *) data
));
797 case VOCTRL_GET_IMAGE
:
798 return get_image(ctx
, data
);
799 case VOCTRL_DRAW_IMAGE
:
800 return draw_image(vo
, data
);
801 case VOCTRL_GET_PANSCAN
:
803 case VOCTRL_FULLSCREEN
:
804 vo_x11_fullscreen(vo
);
805 /* indended, fallthrough to update panscan on fullscreen/windowed switch */
806 case VOCTRL_SET_PANSCAN
:
809 case VOCTRL_SET_EQUALIZER
:
811 struct voctrl_set_equalizer_args
*args
= data
;
812 return vo_xv_set_eq(vo
, x11
->xv_port
, args
->name
, args
->value
);
814 case VOCTRL_GET_EQUALIZER
:
816 struct voctrl_get_equalizer_args
*args
= data
;
817 return vo_xv_get_eq(vo
, x11
->xv_port
, args
->name
, args
->valueptr
);
819 case VOCTRL_SET_YUV_COLORSPACE
:;
820 int given_cspc
= *(int *)data
% 2;
821 return vo_xv_set_eq(vo
, x11
->xv_port
, "bt_709", given_cspc
* 200 - 100);
822 case VOCTRL_GET_YUV_COLORSPACE
:;
824 if (!vo_xv_get_eq(vo
, x11
->xv_port
, "bt_709", &bt709_enabled
))
826 *(int *)data
= bt709_enabled
== 100;
831 case VOCTRL_UPDATE_SCREENINFO
:
832 update_xinerama_info(vo
);
834 case VOCTRL_REDRAW_OSD
:
835 return redraw_osd(vo
, data
);
840 const struct vo_driver video_out_xv
= {
846 .draw_slice
= draw_slice
,
847 .draw_osd
= draw_osd
,
848 .flip_page
= flip_page
,
849 .check_events
= check_events
,