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 10 matching lines...) Expand all Loading... |
21 namespace { | 21 namespace { |
22 | 22 |
23 // A minimum interval between probes to allow scheduling to be feasible. | 23 // A minimum interval between probes to allow scheduling to be feasible. |
24 constexpr int kMinProbeDeltaMs = 1; | 24 constexpr int kMinProbeDeltaMs = 1; |
25 | 25 |
26 // The minimum number probing packets used. | 26 // The minimum number probing packets used. |
27 constexpr int kMinProbePacketsSent = 5; | 27 constexpr int kMinProbePacketsSent = 5; |
28 | 28 |
29 // The minimum probing duration in ms. | 29 // The minimum probing duration in ms. |
30 constexpr int kMinProbeDurationMs = 15; | 30 constexpr int kMinProbeDurationMs = 15; |
31 | |
32 } // namespace | 31 } // namespace |
33 | 32 |
34 BitrateProber::BitrateProber() | 33 BitrateProber::BitrateProber() : BitrateProber(nullptr) {} |
| 34 |
| 35 BitrateProber::BitrateProber( |
| 36 ProbeClusterCreatedObserver* cluster_created_observer) |
35 : probing_state_(ProbingState::kDisabled), | 37 : probing_state_(ProbingState::kDisabled), |
36 next_probe_time_ms_(-1), | 38 next_probe_time_ms_(-1), |
37 next_cluster_id_(0) { | 39 next_cluster_id_(0), |
| 40 cluster_created_observer_(cluster_created_observer) { |
38 SetEnabled(true); | 41 SetEnabled(true); |
39 } | 42 } |
40 | 43 |
41 void BitrateProber::SetEnabled(bool enable) { | 44 void BitrateProber::SetEnabled(bool enable) { |
42 if (enable) { | 45 if (enable) { |
43 if (probing_state_ == ProbingState::kDisabled) { | 46 if (probing_state_ == ProbingState::kDisabled) { |
44 probing_state_ = ProbingState::kInactive; | 47 probing_state_ = ProbingState::kInactive; |
45 LOG(LS_INFO) << "Bandwidth probing enabled, set to inactive"; | 48 LOG(LS_INFO) << "Bandwidth probing enabled, set to inactive"; |
46 } | 49 } |
47 } else { | 50 } else { |
(...skipping 19 matching lines...) Expand all Loading... |
67 } | 70 } |
68 | 71 |
69 void BitrateProber::CreateProbeCluster(int bitrate_bps) { | 72 void BitrateProber::CreateProbeCluster(int bitrate_bps) { |
70 RTC_DCHECK(probing_state_ != ProbingState::kDisabled); | 73 RTC_DCHECK(probing_state_ != ProbingState::kDisabled); |
71 ProbeCluster cluster; | 74 ProbeCluster cluster; |
72 cluster.min_probes = kMinProbePacketsSent; | 75 cluster.min_probes = kMinProbePacketsSent; |
73 cluster.min_bytes = bitrate_bps * kMinProbeDurationMs / 8000; | 76 cluster.min_bytes = bitrate_bps * kMinProbeDurationMs / 8000; |
74 cluster.bitrate_bps = bitrate_bps; | 77 cluster.bitrate_bps = bitrate_bps; |
75 cluster.id = next_cluster_id_++; | 78 cluster.id = next_cluster_id_++; |
76 clusters_.push(cluster); | 79 clusters_.push(cluster); |
77 | |
78 LOG(LS_INFO) << "Probe cluster (bitrate:min bytes:min packets): (" | 80 LOG(LS_INFO) << "Probe cluster (bitrate:min bytes:min packets): (" |
79 << cluster.bitrate_bps << ":" << cluster.min_bytes << ":" | 81 << cluster.bitrate_bps << ":" << cluster.min_bytes << ":" |
80 << cluster.min_probes << ")"; | 82 << cluster.min_probes << ")"; |
81 // If we are already probing, continue to do so. Otherwise set it to | 83 // If we are already probing, continue to do so. Otherwise set it to |
82 // kInactive and wait for OnIncomingPacket to start the probing. | 84 // kInactive and wait for OnIncomingPacket to start the probing. |
83 if (probing_state_ != ProbingState::kActive) | 85 if (probing_state_ != ProbingState::kActive) |
84 probing_state_ = ProbingState::kInactive; | 86 probing_state_ = ProbingState::kInactive; |
| 87 if (cluster_created_observer_) { |
| 88 cluster_created_observer_->OnProbingClusterCreated( |
| 89 cluster.id, cluster.min_bytes, cluster.min_probes); |
| 90 } |
85 } | 91 } |
86 | 92 |
87 void BitrateProber::ResetState() { | 93 void BitrateProber::ResetState() { |
88 // Recreate all probing clusters. | 94 // Recreate all probing clusters. |
89 std::queue<ProbeCluster> clusters; | 95 std::queue<ProbeCluster> clusters; |
90 clusters.swap(clusters_); | 96 clusters.swap(clusters_); |
91 while (!clusters.empty()) { | 97 while (!clusters.empty()) { |
92 CreateProbeCluster(clusters.front().bitrate_bps); | 98 CreateProbeCluster(clusters.front().bitrate_bps); |
93 clusters.pop(); | 99 clusters.pop(); |
94 } | 100 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 | 165 |
160 // Compute the time delta from the cluster start to ensure probe bitrate stays | 166 // Compute the time delta from the cluster start to ensure probe bitrate stays |
161 // close to the target bitrate. Result is in milliseconds. | 167 // close to the target bitrate. Result is in milliseconds. |
162 int64_t delta_ms = (8000ll * cluster.sent_bytes + cluster.bitrate_bps / 2) / | 168 int64_t delta_ms = (8000ll * cluster.sent_bytes + cluster.bitrate_bps / 2) / |
163 cluster.bitrate_bps; | 169 cluster.bitrate_bps; |
164 return cluster.time_started_ms + delta_ms; | 170 return cluster.time_started_ms + delta_ms; |
165 } | 171 } |
166 | 172 |
167 | 173 |
168 } // namespace webrtc | 174 } // namespace webrtc |
OLD | NEW |