| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 } | 81 } |
| 82 | 82 |
| 83 void BitrateProber::CreateProbeCluster(int bitrate_bps, int64_t now_ms) { | 83 void BitrateProber::CreateProbeCluster(int bitrate_bps, int64_t now_ms) { |
| 84 RTC_DCHECK(probing_state_ != ProbingState::kDisabled); | 84 RTC_DCHECK(probing_state_ != ProbingState::kDisabled); |
| 85 while (!clusters_.empty() && | 85 while (!clusters_.empty() && |
| 86 now_ms - clusters_.front().time_created_ms > kProbeClusterTimeoutMs) { | 86 now_ms - clusters_.front().time_created_ms > kProbeClusterTimeoutMs) { |
| 87 clusters_.pop(); | 87 clusters_.pop(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 ProbeCluster cluster; | 90 ProbeCluster cluster; |
| 91 cluster.min_probes = kMinProbePacketsSent; | |
| 92 cluster.min_bytes = bitrate_bps * kMinProbeDurationMs / 8000; | |
| 93 cluster.bitrate_bps = bitrate_bps; | |
| 94 cluster.time_created_ms = now_ms; | 91 cluster.time_created_ms = now_ms; |
| 95 cluster.id = next_cluster_id_++; | 92 cluster.pace_info.probe_cluster_min_probes = kMinProbePacketsSent; |
| 93 cluster.pace_info.probe_cluster_min_bytes = |
| 94 bitrate_bps * kMinProbeDurationMs / 8000; |
| 95 cluster.pace_info.send_bitrate_bps = bitrate_bps; |
| 96 cluster.pace_info.probe_cluster_id = next_cluster_id_++; |
| 96 clusters_.push(cluster); | 97 clusters_.push(cluster); |
| 97 | 98 |
| 98 LOG(LS_INFO) << "Probe cluster (bitrate:min bytes:min packets): (" | 99 LOG(LS_INFO) << "Probe cluster (bitrate:min bytes:min packets): (" |
| 99 << cluster.bitrate_bps << ":" << cluster.min_bytes << ":" | 100 << cluster.pace_info.send_bitrate_bps << ":" |
| 100 << cluster.min_probes << ")"; | 101 << cluster.pace_info.probe_cluster_min_bytes << ":" |
| 102 << cluster.pace_info.probe_cluster_min_probes << ")"; |
| 101 // If we are already probing, continue to do so. Otherwise set it to | 103 // If we are already probing, continue to do so. Otherwise set it to |
| 102 // kInactive and wait for OnIncomingPacket to start the probing. | 104 // kInactive and wait for OnIncomingPacket to start the probing. |
| 103 if (probing_state_ != ProbingState::kActive) | 105 if (probing_state_ != ProbingState::kActive) |
| 104 probing_state_ = ProbingState::kInactive; | 106 probing_state_ = ProbingState::kInactive; |
| 105 } | 107 } |
| 106 | 108 |
| 107 void BitrateProber::ResetState(int64_t now_ms) { | 109 void BitrateProber::ResetState(int64_t now_ms) { |
| 108 RTC_DCHECK(probing_state_ == ProbingState::kActive); | 110 RTC_DCHECK(probing_state_ == ProbingState::kActive); |
| 109 | 111 |
| 110 // Recreate all probing clusters. | 112 // Recreate all probing clusters. |
| 111 std::queue<ProbeCluster> clusters; | 113 std::queue<ProbeCluster> clusters; |
| 112 clusters.swap(clusters_); | 114 clusters.swap(clusters_); |
| 113 while (!clusters.empty()) { | 115 while (!clusters.empty()) { |
| 114 if (clusters.front().retries < kMaxRetryAttempts) { | 116 if (clusters.front().retries < kMaxRetryAttempts) { |
| 115 CreateProbeCluster(clusters.front().bitrate_bps, now_ms); | 117 CreateProbeCluster(clusters.front().pace_info.send_bitrate_bps, now_ms); |
| 116 clusters_.back().retries = clusters.front().retries + 1; | 118 clusters_.back().retries = clusters.front().retries + 1; |
| 117 } | 119 } |
| 118 clusters.pop(); | 120 clusters.pop(); |
| 119 } | 121 } |
| 120 | 122 |
| 121 probing_state_ = ProbingState::kInactive; | 123 probing_state_ = ProbingState::kInactive; |
| 122 } | 124 } |
| 123 | 125 |
| 124 int BitrateProber::TimeUntilNextProbe(int64_t now_ms) { | 126 int BitrateProber::TimeUntilNextProbe(int64_t now_ms) { |
| 125 // Probing is not active or probing is already complete. | 127 // Probing is not active or probing is already complete. |
| 126 if (probing_state_ != ProbingState::kActive || clusters_.empty()) | 128 if (probing_state_ != ProbingState::kActive || clusters_.empty()) |
| 127 return -1; | 129 return -1; |
| 128 | 130 |
| 129 int time_until_probe_ms = 0; | 131 int time_until_probe_ms = 0; |
| 130 if (next_probe_time_ms_ >= 0) { | 132 if (next_probe_time_ms_ >= 0) { |
| 131 time_until_probe_ms = next_probe_time_ms_ - now_ms; | 133 time_until_probe_ms = next_probe_time_ms_ - now_ms; |
| 132 if (time_until_probe_ms < -kMaxProbeDelayMs) { | 134 if (time_until_probe_ms < -kMaxProbeDelayMs) { |
| 133 ResetState(now_ms); | 135 ResetState(now_ms); |
| 134 return -1; | 136 return -1; |
| 135 } | 137 } |
| 136 } | 138 } |
| 137 | 139 |
| 138 return std::max(time_until_probe_ms, 0); | 140 return std::max(time_until_probe_ms, 0); |
| 139 } | 141 } |
| 140 | 142 |
| 141 int BitrateProber::CurrentClusterId() const { | 143 PacedPacketInfo BitrateProber::CurrentCluster() const { |
| 142 RTC_DCHECK(!clusters_.empty()); | 144 RTC_DCHECK(!clusters_.empty()); |
| 143 RTC_DCHECK(ProbingState::kActive == probing_state_); | 145 RTC_DCHECK(ProbingState::kActive == probing_state_); |
| 144 return clusters_.front().id; | 146 return clusters_.front().pace_info; |
| 145 } | 147 } |
| 146 | 148 |
| 147 // Probe size is recommended based on the probe bitrate required. We choose | 149 // Probe size is recommended based on the probe bitrate required. We choose |
| 148 // a minimum of twice |kMinProbeDeltaMs| interval to allow scheduling to be | 150 // a minimum of twice |kMinProbeDeltaMs| interval to allow scheduling to be |
| 149 // feasible. | 151 // feasible. |
| 150 size_t BitrateProber::RecommendedMinProbeSize() const { | 152 size_t BitrateProber::RecommendedMinProbeSize() const { |
| 151 RTC_DCHECK(!clusters_.empty()); | 153 RTC_DCHECK(!clusters_.empty()); |
| 152 return clusters_.front().bitrate_bps * 2 * kMinProbeDeltaMs / (8 * 1000); | 154 return clusters_.front().pace_info.send_bitrate_bps * 2 * kMinProbeDeltaMs / |
| 155 (8 * 1000); |
| 153 } | 156 } |
| 154 | 157 |
| 155 void BitrateProber::ProbeSent(int64_t now_ms, size_t bytes) { | 158 void BitrateProber::ProbeSent(int64_t now_ms, size_t bytes) { |
| 156 RTC_DCHECK(probing_state_ == ProbingState::kActive); | 159 RTC_DCHECK(probing_state_ == ProbingState::kActive); |
| 157 RTC_DCHECK_GT(bytes, 0); | 160 RTC_DCHECK_GT(bytes, 0); |
| 158 | 161 |
| 159 if (!clusters_.empty()) { | 162 if (!clusters_.empty()) { |
| 160 ProbeCluster* cluster = &clusters_.front(); | 163 ProbeCluster* cluster = &clusters_.front(); |
| 161 if (cluster->sent_probes == 0) { | 164 if (cluster->sent_probes == 0) { |
| 162 RTC_DCHECK_EQ(cluster->time_started_ms, -1); | 165 RTC_DCHECK_EQ(cluster->time_started_ms, -1); |
| 163 cluster->time_started_ms = now_ms; | 166 cluster->time_started_ms = now_ms; |
| 164 } | 167 } |
| 165 cluster->sent_bytes += static_cast<int>(bytes); | 168 cluster->sent_bytes += static_cast<int>(bytes); |
| 166 cluster->sent_probes += 1; | 169 cluster->sent_probes += 1; |
| 167 next_probe_time_ms_ = GetNextProbeTime(clusters_.front()); | 170 next_probe_time_ms_ = GetNextProbeTime(clusters_.front()); |
| 168 if (cluster->sent_bytes >= cluster->min_bytes && | 171 if (cluster->sent_bytes >= cluster->pace_info.probe_cluster_min_bytes && |
| 169 cluster->sent_probes >= cluster->min_probes) { | 172 cluster->sent_probes >= cluster->pace_info.probe_cluster_min_probes) { |
| 170 clusters_.pop(); | 173 clusters_.pop(); |
| 171 } | 174 } |
| 172 if (clusters_.empty()) | 175 if (clusters_.empty()) |
| 173 probing_state_ = ProbingState::kSuspended; | 176 probing_state_ = ProbingState::kSuspended; |
| 174 } | 177 } |
| 175 } | 178 } |
| 176 | 179 |
| 177 int64_t BitrateProber::GetNextProbeTime(const ProbeCluster& cluster) { | 180 int64_t BitrateProber::GetNextProbeTime(const ProbeCluster& cluster) { |
| 178 RTC_CHECK_GT(cluster.bitrate_bps, 0); | 181 RTC_CHECK_GT(cluster.pace_info.send_bitrate_bps, 0); |
| 179 RTC_CHECK_GE(cluster.time_started_ms, 0); | 182 RTC_CHECK_GE(cluster.time_started_ms, 0); |
| 180 | 183 |
| 181 // Compute the time delta from the cluster start to ensure probe bitrate stays | 184 // Compute the time delta from the cluster start to ensure probe bitrate stays |
| 182 // close to the target bitrate. Result is in milliseconds. | 185 // close to the target bitrate. Result is in milliseconds. |
| 183 int64_t delta_ms = (8000ll * cluster.sent_bytes + cluster.bitrate_bps / 2) / | 186 int64_t delta_ms = |
| 184 cluster.bitrate_bps; | 187 (8000ll * cluster.sent_bytes + cluster.pace_info.send_bitrate_bps / 2) / |
| 188 cluster.pace_info.send_bitrate_bps; |
| 185 return cluster.time_started_ms + delta_ms; | 189 return cluster.time_started_ms + delta_ms; |
| 186 } | 190 } |
| 187 | 191 |
| 188 | 192 |
| 189 } // namespace webrtc | 193 } // namespace webrtc |
| OLD | NEW |