Index: /home/mark/trunk/mythtv/configure
===================================================================
--- /home/mark/trunk/mythtv/configure	(revision 25868)
+++ /home/mark/trunk/mythtv/configure	(working copy)
@@ -128,6 +128,7 @@
   --enable-xvmc-vld        enable XvMC VLD accel. for the Unichrome (Pro) chipset
   --xvmc-lib=LIB           XvMC library override (for crosscompiling)
   --enable-vdpau           enable NVidia VDPAU hardware acceleration.
+  --enable-vaapi           enable VAAPI hardware acceleration
   --enable-crystalhd       enable Broadcom CrystalHD hardware decoder support
   --disable-opengl-video   disable OpenGL based video display
   --disable-quartz-video   disable Mac OS X CoreVideo based video display
@@ -1347,6 +1348,7 @@
     mythtranscode
     opengl
     vdpau
+    vaapi
 '
 
 CMDLINE_SELECT="
@@ -1709,6 +1711,7 @@
 xvmc_deps="xv X11_extensions_XvMClib_h"
 xvmc_vld_deps="xvmc X11_extensions_vldXvMC_h"
 xvmcw_deps="xvmc"
+vaapi_deps="x11 opengl_video"
 
 <<BLOCKQUOTE
 # tests
@@ -3541,6 +3544,8 @@
 check_header termios.h
 check_header vdpau/vdpau.h
 check_header vdpau/vdpau_x11.h
+check_header va/va.h
+check_header va/va_glx.h
 check_header X11/extensions/XvMClib.h
 
 check_struct dxva2api.h DXVA_PictureParameters wDecodedPictureIndex
@@ -3819,6 +3824,18 @@
         disable crystalhd;
 fi
 
+if enabled vaapi; then
+    enabled va_va_h && enabled va_va_glx_h || disable vaapi
+    if enabled vaapi; then
+        # for XvBA/VDPAU backends we need splitted desktop 0.31.0 but
+        # for upstream GLX support we need 0.31.1 ???
+        check_cpp_condition va/va.h "VA_VERSION_HEX >= 0x001F0000" ||
+        { echolog "VAAPI requires libva >= 0.31.1" && disable vaapi; }
+    fi
+else
+    disable vaapi
+fi
+
 enabled debug && add_cflags -g"$debuglevel" && add_asflags -g"$debuglevel"
 enabled debug && add_cxxflags -g"$debuglevel"
 
@@ -4376,6 +4393,7 @@
   echo "XvMC libs                 $VENDOR_XVMC_LIBS"
 fi
   echo "VDPAU support             ${vdpau-no}"
+  echo "VAAPI support             ${vaapi-no}"
   echo "CrystalHD support         ${crystalhd-no}"
 fi
   echo "OpenGL video              ${opengl_video-no}"
Index: /home/mark/trunk/mythtv/libs/libmythtv/videoout_openglvaapi.h
===================================================================
--- /home/mark/trunk/mythtv/libs/libmythtv/videoout_openglvaapi.h	(revision 0)
+++ /home/mark/trunk/mythtv/libs/libmythtv/videoout_openglvaapi.h	(revision 0)
@@ -0,0 +1,48 @@
+#ifndef VIDEOOUTPUTOPENGLVAAPI_H
+#define VIDEOOUTPUTOPENGLVAAPI_H
+
+#include "videoout_opengl.h"
+#include "vaapicontext.h"
+
+class VideoOutputOpenGLVAAPI : public VideoOutputOpenGL
+{
+  public:
+    static void GetRenderOptions(render_opts &opts);
+
+    VideoOutputOpenGLVAAPI();
+   ~VideoOutputOpenGLVAAPI();
+
+    bool  Init(int width, int height, float aspect, WId winid,
+               int winx, int winy, int winw, int winh,
+               MythCodecID codec_id, WId embedid = 0);
+    bool  CreateVAAPIContext(QSize size);
+    void  DeleteVAAPIContext(void);
+    bool  CreateBuffers(void);
+    void* GetVAAPIContext(void);
+    uint8_t* GetSurfaceIDPointer(void* buf);
+    void  SetProfile(void);
+    void  TearDown(void);
+    bool  InputChanged(const QSize &input_size, float aspect,
+                       MythCodecID  av_codec_id, void *codec_private,
+                       bool &aspect_only);
+    void  ProcessFrame(VideoFrame *frame, OSD *osd,
+                       FilterChain *filterList,
+                       const PIPMap &pipPlayers,
+                       FrameScanType scan);
+    bool  ApproveDeintFilter(const QString& filtername) const;
+    bool  SetDeinterlacingEnabled(bool);
+    bool  SetupDeinterlace(bool i, const QString& ovrf="");
+    
+    static QStringList GetAllowedRenderers(MythCodecID myth_codec_id,
+                                           const QSize &video_dim);
+    static MythCodecID GetBestSupportedCodec(uint width, uint height,
+                                             uint stream_type,
+                                             bool no_acceleration,
+                                             PixelFormat &pix_fmt);
+
+  private:
+    VAAPIContext *m_ctx;
+};
+
+#endif // VIDEOOUTPUTOPENGLVAAPI_H
+
Index: /home/mark/trunk/mythtv/libs/libmythtv/videoout_opengl.cpp
===================================================================
--- /home/mark/trunk/mythtv/libs/libmythtv/videoout_opengl.cpp	(revision 25868)
+++ /home/mark/trunk/mythtv/libs/libmythtv/videoout_opengl.cpp	(working copy)
@@ -7,8 +7,8 @@
 #include "osd.h"
 #include "mythuihelper.h"
 
-#define LOC      QString("VidOutOGL: ")
-#define LOC_ERR  QString("VidOutOGL: ")
+#define LOC      QString("VidOutGL: ")
+#define LOC_ERR  QString("VidOutGL Error: ")
 
 void VideoOutputOpenGL::GetRenderOptions(render_opts &opts,
                                          QStringList &cpudeints)
@@ -125,12 +125,12 @@
                       winid, winx, winy, winw, winh,
                       codec_id, embedid);
 
-    if (db_vdisp_profile)
-        db_vdisp_profile->SetVideoRenderer("opengl");
+    SetProfile();
 
     success &= SetupContext();
     InitDisplayMeasurements(width, height, false);
     success &= CreateBuffers();
+    success &= CreatePauseFrame();
     success &= SetupOpenGL();
 
     InitOSD();
@@ -146,18 +146,23 @@
     return success;
 }
 
+void VideoOutputOpenGL::SetProfile(void)
+{
+    if (db_vdisp_profile)
+        db_vdisp_profile->SetVideoRenderer("opengl");
+}
+
 bool VideoOutputOpenGL::InputChanged(const QSize &input_size,
                                      float        aspect,
                                      MythCodecID  av_codec_id,
                                      void        *codec_private,
                                      bool        &aspect_only)
 {
-    VERBOSE(VB_PLAYBACK, LOC + QString("InputChanged(%1,%2,%3) %4")
+    VERBOSE(VB_PLAYBACK, LOC + QString("InputChanged(%1,%2,%3) %4->%5")
             .arg(input_size.width()).arg(input_size.height()).arg(aspect)
-            .arg(toString(av_codec_id)));
+            .arg(toString(video_codec_id)).arg(toString(av_codec_id)));
 
     QMutexLocker locker(&gl_context_lock);
-
     if (!codec_is_std(av_codec_id))
     {
         VERBOSE(VB_IMPORTANT, LOC_ERR +
@@ -244,7 +249,8 @@
                                   window.GetVideoDim(), dvr,
                                   window.GetDisplayVideoRect(),
                                   window.GetVideoRect(), true,
-                                  GetFilters(), db_letterbox_colour);
+                                  GetFilters(), !codec_is_std(video_codec_id),
+                                  db_letterbox_colour);
     if (success)
     {
         bool temp_deinterlacing = m_deinterlacing;
@@ -278,12 +284,13 @@
 bool VideoOutputOpenGL::CreateBuffers(void)
 {
     QMutexLocker locker(&gl_context_lock);
-
-    bool success = true;
     vbuffers.Init(31, true, 1, 12, 4, 2, false);
-    success &= vbuffers.CreateBuffers(window.GetVideoDim().width(),
-                                      window.GetVideoDim().height());
+    return vbuffers.CreateBuffers(window.GetVideoDim().width(),
+                                  window.GetVideoDim().height());
+}
 
+bool VideoOutputOpenGL::CreatePauseFrame(void)
+{
     av_pause_frame.height = vbuffers.GetScratchFrame()->height;
     av_pause_frame.width  = vbuffers.GetScratchFrame()->width;
     av_pause_frame.bpp    = vbuffers.GetScratchFrame()->bpp;
@@ -292,11 +299,10 @@
     av_pause_frame.frameNumber = vbuffers.GetScratchFrame()->frameNumber;
 
     if (!av_pause_frame.buf)
-        success = false;
-    else
-        clear(&av_pause_frame, GUID_YV12_PLANAR);
+        return false;
 
-    return success;
+    clear(&av_pause_frame, GUID_YV12_PLANAR);
+    return true;
 }
 
 void VideoOutputOpenGL::ProcessFrame(VideoFrame *frame, OSD *osd,
@@ -308,6 +314,7 @@
     if (!gl_videochain || !gl_context)
         return;
 
+    bool sw_frame = codec_is_std(video_codec_id);
     bool deint_proc = m_deinterlacing && (m_deintFilter != NULL);
     OpenGLLocker ctx_lock(gl_context);
 
@@ -319,11 +326,11 @@
         pauseframe = true;
     }
 
-    if (filterList)
+    if (filterList && sw_frame)
         filterList->ProcessFrame(frame);
 
     bool safepauseframe = pauseframe && !IsBobDeint();
-    if (deint_proc && m_deinterlaceBeforeOSD &&
+    if (sw_frame && deint_proc && m_deinterlaceBeforeOSD &&
        (!pauseframe || safepauseframe))
     {
         m_deintFilter->ProcessFrame(frame, scan);
@@ -335,7 +342,7 @@
         ShowPIPs(frame, pipPlayers);
     }
 
-    if ((!pauseframe || safepauseframe) &&
+    if (sw_frame && (!pauseframe || safepauseframe) &&
         deint_proc && !m_deinterlaceBeforeOSD)
     {
         m_deintFilter->ProcessFrame(frame, scan);
@@ -343,7 +350,7 @@
 
     bool soft_bob = m_deinterlacing && (m_deintfiltername == "bobdeint");
 
-    if (gl_videochain)
+    if (gl_videochain && sw_frame)
         gl_videochain->UpdateInputFrame(frame, soft_bob);
 }
 
@@ -632,7 +639,7 @@
                      QSize(pipVideoWidth, pipVideoHeight),
                      dvr, position,
                      QRect(0, 0, pipVideoWidth, pipVideoHeight),
-                     false, GetFilters());
+                     false, GetFilters(), false);
         gl_pipchain->SetMasterViewport(gl_videochain->GetViewPort());
         if (!success)
         {
@@ -653,7 +660,7 @@
             QSize(pipVideoWidth, pipVideoHeight),
             dvr, position,
             QRect(0, 0, pipVideoWidth, pipVideoHeight),
-            false, GetFilters());
+            false, GetFilters(), false);
 
         gl_pipchain->SetMasterViewport(gl_videochain->GetViewPort());
         if (!success)
Index: /home/mark/trunk/mythtv/libs/libmythtv/avformatdecoder.cpp
===================================================================
--- /home/mark/trunk/mythtv/libs/libmythtv/avformatdecoder.cpp	(revision 25868)
+++ /home/mark/trunk/mythtv/libs/libmythtv/avformatdecoder.cpp	(working copy)
@@ -52,6 +52,10 @@
 }
 #endif // USING_VDPAU
 
+#ifdef USING_VAAPI
+#include "videoout_openglvaapi.h"
+#endif // USING_VAAPI
+
 extern "C" {
 #include "libavutil/avutil.h"
 #include "libavcodec/ac3_parser.h"
@@ -126,6 +130,8 @@
 void render_slice_vdpau(struct AVCodecContext *s, const AVFrame *src,
                         int offset[4], int y, int type, int height);
 
+int  get_avf_buffer_vaapi(struct AVCodecContext *c, AVFrame *pic);
+
 static AVCodec *find_vdpau_decoder(AVCodec *c, enum CodecID id)
 {
     AVCodec *codec = c;
@@ -238,6 +244,11 @@
     (*opts.equiv_decoders)["vdpau"].append("dummy");
 #endif
 
+#ifdef USING_VAAPI
+    opts.decoders->append("vaapi");
+    (*opts.equiv_decoders)["vaapi"].append("dummy");
+#endif
+
     PrivateDecoder::GetDecoders(opts);
 }
 
@@ -1154,6 +1165,25 @@
     return fmt[i];
 }
 
+static bool IS_VAAPI_PIX_FMT(enum PixelFormat fmt)
+{
+    return fmt == PIX_FMT_VAAPI_MOCO ||
+           fmt == PIX_FMT_VAAPI_IDCT ||
+           fmt == PIX_FMT_VAAPI_VLD;
+}
+
+static enum PixelFormat get_format_vaapi(struct AVCodecContext *avctx,
+                                         const enum PixelFormat *fmt)
+{
+    if (!fmt)
+        return PIX_FMT_NONE;
+    int i = 0;
+    for (; fmt[i] != PIX_FMT_NONE ; i++)
+        if (IS_VAAPI_PIX_FMT(fmt[i]))
+            break;
+    return fmt[i];
+}
+
 static bool IS_DR1_PIX_FMT(const enum PixelFormat fmt)
 {
     switch (fmt)
@@ -1201,7 +1231,7 @@
     {
         directrendering = true;
         if (!gCoreContext->GetNumSetting("DecodeExtraAudio", 0) &&
-            !CODEC_IS_HWACCEL(codec))
+            !CODEC_IS_HWACCEL(codec, enc))
         {
             SetLowBuffers(false);
         }
@@ -1225,6 +1255,13 @@
         enc->draw_horiz_band = render_slice_vdpau;
         enc->slice_flags     = SLICE_FLAG_CODED_ORDER | SLICE_FLAG_ALLOW_FIELD;
     }
+    else if (CODEC_IS_VAAPI(codec, enc))
+    {
+        enc->get_buffer      = get_avf_buffer_vaapi;
+        enc->get_format      = get_format_vaapi;
+        enc->release_buffer  = release_avf_buffer;
+        enc->slice_flags     = SLICE_FLAG_CODED_ORDER | SLICE_FLAG_ALLOW_FIELD;
+    }
     else if (codec && codec->capabilities & CODEC_CAP_DR1)
     {
         enc->flags          |= CODEC_FLAG_EMU_EDGE;
@@ -1770,6 +1807,25 @@
                         handled = true;
                     }
 #endif // USING_VDPAU
+#ifdef USING_VAAPI
+                    MythCodecID vaapi_mcid;
+                    PixelFormat pix_fmt = PIX_FMT_YUV420P;
+                    vaapi_mcid = VideoOutputOpenGLVAAPI::GetBestSupportedCodec(
+                        width, height, mpeg_version(enc->codec_id),
+                        no_hardware_decoders, pix_fmt);
+
+                    if (vaapi_mcid >= video_codec_id)
+                    {
+                        enc->codec_id = (CodecID)myth2av_codecid(vaapi_mcid);
+                        video_codec_id = vaapi_mcid;
+                        handled = true;
+                        if (!no_hardware_decoders &&
+                            codec_is_vaapi(video_codec_id))
+                        {
+                            enc->pix_fmt = pix_fmt;
+                        }
+                    }
+#endif // USING_VAAPI
 #ifdef USING_XVMC
 
                     bool force_xv = no_hardware_decoders;
@@ -2484,6 +2540,37 @@
     }
 }
 
+int get_avf_buffer_vaapi(struct AVCodecContext *c, AVFrame *pic)
+{
+    AvFormatDecoder *nd = (AvFormatDecoder *)(c->opaque);
+    VideoFrame *frame = nd->GetPlayer()->GetNextVideoFrame(false);
+
+    pic->data[0]     = frame->buf;
+    pic->data[1]     = NULL;
+    pic->data[2]     = NULL;
+    pic->data[3]     = NULL;
+    pic->linesize[0] = 0;
+    pic->linesize[1] = 0;
+    pic->linesize[2] = 0;
+    pic->linesize[3] = 0;
+    pic->opaque      = frame;
+    pic->type        = FF_BUFFER_TYPE_USER;
+    pic->age         = 256 * 256 * 256 * 64;
+    frame->pix_fmt   = c->pix_fmt;
+
+#ifdef USING_VAAPI
+    if (nd->GetPlayer()->getVideoOutput())
+    {
+        VideoOutputOpenGLVAAPI *vo =
+            dynamic_cast<VideoOutputOpenGLVAAPI*>(nd->GetPlayer()->getVideoOutput());
+        c->hwaccel_context = (vaapi_context*)vo->GetVAAPIContext();
+        pic->data[3] = vo->GetSurfaceIDPointer(frame->buf);
+    }
+#endif
+
+    return 0;
+}
+
 void AvFormatDecoder::DecodeDTVCC(const uint8_t *buf, uint len)
 {
     if (!len)
@@ -3362,6 +3449,7 @@
     QStringList list  = text.split('\n', QString::SkipEmptyParts);
     delete dec;
     subReader->AddRawTextSubtitle(list, pkt->convergence_duration);
+    return true;
 }
 
 bool AvFormatDecoder::ProcessDataPacket(AVStream *curstream, AVPacket *pkt,
Index: /home/mark/trunk/mythtv/libs/libmythtv/videoout_openglvaapi.cpp
===================================================================
--- /home/mark/trunk/mythtv/libs/libmythtv/videoout_openglvaapi.cpp	(revision 0)
+++ /home/mark/trunk/mythtv/libs/libmythtv/videoout_openglvaapi.cpp	(revision 0)
@@ -0,0 +1,228 @@
+#include "videoout_openglvaapi.h"
+
+#define LOC      QString("VidOutGLVAAPI: ")
+#define LOC_ERR  QString("VidOutGLVAAPI Error: ")
+
+void VideoOutputOpenGLVAAPI::GetRenderOptions(render_opts &opts)
+{
+    opts.renderers->append("openglvaapi");
+    (*opts.deints)["openglvaapi"].append("vaapionefield");
+    (*opts.deints)["openglvaapi"].append("vaapibobdeint");
+    (*opts.deints)["openglvaapi"].append("none");
+    (*opts.osds)["openglvaapi"].append("opengl2");
+
+    if (opts.decoders->contains("vaapi"))
+        (*opts.safe_renderers)["vaapi"].append("openglvaapi");
+    if (opts.decoders->contains("ffmpeg"))
+        (*opts.safe_renderers)["ffmpeg"].append("openglvaapi");
+    if (opts.decoders->contains("libmpeg2"))
+        (*opts.safe_renderers)["libmpeg2"].append("openglvaapi");
+    (*opts.safe_renderers)["dummy"].append("openglvaapi");
+    (*opts.safe_renderers)["nuppel"].append("openglvaapi");
+
+    opts.priorities->insert("openglvaapi", 110);
+}
+
+VideoOutputOpenGLVAAPI::VideoOutputOpenGLVAAPI()
+  : VideoOutputOpenGL(), m_ctx(NULL)
+{
+    if (gCoreContext->GetNumSetting("UseVideoModes", 0))
+        display_res = DisplayRes::GetDisplayRes(true);
+}
+
+VideoOutputOpenGLVAAPI::~VideoOutputOpenGLVAAPI()
+{
+    TearDown();
+}
+
+void VideoOutputOpenGLVAAPI::TearDown(void)
+{
+    DeleteVAAPIContext();
+}
+
+bool VideoOutputOpenGLVAAPI::InputChanged(const QSize &input_size, float aspect,
+                              MythCodecID  av_codec_id, void *codec_private,
+                              bool &aspect_only)
+{
+    VERBOSE(VB_PLAYBACK, LOC + QString("InputChanged(%1,%2,%3) %4->%5")
+            .arg(input_size.width()).arg(input_size.height()).arg(aspect)
+            .arg(toString(video_codec_id)).arg(toString(av_codec_id)));
+
+    if (!codec_is_vaapi(av_codec_id))
+        return VideoOutputOpenGL::InputChanged(input_size, aspect, av_codec_id,
+                                               codec_private, aspect_only);
+                                                   
+    QMutexLocker locker(&gl_context_lock);
+    bool cid_changed = (video_codec_id != av_codec_id);
+    bool res_changed = input_size  != window.GetVideoDim();
+    bool asp_changed = aspect      != window.GetVideoAspect();
+    
+    if (!res_changed && !cid_changed)
+    {
+        if (asp_changed)
+        {
+            aspect_only = true;
+            VideoAspectRatioChanged(aspect);
+            MoveResize();
+        }
+        return true;
+    }
+
+    TearDown();
+    QRect disp = window.GetDisplayVisibleRect();
+    if (Init(input_size.width(), input_size.height(),
+             aspect, gl_parent_win, disp.left(),  disp.top(),
+             disp.width(), disp.height(), av_codec_id, gl_embed_win))
+    {
+        BestDeint();
+        return true;
+    }
+
+    VERBOSE(VB_IMPORTANT, LOC_ERR +
+        QString("Failed to re-initialise video output."));
+    errorState = kError_Unknown;
+
+    return false;
+}
+
+bool VideoOutputOpenGLVAAPI::Init(int width, int height, float aspect,
+                                  WId winid, int winx, int winy, int winw,
+                                  int winh, MythCodecID codec_id, WId embedid)
+{
+    if (codec_is_vaapi(codec_id))
+    {
+        video_codec_id = codec_id;
+        if (!CreateVAAPIContext(QSize(width, height)))
+            return false;
+    }
+
+    return VideoOutputOpenGL::Init(width, height, aspect, winid, winx, winy,
+                                   winw, winh, video_codec_id, embedid);
+}
+
+bool VideoOutputOpenGLVAAPI::CreateVAAPIContext(QSize size)
+{
+    if (m_ctx)
+        DeleteVAAPIContext();
+    m_ctx = new VAAPIContext(video_codec_id);
+    if (m_ctx && m_ctx->CreateDisplay(size) && m_ctx->CreateBuffers())
+        return true;
+    VERBOSE(VB_IMPORTANT, LOC_ERR + QString("Failed to create VAAPI context."));
+    errorState = kError_Unknown;
+    return false;
+}
+
+void VideoOutputOpenGLVAAPI::DeleteVAAPIContext(void)
+{
+    delete m_ctx;
+    m_ctx = NULL;
+}
+
+bool VideoOutputOpenGLVAAPI::CreateBuffers(void)
+{
+    if ((!codec_is_vaapi(video_codec_id)) || !m_ctx)
+        return VideoOutputOpenGL::CreateBuffers();
+
+    QMutexLocker locker(&gl_context_lock);
+    int num_buffers = m_ctx->GetNumBuffers();
+    const QSize video_dim = window.GetVideoDim();
+    vbuffers.Init(num_buffers, true, 2, 1, 4, 1, false); // shouldn't need pause frame
+
+    bool ok = true;
+    for (int i = 0; i < num_buffers; i++)
+    {
+        ok &= vbuffers.CreateBuffer(video_dim.width(),
+                                    video_dim.height(), i,
+                                    m_ctx->GetVideoSurface(i), FMT_VAAPI);
+    }
+    return ok;
+}
+
+void* VideoOutputOpenGLVAAPI::GetVAAPIContext(void)
+{
+    if (m_ctx)
+        return &m_ctx->m_ctx;
+    return NULL;
+}
+
+uint8_t* VideoOutputOpenGLVAAPI::GetSurfaceIDPointer(void* buf)
+{
+    if (m_ctx)
+        return m_ctx->GetSurfaceIDPointer(buf);
+    return NULL;
+}
+
+void VideoOutputOpenGLVAAPI::SetProfile(void)
+{
+    if (db_vdisp_profile)
+        db_vdisp_profile->SetVideoRenderer("openglvaapi");
+}
+
+bool VideoOutputOpenGLVAAPI::ApproveDeintFilter(const QString &filtername) const
+{
+    return filtername.contains("vaapi");
+}
+
+bool VideoOutputOpenGLVAAPI::SetDeinterlacingEnabled(bool)
+{
+    return true;
+}
+
+bool VideoOutputOpenGLVAAPI::SetupDeinterlace(bool i, const QString& ovrf)
+{
+    return true;
+}
+
+void VideoOutputOpenGLVAAPI::ProcessFrame(VideoFrame *frame, OSD *osd,
+                                          FilterChain *filterList,
+                                          const PIPMap &pipPlayers,
+                                          FrameScanType scan)
+{
+    VideoOutputOpenGL::ProcessFrame(frame, osd, filterList, pipPlayers, scan);
+
+    if (codec_is_vaapi(video_codec_id) && m_ctx && gl_videochain && frame)
+    {
+        gl_context->makeCurrent();
+        uint tex = gl_videochain->GetInputTexture();
+        gl_context->EnableTextures(tex);
+        if (m_ctx->CopySurfaceToTexture(frame->buf, tex,
+                                        gl_videochain->GetTextureType()))
+        {
+            gl_videochain->SetInputUpdated();
+        }
+        gl_context->doneCurrent();
+    }
+}
+
+QStringList VideoOutputOpenGLVAAPI::GetAllowedRenderers(
+    MythCodecID myth_codec_id, const QSize &video_dim)
+{
+    (void) video_dim;
+    QStringList list;
+    if ((codec_is_std(myth_codec_id) || (codec_is_vaapi(myth_codec_id))) &&
+         !getenv("NO_VAAPI"))
+    {
+        list += "openglvaapi";
+    }
+    return list;
+}
+
+MythCodecID VideoOutputOpenGLVAAPI::GetBestSupportedCodec(
+    uint width,       uint height,
+    uint stream_type, bool no_acceleration,
+    PixelFormat &pix_fmt)
+{
+    QSize size(width, height);
+    bool use_cpu = no_acceleration;
+    VideoDisplayProfile vdp;
+    vdp.SetInput(size);
+    QString dec = vdp.GetDecoder();
+
+    MythCodecID test_cid = (MythCodecID)(kCodec_MPEG1_VAAPI + (stream_type-1));
+    use_cpu |= !codec_is_vaapi(test_cid);
+    use_cpu |= !VAAPIContext::IsFormatAccelerated(size, test_cid, pix_fmt);
+    if ((dec != "vaapi") || getenv("NO_VAAPI") || use_cpu)
+        return (MythCodecID)(kCodec_MPEG1 + (stream_type-1));
+
+    return test_cid;
+}
Index: /home/mark/trunk/mythtv/libs/libmythtv/libmythtv.pro
===================================================================
--- /home/mark/trunk/mythtv/libs/libmythtv/libmythtv.pro	(revision 25868)
+++ /home/mark/trunk/mythtv/libs/libmythtv/libmythtv.pro	(working copy)
@@ -352,6 +352,11 @@
     using_opengl_video:HEADERS += openglvideo.h   videoout_opengl.h
     using_opengl_video:SOURCES += openglvideo.cpp videoout_opengl.cpp
 
+    using_vaapi: DEFINES += USING_VAAPI
+    using_vaapi: DEFINES += videoout_openglvaapi.h   vaapicontext.h
+    using_vaapi: SOURCES += videoout_openglvaapi.cpp vaapicontext.cpp
+    using_vaapi: LIBS    += -lva -lva-glx
+
     # Misc. frontend
     HEADERS += DetectLetterbox.h
     SOURCES += DetectLetterbox.cpp
Index: /home/mark/trunk/mythtv/libs/libmythtv/vaapicontext.cpp
===================================================================
--- /home/mark/trunk/mythtv/libs/libmythtv/vaapicontext.cpp	(revision 0)
+++ /home/mark/trunk/mythtv/libs/libmythtv/vaapicontext.cpp	(revision 0)
@@ -0,0 +1,477 @@
+#include <QHash>
+
+#include "mythverbose.h"
+#include "mythxdisplay.h"
+#include "mythcodecid.h"
+#include "vaapicontext.h"
+
+#define LOC     QString("VAAPI: ")
+#define LOC_ERR QString("VAAPI Error: ")
+#define NUM_VAAPI_BUFFERS 40
+
+#define INIT_ST \
+  VAStatus va_status; \
+  bool ok = true;
+
+#define CHECK_ST \
+  ok &= (va_status == VA_STATUS_SUCCESS); \
+  if (!ok) { \
+      VERBOSE(VB_IMPORTANT, LOC_ERR + QString("Error at %1:%2 (#%3, %4)") \
+              .arg(__FILE__).arg( __LINE__).arg(va_status) \
+              .arg(vaErrorStr(va_status))); \
+  }
+
+#define CREATE_CHECK(arg1, arg2) \
+  if (ok) \
+  { \
+      ok = arg1; \
+      if (!ok) \
+          VERBOSE(VB_IMPORTANT, LOC_ERR + arg2); \
+  }
+
+QString profileToString(VAProfile profile)
+{
+    if (VAProfileMPEG2Simple == profile)         return "MPEG2Simple";
+    if (VAProfileMPEG2Main == profile)           return "MPEG2Main";
+    if (VAProfileMPEG4Simple == profile)         return "MPEG4Simple";
+    if (VAProfileMPEG4AdvancedSimple == profile) return "MPEG4AdvSimple";
+    if (VAProfileMPEG4Main == profile)           return "MPEG4Main";
+    if (VAProfileH264Baseline == profile)        return "H264Base";
+    if (VAProfileH264Main == profile)            return "H264Main";
+    if (VAProfileH264High == profile)            return "H264High";
+    if (VAProfileVC1Simple == profile)           return "VC1Simple";
+    if (VAProfileVC1Main == profile)             return "VC1Main";
+    if (VAProfileVC1Advanced == profile)         return "VC1Advanced";
+    if (VAProfileH263Baseline == profile)        return "H263Base";
+    return "Unknown";
+}
+
+QString entryToString(VAEntrypoint entry)
+{
+    if (VAEntrypointVLD == entry)        return "VLD ";
+    if (VAEntrypointIZZ == entry)        return "IZZ (UNSUPPORTED) ";
+    if (VAEntrypointIDCT == entry)       return "IDCT (UNSUPPORTED) ";
+    if (VAEntrypointMoComp == entry)     return "MC (UNSUPPORTED) ";
+    if (VAEntrypointDeblocking == entry) return "Deblock (UNSUPPORTED) ";
+    if (VAEntrypointEncSlice == entry)   return "EncSlice (UNSUPPORTED) ";
+    return "Unknown";
+}
+
+VAProfile preferredProfile(MythCodecID codec)
+{
+    // FIXME handle unsupported codecs properly
+    if (kCodec_H263_VAAPI  == codec) return VAProfileMPEG4AdvancedSimple;
+    if (kCodec_MPEG4_VAAPI == codec) return VAProfileMPEG4AdvancedSimple;
+    if (kCodec_H264_VAAPI  == codec) return VAProfileH264High;
+    if (kCodec_VC1_VAAPI   == codec) return VAProfileVC1Advanced;
+    if (kCodec_WMV3_VAAPI  == codec) return VAProfileVC1Main;
+    return VAProfileMPEG2Main;
+}
+
+class VAAPIDisplay
+{
+  public:
+    VAAPIDisplay() : m_va_disp(NULL), m_x_disp(NULL), m_ref_count(0) { }
+   ~VAAPIDisplay()
+    {
+        if (m_va_disp)
+        {
+            INIT_ST
+            XLOCK(m_x_disp, va_status = vaTerminate(m_va_disp));
+            CHECK_ST
+        }
+        if (m_x_disp)
+        {
+            m_x_disp->Sync(true);
+            delete m_x_disp;
+        }
+    }
+
+    bool Create(void)
+    {
+        m_x_disp = OpenMythXDisplay();
+        if (!m_x_disp)
+            return false;
+
+        MythXLocker locker(m_x_disp);
+        int major_ver, minor_ver;
+        m_va_disp = vaGetDisplayGLX(m_x_disp->GetDisplay());
+        INIT_ST
+        va_status = vaInitialize(m_va_disp, &major_ver, &minor_ver);
+        CHECK_ST
+
+        static bool debugged = false;
+        if (ok && !debugged)
+        {
+            debugged = true;
+            VERBOSE(VB_IMPORTANT, LOC + QString("Version: %1.%2")
+                                        .arg(major_ver).arg(minor_ver));
+            VERBOSE(VB_IMPORTANT, LOC + QString("Vendor : %1")
+                                        .arg(vaQueryVendorString(m_va_disp)));
+        }
+        if (ok)
+            UpRef();
+        return ok;
+    }
+
+    void UpRef(void)
+    {
+        XLOCK(m_x_disp, m_ref_count++)
+    }
+
+    void DownRef(void)
+    {
+        m_x_disp->Lock();
+        m_ref_count--;
+        if (m_ref_count <= 0)
+        {
+            if (gVAAPIDisplay == this)
+                gVAAPIDisplay = NULL;
+            m_x_disp->Unlock();
+            delete this;
+            return;
+        }
+        m_x_disp->Unlock();
+    }
+
+    static VAAPIDisplay* GetDisplay(void)
+    {
+        if (gVAAPIDisplay)
+        {
+            gVAAPIDisplay->UpRef();
+            return gVAAPIDisplay;
+        }
+
+        gVAAPIDisplay = new VAAPIDisplay();
+        if (gVAAPIDisplay && gVAAPIDisplay->Create())
+            return gVAAPIDisplay;
+
+        delete gVAAPIDisplay;
+        gVAAPIDisplay = NULL;
+        return NULL;
+    }
+
+    static VAAPIDisplay *gVAAPIDisplay;
+    void                *m_va_disp;
+    MythXDisplay        *m_x_disp;
+    int                  m_ref_count;
+};
+
+VAAPIDisplay* VAAPIDisplay::gVAAPIDisplay = NULL;
+
+bool VAAPIContext::IsFormatAccelerated(QSize size, MythCodecID codec,
+                                       PixelFormat &pix_fmt)
+{
+    bool result = false;
+    VAAPIContext *ctx = new VAAPIContext(codec);
+    if (ctx)
+    {
+        result  = ctx->CreateDisplay(size);
+        pix_fmt = ctx->GetPixelFormat();
+    }
+    delete ctx;
+    return result;
+}
+
+VAAPIContext::VAAPIContext(MythCodecID codec)
+  : m_codec(codec),
+    m_vaProfile(VAProfileMPEG2Main)/* ?? */,
+    m_vaEntrypoint(VAEntrypointEncSlice),
+    m_pix_fmt(PIX_FMT_YUV420P), m_numSurfaces(NUM_VAAPI_BUFFERS),
+    m_surfaces(NULL), m_surfaceData(NULL)
+{
+    memset(&m_ctx, 0, sizeof(vaapi_context));
+}
+
+VAAPIContext::~VAAPIContext()
+{
+    ClearGLXSurfaces();
+    
+    if (m_display)
+        m_display->m_x_disp->Lock();
+
+    INIT_ST
+    if (m_ctx.context_id)
+    {
+        va_status = vaDestroyContext(m_ctx.display, m_ctx.context_id);
+        CHECK_ST
+    }
+    if (m_ctx.config_id)
+    {
+        va_status = vaDestroyConfig(m_ctx.display, m_ctx.config_id);
+        CHECK_ST
+    }
+    if (m_surfaces)
+    {
+        va_status = vaDestroySurfaces(m_ctx.display, m_surfaces, m_numSurfaces);
+        CHECK_ST
+    }
+
+    if (m_surfaces)
+        delete [] m_surfaces;
+    if (m_surfaceData)
+        delete [] m_surfaceData;
+
+    if (m_display)
+    {
+        m_display->m_x_disp->Unlock();
+        m_display->DownRef();
+    }
+
+    VERBOSE(VB_PLAYBACK, LOC + "Deleted context");
+}
+
+bool VAAPIContext::CreateDisplay(QSize size)\
+{
+    m_size = size;
+    bool ok = true;
+    m_display = VAAPIDisplay::GetDisplay();
+    CREATE_CHECK(!m_size.isEmpty(), "Invalid size")
+    CREATE_CHECK(m_display != NULL, "Invalid display")
+    CREATE_CHECK(InitDisplay(),     "Invalid VADisplay")
+    CREATE_CHECK(InitProfiles(),    "No supported profiles")
+    if (ok)
+        VERBOSE(VB_PLAYBACK, LOC + QString("Created ctx display (%1x%2->%3x%4)")
+            .arg(size.width()).arg(size.height())
+            .arg(m_size.width()).arg(m_size.height()));
+    return ok;
+}
+
+bool VAAPIContext::CreateBuffers(void)
+{
+    bool ok = true;
+    CREATE_CHECK(!m_size.isEmpty(), "Invalid size")
+    CREATE_CHECK(InitBuffers(),     "Failed to create buffers.")
+    CREATE_CHECK(InitContext(),     "Failed to create context")
+    if (ok)
+        VERBOSE(VB_PLAYBACK, LOC + "Created buffers");
+    return ok;
+}
+
+bool VAAPIContext::InitDisplay(void)
+{
+    if (!m_display)
+        return false;
+    m_ctx.display = m_display->m_va_disp;
+    return m_ctx.display;
+}
+
+bool VAAPIContext::InitProfiles(void)
+{
+    if (!(codec_is_vaapi(m_codec)) || !m_ctx.display)
+        return false;
+
+    MythXLocker locker(m_display->m_x_disp);
+    int max_profiles, max_entrypoints;
+    VAProfile profile_wanted = preferredProfile(m_codec);
+    VAProfile profile_found  = VAProfileMPEG2Main;   // FIXME
+    VAEntrypoint entry_found = VAEntrypointEncSlice; // unsupported value
+
+    max_profiles          = vaMaxNumProfiles(m_ctx.display);
+    max_entrypoints       = vaMaxNumEntrypoints(m_ctx.display);
+    VAProfile *profiles   = new VAProfile[max_profiles];
+    VAEntrypoint *entries = new VAEntrypoint[max_entrypoints];
+
+    static bool debugged = false;
+    if (profiles && entries)
+    {
+        INIT_ST
+        int act_profiles, act_entries;
+        va_status = vaQueryConfigProfiles(m_ctx.display,
+                                          profiles,
+                                         &act_profiles);
+        CHECK_ST
+        if (ok && act_profiles > 0)
+        {
+            for (int i = 0; i < act_profiles; i++)
+            {
+                va_status = vaQueryConfigEntrypoints(m_ctx.display,
+                                                     profiles[i],
+                                                     entries,
+                                                    &act_entries);
+                if (va_status == VA_STATUS_SUCCESS && act_entries > 0)
+                {
+                    if (profiles[i] == profile_wanted)
+                    {
+                        profile_found = profile_wanted;
+                        for (int j = 0; j < act_entries; j++)
+                            if (entries[j] < entry_found)
+                                entry_found = entries[j];
+                    }
+
+                    if (!debugged)
+                    {
+                        QString entrylist = "Entrypoints: ";
+                        for (int j = 0; j < act_entries; j++)
+                            entrylist += entryToString(entries[j]);
+                        VERBOSE(VB_IMPORTANT, LOC + QString("Profile: %1 %2")
+                            .arg(profileToString(profiles[i])).arg(entrylist));
+                    }
+                }
+            }
+        }
+        debugged = true;
+    }
+    delete profiles;
+    delete entries;
+
+    VERBOSE(VB_PLAYBACK, LOC + QString("Desired profile for '%1': %2")
+        .arg(toString(m_codec)).arg(profileToString(profile_wanted)));
+    VERBOSE(VB_PLAYBACK, LOC + QString("Found profile %1 with entry %2")
+        .arg(profileToString(profile_found)).arg(entryToString(entry_found)));
+
+    if (profile_wanted != profile_found)
+    {
+        VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to find supported profile.");
+        return false;
+    }
+
+    if (entry_found > VAEntrypointVLD)
+    {
+        VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to find suitable entry point.");
+        return false;
+    }
+
+    m_vaProfile = profile_wanted;
+    m_vaEntrypoint = entry_found;
+    if (VAEntrypointVLD == m_vaEntrypoint)
+        m_pix_fmt = PIX_FMT_VAAPI_VLD;
+    return true;
+}
+
+bool VAAPIContext::InitBuffers(void)
+{
+    if (!m_ctx.display)
+        return false;
+        
+    MythXLocker locker(m_display->m_x_disp);
+    m_surfaces    = new VASurfaceID[m_numSurfaces];
+    m_surfaceData = new vaapi_surface[m_numSurfaces];
+
+    if (!m_surfaces || !m_surfaceData)
+        return false;
+
+    INIT_ST
+    va_status = vaCreateSurfaces(m_ctx.display, m_size.width(), m_size.height(),
+                                 VA_RT_FORMAT_YUV420, m_numSurfaces,
+                                 m_surfaces);
+    CHECK_ST
+
+    for (int i = 0; i < m_numSurfaces; i++)
+        m_surfaceData[i].m_id = m_surfaces[i];
+    return ok;
+}
+
+bool VAAPIContext::InitContext(void)
+{
+    if (!m_ctx.display || m_vaEntrypoint > VAEntrypointVLD)
+        return false;
+
+    MythXLocker locker(m_display->m_x_disp);
+    VAConfigAttrib attrib;
+    attrib.type = VAConfigAttribRTFormat;
+    INIT_ST
+    va_status = vaGetConfigAttributes(m_ctx.display, m_vaProfile,
+                                      m_vaEntrypoint, &attrib, 1);
+    CHECK_ST
+
+    if (!ok || !(attrib.value & VA_RT_FORMAT_YUV420))
+    {
+        VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to confirm YUV420 chroma");
+        return false;
+    }
+
+    va_status = vaCreateConfig(m_ctx.display, m_vaProfile, m_vaEntrypoint,
+                               &attrib, 1, &m_ctx.config_id);
+    CHECK_ST
+    if (!ok)
+    {
+        VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to create decoder config.");
+        return false;
+    }
+
+    va_status = vaCreateContext(m_ctx.display, m_ctx.config_id,
+                                m_size.width(), m_size.height(), VA_PROGRESSIVE,
+                                m_surfaces, m_numSurfaces,
+                                &m_ctx.context_id);
+    CHECK_ST
+    if (!ok)
+    {
+        VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to create decoder context.");
+        return false;
+    }
+    return true;
+}
+
+void* VAAPIContext::GetVideoSurface(int i)
+{
+    if (i < 0 || i >= m_numSurfaces)
+        return NULL;
+    return &m_surfaceData[i];
+}
+
+uint8_t* VAAPIContext::GetSurfaceIDPointer(void* buf)
+{
+    if (!buf)
+        return NULL;
+    const vaapi_surface *surf = (vaapi_surface*)buf;
+//    VASurfaceStatus status;
+//    INIT_ST
+//    va_status = vaQuerySurfaceStatus(m_ctx.display, surf->m_id, &status);
+//    CHECK_ST
+//    VERBOSE(VB_IMPORTANT, LOC + QString("Returning VASurfaceID: %1 status %2").arg(surf->m_id).arg(status));
+//    va_status = vaSyncSurface(m_ctx.display, surf->m_id);
+//    CHECK_ST
+    return (uint8_t*)(uintptr_t)surf->m_id;
+}
+
+bool VAAPIContext::CopySurfaceToTexture(const void* buf, uint texture,
+                                        uint texture_type)
+{
+    if (!buf || !texture)
+        return false;
+    void* glx_surface = GetGLXSurface(texture, texture_type);
+    if (!glx_surface)
+        return false;
+    const vaapi_surface *surf = (vaapi_surface*)buf;
+    INIT_ST
+    XLOCK(m_display->m_x_disp,
+          va_status = vaCopySurfaceGLX(m_ctx.display, glx_surface,
+                                       surf->m_id, 0));
+    CHECK_ST
+    return ok;
+}
+
+void* VAAPIContext::GetGLXSurface(uint texture, uint texture_type)
+{
+    if (m_glxSurfaces.contains(texture))
+        return m_glxSurfaces.value(texture);
+
+    void *glx_surface = NULL;
+    INIT_ST
+    XLOCK(m_display->m_x_disp,
+          va_status = vaCreateSurfaceGLX(m_ctx.display, texture_type,
+                                         texture, &glx_surface));
+    CHECK_ST
+    m_glxSurfaces.insert(texture, glx_surface);
+
+    VERBOSE(VB_PLAYBACK, QString("Number of VAAPI GLX surfaces: %1")
+        .arg(m_glxSurfaces.size()));
+    return glx_surface;
+}
+
+void VAAPIContext::ClearGLXSurfaces(void)
+{
+    if (!m_display)
+        return;
+
+    m_display->m_x_disp->Lock();
+    INIT_ST
+    foreach (void* surface, m_glxSurfaces)
+    {
+        va_status = vaDestroySurfaceGLX(m_ctx.display, surface);
+        CHECK_ST
+    }
+    m_glxSurfaces.clear();
+    m_display->m_x_disp->Unlock();
+}
Index: /home/mark/trunk/mythtv/libs/libmythtv/videoout_opengl.h
===================================================================
--- /home/mark/trunk/mythtv/libs/libmythtv/videoout_opengl.h	(revision 25868)
+++ /home/mark/trunk/mythtv/libs/libmythtv/videoout_opengl.h	(working copy)
@@ -11,22 +11,23 @@
   public:
     static void GetRenderOptions(render_opts &opts, QStringList &cpudeints);
     VideoOutputOpenGL();
-   ~VideoOutputOpenGL();
+    virtual ~VideoOutputOpenGL();
 
-    bool Init(int width, int height, float aspect, WId winid,
-              int winx, int winy, int winw, int winh,
-              MythCodecID codec_id, WId embedid = 0);
-    void TearDown(void);
+    virtual bool Init(int width, int height, float aspect, WId winid,
+                      int winx, int winy, int winw, int winh,
+                      MythCodecID codec_id, WId embedid = 0);
+    virtual void SetProfile(void);
+    virtual void TearDown(void);
 
     void PrepareFrame(VideoFrame *buffer, FrameScanType, OSD *osd);
-    void ProcessFrame(VideoFrame *frame, OSD *osd,
-                      FilterChain *filterList,
-                      const PIPMap &pipPlayers,
-                      FrameScanType scan);
-    void Show(FrameScanType );
-    bool InputChanged(const QSize &input_size, float aspect,
-                      MythCodecID  av_codec_id, void *codec_private,
-                      bool &aspect_only);
+    virtual void ProcessFrame(VideoFrame *frame, OSD *osd,
+                              FilterChain *filterList,
+                              const PIPMap &pipPlayers,
+                              FrameScanType scan);
+    virtual void Show(FrameScanType );
+    virtual bool InputChanged(const QSize &input_size, float aspect,
+                              MythCodecID  av_codec_id, void *codec_private,
+                              bool &aspect_only);
     void UpdatePauseFrame(void);
     void DrawUnusedRects(bool) { }
     void Zoom(ZoomDirection direction);
@@ -37,8 +38,8 @@
                                            const QSize &video_dim);
     void EmbedInWidget(int x, int y, int w, int h);
     void StopEmbedding(void);
-    bool SetDeinterlacingEnabled(bool);
-    bool SetupDeinterlace(bool i, const QString& ovrf="");
+    virtual bool SetDeinterlacingEnabled(bool);
+    virtual bool SetupDeinterlace(bool i, const QString& ovrf="");
     void ShowPIP(VideoFrame  *frame,
                  MythPlayer  *pipplayer,
                  PIPLocation  loc);
@@ -51,8 +52,9 @@
     virtual bool ApproveDeintFilter(const QString& filtername) const;
     virtual MythPainter *GetOSDPainter(void)  { return (MythPainter*)gl_painter; }
 
-  private:
-    bool CreateBuffers(void);
+  protected:
+    virtual bool CreateBuffers(void);
+    bool CreatePauseFrame(void);
     bool SetupContext(void);
     bool SetupOpenGL(void);
     void InitOSD(void);
Index: /home/mark/trunk/mythtv/libs/libmythtv/openglvideo.h
===================================================================
--- /home/mark/trunk/mythtv/libs/libmythtv/openglvideo.h	(revision 25868)
+++ /home/mark/trunk/mythtv/libs/libmythtv/openglvideo.h	(working copy)
@@ -44,8 +44,12 @@
               QSize videoDim, QRect displayVisibleRect,
               QRect displayVideoRect, QRect videoRect,
               bool viewport_control,  QString options,
+              bool hwaccel,
               LetterBoxColour letterbox_colour = kLetterBoxColour_Black);
 
+    uint GetInputTexture(void);
+    uint GetTextureType(void);
+    void SetInputUpdated(void);
     void UpdateInputFrame(const VideoFrame *frame, bool soft_bob = false);
 
     /// \brief Public interface to AddFilter(OpenGLFilterType filter)
@@ -124,6 +128,7 @@
     OpenGLFilterType defaultUpsize;
     uint           gl_features;
     bool           using_ycbcrtex;
+    bool           using_hardwaretex;
     LetterBoxColour gl_letterbox_colour;
 };
 #endif // _OPENGL_VIDEO_H__
Index: /home/mark/trunk/mythtv/libs/libmythtv/openglvideo.cpp
===================================================================
--- /home/mark/trunk/mythtv/libs/libmythtv/openglvideo.cpp	(revision 25868)
+++ /home/mark/trunk/mythtv/libs/libmythtv/openglvideo.cpp	(working copy)
@@ -84,6 +84,7 @@
     textureRects(false),      textureType(GL_TEXTURE_2D),
     helperTexture(0),         defaultUpsize(kGLFilterResize),
     gl_features(0),           using_ycbcrtex(false),
+    using_hardwaretex(false),
     gl_letterbox_colour(kLetterBoxColour_Black)
 {
 }
@@ -139,6 +140,7 @@
                        QSize videoDim, QRect displayVisibleRect,
                        QRect displayVideoRect, QRect videoRect,
                        bool viewport_control, QString options,
+                       bool hw_accel,
                        LetterBoxColour letterbox_colour)
 {
     gl_context            = glcontext;
@@ -175,10 +177,12 @@
 
     SetViewPort(display_visible_rect.size());
 
-    bool use_pbo        = gl_features & kGLExtPBufObj;
+    using_hardwaretex   = hw_accel;
+    bool use_pbo        = !using_hardwaretex && (gl_features & kGLExtPBufObj);
     bool basic_features = gl_features & kGLExtFragProg;
     bool full_features  = basic_features && (gl_features & kGLExtFBufObj);
-    using_ycbcrtex      = !full_features && (gl_features & kGLMesaYCbCr);
+    using_ycbcrtex      = !using_hardwaretex && !full_features &&
+                          (gl_features & kGLMesaYCbCr);
 
     if (using_ycbcrtex)
         basic_features = false;
@@ -192,27 +196,33 @@
                 QString("No OpenGL feature support for Bicubic filter."));
     }
 
-    if ((defaultUpsize != kGLFilterBicubic) && (gl_features & kGLExtRect))
+    if (!using_hardwaretex &&
+        (defaultUpsize != kGLFilterBicubic) && (gl_features & kGLExtRect))
         textureType = gl_context->GetTextureType(textureRects);
 
     GLuint tex = 0;
     bool    ok = false;
 
-    if (basic_features)
+    if (basic_features && !using_hardwaretex)
     {
         tex = CreateVideoTexture(actual_video_dim, inputTextureSize, use_pbo);
         ok = tex && AddFilter(kGLFilterYUV2RGB);
     }
-    else if (using_ycbcrtex)
+    else if (using_ycbcrtex || using_hardwaretex)
     {
         tex = CreateVideoTexture(actual_video_dim,
                                  inputTextureSize, use_pbo);
         ok = tex && AddFilter(kGLFilterResize);
-        if (ok)
+        if (ok && using_ycbcrtex)
             VERBOSE(VB_PLAYBACK, LOC + QString("Using GL_MESA_ycbcr_texture for"
                                                " colorspace conversion."));
+        else if (ok && using_hardwaretex)
+            VERBOSE(VB_PLAYBACK, LOC + QString("Using plain RGBA tex for hw accel."));
         else
+        {
             using_ycbcrtex = false;
+            using_hardwaretex = false;
+        }
     }
 
     if (ok)
@@ -707,6 +717,11 @@
         tmp_tex = gl_context->CreateTexture(size, use_pbo, textureType,
                                             GL_UNSIGNED_SHORT_8_8_MESA,
                                             GL_YCBCR_MESA, GL_YCBCR_MESA);
+    else if (using_hardwaretex)
+        tmp_tex = gl_context->CreateTexture(size, use_pbo, textureType,
+                                            GL_UNSIGNED_BYTE, GL_RGBA,
+                                            GL_RGBA, GL_LINEAR,
+                                            GL_CLAMP_TO_EDGE);
     else
         tmp_tex = gl_context->CreateTexture(size, use_pbo, textureType);
     tex_size = gl_context->GetTextureSize(textureType, size);
@@ -737,6 +752,21 @@
     return QSize(w, h);
 }
 
+uint OpenGLVideo::GetInputTexture(void)
+{
+    return inputTextures[0];
+}
+
+uint OpenGLVideo::GetTextureType(void)
+{
+    return textureType;
+}
+
+void OpenGLVideo::SetInputUpdated(void)
+{
+    inputUpdated = true;
+}
+
 /**
  * \fn OpenGLVideo::UpdateInputFrame(const VideoFrame *frame, bool soft_bob)
  *  Update the current input texture using the data from the given YV12 video
Index: /home/mark/trunk/mythtv/libs/libmythtv/mythcodecid.h
===================================================================
--- /home/mark/trunk/mythtv/libs/libmythtv/mythcodecid.h	(revision 25868)
+++ /home/mark/trunk/mythtv/libs/libmythtv/mythcodecid.h	(working copy)
@@ -115,7 +115,9 @@
                               codec->id == CODEC_ID_MPEG2VIDEO_XVMC_VLD))
 #define CODEC_IS_VDPAU(codec) (codec &&\
                                codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)
-#define CODEC_IS_HWACCEL(codec)  (CODEC_IS_XVMC(codec)  ||\
-                                  CODEC_IS_VDPAU(codec))
+#define CODEC_IS_VAAPI(codec, enc) (codec && IS_VAAPI_PIX_FMT(enc->pix_fmt))
+#define CODEC_IS_HWACCEL(codec, enc) (CODEC_IS_XVMC(codec)  ||\
+                                      CODEC_IS_VDPAU(codec) ||\
+                                      CODEC_IS_VAAPI(codec, enc))
 
 #endif // _MYTH_CODEC_ID_H_
Index: /home/mark/trunk/mythtv/libs/libmythtv/videooutbase.cpp
===================================================================
--- /home/mark/trunk/mythtv/libs/libmythtv/videooutbase.cpp	(revision 25868)
+++ /home/mark/trunk/mythtv/libs/libmythtv/videooutbase.cpp	(working copy)
@@ -40,6 +40,10 @@
 #include "videoout_vdpau.h"
 #endif
 
+#ifdef USING_VAAPI
+#include "videoout_openglvaapi.h"
+#endif
+
 #include "videoout_null.h"
 #include "dithertable.h"
 
@@ -96,6 +100,10 @@
 #ifdef USING_VDPAU
     VideoOutputVDPAU::GetRenderOptions(opts);
 #endif // USING_VDPAU
+
+#ifdef USING_VAAPI
+    VideoOutputOpenGLVAAPI::GetRenderOptions(opts);
+#endif // USING_VAAPI
 }
 
 /**
@@ -143,6 +151,10 @@
     renderers += VideoOutputVDPAU::GetAllowedRenderers(codec_id, video_dim);
 #endif // USING_VDPAU
 
+#ifdef USING_VAAPI
+    renderers += VideoOutputOpenGLVAAPI::GetAllowedRenderers(codec_id, video_dim);
+#endif // USING_VAAPI
+
     VERBOSE(VB_PLAYBACK, LOC + "Allowed renderers: " +
             to_comma_list(renderers));
 
@@ -205,6 +217,11 @@
             vo = new VideoOutputVDPAU();
 #endif // USING_VDPAU
 
+#ifdef USING_VAAPI
+        if (renderer == "openglvaapi")
+            vo = new VideoOutputOpenGLVAAPI();
+#endif // USING_VAAPI
+
 #ifdef USING_XV
         if (xvlist.contains(renderer))
             vo = new VideoOutputXv();
Index: /home/mark/trunk/mythtv/libs/libmythtv/vaapicontext.h
===================================================================
--- /home/mark/trunk/mythtv/libs/libmythtv/vaapicontext.h	(revision 0)
+++ /home/mark/trunk/mythtv/libs/libmythtv/vaapicontext.h	(revision 0)
@@ -0,0 +1,55 @@
+#ifndef VAAPICONTEXT_H
+#define VAAPICONTEXT_H
+
+extern "C" {
+#include "libavcodec/vaapi.h"
+}
+#include "va/va.h"
+#include "va/va_glx.h"
+#include <QHash>
+
+struct vaapi_surface
+{
+    VASurfaceID m_id;
+};
+class VAAPIDisplay;
+
+class VAAPIContext
+{
+  public:
+    static bool IsFormatAccelerated(QSize size, MythCodecID codec,
+                                    PixelFormat &pix_fmt);
+    VAAPIContext(MythCodecID codec);
+   ~VAAPIContext();
+
+    bool  CreateDisplay(QSize size);
+    bool  CreateBuffers(void);
+    void* GetVideoSurface(int i);
+    uint8_t* GetSurfaceIDPointer(void* buf);
+    
+    int   GetNumBuffers(void)        { return m_numSurfaces; }
+    PixelFormat GetPixelFormat(void) { return m_pix_fmt;     }
+    
+    bool  CopySurfaceToTexture(const void* buf, uint texture, uint texture_type);
+    void* GetGLXSurface(uint texture, uint texture_type);
+    void  ClearGLXSurfaces(void);
+
+    bool InitDisplay(void);
+    bool InitProfiles(void);
+    bool InitBuffers(void);
+    bool InitContext(void);
+
+    vaapi_context  m_ctx;
+    MythCodecID    m_codec;
+    QSize          m_size;
+    VAAPIDisplay  *m_display;
+    VAProfile      m_vaProfile;
+    VAEntrypoint   m_vaEntrypoint;
+    PixelFormat    m_pix_fmt;
+    int            m_numSurfaces;
+    VASurfaceID   *m_surfaces;
+    vaapi_surface *m_surfaceData;
+    QHash<uint, void*> m_glxSurfaces;
+};
+
+#endif // VAAPICONTEXT_H

