[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / cores / dvdplayer / DVDCodecs / Video / VAAPI.h
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://www.xbmc.org
4  *
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.
9  *
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.
14  *
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
18  *
19  */
20 #pragma once
21
22 #include "system_gl.h"
23
24 #include "DllAvCodec.h"
25 #include "DVDVideoCodecFFmpeg.h"
26 #include <libavcodec/vaapi.h>
27 #include <va/va.h>
28 #include <va/va_x11.h>
29 #include <va/va_glx.h>
30 #include <list>
31 #include <boost/shared_ptr.hpp>
32
33
34 namespace VAAPI {
35
36 typedef boost::shared_ptr<VASurfaceID const> VASurfacePtr;
37
38 struct CDisplay
39   : CCriticalSection
40 {
41   CDisplay(VADisplay display, bool deinterlace)
42     : m_display(display)
43     , m_lost(false)
44     , m_deinterlace(deinterlace)
45   {}
46  ~CDisplay();
47
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; };
52 private:
53   VADisplay m_display;
54   bool      m_lost;
55   bool      m_deinterlace;
56 };
57
58 typedef boost::shared_ptr<CDisplay> CDisplayPtr;
59
60 struct CSurface
61 {
62   CSurface(VASurfaceID id, CDisplayPtr& display)
63    : m_id(id)
64    , m_display(display)
65   {}
66
67  ~CSurface();
68
69   VASurfaceID m_id;
70   CDisplayPtr m_display;
71 };
72
73 typedef boost::shared_ptr<CSurface> CSurfacePtr;
74
75 struct CSurfaceGL
76 {
77   CSurfaceGL(void* id, CDisplayPtr& display)
78     : m_id(id)
79     , m_display(display)
80   {}
81  ~CSurfaceGL();
82  
83   void*       m_id;
84   CDisplayPtr m_display;
85 };
86
87 typedef boost::shared_ptr<CSurfaceGL> CSurfaceGLPtr;
88
89 // silly type to avoid includes
90 struct CHolder
91 {
92   CDisplayPtr   display;
93   CSurfacePtr   surface;
94   CSurfaceGLPtr surfglx;
95
96   CHolder()
97   {}
98 };
99
100 class CDecoder
101   : public CDVDVideoCodecFFmpeg::IHardwareDecoder
102 {
103   bool EnsureContext(AVCodecContext *avctx);
104   bool EnsureSurfaces(AVCodecContext *avctx, unsigned n_surfaces_count);
105 public:
106   CDecoder();
107  ~CDecoder();
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; }
115
116   int   GetBuffer(AVCodecContext *avctx, AVFrame *pic);
117   void  RelBuffer(AVCodecContext *avctx, AVFrame *pic);
118
119   VADisplay    GetDisplay() { return m_display->get(); }
120 protected:
121   
122   static const unsigned  m_surfaces_max = 32;
123   unsigned               m_surfaces_count;
124   VASurfaceID            m_surfaces[m_surfaces_max];
125
126   int                    m_refs;
127   std::list<CSurfacePtr> m_surfaces_used;
128   std::list<CSurfacePtr> m_surfaces_free;
129
130   CDisplayPtr    m_display;
131   VAConfigID     m_config;
132   VAContextID    m_context;
133
134   vaapi_context *m_hwaccel;
135
136   CHolder        m_holder; // silly struct to pass data to renderer
137 };
138
139 }