[MPlayer-dev-eng] [PATCH]VO_VDPAU, round 6

Carl Eugen Hoyos cehoyos at rainbow.studorg.tuwien.ac.at
Sat Jan 31 23:47:22 CET 2009


Hi!

I believe I adressed all issues that Diego and Reimar kindly pointed to.
Please don't be too harsh if I forgot something.

Testing vdpau's return values is now done by macros again, and they output 
text messages instead of the error number.

Please comment, Carl Eugen
-------------- next part --------------
Index: Makefile
===================================================================
--- Makefile	(revision 28405)
+++ Makefile	(working copy)
@@ -628,6 +628,7 @@
 SRCS_MPLAYER-$(TGA)           += libvo/vo_tga.c
 SRCS_MPLAYER-$(V4L2)          += libvo/vo_v4l2.c
 SRCS_MPLAYER-$(V4L2)          += libao2/ao_v4l2.c
+SRCS_MPLAYER-$(VDPAU)         += libvo/vo_vdpau.c
 SRCS_MPLAYER-$(VESA)          += libvo/gtf.c libvo/vo_vesa.c libvo/vesa_lvo.c
 SRCS_MPLAYER-$(VIDIX)         += libvo/vo_cvidix.c \
                                  libvo/vosub_vidix.c \
Index: libvo/video_out.c
===================================================================
--- libvo/video_out.c	(revision 28405)
+++ libvo/video_out.c	(working copy)
@@ -71,6 +71,7 @@
 extern vo_functions_t video_out_x11;
 extern vo_functions_t video_out_xover;
 extern vo_functions_t video_out_xvmc;
+extern vo_functions_t video_out_vdpau;
 extern vo_functions_t video_out_xv;
 extern vo_functions_t video_out_gl;
 extern vo_functions_t video_out_gl2;
@@ -153,6 +154,9 @@
 #ifdef CONFIG_3DFX
         &video_out_3dfx,
 #endif
+#ifdef CONFIG_VDPAU
+        &video_out_vdpau,
+#endif
 #ifdef CONFIG_XV
         &video_out_xv,
 #endif
Index: libvo/vo_vdpau.c
===================================================================
--- libvo/vo_vdpau.c	(revision 0)
+++ libvo/vo_vdpau.c	(revision 0)
@@ -0,0 +1,699 @@
+/*
+ * VDPAU Renderer for MPlayer.
+ * VDPAU with X11 interface.
+ *
+ * Copyright (C) 2008 NVIDIA
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MPlayer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 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 are collected through
+ * the "vdpau_render_state" structure after parsing all headers
+ * etc. in libavcodec for different codecs.
+ *
+ * @{
+ */
+
+#include <stdio.h>
+
+#include "config.h"
+#include "mp_msg.h"
+#include "video_out.h"
+#include "video_out_internal.h"
+#include "x11_common.h"
+#include "sub.h"
+
+#include "libavcodec/vdpau.h"
+
+#ifdef CONFIG_GUI
+#include "gui/interface.h"
+#endif
+
+#include "libavutil/common.h"
+#include <assert.h>
+
+static vo_info_t info = {
+    "VDPAU with X11",
+    "vdpau",
+    "Rajib Mahapatra <rmahapatra at nvidia.com> and others",
+    ""
+};
+
+LIBVO_EXTERN(vdpau)
+
+#define CHECK_ST_ERROR \
+    if (vdp_st != VDP_STATUS_OK) { \
+        mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Error at line %d: %s\n", \
+               __LINE__, vdp_get_error_string(vdp_st)); \
+        return -1; \
+    }
+
+#define CHECK_ST_WARNING \
+    if (vdp_st != VDP_STATUS_OK) \
+        mp_msg(MSGT_VO, MSGL_WARN, "[vdpau]Warning at line %d: %s\n", \
+               __LINE__, vdp_get_error_string(vdp_st));
+
+/* number of video and output surfaces */
+#define NUM_OUTPUT_SURFACES                3
+#define NUM_VIDEO_SURFACES_NON_ACCEL_YUV   1
+
+/* number of palette entries */
+#define PALETTE_SIZE 256
+
+/*
+ * Global variable declaration - VDPAU specific
+ */
+
+/* Declaration for all variables of win_x11_init_vdpau_procs() and
+ * win_x11_init_vdpau_flip_queue() functions
+ */
+static VdpDevice                          vdp_device;
+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 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;
+
+/* output_surfaces[2] is used in composite-picture. */
+static VdpOutputSurfaceRenderOutputSurface       *vdp_output_surface_render_output_surface;
+static VdpOutputSurfacePutBitsIndexed            *vdp_output_surface_put_bits_indexed;
+
+static VdpVideoSurface                   *video_surfaces;
+static VdpOutputSurface                   output_surfaces[NUM_OUTPUT_SURFACES];
+static VdpVideoSurface                    video_surface;
+static VdpOutputSurface                   output_surface;
+
+static VdpVideoMixer                      video_mixer;
+
+static VdpRect                            out_rect;
+static VdpRect                            out_rect_vid;
+
+static struct vdpau_render_state         *surface_render;
+static int                                surface_num;
+static uint32_t                           vid_width, vid_height;
+static uint32_t                           image_format;
+
+/* draw_osd */
+static unsigned char                     *index_data;
+static int                                index_data_size;
+static int                                osd_alloc;
+static uint32_t                          *palette;
+
+/*
+ * X11 specific.
+ */
+static int                                visible_buf;
+static int                                flip_flag;
+
+static int                                int_pause;
+
+static uint32_t                           drwX, drwY;
+static uint32_t                           max_width, max_height;
+
+static void calc_drwXY_dWH(uint32_t *drwX, uint32_t *drwY,
+                           uint32_t *d_wh, uint32_t *d_ht)
+{
+    vo_calc_drwXY(drwX, drwY);
+
+    out_rect_vid.x0 = *drwX;
+    out_rect_vid.y0 = *drwY;
+    out_rect_vid.x1 = vo_dwidth  + out_rect_vid.x0;
+    out_rect_vid.y1 = vo_dheight + out_rect_vid.y0;
+
+    out_rect.x0 = 0;
+    out_rect.x1 = out_rect_vid.x1;
+    out_rect.y0 = 0;
+    out_rect.y1 = out_rect_vid.y1;
+}
+
+/* Initialize vdp_get_proc_address, called from preinit() */
+static int win_x11_init_vdpau_procs(void)
+{
+    VdpStatus vdp_st;
+
+    struct vdp_function {
+        const int id;
+        void *pointer;
+    };
+
+    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_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},
+        {0, NULL}
+    };
+
+    vdp_st = vdp_device_create_x11(mDisplay, mScreen,
+                                   &vdp_device, &vdp_get_proc_address);
+    CHECK_ST_ERROR
+
+    for (dsc = vdp_func; dsc->pointer; dsc++) {
+        vdp_st = vdp_get_proc_address(vdp_device, dsc->id, dsc->pointer);
+        CHECK_ST_ERROR
+    }
+    return 0;
+}
+
+/* Initialize vdpau_flip_queue, called from config() */
+static int win_x11_init_vdpau_flip_queue(void)
+{
+    VdpStatus vdp_st;
+
+    vdp_st = vdp_presentation_queue_target_create_x11(vdp_device, vo_window, 
+                                                      &vdp_flip_target);
+    CHECK_ST_ERROR
+
+    vdp_st = vdp_presentation_queue_create(vdp_device, vdp_flip_target,
+                                           &vdp_flip_queue);
+    CHECK_ST_ERROR
+
+    return 0;
+}
+
+    // Creation of VideoMixer.
+static int create_vdp_mixer(VdpChromaType vdp_chroma_type) {
+#define VDP_NUM_MIXER_PARAMETER 3
+    int i;
+    VdpStatus vdp_st;
+    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
+    };
+    void const* const parameter_values[VDP_NUM_MIXER_PARAMETER] = {&vid_width,
+                                                                   &vid_height,
+                                                                   &vdp_chroma_type
+    };
+
+    surface_render = calloc(NUM_VIDEO_SURFACES_NON_ACCEL_YUV,
+                            sizeof(struct vdpau_render_state));
+
+    for (i = 0; i < NUM_VIDEO_SURFACES_NON_ACCEL_YUV; i++) {
+        surface_render[i].state = FF_VDPAU_STATE_USED_FOR_RENDER;
+        surface_render[i].surface = video_surfaces[i];
+    }
+
+    vdp_st = vdp_video_mixer_create(vdp_device, 0, 0,
+                                    VDP_NUM_MIXER_PARAMETER,
+                                    parameters, parameter_values,
+                                    &video_mixer);
+    CHECK_ST_ERROR
+
+    return 0;
+}
+
+/*
+ * 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)
+{
+    XVisualInfo vinfo;
+    XSetWindowAttributes xswa;
+    XWindowAttributes attribs;
+    unsigned long xswamask;
+    int depth;
+    VdpStatus vdp_st;
+    int i;
+    VdpChromaType vdp_chroma_type = VDP_CHROMA_TYPE_420;
+
+#ifdef CONFIG_XF86VM
+    int vm = flags & VOFLAG_MODESWITCHING;
+#endif
+
+    if (vo_config_count)
+        return 0;
+
+    image_format = format;
+
+    int_pause = 0;
+    visible_buf = -1;
+
+    flip_flag = flags & VOFLAG_FLIPPING;
+
+#ifdef CONFIG_GUI
+    if (use_gui)
+        guiGetEvent(guiSetShVideo, 0);  // let the GUI setup/resize our window
+    else
+#endif
+    {
+#ifdef CONFIG_XF86VM
+        if (vm)
+            vo_vm_switch();
+        else
+#endif
+        XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &attribs);
+        depth = attribs.depth;
+        if (depth != 15 && depth != 16 && depth != 24 && depth != 32)
+            depth = 24;
+        XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo);
+
+        xswa.background_pixel = 0;
+        xswa.border_pixel = 0;
+        xswamask = CWBackPixel | CWBorderPixel;
+
+        vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, d_width, d_height,
+                                flags, CopyFromParent, "x11", title);
+        XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa);
+
+        XSync(mDisplay, False);
+
+#ifdef CONFIG_XF86VM
+        if (vm) {
+            /* Grab the mouse pointer in our window */
+            if (vo_grabpointer)
+                XGrabPointer(mDisplay, vo_window, True, 0,
+                             GrabModeAsync, GrabModeAsync,
+                             vo_window, None, CurrentTime);
+            XSetInputFocus(mDisplay, vo_window, RevertToNone, CurrentTime);
+        }
+#endif
+    }
+
+    if ((flags & VOFLAG_FULLSCREEN) && WinID <= 0)
+        vo_fs = 1;
+    calc_drwXY_dWH(&drwX, &drwY, &d_width, &d_height);
+
+    /* -----VDPAU related code here -------- */
+    video_surfaces = calloc(NUM_VIDEO_SURFACES_NON_ACCEL_YUV,
+                            sizeof(VdpVideoSurface));
+
+    if (win_x11_init_vdpau_flip_queue())
+        return -1;
+
+    // video width and height
+    vid_width = width;
+    vid_height = height;
+
+    // Creation of video_surfaces
+    for (i = 0; i < NUM_VIDEO_SURFACES_NON_ACCEL_YUV; i++) {
+        vdp_st = vdp_video_surface_create(vdp_device, vdp_chroma_type,
+                                          vid_width, vid_height,
+                                          &video_surfaces[i]);
+        CHECK_ST_ERROR
+        mp_msg(MSGT_VO, MSGL_DBG2, "VID CREATE: %u\n", video_surfaces[i]);
+    }
+
+    assert(!surface_render);
+
+    if (create_vdp_mixer(vdp_chroma_type))
+        return -1;
+
+    max_width  = FFMAX(max_width,  d_width);
+    max_height = FFMAX(max_height, d_height);
+
+    // Creation of output_surfaces
+    for (i = 0; i < NUM_OUTPUT_SURFACES; i++) {
+        vdp_st = vdp_output_surface_create(vdp_device, VDP_RGBA_FORMAT_B8G8R8A8,
+                                           max_width, max_height,
+                                           &output_surfaces[i]);
+        CHECK_ST_ERROR
+        mp_msg(MSGT_VO, MSGL_DBG2, "OUT CREATE: %u\n", output_surfaces[i]);
+    }
+
+    surface_num = 0;
+
+    return 0;
+}
+
+static void check_events(void)
+{
+    int e = vo_x11_check_events(mDisplay);
+
+    if (e & VO_EVENT_RESIZE) {
+        mp_msg(MSGT_VO, MSGL_V, "[vdpau] dx: %d dy: %d dw: %d dh: %d\n", drwX,
+               drwY, vo_dwidth, vo_dheight);
+
+        calc_drwXY_dWH(&drwX, &drwY, &vo_dwidth, &vo_dheight);
+    }
+
+    if ((e & VO_EVENT_EXPOSE || e & VO_EVENT_RESIZE) && int_pause) {
+        /* did we already draw a buffer */
+        if (visible_buf != -1) {
+            /* redraw the last visible buffer */
+            VdpStatus vdp_st;
+            vdp_st = vdp_presentation_queue_display(vdp_flip_queue,
+                                                    output_surface, // output_surfaces[0 / 1],
+                                                    FFMIN(max_width, FFMAX(out_rect.x1, out_rect_vid.x1)),
+                                                    FFMIN(max_width, FFMAX(out_rect.y1, out_rect_vid.y1)),
+                                                    0);
+            CHECK_ST_WARNING
+        }
+    }
+}
+
+static void draw_osd_I8A8(int x0,int y0, int w,int h, unsigned char *src,
+                          unsigned char *srca, int stride)
+{
+    VdpStatus vdp_st;
+    int i, j;
+    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 (index_data_size < index_data_size_required) {
+        index_data = realloc(index_data, index_data_size_required);
+        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];
+        }
+
+    output_indexed_rect_vid.x0 = out_rect_vid.x0 + x0;
+    output_indexed_rect_vid.y0 = out_rect_vid.y0 + y0;
+    output_indexed_rect_vid.x1 = output_indexed_rect_vid.x0 + w;
+    output_indexed_rect_vid.y1 = output_indexed_rect_vid.y0 + h;
+
+    pitch = w*2;
+
+    // write source_data to output_surfaces[2].
+    vdp_st = vdp_output_surface_put_bits_indexed(output_surfaces[2],
+                                                 VDP_INDEXED_FORMAT_I8A8,
+                                                 (void const* const*)&index_data,
+                                                 &pitch,
+                                                 &output_indexed_rect_vid,
+                                                 VDP_COLOR_TABLE_FORMAT_B8G8R8X8,
+                                                 (void *)palette);
+    CHECK_ST_WARNING
+
+    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;
+
+    vdp_st = vdp_output_surface_render_output_surface(output_surface,
+                                                      &output_indexed_rect_vid,
+                                                      output_surfaces[2],
+                                                      &output_indexed_rect_vid,
+                                                      NULL,
+                                                      &blend_state,
+                                                      VDP_OUTPUT_SURFACE_RENDER_ROTATE_0);
+    CHECK_ST_WARNING
+}
+
+static void OSD_init(void)
+{
+    int i;
+
+    if (vid_width == 0 || vid_height == 0)
+        return;
+
+    /* create palette table */
+    palette = calloc(PALETTE_SIZE, sizeof(*palette));
+
+    // full grayscale palette.
+    for (i = 0; i < PALETTE_SIZE; ++i)
+        palette[i] = (i << 16) | (i << 8) | i;
+
+    index_data = NULL;
+    index_data_size = 0;
+    osd_alloc = 1;
+}
+
+static void draw_osd(void)
+{
+    mp_msg(MSGT_VO, MSGL_DBG2, "DRAW_OSD\n");
+    if (!osd_alloc)
+        OSD_init();
+
+    vo_draw_text(vo_dwidth, vo_dheight, draw_osd_I8A8);
+}
+
+static void flip_page(void)
+{
+    VdpStatus vdp_st;
+    mp_msg(MSGT_VO, MSGL_DBG2, "\nFLIP_PAGE VID:%u -> OUT:%u\n",
+           video_surface, output_surface);
+
+    vdp_st = vdp_presentation_queue_display(vdp_flip_queue, output_surface,
+                                            FFMIN(max_width, FFMAX(out_rect.x1, out_rect_vid.x1)),
+                                            FFMIN(max_width, FFMAX(out_rect.y1, out_rect_vid.y1)),
+                                            0);
+    CHECK_ST_WARNING
+
+    surface_num = surface_num ^ 1;
+    visible_buf = 1;
+}
+
+static uint32_t start_slice(mp_image_t *mpi)
+{
+    mpi->flags &= ~MP_IMGFLAG_DRAW_CALLBACK;
+    return VO_TRUE;
+}
+
+static int draw_slice(uint8_t *image[], int stride[], int w, int h,
+                      int x, int y)
+{
+    return VO_FALSE;
+}
+
+
+static int draw_frame(uint8_t *src[])
+{
+    return VO_ERROR;
+}
+
+static uint32_t draw_image(mp_image_t *mpi)
+{
+    VdpStatus vdp_st;
+    VdpTime dummy;
+    void *destdata[3] = {mpi->planes[0], mpi->planes[2], mpi->planes[1]};
+
+    assert(mpi->num_planes == 3);
+    video_surface = video_surfaces[0];
+
+    vdp_st = vdp_video_surface_put_bits_y_cb_cr(video_surface,
+                                                VDP_YCBCR_FORMAT_YV12,
+                                                (void const* const*)destdata,
+                                                mpi->stride); // pitch
+    CHECK_ST_ERROR
+
+    output_surface = output_surfaces[surface_num];
+    vdp_st = vdp_presentation_queue_block_until_surface_idle(vdp_flip_queue,
+                                                             output_surface,
+                                                             &dummy);
+    CHECK_ST_ERROR
+
+    vdp_st = vdp_video_mixer_render(video_mixer, VDP_INVALID_HANDLE, 0,
+                                    VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME,
+                                    0, NULL, video_surface, 0, NULL, NULL,
+                                    output_surface,
+                                    &out_rect, &out_rect_vid, 0, NULL);
+    CHECK_ST_ERROR
+
+    mp_msg(MSGT_VO, MSGL_DBG2, "DRAW IMG:%u\n", video_surface);
+    return VO_TRUE;
+}
+
+static int query_format(uint32_t format)
+{
+    if (format == IMGFMT_YV12)
+        return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_OSD;
+    return 0;
+}
+
+static void DestroyVdpauObjects(void)
+{
+    int i;
+    VdpStatus vdp_st;
+
+    vdp_st = vdp_presentation_queue_destroy(vdp_flip_queue);
+    CHECK_ST_WARNING
+
+    vdp_st = vdp_presentation_queue_target_destroy(vdp_flip_target);
+    CHECK_ST_WARNING
+
+    vdp_st = vdp_video_mixer_destroy(video_mixer);
+    CHECK_ST_WARNING
+
+    for (i = 0; i < NUM_OUTPUT_SURFACES; i++) {
+        vdp_st = vdp_output_surface_destroy(output_surfaces[i]);
+        CHECK_ST_WARNING
+    }
+
+    for (i = 0; i < NUM_VIDEO_SURFACES_NON_ACCEL_YUV; i++) {
+        vdp_st = vdp_video_surface_destroy(video_surfaces[i]);
+        CHECK_ST_WARNING
+    }
+
+    vdp_st = vdp_device_destroy(vdp_device);
+    CHECK_ST_WARNING
+}
+
+static void uninit(void)
+{
+    if (!vo_config_count)
+        return;
+    visible_buf = -1;
+    osd_alloc = 0;
+
+    /* Destroy all vdpau objects */
+    DestroyVdpauObjects();
+
+    free(video_surfaces);
+    video_surfaces = NULL;
+    free(surface_render);
+    surface_render = NULL;
+    free(index_data);
+    index_data = NULL;
+    free(palette);
+    palette = NULL;
+
+#ifdef CONFIG_XF86VM
+    vo_vm_close();
+#endif
+    vo_x11_uninit();
+}
+
+static int preinit(const char *arg)
+{
+    if (arg) {
+        mp_msg(MSGT_VO, MSGL_ERR, "vo_vdpau: Unknown subdevice: %s\n", arg);
+        return ENOSYS;
+    }
+
+    if (!vo_init() || win_x11_init_vdpau_procs())
+        return -1;
+
+    max_width  = vo_screenwidth;
+    max_height = vo_screenheight;
+
+    return 0;
+}
+
+static int control(uint32_t request, void *data, ...)
+{
+    switch (request) {
+        case VOCTRL_PAUSE:
+            return (int_pause = 1);
+        case VOCTRL_RESUME:
+            return (int_pause = 0);
+        case VOCTRL_QUERY_FORMAT:
+            return query_format(*(uint32_t *)data);
+        case VOCTRL_DRAW_IMAGE:
+            return draw_image(data);
+        case VOCTRL_START_SLICE:
+            return start_slice(data);
+        case VOCTRL_GUISUPPORT:
+            return VO_TRUE;
+        case VOCTRL_FULLSCREEN:
+            vo_x11_fullscreen();
+            return VO_TRUE;
+        case VOCTRL_SET_EQUALIZER: {
+            va_list ap;
+            int value;
+
+            va_start(ap, data);
+            value = va_arg(ap, int);
+
+            va_end(ap);
+            return vo_x11_set_equalizer(data, value);
+        }
+        case VOCTRL_GET_EQUALIZER: {
+            va_list ap;
+            int *value;
+
+            va_start(ap, data);
+            value = va_arg(ap, int *);
+
+            va_end(ap);
+            return vo_x11_get_equalizer(data, value);
+        }
+        case VOCTRL_ONTOP:
+            vo_x11_ontop();
+            return VO_TRUE;
+        case VOCTRL_UPDATE_SCREENINFO:
+            update_xinerama_info();
+            return VO_TRUE;
+    }
+    return VO_NOTIMPL;
+}
+
+/* @} */
Index: configure
===================================================================
--- configure	(revision 28405)
+++ configure	(working copy)
@@ -382,6 +382,7 @@
   --enable-xmga            enable mga_vid X11 video output [autodetect]
   --enable-xv              enable Xv video output [autodetect]
   --enable-xvmc            enable XvMC acceleration [disable]
+  --enable-vdpau           enable VDPAU acceleration [autodetect]
   --enable-vm              enable XF86VidMode support [autodetect]
   --enable-xinerama        enable Xinerama support [autodetect]
   --enable-x11             enable X11 video output [autodetect]
@@ -552,6 +553,7 @@
 _dga2=auto
 _xv=auto
 _xvmc=no  #auto when complete
+_vdpau=auto
 _sdl=auto
 _direct3d=auto
 _directx=auto
@@ -877,6 +879,8 @@
   --disable-xv)		_xv=no		;;
   --enable-xvmc)        _xvmc=yes       ;;
   --disable-xvmc)       _xvmc=no        ;;
+  --enable-vdpau)       _vdpau=yes      ;;
+  --disable-vdpau)      _vdpau=no       ;;
   --enable-sdl)		_sdl=yes	;;
   --disable-sdl)	_sdl=no		;;
   --enable-direct3d)    _direct3d=yes   ;;
@@ -4132,7 +4136,7 @@
   _novomodules="x11 $_novomodules"
   _res_comment="check if the dev(el) packages are installed"
   # disable stuff that depends on X
-  _xv=no ; _xvmc=no ; _xinerama=no ; _vm=no ; _xf86keysym=no
+  _xv=no ; _xvmc=no ; _xinerama=no ; _vm=no ; _xf86keysym=no ; _vdpau=no
 fi
 echores "$_x11"
 
@@ -4243,6 +4247,27 @@
 echores "$_xvmc"
 
 
+echocheck "VDPAU"
+if test "$_vdpau" = auto ; then
+  cat > $TMPC <<EOF
+#include <vdpau/vdpau_x11.h>
+int main(void) {vdp_device_create_x11(0, 0, 0, 0); return 0;}
+EOF
+  _vdpau=no
+  cc_check -lvdpau && _vdpau=yes
+fi
+
+if test "$_vdpau" = yes ; then
+  _def_vdpau='#define CONFIG_VDPAU 1'
+  _libs_mplayer="$_libs_mplayer -lvdpau"
+  _vomodules="vdpau $_vomodules"
+else
+  _def_vdpau='#undef CONFIG_VDPAU'
+  _novomodules="vdpau $_novomodules"
+fi
+echores "$_vdpau"
+
+
 echocheck "Xinerama"
 if test "$_xinerama" = auto ; then
   cat > $TMPC <<EOF
@@ -8087,6 +8112,7 @@
 UNRAR_EXEC = $_unrar_exec
 V4L2 = $_v4l2
 VCD = $_vcd
+VDPAU = $_vdpau
 VESA = $_vesa
 VIDIX = $_vidix
 VIDIX_PCIDB = $_vidix_pcidb_val
@@ -8528,6 +8554,7 @@
 $_def_tdfxvid
 $_def_tga
 $_def_v4l2
+$_def_vdpau
 $_def_vesa
 $_def_vidix
 $_def_vidix_drv_cyberblade


More information about the MPlayer-dev-eng mailing list