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 H264DPB::H264DPB() : max_num_pics_(0) {}
14 H264DPB::~H264DPB() {}
16 void H264DPB::Clear() {
20 void H264DPB::set_max_num_pics(size_t max_num_pics
) {
21 DCHECK_LE(max_num_pics
, kDPBMaxSize
);
22 max_num_pics_
= max_num_pics
;
23 if (pics_
.size() > max_num_pics_
)
24 pics_
.resize(max_num_pics_
);
27 void H264DPB::DeleteByPOC(int poc
) {
28 for (Pictures::iterator it
= pics_
.begin(); it
!= pics_
.end(); ++it
) {
29 if ((*it
)->pic_order_cnt
== poc
) {
34 NOTREACHED() << "Missing POC: " << poc
;
37 void H264DPB::DeleteUnused() {
38 for (Pictures::iterator it
= pics_
.begin(); it
!= pics_
.end(); ) {
39 if ((*it
)->outputted
&& !(*it
)->ref
)
46 void H264DPB::StorePic(H264Picture
* pic
) {
47 DCHECK_LT(pics_
.size(), max_num_pics_
);
48 DVLOG(3) << "Adding PicNum: " << pic
->pic_num
<< " ref: " << (int)pic
->ref
49 << " longterm: " << (int)pic
->long_term
<< " to DPB";
53 int H264DPB::CountRefPics() {
55 for (size_t i
= 0; i
< pics_
.size(); ++i
) {
62 void H264DPB::MarkAllUnusedForRef() {
63 for (size_t i
= 0; i
< pics_
.size(); ++i
)
64 pics_
[i
]->ref
= false;
67 H264Picture
* H264DPB::GetShortRefPicByPicNum(int pic_num
) {
68 for (size_t i
= 0; i
< pics_
.size(); ++i
) {
69 H264Picture
* pic
= pics_
[i
];
70 if (pic
->ref
&& !pic
->long_term
&& pic
->pic_num
== pic_num
)
74 DVLOG(1) << "Missing short ref pic num: " << pic_num
;
78 H264Picture
* H264DPB::GetLongRefPicByLongTermPicNum(int pic_num
) {
79 for (size_t i
= 0; i
< pics_
.size(); ++i
) {
80 H264Picture
* pic
= pics_
[i
];
81 if (pic
->ref
&& pic
->long_term
&& pic
->long_term_pic_num
== pic_num
)
85 DVLOG(1) << "Missing long term pic num: " << pic_num
;
89 H264Picture
* H264DPB::GetLowestFrameNumWrapShortRefPic() {
90 H264Picture
* ret
= NULL
;
91 for (size_t i
= 0; i
< pics_
.size(); ++i
) {
92 H264Picture
* pic
= pics_
[i
];
93 if (pic
->ref
&& !pic
->long_term
&&
94 (!ret
|| pic
->frame_num_wrap
< ret
->frame_num_wrap
))
100 void H264DPB::GetNotOutputtedPicsAppending(H264Picture::PtrVector
& out
) {
101 for (size_t i
= 0; i
< pics_
.size(); ++i
) {
102 H264Picture
* pic
= pics_
[i
];
108 void H264DPB::GetShortTermRefPicsAppending(H264Picture::PtrVector
& out
) {
109 for (size_t i
= 0; i
< pics_
.size(); ++i
) {
110 H264Picture
* pic
= pics_
[i
];
111 if (pic
->ref
&& !pic
->long_term
)
116 void H264DPB::GetLongTermRefPicsAppending(H264Picture::PtrVector
& out
) {
117 for (size_t i
= 0; i
< pics_
.size(); ++i
) {
118 H264Picture
* pic
= pics_
[i
];
119 if (pic
->ref
&& pic
->long_term
)
124 } // namespace content