OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 #include "webrtc/modules/pacing/bitrate_prober.h" | 11 #include "webrtc/modules/pacing/bitrate_prober.h" |
12 | 12 |
13 #include <assert.h> | |
14 #include <algorithm> | 13 #include <algorithm> |
15 #include <limits> | |
16 #include <sstream> | |
17 #include <utility> | |
18 | 14 |
19 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
20 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
21 #include "webrtc/modules/pacing/paced_sender.h" | 17 #include "webrtc/modules/pacing/paced_sender.h" |
22 | 18 |
23 namespace webrtc { | 19 namespace webrtc { |
24 | 20 |
25 namespace { | 21 namespace { |
26 | 22 |
27 // Inactivity threshold above which probing is restarted. | 23 // Inactivity threshold above which probing is restarted. |
28 constexpr int kInactivityThresholdMs = 5000; | 24 constexpr int kInactivityThresholdMs = 5000; |
29 | 25 |
30 int ComputeDeltaFromBitrate(size_t packet_size, uint32_t bitrate_bps) { | 26 int ComputeDeltaFromBitrate(size_t packet_size, uint32_t bitrate_bps) { |
31 assert(bitrate_bps > 0); | 27 RTC_CHECK_GT(bitrate_bps, 0u); |
32 // Compute the time delta needed to send packet_size bytes at bitrate_bps | 28 // Compute the time delta needed to send packet_size bytes at bitrate_bps |
33 // bps. Result is in milliseconds. | 29 // bps. Result is in milliseconds. |
34 return static_cast<int>((1000ll * packet_size * 8) / bitrate_bps); | 30 return static_cast<int>((1000ll * packet_size * 8) / bitrate_bps); |
35 } | 31 } |
36 } // namespace | 32 } // namespace |
37 | 33 |
38 BitrateProber::BitrateProber() | 34 BitrateProber::BitrateProber() |
39 : probing_state_(ProbingState::kDisabled), | 35 : probing_state_(ProbingState::kDisabled), |
40 packet_size_last_sent_(0), | 36 packet_size_last_sent_(0), |
41 time_last_probe_sent_ms_(-1), | 37 time_last_probe_sent_ms_(-1), |
(...skipping 10 matching lines...) Expand all Loading... | |
52 } else { | 48 } else { |
53 probing_state_ = ProbingState::kDisabled; | 49 probing_state_ = ProbingState::kDisabled; |
54 LOG(LS_INFO) << "Bandwidth probing disabled"; | 50 LOG(LS_INFO) << "Bandwidth probing disabled"; |
55 } | 51 } |
56 } | 52 } |
57 | 53 |
58 bool BitrateProber::IsProbing() const { | 54 bool BitrateProber::IsProbing() const { |
59 return probing_state_ == ProbingState::kActive; | 55 return probing_state_ == ProbingState::kActive; |
60 } | 56 } |
61 | 57 |
62 void BitrateProber::OnIncomingPacket(uint32_t bitrate_bps, | 58 void BitrateProber::OnIncomingPacket(size_t packet_size) { |
philipel
2016/08/12 12:53:44
Instead of creating clusters and trigger probing (
| |
63 size_t packet_size, | |
64 int64_t now_ms) { | |
65 // Don't initialize probing unless we have something large enough to start | 59 // Don't initialize probing unless we have something large enough to start |
66 // probing. | 60 // probing. |
67 if (packet_size < PacedSender::kMinProbePacketSize) | 61 if (probing_state_ == ProbingState::kInactive && |
68 return; | 62 packet_size >= PacedSender::kMinProbePacketSize) { |
69 if (probing_state_ != ProbingState::kInactive) | 63 probing_state_ = ProbingState::kActive; |
70 return; | 64 } |
71 // Max number of packets used for probing. | 65 } |
72 const int kMaxNumProbes = 2; | |
73 const int kPacketsPerProbe = 5; | |
74 const float kProbeBitrateMultipliers[kMaxNumProbes] = {3, 6}; | |
75 std::stringstream bitrate_log; | |
76 bitrate_log << "Start probing for bandwidth, (bitrate:packets): "; | |
77 for (int i = 0; i < kMaxNumProbes; ++i) { | |
78 ProbeCluster cluster; | |
79 // We need one extra to get 5 deltas for the first probe, therefore (i == 0) | |
80 cluster.max_probe_packets = kPacketsPerProbe + (i == 0 ? 1 : 0); | |
81 cluster.probe_bitrate_bps = kProbeBitrateMultipliers[i] * bitrate_bps; | |
82 cluster.id = next_cluster_id_++; | |
83 | 66 |
84 bitrate_log << "(" << cluster.probe_bitrate_bps << ":" | 67 void BitrateProber::ProbeBitrate(uint32_t bitrate_bps, int num_packets) { |
85 << cluster.max_probe_packets << ") "; | 68 ProbeCluster cluster; |
86 | 69 cluster.max_probe_packets = num_packets; |
87 clusters_.push(cluster); | 70 cluster.probe_bitrate_bps = bitrate_bps; |
88 } | 71 cluster.id = next_cluster_id_++; |
89 LOG(LS_INFO) << bitrate_log.str().c_str(); | 72 clusters_.push_back(cluster); |
90 probing_state_ = ProbingState::kActive; | 73 LOG(LS_INFO) << "Probe cluster (bitrate:packets): (" |
74 << cluster.probe_bitrate_bps << ":" << cluster.max_probe_packets | |
75 << ") "; | |
76 if (probing_state_ != ProbingState::kActive) | |
danilchap
2016/08/12 15:13:34
wouldn't that activate probing even if it is in Pr
Irfan
2016/08/12 15:26:06
There should probably be an RTC_DCHECK() that ensu
| |
77 probing_state_ = ProbingState::kInactive; | |
91 } | 78 } |
92 | 79 |
93 void BitrateProber::ResetState() { | 80 void BitrateProber::ResetState() { |
94 time_last_probe_sent_ms_ = -1; | 81 time_last_probe_sent_ms_ = -1; |
95 packet_size_last_sent_ = 0; | 82 packet_size_last_sent_ = 0; |
96 clusters_ = std::queue<ProbeCluster>(); | 83 |
84 // Reset all queued probing clusters. | |
stefan-webrtc
2016/08/12 13:19:58
What does resetting mean? It seems odd to me that
philipel
2016/08/12 14:08:06
Now use ProbeAtBitrate instead to recreate the pro
| |
85 for (auto& cluster : clusters_) { | |
86 cluster.id = next_cluster_id_++; | |
87 cluster.sent_probe_packets = 0; | |
88 } | |
philipel
2016/08/12 12:53:44
In the unittest BitrateProberTest.DoesntProbeWitho
stefan-webrtc
2016/08/12 13:19:58
If this is the answer to my question above, then m
philipel
2016/08/12 14:08:06
Yes, the current behavior is to retry probing if w
| |
97 // If its enabled, reset to inactive. | 89 // If its enabled, reset to inactive. |
98 if (probing_state_ != ProbingState::kDisabled) | 90 if (probing_state_ != ProbingState::kDisabled) |
99 probing_state_ = ProbingState::kInactive; | 91 probing_state_ = ProbingState::kInactive; |
100 } | 92 } |
101 | 93 |
102 int BitrateProber::TimeUntilNextProbe(int64_t now_ms) { | 94 int BitrateProber::TimeUntilNextProbe(int64_t now_ms) { |
103 // Probing is not active or probing is already complete. | 95 // Probing is not active or probing is already complete. |
104 if (probing_state_ != ProbingState::kActive || clusters_.empty()) | 96 if (probing_state_ != ProbingState::kActive || clusters_.empty()) |
105 return -1; | 97 return -1; |
106 // time_last_probe_sent_ms_ of -1 indicates no probes have yet been sent. | 98 // time_last_probe_sent_ms_ of -1 indicates no probes have yet been sent. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 if (packet_size < PacedSender::kMinProbePacketSize) | 146 if (packet_size < PacedSender::kMinProbePacketSize) |
155 return; | 147 return; |
156 packet_size_last_sent_ = packet_size; | 148 packet_size_last_sent_ = packet_size; |
157 if (probing_state_ != ProbingState::kActive) | 149 if (probing_state_ != ProbingState::kActive) |
158 return; | 150 return; |
159 time_last_probe_sent_ms_ = now_ms; | 151 time_last_probe_sent_ms_ = now_ms; |
160 if (!clusters_.empty()) { | 152 if (!clusters_.empty()) { |
161 ProbeCluster* cluster = &clusters_.front(); | 153 ProbeCluster* cluster = &clusters_.front(); |
162 ++cluster->sent_probe_packets; | 154 ++cluster->sent_probe_packets; |
163 if (cluster->sent_probe_packets == cluster->max_probe_packets) | 155 if (cluster->sent_probe_packets == cluster->max_probe_packets) |
164 clusters_.pop(); | 156 clusters_.pop_front(); |
165 if (clusters_.empty()) | 157 if (clusters_.empty()) |
166 probing_state_ = ProbingState::kSuspended; | 158 probing_state_ = ProbingState::kSuspended; |
167 } | 159 } |
168 } | 160 } |
169 } // namespace webrtc | 161 } // namespace webrtc |
OLD | NEW |