1 /* 2 * Copyright (c) 2016 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 #ifndef MODULES_AUDIO_CODING_AUDIO_NETWORK_ADAPTOR_FEC_CONTROLLER_PLR_BASED_H_ 12 #define MODULES_AUDIO_CODING_AUDIO_NETWORK_ADAPTOR_FEC_CONTROLLER_PLR_BASED_H_ 13 14 #include <memory> 15 16 #include "absl/types/optional.h" 17 #include "common_audio/smoothing_filter.h" 18 #include "modules/audio_coding/audio_network_adaptor/controller.h" 19 #include "modules/audio_coding/audio_network_adaptor/include/audio_network_adaptor_config.h" 20 #include "modules/audio_coding/audio_network_adaptor/util/threshold_curve.h" 21 #include "rtc_base/constructor_magic.h" 22 23 namespace webrtc { 24 25 class FecControllerPlrBased final : public Controller { 26 public: 27 struct Config { 28 // |fec_enabling_threshold| defines a curve, above which FEC should be 29 // enabled. |fec_disabling_threshold| defines a curve, under which FEC 30 // should be disabled. See below 31 // 32 // packet-loss ^ | | 33 // | | | FEC 34 // | \ \ ON 35 // | FEC \ \_______ fec_enabling_threshold 36 // | OFF \_________ fec_disabling_threshold 37 // |-----------------> bandwidth 38 Config(bool initial_fec_enabled, 39 const ThresholdCurve& fec_enabling_threshold, 40 const ThresholdCurve& fec_disabling_threshold, 41 int time_constant_ms); 42 bool initial_fec_enabled; 43 ThresholdCurve fec_enabling_threshold; 44 ThresholdCurve fec_disabling_threshold; 45 int time_constant_ms; 46 }; 47 48 // Dependency injection for testing. 49 FecControllerPlrBased(const Config& config, 50 std::unique_ptr<SmoothingFilter> smoothing_filter); 51 52 explicit FecControllerPlrBased(const Config& config); 53 54 ~FecControllerPlrBased() override; 55 56 void UpdateNetworkMetrics(const NetworkMetrics& network_metrics) override; 57 58 void MakeDecision(AudioEncoderRuntimeConfig* config) override; 59 60 private: 61 bool FecEnablingDecision(const absl::optional<float>& packet_loss) const; 62 bool FecDisablingDecision(const absl::optional<float>& packet_loss) const; 63 64 const Config config_; 65 bool fec_enabled_; 66 absl::optional<int> uplink_bandwidth_bps_; 67 const std::unique_ptr<SmoothingFilter> packet_loss_smoother_; 68 69 RTC_DISALLOW_COPY_AND_ASSIGN(FecControllerPlrBased); 70 }; 71 72 } // namespace webrtc 73 74 #endif // MODULES_AUDIO_CODING_AUDIO_NETWORK_ADAPTOR_FEC_CONTROLLER_PLR_BASED_H_ 75