blob: 223c4769e6198294d4b8cd97c1ac694a006c8799 [file] [log] [blame]
tschumim9d117642017-07-17 01:41:41 -07001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/congestion_controller/acknowledged_bitrate_estimator.h"
tschumim9d117642017-07-17 01:41:41 -070012
13#include <utility>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
16#include "rtc_base/ptr_util.h"
tschumim9d117642017-07-17 01:41:41 -070017
18namespace webrtc {
19
20namespace {
21bool IsInSendTimeHistory(const PacketFeedback& packet) {
22 return packet.send_time_ms >= 0;
23}
24} // namespace
25
26AcknowledgedBitrateEstimator::AcknowledgedBitrateEstimator()
27 : AcknowledgedBitrateEstimator(rtc::MakeUnique<BitrateEstimator>()) {}
28
29AcknowledgedBitrateEstimator::AcknowledgedBitrateEstimator(
30 std::unique_ptr<BitrateEstimator> bitrate_estimator)
31 : bitrate_estimator_(std::move(bitrate_estimator)) {}
32
33void 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
46rtc::Optional<uint32_t> AcknowledgedBitrateEstimator::bitrate_bps() const {
47 return bitrate_estimator_->bitrate_bps();
48}
49
50void AcknowledgedBitrateEstimator::SetAlrEndedTimeMs(
51 int64_t alr_ended_time_ms) {
52 alr_ended_time_ms_.emplace(alr_ended_time_ms);
53}
54
55void 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