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/base/logging.h" | 18 #include "webrtc/base/logging.h" |
19 #include "webrtc/modules/pacing/paced_sender.h" | 19 #include "webrtc/modules/pacing/paced_sender.h" |
20 | 20 |
21 namespace webrtc { | 21 namespace webrtc { |
22 | 22 |
23 namespace { | 23 namespace { |
24 int ComputeDeltaFromBitrate(size_t packet_size, int bitrate_bps) { | 24 int ComputeDeltaFromBitrate(size_t packet_size, uint32_t bitrate_bps) { |
25 assert(bitrate_bps > 0); | 25 assert(bitrate_bps > 0); |
26 // 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 |
27 // bps. Result is in milliseconds. | 27 // bps. Result is in milliseconds. |
28 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 / |
29 bitrate_bps); | 29 bitrate_bps); |
30 } | 30 } |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 BitrateProber::BitrateProber() | 33 BitrateProber::BitrateProber() |
34 : probing_state_(kDisabled), | 34 : probing_state_(kDisabled), |
(...skipping 10 matching lines...) Expand all 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::OnIncomingPacket(int bitrate_bps, | 55 void BitrateProber::OnIncomingPacket(uint32_t bitrate_bps, |
56 size_t packet_size, | 56 size_t packet_size, |
57 int64_t now_ms) { | 57 int64_t now_ms) { |
58 // Don't initialize probing unless we have something large enough to start | 58 // Don't initialize probing unless we have something large enough to start |
59 // probing. | 59 // probing. |
60 if (packet_size < PacedSender::kMinProbePacketSize) | 60 if (packet_size < PacedSender::kMinProbePacketSize) |
61 return; | 61 return; |
62 if (probing_state_ != kAllowedToProbe) | 62 if (probing_state_ != kAllowedToProbe) |
63 return; | 63 return; |
64 probe_bitrates_.clear(); | 64 probe_bitrates_.clear(); |
65 // Max number of packets used for probing. | 65 // Max number of packets used for probing. |
66 const int kMaxNumProbes = 2; | 66 const int kMaxNumProbes = 2; |
67 const int kPacketsPerProbe = 5; | 67 const int kPacketsPerProbe = 5; |
68 const float kProbeBitrateMultipliers[kMaxNumProbes] = {3, 6}; | 68 const float kProbeBitrateMultipliers[kMaxNumProbes] = {3, 6}; |
69 int bitrates_bps[kMaxNumProbes]; | 69 uint32_t bitrates_bps[kMaxNumProbes]; |
70 std::stringstream bitrate_log; | 70 std::stringstream bitrate_log; |
71 bitrate_log << "Start probing for bandwidth, bitrates:"; | 71 bitrate_log << "Start probing for bandwidth, bitrates:"; |
72 for (int i = 0; i < kMaxNumProbes; ++i) { | 72 for (int i = 0; i < kMaxNumProbes; ++i) { |
73 bitrates_bps[i] = kProbeBitrateMultipliers[i] * bitrate_bps; | 73 bitrates_bps[i] = kProbeBitrateMultipliers[i] * bitrate_bps; |
74 bitrate_log << " " << bitrates_bps[i]; | 74 bitrate_log << " " << bitrates_bps[i]; |
75 // 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. |
76 if (i == 0) | 76 if (i == 0) |
77 probe_bitrates_.push_back(bitrates_bps[i]); | 77 probe_bitrates_.push_back(bitrates_bps[i]); |
78 for (int j = 0; j < kPacketsPerProbe; ++j) | 78 for (int j = 0; j < kPacketsPerProbe; ++j) |
79 probe_bitrates_.push_back(bitrates_bps[i]); | 79 probe_bitrates_.push_back(bitrates_bps[i]); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 if (packet_size < PacedSender::kMinProbePacketSize) | 138 if (packet_size < PacedSender::kMinProbePacketSize) |
139 return; | 139 return; |
140 packet_size_last_send_ = packet_size; | 140 packet_size_last_send_ = packet_size; |
141 time_last_send_ms_ = now_ms; | 141 time_last_send_ms_ = now_ms; |
142 if (probing_state_ != kProbing) | 142 if (probing_state_ != kProbing) |
143 return; | 143 return; |
144 if (!probe_bitrates_.empty()) | 144 if (!probe_bitrates_.empty()) |
145 probe_bitrates_.pop_front(); | 145 probe_bitrates_.pop_front(); |
146 } | 146 } |
147 } // namespace webrtc | 147 } // namespace webrtc |
OLD | NEW |