/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. #include "system_gl.h"
  22. #include "DllAvCodec.h"
  23. #include "DVDVideoCodecFFmpeg.h"
  24. #include <libavcodec/vaapi.h>
  25. #include <va/va.h>
  26. #include <va/va_x11.h>
  27. #include <va/va_glx.h>
  28. #include <list>
  29. #include <boost/shared_ptr.hpp>
  30. namespace VAAPI {
  31. typedef boost::shared_ptr<VASurfaceID const> VASurfacePtr;
  32. struct CDisplay
  33. : CCriticalSection
  34. {
  35. CDisplay(VADisplay display, bool deinterlace)
  36. : m_display(display)
  37. , m_lost(false)
  38. , m_deinterlace(deinterlace)
  39. , m_support_4k(true)
  40. {}
  41. ~CDisplay();
  42. VADisplay get() { return m_display; }
  43. bool lost() { return m_lost; }
  44. void lost(bool lost) { m_lost = lost; }
  45. bool support_deinterlace() { return m_deinterlace; };
  46. bool support_4k() { return m_support_4k; };
  47. void support_4k(bool support_4k) { m_support_4k = support_4k; };
  48. private:
  49. VADisplay m_display;
  50. bool m_lost;
  51. bool m_deinterlace;
  52. bool m_support_4k;
  53. };
  54. typedef boost::shared_ptr<CDisplay> CDisplayPtr;
  55. struct CSurface
  56. {
  57. CSurface(VASurfaceID id, CDisplayPtr& display)
  58. : m_id(id)
  59. , m_display(display)
  60. {}
  61. ~CSurface();
  62. VASurfaceID m_id;
  63. CDisplayPtr m_display;
  64. };
  65. typedef boost::shared_ptr<CSurface> CSurfacePtr;
  66. struct CSurfaceGL
  67. {
  68. CSurfaceGL(void* id, CDisplayPtr& display)
  69. : m_id(id)
  70. , m_display(display)
  71. {}
  72. ~CSurfaceGL();
  73. void* m_id;
  74. CDisplayPtr m_display;
  75. };
  76. typedef boost::shared_ptr<CSurfaceGL> CSurfaceGLPtr;
  77. // silly type to avoid includes
  78. struct CHolder
  79. {
  80. CDisplayPtr display;
  81. CSurfacePtr surface;
  82. CSurfaceGLPtr surfglx;
  83. CHolder()
  84. {}
  85. };
  86. class CDecoder
  87. : public CDVDVideoCodecFFmpeg::IHardwareDecoder
  88. {
  89. bool EnsureContext(AVCodecContext *avctx);
  90. bool EnsureSurfaces(AVCodecContext *avctx, unsigned n_surfaces_count);
  91. public:
  92. CDecoder();
  93. ~CDecoder();
  94. virtual bool Open (AVCodecContext* avctx, const enum PixelFormat, unsigned int surfaces = 0);
  95. virtual int Decode (AVCodecContext* avctx, AVFrame* frame);
  96. virtual bool GetPicture(AVCodecContext* avctx, AVFrame* frame, DVDVideoPicture* picture);
  97. virtual int Check (AVCodecContext* avctx);
  98. virtual void Close();
  99. virtual const std::string Name() { return "vaapi"; }
  100. virtual CCriticalSection* Section() { if(m_display) return m_display.get(); else return NULL; }
  101. virtual unsigned GetAllowedReferences();
  102. int GetBuffer(AVCodecContext *avctx, AVFrame *pic);
  103. void RelBuffer(AVCodecContext *avctx, AVFrame *pic);
  104. VADisplay GetDisplay() { return m_display->get(); }
  105. protected:
  106. static const unsigned m_surfaces_max = 32;
  107. unsigned m_surfaces_count;
  108. VASurfaceID m_surfaces[m_surfaces_max];
  109. unsigned m_renderbuffers_count;
  110. int m_refs;
  111. std::list<CSurfacePtr> m_surfaces_used;
  112. std::list<CSurfacePtr> m_surfaces_free;
  113. CDisplayPtr m_display;
  114. VAConfigID m_config;
  115. VAContextID m_context;
  116. vaapi_context *m_hwaccel;
  117. CHolder m_holder; // silly struct to pass data to renderer
  118. };
  119. }