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 "libavutil/common.h"
66 static const vo_info_t info
= {
69 "Gerd Knorr <kraxel@goldbach.in-berlin.de> and others",
76 #include <X11/extensions/XShm.h>
79 // Note: depends on the inclusion of X11/extensions/XShm.h
80 #include <X11/extensions/Xv.h>
81 #include <X11/extensions/Xvlib.h>
85 XvImageFormatValues
*fo
;
86 unsigned int formats
, adaptors
, xv_format
;
91 int have_visible_image_copy
;
92 int have_next_image_copy
;
93 int unchanged_visible_image
;
94 int unchanged_next_image
;
96 XvImage
*xvimage
[NUM_BUFFERS
+ 1];
98 uint32_t image_height
;
99 uint32_t image_format
;
101 struct vo_rect src_rect
;
102 struct vo_rect dst_rect
;
103 uint32_t max_width
, max_height
; // zero means: not set
105 int osd_objects_drawn
;
106 void (*draw_alpha_fnc
)(void *ctx
, int x0
, int y0
, int w
, int h
,
107 unsigned char *src
, unsigned char *srca
,
110 XShmSegmentInfo Shminfo
[NUM_BUFFERS
+ 1];
115 static void allocate_xvimage(struct vo
*, int);
118 static void fixup_osd_position(struct vo
*vo
, int *x0
, int *y0
, int *w
, int *h
)
120 struct xvctx
*ctx
= vo
->priv
;
121 *x0
+= ctx
->image_width
* (vo
->panscan_x
>> 1)
122 / (vo
->dwidth
+ vo
->panscan_x
);
123 *w
= av_clip(*w
, 0, ctx
->image_width
);
124 *h
= av_clip(*h
, 0, ctx
->image_height
);
125 *x0
= FFMIN(*x0
, ctx
->image_width
- *w
);
126 *y0
= FFMIN(*y0
, ctx
->image_height
- *h
);
129 static void draw_alpha_yv12(void *p
, int x0
, int y0
, int w
, int h
,
130 unsigned char *src
, unsigned char *srca
,
134 struct xvctx
*ctx
= vo
->priv
;
135 fixup_osd_position(vo
, &x0
, &y0
, &w
, &h
);
136 vo_draw_alpha_yv12(w
, h
, src
, srca
, stride
,
137 ctx
->xvimage
[ctx
->current_buf
]->data
+
138 ctx
->xvimage
[ctx
->current_buf
]->offsets
[0] +
139 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0] * y0
+ x0
,
140 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0]);
141 ctx
->osd_objects_drawn
++;
144 static void draw_alpha_yuy2(void *p
, int x0
, int y0
, int w
, int h
,
145 unsigned char *src
, unsigned char *srca
,
149 struct xvctx
*ctx
= vo
->priv
;
150 fixup_osd_position(vo
, &x0
, &y0
, &w
, &h
);
151 vo_draw_alpha_yuy2(w
, h
, src
, srca
, stride
,
152 ctx
->xvimage
[ctx
->current_buf
]->data
+
153 ctx
->xvimage
[ctx
->current_buf
]->offsets
[0] +
154 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0] * y0
+ 2 * x0
,
155 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0]);
156 ctx
->osd_objects_drawn
++;
159 static void draw_alpha_uyvy(void *p
, int x0
, int y0
, int w
, int h
,
160 unsigned char *src
, unsigned char *srca
,
164 struct xvctx
*ctx
= vo
->priv
;
165 fixup_osd_position(vo
, &x0
, &y0
, &w
, &h
);
166 vo_draw_alpha_yuy2(w
, h
, src
, srca
, stride
,
167 ctx
->xvimage
[ctx
->current_buf
]->data
+
168 ctx
->xvimage
[ctx
->current_buf
]->offsets
[0] +
169 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0] * y0
+ 2 * x0
+ 1,
170 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0]);
171 ctx
->osd_objects_drawn
++;
174 static void draw_alpha_null(void *p
, int x0
, int y0
, int w
, int h
,
175 unsigned char *src
, unsigned char *srca
,
181 static void deallocate_xvimage(struct vo
*vo
, int foo
);
183 static void resize(struct vo
*vo
)
185 struct xvctx
*ctx
= vo
->priv
;
187 calc_src_dst_rects(vo
, ctx
->image_width
, ctx
->image_height
, &ctx
->src_rect
,
188 &ctx
->dst_rect
, NULL
, NULL
);
189 struct vo_rect
*dst
= &ctx
->dst_rect
;
190 vo_x11_clearwindow_part(vo
, vo
->x11
->window
, dst
->width
, dst
->height
, 1);
191 vo_xv_draw_colorkey(vo
, dst
->left
, dst
->top
, dst
->width
, dst
->height
);
195 * connect to server, create and map window,
196 * allocate colors and (shared) memory
198 static int config(struct vo
*vo
, uint32_t width
, uint32_t height
,
199 uint32_t d_width
, uint32_t d_height
, uint32_t flags
,
200 char *title
, uint32_t format
)
202 struct vo_x11_state
*x11
= vo
->x11
;
204 XSetWindowAttributes xswa
;
205 XWindowAttributes attribs
;
206 unsigned long xswamask
;
208 struct xvctx
*ctx
= vo
->priv
;
211 ctx
->image_height
= height
;
212 ctx
->image_width
= width
;
213 ctx
->image_format
= format
;
215 if ((ctx
->max_width
!= 0 && ctx
->max_height
!= 0)
216 && (ctx
->image_width
> ctx
->max_width
217 || ctx
->image_height
> ctx
->max_height
)) {
218 mp_tmsg(MSGT_VO
, MSGL_ERR
, "Source image dimensions are too high: %ux%u (maximum is %ux%u)\n",
219 ctx
->image_width
, ctx
->image_height
, ctx
->max_width
,
224 ctx
->visible_buf
= -1;
225 ctx
->have_visible_image_copy
= false;
226 ctx
->have_next_image_copy
= false;
228 /* check image formats */
230 for (i
= 0; i
< ctx
->formats
; i
++) {
231 mp_msg(MSGT_VO
, MSGL_V
, "Xvideo image format: 0x%x (%4.4s) %s\n",
232 ctx
->fo
[i
].id
, (char *) &ctx
->fo
[i
].id
,
233 (ctx
->fo
[i
].format
== XvPacked
) ? "packed" : "planar");
234 if (ctx
->fo
[i
].id
== format
)
235 ctx
->xv_format
= ctx
->fo
[i
].id
;
242 int vm
= flags
& VOFLAG_MODESWITCHING
;
245 ctx
->mode_switched
= 1;
248 XGetWindowAttributes(x11
->display
, DefaultRootWindow(x11
->display
),
250 depth
= attribs
.depth
;
251 if (depth
!= 15 && depth
!= 16 && depth
!= 24 && depth
!= 32)
253 XMatchVisualInfo(x11
->display
, x11
->screen
, depth
, TrueColor
, &vinfo
);
255 xswa
.border_pixel
= 0;
256 xswamask
= CWBorderPixel
;
257 if (x11
->xv_ck_info
.method
== CK_METHOD_BACKGROUND
) {
258 xswa
.background_pixel
= x11
->xv_colorkey
;
259 xswamask
|= CWBackPixel
;
262 vo_x11_create_vo_window(vo
, &vinfo
, vo
->dx
, vo
->dy
, vo
->dwidth
,
263 vo
->dheight
, flags
, CopyFromParent
, "xv",
265 XChangeWindowAttributes(x11
->display
, x11
->window
, xswamask
, &xswa
);
269 /* Grab the mouse pointer in our window */
271 XGrabPointer(x11
->display
, x11
->window
, True
, 0, GrabModeAsync
,
272 GrabModeAsync
, x11
->window
, None
, CurrentTime
);
273 XSetInputFocus(x11
->display
, x11
->window
, RevertToNone
,
279 mp_msg(MSGT_VO
, MSGL_V
, "using Xvideo port %d for hw scaling\n",
282 switch (ctx
->xv_format
) {
286 ctx
->draw_alpha_fnc
= draw_alpha_yv12
;
290 ctx
->draw_alpha_fnc
= draw_alpha_yuy2
;
293 ctx
->draw_alpha_fnc
= draw_alpha_uyvy
;
296 ctx
->draw_alpha_fnc
= draw_alpha_null
;
299 // In case config has been called before
300 for (i
= 0; i
< ctx
->total_buffers
; i
++)
301 deallocate_xvimage(vo
, i
);
304 vo_doublebuffering
? (vo_directrendering
? NUM_BUFFERS
: 2) : 1;
305 ctx
->total_buffers
= ctx
->num_buffers
+ 1;
307 for (i
= 0; i
< ctx
->total_buffers
; i
++)
308 allocate_xvimage(vo
, i
);
310 ctx
->current_buf
= 0;
311 ctx
->current_ip_buf
= 0;
319 static void allocate_xvimage(struct vo
*vo
, int foo
)
321 struct xvctx
*ctx
= vo
->priv
;
322 struct vo_x11_state
*x11
= vo
->x11
;
324 * allocate XvImages. FIXME: no error checking, without
325 * mit-shm this will bomb... trzing to fix ::atmos
328 if (x11
->display_is_local
&& XShmQueryExtension(x11
->display
))
332 mp_tmsg(MSGT_VO
, MSGL_INFO
, "[VO_XV] Shared memory not supported\nReverting to normal Xv.\n");
334 if (ctx
->Shmem_Flag
) {
336 (XvImage
*) XvShmCreateImage(x11
->display
, x11
->xv_port
,
337 ctx
->xv_format
, NULL
,
338 ctx
->image_width
, ctx
->image_height
,
341 ctx
->Shminfo
[foo
].shmid
= shmget(IPC_PRIVATE
,
342 ctx
->xvimage
[foo
]->data_size
,
344 ctx
->Shminfo
[foo
].shmaddr
= (char *) shmat(ctx
->Shminfo
[foo
].shmid
, 0,
346 ctx
->Shminfo
[foo
].readOnly
= False
;
348 ctx
->xvimage
[foo
]->data
= ctx
->Shminfo
[foo
].shmaddr
;
349 XShmAttach(x11
->display
, &ctx
->Shminfo
[foo
]);
350 XSync(x11
->display
, False
);
351 shmctl(ctx
->Shminfo
[foo
].shmid
, IPC_RMID
, 0);
356 (XvImage
*) XvCreateImage(x11
->display
, x11
->xv_port
,
357 ctx
->xv_format
, NULL
, ctx
->image_width
,
359 ctx
->xvimage
[foo
]->data
= malloc(ctx
->xvimage
[foo
]->data_size
);
360 XSync(x11
->display
, False
);
362 memset(ctx
->xvimage
[foo
]->data
, 128, ctx
->xvimage
[foo
]->data_size
);
366 static void deallocate_xvimage(struct vo
*vo
, int foo
)
368 struct xvctx
*ctx
= vo
->priv
;
370 if (ctx
->Shmem_Flag
) {
371 XShmDetach(vo
->x11
->display
, &ctx
->Shminfo
[foo
]);
372 shmdt(ctx
->Shminfo
[foo
].shmaddr
);
376 free(ctx
->xvimage
[foo
]->data
);
378 XFree(ctx
->xvimage
[foo
]);
380 XSync(vo
->x11
->display
, False
);
384 static inline void put_xvimage(struct vo
*vo
, XvImage
*xvi
)
386 struct xvctx
*ctx
= vo
->priv
;
387 struct vo_x11_state
*x11
= vo
->x11
;
388 struct vo_rect
*src
= &ctx
->src_rect
;
389 struct vo_rect
*dst
= &ctx
->dst_rect
;
391 if (ctx
->Shmem_Flag
) {
392 XvShmPutImage(x11
->display
, x11
->xv_port
, x11
->window
, x11
->vo_gc
, xvi
,
393 src
->left
, src
->top
, src
->width
, src
->height
,
394 dst
->left
, dst
->top
, dst
->width
, dst
->height
,
399 XvPutImage(x11
->display
, x11
->xv_port
, x11
->window
, x11
->vo_gc
, xvi
,
400 src
->left
, src
->top
, src
->width
, src
->height
,
401 dst
->left
, dst
->top
, dst
->width
, dst
->height
);
405 // Only copies luma for planar formats as draw_alpha doesn't change others */
406 static void copy_backup_image(struct vo
*vo
, int dest
, int src
)
408 struct xvctx
*ctx
= vo
->priv
;
410 XvImage
*vb
= ctx
->xvimage
[dest
];
411 XvImage
*cp
= ctx
->xvimage
[src
];
412 memcpy_pic(vb
->data
+ vb
->offsets
[0], cp
->data
+ cp
->offsets
[0],
413 vb
->width
, vb
->height
,
414 vb
->pitches
[0], cp
->pitches
[0]);
417 static void check_events(struct vo
*vo
)
419 struct xvctx
*ctx
= vo
->priv
;
420 int e
= vo_x11_check_events(vo
);
422 if (e
& VO_EVENT_EXPOSE
|| e
& VO_EVENT_RESIZE
)
425 if ((e
& VO_EVENT_EXPOSE
|| e
& VO_EVENT_RESIZE
) && ctx
->is_paused
) {
426 /* did we already draw a buffer */
427 if (ctx
->visible_buf
!= -1) {
428 /* redraw the last visible buffer */
429 put_xvimage(vo
, ctx
->xvimage
[ctx
->visible_buf
]);
434 static void draw_osd(struct vo
*vo
, struct osd_state
*osd
)
436 struct xvctx
*ctx
= vo
->priv
;
438 ctx
->osd_objects_drawn
= 0;
441 ctx
->image_width
* vo
->panscan_x
/ (vo
->dwidth
+
443 ctx
->image_height
, ctx
->draw_alpha_fnc
, vo
);
444 if (ctx
->osd_objects_drawn
)
445 ctx
->unchanged_next_image
= false;
448 static int redraw_osd(struct vo
*vo
, struct osd_state
*osd
)
450 struct xvctx
*ctx
= vo
->priv
;
452 if (ctx
->have_visible_image_copy
)
453 copy_backup_image(vo
, ctx
->visible_buf
, ctx
->num_buffers
);
454 else if (ctx
->unchanged_visible_image
) {
455 copy_backup_image(vo
, ctx
->num_buffers
, ctx
->visible_buf
);
456 ctx
->have_visible_image_copy
= true;
460 int temp
= ctx
->current_buf
;
461 ctx
->current_buf
= ctx
->visible_buf
;
463 ctx
->current_buf
= temp
;
464 put_xvimage(vo
, ctx
->xvimage
[ctx
->visible_buf
]);
468 static void flip_page(struct vo
*vo
)
470 struct xvctx
*ctx
= vo
->priv
;
471 put_xvimage(vo
, ctx
->xvimage
[ctx
->current_buf
]);
473 /* remember the currently visible buffer */
474 ctx
->visible_buf
= ctx
->current_buf
;
476 ctx
->have_visible_image_copy
= ctx
->have_next_image_copy
;
477 ctx
->have_next_image_copy
= false;
478 ctx
->unchanged_visible_image
= ctx
->unchanged_next_image
;
479 ctx
->unchanged_next_image
= false;
481 if (ctx
->num_buffers
> 1) {
482 ctx
->current_buf
= vo_directrendering
? 0 : ((ctx
->current_buf
+ 1) %
484 XFlush(vo
->x11
->display
);
486 XSync(vo
->x11
->display
, False
);
490 static int draw_slice(struct vo
*vo
, uint8_t *image
[], int stride
[], int w
,
493 struct xvctx
*ctx
= vo
->priv
;
495 XvImage
*current_image
= ctx
->xvimage
[ctx
->current_buf
];
497 dst
= current_image
->data
+ current_image
->offsets
[0]
498 + current_image
->pitches
[0] * y
+ x
;
499 memcpy_pic(dst
, image
[0], w
, h
, current_image
->pitches
[0], stride
[0]);
506 dst
= current_image
->data
+ current_image
->offsets
[1]
507 + current_image
->pitches
[1] * y
+ x
;
508 if (ctx
->image_format
!= IMGFMT_YV12
)
509 memcpy_pic(dst
, image
[1], w
, h
, current_image
->pitches
[1], stride
[1]);
511 memcpy_pic(dst
, image
[2], w
, h
, current_image
->pitches
[1], stride
[2]);
513 dst
= current_image
->data
+ current_image
->offsets
[2]
514 + current_image
->pitches
[2] * y
+ x
;
515 if (ctx
->image_format
== IMGFMT_YV12
)
516 memcpy_pic(dst
, image
[1], w
, h
, current_image
->pitches
[1], stride
[1]);
518 memcpy_pic(dst
, image
[2], w
, h
, current_image
->pitches
[1], stride
[2]);
523 static uint32_t draw_image(struct vo
*vo
, mp_image_t
*mpi
)
525 struct xvctx
*ctx
= vo
->priv
;
527 ctx
->have_next_image_copy
= false;
529 if (mpi
->flags
& MP_IMGFLAG_DIRECT
)
531 ctx
->current_buf
= (size_t)(mpi
->priv
); // hack!
532 else if (mpi
->flags
& MP_IMGFLAG_DRAW_CALLBACK
)
534 else if (mpi
->flags
& MP_IMGFLAG_PLANAR
)
535 draw_slice(vo
, mpi
->planes
, mpi
->stride
, mpi
->w
, mpi
->h
, 0, 0);
536 else if (mpi
->flags
& MP_IMGFLAG_YUV
)
538 memcpy_pic(ctx
->xvimage
[ctx
->current_buf
]->data
+
539 ctx
->xvimage
[ctx
->current_buf
]->offsets
[0], mpi
->planes
[0],
540 mpi
->w
* (mpi
->bpp
/ 8), mpi
->h
,
541 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0], mpi
->stride
[0]);
545 if (ctx
->is_paused
) {
546 copy_backup_image(vo
, ctx
->num_buffers
, ctx
->current_buf
);
547 ctx
->have_next_image_copy
= true;
549 ctx
->unchanged_next_image
= true;
553 static uint32_t get_image(struct xvctx
*ctx
, mp_image_t
*mpi
)
555 // we shouldn't change current_buf unless we do DR!
556 int buf
= ctx
->current_buf
;
558 if (mpi
->type
== MP_IMGTYPE_STATIC
&& ctx
->num_buffers
> 1)
559 return VO_FALSE
; // it is not static
560 if (mpi
->imgfmt
!= ctx
->image_format
)
561 return VO_FALSE
; // needs conversion :(
562 if (mpi
->flags
& MP_IMGFLAG_READABLE
563 && (mpi
->type
== MP_IMGTYPE_IPB
|| mpi
->type
== MP_IMGTYPE_IP
)) {
564 // reference (I/P) frame of IP or IPB:
565 if (ctx
->num_buffers
< 2)
566 return VO_FALSE
; // not enough
567 ctx
->current_ip_buf
^= 1;
568 // for IPB with 2 buffers we can DR only one of the 2 P frames:
569 if (mpi
->type
== MP_IMGTYPE_IPB
&& ctx
->num_buffers
< 3
570 && ctx
->current_ip_buf
)
572 buf
= ctx
->current_ip_buf
;
573 if (mpi
->type
== MP_IMGTYPE_IPB
)
574 ++buf
; // preserve space for B
576 if (mpi
->height
> ctx
->xvimage
[buf
]->height
)
577 return VO_FALSE
; //buffer to small
578 if (mpi
->width
* (mpi
->bpp
/ 8) > ctx
->xvimage
[buf
]->pitches
[0])
579 return VO_FALSE
; //buffer to small
580 if ((mpi
->flags
& (MP_IMGFLAG_ACCEPT_STRIDE
| MP_IMGFLAG_ACCEPT_WIDTH
))
581 || (mpi
->width
* (mpi
->bpp
/ 8) == ctx
->xvimage
[buf
]->pitches
[0])) {
582 ctx
->current_buf
= buf
;
583 XvImage
*current_image
= ctx
->xvimage
[ctx
->current_buf
];
584 mpi
->planes
[0] = current_image
->data
+ current_image
->offsets
[0];
585 mpi
->stride
[0] = current_image
->pitches
[0];
586 mpi
->width
= mpi
->stride
[0] / (mpi
->bpp
/ 8);
587 if (mpi
->flags
& MP_IMGFLAG_PLANAR
) {
588 if (mpi
->flags
& MP_IMGFLAG_SWAPPED
) {
590 mpi
->planes
[1] = current_image
->data
591 + current_image
->offsets
[1];
592 mpi
->planes
[2] = current_image
->data
593 + current_image
->offsets
[2];
594 mpi
->stride
[1] = current_image
->pitches
[1];
595 mpi
->stride
[2] = current_image
->pitches
[2];
598 mpi
->planes
[1] = current_image
->data
599 + current_image
->offsets
[2];
600 mpi
->planes
[2] = current_image
->data
601 + current_image
->offsets
[1];
602 mpi
->stride
[1] = current_image
->pitches
[2];
603 mpi
->stride
[2] = current_image
->pitches
[1];
606 mpi
->flags
|= MP_IMGFLAG_DIRECT
;
607 mpi
->priv
= (void *)(size_t)ctx
->current_buf
;
613 static int query_format(struct xvctx
*ctx
, uint32_t format
)
616 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
618 /* check image formats */
619 for (i
= 0; i
< ctx
->formats
; i
++) {
620 if (ctx
->fo
[i
].id
== format
)
621 return flag
; //xv_format = fo[i].id;
626 static void uninit(struct vo
*vo
)
628 struct xvctx
*ctx
= vo
->priv
;
631 ctx
->visible_buf
= -1;
633 XvFreeAdaptorInfo(ctx
->ai
);
639 for (i
= 0; i
< ctx
->total_buffers
; i
++)
640 deallocate_xvimage(vo
, i
);
642 if (ctx
->mode_switched
)
645 // uninit() shouldn't get called unless initialization went past vo_init()
649 static int preinit(struct vo
*vo
, const char *arg
)
654 strarg_t ck_src_arg
= { 0, NULL
};
655 strarg_t ck_method_arg
= { 0, NULL
};
656 struct xvctx
*ctx
= talloc_zero(vo
, struct xvctx
);
658 struct vo_x11_state
*x11
= vo
->x11
;
661 const opt_t subopts
[] =
663 /* name arg type arg var test */
664 { "port", OPT_ARG_INT
, &x11
->xv_port
, int_pos
},
665 { "adaptor", OPT_ARG_INT
, &xv_adaptor
, int_non_neg
},
666 { "ck", OPT_ARG_STR
, &ck_src_arg
, xv_test_ck
},
667 { "ck-method", OPT_ARG_STR
, &ck_method_arg
, xv_test_ckm
},
673 /* parse suboptions */
674 if (subopt_parse(arg
, subopts
) != 0) {
678 /* modify colorkey settings according to the given options */
679 xv_setup_colorkeyhandling(vo
, ck_method_arg
.str
, ck_src_arg
.str
);
684 /* check for Xvideo extension */
685 unsigned int ver
, rel
, req
, ev
, err
;
686 if (Success
!= XvQueryExtension(x11
->display
, &ver
, &rel
, &req
, &ev
, &err
)) {
687 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");
691 /* check for Xvideo support */
693 XvQueryAdaptors(x11
->display
, DefaultRootWindow(x11
->display
),
694 &ctx
->adaptors
, &ctx
->ai
)) {
695 mp_tmsg(MSGT_VO
, MSGL_ERR
, "[VO_XV] XvQueryAdaptors failed.\n");
703 for (port_found
= 0, i
= 0; !port_found
&& i
< ctx
->adaptors
; i
++) {
704 if ((ctx
->ai
[i
].type
& XvInputMask
)
705 && (ctx
->ai
[i
].type
& XvImageMask
)) {
706 for (xv_p
= ctx
->ai
[i
].base_id
;
707 xv_p
< ctx
->ai
[i
].base_id
+ ctx
->ai
[i
].num_ports
;
709 if (xv_p
== x11
->xv_port
) {
717 if (XvGrabPort(x11
->display
, x11
->xv_port
, CurrentTime
))
720 mp_tmsg(MSGT_VO
, MSGL_WARN
, "[VO_XV] Invalid port parameter, overriding with port 0.\n");
725 for (i
= 0; i
< ctx
->adaptors
&& x11
->xv_port
== 0; i
++) {
726 /* check if adaptor number has been specified */
727 if (xv_adaptor
!= -1 && xv_adaptor
!= i
)
730 if ((ctx
->ai
[i
].type
& XvInputMask
) && (ctx
->ai
[i
].type
& XvImageMask
)) {
731 for (xv_p
= ctx
->ai
[i
].base_id
;
732 xv_p
< ctx
->ai
[i
].base_id
+ ctx
->ai
[i
].num_ports
; ++xv_p
)
733 if (!XvGrabPort(x11
->display
, xv_p
, CurrentTime
)) {
735 mp_msg(MSGT_VO
, MSGL_V
,
736 "[VO_XV] Using Xv Adapter #%d (%s)\n",
740 mp_tmsg(MSGT_VO
, MSGL_WARN
, "[VO_XV] Could not grab port %i.\n",
748 mp_tmsg(MSGT_VO
, MSGL_ERR
,
749 "[VO_XV] Could not find free Xvideo port - maybe another process is already\n"\
750 "[VO_XV] using it. Close all video applications, and try again. If that does\n"\
751 "[VO_XV] not help, see 'mplayer -vo help' for other (non-xv) video out drivers.\n");
753 mp_tmsg(MSGT_VO
, MSGL_ERR
,
754 "[VO_XV] It seems there is no Xvideo support for your video card available.\n"\
755 "[VO_XV] Run 'xvinfo' to verify its Xv support and read\n"\
756 "[VO_XV] DOCS/HTML/en/video.html#xv!\n"\
757 "[VO_XV] See 'mplayer -vo help' for other (non-xv) video out drivers.\n"\
758 "[VO_XV] Try -vo x11.\n");
762 if (!vo_xv_init_colorkey(vo
)) {
763 goto error
; // bail out, colorkey setup failed
765 vo_xv_enable_vsync(vo
);
766 vo_xv_get_max_img_dim(vo
, &ctx
->max_width
, &ctx
->max_height
);
768 ctx
->fo
= XvListImageFormats(x11
->display
, x11
->xv_port
,
769 (int *) &ctx
->formats
);
774 uninit(vo
); // free resources
778 static int control(struct vo
*vo
, uint32_t request
, void *data
)
780 struct xvctx
*ctx
= vo
->priv
;
781 struct vo_x11_state
*x11
= vo
->x11
;
784 return (ctx
->is_paused
= 1);
786 return (ctx
->is_paused
= 0);
787 case VOCTRL_QUERY_FORMAT
:
788 return query_format(ctx
, *((uint32_t *) data
));
789 case VOCTRL_GET_IMAGE
:
790 return get_image(ctx
, data
);
791 case VOCTRL_DRAW_IMAGE
:
792 return draw_image(vo
, data
);
793 case VOCTRL_GET_PANSCAN
:
795 case VOCTRL_FULLSCREEN
:
796 vo_x11_fullscreen(vo
);
797 /* indended, fallthrough to update panscan on fullscreen/windowed switch */
798 case VOCTRL_SET_PANSCAN
:
801 case VOCTRL_SET_EQUALIZER
:
803 struct voctrl_set_equalizer_args
*args
= data
;
804 return vo_xv_set_eq(vo
, x11
->xv_port
, args
->name
, args
->value
);
806 case VOCTRL_GET_EQUALIZER
:
808 struct voctrl_get_equalizer_args
*args
= data
;
809 return vo_xv_get_eq(vo
, x11
->xv_port
, args
->name
, args
->valueptr
);
811 case VOCTRL_SET_YUV_COLORSPACE
:;
812 int given_cspc
= *(int *)data
% 2;
813 return vo_xv_set_eq(vo
, x11
->xv_port
, "bt_709", given_cspc
* 200 - 100);
814 case VOCTRL_GET_YUV_COLORSPACE
:;
816 if (!vo_xv_get_eq(vo
, x11
->xv_port
, "bt_709", &bt709_enabled
))
818 *(int *)data
= bt709_enabled
== 100;
823 case VOCTRL_UPDATE_SCREENINFO
:
824 update_xinerama_info(vo
);
826 case VOCTRL_REDRAW_OSD
:
827 return redraw_osd(vo
, data
);
832 const struct vo_driver video_out_xv
= {
838 .draw_slice
= draw_slice
,
839 .draw_osd
= draw_osd
,
840 .flip_page
= flip_page
,
841 .check_events
= check_events
,