1 /* 2 * Copyright (c) 2015 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 // Implementation of Network-Assisted Dynamic Adaptation's (NADA's) proposal 13 // Version according to Draft Document (mentioned in references) 14 // http://tools.ietf.org/html/draft-zhu-rmcat-nada-06 15 // From March 26, 2015. 16 17 #ifndef WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_ESTIMATORS_NADA_H_ 18 #define WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_ESTIMATORS_NADA_H_ 19 20 #include <list> 21 #include <map> 22 23 #include "webrtc/modules/include/module_common_types.h" 24 #include "webrtc/modules/remote_bitrate_estimator/test/bwe.h" 25 #include "webrtc/voice_engine/channel.h" 26 27 namespace webrtc { 28 29 class ReceiveStatistics; 30 31 namespace testing { 32 namespace bwe { 33 34 class NadaBweReceiver : public BweReceiver { 35 public: 36 explicit NadaBweReceiver(int flow_id); 37 virtual ~NadaBweReceiver(); 38 39 void ReceivePacket(int64_t arrival_time_ms, 40 const MediaPacket& media_packet) override; 41 FeedbackPacket* GetFeedback(int64_t now_ms) override; 42 43 static int64_t MedianFilter(int64_t* v, int size); 44 static int64_t ExponentialSmoothingFilter(int64_t new_value, 45 int64_t last_smoothed_value, 46 float alpha); 47 48 static const int64_t kReceivingRateTimeWindowMs; 49 50 private: 51 SimulatedClock clock_; 52 int64_t last_feedback_ms_; 53 rtc::scoped_ptr<ReceiveStatistics> recv_stats_; 54 int64_t baseline_delay_ms_; // Referred as d_f. 55 int64_t delay_signal_ms_; // Referred as d_n. 56 int64_t last_congestion_signal_ms_; 57 int last_delays_index_; 58 int64_t exp_smoothed_delay_ms_; // Referred as d_hat_n. 59 int64_t est_queuing_delay_signal_ms_; // Referred as d_tilde_n. 60 int64_t last_delays_ms_[5]; // Used for Median Filter. 61 }; 62 63 class NadaBweSender : public BweSender { 64 public: 65 NadaBweSender(int kbps, BitrateObserver* observer, Clock* clock); 66 NadaBweSender(BitrateObserver* observer, Clock* clock); 67 virtual ~NadaBweSender(); 68 69 int GetFeedbackIntervalMs() const override; 70 // Updates the min_feedback_delay_ms_ and the min_round_trip_time_ms_. 71 void GiveFeedback(const FeedbackPacket& feedback) override; OnPacketsSent(const Packets & packets)72 void OnPacketsSent(const Packets& packets) override {} 73 int64_t TimeUntilNextProcess() override; 74 int Process() override; 75 void AcceleratedRampUp(const NadaFeedback& fb); 76 void AcceleratedRampDown(const NadaFeedback& fb); 77 void GradualRateUpdate(const NadaFeedback& fb, 78 float delta_s, 79 double smoothing_factor); 80 bitrate_kbps()81 int bitrate_kbps() const { return bitrate_kbps_; } set_bitrate_kbps(int bitrate_kbps)82 void set_bitrate_kbps(int bitrate_kbps) { bitrate_kbps_ = bitrate_kbps; } original_operating_mode()83 bool original_operating_mode() const { return original_operating_mode_; } set_original_operating_mode(bool original_operating_mode)84 void set_original_operating_mode(bool original_operating_mode) { 85 original_operating_mode_ = original_operating_mode; 86 } NowMs()87 int64_t NowMs() const { return clock_->TimeInMilliseconds(); } 88 89 private: 90 Clock* const clock_; 91 BitrateObserver* const observer_; 92 // Used as an upper bound for calling AcceleratedRampDown. 93 const float kMaxCongestionSignalMs = 40.0f + kMinBitrateKbps / 15; 94 // Referred as R_min, default initialization for bitrate R_n. 95 int64_t last_feedback_ms_ = 0; 96 // Referred as delta_0, initialized as an upper bound. 97 int64_t min_feedback_delay_ms_ = 200; 98 // Referred as RTT_0, initialized as an upper bound. 99 int64_t min_round_trip_time_ms_ = 100; 100 bool original_operating_mode_; 101 102 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(NadaBweSender); 103 }; 104 105 } // namespace bwe 106 } // namespace testing 107 } // namespace webrtc 108 109 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_ESTIMATORS_NADA_H_ 110