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_FRAME_LENGTH_CONTROLLER_H_ 12 #define MODULES_AUDIO_CODING_AUDIO_NETWORK_ADAPTOR_FRAME_LENGTH_CONTROLLER_H_ 13 14 #include <stddef.h> 15 16 #include <map> 17 #include <set> 18 19 #include "absl/types/optional.h" 20 #include "modules/audio_coding/audio_network_adaptor/controller.h" 21 #include "modules/audio_coding/audio_network_adaptor/include/audio_network_adaptor_config.h" 22 23 namespace webrtc { 24 25 // Determines target frame length based on the network metrics and the decision 26 // of FEC controller. 27 class FrameLengthController final : public Controller { 28 public: 29 struct Config { 30 struct FrameLengthChange { 31 FrameLengthChange(int from_frame_length_ms, int to_frame_length_ms); 32 bool operator<(const FrameLengthChange& rhs) const; 33 int from_frame_length_ms; 34 int to_frame_length_ms; 35 }; 36 Config(const std::set<int>& encoder_frame_lengths_ms, 37 int initial_frame_length_ms, 38 int min_encoder_bitrate_bps, 39 float fl_increasing_packet_loss_fraction, 40 float fl_decreasing_packet_loss_fraction, 41 int fl_increase_overhead_offset, 42 int fl_decrease_overhead_offset, 43 std::map<FrameLengthChange, int> fl_changing_bandwidths_bps); 44 Config(const Config& other); 45 ~Config(); 46 std::set<int> encoder_frame_lengths_ms; 47 int initial_frame_length_ms; 48 int min_encoder_bitrate_bps; 49 // Uplink packet loss fraction below which frame length can increase. 50 float fl_increasing_packet_loss_fraction; 51 // Uplink packet loss fraction below which frame length should decrease. 52 float fl_decreasing_packet_loss_fraction; 53 // Offset to apply to overhead calculation when increasing frame length. 54 int fl_increase_overhead_offset; 55 // Offset to apply to overhead calculation when decreasing frame length. 56 int fl_decrease_overhead_offset; 57 std::map<FrameLengthChange, int> fl_changing_bandwidths_bps; 58 }; 59 60 explicit FrameLengthController(const Config& config); 61 62 ~FrameLengthController() override; 63 64 FrameLengthController(const FrameLengthController&) = delete; 65 FrameLengthController& operator=(const FrameLengthController&) = delete; 66 67 void UpdateNetworkMetrics(const NetworkMetrics& network_metrics) override; 68 69 void MakeDecision(AudioEncoderRuntimeConfig* config) override; 70 71 private: 72 bool FrameLengthIncreasingDecision(const AudioEncoderRuntimeConfig& config); 73 74 bool FrameLengthDecreasingDecision(const AudioEncoderRuntimeConfig& config); 75 76 const Config config_; 77 78 std::set<int>::const_iterator frame_length_ms_; 79 80 absl::optional<int> uplink_bandwidth_bps_; 81 82 absl::optional<float> uplink_packet_loss_fraction_; 83 84 absl::optional<size_t> overhead_bytes_per_packet_; 85 86 // True if the previous frame length decision was an increase, otherwise 87 // false. 88 bool prev_decision_increase_ = false; 89 }; 90 91 } // namespace webrtc 92 93 #endif // MODULES_AUDIO_CODING_AUDIO_NETWORK_ADAPTOR_FRAME_LENGTH_CONTROLLER_H_ 94