h265_vaapi_video_decoder_delegate.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Copyright 2020 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_H265_VAAPI_VIDEO_DECODER_DELEGATE_H_
  5. #define MEDIA_GPU_VAAPI_H265_VAAPI_VIDEO_DECODER_DELEGATE_H_
  6. #include <va/va.h>
  7. #include "base/memory/scoped_refptr.h"
  8. #include "build/chromeos_buildflags.h"
  9. #include "media/gpu/h265_decoder.h"
  10. #include "media/gpu/h265_dpb.h"
  11. #include "media/gpu/vaapi/vaapi_video_decoder_delegate.h"
  12. #include "media/video/h265_parser.h"
  13. // Verbatim from va/va.h, where typedef is used.
  14. typedef struct _VAPictureHEVC VAPictureHEVC;
  15. namespace media {
  16. class CdmContext;
  17. class H265Picture;
  18. class H265VaapiVideoDecoderDelegate : public H265Decoder::H265Accelerator,
  19. public VaapiVideoDecoderDelegate {
  20. public:
  21. H265VaapiVideoDecoderDelegate(
  22. DecodeSurfaceHandler<VASurface>* vaapi_dec,
  23. scoped_refptr<VaapiWrapper> vaapi_wrapper,
  24. ProtectedSessionUpdateCB on_protected_session_update_cb,
  25. CdmContext* cdm_context,
  26. EncryptionScheme encryption_scheme);
  27. H265VaapiVideoDecoderDelegate(const H265VaapiVideoDecoderDelegate&) = delete;
  28. H265VaapiVideoDecoderDelegate& operator=(
  29. const H265VaapiVideoDecoderDelegate&) = delete;
  30. ~H265VaapiVideoDecoderDelegate() override;
  31. // H265Decoder::H265Accelerator implementation.
  32. scoped_refptr<H265Picture> CreateH265Picture() override;
  33. Status SubmitFrameMetadata(const H265SPS* sps,
  34. const H265PPS* pps,
  35. const H265SliceHeader* slice_hdr,
  36. const H265Picture::Vector& ref_pic_list,
  37. scoped_refptr<H265Picture> pic) override;
  38. Status SubmitSlice(const H265SPS* sps,
  39. const H265PPS* pps,
  40. const H265SliceHeader* slice_hdr,
  41. const H265Picture::Vector& ref_pic_list0,
  42. const H265Picture::Vector& ref_pic_list1,
  43. const H265Picture::Vector& ref_pic_set_lt_curr,
  44. const H265Picture::Vector& ref_pic_set_st_curr_after,
  45. const H265Picture::Vector& ref_pic_set_st_curr_before,
  46. scoped_refptr<H265Picture> pic,
  47. const uint8_t* data,
  48. size_t size,
  49. const std::vector<SubsampleEntry>& subsamples) override;
  50. Status SubmitDecode(scoped_refptr<H265Picture> pic) override;
  51. bool OutputPicture(scoped_refptr<H265Picture> pic) override;
  52. void Reset() override;
  53. Status SetStream(base::span<const uint8_t> stream,
  54. const DecryptConfig* decrypt_config) override;
  55. bool IsChromaSamplingSupported(VideoChromaSampling chroma_sampling) override;
  56. private:
  57. void FillVAPicture(VAPictureHEVC* va_pic, scoped_refptr<H265Picture> pic);
  58. void FillVARefFramesFromRefList(const H265Picture::Vector& ref_pic_list,
  59. VAPictureHEVC* va_pics);
  60. // Returns |kInvalidRefPicIndex| if it cannot find a picture.
  61. int GetRefPicIndex(int poc);
  62. // Submits the slice data to the decoder for the prior slice that was just
  63. // submitted to us. This allows us to handle multi-slice pictures properly.
  64. // |last_slice| is set to true when submitting the last slice, false
  65. // otherwise.
  66. bool SubmitPriorSliceDataIfPresent(bool last_slice);
  67. // Stores the POCs (picture order counts) in the ReferenceFrames submitted as
  68. // the frame metadata so we can determine the indices for the reference frames
  69. // in the slice metadata.
  70. std::vector<int> ref_pic_list_pocs_;
  71. // Data from the prior/current slice for handling multi slice so we can
  72. // properly set the flag for the last slice.
  73. VASliceParameterBufferHEVC slice_param_;
  74. // We can hold onto the slice data pointer because we process all frames as
  75. // one DecoderBuffer, so the memory will still be accessible until the frame
  76. // is done. |last_slice_data_| being non-null indicates we have a valid
  77. // |slice_param_| filled.
  78. const uint8_t* last_slice_data_{nullptr};
  79. size_t last_slice_size_{0};
  80. std::string last_transcrypt_params_;
  81. #if BUILDFLAG(IS_CHROMEOS_ASH)
  82. // We need to hold onto this memory here because it's referenced by the
  83. // mapped buffer in libva across calls. It is filled in SubmitSlice() and
  84. // stays alive until SubmitDecode() or Reset().
  85. std::vector<VAEncryptionSegmentInfo> encryption_segment_info_;
  86. // We need to retain this for the multi-slice case since that will aggregate
  87. // the encryption details across all the slices.
  88. VAEncryptionParameters crypto_params_;
  89. #endif // BUILDFLAG(IS_CHROMEOS_ASH)
  90. };
  91. } // namespace media
  92. #endif // MEDIA_GPU_VAAPI_H265_VAAPI_VIDEO_DECODER_DELEGATE_H_