2 * Copyright (C) 2005-2013 Team XBMC
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "system_gl.h"
24 #include "DllAvCodec.h"
25 #include "DVDVideoCodecFFmpeg.h"
26 #include <libavcodec/vaapi.h>
28 #include <va/va_x11.h>
29 #include <va/va_glx.h>
31 #include <boost/shared_ptr.hpp>
36 typedef boost::shared_ptr<VASurfaceID const> VASurfacePtr;
41 CDisplay(VADisplay display, bool deinterlace)
44 , m_deinterlace(deinterlace)
48 VADisplay get() { return m_display; }
49 bool lost() { return m_lost; }
50 void lost(bool lost) { m_lost = lost; }
51 bool support_deinterlace() { return m_deinterlace; };
58 typedef boost::shared_ptr<CDisplay> CDisplayPtr;
62 CSurface(VASurfaceID id, CDisplayPtr& display)
70 CDisplayPtr m_display;
73 typedef boost::shared_ptr<CSurface> CSurfacePtr;
77 CSurfaceGL(void* id, CDisplayPtr& display)
84 CDisplayPtr m_display;
87 typedef boost::shared_ptr<CSurfaceGL> CSurfaceGLPtr;
89 // silly type to avoid includes
94 CSurfaceGLPtr surfglx;
101 : public CDVDVideoCodecFFmpeg::IHardwareDecoder
103 bool EnsureContext(AVCodecContext *avctx);
104 bool EnsureSurfaces(AVCodecContext *avctx, unsigned n_surfaces_count);
108 virtual bool Open (AVCodecContext* avctx, const enum PixelFormat, unsigned int surfaces = 0);
109 virtual int Decode (AVCodecContext* avctx, AVFrame* frame);
110 virtual bool GetPicture(AVCodecContext* avctx, AVFrame* frame, DVDVideoPicture* picture);
111 virtual int Check (AVCodecContext* avctx);
112 virtual void Close();
113 virtual const std::string Name() { return "vaapi"; }
114 virtual CCriticalSection* Section() { if(m_display) return m_display.get(); else return NULL; }
116 int GetBuffer(AVCodecContext *avctx, AVFrame *pic);
117 void RelBuffer(AVCodecContext *avctx, AVFrame *pic);
119 VADisplay GetDisplay() { return m_display->get(); }
122 static const unsigned m_surfaces_max = 32;
123 unsigned m_surfaces_count;
124 VASurfaceID m_surfaces[m_surfaces_max];
127 std::list<CSurfacePtr> m_surfaces_used;
128 std::list<CSurfacePtr> m_surfaces_free;
130 CDisplayPtr m_display;
132 VAContextID m_context;
134 vaapi_context *m_hwaccel;
136 CHolder m_holder; // silly struct to pass data to renderer