h265_dpb.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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_H265_DPB_H_
  5. #define MEDIA_GPU_H265_DPB_H_
  6. #include <vector>
  7. #include "base/memory/ref_counted.h"
  8. #include "media/base/video_color_space.h"
  9. #include "media/gpu/codec_picture.h"
  10. #include "media/gpu/media_gpu_export.h"
  11. namespace media {
  12. class VaapiH265Picture;
  13. class D3D11H265Picture;
  14. // A picture (a frame or a field) in the H.265 spec sense.
  15. // See spec at http://www.itu.int/rec/T-REC-H.265
  16. class MEDIA_GPU_EXPORT H265Picture : public CodecPicture {
  17. public:
  18. using Vector = std::vector<scoped_refptr<H265Picture>>;
  19. H265Picture();
  20. H265Picture(const H265Picture&) = delete;
  21. H265Picture& operator=(const H265Picture&) = delete;
  22. virtual VaapiH265Picture* AsVaapiH265Picture();
  23. virtual D3D11H265Picture* AsD3D11H265Picture();
  24. enum ReferenceType {
  25. kUnused = 0,
  26. kShortTermCurrBefore = 1,
  27. kShortTermCurrAfter = 2,
  28. kShortTermFoll = 3,
  29. kLongTermCurr = 4,
  30. kLongTermFoll = 5,
  31. };
  32. static std::string GetReferenceName(ReferenceType ref) {
  33. if (ref == kUnused)
  34. return "Unused";
  35. else if (ref == kLongTermCurr || ref == kLongTermFoll)
  36. return "LongTerm";
  37. else
  38. return "ShortTerm";
  39. }
  40. bool IsLongTermRef() const {
  41. return ref_ == kLongTermCurr || ref_ == kLongTermFoll;
  42. }
  43. bool IsShortTermRef() const {
  44. return ref_ == kShortTermCurrBefore || ref_ == kShortTermCurrAfter ||
  45. ref_ == kShortTermFoll;
  46. }
  47. bool IsUnused() const { return ref_ == kUnused; }
  48. // Values calculated per H.265 specification or taken from slice header.
  49. // See spec for more details on each (some names have been converted from
  50. // CamelCase in spec to Chromium-style names).
  51. int nal_unit_type_;
  52. bool no_rasl_output_flag_{false};
  53. bool no_output_of_prior_pics_flag_{false};
  54. bool pic_output_flag_{false};
  55. bool valid_for_prev_tid0_pic_{false};
  56. int slice_pic_order_cnt_lsb_{0};
  57. int pic_order_cnt_msb_{0};
  58. int pic_order_cnt_val_{0};
  59. // Our own state variables.
  60. bool irap_pic_;
  61. bool first_picture_;
  62. bool processed_{false};
  63. ReferenceType ref_{kUnused};
  64. bool outputted_{false};
  65. protected:
  66. ~H265Picture() override;
  67. };
  68. // DPB - Decoded Picture Buffer.
  69. // Stores decoded pictures that will be used for future display and/or
  70. // reference.
  71. class H265DPB {
  72. public:
  73. H265DPB();
  74. H265DPB(const H265DPB&) = delete;
  75. H265DPB& operator=(const H265DPB&) = delete;
  76. ~H265DPB();
  77. void set_max_num_pics(size_t max_num_pics);
  78. size_t max_num_pics() const { return max_num_pics_; }
  79. // Removes all entries from the DPB.
  80. void Clear();
  81. // Stores |pic| in the DPB. If |used_for_long_term| is true it'll be marked as
  82. // used for long term reference, otherwise it'll be marked as used for short
  83. // term reference.
  84. void StorePicture(scoped_refptr<H265Picture> pic,
  85. H265Picture::ReferenceType ref);
  86. // Mark all pictures in DPB as unused for reference.
  87. void MarkAllUnusedForReference();
  88. // Removes all pictures from the DPB that do not have |pic_output_flag_| set
  89. // and are marked Unused for reference.
  90. void DeleteUnused();
  91. // Returns the number of pictures in the DPB that are marked for reference.
  92. int GetReferencePicCount();
  93. // Returns a picture in the DPB which has a POC equal to |poc| and marks it
  94. // with |ref| reference type. If not found, returns nullptr.
  95. scoped_refptr<H265Picture> GetPicByPocAndMark(int poc,
  96. H265Picture::ReferenceType ref);
  97. // Returns a picture in the DPB which has a POC bitmasked by |mask| which
  98. // equals |poc| and marks it with |ref| reference type. If not found, returns
  99. // nullptr. If |mask| is zero, then no bitmasking is done.
  100. scoped_refptr<H265Picture>
  101. GetPicByPocMaskedAndMark(int poc, int mask, H265Picture::ReferenceType ref);
  102. // Appends to |out| all of the pictures in the DPB that are flagged for output
  103. // but have not be outputted yet.
  104. void AppendPendingOutputPics(H265Picture::Vector* out);
  105. // Appends to |out| all of the pictures in the DPB that are not marked as
  106. // unused for reference.
  107. void AppendReferencePics(H265Picture::Vector* out);
  108. size_t size() const { return pics_.size(); }
  109. bool IsFull() const { return pics_.size() >= max_num_pics_; }
  110. private:
  111. H265Picture::Vector pics_;
  112. size_t max_num_pics_{0};
  113. };
  114. } // namespace media
  115. #endif // MEDIA_GPU_H265_DPB_H_