1 /* vo_xv.c, X11 Xv interface */
3 // Number of buffers _FOR_DOUBLEBUFFERING_MODE_
4 // Use option -double to enable double buffering! (default: single buffer)
30 #include "video_out.h"
31 #include "libmpcodecs/vfcap.h"
32 #include "libmpcodecs/mp_image.h"
36 #include <X11/Xutil.h>
39 #include "x11_common.h"
41 #include "fastmemcpy.h"
45 #include "subopt-helper.h"
47 #include "input/input.h"
51 #include "gui/interface.h"
54 #include "libavutil/common.h"
56 static const vo_info_t info
= {
59 "Gerd Knorr <kraxel@goldbach.in-berlin.de> and others",
66 #include <X11/extensions/XShm.h>
69 // Note: depends on the inclusion of X11/extensions/XShm.h
70 #include <X11/extensions/Xv.h>
71 #include <X11/extensions/Xvlib.h>
75 XvImageFormatValues
*fo
;
76 unsigned int formats
, adaptors
, xv_format
;
81 int have_visible_image_copy
;
82 int have_next_image_copy
;
83 int unchanged_visible_image
;
84 int unchanged_next_image
;
86 XvImage
*xvimage
[NUM_BUFFERS
+ 1];
88 uint32_t image_height
;
89 uint32_t image_format
;
92 uint32_t max_width
, max_height
; // zero means: not set
93 int event_fd_registered
; // for uninit called from preinit
95 int osd_objects_drawn
;
96 void (*draw_alpha_fnc
)(void *ctx
, int x0
, int y0
, int w
, int h
,
97 unsigned char *src
, unsigned char *srca
,
100 XShmSegmentInfo Shminfo
[NUM_BUFFERS
];
105 static void allocate_xvimage(struct vo
*, int);
108 static void draw_alpha_yv12(void *p
, int x0
, int y0
, int w
, int h
,
109 unsigned char *src
, unsigned char *srca
,
113 struct xvctx
*ctx
= vo
->priv
;
114 x0
+= ctx
->image_width
* (vo
->panscan_x
>> 1)
115 / (vo
->dwidth
+ vo
->panscan_x
);
116 vo_draw_alpha_yv12(w
, h
, src
, srca
, stride
,
117 ctx
->xvimage
[ctx
->current_buf
]->data
+
118 ctx
->xvimage
[ctx
->current_buf
]->offsets
[0] +
119 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0] * y0
+ x0
,
120 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0]);
121 ctx
->osd_objects_drawn
++;
124 static void draw_alpha_yuy2(void *p
, int x0
, int y0
, int w
, int h
,
125 unsigned char *src
, unsigned char *srca
,
129 struct xvctx
*ctx
= vo
->priv
;
130 x0
+= ctx
->image_width
* (vo
->panscan_x
>> 1)
131 / (vo
->dwidth
+ vo
->panscan_x
);
132 vo_draw_alpha_yuy2(w
, h
, src
, srca
, stride
,
133 ctx
->xvimage
[ctx
->current_buf
]->data
+
134 ctx
->xvimage
[ctx
->current_buf
]->offsets
[0] +
135 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0] * y0
+ 2 * x0
,
136 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0]);
137 ctx
->osd_objects_drawn
++;
140 static void draw_alpha_uyvy(void *p
, int x0
, int y0
, int w
, int h
,
141 unsigned char *src
, unsigned char *srca
,
145 struct xvctx
*ctx
= vo
->priv
;
146 x0
+= ctx
->image_width
* (vo
->panscan_x
>> 1)
147 / (vo
->dwidth
+ vo
->panscan_x
);
148 vo_draw_alpha_yuy2(w
, h
, src
, srca
, stride
,
149 ctx
->xvimage
[ctx
->current_buf
]->data
+
150 ctx
->xvimage
[ctx
->current_buf
]->offsets
[0] +
151 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0] * y0
+ 2 * x0
+ 1,
152 ctx
->xvimage
[ctx
->current_buf
]->pitches
[0]);
153 ctx
->osd_objects_drawn
++;
156 static void draw_alpha_null(void *p
, int x0
, int y0
, int w
, int h
,
157 unsigned char *src
, unsigned char *srca
,
163 static void deallocate_xvimage(struct vo
*vo
, int foo
);
166 * connect to server, create and map window,
167 * allocate colors and (shared) memory
169 static int config(struct vo
*vo
, uint32_t width
, uint32_t height
,
170 uint32_t d_width
, uint32_t d_height
, uint32_t flags
,
171 char *title
, uint32_t format
)
173 struct MPOpts
*opts
= vo
->opts
;
174 struct vo_x11_state
*x11
= vo
->x11
;
176 XSetWindowAttributes xswa
;
177 XWindowAttributes attribs
;
178 unsigned long xswamask
;
180 struct xvctx
*ctx
= vo
->priv
;
183 ctx
->image_height
= height
;
184 ctx
->image_width
= width
;
185 ctx
->image_format
= format
;
187 if ((ctx
->max_width
!= 0 && ctx
->max_height
!= 0)
188 && (ctx
->image_width
> ctx
->max_width
189 || ctx
->image_height
> ctx
->max_height
)) {
190 mp_msg(MSGT_VO
, MSGL_ERR
, MSGTR_VO_XV_ImagedimTooHigh
,
191 ctx
->image_width
, ctx
->image_height
, ctx
->max_width
,
197 ctx
->visible_buf
= -1;
198 ctx
->have_visible_image_copy
= false;
199 ctx
->have_next_image_copy
= false;
201 /* check image formats */
203 for (i
= 0; i
< ctx
->formats
; i
++) {
204 mp_msg(MSGT_VO
, MSGL_V
, "Xvideo image format: 0x%x (%4.4s) %s\n",
205 ctx
->fo
[i
].id
, (char *) &ctx
->fo
[i
].id
,
206 (ctx
->fo
[i
].format
== XvPacked
) ? "packed" : "planar");
207 if (ctx
->fo
[i
].id
== format
)
208 ctx
->xv_format
= ctx
->fo
[i
].id
;
215 guiGetEvent(guiSetShVideo
, 0); // the GUI will set up / resize the window
220 int vm
= flags
& VOFLAG_MODESWITCHING
;
223 ctx
->mode_switched
= 1;
226 XGetWindowAttributes(x11
->display
, DefaultRootWindow(x11
->display
),
228 depth
= attribs
.depth
;
229 if (depth
!= 15 && depth
!= 16 && depth
!= 24 && depth
!= 32)
231 XMatchVisualInfo(x11
->display
, x11
->screen
, depth
, TrueColor
, &vinfo
);
233 xswa
.background_pixel
= 0;
234 if (x11
->xv_ck_info
.method
== CK_METHOD_BACKGROUND
)
235 xswa
.background_pixel
= x11
->xv_colorkey
;
236 xswa
.border_pixel
= 0;
237 xswamask
= CWBackPixel
| CWBorderPixel
;
239 vo_x11_create_vo_window(vo
, &vinfo
, vo
->dx
, vo
->dy
, vo
->dwidth
,
240 vo
->dheight
, flags
, CopyFromParent
, "xv",
242 XChangeWindowAttributes(x11
->display
, x11
->window
, xswamask
, &xswa
);
246 /* Grab the mouse pointer in our window */
248 XGrabPointer(x11
->display
, x11
->window
, True
, 0, GrabModeAsync
,
249 GrabModeAsync
, x11
->window
, None
, CurrentTime
);
250 XSetInputFocus(x11
->display
, x11
->window
, RevertToNone
,
256 mp_msg(MSGT_VO
, MSGL_V
, "using Xvideo port %d for hw scaling\n",
259 switch (ctx
->xv_format
) {
263 ctx
->draw_alpha_fnc
= draw_alpha_yv12
;
267 ctx
->draw_alpha_fnc
= draw_alpha_yuy2
;
270 ctx
->draw_alpha_fnc
= draw_alpha_uyvy
;
273 ctx
->draw_alpha_fnc
= draw_alpha_null
;
276 // In case config has been called before
277 for (i
= 0; i
< ctx
->total_buffers
; i
++)
278 deallocate_xvimage(vo
, i
);
281 vo_doublebuffering
? (vo_directrendering
? NUM_BUFFERS
: 2) : 1;
282 ctx
->total_buffers
= ctx
->num_buffers
+ 1;
284 for (i
= 0; i
< ctx
->total_buffers
; i
++)
285 allocate_xvimage(vo
, i
);
287 ctx
->current_buf
= 0;
288 ctx
->current_ip_buf
= 0;
290 if ((flags
& VOFLAG_FULLSCREEN
) && WinID
<= 0)
292 vo_calc_drwXY(vo
, &ctx
->drwX
, &ctx
->drwY
);
296 vo_xv_draw_colorkey(vo
, ctx
->drwX
- (vo
->panscan_x
>> 1),
297 ctx
->drwY
- (vo
->panscan_y
>> 1),
298 vo
->dwidth
+ vo
->panscan_x
- 1,
299 vo
->dheight
+ vo
->panscan_y
- 1);
301 mp_msg(MSGT_VO
, MSGL_V
, "[xv] dx: %d dy: %d dw: %d dh: %d\n", ctx
->drwX
,
302 ctx
->drwY
, vo
->dwidth
, vo
->dheight
);
307 static void allocate_xvimage(struct vo
*vo
, int foo
)
309 struct xvctx
*ctx
= vo
->priv
;
310 struct vo_x11_state
*x11
= vo
->x11
;
312 * allocate XvImages. FIXME: no error checking, without
313 * mit-shm this will bomb... trzing to fix ::atmos
316 if (x11
->display_is_local
&& XShmQueryExtension(x11
->display
))
320 mp_msg(MSGT_VO
, MSGL_INFO
, MSGTR_LIBVO_XV_SharedMemoryNotSupported
);
322 if (ctx
->Shmem_Flag
) {
324 (XvImage
*) XvShmCreateImage(x11
->display
, x11
->xv_port
,
325 ctx
->xv_format
, NULL
,
326 ctx
->image_width
, ctx
->image_height
,
329 ctx
->Shminfo
[foo
].shmid
= shmget(IPC_PRIVATE
,
330 ctx
->xvimage
[foo
]->data_size
,
332 ctx
->Shminfo
[foo
].shmaddr
= (char *) shmat(ctx
->Shminfo
[foo
].shmid
, 0,
334 ctx
->Shminfo
[foo
].readOnly
= False
;
336 ctx
->xvimage
[foo
]->data
= ctx
->Shminfo
[foo
].shmaddr
;
337 XShmAttach(x11
->display
, &ctx
->Shminfo
[foo
]);
338 XSync(x11
->display
, False
);
339 shmctl(ctx
->Shminfo
[foo
].shmid
, IPC_RMID
, 0);
344 (XvImage
*) XvCreateImage(x11
->display
, x11
->xv_port
,
345 ctx
->xv_format
, NULL
, ctx
->image_width
,
347 ctx
->xvimage
[foo
]->data
= malloc(ctx
->xvimage
[foo
]->data_size
);
348 XSync(x11
->display
, False
);
350 memset(ctx
->xvimage
[foo
]->data
, 128, ctx
->xvimage
[foo
]->data_size
);
354 static void deallocate_xvimage(struct vo
*vo
, int foo
)
356 struct xvctx
*ctx
= vo
->priv
;
358 if (ctx
->Shmem_Flag
) {
359 XShmDetach(vo
->x11
->display
, &ctx
->Shminfo
[foo
]);
360 shmdt(ctx
->Shminfo
[foo
].shmaddr
);
364 free(ctx
->xvimage
[foo
]->data
);
366 XFree(ctx
->xvimage
[foo
]);
368 XSync(vo
->x11
->display
, False
);
372 static inline void put_xvimage(struct vo
*vo
, XvImage
*xvi
)
374 struct xvctx
*ctx
= vo
->priv
;
375 struct vo_x11_state
*x11
= vo
->x11
;
377 if (ctx
->Shmem_Flag
) {
378 XvShmPutImage(x11
->display
, x11
->xv_port
, x11
->window
, x11
->vo_gc
, xvi
,
379 0, 0, ctx
->image_width
, ctx
->image_height
,
380 ctx
->drwX
- (vo
->panscan_x
>> 1),
381 ctx
->drwY
- (vo
->panscan_y
>> 1),
382 vo
->dwidth
+ vo
->panscan_x
, vo
->dheight
+ vo
->panscan_y
,
387 XvPutImage(x11
->display
, x11
->xv_port
, x11
->window
, x11
->vo_gc
, xvi
, 0,
388 0, ctx
->image_width
, ctx
->image_height
,
389 ctx
->drwX
- (vo
->panscan_x
>> 1),
390 ctx
->drwY
- (vo
->panscan_y
>> 1),
391 vo
->dwidth
+ vo
->panscan_x
, vo
->dheight
+ vo
->panscan_y
);
395 // Only copies luma for planar formats as draw_alpha doesn't change others */
396 void copy_backup_image(struct vo
*vo
, int dest
, int src
)
398 struct xvctx
*ctx
= vo
->priv
;
400 XvImage
*vb
= ctx
->xvimage
[dest
];
401 XvImage
*cp
= ctx
->xvimage
[src
];
402 memcpy_pic(vb
->data
+ vb
->offsets
[0], cp
->data
+ cp
->offsets
[0],
403 vb
->width
, vb
->height
,
404 vb
->pitches
[0], cp
->pitches
[0]);
407 static void check_events(struct vo
*vo
)
409 struct xvctx
*ctx
= vo
->priv
;
410 struct vo_x11_state
*x11
= vo
->x11
;
411 int e
= vo_x11_check_events(vo
);
413 if (e
& VO_EVENT_RESIZE
)
414 vo_calc_drwXY(vo
, &ctx
->drwX
, &ctx
->drwY
);
416 if (e
& VO_EVENT_EXPOSE
|| e
& VO_EVENT_RESIZE
) {
417 vo_xv_draw_colorkey(vo
, ctx
->drwX
- (vo
->panscan_x
>> 1),
418 ctx
->drwY
- (vo
->panscan_y
>> 1),
419 vo
->dwidth
+ vo
->panscan_x
- 1,
420 vo
->dheight
+ vo
->panscan_y
- 1);
423 if ((e
& VO_EVENT_EXPOSE
|| e
& VO_EVENT_RESIZE
) && ctx
->is_paused
) {
424 /* did we already draw a buffer */
425 if (ctx
->visible_buf
!= -1) {
426 /* redraw the last visible buffer */
427 put_xvimage(vo
, ctx
->xvimage
[ctx
->visible_buf
]);
432 static void draw_osd(struct vo
*vo
, struct osd_state
*osd
)
434 struct xvctx
*ctx
= vo
->priv
;
436 ctx
->osd_objects_drawn
= 0;
439 ctx
->image_width
* vo
->panscan_x
/ (vo
->dwidth
+
441 ctx
->image_height
, ctx
->draw_alpha_fnc
, vo
);
442 if (ctx
->osd_objects_drawn
)
443 ctx
->unchanged_next_image
= false;
446 static int redraw_osd(struct vo
*vo
, struct osd_state
*osd
)
448 struct xvctx
*ctx
= vo
->priv
;
450 if (ctx
->have_visible_image_copy
)
451 copy_backup_image(vo
, ctx
->visible_buf
, ctx
->num_buffers
);
452 else if (ctx
->unchanged_visible_image
) {
453 copy_backup_image(vo
, ctx
->num_buffers
, ctx
->visible_buf
);
454 ctx
->have_visible_image_copy
= true;
458 int temp
= ctx
->current_buf
;
459 ctx
->current_buf
= ctx
->visible_buf
;
461 ctx
->current_buf
= temp
;
462 put_xvimage(vo
, ctx
->xvimage
[ctx
->visible_buf
]);
466 static void flip_page(struct vo
*vo
)
468 struct xvctx
*ctx
= vo
->priv
;
469 put_xvimage(vo
, ctx
->xvimage
[ctx
->current_buf
]);
471 /* remember the currently visible buffer */
472 ctx
->visible_buf
= ctx
->current_buf
;
474 ctx
->have_visible_image_copy
= ctx
->have_next_image_copy
;
475 ctx
->have_next_image_copy
= false;
476 ctx
->unchanged_visible_image
= ctx
->unchanged_next_image
;
477 ctx
->unchanged_next_image
= false;
479 if (ctx
->num_buffers
> 1) {
480 ctx
->current_buf
= vo_directrendering
? 0 : ((ctx
->current_buf
+ 1) %
482 XFlush(vo
->x11
->display
);
484 XSync(vo
->x11
->display
, False
);
488 static int draw_slice(struct vo
*vo
, uint8_t *image
[], int stride
[], int w
,
491 struct xvctx
*ctx
= vo
->priv
;
493 XvImage
*current_image
= ctx
->xvimage
[ctx
->current_buf
];
495 dst
= current_image
->data
+ current_image
->offsets
[0]
496 + current_image
->pitches
[0] * y
+ x
;
497 memcpy_pic(dst
, image
[0], w
, h
, current_image
->pitches
[0], stride
[0]);
504 dst
= current_image
->data
+ current_image
->offsets
[1]
505 + current_image
->pitches
[1] * y
+ x
;
506 if (ctx
->image_format
!= IMGFMT_YV12
)
507 memcpy_pic(dst
, image
[1], w
, h
, current_image
->pitches
[1], stride
[1]);
509 memcpy_pic(dst
, image
[2], w
, h
, current_image
->pitches
[1], stride
[2]);
511 dst
= current_image
->data
+ current_image
->offsets
[2]
512 + current_image
->pitches
[2] * y
+ x
;
513 if (ctx
->image_format
== IMGFMT_YV12
)
514 memcpy_pic(dst
, image
[1], w
, h
, current_image
->pitches
[1], stride
[1]);
516 memcpy_pic(dst
, image
[2], w
, h
, current_image
->pitches
[1], stride
[2]);
521 static int draw_frame(struct vo
*vo
, uint8_t *src
[])
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
;
674 /* name arg type arg var test */
675 {"port", OPT_ARG_INT
, &x11
->xv_port
, (opt_test_f
) int_pos
},
676 {"adaptor", OPT_ARG_INT
, &xv_adaptor
, (opt_test_f
) int_non_neg
},
677 {"ck", OPT_ARG_STR
, &ck_src_arg
, xv_test_ck
},
678 {"ck-method", OPT_ARG_STR
, &ck_method_arg
, xv_test_ckm
},
684 /* parse suboptions */
685 if (subopt_parse(arg
, subopts
) != 0) {
689 /* modify colorkey settings according to the given options */
690 xv_setup_colorkeyhandling(vo
, ck_method_arg
.str
, ck_src_arg
.str
);
695 /* check for Xvideo extension */
696 unsigned int ver
, rel
, req
, ev
, err
;
697 if (Success
!= XvQueryExtension(x11
->display
, &ver
, &rel
, &req
, &ev
, &err
)) {
698 mp_msg(MSGT_VO
, MSGL_ERR
, MSGTR_LIBVO_XV_XvNotSupportedByX11
);
702 /* check for Xvideo support */
704 XvQueryAdaptors(x11
->display
, DefaultRootWindow(x11
->display
),
705 &ctx
->adaptors
, &ctx
->ai
)) {
706 mp_msg(MSGT_VO
, MSGL_ERR
, MSGTR_LIBVO_XV_XvQueryAdaptorsFailed
);
714 for (port_found
= 0, i
= 0; !port_found
&& i
< ctx
->adaptors
; i
++) {
715 if ((ctx
->ai
[i
].type
& XvInputMask
)
716 && (ctx
->ai
[i
].type
& XvImageMask
)) {
717 for (xv_p
= ctx
->ai
[i
].base_id
;
718 xv_p
< ctx
->ai
[i
].base_id
+ ctx
->ai
[i
].num_ports
;
720 if (xv_p
== x11
->xv_port
) {
728 if (XvGrabPort(x11
->display
, x11
->xv_port
, CurrentTime
))
731 mp_msg(MSGT_VO
, MSGL_WARN
, MSGTR_LIBVO_XV_InvalidPortParameter
);
736 for (i
= 0; i
< ctx
->adaptors
&& x11
->xv_port
== 0; i
++) {
737 /* check if adaptor number has been specified */
738 if (xv_adaptor
!= -1 && xv_adaptor
!= i
)
741 if ((ctx
->ai
[i
].type
& XvInputMask
) && (ctx
->ai
[i
].type
& XvImageMask
)) {
742 for (xv_p
= ctx
->ai
[i
].base_id
;
743 xv_p
< ctx
->ai
[i
].base_id
+ ctx
->ai
[i
].num_ports
; ++xv_p
)
744 if (!XvGrabPort(x11
->display
, xv_p
, CurrentTime
)) {
746 mp_msg(MSGT_VO
, MSGL_V
,
747 "[VO_XV] Using Xv Adapter #%d (%s)\n",
751 mp_msg(MSGT_VO
, MSGL_WARN
, MSGTR_LIBVO_XV_CouldNotGrabPort
,
759 mp_msg(MSGT_VO
, MSGL_ERR
, MSGTR_LIBVO_XV_CouldNotFindFreePort
);
761 mp_msg(MSGT_VO
, MSGL_ERR
, MSGTR_LIBVO_XV_NoXvideoSupport
);
765 if (!vo_xv_init_colorkey(vo
)) {
766 goto error
; // bail out, colorkey setup failed
768 vo_xv_enable_vsync(vo
);
769 vo_xv_get_max_img_dim(vo
, &ctx
->max_width
, &ctx
->max_height
);
771 ctx
->fo
= XvListImageFormats(x11
->display
, x11
->xv_port
,
772 (int *) &ctx
->formats
);
774 mp_input_add_key_fd(vo
->input_ctx
, ConnectionNumber(x11
->display
), 1,
775 x11_fd_callback
, NULL
, vo
);
776 ctx
->event_fd_registered
= 1;
780 uninit(vo
); // free resources
784 static int control(struct vo
*vo
, uint32_t request
, void *data
)
786 struct xvctx
*ctx
= vo
->priv
;
787 struct vo_x11_state
*x11
= vo
->x11
;
790 return (ctx
->is_paused
= 1);
792 return (ctx
->is_paused
= 0);
793 case VOCTRL_QUERY_FORMAT
:
794 return query_format(ctx
, *((uint32_t *) data
));
795 case VOCTRL_GET_IMAGE
:
796 return get_image(ctx
, data
);
797 case VOCTRL_DRAW_IMAGE
:
798 return draw_image(vo
, data
);
799 case VOCTRL_GUISUPPORT
:
801 case VOCTRL_GET_PANSCAN
:
802 if (!vo
->config_ok
|| !vo_fs
)
805 case VOCTRL_FULLSCREEN
:
806 vo_x11_fullscreen(vo
);
807 /* indended, fallthrough to update panscan on fullscreen/windowed switch */
808 case VOCTRL_SET_PANSCAN
:
809 if ((vo_fs
&& (vo_panscan
!= vo
->panscan_amount
))
810 || (!vo_fs
&& vo
->panscan_amount
)) {
811 int old_y
= vo
->panscan_y
;
815 if (old_y
!= vo
->panscan_y
) {
816 vo_x11_clearwindow_part(vo
, x11
->window
,
817 vo
->dwidth
+ vo
->panscan_x
- 1,
818 vo
->dheight
+ vo
->panscan_y
- 1, 1);
819 vo_xv_draw_colorkey(vo
, ctx
->drwX
- (vo
->panscan_x
>> 1),
820 ctx
->drwY
- (vo
->panscan_y
>> 1),
821 vo
->dwidth
+ vo
->panscan_x
- 1,
822 vo
->dheight
+ vo
->panscan_y
- 1);
827 case VOCTRL_SET_EQUALIZER
:
829 struct voctrl_set_equalizer_args
*args
= data
;
830 return vo_xv_set_eq(vo
, x11
->xv_port
, args
->name
, args
->value
);
832 case VOCTRL_GET_EQUALIZER
:
834 struct voctrl_get_equalizer_args
*args
= data
;
835 return vo_xv_get_eq(vo
, x11
->xv_port
, args
->name
, args
->valueptr
);
840 case VOCTRL_UPDATE_SCREENINFO
:
841 update_xinerama_info(vo
);
843 case VOCTRL_REDRAW_OSD
:
844 return redraw_osd(vo
, data
);
849 const struct vo_driver video_out_xv
= {
855 .draw_frame
= draw_frame
,
856 .draw_slice
= draw_slice
,
857 .draw_osd
= draw_osd
,
858 .flip_page
= flip_page
,
859 .check_events
= check_events
,