GPU workaround to simulate Out of Memory errors with large textures
[chromium-blink-merge.git] / content / common / gpu / media / vaapi_h264_dpb.cc
blob7141618ce78433261ce5cc14b29893bacabce114
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.
5 #include <algorithm>
7 #include "base/logging.h"
8 #include "base/stl_util.h"
9 #include "content/common/gpu/media/vaapi_h264_dpb.h"
11 namespace content {
13 VaapiH264DPB::VaapiH264DPB() : max_num_pics_(0) {
15 VaapiH264DPB::~VaapiH264DPB() {
18 void VaapiH264DPB::Clear() {
19 pics_.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) {
32 pics_.erase(it);
33 return;
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)
42 it = pics_.erase(it);
43 else
44 ++it;
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";
52 pics_.push_back(pic);
55 int VaapiH264DPB::CountRefPics() {
56 int ret = 0;
57 for (size_t i = 0; i < pics_.size(); ++i) {
58 if (pics_[i]->ref)
59 ++ret;
61 return ret;
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)
73 return pic;
76 DVLOG(1) << "Missing short ref pic num: " << pic_num;
77 return NULL;
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)
84 return pic;
87 DVLOG(1) << "Missing long term pic num: " << pic_num;
88 return NULL;
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))
97 ret = pic;
99 return ret;
102 void VaapiH264DPB::GetNotOutputtedPicsAppending(
103 VaapiH264Picture::PtrVector& out) {
104 for (size_t i = 0; i < pics_.size(); ++i) {
105 VaapiH264Picture* pic = pics_[i];
106 if (!pic->outputted)
107 out.push_back(pic);
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)
116 out.push_back(pic);
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)
125 out.push_back(pic);
129 } // namespace content