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

Side by Side Diff: webrtc/modules/bitrate_controller/bitrate_controller_impl.cc

Issue 2223033002: Fix issue where the number of packets reported in tests/simulations sometimes are negative. (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
« no previous file with comments | « no previous file | webrtc/modules/bitrate_controller/bitrate_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 */
11 11
12 #include "webrtc/modules/bitrate_controller/bitrate_controller_impl.h" 12 #include "webrtc/modules/bitrate_controller/bitrate_controller_impl.h"
13 13
14 #include <algorithm> 14 #include <algorithm>
15 #include <map> 15 #include <map>
16 #include <utility> 16 #include <utility>
17 17
18 #include "webrtc/base/checks.h"
19 #include "webrtc/base/logging.h"
18 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" 20 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
19 21
20 namespace webrtc { 22 namespace webrtc {
21 23
22 class BitrateControllerImpl::RtcpBandwidthObserverImpl 24 class BitrateControllerImpl::RtcpBandwidthObserverImpl
23 : public RtcpBandwidthObserver { 25 : public RtcpBandwidthObserver {
24 public: 26 public:
25 explicit RtcpBandwidthObserverImpl(BitrateControllerImpl* owner) 27 explicit RtcpBandwidthObserverImpl(BitrateControllerImpl* owner)
26 : owner_(owner) { 28 : owner_(owner) {
27 } 29 }
28 virtual ~RtcpBandwidthObserverImpl() { 30 virtual ~RtcpBandwidthObserverImpl() {
29 } 31 }
30 // Received RTCP REMB or TMMBR. 32 // Received RTCP REMB or TMMBR.
31 void OnReceivedEstimatedBitrate(uint32_t bitrate) override { 33 void OnReceivedEstimatedBitrate(uint32_t bitrate) override {
32 owner_->OnReceivedEstimatedBitrate(bitrate); 34 owner_->OnReceivedEstimatedBitrate(bitrate);
33 } 35 }
34 // Received RTCP receiver block. 36 // Received RTCP receiver block.
35 void OnReceivedRtcpReceiverReport(const ReportBlockList& report_blocks, 37 void OnReceivedRtcpReceiverReport(const ReportBlockList& report_blocks,
36 int64_t rtt, 38 int64_t rtt,
37 int64_t now_ms) override { 39 int64_t now_ms) override {
38 if (report_blocks.empty()) 40 if (report_blocks.empty())
39 return; 41 return;
40 42
41 int fraction_lost_aggregate = 0; 43 int fraction_lost_aggregate = 0;
42 int total_number_of_packets = 0; 44 int total_number_of_packets = 0;
43 45
44 // Compute the a weighted average of the fraction loss from all report 46 // Compute the a weighted average of the fraction loss from all report
45 // blocks. 47 // blocks.
46 for (ReportBlockList::const_iterator it = report_blocks.begin(); 48 for (const RTCPReportBlock& report_block : report_blocks) {
47 it != report_blocks.end(); ++it) {
48 std::map<uint32_t, uint32_t>::iterator seq_num_it = 49 std::map<uint32_t, uint32_t>::iterator seq_num_it =
49 ssrc_to_last_received_extended_high_seq_num_.find(it->sourceSSRC); 50 ssrc_to_last_received_extended_high_seq_num_.find(
51 report_block.sourceSSRC);
50 52
51 int number_of_packets = 0; 53 int number_of_packets = 0;
52 if (seq_num_it != ssrc_to_last_received_extended_high_seq_num_.end()) 54 if (seq_num_it != ssrc_to_last_received_extended_high_seq_num_.end()) {
53 number_of_packets = it->extendedHighSeqNum - 55 number_of_packets =
54 seq_num_it->second; 56 report_block.extendedHighSeqNum - seq_num_it->second;
57 }
55 58
56 fraction_lost_aggregate += number_of_packets * it->fractionLost; 59 fraction_lost_aggregate += number_of_packets * report_block.fractionLost;
57 total_number_of_packets += number_of_packets; 60 total_number_of_packets += number_of_packets;
58 61
59 // Update last received for this SSRC. 62 // Update last received for this SSRC.
60 ssrc_to_last_received_extended_high_seq_num_[it->sourceSSRC] = 63 ssrc_to_last_received_extended_high_seq_num_[report_block.sourceSSRC] =
61 it->extendedHighSeqNum; 64 report_block.extendedHighSeqNum;
65 }
66 if (total_number_of_packets < 0) {
terelius 2016/08/09 08:31:07 Can/should this happen, or are we hiding bugs by i
stefan-webrtc 2016/08/09 08:56:03 It can happen since a malicious RTCP sender could
terelius 2016/08/09 11:28:37 Good point. Is/should there be a unit test for thi
stefan-webrtc 2016/08/09 11:32:12 Right. We could add one, but I'm not sure exactly
terelius 2016/08/10 09:45:12 Yes, or possibly check that owner_->OnReceivedRtcp
67 LOG(LS_WARNING) << "Received report block where extended high sequence "
68 "number goes backwards, ignoring.";
69 return;
62 } 70 }
63 if (total_number_of_packets == 0) 71 if (total_number_of_packets == 0)
64 fraction_lost_aggregate = 0; 72 fraction_lost_aggregate = 0;
65 else 73 else
66 fraction_lost_aggregate = (fraction_lost_aggregate + 74 fraction_lost_aggregate = (fraction_lost_aggregate +
67 total_number_of_packets / 2) / total_number_of_packets; 75 total_number_of_packets / 2) / total_number_of_packets;
68 if (fraction_lost_aggregate > 255) 76 if (fraction_lost_aggregate > 255)
69 return; 77 return;
70 78
79 RTC_DCHECK_GE(total_number_of_packets, 0);
80
71 owner_->OnReceivedRtcpReceiverReport(fraction_lost_aggregate, rtt, 81 owner_->OnReceivedRtcpReceiverReport(fraction_lost_aggregate, rtt,
72 total_number_of_packets, now_ms); 82 total_number_of_packets, now_ms);
73 } 83 }
74 84
75 private: 85 private:
76 std::map<uint32_t, uint32_t> ssrc_to_last_received_extended_high_seq_num_; 86 std::map<uint32_t, uint32_t> ssrc_to_last_received_extended_high_seq_num_;
77 BitrateControllerImpl* owner_; 87 BitrateControllerImpl* owner_;
78 }; 88 };
79 89
80 BitrateController* BitrateController::CreateBitrateController( 90 BitrateController* BitrateController::CreateBitrateController(
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 bandwidth_estimation_.CurrentEstimate(&bitrate, &fraction_loss, &rtt); 268 bandwidth_estimation_.CurrentEstimate(&bitrate, &fraction_loss, &rtt);
259 if (bitrate > 0) { 269 if (bitrate > 0) {
260 bitrate = bitrate - std::min<int>(bitrate, reserved_bitrate_bps_); 270 bitrate = bitrate - std::min<int>(bitrate, reserved_bitrate_bps_);
261 bitrate = std::max(bitrate, bandwidth_estimation_.GetMinBitrate()); 271 bitrate = std::max(bitrate, bandwidth_estimation_.GetMinBitrate());
262 *bandwidth = bitrate; 272 *bandwidth = bitrate;
263 return true; 273 return true;
264 } 274 }
265 return false; 275 return false;
266 } 276 }
267 } // namespace webrtc 277 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/modules/bitrate_controller/bitrate_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698