Add const where appropriate, also gets rid of a compiler warning.
[mplayer/glamo.git] / libvo / vo_vdpau.c
blobfffb1b010e319183bc38f8ffa1ff9dfa0c451768
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 int_pause = 0;
557 visible_buf = 0;
559 #ifdef CONFIG_GUI
560 if (use_gui)
561 guiGetEvent(guiSetShVideo, 0); // the GUI will set up / resize our window
562 else
563 #endif
565 #ifdef CONFIG_XF86VM
566 if (vm)
567 vo_vm_switch();
568 else
569 #endif
570 XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &attribs);
571 depth = attribs.depth;
572 if (depth != 15 && depth != 16 && depth != 24 && depth != 32)
573 depth = 24;
574 XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo);
576 xswa.background_pixel = 0;
577 xswa.border_pixel = 0;
578 /* Do not use CWBackPixel: It leads to VDPAU errors after
579 aspect ratio changes. */
580 xswamask = CWBorderPixel;
582 vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, d_width, d_height,
583 flags, CopyFromParent, "vdpau", title);
584 XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa);
586 #ifdef CONFIG_XF86VM
587 if (vm) {
588 /* Grab the mouse pointer in our window */
589 if (vo_grabpointer)
590 XGrabPointer(mDisplay, vo_window, True, 0,
591 GrabModeAsync, GrabModeAsync,
592 vo_window, None, CurrentTime);
593 XSetInputFocus(mDisplay, vo_window, RevertToNone, CurrentTime);
595 #endif
598 if ((flags & VOFLAG_FULLSCREEN) && WinID <= 0)
599 vo_fs = 1;
601 /* -----VDPAU related code here -------- */
602 if (vdp_flip_queue == VDP_INVALID_HANDLE && win_x11_init_vdpau_flip_queue())
603 return -1;
605 vdp_chroma_type = VDP_CHROMA_TYPE_420;
606 switch (image_format) {
607 case IMGFMT_YV12:
608 case IMGFMT_I420:
609 case IMGFMT_IYUV:
610 vdp_pixel_format = VDP_YCBCR_FORMAT_YV12;
611 break;
612 case IMGFMT_NV12:
613 vdp_pixel_format = VDP_YCBCR_FORMAT_NV12;
614 break;
615 case IMGFMT_YUY2:
616 vdp_pixel_format = VDP_YCBCR_FORMAT_YUYV;
617 vdp_chroma_type = VDP_CHROMA_TYPE_422;
618 break;
619 case IMGFMT_UYVY:
620 vdp_pixel_format = VDP_YCBCR_FORMAT_UYVY;
621 vdp_chroma_type = VDP_CHROMA_TYPE_422;
623 if (create_vdp_mixer(vdp_chroma_type))
624 return -1;
626 surface_num = 0;
627 vid_surface_num = -1;
628 resize();
630 return 0;
633 static void check_events(void)
635 int e = vo_x11_check_events(mDisplay);
637 if (e & VO_EVENT_RESIZE)
638 resize();
640 if ((e & VO_EVENT_EXPOSE || e & VO_EVENT_RESIZE) && int_pause) {
641 /* did we already draw a buffer */
642 if (visible_buf) {
643 /* redraw the last visible buffer */
644 VdpStatus vdp_st;
645 vdp_st = vdp_presentation_queue_display(vdp_flip_queue,
646 output_surfaces[surface_num],
647 vo_dwidth, vo_dheight,
649 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_display")
654 static void draw_osd_I8A8(int x0,int y0, int w,int h, unsigned char *src,
655 unsigned char *srca, int stride)
657 VdpOutputSurface output_surface = output_surfaces[surface_num];
658 VdpStatus vdp_st;
659 int i, j;
660 int pitch;
661 int index_data_size_required;
662 VdpRect output_indexed_rect_vid;
663 VdpOutputSurfaceRenderBlendState blend_state;
665 if (!w || !h)
666 return;
668 index_data_size_required = 2*w*h;
669 if (index_data_size < index_data_size_required) {
670 index_data = realloc(index_data, index_data_size_required);
671 index_data_size = index_data_size_required;
674 // index_data creation, component order - I, A, I, A, .....
675 for (i = 0; i < h; i++)
676 for (j = 0; j < w; j++) {
677 index_data[i*2*w + j*2] = src [i*stride+j];
678 index_data[i*2*w + j*2 + 1] = -srca[i*stride+j];
681 output_indexed_rect_vid.x0 = x0;
682 output_indexed_rect_vid.y0 = y0;
683 output_indexed_rect_vid.x1 = x0 + w;
684 output_indexed_rect_vid.y1 = y0 + h;
686 pitch = w*2;
688 // write source_data to osd_surface.
689 vdp_st = vdp_output_surface_put_bits_indexed(osd_surface,
690 VDP_INDEXED_FORMAT_I8A8,
691 (const void *const*)&index_data,
692 &pitch,
693 &output_indexed_rect_vid,
694 VDP_COLOR_TABLE_FORMAT_B8G8R8X8,
695 (void *)palette);
696 CHECK_ST_WARNING("Error when calling vdp_output_surface_put_bits_indexed")
698 blend_state.struct_version = VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION;
699 blend_state.blend_factor_source_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE;
700 blend_state.blend_factor_source_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE;
701 blend_state.blend_factor_destination_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
702 blend_state.blend_factor_destination_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
703 blend_state.blend_equation_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD;
704 blend_state.blend_equation_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD;
706 vdp_st = vdp_output_surface_render_output_surface(output_surface,
707 &output_indexed_rect_vid,
708 osd_surface,
709 &output_indexed_rect_vid,
710 NULL,
711 &blend_state,
712 VDP_OUTPUT_SURFACE_RENDER_ROTATE_0);
713 CHECK_ST_WARNING("Error when calling vdp_output_surface_render_output_surface")
716 static void draw_eosd(void) {
717 VdpStatus vdp_st;
718 VdpOutputSurface output_surface = output_surfaces[surface_num];
719 VdpOutputSurfaceRenderBlendState blend_state;
720 int i;
722 blend_state.struct_version = VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION;
723 blend_state.blend_factor_source_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_SRC_ALPHA;
724 blend_state.blend_factor_source_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE;
725 blend_state.blend_factor_destination_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
726 blend_state.blend_factor_destination_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_SRC_ALPHA;
727 blend_state.blend_equation_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD;
728 blend_state.blend_equation_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD;
730 for (i=0; i<eosd_render_count; i++) {
731 vdp_st = vdp_output_surface_render_bitmap_surface(
732 output_surface, &eosd_targets[i].dest,
733 eosd_targets[i].surface, &eosd_targets[i].source,
734 &eosd_targets[i].color, &blend_state,
735 VDP_OUTPUT_SURFACE_RENDER_ROTATE_0);
736 CHECK_ST_WARNING("EOSD: Error when rendering")
740 static void generate_eosd(mp_eosd_images_t *imgs) {
741 VdpStatus vdp_st;
742 VdpRect destRect;
743 int j, found;
744 ass_image_t *img = imgs->imgs;
745 ass_image_t *i;
747 // Nothing changed, no need to redraw
748 if (imgs->changed == 0)
749 return;
750 eosd_render_count = 0;
751 // There's nothing to render!
752 if (!img)
753 return;
755 if (imgs->changed == 1)
756 goto eosd_skip_upload;
758 for (j=0; j<eosd_surface_count; j++)
759 eosd_surfaces[j].in_use = 0;
761 for (i = img; i; i = i->next) {
762 // Try to reuse a suitable surface
763 found = -1;
764 for (j=0; j<eosd_surface_count; j++) {
765 if (eosd_surfaces[j].surface != VDP_INVALID_HANDLE && !eosd_surfaces[j].in_use &&
766 eosd_surfaces[j].w >= i->w && eosd_surfaces[j].h >= i->h) {
767 found = j;
768 break;
771 // None found, allocate a new surface
772 if (found < 0) {
773 for (j=0; j<eosd_surface_count; j++) {
774 if (!eosd_surfaces[j].in_use) {
775 if (eosd_surfaces[j].surface != VDP_INVALID_HANDLE)
776 vdp_bitmap_surface_destroy(eosd_surfaces[j].surface);
777 found = j;
778 break;
781 // Allocate new space for surface/target arrays
782 if (found < 0) {
783 j = found = eosd_surface_count;
784 eosd_surface_count = eosd_surface_count ? eosd_surface_count*2 : EOSD_SURFACES_INITIAL;
785 eosd_surfaces = realloc(eosd_surfaces, eosd_surface_count * sizeof(*eosd_surfaces));
786 eosd_targets = realloc(eosd_targets, eosd_surface_count * sizeof(*eosd_targets));
787 for(j=found; j<eosd_surface_count; j++) {
788 eosd_surfaces[j].surface = VDP_INVALID_HANDLE;
789 eosd_surfaces[j].in_use = 0;
792 vdp_st = vdp_bitmap_surface_create(vdp_device, VDP_RGBA_FORMAT_A8,
793 i->w, i->h, VDP_TRUE, &eosd_surfaces[found].surface);
794 CHECK_ST_WARNING("EOSD: error when creating surface")
795 eosd_surfaces[found].w = i->w;
796 eosd_surfaces[found].h = i->h;
798 eosd_surfaces[found].in_use = 1;
799 eosd_targets[eosd_render_count].surface = eosd_surfaces[found].surface;
800 destRect.x0 = 0;
801 destRect.y0 = 0;
802 destRect.x1 = i->w;
803 destRect.y1 = i->h;
804 vdp_st = vdp_bitmap_surface_putbits_native(eosd_targets[eosd_render_count].surface,
805 (const void *) &i->bitmap, &i->stride, &destRect);
806 CHECK_ST_WARNING("EOSD: putbits failed")
807 eosd_render_count++;
810 eosd_skip_upload:
811 eosd_render_count = 0;
812 for (i = img; i; i = i->next) {
813 // Render dest, color, etc.
814 eosd_targets[eosd_render_count].color.alpha = 1.0 - ((i->color >> 0) & 0xff) / 255.0;
815 eosd_targets[eosd_render_count].color.blue = ((i->color >> 8) & 0xff) / 255.0;
816 eosd_targets[eosd_render_count].color.green = ((i->color >> 16) & 0xff) / 255.0;
817 eosd_targets[eosd_render_count].color.red = ((i->color >> 24) & 0xff) / 255.0;
818 eosd_targets[eosd_render_count].dest.x0 = i->dst_x;
819 eosd_targets[eosd_render_count].dest.y0 = i->dst_y;
820 eosd_targets[eosd_render_count].dest.x1 = i->w + i->dst_x;
821 eosd_targets[eosd_render_count].dest.y1 = i->h + i->dst_y;
822 eosd_targets[eosd_render_count].source.x0 = 0;
823 eosd_targets[eosd_render_count].source.y0 = 0;
824 eosd_targets[eosd_render_count].source.x1 = i->w;
825 eosd_targets[eosd_render_count].source.y1 = i->h;
826 eosd_render_count++;
830 static void draw_osd(void)
832 mp_msg(MSGT_VO, MSGL_DBG2, "DRAW_OSD\n");
834 vo_draw_text_ext(vo_dwidth, vo_dheight, border_x, border_y, border_x, border_y,
835 vid_width, vid_height, draw_osd_I8A8);
838 static void flip_page(void)
840 VdpStatus vdp_st;
841 mp_msg(MSGT_VO, MSGL_DBG2, "\nFLIP_PAGE VID:%u -> OUT:%u\n",
842 surface_render[vid_surface_num].surface, output_surfaces[surface_num]);
844 vdp_st = vdp_presentation_queue_display(vdp_flip_queue, output_surfaces[surface_num],
845 vo_dwidth, vo_dheight,
847 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_display")
849 surface_num = (surface_num + 1) % NUM_OUTPUT_SURFACES;
850 visible_buf = 1;
853 static int draw_slice(uint8_t *image[], int stride[], int w, int h,
854 int x, int y)
856 VdpStatus vdp_st;
857 struct vdpau_render_state *rndr = (struct vdpau_render_state *)image[0];
858 int max_refs = image_format == IMGFMT_VDPAU_H264 ? rndr->info.h264.num_ref_frames : 2;
859 if (!IMGFMT_IS_VDPAU(image_format))
860 return VO_FALSE;
861 if ((decoder == VDP_INVALID_HANDLE || decoder_max_refs < max_refs)
862 && !create_vdp_decoder(max_refs))
863 return VO_FALSE;
865 vdp_st = vdp_decoder_render(decoder, rndr->surface, (void *)&rndr->info, rndr->bitstream_buffers_used, rndr->bitstream_buffers);
866 CHECK_ST_WARNING("Failed VDPAU decoder rendering");
867 return VO_TRUE;
871 static int draw_frame(uint8_t *src[])
873 return VO_ERROR;
876 static struct vdpau_render_state *get_surface(int number)
878 if (number > MAX_VIDEO_SURFACES)
879 return NULL;
880 if (surface_render[number].surface == VDP_INVALID_HANDLE) {
881 VdpStatus vdp_st;
882 vdp_st = vdp_video_surface_create(vdp_device, vdp_chroma_type,
883 vid_width, vid_height,
884 &surface_render[number].surface);
885 CHECK_ST_WARNING("Error when calling vdp_video_surface_create")
886 if (vdp_st != VDP_STATUS_OK)
887 return NULL;
889 mp_msg(MSGT_VO, MSGL_DBG2, "VID CREATE: %u\n", surface_render[number].surface);
890 return &surface_render[number];
893 static uint32_t draw_image(mp_image_t *mpi)
895 if (IMGFMT_IS_VDPAU(image_format)) {
896 struct vdpau_render_state *rndr = mpi->priv;
897 vid_surface_num = rndr - surface_render;
898 if (deint_buffer_past_frames) {
899 mpi->usage_count++;
900 if (deint_mpi[1])
901 deint_mpi[1]->usage_count--;
902 deint_mpi[1] = deint_mpi[0];
903 deint_mpi[0] = mpi;
905 } else if (!(mpi->flags & MP_IMGFLAG_DRAW_CALLBACK)) {
906 VdpStatus vdp_st;
907 void *destdata[3] = {mpi->planes[0], mpi->planes[2], mpi->planes[1]};
908 struct vdpau_render_state *rndr = get_surface(deint_counter);
909 deint_counter = (deint_counter + 1) % 3;
910 vid_surface_num = rndr - surface_render;
911 if (image_format == IMGFMT_NV12)
912 destdata[1] = destdata[2];
913 vdp_st = vdp_video_surface_put_bits_y_cb_cr(rndr->surface,
914 vdp_pixel_format,
915 (const void *const*)destdata,
916 mpi->stride); // pitch
917 CHECK_ST_ERROR("Error when calling vdp_video_surface_put_bits_y_cb_cr")
919 if (mpi->fields & MP_IMGFIELD_ORDERED)
920 top_field_first = !!(mpi->fields & MP_IMGFIELD_TOP_FIRST);
921 else
922 top_field_first = 1;
924 video_to_output_surface();
925 return VO_TRUE;
928 static uint32_t get_image(mp_image_t *mpi)
930 struct vdpau_render_state *rndr;
932 // no dr for non-decoding for now
933 if (!IMGFMT_IS_VDPAU(image_format)) return VO_FALSE;
934 if (mpi->type != MP_IMGTYPE_NUMBERED) return VO_FALSE;
936 rndr = get_surface(mpi->number);
937 if (!rndr) {
938 mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] no surfaces available in get_image\n");
939 // TODO: this probably breaks things forever, provide a dummy buffer?
940 return VO_FALSE;
942 mpi->flags |= MP_IMGFLAG_DIRECT;
943 mpi->stride[0] = mpi->stride[1] = mpi->stride[2] = 0;
944 mpi->planes[0] = mpi->planes[1] = mpi->planes[2] = NULL;
945 // hack to get around a check and to avoid a special-case in vd_ffmpeg.c
946 mpi->planes[0] = (void *)rndr;
947 mpi->num_planes = 1;
948 mpi->priv = rndr;
949 return VO_TRUE;
952 static int query_format(uint32_t format)
954 int default_flags = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_OSD | VFCAP_EOSD | VFCAP_EOSD_UNSCALED;
955 switch (format) {
956 case IMGFMT_YV12:
957 case IMGFMT_I420:
958 case IMGFMT_IYUV:
959 case IMGFMT_NV12:
960 case IMGFMT_YUY2:
961 case IMGFMT_UYVY:
962 return default_flags | VOCAP_NOSLICES;
963 case IMGFMT_VDPAU_MPEG1:
964 case IMGFMT_VDPAU_MPEG2:
965 case IMGFMT_VDPAU_H264:
966 case IMGFMT_VDPAU_WMV3:
967 case IMGFMT_VDPAU_VC1:
968 return default_flags;
970 return 0;
973 static void DestroyVdpauObjects(void)
975 int i;
976 VdpStatus vdp_st;
978 free_video_specific();
980 vdp_st = vdp_presentation_queue_destroy(vdp_flip_queue);
981 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_destroy")
983 vdp_st = vdp_presentation_queue_target_destroy(vdp_flip_target);
984 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_target_destroy")
986 for (i = 0; i <= NUM_OUTPUT_SURFACES; i++) {
987 vdp_st = vdp_output_surface_destroy(output_surfaces[i]);
988 output_surfaces[i] = VDP_INVALID_HANDLE;
989 CHECK_ST_WARNING("Error when calling vdp_output_surface_destroy")
992 for (i = 0; i<eosd_surface_count; i++) {
993 if (eosd_surfaces[i].surface != VDP_INVALID_HANDLE) {
994 vdp_st = vdp_bitmap_surface_destroy(eosd_surfaces[i].surface);
995 CHECK_ST_WARNING("Error when calling vdp_bitmap_surface_destroy")
997 eosd_surfaces[i].surface = VDP_INVALID_HANDLE;
1000 vdp_st = vdp_device_destroy(vdp_device);
1001 CHECK_ST_WARNING("Error when calling vdp_device_destroy")
1004 static void uninit(void)
1006 if (!vo_config_count)
1007 return;
1008 visible_buf = 0;
1010 /* Destroy all vdpau objects */
1011 DestroyVdpauObjects();
1013 free(index_data);
1014 index_data = NULL;
1016 free(eosd_surfaces);
1017 eosd_surfaces = NULL;
1018 free(eosd_targets);
1019 eosd_targets = NULL;
1021 #ifdef CONFIG_XF86VM
1022 vo_vm_close();
1023 #endif
1024 vo_x11_uninit();
1026 dlclose(vdpau_lib_handle);
1029 static const opt_t subopts[] = {
1030 {"deint", OPT_ARG_INT, &deint, (opt_test_f)int_non_neg},
1031 {"chroma-deint", OPT_ARG_BOOL, &chroma_deint, NULL},
1032 {"pullup", OPT_ARG_BOOL, &pullup, NULL},
1033 {"denoise", OPT_ARG_FLOAT, &denoise, NULL},
1034 {"sharpen", OPT_ARG_FLOAT, &sharpen, NULL},
1035 {NULL}
1038 static const char help_msg[] =
1039 "\n-vo vdpau command line help:\n"
1040 "Example: mplayer -vo vdpau:deint=2\n"
1041 "\nOptions:\n"
1042 " deint (all modes > 0 respect -field-dominance)\n"
1043 " 0: no deinterlacing\n"
1044 " 1: only show first field\n"
1045 " 2: bob deinterlacing\n"
1046 " 3: temporal deinterlacing (resource-hungry)\n"
1047 " 4: temporal-spatial deinterlacing (very resource-hungry)\n"
1048 " chroma-deint\n"
1049 " Operate on luma and chroma when using temporal deinterlacing (default)\n"
1050 " Use nochroma-deint to speed up temporal deinterlacing\n"
1051 " pullup\n"
1052 " Try to apply inverse-telecine (needs temporal deinterlacing)\n"
1053 " denoise\n"
1054 " Apply denoising, argument is strength from 0.0 to 1.0\n"
1055 " sharpen\n"
1056 " Apply sharpening or softening, argument is strength from -1.0 to 1.0\n"
1059 static int preinit(const char *arg)
1061 int i;
1062 static const char *vdpaulibrary = "libvdpau.so.1";
1063 static const char *vdpau_device_create = "vdp_device_create_x11";
1065 deint = 0;
1066 deint_type = 3;
1067 deint_counter = 0;
1068 deint_buffer_past_frames = 0;
1069 deint_mpi[0] = deint_mpi[1] = NULL;
1070 chroma_deint = 1;
1071 pullup = 0;
1072 denoise = 0;
1073 sharpen = 0;
1074 if (subopt_parse(arg, subopts) != 0) {
1075 mp_msg(MSGT_VO, MSGL_FATAL, help_msg);
1076 return -1;
1078 if (deint)
1079 deint_type = deint;
1080 if (deint > 1)
1081 deint_buffer_past_frames = 1;
1083 vdpau_lib_handle = dlopen(vdpaulibrary, RTLD_LAZY);
1084 if (!vdpau_lib_handle) {
1085 mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Could not open dynamic library %s\n",
1086 vdpaulibrary);
1087 return -1;
1089 vdp_device_create = dlsym(vdpau_lib_handle, vdpau_device_create);
1090 if (!vdp_device_create) {
1091 mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Could not find function %s in %s\n",
1092 vdpau_device_create, vdpaulibrary);
1093 return -1;
1095 if (!vo_init() || win_x11_init_vdpau_procs())
1096 return -1;
1098 decoder = VDP_INVALID_HANDLE;
1099 for (i = 0; i < MAX_VIDEO_SURFACES; i++)
1100 surface_render[i].surface = VDP_INVALID_HANDLE;
1101 video_mixer = VDP_INVALID_HANDLE;
1102 for (i = 0; i <= NUM_OUTPUT_SURFACES; i++)
1103 output_surfaces[i] = VDP_INVALID_HANDLE;
1104 vdp_flip_queue = VDP_INVALID_HANDLE;
1105 output_surface_width = output_surface_height = -1;
1107 // full grayscale palette.
1108 for (i = 0; i < PALETTE_SIZE; ++i)
1109 palette[i] = (i << 16) | (i << 8) | i;
1110 index_data = NULL;
1111 index_data_size = 0;
1113 eosd_surface_count = eosd_render_count = 0;
1114 eosd_surfaces = NULL;
1115 eosd_targets = NULL;
1117 procamp.struct_version = VDP_PROCAMP_VERSION;
1118 procamp.brightness = 0.0;
1119 procamp.contrast = 1.0;
1120 procamp.saturation = 1.0;
1121 procamp.hue = 0.0;
1123 return 0;
1126 static int get_equalizer(char *name, int *value) {
1127 if (!strcasecmp(name, "brightness"))
1128 *value = procamp.brightness * 100;
1129 else if (!strcasecmp(name, "contrast"))
1130 *value = (procamp.contrast-1.0) * 100;
1131 else if (!strcasecmp(name, "saturation"))
1132 *value = (procamp.saturation-1.0) * 100;
1133 else if (!strcasecmp(name, "hue"))
1134 *value = procamp.hue * 100 / M_PI;
1135 else
1136 return VO_NOTIMPL;
1137 return VO_TRUE;
1140 static int set_equalizer(char *name, int value) {
1141 VdpStatus vdp_st;
1142 VdpCSCMatrix matrix;
1143 static const VdpVideoMixerAttribute attributes[] = {VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX};
1144 const void *attribute_values[] = {&matrix};
1146 if (!strcasecmp(name, "brightness"))
1147 procamp.brightness = value / 100.0;
1148 else if (!strcasecmp(name, "contrast"))
1149 procamp.contrast = value / 100.0 + 1.0;
1150 else if (!strcasecmp(name, "saturation"))
1151 procamp.saturation = value / 100.0 + 1.0;
1152 else if (!strcasecmp(name, "hue"))
1153 procamp.hue = value / 100.0 * M_PI;
1154 else
1155 return VO_NOTIMPL;
1157 vdp_st = vdp_generate_csc_matrix(&procamp, VDP_COLOR_STANDARD_ITUR_BT_601,
1158 &matrix);
1159 CHECK_ST_WARNING("Error when generating CSC matrix")
1160 vdp_st = vdp_video_mixer_set_attribute_values(video_mixer, 1, attributes,
1161 attribute_values);
1162 CHECK_ST_WARNING("Error when setting CSC matrix")
1163 return VO_TRUE;
1166 static int control(uint32_t request, void *data, ...)
1168 switch (request) {
1169 case VOCTRL_GET_DEINTERLACE:
1170 *(int*)data = deint;
1171 return VO_TRUE;
1172 case VOCTRL_SET_DEINTERLACE:
1173 deint = *(int*)data;
1174 if (deint)
1175 deint = deint_type;
1176 if (deint_type > 2) {
1177 VdpStatus vdp_st;
1178 VdpVideoMixerFeature features[1] =
1179 {deint_type == 3 ?
1180 VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL :
1181 VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL};
1182 VdpBool feature_enables[1] = {deint ? VDP_TRUE : VDP_FALSE};
1183 vdp_st = vdp_video_mixer_set_feature_enables(video_mixer, 1,
1184 features,
1185 feature_enables);
1186 CHECK_ST_WARNING("Error changing deinterlacing settings")
1187 deint_buffer_past_frames = 1;
1189 return VO_TRUE;
1190 case VOCTRL_PAUSE:
1191 return (int_pause = 1);
1192 case VOCTRL_RESUME:
1193 return (int_pause = 0);
1194 case VOCTRL_QUERY_FORMAT:
1195 return query_format(*(uint32_t *)data);
1196 case VOCTRL_GET_IMAGE:
1197 return get_image(data);
1198 case VOCTRL_DRAW_IMAGE:
1199 return draw_image(data);
1200 case VOCTRL_GUISUPPORT:
1201 return VO_TRUE;
1202 case VOCTRL_BORDER:
1203 vo_x11_border();
1204 resize();
1205 return VO_TRUE;
1206 case VOCTRL_FULLSCREEN:
1207 vo_x11_fullscreen();
1208 resize();
1209 return VO_TRUE;
1210 case VOCTRL_GET_PANSCAN:
1211 return VO_TRUE;
1212 case VOCTRL_SET_PANSCAN:
1213 resize();
1214 return VO_TRUE;
1215 case VOCTRL_SET_EQUALIZER: {
1216 va_list ap;
1217 int value;
1219 va_start(ap, data);
1220 value = va_arg(ap, int);
1222 va_end(ap);
1223 return set_equalizer(data, value);
1225 case VOCTRL_GET_EQUALIZER: {
1226 va_list ap;
1227 int *value;
1229 va_start(ap, data);
1230 value = va_arg(ap, int *);
1232 va_end(ap);
1233 return get_equalizer(data, value);
1235 case VOCTRL_ONTOP:
1236 vo_x11_ontop();
1237 return VO_TRUE;
1238 case VOCTRL_UPDATE_SCREENINFO:
1239 update_xinerama_info();
1240 return VO_TRUE;
1241 case VOCTRL_DRAW_EOSD:
1242 if (!data)
1243 return VO_FALSE;
1244 generate_eosd(data);
1245 draw_eosd();
1246 return VO_TRUE;
1247 case VOCTRL_GET_EOSD_RES: {
1248 mp_eosd_res_t *r = data;
1249 r->mt = r->mb = r->ml = r->mr = 0;
1250 if (vo_fs) {
1251 r->w = vo_screenwidth;
1252 r->h = vo_screenheight;
1253 r->ml = r->mr = border_x;
1254 r->mt = r->mb = border_y;
1255 } else {
1256 r->w = vo_dwidth;
1257 r->h = vo_dheight;
1259 return VO_TRUE;
1262 return VO_NOTIMPL;
1265 /* @} */