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 : last_alr_state_(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 alr_state) { |
| 43 RTC_DCHECK(std::is_sorted(packet_feedback_vector.begin(), |
| 44 packet_feedback_vector.end(), |
| 45 PacketFeedbackComparator())); |
| 46 MaybeResetBitrateEstimator(alr_state); |
| 47 for (const auto& packet : packet_feedback_vector) { |
| 48 if (IsInSendTimeHistory(packet) && !SentBeforLeftAlr(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::SentBeforLeftAlr( |
| 58 const PacketFeedback& packet) { |
| 59 if (left_alr_state_ms_) { |
| 60 if (*left_alr_state_ms_ > packet.send_time_ms) { |
| 61 return true; |
| 62 } else { |
| 63 left_alr_state_ms_.reset(); |
| 64 } |
| 65 } |
| 66 return false; |
| 67 } |
| 68 |
| 69 bool AcknowledgedBitrateEstimator::HasLeftAlrState(bool alr_state) const { |
| 70 return last_alr_state_ && !alr_state; |
| 71 } |
| 72 |
| 73 void AcknowledgedBitrateEstimator::MaybeResetBitrateEstimator(bool alr_state) { |
| 74 if (HasLeftAlrState(alr_state)) { |
| 75 bitrate_estimator_ = bitrate_estimator_creator_->Create(); |
| 76 left_alr_state_ms_ = rtc::Optional<int64_t>(rtc::TimeMillis()); |
| 77 } |
| 78 last_alr_state_ = alr_state; |
| 79 } |
| 80 |
| 81 } // namespace webrtc |
OLD | NEW |