From 7ef7333e5990e5714719d89fa5fdf890beb76e16 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Mon, 4 May 2009 03:01:51 +0300 Subject: [PATCH 01/12] vo_vdpau: Delete GUI stuff, include font_load.h for force_load_font font_load.h was previously included through gui/interface.h --- libvo/vo_vdpau.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/libvo/vo_vdpau.c b/libvo/vo_vdpau.c index e0a2c40de0..532ba67795 100644 --- a/libvo/vo_vdpau.c +++ b/libvo/vo_vdpau.c @@ -46,7 +46,7 @@ #include "libavcodec/vdpau.h" -#include "gui/interface.h" +#include "font_load.h" #include "libavutil/common.h" #include "libavutil/mathematics.h" @@ -555,11 +555,6 @@ static int config(uint32_t width, uint32_t height, uint32_t d_width, visible_buf = 0; -#ifdef CONFIG_GUI - if (use_gui) - guiGetEvent(guiSetShVideo, 0); // the GUI will set up / resize our window - else -#endif { #ifdef CONFIG_XF86VM if (vm) @@ -1196,8 +1191,6 @@ static int control(uint32_t request, void *data) return get_image(data); case VOCTRL_DRAW_IMAGE: return draw_image(data); - case VOCTRL_GUISUPPORT: - return VO_TRUE; case VOCTRL_BORDER: vo_x11_border(); resize(); From 09943048cbe71cb15742608400c595cf5d4d1c45 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Mon, 4 May 2009 03:09:50 +0300 Subject: [PATCH 02/12] vo_vdpau: Make compile as new-style VO --- libvo/vo_vdpau.c | 175 ++++++++++++++++++++++++++--------------------- 1 file changed, 97 insertions(+), 78 deletions(-) diff --git a/libvo/vo_vdpau.c b/libvo/vo_vdpau.c index 532ba67795..dee5c8adc4 100644 --- a/libvo/vo_vdpau.c +++ b/libvo/vo_vdpau.c @@ -37,12 +37,14 @@ #include "config.h" #include "mp_msg.h" +#include "options.h" #include "video_out.h" -#include "video_out_internal.h" #include "x11_common.h" #include "aspect.h" #include "sub.h" #include "subopt-helper.h" +#include "libmpcodecs/vfcap.h" +#include "libmpcodecs/mp_image.h" #include "libavcodec/vdpau.h" @@ -54,15 +56,6 @@ #include "libass/ass.h" #include "libass/ass_mp.h" -static vo_info_t info = { - "VDPAU with X11", - "vdpau", - "Rajib Mahapatra and others", - "" -}; - -LIBVO_EXTERN(vdpau) - #define CHECK_ST_ERROR(message) \ if (vdp_st != VDP_STATUS_OK) { \ mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] %s: %s\n", \ @@ -220,7 +213,9 @@ static void push_deint_surface(VdpVideoSurface surface) deint_surfaces[0] = surface; } -static void video_to_output_surface(void) +static void flip_page(struct vo *vo); +static void draw_osd(struct vo *vo, struct osd_state *osd); +static void video_to_output_surface(struct vo *vo) { VdpTime dummy; VdpStatus vdp_st; @@ -236,8 +231,8 @@ static void video_to_output_surface(void) VdpOutputSurface output_surface; if (i) { draw_eosd(); - draw_osd(); - flip_page(); + //draw_osd(vo, NULL); + flip_page(vo); } if (deint) field = (top_field_first == i) ^ (deint > 1) ? @@ -261,14 +256,15 @@ static void video_to_output_surface(void) } } -static void resize(void) +static void resize(struct vo *vo) { VdpStatus vdp_st; int i; struct vo_rect src_rect; struct vo_rect dst_rect; struct vo_rect borders; - calc_src_dst_rects(vid_width, vid_height, &src_rect, &dst_rect, &borders, NULL); + calc_src_dst_rects(vo, vid_width, vid_height, &src_rect, &dst_rect, + &borders, NULL); out_rect_vid.x0 = dst_rect.left; out_rect_vid.x1 = dst_rect.right; out_rect_vid.y0 = dst_rect.top; @@ -285,14 +281,14 @@ static void resize(void) #endif vo_osd_changed(OSDTYPE_OSD); - if (output_surface_width < vo_dwidth || output_surface_height < vo_dheight) { - if (output_surface_width < vo_dwidth) { + if (output_surface_width < vo->dwidth || output_surface_height < vo->dheight) { + if (output_surface_width < vo->dwidth) { output_surface_width += output_surface_width >> 1; - output_surface_width = FFMAX(output_surface_width, vo_dwidth); + output_surface_width = FFMAX(output_surface_width, vo->dwidth); } - if (output_surface_height < vo_dheight) { + if (output_surface_height < vo->dheight) { output_surface_height += output_surface_height >> 1; - output_surface_height = FFMAX(output_surface_height, vo_dheight); + output_surface_height = FFMAX(output_surface_height, vo->dheight); } // Creation of output_surfaces for (i = 0; i <= NUM_OUTPUT_SURFACES; i++) { @@ -305,14 +301,15 @@ static void resize(void) mp_msg(MSGT_VO, MSGL_DBG2, "OUT CREATE: %u\n", output_surfaces[i]); } } - video_to_output_surface(); + video_to_output_surface(vo); if (visible_buf) - flip_page(); + flip_page(vo); } /* Initialize vdp_get_proc_address, called from preinit() */ -static int win_x11_init_vdpau_procs(void) +static int win_x11_init_vdpau_procs(struct vo *vo) { + struct vo_x11_state *x11 = vo->x11; VdpStatus vdp_st; struct vdp_function { @@ -368,7 +365,7 @@ static int win_x11_init_vdpau_procs(void) {0, NULL} }; - vdp_st = vdp_device_create(mDisplay, mScreen, + vdp_st = vdp_device_create(x11->display, x11->screen, &vdp_device, &vdp_get_proc_address); if (vdp_st != VDP_STATUS_OK) { mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Error when calling vdp_device_create_x11: %i\n", vdp_st); @@ -387,11 +384,12 @@ static int win_x11_init_vdpau_procs(void) } /* Initialize vdpau_flip_queue, called from config() */ -static int win_x11_init_vdpau_flip_queue(void) +static int win_x11_init_vdpau_flip_queue(struct vo *vo) { + struct vo_x11_state *x11 = vo->x11; VdpStatus vdp_st; - vdp_st = vdp_presentation_queue_target_create_x11(vdp_device, vo_window, + vdp_st = vdp_presentation_queue_target_create_x11(vdp_device, x11->window, &vdp_flip_target); CHECK_ST_ERROR("Error when calling vdp_presentation_queue_target_create_x11") @@ -532,10 +530,11 @@ static int create_vdp_decoder(int max_refs) * connect to X server, create and map window, initialize all * VDPAU objects, create different surfaces etc. */ -static int config(uint32_t width, uint32_t height, uint32_t d_width, - uint32_t d_height, uint32_t flags, char *title, - uint32_t format) +static int config(struct vo *vo, uint32_t width, uint32_t height, + uint32_t d_width, uint32_t d_height, uint32_t flags, + char *title, uint32_t format) { + struct vo_x11_state *x11 = vo->x11; XVisualInfo vinfo; XSetWindowAttributes xswa; XWindowAttributes attribs; @@ -558,14 +557,15 @@ static int config(uint32_t width, uint32_t height, uint32_t d_width, { #ifdef CONFIG_XF86VM if (vm) - vo_vm_switch(); + vo_vm_switch(vo); else #endif - XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &attribs); + XGetWindowAttributes(x11->display, DefaultRootWindow(x11->display), + &attribs); depth = attribs.depth; if (depth != 15 && depth != 16 && depth != 24 && depth != 32) depth = 24; - XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo); + XMatchVisualInfo(x11->display, x11->screen, depth, TrueColor, &vinfo); xswa.background_pixel = 0; xswa.border_pixel = 0; @@ -573,18 +573,18 @@ static int config(uint32_t width, uint32_t height, uint32_t d_width, aspect ratio changes. */ xswamask = CWBorderPixel; - vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, d_width, d_height, + vo_x11_create_vo_window(vo, &vinfo, vo->dx, vo->dy, d_width, d_height, flags, CopyFromParent, "vdpau", title); - XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa); + XChangeWindowAttributes(x11->display, x11->window, xswamask, &xswa); #ifdef CONFIG_XF86VM if (vm) { /* Grab the mouse pointer in our window */ if (vo_grabpointer) - XGrabPointer(mDisplay, vo_window, True, 0, + XGrabPointer(x11->display, x11->window, True, 0, GrabModeAsync, GrabModeAsync, - vo_window, None, CurrentTime); - XSetInputFocus(mDisplay, vo_window, RevertToNone, CurrentTime); + x11->window, None, CurrentTime); + XSetInputFocus(x11->display, x11->window, RevertToNone, CurrentTime); } #endif } @@ -593,7 +593,8 @@ static int config(uint32_t width, uint32_t height, uint32_t d_width, vo_fs = 1; /* -----VDPAU related code here -------- */ - if (vdp_flip_queue == VDP_INVALID_HANDLE && win_x11_init_vdpau_flip_queue()) + if (vdp_flip_queue == VDP_INVALID_HANDLE + && win_x11_init_vdpau_flip_queue(vo)) return -1; vdp_chroma_type = VDP_CHROMA_TYPE_420; @@ -619,17 +620,17 @@ static int config(uint32_t width, uint32_t height, uint32_t d_width, surface_num = 0; vid_surface_num = -1; - resize(); + resize(vo); return 0; } -static void check_events(void) +static void check_events(struct vo *vo) { - int e = vo_x11_check_events(mDisplay); + int e = vo_x11_check_events(vo); if (e & VO_EVENT_RESIZE) - resize(); + resize(vo); if ((e & VO_EVENT_EXPOSE || e & VO_EVENT_RESIZE) && int_pause) { /* did we already draw a buffer */ @@ -638,15 +639,15 @@ static void check_events(void) VdpStatus vdp_st; vdp_st = vdp_presentation_queue_display(vdp_flip_queue, output_surfaces[surface_num], - vo_dwidth, vo_dheight, + vo->dwidth, vo->dheight, 0); CHECK_ST_WARNING("Error when calling vdp_presentation_queue_display") } } } -static void draw_osd_I8A8(int x0,int y0, int w,int h, unsigned char *src, - unsigned char *srca, int stride) +static void draw_osd_I8A8(void *ctx, int x0, int y0, int w, int h, + unsigned char *src, unsigned char *srca, int stride) { VdpOutputSurface output_surface = output_surfaces[surface_num]; VdpStatus vdp_st; @@ -821,22 +822,23 @@ eosd_skip_upload: } } -static void draw_osd(void) +static void draw_osd(struct vo *vo, struct osd_state *osd) { mp_msg(MSGT_VO, MSGL_DBG2, "DRAW_OSD\n"); - vo_draw_text_ext(vo_dwidth, vo_dheight, border_x, border_y, border_x, border_y, - vid_width, vid_height, draw_osd_I8A8); + osd_draw_text_ext(osd, vo->dwidth, vo->dheight, border_x, border_y, + border_x, border_y, vid_width, vid_height, + draw_osd_I8A8, vo); } -static void flip_page(void) +static void flip_page(struct vo *vo) { VdpStatus vdp_st; mp_msg(MSGT_VO, MSGL_DBG2, "\nFLIP_PAGE VID:%u -> OUT:%u\n", surface_render[vid_surface_num].surface, output_surfaces[surface_num]); vdp_st = vdp_presentation_queue_display(vdp_flip_queue, output_surfaces[surface_num], - vo_dwidth, vo_dheight, + vo->dwidth, vo->dheight, 0); CHECK_ST_WARNING("Error when calling vdp_presentation_queue_display") @@ -844,8 +846,8 @@ static void flip_page(void) visible_buf = 1; } -static int draw_slice(uint8_t *image[], int stride[], int w, int h, - int x, int y) +static int draw_slice(struct vo *vo, uint8_t *image[], int stride[], int w, + int h, int x, int y) { VdpStatus vdp_st; struct vdpau_render_state *rndr = (struct vdpau_render_state *)image[0]; @@ -862,7 +864,7 @@ static int draw_slice(uint8_t *image[], int stride[], int w, int h, } -static int draw_frame(uint8_t *src[]) +static int draw_frame(struct vo *vo, uint8_t *src[]) { return VO_ERROR; } @@ -884,7 +886,7 @@ static struct vdpau_render_state *get_surface(int number) return &surface_render[number]; } -static uint32_t draw_image(mp_image_t *mpi) +static uint32_t draw_image(struct vo *vo, mp_image_t *mpi) { if (IMGFMT_IS_VDPAU(image_format)) { struct vdpau_render_state *rndr = mpi->priv; @@ -915,7 +917,7 @@ static uint32_t draw_image(mp_image_t *mpi) else top_field_first = 1; - video_to_output_surface(); + video_to_output_surface(vo); return VO_TRUE; } @@ -995,9 +997,9 @@ static void DestroyVdpauObjects(void) CHECK_ST_WARNING("Error when calling vdp_device_destroy") } -static void uninit(void) +static void uninit(struct vo *vo) { - if (!vo_config_count) + if (!vo->config_count) return; visible_buf = 0; @@ -1013,9 +1015,9 @@ static void uninit(void) eosd_targets = NULL; #ifdef CONFIG_XF86VM - vo_vm_close(); + vo_vm_close(vo); #endif - vo_x11_uninit(); + vo_x11_uninit(vo); dlclose(vdpau_lib_handle); } @@ -1050,7 +1052,7 @@ static const char help_msg[] = " Apply sharpening or softening, argument is strength from -1.0 to 1.0\n" ; -static int preinit(const char *arg) +static int preinit(struct vo *vo, const char *arg) { int i; static const char *vdpaulibrary = "libvdpau.so.1"; @@ -1086,7 +1088,7 @@ static int preinit(const char *arg) vdpau_device_create, vdpaulibrary); return -1; } - if (!vo_init() || win_x11_init_vdpau_procs()) + if (!vo_init(vo) || win_x11_init_vdpau_procs(vo)) return -1; decoder = VDP_INVALID_HANDLE; @@ -1117,7 +1119,7 @@ static int preinit(const char *arg) return 0; } -static int get_equalizer(char *name, int *value) { +static int get_equalizer(const char *name, int *value) { if (!strcasecmp(name, "brightness")) *value = procamp.brightness * 100; else if (!strcasecmp(name, "contrast")) @@ -1131,7 +1133,7 @@ static int get_equalizer(char *name, int *value) { return VO_TRUE; } -static int set_equalizer(char *name, int value) { +static int set_equalizer(const char *name, int value) { VdpStatus vdp_st; VdpCSCMatrix matrix; static const VdpVideoMixerAttribute attributes[] = {VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX}; @@ -1157,7 +1159,7 @@ static int set_equalizer(char *name, int value) { return VO_TRUE; } -static int control(uint32_t request, void *data) +static int control(struct vo *vo, uint32_t request, void *data) { switch (request) { case VOCTRL_GET_DEINTERLACE: @@ -1190,19 +1192,19 @@ static int control(uint32_t request, void *data) case VOCTRL_GET_IMAGE: return get_image(data); case VOCTRL_DRAW_IMAGE: - return draw_image(data); + return draw_image(vo, data); case VOCTRL_BORDER: - vo_x11_border(); - resize(); - return VO_TRUE; + vo_x11_border(vo); + resize(vo); + return VO_TRUE; case VOCTRL_FULLSCREEN: - vo_x11_fullscreen(); - resize(); + vo_x11_fullscreen(vo); + resize(vo); return VO_TRUE; case VOCTRL_GET_PANSCAN: return VO_TRUE; case VOCTRL_SET_PANSCAN: - resize(); + resize(vo); return VO_TRUE; case VOCTRL_SET_EQUALIZER: { struct voctrl_set_equalizer_args *args = data; @@ -1214,10 +1216,10 @@ static int control(uint32_t request, void *data) return get_equalizer(args->name, args->valueptr); } case VOCTRL_ONTOP: - vo_x11_ontop(); + vo_x11_ontop(vo); return VO_TRUE; case VOCTRL_UPDATE_SCREENINFO: - update_xinerama_info(); + update_xinerama_info(vo); return VO_TRUE; case VOCTRL_DRAW_EOSD: if (!data) @@ -1229,13 +1231,13 @@ static int control(uint32_t request, void *data) mp_eosd_res_t *r = data; r->mt = r->mb = r->ml = r->mr = 0; if (vo_fs) { - r->w = vo_screenwidth; - r->h = vo_screenheight; + r->w = vo->opts->vo_screenwidth; + r->h = vo->opts->vo_screenheight; r->ml = r->mr = border_x; r->mt = r->mb = border_y; } else { - r->w = vo_dwidth; - r->h = vo_dheight; + r->w = vo->dwidth; + r->h = vo->dheight; } return VO_TRUE; } @@ -1243,4 +1245,21 @@ static int control(uint32_t request, void *data) return VO_NOTIMPL; } -/* @} */ +const struct vo_driver video_out_vdpau = { + .is_new = 1, + .info = &(struct vo_info_s){ + "VDPAU with X11", + "vdpau", + "Rajib Mahapatra and others", + "" + }, + .preinit = preinit, + .config = config, + .control = control, + .draw_frame = draw_frame, + .draw_slice = draw_slice, + .draw_osd = draw_osd, + .flip_page = flip_page, + .check_events = check_events, + .uninit = uninit, +}; From dc44507f2ad9d6301557d32d41a87cee6e6ae934 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Wed, 6 May 2009 00:17:21 +0300 Subject: [PATCH 03/12] vo_vdpau: Add template file for VDPAU functions Add a template file that contains a single listing of various information needed about the VDPAU interface functions, and is then included multiple times to create required declarations and tables. Previously some of the information needed to be duplicated for each of those uses. --- TOOLS/vdpau_functions.py | 56 ++++++++++++++++++++++++ libvo/vdpau_template.c | 37 ++++++++++++++++ libvo/vo_vdpau.c | 93 +++------------------------------------- 3 files changed, 100 insertions(+), 86 deletions(-) create mode 100644 TOOLS/vdpau_functions.py create mode 100644 libvo/vdpau_template.c diff --git a/TOOLS/vdpau_functions.py b/TOOLS/vdpau_functions.py new file mode 100644 index 0000000000..386d70ab33 --- /dev/null +++ b/TOOLS/vdpau_functions.py @@ -0,0 +1,56 @@ +# Generate vdpau_template.c + +functions = """ +# get_error_string should be first, because the function lookup loop should +# have it available to print errors for other functions +get_error_string + +bitmap_surface_create +bitmap_surface_destroy +bitmap_surface_put_bits_native +decoder_create +decoder_destroy +decoder_render +device_destroy +generate_csc_matrix GenerateCSCMatrix # CSC completely capitalized +output_surface_create +output_surface_destroy +output_surface_put_bits_indexed +output_surface_put_bits_native +output_surface_render_bitmap_surface +output_surface_render_output_surface +presentation_queue_block_until_surface_idle +presentation_queue_create +presentation_queue_destroy +presentation_queue_display +presentation_queue_target_create_x11 +presentation_queue_target_destroy +video_mixer_create +video_mixer_destroy +video_mixer_render +video_mixer_set_attribute_values +video_mixer_set_feature_enables +video_surface_create +video_surface_destroy +video_surface_put_bits_y_cb_cr +""" + +print(""" +/* List the VDPAU functions used by MPlayer. + * Generated by vdpau_functions.py. + * First argument on each line is the VDPAU function type name, + * second macro name needed to get function address, + * third name MPlayer uses for the function. + */ +""") +for line in functions.splitlines(): + parts = line.split('#')[0].strip().split() + if not parts: + continue # empty/comment line + if len(parts) > 1: + mp_name, vdpau_name = parts + else: + mp_name = parts[0] + vdpau_name = ''.join(part.capitalize() for part in mp_name.split('_')) + macro_name = mp_name.upper() + print('VDP_FUNCTION(Vdp%s, VDP_FUNC_ID_%s, %s)' % (vdpau_name, macro_name, mp_name)) diff --git a/libvo/vdpau_template.c b/libvo/vdpau_template.c new file mode 100644 index 0000000000..82660b9bb5 --- /dev/null +++ b/libvo/vdpau_template.c @@ -0,0 +1,37 @@ + +/* List the VDPAU functions used by MPlayer. + * Generated by vdpau_functions.py. + * First argument on each line is the VDPAU function type name, + * second macro name needed to get function address, + * third name MPlayer uses for the function. + */ + +VDP_FUNCTION(VdpGetErrorString, VDP_FUNC_ID_GET_ERROR_STRING, get_error_string) +VDP_FUNCTION(VdpBitmapSurfaceCreate, VDP_FUNC_ID_BITMAP_SURFACE_CREATE, bitmap_surface_create) +VDP_FUNCTION(VdpBitmapSurfaceDestroy, VDP_FUNC_ID_BITMAP_SURFACE_DESTROY, bitmap_surface_destroy) +VDP_FUNCTION(VdpBitmapSurfacePutBitsNative, VDP_FUNC_ID_BITMAP_SURFACE_PUT_BITS_NATIVE, bitmap_surface_put_bits_native) +VDP_FUNCTION(VdpDecoderCreate, VDP_FUNC_ID_DECODER_CREATE, decoder_create) +VDP_FUNCTION(VdpDecoderDestroy, VDP_FUNC_ID_DECODER_DESTROY, decoder_destroy) +VDP_FUNCTION(VdpDecoderRender, VDP_FUNC_ID_DECODER_RENDER, decoder_render) +VDP_FUNCTION(VdpDeviceDestroy, VDP_FUNC_ID_DEVICE_DESTROY, device_destroy) +VDP_FUNCTION(VdpGenerateCSCMatrix, VDP_FUNC_ID_GENERATE_CSC_MATRIX, generate_csc_matrix) +VDP_FUNCTION(VdpOutputSurfaceCreate, VDP_FUNC_ID_OUTPUT_SURFACE_CREATE, output_surface_create) +VDP_FUNCTION(VdpOutputSurfaceDestroy, VDP_FUNC_ID_OUTPUT_SURFACE_DESTROY, output_surface_destroy) +VDP_FUNCTION(VdpOutputSurfacePutBitsIndexed, VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_INDEXED, output_surface_put_bits_indexed) +VDP_FUNCTION(VdpOutputSurfacePutBitsNative, VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_NATIVE, output_surface_put_bits_native) +VDP_FUNCTION(VdpOutputSurfaceRenderBitmapSurface, VDP_FUNC_ID_OUTPUT_SURFACE_RENDER_BITMAP_SURFACE, output_surface_render_bitmap_surface) +VDP_FUNCTION(VdpOutputSurfaceRenderOutputSurface, VDP_FUNC_ID_OUTPUT_SURFACE_RENDER_OUTPUT_SURFACE, output_surface_render_output_surface) +VDP_FUNCTION(VdpPresentationQueueBlockUntilSurfaceIdle, VDP_FUNC_ID_PRESENTATION_QUEUE_BLOCK_UNTIL_SURFACE_IDLE, presentation_queue_block_until_surface_idle) +VDP_FUNCTION(VdpPresentationQueueCreate, VDP_FUNC_ID_PRESENTATION_QUEUE_CREATE, presentation_queue_create) +VDP_FUNCTION(VdpPresentationQueueDestroy, VDP_FUNC_ID_PRESENTATION_QUEUE_DESTROY, presentation_queue_destroy) +VDP_FUNCTION(VdpPresentationQueueDisplay, VDP_FUNC_ID_PRESENTATION_QUEUE_DISPLAY, presentation_queue_display) +VDP_FUNCTION(VdpPresentationQueueTargetCreateX11, VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_CREATE_X11, presentation_queue_target_create_x11) +VDP_FUNCTION(VdpPresentationQueueTargetDestroy, VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_DESTROY, presentation_queue_target_destroy) +VDP_FUNCTION(VdpVideoMixerCreate, VDP_FUNC_ID_VIDEO_MIXER_CREATE, video_mixer_create) +VDP_FUNCTION(VdpVideoMixerDestroy, VDP_FUNC_ID_VIDEO_MIXER_DESTROY, video_mixer_destroy) +VDP_FUNCTION(VdpVideoMixerRender, VDP_FUNC_ID_VIDEO_MIXER_RENDER, video_mixer_render) +VDP_FUNCTION(VdpVideoMixerSetAttributeValues, VDP_FUNC_ID_VIDEO_MIXER_SET_ATTRIBUTE_VALUES, video_mixer_set_attribute_values) +VDP_FUNCTION(VdpVideoMixerSetFeatureEnables, VDP_FUNC_ID_VIDEO_MIXER_SET_FEATURE_ENABLES, video_mixer_set_feature_enables) +VDP_FUNCTION(VdpVideoSurfaceCreate, VDP_FUNC_ID_VIDEO_SURFACE_CREATE, video_surface_create) +VDP_FUNCTION(VdpVideoSurfaceDestroy, VDP_FUNC_ID_VIDEO_SURFACE_DESTROY, video_surface_destroy) +VDP_FUNCTION(VdpVideoSurfacePutBitsYCbCr, VDP_FUNC_ID_VIDEO_SURFACE_PUT_BITS_Y_CB_CR, video_surface_put_bits_y_cb_cr) diff --git a/libvo/vo_vdpau.c b/libvo/vo_vdpau.c index dee5c8adc4..5e1c6a937c 100644 --- a/libvo/vo_vdpau.c +++ b/libvo/vo_vdpau.c @@ -92,49 +92,9 @@ static VdpGetProcAddress *vdp_get_proc_address; static VdpPresentationQueueTarget vdp_flip_target; static VdpPresentationQueue vdp_flip_queue; -static VdpDeviceDestroy *vdp_device_destroy; -static VdpVideoSurfaceCreate *vdp_video_surface_create; -static VdpVideoSurfaceDestroy *vdp_video_surface_destroy; - -static VdpGetErrorString *vdp_get_error_string; - -/* May be used in software filtering/postprocessing options - * in MPlayer (./mplayer -vf ..) if we copy video_surface data to - * system memory. - */ -static VdpVideoSurfacePutBitsYCbCr *vdp_video_surface_put_bits_y_cb_cr; -static VdpOutputSurfacePutBitsNative *vdp_output_surface_put_bits_native; - -static VdpOutputSurfaceCreate *vdp_output_surface_create; -static VdpOutputSurfaceDestroy *vdp_output_surface_destroy; - -/* VideoMixer puts video_surface data on displayable output_surface. */ -static VdpVideoMixerCreate *vdp_video_mixer_create; -static VdpVideoMixerDestroy *vdp_video_mixer_destroy; -static VdpVideoMixerRender *vdp_video_mixer_render; -static VdpVideoMixerSetFeatureEnables *vdp_video_mixer_set_feature_enables; -static VdpVideoMixerSetAttributeValues *vdp_video_mixer_set_attribute_values; - -static VdpPresentationQueueTargetDestroy *vdp_presentation_queue_target_destroy; -static VdpPresentationQueueCreate *vdp_presentation_queue_create; -static VdpPresentationQueueDestroy *vdp_presentation_queue_destroy; -static VdpPresentationQueueDisplay *vdp_presentation_queue_display; -static VdpPresentationQueueBlockUntilSurfaceIdle *vdp_presentation_queue_block_until_surface_idle; -static VdpPresentationQueueTargetCreateX11 *vdp_presentation_queue_target_create_x11; - -static VdpOutputSurfaceRenderOutputSurface *vdp_output_surface_render_output_surface; -static VdpOutputSurfacePutBitsIndexed *vdp_output_surface_put_bits_indexed; -static VdpOutputSurfaceRenderBitmapSurface *vdp_output_surface_render_bitmap_surface; - -static VdpBitmapSurfaceCreate *vdp_bitmap_surface_create; -static VdpBitmapSurfaceDestroy *vdp_bitmap_surface_destroy; -static VdpBitmapSurfacePutBitsNative *vdp_bitmap_surface_putbits_native; - -static VdpDecoderCreate *vdp_decoder_create; -static VdpDecoderDestroy *vdp_decoder_destroy; -static VdpDecoderRender *vdp_decoder_render; - -static VdpGenerateCSCMatrix *vdp_generate_csc_matrix; +#define VDP_FUNCTION(vdp_type, _, mp_name) static vdp_type *vdp_##mp_name; +#include "vdpau_template.c" +#undef VDP_FUNCTION static void *vdpau_lib_handle; /* output_surfaces[NUM_OUTPUT_SURFACES] is misused for OSD. */ @@ -320,48 +280,9 @@ static int win_x11_init_vdpau_procs(struct vo *vo) const struct vdp_function *dsc; static const struct vdp_function vdp_func[] = { - {VDP_FUNC_ID_GET_ERROR_STRING, &vdp_get_error_string}, - {VDP_FUNC_ID_DEVICE_DESTROY, &vdp_device_destroy}, - {VDP_FUNC_ID_VIDEO_SURFACE_CREATE, &vdp_video_surface_create}, - {VDP_FUNC_ID_VIDEO_SURFACE_DESTROY, &vdp_video_surface_destroy}, - {VDP_FUNC_ID_VIDEO_SURFACE_PUT_BITS_Y_CB_CR, - &vdp_video_surface_put_bits_y_cb_cr}, - {VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_NATIVE, - &vdp_output_surface_put_bits_native}, - {VDP_FUNC_ID_OUTPUT_SURFACE_CREATE, &vdp_output_surface_create}, - {VDP_FUNC_ID_OUTPUT_SURFACE_DESTROY, &vdp_output_surface_destroy}, - {VDP_FUNC_ID_VIDEO_MIXER_CREATE, &vdp_video_mixer_create}, - {VDP_FUNC_ID_VIDEO_MIXER_DESTROY, &vdp_video_mixer_destroy}, - {VDP_FUNC_ID_VIDEO_MIXER_RENDER, &vdp_video_mixer_render}, - {VDP_FUNC_ID_VIDEO_MIXER_SET_FEATURE_ENABLES, - &vdp_video_mixer_set_feature_enables}, - {VDP_FUNC_ID_VIDEO_MIXER_SET_ATTRIBUTE_VALUES, - &vdp_video_mixer_set_attribute_values}, - {VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_DESTROY, - &vdp_presentation_queue_target_destroy}, - {VDP_FUNC_ID_PRESENTATION_QUEUE_CREATE, &vdp_presentation_queue_create}, - {VDP_FUNC_ID_PRESENTATION_QUEUE_DESTROY, - &vdp_presentation_queue_destroy}, - {VDP_FUNC_ID_PRESENTATION_QUEUE_DISPLAY, - &vdp_presentation_queue_display}, - {VDP_FUNC_ID_PRESENTATION_QUEUE_BLOCK_UNTIL_SURFACE_IDLE, - &vdp_presentation_queue_block_until_surface_idle}, - {VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_CREATE_X11, - &vdp_presentation_queue_target_create_x11}, - {VDP_FUNC_ID_OUTPUT_SURFACE_RENDER_OUTPUT_SURFACE, - &vdp_output_surface_render_output_surface}, - {VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_INDEXED, - &vdp_output_surface_put_bits_indexed}, - {VDP_FUNC_ID_DECODER_CREATE, &vdp_decoder_create}, - {VDP_FUNC_ID_DECODER_RENDER, &vdp_decoder_render}, - {VDP_FUNC_ID_DECODER_DESTROY, &vdp_decoder_destroy}, - {VDP_FUNC_ID_BITMAP_SURFACE_CREATE, &vdp_bitmap_surface_create}, - {VDP_FUNC_ID_BITMAP_SURFACE_DESTROY, &vdp_bitmap_surface_destroy}, - {VDP_FUNC_ID_BITMAP_SURFACE_PUT_BITS_NATIVE, - &vdp_bitmap_surface_putbits_native}, - {VDP_FUNC_ID_OUTPUT_SURFACE_RENDER_BITMAP_SURFACE, - &vdp_output_surface_render_bitmap_surface}, - {VDP_FUNC_ID_GENERATE_CSC_MATRIX, &vdp_generate_csc_matrix}, +#define VDP_FUNCTION(_, macro_name, mp_name) {macro_name, &vdp_##mp_name}, +#include "vdpau_template.c" +#undef VDP_FUNCTION {0, NULL} }; @@ -796,7 +717,7 @@ static void generate_eosd(mp_eosd_images_t *imgs) { destRect.y0 = 0; destRect.x1 = i->w; destRect.y1 = i->h; - vdp_st = vdp_bitmap_surface_putbits_native(eosd_targets[eosd_render_count].surface, + vdp_st = vdp_bitmap_surface_put_bits_native(eosd_targets[eosd_render_count].surface, (const void *) &i->bitmap, &i->stride, &destRect); CHECK_ST_WARNING("EOSD: putbits failed") eosd_render_count++; From 72527eea10a4a4c2a03627cbd97dfc60bff4fd34 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Wed, 6 May 2009 00:32:09 +0300 Subject: [PATCH 04/12] vo_vdpau: Move VDPAU interface pointers into one struct Replace a bunch of vdp_* function pointer variables with one struct. A variable that was before named "vdp_xyz" is now the struct field "vdp.xyz". --- libvo/vo_vdpau.c | 108 ++++++++++++++++++++++++----------------------- 1 file changed, 55 insertions(+), 53 deletions(-) diff --git a/libvo/vo_vdpau.c b/libvo/vo_vdpau.c index 5e1c6a937c..c924389509 100644 --- a/libvo/vo_vdpau.c +++ b/libvo/vo_vdpau.c @@ -59,14 +59,14 @@ #define CHECK_ST_ERROR(message) \ if (vdp_st != VDP_STATUS_OK) { \ mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] %s: %s\n", \ - message, vdp_get_error_string(vdp_st)); \ + message, vdp.get_error_string(vdp_st)); \ return -1; \ } #define CHECK_ST_WARNING(message) \ if (vdp_st != VDP_STATUS_OK) \ mp_msg(MSGT_VO, MSGL_WARN, "[vdpau] %s: %s\n", \ - message, vdp_get_error_string(vdp_st)); + message, vdp.get_error_string(vdp_st)); /* number of video and output surfaces */ #define NUM_OUTPUT_SURFACES 2 @@ -92,9 +92,11 @@ static VdpGetProcAddress *vdp_get_proc_address; static VdpPresentationQueueTarget vdp_flip_target; static VdpPresentationQueue vdp_flip_queue; -#define VDP_FUNCTION(vdp_type, _, mp_name) static vdp_type *vdp_##mp_name; +struct vdp_functions { +#define VDP_FUNCTION(vdp_type, _, mp_name) vdp_type *mp_name; #include "vdpau_template.c" #undef VDP_FUNCTION +} vdp; static void *vdpau_lib_handle; /* output_surfaces[NUM_OUTPUT_SURFACES] is misused for OSD. */ @@ -199,12 +201,12 @@ static void video_to_output_surface(struct vo *vo) VDP_VIDEO_MIXER_PICTURE_STRUCTURE_BOTTOM_FIELD: VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD; output_surface = output_surfaces[surface_num]; - vdp_st = vdp_presentation_queue_block_until_surface_idle(vdp_flip_queue, + vdp_st = vdp.presentation_queue_block_until_surface_idle(vdp_flip_queue, output_surface, &dummy); - CHECK_ST_WARNING("Error when calling vdp_presentation_queue_block_until_surface_idle") + CHECK_ST_WARNING("Error when calling vdp.presentation_queue_block_until_surface_idle") - vdp_st = vdp_video_mixer_render(video_mixer, VDP_INVALID_HANDLE, 0, + vdp_st = vdp.video_mixer_render(video_mixer, VDP_INVALID_HANDLE, 0, field, 2, deint_surfaces + 1, deint_surfaces[0], 1, &surface_render[vid_surface_num].surface, @@ -253,11 +255,11 @@ static void resize(struct vo *vo) // Creation of output_surfaces for (i = 0; i <= NUM_OUTPUT_SURFACES; i++) { if (output_surfaces[i] != VDP_INVALID_HANDLE) - vdp_output_surface_destroy(output_surfaces[i]); - vdp_st = vdp_output_surface_create(vdp_device, VDP_RGBA_FORMAT_B8G8R8A8, + vdp.output_surface_destroy(output_surfaces[i]); + vdp_st = vdp.output_surface_create(vdp_device, VDP_RGBA_FORMAT_B8G8R8A8, output_surface_width, output_surface_height, &output_surfaces[i]); - CHECK_ST_WARNING("Error when calling vdp_output_surface_create") + CHECK_ST_WARNING("Error when calling vdp.output_surface_create") mp_msg(MSGT_VO, MSGL_DBG2, "OUT CREATE: %u\n", output_surfaces[i]); } } @@ -280,7 +282,7 @@ static int win_x11_init_vdpau_procs(struct vo *vo) const struct vdp_function *dsc; static const struct vdp_function vdp_func[] = { -#define VDP_FUNCTION(_, macro_name, mp_name) {macro_name, &vdp_##mp_name}, +#define VDP_FUNCTION(_, macro_name, mp_name) {macro_name, &vdp.mp_name}, #include "vdpau_template.c" #undef VDP_FUNCTION {0, NULL} @@ -293,11 +295,11 @@ static int win_x11_init_vdpau_procs(struct vo *vo) return -1; } - vdp_get_error_string = NULL; + vdp.get_error_string = NULL; for (dsc = vdp_func; dsc->pointer; dsc++) { vdp_st = vdp_get_proc_address(vdp_device, dsc->id, dsc->pointer); if (vdp_st != VDP_STATUS_OK) { - 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) : "?"); + 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) : "?"); return -1; } } @@ -310,13 +312,13 @@ static int win_x11_init_vdpau_flip_queue(struct vo *vo) struct vo_x11_state *x11 = vo->x11; VdpStatus vdp_st; - vdp_st = vdp_presentation_queue_target_create_x11(vdp_device, x11->window, + vdp_st = vdp.presentation_queue_target_create_x11(vdp_device, x11->window, &vdp_flip_target); - CHECK_ST_ERROR("Error when calling vdp_presentation_queue_target_create_x11") + CHECK_ST_ERROR("Error when calling vdp.presentation_queue_target_create_x11") - vdp_st = vdp_presentation_queue_create(vdp_device, vdp_flip_target, + vdp_st = vdp.presentation_queue_create(vdp_device, vdp_flip_target, &vdp_flip_queue); - CHECK_ST_ERROR("Error when calling vdp_presentation_queue_create") + CHECK_ST_ERROR("Error when calling vdp.presentation_queue_create") return 0; } @@ -356,7 +358,7 @@ static int create_vdp_mixer(VdpChromaType vdp_chroma_type) { if (sharpen) features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_SHARPNESS; - vdp_st = vdp_video_mixer_create(vdp_device, feature_count, features, + vdp_st = vdp.video_mixer_create(vdp_device, feature_count, features, VDP_NUM_MIXER_PARAMETER, parameters, parameter_values, &video_mixer); @@ -366,13 +368,13 @@ static int create_vdp_mixer(VdpChromaType vdp_chroma_type) { if (deint < 3) feature_enables[0] = VDP_FALSE; if (feature_count) - vdp_video_mixer_set_feature_enables(video_mixer, feature_count, features, feature_enables); + vdp.video_mixer_set_feature_enables(video_mixer, feature_count, features, feature_enables); if (denoise) - vdp_video_mixer_set_attribute_values(video_mixer, 1, denoise_attrib, denoise_value); + vdp.video_mixer_set_attribute_values(video_mixer, 1, denoise_attrib, denoise_value); if (sharpen) - vdp_video_mixer_set_attribute_values(video_mixer, 1, sharpen_attrib, sharpen_value); + vdp.video_mixer_set_attribute_values(video_mixer, 1, sharpen_attrib, sharpen_value); if (!chroma_deint) - vdp_video_mixer_set_attribute_values(video_mixer, 1, skip_chroma_attrib, skip_chroma_value_ptr); + vdp.video_mixer_set_attribute_values(video_mixer, 1, skip_chroma_attrib, skip_chroma_value_ptr); return 0; } @@ -383,7 +385,7 @@ static void free_video_specific(void) { VdpStatus vdp_st; if (decoder != VDP_INVALID_HANDLE) - vdp_decoder_destroy(decoder); + vdp.decoder_destroy(decoder); decoder = VDP_INVALID_HANDLE; decoder_max_refs = -1; @@ -398,14 +400,14 @@ static void free_video_specific(void) { for (i = 0; i < MAX_VIDEO_SURFACES; i++) { if (surface_render[i].surface != VDP_INVALID_HANDLE) { - vdp_st = vdp_video_surface_destroy(surface_render[i].surface); + vdp_st = vdp.video_surface_destroy(surface_render[i].surface); CHECK_ST_WARNING("Error when calling vdp_video_surface_destroy") } surface_render[i].surface = VDP_INVALID_HANDLE; } if (video_mixer != VDP_INVALID_HANDLE) { - vdp_st = vdp_video_mixer_destroy(video_mixer); + vdp_st = vdp.video_mixer_destroy(video_mixer); CHECK_ST_WARNING("Error when calling vdp_video_mixer_destroy") } video_mixer = VDP_INVALID_HANDLE; @@ -416,7 +418,7 @@ static int create_vdp_decoder(int max_refs) VdpStatus vdp_st; VdpDecoderProfile vdp_decoder_profile; if (decoder != VDP_INVALID_HANDLE) - vdp_decoder_destroy(decoder); + vdp.decoder_destroy(decoder); switch (image_format) { case IMGFMT_VDPAU_MPEG1: vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG1; @@ -435,7 +437,7 @@ static int create_vdp_decoder(int max_refs) vdp_decoder_profile = VDP_DECODER_PROFILE_VC1_ADVANCED; break; } - vdp_st = vdp_decoder_create(vdp_device, vdp_decoder_profile, + vdp_st = vdp.decoder_create(vdp_device, vdp_decoder_profile, vid_width, vid_height, max_refs, &decoder); CHECK_ST_WARNING("Failed creating VDPAU decoder"); if (vdp_st != VDP_STATUS_OK) { @@ -558,11 +560,11 @@ static void check_events(struct vo *vo) if (visible_buf) { /* redraw the last visible buffer */ VdpStatus vdp_st; - vdp_st = vdp_presentation_queue_display(vdp_flip_queue, + vdp_st = vdp.presentation_queue_display(vdp_flip_queue, output_surfaces[surface_num], vo->dwidth, vo->dheight, 0); - CHECK_ST_WARNING("Error when calling vdp_presentation_queue_display") + CHECK_ST_WARNING("Error when calling vdp.presentation_queue_display") } } } @@ -602,14 +604,14 @@ static void draw_osd_I8A8(void *ctx, int x0, int y0, int w, int h, pitch = w*2; // write source_data to osd_surface. - vdp_st = vdp_output_surface_put_bits_indexed(osd_surface, + vdp_st = vdp.output_surface_put_bits_indexed(osd_surface, VDP_INDEXED_FORMAT_I8A8, (const void *const*)&index_data, &pitch, &output_indexed_rect_vid, VDP_COLOR_TABLE_FORMAT_B8G8R8X8, (void *)palette); - CHECK_ST_WARNING("Error when calling vdp_output_surface_put_bits_indexed") + CHECK_ST_WARNING("Error when calling vdp.output_surface_put_bits_indexed") blend_state.struct_version = VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION; blend_state.blend_factor_source_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE; @@ -619,14 +621,14 @@ static void draw_osd_I8A8(void *ctx, int x0, int y0, int w, int h, blend_state.blend_equation_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD; blend_state.blend_equation_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD; - vdp_st = vdp_output_surface_render_output_surface(output_surface, + vdp_st = vdp.output_surface_render_output_surface(output_surface, &output_indexed_rect_vid, osd_surface, &output_indexed_rect_vid, NULL, &blend_state, VDP_OUTPUT_SURFACE_RENDER_ROTATE_0); - CHECK_ST_WARNING("Error when calling vdp_output_surface_render_output_surface") + CHECK_ST_WARNING("Error when calling vdp.output_surface_render_output_surface") } static void draw_eosd(void) { @@ -644,7 +646,7 @@ static void draw_eosd(void) { blend_state.blend_equation_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD; for (i=0; iw, i->h, VDP_TRUE, &eosd_surfaces[found].surface); CHECK_ST_WARNING("EOSD: error when creating surface") eosd_surfaces[found].w = i->w; @@ -717,7 +719,7 @@ static void generate_eosd(mp_eosd_images_t *imgs) { destRect.y0 = 0; destRect.x1 = i->w; destRect.y1 = i->h; - vdp_st = vdp_bitmap_surface_put_bits_native(eosd_targets[eosd_render_count].surface, + vdp_st = vdp.bitmap_surface_put_bits_native(eosd_targets[eosd_render_count].surface, (const void *) &i->bitmap, &i->stride, &destRect); CHECK_ST_WARNING("EOSD: putbits failed") eosd_render_count++; @@ -758,10 +760,10 @@ static void flip_page(struct vo *vo) mp_msg(MSGT_VO, MSGL_DBG2, "\nFLIP_PAGE VID:%u -> OUT:%u\n", surface_render[vid_surface_num].surface, output_surfaces[surface_num]); - vdp_st = vdp_presentation_queue_display(vdp_flip_queue, output_surfaces[surface_num], + vdp_st = vdp.presentation_queue_display(vdp_flip_queue, output_surfaces[surface_num], vo->dwidth, vo->dheight, 0); - CHECK_ST_WARNING("Error when calling vdp_presentation_queue_display") + CHECK_ST_WARNING("Error when calling vdp.presentation_queue_display") surface_num = (surface_num + 1) % NUM_OUTPUT_SURFACES; visible_buf = 1; @@ -779,7 +781,7 @@ static int draw_slice(struct vo *vo, uint8_t *image[], int stride[], int w, && !create_vdp_decoder(max_refs)) return VO_FALSE; - vdp_st = vdp_decoder_render(decoder, rndr->surface, (void *)&rndr->info, rndr->bitstream_buffers_used, rndr->bitstream_buffers); + vdp_st = vdp.decoder_render(decoder, rndr->surface, (void *)&rndr->info, rndr->bitstream_buffers_used, rndr->bitstream_buffers); CHECK_ST_WARNING("Failed VDPAU decoder rendering"); return VO_TRUE; } @@ -796,7 +798,7 @@ static struct vdpau_render_state *get_surface(int number) return NULL; if (surface_render[number].surface == VDP_INVALID_HANDLE) { VdpStatus vdp_st; - vdp_st = vdp_video_surface_create(vdp_device, vdp_chroma_type, + vdp_st = vdp.video_surface_create(vdp_device, vdp_chroma_type, vid_width, vid_height, &surface_render[number].surface); CHECK_ST_WARNING("Error when calling vdp_video_surface_create") @@ -827,7 +829,7 @@ static uint32_t draw_image(struct vo *vo, mp_image_t *mpi) vid_surface_num = rndr - surface_render; if (image_format == IMGFMT_NV12) destdata[1] = destdata[2]; - vdp_st = vdp_video_surface_put_bits_y_cb_cr(rndr->surface, + vdp_st = vdp.video_surface_put_bits_y_cb_cr(rndr->surface, vdp_pixel_format, (const void *const*)destdata, mpi->stride); // pitch @@ -894,27 +896,27 @@ static void DestroyVdpauObjects(void) free_video_specific(); - vdp_st = vdp_presentation_queue_destroy(vdp_flip_queue); - CHECK_ST_WARNING("Error when calling vdp_presentation_queue_destroy") + vdp_st = vdp.presentation_queue_destroy(vdp_flip_queue); + CHECK_ST_WARNING("Error when calling vdp.presentation_queue_destroy") - vdp_st = vdp_presentation_queue_target_destroy(vdp_flip_target); - CHECK_ST_WARNING("Error when calling vdp_presentation_queue_target_destroy") + vdp_st = vdp.presentation_queue_target_destroy(vdp_flip_target); + CHECK_ST_WARNING("Error when calling vdp.presentation_queue_target_destroy") for (i = 0; i <= NUM_OUTPUT_SURFACES; i++) { - vdp_st = vdp_output_surface_destroy(output_surfaces[i]); + vdp_st = vdp.output_surface_destroy(output_surfaces[i]); output_surfaces[i] = VDP_INVALID_HANDLE; - CHECK_ST_WARNING("Error when calling vdp_output_surface_destroy") + CHECK_ST_WARNING("Error when calling vdp.output_surface_destroy") } for (i = 0; i Date: Wed, 6 May 2009 21:04:37 +0300 Subject: [PATCH 05/12] vo_vdpau: Replace global function table with context variable --- libvo/vo_vdpau.c | 239 +++++++++++++++++++++++++++++------------------ 1 file changed, 148 insertions(+), 91 deletions(-) diff --git a/libvo/vo_vdpau.c b/libvo/vo_vdpau.c index c924389509..c6e2973ddd 100644 --- a/libvo/vo_vdpau.c +++ b/libvo/vo_vdpau.c @@ -38,6 +38,7 @@ #include "config.h" #include "mp_msg.h" #include "options.h" +#include "talloc.h" #include "video_out.h" #include "x11_common.h" #include "aspect.h" @@ -59,14 +60,14 @@ #define CHECK_ST_ERROR(message) \ if (vdp_st != VDP_STATUS_OK) { \ mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] %s: %s\n", \ - message, vdp.get_error_string(vdp_st)); \ + message, vdp->get_error_string(vdp_st)); \ return -1; \ } #define CHECK_ST_WARNING(message) \ if (vdp_st != VDP_STATUS_OK) \ mp_msg(MSGT_VO, MSGL_WARN, "[vdpau] %s: %s\n", \ - message, vdp.get_error_string(vdp_st)); + message, vdp->get_error_string(vdp_st)); /* number of video and output surfaces */ #define NUM_OUTPUT_SURFACES 2 @@ -82,6 +83,16 @@ * Global variable declaration - VDPAU specific */ +struct vdp_functions { +#define VDP_FUNCTION(vdp_type, _, mp_name) vdp_type *mp_name; +#include "vdpau_template.c" +#undef VDP_FUNCTION +}; + +struct vdpctx { + struct vdp_functions *vdp; +}; + /* Declaration for all variables of win_x11_init_vdpau_procs() and * win_x11_init_vdpau_flip_queue() functions */ @@ -92,12 +103,6 @@ static VdpGetProcAddress *vdp_get_proc_address; static VdpPresentationQueueTarget vdp_flip_target; static VdpPresentationQueue vdp_flip_queue; -struct vdp_functions { -#define VDP_FUNCTION(vdp_type, _, mp_name) vdp_type *mp_name; -#include "vdpau_template.c" -#undef VDP_FUNCTION -} vdp; - static void *vdpau_lib_handle; /* output_surfaces[NUM_OUTPUT_SURFACES] is misused for OSD. */ #define osd_surface output_surfaces[NUM_OUTPUT_SURFACES] @@ -166,8 +171,6 @@ static VdpProcamp procamp; static int visible_buf; static int int_pause; -static void draw_eosd(void); - static void push_deint_surface(VdpVideoSurface surface) { deint_surfaces[2] = deint_surfaces[1]; @@ -176,9 +179,10 @@ static void push_deint_surface(VdpVideoSurface surface) } static void flip_page(struct vo *vo); -static void draw_osd(struct vo *vo, struct osd_state *osd); static void video_to_output_surface(struct vo *vo) { + struct vdpctx *vc = vo->priv; + struct vdp_functions *vdp = vc->vdp; VdpTime dummy; VdpStatus vdp_st; int i; @@ -192,7 +196,7 @@ static void video_to_output_surface(struct vo *vo) int field = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME; VdpOutputSurface output_surface; if (i) { - draw_eosd(); + // draw_eosd(vo); //draw_osd(vo, NULL); flip_page(vo); } @@ -201,12 +205,12 @@ static void video_to_output_surface(struct vo *vo) VDP_VIDEO_MIXER_PICTURE_STRUCTURE_BOTTOM_FIELD: VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD; output_surface = output_surfaces[surface_num]; - vdp_st = vdp.presentation_queue_block_until_surface_idle(vdp_flip_queue, + vdp_st = vdp->presentation_queue_block_until_surface_idle(vdp_flip_queue, output_surface, &dummy); - CHECK_ST_WARNING("Error when calling vdp.presentation_queue_block_until_surface_idle") + CHECK_ST_WARNING("Error when calling vdp->presentation_queue_block_until_surface_idle") - vdp_st = vdp.video_mixer_render(video_mixer, VDP_INVALID_HANDLE, 0, + vdp_st = vdp->video_mixer_render(video_mixer, VDP_INVALID_HANDLE, 0, field, 2, deint_surfaces + 1, deint_surfaces[0], 1, &surface_render[vid_surface_num].surface, @@ -220,6 +224,8 @@ static void video_to_output_surface(struct vo *vo) static void resize(struct vo *vo) { + struct vdpctx *vc = vo->priv; + struct vdp_functions *vdp = vc->vdp; VdpStatus vdp_st; int i; struct vo_rect src_rect; @@ -255,11 +261,11 @@ static void resize(struct vo *vo) // Creation of output_surfaces for (i = 0; i <= NUM_OUTPUT_SURFACES; i++) { if (output_surfaces[i] != VDP_INVALID_HANDLE) - vdp.output_surface_destroy(output_surfaces[i]); - vdp_st = vdp.output_surface_create(vdp_device, VDP_RGBA_FORMAT_B8G8R8A8, + vdp->output_surface_destroy(output_surfaces[i]); + vdp_st = vdp->output_surface_create(vdp_device, VDP_RGBA_FORMAT_B8G8R8A8, output_surface_width, output_surface_height, &output_surfaces[i]); - CHECK_ST_WARNING("Error when calling vdp.output_surface_create") + CHECK_ST_WARNING("Error when calling vdp->output_surface_create") mp_msg(MSGT_VO, MSGL_DBG2, "OUT CREATE: %u\n", output_surfaces[i]); } } @@ -272,20 +278,23 @@ static void resize(struct vo *vo) static int win_x11_init_vdpau_procs(struct vo *vo) { struct vo_x11_state *x11 = vo->x11; + struct vdpctx *vc = vo->priv; + struct vdp_functions *vdp = talloc_zero(vc, struct vdp_functions); + vc->vdp = vdp; VdpStatus vdp_st; struct vdp_function { const int id; - void *pointer; + int offset; }; const struct vdp_function *dsc; static const struct vdp_function vdp_func[] = { -#define VDP_FUNCTION(_, macro_name, mp_name) {macro_name, &vdp.mp_name}, +#define VDP_FUNCTION(_, macro_name, mp_name) {macro_name, offsetof(struct vdp_functions, mp_name)}, #include "vdpau_template.c" #undef VDP_FUNCTION - {0, NULL} + {0, -1} }; vdp_st = vdp_device_create(x11->display, x11->screen, @@ -295,11 +304,12 @@ static int win_x11_init_vdpau_procs(struct vo *vo) return -1; } - vdp.get_error_string = NULL; - for (dsc = vdp_func; dsc->pointer; dsc++) { - vdp_st = vdp_get_proc_address(vdp_device, dsc->id, dsc->pointer); + vdp->get_error_string = NULL; + for (dsc = vdp_func; dsc->offset >= 0; dsc++) { + vdp_st = vdp_get_proc_address(vdp_device, dsc->id, + (void **)((char *)vdp + dsc->offset)); if (vdp_st != VDP_STATUS_OK) { - 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) : "?"); + 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) : "?"); return -1; } } @@ -309,21 +319,26 @@ static int win_x11_init_vdpau_procs(struct vo *vo) /* Initialize vdpau_flip_queue, called from config() */ static int win_x11_init_vdpau_flip_queue(struct vo *vo) { + struct vdpctx *vc = vo->priv; + struct vdp_functions *vdp = vc->vdp; struct vo_x11_state *x11 = vo->x11; VdpStatus vdp_st; - vdp_st = vdp.presentation_queue_target_create_x11(vdp_device, x11->window, + vdp_st = vdp->presentation_queue_target_create_x11(vdp_device, x11->window, &vdp_flip_target); - CHECK_ST_ERROR("Error when calling vdp.presentation_queue_target_create_x11") + CHECK_ST_ERROR("Error when calling vdp->presentation_queue_target_create_x11") - vdp_st = vdp.presentation_queue_create(vdp_device, vdp_flip_target, + vdp_st = vdp->presentation_queue_create(vdp_device, vdp_flip_target, &vdp_flip_queue); - CHECK_ST_ERROR("Error when calling vdp.presentation_queue_create") + CHECK_ST_ERROR("Error when calling vdp->presentation_queue_create") return 0; } -static int create_vdp_mixer(VdpChromaType vdp_chroma_type) { +static int create_vdp_mixer(struct vo *vo, VdpChromaType vdp_chroma_type) +{ + struct vdpctx *vc = vo->priv; + struct vdp_functions *vdp = vc->vdp; #define VDP_NUM_MIXER_PARAMETER 3 #define MAX_NUM_FEATURES 5 int i; @@ -358,7 +373,7 @@ static int create_vdp_mixer(VdpChromaType vdp_chroma_type) { if (sharpen) features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_SHARPNESS; - vdp_st = vdp.video_mixer_create(vdp_device, feature_count, features, + vdp_st = vdp->video_mixer_create(vdp_device, feature_count, features, VDP_NUM_MIXER_PARAMETER, parameters, parameter_values, &video_mixer); @@ -368,24 +383,27 @@ static int create_vdp_mixer(VdpChromaType vdp_chroma_type) { if (deint < 3) feature_enables[0] = VDP_FALSE; if (feature_count) - vdp.video_mixer_set_feature_enables(video_mixer, feature_count, features, feature_enables); + vdp->video_mixer_set_feature_enables(video_mixer, feature_count, features, feature_enables); if (denoise) - vdp.video_mixer_set_attribute_values(video_mixer, 1, denoise_attrib, denoise_value); + vdp->video_mixer_set_attribute_values(video_mixer, 1, denoise_attrib, denoise_value); if (sharpen) - vdp.video_mixer_set_attribute_values(video_mixer, 1, sharpen_attrib, sharpen_value); + vdp->video_mixer_set_attribute_values(video_mixer, 1, sharpen_attrib, sharpen_value); if (!chroma_deint) - vdp.video_mixer_set_attribute_values(video_mixer, 1, skip_chroma_attrib, skip_chroma_value_ptr); + vdp->video_mixer_set_attribute_values(video_mixer, 1, skip_chroma_attrib, skip_chroma_value_ptr); return 0; } // Free everything specific to a certain video file -static void free_video_specific(void) { +static void free_video_specific(struct vo *vo) +{ + struct vdpctx *vc = vo->priv; + struct vdp_functions *vdp = vc->vdp; int i; VdpStatus vdp_st; if (decoder != VDP_INVALID_HANDLE) - vdp.decoder_destroy(decoder); + vdp->decoder_destroy(decoder); decoder = VDP_INVALID_HANDLE; decoder_max_refs = -1; @@ -400,25 +418,27 @@ static void free_video_specific(void) { for (i = 0; i < MAX_VIDEO_SURFACES; i++) { if (surface_render[i].surface != VDP_INVALID_HANDLE) { - vdp_st = vdp.video_surface_destroy(surface_render[i].surface); + vdp_st = vdp->video_surface_destroy(surface_render[i].surface); CHECK_ST_WARNING("Error when calling vdp_video_surface_destroy") } surface_render[i].surface = VDP_INVALID_HANDLE; } if (video_mixer != VDP_INVALID_HANDLE) { - vdp_st = vdp.video_mixer_destroy(video_mixer); + vdp_st = vdp->video_mixer_destroy(video_mixer); CHECK_ST_WARNING("Error when calling vdp_video_mixer_destroy") } video_mixer = VDP_INVALID_HANDLE; } -static int create_vdp_decoder(int max_refs) +static int create_vdp_decoder(struct vo *vo, int max_refs) { + struct vdpctx *vc = vo->priv; + struct vdp_functions *vdp = vc->vdp; VdpStatus vdp_st; VdpDecoderProfile vdp_decoder_profile; if (decoder != VDP_INVALID_HANDLE) - vdp.decoder_destroy(decoder); + vdp->decoder_destroy(decoder); switch (image_format) { case IMGFMT_VDPAU_MPEG1: vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG1; @@ -437,7 +457,7 @@ static int create_vdp_decoder(int max_refs) vdp_decoder_profile = VDP_DECODER_PROFILE_VC1_ADVANCED; break; } - vdp_st = vdp.decoder_create(vdp_device, vdp_decoder_profile, + vdp_st = vdp->decoder_create(vdp_device, vdp_decoder_profile, vid_width, vid_height, max_refs, &decoder); CHECK_ST_WARNING("Failed creating VDPAU decoder"); if (vdp_st != VDP_STATUS_OK) { @@ -471,8 +491,8 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, image_format = format; vid_width = width; vid_height = height; - free_video_specific(); - if (IMGFMT_IS_VDPAU(image_format) && !create_vdp_decoder(2)) + free_video_specific(vo); + if (IMGFMT_IS_VDPAU(image_format) && !create_vdp_decoder(vo, 2)) return -1; visible_buf = 0; @@ -538,7 +558,7 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, vdp_pixel_format = VDP_YCBCR_FORMAT_UYVY; vdp_chroma_type = VDP_CHROMA_TYPE_422; } - if (create_vdp_mixer(vdp_chroma_type)) + if (create_vdp_mixer(vo, vdp_chroma_type)) return -1; surface_num = 0; @@ -550,6 +570,9 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, static void check_events(struct vo *vo) { + struct vdpctx *vc = vo->priv; + struct vdp_functions *vdp = vc->vdp; + int e = vo_x11_check_events(vo); if (e & VO_EVENT_RESIZE) @@ -560,11 +583,11 @@ static void check_events(struct vo *vo) if (visible_buf) { /* redraw the last visible buffer */ VdpStatus vdp_st; - vdp_st = vdp.presentation_queue_display(vdp_flip_queue, + vdp_st = vdp->presentation_queue_display(vdp_flip_queue, output_surfaces[surface_num], vo->dwidth, vo->dheight, 0); - CHECK_ST_WARNING("Error when calling vdp.presentation_queue_display") + CHECK_ST_WARNING("Error when calling vdp->presentation_queue_display") } } } @@ -572,6 +595,9 @@ static void check_events(struct vo *vo) static void draw_osd_I8A8(void *ctx, int x0, int y0, int w, int h, unsigned char *src, unsigned char *srca, int stride) { + struct vo *vo = ctx; + struct vdpctx *vc = vo->priv; + struct vdp_functions *vdp = vc->vdp; VdpOutputSurface output_surface = output_surfaces[surface_num]; VdpStatus vdp_st; int i, j; @@ -604,14 +630,14 @@ static void draw_osd_I8A8(void *ctx, int x0, int y0, int w, int h, pitch = w*2; // write source_data to osd_surface. - vdp_st = vdp.output_surface_put_bits_indexed(osd_surface, + vdp_st = vdp->output_surface_put_bits_indexed(osd_surface, VDP_INDEXED_FORMAT_I8A8, (const void *const*)&index_data, &pitch, &output_indexed_rect_vid, VDP_COLOR_TABLE_FORMAT_B8G8R8X8, (void *)palette); - CHECK_ST_WARNING("Error when calling vdp.output_surface_put_bits_indexed") + CHECK_ST_WARNING("Error when calling vdp->output_surface_put_bits_indexed") blend_state.struct_version = VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION; blend_state.blend_factor_source_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE; @@ -621,17 +647,20 @@ static void draw_osd_I8A8(void *ctx, int x0, int y0, int w, int h, blend_state.blend_equation_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD; blend_state.blend_equation_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD; - vdp_st = vdp.output_surface_render_output_surface(output_surface, + vdp_st = vdp->output_surface_render_output_surface(output_surface, &output_indexed_rect_vid, osd_surface, &output_indexed_rect_vid, NULL, &blend_state, VDP_OUTPUT_SURFACE_RENDER_ROTATE_0); - CHECK_ST_WARNING("Error when calling vdp.output_surface_render_output_surface") + CHECK_ST_WARNING("Error when calling vdp->output_surface_render_output_surface") } -static void draw_eosd(void) { +static void draw_eosd(struct vo *vo) +{ + struct vdpctx *vc = vo->priv; + struct vdp_functions *vdp = vc->vdp; VdpStatus vdp_st; VdpOutputSurface output_surface = output_surfaces[surface_num]; VdpOutputSurfaceRenderBlendState blend_state; @@ -646,7 +675,7 @@ static void draw_eosd(void) { blend_state.blend_equation_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD; for (i=0; ioutput_surface_render_bitmap_surface( output_surface, &eosd_targets[i].dest, eosd_targets[i].surface, &eosd_targets[i].source, &eosd_targets[i].color, &blend_state, @@ -655,7 +684,10 @@ static void draw_eosd(void) { } } -static void generate_eosd(mp_eosd_images_t *imgs) { +static void generate_eosd(struct vo *vo, mp_eosd_images_t *imgs) +{ + struct vdpctx *vc = vo->priv; + struct vdp_functions *vdp = vc->vdp; VdpStatus vdp_st; VdpRect destRect; int j, found; @@ -691,7 +723,7 @@ static void generate_eosd(mp_eosd_images_t *imgs) { for (j=0; jbitmap_surface_destroy(eosd_surfaces[j].surface); found = j; break; } @@ -707,7 +739,7 @@ static void generate_eosd(mp_eosd_images_t *imgs) { eosd_surfaces[j].in_use = 0; } } - vdp_st = vdp.bitmap_surface_create(vdp_device, VDP_RGBA_FORMAT_A8, + vdp_st = vdp->bitmap_surface_create(vdp_device, VDP_RGBA_FORMAT_A8, i->w, i->h, VDP_TRUE, &eosd_surfaces[found].surface); CHECK_ST_WARNING("EOSD: error when creating surface") eosd_surfaces[found].w = i->w; @@ -719,7 +751,7 @@ static void generate_eosd(mp_eosd_images_t *imgs) { destRect.y0 = 0; destRect.x1 = i->w; destRect.y1 = i->h; - vdp_st = vdp.bitmap_surface_put_bits_native(eosd_targets[eosd_render_count].surface, + vdp_st = vdp->bitmap_surface_put_bits_native(eosd_targets[eosd_render_count].surface, (const void *) &i->bitmap, &i->stride, &destRect); CHECK_ST_WARNING("EOSD: putbits failed") eosd_render_count++; @@ -756,14 +788,16 @@ static void draw_osd(struct vo *vo, struct osd_state *osd) static void flip_page(struct vo *vo) { + struct vdpctx *vc = vo->priv; + struct vdp_functions *vdp = vc->vdp; VdpStatus vdp_st; mp_msg(MSGT_VO, MSGL_DBG2, "\nFLIP_PAGE VID:%u -> OUT:%u\n", surface_render[vid_surface_num].surface, output_surfaces[surface_num]); - vdp_st = vdp.presentation_queue_display(vdp_flip_queue, output_surfaces[surface_num], + vdp_st = vdp->presentation_queue_display(vdp_flip_queue, output_surfaces[surface_num], vo->dwidth, vo->dheight, 0); - CHECK_ST_WARNING("Error when calling vdp.presentation_queue_display") + CHECK_ST_WARNING("Error when calling vdp->presentation_queue_display") surface_num = (surface_num + 1) % NUM_OUTPUT_SURFACES; visible_buf = 1; @@ -772,16 +806,18 @@ static void flip_page(struct vo *vo) static int draw_slice(struct vo *vo, uint8_t *image[], int stride[], int w, int h, int x, int y) { + struct vdpctx *vc = vo->priv; + struct vdp_functions *vdp = vc->vdp; VdpStatus vdp_st; struct vdpau_render_state *rndr = (struct vdpau_render_state *)image[0]; int max_refs = image_format == IMGFMT_VDPAU_H264 ? rndr->info.h264.num_ref_frames : 2; if (!IMGFMT_IS_VDPAU(image_format)) return VO_FALSE; if ((decoder == VDP_INVALID_HANDLE || decoder_max_refs < max_refs) - && !create_vdp_decoder(max_refs)) + && !create_vdp_decoder(vo, max_refs)) return VO_FALSE; - vdp_st = vdp.decoder_render(decoder, rndr->surface, (void *)&rndr->info, rndr->bitstream_buffers_used, rndr->bitstream_buffers); + vdp_st = vdp->decoder_render(decoder, rndr->surface, (void *)&rndr->info, rndr->bitstream_buffers_used, rndr->bitstream_buffers); CHECK_ST_WARNING("Failed VDPAU decoder rendering"); return VO_TRUE; } @@ -792,13 +828,16 @@ static int draw_frame(struct vo *vo, uint8_t *src[]) return VO_ERROR; } -static struct vdpau_render_state *get_surface(int number) +static struct vdpau_render_state *get_surface(struct vo *vo, int number) { + struct vdpctx *vc = vo->priv; + struct vdp_functions *vdp = vc->vdp; + if (number > MAX_VIDEO_SURFACES) return NULL; if (surface_render[number].surface == VDP_INVALID_HANDLE) { VdpStatus vdp_st; - vdp_st = vdp.video_surface_create(vdp_device, vdp_chroma_type, + vdp_st = vdp->video_surface_create(vdp_device, vdp_chroma_type, vid_width, vid_height, &surface_render[number].surface); CHECK_ST_WARNING("Error when calling vdp_video_surface_create") @@ -811,6 +850,9 @@ static struct vdpau_render_state *get_surface(int number) static uint32_t draw_image(struct vo *vo, mp_image_t *mpi) { + struct vdpctx *vc = vo->priv; + struct vdp_functions *vdp = vc->vdp; + if (IMGFMT_IS_VDPAU(image_format)) { struct vdpau_render_state *rndr = mpi->priv; vid_surface_num = rndr - surface_render; @@ -824,12 +866,12 @@ static uint32_t draw_image(struct vo *vo, mp_image_t *mpi) } else if (!(mpi->flags & MP_IMGFLAG_DRAW_CALLBACK)) { VdpStatus vdp_st; void *destdata[3] = {mpi->planes[0], mpi->planes[2], mpi->planes[1]}; - struct vdpau_render_state *rndr = get_surface(deint_counter); + struct vdpau_render_state *rndr = get_surface(vo, deint_counter); deint_counter = (deint_counter + 1) % 3; vid_surface_num = rndr - surface_render; if (image_format == IMGFMT_NV12) destdata[1] = destdata[2]; - vdp_st = vdp.video_surface_put_bits_y_cb_cr(rndr->surface, + vdp_st = vdp->video_surface_put_bits_y_cb_cr(rndr->surface, vdp_pixel_format, (const void *const*)destdata, mpi->stride); // pitch @@ -844,7 +886,7 @@ static uint32_t draw_image(struct vo *vo, mp_image_t *mpi) return VO_TRUE; } -static uint32_t get_image(mp_image_t *mpi) +static uint32_t get_image(struct vo *vo, mp_image_t *mpi) { struct vdpau_render_state *rndr; @@ -852,7 +894,7 @@ static uint32_t get_image(mp_image_t *mpi) if (!IMGFMT_IS_VDPAU(image_format)) return VO_FALSE; if (mpi->type != MP_IMGTYPE_NUMBERED) return VO_FALSE; - rndr = get_surface(mpi->number); + rndr = get_surface(vo, mpi->number); if (!rndr) { mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] no surfaces available in get_image\n"); // TODO: this probably breaks things forever, provide a dummy buffer? @@ -889,34 +931,37 @@ static int query_format(uint32_t format) return 0; } -static void DestroyVdpauObjects(void) +static void destroy_vdpau_objects(struct vo *vo) { + struct vdpctx *vc = vo->priv; + struct vdp_functions *vdp = vc->vdp; + int i; VdpStatus vdp_st; - free_video_specific(); + free_video_specific(vo); - vdp_st = vdp.presentation_queue_destroy(vdp_flip_queue); - CHECK_ST_WARNING("Error when calling vdp.presentation_queue_destroy") + vdp_st = vdp->presentation_queue_destroy(vdp_flip_queue); + CHECK_ST_WARNING("Error when calling vdp->presentation_queue_destroy") - vdp_st = vdp.presentation_queue_target_destroy(vdp_flip_target); - CHECK_ST_WARNING("Error when calling vdp.presentation_queue_target_destroy") + vdp_st = vdp->presentation_queue_target_destroy(vdp_flip_target); + CHECK_ST_WARNING("Error when calling vdp->presentation_queue_target_destroy") for (i = 0; i <= NUM_OUTPUT_SURFACES; i++) { - vdp_st = vdp.output_surface_destroy(output_surfaces[i]); + vdp_st = vdp->output_surface_destroy(output_surfaces[i]); output_surfaces[i] = VDP_INVALID_HANDLE; - CHECK_ST_WARNING("Error when calling vdp.output_surface_destroy") + CHECK_ST_WARNING("Error when calling vdp->output_surface_destroy") } for (i = 0; ibitmap_surface_destroy(eosd_surfaces[i].surface); + CHECK_ST_WARNING("Error when calling vdp->bitmap_surface_destroy") } eosd_surfaces[i].surface = VDP_INVALID_HANDLE; } - vdp_st = vdp.device_destroy(vdp_device); + vdp_st = vdp->device_destroy(vdp_device); CHECK_ST_WARNING("Error when calling vdp_device_destroy") } @@ -927,7 +972,7 @@ static void uninit(struct vo *vo) visible_buf = 0; /* Destroy all vdpau objects */ - DestroyVdpauObjects(); + destroy_vdpau_objects(vo); free(index_data); index_data = NULL; @@ -978,8 +1023,9 @@ static const char help_msg[] = static int preinit(struct vo *vo, const char *arg) { int i; - static const char *vdpaulibrary = "libvdpau.so.1"; - static const char *vdpau_device_create = "vdp_device_create_x11"; + + struct vdpctx *vc = talloc_zero(vo, struct vdpctx); + vo->priv = vc; deint = 0; deint_type = 3; @@ -999,6 +1045,8 @@ static int preinit(struct vo *vo, const char *arg) if (deint > 1) deint_buffer_past_frames = 1; + char *vdpaulibrary = "libvdpau.so.1"; + char *vdpau_device_create = "vdp_device_create_x11"; vdpau_lib_handle = dlopen(vdpaulibrary, RTLD_LAZY); if (!vdpau_lib_handle) { mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Could not open dynamic library %s\n", @@ -1042,7 +1090,10 @@ static int preinit(struct vo *vo, const char *arg) return 0; } -static int get_equalizer(const char *name, int *value) { +static int get_equalizer(struct vo *vo, const char *name, int *value) +{ + struct vdpctx *vc = vo->priv; + if (!strcasecmp(name, "brightness")) *value = procamp.brightness * 100; else if (!strcasecmp(name, "contrast")) @@ -1056,7 +1107,10 @@ static int get_equalizer(const char *name, int *value) { return VO_TRUE; } -static int set_equalizer(const char *name, int value) { +static int set_equalizer(struct vo *vo, const char *name, int value) +{ + struct vdpctx *vc = vo->priv; + struct vdp_functions *vdp = vc->vdp; VdpStatus vdp_st; VdpCSCMatrix matrix; static const VdpVideoMixerAttribute attributes[] = {VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX}; @@ -1073,10 +1127,10 @@ static int set_equalizer(const char *name, int value) { else return VO_NOTIMPL; - vdp_st = vdp.generate_csc_matrix(&procamp, VDP_COLOR_STANDARD_ITUR_BT_601, + vdp_st = vdp->generate_csc_matrix(&procamp, VDP_COLOR_STANDARD_ITUR_BT_601, &matrix); CHECK_ST_WARNING("Error when generating CSC matrix") - vdp_st = vdp.video_mixer_set_attribute_values(video_mixer, 1, attributes, + vdp_st = vdp->video_mixer_set_attribute_values(video_mixer, 1, attributes, attribute_values); CHECK_ST_WARNING("Error when setting CSC matrix") return VO_TRUE; @@ -1084,6 +1138,9 @@ static int set_equalizer(const char *name, int value) { static int control(struct vo *vo, uint32_t request, void *data) { + struct vdpctx *vc = vo->priv; + struct vdp_functions *vdp = vc->vdp; + switch (request) { case VOCTRL_GET_DEINTERLACE: *(int*)data = deint; @@ -1099,7 +1156,7 @@ static int control(struct vo *vo, uint32_t request, void *data) VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL : VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL}; VdpBool feature_enables[1] = {deint ? VDP_TRUE : VDP_FALSE}; - vdp_st = vdp.video_mixer_set_feature_enables(video_mixer, 1, + vdp_st = vdp->video_mixer_set_feature_enables(video_mixer, 1, features, feature_enables); CHECK_ST_WARNING("Error changing deinterlacing settings") @@ -1113,7 +1170,7 @@ static int control(struct vo *vo, uint32_t request, void *data) case VOCTRL_QUERY_FORMAT: return query_format(*(uint32_t *)data); case VOCTRL_GET_IMAGE: - return get_image(data); + return get_image(vo, data); case VOCTRL_DRAW_IMAGE: return draw_image(vo, data); case VOCTRL_BORDER: @@ -1131,12 +1188,12 @@ static int control(struct vo *vo, uint32_t request, void *data) return VO_TRUE; case VOCTRL_SET_EQUALIZER: { struct voctrl_set_equalizer_args *args = data; - return set_equalizer(args->name, args->value); + return set_equalizer(vo, args->name, args->value); } case VOCTRL_GET_EQUALIZER: { struct voctrl_get_equalizer_args *args = data; - return get_equalizer(args->name, args->valueptr); + return get_equalizer(vo, args->name, args->valueptr); } case VOCTRL_ONTOP: vo_x11_ontop(vo); @@ -1147,8 +1204,8 @@ static int control(struct vo *vo, uint32_t request, void *data) case VOCTRL_DRAW_EOSD: if (!data) return VO_FALSE; - generate_eosd(data); - draw_eosd(); + generate_eosd(vo, data); + draw_eosd(vo); return VO_TRUE; case VOCTRL_GET_EOSD_RES: { mp_eosd_res_t *r = data; From 8a26256b87f674764b27a5844e892bce281a0fb9 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Wed, 6 May 2009 22:21:19 +0300 Subject: [PATCH 06/12] vo_vdpau: Make info struct const --- libvo/vo_vdpau.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libvo/vo_vdpau.c b/libvo/vo_vdpau.c index c6e2973ddd..3db31dbb08 100644 --- a/libvo/vo_vdpau.c +++ b/libvo/vo_vdpau.c @@ -1227,7 +1227,7 @@ static int control(struct vo *vo, uint32_t request, void *data) const struct vo_driver video_out_vdpau = { .is_new = 1, - .info = &(struct vo_info_s){ + .info = &(const struct vo_info_s){ "VDPAU with X11", "vdpau", "Rajib Mahapatra and others", From 35dbbc9e3130f79fdcd3e207ecb0ea70c0e1bcf1 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Wed, 6 May 2009 23:42:24 +0300 Subject: [PATCH 07/12] vo_vdpau: Move things to context struct --- libvo/vo_vdpau.c | 511 ++++++++++++++++++++++++----------------------- 1 file changed, 257 insertions(+), 254 deletions(-) diff --git a/libvo/vo_vdpau.c b/libvo/vo_vdpau.c index 3db31dbb08..219a64cfbc 100644 --- a/libvo/vo_vdpau.c +++ b/libvo/vo_vdpau.c @@ -91,57 +91,55 @@ struct vdp_functions { struct vdpctx { struct vdp_functions *vdp; + + VdpDevice vdp_device; + VdpDeviceCreateX11 *vdp_device_create; + VdpGetProcAddress *vdp_get_proc_address; + + VdpPresentationQueueTarget flip_target; + VdpPresentationQueue flip_queue; + + void *vdpau_lib_handle; + + /* output_surfaces[NUM_OUTPUT_SURFACES] is misused for OSD. */ +#define osd_surface vc->output_surfaces[NUM_OUTPUT_SURFACES] + VdpOutputSurface output_surfaces[NUM_OUTPUT_SURFACES + 1]; + VdpVideoSurface deint_surfaces[3]; + mp_image_t *deint_mpi[2]; + int output_surface_width, output_surface_height; + + VdpVideoMixer video_mixer; + int deint; + int deint_type; + int deint_counter; + int deint_buffer_past_frames; + int pullup; + float denoise; + float sharpen; + int chroma_deint; + int top_field_first; + + VdpDecoder decoder; + int decoder_max_refs; + + VdpRect src_rect_vid; + VdpRect out_rect_vid; + int border_x, border_y; + + struct vdpau_render_state surface_render[MAX_VIDEO_SURFACES]; + int surface_num; + int vid_surface_num; + uint32_t vid_width, vid_height; + uint32_t image_format; + VdpChromaType vdp_chroma_type; + VdpYCbCrFormat vdp_pixel_format; + + /* draw_osd */ + unsigned char *index_data; + int index_data_size; + uint32_t palette[PALETTE_SIZE]; }; -/* Declaration for all variables of win_x11_init_vdpau_procs() and - * win_x11_init_vdpau_flip_queue() functions - */ -static VdpDevice vdp_device; -static VdpDeviceCreateX11 *vdp_device_create; -static VdpGetProcAddress *vdp_get_proc_address; - -static VdpPresentationQueueTarget vdp_flip_target; -static VdpPresentationQueue vdp_flip_queue; - -static void *vdpau_lib_handle; -/* output_surfaces[NUM_OUTPUT_SURFACES] is misused for OSD. */ -#define osd_surface output_surfaces[NUM_OUTPUT_SURFACES] -static VdpOutputSurface output_surfaces[NUM_OUTPUT_SURFACES + 1]; -static VdpVideoSurface deint_surfaces[3]; -static mp_image_t *deint_mpi[2]; -static int output_surface_width, output_surface_height; - -static VdpVideoMixer video_mixer; -static int deint; -static int deint_type; -static int deint_counter; -static int deint_buffer_past_frames; -static int pullup; -static float denoise; -static float sharpen; -static int chroma_deint; -static int top_field_first; - -static VdpDecoder decoder; -static int decoder_max_refs; - -static VdpRect src_rect_vid; -static VdpRect out_rect_vid; -static int border_x, border_y; - -static struct vdpau_render_state surface_render[MAX_VIDEO_SURFACES]; -static int surface_num; -static int vid_surface_num; -static uint32_t vid_width, vid_height; -static uint32_t image_format; -static VdpChromaType vdp_chroma_type; -static VdpYCbCrFormat vdp_pixel_format; - -/* draw_osd */ -static unsigned char *index_data; -static int index_data_size; -static uint32_t palette[PALETTE_SIZE]; - // EOSD // Pool of surfaces struct { @@ -171,11 +169,12 @@ static VdpProcamp procamp; static int visible_buf; static int int_pause; -static void push_deint_surface(VdpVideoSurface surface) +static void push_deint_surface(struct vo *vo, VdpVideoSurface surface) { - deint_surfaces[2] = deint_surfaces[1]; - deint_surfaces[1] = deint_surfaces[0]; - deint_surfaces[0] = surface; + struct vdpctx *vc = vo->priv; + vc->deint_surfaces[2] = vc->deint_surfaces[1]; + vc->deint_surfaces[1] = vc->deint_surfaces[0]; + vc->deint_surfaces[0] = surface; } static void flip_page(struct vo *vo); @@ -186,13 +185,13 @@ static void video_to_output_surface(struct vo *vo) VdpTime dummy; VdpStatus vdp_st; int i; - if (vid_surface_num < 0) + if (vc->vid_surface_num < 0) return; - if (deint < 2 || deint_surfaces[0] == VDP_INVALID_HANDLE) - push_deint_surface(surface_render[vid_surface_num].surface); + if (vc->deint < 2 || vc->deint_surfaces[0] == VDP_INVALID_HANDLE) + push_deint_surface(vo, vc->surface_render[vc->vid_surface_num].surface); - for (i = 0; i <= !!(deint > 1); i++) { + for (i = 0; i <= !!(vc->deint > 1); i++) { int field = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME; VdpOutputSurface output_surface; if (i) { @@ -200,25 +199,25 @@ static void video_to_output_surface(struct vo *vo) //draw_osd(vo, NULL); flip_page(vo); } - if (deint) - field = (top_field_first == i) ^ (deint > 1) ? + if (vc->deint) + field = (vc->top_field_first == i) ^ (vc->deint > 1) ? VDP_VIDEO_MIXER_PICTURE_STRUCTURE_BOTTOM_FIELD: VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD; - output_surface = output_surfaces[surface_num]; - vdp_st = vdp->presentation_queue_block_until_surface_idle(vdp_flip_queue, + output_surface = vc->output_surfaces[vc->surface_num]; + vdp_st = vdp->presentation_queue_block_until_surface_idle(vc->flip_queue, output_surface, &dummy); CHECK_ST_WARNING("Error when calling vdp->presentation_queue_block_until_surface_idle") - vdp_st = vdp->video_mixer_render(video_mixer, VDP_INVALID_HANDLE, 0, - field, 2, deint_surfaces + 1, - deint_surfaces[0], - 1, &surface_render[vid_surface_num].surface, - &src_rect_vid, + vdp_st = vdp->video_mixer_render(vc->video_mixer, VDP_INVALID_HANDLE, 0, + field, 2, vc->deint_surfaces + 1, + vc->deint_surfaces[0], + 1, &vc->surface_render[vc->vid_surface_num].surface, + &vc->src_rect_vid, output_surface, - NULL, &out_rect_vid, 0, NULL); + NULL, &vc->out_rect_vid, 0, NULL); CHECK_ST_WARNING("Error when calling vdp_video_mixer_render") - push_deint_surface(surface_render[vid_surface_num].surface); + push_deint_surface(vo, vc->surface_render[vc->vid_surface_num].surface); } } @@ -231,42 +230,42 @@ static void resize(struct vo *vo) struct vo_rect src_rect; struct vo_rect dst_rect; struct vo_rect borders; - calc_src_dst_rects(vo, vid_width, vid_height, &src_rect, &dst_rect, + calc_src_dst_rects(vo, vc->vid_width, vc->vid_height, &src_rect, &dst_rect, &borders, NULL); - out_rect_vid.x0 = dst_rect.left; - out_rect_vid.x1 = dst_rect.right; - out_rect_vid.y0 = dst_rect.top; - out_rect_vid.y1 = dst_rect.bottom; - src_rect_vid.x0 = src_rect.left; - src_rect_vid.x1 = src_rect.right; - src_rect_vid.y0 = src_rect.top; - src_rect_vid.y1 = src_rect.bottom; - border_x = borders.left; - border_y = borders.top; + vc->out_rect_vid.x0 = dst_rect.left; + vc->out_rect_vid.x1 = dst_rect.right; + vc->out_rect_vid.y0 = dst_rect.top; + vc->out_rect_vid.y1 = dst_rect.bottom; + vc->src_rect_vid.x0 = src_rect.left; + vc->src_rect_vid.x1 = src_rect.right; + vc->src_rect_vid.y0 = src_rect.top; + vc->src_rect_vid.y1 = src_rect.bottom; + vc->border_x = borders.left; + vc->border_y = borders.top; #ifdef CONFIG_FREETYPE // adjust font size to display size force_load_font = 1; #endif vo_osd_changed(OSDTYPE_OSD); - if (output_surface_width < vo->dwidth || output_surface_height < vo->dheight) { - if (output_surface_width < vo->dwidth) { - output_surface_width += output_surface_width >> 1; - output_surface_width = FFMAX(output_surface_width, vo->dwidth); + if (vc->output_surface_width < vo->dwidth || vc->output_surface_height < vo->dheight) { + if (vc->output_surface_width < vo->dwidth) { + vc->output_surface_width += vc->output_surface_width >> 1; + vc->output_surface_width = FFMAX(vc->output_surface_width, vo->dwidth); } - if (output_surface_height < vo->dheight) { - output_surface_height += output_surface_height >> 1; - output_surface_height = FFMAX(output_surface_height, vo->dheight); + if (vc->output_surface_height < vo->dheight) { + vc->output_surface_height += vc->output_surface_height >> 1; + vc->output_surface_height = FFMAX(vc->output_surface_height, vo->dheight); } // Creation of output_surfaces for (i = 0; i <= NUM_OUTPUT_SURFACES; i++) { - if (output_surfaces[i] != VDP_INVALID_HANDLE) - vdp->output_surface_destroy(output_surfaces[i]); - vdp_st = vdp->output_surface_create(vdp_device, VDP_RGBA_FORMAT_B8G8R8A8, - output_surface_width, output_surface_height, - &output_surfaces[i]); + if (vc->output_surfaces[i] != VDP_INVALID_HANDLE) + vdp->output_surface_destroy(vc->output_surfaces[i]); + vdp_st = vdp->output_surface_create(vc->vdp_device, VDP_RGBA_FORMAT_B8G8R8A8, + vc->output_surface_width, vc->output_surface_height, + &vc->output_surfaces[i]); CHECK_ST_WARNING("Error when calling vdp->output_surface_create") - mp_msg(MSGT_VO, MSGL_DBG2, "OUT CREATE: %u\n", output_surfaces[i]); + mp_msg(MSGT_VO, MSGL_DBG2, "OUT CREATE: %u\n", vc->output_surfaces[i]); } } video_to_output_surface(vo); @@ -297,8 +296,8 @@ static int win_x11_init_vdpau_procs(struct vo *vo) {0, -1} }; - vdp_st = vdp_device_create(x11->display, x11->screen, - &vdp_device, &vdp_get_proc_address); + vdp_st = vc->vdp_device_create(x11->display, x11->screen, + &vc->vdp_device, &vc->vdp_get_proc_address); if (vdp_st != VDP_STATUS_OK) { mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Error when calling vdp_device_create_x11: %i\n", vdp_st); return -1; @@ -306,7 +305,7 @@ static int win_x11_init_vdpau_procs(struct vo *vo) vdp->get_error_string = NULL; for (dsc = vdp_func; dsc->offset >= 0; dsc++) { - vdp_st = vdp_get_proc_address(vdp_device, dsc->id, + vdp_st = vc->vdp_get_proc_address(vc->vdp_device, dsc->id, (void **)((char *)vdp + dsc->offset)); if (vdp_st != VDP_STATUS_OK) { 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) : "?"); @@ -324,12 +323,12 @@ static int win_x11_init_vdpau_flip_queue(struct vo *vo) struct vo_x11_state *x11 = vo->x11; VdpStatus vdp_st; - vdp_st = vdp->presentation_queue_target_create_x11(vdp_device, x11->window, - &vdp_flip_target); + vdp_st = vdp->presentation_queue_target_create_x11(vc->vdp_device, x11->window, + &vc->flip_target); CHECK_ST_ERROR("Error when calling vdp->presentation_queue_target_create_x11") - vdp_st = vdp->presentation_queue_create(vdp_device, vdp_flip_target, - &vdp_flip_queue); + vdp_st = vdp->presentation_queue_create(vc->vdp_device, vc->flip_target, + &vc->flip_queue); CHECK_ST_ERROR("Error when calling vdp->presentation_queue_create") return 0; @@ -347,9 +346,9 @@ static int create_vdp_mixer(struct vo *vo, VdpChromaType vdp_chroma_type) VdpVideoMixerFeature features[MAX_NUM_FEATURES]; VdpBool feature_enables[MAX_NUM_FEATURES]; static const VdpVideoMixerAttribute denoise_attrib[] = {VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL}; - const void * const denoise_value[] = {&denoise}; + const void * const denoise_value[] = {&vc->denoise}; static const VdpVideoMixerAttribute sharpen_attrib[] = {VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL}; - const void * const sharpen_value[] = {&sharpen}; + const void * const sharpen_value[] = {&vc->sharpen}; static const VdpVideoMixerAttribute skip_chroma_attrib[] = {VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE}; const uint8_t skip_chroma_value = 1; const void * const skip_chroma_value_ptr[] = {&skip_chroma_value}; @@ -359,37 +358,37 @@ static int create_vdp_mixer(struct vo *vo, VdpChromaType vdp_chroma_type) VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE }; const void *const parameter_values[VDP_NUM_MIXER_PARAMETER] = { - &vid_width, - &vid_height, + &vc->vid_width, + &vc->vid_height, &vdp_chroma_type }; features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL; - if (deint == 4) + if (vc->deint == 4) features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL; - if (pullup) + if (vc->pullup) features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE; - if (denoise) + if (vc->denoise) features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION; - if (sharpen) + if (vc->sharpen) features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_SHARPNESS; - vdp_st = vdp->video_mixer_create(vdp_device, feature_count, features, + vdp_st = vdp->video_mixer_create(vc->vdp_device, feature_count, features, VDP_NUM_MIXER_PARAMETER, parameters, parameter_values, - &video_mixer); + &vc->video_mixer); CHECK_ST_ERROR("Error when calling vdp_video_mixer_create") for (i = 0; i < feature_count; i++) feature_enables[i] = VDP_TRUE; - if (deint < 3) + if (vc->deint < 3) feature_enables[0] = VDP_FALSE; if (feature_count) - vdp->video_mixer_set_feature_enables(video_mixer, feature_count, features, feature_enables); - if (denoise) - vdp->video_mixer_set_attribute_values(video_mixer, 1, denoise_attrib, denoise_value); - if (sharpen) - vdp->video_mixer_set_attribute_values(video_mixer, 1, sharpen_attrib, sharpen_value); - if (!chroma_deint) - vdp->video_mixer_set_attribute_values(video_mixer, 1, skip_chroma_attrib, skip_chroma_value_ptr); + vdp->video_mixer_set_feature_enables(vc->video_mixer, feature_count, features, feature_enables); + if (vc->denoise) + vdp->video_mixer_set_attribute_values(vc->video_mixer, 1, denoise_attrib, denoise_value); + if (vc->sharpen) + vdp->video_mixer_set_attribute_values(vc->video_mixer, 1, sharpen_attrib, sharpen_value); + if (!vc->chroma_deint) + vdp->video_mixer_set_attribute_values(vc->video_mixer, 1, skip_chroma_attrib, skip_chroma_value_ptr); return 0; } @@ -402,33 +401,33 @@ static void free_video_specific(struct vo *vo) int i; VdpStatus vdp_st; - if (decoder != VDP_INVALID_HANDLE) - vdp->decoder_destroy(decoder); - decoder = VDP_INVALID_HANDLE; - decoder_max_refs = -1; + if (vc->decoder != VDP_INVALID_HANDLE) + vdp->decoder_destroy(vc->decoder); + vc->decoder = VDP_INVALID_HANDLE; + vc->decoder_max_refs = -1; for (i = 0; i < 3; i++) - deint_surfaces[i] = VDP_INVALID_HANDLE; + vc->deint_surfaces[i] = VDP_INVALID_HANDLE; for (i = 0; i < 2; i++) - if (deint_mpi[i]) { - deint_mpi[i]->usage_count--; - deint_mpi[i] = NULL; + if (vc->deint_mpi[i]) { + vc->deint_mpi[i]->usage_count--; + vc->deint_mpi[i] = NULL; } for (i = 0; i < MAX_VIDEO_SURFACES; i++) { - if (surface_render[i].surface != VDP_INVALID_HANDLE) { - vdp_st = vdp->video_surface_destroy(surface_render[i].surface); + if (vc->surface_render[i].surface != VDP_INVALID_HANDLE) { + vdp_st = vdp->video_surface_destroy(vc->surface_render[i].surface); CHECK_ST_WARNING("Error when calling vdp_video_surface_destroy") } - surface_render[i].surface = VDP_INVALID_HANDLE; + vc->surface_render[i].surface = VDP_INVALID_HANDLE; } - if (video_mixer != VDP_INVALID_HANDLE) { - vdp_st = vdp->video_mixer_destroy(video_mixer); + if (vc->video_mixer != VDP_INVALID_HANDLE) { + vdp_st = vdp->video_mixer_destroy(vc->video_mixer); CHECK_ST_WARNING("Error when calling vdp_video_mixer_destroy") } - video_mixer = VDP_INVALID_HANDLE; + vc->video_mixer = VDP_INVALID_HANDLE; } static int create_vdp_decoder(struct vo *vo, int max_refs) @@ -437,9 +436,9 @@ static int create_vdp_decoder(struct vo *vo, int max_refs) struct vdp_functions *vdp = vc->vdp; VdpStatus vdp_st; VdpDecoderProfile vdp_decoder_profile; - if (decoder != VDP_INVALID_HANDLE) - vdp->decoder_destroy(decoder); - switch (image_format) { + if (vc->decoder != VDP_INVALID_HANDLE) + vdp->decoder_destroy(vc->decoder); + switch (vc->image_format) { case IMGFMT_VDPAU_MPEG1: vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG1; break; @@ -457,15 +456,15 @@ static int create_vdp_decoder(struct vo *vo, int max_refs) vdp_decoder_profile = VDP_DECODER_PROFILE_VC1_ADVANCED; break; } - vdp_st = vdp->decoder_create(vdp_device, vdp_decoder_profile, - vid_width, vid_height, max_refs, &decoder); + vdp_st = vdp->decoder_create(vc->vdp_device, vdp_decoder_profile, + vc->vid_width, vc->vid_height, max_refs, &vc->decoder); CHECK_ST_WARNING("Failed creating VDPAU decoder"); if (vdp_st != VDP_STATUS_OK) { - decoder = VDP_INVALID_HANDLE; - decoder_max_refs = 0; + vc->decoder = VDP_INVALID_HANDLE; + vc->decoder_max_refs = 0; return 0; } - decoder_max_refs = max_refs; + vc->decoder_max_refs = max_refs; return 1; } @@ -477,6 +476,7 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) { + struct vdpctx *vc = vo->priv; struct vo_x11_state *x11 = vo->x11; XVisualInfo vinfo; XSetWindowAttributes xswa; @@ -488,11 +488,11 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, int vm = flags & VOFLAG_MODESWITCHING; #endif - image_format = format; - vid_width = width; - vid_height = height; + vc->image_format = format; + vc->vid_width = width; + vc->vid_height = height; free_video_specific(vo); - if (IMGFMT_IS_VDPAU(image_format) && !create_vdp_decoder(vo, 2)) + if (IMGFMT_IS_VDPAU(vc->image_format) && !create_vdp_decoder(vo, 2)) return -1; visible_buf = 0; @@ -536,33 +536,33 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, vo_fs = 1; /* -----VDPAU related code here -------- */ - if (vdp_flip_queue == VDP_INVALID_HANDLE + if (vc->flip_queue == VDP_INVALID_HANDLE && win_x11_init_vdpau_flip_queue(vo)) return -1; - vdp_chroma_type = VDP_CHROMA_TYPE_420; - switch (image_format) { + vc->vdp_chroma_type = VDP_CHROMA_TYPE_420; + switch (vc->image_format) { case IMGFMT_YV12: case IMGFMT_I420: case IMGFMT_IYUV: - vdp_pixel_format = VDP_YCBCR_FORMAT_YV12; + vc->vdp_pixel_format = VDP_YCBCR_FORMAT_YV12; break; case IMGFMT_NV12: - vdp_pixel_format = VDP_YCBCR_FORMAT_NV12; + vc->vdp_pixel_format = VDP_YCBCR_FORMAT_NV12; break; case IMGFMT_YUY2: - vdp_pixel_format = VDP_YCBCR_FORMAT_YUYV; - vdp_chroma_type = VDP_CHROMA_TYPE_422; + vc->vdp_pixel_format = VDP_YCBCR_FORMAT_YUYV; + vc->vdp_chroma_type = VDP_CHROMA_TYPE_422; break; case IMGFMT_UYVY: - vdp_pixel_format = VDP_YCBCR_FORMAT_UYVY; - vdp_chroma_type = VDP_CHROMA_TYPE_422; + vc->vdp_pixel_format = VDP_YCBCR_FORMAT_UYVY; + vc->vdp_chroma_type = VDP_CHROMA_TYPE_422; } - if (create_vdp_mixer(vo, vdp_chroma_type)) + if (create_vdp_mixer(vo, vc->vdp_chroma_type)) return -1; - surface_num = 0; - vid_surface_num = -1; + vc->surface_num = 0; + vc->vid_surface_num = -1; resize(vo); return 0; @@ -583,8 +583,8 @@ static void check_events(struct vo *vo) if (visible_buf) { /* redraw the last visible buffer */ VdpStatus vdp_st; - vdp_st = vdp->presentation_queue_display(vdp_flip_queue, - output_surfaces[surface_num], + vdp_st = vdp->presentation_queue_display(vc->flip_queue, + vc->output_surfaces[vc->surface_num], vo->dwidth, vo->dheight, 0); CHECK_ST_WARNING("Error when calling vdp->presentation_queue_display") @@ -598,7 +598,7 @@ static void draw_osd_I8A8(void *ctx, int x0, int y0, int w, int h, struct vo *vo = ctx; struct vdpctx *vc = vo->priv; struct vdp_functions *vdp = vc->vdp; - VdpOutputSurface output_surface = output_surfaces[surface_num]; + VdpOutputSurface output_surface = vc->output_surfaces[vc->surface_num]; VdpStatus vdp_st; int i, j; int pitch; @@ -610,16 +610,16 @@ static void draw_osd_I8A8(void *ctx, int x0, int y0, int w, int h, return; index_data_size_required = 2*w*h; - if (index_data_size < index_data_size_required) { - index_data = realloc(index_data, index_data_size_required); - index_data_size = index_data_size_required; + if (vc->index_data_size < index_data_size_required) { + vc->index_data = realloc(vc->index_data, index_data_size_required); + vc->index_data_size = index_data_size_required; } // index_data creation, component order - I, A, I, A, ..... for (i = 0; i < h; i++) for (j = 0; j < w; j++) { - index_data[i*2*w + j*2] = src [i*stride+j]; - index_data[i*2*w + j*2 + 1] = -srca[i*stride+j]; + vc->index_data[i*2*w + j*2] = src [i*stride+j]; + vc->index_data[i*2*w + j*2 + 1] = -srca[i*stride+j]; } output_indexed_rect_vid.x0 = x0; @@ -632,11 +632,11 @@ static void draw_osd_I8A8(void *ctx, int x0, int y0, int w, int h, // write source_data to osd_surface. vdp_st = vdp->output_surface_put_bits_indexed(osd_surface, VDP_INDEXED_FORMAT_I8A8, - (const void *const*)&index_data, + (const void *const*)&vc->index_data, &pitch, &output_indexed_rect_vid, VDP_COLOR_TABLE_FORMAT_B8G8R8X8, - (void *)palette); + (void *)vc->palette); CHECK_ST_WARNING("Error when calling vdp->output_surface_put_bits_indexed") blend_state.struct_version = VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION; @@ -662,7 +662,7 @@ static void draw_eosd(struct vo *vo) struct vdpctx *vc = vo->priv; struct vdp_functions *vdp = vc->vdp; VdpStatus vdp_st; - VdpOutputSurface output_surface = output_surfaces[surface_num]; + VdpOutputSurface output_surface = vc->output_surfaces[vc->surface_num]; VdpOutputSurfaceRenderBlendState blend_state; int i; @@ -739,7 +739,7 @@ static void generate_eosd(struct vo *vo, mp_eosd_images_t *imgs) eosd_surfaces[j].in_use = 0; } } - vdp_st = vdp->bitmap_surface_create(vdp_device, VDP_RGBA_FORMAT_A8, + vdp_st = vdp->bitmap_surface_create(vc->vdp_device, VDP_RGBA_FORMAT_A8, i->w, i->h, VDP_TRUE, &eosd_surfaces[found].surface); CHECK_ST_WARNING("EOSD: error when creating surface") eosd_surfaces[found].w = i->w; @@ -779,10 +779,11 @@ eosd_skip_upload: static void draw_osd(struct vo *vo, struct osd_state *osd) { + struct vdpctx *vc = vo->priv; mp_msg(MSGT_VO, MSGL_DBG2, "DRAW_OSD\n"); - osd_draw_text_ext(osd, vo->dwidth, vo->dheight, border_x, border_y, - border_x, border_y, vid_width, vid_height, + osd_draw_text_ext(osd, vo->dwidth, vo->dheight, vc->border_x, vc->border_y, + vc->border_x, vc->border_y, vc->vid_width, vc->vid_height, draw_osd_I8A8, vo); } @@ -792,14 +793,14 @@ static void flip_page(struct vo *vo) struct vdp_functions *vdp = vc->vdp; VdpStatus vdp_st; mp_msg(MSGT_VO, MSGL_DBG2, "\nFLIP_PAGE VID:%u -> OUT:%u\n", - surface_render[vid_surface_num].surface, output_surfaces[surface_num]); + vc->surface_render[vc->vid_surface_num].surface, vc->output_surfaces[vc->surface_num]); - vdp_st = vdp->presentation_queue_display(vdp_flip_queue, output_surfaces[surface_num], + vdp_st = vdp->presentation_queue_display(vc->flip_queue, vc->output_surfaces[vc->surface_num], vo->dwidth, vo->dheight, 0); CHECK_ST_WARNING("Error when calling vdp->presentation_queue_display") - surface_num = (surface_num + 1) % NUM_OUTPUT_SURFACES; + vc->surface_num = (vc->surface_num + 1) % NUM_OUTPUT_SURFACES; visible_buf = 1; } @@ -810,14 +811,14 @@ static int draw_slice(struct vo *vo, uint8_t *image[], int stride[], int w, struct vdp_functions *vdp = vc->vdp; VdpStatus vdp_st; struct vdpau_render_state *rndr = (struct vdpau_render_state *)image[0]; - int max_refs = image_format == IMGFMT_VDPAU_H264 ? rndr->info.h264.num_ref_frames : 2; - if (!IMGFMT_IS_VDPAU(image_format)) + int max_refs = vc->image_format == IMGFMT_VDPAU_H264 ? rndr->info.h264.num_ref_frames : 2; + if (!IMGFMT_IS_VDPAU(vc->image_format)) return VO_FALSE; - if ((decoder == VDP_INVALID_HANDLE || decoder_max_refs < max_refs) + if ((vc->decoder == VDP_INVALID_HANDLE || vc->decoder_max_refs < max_refs) && !create_vdp_decoder(vo, max_refs)) return VO_FALSE; - vdp_st = vdp->decoder_render(decoder, rndr->surface, (void *)&rndr->info, rndr->bitstream_buffers_used, rndr->bitstream_buffers); + vdp_st = vdp->decoder_render(vc->decoder, rndr->surface, (void *)&rndr->info, rndr->bitstream_buffers_used, rndr->bitstream_buffers); CHECK_ST_WARNING("Failed VDPAU decoder rendering"); return VO_TRUE; } @@ -835,17 +836,17 @@ static struct vdpau_render_state *get_surface(struct vo *vo, int number) if (number > MAX_VIDEO_SURFACES) return NULL; - if (surface_render[number].surface == VDP_INVALID_HANDLE) { + if (vc->surface_render[number].surface == VDP_INVALID_HANDLE) { VdpStatus vdp_st; - vdp_st = vdp->video_surface_create(vdp_device, vdp_chroma_type, - vid_width, vid_height, - &surface_render[number].surface); + vdp_st = vdp->video_surface_create(vc->vdp_device, vc->vdp_chroma_type, + vc->vid_width, vc->vid_height, + &vc->surface_render[number].surface); CHECK_ST_WARNING("Error when calling vdp_video_surface_create") if (vdp_st != VDP_STATUS_OK) return NULL; } - mp_msg(MSGT_VO, MSGL_DBG2, "VID CREATE: %u\n", surface_render[number].surface); - return &surface_render[number]; + mp_msg(MSGT_VO, MSGL_DBG2, "VID CREATE: %u\n", vc->surface_render[number].surface); + return &vc->surface_render[number]; } static uint32_t draw_image(struct vo *vo, mp_image_t *mpi) @@ -853,34 +854,34 @@ static uint32_t draw_image(struct vo *vo, mp_image_t *mpi) struct vdpctx *vc = vo->priv; struct vdp_functions *vdp = vc->vdp; - if (IMGFMT_IS_VDPAU(image_format)) { + if (IMGFMT_IS_VDPAU(vc->image_format)) { struct vdpau_render_state *rndr = mpi->priv; - vid_surface_num = rndr - surface_render; - if (deint_buffer_past_frames) { + vc->vid_surface_num = rndr - vc->surface_render; + if (vc->deint_buffer_past_frames) { mpi->usage_count++; - if (deint_mpi[1]) - deint_mpi[1]->usage_count--; - deint_mpi[1] = deint_mpi[0]; - deint_mpi[0] = mpi; + if (vc->deint_mpi[1]) + vc->deint_mpi[1]->usage_count--; + vc->deint_mpi[1] = vc->deint_mpi[0]; + vc->deint_mpi[0] = mpi; } } else if (!(mpi->flags & MP_IMGFLAG_DRAW_CALLBACK)) { VdpStatus vdp_st; void *destdata[3] = {mpi->planes[0], mpi->planes[2], mpi->planes[1]}; - struct vdpau_render_state *rndr = get_surface(vo, deint_counter); - deint_counter = (deint_counter + 1) % 3; - vid_surface_num = rndr - surface_render; - if (image_format == IMGFMT_NV12) + struct vdpau_render_state *rndr = get_surface(vo, vc->deint_counter); + vc->deint_counter = (vc->deint_counter + 1) % 3; + vc->vid_surface_num = rndr - vc->surface_render; + if (vc->image_format == IMGFMT_NV12) destdata[1] = destdata[2]; vdp_st = vdp->video_surface_put_bits_y_cb_cr(rndr->surface, - vdp_pixel_format, + vc->vdp_pixel_format, (const void *const*)destdata, mpi->stride); // pitch CHECK_ST_ERROR("Error when calling vdp_video_surface_put_bits_y_cb_cr") } if (mpi->fields & MP_IMGFIELD_ORDERED) - top_field_first = !!(mpi->fields & MP_IMGFIELD_TOP_FIRST); + vc->top_field_first = !!(mpi->fields & MP_IMGFIELD_TOP_FIRST); else - top_field_first = 1; + vc->top_field_first = 1; video_to_output_surface(vo); return VO_TRUE; @@ -888,10 +889,11 @@ static uint32_t draw_image(struct vo *vo, mp_image_t *mpi) static uint32_t get_image(struct vo *vo, mp_image_t *mpi) { + struct vdpctx *vc = vo->priv; struct vdpau_render_state *rndr; // no dr for non-decoding for now - if (!IMGFMT_IS_VDPAU(image_format)) return VO_FALSE; + if (!IMGFMT_IS_VDPAU(vc->image_format)) return VO_FALSE; if (mpi->type != MP_IMGTYPE_NUMBERED) return VO_FALSE; rndr = get_surface(vo, mpi->number); @@ -941,15 +943,15 @@ static void destroy_vdpau_objects(struct vo *vo) free_video_specific(vo); - vdp_st = vdp->presentation_queue_destroy(vdp_flip_queue); + vdp_st = vdp->presentation_queue_destroy(vc->flip_queue); CHECK_ST_WARNING("Error when calling vdp->presentation_queue_destroy") - vdp_st = vdp->presentation_queue_target_destroy(vdp_flip_target); + vdp_st = vdp->presentation_queue_target_destroy(vc->flip_target); CHECK_ST_WARNING("Error when calling vdp->presentation_queue_target_destroy") for (i = 0; i <= NUM_OUTPUT_SURFACES; i++) { - vdp_st = vdp->output_surface_destroy(output_surfaces[i]); - output_surfaces[i] = VDP_INVALID_HANDLE; + vdp_st = vdp->output_surface_destroy(vc->output_surfaces[i]); + vc->output_surfaces[i] = VDP_INVALID_HANDLE; CHECK_ST_WARNING("Error when calling vdp->output_surface_destroy") } @@ -961,12 +963,14 @@ static void destroy_vdpau_objects(struct vo *vo) eosd_surfaces[i].surface = VDP_INVALID_HANDLE; } - vdp_st = vdp->device_destroy(vdp_device); + vdp_st = vdp->device_destroy(vc->vdp_device); CHECK_ST_WARNING("Error when calling vdp_device_destroy") } static void uninit(struct vo *vo) { + struct vdpctx *vc = vo->priv; + if (!vo->config_count) return; visible_buf = 0; @@ -974,8 +978,8 @@ static void uninit(struct vo *vo) /* Destroy all vdpau objects */ destroy_vdpau_objects(vo); - free(index_data); - index_data = NULL; + free(vc->index_data); + vc->index_data = NULL; free(eosd_surfaces); eosd_surfaces = NULL; @@ -987,18 +991,9 @@ static void uninit(struct vo *vo) #endif vo_x11_uninit(vo); - dlclose(vdpau_lib_handle); + dlclose(vc->vdpau_lib_handle); } -static const opt_t subopts[] = { - {"deint", OPT_ARG_INT, &deint, (opt_test_f)int_non_neg}, - {"chroma-deint", OPT_ARG_BOOL, &chroma_deint, NULL}, - {"pullup", OPT_ARG_BOOL, &pullup, NULL}, - {"denoise", OPT_ARG_FLOAT, &denoise, NULL}, - {"sharpen", OPT_ARG_FLOAT, &sharpen, NULL}, - {NULL} -}; - static const char help_msg[] = "\n-vo vdpau command line help:\n" "Example: mplayer -vo vdpau:deint=2\n" @@ -1027,34 +1022,42 @@ static int preinit(struct vo *vo, const char *arg) struct vdpctx *vc = talloc_zero(vo, struct vdpctx); vo->priv = vc; - deint = 0; - deint_type = 3; - deint_counter = 0; - deint_buffer_past_frames = 0; - deint_mpi[0] = deint_mpi[1] = NULL; - chroma_deint = 1; - pullup = 0; - denoise = 0; - sharpen = 0; + vc->deint = 0; + vc->deint_type = 3; + vc->deint_counter = 0; + vc->deint_buffer_past_frames = 0; + vc->deint_mpi[0] = vc->deint_mpi[1] = NULL; + vc->chroma_deint = 1; + vc->pullup = 0; + vc->denoise = 0; + vc->sharpen = 0; + const opt_t subopts[] = { + {"deint", OPT_ARG_INT, &vc->deint, (opt_test_f)int_non_neg}, + {"chroma-deint", OPT_ARG_BOOL, &vc->chroma_deint, NULL}, + {"pullup", OPT_ARG_BOOL, &vc->pullup, NULL}, + {"denoise", OPT_ARG_FLOAT, &vc->denoise, NULL}, + {"sharpen", OPT_ARG_FLOAT, &vc->sharpen, NULL}, + {NULL} + }; if (subopt_parse(arg, subopts) != 0) { mp_msg(MSGT_VO, MSGL_FATAL, help_msg); return -1; } - if (deint) - deint_type = deint; - if (deint > 1) - deint_buffer_past_frames = 1; + if (vc->deint) + vc->deint_type = vc->deint; + if (vc->deint > 1) + vc->deint_buffer_past_frames = 1; char *vdpaulibrary = "libvdpau.so.1"; char *vdpau_device_create = "vdp_device_create_x11"; - vdpau_lib_handle = dlopen(vdpaulibrary, RTLD_LAZY); - if (!vdpau_lib_handle) { + vc->vdpau_lib_handle = dlopen(vdpaulibrary, RTLD_LAZY); + if (!vc->vdpau_lib_handle) { mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Could not open dynamic library %s\n", vdpaulibrary); return -1; } - vdp_device_create = dlsym(vdpau_lib_handle, vdpau_device_create); - if (!vdp_device_create) { + vc->vdp_device_create = dlsym(vc->vdpau_lib_handle, vdpau_device_create); + if (!vc->vdp_device_create) { mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Could not find function %s in %s\n", vdpau_device_create, vdpaulibrary); return -1; @@ -1062,20 +1065,20 @@ static int preinit(struct vo *vo, const char *arg) if (!vo_init(vo) || win_x11_init_vdpau_procs(vo)) return -1; - decoder = VDP_INVALID_HANDLE; + vc->decoder = VDP_INVALID_HANDLE; for (i = 0; i < MAX_VIDEO_SURFACES; i++) - surface_render[i].surface = VDP_INVALID_HANDLE; - video_mixer = VDP_INVALID_HANDLE; + vc->surface_render[i].surface = VDP_INVALID_HANDLE; + vc->video_mixer = VDP_INVALID_HANDLE; for (i = 0; i <= NUM_OUTPUT_SURFACES; i++) - output_surfaces[i] = VDP_INVALID_HANDLE; - vdp_flip_queue = VDP_INVALID_HANDLE; - output_surface_width = output_surface_height = -1; + vc->output_surfaces[i] = VDP_INVALID_HANDLE; + vc->flip_queue = VDP_INVALID_HANDLE; + vc->output_surface_width = vc->output_surface_height = -1; // full grayscale palette. for (i = 0; i < PALETTE_SIZE; ++i) - palette[i] = (i << 16) | (i << 8) | i; - index_data = NULL; - index_data_size = 0; + vc->palette[i] = (i << 16) | (i << 8) | i; + vc->index_data = NULL; + vc->index_data_size = 0; eosd_surface_count = eosd_render_count = 0; eosd_surfaces = NULL; @@ -1130,7 +1133,7 @@ static int set_equalizer(struct vo *vo, const char *name, int value) vdp_st = vdp->generate_csc_matrix(&procamp, VDP_COLOR_STANDARD_ITUR_BT_601, &matrix); CHECK_ST_WARNING("Error when generating CSC matrix") - vdp_st = vdp->video_mixer_set_attribute_values(video_mixer, 1, attributes, + vdp_st = vdp->video_mixer_set_attribute_values(vc->video_mixer, 1, attributes, attribute_values); CHECK_ST_WARNING("Error when setting CSC matrix") return VO_TRUE; @@ -1143,24 +1146,24 @@ static int control(struct vo *vo, uint32_t request, void *data) switch (request) { case VOCTRL_GET_DEINTERLACE: - *(int*)data = deint; + *(int*)data = vc->deint; return VO_TRUE; case VOCTRL_SET_DEINTERLACE: - deint = *(int*)data; - if (deint) - deint = deint_type; - if (deint_type > 2) { + vc->deint = *(int*)data; + if (vc->deint) + vc->deint = vc->deint_type; + if (vc->deint_type > 2) { VdpStatus vdp_st; VdpVideoMixerFeature features[1] = - {deint_type == 3 ? + {vc->deint_type == 3 ? VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL : VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL}; - VdpBool feature_enables[1] = {deint ? VDP_TRUE : VDP_FALSE}; - vdp_st = vdp->video_mixer_set_feature_enables(video_mixer, 1, - features, - feature_enables); + VdpBool feature_enables[1] = {vc->deint ? VDP_TRUE : VDP_FALSE}; + vdp_st = vdp->video_mixer_set_feature_enables(vc->video_mixer, + 1, features, + feature_enables); CHECK_ST_WARNING("Error changing deinterlacing settings") - deint_buffer_past_frames = 1; + vc->deint_buffer_past_frames = 1; } return VO_TRUE; case VOCTRL_PAUSE: @@ -1213,8 +1216,8 @@ static int control(struct vo *vo, uint32_t request, void *data) if (vo_fs) { r->w = vo->opts->vo_screenwidth; r->h = vo->opts->vo_screenheight; - r->ml = r->mr = border_x; - r->mt = r->mb = border_y; + r->ml = r->mr = vc->border_x; + r->mt = r->mb = vc->border_y; } else { r->w = vo->dwidth; r->h = vo->dheight; From 7d79dd972dd26080322e194c7969b35950b1181a Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Wed, 6 May 2009 23:49:51 +0300 Subject: [PATCH 08/12] vo_vdpau: Move all remaining static/global variables to context --- libvo/vo_vdpau.c | 206 +++++++++++++++++++++++------------------------ 1 file changed, 103 insertions(+), 103 deletions(-) diff --git a/libvo/vo_vdpau.c b/libvo/vo_vdpau.c index 219a64cfbc..7b85341933 100644 --- a/libvo/vo_vdpau.c +++ b/libvo/vo_vdpau.c @@ -34,6 +34,8 @@ #include #include +#include +#include #include "config.h" #include "mp_msg.h" @@ -138,36 +140,34 @@ struct vdpctx { unsigned char *index_data; int index_data_size; uint32_t palette[PALETTE_SIZE]; + + // EOSD + // Pool of surfaces + struct { + VdpBitmapSurface surface; + int w; + int h; + char in_use; + } *eosd_surfaces; + + // List of surfaces to be rendered + struct { + VdpBitmapSurface surface; + VdpRect source; + VdpRect dest; + VdpColor color; + } *eosd_targets; + + int eosd_render_count; + int eosd_surface_count; + + // Video equalizer + VdpProcamp procamp; + + bool visible_buf; + bool paused; }; -// EOSD -// Pool of surfaces -struct { - VdpBitmapSurface surface; - int w; - int h; - char in_use; -} *eosd_surfaces; - -// List of surfaces to be rendered -struct { - VdpBitmapSurface surface; - VdpRect source; - VdpRect dest; - VdpColor color; -} *eosd_targets; - -static int eosd_render_count; -static int eosd_surface_count; - -// Video equalizer -static VdpProcamp procamp; - -/* - * X11 specific - */ -static int visible_buf; -static int int_pause; static void push_deint_surface(struct vo *vo, VdpVideoSurface surface) { @@ -269,7 +269,7 @@ static void resize(struct vo *vo) } } video_to_output_surface(vo); - if (visible_buf) + if (vc->visible_buf) flip_page(vo); } @@ -495,7 +495,7 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, if (IMGFMT_IS_VDPAU(vc->image_format) && !create_vdp_decoder(vo, 2)) return -1; - visible_buf = 0; + vc->visible_buf = false; { #ifdef CONFIG_XF86VM @@ -578,9 +578,9 @@ static void check_events(struct vo *vo) if (e & VO_EVENT_RESIZE) resize(vo); - if ((e & VO_EVENT_EXPOSE || e & VO_EVENT_RESIZE) && int_pause) { + if ((e & VO_EVENT_EXPOSE || e & VO_EVENT_RESIZE) && vc->paused) { /* did we already draw a buffer */ - if (visible_buf) { + if (vc->visible_buf) { /* redraw the last visible buffer */ VdpStatus vdp_st; vdp_st = vdp->presentation_queue_display(vc->flip_queue, @@ -674,11 +674,11 @@ static void draw_eosd(struct vo *vo) blend_state.blend_equation_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD; blend_state.blend_equation_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD; - for (i=0; ieosd_render_count; i++) { vdp_st = vdp->output_surface_render_bitmap_surface( - output_surface, &eosd_targets[i].dest, - eosd_targets[i].surface, &eosd_targets[i].source, - &eosd_targets[i].color, &blend_state, + output_surface, &vc->eosd_targets[i].dest, + vc->eosd_targets[i].surface, &vc->eosd_targets[i].source, + &vc->eosd_targets[i].color, &blend_state, VDP_OUTPUT_SURFACE_RENDER_ROTATE_0); CHECK_ST_WARNING("EOSD: Error when rendering") } @@ -697,7 +697,7 @@ static void generate_eosd(struct vo *vo, mp_eosd_images_t *imgs) // Nothing changed, no need to redraw if (imgs->changed == 0) return; - eosd_render_count = 0; + vc->eosd_render_count = 0; // There's nothing to render! if (!img) return; @@ -705,75 +705,75 @@ static void generate_eosd(struct vo *vo, mp_eosd_images_t *imgs) if (imgs->changed == 1) goto eosd_skip_upload; - for (j=0; jeosd_surface_count; j++) + vc->eosd_surfaces[j].in_use = 0; for (i = img; i; i = i->next) { // Try to reuse a suitable surface found = -1; - for (j=0; j= i->w && eosd_surfaces[j].h >= i->h) { + for (j=0; jeosd_surface_count; j++) { + if (vc->eosd_surfaces[j].surface != VDP_INVALID_HANDLE && !vc->eosd_surfaces[j].in_use && + vc->eosd_surfaces[j].w >= i->w && vc->eosd_surfaces[j].h >= i->h) { found = j; break; } } // None found, allocate a new surface if (found < 0) { - for (j=0; jbitmap_surface_destroy(eosd_surfaces[j].surface); + for (j=0; jeosd_surface_count; j++) { + if (!vc->eosd_surfaces[j].in_use) { + if (vc->eosd_surfaces[j].surface != VDP_INVALID_HANDLE) + vdp->bitmap_surface_destroy(vc->eosd_surfaces[j].surface); found = j; break; } } // Allocate new space for surface/target arrays if (found < 0) { - j = found = eosd_surface_count; - eosd_surface_count = eosd_surface_count ? eosd_surface_count*2 : EOSD_SURFACES_INITIAL; - eosd_surfaces = realloc(eosd_surfaces, eosd_surface_count * sizeof(*eosd_surfaces)); - eosd_targets = realloc(eosd_targets, eosd_surface_count * sizeof(*eosd_targets)); - for(j=found; jeosd_surface_count; + vc->eosd_surface_count = vc->eosd_surface_count ? vc->eosd_surface_count*2 : EOSD_SURFACES_INITIAL; + vc->eosd_surfaces = realloc(vc->eosd_surfaces, vc->eosd_surface_count * sizeof(*vc->eosd_surfaces)); + vc->eosd_targets = realloc(vc->eosd_targets, vc->eosd_surface_count * sizeof(*vc->eosd_targets)); + for(j=found; jeosd_surface_count; j++) { + vc->eosd_surfaces[j].surface = VDP_INVALID_HANDLE; + vc->eosd_surfaces[j].in_use = 0; } } vdp_st = vdp->bitmap_surface_create(vc->vdp_device, VDP_RGBA_FORMAT_A8, - i->w, i->h, VDP_TRUE, &eosd_surfaces[found].surface); + i->w, i->h, VDP_TRUE, &vc->eosd_surfaces[found].surface); CHECK_ST_WARNING("EOSD: error when creating surface") - eosd_surfaces[found].w = i->w; - eosd_surfaces[found].h = i->h; + vc->eosd_surfaces[found].w = i->w; + vc->eosd_surfaces[found].h = i->h; } - eosd_surfaces[found].in_use = 1; - eosd_targets[eosd_render_count].surface = eosd_surfaces[found].surface; + vc->eosd_surfaces[found].in_use = 1; + vc->eosd_targets[vc->eosd_render_count].surface = vc->eosd_surfaces[found].surface; destRect.x0 = 0; destRect.y0 = 0; destRect.x1 = i->w; destRect.y1 = i->h; - vdp_st = vdp->bitmap_surface_put_bits_native(eosd_targets[eosd_render_count].surface, + vdp_st = vdp->bitmap_surface_put_bits_native(vc->eosd_targets[vc->eosd_render_count].surface, (const void *) &i->bitmap, &i->stride, &destRect); CHECK_ST_WARNING("EOSD: putbits failed") - eosd_render_count++; + vc->eosd_render_count++; } eosd_skip_upload: - eosd_render_count = 0; + vc->eosd_render_count = 0; for (i = img; i; i = i->next) { // Render dest, color, etc. - eosd_targets[eosd_render_count].color.alpha = 1.0 - ((i->color >> 0) & 0xff) / 255.0; - eosd_targets[eosd_render_count].color.blue = ((i->color >> 8) & 0xff) / 255.0; - eosd_targets[eosd_render_count].color.green = ((i->color >> 16) & 0xff) / 255.0; - eosd_targets[eosd_render_count].color.red = ((i->color >> 24) & 0xff) / 255.0; - eosd_targets[eosd_render_count].dest.x0 = i->dst_x; - eosd_targets[eosd_render_count].dest.y0 = i->dst_y; - eosd_targets[eosd_render_count].dest.x1 = i->w + i->dst_x; - eosd_targets[eosd_render_count].dest.y1 = i->h + i->dst_y; - eosd_targets[eosd_render_count].source.x0 = 0; - eosd_targets[eosd_render_count].source.y0 = 0; - eosd_targets[eosd_render_count].source.x1 = i->w; - eosd_targets[eosd_render_count].source.y1 = i->h; - eosd_render_count++; + vc->eosd_targets[vc->eosd_render_count].color.alpha = 1.0 - ((i->color >> 0) & 0xff) / 255.0; + vc->eosd_targets[vc->eosd_render_count].color.blue = ((i->color >> 8) & 0xff) / 255.0; + vc->eosd_targets[vc->eosd_render_count].color.green = ((i->color >> 16) & 0xff) / 255.0; + vc->eosd_targets[vc->eosd_render_count].color.red = ((i->color >> 24) & 0xff) / 255.0; + vc->eosd_targets[vc->eosd_render_count].dest.x0 = i->dst_x; + vc->eosd_targets[vc->eosd_render_count].dest.y0 = i->dst_y; + vc->eosd_targets[vc->eosd_render_count].dest.x1 = i->w + i->dst_x; + vc->eosd_targets[vc->eosd_render_count].dest.y1 = i->h + i->dst_y; + vc->eosd_targets[vc->eosd_render_count].source.x0 = 0; + vc->eosd_targets[vc->eosd_render_count].source.y0 = 0; + vc->eosd_targets[vc->eosd_render_count].source.x1 = i->w; + vc->eosd_targets[vc->eosd_render_count].source.y1 = i->h; + vc->eosd_render_count++; } } @@ -801,7 +801,7 @@ static void flip_page(struct vo *vo) CHECK_ST_WARNING("Error when calling vdp->presentation_queue_display") vc->surface_num = (vc->surface_num + 1) % NUM_OUTPUT_SURFACES; - visible_buf = 1; + vc->visible_buf = true; } static int draw_slice(struct vo *vo, uint8_t *image[], int stride[], int w, @@ -955,12 +955,12 @@ static void destroy_vdpau_objects(struct vo *vo) CHECK_ST_WARNING("Error when calling vdp->output_surface_destroy") } - for (i = 0; ibitmap_surface_destroy(eosd_surfaces[i].surface); + for (i = 0; ieosd_surface_count; i++) { + if (vc->eosd_surfaces[i].surface != VDP_INVALID_HANDLE) { + vdp_st = vdp->bitmap_surface_destroy(vc->eosd_surfaces[i].surface); CHECK_ST_WARNING("Error when calling vdp->bitmap_surface_destroy") } - eosd_surfaces[i].surface = VDP_INVALID_HANDLE; + vc->eosd_surfaces[i].surface = VDP_INVALID_HANDLE; } vdp_st = vdp->device_destroy(vc->vdp_device); @@ -973,7 +973,7 @@ static void uninit(struct vo *vo) if (!vo->config_count) return; - visible_buf = 0; + vc->visible_buf = false; /* Destroy all vdpau objects */ destroy_vdpau_objects(vo); @@ -981,10 +981,10 @@ static void uninit(struct vo *vo) free(vc->index_data); vc->index_data = NULL; - free(eosd_surfaces); - eosd_surfaces = NULL; - free(eosd_targets); - eosd_targets = NULL; + free(vc->eosd_surfaces); + vc->eosd_surfaces = NULL; + free(vc->eosd_targets); + vc->eosd_targets = NULL; #ifdef CONFIG_XF86VM vo_vm_close(vo); @@ -1080,15 +1080,15 @@ static int preinit(struct vo *vo, const char *arg) vc->index_data = NULL; vc->index_data_size = 0; - eosd_surface_count = eosd_render_count = 0; - eosd_surfaces = NULL; - eosd_targets = NULL; + vc->eosd_surface_count = vc->eosd_render_count = 0; + vc->eosd_surfaces = NULL; + vc->eosd_targets = NULL; - procamp.struct_version = VDP_PROCAMP_VERSION; - procamp.brightness = 0.0; - procamp.contrast = 1.0; - procamp.saturation = 1.0; - procamp.hue = 0.0; + vc->procamp.struct_version = VDP_PROCAMP_VERSION; + vc->procamp.brightness = 0.0; + vc->procamp.contrast = 1.0; + vc->procamp.saturation = 1.0; + vc->procamp.hue = 0.0; return 0; } @@ -1098,13 +1098,13 @@ static int get_equalizer(struct vo *vo, const char *name, int *value) struct vdpctx *vc = vo->priv; if (!strcasecmp(name, "brightness")) - *value = procamp.brightness * 100; + *value = vc->procamp.brightness * 100; else if (!strcasecmp(name, "contrast")) - *value = (procamp.contrast-1.0) * 100; + *value = (vc->procamp.contrast-1.0) * 100; else if (!strcasecmp(name, "saturation")) - *value = (procamp.saturation-1.0) * 100; + *value = (vc->procamp.saturation-1.0) * 100; else if (!strcasecmp(name, "hue")) - *value = procamp.hue * 100 / M_PI; + *value = vc->procamp.hue * 100 / M_PI; else return VO_NOTIMPL; return VO_TRUE; @@ -1120,17 +1120,17 @@ static int set_equalizer(struct vo *vo, const char *name, int value) const void *attribute_values[] = {&matrix}; if (!strcasecmp(name, "brightness")) - procamp.brightness = value / 100.0; + vc->procamp.brightness = value / 100.0; else if (!strcasecmp(name, "contrast")) - procamp.contrast = value / 100.0 + 1.0; + vc->procamp.contrast = value / 100.0 + 1.0; else if (!strcasecmp(name, "saturation")) - procamp.saturation = value / 100.0 + 1.0; + vc->procamp.saturation = value / 100.0 + 1.0; else if (!strcasecmp(name, "hue")) - procamp.hue = value / 100.0 * M_PI; + vc->procamp.hue = value / 100.0 * M_PI; else return VO_NOTIMPL; - vdp_st = vdp->generate_csc_matrix(&procamp, VDP_COLOR_STANDARD_ITUR_BT_601, + vdp_st = vdp->generate_csc_matrix(&vc->procamp, VDP_COLOR_STANDARD_ITUR_BT_601, &matrix); CHECK_ST_WARNING("Error when generating CSC matrix") vdp_st = vdp->video_mixer_set_attribute_values(vc->video_mixer, 1, attributes, @@ -1167,9 +1167,9 @@ static int control(struct vo *vo, uint32_t request, void *data) } return VO_TRUE; case VOCTRL_PAUSE: - return (int_pause = 1); + return (vc->paused = true); case VOCTRL_RESUME: - return (int_pause = 0); + return (vc->paused = false); case VOCTRL_QUERY_FORMAT: return query_format(*(uint32_t *)data); case VOCTRL_GET_IMAGE: From e2e0d58407a94061e96d71cab42784b2d25bd5ee Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Fri, 8 May 2009 20:57:22 +0300 Subject: [PATCH 09/12] vo_vdpau: Make CHECK_ST macro safer Also contains a couple of changes in destroy_vdpau_objects. --- libvo/vo_vdpau.c | 92 +++++++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 41 deletions(-) diff --git a/libvo/vo_vdpau.c b/libvo/vo_vdpau.c index 7b85341933..48d8931c76 100644 --- a/libvo/vo_vdpau.c +++ b/libvo/vo_vdpau.c @@ -60,16 +60,20 @@ #include "libass/ass_mp.h" #define CHECK_ST_ERROR(message) \ - if (vdp_st != VDP_STATUS_OK) { \ - mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] %s: %s\n", \ - message, vdp->get_error_string(vdp_st)); \ - return -1; \ - } + do { \ + if (vdp_st != VDP_STATUS_OK) { \ + mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] %s: %s\n", \ + message, vdp->get_error_string(vdp_st)); \ + return -1; \ + } \ + } while (0) #define CHECK_ST_WARNING(message) \ - if (vdp_st != VDP_STATUS_OK) \ - mp_msg(MSGT_VO, MSGL_WARN, "[vdpau] %s: %s\n", \ - message, vdp->get_error_string(vdp_st)); + do { \ + if (vdp_st != VDP_STATUS_OK) \ + mp_msg(MSGT_VO, MSGL_WARN, "[ vdpau] %s: %s\n", \ + message, vdp->get_error_string(vdp_st)); \ + } while (0) /* number of video and output surfaces */ #define NUM_OUTPUT_SURFACES 2 @@ -207,7 +211,7 @@ static void video_to_output_surface(struct vo *vo) vdp_st = vdp->presentation_queue_block_until_surface_idle(vc->flip_queue, output_surface, &dummy); - CHECK_ST_WARNING("Error when calling vdp->presentation_queue_block_until_surface_idle") + CHECK_ST_WARNING("Error when calling vdp->presentation_queue_block_until_surface_idle"); vdp_st = vdp->video_mixer_render(vc->video_mixer, VDP_INVALID_HANDLE, 0, field, 2, vc->deint_surfaces + 1, @@ -216,7 +220,7 @@ static void video_to_output_surface(struct vo *vo) &vc->src_rect_vid, output_surface, NULL, &vc->out_rect_vid, 0, NULL); - CHECK_ST_WARNING("Error when calling vdp_video_mixer_render") + CHECK_ST_WARNING("Error when calling vdp_video_mixer_render"); push_deint_surface(vo, vc->surface_render[vc->vid_surface_num].surface); } } @@ -264,7 +268,7 @@ static void resize(struct vo *vo) vdp_st = vdp->output_surface_create(vc->vdp_device, VDP_RGBA_FORMAT_B8G8R8A8, vc->output_surface_width, vc->output_surface_height, &vc->output_surfaces[i]); - CHECK_ST_WARNING("Error when calling vdp->output_surface_create") + CHECK_ST_WARNING("Error when calling vdp->output_surface_create"); mp_msg(MSGT_VO, MSGL_DBG2, "OUT CREATE: %u\n", vc->output_surfaces[i]); } } @@ -325,11 +329,11 @@ static int win_x11_init_vdpau_flip_queue(struct vo *vo) vdp_st = vdp->presentation_queue_target_create_x11(vc->vdp_device, x11->window, &vc->flip_target); - CHECK_ST_ERROR("Error when calling vdp->presentation_queue_target_create_x11") + CHECK_ST_ERROR("Error when calling vdp->presentation_queue_target_create_x11"); vdp_st = vdp->presentation_queue_create(vc->vdp_device, vc->flip_target, &vc->flip_queue); - CHECK_ST_ERROR("Error when calling vdp->presentation_queue_create") + CHECK_ST_ERROR("Error when calling vdp->presentation_queue_create"); return 0; } @@ -376,7 +380,7 @@ static int create_vdp_mixer(struct vo *vo, VdpChromaType vdp_chroma_type) VDP_NUM_MIXER_PARAMETER, parameters, parameter_values, &vc->video_mixer); - CHECK_ST_ERROR("Error when calling vdp_video_mixer_create") + CHECK_ST_ERROR("Error when calling vdp_video_mixer_create"); for (i = 0; i < feature_count; i++) feature_enables[i] = VDP_TRUE; if (vc->deint < 3) @@ -418,14 +422,14 @@ static void free_video_specific(struct vo *vo) for (i = 0; i < MAX_VIDEO_SURFACES; i++) { if (vc->surface_render[i].surface != VDP_INVALID_HANDLE) { vdp_st = vdp->video_surface_destroy(vc->surface_render[i].surface); - CHECK_ST_WARNING("Error when calling vdp_video_surface_destroy") + CHECK_ST_WARNING("Error when calling vdp_video_surface_destroy"); } vc->surface_render[i].surface = VDP_INVALID_HANDLE; } if (vc->video_mixer != VDP_INVALID_HANDLE) { vdp_st = vdp->video_mixer_destroy(vc->video_mixer); - CHECK_ST_WARNING("Error when calling vdp_video_mixer_destroy") + CHECK_ST_WARNING("Error when calling vdp_video_mixer_destroy"); } vc->video_mixer = VDP_INVALID_HANDLE; } @@ -587,7 +591,7 @@ static void check_events(struct vo *vo) vc->output_surfaces[vc->surface_num], vo->dwidth, vo->dheight, 0); - CHECK_ST_WARNING("Error when calling vdp->presentation_queue_display") + CHECK_ST_WARNING("Error when calling vdp->presentation_queue_display"); } } } @@ -637,7 +641,7 @@ static void draw_osd_I8A8(void *ctx, int x0, int y0, int w, int h, &output_indexed_rect_vid, VDP_COLOR_TABLE_FORMAT_B8G8R8X8, (void *)vc->palette); - CHECK_ST_WARNING("Error when calling vdp->output_surface_put_bits_indexed") + CHECK_ST_WARNING("Error when calling vdp->output_surface_put_bits_indexed"); blend_state.struct_version = VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION; blend_state.blend_factor_source_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE; @@ -654,7 +658,7 @@ static void draw_osd_I8A8(void *ctx, int x0, int y0, int w, int h, NULL, &blend_state, VDP_OUTPUT_SURFACE_RENDER_ROTATE_0); - CHECK_ST_WARNING("Error when calling vdp->output_surface_render_output_surface") + CHECK_ST_WARNING("Error when calling vdp->output_surface_render_output_surface"); } static void draw_eosd(struct vo *vo) @@ -680,7 +684,7 @@ static void draw_eosd(struct vo *vo) vc->eosd_targets[i].surface, &vc->eosd_targets[i].source, &vc->eosd_targets[i].color, &blend_state, VDP_OUTPUT_SURFACE_RENDER_ROTATE_0); - CHECK_ST_WARNING("EOSD: Error when rendering") + CHECK_ST_WARNING("EOSD: Error when rendering"); } } @@ -741,7 +745,7 @@ static void generate_eosd(struct vo *vo, mp_eosd_images_t *imgs) } vdp_st = vdp->bitmap_surface_create(vc->vdp_device, VDP_RGBA_FORMAT_A8, i->w, i->h, VDP_TRUE, &vc->eosd_surfaces[found].surface); - CHECK_ST_WARNING("EOSD: error when creating surface") + CHECK_ST_WARNING("EOSD: error when creating surface"); vc->eosd_surfaces[found].w = i->w; vc->eosd_surfaces[found].h = i->h; } @@ -753,7 +757,7 @@ static void generate_eosd(struct vo *vo, mp_eosd_images_t *imgs) destRect.y1 = i->h; vdp_st = vdp->bitmap_surface_put_bits_native(vc->eosd_targets[vc->eosd_render_count].surface, (const void *) &i->bitmap, &i->stride, &destRect); - CHECK_ST_WARNING("EOSD: putbits failed") + CHECK_ST_WARNING("EOSD: putbits failed"); vc->eosd_render_count++; } @@ -798,7 +802,7 @@ static void flip_page(struct vo *vo) vdp_st = vdp->presentation_queue_display(vc->flip_queue, vc->output_surfaces[vc->surface_num], vo->dwidth, vo->dheight, 0); - CHECK_ST_WARNING("Error when calling vdp->presentation_queue_display") + CHECK_ST_WARNING("Error when calling vdp->presentation_queue_display"); vc->surface_num = (vc->surface_num + 1) % NUM_OUTPUT_SURFACES; vc->visible_buf = true; @@ -841,7 +845,7 @@ static struct vdpau_render_state *get_surface(struct vo *vo, int number) vdp_st = vdp->video_surface_create(vc->vdp_device, vc->vdp_chroma_type, vc->vid_width, vc->vid_height, &vc->surface_render[number].surface); - CHECK_ST_WARNING("Error when calling vdp_video_surface_create") + CHECK_ST_WARNING("Error when calling vdp_video_surface_create"); if (vdp_st != VDP_STATUS_OK) return NULL; } @@ -876,7 +880,7 @@ static uint32_t draw_image(struct vo *vo, mp_image_t *mpi) vc->vdp_pixel_format, (const void *const*)destdata, mpi->stride); // pitch - CHECK_ST_ERROR("Error when calling vdp_video_surface_put_bits_y_cb_cr") + CHECK_ST_ERROR("Error when calling vdp_video_surface_put_bits_y_cb_cr"); } if (mpi->fields & MP_IMGFIELD_ORDERED) vc->top_field_first = !!(mpi->fields & MP_IMGFIELD_TOP_FIRST); @@ -943,28 +947,34 @@ static void destroy_vdpau_objects(struct vo *vo) free_video_specific(vo); - vdp_st = vdp->presentation_queue_destroy(vc->flip_queue); - CHECK_ST_WARNING("Error when calling vdp->presentation_queue_destroy") + if (vc->flip_queue != VDP_INVALID_HANDLE) { + vdp_st = vdp->presentation_queue_destroy(vc->flip_queue); + CHECK_ST_WARNING("Error when calling vdp->presentation_queue_destroy"); + } - vdp_st = vdp->presentation_queue_target_destroy(vc->flip_target); - CHECK_ST_WARNING("Error when calling vdp->presentation_queue_target_destroy") + if (vc->flip_target != VDP_INVALID_HANDLE) { + vdp_st = vdp->presentation_queue_target_destroy(vc->flip_target); + CHECK_ST_WARNING("Error when calling vdp->presentation_queue_target_destroy"); + } for (i = 0; i <= NUM_OUTPUT_SURFACES; i++) { + if (vc->output_surfaces[i] == VDP_INVALID_HANDLE) + continue; vdp_st = vdp->output_surface_destroy(vc->output_surfaces[i]); - vc->output_surfaces[i] = VDP_INVALID_HANDLE; - CHECK_ST_WARNING("Error when calling vdp->output_surface_destroy") + CHECK_ST_WARNING("Error when calling vdp->output_surface_destroy"); } for (i = 0; ieosd_surface_count; i++) { - if (vc->eosd_surfaces[i].surface != VDP_INVALID_HANDLE) { - vdp_st = vdp->bitmap_surface_destroy(vc->eosd_surfaces[i].surface); - CHECK_ST_WARNING("Error when calling vdp->bitmap_surface_destroy") - } - vc->eosd_surfaces[i].surface = VDP_INVALID_HANDLE; + if (vc->eosd_surfaces[i].surface == VDP_INVALID_HANDLE) + continue; + vdp_st = vdp->bitmap_surface_destroy(vc->eosd_surfaces[i].surface); + CHECK_ST_WARNING("Error when calling vdp->bitmap_surface_destroy"); } - vdp_st = vdp->device_destroy(vc->vdp_device); - CHECK_ST_WARNING("Error when calling vdp_device_destroy") + if (vc->vdp_device != VDP_INVALID_HANDLE) { + vdp_st = vdp->device_destroy(vc->vdp_device); + CHECK_ST_WARNING("Error when calling vdp_device_destroy"); + } } static void uninit(struct vo *vo) @@ -1132,10 +1142,10 @@ static int set_equalizer(struct vo *vo, const char *name, int value) vdp_st = vdp->generate_csc_matrix(&vc->procamp, VDP_COLOR_STANDARD_ITUR_BT_601, &matrix); - CHECK_ST_WARNING("Error when generating CSC matrix") + CHECK_ST_WARNING("Error when generating CSC matrix"); vdp_st = vdp->video_mixer_set_attribute_values(vc->video_mixer, 1, attributes, attribute_values); - CHECK_ST_WARNING("Error when setting CSC matrix") + CHECK_ST_WARNING("Error when setting CSC matrix"); return VO_TRUE; } @@ -1162,7 +1172,7 @@ static int control(struct vo *vo, uint32_t request, void *data) vdp_st = vdp->video_mixer_set_feature_enables(vc->video_mixer, 1, features, feature_enables); - CHECK_ST_WARNING("Error changing deinterlacing settings") + CHECK_ST_WARNING("Error changing deinterlacing settings"); vc->deint_buffer_past_frames = 1; } return VO_TRUE; From fa860a7ffa80ebdd1361971780ea01d85746c01f Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Fri, 8 May 2009 21:48:01 +0300 Subject: [PATCH 10/12] vo_vpdau: Clean up uninit logic --- libvo/vo_vdpau.c | 106 ++++++++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 52 deletions(-) diff --git a/libvo/vo_vdpau.c b/libvo/vo_vdpau.c index 48d8931c76..5264a4d7ee 100644 --- a/libvo/vo_vdpau.c +++ b/libvo/vo_vdpau.c @@ -151,7 +151,7 @@ struct vdpctx { VdpBitmapSurface surface; int w; int h; - char in_use; + bool in_use; } *eosd_surfaces; // List of surfaces to be rendered @@ -170,6 +170,9 @@ struct vdpctx { bool visible_buf; bool paused; + + // These tell what's been initialized and uninit() should free/uninitialize + bool mode_switched; }; @@ -301,7 +304,7 @@ static int win_x11_init_vdpau_procs(struct vo *vo) }; vdp_st = vc->vdp_device_create(x11->display, x11->screen, - &vc->vdp_device, &vc->vdp_get_proc_address); + &vc->vdp_device, &vc->vdp_get_proc_address); if (vdp_st != VDP_STATUS_OK) { mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Error when calling vdp_device_create_x11: %i\n", vdp_st); return -1; @@ -503,9 +506,10 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, { #ifdef CONFIG_XF86VM - if (vm) + if (vm) { vo_vm_switch(vo); - else + vc->mode_switched = true; + } #endif XGetWindowAttributes(x11->display, DefaultRootWindow(x11->display), &attribs); @@ -615,7 +619,8 @@ static void draw_osd_I8A8(void *ctx, int x0, int y0, int w, int h, index_data_size_required = 2*w*h; if (vc->index_data_size < index_data_size_required) { - vc->index_data = realloc(vc->index_data, index_data_size_required); + vc->index_data = talloc_realloc_size(vc, vc->index_data, + index_data_size_required); vc->index_data_size = index_data_size_required; } @@ -710,7 +715,7 @@ static void generate_eosd(struct vo *vo, mp_eosd_images_t *imgs) goto eosd_skip_upload; for (j=0; jeosd_surface_count; j++) - vc->eosd_surfaces[j].in_use = 0; + vc->eosd_surfaces[j].in_use = false; for (i = img; i; i = i->next) { // Try to reuse a suitable surface @@ -724,7 +729,7 @@ static void generate_eosd(struct vo *vo, mp_eosd_images_t *imgs) } // None found, allocate a new surface if (found < 0) { - for (j=0; jeosd_surface_count; j++) { + for (j = 0; j < vc->eosd_surface_count; j++) { if (!vc->eosd_surfaces[j].in_use) { if (vc->eosd_surfaces[j].surface != VDP_INVALID_HANDLE) vdp->bitmap_surface_destroy(vc->eosd_surfaces[j].surface); @@ -736,20 +741,25 @@ static void generate_eosd(struct vo *vo, mp_eosd_images_t *imgs) if (found < 0) { j = found = vc->eosd_surface_count; vc->eosd_surface_count = vc->eosd_surface_count ? vc->eosd_surface_count*2 : EOSD_SURFACES_INITIAL; - vc->eosd_surfaces = realloc(vc->eosd_surfaces, vc->eosd_surface_count * sizeof(*vc->eosd_surfaces)); - vc->eosd_targets = realloc(vc->eosd_targets, vc->eosd_surface_count * sizeof(*vc->eosd_targets)); - for(j=found; jeosd_surface_count; j++) { + vc->eosd_surfaces = talloc_realloc_size(vc, vc->eosd_surfaces, + vc->eosd_surface_count + * sizeof(*vc->eosd_surfaces)); + vc->eosd_targets = talloc_realloc_size(vc, vc->eosd_targets, + vc->eosd_surface_count + * sizeof(*vc->eosd_targets)); + for(j = found; j < vc->eosd_surface_count; j++) { vc->eosd_surfaces[j].surface = VDP_INVALID_HANDLE; - vc->eosd_surfaces[j].in_use = 0; + vc->eosd_surfaces[j].in_use = false; } } - vdp_st = vdp->bitmap_surface_create(vc->vdp_device, VDP_RGBA_FORMAT_A8, + vdp_st = vdp->bitmap_surface_create(vc->vdp_device, + VDP_RGBA_FORMAT_A8, i->w, i->h, VDP_TRUE, &vc->eosd_surfaces[found].surface); CHECK_ST_WARNING("EOSD: error when creating surface"); vc->eosd_surfaces[found].w = i->w; vc->eosd_surfaces[found].h = i->h; } - vc->eosd_surfaces[found].in_use = 1; + vc->eosd_surfaces[found].in_use = true; vc->eosd_targets[vc->eosd_render_count].surface = vc->eosd_surfaces[found].surface; destRect.x0 = 0; destRect.y0 = 0; @@ -964,40 +974,27 @@ static void destroy_vdpau_objects(struct vo *vo) CHECK_ST_WARNING("Error when calling vdp->output_surface_destroy"); } - for (i = 0; ieosd_surface_count; i++) { + for (i = 0; i < vc->eosd_surface_count; i++) { if (vc->eosd_surfaces[i].surface == VDP_INVALID_HANDLE) continue; vdp_st = vdp->bitmap_surface_destroy(vc->eosd_surfaces[i].surface); CHECK_ST_WARNING("Error when calling vdp->bitmap_surface_destroy"); } - if (vc->vdp_device != VDP_INVALID_HANDLE) { - vdp_st = vdp->device_destroy(vc->vdp_device); - CHECK_ST_WARNING("Error when calling vdp_device_destroy"); - } + vdp_st = vdp->device_destroy(vc->vdp_device); + CHECK_ST_WARNING("Error when calling vdp_device_destroy"); } static void uninit(struct vo *vo) { struct vdpctx *vc = vo->priv; - if (!vo->config_count) - return; - vc->visible_buf = false; - /* Destroy all vdpau objects */ destroy_vdpau_objects(vo); - free(vc->index_data); - vc->index_data = NULL; - - free(vc->eosd_surfaces); - vc->eosd_surfaces = NULL; - free(vc->eosd_targets); - vc->eosd_targets = NULL; - #ifdef CONFIG_XF86VM - vo_vm_close(vo); + if (vc->mode_switched) + vo_vm_close(vo); #endif vo_x11_uninit(vo); @@ -1032,15 +1029,20 @@ static int preinit(struct vo *vo, const char *arg) struct vdpctx *vc = talloc_zero(vo, struct vdpctx); vo->priv = vc; - vc->deint = 0; + // Mark everything as invalid first so uninit() can tell what has been + // allocated + vc->decoder = VDP_INVALID_HANDLE; + for (i = 0; i < MAX_VIDEO_SURFACES; i++) + vc->surface_render[i].surface = VDP_INVALID_HANDLE; + vc->video_mixer = VDP_INVALID_HANDLE; + vc->flip_queue = VDP_INVALID_HANDLE; + vc->flip_target = VDP_INVALID_HANDLE; + for (i = 0; i <= NUM_OUTPUT_SURFACES; i++) + vc->output_surfaces[i] = VDP_INVALID_HANDLE; + vc->vdp_device = VDP_INVALID_HANDLE; + vc->deint_type = 3; - vc->deint_counter = 0; - vc->deint_buffer_past_frames = 0; - vc->deint_mpi[0] = vc->deint_mpi[1] = NULL; vc->chroma_deint = 1; - vc->pullup = 0; - vc->denoise = 0; - vc->sharpen = 0; const opt_t subopts[] = { {"deint", OPT_ARG_INT, &vc->deint, (opt_test_f)int_non_neg}, {"chroma-deint", OPT_ARG_BOOL, &vc->chroma_deint, NULL}, @@ -1070,29 +1072,29 @@ static int preinit(struct vo *vo, const char *arg) if (!vc->vdp_device_create) { mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Could not find function %s in %s\n", vdpau_device_create, vdpaulibrary); + dlclose(vc->vdpau_lib_handle); return -1; } - if (!vo_init(vo) || win_x11_init_vdpau_procs(vo)) + if (!vo_init(vo)) { + dlclose(vc->vdpau_lib_handle); return -1; + } + + // After this calling uninit() should work to free resources + + if (win_x11_init_vdpau_procs(vo) < 0) { + if (vc->vdp->device_destroy) + vc->vdp->device_destroy(vc->vdp_device); + vo_x11_uninit(vo); + dlclose(vc->vdpau_lib_handle); + return -1; + } - vc->decoder = VDP_INVALID_HANDLE; - for (i = 0; i < MAX_VIDEO_SURFACES; i++) - vc->surface_render[i].surface = VDP_INVALID_HANDLE; - vc->video_mixer = VDP_INVALID_HANDLE; - for (i = 0; i <= NUM_OUTPUT_SURFACES; i++) - vc->output_surfaces[i] = VDP_INVALID_HANDLE; - vc->flip_queue = VDP_INVALID_HANDLE; vc->output_surface_width = vc->output_surface_height = -1; // full grayscale palette. for (i = 0; i < PALETTE_SIZE; ++i) vc->palette[i] = (i << 16) | (i << 8) | i; - vc->index_data = NULL; - vc->index_data_size = 0; - - vc->eosd_surface_count = vc->eosd_render_count = 0; - vc->eosd_surfaces = NULL; - vc->eosd_targets = NULL; vc->procamp.struct_version = VDP_PROCAMP_VERSION; vc->procamp.brightness = 0.0; From 3013f956dcb136a999cd474440ff3fdefaf631e9 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Fri, 8 May 2009 21:49:52 +0300 Subject: [PATCH 11/12] vo_vdpau: reindent after GUI code removal --- libvo/vo_vdpau.c | 64 +++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/libvo/vo_vdpau.c b/libvo/vo_vdpau.c index 5264a4d7ee..82a0a23d9f 100644 --- a/libvo/vo_vdpau.c +++ b/libvo/vo_vdpau.c @@ -504,41 +504,39 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, vc->visible_buf = false; - { #ifdef CONFIG_XF86VM - if (vm) { - vo_vm_switch(vo); - vc->mode_switched = true; - } -#endif - XGetWindowAttributes(x11->display, DefaultRootWindow(x11->display), - &attribs); - depth = attribs.depth; - if (depth != 15 && depth != 16 && depth != 24 && depth != 32) - depth = 24; - XMatchVisualInfo(x11->display, x11->screen, depth, TrueColor, &vinfo); - - xswa.background_pixel = 0; - xswa.border_pixel = 0; - /* Do not use CWBackPixel: It leads to VDPAU errors after - aspect ratio changes. */ - xswamask = CWBorderPixel; - - vo_x11_create_vo_window(vo, &vinfo, vo->dx, vo->dy, d_width, d_height, - flags, CopyFromParent, "vdpau", title); - XChangeWindowAttributes(x11->display, x11->window, xswamask, &xswa); - -#ifdef CONFIG_XF86VM - if (vm) { - /* Grab the mouse pointer in our window */ - if (vo_grabpointer) - XGrabPointer(x11->display, x11->window, True, 0, - GrabModeAsync, GrabModeAsync, - x11->window, None, CurrentTime); - XSetInputFocus(x11->display, x11->window, RevertToNone, CurrentTime); - } -#endif + if (vm) { + vo_vm_switch(vo); + vc->mode_switched = true; } +#endif + XGetWindowAttributes(x11->display, DefaultRootWindow(x11->display), + &attribs); + depth = attribs.depth; + if (depth != 15 && depth != 16 && depth != 24 && depth != 32) + depth = 24; + XMatchVisualInfo(x11->display, x11->screen, depth, TrueColor, &vinfo); + + xswa.background_pixel = 0; + xswa.border_pixel = 0; + /* Do not use CWBackPixel: It leads to VDPAU errors after + * aspect ratio changes. */ + xswamask = CWBorderPixel; + + vo_x11_create_vo_window(vo, &vinfo, vo->dx, vo->dy, d_width, d_height, + flags, CopyFromParent, "vdpau", title); + XChangeWindowAttributes(x11->display, x11->window, xswamask, &xswa); + +#ifdef CONFIG_XF86VM + if (vm) { + /* Grab the mouse pointer in our window */ + if (vo_grabpointer) + XGrabPointer(x11->display, x11->window, True, 0, + GrabModeAsync, GrabModeAsync, + x11->window, None, CurrentTime); + XSetInputFocus(x11->display, x11->window, RevertToNone, CurrentTime); + } +#endif if ((flags & VOFLAG_FULLSCREEN) && WinID <= 0) vo_fs = 1; From 84964c0dec03b4d7ba6e0b78a49273f7ca8a56ea Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Sat, 9 May 2009 18:08:30 +0300 Subject: [PATCH 12/12] vo_vdpau.c: cosmetics --- libvo/vo_vdpau.c | 450 +++++++++++++++++++++++++++-------------------- 1 file changed, 255 insertions(+), 195 deletions(-) diff --git a/libvo/vo_vdpau.c b/libvo/vo_vdpau.c index 82a0a23d9f..8750cd5871 100644 --- a/libvo/vo_vdpau.c +++ b/libvo/vo_vdpau.c @@ -20,16 +20,11 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -/** - * \defgroup VDPAU_Presentation VDPAU Presentation - * \ingroup Decoder - * +/* * Actual decoding and presentation are implemented here. * All necessary frame information is collected through * the "vdpau_render_state" structure after parsing all headers * etc. in libavcodec for different codecs. - * - * @{ */ #include @@ -155,7 +150,7 @@ struct vdpctx { } *eosd_surfaces; // List of surfaces to be rendered - struct { + struct eosd_target { VdpBitmapSurface surface; VdpRect source; VdpRect dest; @@ -198,31 +193,32 @@ static void video_to_output_surface(struct vo *vo) if (vc->deint < 2 || vc->deint_surfaces[0] == VDP_INVALID_HANDLE) push_deint_surface(vo, vc->surface_render[vc->vid_surface_num].surface); - for (i = 0; i <= !!(vc->deint > 1); i++) { + for (i = 0; i <= (vc->deint > 1); i++) { int field = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME; VdpOutputSurface output_surface; if (i) { - // draw_eosd(vo); - //draw_osd(vo, NULL); + // draw_eosd() + // draw_osd() flip_page(vo); } if (vc->deint) field = (vc->top_field_first == i) ^ (vc->deint > 1) ? - VDP_VIDEO_MIXER_PICTURE_STRUCTURE_BOTTOM_FIELD: - VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD; + VDP_VIDEO_MIXER_PICTURE_STRUCTURE_BOTTOM_FIELD: + VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD; output_surface = vc->output_surfaces[vc->surface_num]; - vdp_st = vdp->presentation_queue_block_until_surface_idle(vc->flip_queue, - output_surface, - &dummy); - CHECK_ST_WARNING("Error when calling vdp->presentation_queue_block_until_surface_idle"); + vdp_st = vdp-> + presentation_queue_block_until_surface_idle(vc->flip_queue, + output_surface, + &dummy); + CHECK_ST_WARNING("Error when calling " + "vdp_presentation_queue_block_until_surface_idle"); - vdp_st = vdp->video_mixer_render(vc->video_mixer, VDP_INVALID_HANDLE, 0, - field, 2, vc->deint_surfaces + 1, - vc->deint_surfaces[0], - 1, &vc->surface_render[vc->vid_surface_num].surface, - &vc->src_rect_vid, - output_surface, - NULL, &vc->out_rect_vid, 0, NULL); + vdp_st = vdp->video_mixer_render(vc->video_mixer, VDP_INVALID_HANDLE, + 0, field, 2, vc->deint_surfaces + 1, + vc->deint_surfaces[0], 1, + &vc->surface_render[vc->vid_surface_num].surface, + &vc->src_rect_vid, output_surface, + NULL, &vc->out_rect_vid, 0, NULL); CHECK_ST_WARNING("Error when calling vdp_video_mixer_render"); push_deint_surface(vo, vc->surface_render[vc->vid_surface_num].surface); } @@ -255,24 +251,30 @@ static void resize(struct vo *vo) #endif vo_osd_changed(OSDTYPE_OSD); - if (vc->output_surface_width < vo->dwidth || vc->output_surface_height < vo->dheight) { + if (vc->output_surface_width < vo->dwidth + || vc->output_surface_height < vo->dheight) { if (vc->output_surface_width < vo->dwidth) { vc->output_surface_width += vc->output_surface_width >> 1; - vc->output_surface_width = FFMAX(vc->output_surface_width, vo->dwidth); + vc->output_surface_width = FFMAX(vc->output_surface_width, + vo->dwidth); } if (vc->output_surface_height < vo->dheight) { vc->output_surface_height += vc->output_surface_height >> 1; - vc->output_surface_height = FFMAX(vc->output_surface_height, vo->dheight); + vc->output_surface_height = FFMAX(vc->output_surface_height, + vo->dheight); } // Creation of output_surfaces for (i = 0; i <= NUM_OUTPUT_SURFACES; i++) { if (vc->output_surfaces[i] != VDP_INVALID_HANDLE) vdp->output_surface_destroy(vc->output_surfaces[i]); - vdp_st = vdp->output_surface_create(vc->vdp_device, VDP_RGBA_FORMAT_B8G8R8A8, - vc->output_surface_width, vc->output_surface_height, - &vc->output_surfaces[i]); - CHECK_ST_WARNING("Error when calling vdp->output_surface_create"); - mp_msg(MSGT_VO, MSGL_DBG2, "OUT CREATE: %u\n", vc->output_surfaces[i]); + vdp_st = vdp->output_surface_create(vc->vdp_device, + VDP_RGBA_FORMAT_B8G8R8A8, + vc->output_surface_width, + vc->output_surface_height, + &vc->output_surfaces[i]); + CHECK_ST_WARNING("Error when calling vdp_output_surface_create"); + mp_msg(MSGT_VO, MSGL_DBG2, "OUT CREATE: %u\n", + vc->output_surfaces[i]); } } video_to_output_surface(vo); @@ -303,10 +305,11 @@ static int win_x11_init_vdpau_procs(struct vo *vo) {0, -1} }; - vdp_st = vc->vdp_device_create(x11->display, x11->screen, - &vc->vdp_device, &vc->vdp_get_proc_address); + vdp_st = vc->vdp_device_create(x11->display, x11->screen,&vc->vdp_device, + &vc->vdp_get_proc_address); if (vdp_st != VDP_STATUS_OK) { - mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Error when calling vdp_device_create_x11: %i\n", vdp_st); + mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Error when calling " + "vdp_device_create_x11: %i\n", vdp_st); return -1; } @@ -315,14 +318,15 @@ static int win_x11_init_vdpau_procs(struct vo *vo) vdp_st = vc->vdp_get_proc_address(vc->vdp_device, dsc->id, (void **)((char *)vdp + dsc->offset)); if (vdp_st != VDP_STATUS_OK) { - 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) : "?"); + 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) : "?"); return -1; } } return 0; } -/* Initialize vdpau_flip_queue, called from config() */ static int win_x11_init_vdpau_flip_queue(struct vo *vo) { struct vdpctx *vc = vo->priv; @@ -330,13 +334,15 @@ static int win_x11_init_vdpau_flip_queue(struct vo *vo) struct vo_x11_state *x11 = vo->x11; VdpStatus vdp_st; - vdp_st = vdp->presentation_queue_target_create_x11(vc->vdp_device, x11->window, - &vc->flip_target); - CHECK_ST_ERROR("Error when calling vdp->presentation_queue_target_create_x11"); + vdp_st = vdp->presentation_queue_target_create_x11(vc->vdp_device, + x11->window, + &vc->flip_target); + CHECK_ST_ERROR("Error when calling " + "vdp_presentation_queue_target_create_x11"); vdp_st = vdp->presentation_queue_create(vc->vdp_device, vc->flip_target, - &vc->flip_queue); - CHECK_ST_ERROR("Error when calling vdp->presentation_queue_create"); + &vc->flip_queue); + CHECK_ST_ERROR("Error when calling vdp_presentation_queue_create"); return 0; } @@ -352,26 +358,30 @@ static int create_vdp_mixer(struct vo *vo, VdpChromaType vdp_chroma_type) int feature_count = 0; VdpVideoMixerFeature features[MAX_NUM_FEATURES]; VdpBool feature_enables[MAX_NUM_FEATURES]; - static const VdpVideoMixerAttribute denoise_attrib[] = {VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL}; + static const VdpVideoMixerAttribute denoise_attrib[] = + {VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL}; const void * const denoise_value[] = {&vc->denoise}; - static const VdpVideoMixerAttribute sharpen_attrib[] = {VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL}; + static const VdpVideoMixerAttribute sharpen_attrib[] = + {VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL}; const void * const sharpen_value[] = {&vc->sharpen}; - static const VdpVideoMixerAttribute skip_chroma_attrib[] = {VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE}; + static const VdpVideoMixerAttribute skip_chroma_attrib[] = + {VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE}; const uint8_t skip_chroma_value = 1; const void * const skip_chroma_value_ptr[] = {&skip_chroma_value}; static const VdpVideoMixerParameter parameters[VDP_NUM_MIXER_PARAMETER] = { VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH, VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT, - VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE + VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE, }; const void *const parameter_values[VDP_NUM_MIXER_PARAMETER] = { &vc->vid_width, &vc->vid_height, - &vdp_chroma_type + &vdp_chroma_type, }; features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL; if (vc->deint == 4) - features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL; + features[feature_count++] = + VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL; if (vc->pullup) features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE; if (vc->denoise) @@ -380,22 +390,28 @@ static int create_vdp_mixer(struct vo *vo, VdpChromaType vdp_chroma_type) features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_SHARPNESS; vdp_st = vdp->video_mixer_create(vc->vdp_device, feature_count, features, - VDP_NUM_MIXER_PARAMETER, - parameters, parameter_values, - &vc->video_mixer); + VDP_NUM_MIXER_PARAMETER, + parameters, parameter_values, + &vc->video_mixer); CHECK_ST_ERROR("Error when calling vdp_video_mixer_create"); - for (i = 0; i < feature_count; i++) feature_enables[i] = VDP_TRUE; + for (i = 0; i < feature_count; i++) + feature_enables[i] = VDP_TRUE; if (vc->deint < 3) feature_enables[0] = VDP_FALSE; if (feature_count) - vdp->video_mixer_set_feature_enables(vc->video_mixer, feature_count, features, feature_enables); + vdp->video_mixer_set_feature_enables(vc->video_mixer, feature_count, + features, feature_enables); if (vc->denoise) - vdp->video_mixer_set_attribute_values(vc->video_mixer, 1, denoise_attrib, denoise_value); + vdp->video_mixer_set_attribute_values(vc->video_mixer, 1, + denoise_attrib, denoise_value); if (vc->sharpen) - vdp->video_mixer_set_attribute_values(vc->video_mixer, 1, sharpen_attrib, sharpen_value); + vdp->video_mixer_set_attribute_values(vc->video_mixer, 1, + sharpen_attrib, sharpen_value); if (!vc->chroma_deint) - vdp->video_mixer_set_attribute_values(vc->video_mixer, 1, skip_chroma_attrib, skip_chroma_value_ptr); + vdp->video_mixer_set_attribute_values(vc->video_mixer, 1, + skip_chroma_attrib, + skip_chroma_value_ptr); return 0; } @@ -424,8 +440,8 @@ static void free_video_specific(struct vo *vo) for (i = 0; i < MAX_VIDEO_SURFACES; i++) { if (vc->surface_render[i].surface != VDP_INVALID_HANDLE) { - vdp_st = vdp->video_surface_destroy(vc->surface_render[i].surface); - CHECK_ST_WARNING("Error when calling vdp_video_surface_destroy"); + vdp_st = vdp->video_surface_destroy(vc->surface_render[i].surface); + CHECK_ST_WARNING("Error when calling vdp_video_surface_destroy"); } vc->surface_render[i].surface = VDP_INVALID_HANDLE; } @@ -454,7 +470,8 @@ static int create_vdp_decoder(struct vo *vo, int max_refs) break; case IMGFMT_VDPAU_H264: vdp_decoder_profile = VDP_DECODER_PROFILE_H264_HIGH; - mp_msg(MSGT_VO, MSGL_V, "[vdpau] Creating H264 hardware decoder for %d reference frames.\n", max_refs); + mp_msg(MSGT_VO, MSGL_V, "[vdpau] Creating H264 hardware decoder " + "for %d reference frames.\n", max_refs); break; case IMGFMT_VDPAU_WMV3: vdp_decoder_profile = VDP_DECODER_PROFILE_VC1_MAIN; @@ -464,7 +481,8 @@ static int create_vdp_decoder(struct vo *vo, int max_refs) break; } vdp_st = vdp->decoder_create(vc->vdp_device, vdp_decoder_profile, - vc->vid_width, vc->vid_height, max_refs, &vc->decoder); + vc->vid_width, vc->vid_height, max_refs, + &vc->decoder); CHECK_ST_WARNING("Failed creating VDPAU decoder"); if (vdp_st != VDP_STATUS_OK) { vc->decoder = VDP_INVALID_HANDLE; @@ -590,10 +608,10 @@ static void check_events(struct vo *vo) /* redraw the last visible buffer */ VdpStatus vdp_st; vdp_st = vdp->presentation_queue_display(vc->flip_queue, - vc->output_surfaces[vc->surface_num], - vo->dwidth, vo->dheight, - 0); - CHECK_ST_WARNING("Error when calling vdp->presentation_queue_display"); + vc->output_surfaces[vc->surface_num], + vo->dwidth, vo->dheight, 0); + CHECK_ST_WARNING("Error when calling " + "vdp_presentation_queue_display"); } } } @@ -606,25 +624,24 @@ static void draw_osd_I8A8(void *ctx, int x0, int y0, int w, int h, struct vdp_functions *vdp = vc->vdp; VdpOutputSurface output_surface = vc->output_surfaces[vc->surface_num]; VdpStatus vdp_st; - int i, j; + int i; int pitch; int index_data_size_required; VdpRect output_indexed_rect_vid; - VdpOutputSurfaceRenderBlendState blend_state; if (!w || !h) return; index_data_size_required = 2*w*h; if (vc->index_data_size < index_data_size_required) { - vc->index_data = talloc_realloc_size(vc, vc->index_data, - index_data_size_required); + vc->index_data = talloc_realloc_size(vc, vc->index_data, + index_data_size_required); vc->index_data_size = index_data_size_required; } // index_data creation, component order - I, A, I, A, ..... for (i = 0; i < h; i++) - for (j = 0; j < w; j++) { + for (int j = 0; j < w; j++) { vc->index_data[i*2*w + j*2] = src [i*stride+j]; vc->index_data[i*2*w + j*2 + 1] = -srca[i*stride+j]; } @@ -637,31 +654,37 @@ static void draw_osd_I8A8(void *ctx, int x0, int y0, int w, int h, pitch = w*2; // write source_data to osd_surface. - vdp_st = vdp->output_surface_put_bits_indexed(osd_surface, - VDP_INDEXED_FORMAT_I8A8, - (const void *const*)&vc->index_data, - &pitch, - &output_indexed_rect_vid, - VDP_COLOR_TABLE_FORMAT_B8G8R8X8, - (void *)vc->palette); - CHECK_ST_WARNING("Error when calling vdp->output_surface_put_bits_indexed"); + vdp_st = vdp-> + output_surface_put_bits_indexed(osd_surface, VDP_INDEXED_FORMAT_I8A8, + (const void *const*)&vc->index_data, + &pitch, &output_indexed_rect_vid, + VDP_COLOR_TABLE_FORMAT_B8G8R8X8, + (void *)vc->palette); + CHECK_ST_WARNING("Error when calling vdp_output_surface_put_bits_indexed"); - blend_state.struct_version = VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION; - blend_state.blend_factor_source_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE; - blend_state.blend_factor_source_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE; - blend_state.blend_factor_destination_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; - blend_state.blend_factor_destination_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; - blend_state.blend_equation_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD; - blend_state.blend_equation_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD; + VdpOutputSurfaceRenderBlendState blend_state = { + .struct_version = VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION, + .blend_factor_source_color = + VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE, + .blend_factor_source_alpha = + VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE, + .blend_factor_destination_color = + VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, + .blend_factor_destination_alpha = + VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, + .blend_equation_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD, + .blend_equation_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD, + }; - vdp_st = vdp->output_surface_render_output_surface(output_surface, - &output_indexed_rect_vid, - osd_surface, - &output_indexed_rect_vid, - NULL, - &blend_state, - VDP_OUTPUT_SURFACE_RENDER_ROTATE_0); - CHECK_ST_WARNING("Error when calling vdp->output_surface_render_output_surface"); + vdp_st = vdp-> + output_surface_render_output_surface(output_surface, + &output_indexed_rect_vid, + osd_surface, + &output_indexed_rect_vid, + NULL, &blend_state, + VDP_OUTPUT_SURFACE_RENDER_ROTATE_0); + CHECK_ST_WARNING("Error when calling " + "vdp_output_surface_render_output_surface"); } static void draw_eosd(struct vo *vo) @@ -670,23 +693,31 @@ static void draw_eosd(struct vo *vo) struct vdp_functions *vdp = vc->vdp; VdpStatus vdp_st; VdpOutputSurface output_surface = vc->output_surfaces[vc->surface_num]; - VdpOutputSurfaceRenderBlendState blend_state; int i; - blend_state.struct_version = VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION; - blend_state.blend_factor_source_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_SRC_ALPHA; - blend_state.blend_factor_source_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE; - blend_state.blend_factor_destination_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; - blend_state.blend_factor_destination_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_SRC_ALPHA; - blend_state.blend_equation_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD; - blend_state.blend_equation_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD; + VdpOutputSurfaceRenderBlendState blend_state = { + .struct_version = VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION, + .blend_factor_source_color = + VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_SRC_ALPHA, + .blend_factor_source_alpha = + VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE, + .blend_factor_destination_color = + VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, + .blend_factor_destination_alpha = + VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_SRC_ALPHA, + .blend_equation_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD, + .blend_equation_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD, + }; - for (i=0; ieosd_render_count; i++) { - vdp_st = vdp->output_surface_render_bitmap_surface( - output_surface, &vc->eosd_targets[i].dest, - vc->eosd_targets[i].surface, &vc->eosd_targets[i].source, - &vc->eosd_targets[i].color, &blend_state, - VDP_OUTPUT_SURFACE_RENDER_ROTATE_0); + for (i = 0; i < vc->eosd_render_count; i++) { + vdp_st = vdp-> + output_surface_render_bitmap_surface(output_surface, + &vc->eosd_targets[i].dest, + vc->eosd_targets[i].surface, + &vc->eosd_targets[i].source, + &vc->eosd_targets[i].color, + &blend_state, + VDP_OUTPUT_SURFACE_RENDER_ROTATE_0); CHECK_ST_WARNING("EOSD: Error when rendering"); } } @@ -697,94 +728,104 @@ static void generate_eosd(struct vo *vo, mp_eosd_images_t *imgs) struct vdp_functions *vdp = vc->vdp; VdpStatus vdp_st; VdpRect destRect; - int j, found; + int i, found; ass_image_t *img = imgs->imgs; - ass_image_t *i; + ass_image_t *p; - // Nothing changed, no need to redraw if (imgs->changed == 0) - return; + return; // Nothing changed, no need to redraw + vc->eosd_render_count = 0; - // There's nothing to render! + if (!img) - return; + return; // There's nothing to render! if (imgs->changed == 1) goto eosd_skip_upload; - for (j=0; jeosd_surface_count; j++) - vc->eosd_surfaces[j].in_use = false; + for (i = 0; i < vc->eosd_surface_count; i++) + vc->eosd_surfaces[i].in_use = false; - for (i = img; i; i = i->next) { + int snum; + for (p = img, snum = 0; p; p = p->next, snum++) { // Try to reuse a suitable surface found = -1; - for (j=0; jeosd_surface_count; j++) { - if (vc->eosd_surfaces[j].surface != VDP_INVALID_HANDLE && !vc->eosd_surfaces[j].in_use && - vc->eosd_surfaces[j].w >= i->w && vc->eosd_surfaces[j].h >= i->h) { - found = j; + for (i = 0; i < vc->eosd_surface_count; i++) { + if (vc->eosd_surfaces[i].surface != VDP_INVALID_HANDLE + && !vc->eosd_surfaces[i].in_use + && vc->eosd_surfaces[i].w >= p->w + && vc->eosd_surfaces[i].h >= p->h) { + found = i; break; } } // None found, allocate a new surface if (found < 0) { - for (j = 0; j < vc->eosd_surface_count; j++) { - if (!vc->eosd_surfaces[j].in_use) { - if (vc->eosd_surfaces[j].surface != VDP_INVALID_HANDLE) - vdp->bitmap_surface_destroy(vc->eosd_surfaces[j].surface); - found = j; + for (i = 0; i < vc->eosd_surface_count; i++) { + if (!vc->eosd_surfaces[i].in_use) { + if (vc->eosd_surfaces[i].surface != VDP_INVALID_HANDLE) + vdp->bitmap_surface_destroy(vc->eosd_surfaces[i].surface); + found = i; break; } } // Allocate new space for surface/target arrays if (found < 0) { - j = found = vc->eosd_surface_count; - vc->eosd_surface_count = vc->eosd_surface_count ? vc->eosd_surface_count*2 : EOSD_SURFACES_INITIAL; - vc->eosd_surfaces = talloc_realloc_size(vc, vc->eosd_surfaces, - vc->eosd_surface_count - * sizeof(*vc->eosd_surfaces)); - vc->eosd_targets = talloc_realloc_size(vc, vc->eosd_targets, - vc->eosd_surface_count - * sizeof(*vc->eosd_targets)); - for(j = found; j < vc->eosd_surface_count; j++) { - vc->eosd_surfaces[j].surface = VDP_INVALID_HANDLE; - vc->eosd_surfaces[j].in_use = false; + i = found = vc->eosd_surface_count; + vc->eosd_surface_count = vc->eosd_surface_count ? + vc->eosd_surface_count * 2 : EOSD_SURFACES_INITIAL; + vc->eosd_surfaces = + talloc_realloc_size(vc, vc->eosd_surfaces, + vc->eosd_surface_count + * sizeof(*vc->eosd_surfaces)); + vc->eosd_targets = + talloc_realloc_size(vc, vc->eosd_targets, + vc->eosd_surface_count + * sizeof(*vc->eosd_targets)); + for(i = found; i < vc->eosd_surface_count; i++) { + vc->eosd_surfaces[i].surface = VDP_INVALID_HANDLE; + vc->eosd_surfaces[i].in_use = false; } } - vdp_st = vdp->bitmap_surface_create(vc->vdp_device, - VDP_RGBA_FORMAT_A8, - i->w, i->h, VDP_TRUE, &vc->eosd_surfaces[found].surface); + vdp_st = + vdp->bitmap_surface_create(vc->vdp_device, + VDP_RGBA_FORMAT_A8, + p->w, p->h, VDP_TRUE, + &vc->eosd_surfaces[found].surface); CHECK_ST_WARNING("EOSD: error when creating surface"); - vc->eosd_surfaces[found].w = i->w; - vc->eosd_surfaces[found].h = i->h; + vc->eosd_surfaces[found].w = p->w; + vc->eosd_surfaces[found].h = p->h; } vc->eosd_surfaces[found].in_use = true; - vc->eosd_targets[vc->eosd_render_count].surface = vc->eosd_surfaces[found].surface; + vc->eosd_targets[snum].surface = + vc->eosd_surfaces[found].surface; destRect.x0 = 0; destRect.y0 = 0; - destRect.x1 = i->w; - destRect.y1 = i->h; - vdp_st = vdp->bitmap_surface_put_bits_native(vc->eosd_targets[vc->eosd_render_count].surface, - (const void *) &i->bitmap, &i->stride, &destRect); + destRect.x1 = p->w; + destRect.y1 = p->h; + vdp_st = + vdp->bitmap_surface_put_bits_native(vc->eosd_targets[snum].surface, + (const void *) &p->bitmap, + &p->stride, &destRect); CHECK_ST_WARNING("EOSD: putbits failed"); - vc->eosd_render_count++; } eosd_skip_upload: - vc->eosd_render_count = 0; - for (i = img; i; i = i->next) { + for (p = img; p; p = p->next) { // Render dest, color, etc. - vc->eosd_targets[vc->eosd_render_count].color.alpha = 1.0 - ((i->color >> 0) & 0xff) / 255.0; - vc->eosd_targets[vc->eosd_render_count].color.blue = ((i->color >> 8) & 0xff) / 255.0; - vc->eosd_targets[vc->eosd_render_count].color.green = ((i->color >> 16) & 0xff) / 255.0; - vc->eosd_targets[vc->eosd_render_count].color.red = ((i->color >> 24) & 0xff) / 255.0; - vc->eosd_targets[vc->eosd_render_count].dest.x0 = i->dst_x; - vc->eosd_targets[vc->eosd_render_count].dest.y0 = i->dst_y; - vc->eosd_targets[vc->eosd_render_count].dest.x1 = i->w + i->dst_x; - vc->eosd_targets[vc->eosd_render_count].dest.y1 = i->h + i->dst_y; - vc->eosd_targets[vc->eosd_render_count].source.x0 = 0; - vc->eosd_targets[vc->eosd_render_count].source.y0 = 0; - vc->eosd_targets[vc->eosd_render_count].source.x1 = i->w; - vc->eosd_targets[vc->eosd_render_count].source.y1 = i->h; + struct eosd_target *target = &vc->eosd_targets[vc->eosd_render_count]; + target->color.alpha = 1.0 - ((p->color >> 0) & 0xff) / 255.0; + target->color.blue = ((p->color >> 8) & 0xff) / 255.0; + target->color.green = ((p->color >> 16) & 0xff) / 255.0; + target->color.red = ((p->color >> 24) & 0xff) / 255.0; + target->dest.x0 = p->dst_x; + target->dest.y0 = p->dst_y; + target->dest.x1 = p->w + p->dst_x; + target->dest.y1 = p->h + p->dst_y; + target->source.x0 = 0; + target->source.y0 = 0; + target->source.x1 = p->w; + target->source.y1 = p->h; vc->eosd_render_count++; } } @@ -795,8 +836,8 @@ static void draw_osd(struct vo *vo, struct osd_state *osd) mp_msg(MSGT_VO, MSGL_DBG2, "DRAW_OSD\n"); osd_draw_text_ext(osd, vo->dwidth, vo->dheight, vc->border_x, vc->border_y, - vc->border_x, vc->border_y, vc->vid_width, vc->vid_height, - draw_osd_I8A8, vo); + vc->border_x, vc->border_y, vc->vid_width, + vc->vid_height, draw_osd_I8A8, vo); } static void flip_page(struct vo *vo) @@ -804,13 +845,16 @@ static void flip_page(struct vo *vo) struct vdpctx *vc = vo->priv; struct vdp_functions *vdp = vc->vdp; VdpStatus vdp_st; - mp_msg(MSGT_VO, MSGL_DBG2, "\nFLIP_PAGE VID:%u -> OUT:%u\n", - vc->surface_render[vc->vid_surface_num].surface, vc->output_surfaces[vc->surface_num]); - vdp_st = vdp->presentation_queue_display(vc->flip_queue, vc->output_surfaces[vc->surface_num], - vo->dwidth, vo->dheight, - 0); - CHECK_ST_WARNING("Error when calling vdp->presentation_queue_display"); + mp_msg(MSGT_VO, MSGL_DBG2, "\nFLIP_PAGE VID:%u -> OUT:%u\n", + vc->surface_render[vc->vid_surface_num].surface, + vc->output_surfaces[vc->surface_num]); + + vdp_st = + vdp->presentation_queue_display(vc->flip_queue, + vc->output_surfaces[vc->surface_num], + vo->dwidth, vo->dheight, 0); + CHECK_ST_WARNING("Error when calling vdp_presentation_queue_display"); vc->surface_num = (vc->surface_num + 1) % NUM_OUTPUT_SURFACES; vc->visible_buf = true; @@ -823,14 +867,18 @@ static int draw_slice(struct vo *vo, uint8_t *image[], int stride[], int w, struct vdp_functions *vdp = vc->vdp; VdpStatus vdp_st; struct vdpau_render_state *rndr = (struct vdpau_render_state *)image[0]; - int max_refs = vc->image_format == IMGFMT_VDPAU_H264 ? rndr->info.h264.num_ref_frames : 2; + int max_refs = vc->image_format == IMGFMT_VDPAU_H264 ? + rndr->info.h264.num_ref_frames : 2; if (!IMGFMT_IS_VDPAU(vc->image_format)) return VO_FALSE; if ((vc->decoder == VDP_INVALID_HANDLE || vc->decoder_max_refs < max_refs) && !create_vdp_decoder(vo, max_refs)) return VO_FALSE; - - vdp_st = vdp->decoder_render(vc->decoder, rndr->surface, (void *)&rndr->info, rndr->bitstream_buffers_used, rndr->bitstream_buffers); + + vdp_st = vdp->decoder_render(vc->decoder, rndr->surface, + (void *)&rndr->info, + rndr->bitstream_buffers_used, + rndr->bitstream_buffers); CHECK_ST_WARNING("Failed VDPAU decoder rendering"); return VO_TRUE; } @@ -851,13 +899,14 @@ static struct vdpau_render_state *get_surface(struct vo *vo, int number) if (vc->surface_render[number].surface == VDP_INVALID_HANDLE) { VdpStatus vdp_st; vdp_st = vdp->video_surface_create(vc->vdp_device, vc->vdp_chroma_type, - vc->vid_width, vc->vid_height, - &vc->surface_render[number].surface); + vc->vid_width, vc->vid_height, + &vc->surface_render[number].surface); CHECK_ST_WARNING("Error when calling vdp_video_surface_create"); if (vdp_st != VDP_STATUS_OK) return NULL; } - mp_msg(MSGT_VO, MSGL_DBG2, "VID CREATE: %u\n", vc->surface_render[number].surface); + mp_msg(MSGT_VO, MSGL_DBG2, "VID CREATE: %u\n", + vc->surface_render[number].surface); return &vc->surface_render[number]; } @@ -884,11 +933,13 @@ static uint32_t draw_image(struct vo *vo, mp_image_t *mpi) vc->vid_surface_num = rndr - vc->surface_render; if (vc->image_format == IMGFMT_NV12) destdata[1] = destdata[2]; - vdp_st = vdp->video_surface_put_bits_y_cb_cr(rndr->surface, - vc->vdp_pixel_format, - (const void *const*)destdata, - mpi->stride); // pitch - CHECK_ST_ERROR("Error when calling vdp_video_surface_put_bits_y_cb_cr"); + vdp_st = + vdp->video_surface_put_bits_y_cb_cr(rndr->surface, + vc->vdp_pixel_format, + (const void *const*)destdata, + mpi->stride); // pitch + CHECK_ST_ERROR("Error when calling " + "vdp_video_surface_put_bits_y_cb_cr"); } if (mpi->fields & MP_IMGFIELD_ORDERED) vc->top_field_first = !!(mpi->fields & MP_IMGFIELD_TOP_FIRST); @@ -905,12 +956,15 @@ static uint32_t get_image(struct vo *vo, mp_image_t *mpi) struct vdpau_render_state *rndr; // no dr for non-decoding for now - if (!IMGFMT_IS_VDPAU(vc->image_format)) return VO_FALSE; - if (mpi->type != MP_IMGTYPE_NUMBERED) return VO_FALSE; + if (!IMGFMT_IS_VDPAU(vc->image_format)) + return VO_FALSE; + if (mpi->type != MP_IMGTYPE_NUMBERED) + return VO_FALSE; rndr = get_surface(vo, mpi->number); if (!rndr) { - mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] no surfaces available in get_image\n"); + mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] no surfaces available in " + "get_image\n"); // TODO: this probably breaks things forever, provide a dummy buffer? return VO_FALSE; } @@ -926,7 +980,9 @@ static uint32_t get_image(struct vo *vo, mp_image_t *mpi) static int query_format(uint32_t format) { - int default_flags = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_OSD | VFCAP_EOSD | VFCAP_EOSD_UNSCALED; + int default_flags = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW + | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_OSD | VFCAP_EOSD + | VFCAP_EOSD_UNSCALED; switch (format) { case IMGFMT_YV12: case IMGFMT_I420: @@ -957,26 +1013,27 @@ static void destroy_vdpau_objects(struct vo *vo) if (vc->flip_queue != VDP_INVALID_HANDLE) { vdp_st = vdp->presentation_queue_destroy(vc->flip_queue); - CHECK_ST_WARNING("Error when calling vdp->presentation_queue_destroy"); + CHECK_ST_WARNING("Error when calling vdp_presentation_queue_destroy"); } if (vc->flip_target != VDP_INVALID_HANDLE) { vdp_st = vdp->presentation_queue_target_destroy(vc->flip_target); - CHECK_ST_WARNING("Error when calling vdp->presentation_queue_target_destroy"); + CHECK_ST_WARNING("Error when calling " + "vdp_presentation_queue_target_destroy"); } for (i = 0; i <= NUM_OUTPUT_SURFACES; i++) { if (vc->output_surfaces[i] == VDP_INVALID_HANDLE) continue; vdp_st = vdp->output_surface_destroy(vc->output_surfaces[i]); - CHECK_ST_WARNING("Error when calling vdp->output_surface_destroy"); + CHECK_ST_WARNING("Error when calling vdp_output_surface_destroy"); } for (i = 0; i < vc->eosd_surface_count; i++) { if (vc->eosd_surfaces[i].surface == VDP_INVALID_HANDLE) continue; vdp_st = vdp->bitmap_surface_destroy(vc->eosd_surfaces[i].surface); - CHECK_ST_WARNING("Error when calling vdp->bitmap_surface_destroy"); + CHECK_ST_WARNING("Error when calling vdp_bitmap_surface_destroy"); } vdp_st = vdp->device_destroy(vc->vdp_device); @@ -1062,8 +1119,8 @@ static int preinit(struct vo *vo, const char *arg) char *vdpau_device_create = "vdp_device_create_x11"; vc->vdpau_lib_handle = dlopen(vdpaulibrary, RTLD_LAZY); if (!vc->vdpau_lib_handle) { - mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Could not open dynamic library %s\n", - vdpaulibrary); + mp_msg(MSGT_VO, MSGL_ERR, + "[vdpau] Could not open dynamic library %s\n", vdpaulibrary); return -1; } vc->vdp_device_create = dlsym(vc->vdpau_lib_handle, vdpau_device_create); @@ -1110,9 +1167,9 @@ static int get_equalizer(struct vo *vo, const char *name, int *value) if (!strcasecmp(name, "brightness")) *value = vc->procamp.brightness * 100; else if (!strcasecmp(name, "contrast")) - *value = (vc->procamp.contrast-1.0) * 100; + *value = (vc->procamp.contrast - 1.0) * 100; else if (!strcasecmp(name, "saturation")) - *value = (vc->procamp.saturation-1.0) * 100; + *value = (vc->procamp.saturation - 1.0) * 100; else if (!strcasecmp(name, "hue")) *value = vc->procamp.hue * 100 / M_PI; else @@ -1126,7 +1183,8 @@ static int set_equalizer(struct vo *vo, const char *name, int value) struct vdp_functions *vdp = vc->vdp; VdpStatus vdp_st; VdpCSCMatrix matrix; - static const VdpVideoMixerAttribute attributes[] = {VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX}; + static const VdpVideoMixerAttribute attributes[] = + {VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX}; const void *attribute_values[] = {&matrix}; if (!strcasecmp(name, "brightness")) @@ -1140,11 +1198,13 @@ static int set_equalizer(struct vo *vo, const char *name, int value) else return VO_NOTIMPL; - vdp_st = vdp->generate_csc_matrix(&vc->procamp, VDP_COLOR_STANDARD_ITUR_BT_601, - &matrix); + vdp_st = vdp->generate_csc_matrix(&vc->procamp, + VDP_COLOR_STANDARD_ITUR_BT_601, + &matrix); CHECK_ST_WARNING("Error when generating CSC matrix"); - vdp_st = vdp->video_mixer_set_attribute_values(vc->video_mixer, 1, attributes, - attribute_values); + vdp_st = vdp->video_mixer_set_attribute_values(vc->video_mixer, 1, + attributes, + attribute_values); CHECK_ST_WARNING("Error when setting CSC matrix"); return VO_TRUE; }