# HG changeset patch
# User Petri Hintukainen <phintuka@...>
# Date 1358427683 -7200
# Node ID e3358fb09b8bbdd7e3129d503feec0346155a08a
# Branch default
# Parent a4e2b8a00ad175f2f8604556c94f09f4c2b0dedb
VAAPI decoder and video output plugin from https://github.com/huceke/xine-lib-vaapi
diff --git a/ChangeLog b/ChangeLog
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,5 @@
xine-lib (1.2.3) ????-??-??
+ * Add VAAPI HW decoding support
* Add OpenGL 2.0 output plugin
* Add crop support to XShm output plugins
* Add color matrix and full range support to OpenGL/Xv/XShm output plugins
--git a/include/xine.h b/include/xine.h
--- a/include/xine.h
+++ b/include/xine.h
@@ -458,6 +458,7 @@
#define XINE_IMGFMT_XVMC (('C'<<24)|('M'<<16)|('v'<<8)|'X')
#define XINE_IMGFMT_XXMC (('C'<<24)|('M'<<16)|('x'<<8)|'X')
#define XINE_IMGFMT_VDPAU (('A'<<24)|('P'<<16)|('D'<<8)|'V')
+#define XINE_IMGFMT_VAAPI (('P'<<24)|('A'<<16)|('A'<<8)|'V')
/* get current xine's virtual presentation timestamp (1/90000 sec)
* note: this is mostly internal data.
--git a/include/xine/video_out.h b/include/xine/video_out.h
--- a/include/xine/video_out.h
+++ b/include/xine/video_out.h
@@ -310,6 +310,7 @@
#define VO_CAP_VDPAU_MPEG12 0x00000100 /* driver can use VDPAU for mpeg1/2 */
#define VO_CAP_VDPAU_VC1 0x00000200 /* driver can use VDPAU for VC1 */
#define VO_CAP_VDPAU_MPEG4 0x00000400 /* driver can use VDPAU for mpeg4-part2 */
+#define VO_CAP_VAAPI 0x00000800 /* driver can use VAAPI */
#define VO_CAP_COLOR_MATRIX 0x00004000 /* driver can use alternative yuv->rgb matrices */
#define VO_CAP_FULLRANGE 0x00008000 /* driver handles fullrange yuv */
#define VO_CAP_HUE 0x00010000
--git a/m4/summary.m4 b/m4/summary.m4
--- a/m4/summary.m4
+++ b/m4/summary.m4
@@ -211,6 +211,7 @@
if test x"$have_opengl2" = x"yes"; then
echo " - OpenGL 2.0 (with bicubic scaling)"
fi
+ test x"$have_vaapi" = x"yes" && echo " - vaapi (Video Acceleration (VA) API for Linux)"
test x"$have_vdpau" = x"yes" && echo " - vdpau (X11 Video Decode and Presentation API for Unix)"
if test x"$have_sunfb" = x"yes"; then
if test x"$have_sundga" = x"yes"; then
--git a/m4/video_out.m4 b/m4/video_out.m4
--- a/m4/video_out.m4
+++ b/m4/video_out.m4
@@ -27,6 +27,7 @@
default_enable_xinerama=yes
default_enable_xvmc=yes
default_enable_vdpau=no
+ default_enable_vaapi=no
default_with_caca=yes
default_with_libstk=no
@@ -56,6 +57,7 @@
default_enable_fb=yes
default_enable_vidix=yes
default_enable_vdpau=yes
+ default_enable_vaapi=yes
enable_linux=yes
;;
esac
@@ -517,5 +519,14 @@
fi
fi
AM_CONDITIONAL([ENABLE_VDPAU], test x"$have_vdpau" = x"yes")
-
+
+ dnl VAAPI
+ XINE_ARG_ENABLE([vaapi], [Disable VAAPI output plugin])
+ if test x"$no_x" != x"yes" && test x"$enable_vaapi" != x"no"; then
+ PKG_CHECK_MODULES([LIBVA], [libva], [have_vaapi=yes], [have_vaapi=no])
+ AC_CHECK_HEADERS([va/va.h], , [have_vaapi=no])
+ AC_CHECK_HEADERS([va/va_x11.h], , [have_vaapi=no])
+ fi
+ AM_CONDITIONAL([ENABLE_VAAPI], test x"$have_vaapi" = x"yes")
+
])dnl XINE_VIDEO_OUT_PLUGIN
--git a/src/combined/ffmpeg/ff_video_decoder.c b/src/combined/ffmpeg/ff_video_decoder.c
--- a/src/combined/ffmpeg/ff_video_decoder.c
+++ b/src/combined/ffmpeg/ff_video_decoder.c
@@ -50,6 +50,12 @@
# include <libpostproc/postprocess.h>
#endif
+#ifdef HAVE_VA_VA_X11_H
+#include <libavcodec/vaapi.h>
+#include "accel_vaapi.h"
+#define ENABLE_VAAPI 1
+#endif
+
#include "ffmpeg_compat.h"
#define VIDEOBUFSIZE (128*1024)
@@ -70,6 +76,9 @@
int8_t choose_speed_over_accuracy;
uint8_t enable_dri;
+ uint8_t enable_vaapi;
+ uint8_t vaapi_mpeg_softdec;
+
xine_t *xine;
} ff_video_class_t;
@@ -140,6 +149,12 @@
#endif
uint8_t set_stream_info;
+
+#ifdef ENABLE_VAAPI
+ struct vaapi_context vaapi_context;
+ vaapi_accel_t *accel;
+ vo_frame_t *accel_img;
+#endif
};
/* import color matrix names */
@@ -204,6 +219,7 @@
vo_frame_t *img;
int width = context->width;
int height = context->height;
+ int guarded_render = 0;
ff_check_colorspace (this);
@@ -221,8 +237,70 @@
avcodec_align_dimensions(context, &width, &height);
- if (this->full2mpeg || (this->context->pix_fmt != PIX_FMT_YUV420P &&
- this->context->pix_fmt != PIX_FMT_YUVJ420P)) {
+#ifdef ENABLE_VAAPI
+ if( this->context->pix_fmt == PIX_FMT_VAAPI_VLD) {
+
+ av_frame->opaque = NULL;
+ av_frame->data[0] = NULL;
+ av_frame->data[1] = NULL;
+ av_frame->data[2] = NULL;
+ av_frame->data[3] = NULL;
+ av_frame->type = FF_BUFFER_TYPE_USER;
+#ifdef AVFRAMEAGE
+ av_frame->age = 1;
+#endif
+ av_frame->reordered_opaque = context->reordered_opaque;
+
+ if(!this->accel->guarded_render(this->accel_img)) {
+ img = this->stream->video_out->get_frame (this->stream->video_out,
+ width,
+ height,
+ this->aspect_ratio,
+ this->output_format,
+ VO_BOTH_FIELDS|this->frame_flags);
+
+ av_frame->opaque = img;
+ xine_list_push_back(this->dr1_frames, av_frame);
+
+ vaapi_accel_t *accel = (vaapi_accel_t*)img->accel_data;
+ ff_vaapi_surface_t *va_surface = accel->get_vaapi_surface(img);
+
+ if(va_surface) {
+ av_frame->data[0] = (void *)va_surface;//(void *)(uintptr_t)va_surface->va_surface_id;
+ av_frame->data[3] = (void *)(uintptr_t)va_surface->va_surface_id;
+ }
+ } else {
+ ff_vaapi_surface_t *va_surface = this->accel->get_vaapi_surface(this->accel_img);
+
+ if(va_surface) {
+ av_frame->data[0] = (void *)va_surface;//(void *)(uintptr_t)va_surface->va_surface_id;
+ av_frame->data[3] = (void *)(uintptr_t)va_surface->va_surface_id;
+ }
+ }
+
+ lprintf("1: 0x%08x\n", av_frame->data[3]);
+
+ av_frame->linesize[0] = 0;
+ av_frame->linesize[1] = 0;
+ av_frame->linesize[2] = 0;
+ av_frame->linesize[3] = 0;
+
+ this->is_direct_rendering_disabled = 1;
+
+ return 0;
+ }
+
+ /* on vaapi out do not use direct rendeing */
+ if(this->class->enable_vaapi) {
+ this->output_format = XINE_IMGFMT_YV12;
+ }
+
+ if(this->accel)
+ guarded_render = this->accel->guarded_render(this->accel_img);
+#endif /* ENABLE_VAAPI */
+
+ if ((this->full2mpeg || (this->context->pix_fmt != PIX_FMT_YUV420P &&
+ this->context->pix_fmt != PIX_FMT_YUVJ420P)) || guarded_render) {
if (!this->is_direct_rendering_disabled) {
xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
_("ffmpeg_video_dec: unsupported frame format, DR1 disabled.\n"));
@@ -293,6 +371,18 @@
static void release_buffer(struct AVCodecContext *context, AVFrame *av_frame){
ff_video_decoder_t *this = (ff_video_decoder_t *)context->opaque;
+#ifdef ENABLE_VAAPI
+ if( this->context->pix_fmt == PIX_FMT_VAAPI_VLD ) {
+ if(this->accel->guarded_render(this->accel_img)) {
+ ff_vaapi_surface_t *va_surface = (ff_vaapi_surface_t *)av_frame->data[0];
[... 244 lines omitted ...]
+ this->size);
+ } else
+# endif
+ {
len = avcodec_decode_video (this->context, this->av_frame,
&got_picture, &chunk_buf[offset],
this->size);
+ }
#endif
/* reset consumed pts value */
this->context->reordered_opaque = ff_tag_pts(this, 0);
@@ -1555,7 +1777,7 @@
/* indirect rendering */
/* initialize the colorspace converter */
- if (!this->cs_convert_init) {
+ if (!this->cs_convert_init && !this->context->pix_fmt != PIX_FMT_VAAPI_VLD) {
if ((this->context->pix_fmt == PIX_FMT_RGB32) ||
(this->context->pix_fmt == PIX_FMT_RGB565) ||
(this->context->pix_fmt == PIX_FMT_RGB555) ||
@@ -1591,10 +1813,10 @@
}
/* post processing */
- if(this->pp_quality != this->class->pp_quality)
+ if(this->pp_quality != this->class->pp_quality && this->context->pix_fmt != PIX_FMT_VAAPI_VLD)
pp_change_quality(this);
- if(this->pp_available && this->pp_quality) {
+ if(this->pp_available && this->pp_quality && this->context->pix_fmt != PIX_FMT_VAAPI_VLD) {
if(this->av_frame->opaque) {
/* DR1 */
@@ -1616,7 +1838,8 @@
} else if (!this->av_frame->opaque) {
/* colorspace conversion or copy */
- ff_convert_frame(this, img, this->av_frame);
+ if( this->context->pix_fmt != PIX_FMT_VAAPI_VLD)
+ ff_convert_frame(this, img, this->av_frame);
}
img->pts = ff_untag_pts(this, this->av_frame->reordered_opaque);
@@ -1645,6 +1868,17 @@
img->progressive_frame = !this->av_frame->interlaced_frame;
img->top_field_first = this->av_frame->top_field_first;
+#ifdef ENABLE_VAAPI
+ if( this->context->pix_fmt == PIX_FMT_VAAPI_VLD) {
+ if(this->accel->guarded_render(this->accel_img)) {
+ ff_vaapi_surface_t *va_surface = (ff_vaapi_surface_t *)this->av_frame->data[0];
+ this->accel->render_vaapi_surface(img, va_surface);
+ if(va_surface)
+ lprintf("handle_buffer: render_vaapi_surface va_surface_id 0x%08x\n", this->av_frame->data[0]);
+ }
+ }
+#endif /* ENABLE_VAAPI */
+
this->skipframes = img->draw(img, this->stream);
if(free_img)
@@ -1868,6 +2102,11 @@
xine_list_delete(this->dr1_frames);
+#ifdef ENABLE_VAAPI
+ if(this->accel_img)
+ this->accel_img->free(this->accel_img);
+#endif
+
free (this_gen);
}
@@ -1917,6 +2156,35 @@
this->debug_fmt = -1;
#endif
+#ifdef ENABLE_VAAPI
+ memset(&this->vaapi_context, 0x0 ,sizeof(struct vaapi_context));
+
+ this->accel = NULL;
+ this->accel_img = NULL;
+#endif
+
+
+#ifdef ENABLE_VAAPI
+ if(this->class->enable_vaapi && (stream->video_driver->get_capabilities(stream->video_driver) & VO_CAP_VAAPI)) {
+ xprintf(this->class->xine, XINE_VERBOSITY_LOG, _("ffmpeg_video_dec: vaapi_mpeg_softdec %d\n"),
+ this->class->vaapi_mpeg_softdec );
+
+ this->accel_img = stream->video_out->get_frame( stream->video_out, 1920, 1080, 1, XINE_IMGFMT_VAAPI, VO_BOTH_FIELDS );
+
+ if( this->accel_img ) {
+ this->accel = (vaapi_accel_t*)this->accel_img->accel_data;
+ xprintf(this->class->xine, XINE_VERBOSITY_LOG, _("ffmpeg_video_dec: VAAPI Enabled in config.\n"));
+ } else {
+ this->class->enable_vaapi = 0;
+ xprintf(this->class->xine, XINE_VERBOSITY_LOG, _("ffmpeg_video_dec: VAAPI Enabled disabled by driver.\n"));
+ }
+ } else {
+ this->class->enable_vaapi = 0;
+ this->class->vaapi_mpeg_softdec = 0;
+ xprintf(this->class->xine, XINE_VERBOSITY_LOG, _("ffmpeg_video_dec: VAAPI Enabled disabled by driver.\n"));
+ }
+#endif
+
return &this->video_decoder;
}
@@ -1982,6 +2250,18 @@
"streams with lot of reference frames."),
10, dri_cb, this);
+#ifdef ENABLE_VAAPI
+ this->vaapi_mpeg_softdec = xine->config->register_bool(config, "video.processing.vaapi_mpeg_softdec", 0,
+ _("VAAPI Mpeg2 softdecoding"),
+ _("If the machine freezes on mpeg2 decoding use mpeg2 software decoding."),
+ 10, vaapi_mpeg_softdec_func, this);
+
+ this->enable_vaapi = xine->config->register_bool(config, "video.processing.ffmpeg_enable_vaapi", 1,
+ _("Enable VAAPI"),
+ _("Enable or disable usage of vaapi"),
+ 10, vaapi_enable_vaapi, this);
+#endif /* ENABLE_VAAPI */
+
return this;
}
--git a/src/video_out/Makefile.am b/src/video_out/Makefile.am
--- a/src/video_out/Makefile.am
+++ b/src/video_out/Makefile.am
@@ -46,6 +46,10 @@
vdpau_module = xineplug_vo_out_vdpau.la
endif
+if ENABLE_VAAPI
+vaapi_module = xineplug_vo_out_vaapi.la
+endif
+
if ENABLE_XCB
XCBOSD = xcbosd.c
if ENABLE_XCBSHM
@@ -121,6 +125,7 @@
$(xcbshm_module) \
$(xcbxv_module) \
$(vdpau_module) \
+ $(vaapi_module) \
xineplug_vo_out_raw.la \
xineplug_vo_out_none.la
@@ -128,6 +133,10 @@
xineplug_vo_out_vdpau_la_LIBADD = $(XINE_LIB) $(MLIB_LIBS) $(AVUTIL_LIBS) $(PTHREAD_LIBS) $(X_LIBS) $(LTLIBINTL) $(VDPAU_LIBS) -lm
xineplug_vo_out_vdpau_la_CFLAGS = $(VISIBILITY_FLAG) $(MLIB_CFLAGS) $(X_CFLAGS) $(VDPAU_CFLAGS) $(AVUTIL_CFLAGS) -fno-strict-aliasing
+xineplug_vo_out_vaapi_la_SOURCES = $(X11OSD) video_out_vaapi.c
+xineplug_vo_out_vaapi_la_LIBADD = $(YUV_LIBS) $(XINE_LIB) $(OPENGL_LIBS) $(FFMPEG_LIBS) $(AVUTIL_LIBS) $(X_LIBS) $(PTHREAD_LIBS) $(LTLIBINTL) -ldl -lGLU -lva-glx -lva-x11 -lva
+xineplug_vo_out_vaapi_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS) $(XV_CFLAGS) -fno-strict-aliasing
+
xineplug_vo_out_xcbshm_la_SOURCES = video_out_xcbshm.c $(XCBOSD)
xineplug_vo_out_xcbshm_la_LIBADD = $(YUV_LIBS) $(PTHREAD_LIBS) $(XCB_LIBS) $(XCBSHM_LIBS) $(LTLIBINTL)
xineplug_vo_out_xcbshm_la_CFLAGS = $(AM_CFLAGS) $(XCB_CFLAGS) $(XCBSHM_CFLAGS) $(AVUTIL_CFLAGS) -fno-strict-aliasing
--git a/src/video_out/video_out_vaapi.c b/src/video_out/video_out_vaapi.c
new file mode 100644
--- /dev/null
+++ b/src/video_out/video_out_vaapi.c
@@ -0,0 +1,4014 @@
+/*
+ * Copyright (C) 2000-2004, 2008 the xine project
+ *
+ * This file is part of xine, a free video player.
+ *
+ * xine 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.
+ *
+ * xine 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
+ *
+ * video_out_vaapi.c, VAAPI video extension interface for xine
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <math.h>
+
+#include <sys/types.h>
+#if defined(__FreeBSD__)
+#include <machine/param.h>
+#endif
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/time.h>
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/cursorfont.h>
+#include <time.h>
+#include <unistd.h>
+#include "yuv2rgb.h"
+
+#define LOG_MODULE "video_out_vaapi"
+#define LOG_VERBOSE
+/*
+#define LOG
+*/
+/*
+#define DEBUG_SURFACE
+*/
+#include "xine.h"
+#include <xine/video_out.h>
+#include <xine/xine_internal.h>
+#include <xine/xineutils.h>
+#include <xine/vo_scale.h>
+
+#include <GL/glu.h>
+#include <GL/glx.h>
+#include <GL/glext.h>
+#include <GL/gl.h>
+#include <dlfcn.h>
+
+#include <va/va_x11.h>
+#include <va/va_glx.h>
+
+#include "accel_vaapi.h"
+
+#ifndef VA_SURFACE_ATTRIB_SETTABLE
+#define vaCreateSurfaces(d, f, w, h, s, ns, a, na) \
+ vaCreateSurfaces(d, w, h, f, ns, s)
+#endif
+
+#define RENDER_SURFACES 50
+#define SOFT_SURFACES 3
+#define SW_WIDTH 1920
+#define SW_HEIGHT 1080
+#define STABLE_FRAME_COUNTER 4
+#define SW_CONTEXT_INIT_FORMAT -1 //VAProfileH264Main
+
+#if defined VA_SRC_BT601 && defined VA_SRC_BT709
+# define USE_VAAPI_COLORSPACE 1
+#else
+# define USE_VAAPI_COLORSPACE 0
+#endif
+
+#define IMGFMT_VAAPI 0x56410000 /* 'VA'00 */
+#define IMGFMT_VAAPI_MASK 0xFFFF0000
+#define IMGFMT_IS_VAAPI(fmt) (((fmt) & IMGFMT_VAAPI_MASK) == IMGFMT_VAAPI)
+#define IMGFMT_VAAPI_CODEC_MASK 0x000000F0
+#define IMGFMT_VAAPI_CODEC(fmt) ((fmt) & IMGFMT_VAAPI_CODEC_MASK)
+#define IMGFMT_VAAPI_CODEC_MPEG2 (0x10)
+#define IMGFMT_VAAPI_CODEC_MPEG4 (0x20)
+#define IMGFMT_VAAPI_CODEC_H264 (0x30)
+#define IMGFMT_VAAPI_CODEC_VC1 (0x40)
+#define IMGFMT_VAAPI_MPEG2 (IMGFMT_VAAPI|IMGFMT_VAAPI_CODEC_MPEG2)
+#define IMGFMT_VAAPI_MPEG2_IDCT (IMGFMT_VAAPI|IMGFMT_VAAPI_CODEC_MPEG2|1)
+#define IMGFMT_VAAPI_MPEG2_MOCO (IMGFMT_VAAPI|IMGFMT_VAAPI_CODEC_MPEG2|2)
+#define IMGFMT_VAAPI_MPEG4 (IMGFMT_VAAPI|IMGFMT_VAAPI_CODEC_MPEG4)
+#define IMGFMT_VAAPI_H263 (IMGFMT_VAAPI|IMGFMT_VAAPI_CODEC_MPEG4|1)
+#define IMGFMT_VAAPI_H264 (IMGFMT_VAAPI|IMGFMT_VAAPI_CODEC_H264)
+#define IMGFMT_VAAPI_VC1 (IMGFMT_VAAPI|IMGFMT_VAAPI_CODEC_VC1)
+#define IMGFMT_VAAPI_WMV3 (IMGFMT_VAAPI|IMGFMT_VAAPI_CODEC_VC1|1)
+
+#define FOVY 60.0f
+#define ASPECT 1.0f
+#define Z_NEAR 0.1f
+#define Z_FAR 100.0f
+#define Z_CAMERA 0.869f
+
+#ifndef GLAPIENTRY
+#ifdef APIENTRY
+#define GLAPIENTRY APIENTRY
+#else
+#define GLAPIENTRY
+#endif
+#endif
+
[... 3763 lines omitted ...]
+ this->capabilities = VO_CAP_YV12 | VO_CAP_YUY2 | VO_CAP_CROP | VO_CAP_UNSCALED_OVERLAY | VO_CAP_ARGB_LAYER_OVERLAY | VO_CAP_VAAPI | VO_CAP_CUSTOM_EXTENT_OVERLAY;
+
+ /* overlay converter */
+ this->yuv2rgb_factory = yuv2rgb_factory_init (MODE_24_BGR, 0, NULL);
+ this->ovl_yuv2rgb = this->yuv2rgb_factory->create_converter( this->yuv2rgb_factory );
+
+ this->vo_driver.get_capabilities = vaapi_get_capabilities;
+ this->vo_driver.alloc_frame = vaapi_alloc_frame;
+ this->vo_driver.update_frame_format = vaapi_update_frame_format;
+ this->vo_driver.overlay_begin = vaapi_overlay_begin;
+ this->vo_driver.overlay_blend = vaapi_overlay_blend;
+ this->vo_driver.overlay_end = vaapi_overlay_end;
+ this->vo_driver.display_frame = vaapi_display_frame;
+ this->vo_driver.get_property = vaapi_get_property;
+ this->vo_driver.set_property = vaapi_set_property;
+ this->vo_driver.get_property_min_max = vaapi_get_property_min_max;
+ this->vo_driver.gui_data_exchange = vaapi_gui_data_exchange;
+ this->vo_driver.dispose = vaapi_dispose;
+ this->vo_driver.redraw_needed = vaapi_redraw_needed;
+
+ this->deinterlace = 0;
+ this->vdr_osd_width = 0;
+ this->vdr_osd_height = 0;
+
+ this->vdr_osd_width = config->register_num( config, "video.output.vaapi_vdr_osd_width", 0,
+ _("vaapi: VDR osd width workaround."),
+ _("vaapi: VDR osd width workaround."),
+ 10, vaapi_vdr_osd_width_flag, this );
+
+ this->vdr_osd_height = config->register_num( config, "video.output.vaapi_vdr_osd_height", 0,
+ _("vaapi: VDR osd height workaround."),
+ _("vaapi: VDR osd height workaround."),
+ 10, vaapi_vdr_osd_height_flag, this );
+
+ this->deinterlace = config->register_num( config, "video.output.vaapi_deinterlace", 0,
+ _("vaapi: set deinterlace to 0 ( none ), 1 ( top field ), 2 ( bob )."),
+ _("vaapi: set deinterlace to 0 ( none ), 1 ( top field ), 2 ( bob )."),
+ 10, vaapi_deinterlace_flag, this );
+
+ this->guarded_render = config->register_num( config, "video.output.vaapi_guarded_render", 1,
+ _("vaapi: set vaapi_guarded_render to 0 ( no ) 1 ( yes )"),
+ _("vaapi: set vaapi_guarded_render to 0 ( no ) 1 ( yes )"),
+ 10, vaapi_guarded_render, this );
+
+ this->scaling_level_enum = config->register_enum(config, "video.output.vaapi_scaling_level", 0,
+ (char **)scaling_level_enum_names,
+ _("vaapi: set scaling level to : default (default) fast (fast) hq (HQ) nla (anamorphic)"),
+ _("vaapi: set scaling level to : default (default) fast (fast) hq (HQ) nla (anamorphic)"),
+ 10, vaapi_scaling_level, this);
+
+ this->scaling_level = scaling_level_enum_values[this->scaling_level_enum];
+
+ this->swap_uv_planes = config->register_bool( config, "video.output.vaapi_swap_uv_planes", 0,
+ _("vaapi: swap UV planes."),
+ _("vaapi: this is a workaround for buggy drivers ( intel IronLake ).\n"
+ "There the UV planes are swapped.\n"),
+ 10, vaapi_swap_uv_planes, this);
+
+
+ pthread_mutex_init(&this->vaapi_lock, NULL);
+
+ pthread_mutex_lock(&this->vaapi_lock);
+
+ int i;
+ for (i = 0; i < VO_NUM_PROPERTIES; i++) {
+ this->props[i].value = 0;
+ this->props[i].min = 0;
+ this->props[i].max = 0;
+ this->props[i].atom = 0;
+ this->props[i].entry = NULL;
+ this->props[i].this = this;
+ }
+
+ this->sc.user_ratio =
+ this->props[VO_PROP_ASPECT_RATIO].value = XINE_VO_ASPECT_AUTO;
+ this->props[VO_PROP_ZOOM_X].value = 100;
+ this->props[VO_PROP_ZOOM_Y].value = 100;
+
+ this->va_context->last_sub_surface_id = VA_INVALID_SURFACE;
+ this->va_context->last_sub_image_fmt = 0;
+
+ if(vaapi_init_internal((vo_driver_t *)this, SW_CONTEXT_INIT_FORMAT, SW_WIDTH, SW_HEIGHT, 0) != VA_STATUS_SUCCESS) {
+ vaapi_dispose((vo_driver_t *)this);
+ return NULL;
+ }
+ vaapi_close((vo_driver_t *)this);
+ this->va_context->valid_context = 0;
+ this->va_context->driver = (vo_driver_t *)this;
+
+ pthread_mutex_unlock(&this->vaapi_lock);
+
+ xprintf(this->xine, XINE_VERBOSITY_LOG, LOG_MODULE " vaapi_open: Deinterlace : %d\n", this->deinterlace);
+ xprintf(this->xine, XINE_VERBOSITY_LOG, LOG_MODULE " vaapi_open: Render surfaces : %d\n", RENDER_SURFACES);
+ xprintf(this->xine, XINE_VERBOSITY_LOG, LOG_MODULE " vaapi_open: Opengl render : %d\n", this->opengl_render);
+
+ return &this->vo_driver;
+}
+
+/*
+ * class functions
+ */
+static void *vaapi_init_class (xine_t *xine, void *visual_gen) {
+ vaapi_class_t *this = (vaapi_class_t *) calloc(1, sizeof(vaapi_class_t));
+
+ this->driver_class.open_plugin = vaapi_open_plugin;
+ this->driver_class.identifier = "vaapi";
+ this->driver_class.description = N_("xine video output plugin using the MIT X video extension");
+ this->driver_class.dispose = default_video_driver_class_dispose;
+ this->config = xine->config;
+ this->xine = xine;
+
+ return this;
+}
+
+static const vo_info_t vo_info_vaapi = {
+ 9, /* priority */
+ XINE_VISUAL_TYPE_X11 /* visual type */
+};
+
+/*
+ * exported plugin catalog entry
+ */
+
+const plugin_info_t xine_plugin_info[] EXPORTED = {
+ /* type, API, "name", version, special_info, init_function */
+ { PLUGIN_VIDEO_OUT, 22, "vaapi", XINE_VERSION_CODE, &vo_info_vaapi, vaapi_init_class },
+ { PLUGIN_NONE, 0, "", 0, NULL, NULL }
+};
--git a/src/xine-engine/accel_vaapi.h b/src/xine-engine/accel_vaapi.h
new file mode 100644
--- /dev/null
+++ b/src/xine-engine/accel_vaapi.h
@@ -0,0 +1,135 @@
+/*
+ * Copyright (C) 2008 the xine project
+ *
+ * This file is part of xine, a free video player.
+ *
+ * xine 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.
+ *
+ * xine 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
+ *
+ *
+ * Common acceleration definitions for vdpau
+ *
+ *
+ */
+
+#ifndef HAVE_XINE_ACCEL_VAAPI_H
+#define HAVE_XINE_ACCEL_VAAPI_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <va/va_x11.h>
+#include <pthread.h>
+#ifdef HAVE_FFMPEG_AVUTIL_H
+# include <avcodec.h>
+#else
+# include <libavcodec/avcodec.h>
+#endif
+
+#if LIBAVCODEC_VERSION_MAJOR >= 53 || (LIBAVCODEC_VERSION_MAJOR == 52 && LIBAVCODEC_VERSION_MINOR >= 32)
+# define AVVIDEO 2
+#else
+# define AVVIDEO 1
+# define pp_context pp_context_t
+# define pp_mode pp_mode_t
+#endif
+
+#define NUM_OUTPUT_SURFACES 22
+
+#define SURFACE_FREE 0
+#define SURFACE_ALOC 1
+#define SURFACE_RELEASE 2
+#define SURFACE_RENDER 3
+#define SURFACE_RENDER_RELEASE 5
+
+struct vaapi_equalizer {
+ VADisplayAttribute brightness;
+ VADisplayAttribute contrast;
+ VADisplayAttribute hue;
+ VADisplayAttribute saturation;
+};
+
+typedef struct ff_vaapi_context_s ff_vaapi_context_t;
+
+struct ff_vaapi_context_s {
+ VADisplay va_display;
+ VAContextID va_context_id;
+ VAConfigID va_config_id;
+ int width;
+ int height;
+ int sw_width;
+ int sw_height;
+ int va_profile;
+ unsigned int va_colorspace;
+ VAImage va_subpic_image;
+ VASubpictureID va_subpic_id;
+ int va_subpic_width;
+ int va_subpic_height;
+ int is_bound;
+ void *gl_surface;
+ unsigned int soft_head;
+ unsigned int valid_context;
+ unsigned int va_head;
+ unsigned int va_soft_head;
+ vo_driver_t *driver;
+ unsigned int last_sub_image_fmt;
+ VASurfaceID last_sub_surface_id;
+ struct vaapi_equalizer va_equalizer;
+ VAImageFormat *va_image_formats;
+ int va_num_image_formats;
+ VAImageFormat *va_subpic_formats;
+ int va_num_subpic_formats;
+};
+
+typedef struct ff_vaapi_surface_s ff_vaapi_surface_t;
+typedef struct vaapi_accel_s vaapi_accel_t;
+
+struct ff_vaapi_surface_s {
+ unsigned int index;
+ vaapi_accel_t *accel;
+ VASurfaceID va_surface_id;
+ unsigned int status;
+};
+
+struct vaapi_accel_s {
+ unsigned int index;
+ vo_frame_t *vo_frame;
+
+#if AVVIDEO > 1
+ int (*avcodec_decode_video2)(vo_frame_t *frame_gen, AVCodecContext *avctx, AVFrame *picture,
+ int *got_picture_ptr, AVPacket *avpkt);
+#else
+ int (*avcodec_decode_video)(vo_frame_t *frame_gen, AVCodecContext *avctx, AVFrame *picture,
+ int *got_picture_ptr, uint8_t *buf, int buf_size);
+#endif
+ VAStatus (*vaapi_init)(vo_frame_t *frame_gen, int va_profile, int width, int height, int softrender);
+ int (*profile_from_imgfmt)(vo_frame_t *frame_gen, enum PixelFormat pix_fmt, int codec_id, int vaapi_mpeg_sofdec);
+ ff_vaapi_context_t *(*get_context)(vo_frame_t *frame_gen);
+ int (*guarded_render)(vo_frame_t *frame_gen);
+ ff_vaapi_surface_t *(*get_vaapi_surface)(vo_frame_t *frame_gen);
+ void (*render_vaapi_surface)(vo_frame_t *frame_gen, ff_vaapi_surface_t *va_surface);
+ void (*release_vaapi_surface)(vo_frame_t *frame_gen, ff_vaapi_surface_t *va_surface);
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
|