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