OLD | NEW |
---|---|
(Empty) | |
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 "h264_dpb.h" | |
6 | |
7 #include <algorithm> | |
8 | |
9 #include "base/logging.h" | |
10 #include "base/stl_util.h" | |
11 | |
12 struct PicByPOC : public std::binary_function<H264Picture*, int, bool> { | |
13 bool operator()(const H264Picture* pic, const int& pic_num) const { | |
14 return pic->PicOrderCnt == pic_num; | |
15 } | |
16 }; | |
17 | |
18 struct ShortRefPicByPicNum | |
19 : public std::binary_function<H264Picture*, int, bool> { | |
20 bool operator()(const H264Picture* pic, const int& pic_num) const { | |
21 return (pic->ref && | |
22 !pic->long_term && | |
23 pic->PicNum == pic_num); | |
24 } | |
25 }; | |
26 | |
27 struct LongRefPicByLongTermPicNum | |
28 : public std::binary_function<H264Picture*, int, bool> { | |
29 bool operator()(const H264Picture* pic, const int& pic_num) const { | |
30 return (pic->ref && | |
31 pic->long_term && | |
32 pic->LongTermPicNum == pic_num); | |
33 } | |
34 }; | |
35 | |
36 struct IsH264ShortTermRefPic : public std::unary_function<H264Picture*, bool> { | |
37 bool operator()(const H264Picture* pic) const { | |
38 return (pic->ref && !pic->long_term); | |
39 } | |
40 }; | |
41 | |
42 H264DPB::H264DPB() {} | |
43 | |
44 H264DPB::~H264DPB() { | |
45 Clear(); | |
46 } | |
47 | |
48 void H264DPB::Clear() { | |
49 STLDeleteElements(&pics_); | |
50 } | |
51 | |
52 void H264DPB::RemovePic(const PicsVector::iterator iter) { | |
53 DVLOG(3) << "Removing picnum: " << (*iter)->PicNum << " from DPB"; | |
54 delete *iter; | |
55 pics_.erase(iter); | |
56 } | |
57 | |
58 void H264DPB::RemoveByPOC(int poc) { | |
59 PicsVector::iterator iter = std::find_if(pics_.begin(), pics_.end(), | |
Ami GONE FROM CHROMIUM
2012/03/21 13:16:24
I don't think using the STL algorithm business is
Pawel Osciak
2012/04/05 10:37:20
Done.
| |
60 std::bind2nd(PicByPOC(), poc)); | |
61 DCHECK(iter != pics_.end()); | |
62 RemovePic(iter); | |
63 } | |
64 | |
65 void H264DPB::RemoveUnused() { | |
66 PicsVector::iterator iter = pics_.begin(); | |
Ami GONE FROM CHROMIUM
2012/03/21 13:16:24
Ditto replace functional style w/ explicit:
for (P
Pawel Osciak
2012/04/05 10:37:20
Done.
| |
67 | |
68 while (1) { | |
69 // TODO posciak: for_each? | |
70 iter = std::find_if(iter, pics_.end(), H264Picture::IsUnused()); | |
71 if (iter == pics_.end()) | |
72 break; | |
73 RemovePic(iter); | |
74 } | |
75 } | |
76 | |
77 void H264DPB::StorePic(H264Picture* pic) { | |
78 DCHECK_LT(pics_.size(), kDPBMaxSize); | |
79 DVLOG(3) << "Adding picnum: " << pic->PicNum << " ref: " << (int)pic->ref | |
80 << " longterm: " << (int)pic->long_term << " to DPB"; | |
81 pics_.push_back(pic); | |
82 } | |
83 | |
84 int H264DPB::CountRefPics() { | |
85 return std::count_if(pics_.begin(), pics_.end(), H264Picture::IsReference()); | |
86 } | |
87 | |
88 struct MarkPicUnusedForRef { | |
89 void operator()(H264Picture*& pic) { | |
90 pic->ref = false; | |
91 } | |
92 }; | |
93 | |
94 void H264DPB::MarkAllUnusedForRef() { | |
95 std::for_each(pics_.begin(), pics_.end(), MarkPicUnusedForRef()); | |
96 } | |
97 | |
98 H264Picture* H264DPB::GetRefPicByPicNum(int pic_num, bool long_term) { | |
Ami GONE FROM CHROMIUM
2012/03/21 13:16:24
I suspect you'll want to simply drop this function
Pawel Osciak
2012/04/05 10:37:20
Done.
| |
99 PicsVector::iterator iter; | |
100 | |
101 if (long_term) | |
102 iter = std::find_if(pics_.begin(), pics_.end(), | |
103 std::bind2nd(LongRefPicByLongTermPicNum(), pic_num)); | |
104 else | |
105 iter = std::find_if(pics_.begin(), pics_.end(), | |
106 std::bind2nd(ShortRefPicByPicNum(), pic_num)); | |
107 | |
108 if (iter == pics_.end()) { | |
109 DLOG(ERROR) << "Requested " << (long_term ? "LongTerm" : "") | |
110 << "PicNum " << pic_num << " not found in DPB"; | |
111 return NULL; | |
112 } else { | |
113 return *iter; | |
114 } | |
115 } | |
116 | |
117 H264Picture* H264DPB::GetShortRefPicByPicNum(int pic_num) { | |
118 return GetRefPicByPicNum(pic_num, false); | |
119 } | |
120 | |
121 H264Picture* H264DPB::GetLongRefPicByLongTermPicNum(int pic_num) { | |
122 return GetRefPicByPicNum(pic_num, true); | |
123 } | |
124 | |
125 H264Picture* H264DPB::GetLowestFrameNumWrapRefPic() { | |
126 PicsVector short_refs; | |
127 | |
128 GetShortTermRefPicsAppending(short_refs); | |
129 if (short_refs.empty()) | |
130 return NULL; | |
131 | |
132 return *(std::min_element(short_refs.begin(), short_refs.end(), | |
Ami GONE FROM CHROMIUM
2012/03/21 13:16:24
Ow, that hurted my brain!
Pawel Osciak
2012/03/21 18:40:35
Blame STL :) Do you see a way to make it simpler?
Ami GONE FROM CHROMIUM
2012/03/22 17:01:36
why not the much simpler
H264Picture* ret = NULL;
Pawel Osciak
2012/04/05 10:37:20
Agreed on copying, although this thing is actually
| |
133 H264Picture::FrameNumWrapAscCompare())); | |
134 } | |
135 | |
136 void H264DPB::GetNotOutputtedPicsSortedByPOCAppending(PicsVector& out) { | |
137 // append to ret all not outputted pictures | |
138 std::remove_copy_if(pics_.begin(), pics_.end(), std::back_inserter(out), | |
139 H264Picture::IsOutputted()); | |
140 // and sort them by ascending POC | |
141 std::sort(out.begin(), out.end(), H264Picture::POCAscCompare()); | |
142 } | |
143 | |
144 void H264DPB::GetShortTermRefPicsAppending(PicsVector& out) { | |
145 // copy_if in terms of remove_copy_if | |
146 std::remove_copy_if(pics_.begin(), pics_.end(), std::back_inserter(out), | |
147 std::not1(IsH264ShortTermRefPic())); | |
148 } | |
149 | |
150 void H264DPB::GetLongTermRefPicsAppending(PicsVector& out) { | |
151 // copy_if in terms of remove_copy_if | |
152 std::remove_copy_if(pics_.begin(), pics_.end(), std::back_inserter(out), | |
153 std::not1(H264Picture::IsLongTermRefPic())); | |
154 } | |
155 | |
OLD | NEW |