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> | 13 #include <assert.h> |
14 #include <algorithm> | 14 #include <algorithm> |
15 #include <limits> | 15 #include <limits> |
16 #include <sstream> | 16 #include <sstream> |
17 | 17 |
| 18 #include "webrtc/modules/pacing/include/paced_sender.h" |
18 #include "webrtc/system_wrappers/interface/logging.h" | 19 #include "webrtc/system_wrappers/interface/logging.h" |
19 | 20 |
20 namespace webrtc { | 21 namespace webrtc { |
21 | 22 |
22 namespace { | 23 namespace { |
23 int ComputeDeltaFromBitrate(size_t packet_size, int bitrate_bps) { | 24 int ComputeDeltaFromBitrate(size_t packet_size, int bitrate_bps) { |
24 assert(bitrate_bps > 0); | 25 assert(bitrate_bps > 0); |
25 // Compute the time delta needed to send packet_size bytes at bitrate_bps | 26 // Compute the time delta needed to send packet_size bytes at bitrate_bps |
26 // bps. Result is in milliseconds. | 27 // bps. Result is in milliseconds. |
27 return static_cast<int>(1000ll * static_cast<int64_t>(packet_size) * 8ll / | 28 return static_cast<int>(1000ll * static_cast<int64_t>(packet_size) * 8ll / |
28 bitrate_bps); | 29 bitrate_bps); |
29 } | 30 } |
30 } // namespace | 31 } // namespace |
31 | 32 |
32 const size_t BitrateProber::kMinProbePacketSize = 200; | |
33 | |
34 BitrateProber::BitrateProber() | 33 BitrateProber::BitrateProber() |
35 : probing_state_(kDisabled), | 34 : probing_state_(kDisabled), |
36 packet_size_last_send_(0), | 35 packet_size_last_send_(0), |
37 time_last_send_ms_(-1) { | 36 time_last_send_ms_(-1) { |
38 } | 37 } |
39 | 38 |
40 void BitrateProber::SetEnabled(bool enable) { | 39 void BitrateProber::SetEnabled(bool enable) { |
41 if (enable) { | 40 if (enable) { |
42 if (probing_state_ == kDisabled) { | 41 if (probing_state_ == kDisabled) { |
43 probing_state_ = kAllowedToProbe; | 42 probing_state_ = kAllowedToProbe; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 probing_state_ = kWait; | 82 probing_state_ = kWait; |
84 } | 83 } |
85 if (probe_bitrates_.empty()) { | 84 if (probe_bitrates_.empty()) { |
86 // No probe started, or waiting for next probe. | 85 // No probe started, or waiting for next probe. |
87 return -1; | 86 return -1; |
88 } | 87 } |
89 int64_t elapsed_time_ms = now_ms - time_last_send_ms_; | 88 int64_t elapsed_time_ms = now_ms - time_last_send_ms_; |
90 // We will send the first probe packet immediately if no packet has been | 89 // We will send the first probe packet immediately if no packet has been |
91 // sent before. | 90 // sent before. |
92 int time_until_probe_ms = 0; | 91 int time_until_probe_ms = 0; |
93 if (packet_size_last_send_ > kMinProbePacketSize && | 92 if (packet_size_last_send_ > PacedSender::kMinProbePacketSize && |
94 probing_state_ == kProbing) { | 93 probing_state_ == kProbing) { |
95 int next_delta_ms = ComputeDeltaFromBitrate(packet_size_last_send_, | 94 int next_delta_ms = ComputeDeltaFromBitrate(packet_size_last_send_, |
96 probe_bitrates_.front()); | 95 probe_bitrates_.front()); |
97 time_until_probe_ms = next_delta_ms - elapsed_time_ms; | 96 time_until_probe_ms = next_delta_ms - elapsed_time_ms; |
98 // There is no point in trying to probe with less than 1 ms between packets | 97 // There is no point in trying to probe with less than 1 ms between packets |
99 // as it essentially means trying to probe at infinite bandwidth. | 98 // as it essentially means trying to probe at infinite bandwidth. |
100 const int kMinProbeDeltaMs = 1; | 99 const int kMinProbeDeltaMs = 1; |
101 // If we have waited more than 3 ms for a new packet to probe with we will | 100 // If we have waited more than 3 ms for a new packet to probe with we will |
102 // consider this probing session over. | 101 // consider this probing session over. |
103 const int kMaxProbeDelayMs = 3; | 102 const int kMaxProbeDelayMs = 3; |
(...skipping 17 matching lines...) Expand all Loading... |
121 void BitrateProber::PacketSent(int64_t now_ms, size_t packet_size) { | 120 void BitrateProber::PacketSent(int64_t now_ms, size_t packet_size) { |
122 assert(packet_size > 0); | 121 assert(packet_size > 0); |
123 packet_size_last_send_ = packet_size; | 122 packet_size_last_send_ = packet_size; |
124 time_last_send_ms_ = now_ms; | 123 time_last_send_ms_ = now_ms; |
125 if (probing_state_ != kProbing) | 124 if (probing_state_ != kProbing) |
126 return; | 125 return; |
127 if (!probe_bitrates_.empty()) | 126 if (!probe_bitrates_.empty()) |
128 probe_bitrates_.pop_front(); | 127 probe_bitrates_.pop_front(); |
129 } | 128 } |
130 } // namespace webrtc | 129 } // namespace webrtc |
OLD | NEW |