Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/tmmbr_help.cc

Issue 2234783002: Cleaned out candidateSet member from TMMBRHelp class (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 uint32_t ssrcSet) { 45 uint32_t ssrcSet) {
46 RTC_DCHECK_LT(size(), capacity()); 46 RTC_DCHECK_LT(size(), capacity());
47 SetEntry(size(), tmmbrSet, packetOHSet, ssrcSet); 47 SetEntry(size(), tmmbrSet, packetOHSet, ssrcSet);
48 } 48 }
49 49
50 void TMMBRSet::RemoveEntry(uint32_t sourceIdx) { 50 void TMMBRSet::RemoveEntry(uint32_t sourceIdx) {
51 RTC_DCHECK_LT(sourceIdx, size()); 51 RTC_DCHECK_LT(sourceIdx, size());
52 erase(begin() + sourceIdx); 52 erase(begin() + sourceIdx);
53 } 53 }
54 54
55 TMMBRSet* TMMBRHelp::VerifyAndAllocateCandidateSet(uint32_t minimumSize) { 55 std::vector<rtcp::TmmbItem> TMMBRHelp::FindBoundingSet(
56 _candidateSet.VerifyAndAllocateSet(minimumSize); 56 std::vector<rtcp::TmmbItem> candidates) {
57 return &_candidateSet; 57 // Filter out candidates with 0 bitrate.
58 } 58 for (auto it = candidates.begin(); it != candidates.end();) {
59 59 if (!it->bitrate_bps())
60 TMMBRSet* TMMBRHelp::CandidateSet() { 60 it = candidates.erase(it);
61 return &_candidateSet; 61 else
62 } 62 ++it;
63
64 std::vector<rtcp::TmmbItem> TMMBRHelp::FindTMMBRBoundingSet() {
65 // Work on local variable, will be modified
66 TMMBRSet candidateSet;
67 candidateSet.VerifyAndAllocateSet(_candidateSet.capacity());
68
69 for (size_t i = 0; i < _candidateSet.size(); i++) {
70 if (_candidateSet.Tmmbr(i)) {
71 candidateSet.AddEntry(_candidateSet.Tmmbr(i), _candidateSet.PacketOH(i),
72 _candidateSet.Ssrc(i));
73 } else {
74 // make sure this is zero if tmmbr = 0
75 RTC_DCHECK_EQ(_candidateSet.PacketOH(i), 0u);
danilchap 2016/08/10 11:18:48 this DCHECK removed because it validates input. Ni
76 // Old code:
77 // _candidateSet.ptrPacketOHSet[i] = 0;
78 }
79 } 63 }
80 64
81 // Number of set candidates 65 if (candidates.size() <= 1)
82 int32_t numSetCandidates = candidateSet.lengthOfSet(); 66 return candidates;
83 // Find bounding set
84 std::vector<rtcp::TmmbItem> bounding;
85 if (numSetCandidates > 0) {
86 FindBoundingSet(std::move(candidateSet), &bounding);
87 size_t numBoundingSet = bounding.size();
88 RTC_DCHECK_GE(numBoundingSet, 1u);
89 RTC_DCHECK_LE(numBoundingSet, _candidateSet.size());
90 }
91 return bounding;
92 }
93 67
94 void TMMBRHelp::FindBoundingSet(std::vector<rtcp::TmmbItem> candidates,
95 std::vector<rtcp::TmmbItem>* bounding_set) {
96 RTC_DCHECK(bounding_set);
97 RTC_DCHECK(!candidates.empty());
98 size_t num_candidates = candidates.size(); 68 size_t num_candidates = candidates.size();
99 69
100 if (num_candidates == 1) {
101 RTC_DCHECK(candidates[0].bitrate_bps());
102 *bounding_set = std::move(candidates);
103 return;
104 }
105
106 // 1. Sort by increasing packet overhead. 70 // 1. Sort by increasing packet overhead.
107 std::sort(candidates.begin(), candidates.end(), 71 std::sort(candidates.begin(), candidates.end(),
108 [](const rtcp::TmmbItem& lhs, const rtcp::TmmbItem& rhs) { 72 [](const rtcp::TmmbItem& lhs, const rtcp::TmmbItem& rhs) {
109 return lhs.packet_overhead() < rhs.packet_overhead(); 73 return lhs.packet_overhead() < rhs.packet_overhead();
110 }); 74 });
111 75
112 // 2. For tuples with same overhead, keep the one with the lowest bitrate. 76 // 2. For tuples with same overhead, keep the one with the lowest bitrate.
113 for (auto it = candidates.begin(); it != candidates.end();) { 77 for (auto it = candidates.begin(); it != candidates.end();) {
114 RTC_DCHECK(it->bitrate_bps()); 78 RTC_DCHECK(it->bitrate_bps());
115 auto current_min = it; 79 auto current_min = it;
116 auto next_it = it + 1; 80 auto next_it = it + 1;
117 // Use fact candidates are sorted by overhead, so candidates with same 81 // Use fact candidates are sorted by overhead, so candidates with same
118 // overhead are adjusted. 82 // overhead are adjusted.
119 while (next_it != candidates.end() && 83 while (next_it != candidates.end() &&
120 next_it->packet_overhead() == current_min->packet_overhead()) { 84 next_it->packet_overhead() == current_min->packet_overhead()) {
121 if (next_it->bitrate_bps() < current_min->bitrate_bps()) { 85 if (next_it->bitrate_bps() < current_min->bitrate_bps()) {
122 current_min->set_bitrate_bps(0); 86 current_min->set_bitrate_bps(0);
123 current_min = next_it; 87 current_min = next_it;
124 } else { 88 } else {
125 next_it->set_bitrate_bps(0); 89 next_it->set_bitrate_bps(0);
126 } 90 }
127 ++next_it; 91 ++next_it;
128 --num_candidates; 92 --num_candidates;
129 } 93 }
130 it = next_it; 94 it = next_it;
131 } 95 }
132 96
133 // 3. Select and remove tuple with lowest tmmbr. 97 // 3. Select and remove tuple with lowest bitrate.
134 // (If more than 1, choose the one with highest overhead). 98 // (If more than 1, choose the one with highest overhead).
135 auto min_bitrate_it = candidates.end(); 99 auto min_bitrate_it = candidates.end();
136 for (auto it = candidates.begin(); it != candidates.end(); ++it) { 100 for (auto it = candidates.begin(); it != candidates.end(); ++it) {
137 if (it->bitrate_bps()) { 101 if (it->bitrate_bps()) {
138 min_bitrate_it = it; 102 min_bitrate_it = it;
139 break; 103 break;
140 } 104 }
141 } 105 }
142 106
143 for (auto it = min_bitrate_it; it != candidates.end(); ++it) { 107 for (auto it = min_bitrate_it; it != candidates.end(); ++it) {
144 if (it->bitrate_bps() && 108 if (it->bitrate_bps() &&
145 it->bitrate_bps() <= min_bitrate_it->bitrate_bps()) { 109 it->bitrate_bps() <= min_bitrate_it->bitrate_bps()) {
146 // Get min bitrate. 110 // Get min bitrate.
147 min_bitrate_it = it; 111 min_bitrate_it = it;
148 } 112 }
149 } 113 }
150 114
151 bounding_set->clear(); 115 std::vector<rtcp::TmmbItem> bounding_set;
152 bounding_set->reserve(num_candidates); 116 bounding_set.reserve(num_candidates);
153 std::vector<float> intersection(num_candidates); 117 std::vector<float> intersection(num_candidates);
154 std::vector<float> max_packet_rate(num_candidates); 118 std::vector<float> max_packet_rate(num_candidates);
155 119
156 // First member of selected list. 120 // First member of selected list.
157 bounding_set->push_back(*min_bitrate_it); 121 bounding_set.push_back(*min_bitrate_it);
158 intersection[0] = 0; 122 intersection[0] = 0;
159 // Calculate its maximum packet rate (where its line crosses x-axis). 123 // Calculate its maximum packet rate (where its line crosses x-axis).
160 uint16_t packet_overhead = bounding_set->back().packet_overhead(); 124 uint16_t packet_overhead = bounding_set.back().packet_overhead();
161 if (packet_overhead == 0) { 125 if (packet_overhead == 0) {
162 // Avoid division by zero. 126 // Avoid division by zero.
163 max_packet_rate[0] = std::numeric_limits<float>::max(); 127 max_packet_rate[0] = std::numeric_limits<float>::max();
164 } else { 128 } else {
165 max_packet_rate[0] = bounding_set->back().bitrate_bps() / 129 max_packet_rate[0] =
166 static_cast<float>(packet_overhead); 130 bounding_set.back().bitrate_bps() / static_cast<float>(packet_overhead);
167 } 131 }
168 // Remove from candidate list. 132 // Remove from candidate list.
169 min_bitrate_it->set_bitrate_bps(0); 133 min_bitrate_it->set_bitrate_bps(0);
170 --num_candidates; 134 --num_candidates;
171 135
172 // 4. Discard from candidate list all tuple with lower overhead 136 // 4. Discard from candidate list all tuple with lower overhead
173 // (next tuple must be steeper). 137 // (next tuple must be steeper).
174 for (auto it = candidates.begin(); it != candidates.end(); ++it) { 138 for (auto it = candidates.begin(); it != candidates.end(); ++it) {
175 if (it->bitrate_bps() && 139 if (it->bitrate_bps() &&
176 it->packet_overhead() < bounding_set->front().packet_overhead()) { 140 it->packet_overhead() < bounding_set.front().packet_overhead()) {
177 it->set_bitrate_bps(0); 141 it->set_bitrate_bps(0);
178 --num_candidates; 142 --num_candidates;
179 } 143 }
180 } 144 }
181 145
182 bool get_new_candidate = true; 146 bool get_new_candidate = true;
183 rtcp::TmmbItem cur_candidate; 147 rtcp::TmmbItem cur_candidate;
184 while (num_candidates > 0) { 148 while (num_candidates > 0) {
185 if (get_new_candidate) { 149 if (get_new_candidate) {
186 // 5. Remove first remaining tuple from candidate list. 150 // 5. Remove first remaining tuple from candidate list.
187 for (auto it = candidates.begin(); it != candidates.end(); ++it) { 151 for (auto it = candidates.begin(); it != candidates.end(); ++it) {
188 if (it->bitrate_bps()) { 152 if (it->bitrate_bps()) {
189 cur_candidate = *it; 153 cur_candidate = *it;
190 it->set_bitrate_bps(0); 154 it->set_bitrate_bps(0);
191 break; 155 break;
192 } 156 }
193 } 157 }
194 } 158 }
195 159
196 // 6. Calculate packet rate and intersection of the current 160 // 6. Calculate packet rate and intersection of the current
197 // line with line of last tuple in selected list. 161 // line with line of last tuple in selected list.
198 RTC_DCHECK_NE(cur_candidate.packet_overhead(), 162 RTC_DCHECK_NE(cur_candidate.packet_overhead(),
199 bounding_set->back().packet_overhead()); 163 bounding_set.back().packet_overhead());
200 float packet_rate = static_cast<float>(cur_candidate.bitrate_bps() - 164 float packet_rate = static_cast<float>(cur_candidate.bitrate_bps() -
201 bounding_set->back().bitrate_bps()) / 165 bounding_set.back().bitrate_bps()) /
202 (cur_candidate.packet_overhead() - 166 (cur_candidate.packet_overhead() -
203 bounding_set->back().packet_overhead()); 167 bounding_set.back().packet_overhead());
204 168
205 // 7. If the packet rate is equal or lower than intersection of 169 // 7. If the packet rate is equal or lower than intersection of
206 // last tuple in selected list, 170 // last tuple in selected list,
207 // remove last tuple in selected list & go back to step 6. 171 // remove last tuple in selected list & go back to step 6.
208 if (packet_rate <= intersection[bounding_set->size() - 1]) { 172 if (packet_rate <= intersection[bounding_set.size() - 1]) {
209 // Remove last tuple and goto step 6. 173 // Remove last tuple and goto step 6.
210 bounding_set->pop_back(); 174 bounding_set.pop_back();
211 get_new_candidate = false; 175 get_new_candidate = false;
212 } else { 176 } else {
213 // 8. If packet rate is lower than maximum packet rate of 177 // 8. If packet rate is lower than maximum packet rate of
214 // last tuple in selected list, add current tuple to selected 178 // last tuple in selected list, add current tuple to selected
215 // list. 179 // list.
216 if (packet_rate < max_packet_rate[bounding_set->size() - 1]) { 180 if (packet_rate < max_packet_rate[bounding_set.size() - 1]) {
217 bounding_set->push_back(cur_candidate); 181 bounding_set.push_back(cur_candidate);
218 intersection[bounding_set->size() - 1] = packet_rate; 182 intersection[bounding_set.size() - 1] = packet_rate;
219 uint16_t packet_overhead = bounding_set->back().packet_overhead(); 183 uint16_t packet_overhead = bounding_set.back().packet_overhead();
220 RTC_DCHECK_NE(packet_overhead, 0); 184 RTC_DCHECK_NE(packet_overhead, 0);
221 max_packet_rate[bounding_set->size() - 1] = 185 max_packet_rate[bounding_set.size() - 1] =
222 bounding_set->back().bitrate_bps() / 186 bounding_set.back().bitrate_bps() /
223 static_cast<float>(packet_overhead); 187 static_cast<float>(packet_overhead);
224 } 188 }
225 --num_candidates; 189 --num_candidates;
226 get_new_candidate = true; 190 get_new_candidate = true;
227 } 191 }
228 192
229 // 9. Go back to step 5 if any tuple remains in candidate list. 193 // 9. Go back to step 5 if any tuple remains in candidate list.
230 } 194 }
195 RTC_DCHECK(!bounding_set.empty());
196 return bounding_set;
231 } 197 }
232 198
233 bool TMMBRHelp::IsOwner(const std::vector<rtcp::TmmbItem>& bounding, 199 bool TMMBRHelp::IsOwner(const std::vector<rtcp::TmmbItem>& bounding,
234 uint32_t ssrc) { 200 uint32_t ssrc) {
235 for (const rtcp::TmmbItem& item : bounding) { 201 for (const rtcp::TmmbItem& item : bounding) {
236 if (item.ssrc() == ssrc) { 202 if (item.ssrc() == ssrc) {
237 return true; 203 return true;
238 } 204 }
239 } 205 }
240 return false; 206 return false;
241 } 207 }
242 208
243 bool TMMBRHelp::CalcMinBitRate(uint32_t* minBitrateKbit) const { 209 uint64_t TMMBRHelp::CalcMinBitrateBps(
244 if (_candidateSet.size() == 0) { 210 const std::vector<rtcp::TmmbItem>& candidates) {
245 // Empty bounding set. 211 RTC_DCHECK(!candidates.empty());
246 return false; 212 uint64_t min_bitrate_bps = std::numeric_limits<uint64_t>::max();
213 for (const rtcp::TmmbItem& item : candidates) {
214 uint64_t current_bitrate = item.bitrate_bps();
215 if (current_bitrate < MIN_VIDEO_BW_MANAGEMENT_BITRATE * 1000)
216 current_bitrate = MIN_VIDEO_BW_MANAGEMENT_BITRATE * 1000;
217
218 if (current_bitrate < min_bitrate_bps)
219 min_bitrate_bps = current_bitrate;
247 } 220 }
248 *minBitrateKbit = std::numeric_limits<uint32_t>::max(); 221 return min_bitrate_bps;
249
250 for (size_t i = 0; i < _candidateSet.lengthOfSet(); ++i) {
251 uint32_t curNetBitRateKbit = _candidateSet.Tmmbr(i);
252 if (curNetBitRateKbit < MIN_VIDEO_BW_MANAGEMENT_BITRATE) {
253 curNetBitRateKbit = MIN_VIDEO_BW_MANAGEMENT_BITRATE;
254 }
255 *minBitrateKbit = curNetBitRateKbit < *minBitrateKbit ? curNetBitRateKbit
256 : *minBitrateKbit;
257 }
258 return true;
259 } 222 }
260 } // namespace webrtc 223 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698