1 // Copyright (c) 2012 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.
7 #include "base/logging.h"
8 #include "base/stl_util.h"
9 #include "content/common/gpu/media/h264_dpb.h"
13 H264Picture::H264Picture()
14 : top_field_order_cnt(0),
15 bottom_field_order_cnt(0),
24 long_term_frame_idx(0),
25 type(media::H264SliceHeader::kPSlice
),
32 long_term_reference_flag(false),
33 adaptive_ref_pic_marking_mode_flag(false),
35 memset(&ref_pic_marking
, 0, sizeof(ref_pic_marking
));
38 H264Picture::~H264Picture() {
41 V4L2H264Picture
* H264Picture::AsV4L2H264Picture() {
45 VaapiH264Picture
* H264Picture::AsVaapiH264Picture() {
49 H264DPB::H264DPB() : max_num_pics_(0) {}
50 H264DPB::~H264DPB() {}
52 void H264DPB::Clear() {
56 void H264DPB::set_max_num_pics(size_t max_num_pics
) {
57 DCHECK_LE(max_num_pics
, kDPBMaxSize
);
58 max_num_pics_
= max_num_pics
;
59 if (pics_
.size() > max_num_pics_
)
60 pics_
.resize(max_num_pics_
);
63 void H264DPB::UpdatePicPositions() {
65 for (auto& pic
: pics_
) {
66 pic
->dpb_position
= i
;
71 void H264DPB::DeleteByPOC(int poc
) {
72 for (H264Picture::Vector::iterator it
= pics_
.begin();
73 it
!= pics_
.end(); ++it
) {
74 if ((*it
)->pic_order_cnt
== poc
) {
80 NOTREACHED() << "Missing POC: " << poc
;
83 void H264DPB::DeleteUnused() {
84 for (H264Picture::Vector::iterator it
= pics_
.begin(); it
!= pics_
.end(); ) {
85 if ((*it
)->outputted
&& !(*it
)->ref
)
93 void H264DPB::StorePic(const scoped_refptr
<H264Picture
>& pic
) {
94 DCHECK_LT(pics_
.size(), max_num_pics_
);
95 DVLOG(3) << "Adding PicNum: " << pic
->pic_num
<< " ref: " << (int)pic
->ref
96 << " longterm: " << (int)pic
->long_term
<< " to DPB";
97 pic
->dpb_position
= pics_
.size();
101 int H264DPB::CountRefPics() {
103 for (size_t i
= 0; i
< pics_
.size(); ++i
) {
110 void H264DPB::MarkAllUnusedForRef() {
111 for (size_t i
= 0; i
< pics_
.size(); ++i
)
112 pics_
[i
]->ref
= false;
115 scoped_refptr
<H264Picture
> H264DPB::GetShortRefPicByPicNum(int pic_num
) {
116 for (const auto& pic
: pics_
) {
117 if (pic
->ref
&& !pic
->long_term
&& pic
->pic_num
== pic_num
)
121 DVLOG(1) << "Missing short ref pic num: " << pic_num
;
125 scoped_refptr
<H264Picture
> H264DPB::GetLongRefPicByLongTermPicNum(int pic_num
) {
126 for (const auto& pic
: pics_
) {
127 if (pic
->ref
&& pic
->long_term
&& pic
->long_term_pic_num
== pic_num
)
131 DVLOG(1) << "Missing long term pic num: " << pic_num
;
135 scoped_refptr
<H264Picture
> H264DPB::GetLowestFrameNumWrapShortRefPic() {
136 scoped_refptr
<H264Picture
> ret
;
137 for (const auto& pic
: pics_
) {
138 if (pic
->ref
&& !pic
->long_term
&&
139 (!ret
|| pic
->frame_num_wrap
< ret
->frame_num_wrap
))
145 void H264DPB::GetNotOutputtedPicsAppending(H264Picture::Vector
* out
) {
146 for (const auto& pic
: pics_
) {
152 void H264DPB::GetShortTermRefPicsAppending(H264Picture::Vector
* out
) {
153 for (const auto& pic
: pics_
) {
154 if (pic
->ref
&& !pic
->long_term
)
159 void H264DPB::GetLongTermRefPicsAppending(H264Picture::Vector
* out
) {
160 for (const auto& pic
: pics_
) {
161 if (pic
->ref
&& pic
->long_term
)
166 } // namespace content