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