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.
24 * \defgroup VDPAU_Presentation VDPAU Presentation
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.
39 #include "video_out.h"
40 #include "video_out_internal.h"
41 #include "x11_common.h"
44 #include "subopt-helper.h"
46 #include "libavcodec/vdpau.h"
48 #include "gui/interface.h"
50 #include "libavutil/common.h"
51 #include "libavutil/mathematics.h"
53 #include "libass/ass_mp.h"
55 static vo_info_t info
= {
58 "Rajib Mahapatra <rmahapatra@nvidia.com> and others",
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)); \
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 3
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 VdpGetProcAddress
*vdp_get_proc_address
;
96 static VdpPresentationQueueTarget vdp_flip_target
;
97 static VdpPresentationQueue vdp_flip_queue
;
99 static VdpDeviceDestroy
*vdp_device_destroy
;
100 static VdpVideoSurfaceCreate
*vdp_video_surface_create
;
101 static VdpVideoSurfaceDestroy
*vdp_video_surface_destroy
;
103 static VdpGetErrorString
*vdp_get_error_string
;
105 /* May be used in software filtering/postprocessing options
106 * in MPlayer (./mplayer -vf ..) if we copy video_surface data to
109 static VdpVideoSurfacePutBitsYCbCr
*vdp_video_surface_put_bits_y_cb_cr
;
110 static VdpOutputSurfacePutBitsNative
*vdp_output_surface_put_bits_native
;
112 static VdpOutputSurfaceCreate
*vdp_output_surface_create
;
113 static VdpOutputSurfaceDestroy
*vdp_output_surface_destroy
;
115 /* VideoMixer puts video_surface data on displayable output_surface. */
116 static VdpVideoMixerCreate
*vdp_video_mixer_create
;
117 static VdpVideoMixerDestroy
*vdp_video_mixer_destroy
;
118 static VdpVideoMixerRender
*vdp_video_mixer_render
;
119 static VdpVideoMixerSetFeatureEnables
*vdp_video_mixer_set_feature_enables
;
120 static VdpVideoMixerSetAttributeValues
*vdp_video_mixer_set_attribute_values
;
122 static VdpPresentationQueueTargetDestroy
*vdp_presentation_queue_target_destroy
;
123 static VdpPresentationQueueCreate
*vdp_presentation_queue_create
;
124 static VdpPresentationQueueDestroy
*vdp_presentation_queue_destroy
;
125 static VdpPresentationQueueDisplay
*vdp_presentation_queue_display
;
126 static VdpPresentationQueueBlockUntilSurfaceIdle
*vdp_presentation_queue_block_until_surface_idle
;
127 static VdpPresentationQueueTargetCreateX11
*vdp_presentation_queue_target_create_x11
;
129 static VdpOutputSurfaceRenderOutputSurface
*vdp_output_surface_render_output_surface
;
130 static VdpOutputSurfacePutBitsIndexed
*vdp_output_surface_put_bits_indexed
;
131 static VdpOutputSurfaceRenderBitmapSurface
*vdp_output_surface_render_bitmap_surface
;
133 static VdpBitmapSurfaceCreate
*vdp_bitmap_surface_create
;
134 static VdpBitmapSurfaceDestroy
*vdp_bitmap_surface_destroy
;
135 static VdpBitmapSurfacePutBitsNative
*vdp_bitmap_surface_putbits_native
;
137 static VdpDecoderCreate
*vdp_decoder_create
;
138 static VdpDecoderDestroy
*vdp_decoder_destroy
;
139 static VdpDecoderRender
*vdp_decoder_render
;
141 static VdpGenerateCSCMatrix
*vdp_generate_csc_matrix
;
142 static VdpPreemptionCallbackRegister
*vdp_preemption_callback_register
;
144 /* output_surfaces[NUM_OUTPUT_SURFACES] is misused for OSD. */
145 #define osd_surface output_surfaces[NUM_OUTPUT_SURFACES]
146 static VdpOutputSurface output_surfaces
[NUM_OUTPUT_SURFACES
+ 1];
147 static VdpVideoSurface deint_surfaces
[3];
148 static mp_image_t
*deint_mpi
[2];
149 static int output_surface_width
, output_surface_height
;
151 static VdpVideoMixer video_mixer
;
153 static int deint_type
;
154 static int deint_counter
;
156 static float denoise
;
157 static float sharpen
;
158 static int colorspace
;
159 static int chroma_deint
;
160 static int force_mixer
;
161 static int top_field_first
;
163 static int hqscaling
;
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 static volatile int is_preempted
;
183 static unsigned char *index_data
;
184 static int index_data_size
;
185 static uint32_t palette
[PALETTE_SIZE
];
190 VdpBitmapSurface surface
;
196 // List of surfaces to be rendered
198 VdpBitmapSurface surface
;
204 static int eosd_render_count
;
205 static int eosd_surface_count
;
208 static VdpProcamp procamp
;
213 static int visible_buf
;
214 static int int_pause
;
216 static void draw_eosd(void);
218 static void push_deint_surface(VdpVideoSurface surface
)
220 deint_surfaces
[2] = deint_surfaces
[1];
221 deint_surfaces
[1] = deint_surfaces
[0];
222 deint_surfaces
[0] = surface
;
225 static void video_to_output_surface(void)
230 if (vid_surface_num
< 0)
233 if (deint
< 2 || deint_surfaces
[0] == VDP_INVALID_HANDLE
)
234 push_deint_surface(surface_render
[vid_surface_num
].surface
);
236 for (i
= 0; i
<= !!(deint
> 1); i
++) {
237 int field
= VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME
;
238 VdpOutputSurface output_surface
;
245 field
= (top_field_first
== i
) ^ (deint
> 1) ?
246 VDP_VIDEO_MIXER_PICTURE_STRUCTURE_BOTTOM_FIELD
:
247 VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD
;
248 output_surface
= output_surfaces
[surface_num
];
249 vdp_st
= vdp_presentation_queue_block_until_surface_idle(vdp_flip_queue
,
252 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_block_until_surface_idle")
254 vdp_st
= vdp_video_mixer_render(video_mixer
, VDP_INVALID_HANDLE
, 0,
255 field
, 2, deint_surfaces
+ 1,
257 1, &surface_render
[vid_surface_num
].surface
,
260 NULL
, &out_rect_vid
, 0, NULL
);
261 CHECK_ST_WARNING("Error when calling vdp_video_mixer_render")
262 push_deint_surface(surface_render
[vid_surface_num
].surface
);
266 static void resize(void)
270 struct vo_rect src_rect
;
271 struct vo_rect dst_rect
;
272 struct vo_rect borders
;
273 calc_src_dst_rects(vid_width
, vid_height
, &src_rect
, &dst_rect
, &borders
, NULL
);
274 out_rect_vid
.x0
= dst_rect
.left
;
275 out_rect_vid
.x1
= dst_rect
.right
;
276 out_rect_vid
.y0
= dst_rect
.top
;
277 out_rect_vid
.y1
= dst_rect
.bottom
;
278 src_rect_vid
.x0
= src_rect
.left
;
279 src_rect_vid
.x1
= src_rect
.right
;
280 src_rect_vid
.y0
= flip
? src_rect
.bottom
: src_rect
.top
;
281 src_rect_vid
.y1
= flip
? src_rect
.top
: src_rect
.bottom
;
282 border_x
= borders
.left
;
283 border_y
= borders
.top
;
284 #ifdef CONFIG_FREETYPE
285 // adjust font size to display size
288 vo_osd_changed(OSDTYPE_OSD
);
290 if (output_surface_width
< vo_dwidth
|| output_surface_height
< vo_dheight
) {
291 if (output_surface_width
< vo_dwidth
) {
292 output_surface_width
+= output_surface_width
>> 1;
293 output_surface_width
= FFMAX(output_surface_width
, vo_dwidth
);
295 if (output_surface_height
< vo_dheight
) {
296 output_surface_height
+= output_surface_height
>> 1;
297 output_surface_height
= FFMAX(output_surface_height
, vo_dheight
);
299 // Creation of output_surfaces
300 for (i
= 0; i
<= NUM_OUTPUT_SURFACES
; i
++) {
301 if (output_surfaces
[i
] != VDP_INVALID_HANDLE
)
302 vdp_output_surface_destroy(output_surfaces
[i
]);
303 vdp_st
= vdp_output_surface_create(vdp_device
, VDP_RGBA_FORMAT_B8G8R8A8
,
304 output_surface_width
, output_surface_height
,
305 &output_surfaces
[i
]);
306 CHECK_ST_WARNING("Error when calling vdp_output_surface_create")
307 mp_msg(MSGT_VO
, MSGL_DBG2
, "OUT CREATE: %u\n", output_surfaces
[i
]);
310 if (image_format
== IMGFMT_BGRA
) {
311 vdp_st
= vdp_output_surface_render_output_surface(output_surfaces
[surface_num
],
312 NULL
, VDP_INVALID_HANDLE
,
314 VDP_OUTPUT_SURFACE_RENDER_ROTATE_0
);
315 CHECK_ST_WARNING("Error when calling vdp_output_surface_render_output_surface")
316 vdp_st
= vdp_output_surface_render_output_surface(output_surfaces
[1 - surface_num
],
317 NULL
, VDP_INVALID_HANDLE
,
319 VDP_OUTPUT_SURFACE_RENDER_ROTATE_0
);
320 CHECK_ST_WARNING("Error when calling vdp_output_surface_render_output_surface")
322 video_to_output_surface();
327 static void preemption_callback(VdpDevice device
, void *context
)
329 mp_msg(MSGT_VO
, MSGL_ERR
, "[vdpau] Display preemption detected\n");
333 /* Initialize vdp_get_proc_address, called from preinit() */
334 static int win_x11_init_vdpau_procs(void)
338 struct vdp_function
{
343 const struct vdp_function
*dsc
;
345 static const struct vdp_function vdp_func
[] = {
346 {VDP_FUNC_ID_GET_ERROR_STRING
, &vdp_get_error_string
},
347 {VDP_FUNC_ID_DEVICE_DESTROY
, &vdp_device_destroy
},
348 {VDP_FUNC_ID_VIDEO_SURFACE_CREATE
, &vdp_video_surface_create
},
349 {VDP_FUNC_ID_VIDEO_SURFACE_DESTROY
, &vdp_video_surface_destroy
},
350 {VDP_FUNC_ID_VIDEO_SURFACE_PUT_BITS_Y_CB_CR
,
351 &vdp_video_surface_put_bits_y_cb_cr
},
352 {VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_NATIVE
,
353 &vdp_output_surface_put_bits_native
},
354 {VDP_FUNC_ID_OUTPUT_SURFACE_CREATE
, &vdp_output_surface_create
},
355 {VDP_FUNC_ID_OUTPUT_SURFACE_DESTROY
, &vdp_output_surface_destroy
},
356 {VDP_FUNC_ID_VIDEO_MIXER_CREATE
, &vdp_video_mixer_create
},
357 {VDP_FUNC_ID_VIDEO_MIXER_DESTROY
, &vdp_video_mixer_destroy
},
358 {VDP_FUNC_ID_VIDEO_MIXER_RENDER
, &vdp_video_mixer_render
},
359 {VDP_FUNC_ID_VIDEO_MIXER_SET_FEATURE_ENABLES
,
360 &vdp_video_mixer_set_feature_enables
},
361 {VDP_FUNC_ID_VIDEO_MIXER_SET_ATTRIBUTE_VALUES
,
362 &vdp_video_mixer_set_attribute_values
},
363 {VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_DESTROY
,
364 &vdp_presentation_queue_target_destroy
},
365 {VDP_FUNC_ID_PRESENTATION_QUEUE_CREATE
, &vdp_presentation_queue_create
},
366 {VDP_FUNC_ID_PRESENTATION_QUEUE_DESTROY
,
367 &vdp_presentation_queue_destroy
},
368 {VDP_FUNC_ID_PRESENTATION_QUEUE_DISPLAY
,
369 &vdp_presentation_queue_display
},
370 {VDP_FUNC_ID_PRESENTATION_QUEUE_BLOCK_UNTIL_SURFACE_IDLE
,
371 &vdp_presentation_queue_block_until_surface_idle
},
372 {VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_CREATE_X11
,
373 &vdp_presentation_queue_target_create_x11
},
374 {VDP_FUNC_ID_OUTPUT_SURFACE_RENDER_OUTPUT_SURFACE
,
375 &vdp_output_surface_render_output_surface
},
376 {VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_INDEXED
,
377 &vdp_output_surface_put_bits_indexed
},
378 {VDP_FUNC_ID_DECODER_CREATE
, &vdp_decoder_create
},
379 {VDP_FUNC_ID_DECODER_RENDER
, &vdp_decoder_render
},
380 {VDP_FUNC_ID_DECODER_DESTROY
, &vdp_decoder_destroy
},
381 {VDP_FUNC_ID_BITMAP_SURFACE_CREATE
, &vdp_bitmap_surface_create
},
382 {VDP_FUNC_ID_BITMAP_SURFACE_DESTROY
, &vdp_bitmap_surface_destroy
},
383 {VDP_FUNC_ID_BITMAP_SURFACE_PUT_BITS_NATIVE
,
384 &vdp_bitmap_surface_putbits_native
},
385 {VDP_FUNC_ID_OUTPUT_SURFACE_RENDER_BITMAP_SURFACE
,
386 &vdp_output_surface_render_bitmap_surface
},
387 {VDP_FUNC_ID_GENERATE_CSC_MATRIX
, &vdp_generate_csc_matrix
},
388 {VDP_FUNC_ID_PREEMPTION_CALLBACK_REGISTER
,
389 &vdp_preemption_callback_register
},
393 vdp_st
= vdp_device_create_x11(mDisplay
, mScreen
,
394 &vdp_device
, &vdp_get_proc_address
);
395 if (vdp_st
!= VDP_STATUS_OK
) {
396 mp_msg(MSGT_VO
, MSGL_ERR
, "[vdpau] Error when calling vdp_device_create_x11: %i\n", vdp_st
);
400 vdp_get_error_string
= NULL
;
401 for (dsc
= vdp_func
; dsc
->pointer
; dsc
++) {
402 vdp_st
= vdp_get_proc_address(vdp_device
, dsc
->id
, dsc
->pointer
);
403 if (vdp_st
!= VDP_STATUS_OK
) {
404 mp_msg(MSGT_VO
, MSGL_ERR
, "[vdpau] Error when calling vdp_get_proc_address(function id %d): %s\n",
405 dsc
->id
, vdp_get_error_string
? vdp_get_error_string(vdp_st
) : "?");
409 vdp_st
= vdp_preemption_callback_register(vdp_device
,
410 preemption_callback
, NULL
);
411 CHECK_ST_ERROR("Error when calling vdp_preemption_callback_register")
416 /* Initialize vdpau_flip_queue, called from config() */
417 static int win_x11_init_vdpau_flip_queue(void)
421 vdp_st
= vdp_presentation_queue_target_create_x11(vdp_device
, vo_window
,
423 CHECK_ST_ERROR("Error when calling vdp_presentation_queue_target_create_x11")
425 vdp_st
= vdp_presentation_queue_create(vdp_device
, vdp_flip_target
,
427 CHECK_ST_ERROR("Error when calling vdp_presentation_queue_create")
432 static int update_csc_matrix(void)
436 static const VdpVideoMixerAttribute attributes
[] = {VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX
};
437 const void *attribute_values
[] = {&matrix
};
438 static const VdpColorStandard vdp_colors
[] = {0, VDP_COLOR_STANDARD_ITUR_BT_601
, VDP_COLOR_STANDARD_ITUR_BT_709
, VDP_COLOR_STANDARD_SMPTE_240M
};
439 static const char * const vdp_names
[] = {NULL
, "BT.601", "BT.709", "SMPTE-240M"};
440 int csp
= colorspace
;
443 csp
= vid_width
>= 1280 || vid_height
> 576 ? 2 : 1;
445 mp_msg(MSGT_VO
, MSGL_V
, "[vdpau] Updating CSC matrix for %s\n",
448 vdp_st
= vdp_generate_csc_matrix(&procamp
, vdp_colors
[csp
], &matrix
);
449 CHECK_ST_WARNING("Error when generating CSC matrix")
451 vdp_st
= vdp_video_mixer_set_attribute_values(video_mixer
, 1, attributes
,
453 CHECK_ST_WARNING("Error when setting CSC matrix")
457 static int create_vdp_mixer(VdpChromaType vdp_chroma_type
)
459 #define VDP_NUM_MIXER_PARAMETER 3
460 #define MAX_NUM_FEATURES 6
463 int feature_count
= 0;
464 VdpVideoMixerFeature features
[MAX_NUM_FEATURES
];
465 VdpBool feature_enables
[MAX_NUM_FEATURES
];
466 static const VdpVideoMixerAttribute denoise_attrib
[] = {VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL
};
467 const void * const denoise_value
[] = {&denoise
};
468 static const VdpVideoMixerAttribute sharpen_attrib
[] = {VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL
};
469 const void * const sharpen_value
[] = {&sharpen
};
470 static const VdpVideoMixerAttribute skip_chroma_attrib
[] = {VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE
};
471 const uint8_t skip_chroma_value
= 1;
472 const void * const skip_chroma_value_ptr
[] = {&skip_chroma_value
};
473 static const VdpVideoMixerParameter parameters
[VDP_NUM_MIXER_PARAMETER
] = {
474 VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH
,
475 VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT
,
476 VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE
478 const void *const parameter_values
[VDP_NUM_MIXER_PARAMETER
] = {
483 features
[feature_count
++] = VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL
;
485 features
[feature_count
++] = VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL
;
487 features
[feature_count
++] = VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE
;
489 features
[feature_count
++] = VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION
;
491 features
[feature_count
++] = VDP_VIDEO_MIXER_FEATURE_SHARPNESS
;
493 features
[feature_count
++] = VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1
+ (hqscaling
- 1);
495 vdp_st
= vdp_video_mixer_create(vdp_device
, feature_count
, features
,
496 VDP_NUM_MIXER_PARAMETER
,
497 parameters
, parameter_values
,
499 CHECK_ST_ERROR("Error when calling vdp_video_mixer_create")
501 for (i
= 0; i
< feature_count
; i
++)
502 feature_enables
[i
] = VDP_TRUE
;
504 feature_enables
[0] = VDP_FALSE
;
506 vdp_video_mixer_set_feature_enables(video_mixer
, feature_count
, features
, feature_enables
);
508 vdp_video_mixer_set_attribute_values(video_mixer
, 1, denoise_attrib
, denoise_value
);
510 vdp_video_mixer_set_attribute_values(video_mixer
, 1, sharpen_attrib
, sharpen_value
);
512 vdp_video_mixer_set_attribute_values(video_mixer
, 1, skip_chroma_attrib
, skip_chroma_value_ptr
);
518 // Free everything specific to a certain video file
519 static void free_video_specific(void)
524 if (decoder
!= VDP_INVALID_HANDLE
)
525 vdp_decoder_destroy(decoder
);
526 decoder
= VDP_INVALID_HANDLE
;
527 decoder_max_refs
= -1;
529 for (i
= 0; i
< 3; i
++)
530 deint_surfaces
[i
] = VDP_INVALID_HANDLE
;
532 for (i
= 0; i
< 2; i
++)
534 deint_mpi
[i
]->usage_count
--;
538 for (i
= 0; i
< MAX_VIDEO_SURFACES
; i
++) {
539 if (surface_render
[i
].surface
!= VDP_INVALID_HANDLE
) {
540 vdp_st
= vdp_video_surface_destroy(surface_render
[i
].surface
);
541 CHECK_ST_WARNING("Error when calling vdp_video_surface_destroy")
543 surface_render
[i
].surface
= VDP_INVALID_HANDLE
;
546 if (video_mixer
!= VDP_INVALID_HANDLE
) {
547 vdp_st
= vdp_video_mixer_destroy(video_mixer
);
548 CHECK_ST_WARNING("Error when calling vdp_video_mixer_destroy")
550 video_mixer
= VDP_INVALID_HANDLE
;
553 static int create_vdp_decoder(uint32_t format
, uint32_t width
, uint32_t height
,
557 VdpDecoderProfile vdp_decoder_profile
;
558 if (decoder
!= VDP_INVALID_HANDLE
)
559 vdp_decoder_destroy(decoder
);
561 case IMGFMT_VDPAU_MPEG1
:
562 vdp_decoder_profile
= VDP_DECODER_PROFILE_MPEG1
;
564 case IMGFMT_VDPAU_MPEG2
:
565 vdp_decoder_profile
= VDP_DECODER_PROFILE_MPEG2_MAIN
;
567 case IMGFMT_VDPAU_H264
:
568 vdp_decoder_profile
= VDP_DECODER_PROFILE_H264_HIGH
;
569 mp_msg(MSGT_VO
, MSGL_V
, "[vdpau] Creating H264 hardware decoder for %d reference frames.\n", max_refs
);
571 case IMGFMT_VDPAU_WMV3
:
572 vdp_decoder_profile
= VDP_DECODER_PROFILE_VC1_MAIN
;
574 case IMGFMT_VDPAU_VC1
:
575 vdp_decoder_profile
= VDP_DECODER_PROFILE_VC1_ADVANCED
;
577 case IMGFMT_VDPAU_MPEG4
:
578 vdp_decoder_profile
= VDP_DECODER_PROFILE_MPEG4_PART2_ASP
;
583 vdp_st
= vdp_decoder_create(vdp_device
, vdp_decoder_profile
,
584 width
, height
, max_refs
, &decoder
);
585 CHECK_ST_WARNING("Failed creating VDPAU decoder");
586 if (vdp_st
!= VDP_STATUS_OK
) {
588 decoder
= VDP_INVALID_HANDLE
;
589 decoder_max_refs
= 0;
592 decoder_max_refs
= max_refs
;
596 static void mark_vdpau_objects_uninitialized(void)
600 decoder
= VDP_INVALID_HANDLE
;
601 for (i
= 0; i
< MAX_VIDEO_SURFACES
; i
++)
602 surface_render
[i
].surface
= VDP_INVALID_HANDLE
;
603 for (i
= 0; i
< 3; i
++) {
604 deint_surfaces
[i
] = VDP_INVALID_HANDLE
;
605 if (i
< 2 && deint_mpi
[i
])
606 deint_mpi
[i
]->usage_count
--;
609 video_mixer
= VDP_INVALID_HANDLE
;
610 vdp_flip_queue
= VDP_INVALID_HANDLE
;
611 vdp_flip_target
= VDP_INVALID_HANDLE
;
612 for (i
= 0; i
<= NUM_OUTPUT_SURFACES
; i
++)
613 output_surfaces
[i
] = VDP_INVALID_HANDLE
;
614 vdp_device
= VDP_INVALID_HANDLE
;
615 for (i
= 0; i
< eosd_surface_count
; i
++)
616 eosd_surfaces
[i
].surface
= VDP_INVALID_HANDLE
;
617 output_surface_width
= output_surface_height
= -1;
618 eosd_render_count
= 0;
622 static int handle_preemption(void)
627 mp_msg(MSGT_VO
, MSGL_INFO
, "[vdpau] Attempting to recover from preemption.\n");
628 mark_vdpau_objects_uninitialized();
629 if (win_x11_init_vdpau_procs() < 0 ||
630 win_x11_init_vdpau_flip_queue() < 0 ||
631 create_vdp_mixer(vdp_chroma_type
) < 0) {
632 mp_msg(MSGT_VO
, MSGL_ERR
, "[vdpau] Recovering from preemption failed\n");
637 mp_msg(MSGT_VO
, MSGL_INFO
, "[vdpau] Recovered from display preemption.\n");
642 * connect to X server, create and map window, initialize all
643 * VDPAU objects, create different surfaces etc.
645 static int config(uint32_t width
, uint32_t height
, uint32_t d_width
,
646 uint32_t d_height
, uint32_t flags
, char *title
,
650 XSetWindowAttributes xswa
;
651 XWindowAttributes attribs
;
652 unsigned long xswamask
;
656 int vm
= flags
& VOFLAG_MODESWITCHING
;
658 flip
= flags
& VOFLAG_FLIPPING
;
660 image_format
= format
;
663 free_video_specific();
664 if (IMGFMT_IS_VDPAU(image_format
)
665 && !create_vdp_decoder(image_format
, vid_width
, vid_height
, 2))
673 guiGetEvent(guiSetShVideo
, 0); // the GUI will set up / resize our window
682 XGetWindowAttributes(mDisplay
, DefaultRootWindow(mDisplay
), &attribs
);
683 depth
= attribs
.depth
;
684 if (depth
!= 15 && depth
!= 16 && depth
!= 24 && depth
!= 32)
686 XMatchVisualInfo(mDisplay
, mScreen
, depth
, TrueColor
, &vinfo
);
688 xswa
.background_pixel
= 0;
689 xswa
.border_pixel
= 0;
690 /* Do not use CWBackPixel: It leads to VDPAU errors after
691 aspect ratio changes. */
692 xswamask
= CWBorderPixel
;
694 vo_x11_create_vo_window(&vinfo
, vo_dx
, vo_dy
, d_width
, d_height
,
695 flags
, CopyFromParent
, "vdpau", title
);
696 XChangeWindowAttributes(mDisplay
, vo_window
, xswamask
, &xswa
);
700 /* Grab the mouse pointer in our window */
702 XGrabPointer(mDisplay
, vo_window
, True
, 0,
703 GrabModeAsync
, GrabModeAsync
,
704 vo_window
, None
, CurrentTime
);
705 XSetInputFocus(mDisplay
, vo_window
, RevertToNone
, CurrentTime
);
710 if ((flags
& VOFLAG_FULLSCREEN
) && WinID
<= 0)
713 /* -----VDPAU related code here -------- */
714 if (vdp_flip_queue
== VDP_INVALID_HANDLE
&& win_x11_init_vdpau_flip_queue())
717 vdp_chroma_type
= VDP_CHROMA_TYPE_420
;
718 switch (image_format
) {
722 vdp_pixel_format
= VDP_YCBCR_FORMAT_YV12
;
725 vdp_pixel_format
= VDP_YCBCR_FORMAT_NV12
;
728 vdp_pixel_format
= VDP_YCBCR_FORMAT_YUYV
;
729 vdp_chroma_type
= VDP_CHROMA_TYPE_422
;
732 vdp_pixel_format
= VDP_YCBCR_FORMAT_UYVY
;
733 vdp_chroma_type
= VDP_CHROMA_TYPE_422
;
735 if (create_vdp_mixer(vdp_chroma_type
))
739 vid_surface_num
= -1;
745 static void check_events(void)
747 int e
= vo_x11_check_events(mDisplay
);
749 if (handle_preemption() < 0)
752 if (e
& VO_EVENT_RESIZE
)
755 if ((e
& VO_EVENT_EXPOSE
|| e
& VO_EVENT_RESIZE
) && int_pause
) {
756 /* did we already draw a buffer */
758 /* redraw the last visible buffer */
760 vdp_st
= vdp_presentation_queue_display(vdp_flip_queue
,
761 output_surfaces
[surface_num
],
762 vo_dwidth
, vo_dheight
,
764 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_display")
769 static void draw_osd_I8A8(int x0
,int y0
, int w
,int h
, unsigned char *src
,
770 unsigned char *srca
, int stride
)
772 VdpOutputSurface output_surface
= output_surfaces
[surface_num
];
776 int index_data_size_required
;
777 VdpRect output_indexed_rect_vid
;
778 VdpOutputSurfaceRenderBlendState blend_state
;
783 index_data_size_required
= 2*w
*h
;
784 if (index_data_size
< index_data_size_required
) {
785 index_data
= realloc(index_data
, index_data_size_required
);
786 index_data_size
= index_data_size_required
;
789 // index_data creation, component order - I, A, I, A, .....
790 for (i
= 0; i
< h
; i
++)
791 for (j
= 0; j
< w
; j
++) {
792 index_data
[i
*2*w
+ j
*2] = src
[i
*stride
+ j
];
793 index_data
[i
*2*w
+ j
*2 + 1] = -srca
[i
*stride
+ j
];
796 output_indexed_rect_vid
.x0
= x0
;
797 output_indexed_rect_vid
.y0
= y0
;
798 output_indexed_rect_vid
.x1
= x0
+ w
;
799 output_indexed_rect_vid
.y1
= y0
+ h
;
803 // write source_data to osd_surface.
804 vdp_st
= vdp_output_surface_put_bits_indexed(osd_surface
,
805 VDP_INDEXED_FORMAT_I8A8
,
806 (const void *const*)&index_data
,
808 &output_indexed_rect_vid
,
809 VDP_COLOR_TABLE_FORMAT_B8G8R8X8
,
811 CHECK_ST_WARNING("Error when calling vdp_output_surface_put_bits_indexed")
813 blend_state
.struct_version
= VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION
;
814 blend_state
.blend_factor_source_color
= VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE
;
815 blend_state
.blend_factor_source_alpha
= VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE
;
816 blend_state
.blend_factor_destination_color
= VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA
;
817 blend_state
.blend_factor_destination_alpha
= VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA
;
818 blend_state
.blend_equation_color
= VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD
;
819 blend_state
.blend_equation_alpha
= VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD
;
821 vdp_st
= vdp_output_surface_render_output_surface(output_surface
,
822 &output_indexed_rect_vid
,
824 &output_indexed_rect_vid
,
827 VDP_OUTPUT_SURFACE_RENDER_ROTATE_0
);
828 CHECK_ST_WARNING("Error when calling vdp_output_surface_render_output_surface")
831 static void draw_eosd(void)
834 VdpOutputSurface output_surface
= output_surfaces
[surface_num
];
835 VdpOutputSurfaceRenderBlendState blend_state
;
838 blend_state
.struct_version
= VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION
;
839 blend_state
.blend_factor_source_color
= VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_SRC_ALPHA
;
840 blend_state
.blend_factor_source_alpha
= VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE
;
841 blend_state
.blend_factor_destination_color
= VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA
;
842 blend_state
.blend_factor_destination_alpha
= VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_SRC_ALPHA
;
843 blend_state
.blend_equation_color
= VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD
;
844 blend_state
.blend_equation_alpha
= VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD
;
846 for (i
= 0; i
< eosd_render_count
; i
++) {
847 vdp_st
= vdp_output_surface_render_bitmap_surface(
848 output_surface
, &eosd_targets
[i
].dest
,
849 eosd_targets
[i
].surface
, &eosd_targets
[i
].source
,
850 &eosd_targets
[i
].color
, &blend_state
,
851 VDP_OUTPUT_SURFACE_RENDER_ROTATE_0
);
852 CHECK_ST_WARNING("EOSD: Error when rendering")
856 static void generate_eosd(mp_eosd_images_t
*imgs
)
861 ass_image_t
*img
= imgs
->imgs
;
864 // Nothing changed, no need to redraw
865 if (imgs
->changed
== 0)
867 eosd_render_count
= 0;
868 // There's nothing to render!
872 if (imgs
->changed
== 1)
873 goto eosd_skip_upload
;
875 for (j
= 0; j
< eosd_surface_count
; j
++)
876 eosd_surfaces
[j
].in_use
= 0;
878 for (i
= img
; i
; i
= i
->next
) {
879 // Try to reuse a suitable surface
881 for (j
= 0; j
< eosd_surface_count
; j
++) {
882 if (eosd_surfaces
[j
].surface
!= VDP_INVALID_HANDLE
&& !eosd_surfaces
[j
].in_use
&&
883 eosd_surfaces
[j
].w
>= i
->w
&& eosd_surfaces
[j
].h
>= i
->h
) {
888 // None found, allocate a new surface
890 for (j
= 0; j
< eosd_surface_count
; j
++) {
891 if (!eosd_surfaces
[j
].in_use
) {
892 if (eosd_surfaces
[j
].surface
!= VDP_INVALID_HANDLE
)
893 vdp_bitmap_surface_destroy(eosd_surfaces
[j
].surface
);
898 // Allocate new space for surface/target arrays
900 j
= found
= eosd_surface_count
;
901 eosd_surface_count
= eosd_surface_count
? eosd_surface_count
*2 : EOSD_SURFACES_INITIAL
;
902 eosd_surfaces
= realloc(eosd_surfaces
, eosd_surface_count
* sizeof(*eosd_surfaces
));
903 eosd_targets
= realloc(eosd_targets
, eosd_surface_count
* sizeof(*eosd_targets
));
904 for (j
= found
; j
< eosd_surface_count
; j
++) {
905 eosd_surfaces
[j
].surface
= VDP_INVALID_HANDLE
;
906 eosd_surfaces
[j
].in_use
= 0;
909 vdp_st
= vdp_bitmap_surface_create(vdp_device
, VDP_RGBA_FORMAT_A8
,
910 i
->w
, i
->h
, VDP_TRUE
, &eosd_surfaces
[found
].surface
);
911 CHECK_ST_WARNING("EOSD: error when creating surface")
912 eosd_surfaces
[found
].w
= i
->w
;
913 eosd_surfaces
[found
].h
= i
->h
;
915 eosd_surfaces
[found
].in_use
= 1;
916 eosd_targets
[eosd_render_count
].surface
= eosd_surfaces
[found
].surface
;
921 vdp_st
= vdp_bitmap_surface_putbits_native(eosd_targets
[eosd_render_count
].surface
,
922 (const void *) &i
->bitmap
, &i
->stride
, &destRect
);
923 CHECK_ST_WARNING("EOSD: putbits failed")
928 eosd_render_count
= 0;
929 for (i
= img
; i
; i
= i
->next
) {
930 // Render dest, color, etc.
931 eosd_targets
[eosd_render_count
].color
.alpha
= 1.0 - ((i
->color
>> 0) & 0xff) / 255.0;
932 eosd_targets
[eosd_render_count
].color
.blue
= ((i
->color
>> 8) & 0xff) / 255.0;
933 eosd_targets
[eosd_render_count
].color
.green
= ((i
->color
>> 16) & 0xff) / 255.0;
934 eosd_targets
[eosd_render_count
].color
.red
= ((i
->color
>> 24) & 0xff) / 255.0;
935 eosd_targets
[eosd_render_count
].dest
.x0
= i
->dst_x
;
936 eosd_targets
[eosd_render_count
].dest
.y0
= i
->dst_y
;
937 eosd_targets
[eosd_render_count
].dest
.x1
= i
->w
+ i
->dst_x
;
938 eosd_targets
[eosd_render_count
].dest
.y1
= i
->h
+ i
->dst_y
;
939 eosd_targets
[eosd_render_count
].source
.x0
= 0;
940 eosd_targets
[eosd_render_count
].source
.y0
= 0;
941 eosd_targets
[eosd_render_count
].source
.x1
= i
->w
;
942 eosd_targets
[eosd_render_count
].source
.y1
= i
->h
;
947 static void draw_osd(void)
949 mp_msg(MSGT_VO
, MSGL_DBG2
, "DRAW_OSD\n");
951 if (handle_preemption() < 0)
954 vo_draw_text_ext(vo_dwidth
, vo_dheight
, border_x
, border_y
, border_x
, border_y
,
955 vid_width
, vid_height
, draw_osd_I8A8
);
958 static void flip_page(void)
961 mp_msg(MSGT_VO
, MSGL_DBG2
, "\nFLIP_PAGE VID:%u -> OUT:%u\n",
962 surface_render
[vid_surface_num
].surface
, output_surfaces
[surface_num
]);
964 if (handle_preemption() < 0)
967 vdp_st
= vdp_presentation_queue_display(vdp_flip_queue
, output_surfaces
[surface_num
],
968 vo_dwidth
, vo_dheight
,
970 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_display")
972 surface_num
= (surface_num
+ 1) % NUM_OUTPUT_SURFACES
;
976 static int draw_slice(uint8_t *image
[], int stride
[], int w
, int h
,
980 struct vdpau_render_state
*rndr
= (struct vdpau_render_state
*)image
[0];
981 int max_refs
= image_format
== IMGFMT_VDPAU_H264
? rndr
->info
.h264
.num_ref_frames
: 2;
983 if (handle_preemption() < 0)
986 if (!IMGFMT_IS_VDPAU(image_format
))
988 if ((decoder
== VDP_INVALID_HANDLE
|| decoder_max_refs
< max_refs
)
989 && !create_vdp_decoder(image_format
, vid_width
, vid_height
, max_refs
))
992 vdp_st
= vdp_decoder_render(decoder
, rndr
->surface
, (void *)&rndr
->info
, rndr
->bitstream_buffers_used
, rndr
->bitstream_buffers
);
993 CHECK_ST_WARNING("Failed VDPAU decoder rendering");
998 static int draw_frame(uint8_t *src
[])
1003 static struct vdpau_render_state
*get_surface(int number
)
1005 if (number
> MAX_VIDEO_SURFACES
)
1007 if (surface_render
[number
].surface
== VDP_INVALID_HANDLE
) {
1009 vdp_st
= vdp_video_surface_create(vdp_device
, vdp_chroma_type
,
1010 vid_width
, vid_height
,
1011 &surface_render
[number
].surface
);
1012 CHECK_ST_WARNING("Error when calling vdp_video_surface_create")
1013 if (vdp_st
!= VDP_STATUS_OK
)
1016 mp_msg(MSGT_VO
, MSGL_DBG2
, "VID CREATE: %u\n", surface_render
[number
].surface
);
1017 return &surface_render
[number
];
1020 static uint32_t draw_image(mp_image_t
*mpi
)
1022 if (IMGFMT_IS_VDPAU(image_format
)) {
1023 struct vdpau_render_state
*rndr
= mpi
->priv
;
1024 vid_surface_num
= rndr
- surface_render
;
1027 deint_mpi
[1]->usage_count
--;
1028 deint_mpi
[1] = deint_mpi
[0];
1030 } else if (image_format
== IMGFMT_BGRA
) {
1032 VdpRect r
= {0, 0, vid_width
, vid_height
};
1033 vdp_st
= vdp_output_surface_put_bits_native(output_surfaces
[2],
1034 (void const*const*)mpi
->planes
,
1036 CHECK_ST_ERROR("Error when calling vdp_output_surface_put_bits_native")
1037 vdp_st
= vdp_output_surface_render_output_surface(output_surfaces
[surface_num
],
1040 &src_rect_vid
, NULL
, NULL
,
1041 VDP_OUTPUT_SURFACE_RENDER_ROTATE_0
);
1042 CHECK_ST_ERROR("Error when calling vdp_output_surface_render_output_surface")
1043 } else if (!(mpi
->flags
& MP_IMGFLAG_DRAW_CALLBACK
)) {
1045 void *destdata
[3] = {mpi
->planes
[0], mpi
->planes
[2], mpi
->planes
[1]};
1046 struct vdpau_render_state
*rndr
= get_surface(deint_counter
);
1047 deint_counter
= (deint_counter
+ 1) % 3;
1048 vid_surface_num
= rndr
- surface_render
;
1049 if (image_format
== IMGFMT_NV12
)
1050 destdata
[1] = destdata
[2];
1051 vdp_st
= vdp_video_surface_put_bits_y_cb_cr(rndr
->surface
,
1053 (const void *const*)destdata
,
1054 mpi
->stride
); // pitch
1055 CHECK_ST_ERROR("Error when calling vdp_video_surface_put_bits_y_cb_cr")
1057 if (mpi
->fields
& MP_IMGFIELD_ORDERED
)
1058 top_field_first
= !!(mpi
->fields
& MP_IMGFIELD_TOP_FIRST
);
1060 top_field_first
= 1;
1062 video_to_output_surface();
1066 static uint32_t get_image(mp_image_t
*mpi
)
1068 struct vdpau_render_state
*rndr
;
1070 // no dr for non-decoding for now
1071 if (!IMGFMT_IS_VDPAU(image_format
))
1073 if (mpi
->type
!= MP_IMGTYPE_NUMBERED
)
1076 rndr
= get_surface(mpi
->number
);
1078 mp_msg(MSGT_VO
, MSGL_ERR
, "[vdpau] no surfaces available in get_image\n");
1079 // TODO: this probably breaks things forever, provide a dummy buffer?
1082 mpi
->flags
|= MP_IMGFLAG_DIRECT
;
1083 mpi
->stride
[0] = mpi
->stride
[1] = mpi
->stride
[2] = 0;
1084 mpi
->planes
[0] = mpi
->planes
[1] = mpi
->planes
[2] = NULL
;
1085 // hack to get around a check and to avoid a special-case in vd_ffmpeg.c
1086 mpi
->planes
[0] = (void *)rndr
;
1087 mpi
->num_planes
= 1;
1092 static int query_format(uint32_t format
)
1094 int default_flags
= VFCAP_CSP_SUPPORTED
| VFCAP_CSP_SUPPORTED_BY_HW
| VFCAP_HWSCALE_UP
| VFCAP_HWSCALE_DOWN
| VFCAP_OSD
| VFCAP_EOSD
| VFCAP_EOSD_UNSCALED
| VFCAP_FLIP
;
1105 return default_flags
| VOCAP_NOSLICES
;
1106 case IMGFMT_VDPAU_MPEG1
:
1107 case IMGFMT_VDPAU_MPEG2
:
1108 case IMGFMT_VDPAU_H264
:
1109 case IMGFMT_VDPAU_WMV3
:
1110 case IMGFMT_VDPAU_VC1
:
1111 case IMGFMT_VDPAU_MPEG4
:
1112 if (create_vdp_decoder(format
, 48, 48, 2))
1113 return default_flags
;
1118 static void DestroyVdpauObjects(void)
1123 free_video_specific();
1125 vdp_st
= vdp_presentation_queue_destroy(vdp_flip_queue
);
1126 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_destroy")
1128 vdp_st
= vdp_presentation_queue_target_destroy(vdp_flip_target
);
1129 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_target_destroy")
1131 for (i
= 0; i
<= NUM_OUTPUT_SURFACES
; i
++) {
1132 vdp_st
= vdp_output_surface_destroy(output_surfaces
[i
]);
1133 output_surfaces
[i
] = VDP_INVALID_HANDLE
;
1134 CHECK_ST_WARNING("Error when calling vdp_output_surface_destroy")
1137 for (i
= 0; i
<eosd_surface_count
; i
++) {
1138 if (eosd_surfaces
[i
].surface
!= VDP_INVALID_HANDLE
) {
1139 vdp_st
= vdp_bitmap_surface_destroy(eosd_surfaces
[i
].surface
);
1140 CHECK_ST_WARNING("Error when calling vdp_bitmap_surface_destroy")
1142 eosd_surfaces
[i
].surface
= VDP_INVALID_HANDLE
;
1145 vdp_st
= vdp_device_destroy(vdp_device
);
1146 CHECK_ST_WARNING("Error when calling vdp_device_destroy")
1149 static void uninit(void)
1153 if (!vo_config_count
)
1157 for (i
= 0; i
< MAX_VIDEO_SURFACES
; i
++) {
1158 // Allocated in ff_vdpau_add_data_chunk()
1159 av_freep(&surface_render
[i
].bitstream_buffers
);
1160 surface_render
[i
].bitstream_buffers_allocated
= 0;
1163 /* Destroy all vdpau objects */
1164 DestroyVdpauObjects();
1169 free(eosd_surfaces
);
1170 eosd_surfaces
= NULL
;
1172 eosd_targets
= NULL
;
1174 #ifdef CONFIG_XF86VM
1180 static const opt_t subopts
[] = {
1181 {"deint", OPT_ARG_INT
, &deint
, (opt_test_f
)int_non_neg
},
1182 {"chroma-deint", OPT_ARG_BOOL
, &chroma_deint
, NULL
},
1183 {"pullup", OPT_ARG_BOOL
, &pullup
, NULL
},
1184 {"denoise", OPT_ARG_FLOAT
, &denoise
, NULL
},
1185 {"sharpen", OPT_ARG_FLOAT
, &sharpen
, NULL
},
1186 {"colorspace", OPT_ARG_INT
, &colorspace
, NULL
},
1187 {"force-mixer", OPT_ARG_BOOL
, &force_mixer
, NULL
},
1188 {"hqscaling", OPT_ARG_INT
, &hqscaling
, (opt_test_f
)int_non_neg
},
1192 static const char help_msg
[] =
1193 "\n-vo vdpau command line help:\n"
1194 "Example: mplayer -vo vdpau:deint=2\n"
1196 " deint (all modes > 0 respect -field-dominance)\n"
1197 " 0: no deinterlacing\n"
1198 " 1: only show first field\n"
1199 " 2: bob deinterlacing\n"
1200 " 3: temporal deinterlacing (resource-hungry)\n"
1201 " 4: temporal-spatial deinterlacing (very resource-hungry)\n"
1203 " Operate on luma and chroma when using temporal deinterlacing (default)\n"
1204 " Use nochroma-deint to speed up temporal deinterlacing\n"
1206 " Try to apply inverse-telecine (needs temporal deinterlacing)\n"
1208 " Apply denoising, argument is strength from 0.0 to 1.0\n"
1210 " Apply sharpening or softening, argument is strength from -1.0 to 1.0\n"
1212 " 0: guess based on video resolution\n"
1213 " 1: ITU-R BT.601 (default)\n"
1214 " 2: ITU-R BT.709\n"
1217 " 0: default VDPAU scaler\n"
1218 " 1-9: high quality VDPAU scaler (needs capable hardware)\n"
1220 " Use the VDPAU mixer (default)\n"
1221 " Use noforce-mixer to allow BGRA output (disables all above options)\n"
1224 static int preinit(const char *arg
)
1231 deint_mpi
[0] = deint_mpi
[1] = NULL
;
1239 if (subopt_parse(arg
, subopts
) != 0) {
1240 mp_msg(MSGT_VO
, MSGL_FATAL
, help_msg
);
1245 if (colorspace
< 0 || colorspace
> 3) {
1246 mp_msg(MSGT_VO
, MSGL_WARN
, "[vdpau] Invalid color space specified, "
1251 if (!vo_init() || win_x11_init_vdpau_procs())
1254 decoder
= VDP_INVALID_HANDLE
;
1255 for (i
= 0; i
< MAX_VIDEO_SURFACES
; i
++)
1256 surface_render
[i
].surface
= VDP_INVALID_HANDLE
;
1257 video_mixer
= VDP_INVALID_HANDLE
;
1258 for (i
= 0; i
<= NUM_OUTPUT_SURFACES
; i
++)
1259 output_surfaces
[i
] = VDP_INVALID_HANDLE
;
1260 vdp_flip_queue
= VDP_INVALID_HANDLE
;
1261 output_surface_width
= output_surface_height
= -1;
1263 // full grayscale palette.
1264 for (i
= 0; i
< PALETTE_SIZE
; ++i
)
1265 palette
[i
] = (i
<< 16) | (i
<< 8) | i
;
1267 index_data_size
= 0;
1269 eosd_surface_count
= eosd_render_count
= 0;
1270 eosd_surfaces
= NULL
;
1271 eosd_targets
= NULL
;
1273 procamp
.struct_version
= VDP_PROCAMP_VERSION
;
1274 procamp
.brightness
= 0.0;
1275 procamp
.contrast
= 1.0;
1276 procamp
.saturation
= 1.0;
1282 static int get_equalizer(char *name
, int *value
)
1284 if (!strcasecmp(name
, "brightness"))
1285 *value
= procamp
.brightness
* 100;
1286 else if (!strcasecmp(name
, "contrast"))
1287 *value
= (procamp
.contrast
-1.0) * 100;
1288 else if (!strcasecmp(name
, "saturation"))
1289 *value
= (procamp
.saturation
-1.0) * 100;
1290 else if (!strcasecmp(name
, "hue"))
1291 *value
= procamp
.hue
* 100 / M_PI
;
1297 static int set_equalizer(char *name
, int value
)
1299 if (!strcasecmp(name
, "brightness"))
1300 procamp
.brightness
= value
/ 100.0;
1301 else if (!strcasecmp(name
, "contrast"))
1302 procamp
.contrast
= value
/ 100.0 + 1.0;
1303 else if (!strcasecmp(name
, "saturation"))
1304 procamp
.saturation
= value
/ 100.0 + 1.0;
1305 else if (!strcasecmp(name
, "hue"))
1306 procamp
.hue
= value
/ 100.0 * M_PI
;
1310 return update_csc_matrix();
1313 static int control(uint32_t request
, void *data
, ...)
1315 if (handle_preemption() < 0)
1319 case VOCTRL_GET_DEINTERLACE
:
1320 *(int*)data
= deint
;
1322 case VOCTRL_SET_DEINTERLACE
:
1323 if (image_format
== IMGFMT_BGRA
)
1325 deint
= *(int*)data
;
1328 if (deint_type
> 2) {
1330 VdpVideoMixerFeature features
[1] =
1332 VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL
:
1333 VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL
};
1334 VdpBool feature_enables
[1] = {deint
? VDP_TRUE
: VDP_FALSE
};
1335 vdp_st
= vdp_video_mixer_set_feature_enables(video_mixer
, 1,
1338 CHECK_ST_WARNING("Error changing deinterlacing settings")
1342 return int_pause
= 1;
1344 return int_pause
= 0;
1345 case VOCTRL_QUERY_FORMAT
:
1346 return query_format(*(uint32_t *)data
);
1347 case VOCTRL_GET_IMAGE
:
1348 return get_image(data
);
1349 case VOCTRL_DRAW_IMAGE
:
1350 return draw_image(data
);
1351 case VOCTRL_GUISUPPORT
:
1357 case VOCTRL_FULLSCREEN
:
1358 vo_x11_fullscreen();
1361 case VOCTRL_GET_PANSCAN
:
1363 case VOCTRL_SET_PANSCAN
:
1366 case VOCTRL_SET_EQUALIZER
: {
1369 if (image_format
== IMGFMT_BGRA
)
1373 value
= va_arg(ap
, int);
1376 return set_equalizer(data
, value
);
1378 case VOCTRL_GET_EQUALIZER
: {
1383 value
= va_arg(ap
, int *);
1386 return get_equalizer(data
, value
);
1391 case VOCTRL_UPDATE_SCREENINFO
:
1392 update_xinerama_info();
1394 case VOCTRL_DRAW_EOSD
:
1397 generate_eosd(data
);
1400 case VOCTRL_GET_EOSD_RES
: {
1401 mp_eosd_res_t
*r
= data
;
1402 r
->mt
= r
->mb
= r
->ml
= r
->mr
= 0;
1403 r
->srcw
= vid_width
; r
->srch
= vid_height
;
1405 r
->w
= vo_screenwidth
;
1406 r
->h
= vo_screenheight
;
1407 r
->ml
= r
->mr
= border_x
;
1408 r
->mt
= r
->mb
= border_y
;