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 AcknowledgedBitrateEstimator::AcknowledgedBitrateEstimator() | |
28 : AcknowledgedBitrateEstimator(rtc::MakeUnique<BitrateEstimator>()) {} | |
29 | |
30 AcknowledgedBitrateEstimator::AcknowledgedBitrateEstimator( | |
31 std::unique_ptr<BitrateEstimator> bitrate_estimator) | |
32 : bitrate_estimator_(std::move(bitrate_estimator)) {} | |
33 | |
34 void AcknowledgedBitrateEstimator::IncomingPacketFeedbackVector( | |
35 const std::vector<PacketFeedback>& packet_feedback_vector, | |
36 bool currently_in_alr) { | |
37 RTC_DCHECK(std::is_sorted(packet_feedback_vector.begin(), | |
38 packet_feedback_vector.end(), | |
39 PacketFeedbackComparator())); | |
40 CheckAlrEndTime(currently_in_alr); | |
41 for (const auto& packet : packet_feedback_vector) { | |
42 if (IsInSendTimeHistory(packet)) { | |
43 MaybeExpectFastRateChange(packet.send_time_ms); | |
44 bitrate_estimator_->Update(packet.arrival_time_ms, packet.payload_size); | |
45 } | |
46 } | |
47 } | |
48 | |
49 rtc::Optional<uint32_t> AcknowledgedBitrateEstimator::bitrate_bps() const { | |
50 return bitrate_estimator_->bitrate_bps(); | |
51 } | |
52 | |
53 bool AcknowledgedBitrateEstimator::AlrEnded(bool currently_in_alr) const { | |
54 return was_in_alr_time_ms_ && !currently_in_alr; | |
55 } | |
56 | |
57 void AcknowledgedBitrateEstimator::CheckAlrEndTime(bool currently_in_alr) { | |
terelius
2017/07/11 20:54:19
How about
bool currently_in_alr = pacer->GetAlrSta
tschumi
2017/07/13 09:05:07
Impl. according to offline discussion.
| |
58 if (AlrEnded(currently_in_alr)) { | |
59 alr_ended_time_ms_ = was_in_alr_time_ms_; | |
60 } | |
61 was_in_alr_time_ms_ = currently_in_alr | |
62 ? rtc::Optional<int64_t>(rtc::TimeMillis()) | |
63 : rtc::Optional<int64_t>(); | |
64 } | |
65 | |
66 void AcknowledgedBitrateEstimator::MaybeExpectFastRateChange( | |
terelius
2017/07/11 20:54:19
Maybe inline this function? (It is important that
tschumi
2017/07/13 09:05:07
:)
I prefer it this way.
| |
67 int64_t packet_send_time_ms) { | |
68 if (alr_ended_time_ms_ && packet_send_time_ms > *alr_ended_time_ms_) { | |
69 bitrate_estimator_->ExpectFastRateChange(); | |
70 alr_ended_time_ms_.reset(); | |
71 } | |
72 } | |
73 | |
74 } // namespace webrtc | |
OLD | NEW |