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/base/ptr_util.h" | |
16 #include "webrtc/base/timeutils.h" | |
17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | |
18 | |
19 namespace webrtc { | |
20 | |
21 namespace { | |
22 bool IsInSendTimeHistory(const PacketFeedback& packet) { | |
23 return packet.send_time_ms >= 0; | |
24 } | |
25 } // namespace | |
26 | |
27 std::unique_ptr<BitrateEstimator> BitrateEstimatorCreator::Create() { | |
28 return rtc::MakeUnique<BitrateEstimator>(); | |
29 } | |
30 | |
31 AcknowledgedBitrateEstimator::AcknowledgedBitrateEstimator() | |
32 : AcknowledgedBitrateEstimator(rtc::MakeUnique<BitrateEstimatorCreator>()) { | |
33 } | |
34 | |
35 AcknowledgedBitrateEstimator::AcknowledgedBitrateEstimator( | |
36 std::unique_ptr<BitrateEstimatorCreator> bitrate_estimator_creator) | |
37 : was_in_alr_(false), | |
38 bitrate_estimator_creator_(std::move(bitrate_estimator_creator)), | |
39 bitrate_estimator_(bitrate_estimator_creator_->Create()) {} | |
40 | |
41 void AcknowledgedBitrateEstimator::IncomingPacketFeedbackVector( | |
42 const std::vector<PacketFeedback>& packet_feedback_vector, | |
43 bool currently_in_alr) { | |
44 RTC_DCHECK(std::is_sorted(packet_feedback_vector.begin(), | |
45 packet_feedback_vector.end(), | |
46 PacketFeedbackComparator())); | |
47 MaybeResetBitrateEstimator(currently_in_alr); | |
48 for (const auto& packet : packet_feedback_vector) { | |
49 if (IsInSendTimeHistory(packet) && !SentBeforeAlrEnded(packet)) | |
50 bitrate_estimator_->Update(packet.arrival_time_ms, packet.payload_size); | |
51 } | |
52 } | |
53 | |
54 rtc::Optional<uint32_t> AcknowledgedBitrateEstimator::bitrate_bps() const { | |
55 return bitrate_estimator_->bitrate_bps(); | |
56 } | |
57 | |
58 bool AcknowledgedBitrateEstimator::SentBeforeAlrEnded( | |
59 const PacketFeedback& packet) { | |
60 if (alr_ended_time_ms_) { | |
61 if (*alr_ended_time_ms_ > packet.send_time_ms) { | |
62 return true; | |
63 } | |
64 } | |
65 return false; | |
66 } | |
67 | |
68 bool AcknowledgedBitrateEstimator::AlrEnded(bool currently_in_alr) const { | |
69 return was_in_alr_ && !currently_in_alr; | |
70 } | |
71 | |
72 void AcknowledgedBitrateEstimator::MaybeResetBitrateEstimator( | |
73 bool currently_in_alr) { | |
74 if (AlrEnded(currently_in_alr)) { | |
75 bitrate_estimator_ = bitrate_estimator_creator_->Create(); | |
76 alr_ended_time_ms_ = rtc::Optional<int64_t>(rtc::TimeMillis()); | |
77 } | |
78 was_in_alr_ = currently_in_alr; | |
79 } | |
80 | |
81 } // namespace webrtc | |
OLD | NEW |