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() const { | |
28 return rtc::MakeUnique<BitrateEstimator>(); | |
29 } | |
30 | |
31 AcknowledgedBitrateEstimator::AcknowledgedBitrateEstimator( | |
32 std::unique_ptr<BitrateEstimatorCreator> bitrate_estimator_creator) | |
33 : was_in_alr_(false), | |
34 bitrate_estimator_creator_( | |
35 bitrate_estimator_creator | |
36 ? std::move(bitrate_estimator_creator) | |
37 : rtc::MakeUnique<BitrateEstimatorCreator>()), | |
38 bitrate_estimator_(bitrate_estimator_creator_->Create()) {} | |
39 | |
40 void AcknowledgedBitrateEstimator::IncomingPacketFeedbackVector( | |
41 const std::vector<PacketFeedback>& packet_feedback_vector, | |
42 bool currently_in_alr) { | |
43 RTC_DCHECK(std::is_sorted(packet_feedback_vector.begin(), | |
44 packet_feedback_vector.end(), | |
45 PacketFeedbackComparator())); | |
46 MaybeResetBitrateEstimator(currently_in_alr); | |
47 for (const auto& packet : packet_feedback_vector) { | |
48 if (IsInSendTimeHistory(packet) && !SentBeforeAlrEnded(packet)) | |
49 bitrate_estimator_->Update(packet.arrival_time_ms, packet.payload_size); | |
50 } | |
51 } | |
52 | |
53 rtc::Optional<uint32_t> AcknowledgedBitrateEstimator::bitrate_bps() const { | |
54 return bitrate_estimator_->bitrate_bps(); | |
55 } | |
56 | |
57 bool AcknowledgedBitrateEstimator::SentBeforeAlrEnded( | |
58 const PacketFeedback& packet) { | |
59 if (alr_ended_time_ms_) { | |
60 if (*alr_ended_time_ms_ > packet.send_time_ms) { | |
61 return true; | |
62 } else { | |
63 alr_ended_time_ms_.reset(); | |
philipel
2017/06/14 09:34:05
What happens if feedback messages are reordered? W
tschumi
2017/06/14 10:57:46
Right, this reset is kind of senseless.
| |
64 } | |
65 } | |
66 return false; | |
67 } | |
68 | |
69 bool AcknowledgedBitrateEstimator::AlrEnded(bool currently_in_alr) const { | |
70 return was_in_alr_ && !currently_in_alr; | |
71 } | |
72 | |
73 void AcknowledgedBitrateEstimator::MaybeResetBitrateEstimator( | |
74 bool currently_in_alr) { | |
75 if (AlrEnded(currently_in_alr)) { | |
76 bitrate_estimator_ = bitrate_estimator_creator_->Create(); | |
77 alr_ended_time_ms_ = rtc::Optional<int64_t>(rtc::TimeMillis()); | |
78 } | |
79 was_in_alr_ = currently_in_alr; | |
80 } | |
81 | |
82 } // namespace webrtc | |
OLD | NEW |