Output number of reference frames before creating H264 vdpau decoder.
[mplayer/glamo.git] / libvo / vo_vdpau.c
blobf7f2450751db9e8ce5933e140082cbd1f2cd3a5e
1 /*
2 * VDPAU video output driver
4 * Copyright (C) 2008 NVIDIA
6 * This file is part of MPlayer.
8 * MPlayer is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * MPlayer is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 /**
24 * \defgroup VDPAU_Presentation VDPAU Presentation
25 * \ingroup Decoder
27 * Actual decoding and presentation are implemented here.
28 * All necessary frame information is collected through
29 * the "vdpau_render_state" structure after parsing all headers
30 * etc. in libavcodec for different codecs.
32 * @{
35 #include <stdio.h>
36 #include <dlfcn.h>
38 #include "config.h"
39 #include "mp_msg.h"
40 #include "video_out.h"
41 #include "video_out_internal.h"
42 #include "x11_common.h"
43 #include "aspect.h"
44 #include "sub.h"
45 #include "subopt-helper.h"
47 #include "libavcodec/vdpau.h"
49 #include "gui/interface.h"
51 #include "libavutil/common.h"
52 #include "libavutil/mathematics.h"
54 #include "libass/ass.h"
55 #include "libass/ass_mp.h"
57 static vo_info_t info = {
58 "VDPAU with X11",
59 "vdpau",
60 "Rajib Mahapatra <rmahapatra@nvidia.com> and others",
64 LIBVO_EXTERN(vdpau)
66 #define CHECK_ST_ERROR(message) \
67 if (vdp_st != VDP_STATUS_OK) { \
68 mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] %s: %s\n", \
69 message, vdp_get_error_string(vdp_st)); \
70 return -1; \
73 #define CHECK_ST_WARNING(message) \
74 if (vdp_st != VDP_STATUS_OK) \
75 mp_msg(MSGT_VO, MSGL_WARN, "[vdpau] %s: %s\n", \
76 message, vdp_get_error_string(vdp_st));
78 /* number of video and output surfaces */
79 #define NUM_OUTPUT_SURFACES 2
80 #define MAX_VIDEO_SURFACES 50
82 /* number of palette entries */
83 #define PALETTE_SIZE 256
85 /* Initial maximum number of EOSD surfaces */
86 #define EOSD_SURFACES_INITIAL 512
89 * Global variable declaration - VDPAU specific
92 /* Declaration for all variables of win_x11_init_vdpau_procs() and
93 * win_x11_init_vdpau_flip_queue() functions
95 static VdpDevice vdp_device;
96 static VdpDeviceCreateX11 *vdp_device_create;
97 static VdpGetProcAddress *vdp_get_proc_address;
99 static VdpPresentationQueueTarget vdp_flip_target;
100 static VdpPresentationQueue vdp_flip_queue;
102 static VdpDeviceDestroy *vdp_device_destroy;
103 static VdpVideoSurfaceCreate *vdp_video_surface_create;
104 static VdpVideoSurfaceDestroy *vdp_video_surface_destroy;
106 static VdpGetErrorString *vdp_get_error_string;
108 /* May be used in software filtering/postprocessing options
109 * in MPlayer (./mplayer -vf ..) if we copy video_surface data to
110 * system memory.
112 static VdpVideoSurfacePutBitsYCbCr *vdp_video_surface_put_bits_y_cb_cr;
113 static VdpOutputSurfacePutBitsNative *vdp_output_surface_put_bits_native;
115 static VdpOutputSurfaceCreate *vdp_output_surface_create;
116 static VdpOutputSurfaceDestroy *vdp_output_surface_destroy;
118 /* VideoMixer puts video_surface data on displayable output_surface. */
119 static VdpVideoMixerCreate *vdp_video_mixer_create;
120 static VdpVideoMixerDestroy *vdp_video_mixer_destroy;
121 static VdpVideoMixerRender *vdp_video_mixer_render;
122 static VdpVideoMixerSetFeatureEnables *vdp_video_mixer_set_feature_enables;
123 static VdpVideoMixerSetAttributeValues *vdp_video_mixer_set_attribute_values;
125 static VdpPresentationQueueTargetDestroy *vdp_presentation_queue_target_destroy;
126 static VdpPresentationQueueCreate *vdp_presentation_queue_create;
127 static VdpPresentationQueueDestroy *vdp_presentation_queue_destroy;
128 static VdpPresentationQueueDisplay *vdp_presentation_queue_display;
129 static VdpPresentationQueueBlockUntilSurfaceIdle *vdp_presentation_queue_block_until_surface_idle;
130 static VdpPresentationQueueTargetCreateX11 *vdp_presentation_queue_target_create_x11;
132 static VdpOutputSurfaceRenderOutputSurface *vdp_output_surface_render_output_surface;
133 static VdpOutputSurfacePutBitsIndexed *vdp_output_surface_put_bits_indexed;
134 static VdpOutputSurfaceRenderBitmapSurface *vdp_output_surface_render_bitmap_surface;
136 static VdpBitmapSurfaceCreate *vdp_bitmap_surface_create;
137 static VdpBitmapSurfaceDestroy *vdp_bitmap_surface_destroy;
138 static VdpBitmapSurfacePutBitsNative *vdp_bitmap_surface_putbits_native;
140 static VdpDecoderCreate *vdp_decoder_create;
141 static VdpDecoderDestroy *vdp_decoder_destroy;
142 static VdpDecoderRender *vdp_decoder_render;
144 static VdpGenerateCSCMatrix *vdp_generate_csc_matrix;
146 static void *vdpau_lib_handle;
147 /* output_surfaces[NUM_OUTPUT_SURFACES] is misused for OSD. */
148 #define osd_surface output_surfaces[NUM_OUTPUT_SURFACES]
149 static VdpOutputSurface output_surfaces[NUM_OUTPUT_SURFACES + 1];
150 static int output_surface_width, output_surface_height;
152 static VdpVideoMixer video_mixer;
153 static int deint;
154 static int deint_type;
155 static int pullup;
156 static float denoise;
157 static float sharpen;
158 static int top_field_first;
160 static VdpDecoder decoder;
161 static int decoder_max_refs;
163 static VdpRect src_rect_vid;
164 static VdpRect out_rect_vid;
165 static int border_x, border_y;
167 static struct vdpau_render_state surface_render[MAX_VIDEO_SURFACES];
168 static int surface_num;
169 static int vid_surface_num;
170 static uint32_t vid_width, vid_height;
171 static uint32_t image_format;
172 static const VdpChromaType vdp_chroma_type = VDP_CHROMA_TYPE_420;
174 /* draw_osd */
175 static unsigned char *index_data;
176 static int index_data_size;
177 static uint32_t palette[PALETTE_SIZE];
179 // EOSD
180 // Pool of surfaces
181 struct {
182 VdpBitmapSurface surface;
183 int w;
184 int h;
185 char in_use;
186 } *eosd_surfaces;
188 // List of surfaces to be rendered
189 struct {
190 VdpBitmapSurface surface;
191 VdpRect source;
192 VdpRect dest;
193 VdpColor color;
194 } *eosd_targets;
196 static int eosd_render_count;
197 static int eosd_surface_count;
199 // Video equalizer
200 static VdpProcamp procamp;
203 * X11 specific
205 static int visible_buf;
206 static int int_pause;
208 static void draw_eosd(void);
210 static void video_to_output_surface(void)
212 VdpTime dummy;
213 VdpStatus vdp_st;
214 int i;
215 if (vid_surface_num < 0)
216 return;
218 // we would need to provide 2 past and 1 future frames to allow advanced
219 // deinterlacing, which is not really possible currently.
220 for (i = 0; i <= !!(deint > 1); i++) {
221 int field = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME;
222 VdpOutputSurface output_surface;
223 if (i) {
224 draw_eosd();
225 draw_osd();
226 flip_page();
228 if (deint)
229 field = top_field_first == i ?
230 VDP_VIDEO_MIXER_PICTURE_STRUCTURE_BOTTOM_FIELD:
231 VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD;
232 output_surface = output_surfaces[surface_num];
233 vdp_st = vdp_presentation_queue_block_until_surface_idle(vdp_flip_queue,
234 output_surface,
235 &dummy);
236 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_block_until_surface_idle")
238 vdp_st = vdp_video_mixer_render(video_mixer, VDP_INVALID_HANDLE, 0,
239 field, 0, NULL,
240 surface_render[vid_surface_num].surface,
241 0, NULL, &src_rect_vid,
242 output_surface,
243 NULL, &out_rect_vid, 0, NULL);
244 CHECK_ST_WARNING("Error when calling vdp_video_mixer_render")
248 static void resize(void)
250 VdpStatus vdp_st;
251 int i;
252 struct vo_rect src_rect;
253 struct vo_rect dst_rect;
254 struct vo_rect borders;
255 calc_src_dst_rects(vid_width, vid_height, &src_rect, &dst_rect, &borders, NULL);
256 out_rect_vid.x0 = dst_rect.left;
257 out_rect_vid.x1 = dst_rect.right;
258 out_rect_vid.y0 = dst_rect.top;
259 out_rect_vid.y1 = dst_rect.bottom;
260 src_rect_vid.x0 = src_rect.left;
261 src_rect_vid.x1 = src_rect.right;
262 src_rect_vid.y0 = src_rect.top;
263 src_rect_vid.y1 = src_rect.bottom;
264 border_x = borders.left;
265 border_y = borders.top;
266 #ifdef CONFIG_FREETYPE
267 // adjust font size to display size
268 force_load_font = 1;
269 #endif
270 vo_osd_changed(OSDTYPE_OSD);
272 if (output_surface_width < vo_dwidth || output_surface_height < vo_dheight) {
273 if (output_surface_width < vo_dwidth) {
274 output_surface_width += output_surface_width >> 1;
275 output_surface_width = FFMAX(output_surface_width, vo_dwidth);
277 if (output_surface_height < vo_dheight) {
278 output_surface_height += output_surface_height >> 1;
279 output_surface_height = FFMAX(output_surface_height, vo_dheight);
281 // Creation of output_surfaces
282 for (i = 0; i <= NUM_OUTPUT_SURFACES; i++) {
283 if (output_surfaces[i] != VDP_INVALID_HANDLE)
284 vdp_output_surface_destroy(output_surfaces[i]);
285 vdp_st = vdp_output_surface_create(vdp_device, VDP_RGBA_FORMAT_B8G8R8A8,
286 output_surface_width, output_surface_height,
287 &output_surfaces[i]);
288 CHECK_ST_WARNING("Error when calling vdp_output_surface_create")
289 mp_msg(MSGT_VO, MSGL_DBG2, "OUT CREATE: %u\n", output_surfaces[i]);
292 video_to_output_surface();
293 if (visible_buf)
294 flip_page();
297 /* Initialize vdp_get_proc_address, called from preinit() */
298 static int win_x11_init_vdpau_procs(void)
300 VdpStatus vdp_st;
302 struct vdp_function {
303 const int id;
304 void *pointer;
307 const struct vdp_function *dsc;
309 static const struct vdp_function vdp_func[] = {
310 {VDP_FUNC_ID_GET_ERROR_STRING, &vdp_get_error_string},
311 {VDP_FUNC_ID_DEVICE_DESTROY, &vdp_device_destroy},
312 {VDP_FUNC_ID_VIDEO_SURFACE_CREATE, &vdp_video_surface_create},
313 {VDP_FUNC_ID_VIDEO_SURFACE_DESTROY, &vdp_video_surface_destroy},
314 {VDP_FUNC_ID_VIDEO_SURFACE_PUT_BITS_Y_CB_CR,
315 &vdp_video_surface_put_bits_y_cb_cr},
316 {VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_NATIVE,
317 &vdp_output_surface_put_bits_native},
318 {VDP_FUNC_ID_OUTPUT_SURFACE_CREATE, &vdp_output_surface_create},
319 {VDP_FUNC_ID_OUTPUT_SURFACE_DESTROY, &vdp_output_surface_destroy},
320 {VDP_FUNC_ID_VIDEO_MIXER_CREATE, &vdp_video_mixer_create},
321 {VDP_FUNC_ID_VIDEO_MIXER_DESTROY, &vdp_video_mixer_destroy},
322 {VDP_FUNC_ID_VIDEO_MIXER_RENDER, &vdp_video_mixer_render},
323 {VDP_FUNC_ID_VIDEO_MIXER_SET_FEATURE_ENABLES,
324 &vdp_video_mixer_set_feature_enables},
325 {VDP_FUNC_ID_VIDEO_MIXER_SET_ATTRIBUTE_VALUES,
326 &vdp_video_mixer_set_attribute_values},
327 {VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_DESTROY,
328 &vdp_presentation_queue_target_destroy},
329 {VDP_FUNC_ID_PRESENTATION_QUEUE_CREATE, &vdp_presentation_queue_create},
330 {VDP_FUNC_ID_PRESENTATION_QUEUE_DESTROY,
331 &vdp_presentation_queue_destroy},
332 {VDP_FUNC_ID_PRESENTATION_QUEUE_DISPLAY,
333 &vdp_presentation_queue_display},
334 {VDP_FUNC_ID_PRESENTATION_QUEUE_BLOCK_UNTIL_SURFACE_IDLE,
335 &vdp_presentation_queue_block_until_surface_idle},
336 {VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_CREATE_X11,
337 &vdp_presentation_queue_target_create_x11},
338 {VDP_FUNC_ID_OUTPUT_SURFACE_RENDER_OUTPUT_SURFACE,
339 &vdp_output_surface_render_output_surface},
340 {VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_INDEXED,
341 &vdp_output_surface_put_bits_indexed},
342 {VDP_FUNC_ID_DECODER_CREATE, &vdp_decoder_create},
343 {VDP_FUNC_ID_DECODER_RENDER, &vdp_decoder_render},
344 {VDP_FUNC_ID_DECODER_DESTROY, &vdp_decoder_destroy},
345 {VDP_FUNC_ID_BITMAP_SURFACE_CREATE, &vdp_bitmap_surface_create},
346 {VDP_FUNC_ID_BITMAP_SURFACE_DESTROY, &vdp_bitmap_surface_destroy},
347 {VDP_FUNC_ID_BITMAP_SURFACE_PUT_BITS_NATIVE,
348 &vdp_bitmap_surface_putbits_native},
349 {VDP_FUNC_ID_OUTPUT_SURFACE_RENDER_BITMAP_SURFACE,
350 &vdp_output_surface_render_bitmap_surface},
351 {VDP_FUNC_ID_GENERATE_CSC_MATRIX, &vdp_generate_csc_matrix},
352 {0, NULL}
355 vdp_st = vdp_device_create(mDisplay, mScreen,
356 &vdp_device, &vdp_get_proc_address);
357 if (vdp_st != VDP_STATUS_OK) {
358 mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Error when calling vdp_device_create_x11: %i\n", vdp_st);
359 return -1;
362 for (dsc = vdp_func; dsc->pointer; dsc++) {
363 vdp_st = vdp_get_proc_address(vdp_device, dsc->id, dsc->pointer);
364 if (vdp_st != VDP_STATUS_OK) {
365 mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Error when calling vdp_get_proc_address(function id %d): %s\n", dsc->id, vdp_get_error_string ? vdp_get_error_string(vdp_st) : "?");
366 return -1;
369 return 0;
372 /* Initialize vdpau_flip_queue, called from config() */
373 static int win_x11_init_vdpau_flip_queue(void)
375 VdpStatus vdp_st;
377 vdp_st = vdp_presentation_queue_target_create_x11(vdp_device, vo_window,
378 &vdp_flip_target);
379 CHECK_ST_ERROR("Error when calling vdp_presentation_queue_target_create_x11")
381 vdp_st = vdp_presentation_queue_create(vdp_device, vdp_flip_target,
382 &vdp_flip_queue);
383 CHECK_ST_ERROR("Error when calling vdp_presentation_queue_create")
385 return 0;
388 static int create_vdp_mixer(VdpChromaType vdp_chroma_type) {
389 #define VDP_NUM_MIXER_PARAMETER 3
390 #define MAX_NUM_FEATURES 5
391 int i;
392 VdpStatus vdp_st;
393 int feature_count = 0;
394 VdpVideoMixerFeature features[MAX_NUM_FEATURES];
395 VdpBool feature_enables[MAX_NUM_FEATURES];
396 static const VdpVideoMixerAttribute denoise_attrib[] = {VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL};
397 const void * const denoise_value[] = {&denoise};
398 static const VdpVideoMixerAttribute sharpen_attrib[] = {VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL};
399 const void * const sharpen_value[] = {&sharpen};
400 static const VdpVideoMixerParameter parameters[VDP_NUM_MIXER_PARAMETER] = {
401 VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH,
402 VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT,
403 VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE
405 const void *const parameter_values[VDP_NUM_MIXER_PARAMETER] = {
406 &vid_width,
407 &vid_height,
408 &vdp_chroma_type
410 if (deint == 3)
411 features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL;
412 if (deint == 4)
413 features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL;
414 if (pullup)
415 features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE;
416 if (denoise)
417 features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION;
418 if (sharpen)
419 features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_SHARPNESS;
421 vdp_st = vdp_video_mixer_create(vdp_device, feature_count, features,
422 VDP_NUM_MIXER_PARAMETER,
423 parameters, parameter_values,
424 &video_mixer);
425 CHECK_ST_ERROR("Error when calling vdp_video_mixer_create")
427 for (i = 0; i < feature_count; i++) feature_enables[i] = VDP_TRUE;
428 if (feature_count)
429 vdp_video_mixer_set_feature_enables(video_mixer, feature_count, features, feature_enables);
430 if (denoise)
431 vdp_video_mixer_set_attribute_values(video_mixer, 1, denoise_attrib, denoise_value);
432 if (sharpen)
433 vdp_video_mixer_set_attribute_values(video_mixer, 1, sharpen_attrib, sharpen_value);
435 return 0;
438 // Free everything specific to a certain video file
439 static void free_video_specific(void) {
440 int i;
441 VdpStatus vdp_st;
443 if (decoder != VDP_INVALID_HANDLE)
444 vdp_decoder_destroy(decoder);
445 decoder = VDP_INVALID_HANDLE;
446 decoder_max_refs = -1;
448 for (i = 0; i < MAX_VIDEO_SURFACES; i++) {
449 if (surface_render[i].surface != VDP_INVALID_HANDLE) {
450 vdp_st = vdp_video_surface_destroy(surface_render[i].surface);
451 CHECK_ST_WARNING("Error when calling vdp_video_surface_destroy")
453 surface_render[i].surface = VDP_INVALID_HANDLE;
456 if (video_mixer != VDP_INVALID_HANDLE) {
457 vdp_st = vdp_video_mixer_destroy(video_mixer);
458 CHECK_ST_WARNING("Error when calling vdp_video_mixer_destroy")
460 video_mixer = VDP_INVALID_HANDLE;
464 * connect to X server, create and map window, initialize all
465 * VDPAU objects, create different surfaces etc.
467 static int config(uint32_t width, uint32_t height, uint32_t d_width,
468 uint32_t d_height, uint32_t flags, char *title,
469 uint32_t format)
471 XVisualInfo vinfo;
472 XSetWindowAttributes xswa;
473 XWindowAttributes attribs;
474 unsigned long xswamask;
475 int depth;
477 #ifdef CONFIG_XF86VM
478 int vm = flags & VOFLAG_MODESWITCHING;
479 #endif
481 image_format = format;
483 int_pause = 0;
484 visible_buf = 0;
486 #ifdef CONFIG_GUI
487 if (use_gui)
488 guiGetEvent(guiSetShVideo, 0); // the GUI will set up / resize our window
489 else
490 #endif
492 #ifdef CONFIG_XF86VM
493 if (vm)
494 vo_vm_switch();
495 else
496 #endif
497 XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &attribs);
498 depth = attribs.depth;
499 if (depth != 15 && depth != 16 && depth != 24 && depth != 32)
500 depth = 24;
501 XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo);
503 xswa.background_pixel = 0;
504 xswa.border_pixel = 0;
505 xswamask = CWBackPixel | CWBorderPixel;
507 vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, d_width, d_height,
508 flags, CopyFromParent, "vdpau", title);
509 XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa);
511 #ifdef CONFIG_XF86VM
512 if (vm) {
513 /* Grab the mouse pointer in our window */
514 if (vo_grabpointer)
515 XGrabPointer(mDisplay, vo_window, True, 0,
516 GrabModeAsync, GrabModeAsync,
517 vo_window, None, CurrentTime);
518 XSetInputFocus(mDisplay, vo_window, RevertToNone, CurrentTime);
520 #endif
523 if ((flags & VOFLAG_FULLSCREEN) && WinID <= 0)
524 vo_fs = 1;
526 /* -----VDPAU related code here -------- */
528 free_video_specific();
530 if (vdp_flip_queue == VDP_INVALID_HANDLE && win_x11_init_vdpau_flip_queue())
531 return -1;
533 // video width and height
534 vid_width = width;
535 vid_height = height;
537 if (create_vdp_mixer(vdp_chroma_type))
538 return -1;
540 surface_num = 0;
541 vid_surface_num = -1;
542 resize();
544 return 0;
547 static void check_events(void)
549 int e = vo_x11_check_events(mDisplay);
551 if (e & VO_EVENT_RESIZE)
552 resize();
554 if ((e & VO_EVENT_EXPOSE || e & VO_EVENT_RESIZE) && int_pause) {
555 /* did we already draw a buffer */
556 if (visible_buf) {
557 /* redraw the last visible buffer */
558 VdpStatus vdp_st;
559 vdp_st = vdp_presentation_queue_display(vdp_flip_queue,
560 output_surfaces[surface_num],
561 vo_dwidth, vo_dheight,
563 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_display")
568 static void draw_osd_I8A8(int x0,int y0, int w,int h, unsigned char *src,
569 unsigned char *srca, int stride)
571 VdpOutputSurface output_surface = output_surfaces[surface_num];
572 VdpStatus vdp_st;
573 int i, j;
574 int pitch;
575 int index_data_size_required;
576 VdpRect output_indexed_rect_vid;
577 VdpOutputSurfaceRenderBlendState blend_state;
579 if (!w || !h)
580 return;
582 index_data_size_required = 2*w*h;
583 if (index_data_size < index_data_size_required) {
584 index_data = realloc(index_data, index_data_size_required);
585 index_data_size = index_data_size_required;
588 // index_data creation, component order - I, A, I, A, .....
589 for (i = 0; i < h; i++)
590 for (j = 0; j < w; j++) {
591 index_data[i*2*w + j*2] = src [i*stride+j];
592 index_data[i*2*w + j*2 + 1] = -srca[i*stride+j];
595 output_indexed_rect_vid.x0 = x0;
596 output_indexed_rect_vid.y0 = y0;
597 output_indexed_rect_vid.x1 = x0 + w;
598 output_indexed_rect_vid.y1 = y0 + h;
600 pitch = w*2;
602 // write source_data to osd_surface.
603 vdp_st = vdp_output_surface_put_bits_indexed(osd_surface,
604 VDP_INDEXED_FORMAT_I8A8,
605 (const void *const*)&index_data,
606 &pitch,
607 &output_indexed_rect_vid,
608 VDP_COLOR_TABLE_FORMAT_B8G8R8X8,
609 (void *)palette);
610 CHECK_ST_WARNING("Error when calling vdp_output_surface_put_bits_indexed")
612 blend_state.struct_version = VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION;
613 blend_state.blend_factor_source_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE;
614 blend_state.blend_factor_source_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE;
615 blend_state.blend_factor_destination_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
616 blend_state.blend_factor_destination_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
617 blend_state.blend_equation_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD;
618 blend_state.blend_equation_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD;
620 vdp_st = vdp_output_surface_render_output_surface(output_surface,
621 &output_indexed_rect_vid,
622 osd_surface,
623 &output_indexed_rect_vid,
624 NULL,
625 &blend_state,
626 VDP_OUTPUT_SURFACE_RENDER_ROTATE_0);
627 CHECK_ST_WARNING("Error when calling vdp_output_surface_render_output_surface")
630 static void draw_eosd(void) {
631 VdpStatus vdp_st;
632 VdpOutputSurface output_surface = output_surfaces[surface_num];
633 VdpOutputSurfaceRenderBlendState blend_state;
634 int i;
636 blend_state.struct_version = VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION;
637 blend_state.blend_factor_source_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_SRC_ALPHA;
638 blend_state.blend_factor_source_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE;
639 blend_state.blend_factor_destination_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
640 blend_state.blend_factor_destination_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_SRC_ALPHA;
641 blend_state.blend_equation_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD;
642 blend_state.blend_equation_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD;
644 for (i=0; i<eosd_render_count; i++) {
645 vdp_st = vdp_output_surface_render_bitmap_surface(
646 output_surface, &eosd_targets[i].dest,
647 eosd_targets[i].surface, &eosd_targets[i].source,
648 &eosd_targets[i].color, &blend_state,
649 VDP_OUTPUT_SURFACE_RENDER_ROTATE_0);
650 CHECK_ST_WARNING("EOSD: Error when rendering")
654 static void generate_eosd(mp_eosd_images_t *imgs) {
655 VdpStatus vdp_st;
656 VdpRect destRect;
657 int j, found;
658 ass_image_t *img = imgs->imgs;
659 ass_image_t *i;
661 // Nothing changed, no need to redraw
662 if (imgs->changed == 0)
663 return;
664 eosd_render_count = 0;
665 // There's nothing to render!
666 if (!img)
667 return;
669 if (imgs->changed == 1)
670 goto eosd_skip_upload;
672 for (j=0; j<eosd_surface_count; j++)
673 eosd_surfaces[j].in_use = 0;
675 for (i = img; i; i = i->next) {
676 // Try to reuse a suitable surface
677 found = -1;
678 for (j=0; j<eosd_surface_count; j++) {
679 if (eosd_surfaces[j].surface != VDP_INVALID_HANDLE && !eosd_surfaces[j].in_use &&
680 eosd_surfaces[j].w >= i->w && eosd_surfaces[j].h >= i->h) {
681 found = j;
682 break;
685 // None found, allocate a new surface
686 if (found < 0) {
687 for (j=0; j<eosd_surface_count; j++) {
688 if (!eosd_surfaces[j].in_use) {
689 if (eosd_surfaces[j].surface != VDP_INVALID_HANDLE)
690 vdp_bitmap_surface_destroy(eosd_surfaces[j].surface);
691 found = j;
692 break;
695 // Allocate new space for surface/target arrays
696 if (found < 0) {
697 j = found = eosd_surface_count;
698 eosd_surface_count = eosd_surface_count ? eosd_surface_count*2 : EOSD_SURFACES_INITIAL;
699 eosd_surfaces = realloc(eosd_surfaces, eosd_surface_count * sizeof(*eosd_surfaces));
700 eosd_targets = realloc(eosd_targets, eosd_surface_count * sizeof(*eosd_targets));
701 for(j=found; j<eosd_surface_count; j++) {
702 eosd_surfaces[j].surface = VDP_INVALID_HANDLE;
703 eosd_surfaces[j].in_use = 0;
706 vdp_st = vdp_bitmap_surface_create(vdp_device, VDP_RGBA_FORMAT_A8,
707 i->w, i->h, VDP_TRUE, &eosd_surfaces[found].surface);
708 CHECK_ST_WARNING("EOSD: error when creating surface")
709 eosd_surfaces[found].w = i->w;
710 eosd_surfaces[found].h = i->h;
712 eosd_surfaces[found].in_use = 1;
713 eosd_targets[eosd_render_count].surface = eosd_surfaces[found].surface;
714 destRect.x0 = 0;
715 destRect.y0 = 0;
716 destRect.x1 = i->w;
717 destRect.y1 = i->h;
718 vdp_st = vdp_bitmap_surface_putbits_native(eosd_targets[eosd_render_count].surface,
719 (const void *) &i->bitmap, &i->stride, &destRect);
720 CHECK_ST_WARNING("EOSD: putbits failed")
721 eosd_render_count++;
724 eosd_skip_upload:
725 eosd_render_count = 0;
726 for (i = img; i; i = i->next) {
727 // Render dest, color, etc.
728 eosd_targets[eosd_render_count].color.alpha = 1.0 - ((i->color >> 0) & 0xff) / 255.0;
729 eosd_targets[eosd_render_count].color.blue = ((i->color >> 8) & 0xff) / 255.0;
730 eosd_targets[eosd_render_count].color.green = ((i->color >> 16) & 0xff) / 255.0;
731 eosd_targets[eosd_render_count].color.red = ((i->color >> 24) & 0xff) / 255.0;
732 eosd_targets[eosd_render_count].dest.x0 = i->dst_x;
733 eosd_targets[eosd_render_count].dest.y0 = i->dst_y;
734 eosd_targets[eosd_render_count].dest.x1 = i->w + i->dst_x;
735 eosd_targets[eosd_render_count].dest.y1 = i->h + i->dst_y;
736 eosd_targets[eosd_render_count].source.x0 = 0;
737 eosd_targets[eosd_render_count].source.y0 = 0;
738 eosd_targets[eosd_render_count].source.x1 = i->w;
739 eosd_targets[eosd_render_count].source.y1 = i->h;
740 eosd_render_count++;
744 static void draw_osd(void)
746 mp_msg(MSGT_VO, MSGL_DBG2, "DRAW_OSD\n");
748 vo_draw_text_ext(vo_dwidth, vo_dheight, border_x, border_y, border_x, border_y,
749 vid_width, vid_height, draw_osd_I8A8);
752 static void flip_page(void)
754 VdpStatus vdp_st;
755 mp_msg(MSGT_VO, MSGL_DBG2, "\nFLIP_PAGE VID:%u -> OUT:%u\n",
756 surface_render[vid_surface_num].surface, output_surfaces[surface_num]);
758 vdp_st = vdp_presentation_queue_display(vdp_flip_queue, output_surfaces[surface_num],
759 vo_dwidth, vo_dheight,
761 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_display")
763 surface_num = (surface_num + 1) % NUM_OUTPUT_SURFACES;
764 visible_buf = 1;
767 static int draw_slice(uint8_t *image[], int stride[], int w, int h,
768 int x, int y)
770 VdpStatus vdp_st;
771 struct vdpau_render_state *rndr = (struct vdpau_render_state *)image[0];
772 int max_refs = image_format == IMGFMT_VDPAU_H264 ? rndr->info.h264.num_ref_frames : 2;
773 if (!IMGFMT_IS_VDPAU(image_format))
774 return VO_FALSE;
775 if (decoder == VDP_INVALID_HANDLE || decoder_max_refs < max_refs) {
776 VdpDecoderProfile vdp_decoder_profile;
777 if (decoder != VDP_INVALID_HANDLE)
778 vdp_decoder_destroy(decoder);
779 decoder = VDP_INVALID_HANDLE;
780 switch (image_format) {
781 case IMGFMT_VDPAU_MPEG1:
782 vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG1;
783 break;
784 case IMGFMT_VDPAU_MPEG2:
785 vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG2_MAIN;
786 break;
787 case IMGFMT_VDPAU_H264:
788 vdp_decoder_profile = VDP_DECODER_PROFILE_H264_HIGH;
789 mp_msg(MSGT_VO, MSGL_V, "[vdpau] Creating H264 hardware decoder for %d reference frames.\n", max_refs);
790 break;
791 case IMGFMT_VDPAU_WMV3:
792 vdp_decoder_profile = VDP_DECODER_PROFILE_VC1_MAIN;
793 break;
794 case IMGFMT_VDPAU_VC1:
795 vdp_decoder_profile = VDP_DECODER_PROFILE_VC1_ADVANCED;
796 break;
798 vdp_st = vdp_decoder_create(vdp_device, vdp_decoder_profile, vid_width, vid_height, max_refs, &decoder);
799 CHECK_ST_WARNING("Failed creating VDPAU decoder");
800 if (vdp_st != VDP_STATUS_OK) {
801 decoder = VDP_INVALID_HANDLE;
802 decoder_max_refs = 0;
803 return VO_FALSE;
805 decoder_max_refs = max_refs;
807 vdp_st = vdp_decoder_render(decoder, rndr->surface, (void *)&rndr->info, rndr->bitstream_buffers_used, rndr->bitstream_buffers);
808 CHECK_ST_WARNING("Failed VDPAU decoder rendering");
809 return VO_TRUE;
813 static int draw_frame(uint8_t *src[])
815 return VO_ERROR;
818 static struct vdpau_render_state *get_surface(int number)
820 if (number > MAX_VIDEO_SURFACES)
821 return NULL;
822 if (surface_render[number].surface == VDP_INVALID_HANDLE) {
823 VdpStatus vdp_st;
824 vdp_st = vdp_video_surface_create(vdp_device, vdp_chroma_type,
825 vid_width, vid_height,
826 &surface_render[number].surface);
827 CHECK_ST_WARNING("Error when calling vdp_video_surface_create")
828 if (vdp_st != VDP_STATUS_OK)
829 return NULL;
831 mp_msg(MSGT_VO, MSGL_DBG2, "VID CREATE: %u\n", surface_render[number].surface);
832 return &surface_render[number];
835 static uint32_t draw_image(mp_image_t *mpi)
837 if (IMGFMT_IS_VDPAU(image_format)) {
838 struct vdpau_render_state *rndr = mpi->priv;
839 vid_surface_num = rndr - surface_render;
840 } else if (!(mpi->flags & MP_IMGFLAG_DRAW_CALLBACK)) {
841 VdpStatus vdp_st;
842 void *destdata[3] = {mpi->planes[0], mpi->planes[2], mpi->planes[1]};
843 struct vdpau_render_state *rndr = get_surface(0);
844 vid_surface_num = rndr - surface_render;
845 vdp_st = vdp_video_surface_put_bits_y_cb_cr(rndr->surface,
846 VDP_YCBCR_FORMAT_YV12,
847 (const void *const*)destdata,
848 mpi->stride); // pitch
849 CHECK_ST_ERROR("Error when calling vdp_video_surface_put_bits_y_cb_cr")
851 top_field_first = !!(mpi->fields & MP_IMGFIELD_TOP_FIRST);
853 video_to_output_surface();
854 return VO_TRUE;
857 static uint32_t get_image(mp_image_t *mpi)
859 struct vdpau_render_state *rndr;
861 // no dr for non-decoding for now
862 if (!IMGFMT_IS_VDPAU(image_format)) return VO_FALSE;
863 if (mpi->type != MP_IMGTYPE_NUMBERED) return VO_FALSE;
865 rndr = get_surface(mpi->number);
866 if (!rndr) {
867 mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] no surfaces available in get_image\n");
868 // TODO: this probably breaks things forever, provide a dummy buffer?
869 return VO_FALSE;
871 mpi->flags |= MP_IMGFLAG_DIRECT;
872 mpi->stride[0] = mpi->stride[1] = mpi->stride[2] = 0;
873 mpi->planes[0] = mpi->planes[1] = mpi->planes[2] = NULL;
874 // hack to get around a check and to avoid a special-case in vd_ffmpeg.c
875 mpi->planes[0] = (void *)rndr;
876 mpi->num_planes = 1;
877 mpi->priv = rndr;
878 return VO_TRUE;
881 static int query_format(uint32_t format)
883 int default_flags = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_OSD | VFCAP_EOSD | VFCAP_EOSD_UNSCALED;
884 switch (format) {
885 case IMGFMT_YV12:
886 return default_flags | VOCAP_NOSLICES;
887 case IMGFMT_VDPAU_MPEG1:
888 case IMGFMT_VDPAU_MPEG2:
889 case IMGFMT_VDPAU_H264:
890 case IMGFMT_VDPAU_WMV3:
891 case IMGFMT_VDPAU_VC1:
892 return default_flags;
894 return 0;
897 static void DestroyVdpauObjects(void)
899 int i;
900 VdpStatus vdp_st;
902 free_video_specific();
904 vdp_st = vdp_presentation_queue_destroy(vdp_flip_queue);
905 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_destroy")
907 vdp_st = vdp_presentation_queue_target_destroy(vdp_flip_target);
908 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_target_destroy")
910 for (i = 0; i <= NUM_OUTPUT_SURFACES; i++) {
911 vdp_st = vdp_output_surface_destroy(output_surfaces[i]);
912 output_surfaces[i] = VDP_INVALID_HANDLE;
913 CHECK_ST_WARNING("Error when calling vdp_output_surface_destroy")
916 for (i = 0; i<eosd_surface_count; i++) {
917 if (eosd_surfaces[i].surface != VDP_INVALID_HANDLE) {
918 vdp_st = vdp_bitmap_surface_destroy(eosd_surfaces[i].surface);
919 CHECK_ST_WARNING("Error when calling vdp_bitmap_surface_destroy")
921 eosd_surfaces[i].surface = VDP_INVALID_HANDLE;
924 vdp_st = vdp_device_destroy(vdp_device);
925 CHECK_ST_WARNING("Error when calling vdp_device_destroy")
928 static void uninit(void)
930 if (!vo_config_count)
931 return;
932 visible_buf = 0;
934 /* Destroy all vdpau objects */
935 DestroyVdpauObjects();
937 free(index_data);
938 index_data = NULL;
940 free(eosd_surfaces);
941 eosd_surfaces = NULL;
942 free(eosd_targets);
943 eosd_targets = NULL;
945 #ifdef CONFIG_XF86VM
946 vo_vm_close();
947 #endif
948 vo_x11_uninit();
950 dlclose(vdpau_lib_handle);
953 static const opt_t subopts[] = {
954 {"deint", OPT_ARG_INT, &deint, (opt_test_f)int_non_neg},
955 {"pullup", OPT_ARG_BOOL, &pullup, NULL},
956 {"denoise", OPT_ARG_FLOAT, &denoise, NULL},
957 {"sharpen", OPT_ARG_FLOAT, &sharpen, NULL},
958 {NULL}
961 static const char help_msg[] =
962 "\n-vo vdpau command line help:\n"
963 "Example: mplayer -vo vdpau:deint=2\n"
964 "\nOptions:\n"
965 " deint (all modes > 0 respect -field-dominance)\n"
966 " 0: no deinterlacing\n"
967 " 1: only show first field\n"
968 " 2: bob deinterlacing (current fallback)\n"
969 " 3: temporal deinterlacing (not yet working)\n"
970 " 4: temporal-spatial deinterlacing (not yet working)\n"
971 " pullup\n"
972 " Try to apply inverse-telecine (needs deinterlacing, not working)\n"
973 " denoise\n"
974 " Apply denoising, argument is strength from 0.0 to 1.0\n"
975 " sharpen\n"
976 " Apply sharpening or softening, argument is strength from -1.0 to 1.0\n"
979 static int preinit(const char *arg)
981 int i;
982 static const char *vdpaulibrary = "libvdpau.so.1";
983 static const char *vdpau_device_create = "vdp_device_create_x11";
985 deint = 0;
986 deint_type = 3;
987 pullup = 0;
988 denoise = 0;
989 sharpen = 0;
990 if (subopt_parse(arg, subopts) != 0) {
991 mp_msg(MSGT_VO, MSGL_FATAL, help_msg);
992 return -1;
994 if (deint)
995 deint_type = deint;
997 vdpau_lib_handle = dlopen(vdpaulibrary, RTLD_LAZY);
998 if (!vdpau_lib_handle) {
999 mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Could not open dynamic library %s\n",
1000 vdpaulibrary);
1001 return -1;
1003 vdp_device_create = dlsym(vdpau_lib_handle, vdpau_device_create);
1004 if (!vdp_device_create) {
1005 mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Could not find function %s in %s\n",
1006 vdpau_device_create, vdpaulibrary);
1007 return -1;
1009 if (!vo_init() || win_x11_init_vdpau_procs())
1010 return -1;
1012 decoder = VDP_INVALID_HANDLE;
1013 for (i = 0; i < MAX_VIDEO_SURFACES; i++)
1014 surface_render[i].surface = VDP_INVALID_HANDLE;
1015 video_mixer = VDP_INVALID_HANDLE;
1016 for (i = 0; i <= NUM_OUTPUT_SURFACES; i++)
1017 output_surfaces[i] = VDP_INVALID_HANDLE;
1018 vdp_flip_queue = VDP_INVALID_HANDLE;
1019 output_surface_width = output_surface_height = -1;
1021 // full grayscale palette.
1022 for (i = 0; i < PALETTE_SIZE; ++i)
1023 palette[i] = (i << 16) | (i << 8) | i;
1024 index_data = NULL;
1025 index_data_size = 0;
1027 eosd_surface_count = eosd_render_count = 0;
1028 eosd_surfaces = NULL;
1029 eosd_targets = NULL;
1031 procamp.struct_version = VDP_PROCAMP_VERSION;
1032 procamp.brightness = 0.0;
1033 procamp.contrast = 1.0;
1034 procamp.saturation = 1.0;
1035 procamp.hue = 0.0;
1037 return 0;
1040 static int get_equalizer(char *name, int *value) {
1041 if (!strcasecmp(name, "brightness"))
1042 *value = procamp.brightness * 100;
1043 else if (!strcasecmp(name, "contrast"))
1044 *value = (procamp.contrast-1.0) * 100;
1045 else if (!strcasecmp(name, "saturation"))
1046 *value = (procamp.saturation-1.0) * 100;
1047 else if (!strcasecmp(name, "hue"))
1048 *value = procamp.hue * 100 / M_PI;
1049 else
1050 return VO_NOTIMPL;
1051 return VO_TRUE;
1054 static int set_equalizer(char *name, int value) {
1055 VdpStatus vdp_st;
1056 VdpCSCMatrix matrix;
1057 static const VdpVideoMixerAttribute attributes[] = {VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX};
1058 const void *attribute_values[] = {&matrix};
1060 if (!strcasecmp(name, "brightness"))
1061 procamp.brightness = value / 100.0;
1062 else if (!strcasecmp(name, "contrast"))
1063 procamp.contrast = value / 100.0 + 1.0;
1064 else if (!strcasecmp(name, "saturation"))
1065 procamp.saturation = value / 100.0 + 1.0;
1066 else if (!strcasecmp(name, "hue"))
1067 procamp.hue = value / 100.0 * M_PI;
1068 else
1069 return VO_NOTIMPL;
1071 vdp_st = vdp_generate_csc_matrix(&procamp, VDP_COLOR_STANDARD_ITUR_BT_601,
1072 &matrix);
1073 CHECK_ST_WARNING("Error when generating CSC matrix")
1074 vdp_st = vdp_video_mixer_set_attribute_values(video_mixer, 1, attributes,
1075 attribute_values);
1076 CHECK_ST_WARNING("Error when setting CSC matrix")
1077 return VO_TRUE;
1080 static int control(uint32_t request, void *data, ...)
1082 switch (request) {
1083 case VOCTRL_GET_DEINTERLACE:
1084 *(int*)data = deint;
1085 return VO_TRUE;
1086 case VOCTRL_SET_DEINTERLACE:
1087 deint = *(int*)data;
1088 if (deint)
1089 deint = deint_type;
1090 return VO_TRUE;
1091 case VOCTRL_PAUSE:
1092 return (int_pause = 1);
1093 case VOCTRL_RESUME:
1094 return (int_pause = 0);
1095 case VOCTRL_QUERY_FORMAT:
1096 return query_format(*(uint32_t *)data);
1097 case VOCTRL_GET_IMAGE:
1098 return get_image(data);
1099 case VOCTRL_DRAW_IMAGE:
1100 return draw_image(data);
1101 case VOCTRL_GUISUPPORT:
1102 return VO_TRUE;
1103 case VOCTRL_BORDER:
1104 vo_x11_border();
1105 resize();
1106 return VO_TRUE;
1107 case VOCTRL_FULLSCREEN:
1108 vo_x11_fullscreen();
1109 resize();
1110 return VO_TRUE;
1111 case VOCTRL_GET_PANSCAN:
1112 return VO_TRUE;
1113 case VOCTRL_SET_PANSCAN:
1114 resize();
1115 return VO_TRUE;
1116 case VOCTRL_SET_EQUALIZER: {
1117 va_list ap;
1118 int value;
1120 va_start(ap, data);
1121 value = va_arg(ap, int);
1123 va_end(ap);
1124 return set_equalizer(data, value);
1126 case VOCTRL_GET_EQUALIZER: {
1127 va_list ap;
1128 int *value;
1130 va_start(ap, data);
1131 value = va_arg(ap, int *);
1133 va_end(ap);
1134 return get_equalizer(data, value);
1136 case VOCTRL_ONTOP:
1137 vo_x11_ontop();
1138 return VO_TRUE;
1139 case VOCTRL_UPDATE_SCREENINFO:
1140 update_xinerama_info();
1141 return VO_TRUE;
1142 case VOCTRL_DRAW_EOSD:
1143 if (!data)
1144 return VO_FALSE;
1145 generate_eosd(data);
1146 draw_eosd();
1147 return VO_TRUE;
1148 case VOCTRL_GET_EOSD_RES: {
1149 mp_eosd_res_t *r = data;
1150 r->mt = r->mb = r->ml = r->mr = 0;
1151 if (vo_fs) {
1152 r->w = vo_screenwidth;
1153 r->h = vo_screenheight;
1154 r->ml = r->mr = border_x;
1155 r->mt = r->mb = border_y;
1156 } else {
1157 r->w = vo_dwidth;
1158 r->h = vo_dheight;
1160 return VO_TRUE;
1163 return VO_NOTIMPL;
1166 /* @} */