1 /* 2 * Copyright (c) 2017 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 "modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator.h" 12 13 #include <stddef.h> 14 15 #include <algorithm> 16 #include <memory> 17 #include <utility> 18 19 #include "rtc_base/checks.h" 20 #include "rtc_base/numerics/safe_conversions.h" 21 22 namespace webrtc { 23 AcknowledgedBitrateEstimator(const WebRtcKeyValueConfig * key_value_config)24AcknowledgedBitrateEstimator::AcknowledgedBitrateEstimator( 25 const WebRtcKeyValueConfig* key_value_config) 26 : AcknowledgedBitrateEstimator( 27 key_value_config, 28 std::make_unique<BitrateEstimator>(key_value_config)) {} 29 ~AcknowledgedBitrateEstimator()30AcknowledgedBitrateEstimator::~AcknowledgedBitrateEstimator() {} 31 AcknowledgedBitrateEstimator(const WebRtcKeyValueConfig * key_value_config,std::unique_ptr<BitrateEstimator> bitrate_estimator)32AcknowledgedBitrateEstimator::AcknowledgedBitrateEstimator( 33 const WebRtcKeyValueConfig* key_value_config, 34 std::unique_ptr<BitrateEstimator> bitrate_estimator) 35 : in_alr_(false), bitrate_estimator_(std::move(bitrate_estimator)) {} 36 IncomingPacketFeedbackVector(const std::vector<PacketResult> & packet_feedback_vector)37void AcknowledgedBitrateEstimator::IncomingPacketFeedbackVector( 38 const std::vector<PacketResult>& packet_feedback_vector) { 39 RTC_DCHECK(std::is_sorted(packet_feedback_vector.begin(), 40 packet_feedback_vector.end(), 41 PacketResult::ReceiveTimeOrder())); 42 for (const auto& packet : packet_feedback_vector) { 43 if (alr_ended_time_ && packet.sent_packet.send_time > *alr_ended_time_) { 44 bitrate_estimator_->ExpectFastRateChange(); 45 alr_ended_time_.reset(); 46 } 47 DataSize acknowledged_estimate = packet.sent_packet.size; 48 acknowledged_estimate += packet.sent_packet.prior_unacked_data; 49 bitrate_estimator_->Update(packet.receive_time, acknowledged_estimate, 50 in_alr_); 51 } 52 } 53 bitrate() const54absl::optional<DataRate> AcknowledgedBitrateEstimator::bitrate() const { 55 return bitrate_estimator_->bitrate(); 56 } 57 PeekRate() const58absl::optional<DataRate> AcknowledgedBitrateEstimator::PeekRate() const { 59 return bitrate_estimator_->PeekRate(); 60 } 61 SetAlrEndedTime(Timestamp alr_ended_time)62void AcknowledgedBitrateEstimator::SetAlrEndedTime(Timestamp alr_ended_time) { 63 alr_ended_time_.emplace(alr_ended_time); 64 } 65 SetAlr(bool in_alr)66void AcknowledgedBitrateEstimator::SetAlr(bool in_alr) { 67 in_alr_ = in_alr; 68 } 69 70 } // namespace webrtc 71