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 General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
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)
49 VADisplay get() { return m_display; }
50 bool lost() { return m_lost; }
51 void lost(bool lost) { m_lost = lost; }
52 bool support_deinterlace() { return m_deinterlace; };
53 bool support_4k() { return m_support_4k; };
54 void support_4k(bool support_4k) { m_support_4k = support_4k; };
62 typedef boost::shared_ptr<CDisplay> CDisplayPtr;
66 CSurface(VASurfaceID id, CDisplayPtr& display)
74 CDisplayPtr m_display;
77 typedef boost::shared_ptr<CSurface> CSurfacePtr;
81 CSurfaceGL(void* id, CDisplayPtr& display)
88 CDisplayPtr m_display;
91 typedef boost::shared_ptr<CSurfaceGL> CSurfaceGLPtr;
93 // silly type to avoid includes
98 CSurfaceGLPtr surfglx;
105 : public CDVDVideoCodecFFmpeg::IHardwareDecoder
107 bool EnsureContext(AVCodecContext *avctx);
108 bool EnsureSurfaces(AVCodecContext *avctx, unsigned n_surfaces_count);
112 virtual bool Open (AVCodecContext* avctx, const enum PixelFormat, unsigned int surfaces = 0);
113 virtual int Decode (AVCodecContext* avctx, AVFrame* frame);
114 virtual bool GetPicture(AVCodecContext* avctx, AVFrame* frame, DVDVideoPicture* picture);
115 virtual int Check (AVCodecContext* avctx);
116 virtual void Close();
117 virtual const std::string Name() { return "vaapi"; }
118 virtual CCriticalSection* Section() { if(m_display) return m_display.get(); else return NULL; }
119 virtual unsigned GetAllowedReferences();
121 int GetBuffer(AVCodecContext *avctx, AVFrame *pic);
122 void RelBuffer(AVCodecContext *avctx, AVFrame *pic);
124 VADisplay GetDisplay() { return m_display->get(); }
127 static const unsigned m_surfaces_max = 32;
128 unsigned m_surfaces_count;
129 VASurfaceID m_surfaces[m_surfaces_max];
130 unsigned m_renderbuffers_count;
133 std::list<CSurfacePtr> m_surfaces_used;
134 std::list<CSurfacePtr> m_surfaces_free;
136 CDisplayPtr m_display;
138 VAContextID m_context;
140 vaapi_context *m_hwaccel;
142 CHolder m_holder; // silly struct to pass data to renderer