[MPlayer-dev-eng] [PATCH]VO_VDPAU, round 3
Carl Eugen Hoyos
cehoyos at rainbow.studorg.tuwien.ac.at
Sat Jan 10 03:43:27 CET 2009
Hi!
Attached is round three of vo_vdpau, at least one factorisation is still
missing, because I'm not sure which part exactly should be taken out.
I did not yet look at panscan.
Please comment, Carl Eugen
-------------- next part --------------
Index: Makefile
===================================================================
--- Makefile (revision 28285)
+++ Makefile (working copy)
@@ -617,6 +617,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 28286)
+++ 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,936 @@
+/*
+ * VDPAU Renderer for MPlayer.
+ * vo_vdpau.c - 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 informations are collected through
+ * "vdpau_render_state" structure after parsing all headers
+ * etc in ffmpeg module for different codecs.
+ *
+ * @{
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "mp_msg.h"
+#include "help_mp.h"
+#include "video_out.h"
+#include "video_out_internal.h"
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <errno.h>
+
+#include "x11_common.h"
+
+#include "libavcodec/vdpau.h"
+
+#include "fastmemcpy.h"
+#include "sub.h"
+#include "aspect.h"
+
+#include "subopt-helper.h"
+
+#include "input/input.h"
+
+#ifdef HAVE_NEW_GUI
+#include "gui/interface.h"
+#endif
+
+#include "libavutil/common.h"
+#include <assert.h>
+
+#define TRACE_SURFACES 0
+
+static vo_info_t info = {
+ "VDPAU with X11",
+ "vdpau",
+ "Rajib Mahapatra <rmahapatra at nvidia.com> and others",
+ ""
+};
+
+LIBVO_EXTERN(vdpau)
+
+/* Numbers of video and ouput Surfaces */
+#define NUM_OUTPUT_SURFACES 3
+#define NUM_VIDEO_SURFACES_NON_ACCEL_YUV 1 // surfaces for YV12 etc.
+#define NUM_VIDEO_SURFACES_NON_ACCEL_RGB 0 // surfaces for RGB or YUV4:4:4
+
+/* Numbers of palette entires */
+#define PALETTE_SIZE 256
+
+/*
+ * Global variables declaration - VDPAU specific.
+ */
+
+/* Declaration for all variables of win_x11_init_vdpau_procs() and
+ * win_x11_init_vdpau_flip_queue() function.
+ */
+static VdpDevice vdp_device;
+static VdpGetProcAddress * vdp_get_proc_address;
+
+static VdpPresentationQueueTarget vdp_flip_target;
+static VdpPresentationQueue vdp_flip_queue;
+
+VdpDeviceDestroy * vdp_device_destroy;
+VdpVideoSurfaceCreate * vdp_video_surface_create;
+VdpVideoSurfaceDestroy * vdp_video_surface_destroy;
+
+/* May be used in software filtering/postprocessing options
+ * in MPlayer(./mplayer -vf ..) if we want copy video_surface data to
+ * sytem memory.
+ */
+static VdpVideoSurfacePutBitsYCbCr *vdp_video_surface_put_bits_y_cb_cr;
+static VdpVideoSurfacePutBitsYCbCr *vdp_video_surface_get_bits_y_cb_cr;
+
+static VdpOutputSurfacePutBitsYCbCr *vdp_output_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 videoSurface data to displayble ouputSurface. */
+static VdpVideoMixerCreate *vdp_video_mixer_create;
+static VdpVideoMixerSetFeatureEnables *vdp_video_mixer_set_feature_enables;
+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;
+static VdpPresentationQueueQuerySurfaceStatus *vdp_presentation_queue_query_surface_status;
+
+/* outputSurfaces[2] is used in composite-picture. */
+static VdpOutputSurfaceRenderOutputSurface *vdp_output_surface_render_output_surface;
+static VdpOutputSurfacePutBitsIndexed *vdp_output_surface_put_bits_indexed;
+
+static VdpDecoderCreate *vdp_decoder_create;
+static VdpDecoderDestroy *vdp_decoder_destroy;
+static VdpDecoderRender *vdp_decoder_render;
+
+static VdpVideoSurface *videoSurfaces;
+static VdpOutputSurface outputSurfaces[NUM_OUTPUT_SURFACES];
+static VdpVideoSurface videoSurface;
+static VdpOutputSurface outputSurface;
+
+static VdpDecoder decoder;
+static VdpVideoMixer videoMixer;
+
+static VdpRect outRect;
+static VdpRect outRectVid;
+
+static struct vdpau_render_state * surface_render;
+static int surfaceNum;
+static uint32_t vid_width, vid_height;
+static uint32_t image_format;
+static uint32_t num_video_surfaces;
+
+/* draw_osd */
+static unsigned char *indexData;
+static int indexData_size;
+static int osd_alloc;
+static uint32_t *palette;
+
+/*
+ * X11 specific.
+ */
+static int visible_buf = -1; // -1 means: no buffer was drawn yet
+
+static int flip_flag;
+
+static int int_pause;
+
+static uint32_t drwX, drwY;
+static uint32_t max_width = 0, max_height = 0; // zero means: not set
+
+static void calc_drwXY_dWH(uint32_t *drwX, uint32_t *drwY, uint32_t *d_wh, uint32_t *d_ht)
+{
+ vo_calc_drwXY(drwX, drwY);
+
+ // Now, Calculate outRectVid and outRect.
+ outRectVid.x0 = *drwX-(vo_panscan_x>>1);
+ outRectVid.y0 = *drwY-(vo_panscan_y>>1);
+ outRectVid.x1 = vo_dwidth+vo_panscan_x+outRectVid.x0;
+ outRectVid.y1 = vo_dheight+vo_panscan_y+outRectVid.y0;
+
+ outRect.x0 = 0;
+ outRect.x1 = FFMAX(vo_screenwidth, outRectVid.x1);
+ outRect.y0 = 0;
+ outRect.y1 = FFMAX(vo_screenheight, outRectVid.y1);
+}
+
+/* Initialize Get Proc Address, called from config() */
+static void 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_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_VIDEO_SURFACE_GET_BITS_Y_CB_CR,
+ &vdp_video_surface_get_bits_y_cb_cr},
+ {VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_Y_CB_CR,
+ &vdp_output_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_SET_FEATURE_ENABLES,
+ &vdp_video_mixer_set_feature_enables},
+ {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_DECODER_CREATE, &vdp_decoder_create},
+ {VDP_FUNC_ID_DECODER_DESTROY, &vdp_decoder_destroy},
+ {VDP_FUNC_ID_DECODER_RENDER, &vdp_decoder_render},
+ {VDP_FUNC_ID_PRESENTATION_QUEUE_QUERY_SURFACE_STATUS,
+ &vdp_presentation_queue_query_surface_status},
+ {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
+ );
+ if (vdp_st != VDP_STATUS_OK)
+ mp_msg(MSGT_VO, MSGL_ERR, "Error %d at %s:%d\n",
+ vdp_st, __FILE__, __LINE__);
+
+ 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, "Error %d at %s:%d\n",
+ vdp_st, __FILE__, __LINE__);
+ }
+}
+
+/* Destroy vdpau procs, called from uninit() */
+static VdpStatus win_x11_fini_vdpau_procs(void)
+{
+ VdpStatus vdp_st;
+
+ vdp_st = vdp_device_destroy(vdp_device);
+ if (vdp_st != VDP_STATUS_OK)
+ printf("Error %d at %s:%d\n", vdp_st, __FILE__, __LINE__);
+
+ return VDP_STATUS_OK;
+}
+
+/* Initialize vdpau_flip_queue, called from config() */
+static void win_x11_init_vdpau_flip_queue(void)
+{
+ VdpStatus vdp_st;
+
+ vdp_st = vdp_presentation_queue_target_create_x11(
+ vdp_device,
+ vo_window, //x_window,
+ &vdp_flip_target
+ );
+ if (vdp_st != VDP_STATUS_OK)
+ printf("Error %d at %s:%d\n", vdp_st, __FILE__, __LINE__);
+
+ vdp_st = vdp_presentation_queue_create(
+ vdp_device,
+ vdp_flip_target,
+ &vdp_flip_queue
+ );
+ if (vdp_st != VDP_STATUS_OK)
+ printf("Error %d at %s:%d\n", vdp_st, __FILE__, __LINE__);
+
+}
+
+/* Destroy vdpau_flip_queue, called from uninit() */
+static VdpStatus win_x11_fini_vdpau_flip_queue(void)
+{
+ VdpStatus vdp_st;
+
+ vdp_st = vdp_presentation_queue_destroy(vdp_flip_queue);
+ if (vdp_st != VDP_STATUS_OK)
+ printf("Error %d at %s:%d\n", vdp_st, __FILE__, __LINE__);
+
+ vdp_st = vdp_presentation_queue_target_destroy(vdp_flip_target);
+ if (vdp_st != VDP_STATUS_OK)
+ printf("Error %d at %s:%d\n", vdp_st, __FILE__, __LINE__);
+
+ return VDP_STATUS_OK;
+}
+
+/*
+ * 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;
+
+#ifdef HAVE_XF86VM
+ int vm = flags & VOFLAG_MODESWITCHING;
+#endif
+
+ if (vo_config_count)
+ {
+ // FIXME: We should really check for matching parameters here,
+ // and uninit/re-config if they have changed?
+ return 0;
+ }
+
+ image_format = format;
+
+ switch (format) {
+
+ /* Non VDPAU specific formats.
+ * No HW acceleration. VdpDecoder will not be created and
+ * there will be no call for VdpDecoderRender.
+ */
+ case IMGFMT_YV12:
+ vdp_chroma_type = VDP_CHROMA_TYPE_420;
+ num_video_surfaces = NUM_VIDEO_SURFACES_NON_ACCEL_YUV;
+ break;
+ case IMGFMT_BGRA:
+ // No need for videoSurfaces, directly renders to outputSurface.
+ num_video_surfaces = NUM_VIDEO_SURFACES_NON_ACCEL_RGB;
+ break;
+ default:
+ assert(0);
+ return 1;
+ }
+
+ int_pause = 0;
+ visible_buf = -1;
+
+ flip_flag = flags & VOFLAG_FLIPPING;
+
+#ifdef HAVE_NEW_GUI
+ if (use_gui)
+ guiGetEvent(guiSetShVideo, 0); // let the GUI to setup/resize our window
+ else
+#endif
+ {
+#ifdef HAVE_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 HAVE_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);
+ panscan_calc();
+
+ /* -----VDPAU related code here -------- */
+ if (num_video_surfaces)
+ videoSurfaces = calloc(num_video_surfaces, sizeof(VdpVideoSurface));
+
+ /* get proc address */
+ win_x11_init_vdpau_procs();
+ win_x11_init_vdpau_flip_queue();
+
+ // video width and height
+ vid_width = width;
+ vid_height = height;
+
+ // Creation of VideoSurfaces
+ for (i = 0; i < num_video_surfaces; i++) {
+ vdp_st = vdp_video_surface_create(
+ vdp_device,
+ vdp_chroma_type,
+ vid_width,
+ vid_height,
+ &videoSurfaces[i]
+ );
+ if (vdp_st != VDP_STATUS_OK)
+ printf("Error %d at %s:%d\n", vdp_st, __FILE__, __LINE__);
+#if TRACE_SURFACES
+ printf("VID CREATE: %u\n", videoSurfaces[i]);
+#endif
+ }
+
+ assert(!surface_render);
+ if (num_video_surfaces) {
+#define VDP_NUM_MIXER_PARAMETER 3
+ // Creation of VideoMixer.
+ 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, sizeof(struct vdpau_render_state));
+
+ for (i = 0; i < num_video_surfaces; i++) {
+ surface_render[i].state = FF_VDPAU_STATE_USED_FOR_RENDER;
+ surface_render[i].surface = videoSurfaces[i];
+ }
+
+ vdp_st = vdp_video_mixer_create(
+ vdp_device,
+ 0,
+ 0,
+ VDP_NUM_MIXER_PARAMETER,
+ parameters,
+ parameter_values,
+ &videoMixer
+ );
+ if (vdp_st != VDP_STATUS_OK)
+ printf("Error %d at %s:%d\n", vdp_st, __FILE__, __LINE__);
+ }
+
+ max_width = FFMAX(max_width, d_width);
+ max_height = FFMAX(max_height, d_width);
+
+ // Creation of outputSurfaces
+ for (i = 0; i < NUM_OUTPUT_SURFACES; i++) {
+ vdp_st = vdp_output_surface_create(
+ vdp_device,
+ VDP_RGBA_FORMAT_B8G8R8A8,
+ max_width,
+ max_height,
+ &outputSurfaces[i]
+ );
+ if (vdp_st != VDP_STATUS_OK)
+ printf("Error %d at %s:%d\n", vdp_st, __FILE__, __LINE__);
+#if TRACE_SURFACES
+ printf("OUT CREATE: %u\n", outputSurfaces[i]);
+#endif
+ }
+
+ surfaceNum = 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,
+ outputSurface, // outputSurfaces[0 / 1],
+ FFMIN(max_width, FFMAX(outRect.x1, outRectVid.x1)),
+ FFMIN(max_width, FFMAX(outRect.y1, outRectVid.y1)),
+ 0
+ );
+ if (vdp_st != VDP_STATUS_OK)
+ printf("Error %d at %s:%d\n", vdp_st, __FILE__, __LINE__);
+ }
+ }
+}
+
+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 indexData_size_required;
+ unsigned char a;
+ VdpRect outputIndexedRectVid;
+ VdpOutputSurfaceRenderBlendState blendState;
+
+ if (!w || !h)
+ return;
+
+ indexData_size_required = 2*w*h;
+ if (indexData_size < indexData_size_required) {
+ indexData = realloc(indexData, indexData_size_required);
+ indexData_size = indexData_size_required;
+ }
+
+ // indexData creation, component order - I, A, I, A, .....
+ for (i = 0; i < h; i++) {
+ for (j = 0; j < w; j++) {
+ indexData[i*2*w + j*2] = src[i*stride+j]; // index for palette-table
+ a = srca[i*stride+j]; // alpha_data
+ indexData[i*2*w + j*2 + 1] = -srca[i*stride+j];;
+ }
+ }
+
+ outputIndexedRectVid.x0 = outRectVid.x0 + x0;
+ outputIndexedRectVid.y0 = outRectVid.y0 + y0;
+ outputIndexedRectVid.x1 = outputIndexedRectVid.x0 + w;
+ outputIndexedRectVid.y1 = outputIndexedRectVid.y0 + h;
+
+ pitch = w*2;
+
+ // write source_data to outputSurfaces[2].
+ vdp_st = vdp_output_surface_put_bits_indexed(
+ outputSurfaces[2],
+ VDP_INDEXED_FORMAT_I8A8,
+ (void **)&indexData,
+ &pitch,
+ &outputIndexedRectVid,
+ VDP_COLOR_TABLE_FORMAT_B8G8R8X8,
+ (void *)palette
+ );
+ if (vdp_st != VDP_STATUS_OK)
+ printf("Error %d at %s:%d\n", vdp_st, __FILE__, __LINE__);
+
+ blendState.struct_version = VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION;
+ blendState.blend_factor_source_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE;
+ blendState.blend_factor_source_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE;
+ blendState.blend_factor_destination_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
+ blendState.blend_factor_destination_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
+ blendState.blend_equation_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD;
+ blendState.blend_equation_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD;
+
+ // compositing outputSurfaces[2] to outputSurface i.e outputSurfaces - 0 or 1.
+ vdp_st = vdp_output_surface_render_output_surface(
+ outputSurface,
+ &outputIndexedRectVid,
+ outputSurfaces[2],
+ &outputIndexedRectVid,
+ NULL,
+ &blendState,
+ VDP_OUTPUT_SURFACE_RENDER_ROTATE_0
+ );
+ if (vdp_st != VDP_STATUS_OK)
+ printf("Error %d at %s:%d\n", vdp_st, __FILE__, __LINE__);
+}
+
+static void OSD_init()
+{
+ 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;
+ }
+
+ indexData = NULL;
+ indexData_size = 0;
+ osd_alloc = 1;
+}
+
+static void draw_osd(void)
+{
+#if TRACE_SURFACES
+ printf("DRAW_OSD\n");
+#endif
+ if (!osd_alloc)
+ OSD_init();
+
+ vo_draw_text(vo_dwidth, vo_dheight, draw_osd_I8A8);
+}
+
+static void flip_page(void)
+{
+ VdpStatus vdp_st;
+#if TRACE_SURFACES
+ printf("\nFLIP_PAGE VID:%u -> OUT:%u\n", videoSurface, outputSurface);
+#endif
+
+ vdp_st = vdp_presentation_queue_display(
+ vdp_flip_queue,
+ outputSurface,
+ FFMIN(max_width, FFMAX(outRect.x1, outRectVid.x1)),
+ FFMIN(max_width, FFMAX(outRect.y1, outRectVid.y1)),
+ 0
+ );
+ if (vdp_st != VDP_STATUS_OK)
+ printf("Error %d at %s:%d\n", vdp_st, __FILE__, __LINE__);
+
+ surfaceNum = surfaceNum ^ 1;
+ visible_buf = 1;
+ return;
+}
+
+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)
+{
+ VdpStatus vdp_st;
+ struct vdpau_render_state * rndr;
+
+ rndr = (struct vdpau_render_state*)image[2]; // this is a copy of private
+ assert( rndr );
+
+#if TRACE_SURFACES
+ printf("\nDRAW_SLICE -> VID:%u\n", rndr->surface);
+#endif
+
+ /* VdpDecoderRender is called with decoding order. Decoded images are store in
+ * videoSurface like rndr->surface. VdpVideoMixerRender put this videoSurface
+ * to outputSurface which is displayable.
+ */
+ vdp_st = vdp_decoder_render(
+ decoder,
+ rndr->surface,
+ (void*)&(rndr->info),
+ rndr->bitstream_buffers_used,
+ rndr->bitstream_buffers
+ );
+ if (vdp_st != VDP_STATUS_OK)
+ printf("Error %d at %s:%d\n", vdp_st, __FILE__, __LINE__);
+
+ return VO_TRUE;
+}
+
+static int draw_frame(uint8_t * src[])
+{
+#if TRACE_SURFACES
+ printf("DRAW_FRAME\n");
+#endif
+
+ mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_XV_DrawFrameCalled);
+ return -1;
+}
+
+static uint32_t draw_image(mp_image_t * mpi)
+{
+ VdpStatus vdp_st;
+ VdpTime dummy;
+ VdpYCbCrFormat vdp_ycbcr_format;
+ VdpRGBAFormat vdp_rgba_format;
+ void *destdata[3];
+
+ // check for non-VDPAU and non RGB/YUV4:4:4 surface formats.
+ switch (image_format) {
+ case IMGFMT_YV12:
+ assert(mpi->num_planes == 3);
+ vdp_ycbcr_format = VDP_YCBCR_FORMAT_YV12;
+ destdata[0] = mpi->planes[0];
+ destdata[1] = mpi->planes[2];
+ destdata[2] = mpi->planes[1];
+ videoSurface = videoSurfaces[0];
+
+ vdp_st = vdp_video_surface_put_bits_y_cb_cr(
+ videoSurface,
+ vdp_ycbcr_format, // YV12
+ destdata,
+ mpi->stride // pitch
+ );
+ if (vdp_st != VDP_STATUS_OK)
+ printf("Error %d at %s:%d\n", vdp_st, __FILE__, __LINE__);
+ break;
+ default:
+ break;
+ }
+
+ outputSurface = outputSurfaces[surfaceNum];
+ vdp_st = vdp_presentation_queue_block_until_surface_idle(
+ vdp_flip_queue,
+ outputSurface,
+ &dummy
+ );
+ if (vdp_st != VDP_STATUS_OK)
+ printf("Error %d at %s:%d\n", vdp_st, __FILE__, __LINE__);
+
+ if (!num_video_surfaces) { // RGB surface formats
+ switch (image_format) {
+ case IMGFMT_BGRA:
+ assert(mpi->num_planes == 1);
+ vdp_rgba_format = VDP_RGBA_FORMAT_B8G8R8A8;
+ destdata[0] = mpi->planes[0];
+ break;
+ default:
+ assert(0);
+ return VO_ERROR;
+ }
+ vdp_st = vdp_output_surface_put_bits_native(
+ outputSurface,
+ destdata,
+ mpi->stride, // pitch
+ NULL // or &outRectVid ?? Not sure.
+ );
+ if (vdp_st != VDP_STATUS_OK)
+ printf("Error %d at %s:%d\n", vdp_st, __FILE__, __LINE__);
+ } else {
+ vdp_st = vdp_video_mixer_render(
+ videoMixer,
+ VDP_INVALID_HANDLE,
+ 0,
+ VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME,
+ 0,
+ NULL,
+ videoSurface,
+ 0,
+ NULL,
+ NULL,
+ outputSurface,
+ &outRect,
+ &outRectVid,
+ 0,
+ NULL
+ );
+ if (vdp_st != VDP_STATUS_OK)
+ printf("Error %d at %s:%d\n", vdp_st, __FILE__, __LINE__);
+ }
+
+#if TRACE_SURFACES
+ printf("\DRAW IMG:%u\n", videoSurface);
+#endif
+
+ return VO_TRUE;
+}
+
+static int query_format(uint32_t format)
+{
+ /* Following surface format is supported by VDPAU.
+ * vd.c: mpcodecs_config_vo() queries supported surface
+ * format for VDPAU.
+ * Return flag/value describes driver-capabilities.
+ * (VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN
+ * are basic driver capabilities.)
+ */
+
+ switch (format) {
+ // non-VDPAU specific format. used in non-accelerated video.
+ case IMGFMT_YV12:
+ case IMGFMT_BGRA:
+ return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_OSD;
+ }
+
+ return 0;
+}
+
+static void DestroyVdpauObjects()
+{
+ int i;
+ VdpStatus vdp_st;
+
+ vdp_st = win_x11_fini_vdpau_flip_queue();
+ if (vdp_st != VDP_STATUS_OK)
+ printf("Error %d at %s:%d\n", vdp_st, __FILE__, __LINE__);
+
+ if (num_video_surfaces) {
+ vdp_st = vdp_video_mixer_destroy(videoMixer);
+ if (vdp_st != VDP_STATUS_OK)
+ printf("Error %d at %s:%d\n", vdp_st, __FILE__, __LINE__);
+ }
+
+ for (i = 0; i < NUM_OUTPUT_SURFACES; i++) {
+ vdp_st = vdp_output_surface_destroy(outputSurfaces[i]);
+ if (vdp_st != VDP_STATUS_OK)
+ printf("Error %d at %s:%d\n", vdp_st, __FILE__, __LINE__);
+ }
+
+ for (i = 0; i < num_video_surfaces; i++) {
+ vdp_st = vdp_video_surface_destroy(videoSurfaces[i]);
+ if (vdp_st != VDP_STATUS_OK)
+ printf("Error %d at %s:%d\n", vdp_st, __FILE__, __LINE__);
+ }
+
+ vdp_st = win_x11_fini_vdpau_procs();
+ if (vdp_st != VDP_STATUS_OK)
+ printf("Error %d at %s:%d\n", vdp_st, __FILE__, __LINE__);
+}
+
+static void uninit(void)
+{
+ if (!vo_config_count)
+ return;
+ visible_buf = -1;
+ osd_alloc = 0;
+
+ /* Destroy all vdpau objects */
+ DestroyVdpauObjects();
+
+ free(videoSurfaces);
+ videoSurfaces = NULL;
+ free(surface_render);
+ surface_render = NULL;
+ free(indexData);
+ indexData = NULL;
+ free(palette);
+ palette = NULL;
+
+#ifdef HAVE_XF86VM
+ vo_vm_close(mDisplay);
+#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())
+ return -1; // Can't open X11
+
+ 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();
+ 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 28285)
+++ 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 ;;
@@ -4036,7 +4040,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"
@@ -4147,6 +4151,30 @@
echores "$_xvmc"
+echocheck "VDPAU"
+if test "$_vdpau" = auto ; then
+ cat > $TMPC <<EOF
+#include <vdpau/vdpau_x11.h>
+int main(void) {
+ (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"
+ _vosrc="$_vosrc vo_vdpau.c"
+ _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
@@ -8066,6 +8094,7 @@
UNRAR_EXEC = $_unrar_exec
V4L2 = $_v4l2
VCD = $_vcd
+VDPAU = $_vdpau
VESA = $_vesa
VIDIX = $_vidix
VIDIX_PCIDB = $_vidix_pcidb_val
@@ -8501,6 +8530,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