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.
40 #include "video_out.h"
41 #include "video_out_internal.h"
42 #include "x11_common.h"
45 #include "subopt-helper.h"
47 #include "libavcodec/vdpau.h"
49 #include "gui/interface.h"
51 #include "libavutil/common.h"
53 static vo_info_t info
= {
56 "Rajib Mahapatra <rmahapatra@nvidia.com> and others",
62 #define CHECK_ST_ERROR(message) \
63 if (vdp_st != VDP_STATUS_OK) { \
64 mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] %s: %s\n", \
65 message, vdp_get_error_string(vdp_st)); \
69 #define CHECK_ST_WARNING(message) \
70 if (vdp_st != VDP_STATUS_OK) \
71 mp_msg(MSGT_VO, MSGL_WARN, "[vdpau] %s: %s\n", \
72 message, vdp_get_error_string(vdp_st));
74 /* number of video and output surfaces */
75 #define NUM_OUTPUT_SURFACES 3
76 #define MAX_VIDEO_SURFACES 50
78 /* number of palette entries */
79 #define PALETTE_SIZE 256
82 * Global variable declaration - VDPAU specific
85 /* Declaration for all variables of win_x11_init_vdpau_procs() and
86 * win_x11_init_vdpau_flip_queue() functions
88 static VdpDevice vdp_device
;
89 static VdpDeviceCreateX11
*vdp_device_create
;
90 static VdpGetProcAddress
*vdp_get_proc_address
;
92 static VdpPresentationQueueTarget vdp_flip_target
;
93 static VdpPresentationQueue vdp_flip_queue
;
95 static VdpDeviceDestroy
*vdp_device_destroy
;
96 static VdpVideoSurfaceCreate
*vdp_video_surface_create
;
97 static VdpVideoSurfaceDestroy
*vdp_video_surface_destroy
;
99 static VdpGetErrorString
*vdp_get_error_string
;
101 /* May be used in software filtering/postprocessing options
102 * in MPlayer (./mplayer -vf ..) if we copy video_surface data to
105 static VdpVideoSurfacePutBitsYCbCr
*vdp_video_surface_put_bits_y_cb_cr
;
106 static VdpOutputSurfacePutBitsNative
*vdp_output_surface_put_bits_native
;
108 static VdpOutputSurfaceCreate
*vdp_output_surface_create
;
109 static VdpOutputSurfaceDestroy
*vdp_output_surface_destroy
;
111 /* VideoMixer puts video_surface data on displayable output_surface. */
112 static VdpVideoMixerCreate
*vdp_video_mixer_create
;
113 static VdpVideoMixerDestroy
*vdp_video_mixer_destroy
;
114 static VdpVideoMixerRender
*vdp_video_mixer_render
;
115 static VdpVideoMixerSetFeatureEnables
*vdp_video_mixer_set_feature_enables
;
116 static VdpVideoMixerSetAttributeValues
*vdp_video_mixer_set_attribute_values
;
118 static VdpPresentationQueueTargetDestroy
*vdp_presentation_queue_target_destroy
;
119 static VdpPresentationQueueCreate
*vdp_presentation_queue_create
;
120 static VdpPresentationQueueDestroy
*vdp_presentation_queue_destroy
;
121 static VdpPresentationQueueDisplay
*vdp_presentation_queue_display
;
122 static VdpPresentationQueueBlockUntilSurfaceIdle
*vdp_presentation_queue_block_until_surface_idle
;
123 static VdpPresentationQueueTargetCreateX11
*vdp_presentation_queue_target_create_x11
;
125 /* output_surfaces[2] is used in composite-picture. */
126 static VdpOutputSurfaceRenderOutputSurface
*vdp_output_surface_render_output_surface
;
127 static VdpOutputSurfacePutBitsIndexed
*vdp_output_surface_put_bits_indexed
;
129 static VdpDecoderCreate
*vdp_decoder_create
;
130 static VdpDecoderDestroy
*vdp_decoder_destroy
;
131 static VdpDecoderRender
*vdp_decoder_render
;
133 static void *vdpau_lib_handle
;
134 static VdpOutputSurface output_surfaces
[NUM_OUTPUT_SURFACES
];
135 static int output_surface_width
, output_surface_height
;
137 static VdpVideoMixer video_mixer
;
140 static float denoise
;
141 static float sharpen
;
143 static VdpDecoder decoder
;
144 static int decoder_max_refs
;
146 static VdpRect src_rect_vid
;
147 static VdpRect out_rect_vid
;
148 static int border_x
, border_y
;
150 static struct vdpau_render_state surface_render
[MAX_VIDEO_SURFACES
];
151 static int surface_num
;
152 static int vid_surface_num
;
153 static uint32_t vid_width
, vid_height
;
154 static uint32_t image_format
;
155 static const VdpChromaType vdp_chroma_type
= VDP_CHROMA_TYPE_420
;
158 static unsigned char *index_data
;
159 static int index_data_size
;
160 static uint32_t palette
[PALETTE_SIZE
];
165 static int visible_buf
;
166 static int int_pause
;
168 static void video_to_output_surface(void)
172 VdpOutputSurface output_surface
= output_surfaces
[surface_num
];
173 if (vid_surface_num
< 0)
176 vdp_st
= vdp_presentation_queue_block_until_surface_idle(vdp_flip_queue
,
179 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_block_until_surface_idle")
181 vdp_st
= vdp_video_mixer_render(video_mixer
, VDP_INVALID_HANDLE
, 0,
182 VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME
,
183 0, NULL
, surface_render
[vid_surface_num
].surface
, 0, NULL
, &src_rect_vid
,
185 NULL
, &out_rect_vid
, 0, NULL
);
186 CHECK_ST_WARNING("Error when calling vdp_video_mixer_render")
189 static void resize(void)
193 struct vo_rect src_rect
;
194 struct vo_rect dst_rect
;
195 struct vo_rect borders
;
196 calc_src_dst_rects(vid_width
, vid_height
, &src_rect
, &dst_rect
, &borders
, NULL
);
197 out_rect_vid
.x0
= dst_rect
.left
;
198 out_rect_vid
.x1
= dst_rect
.right
;
199 out_rect_vid
.y0
= dst_rect
.top
;
200 out_rect_vid
.y1
= dst_rect
.bottom
;
201 src_rect_vid
.x0
= src_rect
.left
;
202 src_rect_vid
.x1
= src_rect
.right
;
203 src_rect_vid
.y0
= src_rect
.top
;
204 src_rect_vid
.y1
= src_rect
.bottom
;
205 border_x
= borders
.left
;
206 border_y
= borders
.top
;
207 #ifdef CONFIG_FREETYPE
208 // adjust font size to display size
211 vo_osd_changed(OSDTYPE_OSD
);
213 if (output_surface_width
< vo_dwidth
|| output_surface_height
< vo_dheight
) {
214 if (output_surface_width
< vo_dwidth
) {
215 output_surface_width
+= output_surface_width
>> 1;
216 output_surface_width
= FFMAX(output_surface_width
, vo_dwidth
);
218 if (output_surface_height
< vo_dheight
) {
219 output_surface_height
+= output_surface_height
>> 1;
220 output_surface_height
= FFMAX(output_surface_height
, vo_dheight
);
222 // Creation of output_surfaces
223 for (i
= 0; i
< NUM_OUTPUT_SURFACES
; i
++) {
224 if (output_surfaces
[i
] != VDP_INVALID_HANDLE
)
225 vdp_output_surface_destroy(output_surfaces
[i
]);
226 vdp_st
= vdp_output_surface_create(vdp_device
, VDP_RGBA_FORMAT_B8G8R8A8
,
227 output_surface_width
, output_surface_height
,
228 &output_surfaces
[i
]);
229 CHECK_ST_WARNING("Error when calling vdp_output_surface_create")
230 mp_msg(MSGT_VO
, MSGL_DBG2
, "OUT CREATE: %u\n", output_surfaces
[i
]);
233 video_to_output_surface();
238 /* Initialize vdp_get_proc_address, called from preinit() */
239 static int win_x11_init_vdpau_procs(void)
243 struct vdp_function
{
248 const struct vdp_function
*dsc
;
250 static const struct vdp_function vdp_func
[] = {
251 {VDP_FUNC_ID_GET_ERROR_STRING
, &vdp_get_error_string
},
252 {VDP_FUNC_ID_DEVICE_DESTROY
, &vdp_device_destroy
},
253 {VDP_FUNC_ID_VIDEO_SURFACE_CREATE
, &vdp_video_surface_create
},
254 {VDP_FUNC_ID_VIDEO_SURFACE_DESTROY
, &vdp_video_surface_destroy
},
255 {VDP_FUNC_ID_VIDEO_SURFACE_PUT_BITS_Y_CB_CR
,
256 &vdp_video_surface_put_bits_y_cb_cr
},
257 {VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_NATIVE
,
258 &vdp_output_surface_put_bits_native
},
259 {VDP_FUNC_ID_OUTPUT_SURFACE_CREATE
, &vdp_output_surface_create
},
260 {VDP_FUNC_ID_OUTPUT_SURFACE_DESTROY
, &vdp_output_surface_destroy
},
261 {VDP_FUNC_ID_VIDEO_MIXER_CREATE
, &vdp_video_mixer_create
},
262 {VDP_FUNC_ID_VIDEO_MIXER_DESTROY
, &vdp_video_mixer_destroy
},
263 {VDP_FUNC_ID_VIDEO_MIXER_RENDER
, &vdp_video_mixer_render
},
264 {VDP_FUNC_ID_VIDEO_MIXER_SET_FEATURE_ENABLES
,
265 &vdp_video_mixer_set_feature_enables
},
266 {VDP_FUNC_ID_VIDEO_MIXER_SET_ATTRIBUTE_VALUES
,
267 &vdp_video_mixer_set_attribute_values
},
268 {VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_DESTROY
,
269 &vdp_presentation_queue_target_destroy
},
270 {VDP_FUNC_ID_PRESENTATION_QUEUE_CREATE
, &vdp_presentation_queue_create
},
271 {VDP_FUNC_ID_PRESENTATION_QUEUE_DESTROY
,
272 &vdp_presentation_queue_destroy
},
273 {VDP_FUNC_ID_PRESENTATION_QUEUE_DISPLAY
,
274 &vdp_presentation_queue_display
},
275 {VDP_FUNC_ID_PRESENTATION_QUEUE_BLOCK_UNTIL_SURFACE_IDLE
,
276 &vdp_presentation_queue_block_until_surface_idle
},
277 {VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_CREATE_X11
,
278 &vdp_presentation_queue_target_create_x11
},
279 {VDP_FUNC_ID_OUTPUT_SURFACE_RENDER_OUTPUT_SURFACE
,
280 &vdp_output_surface_render_output_surface
},
281 {VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_INDEXED
,
282 &vdp_output_surface_put_bits_indexed
},
283 {VDP_FUNC_ID_DECODER_CREATE
, &vdp_decoder_create
},
284 {VDP_FUNC_ID_DECODER_RENDER
, &vdp_decoder_render
},
285 {VDP_FUNC_ID_DECODER_DESTROY
, &vdp_decoder_destroy
},
289 vdp_st
= vdp_device_create(mDisplay
, mScreen
,
290 &vdp_device
, &vdp_get_proc_address
);
291 if (vdp_st
!= VDP_STATUS_OK
) {
292 mp_msg(MSGT_VO
, MSGL_ERR
, "[vdpau] Error when calling vdp_device_create_x11: %i\n", vdp_st
);
296 for (dsc
= vdp_func
; dsc
->pointer
; dsc
++) {
297 vdp_st
= vdp_get_proc_address(vdp_device
, dsc
->id
, dsc
->pointer
);
298 if (vdp_st
!= VDP_STATUS_OK
) {
299 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
) : "?");
306 /* Initialize vdpau_flip_queue, called from config() */
307 static int win_x11_init_vdpau_flip_queue(void)
311 vdp_st
= vdp_presentation_queue_target_create_x11(vdp_device
, vo_window
,
313 CHECK_ST_ERROR("Error when calling vdp_presentation_queue_target_create_x11")
315 vdp_st
= vdp_presentation_queue_create(vdp_device
, vdp_flip_target
,
317 CHECK_ST_ERROR("Error when calling vdp_presentation_queue_create")
322 static int create_vdp_mixer(VdpChromaType vdp_chroma_type
) {
323 #define VDP_NUM_MIXER_PARAMETER 3
324 #define MAX_NUM_FEATURES 5
327 int feature_count
= 0;
328 VdpVideoMixerFeature features
[MAX_NUM_FEATURES
];
329 VdpBool feature_enables
[MAX_NUM_FEATURES
];
330 static const denoise_attrib
[] = {VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL
};
331 const void * const denoise_value
[] = {&denoise
};
332 static const sharpen_attrib
[] = {VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL
};
333 const void * const sharpen_value
[] = {&sharpen
};
334 static const VdpVideoMixerParameter parameters
[VDP_NUM_MIXER_PARAMETER
] = {
335 VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH
,
336 VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT
,
337 VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE
339 const void *const parameter_values
[VDP_NUM_MIXER_PARAMETER
] = {
345 features
[feature_count
++] = VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL
;
347 features
[feature_count
++] = VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL
;
349 features
[feature_count
++] = VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE
;
351 features
[feature_count
++] = VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION
;
353 features
[feature_count
++] = VDP_VIDEO_MIXER_FEATURE_SHARPNESS
;
355 vdp_st
= vdp_video_mixer_create(vdp_device
, feature_count
, features
,
356 VDP_NUM_MIXER_PARAMETER
,
357 parameters
, parameter_values
,
359 CHECK_ST_ERROR("Error when calling vdp_video_mixer_create")
361 for (i
= 0; i
< feature_count
; i
++) feature_enables
[i
] = VDP_TRUE
;
363 vdp_video_mixer_set_feature_enables(video_mixer
, feature_count
, features
, feature_enables
);
365 vdp_video_mixer_set_attribute_values(video_mixer
, 1, denoise_attrib
, denoise_value
);
367 vdp_video_mixer_set_attribute_values(video_mixer
, 1, sharpen_attrib
, sharpen_value
);
372 // Free everything specific to a certain video file
373 static void free_video_specific(void) {
377 if (decoder
!= VDP_INVALID_HANDLE
)
378 vdp_decoder_destroy(decoder
);
379 decoder
= VDP_INVALID_HANDLE
;
380 decoder_max_refs
= -1;
382 for (i
= 0; i
< MAX_VIDEO_SURFACES
; i
++) {
383 if (surface_render
[i
].surface
!= VDP_INVALID_HANDLE
) {
384 vdp_st
= vdp_video_surface_destroy(surface_render
[i
].surface
);
385 CHECK_ST_WARNING("Error when calling vdp_video_surface_destroy")
387 surface_render
[i
].surface
= VDP_INVALID_HANDLE
;
390 if (video_mixer
!= VDP_INVALID_HANDLE
)
391 vdp_st
= vdp_video_mixer_destroy(video_mixer
);
392 CHECK_ST_WARNING("Error when calling vdp_video_mixer_destroy")
393 video_mixer
= VDP_INVALID_HANDLE
;
397 * connect to X server, create and map window, initialize all
398 * VDPAU objects, create different surfaces etc.
400 static int config(uint32_t width
, uint32_t height
, uint32_t d_width
,
401 uint32_t d_height
, uint32_t flags
, char *title
,
405 XSetWindowAttributes xswa
;
406 XWindowAttributes attribs
;
407 unsigned long xswamask
;
411 int vm
= flags
& VOFLAG_MODESWITCHING
;
414 image_format
= format
;
421 guiGetEvent(guiSetShVideo
, 0); // the GUI will set up / resize our window
430 XGetWindowAttributes(mDisplay
, DefaultRootWindow(mDisplay
), &attribs
);
431 depth
= attribs
.depth
;
432 if (depth
!= 15 && depth
!= 16 && depth
!= 24 && depth
!= 32)
434 XMatchVisualInfo(mDisplay
, mScreen
, depth
, TrueColor
, &vinfo
);
436 xswa
.background_pixel
= 0;
437 xswa
.border_pixel
= 0;
438 xswamask
= CWBackPixel
| CWBorderPixel
;
440 vo_x11_create_vo_window(&vinfo
, vo_dx
, vo_dy
, d_width
, d_height
,
441 flags
, CopyFromParent
, "vdpau", title
);
442 XChangeWindowAttributes(mDisplay
, vo_window
, xswamask
, &xswa
);
446 /* Grab the mouse pointer in our window */
448 XGrabPointer(mDisplay
, vo_window
, True
, 0,
449 GrabModeAsync
, GrabModeAsync
,
450 vo_window
, None
, CurrentTime
);
451 XSetInputFocus(mDisplay
, vo_window
, RevertToNone
, CurrentTime
);
456 if ((flags
& VOFLAG_FULLSCREEN
) && WinID
<= 0)
459 /* -----VDPAU related code here -------- */
461 free_video_specific();
463 if (vdp_flip_queue
== VDP_INVALID_HANDLE
&& win_x11_init_vdpau_flip_queue())
466 // video width and height
470 if (create_vdp_mixer(vdp_chroma_type
))
474 vid_surface_num
= -1;
480 static void check_events(void)
482 int e
= vo_x11_check_events(mDisplay
);
484 if (e
& VO_EVENT_RESIZE
)
487 if ((e
& VO_EVENT_EXPOSE
|| e
& VO_EVENT_RESIZE
) && int_pause
) {
488 /* did we already draw a buffer */
490 /* redraw the last visible buffer */
492 vdp_st
= vdp_presentation_queue_display(vdp_flip_queue
,
493 output_surfaces
[surface_num
],
494 vo_dwidth
, vo_dheight
,
496 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_display")
501 static void draw_osd_I8A8(int x0
,int y0
, int w
,int h
, unsigned char *src
,
502 unsigned char *srca
, int stride
)
504 VdpOutputSurface output_surface
= output_surfaces
[surface_num
];
508 int index_data_size_required
;
509 VdpRect output_indexed_rect_vid
;
510 VdpOutputSurfaceRenderBlendState blend_state
;
515 index_data_size_required
= 2*w
*h
;
516 if (index_data_size
< index_data_size_required
) {
517 index_data
= realloc(index_data
, index_data_size_required
);
518 index_data_size
= index_data_size_required
;
521 // index_data creation, component order - I, A, I, A, .....
522 for (i
= 0; i
< h
; i
++)
523 for (j
= 0; j
< w
; j
++) {
524 index_data
[i
*2*w
+ j
*2] = src
[i
*stride
+j
];
525 index_data
[i
*2*w
+ j
*2 + 1] = -srca
[i
*stride
+j
];
528 output_indexed_rect_vid
.x0
= x0
;
529 output_indexed_rect_vid
.y0
= y0
;
530 output_indexed_rect_vid
.x1
= x0
+ w
;
531 output_indexed_rect_vid
.y1
= y0
+ h
;
535 // write source_data to output_surfaces[2].
536 vdp_st
= vdp_output_surface_put_bits_indexed(output_surfaces
[2],
537 VDP_INDEXED_FORMAT_I8A8
,
538 (const void *const*)&index_data
,
540 &output_indexed_rect_vid
,
541 VDP_COLOR_TABLE_FORMAT_B8G8R8X8
,
543 CHECK_ST_WARNING("Error when calling vdp_output_surface_put_bits_indexed")
545 blend_state
.struct_version
= VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION
;
546 blend_state
.blend_factor_source_color
= VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE
;
547 blend_state
.blend_factor_source_alpha
= VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE
;
548 blend_state
.blend_factor_destination_color
= VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA
;
549 blend_state
.blend_factor_destination_alpha
= VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA
;
550 blend_state
.blend_equation_color
= VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD
;
551 blend_state
.blend_equation_alpha
= VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD
;
553 vdp_st
= vdp_output_surface_render_output_surface(output_surface
,
554 &output_indexed_rect_vid
,
556 &output_indexed_rect_vid
,
559 VDP_OUTPUT_SURFACE_RENDER_ROTATE_0
);
560 CHECK_ST_WARNING("Error when calling vdp_output_surface_render_output_surface")
563 static void draw_osd(void)
565 mp_msg(MSGT_VO
, MSGL_DBG2
, "DRAW_OSD\n");
567 vo_draw_text_ext(vo_dwidth
, vo_dheight
, border_x
, border_y
, border_x
, border_y
,
568 vid_width
, vid_height
, draw_osd_I8A8
);
571 static void flip_page(void)
574 mp_msg(MSGT_VO
, MSGL_DBG2
, "\nFLIP_PAGE VID:%u -> OUT:%u\n",
575 surface_render
[vid_surface_num
].surface
, output_surfaces
[surface_num
]);
577 vdp_st
= vdp_presentation_queue_display(vdp_flip_queue
, output_surfaces
[surface_num
],
578 vo_dwidth
, vo_dheight
,
580 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_display")
582 surface_num
= !surface_num
;
586 static int draw_slice(uint8_t *image
[], int stride
[], int w
, int h
,
590 struct vdpau_render_state
*rndr
= (struct vdpau_render_state
*)image
[0];
591 int max_refs
= image_format
== IMGFMT_VDPAU_H264
? rndr
->info
.h264
.num_ref_frames
: 2;
592 if (!IMGFMT_IS_VDPAU(image_format
))
594 if (decoder
== VDP_INVALID_HANDLE
|| decoder_max_refs
< max_refs
) {
595 VdpDecoderProfile vdp_decoder_profile
;
596 if (decoder
!= VDP_INVALID_HANDLE
)
597 vdp_decoder_destroy(decoder
);
598 decoder
= VDP_INVALID_HANDLE
;
599 switch (image_format
) {
600 case IMGFMT_VDPAU_MPEG1
:
601 vdp_decoder_profile
= VDP_DECODER_PROFILE_MPEG1
;
603 case IMGFMT_VDPAU_MPEG2
:
604 vdp_decoder_profile
= VDP_DECODER_PROFILE_MPEG2_MAIN
;
606 case IMGFMT_VDPAU_H264
:
607 vdp_decoder_profile
= VDP_DECODER_PROFILE_H264_HIGH
;
609 case IMGFMT_VDPAU_WMV3
:
610 vdp_decoder_profile
= VDP_DECODER_PROFILE_VC1_MAIN
;
612 case IMGFMT_VDPAU_VC1
:
613 vdp_decoder_profile
= VDP_DECODER_PROFILE_VC1_ADVANCED
;
616 vdp_st
= vdp_decoder_create(vdp_device
, vdp_decoder_profile
, vid_width
, vid_height
, max_refs
, &decoder
);
617 CHECK_ST_WARNING("Failed creating VDPAU decoder");
618 decoder_max_refs
= max_refs
;
620 vdp_st
= vdp_decoder_render(decoder
, rndr
->surface
, (void *)&rndr
->info
, rndr
->bitstream_buffers_used
, rndr
->bitstream_buffers
);
621 CHECK_ST_WARNING("Failed VDPAU decoder rendering");
626 static int draw_frame(uint8_t *src
[])
631 static struct vdpau_render_state
*get_surface(int number
)
633 if (number
> MAX_VIDEO_SURFACES
)
635 if (surface_render
[number
].surface
== VDP_INVALID_HANDLE
) {
637 vdp_st
= vdp_video_surface_create(vdp_device
, vdp_chroma_type
,
638 vid_width
, vid_height
,
639 &surface_render
[number
].surface
);
640 CHECK_ST_WARNING("Error when calling vdp_video_surface_create")
641 if (vdp_st
!= VDP_STATUS_OK
)
644 mp_msg(MSGT_VO
, MSGL_DBG2
, "VID CREATE: %u\n", surface_render
[number
].surface
);
645 return &surface_render
[number
];
648 static uint32_t draw_image(mp_image_t
*mpi
)
650 if (IMGFMT_IS_VDPAU(image_format
)) {
651 struct vdpau_render_state
*rndr
= mpi
->priv
;
652 vid_surface_num
= rndr
- surface_render
;
653 } else if (!(mpi
->flags
& MP_IMGFLAG_DRAW_CALLBACK
)) {
655 void *destdata
[3] = {mpi
->planes
[0], mpi
->planes
[2], mpi
->planes
[1]};
656 struct vdpau_render_state
*rndr
= get_surface(0);
657 vid_surface_num
= rndr
- surface_render
;
658 vdp_st
= vdp_video_surface_put_bits_y_cb_cr(rndr
->surface
,
659 VDP_YCBCR_FORMAT_YV12
,
660 (const void *const*)destdata
,
661 mpi
->stride
); // pitch
662 CHECK_ST_ERROR("Error when calling vdp_video_surface_put_bits_y_cb_cr")
665 video_to_output_surface();
669 static uint32_t get_image(mp_image_t
*mpi
)
671 struct vdpau_render_state
*rndr
;
673 // no dr for non-decoding for now
674 if (!IMGFMT_IS_VDPAU(image_format
)) return VO_FALSE
;
675 if (mpi
->type
!= MP_IMGTYPE_NUMBERED
) return VO_FALSE
;
677 rndr
= get_surface(mpi
->number
);
679 mp_msg(MSGT_VO
, MSGL_ERR
, "[vdpau] no surfaces available in get_image\n");
680 // TODO: this probably breaks things forever, provide a dummy buffer?
683 mpi
->flags
|= MP_IMGFLAG_DIRECT
;
684 mpi
->stride
[0] = mpi
->stride
[1] = mpi
->stride
[2] = 0;
685 mpi
->planes
[0] = mpi
->planes
[1] = mpi
->planes
[2] = NULL
;
686 // hack to get around a check and to avoid a special-case in vd_ffmpeg.c
687 mpi
->planes
[0] = (void *)rndr
;
693 static int query_format(uint32_t format
)
695 int default_flags
= VFCAP_CSP_SUPPORTED
| VFCAP_CSP_SUPPORTED_BY_HW
| VFCAP_HWSCALE_UP
| VFCAP_HWSCALE_DOWN
| VFCAP_OSD
;
698 return default_flags
| VOCAP_NOSLICES
;
699 case IMGFMT_VDPAU_MPEG1
:
700 case IMGFMT_VDPAU_MPEG2
:
701 case IMGFMT_VDPAU_H264
:
702 case IMGFMT_VDPAU_WMV3
:
703 case IMGFMT_VDPAU_VC1
:
704 return default_flags
;
709 static void DestroyVdpauObjects(void)
714 free_video_specific();
716 vdp_st
= vdp_presentation_queue_destroy(vdp_flip_queue
);
717 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_destroy")
719 vdp_st
= vdp_presentation_queue_target_destroy(vdp_flip_target
);
720 CHECK_ST_WARNING("Error when calling vdp_presentation_queue_target_destroy")
722 for (i
= 0; i
< NUM_OUTPUT_SURFACES
; i
++) {
723 vdp_st
= vdp_output_surface_destroy(output_surfaces
[i
]);
724 output_surfaces
[i
] = VDP_INVALID_HANDLE
;
725 CHECK_ST_WARNING("Error when calling vdp_output_surface_destroy")
728 vdp_st
= vdp_device_destroy(vdp_device
);
729 CHECK_ST_WARNING("Error when calling vdp_device_destroy")
732 static void uninit(void)
734 if (!vo_config_count
)
738 /* Destroy all vdpau objects */
739 DestroyVdpauObjects();
749 dlclose(vdpau_lib_handle
);
752 static opt_t subopts
[] = {
753 {"deint", OPT_ARG_INT
, &deint
, (opt_test_f
)int_non_neg
},
754 {"pullup", OPT_ARG_BOOL
, &pullup
, NULL
},
755 {"denoise", OPT_ARG_FLOAT
, &denoise
, NULL
},
756 {"sharpen", OPT_ARG_FLOAT
, &sharpen
, NULL
},
760 static const char help_msg
[] =
761 "\n-vo vdpau command line help:\n"
762 "Example: mplayer -vo vdpau:deint=2\n"
765 " 0: no deinterlacing\n"
766 " 1: temporal deinterlacing\n"
767 " 2: temporal-spatial deinterlacing\n"
769 " Try to apply inverse-telecine\n"
771 " Apply denoising, argument is strength from 0.0 to 1.0\n"
773 " Apply sharpening or softening, argument is strength from -1.0 to 1.0\n"
776 static int preinit(const char *arg
)
779 static const char *vdpaulibrary
= "libvdpau.so.1";
780 static const char *vdpau_device_create
= "vdp_device_create_x11";
786 if (subopt_parse(arg
, subopts
) != 0) {
787 mp_msg(MSGT_VO
, MSGL_FATAL
, help_msg
);
791 vdpau_lib_handle
= dlopen(vdpaulibrary
, RTLD_LAZY
);
792 if (!vdpau_lib_handle
) {
793 mp_msg(MSGT_VO
, MSGL_ERR
, "[vdpau] Could not open dynamic library %s\n",
797 vdp_device_create
= dlsym(vdpau_lib_handle
, vdpau_device_create
);
798 if (!vdp_device_create
) {
799 mp_msg(MSGT_VO
, MSGL_ERR
, "[vdpau] Could not find function %s in %s\n",
800 vdpau_device_create
, vdpaulibrary
);
803 if (!vo_init() || win_x11_init_vdpau_procs())
806 decoder
= VDP_INVALID_HANDLE
;
807 for (i
= 0; i
< MAX_VIDEO_SURFACES
; i
++)
808 surface_render
[i
].surface
= VDP_INVALID_HANDLE
;
809 video_mixer
= VDP_INVALID_HANDLE
;
810 for (i
= 0; i
< NUM_OUTPUT_SURFACES
; i
++)
811 output_surfaces
[i
] = VDP_INVALID_HANDLE
;
812 vdp_flip_queue
= VDP_INVALID_HANDLE
;
813 output_surface_width
= output_surface_height
= -1;
815 // full grayscale palette.
816 for (i
= 0; i
< PALETTE_SIZE
; ++i
)
817 palette
[i
] = (i
<< 16) | (i
<< 8) | i
;
824 static int control(uint32_t request
, void *data
, ...)
828 return (int_pause
= 1);
830 return (int_pause
= 0);
831 case VOCTRL_QUERY_FORMAT
:
832 return query_format(*(uint32_t *)data
);
833 case VOCTRL_GET_IMAGE
:
834 return get_image(data
);
835 case VOCTRL_DRAW_IMAGE
:
836 return draw_image(data
);
837 case VOCTRL_GUISUPPORT
:
843 case VOCTRL_FULLSCREEN
:
847 case VOCTRL_GET_PANSCAN
:
849 case VOCTRL_SET_PANSCAN
:
852 case VOCTRL_SET_EQUALIZER
: {
857 value
= va_arg(ap
, int);
860 return vo_x11_set_equalizer(data
, value
);
862 case VOCTRL_GET_EQUALIZER
: {
867 value
= va_arg(ap
, int *);
870 return vo_x11_get_equalizer(data
, value
);
875 case VOCTRL_UPDATE_SCREENINFO
:
876 update_xinerama_info();