[MPlayer-dev-eng] [PATCH]Add vo vdpau
Carl Eugen Hoyos
cehoyos at rainbow.studorg.tuwien.ac.at
Mon Jan 5 04:28:52 CET 2009
Hi!
Attached is a first version of vo vdpau.
When I shortly tested it, it seemed as fast as xv.
It is of course precondition for HW accelerated VDPAU decoding.
Please comment (not to harsh), Carl Eugen
-------------- next part --------------
Index: Makefile
===================================================================
--- Makefile (revision 28258)
+++ 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 28258)
+++ 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,1145 @@
+/*
+ * 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_render.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)
+
+#define ARSIZE(x) (sizeof(x) / sizeof((x)[0]))
+
+/* MACRO for error check */
+#define CHECK_ST \
+ if (vdp_st != VDP_STATUS_OK) { \
+ printf("Error %d at %s:%d\n", vdp_st, __FILE__, __LINE__); \
+ exit(1); \
+ }
+
+/* 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 varialbles of win_x11_init_vdpau_procs() and
+ * win_x11_init_vdpau_flip_queue() function.
+ */
+VdpDevice vdp_device;
+VdpGetProcAddress * vdp_get_proc_address;
+
+VdpPresentationQueueTarget vdp_flip_target;
+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.
+ */
+VdpVideoSurfacePutBitsYCbCr * vdp_video_surface_put_bits_y_cb_cr;
+VdpVideoSurfacePutBitsYCbCr * vdp_video_surface_get_bits_y_cb_cr;
+
+VdpOutputSurfacePutBitsYCbCr * vdp_output_surface_put_bits_y_cb_cr;
+VdpOutputSurfacePutBitsNative * vdp_output_surface_put_bits_native;
+
+VdpOutputSurfaceCreate * vdp_output_surface_create;
+VdpOutputSurfaceDestroy * vdp_output_surface_destroy;
+
+/* videoMixer puts videoSurface data to displayble ouputSurface. */
+VdpVideoMixerCreate * vdp_video_mixer_create;
+VdpVideoMixerSetFeatureEnables * vdp_video_mixer_set_feature_enables;
+VdpVideoMixerDestroy * vdp_video_mixer_destroy;
+VdpVideoMixerRender * vdp_video_mixer_render;
+
+VdpPresentationQueueTargetDestroy * vdp_presentation_queue_target_destroy;
+VdpPresentationQueueCreate * vdp_presentation_queue_create;
+VdpPresentationQueueDestroy * vdp_presentation_queue_destroy;
+VdpPresentationQueueDisplay * vdp_presentation_queue_display;
+VdpPresentationQueueBlockUntilSurfaceIdle * vdp_presentation_queue_block_until_surface_idle;
+VdpPresentationQueueTargetCreateX11 * vdp_presentation_queue_target_create_x11;
+VdpPresentationQueueQuerySurfaceStatus * vdp_presentation_queue_query_surface_status;
+
+/* outputSurfaces[2] is used in composite-picture. */
+VdpOutputSurfaceRenderOutputSurface * vdp_output_surface_render_output_surface;
+VdpOutputSurfacePutBitsIndexed * vdp_output_surface_put_bits_indexed;
+
+VdpDecoderCreate * vdp_decoder_create;
+VdpDecoderDestroy * vdp_decoder_destroy;
+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;
+int surfaceNum;
+static uint32_t vid_width, vid_height;
+static uint32_t image_format;
+static uint32_t num_video_surfaces;
+extern uint32_t num_reference_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 Window mRoot;
+static uint32_t drwX, drwY, drwBorderWidth, drwDepth;
+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)
+{
+ *drwX = *drwY = 0;
+ if (vo_fs) {
+ aspect(&vo_dwidth, &vo_dheight, A_ZOOM);
+ vo_dwidth = FFMIN(vo_dwidth, vo_screenwidth);
+ vo_dheight = FFMIN(vo_dheight, vo_screenheight);
+ *drwX = (vo_screenwidth - vo_dwidth) / 2;
+ *drwY = (vo_screenheight - vo_dheight) / 2;
+ mp_msg(MSGT_VO, MSGL_V, "[vdpau-fs] dx: %d dy: %d dw: %d dh: %d\n",
+ *drwX, *drwY, vo_dwidth, vo_dheight);
+ } else if (WinID == 0) {
+ *drwX = vo_dx;
+ *drwY = vo_dy;
+ }
+
+ // 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;
+
+ // Create Device
+ vdp_st = vdp_device_create_x11(
+ mDisplay, //x_display,
+ mScreen, //x_screen,
+ &vdp_device,
+ &vdp_get_proc_address
+ );
+ CHECK_ST
+
+ vdp_st = vdp_get_proc_address(
+ vdp_device,
+ VDP_FUNC_ID_DEVICE_DESTROY,
+ (void *)&vdp_device_destroy
+ );
+ CHECK_ST
+
+ vdp_st = vdp_get_proc_address(
+ vdp_device,
+ VDP_FUNC_ID_VIDEO_SURFACE_CREATE,
+ (void *)&vdp_video_surface_create
+ );
+ CHECK_ST
+
+ vdp_st = vdp_get_proc_address(
+ vdp_device,
+ VDP_FUNC_ID_VIDEO_SURFACE_DESTROY,
+ (void *)&vdp_video_surface_destroy
+ );
+ CHECK_ST
+
+ vdp_st = vdp_get_proc_address(
+ vdp_device,
+ VDP_FUNC_ID_VIDEO_SURFACE_PUT_BITS_Y_CB_CR,
+ (void *)&vdp_video_surface_put_bits_y_cb_cr
+ );
+ CHECK_ST
+
+ vdp_st = vdp_get_proc_address(
+ vdp_device,
+ VDP_FUNC_ID_VIDEO_SURFACE_GET_BITS_Y_CB_CR,
+ (void *)&vdp_video_surface_get_bits_y_cb_cr
+ );
+ CHECK_ST
+
+ vdp_st = vdp_get_proc_address(
+ vdp_device,
+ VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_Y_CB_CR,
+ (void *)&vdp_output_surface_put_bits_y_cb_cr
+ );
+ CHECK_ST
+
+ vdp_st = vdp_get_proc_address(
+ vdp_device,
+ VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_NATIVE,
+ (void *)&vdp_output_surface_put_bits_native
+ );
+ CHECK_ST
+
+
+ vdp_st = vdp_get_proc_address(
+ vdp_device,
+ VDP_FUNC_ID_OUTPUT_SURFACE_CREATE,
+ (void *)&vdp_output_surface_create
+ );
+ CHECK_ST
+
+ vdp_st = vdp_get_proc_address(
+ vdp_device,
+ VDP_FUNC_ID_OUTPUT_SURFACE_DESTROY,
+ (void *)&vdp_output_surface_destroy
+ );
+ CHECK_ST
+
+ vdp_st = vdp_get_proc_address(
+ vdp_device,
+ VDP_FUNC_ID_VIDEO_MIXER_CREATE,
+ (void *)&vdp_video_mixer_create
+ );
+ CHECK_ST
+
+ vdp_st = vdp_get_proc_address(
+ vdp_device,
+ VDP_FUNC_ID_VIDEO_MIXER_SET_FEATURE_ENABLES,
+ (void *)&vdp_video_mixer_set_feature_enables
+ );
+ CHECK_ST
+
+ vdp_st = vdp_get_proc_address(
+ vdp_device,
+ VDP_FUNC_ID_VIDEO_MIXER_DESTROY,
+ (void *)&vdp_video_mixer_destroy
+ );
+ CHECK_ST
+
+ vdp_st = vdp_get_proc_address(
+ vdp_device,
+ VDP_FUNC_ID_VIDEO_MIXER_RENDER,
+ (void *)&vdp_video_mixer_render
+ );
+ CHECK_ST
+
+ vdp_st = vdp_get_proc_address(
+ vdp_device,
+ VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_DESTROY,
+ (void *)&vdp_presentation_queue_target_destroy
+ );
+ CHECK_ST
+
+ vdp_st = vdp_get_proc_address(
+ vdp_device,
+ VDP_FUNC_ID_PRESENTATION_QUEUE_CREATE,
+ (void *)&vdp_presentation_queue_create
+ );
+ CHECK_ST
+
+ vdp_st = vdp_get_proc_address(
+ vdp_device,
+ VDP_FUNC_ID_PRESENTATION_QUEUE_DESTROY,
+ (void *)&vdp_presentation_queue_destroy
+ );
+ CHECK_ST
+
+ vdp_st = vdp_get_proc_address(
+ vdp_device,
+ VDP_FUNC_ID_PRESENTATION_QUEUE_DISPLAY,
+ (void *)&vdp_presentation_queue_display
+ );
+ CHECK_ST
+
+ vdp_st = vdp_get_proc_address(
+ vdp_device,
+ VDP_FUNC_ID_PRESENTATION_QUEUE_BLOCK_UNTIL_SURFACE_IDLE,
+ (void *)&vdp_presentation_queue_block_until_surface_idle
+ );
+ CHECK_ST
+
+ vdp_st = vdp_get_proc_address(
+ vdp_device,
+ VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_CREATE_X11,
+ (void *)&vdp_presentation_queue_target_create_x11
+ );
+ CHECK_ST
+
+ vdp_st = vdp_get_proc_address(
+ vdp_device,
+ VDP_FUNC_ID_DECODER_CREATE,
+ (void *)&vdp_decoder_create
+ );
+ CHECK_ST
+
+ vdp_st = vdp_get_proc_address(
+ vdp_device,
+ VDP_FUNC_ID_DECODER_DESTROY,
+ (void *)&vdp_decoder_destroy
+ );
+ CHECK_ST
+
+ vdp_st = vdp_get_proc_address(
+ vdp_device,
+ VDP_FUNC_ID_DECODER_RENDER,
+ (void *)&vdp_decoder_render
+ );
+ CHECK_ST
+
+ vdp_st = vdp_get_proc_address(
+ vdp_device,
+ VDP_FUNC_ID_PRESENTATION_QUEUE_QUERY_SURFACE_STATUS,
+ (void *)&vdp_presentation_queue_query_surface_status
+ );
+ CHECK_ST
+
+ // Added for draw_osd.
+ vdp_st = vdp_get_proc_address(
+ vdp_device,
+ VDP_FUNC_ID_OUTPUT_SURFACE_RENDER_OUTPUT_SURFACE,
+ (void *)&vdp_output_surface_render_output_surface
+ );
+ CHECK_ST
+
+ vdp_st = vdp_get_proc_address(
+ vdp_device,
+ VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_INDEXED,
+ (void *)&vdp_output_surface_put_bits_indexed
+ );
+ CHECK_ST
+}
+
+/* Destroy vdpau procs, called from uninit() */
+static VdpStatus win_x11_fini_vdpau_procs(void)
+{
+ VdpStatus vdp_st;
+
+ vdp_st = vdp_device_destroy(
+ vdp_device
+ );
+ CHECK_ST
+
+ 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
+ );
+ CHECK_ST
+
+ vdp_st = vdp_presentation_queue_create(
+ vdp_device,
+ vdp_flip_target,
+ &vdp_flip_queue
+ );
+ CHECK_ST
+
+}
+
+/* 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
+ );
+ CHECK_ST
+
+ vdp_st = vdp_presentation_queue_target_destroy(
+ vdp_flip_target
+ );
+ CHECK_ST
+
+ 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;
+ uint32_t max_references;
+
+#ifdef HAVE_XF86VM
+ int vm = 0;
+ unsigned int modeline_width, modeline_height;
+ static uint32_t vm_width;
+ static uint32_t vm_height;
+#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;
+
+ // FIXME: Are higher profiles able to decode all lower profile streams?
+ 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;
+ }
+
+ vo_mouse_autohide = 1;
+ int_pause = 0;
+ visible_buf = -1;
+
+#ifdef HAVE_XF86VM
+ if (flags & VOFLAG_MODESWITCHING)
+ vm = 1;
+#endif
+
+ 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)
+ {
+ if ((d_width == 0) && (d_height == 0))
+ {
+ vm_width = width;
+ vm_height = height;
+ } else
+ {
+ vm_width = d_width;
+ vm_height = d_height;
+ }
+ vo_vm_switch(vm_width, vm_height, &modeline_width,
+ &modeline_height);
+ aspect_save_screenres(modeline_width, modeline_height);
+ } 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;
+
+ if (WinID >= 0)
+ {
+ vo_window = WinID ? ((Window) WinID) : mRootWin;
+ if (WinID)
+ {
+ XUnmapWindow(mDisplay, vo_window);
+ XChangeWindowAttributes(mDisplay, vo_window, xswamask,
+ &xswa);
+ vo_x11_selectinput_witherr(mDisplay, vo_window,
+ StructureNotifyMask |
+ KeyPressMask |
+ PropertyChangeMask |
+ PointerMotionMask |
+ ButtonPressMask |
+ ButtonReleaseMask |
+ ExposureMask);
+ XMapWindow(mDisplay, vo_window);
+ XGetGeometry(mDisplay, vo_window, &mRoot,
+ &drwX, &drwY, &vo_dwidth, &vo_dheight,
+ &drwBorderWidth, &drwDepth);
+ if (vo_dwidth <= 0) vo_dwidth = d_width;
+ if (vo_dheight <= 0) vo_dheight = d_height;
+ aspect_save_prescale(vo_dwidth, vo_dheight);
+ }
+ } else
+ {
+ 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
+ }
+
+ aspect(&vo_dwidth, &vo_dheight, A_NOZOOM);
+ if ((flags & VOFLAG_FULLSCREEN) && WinID <= 0) vo_fs = 1;
+ calc_drwXY_dWH(&drwX, &drwY, &d_width, &d_height);
+ panscan_calc();
+
+ if (vo_ontop)
+ vo_x11_setlayer(mDisplay, vo_window, vo_ontop);
+
+ /* -----VDPAU related code here -------- */
+ if (num_video_surfaces) {
+ videoSurfaces = (VdpVideoSurface *)malloc(sizeof(VdpVideoSurface)*num_video_surfaces);
+ } else {
+ videoSurfaces = NULL;
+ }
+
+ /* get proc address */
+ win_x11_init_vdpau_procs();
+ win_x11_init_vdpau_flip_queue();
+
+ // video width and height
+ vid_width = width;
+ vid_height = height;
+
+ max_references = 2;
+
+ // 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]
+ );
+ CHECK_ST
+#if TRACE_SURFACES
+ printf("VID CREATE: %u\n", videoSurfaces[i]);
+#endif
+ }
+
+ if (num_video_surfaces) {
+ // Creation of VideoMixer.
+ VdpVideoMixerParameter parameters[] = {
+ VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH,
+ VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT,
+ VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE
+ };
+
+ void const * parameter_values[] = {
+ &vid_width,
+ &vid_height,
+ &vdp_chroma_type
+ };
+
+ surface_render = malloc(num_video_surfaces*sizeof(struct vdpau_render_state));
+ memset(surface_render,0,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,
+ ARSIZE(parameters),
+ parameters,
+ parameter_values,
+ &videoMixer
+ );
+ CHECK_ST
+ } else {
+ surface_render = NULL;
+ }
+
+ 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]
+ );
+ CHECK_ST
+#if TRACE_SURFACES
+ printf("OUT CREATE: %u\n", outputSurfaces[i]);
+#endif
+ }
+
+ surfaceNum = 0;
+ vo_directrendering = 1;
+
+ 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
+ );
+ CHECK_ST
+ }
+
+ }
+}
+
+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 == 0 || h == 0)
+ return;
+
+ indexData_size_required = 2*w*h;
+ if (indexData_size < indexData_size_required) {
+ indexData = (unsigned char *)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] = (a == 0) ? 255 : a;
+ }
+ }
+
+ 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
+ );
+ CHECK_ST
+
+ blendState.struct_version = VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION;
+ blendState.blend_factor_source_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
+ blendState.blend_factor_source_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
+ blendState.blend_factor_destination_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_SRC_ALPHA;
+ blendState.blend_factor_destination_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_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
+ );
+ CHECK_ST
+}
+
+static void OSD_init()
+{
+ int i;
+
+ if (vid_width == 0 || vid_height == 0)
+ return;
+
+ /* create palette table */
+ palette = (uint32_t *)malloc(PALETTE_SIZE * sizeof(*palette));
+ if (palette == NULL)
+ return;
+
+ // 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
+ );
+ CHECK_ST
+
+ 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 != NULL );
+
+#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->bitstreamBuffersUsed,
+ rndr->bitstreamBuffers
+ );
+ CHECK_ST
+
+ 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
+ );
+ CHECK_ST
+ break;
+ default:
+ break;
+ }
+
+ outputSurface = outputSurfaces[surfaceNum];
+ vdp_st = vdp_presentation_queue_block_until_surface_idle(
+ vdp_flip_queue,
+ outputSurface,
+ &dummy
+ );
+ CHECK_ST
+
+ 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.
+ );
+ CHECK_ST
+ } 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
+ );
+ CHECK_ST
+ }
+
+#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;
+ }
+
+ return 0;
+}
+
+static void DestroyVdpauObjects()
+{
+ int i;
+ VdpStatus vdp_st;
+
+ vdp_st = win_x11_fini_vdpau_flip_queue();
+ CHECK_ST
+
+ if (num_video_surfaces) {
+ vdp_st = vdp_video_mixer_destroy(
+ videoMixer
+ );
+ CHECK_ST
+ }
+
+ for (i = 0; i < NUM_OUTPUT_SURFACES; i++) {
+ vdp_st = vdp_output_surface_destroy(
+ outputSurfaces[i]
+ );
+ CHECK_ST
+ }
+
+ for (i = 0; i < num_video_surfaces; i++) {
+ vdp_st = vdp_video_surface_destroy(
+ videoSurfaces[i]
+ );
+ CHECK_ST
+ }
+
+ vdp_st = win_x11_fini_vdpau_procs();
+ CHECK_ST
+}
+
+static void uninit(void)
+{
+ if (!vo_config_count)
+ return;
+ visible_buf = -1;
+ osd_alloc = 0;
+
+ /* Destroy all vdpau objects */
+ DestroyVdpauObjects();
+
+ if (videoSurfaces) {
+ free(videoSurfaces);
+ videoSurfaces = NULL;
+ }
+
+ if (surface_render) {
+ free(surface_render);
+ surface_render = NULL;
+ }
+
+ if (indexData) {
+ free(indexData);
+ indexData = NULL;
+ }
+
+ if (palette) {
+ free(palette);
+ palette = NULL;
+ }
+
+#ifdef HAVE_XF86VM
+ vo_vm_close(mDisplay);
+#endif
+ mp_input_rm_event_fd(ConnectionNumber(mDisplay));
+ vo_x11_uninit();
+}
+
+static int preinit(const char *arg)
+{
+ if (arg)
+ {
+ mp_msg(MSGT_VO, MSGL_ERR, "vo_x11: 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 28258)
+++ 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
@@ -8067,6 +8095,7 @@
UNRAR_EXEC = $_unrar_exec
V4L2 = $_v4l2
VCD = $_vcd
+VDPAU = $_vdpau
VESA = $_vesa
VIDIX = $_vidix
VIDIX_PCIDB = $_vidix_pcidb_val
@@ -8503,6 +8532,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