Chromium Code Reviews| 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 | |
| 12 #include <time.h> | |
| 13 #include <algorithm> | |
| 14 #include <utility> | |
| 15 | |
| 16 #include "webrtc/base/logging.h" | |
| 17 #include "webrtc/modules/remote_bitrate_estimator/test/estimators/bbr.h" | |
|
philipel
2017/05/29 11:48:21
This should be on top
| |
| 18 #include "webrtc/modules/congestion_controller/delay_based_bwe.h" | |
| 19 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h" | |
| 20 | |
| 21 namespace webrtc { | |
| 22 namespace testing { | |
| 23 namespace bwe { | |
| 24 namespace { | |
| 25 const float kHighGain = 2.885f; | |
| 26 const float kDrainGain = 1.f / kHighGain; | |
| 27 const int kFeedbackIntervals = 100; | |
| 28 } | |
| 29 | |
| 30 BbrBweSender::BbrBweSender(int kbps, BitrateObserver* observer, Clock* clock) | |
| 31 : BweSender(kbps), | |
| 32 clock_(clock), | |
| 33 observer_(observer), | |
| 34 send_time_(), | |
| 35 mode_(STARTUP), | |
| 36 stats_(), | |
| 37 round_trip_end_(0), | |
| 38 rt_count_(0), | |
| 39 last_packet_sent_(0) { | |
| 40 // Initially enter Startup mode. | |
| 41 EnterStartup(); | |
| 42 } | |
| 43 | |
| 44 BbrBweSender::~BbrBweSender() {} | |
| 45 | |
| 46 int BbrBweSender::GetFeedbackIntervalMs() const { | |
| 47 return kFeedbackIntervals; | |
| 48 } | |
| 49 | |
| 50 int BbrBweSender::GetPacketSize(uint64_t sequence_number) { | |
| 51 return 0; | |
| 52 } | |
| 53 | |
| 54 void BbrBweSender::GiveFeedback(const FeedbackPacket& feedback) { | |
| 55 bool min_rtt_expired = false; | |
| 56 int now = clock_->TimeInMilliseconds(); | |
| 57 int64_t bytes_acked = 0; | |
| 58 const BbrBweFeedback& fb = static_cast<const BbrBweFeedback&>(feedback); | |
| 59 const std::vector<std::pair<uint64_t, int64_t>>& feedback_vector = | |
| 60 fb.packet_feedback_vector(); | |
| 61 // Calculate number of bytes acknowledged after the feedback. | |
| 62 for (const auto& feedback : feedback_vector) { | |
| 63 bytes_acked += GetPacketSize(feedback.first); | |
| 64 } | |
| 65 // Update bandwidth and min_rtt estimates,also | |
| 66 // check if current min_rtt estimate expired or not. | |
| 67 min_rtt_expired = UpdateBandwidthAndMinRtt(now, feedback_vector, bytes_acked); | |
| 68 // If it did enter ProbeRtt mode. | |
| 69 if (min_rtt_expired) { | |
| 70 EnterProbeRtt(now); | |
| 71 } | |
| 72 // This switch checks whether it is time or not to exit | |
| 73 // the current mode we are in. | |
| 74 switch (mode_) { | |
| 75 case STARTUP: | |
| 76 TryExitingStartup(); | |
| 77 break; | |
| 78 case DRAIN: | |
| 79 TryExitingDrain(now); | |
| 80 break; | |
| 81 case PROBE_BW: | |
| 82 TryUpdatingCyclePhase(now); | |
| 83 break; | |
| 84 case PROBE_RTT: | |
| 85 TryExitingProbeRtt(now); | |
| 86 break; | |
| 87 } | |
| 88 | |
| 89 // Update pacing rate and congestion window values. | |
| 90 // TODO(gnish): Implement CalculatePacingRate() and | |
| 91 // CalculateCongestionWindow() functions. | |
| 92 stats_->CalculatePacingRate(); | |
| 93 stats_->CalculateCongestionWindow(); | |
| 94 } | |
| 95 | |
| 96 bool BbrBweSender::UpdateBandwidthAndMinRtt( | |
| 97 int64_t now, | |
| 98 const std::vector<std::pair<uint64_t, int64_t>>& feedback_vector, | |
| 99 int64_t bytes_acked) { | |
| 100 return false; | |
| 101 } | |
| 102 | |
| 103 void BbrBweSender::EnterStartup() { | |
| 104 mode_ = STARTUP; | |
| 105 stats_->set_pacing_gain(kHighGain); | |
| 106 } | |
| 107 | |
| 108 void BbrBweSender::TryExitingStartup() { | |
| 109 // If delivery rate hasn't grown | |
| 110 // switch to Drain mode. | |
| 111 // TODO(gnish): Implement DeliveryRateGrows() | |
| 112 if (!stats_->DeliveryRateGrows()) { | |
| 113 mode_ = DRAIN; | |
| 114 stats_->set_pacing_gain(kDrainGain); | |
| 115 } | |
| 116 } | |
| 117 | |
| 118 void BbrBweSender::TryExitingDrain(int64_t now) {} | |
| 119 | |
| 120 void BbrBweSender::EnterProbeBw(int64_t now) {} | |
| 121 | |
| 122 void BbrBweSender::TryUpdatingCyclePhase(int64_t now) {} | |
| 123 | |
| 124 void BbrBweSender::EnterProbeRtt(int64_t now) {} | |
| 125 | |
| 126 void BbrBweSender::TryExitingProbeRtt(int64_t now) {} | |
| 127 | |
| 128 int64_t BbrBweSender::TimeUntilNextProcess() { | |
| 129 return 100; | |
| 130 } | |
| 131 | |
| 132 void BbrBweSender::OnPacketsSent(const Packets& packets) {} | |
| 133 | |
| 134 void BbrBweSender::Process() {} | |
| 135 | |
| 136 BbrBweReceiver::BbrBweReceiver(int flow_id) | |
| 137 : BweReceiver(flow_id, kReceivingRateTimeWindowMs), | |
| 138 last_feedback_ms_(0), | |
| 139 clock_(0), | |
| 140 packet_feedbacks_() {} | |
| 141 | |
| 142 BbrBweReceiver::~BbrBweReceiver() {} | |
| 143 | |
| 144 void BbrBweReceiver::ReceivePacket(int64_t arrival_time_ms, | |
| 145 const MediaPacket& media_packet) { | |
| 146 packet_feedbacks_.push_back( | |
| 147 {media_packet.sequence_number(), arrival_time_ms}); | |
| 148 BweReceiver::ReceivePacket(arrival_time_ms, media_packet); | |
| 149 } | |
| 150 | |
| 151 FeedbackPacket* BbrBweReceiver::GetFeedback(int64_t now_ms) { | |
| 152 if (now_ms - last_feedback_ms_ < kFeedbackIntervals) | |
| 153 return NULL; | |
| 154 last_feedback_ms_ = now_ms; | |
| 155 int64_t corrected_send_time_ms = 0L; | |
| 156 if (!received_packets_.empty()) { | |
| 157 PacketIdentifierNode* latest = *(received_packets_.begin()); | |
| 158 corrected_send_time_ms = | |
| 159 latest->send_time_ms + now_ms - latest->arrival_time_ms; | |
| 160 } | |
| 161 FeedbackPacket* fb = new BbrBweFeedback( | |
| 162 flow_id_, now_ms * 1000, corrected_send_time_ms, packet_feedbacks_); | |
| 163 packet_feedbacks_.clear(); | |
| 164 return fb; | |
| 165 } | |
| 166 } // namespace bwe | |
| 167 } // namespace testing | |
| 168 } // namespace webrtc | |
| OLD | NEW |