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/vaapi_h264_dpb.h"
13 VaapiH264DPB::VaapiH264DPB() : max_num_pics_(0) {
15 VaapiH264DPB::~VaapiH264DPB() {
18 void VaapiH264DPB::Clear() {
22 void VaapiH264DPB::set_max_num_pics(size_t max_num_pics
) {
23 DCHECK_LE(max_num_pics
, kDPBMaxSize
);
24 max_num_pics_
= max_num_pics
;
25 if (pics_
.size() > max_num_pics_
)
26 pics_
.resize(max_num_pics_
);
29 void VaapiH264DPB::DeleteByPOC(int poc
) {
30 for (Pictures::iterator it
= pics_
.begin(); it
!= pics_
.end(); ++it
) {
31 if ((*it
)->pic_order_cnt
== poc
) {
36 NOTREACHED() << "Missing POC: " << poc
;
39 void VaapiH264DPB::DeleteUnused() {
40 for (Pictures::iterator it
= pics_
.begin(); it
!= pics_
.end(); ) {
41 if ((*it
)->outputted
&& !(*it
)->ref
)
48 void VaapiH264DPB::StorePic(VaapiH264Picture
* pic
) {
49 DCHECK_LT(pics_
.size(), max_num_pics_
);
50 DVLOG(3) << "Adding PicNum: " << pic
->pic_num
<< " ref: " << (int)pic
->ref
51 << " longterm: " << (int)pic
->long_term
<< " to DPB";
55 int VaapiH264DPB::CountRefPics() {
57 for (size_t i
= 0; i
< pics_
.size(); ++i
) {
64 void VaapiH264DPB::MarkAllUnusedForRef() {
65 for (size_t i
= 0; i
< pics_
.size(); ++i
)
66 pics_
[i
]->ref
= false;
69 VaapiH264Picture
* VaapiH264DPB::GetShortRefPicByPicNum(int pic_num
) {
70 for (size_t i
= 0; i
< pics_
.size(); ++i
) {
71 VaapiH264Picture
* pic
= pics_
[i
];
72 if (pic
->ref
&& !pic
->long_term
&& pic
->pic_num
== pic_num
)
76 DVLOG(1) << "Missing short ref pic num: " << pic_num
;
80 VaapiH264Picture
* VaapiH264DPB::GetLongRefPicByLongTermPicNum(int pic_num
) {
81 for (size_t i
= 0; i
< pics_
.size(); ++i
) {
82 VaapiH264Picture
* pic
= pics_
[i
];
83 if (pic
->ref
&& pic
->long_term
&& pic
->long_term_pic_num
== pic_num
)
87 DVLOG(1) << "Missing long term pic num: " << pic_num
;
91 VaapiH264Picture
* VaapiH264DPB::GetLowestFrameNumWrapShortRefPic() {
92 VaapiH264Picture
* ret
= NULL
;
93 for (size_t i
= 0; i
< pics_
.size(); ++i
) {
94 VaapiH264Picture
* pic
= pics_
[i
];
95 if (pic
->ref
&& !pic
->long_term
&&
96 (!ret
|| pic
->frame_num_wrap
< ret
->frame_num_wrap
))
102 void VaapiH264DPB::GetNotOutputtedPicsAppending(
103 VaapiH264Picture::PtrVector
& out
) {
104 for (size_t i
= 0; i
< pics_
.size(); ++i
) {
105 VaapiH264Picture
* pic
= pics_
[i
];
111 void VaapiH264DPB::GetShortTermRefPicsAppending(
112 VaapiH264Picture::PtrVector
& out
) {
113 for (size_t i
= 0; i
< pics_
.size(); ++i
) {
114 VaapiH264Picture
* pic
= pics_
[i
];
115 if (pic
->ref
&& !pic
->long_term
)
120 void VaapiH264DPB::GetLongTermRefPicsAppending(
121 VaapiH264Picture::PtrVector
& out
) {
122 for (size_t i
= 0; i
< pics_
.size(); ++i
) {
123 VaapiH264Picture
* pic
= pics_
[i
];
124 if (pic
->ref
&& pic
->long_term
)
129 } // namespace content