vaapi_common.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef MEDIA_GPU_VAAPI_VAAPI_COMMON_H_
  5. #define MEDIA_GPU_VAAPI_VAAPI_COMMON_H_
  6. #include "build/chromeos_buildflags.h"
  7. #include "media/gpu/av1_picture.h"
  8. #include "media/gpu/h264_dpb.h"
  9. #include "media/gpu/vaapi/va_surface.h"
  10. #include "media/gpu/vp8_picture.h"
  11. #include "media/gpu/vp9_picture.h"
  12. #include "media/media_buildflags.h"
  13. #if BUILDFLAG(ENABLE_HEVC_PARSER_AND_HW_DECODER)
  14. #include "media/gpu/h265_dpb.h"
  15. #endif // BUILDFLAG(ENABLE_HEVC_PARSER_AND_HW_DECODER)
  16. namespace media {
  17. // These picture classes derive from platform-independent, codec-specific
  18. // classes to allow augmenting them with VA-API-specific traits; used when
  19. // providing associated hardware resources and parameters to VA-API drivers.
  20. class VaapiH264Picture : public H264Picture {
  21. public:
  22. explicit VaapiH264Picture(scoped_refptr<VASurface> va_surface);
  23. VaapiH264Picture(const VaapiH264Picture&) = delete;
  24. VaapiH264Picture& operator=(const VaapiH264Picture&) = delete;
  25. VaapiH264Picture* AsVaapiH264Picture() override;
  26. scoped_refptr<VASurface> va_surface() const { return va_surface_; }
  27. VASurfaceID GetVASurfaceID() const { return va_surface_->id(); }
  28. protected:
  29. ~VaapiH264Picture() override;
  30. private:
  31. scoped_refptr<VASurface> va_surface_;
  32. };
  33. #if BUILDFLAG(ENABLE_HEVC_PARSER_AND_HW_DECODER)
  34. class VaapiH265Picture : public H265Picture {
  35. public:
  36. explicit VaapiH265Picture(scoped_refptr<VASurface> va_surface);
  37. VaapiH265Picture(const VaapiH265Picture&) = delete;
  38. VaapiH265Picture& operator=(const VaapiH265Picture&) = delete;
  39. VaapiH265Picture* AsVaapiH265Picture() override;
  40. scoped_refptr<VASurface> va_surface() const { return va_surface_; }
  41. VASurfaceID GetVASurfaceID() const { return va_surface_->id(); }
  42. protected:
  43. ~VaapiH265Picture() override;
  44. private:
  45. scoped_refptr<VASurface> va_surface_;
  46. };
  47. #endif // BUILDFLAG(ENABLE_HEVC_PARSER_AND_HW_DECODER)
  48. class VaapiVP8Picture : public VP8Picture {
  49. public:
  50. explicit VaapiVP8Picture(scoped_refptr<VASurface> va_surface);
  51. VaapiVP8Picture(const VaapiVP8Picture&) = delete;
  52. VaapiVP8Picture& operator=(const VaapiVP8Picture&) = delete;
  53. VaapiVP8Picture* AsVaapiVP8Picture() override;
  54. scoped_refptr<VASurface> va_surface() const { return va_surface_; }
  55. VASurfaceID GetVASurfaceID() const { return va_surface_->id(); }
  56. protected:
  57. ~VaapiVP8Picture() override;
  58. private:
  59. scoped_refptr<VASurface> va_surface_;
  60. };
  61. class VaapiVP9Picture : public VP9Picture {
  62. public:
  63. explicit VaapiVP9Picture(scoped_refptr<VASurface> va_surface);
  64. VaapiVP9Picture(const VaapiVP9Picture&) = delete;
  65. VaapiVP9Picture& operator=(const VaapiVP9Picture&) = delete;
  66. VaapiVP9Picture* AsVaapiVP9Picture() override;
  67. scoped_refptr<VASurface> va_surface() const { return va_surface_; }
  68. VASurfaceID GetVASurfaceID() const { return va_surface_->id(); }
  69. protected:
  70. ~VaapiVP9Picture() override;
  71. private:
  72. scoped_refptr<VP9Picture> CreateDuplicate() override;
  73. scoped_refptr<VASurface> va_surface_;
  74. };
  75. class VaapiAV1Picture : public AV1Picture {
  76. public:
  77. VaapiAV1Picture(scoped_refptr<VASurface> display_va_surface,
  78. scoped_refptr<VASurface> reconstruct_va_surface);
  79. VaapiAV1Picture(const VaapiAV1Picture&) = delete;
  80. VaapiAV1Picture& operator=(const VaapiAV1Picture&) = delete;
  81. const scoped_refptr<VASurface>& display_va_surface() const {
  82. return display_va_surface_;
  83. }
  84. const scoped_refptr<VASurface>& reconstruct_va_surface() const {
  85. return reconstruct_va_surface_;
  86. }
  87. protected:
  88. ~VaapiAV1Picture() override;
  89. private:
  90. scoped_refptr<AV1Picture> CreateDuplicate() override;
  91. // |display_va_surface_| refers to the final decoded frame, both when using
  92. // film grain synthesis and when not using film grain.
  93. // |reconstruct_va_surface_| is only useful when using film grain synthesis:
  94. // it's the decoded frame prior to applying the film grain.
  95. // When not using film grain synthesis, |reconstruct_va_surface_| is equal to
  96. // |display_va_surface_|. This is necessary to simplify the reference frame
  97. // code when filling the VA-API structures and to be able to always use
  98. // reconstruct_va_surface() when calling ExecuteAndDestroyPendingBuffers()
  99. // (the driver expects the reconstructed surface as the target in the case
  100. // of film grain synthesis).
  101. scoped_refptr<VASurface> display_va_surface_;
  102. scoped_refptr<VASurface> reconstruct_va_surface_;
  103. };
  104. } // namespace media
  105. #endif // MEDIA_GPU_VAAPI_VAAPI_COMMON_H_