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

Side by Side Diff: webrtc/modules/congestion_controller/probing_calculator.cc

Issue 2121183002: New ProbingCalculator class. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Removed callback, return result instead. Created 4 years, 5 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
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/modules/congestion_controller/probing_calculator.h"
12
13 #include <algorithm>
14
15 #include "webrtc/base/logging.h"
16
17 namespace {
18 // Max number of saved clusters.
19 constexpr size_t kMaxNumSavedClusters = 5;
20
21 // The minumum number of probes we need for a valid cluster.
22 constexpr int kMinNumProbesValidCluster = 4;
23
24 // The maximum (receive rate)/(send rate) ratio for a valid estimate.
25 constexpr float kValidRatio = 1.2f;
26 }
27
28 namespace webrtc {
29
30 ProbingResult::ProbingResult()
31 : bps(kNoEstimate), timestamp(0) {}
32
33 ProbingResult::ProbingResult(int bps, int64_t timestamp)
34 : bps(bps), timestamp(timestamp) {}
35
36 ProbingCalculator::ProbingCalculator() : last_valid_cluster_id_(0) {}
37
38 ProbingResult ProbingCalculator::PacketFeedback(const PacketInfo& packet_info) {
39 // If this is not a probing packet or if this probing packet
40 // belongs to an old cluster, do nothing.
41 if (packet_info.probe_cluster_id == PacketInfo::kNotAProbe ||
42 packet_info.probe_cluster_id < last_valid_cluster_id_) {
43 return ProbingResult();
44 }
45
46 AggregatedCluster* cluster = &clusters_[packet_info.probe_cluster_id];
47 cluster->first_send_ms =
48 std::min(cluster->first_send_ms, packet_info.send_time_ms);
49 cluster->last_send_ms =
50 std::max(cluster->last_send_ms, packet_info.send_time_ms);
51 cluster->first_receive_ms =
52 std::min(cluster->first_receive_ms, packet_info.arrival_time_ms);
53 cluster->last_receive_ms =
54 std::max(cluster->last_receive_ms, packet_info.arrival_time_ms);
55 cluster->size += packet_info.payload_size;
56 cluster->num_probes += 1;
57
58 // Clean up old clusters.
59 while (clusters_.size() > kMaxNumSavedClusters)
60 clusters_.erase(clusters_.begin());
61
62 if (cluster->num_probes < kMinNumProbesValidCluster)
63 return ProbingResult();
64
65 int send_interval_ms = cluster->last_send_ms - cluster->first_send_ms;
66 int receive_interval_ms =
67 cluster->last_receive_ms - cluster->first_receive_ms;
68
69 if (send_interval_ms == 0 || receive_interval_ms == 0) {
70 LOG(LS_INFO) << "Probing unsuccessful, invalid send/receive interval"
71 << " [cluster id: " << packet_info.probe_cluster_id
72 << "] [send interval: " << send_interval_ms << " ms]"
73 << " [receive interval: " << receive_interval_ms << " ms]";
74
75 return ProbingResult();
76 }
77
78 float send_bps =
79 static_cast<float>(cluster->size) / send_interval_ms * 1000;
80 float receive_bps =
81 static_cast<float>(cluster->size) / receive_interval_ms * 1000;
82 float ratio = receive_bps / send_bps;
stefan-webrtc 2016/08/01 10:55:34 DCHECK_GT(send_bps, 0);
83 if (ratio > kValidRatio) {
84 LOG(LS_INFO) << "Probing unsuccessful, receive/send ratio too high"
85 << " [cluster id: " << packet_info.probe_cluster_id
86 << "] [send: " << cluster->size << " bytes / "
87 << send_interval_ms << " ms = " << send_bps / 1000 << " kb/s]"
88 << " [receive: " << cluster->size << " bytes / "
89 << receive_interval_ms << " ms = " << receive_bps / 1000
90 << " kb/s]"
91 << " [ratio: " << receive_bps / 1000 << " / "
92 << send_bps / 1000 << " = " << ratio << " > kValidRatio ("
93 << kValidRatio << ")]";
94
95 return ProbingResult();
96 }
97 // We have a valid estimate.
98 int result_bps = std::min(send_bps, receive_bps);
99 last_valid_cluster_id_ = packet_info.probe_cluster_id;
100 LOG(LS_INFO) << "Probing successful"
101 << " [cluster id: " << packet_info.probe_cluster_id
102 << "] [send: " << cluster->size << " bytes / "
103 << send_interval_ms << " ms = " << send_bps / 1000 << " kb/s]"
104 << " [receive: " << cluster->size << " bytes / "
105 << receive_interval_ms << " ms = " << receive_bps / 1000
106 << " kb/s]";
107
108 return ProbingResult(result_bps, packet_info.arrival_time_ms);
109 }
110 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698