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

Side by Side Diff: webrtc/modules/pacing/bitrate_prober.cc

Issue 2243823002: Added ProbeBitrate(bitrate_bps, num_probes) to BitrateProber. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: ... in header file. Created 4 years, 4 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
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
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) {
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::ProbeAtBitrate(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(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)
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 // Recreate all probing clusters.
85 std::queue<ProbeCluster> clusters;
86 clusters.swap(clusters_);
87 while (!clusters.empty()) {
88 ProbeAtBitrate(clusters.front().probe_bitrate_bps,
89 clusters.front().max_probe_packets);
90 clusters.pop();
91 }
97 // If its enabled, reset to inactive. 92 // If its enabled, reset to inactive.
98 if (probing_state_ != ProbingState::kDisabled) 93 if (probing_state_ != ProbingState::kDisabled)
99 probing_state_ = ProbingState::kInactive; 94 probing_state_ = ProbingState::kInactive;
100 } 95 }
101 96
102 int BitrateProber::TimeUntilNextProbe(int64_t now_ms) { 97 int BitrateProber::TimeUntilNextProbe(int64_t now_ms) {
103 // Probing is not active or probing is already complete. 98 // Probing is not active or probing is already complete.
104 if (probing_state_ != ProbingState::kActive || clusters_.empty()) 99 if (probing_state_ != ProbingState::kActive || clusters_.empty())
105 return -1; 100 return -1;
106 // time_last_probe_sent_ms_ of -1 indicates no probes have yet been sent. 101 // time_last_probe_sent_ms_ of -1 indicates no probes have yet been sent.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 if (!clusters_.empty()) { 155 if (!clusters_.empty()) {
161 ProbeCluster* cluster = &clusters_.front(); 156 ProbeCluster* cluster = &clusters_.front();
162 ++cluster->sent_probe_packets; 157 ++cluster->sent_probe_packets;
163 if (cluster->sent_probe_packets == cluster->max_probe_packets) 158 if (cluster->sent_probe_packets == cluster->max_probe_packets)
164 clusters_.pop(); 159 clusters_.pop();
165 if (clusters_.empty()) 160 if (clusters_.empty())
166 probing_state_ = ProbingState::kSuspended; 161 probing_state_ = ProbingState::kSuspended;
167 } 162 }
168 } 163 }
169 } // namespace webrtc 164 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/pacing/bitrate_prober.h ('k') | webrtc/modules/pacing/bitrate_prober_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698