Chromium Code Reviews| Index: webrtc/modules/remote_bitrate_estimator/test/estimators/bbr.cc |
| diff --git a/webrtc/modules/remote_bitrate_estimator/test/estimators/bbr.cc b/webrtc/modules/remote_bitrate_estimator/test/estimators/bbr.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9d4a713bf1a642a406862ba1b76280363f72a694 |
| --- /dev/null |
| +++ b/webrtc/modules/remote_bitrate_estimator/test/estimators/bbr.cc |
| @@ -0,0 +1,168 @@ |
| +/* |
| + * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + * |
| + */ |
| + |
| +#include "webrtc/modules/remote_bitrate_estimator/test/estimators/bbr.h" |
| +#include <time.h> |
| +#include <algorithm> |
| +#include <utility> |
| + |
| +#include "webrtc/base/logging.h" |
| + |
|
philipel
2017/05/29 09:38:50
Please fix includes according to the style guide:
gnish2
2017/05/29 11:04:26
Done.
|
| +#include "webrtc/modules/congestion_controller/delay_based_bwe.h" |
| +#include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h" |
| + |
| +namespace webrtc { |
| +namespace testing { |
| +namespace bwe { |
| +namespace { |
| +const float kHighGain = 2.885f; |
| +const float kDrainGain = 1.f / kHighGain; |
| +} |
| +const int kFeedbackIntervals = 100; |
|
philipel
2017/05/29 09:38:49
Move into anonymous namespace.
philipel
2017/05/29 09:38:49
Add empty line between 29-30
gnish2
2017/05/29 11:04:26
Done.
gnish2
2017/05/29 11:04:26
Done.
|
| +BbrBweSender::BbrBweSender(int kbps, BitrateObserver* observer, Clock* clock) |
| + : BweSender(kbps), |
| + clock_(clock), |
| + observer_(observer), |
| + send_time_(), |
| + mode_(STARTUP), |
| + stats_(), |
| + round_trip_end_(0), |
| + rt_count_(0), |
| + last_packet_sent_(0) { |
| + // Initially enter Startup mode. |
| + EnterStartup(); |
| +} |
| + |
| +BbrBweSender::~BbrBweSender() {} |
| + |
| +int BbrBweSender::GetFeedbackIntervalMs() const { |
| + return kFeedbackIntervals; |
| +} |
| + |
| +int BbrBweSender::GetPacketSize(uint64_t sequence_number) { |
| + return 0; |
| +} |
| + |
| +void BbrBweSender::GiveFeedback(const FeedbackPacket& feedback) { |
| + bool min_rtt_expired = false; |
| + int now = clock_->TimeInMilliseconds(); |
| + int64_t bytes_acked = 0; |
| + const BbrBweFeedback& fb = static_cast<const BbrBweFeedback&>(feedback); |
| + const std::vector<std::pair<uint64_t, int64_t> >& feedback_vector = |
|
philipel
2017/05/29 09:38:49
remove whitespace
gnish2
2017/05/29 11:04:26
Done.
|
| + fb.packet_feedback_vector(); |
| + // Calculate number of bytes acknowledged after the feedback. |
| + for (const auto& feedback : feedback_vector) { |
| + bytes_acked += GetPacketSize(feedback.first); |
| + } |
| + // Update bandwidth and min_rtt estimates,also |
| + // check if current min_rtt estimate expired or not. |
| + min_rtt_expired = UpdateBandwidthAndMinRtt(now, feedback_vector, bytes_acked); |
| + // If it did enter ProbeRtt mode. |
| + if (min_rtt_expired) { |
| + EnterProbeRtt(now); |
| + } |
| + // This switch checks whether it is time or not to exit |
| + // the current mode we are in. |
| + switch (mode_) { |
| + case STARTUP: |
| + TryExitingStartup(); |
| + break; |
| + case DRAIN: |
| + TryExitingDrain(now); |
| + break; |
| + case PROBE_BW: |
| + TryUpdatingCyclePhase(now); |
| + break; |
| + case PROBE_RTT: |
| + TryExitingProbeRtt(now); |
| + break; |
| + } |
| + |
| + // Update pacing rate and congestion window values. |
| + // TODO(gnish): Implement CalculatePacingRate() and |
| + // CalculateCongestionWindow() functions. |
| + stats_->CalculatePacingRate(); |
| + stats_->CalculateCongestionWindow(); |
| +} |
| + |
| +bool BbrBweSender::UpdateBandwidthAndMinRtt( |
| + int64_t now, |
| + const std::vector<std::pair<uint64_t, int64_t> >& feedback_vector, |
| + int64_t bytes_acked) { |
| + return false; |
| +} |
| + |
| +void BbrBweSender::EnterStartup() { |
| + mode_ = STARTUP; |
| + stats_->set_pacing_gain(kHighGain); |
| +} |
| + |
| +void BbrBweSender::TryExitingStartup() { |
| + // If delivery rate hasn't grown |
| + // switch to Drain mode. |
| + // TODO(gnish): Implement DeliveryRateGrows() |
| + if (!stats_->DeliveryRateGrows()) { |
| + mode_ = DRAIN; |
| + stats_->set_pacing_gain(kDrainGain); |
| + } |
| +} |
| + |
| +void BbrBweSender::TryExitingDrain(int64_t now) {} |
| + |
| +void BbrBweSender::EnterProbeBw(int64_t now) {} |
| + |
| +void BbrBweSender::TryUpdatingCyclePhase(int64_t now) {} |
| + |
| +void BbrBweSender::EnterProbeRtt(int64_t now) {} |
| + |
| +void BbrBweSender::TryExitingProbeRtt(int64_t now) {} |
| + |
| +int64_t BbrBweSender::TimeUntilNextProcess() { |
| + return 100; |
| +} |
| + |
| +void BbrBweSender::OnPacketsSent(const Packets& packets) {} |
| + |
| +void BbrBweSender::Process() {} |
| + |
| +BbrBweReceiver::BbrBweReceiver(int flow_id) |
| + : BweReceiver(flow_id, kReceivingRateTimeWindowMs), |
| + last_feedback_ms_(0), |
| + clock_(0), |
| + packet_feedbacks_() {} |
| + |
| +BbrBweReceiver::~BbrBweReceiver() {} |
| + |
| +void BbrBweReceiver::ReceivePacket(int64_t arrival_time_ms, |
| + const MediaPacket& media_packet) { |
| + packet_feedbacks_.push_back( |
| + {media_packet.sequence_number(), arrival_time_ms}); |
| + BweReceiver::ReceivePacket(arrival_time_ms, media_packet); |
| +} |
| + |
| +FeedbackPacket* BbrBweReceiver::GetFeedback(int64_t now_ms) { |
| + if (now_ms - last_feedback_ms_ < kFeedbackIntervals) |
| + return NULL; |
| + last_feedback_ms_ = now_ms; |
| + int64_t corrected_send_time_ms = 0L; |
| + if (!received_packets_.empty()) { |
| + PacketIdentifierNode* latest = *(received_packets_.begin()); |
| + corrected_send_time_ms = |
| + latest->send_time_ms + now_ms - latest->arrival_time_ms; |
| + } |
| + FeedbackPacket* fb = new BbrBweFeedback( |
| + flow_id_, now_ms * 1000, corrected_send_time_ms, packet_feedbacks_); |
| + packet_feedbacks_.clear(); |
| + return fb; |
| +} |
| +} // namespace bwe |
| +} // namespace testing |
| +} // namespace webrtc |