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

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: Added kMaxNumSavedClusters. 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 ProbingCalculator::ProbingCalculator(ProbingResultCallback* result_callback)
31 : result_callback_(result_callback), last_valid_cluster_id_(0) {}
32
33 void ProbingCalculator::PacketFeedback(const PacketInfo& packet_info) {
34 // If this is not a probing packet or if this probing packet
35 // belongs to an old cluster, do nothing.
36 if (packet_info.probe_cluster_id == PacketInfo::kNotAProbe ||
37 packet_info.probe_cluster_id < last_valid_cluster_id_) {
38 return;
39 }
40
41 AggregatedCluster* cluster = &clusters_[packet_info.probe_cluster_id];
42 cluster->first_send_ms =
43 std::min(cluster->first_send_ms, packet_info.send_time_ms);
44 cluster->last_send_ms =
45 std::max(cluster->last_send_ms, packet_info.send_time_ms);
46 cluster->first_receive_ms =
47 std::min(cluster->first_receive_ms, packet_info.arrival_time_ms);
48 cluster->last_receive_ms =
49 std::max(cluster->last_receive_ms, packet_info.arrival_time_ms);
50 cluster->size += packet_info.payload_size;
51 cluster->num_probes += 1;
52
53 // Clean up old clusters.
54 while (clusters_.size() > kMaxNumSavedClusters)
55 clusters_.erase(clusters_.begin());
56
57 if (cluster->num_probes < kMinNumProbesValidCluster)
58 return;
59
60 int send_interval_ms = cluster->last_send_ms - cluster->first_send_ms;
61 int receive_interval_ms =
62 cluster->last_receive_ms - cluster->first_receive_ms;
63
64 if (send_interval_ms == 0 || receive_interval_ms == 0) {
65 LOG(LS_INFO) << "Probing unsuccessful, invalid send/receive interval!"
stefan-webrtc 2016/07/15 11:05:31 Can we change from "interval!" to "interval."? Jus
philipel 2016/07/15 12:54:18 Done.
66 << " [cluster id: " << packet_info.probe_cluster_id
67 << "] [send interval: " << send_interval_ms << " ms]"
68 << " [receive interval: " << receive_interval_ms << " ms]";
69 return;
70 }
71
72 float send_bps =
73 static_cast<float>(cluster->size) / send_interval_ms * 1000;
74 float receive_bps =
75 static_cast<float>(cluster->size) / receive_interval_ms * 1000;
76 float ratio = receive_bps / send_bps;
77 if (ratio > kValidRatio) {
78 LOG(LS_INFO) << "Probing unsuccessful, receive/send ratio to high!"
stefan-webrtc 2016/07/15 11:05:31 Same here.
terelius 2016/07/15 11:13:01 Also s/to/too/
philipel 2016/07/15 12:54:18 Done.
philipel 2016/07/15 12:54:18 Done.
79 << " [cluster id: " << packet_info.probe_cluster_id
80 << "] [send: " << cluster->size << " bytes / "
81 << send_interval_ms << " ms = " << send_bps / 1000 << " kB/s]"
stefan-webrtc 2016/07/15 11:05:31 kbps instead of kB/s. B == bytes.
philipel 2016/07/15 12:54:18 Done.
82 << " [receive: " << cluster->size << " bytes / "
83 << receive_interval_ms << " ms = " << receive_bps / 1000
84 << " kB/s]"
85 << " [ratio: " << receive_bps / 1000 << " / "
86 << send_bps / 1000 << " = " << ratio << " > kValidRatio ("
87 << kValidRatio << ")]";
88 return;
89 }
90 // We have a valid estimate.
91 int result_bps = std::min(send_bps, receive_bps);
92 result_callback_->ProbingResult(result_bps, packet_info.arrival_time_ms);
stefan-webrtc 2016/07/15 11:05:31 Maybe we can change this class to simply return th
philipel 2016/07/15 12:54:19 Done.
93 last_valid_cluster_id_ = packet_info.probe_cluster_id;
94 LOG(LS_INFO) << "Probing successful!"
95 << " [cluster id: " << packet_info.probe_cluster_id
96 << "] [send: " << cluster->size << " bytes / "
97 << send_interval_ms << " ms = " << send_bps / 1000 << " kB/s]"
98 << " [receive: " << cluster->size << " bytes / "
99 << receive_interval_ms << " ms = " << receive_bps / 1000
100 << " kB/s]";
101 }
102 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698