Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / common / gpu / media / h264_dpb.cc
blob371d61283139a4df1084b653d6e645ae9edd8a8e
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/h264_dpb.h"
11 namespace content {
13 H264DPB::H264DPB() : max_num_pics_(0) {}
14 H264DPB::~H264DPB() {}
16 void H264DPB::Clear() {
17 pics_.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) {
30 pics_.erase(it);
31 return;
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)
40 it = pics_.erase(it);
41 else
42 ++it;
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";
50 pics_.push_back(pic);
53 int H264DPB::CountRefPics() {
54 int ret = 0;
55 for (size_t i = 0; i < pics_.size(); ++i) {
56 if (pics_[i]->ref)
57 ++ret;
59 return ret;
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)
71 return pic;
74 DVLOG(1) << "Missing short ref pic num: " << pic_num;
75 return NULL;
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)
82 return pic;
85 DVLOG(1) << "Missing long term pic num: " << pic_num;
86 return NULL;
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))
95 ret = pic;
97 return ret;
100 void H264DPB::GetNotOutputtedPicsAppending(H264Picture::PtrVector& out) {
101 for (size_t i = 0; i < pics_.size(); ++i) {
102 H264Picture* pic = pics_[i];
103 if (!pic->outputted)
104 out.push_back(pic);
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)
112 out.push_back(pic);
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)
120 out.push_back(pic);
124 } // namespace content