• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include <algorithm>
6 
7 #include "base/logging.h"
8 #include "base/stl_util.h"
9 #include "content/common/gpu/media/h264_dpb.h"
10 
11 namespace content {
12 
H264DPB()13 H264DPB::H264DPB() : max_num_pics_(0) {}
~H264DPB()14 H264DPB::~H264DPB() {}
15 
Clear()16 void H264DPB::Clear() {
17   pics_.clear();
18 }
19 
set_max_num_pics(size_t max_num_pics)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_);
25 }
26 
DeleteByPOC(int poc)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;
32     }
33   }
34   NOTREACHED() << "Missing POC: " << poc;
35 }
36 
DeleteUnused()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;
43   }
44 }
45 
StorePic(H264Picture * pic)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);
51 }
52 
CountRefPics()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;
58   }
59   return ret;
60 }
61 
MarkAllUnusedForRef()62 void H264DPB::MarkAllUnusedForRef() {
63   for (size_t i = 0; i < pics_.size(); ++i)
64     pics_[i]->ref = false;
65 }
66 
GetShortRefPicByPicNum(int pic_num)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;
72   }
73 
74   DVLOG(1) << "Missing short ref pic num: " << pic_num;
75   return NULL;
76 }
77 
GetLongRefPicByLongTermPicNum(int 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)
82       return pic;
83   }
84 
85   DVLOG(1) << "Missing long term pic num: " << pic_num;
86   return NULL;
87 }
88 
GetLowestFrameNumWrapShortRefPic()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;
96   }
97   return ret;
98 }
99 
GetNotOutputtedPicsAppending(H264Picture::PtrVector & out)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);
105   }
106 }
107 
GetShortTermRefPicsAppending(H264Picture::PtrVector & out)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);
113   }
114 }
115 
GetLongTermRefPicsAppending(H264Picture::PtrVector & out)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);
121   }
122 }
123 
124 }  // namespace content
125