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 namespace content { | |
13 | |
14 H264DPB::H264DPB() {} | |
15 | |
16 H264DPB::~H264DPB() { | |
17 Clear(); | |
18 } | |
19 | |
20 void H264DPB::Clear() { | |
21 STLDeleteElements(&pics_); | |
22 } | |
23 | |
24 void H264DPB::RemovePic(const H264Picture::PtrVector::iterator iter) { | |
25 DVLOG(3) << "Removing pic_num: " << (*iter)->pic_num << " from DPB"; | |
26 delete *iter; | |
27 pics_.erase(iter); | |
28 } | |
29 | |
30 void H264DPB::RemoveByPOC(int poc) { | |
31 for (H264Picture::PtrVector::iterator it = pics_.begin(); it != pics_.end(); | |
32 ++it) { | |
33 if ((*it)->pic_order_cnt == poc) { | |
34 RemovePic(it); | |
35 return; | |
36 } | |
37 } | |
38 DVLOG(1) << "Missing POC: " << poc; | |
Ami GONE FROM CHROMIUM
2012/04/09 02:41:47
Is this not a DCHECK-able offense?
Pawel Osciak
2012/05/03 16:22:07
Yeah, I'm reconsidering error resilience especiall
| |
39 } | |
40 | |
41 void H264DPB::RemoveUnused() { | |
42 for (H264Picture::PtrVector::iterator it = pics_.begin(); it != pics_.end(); | |
43 ++it) { | |
44 if ((*it)->outputted && !(*it)->ref) | |
45 RemovePic(it); | |
Ami GONE FROM CHROMIUM
2012/04/09 02:41:47
Isn't this a bug (erase inside RemovePic invalidat
Pawel Osciak
2012/05/03 16:22:07
Of course. I always forget.
| |
46 } | |
47 } | |
48 | |
49 void H264DPB::StorePic(H264Picture* pic) { | |
50 DCHECK_LT(pics_.size(), kDPBMaxSize); | |
51 DVLOG(3) << "Adding PicNum: " << pic->pic_num << " ref: " << (int)pic->ref | |
52 << " longterm: " << (int)pic->long_term << " to DPB"; | |
53 pics_.push_back(pic); | |
54 } | |
55 | |
56 int H264DPB::CountRefPics() { | |
57 int ret = 0; | |
58 for (size_t i = 0; i < pics_.size(); ++i) { | |
59 if (pics_[i]->ref) | |
60 ++ret; | |
61 } | |
62 return ret; | |
63 } | |
64 | |
65 void H264DPB::MarkAllUnusedForRef() { | |
66 for (size_t i = 0; i < pics_.size(); ++i) | |
67 pics_[i]->ref = false; | |
68 } | |
69 | |
70 H264Picture* H264DPB::GetShortRefPicByPicNum(int pic_num) { | |
71 for (size_t i = 0; i < pics_.size(); ++i) { | |
72 H264Picture* pic = pics_[i]; | |
73 if (pic->ref && !pic->long_term && pic->pic_num == pic_num) | |
74 return pic; | |
75 } | |
76 | |
77 DVLOG(1) << "Missing short ref pic num: " << pic_num; | |
Ami GONE FROM CHROMIUM
2012/04/09 02:41:47
Here and elsewhere aren't these properties of a ma
Pawel Osciak
2012/05/03 16:22:07
My intention was to die gracefully with a stream e
| |
78 return NULL; | |
79 } | |
80 | |
81 H264Picture* H264DPB::GetLongRefPicByLongTermPicNum(int pic_num) { | |
82 for (size_t i = 0; i < pics_.size(); ++i) { | |
83 H264Picture* pic = pics_[i]; | |
84 if (pic->ref && pic->long_term && pic->long_term_pic_num == pic_num) | |
85 return pic; | |
86 } | |
87 | |
88 DVLOG(1) << "Missing long term pic num: " << pic_num; | |
89 return NULL; | |
90 } | |
91 | |
92 H264Picture* H264DPB::GetLowestFrameNumWrapShortRefPic() { | |
93 H264Picture* ret = NULL; | |
Ami GONE FROM CHROMIUM
2012/04/09 02:41:47
A trick to avoid the need for the !ret (and an ext
Pawel Osciak
2012/05/03 16:22:07
Yeah, that's basically the case, but feel more com
| |
94 for (size_t i = 0; i < pics_.size(); ++i) { | |
95 H264Picture* pic = pics_[i]; | |
96 if (pic->ref && !pic->long_term && | |
97 (!ret || pic->frame_num_wrap < ret->frame_num_wrap)) | |
98 ret = pic; | |
99 } | |
100 return ret; | |
101 } | |
102 | |
103 struct IsH264PictureOutputted { | |
104 bool operator()(H264Picture*& pic) { | |
105 return pic->outputted; | |
106 } | |
107 }; | |
108 | |
109 void H264DPB::GetNotOutputtedPicsAppending(H264Picture::PtrVector& out) { | |
110 // Append to ret all not outputted pictures. | |
111 std::remove_copy_if(pics_.begin(), pics_.end(), std::back_inserter(out), | |
112 IsH264PictureOutputted()); | |
Ami GONE FROM CHROMIUM
2012/04/09 02:41:47
Why algorithms instead of a loop?
(here and below)
Pawel Osciak
2012/05/03 16:22:07
You really hate stl, don't you? ;)
Done, even with
Ami GONE FROM CHROMIUM
2012/05/03 23:22:53
Hey, it's not just me - your editor (and future re
| |
113 } | |
114 | |
115 struct IsH264PictureShortTermRef | |
116 : public std::unary_function<H264Picture*, bool> { | |
117 bool operator()(const H264Picture* pic) const { | |
118 return (pic->ref && !pic->long_term); | |
119 } | |
120 }; | |
121 | |
122 void H264DPB::GetShortTermRefPicsAppending(H264Picture::PtrVector& out) { | |
123 // copy_if in terms of remove_copy_if. | |
124 std::remove_copy_if(pics_.begin(), pics_.end(), std::back_inserter(out), | |
125 std::not1(IsH264PictureShortTermRef())); | |
126 } | |
127 | |
128 struct IsH264PictureLongTermRef | |
129 : public std::unary_function<H264Picture*, bool> { | |
130 bool operator()(const H264Picture* pic) const { | |
131 return (pic->ref && pic->long_term); | |
132 } | |
133 }; | |
134 | |
135 void H264DPB::GetLongTermRefPicsAppending(H264Picture::PtrVector& out) { | |
136 // copy_if in terms of remove_copy_if. | |
137 std::remove_copy_if(pics_.begin(), pics_.end(), std::back_inserter(out), | |
138 std::not1(IsH264PictureLongTermRef())); | |
139 } | |
140 | |
141 } // namespace content | |
142 | |
OLD | NEW |