vo_vdpau: Make compile as new-style VO
[mplayer/glamo.git] / libvo / vo_vdpau.c
blobdee5c8adc4ac3e1180a0e567006b8cca0581480f
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 "options.h"
41 #include "video_out.h"
42 #include "x11_common.h"
43 #include "aspect.h"
44 #include "sub.h"
45 #include "subopt-helper.h"
46 #include "libmpcodecs/vfcap.h"
47 #include "libmpcodecs/mp_image.h"
49 #include "libavcodec/vdpau.h"
51 #include "font_load.h"
53 #include "libavutil/common.h"
54 #include "libavutil/mathematics.h"
56 #include "libass/ass.h"
57 #include "libass/ass_mp.h"
59 #define CHECK_ST_ERROR(message) \
60 if (vdp_st != VDP_STATUS_OK) { \
61 mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] %s: %s\n", \
62 message, vdp_get_error_string(vdp_st)); \
63 return -1; \
66 #define CHECK_ST_WARNING(message) \
67 if (vdp_st != VDP_STATUS_OK) \
68 mp_msg(MSGT_VO, MSGL_WARN, "[vdpau] %s: %s\n", \
69 message, vdp_get_error_string(vdp_st));
71 /* number of video and output surfaces */
72 #define NUM_OUTPUT_SURFACES 2
73 #define MAX_VIDEO_SURFACES 50
75 /* number of palette entries */
76 #define PALETTE_SIZE 256
78 /* Initial maximum number of EOSD surfaces */
79 #define EOSD_SURFACES_INITIAL 512
82 * Global variable declaration - VDPAU specific
85 /* Declaration for all variables of win_x11_init_vdpau_procs() and
86 * win_x11_init_vdpau_flip_queue() functions
88 static VdpDevice vdp_device;
89 static VdpDeviceCreateX11 *vdp_device_create;
90 static VdpGetProcAddress *vdp_get_proc_address;
92 static VdpPresentationQueueTarget vdp_flip_target;
93 static VdpPresentationQueue vdp_flip_queue;
95 static VdpDeviceDestroy *vdp_device_destroy;
96 static VdpVideoSurfaceCreate *vdp_video_surface_create;
97 static VdpVideoSurfaceDestroy *vdp_video_surface_destroy;
99 static VdpGetErrorString *vdp_get_error_string;
101 /* May be used in software filtering/postprocessing options
102 * in MPlayer (./mplayer -vf ..) if we copy video_surface data to
103 * system memory.
105 static VdpVideoSurfacePutBitsYCbCr *vdp_video_surface_put_bits_y_cb_cr;
106 static VdpOutputSurfacePutBitsNative *vdp_output_surface_put_bits_native;
108 static VdpOutputSurfaceCreate *vdp_output_surface_create;
109 static VdpOutputSurfaceDestroy *vdp_output_surface_destroy;
111 /* VideoMixer puts video_surface data on displayable output_surface. */
112 static VdpVideoMixerCreate *vdp_video_mixer_create;
113 static VdpVideoMixerDestroy *vdp_video_mixer_destroy;
114 static VdpVideoMixerRender *vdp_video_mixer_render;
115 static VdpVideoMixerSetFeatureEnables *vdp_video_mixer_set_feature_enables;
116 static VdpVideoMixerSetAttributeValues *vdp_video_mixer_set_attribute_values;
118 static VdpPresentationQueueTargetDestroy *vdp_presentation_queue_target_destroy;
119 static VdpPresentationQueueCreate *vdp_presentation_queue_create;
120 static VdpPresentationQueueDestroy *vdp_presentation_queue_destroy;
121 static VdpPresentationQueueDisplay *vdp_presentation_queue_display;
122 static VdpPresentationQueueBlockUntilSurfaceIdle *vdp_presentation_queue_block_until_surface_idle;
123 static VdpPresentationQueueTargetCreateX11 *vdp_presentation_queue_target_create_x11;
125 static VdpOutputSurfaceRenderOutputSurface *vdp_output_surface_render_output_surface;
126 static VdpOutputSurfacePutBitsIndexed *vdp_output_surface_put_bits_indexed;
127 static VdpOutputSurfaceRenderBitmapSurface *vdp_output_surface_render_bitmap_surface;
129 static VdpBitmapSurfaceCreate *vdp_bitmap_surface_create;
130 static VdpBitmapSurfaceDestroy *vdp_bitmap_surface_destroy;
131 static VdpBitmapSurfacePutBitsNative *vdp_bitmap_surface_putbits_native;
133 static VdpDecoderCreate *vdp_decoder_create;
134 static VdpDecoderDestroy *vdp_decoder_destroy;
135 static VdpDecoderRender *vdp_decoder_render;
137 static VdpGenerateCSCMatrix *vdp_generate_csc_matrix;
139 static void *vdpau_lib_handle;
140 /* output_surfaces[NUM_OUTPUT_SURFACES] is misused for OSD. */
141 #define osd_surface output_surfaces[NUM_OUTPUT_SURFACES]
142 static VdpOutputSurface output_surfaces[NUM_OUTPUT_SURFACES + 1];
143 static VdpVideoSurface deint_surfaces[3];
144 static mp_image_t *deint_mpi[2];
145 static int output_surface_width, output_surface_height;
147 static VdpVideoMixer video_mixer;
148 static int deint;
149 static int deint_type;
150 static int deint_counter;
151 static int deint_buffer_past_frames;
152 static int pullup;
153 static float denoise;
154 static float sharpen;
155 static int chroma_deint;
156 static int top_field_first;
158 static VdpDecoder decoder;
159 static int decoder_max_refs;
161 static VdpRect src_rect_vid;
162 static VdpRect out_rect_vid;
163 static int border_x, border_y;
165 static struct vdpau_render_state surface_render[MAX_VIDEO_SURFACES];
166 static int surface_num;
167 static int vid_surface_num;
168 static uint32_t vid_width, vid_height;
169 static uint32_t image_format;
170 static VdpChromaType vdp_chroma_type;
171 static VdpYCbCrFormat vdp_pixel_format;
173 /* draw_osd */
174 static unsigned char *index_data;
175 static int index_data_size;
176 static uint32_t palette[PALETTE_SIZE];
178 // EOSD
179 // Pool of surfaces
180 struct {
181 VdpBitmapSurface surface;
182 int w;
183 int h;
184 char in_use;
185 } *eosd_surfaces;
187 // List of surfaces to be rendered
188 struct {
189 VdpBitmapSurface surface;
190 VdpRect source;
191 VdpRect dest;
192 VdpColor color;
193 } *eosd_targets;
195 static int eosd_render_count;
196 static int eosd_surface_count;
198 // Video equalizer
199 static VdpProcamp procamp;
202 * X11 specific
204 static int visible_buf;
205 static int int_pause;
207 static void draw_eosd(void);
209 static void push_deint_surface(VdpVideoSurface surface)
211 deint_surfaces[2] = deint_surfaces[1];
212 deint_surfaces[1] = deint_surfaces[0];
213 deint_surfaces[0] = surface;
216 static void flip_page(struct vo *vo);
217 static void draw_osd(struct vo *vo, struct osd_state *osd);
218 static void video_to_output_surface(struct vo *vo)
220 VdpTime dummy;
221 VdpStatus vdp_st;
222 int i;
223 if (vid_surface_num < 0)
224 return;
226 if (deint < 2 || deint_surfaces[0] == VDP_INVALID_HANDLE)
227 push_deint_surface(surface_render[vid_surface_num].surface);
229 for (i = 0; i <= !!(deint > 1); i++) {
230 int field = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME;
231 VdpOutputSurface output_surface;
232 if (i) {
233 draw_eosd();
234 //draw_osd(vo, NULL);
235 flip_page(vo);
237 if (deint)
238 field = (top_field_first == i) ^ (deint > 1) ?
239 VDP_VIDEO_MIXER_PICTURE_STRUCTURE_BOTTOM_FIELD:
240 VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD;
241 output_surface = output_surfaces[surface_num];
242 vdp_st = vdp_presentation_queue_block_until_surface_idle(vdp_flip_queue,
243 output_surface,
244 &dummy);
245 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_block_until_surface_idle")
247 vdp_st = vdp_video_mixer_render(video_mixer, VDP_INVALID_HANDLE, 0,
248 field, 2, deint_surfaces + 1,
249 deint_surfaces[0],
250 1, &surface_render[vid_surface_num].surface,
251 &src_rect_vid,
252 output_surface,
253 NULL, &out_rect_vid, 0, NULL);
254 CHECK_ST_WARNING("Error when calling vdp_video_mixer_render")
255 push_deint_surface(surface_render[vid_surface_num].surface);
259 static void resize(struct vo *vo)
261 VdpStatus vdp_st;
262 int i;
263 struct vo_rect src_rect;
264 struct vo_rect dst_rect;
265 struct vo_rect borders;
266 calc_src_dst_rects(vo, vid_width, vid_height, &src_rect, &dst_rect,
267 &borders, NULL);
268 out_rect_vid.x0 = dst_rect.left;
269 out_rect_vid.x1 = dst_rect.right;
270 out_rect_vid.y0 = dst_rect.top;
271 out_rect_vid.y1 = dst_rect.bottom;
272 src_rect_vid.x0 = src_rect.left;
273 src_rect_vid.x1 = src_rect.right;
274 src_rect_vid.y0 = src_rect.top;
275 src_rect_vid.y1 = src_rect.bottom;
276 border_x = borders.left;
277 border_y = borders.top;
278 #ifdef CONFIG_FREETYPE
279 // adjust font size to display size
280 force_load_font = 1;
281 #endif
282 vo_osd_changed(OSDTYPE_OSD);
284 if (output_surface_width < vo->dwidth || output_surface_height < vo->dheight) {
285 if (output_surface_width < vo->dwidth) {
286 output_surface_width += output_surface_width >> 1;
287 output_surface_width = FFMAX(output_surface_width, vo->dwidth);
289 if (output_surface_height < vo->dheight) {
290 output_surface_height += output_surface_height >> 1;
291 output_surface_height = FFMAX(output_surface_height, vo->dheight);
293 // Creation of output_surfaces
294 for (i = 0; i <= NUM_OUTPUT_SURFACES; i++) {
295 if (output_surfaces[i] != VDP_INVALID_HANDLE)
296 vdp_output_surface_destroy(output_surfaces[i]);
297 vdp_st = vdp_output_surface_create(vdp_device, VDP_RGBA_FORMAT_B8G8R8A8,
298 output_surface_width, output_surface_height,
299 &output_surfaces[i]);
300 CHECK_ST_WARNING("Error when calling vdp_output_surface_create")
301 mp_msg(MSGT_VO, MSGL_DBG2, "OUT CREATE: %u\n", output_surfaces[i]);
304 video_to_output_surface(vo);
305 if (visible_buf)
306 flip_page(vo);
309 /* Initialize vdp_get_proc_address, called from preinit() */
310 static int win_x11_init_vdpau_procs(struct vo *vo)
312 struct vo_x11_state *x11 = vo->x11;
313 VdpStatus vdp_st;
315 struct vdp_function {
316 const int id;
317 void *pointer;
320 const struct vdp_function *dsc;
322 static const struct vdp_function vdp_func[] = {
323 {VDP_FUNC_ID_GET_ERROR_STRING, &vdp_get_error_string},
324 {VDP_FUNC_ID_DEVICE_DESTROY, &vdp_device_destroy},
325 {VDP_FUNC_ID_VIDEO_SURFACE_CREATE, &vdp_video_surface_create},
326 {VDP_FUNC_ID_VIDEO_SURFACE_DESTROY, &vdp_video_surface_destroy},
327 {VDP_FUNC_ID_VIDEO_SURFACE_PUT_BITS_Y_CB_CR,
328 &vdp_video_surface_put_bits_y_cb_cr},
329 {VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_NATIVE,
330 &vdp_output_surface_put_bits_native},
331 {VDP_FUNC_ID_OUTPUT_SURFACE_CREATE, &vdp_output_surface_create},
332 {VDP_FUNC_ID_OUTPUT_SURFACE_DESTROY, &vdp_output_surface_destroy},
333 {VDP_FUNC_ID_VIDEO_MIXER_CREATE, &vdp_video_mixer_create},
334 {VDP_FUNC_ID_VIDEO_MIXER_DESTROY, &vdp_video_mixer_destroy},
335 {VDP_FUNC_ID_VIDEO_MIXER_RENDER, &vdp_video_mixer_render},
336 {VDP_FUNC_ID_VIDEO_MIXER_SET_FEATURE_ENABLES,
337 &vdp_video_mixer_set_feature_enables},
338 {VDP_FUNC_ID_VIDEO_MIXER_SET_ATTRIBUTE_VALUES,
339 &vdp_video_mixer_set_attribute_values},
340 {VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_DESTROY,
341 &vdp_presentation_queue_target_destroy},
342 {VDP_FUNC_ID_PRESENTATION_QUEUE_CREATE, &vdp_presentation_queue_create},
343 {VDP_FUNC_ID_PRESENTATION_QUEUE_DESTROY,
344 &vdp_presentation_queue_destroy},
345 {VDP_FUNC_ID_PRESENTATION_QUEUE_DISPLAY,
346 &vdp_presentation_queue_display},
347 {VDP_FUNC_ID_PRESENTATION_QUEUE_BLOCK_UNTIL_SURFACE_IDLE,
348 &vdp_presentation_queue_block_until_surface_idle},
349 {VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_CREATE_X11,
350 &vdp_presentation_queue_target_create_x11},
351 {VDP_FUNC_ID_OUTPUT_SURFACE_RENDER_OUTPUT_SURFACE,
352 &vdp_output_surface_render_output_surface},
353 {VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_INDEXED,
354 &vdp_output_surface_put_bits_indexed},
355 {VDP_FUNC_ID_DECODER_CREATE, &vdp_decoder_create},
356 {VDP_FUNC_ID_DECODER_RENDER, &vdp_decoder_render},
357 {VDP_FUNC_ID_DECODER_DESTROY, &vdp_decoder_destroy},
358 {VDP_FUNC_ID_BITMAP_SURFACE_CREATE, &vdp_bitmap_surface_create},
359 {VDP_FUNC_ID_BITMAP_SURFACE_DESTROY, &vdp_bitmap_surface_destroy},
360 {VDP_FUNC_ID_BITMAP_SURFACE_PUT_BITS_NATIVE,
361 &vdp_bitmap_surface_putbits_native},
362 {VDP_FUNC_ID_OUTPUT_SURFACE_RENDER_BITMAP_SURFACE,
363 &vdp_output_surface_render_bitmap_surface},
364 {VDP_FUNC_ID_GENERATE_CSC_MATRIX, &vdp_generate_csc_matrix},
365 {0, NULL}
368 vdp_st = vdp_device_create(x11->display, x11->screen,
369 &vdp_device, &vdp_get_proc_address);
370 if (vdp_st != VDP_STATUS_OK) {
371 mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Error when calling vdp_device_create_x11: %i\n", vdp_st);
372 return -1;
375 vdp_get_error_string = NULL;
376 for (dsc = vdp_func; dsc->pointer; dsc++) {
377 vdp_st = vdp_get_proc_address(vdp_device, dsc->id, dsc->pointer);
378 if (vdp_st != VDP_STATUS_OK) {
379 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) : "?");
380 return -1;
383 return 0;
386 /* Initialize vdpau_flip_queue, called from config() */
387 static int win_x11_init_vdpau_flip_queue(struct vo *vo)
389 struct vo_x11_state *x11 = vo->x11;
390 VdpStatus vdp_st;
392 vdp_st = vdp_presentation_queue_target_create_x11(vdp_device, x11->window,
393 &vdp_flip_target);
394 CHECK_ST_ERROR("Error when calling vdp_presentation_queue_target_create_x11")
396 vdp_st = vdp_presentation_queue_create(vdp_device, vdp_flip_target,
397 &vdp_flip_queue);
398 CHECK_ST_ERROR("Error when calling vdp_presentation_queue_create")
400 return 0;
403 static int create_vdp_mixer(VdpChromaType vdp_chroma_type) {
404 #define VDP_NUM_MIXER_PARAMETER 3
405 #define MAX_NUM_FEATURES 5
406 int i;
407 VdpStatus vdp_st;
408 int feature_count = 0;
409 VdpVideoMixerFeature features[MAX_NUM_FEATURES];
410 VdpBool feature_enables[MAX_NUM_FEATURES];
411 static const VdpVideoMixerAttribute denoise_attrib[] = {VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL};
412 const void * const denoise_value[] = {&denoise};
413 static const VdpVideoMixerAttribute sharpen_attrib[] = {VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL};
414 const void * const sharpen_value[] = {&sharpen};
415 static const VdpVideoMixerAttribute skip_chroma_attrib[] = {VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE};
416 const uint8_t skip_chroma_value = 1;
417 const void * const skip_chroma_value_ptr[] = {&skip_chroma_value};
418 static const VdpVideoMixerParameter parameters[VDP_NUM_MIXER_PARAMETER] = {
419 VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH,
420 VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT,
421 VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE
423 const void *const parameter_values[VDP_NUM_MIXER_PARAMETER] = {
424 &vid_width,
425 &vid_height,
426 &vdp_chroma_type
428 features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL;
429 if (deint == 4)
430 features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL;
431 if (pullup)
432 features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE;
433 if (denoise)
434 features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION;
435 if (sharpen)
436 features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_SHARPNESS;
438 vdp_st = vdp_video_mixer_create(vdp_device, feature_count, features,
439 VDP_NUM_MIXER_PARAMETER,
440 parameters, parameter_values,
441 &video_mixer);
442 CHECK_ST_ERROR("Error when calling vdp_video_mixer_create")
444 for (i = 0; i < feature_count; i++) feature_enables[i] = VDP_TRUE;
445 if (deint < 3)
446 feature_enables[0] = VDP_FALSE;
447 if (feature_count)
448 vdp_video_mixer_set_feature_enables(video_mixer, feature_count, features, feature_enables);
449 if (denoise)
450 vdp_video_mixer_set_attribute_values(video_mixer, 1, denoise_attrib, denoise_value);
451 if (sharpen)
452 vdp_video_mixer_set_attribute_values(video_mixer, 1, sharpen_attrib, sharpen_value);
453 if (!chroma_deint)
454 vdp_video_mixer_set_attribute_values(video_mixer, 1, skip_chroma_attrib, skip_chroma_value_ptr);
456 return 0;
459 // Free everything specific to a certain video file
460 static void free_video_specific(void) {
461 int i;
462 VdpStatus vdp_st;
464 if (decoder != VDP_INVALID_HANDLE)
465 vdp_decoder_destroy(decoder);
466 decoder = VDP_INVALID_HANDLE;
467 decoder_max_refs = -1;
469 for (i = 0; i < 3; i++)
470 deint_surfaces[i] = VDP_INVALID_HANDLE;
472 for (i = 0; i < 2; i++)
473 if (deint_mpi[i]) {
474 deint_mpi[i]->usage_count--;
475 deint_mpi[i] = NULL;
478 for (i = 0; i < MAX_VIDEO_SURFACES; i++) {
479 if (surface_render[i].surface != VDP_INVALID_HANDLE) {
480 vdp_st = vdp_video_surface_destroy(surface_render[i].surface);
481 CHECK_ST_WARNING("Error when calling vdp_video_surface_destroy")
483 surface_render[i].surface = VDP_INVALID_HANDLE;
486 if (video_mixer != VDP_INVALID_HANDLE) {
487 vdp_st = vdp_video_mixer_destroy(video_mixer);
488 CHECK_ST_WARNING("Error when calling vdp_video_mixer_destroy")
490 video_mixer = VDP_INVALID_HANDLE;
493 static int create_vdp_decoder(int max_refs)
495 VdpStatus vdp_st;
496 VdpDecoderProfile vdp_decoder_profile;
497 if (decoder != VDP_INVALID_HANDLE)
498 vdp_decoder_destroy(decoder);
499 switch (image_format) {
500 case IMGFMT_VDPAU_MPEG1:
501 vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG1;
502 break;
503 case IMGFMT_VDPAU_MPEG2:
504 vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG2_MAIN;
505 break;
506 case IMGFMT_VDPAU_H264:
507 vdp_decoder_profile = VDP_DECODER_PROFILE_H264_HIGH;
508 mp_msg(MSGT_VO, MSGL_V, "[vdpau] Creating H264 hardware decoder for %d reference frames.\n", max_refs);
509 break;
510 case IMGFMT_VDPAU_WMV3:
511 vdp_decoder_profile = VDP_DECODER_PROFILE_VC1_MAIN;
512 break;
513 case IMGFMT_VDPAU_VC1:
514 vdp_decoder_profile = VDP_DECODER_PROFILE_VC1_ADVANCED;
515 break;
517 vdp_st = vdp_decoder_create(vdp_device, vdp_decoder_profile,
518 vid_width, vid_height, max_refs, &decoder);
519 CHECK_ST_WARNING("Failed creating VDPAU decoder");
520 if (vdp_st != VDP_STATUS_OK) {
521 decoder = VDP_INVALID_HANDLE;
522 decoder_max_refs = 0;
523 return 0;
525 decoder_max_refs = max_refs;
526 return 1;
530 * connect to X server, create and map window, initialize all
531 * VDPAU objects, create different surfaces etc.
533 static int config(struct vo *vo, uint32_t width, uint32_t height,
534 uint32_t d_width, uint32_t d_height, uint32_t flags,
535 char *title, uint32_t format)
537 struct vo_x11_state *x11 = vo->x11;
538 XVisualInfo vinfo;
539 XSetWindowAttributes xswa;
540 XWindowAttributes attribs;
541 unsigned long xswamask;
542 int depth;
544 #ifdef CONFIG_XF86VM
545 int vm = flags & VOFLAG_MODESWITCHING;
546 #endif
548 image_format = format;
549 vid_width = width;
550 vid_height = height;
551 free_video_specific();
552 if (IMGFMT_IS_VDPAU(image_format) && !create_vdp_decoder(2))
553 return -1;
555 visible_buf = 0;
558 #ifdef CONFIG_XF86VM
559 if (vm)
560 vo_vm_switch(vo);
561 else
562 #endif
563 XGetWindowAttributes(x11->display, DefaultRootWindow(x11->display),
564 &attribs);
565 depth = attribs.depth;
566 if (depth != 15 && depth != 16 && depth != 24 && depth != 32)
567 depth = 24;
568 XMatchVisualInfo(x11->display, x11->screen, depth, TrueColor, &vinfo);
570 xswa.background_pixel = 0;
571 xswa.border_pixel = 0;
572 /* Do not use CWBackPixel: It leads to VDPAU errors after
573 aspect ratio changes. */
574 xswamask = CWBorderPixel;
576 vo_x11_create_vo_window(vo, &vinfo, vo->dx, vo->dy, d_width, d_height,
577 flags, CopyFromParent, "vdpau", title);
578 XChangeWindowAttributes(x11->display, x11->window, xswamask, &xswa);
580 #ifdef CONFIG_XF86VM
581 if (vm) {
582 /* Grab the mouse pointer in our window */
583 if (vo_grabpointer)
584 XGrabPointer(x11->display, x11->window, True, 0,
585 GrabModeAsync, GrabModeAsync,
586 x11->window, None, CurrentTime);
587 XSetInputFocus(x11->display, x11->window, RevertToNone, CurrentTime);
589 #endif
592 if ((flags & VOFLAG_FULLSCREEN) && WinID <= 0)
593 vo_fs = 1;
595 /* -----VDPAU related code here -------- */
596 if (vdp_flip_queue == VDP_INVALID_HANDLE
597 && win_x11_init_vdpau_flip_queue(vo))
598 return -1;
600 vdp_chroma_type = VDP_CHROMA_TYPE_420;
601 switch (image_format) {
602 case IMGFMT_YV12:
603 case IMGFMT_I420:
604 case IMGFMT_IYUV:
605 vdp_pixel_format = VDP_YCBCR_FORMAT_YV12;
606 break;
607 case IMGFMT_NV12:
608 vdp_pixel_format = VDP_YCBCR_FORMAT_NV12;
609 break;
610 case IMGFMT_YUY2:
611 vdp_pixel_format = VDP_YCBCR_FORMAT_YUYV;
612 vdp_chroma_type = VDP_CHROMA_TYPE_422;
613 break;
614 case IMGFMT_UYVY:
615 vdp_pixel_format = VDP_YCBCR_FORMAT_UYVY;
616 vdp_chroma_type = VDP_CHROMA_TYPE_422;
618 if (create_vdp_mixer(vdp_chroma_type))
619 return -1;
621 surface_num = 0;
622 vid_surface_num = -1;
623 resize(vo);
625 return 0;
628 static void check_events(struct vo *vo)
630 int e = vo_x11_check_events(vo);
632 if (e & VO_EVENT_RESIZE)
633 resize(vo);
635 if ((e & VO_EVENT_EXPOSE || e & VO_EVENT_RESIZE) && int_pause) {
636 /* did we already draw a buffer */
637 if (visible_buf) {
638 /* redraw the last visible buffer */
639 VdpStatus vdp_st;
640 vdp_st = vdp_presentation_queue_display(vdp_flip_queue,
641 output_surfaces[surface_num],
642 vo->dwidth, vo->dheight,
644 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_display")
649 static void draw_osd_I8A8(void *ctx, int x0, int y0, int w, int h,
650 unsigned char *src, unsigned char *srca, int stride)
652 VdpOutputSurface output_surface = output_surfaces[surface_num];
653 VdpStatus vdp_st;
654 int i, j;
655 int pitch;
656 int index_data_size_required;
657 VdpRect output_indexed_rect_vid;
658 VdpOutputSurfaceRenderBlendState blend_state;
660 if (!w || !h)
661 return;
663 index_data_size_required = 2*w*h;
664 if (index_data_size < index_data_size_required) {
665 index_data = realloc(index_data, index_data_size_required);
666 index_data_size = index_data_size_required;
669 // index_data creation, component order - I, A, I, A, .....
670 for (i = 0; i < h; i++)
671 for (j = 0; j < w; j++) {
672 index_data[i*2*w + j*2] = src [i*stride+j];
673 index_data[i*2*w + j*2 + 1] = -srca[i*stride+j];
676 output_indexed_rect_vid.x0 = x0;
677 output_indexed_rect_vid.y0 = y0;
678 output_indexed_rect_vid.x1 = x0 + w;
679 output_indexed_rect_vid.y1 = y0 + h;
681 pitch = w*2;
683 // write source_data to osd_surface.
684 vdp_st = vdp_output_surface_put_bits_indexed(osd_surface,
685 VDP_INDEXED_FORMAT_I8A8,
686 (const void *const*)&index_data,
687 &pitch,
688 &output_indexed_rect_vid,
689 VDP_COLOR_TABLE_FORMAT_B8G8R8X8,
690 (void *)palette);
691 CHECK_ST_WARNING("Error when calling vdp_output_surface_put_bits_indexed")
693 blend_state.struct_version = VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION;
694 blend_state.blend_factor_source_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE;
695 blend_state.blend_factor_source_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE;
696 blend_state.blend_factor_destination_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
697 blend_state.blend_factor_destination_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
698 blend_state.blend_equation_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD;
699 blend_state.blend_equation_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD;
701 vdp_st = vdp_output_surface_render_output_surface(output_surface,
702 &output_indexed_rect_vid,
703 osd_surface,
704 &output_indexed_rect_vid,
705 NULL,
706 &blend_state,
707 VDP_OUTPUT_SURFACE_RENDER_ROTATE_0);
708 CHECK_ST_WARNING("Error when calling vdp_output_surface_render_output_surface")
711 static void draw_eosd(void) {
712 VdpStatus vdp_st;
713 VdpOutputSurface output_surface = output_surfaces[surface_num];
714 VdpOutputSurfaceRenderBlendState blend_state;
715 int i;
717 blend_state.struct_version = VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION;
718 blend_state.blend_factor_source_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_SRC_ALPHA;
719 blend_state.blend_factor_source_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE;
720 blend_state.blend_factor_destination_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
721 blend_state.blend_factor_destination_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_SRC_ALPHA;
722 blend_state.blend_equation_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD;
723 blend_state.blend_equation_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD;
725 for (i=0; i<eosd_render_count; i++) {
726 vdp_st = vdp_output_surface_render_bitmap_surface(
727 output_surface, &eosd_targets[i].dest,
728 eosd_targets[i].surface, &eosd_targets[i].source,
729 &eosd_targets[i].color, &blend_state,
730 VDP_OUTPUT_SURFACE_RENDER_ROTATE_0);
731 CHECK_ST_WARNING("EOSD: Error when rendering")
735 static void generate_eosd(mp_eosd_images_t *imgs) {
736 VdpStatus vdp_st;
737 VdpRect destRect;
738 int j, found;
739 ass_image_t *img = imgs->imgs;
740 ass_image_t *i;
742 // Nothing changed, no need to redraw
743 if (imgs->changed == 0)
744 return;
745 eosd_render_count = 0;
746 // There's nothing to render!
747 if (!img)
748 return;
750 if (imgs->changed == 1)
751 goto eosd_skip_upload;
753 for (j=0; j<eosd_surface_count; j++)
754 eosd_surfaces[j].in_use = 0;
756 for (i = img; i; i = i->next) {
757 // Try to reuse a suitable surface
758 found = -1;
759 for (j=0; j<eosd_surface_count; j++) {
760 if (eosd_surfaces[j].surface != VDP_INVALID_HANDLE && !eosd_surfaces[j].in_use &&
761 eosd_surfaces[j].w >= i->w && eosd_surfaces[j].h >= i->h) {
762 found = j;
763 break;
766 // None found, allocate a new surface
767 if (found < 0) {
768 for (j=0; j<eosd_surface_count; j++) {
769 if (!eosd_surfaces[j].in_use) {
770 if (eosd_surfaces[j].surface != VDP_INVALID_HANDLE)
771 vdp_bitmap_surface_destroy(eosd_surfaces[j].surface);
772 found = j;
773 break;
776 // Allocate new space for surface/target arrays
777 if (found < 0) {
778 j = found = eosd_surface_count;
779 eosd_surface_count = eosd_surface_count ? eosd_surface_count*2 : EOSD_SURFACES_INITIAL;
780 eosd_surfaces = realloc(eosd_surfaces, eosd_surface_count * sizeof(*eosd_surfaces));
781 eosd_targets = realloc(eosd_targets, eosd_surface_count * sizeof(*eosd_targets));
782 for(j=found; j<eosd_surface_count; j++) {
783 eosd_surfaces[j].surface = VDP_INVALID_HANDLE;
784 eosd_surfaces[j].in_use = 0;
787 vdp_st = vdp_bitmap_surface_create(vdp_device, VDP_RGBA_FORMAT_A8,
788 i->w, i->h, VDP_TRUE, &eosd_surfaces[found].surface);
789 CHECK_ST_WARNING("EOSD: error when creating surface")
790 eosd_surfaces[found].w = i->w;
791 eosd_surfaces[found].h = i->h;
793 eosd_surfaces[found].in_use = 1;
794 eosd_targets[eosd_render_count].surface = eosd_surfaces[found].surface;
795 destRect.x0 = 0;
796 destRect.y0 = 0;
797 destRect.x1 = i->w;
798 destRect.y1 = i->h;
799 vdp_st = vdp_bitmap_surface_putbits_native(eosd_targets[eosd_render_count].surface,
800 (const void *) &i->bitmap, &i->stride, &destRect);
801 CHECK_ST_WARNING("EOSD: putbits failed")
802 eosd_render_count++;
805 eosd_skip_upload:
806 eosd_render_count = 0;
807 for (i = img; i; i = i->next) {
808 // Render dest, color, etc.
809 eosd_targets[eosd_render_count].color.alpha = 1.0 - ((i->color >> 0) & 0xff) / 255.0;
810 eosd_targets[eosd_render_count].color.blue = ((i->color >> 8) & 0xff) / 255.0;
811 eosd_targets[eosd_render_count].color.green = ((i->color >> 16) & 0xff) / 255.0;
812 eosd_targets[eosd_render_count].color.red = ((i->color >> 24) & 0xff) / 255.0;
813 eosd_targets[eosd_render_count].dest.x0 = i->dst_x;
814 eosd_targets[eosd_render_count].dest.y0 = i->dst_y;
815 eosd_targets[eosd_render_count].dest.x1 = i->w + i->dst_x;
816 eosd_targets[eosd_render_count].dest.y1 = i->h + i->dst_y;
817 eosd_targets[eosd_render_count].source.x0 = 0;
818 eosd_targets[eosd_render_count].source.y0 = 0;
819 eosd_targets[eosd_render_count].source.x1 = i->w;
820 eosd_targets[eosd_render_count].source.y1 = i->h;
821 eosd_render_count++;
825 static void draw_osd(struct vo *vo, struct osd_state *osd)
827 mp_msg(MSGT_VO, MSGL_DBG2, "DRAW_OSD\n");
829 osd_draw_text_ext(osd, vo->dwidth, vo->dheight, border_x, border_y,
830 border_x, border_y, vid_width, vid_height,
831 draw_osd_I8A8, vo);
834 static void flip_page(struct vo *vo)
836 VdpStatus vdp_st;
837 mp_msg(MSGT_VO, MSGL_DBG2, "\nFLIP_PAGE VID:%u -> OUT:%u\n",
838 surface_render[vid_surface_num].surface, output_surfaces[surface_num]);
840 vdp_st = vdp_presentation_queue_display(vdp_flip_queue, output_surfaces[surface_num],
841 vo->dwidth, vo->dheight,
843 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_display")
845 surface_num = (surface_num + 1) % NUM_OUTPUT_SURFACES;
846 visible_buf = 1;
849 static int draw_slice(struct vo *vo, uint8_t *image[], int stride[], int w,
850 int h, int x, int y)
852 VdpStatus vdp_st;
853 struct vdpau_render_state *rndr = (struct vdpau_render_state *)image[0];
854 int max_refs = image_format == IMGFMT_VDPAU_H264 ? rndr->info.h264.num_ref_frames : 2;
855 if (!IMGFMT_IS_VDPAU(image_format))
856 return VO_FALSE;
857 if ((decoder == VDP_INVALID_HANDLE || decoder_max_refs < max_refs)
858 && !create_vdp_decoder(max_refs))
859 return VO_FALSE;
861 vdp_st = vdp_decoder_render(decoder, rndr->surface, (void *)&rndr->info, rndr->bitstream_buffers_used, rndr->bitstream_buffers);
862 CHECK_ST_WARNING("Failed VDPAU decoder rendering");
863 return VO_TRUE;
867 static int draw_frame(struct vo *vo, uint8_t *src[])
869 return VO_ERROR;
872 static struct vdpau_render_state *get_surface(int number)
874 if (number > MAX_VIDEO_SURFACES)
875 return NULL;
876 if (surface_render[number].surface == VDP_INVALID_HANDLE) {
877 VdpStatus vdp_st;
878 vdp_st = vdp_video_surface_create(vdp_device, vdp_chroma_type,
879 vid_width, vid_height,
880 &surface_render[number].surface);
881 CHECK_ST_WARNING("Error when calling vdp_video_surface_create")
882 if (vdp_st != VDP_STATUS_OK)
883 return NULL;
885 mp_msg(MSGT_VO, MSGL_DBG2, "VID CREATE: %u\n", surface_render[number].surface);
886 return &surface_render[number];
889 static uint32_t draw_image(struct vo *vo, mp_image_t *mpi)
891 if (IMGFMT_IS_VDPAU(image_format)) {
892 struct vdpau_render_state *rndr = mpi->priv;
893 vid_surface_num = rndr - surface_render;
894 if (deint_buffer_past_frames) {
895 mpi->usage_count++;
896 if (deint_mpi[1])
897 deint_mpi[1]->usage_count--;
898 deint_mpi[1] = deint_mpi[0];
899 deint_mpi[0] = mpi;
901 } else if (!(mpi->flags & MP_IMGFLAG_DRAW_CALLBACK)) {
902 VdpStatus vdp_st;
903 void *destdata[3] = {mpi->planes[0], mpi->planes[2], mpi->planes[1]};
904 struct vdpau_render_state *rndr = get_surface(deint_counter);
905 deint_counter = (deint_counter + 1) % 3;
906 vid_surface_num = rndr - surface_render;
907 if (image_format == IMGFMT_NV12)
908 destdata[1] = destdata[2];
909 vdp_st = vdp_video_surface_put_bits_y_cb_cr(rndr->surface,
910 vdp_pixel_format,
911 (const void *const*)destdata,
912 mpi->stride); // pitch
913 CHECK_ST_ERROR("Error when calling vdp_video_surface_put_bits_y_cb_cr")
915 if (mpi->fields & MP_IMGFIELD_ORDERED)
916 top_field_first = !!(mpi->fields & MP_IMGFIELD_TOP_FIRST);
917 else
918 top_field_first = 1;
920 video_to_output_surface(vo);
921 return VO_TRUE;
924 static uint32_t get_image(mp_image_t *mpi)
926 struct vdpau_render_state *rndr;
928 // no dr for non-decoding for now
929 if (!IMGFMT_IS_VDPAU(image_format)) return VO_FALSE;
930 if (mpi->type != MP_IMGTYPE_NUMBERED) return VO_FALSE;
932 rndr = get_surface(mpi->number);
933 if (!rndr) {
934 mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] no surfaces available in get_image\n");
935 // TODO: this probably breaks things forever, provide a dummy buffer?
936 return VO_FALSE;
938 mpi->flags |= MP_IMGFLAG_DIRECT;
939 mpi->stride[0] = mpi->stride[1] = mpi->stride[2] = 0;
940 mpi->planes[0] = mpi->planes[1] = mpi->planes[2] = NULL;
941 // hack to get around a check and to avoid a special-case in vd_ffmpeg.c
942 mpi->planes[0] = (void *)rndr;
943 mpi->num_planes = 1;
944 mpi->priv = rndr;
945 return VO_TRUE;
948 static int query_format(uint32_t format)
950 int default_flags = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_OSD | VFCAP_EOSD | VFCAP_EOSD_UNSCALED;
951 switch (format) {
952 case IMGFMT_YV12:
953 case IMGFMT_I420:
954 case IMGFMT_IYUV:
955 case IMGFMT_NV12:
956 case IMGFMT_YUY2:
957 case IMGFMT_UYVY:
958 return default_flags | VOCAP_NOSLICES;
959 case IMGFMT_VDPAU_MPEG1:
960 case IMGFMT_VDPAU_MPEG2:
961 case IMGFMT_VDPAU_H264:
962 case IMGFMT_VDPAU_WMV3:
963 case IMGFMT_VDPAU_VC1:
964 return default_flags;
966 return 0;
969 static void DestroyVdpauObjects(void)
971 int i;
972 VdpStatus vdp_st;
974 free_video_specific();
976 vdp_st = vdp_presentation_queue_destroy(vdp_flip_queue);
977 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_destroy")
979 vdp_st = vdp_presentation_queue_target_destroy(vdp_flip_target);
980 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_target_destroy")
982 for (i = 0; i <= NUM_OUTPUT_SURFACES; i++) {
983 vdp_st = vdp_output_surface_destroy(output_surfaces[i]);
984 output_surfaces[i] = VDP_INVALID_HANDLE;
985 CHECK_ST_WARNING("Error when calling vdp_output_surface_destroy")
988 for (i = 0; i<eosd_surface_count; i++) {
989 if (eosd_surfaces[i].surface != VDP_INVALID_HANDLE) {
990 vdp_st = vdp_bitmap_surface_destroy(eosd_surfaces[i].surface);
991 CHECK_ST_WARNING("Error when calling vdp_bitmap_surface_destroy")
993 eosd_surfaces[i].surface = VDP_INVALID_HANDLE;
996 vdp_st = vdp_device_destroy(vdp_device);
997 CHECK_ST_WARNING("Error when calling vdp_device_destroy")
1000 static void uninit(struct vo *vo)
1002 if (!vo->config_count)
1003 return;
1004 visible_buf = 0;
1006 /* Destroy all vdpau objects */
1007 DestroyVdpauObjects();
1009 free(index_data);
1010 index_data = NULL;
1012 free(eosd_surfaces);
1013 eosd_surfaces = NULL;
1014 free(eosd_targets);
1015 eosd_targets = NULL;
1017 #ifdef CONFIG_XF86VM
1018 vo_vm_close(vo);
1019 #endif
1020 vo_x11_uninit(vo);
1022 dlclose(vdpau_lib_handle);
1025 static const opt_t subopts[] = {
1026 {"deint", OPT_ARG_INT, &deint, (opt_test_f)int_non_neg},
1027 {"chroma-deint", OPT_ARG_BOOL, &chroma_deint, NULL},
1028 {"pullup", OPT_ARG_BOOL, &pullup, NULL},
1029 {"denoise", OPT_ARG_FLOAT, &denoise, NULL},
1030 {"sharpen", OPT_ARG_FLOAT, &sharpen, NULL},
1031 {NULL}
1034 static const char help_msg[] =
1035 "\n-vo vdpau command line help:\n"
1036 "Example: mplayer -vo vdpau:deint=2\n"
1037 "\nOptions:\n"
1038 " deint (all modes > 0 respect -field-dominance)\n"
1039 " 0: no deinterlacing\n"
1040 " 1: only show first field\n"
1041 " 2: bob deinterlacing\n"
1042 " 3: temporal deinterlacing (resource-hungry)\n"
1043 " 4: temporal-spatial deinterlacing (very resource-hungry)\n"
1044 " chroma-deint\n"
1045 " Operate on luma and chroma when using temporal deinterlacing (default)\n"
1046 " Use nochroma-deint to speed up temporal deinterlacing\n"
1047 " pullup\n"
1048 " Try to apply inverse-telecine (needs temporal deinterlacing)\n"
1049 " denoise\n"
1050 " Apply denoising, argument is strength from 0.0 to 1.0\n"
1051 " sharpen\n"
1052 " Apply sharpening or softening, argument is strength from -1.0 to 1.0\n"
1055 static int preinit(struct vo *vo, const char *arg)
1057 int i;
1058 static const char *vdpaulibrary = "libvdpau.so.1";
1059 static const char *vdpau_device_create = "vdp_device_create_x11";
1061 deint = 0;
1062 deint_type = 3;
1063 deint_counter = 0;
1064 deint_buffer_past_frames = 0;
1065 deint_mpi[0] = deint_mpi[1] = NULL;
1066 chroma_deint = 1;
1067 pullup = 0;
1068 denoise = 0;
1069 sharpen = 0;
1070 if (subopt_parse(arg, subopts) != 0) {
1071 mp_msg(MSGT_VO, MSGL_FATAL, help_msg);
1072 return -1;
1074 if (deint)
1075 deint_type = deint;
1076 if (deint > 1)
1077 deint_buffer_past_frames = 1;
1079 vdpau_lib_handle = dlopen(vdpaulibrary, RTLD_LAZY);
1080 if (!vdpau_lib_handle) {
1081 mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Could not open dynamic library %s\n",
1082 vdpaulibrary);
1083 return -1;
1085 vdp_device_create = dlsym(vdpau_lib_handle, vdpau_device_create);
1086 if (!vdp_device_create) {
1087 mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Could not find function %s in %s\n",
1088 vdpau_device_create, vdpaulibrary);
1089 return -1;
1091 if (!vo_init(vo) || win_x11_init_vdpau_procs(vo))
1092 return -1;
1094 decoder = VDP_INVALID_HANDLE;
1095 for (i = 0; i < MAX_VIDEO_SURFACES; i++)
1096 surface_render[i].surface = VDP_INVALID_HANDLE;
1097 video_mixer = VDP_INVALID_HANDLE;
1098 for (i = 0; i <= NUM_OUTPUT_SURFACES; i++)
1099 output_surfaces[i] = VDP_INVALID_HANDLE;
1100 vdp_flip_queue = VDP_INVALID_HANDLE;
1101 output_surface_width = output_surface_height = -1;
1103 // full grayscale palette.
1104 for (i = 0; i < PALETTE_SIZE; ++i)
1105 palette[i] = (i << 16) | (i << 8) | i;
1106 index_data = NULL;
1107 index_data_size = 0;
1109 eosd_surface_count = eosd_render_count = 0;
1110 eosd_surfaces = NULL;
1111 eosd_targets = NULL;
1113 procamp.struct_version = VDP_PROCAMP_VERSION;
1114 procamp.brightness = 0.0;
1115 procamp.contrast = 1.0;
1116 procamp.saturation = 1.0;
1117 procamp.hue = 0.0;
1119 return 0;
1122 static int get_equalizer(const char *name, int *value) {
1123 if (!strcasecmp(name, "brightness"))
1124 *value = procamp.brightness * 100;
1125 else if (!strcasecmp(name, "contrast"))
1126 *value = (procamp.contrast-1.0) * 100;
1127 else if (!strcasecmp(name, "saturation"))
1128 *value = (procamp.saturation-1.0) * 100;
1129 else if (!strcasecmp(name, "hue"))
1130 *value = procamp.hue * 100 / M_PI;
1131 else
1132 return VO_NOTIMPL;
1133 return VO_TRUE;
1136 static int set_equalizer(const char *name, int value) {
1137 VdpStatus vdp_st;
1138 VdpCSCMatrix matrix;
1139 static const VdpVideoMixerAttribute attributes[] = {VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX};
1140 const void *attribute_values[] = {&matrix};
1142 if (!strcasecmp(name, "brightness"))
1143 procamp.brightness = value / 100.0;
1144 else if (!strcasecmp(name, "contrast"))
1145 procamp.contrast = value / 100.0 + 1.0;
1146 else if (!strcasecmp(name, "saturation"))
1147 procamp.saturation = value / 100.0 + 1.0;
1148 else if (!strcasecmp(name, "hue"))
1149 procamp.hue = value / 100.0 * M_PI;
1150 else
1151 return VO_NOTIMPL;
1153 vdp_st = vdp_generate_csc_matrix(&procamp, VDP_COLOR_STANDARD_ITUR_BT_601,
1154 &matrix);
1155 CHECK_ST_WARNING("Error when generating CSC matrix")
1156 vdp_st = vdp_video_mixer_set_attribute_values(video_mixer, 1, attributes,
1157 attribute_values);
1158 CHECK_ST_WARNING("Error when setting CSC matrix")
1159 return VO_TRUE;
1162 static int control(struct vo *vo, uint32_t request, void *data)
1164 switch (request) {
1165 case VOCTRL_GET_DEINTERLACE:
1166 *(int*)data = deint;
1167 return VO_TRUE;
1168 case VOCTRL_SET_DEINTERLACE:
1169 deint = *(int*)data;
1170 if (deint)
1171 deint = deint_type;
1172 if (deint_type > 2) {
1173 VdpStatus vdp_st;
1174 VdpVideoMixerFeature features[1] =
1175 {deint_type == 3 ?
1176 VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL :
1177 VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL};
1178 VdpBool feature_enables[1] = {deint ? VDP_TRUE : VDP_FALSE};
1179 vdp_st = vdp_video_mixer_set_feature_enables(video_mixer, 1,
1180 features,
1181 feature_enables);
1182 CHECK_ST_WARNING("Error changing deinterlacing settings")
1183 deint_buffer_past_frames = 1;
1185 return VO_TRUE;
1186 case VOCTRL_PAUSE:
1187 return (int_pause = 1);
1188 case VOCTRL_RESUME:
1189 return (int_pause = 0);
1190 case VOCTRL_QUERY_FORMAT:
1191 return query_format(*(uint32_t *)data);
1192 case VOCTRL_GET_IMAGE:
1193 return get_image(data);
1194 case VOCTRL_DRAW_IMAGE:
1195 return draw_image(vo, data);
1196 case VOCTRL_BORDER:
1197 vo_x11_border(vo);
1198 resize(vo);
1199 return VO_TRUE;
1200 case VOCTRL_FULLSCREEN:
1201 vo_x11_fullscreen(vo);
1202 resize(vo);
1203 return VO_TRUE;
1204 case VOCTRL_GET_PANSCAN:
1205 return VO_TRUE;
1206 case VOCTRL_SET_PANSCAN:
1207 resize(vo);
1208 return VO_TRUE;
1209 case VOCTRL_SET_EQUALIZER: {
1210 struct voctrl_set_equalizer_args *args = data;
1211 return set_equalizer(args->name, args->value);
1213 case VOCTRL_GET_EQUALIZER:
1215 struct voctrl_get_equalizer_args *args = data;
1216 return get_equalizer(args->name, args->valueptr);
1218 case VOCTRL_ONTOP:
1219 vo_x11_ontop(vo);
1220 return VO_TRUE;
1221 case VOCTRL_UPDATE_SCREENINFO:
1222 update_xinerama_info(vo);
1223 return VO_TRUE;
1224 case VOCTRL_DRAW_EOSD:
1225 if (!data)
1226 return VO_FALSE;
1227 generate_eosd(data);
1228 draw_eosd();
1229 return VO_TRUE;
1230 case VOCTRL_GET_EOSD_RES: {
1231 mp_eosd_res_t *r = data;
1232 r->mt = r->mb = r->ml = r->mr = 0;
1233 if (vo_fs) {
1234 r->w = vo->opts->vo_screenwidth;
1235 r->h = vo->opts->vo_screenheight;
1236 r->ml = r->mr = border_x;
1237 r->mt = r->mb = border_y;
1238 } else {
1239 r->w = vo->dwidth;
1240 r->h = vo->dheight;
1242 return VO_TRUE;
1245 return VO_NOTIMPL;
1248 const struct vo_driver video_out_vdpau = {
1249 .is_new = 1,
1250 .info = &(struct vo_info_s){
1251 "VDPAU with X11",
1252 "vdpau",
1253 "Rajib Mahapatra <rmahapatra@nvidia.com> and others",
1256 .preinit = preinit,
1257 .config = config,
1258 .control = control,
1259 .draw_frame = draw_frame,
1260 .draw_slice = draw_slice,
1261 .draw_osd = draw_osd,
1262 .flip_page = flip_page,
1263 .check_events = check_events,
1264 .uninit = uninit,