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 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 } else { | 45 } else { |
46 probing_state_ = kDisabled; | 46 probing_state_ = kDisabled; |
47 LOG(LS_INFO) << "Initial bandwidth probing disabled"; | 47 LOG(LS_INFO) << "Initial bandwidth probing disabled"; |
48 } | 48 } |
49 } | 49 } |
50 | 50 |
51 bool BitrateProber::IsProbing() const { | 51 bool BitrateProber::IsProbing() const { |
52 return probing_state_ == kProbing; | 52 return probing_state_ == kProbing; |
53 } | 53 } |
54 | 54 |
55 void BitrateProber::MaybeInitializeProbe(int bitrate_bps) { | 55 void BitrateProber::OnIncomingPacket(int bitrate_bps, |
56 size_t packet_size, | |
57 int64_t now_ms) { | |
58 // Don't initialize probing unless we have something large enough to start | |
59 // probing. | |
60 if (packet_size < PacedSender::kMinProbePacketSize) | |
61 return; | |
56 if (probing_state_ != kAllowedToProbe) | 62 if (probing_state_ != kAllowedToProbe) |
57 return; | 63 return; |
58 probe_bitrates_.clear(); | 64 probe_bitrates_.clear(); |
59 // Max number of packets used for probing. | 65 // Max number of packets used for probing. |
60 const int kMaxNumProbes = 2; | 66 const int kMaxNumProbes = 2; |
61 const int kPacketsPerProbe = 5; | 67 const int kPacketsPerProbe = 5; |
62 const float kProbeBitrateMultipliers[kMaxNumProbes] = {3, 6}; | 68 const float kProbeBitrateMultipliers[kMaxNumProbes] = {3, 6}; |
63 int bitrates_bps[kMaxNumProbes]; | 69 int bitrates_bps[kMaxNumProbes]; |
64 std::stringstream bitrate_log; | 70 std::stringstream bitrate_log; |
65 bitrate_log << "Start probing for bandwidth, bitrates:"; | 71 bitrate_log << "Start probing for bandwidth, bitrates:"; |
66 for (int i = 0; i < kMaxNumProbes; ++i) { | 72 for (int i = 0; i < kMaxNumProbes; ++i) { |
67 bitrates_bps[i] = kProbeBitrateMultipliers[i] * bitrate_bps; | 73 bitrates_bps[i] = kProbeBitrateMultipliers[i] * bitrate_bps; |
68 bitrate_log << " " << bitrates_bps[i]; | 74 bitrate_log << " " << bitrates_bps[i]; |
69 // We need one extra to get 5 deltas for the first probe. | 75 // We need one extra to get 5 deltas for the first probe. |
70 if (i == 0) | 76 if (i == 0) |
71 probe_bitrates_.push_back(bitrates_bps[i]); | 77 probe_bitrates_.push_back(bitrates_bps[i]); |
72 for (int j = 0; j < kPacketsPerProbe; ++j) | 78 for (int j = 0; j < kPacketsPerProbe; ++j) |
73 probe_bitrates_.push_back(bitrates_bps[i]); | 79 probe_bitrates_.push_back(bitrates_bps[i]); |
74 } | 80 } |
75 bitrate_log << ", num packets: " << probe_bitrates_.size(); | 81 bitrate_log << ", num packets: " << probe_bitrates_.size(); |
76 LOG(LS_INFO) << bitrate_log.str().c_str(); | 82 LOG(LS_INFO) << bitrate_log.str().c_str(); |
83 // Set last send time to current time so TimeUntilNextProbe doesn't short | |
84 // circuit due to inactivity. | |
85 time_last_send_ms_ = now_ms; | |
86 // Reset packet size to permit sending the first packet instantly. | |
87 packet_size_last_send_ = 0; | |
stefan-webrtc
2016/02/16 13:50:25
Is this needed? In case we decide to start a probe
pbos-webrtc
2016/02/16 13:57:20
Done.
| |
77 probing_state_ = kProbing; | 88 probing_state_ = kProbing; |
78 } | 89 } |
79 | 90 |
80 int BitrateProber::TimeUntilNextProbe(int64_t now_ms) { | 91 int BitrateProber::TimeUntilNextProbe(int64_t now_ms) { |
81 if (probing_state_ != kDisabled && probe_bitrates_.empty()) { | 92 if (probing_state_ != kDisabled && probe_bitrates_.empty()) { |
82 probing_state_ = kWait; | 93 probing_state_ = kWait; |
83 } | 94 } |
84 if (probe_bitrates_.empty()) { | 95 if (probe_bitrates_.empty() || time_last_send_ms_ == -1) { |
85 // No probe started, or waiting for next probe. | 96 // No probe started, probe finished, or too long since last probe packet. |
86 return -1; | 97 return -1; |
87 } | 98 } |
88 int64_t elapsed_time_ms = now_ms - time_last_send_ms_; | 99 int64_t elapsed_time_ms = now_ms - time_last_send_ms_; |
100 // If no packets have been sent for n milliseconds, temporarily deactivate to | |
101 // not keep spinning. | |
102 static const int kSendDeltaUntilConsideredInactiveMs = 5000; | |
stefan-webrtc
2016/02/16 13:50:25
kInactiveSendDeltaMs?
pbos-webrtc
2016/02/16 13:57:20
Done.
| |
103 if (elapsed_time_ms > kSendDeltaUntilConsideredInactiveMs) { | |
104 time_last_send_ms_ = -1; | |
105 probing_state_ = kAllowedToProbe; | |
stefan-webrtc
2016/02/16 13:50:26
This will start a new probe once the next packet i
pbos-webrtc
2016/02/16 13:57:20
That's the idea. If we had a long period of small-
| |
106 return -1; | |
107 } | |
89 // We will send the first probe packet immediately if no packet has been | 108 // We will send the first probe packet immediately if no packet has been |
90 // sent before. | 109 // sent before. |
91 int time_until_probe_ms = 0; | 110 int time_until_probe_ms = 0; |
92 if (packet_size_last_send_ > PacedSender::kMinProbePacketSize && | 111 if (packet_size_last_send_ != 0 && probing_state_ == kProbing) { |
93 probing_state_ == kProbing) { | |
94 int next_delta_ms = ComputeDeltaFromBitrate(packet_size_last_send_, | 112 int next_delta_ms = ComputeDeltaFromBitrate(packet_size_last_send_, |
95 probe_bitrates_.front()); | 113 probe_bitrates_.front()); |
96 time_until_probe_ms = next_delta_ms - elapsed_time_ms; | 114 time_until_probe_ms = next_delta_ms - elapsed_time_ms; |
97 // There is no point in trying to probe with less than 1 ms between packets | 115 // There is no point in trying to probe with less than 1 ms between packets |
98 // as it essentially means trying to probe at infinite bandwidth. | 116 // as it essentially means trying to probe at infinite bandwidth. |
99 const int kMinProbeDeltaMs = 1; | 117 const int kMinProbeDeltaMs = 1; |
100 // If we have waited more than 3 ms for a new packet to probe with we will | 118 // If we have waited more than 3 ms for a new packet to probe with we will |
101 // consider this probing session over. | 119 // consider this probing session over. |
102 const int kMaxProbeDelayMs = 3; | 120 const int kMaxProbeDelayMs = 3; |
103 if (next_delta_ms < kMinProbeDeltaMs || | 121 if (next_delta_ms < kMinProbeDeltaMs || |
104 time_until_probe_ms < -kMaxProbeDelayMs) { | 122 time_until_probe_ms < -kMaxProbeDelayMs) { |
105 // We currently disable probing after the first probe, as we only want | 123 // We currently disable probing after the first probe, as we only want |
106 // to probe at the beginning of a connection. We should set this to | 124 // to probe at the beginning of a connection. We should set this to |
107 // kWait if we later want to probe periodically. | 125 // kWait if we later want to probe periodically. |
108 probing_state_ = kWait; | 126 probing_state_ = kWait; |
109 LOG(LS_INFO) << "Next delta too small, stop probing."; | 127 LOG(LS_INFO) << "Next delta too small, stop probing."; |
110 time_until_probe_ms = 0; | 128 time_until_probe_ms = 0; |
111 } | 129 } |
112 } | 130 } |
113 return std::max(time_until_probe_ms, 0); | 131 return std::max(time_until_probe_ms, 0); |
114 } | 132 } |
115 | 133 |
116 size_t BitrateProber::RecommendedPacketSize() const { | 134 size_t BitrateProber::RecommendedPacketSize() const { |
117 return packet_size_last_send_; | 135 return packet_size_last_send_; |
118 } | 136 } |
119 | 137 |
120 void BitrateProber::PacketSent(int64_t now_ms, size_t packet_size) { | 138 void BitrateProber::PacketSent(int64_t now_ms, size_t packet_size) { |
121 assert(packet_size > 0); | 139 assert(packet_size > 0); |
140 if (packet_size < PacedSender::kMinProbePacketSize) | |
141 return; | |
122 packet_size_last_send_ = packet_size; | 142 packet_size_last_send_ = packet_size; |
123 time_last_send_ms_ = now_ms; | 143 time_last_send_ms_ = now_ms; |
124 if (probing_state_ != kProbing) | 144 if (probing_state_ != kProbing) |
125 return; | 145 return; |
126 if (!probe_bitrates_.empty()) | 146 if (!probe_bitrates_.empty()) |
127 probe_bitrates_.pop_front(); | 147 probe_bitrates_.pop_front(); |
128 } | 148 } |
129 } // namespace webrtc | 149 } // namespace webrtc |
OLD | NEW |