| 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 <algorithm> | 13 #include <algorithm> | 
| 14 | 14 | 
| 15 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" | 
| 16 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" | 
|  | 17 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" | 
| 17 #include "webrtc/modules/pacing/paced_sender.h" | 18 #include "webrtc/modules/pacing/paced_sender.h" | 
| 18 | 19 | 
| 19 namespace webrtc { | 20 namespace webrtc { | 
| 20 | 21 | 
| 21 namespace { | 22 namespace { | 
| 22 | 23 | 
| 23 // A minimum interval between probes to allow scheduling to be feasible. | 24 // A minimum interval between probes to allow scheduling to be feasible. | 
| 24 constexpr int kMinProbeDeltaMs = 1; | 25 constexpr int kMinProbeDeltaMs = 1; | 
| 25 | 26 | 
| 26 // The minimum number probing packets used. | 27 // The minimum number probing packets used. | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 38 | 39 | 
| 39 // The min probe packet size is scaled with the bitrate we're probing at. | 40 // The min probe packet size is scaled with the bitrate we're probing at. | 
| 40 // This defines the max min probe packet size, meaning that on high bitrates | 41 // This defines the max min probe packet size, meaning that on high bitrates | 
| 41 // we have a min probe packet size of 200 bytes. | 42 // we have a min probe packet size of 200 bytes. | 
| 42 constexpr size_t kMinProbePacketSize = 200; | 43 constexpr size_t kMinProbePacketSize = 200; | 
| 43 | 44 | 
| 44 constexpr int64_t kProbeClusterTimeoutMs = 5000; | 45 constexpr int64_t kProbeClusterTimeoutMs = 5000; | 
| 45 | 46 | 
| 46 }  // namespace | 47 }  // namespace | 
| 47 | 48 | 
| 48 BitrateProber::BitrateProber() | 49 BitrateProber::BitrateProber() : BitrateProber(nullptr) {} | 
|  | 50 | 
|  | 51 BitrateProber::BitrateProber(RtcEventLog* event_log) | 
| 49     : probing_state_(ProbingState::kDisabled), | 52     : probing_state_(ProbingState::kDisabled), | 
| 50       next_probe_time_ms_(-1), | 53       next_probe_time_ms_(-1), | 
| 51       next_cluster_id_(0) { | 54       next_cluster_id_(0), | 
|  | 55       event_log_(event_log) { | 
| 52   SetEnabled(true); | 56   SetEnabled(true); | 
| 53 } | 57 } | 
| 54 | 58 | 
| 55 void BitrateProber::SetEnabled(bool enable) { | 59 void BitrateProber::SetEnabled(bool enable) { | 
| 56   if (enable) { | 60   if (enable) { | 
| 57     if (probing_state_ == ProbingState::kDisabled) { | 61     if (probing_state_ == ProbingState::kDisabled) { | 
| 58       probing_state_ = ProbingState::kInactive; | 62       probing_state_ = ProbingState::kInactive; | 
| 59       LOG(LS_INFO) << "Bandwidth probing enabled, set to inactive"; | 63       LOG(LS_INFO) << "Bandwidth probing enabled, set to inactive"; | 
| 60     } | 64     } | 
| 61   } else { | 65   } else { | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
| 88   } | 92   } | 
| 89 | 93 | 
| 90   ProbeCluster cluster; | 94   ProbeCluster cluster; | 
| 91   cluster.time_created_ms = now_ms; | 95   cluster.time_created_ms = now_ms; | 
| 92   cluster.pace_info.probe_cluster_min_probes = kMinProbePacketsSent; | 96   cluster.pace_info.probe_cluster_min_probes = kMinProbePacketsSent; | 
| 93   cluster.pace_info.probe_cluster_min_bytes = | 97   cluster.pace_info.probe_cluster_min_bytes = | 
| 94       bitrate_bps * kMinProbeDurationMs / 8000; | 98       bitrate_bps * kMinProbeDurationMs / 8000; | 
| 95   cluster.pace_info.send_bitrate_bps = bitrate_bps; | 99   cluster.pace_info.send_bitrate_bps = bitrate_bps; | 
| 96   cluster.pace_info.probe_cluster_id = next_cluster_id_++; | 100   cluster.pace_info.probe_cluster_id = next_cluster_id_++; | 
| 97   clusters_.push(cluster); | 101   clusters_.push(cluster); | 
|  | 102   if (event_log_) | 
|  | 103     event_log_->LogProbeClusterCreated( | 
|  | 104         cluster.pace_info.probe_cluster_id, cluster.pace_info.send_bitrate_bps, | 
|  | 105         cluster.pace_info.probe_cluster_min_probes, | 
|  | 106         cluster.pace_info.probe_cluster_min_bytes); | 
| 98 | 107 | 
| 99   LOG(LS_INFO) << "Probe cluster (bitrate:min bytes:min packets): (" | 108   LOG(LS_INFO) << "Probe cluster (bitrate:min bytes:min packets): (" | 
| 100                << cluster.pace_info.send_bitrate_bps << ":" | 109                << cluster.pace_info.send_bitrate_bps << ":" | 
| 101                << cluster.pace_info.probe_cluster_min_bytes << ":" | 110                << cluster.pace_info.probe_cluster_min_bytes << ":" | 
| 102                << cluster.pace_info.probe_cluster_min_probes << ")"; | 111                << cluster.pace_info.probe_cluster_min_probes << ")"; | 
| 103   // If we are already probing, continue to do so. Otherwise set it to | 112   // If we are already probing, continue to do so. Otherwise set it to | 
| 104   // kInactive and wait for OnIncomingPacket to start the probing. | 113   // kInactive and wait for OnIncomingPacket to start the probing. | 
| 105   if (probing_state_ != ProbingState::kActive) | 114   if (probing_state_ != ProbingState::kActive) | 
| 106     probing_state_ = ProbingState::kInactive; | 115     probing_state_ = ProbingState::kInactive; | 
| 107 } | 116 } | 
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 184   // Compute the time delta from the cluster start to ensure probe bitrate stays | 193   // Compute the time delta from the cluster start to ensure probe bitrate stays | 
| 185   // close to the target bitrate. Result is in milliseconds. | 194   // close to the target bitrate. Result is in milliseconds. | 
| 186   int64_t delta_ms = | 195   int64_t delta_ms = | 
| 187       (8000ll * cluster.sent_bytes + cluster.pace_info.send_bitrate_bps / 2) / | 196       (8000ll * cluster.sent_bytes + cluster.pace_info.send_bitrate_bps / 2) / | 
| 188       cluster.pace_info.send_bitrate_bps; | 197       cluster.pace_info.send_bitrate_bps; | 
| 189   return cluster.time_started_ms + delta_ms; | 198   return cluster.time_started_ms + delta_ms; | 
| 190 } | 199 } | 
| 191 | 200 | 
| 192 | 201 | 
| 193 }  // namespace webrtc | 202 }  // namespace webrtc | 
| OLD | NEW | 
|---|