PageRenderTime 17ms CodeModel.GetById 8ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/xbmc/cores/dvdplayer/DVDCodecs/Video/VAAPI.h

http://github.com/xbmc/xbmc
C++ Header | 145 lines | 99 code | 26 blank | 20 comment | 2 complexity | dd722f049f2df7b8fb63d4c8d1356899 MD5 | raw file
  1/*
  2 *      Copyright (C) 2005-2013 Team XBMC
  3 *      http://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 General Public License
 16 *  along with XBMC; see the file COPYING.  If not, see
 17 *  <http://www.gnu.org/licenses/>.
 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
 34namespace VAAPI {
 35
 36typedef boost::shared_ptr<VASurfaceID const> VASurfacePtr;
 37
 38struct CDisplay
 39  : CCriticalSection
 40{
 41  CDisplay(VADisplay display, bool deinterlace)
 42    : m_display(display)
 43    , m_lost(false)
 44    , m_deinterlace(deinterlace)
 45    , m_support_4k(true)
 46  {}
 47 ~CDisplay();
 48
 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; };
 55private:
 56  VADisplay m_display;
 57  bool      m_lost;
 58  bool      m_deinterlace;
 59  bool      m_support_4k;
 60};
 61
 62typedef boost::shared_ptr<CDisplay> CDisplayPtr;
 63
 64struct CSurface
 65{
 66  CSurface(VASurfaceID id, CDisplayPtr& display)
 67   : m_id(id)
 68   , m_display(display)
 69  {}
 70
 71 ~CSurface();
 72
 73  VASurfaceID m_id;
 74  CDisplayPtr m_display;
 75};
 76
 77typedef boost::shared_ptr<CSurface> CSurfacePtr;
 78
 79struct CSurfaceGL
 80{
 81  CSurfaceGL(void* id, CDisplayPtr& display)
 82    : m_id(id)
 83    , m_display(display)
 84  {}
 85 ~CSurfaceGL();
 86 
 87  void*       m_id;
 88  CDisplayPtr m_display;
 89};
 90
 91typedef boost::shared_ptr<CSurfaceGL> CSurfaceGLPtr;
 92
 93// silly type to avoid includes
 94struct CHolder
 95{
 96  CDisplayPtr   display;
 97  CSurfacePtr   surface;
 98  CSurfaceGLPtr surfglx;
 99
100  CHolder()
101  {}
102};
103
104class CDecoder
105  : public CDVDVideoCodecFFmpeg::IHardwareDecoder
106{
107  bool EnsureContext(AVCodecContext *avctx);
108  bool EnsureSurfaces(AVCodecContext *avctx, unsigned n_surfaces_count);
109public:
110  CDecoder();
111 ~CDecoder();
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();
120
121  int   GetBuffer(AVCodecContext *avctx, AVFrame *pic);
122  void  RelBuffer(AVCodecContext *avctx, AVFrame *pic);
123
124  VADisplay    GetDisplay() { return m_display->get(); }
125protected:
126  
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;
131
132  int                    m_refs;
133  std::list<CSurfacePtr> m_surfaces_used;
134  std::list<CSurfacePtr> m_surfaces_free;
135
136  CDisplayPtr    m_display;
137  VAConfigID     m_config;
138  VAContextID    m_context;
139
140  vaapi_context *m_hwaccel;
141
142  CHolder        m_holder; // silly struct to pass data to renderer
143};
144
145}