OLD | NEW |
(Empty) | |
| 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 "webrtc/modules/congestion_controller/acknowledged_bitrate_estimator.h" |
| 12 |
| 13 #include <utility> |
| 14 |
| 15 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 16 #include "webrtc/rtc_base/ptr_util.h" |
| 17 |
| 18 namespace webrtc { |
| 19 |
| 20 namespace { |
| 21 bool IsInSendTimeHistory(const PacketFeedback& packet) { |
| 22 return packet.send_time_ms >= 0; |
| 23 } |
| 24 } // namespace |
| 25 |
| 26 AcknowledgedBitrateEstimator::AcknowledgedBitrateEstimator() |
| 27 : AcknowledgedBitrateEstimator(rtc::MakeUnique<BitrateEstimator>()) {} |
| 28 |
| 29 AcknowledgedBitrateEstimator::AcknowledgedBitrateEstimator( |
| 30 std::unique_ptr<BitrateEstimator> bitrate_estimator) |
| 31 : bitrate_estimator_(std::move(bitrate_estimator)) {} |
| 32 |
| 33 void AcknowledgedBitrateEstimator::IncomingPacketFeedbackVector( |
| 34 const std::vector<PacketFeedback>& packet_feedback_vector) { |
| 35 RTC_DCHECK(std::is_sorted(packet_feedback_vector.begin(), |
| 36 packet_feedback_vector.end(), |
| 37 PacketFeedbackComparator())); |
| 38 for (const auto& packet : packet_feedback_vector) { |
| 39 if (IsInSendTimeHistory(packet)) { |
| 40 MaybeExpectFastRateChange(packet.send_time_ms); |
| 41 bitrate_estimator_->Update(packet.arrival_time_ms, packet.payload_size); |
| 42 } |
| 43 } |
| 44 } |
| 45 |
| 46 rtc::Optional<uint32_t> AcknowledgedBitrateEstimator::bitrate_bps() const { |
| 47 return bitrate_estimator_->bitrate_bps(); |
| 48 } |
| 49 |
| 50 void AcknowledgedBitrateEstimator::SetAlrEndedTimeMs( |
| 51 int64_t alr_ended_time_ms) { |
| 52 alr_ended_time_ms_.emplace(alr_ended_time_ms); |
| 53 } |
| 54 |
| 55 void AcknowledgedBitrateEstimator::MaybeExpectFastRateChange( |
| 56 int64_t packet_send_time_ms) { |
| 57 if (alr_ended_time_ms_ && packet_send_time_ms > *alr_ended_time_ms_) { |
| 58 bitrate_estimator_->ExpectFastRateChange(); |
| 59 alr_ended_time_ms_.reset(); |
| 60 } |
| 61 } |
| 62 |
| 63 } // namespace webrtc |
OLD | NEW |