Remove trailing whitespace from most files
[mplayer/glamo.git] / libvo / vo_vdpau.c
blob31bfba4eaea0585929dc91c21e31fb573fcb535d
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 VdpVideoSurface deint_surfaces[3];
151 static mp_image_t *deint_mpi[2];
152 static int output_surface_width, output_surface_height;
154 static VdpVideoMixer video_mixer;
155 static int deint;
156 static int deint_type;
157 static int deint_counter;
158 static int deint_buffer_past_frames;
159 static int pullup;
160 static float denoise;
161 static float sharpen;
162 static int chroma_deint;
163 static int top_field_first;
165 static VdpDecoder decoder;
166 static int decoder_max_refs;
168 static VdpRect src_rect_vid;
169 static VdpRect out_rect_vid;
170 static int border_x, border_y;
172 static struct vdpau_render_state surface_render[MAX_VIDEO_SURFACES];
173 static int surface_num;
174 static int vid_surface_num;
175 static uint32_t vid_width, vid_height;
176 static uint32_t image_format;
177 static VdpChromaType vdp_chroma_type;
178 static VdpYCbCrFormat vdp_pixel_format;
180 /* draw_osd */
181 static unsigned char *index_data;
182 static int index_data_size;
183 static uint32_t palette[PALETTE_SIZE];
185 // EOSD
186 // Pool of surfaces
187 struct {
188 VdpBitmapSurface surface;
189 int w;
190 int h;
191 char in_use;
192 } *eosd_surfaces;
194 // List of surfaces to be rendered
195 struct {
196 VdpBitmapSurface surface;
197 VdpRect source;
198 VdpRect dest;
199 VdpColor color;
200 } *eosd_targets;
202 static int eosd_render_count;
203 static int eosd_surface_count;
205 // Video equalizer
206 static VdpProcamp procamp;
209 * X11 specific
211 static int visible_buf;
212 static int int_pause;
214 static void draw_eosd(void);
216 static void push_deint_surface(VdpVideoSurface surface)
218 deint_surfaces[2] = deint_surfaces[1];
219 deint_surfaces[1] = deint_surfaces[0];
220 deint_surfaces[0] = surface;
223 static void video_to_output_surface(void)
225 VdpTime dummy;
226 VdpStatus vdp_st;
227 int i;
228 if (vid_surface_num < 0)
229 return;
231 if (deint < 2 || deint_surfaces[0] == VDP_INVALID_HANDLE)
232 push_deint_surface(surface_render[vid_surface_num].surface);
234 for (i = 0; i <= !!(deint > 1); i++) {
235 int field = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME;
236 VdpOutputSurface output_surface;
237 if (i) {
238 draw_eosd();
239 draw_osd();
240 flip_page();
242 if (deint)
243 field = (top_field_first == i) ^ (deint > 1) ?
244 VDP_VIDEO_MIXER_PICTURE_STRUCTURE_BOTTOM_FIELD:
245 VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD;
246 output_surface = output_surfaces[surface_num];
247 vdp_st = vdp_presentation_queue_block_until_surface_idle(vdp_flip_queue,
248 output_surface,
249 &dummy);
250 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_block_until_surface_idle")
252 vdp_st = vdp_video_mixer_render(video_mixer, VDP_INVALID_HANDLE, 0,
253 field, 2, deint_surfaces + 1,
254 deint_surfaces[0],
255 1, &surface_render[vid_surface_num].surface,
256 &src_rect_vid,
257 output_surface,
258 NULL, &out_rect_vid, 0, NULL);
259 CHECK_ST_WARNING("Error when calling vdp_video_mixer_render")
260 push_deint_surface(surface_render[vid_surface_num].surface);
264 static void resize(void)
266 VdpStatus vdp_st;
267 int i;
268 struct vo_rect src_rect;
269 struct vo_rect dst_rect;
270 struct vo_rect borders;
271 calc_src_dst_rects(vid_width, vid_height, &src_rect, &dst_rect, &borders, NULL);
272 out_rect_vid.x0 = dst_rect.left;
273 out_rect_vid.x1 = dst_rect.right;
274 out_rect_vid.y0 = dst_rect.top;
275 out_rect_vid.y1 = dst_rect.bottom;
276 src_rect_vid.x0 = src_rect.left;
277 src_rect_vid.x1 = src_rect.right;
278 src_rect_vid.y0 = src_rect.top;
279 src_rect_vid.y1 = src_rect.bottom;
280 border_x = borders.left;
281 border_y = borders.top;
282 #ifdef CONFIG_FREETYPE
283 // adjust font size to display size
284 force_load_font = 1;
285 #endif
286 vo_osd_changed(OSDTYPE_OSD);
288 if (output_surface_width < vo_dwidth || output_surface_height < vo_dheight) {
289 if (output_surface_width < vo_dwidth) {
290 output_surface_width += output_surface_width >> 1;
291 output_surface_width = FFMAX(output_surface_width, vo_dwidth);
293 if (output_surface_height < vo_dheight) {
294 output_surface_height += output_surface_height >> 1;
295 output_surface_height = FFMAX(output_surface_height, vo_dheight);
297 // Creation of output_surfaces
298 for (i = 0; i <= NUM_OUTPUT_SURFACES; i++) {
299 if (output_surfaces[i] != VDP_INVALID_HANDLE)
300 vdp_output_surface_destroy(output_surfaces[i]);
301 vdp_st = vdp_output_surface_create(vdp_device, VDP_RGBA_FORMAT_B8G8R8A8,
302 output_surface_width, output_surface_height,
303 &output_surfaces[i]);
304 CHECK_ST_WARNING("Error when calling vdp_output_surface_create")
305 mp_msg(MSGT_VO, MSGL_DBG2, "OUT CREATE: %u\n", output_surfaces[i]);
308 video_to_output_surface();
309 if (visible_buf)
310 flip_page();
313 /* Initialize vdp_get_proc_address, called from preinit() */
314 static int win_x11_init_vdpau_procs(void)
316 VdpStatus vdp_st;
318 struct vdp_function {
319 const int id;
320 void *pointer;
323 const struct vdp_function *dsc;
325 static const struct vdp_function vdp_func[] = {
326 {VDP_FUNC_ID_GET_ERROR_STRING, &vdp_get_error_string},
327 {VDP_FUNC_ID_DEVICE_DESTROY, &vdp_device_destroy},
328 {VDP_FUNC_ID_VIDEO_SURFACE_CREATE, &vdp_video_surface_create},
329 {VDP_FUNC_ID_VIDEO_SURFACE_DESTROY, &vdp_video_surface_destroy},
330 {VDP_FUNC_ID_VIDEO_SURFACE_PUT_BITS_Y_CB_CR,
331 &vdp_video_surface_put_bits_y_cb_cr},
332 {VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_NATIVE,
333 &vdp_output_surface_put_bits_native},
334 {VDP_FUNC_ID_OUTPUT_SURFACE_CREATE, &vdp_output_surface_create},
335 {VDP_FUNC_ID_OUTPUT_SURFACE_DESTROY, &vdp_output_surface_destroy},
336 {VDP_FUNC_ID_VIDEO_MIXER_CREATE, &vdp_video_mixer_create},
337 {VDP_FUNC_ID_VIDEO_MIXER_DESTROY, &vdp_video_mixer_destroy},
338 {VDP_FUNC_ID_VIDEO_MIXER_RENDER, &vdp_video_mixer_render},
339 {VDP_FUNC_ID_VIDEO_MIXER_SET_FEATURE_ENABLES,
340 &vdp_video_mixer_set_feature_enables},
341 {VDP_FUNC_ID_VIDEO_MIXER_SET_ATTRIBUTE_VALUES,
342 &vdp_video_mixer_set_attribute_values},
343 {VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_DESTROY,
344 &vdp_presentation_queue_target_destroy},
345 {VDP_FUNC_ID_PRESENTATION_QUEUE_CREATE, &vdp_presentation_queue_create},
346 {VDP_FUNC_ID_PRESENTATION_QUEUE_DESTROY,
347 &vdp_presentation_queue_destroy},
348 {VDP_FUNC_ID_PRESENTATION_QUEUE_DISPLAY,
349 &vdp_presentation_queue_display},
350 {VDP_FUNC_ID_PRESENTATION_QUEUE_BLOCK_UNTIL_SURFACE_IDLE,
351 &vdp_presentation_queue_block_until_surface_idle},
352 {VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_CREATE_X11,
353 &vdp_presentation_queue_target_create_x11},
354 {VDP_FUNC_ID_OUTPUT_SURFACE_RENDER_OUTPUT_SURFACE,
355 &vdp_output_surface_render_output_surface},
356 {VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_INDEXED,
357 &vdp_output_surface_put_bits_indexed},
358 {VDP_FUNC_ID_DECODER_CREATE, &vdp_decoder_create},
359 {VDP_FUNC_ID_DECODER_RENDER, &vdp_decoder_render},
360 {VDP_FUNC_ID_DECODER_DESTROY, &vdp_decoder_destroy},
361 {VDP_FUNC_ID_BITMAP_SURFACE_CREATE, &vdp_bitmap_surface_create},
362 {VDP_FUNC_ID_BITMAP_SURFACE_DESTROY, &vdp_bitmap_surface_destroy},
363 {VDP_FUNC_ID_BITMAP_SURFACE_PUT_BITS_NATIVE,
364 &vdp_bitmap_surface_putbits_native},
365 {VDP_FUNC_ID_OUTPUT_SURFACE_RENDER_BITMAP_SURFACE,
366 &vdp_output_surface_render_bitmap_surface},
367 {VDP_FUNC_ID_GENERATE_CSC_MATRIX, &vdp_generate_csc_matrix},
368 {0, NULL}
371 vdp_st = vdp_device_create(mDisplay, mScreen,
372 &vdp_device, &vdp_get_proc_address);
373 if (vdp_st != VDP_STATUS_OK) {
374 mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Error when calling vdp_device_create_x11: %i\n", vdp_st);
375 return -1;
378 vdp_get_error_string = NULL;
379 for (dsc = vdp_func; dsc->pointer; dsc++) {
380 vdp_st = vdp_get_proc_address(vdp_device, dsc->id, dsc->pointer);
381 if (vdp_st != VDP_STATUS_OK) {
382 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) : "?");
383 return -1;
386 return 0;
389 /* Initialize vdpau_flip_queue, called from config() */
390 static int win_x11_init_vdpau_flip_queue(void)
392 VdpStatus vdp_st;
394 vdp_st = vdp_presentation_queue_target_create_x11(vdp_device, vo_window,
395 &vdp_flip_target);
396 CHECK_ST_ERROR("Error when calling vdp_presentation_queue_target_create_x11")
398 vdp_st = vdp_presentation_queue_create(vdp_device, vdp_flip_target,
399 &vdp_flip_queue);
400 CHECK_ST_ERROR("Error when calling vdp_presentation_queue_create")
402 return 0;
405 static int create_vdp_mixer(VdpChromaType vdp_chroma_type) {
406 #define VDP_NUM_MIXER_PARAMETER 3
407 #define MAX_NUM_FEATURES 5
408 int i;
409 VdpStatus vdp_st;
410 int feature_count = 0;
411 VdpVideoMixerFeature features[MAX_NUM_FEATURES];
412 VdpBool feature_enables[MAX_NUM_FEATURES];
413 static const VdpVideoMixerAttribute denoise_attrib[] = {VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL};
414 const void * const denoise_value[] = {&denoise};
415 static const VdpVideoMixerAttribute sharpen_attrib[] = {VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL};
416 const void * const sharpen_value[] = {&sharpen};
417 static const VdpVideoMixerAttribute skip_chroma_attrib[] = {VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE};
418 const uint8_t skip_chroma_value = 1;
419 const void * const skip_chroma_value_ptr[] = {&skip_chroma_value};
420 static const VdpVideoMixerParameter parameters[VDP_NUM_MIXER_PARAMETER] = {
421 VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH,
422 VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT,
423 VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE
425 const void *const parameter_values[VDP_NUM_MIXER_PARAMETER] = {
426 &vid_width,
427 &vid_height,
428 &vdp_chroma_type
430 features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL;
431 if (deint == 4)
432 features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL;
433 if (pullup)
434 features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE;
435 if (denoise)
436 features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION;
437 if (sharpen)
438 features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_SHARPNESS;
440 vdp_st = vdp_video_mixer_create(vdp_device, feature_count, features,
441 VDP_NUM_MIXER_PARAMETER,
442 parameters, parameter_values,
443 &video_mixer);
444 CHECK_ST_ERROR("Error when calling vdp_video_mixer_create")
446 for (i = 0; i < feature_count; i++) feature_enables[i] = VDP_TRUE;
447 if (deint < 3)
448 feature_enables[0] = VDP_FALSE;
449 if (feature_count)
450 vdp_video_mixer_set_feature_enables(video_mixer, feature_count, features, feature_enables);
451 if (denoise)
452 vdp_video_mixer_set_attribute_values(video_mixer, 1, denoise_attrib, denoise_value);
453 if (sharpen)
454 vdp_video_mixer_set_attribute_values(video_mixer, 1, sharpen_attrib, sharpen_value);
455 if (!chroma_deint)
456 vdp_video_mixer_set_attribute_values(video_mixer, 1, skip_chroma_attrib, skip_chroma_value_ptr);
458 return 0;
461 // Free everything specific to a certain video file
462 static void free_video_specific(void) {
463 int i;
464 VdpStatus vdp_st;
466 if (decoder != VDP_INVALID_HANDLE)
467 vdp_decoder_destroy(decoder);
468 decoder = VDP_INVALID_HANDLE;
469 decoder_max_refs = -1;
471 for (i = 0; i < 3; i++)
472 deint_surfaces[i] = VDP_INVALID_HANDLE;
474 for (i = 0; i < 2; i++)
475 if (deint_mpi[i]) {
476 deint_mpi[i]->usage_count--;
477 deint_mpi[i] = NULL;
480 for (i = 0; i < MAX_VIDEO_SURFACES; i++) {
481 if (surface_render[i].surface != VDP_INVALID_HANDLE) {
482 vdp_st = vdp_video_surface_destroy(surface_render[i].surface);
483 CHECK_ST_WARNING("Error when calling vdp_video_surface_destroy")
485 surface_render[i].surface = VDP_INVALID_HANDLE;
488 if (video_mixer != VDP_INVALID_HANDLE) {
489 vdp_st = vdp_video_mixer_destroy(video_mixer);
490 CHECK_ST_WARNING("Error when calling vdp_video_mixer_destroy")
492 video_mixer = VDP_INVALID_HANDLE;
495 static int create_vdp_decoder(int max_refs)
497 VdpStatus vdp_st;
498 VdpDecoderProfile vdp_decoder_profile;
499 if (decoder != VDP_INVALID_HANDLE)
500 vdp_decoder_destroy(decoder);
501 switch (image_format) {
502 case IMGFMT_VDPAU_MPEG1:
503 vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG1;
504 break;
505 case IMGFMT_VDPAU_MPEG2:
506 vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG2_MAIN;
507 break;
508 case IMGFMT_VDPAU_H264:
509 vdp_decoder_profile = VDP_DECODER_PROFILE_H264_HIGH;
510 mp_msg(MSGT_VO, MSGL_V, "[vdpau] Creating H264 hardware decoder for %d reference frames.\n", max_refs);
511 break;
512 case IMGFMT_VDPAU_WMV3:
513 vdp_decoder_profile = VDP_DECODER_PROFILE_VC1_MAIN;
514 break;
515 case IMGFMT_VDPAU_VC1:
516 vdp_decoder_profile = VDP_DECODER_PROFILE_VC1_ADVANCED;
517 break;
519 vdp_st = vdp_decoder_create(vdp_device, vdp_decoder_profile,
520 vid_width, vid_height, max_refs, &decoder);
521 CHECK_ST_WARNING("Failed creating VDPAU decoder");
522 if (vdp_st != VDP_STATUS_OK) {
523 decoder = VDP_INVALID_HANDLE;
524 decoder_max_refs = 0;
525 return 0;
527 decoder_max_refs = max_refs;
528 return 1;
532 * connect to X server, create and map window, initialize all
533 * VDPAU objects, create different surfaces etc.
535 static int config(uint32_t width, uint32_t height, uint32_t d_width,
536 uint32_t d_height, uint32_t flags, char *title,
537 uint32_t format)
539 XVisualInfo vinfo;
540 XSetWindowAttributes xswa;
541 XWindowAttributes attribs;
542 unsigned long xswamask;
543 int depth;
545 #ifdef CONFIG_XF86VM
546 int vm = flags & VOFLAG_MODESWITCHING;
547 #endif
549 image_format = format;
550 vid_width = width;
551 vid_height = height;
552 free_video_specific();
553 if (IMGFMT_IS_VDPAU(image_format) && !create_vdp_decoder(2))
554 return -1;
556 visible_buf = 0;
558 #ifdef CONFIG_GUI
559 if (use_gui)
560 guiGetEvent(guiSetShVideo, 0); // the GUI will set up / resize our window
561 else
562 #endif
564 #ifdef CONFIG_XF86VM
565 if (vm)
566 vo_vm_switch();
567 else
568 #endif
569 XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &attribs);
570 depth = attribs.depth;
571 if (depth != 15 && depth != 16 && depth != 24 && depth != 32)
572 depth = 24;
573 XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo);
575 xswa.background_pixel = 0;
576 xswa.border_pixel = 0;
577 /* Do not use CWBackPixel: It leads to VDPAU errors after
578 aspect ratio changes. */
579 xswamask = CWBorderPixel;
581 vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, d_width, d_height,
582 flags, CopyFromParent, "vdpau", title);
583 XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa);
585 #ifdef CONFIG_XF86VM
586 if (vm) {
587 /* Grab the mouse pointer in our window */
588 if (vo_grabpointer)
589 XGrabPointer(mDisplay, vo_window, True, 0,
590 GrabModeAsync, GrabModeAsync,
591 vo_window, None, CurrentTime);
592 XSetInputFocus(mDisplay, vo_window, RevertToNone, CurrentTime);
594 #endif
597 if ((flags & VOFLAG_FULLSCREEN) && WinID <= 0)
598 vo_fs = 1;
600 /* -----VDPAU related code here -------- */
601 if (vdp_flip_queue == VDP_INVALID_HANDLE && win_x11_init_vdpau_flip_queue())
602 return -1;
604 vdp_chroma_type = VDP_CHROMA_TYPE_420;
605 switch (image_format) {
606 case IMGFMT_YV12:
607 case IMGFMT_I420:
608 case IMGFMT_IYUV:
609 vdp_pixel_format = VDP_YCBCR_FORMAT_YV12;
610 break;
611 case IMGFMT_NV12:
612 vdp_pixel_format = VDP_YCBCR_FORMAT_NV12;
613 break;
614 case IMGFMT_YUY2:
615 vdp_pixel_format = VDP_YCBCR_FORMAT_YUYV;
616 vdp_chroma_type = VDP_CHROMA_TYPE_422;
617 break;
618 case IMGFMT_UYVY:
619 vdp_pixel_format = VDP_YCBCR_FORMAT_UYVY;
620 vdp_chroma_type = VDP_CHROMA_TYPE_422;
622 if (create_vdp_mixer(vdp_chroma_type))
623 return -1;
625 surface_num = 0;
626 vid_surface_num = -1;
627 resize();
629 return 0;
632 static void check_events(void)
634 int e = vo_x11_check_events(mDisplay);
636 if (e & VO_EVENT_RESIZE)
637 resize();
639 if ((e & VO_EVENT_EXPOSE || e & VO_EVENT_RESIZE) && int_pause) {
640 /* did we already draw a buffer */
641 if (visible_buf) {
642 /* redraw the last visible buffer */
643 VdpStatus vdp_st;
644 vdp_st = vdp_presentation_queue_display(vdp_flip_queue,
645 output_surfaces[surface_num],
646 vo_dwidth, vo_dheight,
648 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_display")
653 static void draw_osd_I8A8(int x0,int y0, int w,int h, unsigned char *src,
654 unsigned char *srca, int stride)
656 VdpOutputSurface output_surface = output_surfaces[surface_num];
657 VdpStatus vdp_st;
658 int i, j;
659 int pitch;
660 int index_data_size_required;
661 VdpRect output_indexed_rect_vid;
662 VdpOutputSurfaceRenderBlendState blend_state;
664 if (!w || !h)
665 return;
667 index_data_size_required = 2*w*h;
668 if (index_data_size < index_data_size_required) {
669 index_data = realloc(index_data, index_data_size_required);
670 index_data_size = index_data_size_required;
673 // index_data creation, component order - I, A, I, A, .....
674 for (i = 0; i < h; i++)
675 for (j = 0; j < w; j++) {
676 index_data[i*2*w + j*2] = src [i*stride+j];
677 index_data[i*2*w + j*2 + 1] = -srca[i*stride+j];
680 output_indexed_rect_vid.x0 = x0;
681 output_indexed_rect_vid.y0 = y0;
682 output_indexed_rect_vid.x1 = x0 + w;
683 output_indexed_rect_vid.y1 = y0 + h;
685 pitch = w*2;
687 // write source_data to osd_surface.
688 vdp_st = vdp_output_surface_put_bits_indexed(osd_surface,
689 VDP_INDEXED_FORMAT_I8A8,
690 (const void *const*)&index_data,
691 &pitch,
692 &output_indexed_rect_vid,
693 VDP_COLOR_TABLE_FORMAT_B8G8R8X8,
694 (void *)palette);
695 CHECK_ST_WARNING("Error when calling vdp_output_surface_put_bits_indexed")
697 blend_state.struct_version = VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION;
698 blend_state.blend_factor_source_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE;
699 blend_state.blend_factor_source_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE;
700 blend_state.blend_factor_destination_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
701 blend_state.blend_factor_destination_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
702 blend_state.blend_equation_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD;
703 blend_state.blend_equation_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD;
705 vdp_st = vdp_output_surface_render_output_surface(output_surface,
706 &output_indexed_rect_vid,
707 osd_surface,
708 &output_indexed_rect_vid,
709 NULL,
710 &blend_state,
711 VDP_OUTPUT_SURFACE_RENDER_ROTATE_0);
712 CHECK_ST_WARNING("Error when calling vdp_output_surface_render_output_surface")
715 static void draw_eosd(void) {
716 VdpStatus vdp_st;
717 VdpOutputSurface output_surface = output_surfaces[surface_num];
718 VdpOutputSurfaceRenderBlendState blend_state;
719 int i;
721 blend_state.struct_version = VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION;
722 blend_state.blend_factor_source_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_SRC_ALPHA;
723 blend_state.blend_factor_source_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE;
724 blend_state.blend_factor_destination_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
725 blend_state.blend_factor_destination_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_SRC_ALPHA;
726 blend_state.blend_equation_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD;
727 blend_state.blend_equation_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD;
729 for (i=0; i<eosd_render_count; i++) {
730 vdp_st = vdp_output_surface_render_bitmap_surface(
731 output_surface, &eosd_targets[i].dest,
732 eosd_targets[i].surface, &eosd_targets[i].source,
733 &eosd_targets[i].color, &blend_state,
734 VDP_OUTPUT_SURFACE_RENDER_ROTATE_0);
735 CHECK_ST_WARNING("EOSD: Error when rendering")
739 static void generate_eosd(mp_eosd_images_t *imgs) {
740 VdpStatus vdp_st;
741 VdpRect destRect;
742 int j, found;
743 ass_image_t *img = imgs->imgs;
744 ass_image_t *i;
746 // Nothing changed, no need to redraw
747 if (imgs->changed == 0)
748 return;
749 eosd_render_count = 0;
750 // There's nothing to render!
751 if (!img)
752 return;
754 if (imgs->changed == 1)
755 goto eosd_skip_upload;
757 for (j=0; j<eosd_surface_count; j++)
758 eosd_surfaces[j].in_use = 0;
760 for (i = img; i; i = i->next) {
761 // Try to reuse a suitable surface
762 found = -1;
763 for (j=0; j<eosd_surface_count; j++) {
764 if (eosd_surfaces[j].surface != VDP_INVALID_HANDLE && !eosd_surfaces[j].in_use &&
765 eosd_surfaces[j].w >= i->w && eosd_surfaces[j].h >= i->h) {
766 found = j;
767 break;
770 // None found, allocate a new surface
771 if (found < 0) {
772 for (j=0; j<eosd_surface_count; j++) {
773 if (!eosd_surfaces[j].in_use) {
774 if (eosd_surfaces[j].surface != VDP_INVALID_HANDLE)
775 vdp_bitmap_surface_destroy(eosd_surfaces[j].surface);
776 found = j;
777 break;
780 // Allocate new space for surface/target arrays
781 if (found < 0) {
782 j = found = eosd_surface_count;
783 eosd_surface_count = eosd_surface_count ? eosd_surface_count*2 : EOSD_SURFACES_INITIAL;
784 eosd_surfaces = realloc(eosd_surfaces, eosd_surface_count * sizeof(*eosd_surfaces));
785 eosd_targets = realloc(eosd_targets, eosd_surface_count * sizeof(*eosd_targets));
786 for(j=found; j<eosd_surface_count; j++) {
787 eosd_surfaces[j].surface = VDP_INVALID_HANDLE;
788 eosd_surfaces[j].in_use = 0;
791 vdp_st = vdp_bitmap_surface_create(vdp_device, VDP_RGBA_FORMAT_A8,
792 i->w, i->h, VDP_TRUE, &eosd_surfaces[found].surface);
793 CHECK_ST_WARNING("EOSD: error when creating surface")
794 eosd_surfaces[found].w = i->w;
795 eosd_surfaces[found].h = i->h;
797 eosd_surfaces[found].in_use = 1;
798 eosd_targets[eosd_render_count].surface = eosd_surfaces[found].surface;
799 destRect.x0 = 0;
800 destRect.y0 = 0;
801 destRect.x1 = i->w;
802 destRect.y1 = i->h;
803 vdp_st = vdp_bitmap_surface_putbits_native(eosd_targets[eosd_render_count].surface,
804 (const void *) &i->bitmap, &i->stride, &destRect);
805 CHECK_ST_WARNING("EOSD: putbits failed")
806 eosd_render_count++;
809 eosd_skip_upload:
810 eosd_render_count = 0;
811 for (i = img; i; i = i->next) {
812 // Render dest, color, etc.
813 eosd_targets[eosd_render_count].color.alpha = 1.0 - ((i->color >> 0) & 0xff) / 255.0;
814 eosd_targets[eosd_render_count].color.blue = ((i->color >> 8) & 0xff) / 255.0;
815 eosd_targets[eosd_render_count].color.green = ((i->color >> 16) & 0xff) / 255.0;
816 eosd_targets[eosd_render_count].color.red = ((i->color >> 24) & 0xff) / 255.0;
817 eosd_targets[eosd_render_count].dest.x0 = i->dst_x;
818 eosd_targets[eosd_render_count].dest.y0 = i->dst_y;
819 eosd_targets[eosd_render_count].dest.x1 = i->w + i->dst_x;
820 eosd_targets[eosd_render_count].dest.y1 = i->h + i->dst_y;
821 eosd_targets[eosd_render_count].source.x0 = 0;
822 eosd_targets[eosd_render_count].source.y0 = 0;
823 eosd_targets[eosd_render_count].source.x1 = i->w;
824 eosd_targets[eosd_render_count].source.y1 = i->h;
825 eosd_render_count++;
829 static void draw_osd(void)
831 mp_msg(MSGT_VO, MSGL_DBG2, "DRAW_OSD\n");
833 vo_draw_text_ext(vo_dwidth, vo_dheight, border_x, border_y, border_x, border_y,
834 vid_width, vid_height, draw_osd_I8A8);
837 static void flip_page(void)
839 VdpStatus vdp_st;
840 mp_msg(MSGT_VO, MSGL_DBG2, "\nFLIP_PAGE VID:%u -> OUT:%u\n",
841 surface_render[vid_surface_num].surface, output_surfaces[surface_num]);
843 vdp_st = vdp_presentation_queue_display(vdp_flip_queue, output_surfaces[surface_num],
844 vo_dwidth, vo_dheight,
846 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_display")
848 surface_num = (surface_num + 1) % NUM_OUTPUT_SURFACES;
849 visible_buf = 1;
852 static int draw_slice(uint8_t *image[], int stride[], int w, int h,
853 int x, int y)
855 VdpStatus vdp_st;
856 struct vdpau_render_state *rndr = (struct vdpau_render_state *)image[0];
857 int max_refs = image_format == IMGFMT_VDPAU_H264 ? rndr->info.h264.num_ref_frames : 2;
858 if (!IMGFMT_IS_VDPAU(image_format))
859 return VO_FALSE;
860 if ((decoder == VDP_INVALID_HANDLE || decoder_max_refs < max_refs)
861 && !create_vdp_decoder(max_refs))
862 return VO_FALSE;
864 vdp_st = vdp_decoder_render(decoder, rndr->surface, (void *)&rndr->info, rndr->bitstream_buffers_used, rndr->bitstream_buffers);
865 CHECK_ST_WARNING("Failed VDPAU decoder rendering");
866 return VO_TRUE;
870 static int draw_frame(uint8_t *src[])
872 return VO_ERROR;
875 static struct vdpau_render_state *get_surface(int number)
877 if (number > MAX_VIDEO_SURFACES)
878 return NULL;
879 if (surface_render[number].surface == VDP_INVALID_HANDLE) {
880 VdpStatus vdp_st;
881 vdp_st = vdp_video_surface_create(vdp_device, vdp_chroma_type,
882 vid_width, vid_height,
883 &surface_render[number].surface);
884 CHECK_ST_WARNING("Error when calling vdp_video_surface_create")
885 if (vdp_st != VDP_STATUS_OK)
886 return NULL;
888 mp_msg(MSGT_VO, MSGL_DBG2, "VID CREATE: %u\n", surface_render[number].surface);
889 return &surface_render[number];
892 static uint32_t draw_image(mp_image_t *mpi)
894 if (IMGFMT_IS_VDPAU(image_format)) {
895 struct vdpau_render_state *rndr = mpi->priv;
896 vid_surface_num = rndr - surface_render;
897 if (deint_buffer_past_frames) {
898 mpi->usage_count++;
899 if (deint_mpi[1])
900 deint_mpi[1]->usage_count--;
901 deint_mpi[1] = deint_mpi[0];
902 deint_mpi[0] = mpi;
904 } else if (!(mpi->flags & MP_IMGFLAG_DRAW_CALLBACK)) {
905 VdpStatus vdp_st;
906 void *destdata[3] = {mpi->planes[0], mpi->planes[2], mpi->planes[1]};
907 struct vdpau_render_state *rndr = get_surface(deint_counter);
908 deint_counter = (deint_counter + 1) % 3;
909 vid_surface_num = rndr - surface_render;
910 if (image_format == IMGFMT_NV12)
911 destdata[1] = destdata[2];
912 vdp_st = vdp_video_surface_put_bits_y_cb_cr(rndr->surface,
913 vdp_pixel_format,
914 (const void *const*)destdata,
915 mpi->stride); // pitch
916 CHECK_ST_ERROR("Error when calling vdp_video_surface_put_bits_y_cb_cr")
918 if (mpi->fields & MP_IMGFIELD_ORDERED)
919 top_field_first = !!(mpi->fields & MP_IMGFIELD_TOP_FIRST);
920 else
921 top_field_first = 1;
923 video_to_output_surface();
924 return VO_TRUE;
927 static uint32_t get_image(mp_image_t *mpi)
929 struct vdpau_render_state *rndr;
931 // no dr for non-decoding for now
932 if (!IMGFMT_IS_VDPAU(image_format)) return VO_FALSE;
933 if (mpi->type != MP_IMGTYPE_NUMBERED) return VO_FALSE;
935 rndr = get_surface(mpi->number);
936 if (!rndr) {
937 mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] no surfaces available in get_image\n");
938 // TODO: this probably breaks things forever, provide a dummy buffer?
939 return VO_FALSE;
941 mpi->flags |= MP_IMGFLAG_DIRECT;
942 mpi->stride[0] = mpi->stride[1] = mpi->stride[2] = 0;
943 mpi->planes[0] = mpi->planes[1] = mpi->planes[2] = NULL;
944 // hack to get around a check and to avoid a special-case in vd_ffmpeg.c
945 mpi->planes[0] = (void *)rndr;
946 mpi->num_planes = 1;
947 mpi->priv = rndr;
948 return VO_TRUE;
951 static int query_format(uint32_t format)
953 int default_flags = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_OSD | VFCAP_EOSD | VFCAP_EOSD_UNSCALED;
954 switch (format) {
955 case IMGFMT_YV12:
956 case IMGFMT_I420:
957 case IMGFMT_IYUV:
958 case IMGFMT_NV12:
959 case IMGFMT_YUY2:
960 case IMGFMT_UYVY:
961 return default_flags | VOCAP_NOSLICES;
962 case IMGFMT_VDPAU_MPEG1:
963 case IMGFMT_VDPAU_MPEG2:
964 case IMGFMT_VDPAU_H264:
965 case IMGFMT_VDPAU_WMV3:
966 case IMGFMT_VDPAU_VC1:
967 return default_flags;
969 return 0;
972 static void DestroyVdpauObjects(void)
974 int i;
975 VdpStatus vdp_st;
977 free_video_specific();
979 vdp_st = vdp_presentation_queue_destroy(vdp_flip_queue);
980 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_destroy")
982 vdp_st = vdp_presentation_queue_target_destroy(vdp_flip_target);
983 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_target_destroy")
985 for (i = 0; i <= NUM_OUTPUT_SURFACES; i++) {
986 vdp_st = vdp_output_surface_destroy(output_surfaces[i]);
987 output_surfaces[i] = VDP_INVALID_HANDLE;
988 CHECK_ST_WARNING("Error when calling vdp_output_surface_destroy")
991 for (i = 0; i<eosd_surface_count; i++) {
992 if (eosd_surfaces[i].surface != VDP_INVALID_HANDLE) {
993 vdp_st = vdp_bitmap_surface_destroy(eosd_surfaces[i].surface);
994 CHECK_ST_WARNING("Error when calling vdp_bitmap_surface_destroy")
996 eosd_surfaces[i].surface = VDP_INVALID_HANDLE;
999 vdp_st = vdp_device_destroy(vdp_device);
1000 CHECK_ST_WARNING("Error when calling vdp_device_destroy")
1003 static void uninit(void)
1005 if (!vo_config_count)
1006 return;
1007 visible_buf = 0;
1009 /* Destroy all vdpau objects */
1010 DestroyVdpauObjects();
1012 free(index_data);
1013 index_data = NULL;
1015 free(eosd_surfaces);
1016 eosd_surfaces = NULL;
1017 free(eosd_targets);
1018 eosd_targets = NULL;
1020 #ifdef CONFIG_XF86VM
1021 vo_vm_close();
1022 #endif
1023 vo_x11_uninit();
1025 dlclose(vdpau_lib_handle);
1028 static const opt_t subopts[] = {
1029 {"deint", OPT_ARG_INT, &deint, (opt_test_f)int_non_neg},
1030 {"chroma-deint", OPT_ARG_BOOL, &chroma_deint, NULL},
1031 {"pullup", OPT_ARG_BOOL, &pullup, NULL},
1032 {"denoise", OPT_ARG_FLOAT, &denoise, NULL},
1033 {"sharpen", OPT_ARG_FLOAT, &sharpen, NULL},
1034 {NULL}
1037 static const char help_msg[] =
1038 "\n-vo vdpau command line help:\n"
1039 "Example: mplayer -vo vdpau:deint=2\n"
1040 "\nOptions:\n"
1041 " deint (all modes > 0 respect -field-dominance)\n"
1042 " 0: no deinterlacing\n"
1043 " 1: only show first field\n"
1044 " 2: bob deinterlacing\n"
1045 " 3: temporal deinterlacing (resource-hungry)\n"
1046 " 4: temporal-spatial deinterlacing (very resource-hungry)\n"
1047 " chroma-deint\n"
1048 " Operate on luma and chroma when using temporal deinterlacing (default)\n"
1049 " Use nochroma-deint to speed up temporal deinterlacing\n"
1050 " pullup\n"
1051 " Try to apply inverse-telecine (needs temporal deinterlacing)\n"
1052 " denoise\n"
1053 " Apply denoising, argument is strength from 0.0 to 1.0\n"
1054 " sharpen\n"
1055 " Apply sharpening or softening, argument is strength from -1.0 to 1.0\n"
1058 static int preinit(const char *arg)
1060 int i;
1061 static const char *vdpaulibrary = "libvdpau.so.1";
1062 static const char *vdpau_device_create = "vdp_device_create_x11";
1064 deint = 0;
1065 deint_type = 3;
1066 deint_counter = 0;
1067 deint_buffer_past_frames = 0;
1068 deint_mpi[0] = deint_mpi[1] = NULL;
1069 chroma_deint = 1;
1070 pullup = 0;
1071 denoise = 0;
1072 sharpen = 0;
1073 if (subopt_parse(arg, subopts) != 0) {
1074 mp_msg(MSGT_VO, MSGL_FATAL, help_msg);
1075 return -1;
1077 if (deint)
1078 deint_type = deint;
1079 if (deint > 1)
1080 deint_buffer_past_frames = 1;
1082 vdpau_lib_handle = dlopen(vdpaulibrary, RTLD_LAZY);
1083 if (!vdpau_lib_handle) {
1084 mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Could not open dynamic library %s\n",
1085 vdpaulibrary);
1086 return -1;
1088 vdp_device_create = dlsym(vdpau_lib_handle, vdpau_device_create);
1089 if (!vdp_device_create) {
1090 mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Could not find function %s in %s\n",
1091 vdpau_device_create, vdpaulibrary);
1092 return -1;
1094 if (!vo_init() || win_x11_init_vdpau_procs())
1095 return -1;
1097 decoder = VDP_INVALID_HANDLE;
1098 for (i = 0; i < MAX_VIDEO_SURFACES; i++)
1099 surface_render[i].surface = VDP_INVALID_HANDLE;
1100 video_mixer = VDP_INVALID_HANDLE;
1101 for (i = 0; i <= NUM_OUTPUT_SURFACES; i++)
1102 output_surfaces[i] = VDP_INVALID_HANDLE;
1103 vdp_flip_queue = VDP_INVALID_HANDLE;
1104 output_surface_width = output_surface_height = -1;
1106 // full grayscale palette.
1107 for (i = 0; i < PALETTE_SIZE; ++i)
1108 palette[i] = (i << 16) | (i << 8) | i;
1109 index_data = NULL;
1110 index_data_size = 0;
1112 eosd_surface_count = eosd_render_count = 0;
1113 eosd_surfaces = NULL;
1114 eosd_targets = NULL;
1116 procamp.struct_version = VDP_PROCAMP_VERSION;
1117 procamp.brightness = 0.0;
1118 procamp.contrast = 1.0;
1119 procamp.saturation = 1.0;
1120 procamp.hue = 0.0;
1122 return 0;
1125 static int get_equalizer(char *name, int *value) {
1126 if (!strcasecmp(name, "brightness"))
1127 *value = procamp.brightness * 100;
1128 else if (!strcasecmp(name, "contrast"))
1129 *value = (procamp.contrast-1.0) * 100;
1130 else if (!strcasecmp(name, "saturation"))
1131 *value = (procamp.saturation-1.0) * 100;
1132 else if (!strcasecmp(name, "hue"))
1133 *value = procamp.hue * 100 / M_PI;
1134 else
1135 return VO_NOTIMPL;
1136 return VO_TRUE;
1139 static int set_equalizer(char *name, int value) {
1140 VdpStatus vdp_st;
1141 VdpCSCMatrix matrix;
1142 static const VdpVideoMixerAttribute attributes[] = {VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX};
1143 const void *attribute_values[] = {&matrix};
1145 if (!strcasecmp(name, "brightness"))
1146 procamp.brightness = value / 100.0;
1147 else if (!strcasecmp(name, "contrast"))
1148 procamp.contrast = value / 100.0 + 1.0;
1149 else if (!strcasecmp(name, "saturation"))
1150 procamp.saturation = value / 100.0 + 1.0;
1151 else if (!strcasecmp(name, "hue"))
1152 procamp.hue = value / 100.0 * M_PI;
1153 else
1154 return VO_NOTIMPL;
1156 vdp_st = vdp_generate_csc_matrix(&procamp, VDP_COLOR_STANDARD_ITUR_BT_601,
1157 &matrix);
1158 CHECK_ST_WARNING("Error when generating CSC matrix")
1159 vdp_st = vdp_video_mixer_set_attribute_values(video_mixer, 1, attributes,
1160 attribute_values);
1161 CHECK_ST_WARNING("Error when setting CSC matrix")
1162 return VO_TRUE;
1165 static int control(uint32_t request, void *data)
1167 switch (request) {
1168 case VOCTRL_GET_DEINTERLACE:
1169 *(int*)data = deint;
1170 return VO_TRUE;
1171 case VOCTRL_SET_DEINTERLACE:
1172 deint = *(int*)data;
1173 if (deint)
1174 deint = deint_type;
1175 if (deint_type > 2) {
1176 VdpStatus vdp_st;
1177 VdpVideoMixerFeature features[1] =
1178 {deint_type == 3 ?
1179 VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL :
1180 VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL};
1181 VdpBool feature_enables[1] = {deint ? VDP_TRUE : VDP_FALSE};
1182 vdp_st = vdp_video_mixer_set_feature_enables(video_mixer, 1,
1183 features,
1184 feature_enables);
1185 CHECK_ST_WARNING("Error changing deinterlacing settings")
1186 deint_buffer_past_frames = 1;
1188 return VO_TRUE;
1189 case VOCTRL_PAUSE:
1190 return (int_pause = 1);
1191 case VOCTRL_RESUME:
1192 return (int_pause = 0);
1193 case VOCTRL_QUERY_FORMAT:
1194 return query_format(*(uint32_t *)data);
1195 case VOCTRL_GET_IMAGE:
1196 return get_image(data);
1197 case VOCTRL_DRAW_IMAGE:
1198 return draw_image(data);
1199 case VOCTRL_GUISUPPORT:
1200 return VO_TRUE;
1201 case VOCTRL_BORDER:
1202 vo_x11_border();
1203 resize();
1204 return VO_TRUE;
1205 case VOCTRL_FULLSCREEN:
1206 vo_x11_fullscreen();
1207 resize();
1208 return VO_TRUE;
1209 case VOCTRL_GET_PANSCAN:
1210 return VO_TRUE;
1211 case VOCTRL_SET_PANSCAN:
1212 resize();
1213 return VO_TRUE;
1214 case VOCTRL_SET_EQUALIZER: {
1215 struct voctrl_set_equalizer_args *args = data;
1216 return set_equalizer(args->name, args->value);
1218 case VOCTRL_GET_EQUALIZER:
1220 struct voctrl_get_equalizer_args *args = data;
1221 return get_equalizer(args->name, args->valueptr);
1223 case VOCTRL_ONTOP:
1224 vo_x11_ontop();
1225 return VO_TRUE;
1226 case VOCTRL_UPDATE_SCREENINFO:
1227 update_xinerama_info();
1228 return VO_TRUE;
1229 case VOCTRL_DRAW_EOSD:
1230 if (!data)
1231 return VO_FALSE;
1232 generate_eosd(data);
1233 draw_eosd();
1234 return VO_TRUE;
1235 case VOCTRL_GET_EOSD_RES: {
1236 mp_eosd_res_t *r = data;
1237 r->mt = r->mb = r->ml = r->mr = 0;
1238 if (vo_fs) {
1239 r->w = vo_screenwidth;
1240 r->h = vo_screenheight;
1241 r->ml = r->mr = border_x;
1242 r->mt = r->mb = border_y;
1243 } else {
1244 r->w = vo_dwidth;
1245 r->h = vo_dheight;
1247 return VO_TRUE;
1250 return VO_NOTIMPL;
1253 /* @} */