vf_pp: Remove deprecated "hex mode" support
[mplayer.git] / libvo / vo_vdpau.c
blob281bfe60e2e10548594879d248bd71a666dbea76
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"
46 #include "font_load.h"
48 #include "libavcodec/vdpau.h"
50 #include "libavutil/common.h"
51 #include "libavutil/mathematics.h"
53 #include "ass_mp.h"
55 static vo_info_t info = {
56 "VDPAU with X11",
57 "vdpau",
58 "Rajib Mahapatra <rmahapatra@nvidia.com> and others",
62 LIBVO_EXTERN(vdpau)
64 #define CHECK_ST_ERROR(message) \
65 if (vdp_st != VDP_STATUS_OK) { \
66 mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] %s: %s\n", \
67 message, vdp_get_error_string(vdp_st)); \
68 return -1; \
71 #define CHECK_ST_WARNING(message) \
72 if (vdp_st != VDP_STATUS_OK) \
73 mp_msg(MSGT_VO, MSGL_WARN, "[vdpau] %s: %s\n", \
74 message, vdp_get_error_string(vdp_st));
76 /* number of video and output surfaces */
77 #define NUM_OUTPUT_SURFACES 2
78 #define MAX_VIDEO_SURFACES 50
80 /* number of palette entries */
81 #define PALETTE_SIZE 256
83 /* Initial maximum number of EOSD surfaces */
84 #define EOSD_SURFACES_INITIAL 512
87 * Global variable declaration - VDPAU specific
90 /* Declaration for all variables of win_x11_init_vdpau_procs() and
91 * win_x11_init_vdpau_flip_queue() functions
93 static VdpDevice vdp_device;
94 static VdpDeviceCreateX11 *vdp_device_create;
95 static VdpGetProcAddress *vdp_get_proc_address;
97 static VdpPresentationQueueTarget vdp_flip_target;
98 static VdpPresentationQueue vdp_flip_queue;
100 static VdpDeviceDestroy *vdp_device_destroy;
101 static VdpVideoSurfaceCreate *vdp_video_surface_create;
102 static VdpVideoSurfaceDestroy *vdp_video_surface_destroy;
104 static VdpGetErrorString *vdp_get_error_string;
106 /* May be used in software filtering/postprocessing options
107 * in MPlayer (./mplayer -vf ..) if we copy video_surface data to
108 * system memory.
110 static VdpVideoSurfacePutBitsYCbCr *vdp_video_surface_put_bits_y_cb_cr;
111 static VdpOutputSurfacePutBitsNative *vdp_output_surface_put_bits_native;
113 static VdpOutputSurfaceCreate *vdp_output_surface_create;
114 static VdpOutputSurfaceDestroy *vdp_output_surface_destroy;
116 /* VideoMixer puts video_surface data on displayable output_surface. */
117 static VdpVideoMixerCreate *vdp_video_mixer_create;
118 static VdpVideoMixerDestroy *vdp_video_mixer_destroy;
119 static VdpVideoMixerRender *vdp_video_mixer_render;
120 static VdpVideoMixerSetFeatureEnables *vdp_video_mixer_set_feature_enables;
121 static VdpVideoMixerSetAttributeValues *vdp_video_mixer_set_attribute_values;
123 static VdpPresentationQueueTargetDestroy *vdp_presentation_queue_target_destroy;
124 static VdpPresentationQueueCreate *vdp_presentation_queue_create;
125 static VdpPresentationQueueDestroy *vdp_presentation_queue_destroy;
126 static VdpPresentationQueueDisplay *vdp_presentation_queue_display;
127 static VdpPresentationQueueBlockUntilSurfaceIdle *vdp_presentation_queue_block_until_surface_idle;
128 static VdpPresentationQueueTargetCreateX11 *vdp_presentation_queue_target_create_x11;
130 static VdpOutputSurfaceRenderOutputSurface *vdp_output_surface_render_output_surface;
131 static VdpOutputSurfacePutBitsIndexed *vdp_output_surface_put_bits_indexed;
132 static VdpOutputSurfaceRenderBitmapSurface *vdp_output_surface_render_bitmap_surface;
134 static VdpBitmapSurfaceCreate *vdp_bitmap_surface_create;
135 static VdpBitmapSurfaceDestroy *vdp_bitmap_surface_destroy;
136 static VdpBitmapSurfacePutBitsNative *vdp_bitmap_surface_putbits_native;
138 static VdpDecoderCreate *vdp_decoder_create;
139 static VdpDecoderDestroy *vdp_decoder_destroy;
140 static VdpDecoderRender *vdp_decoder_render;
142 static VdpGenerateCSCMatrix *vdp_generate_csc_matrix;
144 static void *vdpau_lib_handle;
145 /* output_surfaces[NUM_OUTPUT_SURFACES] is misused for OSD. */
146 #define osd_surface output_surfaces[NUM_OUTPUT_SURFACES]
147 static VdpOutputSurface output_surfaces[NUM_OUTPUT_SURFACES + 1];
148 static VdpVideoSurface deint_surfaces[3];
149 static mp_image_t *deint_mpi[2];
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 deint_counter;
156 static int deint_buffer_past_frames;
157 static int pullup;
158 static float denoise;
159 static float sharpen;
160 static int chroma_deint;
161 static int top_field_first;
163 static VdpDecoder decoder;
164 static int decoder_max_refs;
166 static VdpRect src_rect_vid;
167 static VdpRect out_rect_vid;
168 static int border_x, border_y;
170 static struct vdpau_render_state surface_render[MAX_VIDEO_SURFACES];
171 static int surface_num;
172 static int vid_surface_num;
173 static uint32_t vid_width, vid_height;
174 static uint32_t image_format;
175 static VdpChromaType vdp_chroma_type;
176 static VdpYCbCrFormat vdp_pixel_format;
178 /* draw_osd */
179 static unsigned char *index_data;
180 static int index_data_size;
181 static uint32_t palette[PALETTE_SIZE];
183 // EOSD
184 // Pool of surfaces
185 struct {
186 VdpBitmapSurface surface;
187 int w;
188 int h;
189 char in_use;
190 } *eosd_surfaces;
192 // List of surfaces to be rendered
193 struct {
194 VdpBitmapSurface surface;
195 VdpRect source;
196 VdpRect dest;
197 VdpColor color;
198 } *eosd_targets;
200 static int eosd_render_count;
201 static int eosd_surface_count;
203 // Video equalizer
204 static VdpProcamp procamp;
207 * X11 specific
209 static int visible_buf;
210 static int int_pause;
212 static void draw_eosd(void);
214 static void push_deint_surface(VdpVideoSurface surface)
216 deint_surfaces[2] = deint_surfaces[1];
217 deint_surfaces[1] = deint_surfaces[0];
218 deint_surfaces[0] = surface;
221 static void video_to_output_surface(void)
223 VdpTime dummy;
224 VdpStatus vdp_st;
225 int i;
226 if (vid_surface_num < 0)
227 return;
229 if (deint < 2 || deint_surfaces[0] == VDP_INVALID_HANDLE)
230 push_deint_surface(surface_render[vid_surface_num].surface);
232 for (i = 0; i <= !!(deint > 1); i++) {
233 int field = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME;
234 VdpOutputSurface output_surface;
235 if (i) {
236 draw_eosd();
237 draw_osd();
238 flip_page();
240 if (deint)
241 field = (top_field_first == i) ^ (deint > 1) ?
242 VDP_VIDEO_MIXER_PICTURE_STRUCTURE_BOTTOM_FIELD:
243 VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD;
244 output_surface = output_surfaces[surface_num];
245 vdp_st = vdp_presentation_queue_block_until_surface_idle(vdp_flip_queue,
246 output_surface,
247 &dummy);
248 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_block_until_surface_idle")
250 vdp_st = vdp_video_mixer_render(video_mixer, VDP_INVALID_HANDLE, 0,
251 field, 2, deint_surfaces + 1,
252 deint_surfaces[0],
253 1, &surface_render[vid_surface_num].surface,
254 &src_rect_vid,
255 output_surface,
256 NULL, &out_rect_vid, 0, NULL);
257 CHECK_ST_WARNING("Error when calling vdp_video_mixer_render")
258 push_deint_surface(surface_render[vid_surface_num].surface);
262 static void resize(void)
264 VdpStatus vdp_st;
265 int i;
266 struct vo_rect src_rect;
267 struct vo_rect dst_rect;
268 struct vo_rect borders;
269 calc_src_dst_rects(vid_width, vid_height, &src_rect, &dst_rect, &borders, NULL);
270 out_rect_vid.x0 = dst_rect.left;
271 out_rect_vid.x1 = dst_rect.right;
272 out_rect_vid.y0 = dst_rect.top;
273 out_rect_vid.y1 = dst_rect.bottom;
274 src_rect_vid.x0 = src_rect.left;
275 src_rect_vid.x1 = src_rect.right;
276 src_rect_vid.y0 = src_rect.top;
277 src_rect_vid.y1 = src_rect.bottom;
278 border_x = borders.left;
279 border_y = borders.top;
280 #ifdef CONFIG_FREETYPE
281 // adjust font size to display size
282 force_load_font = 1;
283 #endif
284 vo_osd_changed(OSDTYPE_OSD);
286 if (output_surface_width < vo_dwidth || output_surface_height < vo_dheight) {
287 if (output_surface_width < vo_dwidth) {
288 output_surface_width += output_surface_width >> 1;
289 output_surface_width = FFMAX(output_surface_width, vo_dwidth);
291 if (output_surface_height < vo_dheight) {
292 output_surface_height += output_surface_height >> 1;
293 output_surface_height = FFMAX(output_surface_height, vo_dheight);
295 // Creation of output_surfaces
296 for (i = 0; i <= NUM_OUTPUT_SURFACES; i++) {
297 if (output_surfaces[i] != VDP_INVALID_HANDLE)
298 vdp_output_surface_destroy(output_surfaces[i]);
299 vdp_st = vdp_output_surface_create(vdp_device, VDP_RGBA_FORMAT_B8G8R8A8,
300 output_surface_width, output_surface_height,
301 &output_surfaces[i]);
302 CHECK_ST_WARNING("Error when calling vdp_output_surface_create")
303 mp_msg(MSGT_VO, MSGL_DBG2, "OUT CREATE: %u\n", output_surfaces[i]);
306 video_to_output_surface();
307 if (visible_buf)
308 flip_page();
311 /* Initialize vdp_get_proc_address, called from preinit() */
312 static int win_x11_init_vdpau_procs(void)
314 VdpStatus vdp_st;
316 struct vdp_function {
317 const int id;
318 void *pointer;
321 const struct vdp_function *dsc;
323 static const struct vdp_function vdp_func[] = {
324 {VDP_FUNC_ID_GET_ERROR_STRING, &vdp_get_error_string},
325 {VDP_FUNC_ID_DEVICE_DESTROY, &vdp_device_destroy},
326 {VDP_FUNC_ID_VIDEO_SURFACE_CREATE, &vdp_video_surface_create},
327 {VDP_FUNC_ID_VIDEO_SURFACE_DESTROY, &vdp_video_surface_destroy},
328 {VDP_FUNC_ID_VIDEO_SURFACE_PUT_BITS_Y_CB_CR,
329 &vdp_video_surface_put_bits_y_cb_cr},
330 {VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_NATIVE,
331 &vdp_output_surface_put_bits_native},
332 {VDP_FUNC_ID_OUTPUT_SURFACE_CREATE, &vdp_output_surface_create},
333 {VDP_FUNC_ID_OUTPUT_SURFACE_DESTROY, &vdp_output_surface_destroy},
334 {VDP_FUNC_ID_VIDEO_MIXER_CREATE, &vdp_video_mixer_create},
335 {VDP_FUNC_ID_VIDEO_MIXER_DESTROY, &vdp_video_mixer_destroy},
336 {VDP_FUNC_ID_VIDEO_MIXER_RENDER, &vdp_video_mixer_render},
337 {VDP_FUNC_ID_VIDEO_MIXER_SET_FEATURE_ENABLES,
338 &vdp_video_mixer_set_feature_enables},
339 {VDP_FUNC_ID_VIDEO_MIXER_SET_ATTRIBUTE_VALUES,
340 &vdp_video_mixer_set_attribute_values},
341 {VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_DESTROY,
342 &vdp_presentation_queue_target_destroy},
343 {VDP_FUNC_ID_PRESENTATION_QUEUE_CREATE, &vdp_presentation_queue_create},
344 {VDP_FUNC_ID_PRESENTATION_QUEUE_DESTROY,
345 &vdp_presentation_queue_destroy},
346 {VDP_FUNC_ID_PRESENTATION_QUEUE_DISPLAY,
347 &vdp_presentation_queue_display},
348 {VDP_FUNC_ID_PRESENTATION_QUEUE_BLOCK_UNTIL_SURFACE_IDLE,
349 &vdp_presentation_queue_block_until_surface_idle},
350 {VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_CREATE_X11,
351 &vdp_presentation_queue_target_create_x11},
352 {VDP_FUNC_ID_OUTPUT_SURFACE_RENDER_OUTPUT_SURFACE,
353 &vdp_output_surface_render_output_surface},
354 {VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_INDEXED,
355 &vdp_output_surface_put_bits_indexed},
356 {VDP_FUNC_ID_DECODER_CREATE, &vdp_decoder_create},
357 {VDP_FUNC_ID_DECODER_RENDER, &vdp_decoder_render},
358 {VDP_FUNC_ID_DECODER_DESTROY, &vdp_decoder_destroy},
359 {VDP_FUNC_ID_BITMAP_SURFACE_CREATE, &vdp_bitmap_surface_create},
360 {VDP_FUNC_ID_BITMAP_SURFACE_DESTROY, &vdp_bitmap_surface_destroy},
361 {VDP_FUNC_ID_BITMAP_SURFACE_PUT_BITS_NATIVE,
362 &vdp_bitmap_surface_putbits_native},
363 {VDP_FUNC_ID_OUTPUT_SURFACE_RENDER_BITMAP_SURFACE,
364 &vdp_output_surface_render_bitmap_surface},
365 {VDP_FUNC_ID_GENERATE_CSC_MATRIX, &vdp_generate_csc_matrix},
366 {0, NULL}
369 vdp_st = vdp_device_create(mDisplay, mScreen,
370 &vdp_device, &vdp_get_proc_address);
371 if (vdp_st != VDP_STATUS_OK) {
372 mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Error when calling vdp_device_create_x11: %i\n", vdp_st);
373 return -1;
376 vdp_get_error_string = NULL;
377 for (dsc = vdp_func; dsc->pointer; dsc++) {
378 vdp_st = vdp_get_proc_address(vdp_device, dsc->id, dsc->pointer);
379 if (vdp_st != VDP_STATUS_OK) {
380 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) : "?");
381 return -1;
384 return 0;
387 /* Initialize vdpau_flip_queue, called from config() */
388 static int win_x11_init_vdpau_flip_queue(void)
390 VdpStatus vdp_st;
392 vdp_st = vdp_presentation_queue_target_create_x11(vdp_device, vo_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(uint32_t width, uint32_t height, uint32_t d_width,
534 uint32_t d_height, uint32_t flags, char *title,
535 uint32_t format)
537 XVisualInfo vinfo;
538 XSetWindowAttributes xswa;
539 XWindowAttributes attribs;
540 unsigned long xswamask;
541 int depth;
543 #ifdef CONFIG_XF86VM
544 int vm = flags & VOFLAG_MODESWITCHING;
545 #endif
547 image_format = format;
548 vid_width = width;
549 vid_height = height;
550 free_video_specific();
551 if (IMGFMT_IS_VDPAU(image_format) && !create_vdp_decoder(2))
552 return -1;
554 visible_buf = 0;
557 #ifdef CONFIG_XF86VM
558 if (vm)
559 vo_vm_switch();
560 else
561 #endif
562 XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &attribs);
563 depth = attribs.depth;
564 if (depth != 15 && depth != 16 && depth != 24 && depth != 32)
565 depth = 24;
566 XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo);
568 xswa.background_pixel = 0;
569 xswa.border_pixel = 0;
570 /* Do not use CWBackPixel: It leads to VDPAU errors after
571 aspect ratio changes. */
572 xswamask = CWBorderPixel;
574 vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, d_width, d_height,
575 flags, CopyFromParent, "vdpau", title);
576 XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa);
578 #ifdef CONFIG_XF86VM
579 if (vm) {
580 /* Grab the mouse pointer in our window */
581 if (vo_grabpointer)
582 XGrabPointer(mDisplay, vo_window, True, 0,
583 GrabModeAsync, GrabModeAsync,
584 vo_window, None, CurrentTime);
585 XSetInputFocus(mDisplay, vo_window, RevertToNone, CurrentTime);
587 #endif
590 if ((flags & VOFLAG_FULLSCREEN) && WinID <= 0)
591 vo_fs = 1;
593 /* -----VDPAU related code here -------- */
594 if (vdp_flip_queue == VDP_INVALID_HANDLE && win_x11_init_vdpau_flip_queue())
595 return -1;
597 vdp_chroma_type = VDP_CHROMA_TYPE_420;
598 switch (image_format) {
599 case IMGFMT_YV12:
600 case IMGFMT_I420:
601 case IMGFMT_IYUV:
602 vdp_pixel_format = VDP_YCBCR_FORMAT_YV12;
603 break;
604 case IMGFMT_NV12:
605 vdp_pixel_format = VDP_YCBCR_FORMAT_NV12;
606 break;
607 case IMGFMT_YUY2:
608 vdp_pixel_format = VDP_YCBCR_FORMAT_YUYV;
609 vdp_chroma_type = VDP_CHROMA_TYPE_422;
610 break;
611 case IMGFMT_UYVY:
612 vdp_pixel_format = VDP_YCBCR_FORMAT_UYVY;
613 vdp_chroma_type = VDP_CHROMA_TYPE_422;
615 if (create_vdp_mixer(vdp_chroma_type))
616 return -1;
618 surface_num = 0;
619 vid_surface_num = -1;
620 resize();
622 return 0;
625 static void check_events(void)
627 int e = vo_x11_check_events(mDisplay);
629 if (e & VO_EVENT_RESIZE)
630 resize();
632 if ((e & VO_EVENT_EXPOSE || e & VO_EVENT_RESIZE) && int_pause) {
633 /* did we already draw a buffer */
634 if (visible_buf) {
635 /* redraw the last visible buffer */
636 VdpStatus vdp_st;
637 vdp_st = vdp_presentation_queue_display(vdp_flip_queue,
638 output_surfaces[surface_num],
639 vo_dwidth, vo_dheight,
641 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_display")
646 static void draw_osd_I8A8(int x0,int y0, int w,int h, unsigned char *src,
647 unsigned char *srca, int stride)
649 VdpOutputSurface output_surface = output_surfaces[surface_num];
650 VdpStatus vdp_st;
651 int i, j;
652 int pitch;
653 int index_data_size_required;
654 VdpRect output_indexed_rect_vid;
655 VdpOutputSurfaceRenderBlendState blend_state;
657 if (!w || !h)
658 return;
660 index_data_size_required = 2*w*h;
661 if (index_data_size < index_data_size_required) {
662 index_data = realloc(index_data, index_data_size_required);
663 index_data_size = index_data_size_required;
666 // index_data creation, component order - I, A, I, A, .....
667 for (i = 0; i < h; i++)
668 for (j = 0; j < w; j++) {
669 index_data[i*2*w + j*2] = src [i*stride+j];
670 index_data[i*2*w + j*2 + 1] = -srca[i*stride+j];
673 output_indexed_rect_vid.x0 = x0;
674 output_indexed_rect_vid.y0 = y0;
675 output_indexed_rect_vid.x1 = x0 + w;
676 output_indexed_rect_vid.y1 = y0 + h;
678 pitch = w*2;
680 // write source_data to osd_surface.
681 vdp_st = vdp_output_surface_put_bits_indexed(osd_surface,
682 VDP_INDEXED_FORMAT_I8A8,
683 (const void *const*)&index_data,
684 &pitch,
685 &output_indexed_rect_vid,
686 VDP_COLOR_TABLE_FORMAT_B8G8R8X8,
687 (void *)palette);
688 CHECK_ST_WARNING("Error when calling vdp_output_surface_put_bits_indexed")
690 blend_state.struct_version = VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION;
691 blend_state.blend_factor_source_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE;
692 blend_state.blend_factor_source_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE;
693 blend_state.blend_factor_destination_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
694 blend_state.blend_factor_destination_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
695 blend_state.blend_equation_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD;
696 blend_state.blend_equation_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD;
698 vdp_st = vdp_output_surface_render_output_surface(output_surface,
699 &output_indexed_rect_vid,
700 osd_surface,
701 &output_indexed_rect_vid,
702 NULL,
703 &blend_state,
704 VDP_OUTPUT_SURFACE_RENDER_ROTATE_0);
705 CHECK_ST_WARNING("Error when calling vdp_output_surface_render_output_surface")
708 static void draw_eosd(void) {
709 VdpStatus vdp_st;
710 VdpOutputSurface output_surface = output_surfaces[surface_num];
711 VdpOutputSurfaceRenderBlendState blend_state;
712 int i;
714 blend_state.struct_version = VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION;
715 blend_state.blend_factor_source_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_SRC_ALPHA;
716 blend_state.blend_factor_source_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE;
717 blend_state.blend_factor_destination_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
718 blend_state.blend_factor_destination_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_SRC_ALPHA;
719 blend_state.blend_equation_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD;
720 blend_state.blend_equation_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD;
722 for (i=0; i<eosd_render_count; i++) {
723 vdp_st = vdp_output_surface_render_bitmap_surface(
724 output_surface, &eosd_targets[i].dest,
725 eosd_targets[i].surface, &eosd_targets[i].source,
726 &eosd_targets[i].color, &blend_state,
727 VDP_OUTPUT_SURFACE_RENDER_ROTATE_0);
728 CHECK_ST_WARNING("EOSD: Error when rendering")
732 static void generate_eosd(mp_eosd_images_t *imgs) {
733 VdpStatus vdp_st;
734 VdpRect destRect;
735 int j, found;
736 ass_image_t *img = imgs->imgs;
737 ass_image_t *i;
739 // Nothing changed, no need to redraw
740 if (imgs->changed == 0)
741 return;
742 eosd_render_count = 0;
743 // There's nothing to render!
744 if (!img)
745 return;
747 if (imgs->changed == 1)
748 goto eosd_skip_upload;
750 for (j=0; j<eosd_surface_count; j++)
751 eosd_surfaces[j].in_use = 0;
753 for (i = img; i; i = i->next) {
754 // Try to reuse a suitable surface
755 found = -1;
756 for (j=0; j<eosd_surface_count; j++) {
757 if (eosd_surfaces[j].surface != VDP_INVALID_HANDLE && !eosd_surfaces[j].in_use &&
758 eosd_surfaces[j].w >= i->w && eosd_surfaces[j].h >= i->h) {
759 found = j;
760 break;
763 // None found, allocate a new surface
764 if (found < 0) {
765 for (j=0; j<eosd_surface_count; j++) {
766 if (!eosd_surfaces[j].in_use) {
767 if (eosd_surfaces[j].surface != VDP_INVALID_HANDLE)
768 vdp_bitmap_surface_destroy(eosd_surfaces[j].surface);
769 found = j;
770 break;
773 // Allocate new space for surface/target arrays
774 if (found < 0) {
775 j = found = eosd_surface_count;
776 eosd_surface_count = eosd_surface_count ? eosd_surface_count*2 : EOSD_SURFACES_INITIAL;
777 eosd_surfaces = realloc(eosd_surfaces, eosd_surface_count * sizeof(*eosd_surfaces));
778 eosd_targets = realloc(eosd_targets, eosd_surface_count * sizeof(*eosd_targets));
779 for(j=found; j<eosd_surface_count; j++) {
780 eosd_surfaces[j].surface = VDP_INVALID_HANDLE;
781 eosd_surfaces[j].in_use = 0;
784 vdp_st = vdp_bitmap_surface_create(vdp_device, VDP_RGBA_FORMAT_A8,
785 i->w, i->h, VDP_TRUE, &eosd_surfaces[found].surface);
786 CHECK_ST_WARNING("EOSD: error when creating surface")
787 eosd_surfaces[found].w = i->w;
788 eosd_surfaces[found].h = i->h;
790 eosd_surfaces[found].in_use = 1;
791 eosd_targets[eosd_render_count].surface = eosd_surfaces[found].surface;
792 destRect.x0 = 0;
793 destRect.y0 = 0;
794 destRect.x1 = i->w;
795 destRect.y1 = i->h;
796 vdp_st = vdp_bitmap_surface_putbits_native(eosd_targets[eosd_render_count].surface,
797 (const void *) &i->bitmap, &i->stride, &destRect);
798 CHECK_ST_WARNING("EOSD: putbits failed")
799 eosd_render_count++;
802 eosd_skip_upload:
803 eosd_render_count = 0;
804 for (i = img; i; i = i->next) {
805 // Render dest, color, etc.
806 eosd_targets[eosd_render_count].color.alpha = 1.0 - ((i->color >> 0) & 0xff) / 255.0;
807 eosd_targets[eosd_render_count].color.blue = ((i->color >> 8) & 0xff) / 255.0;
808 eosd_targets[eosd_render_count].color.green = ((i->color >> 16) & 0xff) / 255.0;
809 eosd_targets[eosd_render_count].color.red = ((i->color >> 24) & 0xff) / 255.0;
810 eosd_targets[eosd_render_count].dest.x0 = i->dst_x;
811 eosd_targets[eosd_render_count].dest.y0 = i->dst_y;
812 eosd_targets[eosd_render_count].dest.x1 = i->w + i->dst_x;
813 eosd_targets[eosd_render_count].dest.y1 = i->h + i->dst_y;
814 eosd_targets[eosd_render_count].source.x0 = 0;
815 eosd_targets[eosd_render_count].source.y0 = 0;
816 eosd_targets[eosd_render_count].source.x1 = i->w;
817 eosd_targets[eosd_render_count].source.y1 = i->h;
818 eosd_render_count++;
822 static void draw_osd(void)
824 mp_msg(MSGT_VO, MSGL_DBG2, "DRAW_OSD\n");
826 vo_draw_text_ext(vo_dwidth, vo_dheight, border_x, border_y, border_x, border_y,
827 vid_width, vid_height, draw_osd_I8A8);
830 static void flip_page(void)
832 VdpStatus vdp_st;
833 mp_msg(MSGT_VO, MSGL_DBG2, "\nFLIP_PAGE VID:%u -> OUT:%u\n",
834 surface_render[vid_surface_num].surface, output_surfaces[surface_num]);
836 vdp_st = vdp_presentation_queue_display(vdp_flip_queue, output_surfaces[surface_num],
837 vo_dwidth, vo_dheight,
839 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_display")
841 surface_num = (surface_num + 1) % NUM_OUTPUT_SURFACES;
842 visible_buf = 1;
845 static int draw_slice(uint8_t *image[], int stride[], int w, int h,
846 int x, int y)
848 VdpStatus vdp_st;
849 struct vdpau_render_state *rndr = (struct vdpau_render_state *)image[0];
850 int max_refs = image_format == IMGFMT_VDPAU_H264 ? rndr->info.h264.num_ref_frames : 2;
851 if (!IMGFMT_IS_VDPAU(image_format))
852 return VO_FALSE;
853 if ((decoder == VDP_INVALID_HANDLE || decoder_max_refs < max_refs)
854 && !create_vdp_decoder(max_refs))
855 return VO_FALSE;
857 vdp_st = vdp_decoder_render(decoder, rndr->surface, (void *)&rndr->info, rndr->bitstream_buffers_used, rndr->bitstream_buffers);
858 CHECK_ST_WARNING("Failed VDPAU decoder rendering");
859 return VO_TRUE;
863 static int draw_frame(uint8_t *src[])
865 return VO_ERROR;
868 static struct vdpau_render_state *get_surface(int number)
870 if (number > MAX_VIDEO_SURFACES)
871 return NULL;
872 if (surface_render[number].surface == VDP_INVALID_HANDLE) {
873 VdpStatus vdp_st;
874 vdp_st = vdp_video_surface_create(vdp_device, vdp_chroma_type,
875 vid_width, vid_height,
876 &surface_render[number].surface);
877 CHECK_ST_WARNING("Error when calling vdp_video_surface_create")
878 if (vdp_st != VDP_STATUS_OK)
879 return NULL;
881 mp_msg(MSGT_VO, MSGL_DBG2, "VID CREATE: %u\n", surface_render[number].surface);
882 return &surface_render[number];
885 static uint32_t draw_image(mp_image_t *mpi)
887 if (IMGFMT_IS_VDPAU(image_format)) {
888 struct vdpau_render_state *rndr = mpi->priv;
889 vid_surface_num = rndr - surface_render;
890 if (deint_buffer_past_frames) {
891 mpi->usage_count++;
892 if (deint_mpi[1])
893 deint_mpi[1]->usage_count--;
894 deint_mpi[1] = deint_mpi[0];
895 deint_mpi[0] = mpi;
897 } else if (!(mpi->flags & MP_IMGFLAG_DRAW_CALLBACK)) {
898 VdpStatus vdp_st;
899 void *destdata[3] = {mpi->planes[0], mpi->planes[2], mpi->planes[1]};
900 struct vdpau_render_state *rndr = get_surface(deint_counter);
901 deint_counter = (deint_counter + 1) % 3;
902 vid_surface_num = rndr - surface_render;
903 if (image_format == IMGFMT_NV12)
904 destdata[1] = destdata[2];
905 vdp_st = vdp_video_surface_put_bits_y_cb_cr(rndr->surface,
906 vdp_pixel_format,
907 (const void *const*)destdata,
908 mpi->stride); // pitch
909 CHECK_ST_ERROR("Error when calling vdp_video_surface_put_bits_y_cb_cr")
911 if (mpi->fields & MP_IMGFIELD_ORDERED)
912 top_field_first = !!(mpi->fields & MP_IMGFIELD_TOP_FIRST);
913 else
914 top_field_first = 1;
916 video_to_output_surface();
917 return VO_TRUE;
920 static uint32_t get_image(mp_image_t *mpi)
922 struct vdpau_render_state *rndr;
924 // no dr for non-decoding for now
925 if (!IMGFMT_IS_VDPAU(image_format)) return VO_FALSE;
926 if (mpi->type != MP_IMGTYPE_NUMBERED) return VO_FALSE;
928 rndr = get_surface(mpi->number);
929 if (!rndr) {
930 mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] no surfaces available in get_image\n");
931 // TODO: this probably breaks things forever, provide a dummy buffer?
932 return VO_FALSE;
934 mpi->flags |= MP_IMGFLAG_DIRECT;
935 mpi->stride[0] = mpi->stride[1] = mpi->stride[2] = 0;
936 mpi->planes[0] = mpi->planes[1] = mpi->planes[2] = NULL;
937 // hack to get around a check and to avoid a special-case in vd_ffmpeg.c
938 mpi->planes[0] = (void *)rndr;
939 mpi->num_planes = 1;
940 mpi->priv = rndr;
941 return VO_TRUE;
944 static int query_format(uint32_t format)
946 int default_flags = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_OSD | VFCAP_EOSD | VFCAP_EOSD_UNSCALED;
947 switch (format) {
948 case IMGFMT_YV12:
949 case IMGFMT_I420:
950 case IMGFMT_IYUV:
951 case IMGFMT_NV12:
952 case IMGFMT_YUY2:
953 case IMGFMT_UYVY:
954 return default_flags | VOCAP_NOSLICES;
955 case IMGFMT_VDPAU_MPEG1:
956 case IMGFMT_VDPAU_MPEG2:
957 case IMGFMT_VDPAU_H264:
958 case IMGFMT_VDPAU_WMV3:
959 case IMGFMT_VDPAU_VC1:
960 return default_flags;
962 return 0;
965 static void DestroyVdpauObjects(void)
967 int i;
968 VdpStatus vdp_st;
970 free_video_specific();
972 vdp_st = vdp_presentation_queue_destroy(vdp_flip_queue);
973 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_destroy")
975 vdp_st = vdp_presentation_queue_target_destroy(vdp_flip_target);
976 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_target_destroy")
978 for (i = 0; i <= NUM_OUTPUT_SURFACES; i++) {
979 vdp_st = vdp_output_surface_destroy(output_surfaces[i]);
980 output_surfaces[i] = VDP_INVALID_HANDLE;
981 CHECK_ST_WARNING("Error when calling vdp_output_surface_destroy")
984 for (i = 0; i<eosd_surface_count; i++) {
985 if (eosd_surfaces[i].surface != VDP_INVALID_HANDLE) {
986 vdp_st = vdp_bitmap_surface_destroy(eosd_surfaces[i].surface);
987 CHECK_ST_WARNING("Error when calling vdp_bitmap_surface_destroy")
989 eosd_surfaces[i].surface = VDP_INVALID_HANDLE;
992 vdp_st = vdp_device_destroy(vdp_device);
993 CHECK_ST_WARNING("Error when calling vdp_device_destroy")
996 static void uninit(void)
998 if (!vo_config_count)
999 return;
1000 visible_buf = 0;
1002 /* Destroy all vdpau objects */
1003 DestroyVdpauObjects();
1005 free(index_data);
1006 index_data = NULL;
1008 free(eosd_surfaces);
1009 eosd_surfaces = NULL;
1010 free(eosd_targets);
1011 eosd_targets = NULL;
1013 #ifdef CONFIG_XF86VM
1014 vo_vm_close();
1015 #endif
1016 vo_x11_uninit();
1018 dlclose(vdpau_lib_handle);
1021 static const opt_t subopts[] = {
1022 {"deint", OPT_ARG_INT, &deint, (opt_test_f)int_non_neg},
1023 {"chroma-deint", OPT_ARG_BOOL, &chroma_deint, NULL},
1024 {"pullup", OPT_ARG_BOOL, &pullup, NULL},
1025 {"denoise", OPT_ARG_FLOAT, &denoise, NULL},
1026 {"sharpen", OPT_ARG_FLOAT, &sharpen, NULL},
1027 {NULL}
1030 static const char help_msg[] =
1031 "\n-vo vdpau command line help:\n"
1032 "Example: mplayer -vo vdpau:deint=2\n"
1033 "\nOptions:\n"
1034 " deint (all modes > 0 respect -field-dominance)\n"
1035 " 0: no deinterlacing\n"
1036 " 1: only show first field\n"
1037 " 2: bob deinterlacing\n"
1038 " 3: temporal deinterlacing (resource-hungry)\n"
1039 " 4: temporal-spatial deinterlacing (very resource-hungry)\n"
1040 " chroma-deint\n"
1041 " Operate on luma and chroma when using temporal deinterlacing (default)\n"
1042 " Use nochroma-deint to speed up temporal deinterlacing\n"
1043 " pullup\n"
1044 " Try to apply inverse-telecine (needs temporal deinterlacing)\n"
1045 " denoise\n"
1046 " Apply denoising, argument is strength from 0.0 to 1.0\n"
1047 " sharpen\n"
1048 " Apply sharpening or softening, argument is strength from -1.0 to 1.0\n"
1051 static int preinit(const char *arg)
1053 int i;
1054 static const char *vdpaulibrary = "libvdpau.so.1";
1055 static const char *vdpau_device_create = "vdp_device_create_x11";
1057 deint = 0;
1058 deint_type = 3;
1059 deint_counter = 0;
1060 deint_buffer_past_frames = 0;
1061 deint_mpi[0] = deint_mpi[1] = NULL;
1062 chroma_deint = 1;
1063 pullup = 0;
1064 denoise = 0;
1065 sharpen = 0;
1066 if (subopt_parse(arg, subopts) != 0) {
1067 mp_msg(MSGT_VO, MSGL_FATAL, help_msg);
1068 return -1;
1070 if (deint)
1071 deint_type = deint;
1072 if (deint > 1)
1073 deint_buffer_past_frames = 1;
1075 vdpau_lib_handle = dlopen(vdpaulibrary, RTLD_LAZY);
1076 if (!vdpau_lib_handle) {
1077 mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Could not open dynamic library %s\n",
1078 vdpaulibrary);
1079 return -1;
1081 vdp_device_create = dlsym(vdpau_lib_handle, vdpau_device_create);
1082 if (!vdp_device_create) {
1083 mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Could not find function %s in %s\n",
1084 vdpau_device_create, vdpaulibrary);
1085 return -1;
1087 if (!vo_init() || win_x11_init_vdpau_procs())
1088 return -1;
1090 decoder = VDP_INVALID_HANDLE;
1091 for (i = 0; i < MAX_VIDEO_SURFACES; i++)
1092 surface_render[i].surface = VDP_INVALID_HANDLE;
1093 video_mixer = VDP_INVALID_HANDLE;
1094 for (i = 0; i <= NUM_OUTPUT_SURFACES; i++)
1095 output_surfaces[i] = VDP_INVALID_HANDLE;
1096 vdp_flip_queue = VDP_INVALID_HANDLE;
1097 output_surface_width = output_surface_height = -1;
1099 // full grayscale palette.
1100 for (i = 0; i < PALETTE_SIZE; ++i)
1101 palette[i] = (i << 16) | (i << 8) | i;
1102 index_data = NULL;
1103 index_data_size = 0;
1105 eosd_surface_count = eosd_render_count = 0;
1106 eosd_surfaces = NULL;
1107 eosd_targets = NULL;
1109 procamp.struct_version = VDP_PROCAMP_VERSION;
1110 procamp.brightness = 0.0;
1111 procamp.contrast = 1.0;
1112 procamp.saturation = 1.0;
1113 procamp.hue = 0.0;
1115 return 0;
1118 static int get_equalizer(char *name, int *value) {
1119 if (!strcasecmp(name, "brightness"))
1120 *value = procamp.brightness * 100;
1121 else if (!strcasecmp(name, "contrast"))
1122 *value = (procamp.contrast-1.0) * 100;
1123 else if (!strcasecmp(name, "saturation"))
1124 *value = (procamp.saturation-1.0) * 100;
1125 else if (!strcasecmp(name, "hue"))
1126 *value = procamp.hue * 100 / M_PI;
1127 else
1128 return VO_NOTIMPL;
1129 return VO_TRUE;
1132 static int set_equalizer(char *name, int value) {
1133 VdpStatus vdp_st;
1134 VdpCSCMatrix matrix;
1135 static const VdpVideoMixerAttribute attributes[] = {VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX};
1136 const void *attribute_values[] = {&matrix};
1138 if (!strcasecmp(name, "brightness"))
1139 procamp.brightness = value / 100.0;
1140 else if (!strcasecmp(name, "contrast"))
1141 procamp.contrast = value / 100.0 + 1.0;
1142 else if (!strcasecmp(name, "saturation"))
1143 procamp.saturation = value / 100.0 + 1.0;
1144 else if (!strcasecmp(name, "hue"))
1145 procamp.hue = value / 100.0 * M_PI;
1146 else
1147 return VO_NOTIMPL;
1149 vdp_st = vdp_generate_csc_matrix(&procamp, VDP_COLOR_STANDARD_ITUR_BT_601,
1150 &matrix);
1151 CHECK_ST_WARNING("Error when generating CSC matrix")
1152 vdp_st = vdp_video_mixer_set_attribute_values(video_mixer, 1, attributes,
1153 attribute_values);
1154 CHECK_ST_WARNING("Error when setting CSC matrix")
1155 return VO_TRUE;
1158 static int control(uint32_t request, void *data)
1160 switch (request) {
1161 case VOCTRL_GET_DEINTERLACE:
1162 *(int*)data = deint;
1163 return VO_TRUE;
1164 case VOCTRL_SET_DEINTERLACE:
1165 deint = *(int*)data;
1166 if (deint)
1167 deint = deint_type;
1168 if (deint_type > 2) {
1169 VdpStatus vdp_st;
1170 VdpVideoMixerFeature features[1] =
1171 {deint_type == 3 ?
1172 VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL :
1173 VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL};
1174 VdpBool feature_enables[1] = {deint ? VDP_TRUE : VDP_FALSE};
1175 vdp_st = vdp_video_mixer_set_feature_enables(video_mixer, 1,
1176 features,
1177 feature_enables);
1178 CHECK_ST_WARNING("Error changing deinterlacing settings")
1179 deint_buffer_past_frames = 1;
1181 return VO_TRUE;
1182 case VOCTRL_PAUSE:
1183 return (int_pause = 1);
1184 case VOCTRL_RESUME:
1185 return (int_pause = 0);
1186 case VOCTRL_QUERY_FORMAT:
1187 return query_format(*(uint32_t *)data);
1188 case VOCTRL_GET_IMAGE:
1189 return get_image(data);
1190 case VOCTRL_DRAW_IMAGE:
1191 return draw_image(data);
1192 case VOCTRL_BORDER:
1193 vo_x11_border();
1194 resize();
1195 return VO_TRUE;
1196 case VOCTRL_FULLSCREEN:
1197 vo_x11_fullscreen();
1198 resize();
1199 return VO_TRUE;
1200 case VOCTRL_GET_PANSCAN:
1201 return VO_TRUE;
1202 case VOCTRL_SET_PANSCAN:
1203 resize();
1204 return VO_TRUE;
1205 case VOCTRL_SET_EQUALIZER: {
1206 struct voctrl_set_equalizer_args *args = data;
1207 return set_equalizer(args->name, args->value);
1209 case VOCTRL_GET_EQUALIZER:
1211 struct voctrl_get_equalizer_args *args = data;
1212 return get_equalizer(args->name, args->valueptr);
1214 case VOCTRL_ONTOP:
1215 vo_x11_ontop();
1216 return VO_TRUE;
1217 case VOCTRL_UPDATE_SCREENINFO:
1218 update_xinerama_info();
1219 return VO_TRUE;
1220 case VOCTRL_DRAW_EOSD:
1221 if (!data)
1222 return VO_FALSE;
1223 generate_eosd(data);
1224 draw_eosd();
1225 return VO_TRUE;
1226 case VOCTRL_GET_EOSD_RES: {
1227 mp_eosd_res_t *r = data;
1228 r->mt = r->mb = r->ml = r->mr = 0;
1229 if (vo_fs) {
1230 r->w = vo_screenwidth;
1231 r->h = vo_screenheight;
1232 r->ml = r->mr = border_x;
1233 r->mt = r->mb = border_y;
1234 } else {
1235 r->w = vo_dwidth;
1236 r->h = vo_dheight;
1238 return VO_TRUE;
1241 return VO_NOTIMPL;
1244 /* @} */