OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
3 * | |
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 | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include "webrtc/modules/congestion_controller/probe_controller.h" | |
12 | |
13 #include <initializer_list> | |
14 | |
15 #include "webrtc/base/logging.h" | |
16 | |
17 namespace webrtc { | |
18 | |
19 namespace { | |
20 | |
21 // Number of deltas between probes per cluster. On the very first cluster, | |
22 // we will need kProbeDeltasPerCluster + 1 probes, but on a cluster following | |
23 // another, we need kProbeDeltasPerCluster probes. | |
24 constexpr int kProbeDeltasPerCluster = 5; | |
25 | |
26 // Maximum waiting time from the time of initiating probing to getting | |
27 // the measured results back. | |
28 constexpr int64_t kMaxWaitingTimeForProbingResultMs = 1000; | |
29 | |
30 // Value of |min_bitrate_to_probe_further_bps_| that indicates | |
31 // further probing is disabled. | |
32 constexpr int kDisableExponentialProbing = 0; | |
philipel
2016/09/08 12:52:47
kExponentialProbingDisabled
Irfan
2016/09/09 08:12:52
Done.
| |
33 | |
34 } // namespace | |
35 | |
36 ProbeController::ProbeController(PacedSender* pacer, Clock* clock) | |
37 : pacer_(pacer), | |
38 clock_(clock), | |
39 state_(State::kInit), | |
40 min_bitrate_to_probe_further_bps_(kDisableExponentialProbing), | |
41 time_last_probing_initiated_ms_(0), | |
42 estimated_bitrate_bps_(0), | |
43 max_bitrate_bps_(0) {} | |
44 | |
45 void ProbeController::SetBitrates(int min_bitrate_bps, | |
46 int start_bitrate_bps, | |
47 int max_bitrate_bps) { | |
48 rtc::CritScope cs(&critsect_); | |
49 if (state_ == State::kInit) { | |
50 // When probing at 1.8 Mbps ( 6x 300), this represents a threshold of | |
51 // 1.2 Mbps to continue probing. | |
52 InitiateProbing({3 * start_bitrate_bps, 6 * start_bitrate_bps}, | |
53 4 * start_bitrate_bps); | |
54 } | |
55 | |
56 // Only do probing if: | |
57 // - we are mid-call, which we consider to be if | |
58 // |estimated_bitrate_bps_| != 0, and | |
59 // - the current bitrate is lower than the new |max_bitrate_bps|, and | |
60 // - we actually want to increase the |max_bitrate_bps_|. | |
61 if (estimated_bitrate_bps_ != 0 && estimated_bitrate_bps_ < max_bitrate_bps && | |
62 max_bitrate_bps > max_bitrate_bps_) { | |
63 InitiateProbing({max_bitrate_bps}, kDisableExponentialProbing); | |
64 } | |
65 max_bitrate_bps_ = max_bitrate_bps; | |
66 } | |
67 | |
68 void ProbeController::SetEstimatedBitrate(int bitrate_bps) { | |
69 rtc::CritScope cs(&critsect_); | |
70 // Continue probing if probing results indicate channel has greater | |
71 // capacity. | |
72 if (state_ == State::kWaitForProbingResult) { | |
73 LOG(LS_INFO) << "SetEstimatedBitrate " << bitrate_bps; | |
74 if (min_bitrate_to_probe_further_bps_ != kDisableExponentialProbing && | |
75 bitrate_bps > min_bitrate_to_probe_further_bps_) { | |
76 // Double the probing bitrate and expect a minimum of 25% gain to | |
77 // continue probing. | |
78 InitiateProbing({2 * bitrate_bps}, 1.25 * bitrate_bps); | |
79 } | |
80 } | |
81 estimated_bitrate_bps_ = bitrate_bps; | |
82 } | |
83 | |
84 void ProbeController::InitiateProbing( | |
85 std::initializer_list<int> bitrates_to_probe, | |
86 int min_bitrate_to_probe_further_bps) { | |
87 bool first_cluster = true; | |
88 for (int bitrate : bitrates_to_probe) { | |
89 if (first_cluster) { | |
90 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster + 1); | |
91 first_cluster = false; | |
92 } else { | |
93 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster); | |
94 } | |
95 } | |
96 min_bitrate_to_probe_further_bps_ = min_bitrate_to_probe_further_bps; | |
97 time_last_probing_initiated_ms_ = clock_->TimeInMilliseconds(); | |
98 if (min_bitrate_to_probe_further_bps == kDisableExponentialProbing) | |
99 state_ = State::kProbingComplete; | |
100 else | |
101 state_ = State::kWaitForProbingResult; | |
102 LOG(LS_INFO) << " min_bitrate_to_probe_further_bps " | |
103 << min_bitrate_to_probe_further_bps_; | |
104 } | |
105 | |
106 void ProbeController::Process() { | |
107 rtc::CritScope cs(&critsect_); | |
108 if (state_ == State::kWaitForProbingResult && | |
109 ((clock_->TimeInMilliseconds() - time_last_probing_initiated_ms_) > | |
philipel
2016/09/08 12:52:47
Remove Process() and add the timeout check to SetE
Irfan
2016/09/09 08:12:52
Done.
| |
110 kMaxWaitingTimeForProbingResultMs)) { | |
111 state_ = State::kProbingComplete; | |
112 min_bitrate_to_probe_further_bps_ = kDisableExponentialProbing; | |
113 LOG(LS_INFO) << "kWaitForResult: timeout"; | |
114 } | |
115 } | |
116 | |
117 } // namespace webrtc | |
OLD | NEW |