OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "content/common/gpu/media/h264_dpb.h" | 9 #include "content/common/gpu/media/h264_dpb.h" |
10 | 10 |
11 namespace content { | 11 namespace content { |
12 | 12 |
| 13 H264PictureBase::H264PictureBase() { |
| 14 memset(this, 0, sizeof(*this)); |
| 15 } |
| 16 |
| 17 H264Picture::H264Picture() { |
| 18 } |
| 19 |
| 20 H264Picture::~H264Picture() { |
| 21 } |
| 22 |
13 H264DPB::H264DPB() : max_num_pics_(0) {} | 23 H264DPB::H264DPB() : max_num_pics_(0) {} |
14 H264DPB::~H264DPB() {} | 24 H264DPB::~H264DPB() {} |
15 | 25 |
16 void H264DPB::Clear() { | 26 void H264DPB::Clear() { |
17 pics_.clear(); | 27 pics_.clear(); |
18 } | 28 } |
19 | 29 |
20 void H264DPB::set_max_num_pics(size_t max_num_pics) { | 30 void H264DPB::set_max_num_pics(size_t max_num_pics) { |
21 DCHECK_LE(max_num_pics, kDPBMaxSize); | 31 DCHECK_LE(max_num_pics, kDPBMaxSize); |
22 max_num_pics_ = max_num_pics; | 32 max_num_pics_ = max_num_pics; |
23 if (pics_.size() > max_num_pics_) | 33 if (pics_.size() > max_num_pics_) |
24 pics_.resize(max_num_pics_); | 34 pics_.resize(max_num_pics_); |
25 } | 35 } |
26 | 36 |
| 37 void H264DPB::UpdatePicPositions() { |
| 38 size_t i = 0; |
| 39 for (auto& pic : pics_) { |
| 40 pic->dpb_position = i; |
| 41 ++i; |
| 42 } |
| 43 } |
| 44 |
27 void H264DPB::DeleteByPOC(int poc) { | 45 void H264DPB::DeleteByPOC(int poc) { |
28 for (Pictures::iterator it = pics_.begin(); it != pics_.end(); ++it) { | 46 for (H264Picture::Vector::iterator it = pics_.begin(); |
| 47 it != pics_.end(); ++it) { |
29 if ((*it)->pic_order_cnt == poc) { | 48 if ((*it)->pic_order_cnt == poc) { |
30 pics_.erase(it); | 49 pics_.erase(it); |
| 50 UpdatePicPositions(); |
31 return; | 51 return; |
32 } | 52 } |
33 } | 53 } |
34 NOTREACHED() << "Missing POC: " << poc; | 54 NOTREACHED() << "Missing POC: " << poc; |
35 } | 55 } |
36 | 56 |
37 void H264DPB::DeleteUnused() { | 57 void H264DPB::DeleteUnused() { |
38 for (Pictures::iterator it = pics_.begin(); it != pics_.end(); ) { | 58 for (H264Picture::Vector::iterator it = pics_.begin(); it != pics_.end(); ) { |
39 if ((*it)->outputted && !(*it)->ref) | 59 if ((*it)->outputted && !(*it)->ref) |
40 it = pics_.erase(it); | 60 it = pics_.erase(it); |
41 else | 61 else |
42 ++it; | 62 ++it; |
43 } | 63 } |
| 64 UpdatePicPositions(); |
44 } | 65 } |
45 | 66 |
46 void H264DPB::StorePic(H264Picture* pic) { | 67 void H264DPB::StorePic(const scoped_refptr<H264Picture>& pic) { |
47 DCHECK_LT(pics_.size(), max_num_pics_); | 68 DCHECK_LT(pics_.size(), max_num_pics_); |
48 DVLOG(3) << "Adding PicNum: " << pic->pic_num << " ref: " << (int)pic->ref | 69 DVLOG(3) << "Adding PicNum: " << pic->pic_num << " ref: " << (int)pic->ref |
49 << " longterm: " << (int)pic->long_term << " to DPB"; | 70 << " longterm: " << (int)pic->long_term << " to DPB"; |
| 71 pic->dpb_position = pics_.size(); |
50 pics_.push_back(pic); | 72 pics_.push_back(pic); |
51 } | 73 } |
52 | 74 |
53 int H264DPB::CountRefPics() { | 75 int H264DPB::CountRefPics() { |
54 int ret = 0; | 76 int ret = 0; |
55 for (size_t i = 0; i < pics_.size(); ++i) { | 77 for (size_t i = 0; i < pics_.size(); ++i) { |
56 if (pics_[i]->ref) | 78 if (pics_[i]->ref) |
57 ++ret; | 79 ++ret; |
58 } | 80 } |
59 return ret; | 81 return ret; |
60 } | 82 } |
61 | 83 |
62 void H264DPB::MarkAllUnusedForRef() { | 84 void H264DPB::MarkAllUnusedForRef() { |
63 for (size_t i = 0; i < pics_.size(); ++i) | 85 for (size_t i = 0; i < pics_.size(); ++i) |
64 pics_[i]->ref = false; | 86 pics_[i]->ref = false; |
65 } | 87 } |
66 | 88 |
67 H264Picture* H264DPB::GetShortRefPicByPicNum(int pic_num) { | 89 scoped_refptr<H264Picture> H264DPB::GetShortRefPicByPicNum(int pic_num) { |
68 for (size_t i = 0; i < pics_.size(); ++i) { | 90 for (const auto& pic : pics_) { |
69 H264Picture* pic = pics_[i]; | |
70 if (pic->ref && !pic->long_term && pic->pic_num == pic_num) | 91 if (pic->ref && !pic->long_term && pic->pic_num == pic_num) |
71 return pic; | 92 return pic; |
72 } | 93 } |
73 | 94 |
74 DVLOG(1) << "Missing short ref pic num: " << pic_num; | 95 DVLOG(1) << "Missing short ref pic num: " << pic_num; |
75 return NULL; | 96 return nullptr; |
76 } | 97 } |
77 | 98 |
78 H264Picture* H264DPB::GetLongRefPicByLongTermPicNum(int pic_num) { | 99 scoped_refptr<H264Picture> H264DPB::GetLongRefPicByLongTermPicNum(int pic_num) { |
79 for (size_t i = 0; i < pics_.size(); ++i) { | 100 for (const auto& pic : pics_) { |
80 H264Picture* pic = pics_[i]; | |
81 if (pic->ref && pic->long_term && pic->long_term_pic_num == pic_num) | 101 if (pic->ref && pic->long_term && pic->long_term_pic_num == pic_num) |
82 return pic; | 102 return pic; |
83 } | 103 } |
84 | 104 |
85 DVLOG(1) << "Missing long term pic num: " << pic_num; | 105 DVLOG(1) << "Missing long term pic num: " << pic_num; |
86 return NULL; | 106 return nullptr; |
87 } | 107 } |
88 | 108 |
89 H264Picture* H264DPB::GetLowestFrameNumWrapShortRefPic() { | 109 scoped_refptr<H264Picture> H264DPB::GetLowestFrameNumWrapShortRefPic() { |
90 H264Picture* ret = NULL; | 110 scoped_refptr<H264Picture> ret; |
91 for (size_t i = 0; i < pics_.size(); ++i) { | 111 for (const auto& pic : pics_) { |
92 H264Picture* pic = pics_[i]; | |
93 if (pic->ref && !pic->long_term && | 112 if (pic->ref && !pic->long_term && |
94 (!ret || pic->frame_num_wrap < ret->frame_num_wrap)) | 113 (!ret || pic->frame_num_wrap < ret->frame_num_wrap)) |
95 ret = pic; | 114 ret = pic; |
96 } | 115 } |
97 return ret; | 116 return ret; |
98 } | 117 } |
99 | 118 |
100 void H264DPB::GetNotOutputtedPicsAppending(H264Picture::PtrVector& out) { | 119 void H264DPB::GetNotOutputtedPicsAppending(H264Picture::Vector* out) { |
101 for (size_t i = 0; i < pics_.size(); ++i) { | 120 for (const auto& pic : pics_) { |
102 H264Picture* pic = pics_[i]; | |
103 if (!pic->outputted) | 121 if (!pic->outputted) |
104 out.push_back(pic); | 122 out->push_back(pic); |
105 } | 123 } |
106 } | 124 } |
107 | 125 |
108 void H264DPB::GetShortTermRefPicsAppending(H264Picture::PtrVector& out) { | 126 void H264DPB::GetShortTermRefPicsAppending(H264Picture::Vector* out) { |
109 for (size_t i = 0; i < pics_.size(); ++i) { | 127 for (const auto& pic : pics_) { |
110 H264Picture* pic = pics_[i]; | |
111 if (pic->ref && !pic->long_term) | 128 if (pic->ref && !pic->long_term) |
112 out.push_back(pic); | 129 out->push_back(pic); |
113 } | 130 } |
114 } | 131 } |
115 | 132 |
116 void H264DPB::GetLongTermRefPicsAppending(H264Picture::PtrVector& out) { | 133 void H264DPB::GetLongTermRefPicsAppending(H264Picture::Vector* out) { |
117 for (size_t i = 0; i < pics_.size(); ++i) { | 134 for (const auto& pic : pics_) { |
118 H264Picture* pic = pics_[i]; | |
119 if (pic->ref && pic->long_term) | 135 if (pic->ref && pic->long_term) |
120 out.push_back(pic); | 136 out->push_back(pic); |
121 } | 137 } |
122 } | 138 } |
123 | 139 |
124 } // namespace content | 140 } // namespace content |
OLD | NEW |