File: h265_dpb.cc

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (122 lines) | stat: -rw-r--r-- 3,188 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/gpu/v4l2/test/h265_dpb.h"

#include <algorithm>

#include "base/logging.h"
#include "media/gpu/macros.h"

namespace media::v4l2_test {

H265Picture::H265Picture() = default;
H265Picture::~H265Picture() = default;

H265DPB::H265DPB() = default;
H265DPB::~H265DPB() = default;

void H265DPB::SetMaxNumPics(size_t max_num_pics) {
  DCHECK_LE(max_num_pics, static_cast<size_t>(kMaxDpbSize));
  max_num_pics_ = max_num_pics;
  // reserve() is a no-op when |pics_.size() <= max_num_pics_|
  pics_.reserve(max_num_pics_);
}

void H265DPB::Clear() {
  pics_.clear();
}

void H265DPB::StorePicture(scoped_refptr<H265Picture> pic) {
  DCHECK_LT(pics_.size(), max_num_pics_);

  LOG(INFO) << "Adding PicNum: " << pic->pic_order_cnt_val_
            << " reference type: " << static_cast<int>(pic->reference_type_);
  pics_.push_back(std::move(pic));
}

void H265DPB::MarkAllUnusedForReference() {
  for (const auto& pic : pics_) {
    pic->reference_type_ = H265Picture::kUnused;
  }
}

void H265DPB::DeleteUnused() {
  // Note that |pic| is removed from the DPB during the for loop.
  // |pic| is removed after swapping with the last one in |pics_|.
  // The for loop will continue with the swapped one.
  for (auto it = pics_.begin(); it != pics_.end();) {
    auto& pic = *it;
    if ((!pic->pic_output_flag_ || pic->outputted_) &&
        (pic->reference_type_ == H265Picture::kUnused)) {
      std::swap(pic, *(pics_.end() - 1));
      pics_.pop_back();
    } else {
      it++;
    }
  }
}

int H265DPB::GetReferencePicCount() {
  int count = 0;
  for (const auto& pic : pics_) {
    if (pic->reference_type_ != H265Picture::kUnused) {
      count++;
    }
  }
  return count;
}

scoped_refptr<H265Picture> H265DPB::GetPicByPocAndMark(
    int poc,
    H265Picture::ReferenceType ref) {
  return GetPicByPocMaskedAndMark(poc, 0, ref);
}

scoped_refptr<H265Picture> H265DPB::GetPicByPocMaskedAndMark(
    int poc,
    int mask,
    H265Picture::ReferenceType ref) {
  for (const auto& pic : pics_) {
    if ((mask && (pic->pic_order_cnt_val_ & mask) == poc) ||
        (!mask && pic->pic_order_cnt_val_ == poc)) {
      pic->reference_type_ = ref;
      return pic;
    }
  }

  LOG(ERROR) << "Missing " << H265Picture::GetReferenceName(ref)
             << " ref pic num: " << poc;
  return nullptr;
}

void H265DPB::AppendPendingOutputPics(H265Picture::Vector* out) {
  for (const auto& pic : pics_) {
    if (pic->pic_output_flag_ && !pic->outputted_) {
      out->push_back(pic);
    }
  }
}

void H265DPB::AppendReferencePics(H265Picture::Vector* out) {
  for (const auto& pic : pics_) {
    if (pic->reference_type_ != H265Picture::kUnused) {
      out->push_back(pic);
    }
  }
}

std::set<uint32_t> H265DPB::GetBufferIdsInUse() const {
  std::set<uint32_t> buffer_ids_in_use;

  for (const auto& pic : pics_) {
    if (pic->reference_type_ != H265Picture::kUnused || !pic->outputted_) {
      buffer_ids_in_use.insert(pic->capture_queue_buffer_id_);
    }
  }

  return buffer_ids_in_use;
}

}  // namespace media::v4l2_test