h265_dpb.cc 2.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. #include <algorithm>
  5. #include "base/logging.h"
  6. #include "media/gpu/h265_dpb.h"
  7. #include "media/video/h265_parser.h"
  8. namespace media {
  9. H265Picture::H265Picture() = default;
  10. H265Picture::~H265Picture() = default;
  11. H265DPB::H265DPB() = default;
  12. H265DPB::~H265DPB() = default;
  13. VaapiH265Picture* H265Picture::AsVaapiH265Picture() {
  14. return nullptr;
  15. }
  16. D3D11H265Picture* H265Picture::AsD3D11H265Picture() {
  17. return nullptr;
  18. }
  19. void H265DPB::set_max_num_pics(size_t max_num_pics) {
  20. DCHECK_LE(max_num_pics, static_cast<size_t>(kMaxDpbSize));
  21. max_num_pics_ = max_num_pics;
  22. if (pics_.size() > max_num_pics_)
  23. pics_.resize(max_num_pics_);
  24. }
  25. void H265DPB::Clear() {
  26. pics_.clear();
  27. }
  28. void H265DPB::StorePicture(scoped_refptr<H265Picture> pic,
  29. H265Picture::ReferenceType ref) {
  30. DCHECK_LT(pics_.size(), max_num_pics_);
  31. pic->ref_ = ref;
  32. DVLOG(3) << "Adding PicNum: " << pic->pic_order_cnt_val_
  33. << " ref: " << static_cast<int>(pic->ref_);
  34. pics_.push_back(std::move(pic));
  35. }
  36. void H265DPB::MarkAllUnusedForReference() {
  37. for (const auto& pic : pics_)
  38. pic->ref_ = H265Picture::kUnused;
  39. }
  40. void H265DPB::DeleteUnused() {
  41. for (auto it = pics_.begin(); it != pics_.end();) {
  42. auto& pic = *it;
  43. if ((!pic->pic_output_flag_ || pic->outputted_) &&
  44. (pic->ref_ == H265Picture::kUnused)) {
  45. std::swap(pic, *(pics_.end() - 1));
  46. pics_.pop_back();
  47. } else {
  48. it++;
  49. }
  50. }
  51. }
  52. int H265DPB::GetReferencePicCount() {
  53. int count = 0;
  54. for (const auto& pic : pics_) {
  55. if (pic->ref_ != H265Picture::kUnused)
  56. count++;
  57. }
  58. return count;
  59. }
  60. scoped_refptr<H265Picture> H265DPB::GetPicByPocAndMark(
  61. int poc,
  62. H265Picture::ReferenceType ref) {
  63. return GetPicByPocMaskedAndMark(poc, 0, ref);
  64. }
  65. scoped_refptr<H265Picture> H265DPB::GetPicByPocMaskedAndMark(
  66. int poc,
  67. int mask,
  68. H265Picture::ReferenceType ref) {
  69. for (const auto& pic : pics_) {
  70. if ((mask && (pic->pic_order_cnt_val_ & mask) == poc) ||
  71. (!mask && pic->pic_order_cnt_val_ == poc)) {
  72. pic->ref_ = ref;
  73. return pic;
  74. }
  75. }
  76. DVLOG(1) << "Missing " << H265Picture::GetReferenceName(ref)
  77. << " ref pic num: " << poc;
  78. return nullptr;
  79. }
  80. void H265DPB::AppendPendingOutputPics(H265Picture::Vector* out) {
  81. for (const auto& pic : pics_) {
  82. if (pic->pic_output_flag_ && !pic->outputted_)
  83. out->push_back(pic);
  84. }
  85. }
  86. void H265DPB::AppendReferencePics(H265Picture::Vector* out) {
  87. for (const auto& pic : pics_) {
  88. if (pic->ref_ != H265Picture::kUnused)
  89. out->push_back(pic);
  90. }
  91. }
  92. } // namespace media