tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

delay_constraints.h (2562B)


      1 /*
      2 *  Copyright (c) 2024 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_NETEQ_DELAY_CONSTRAINTS_H_
     12 #define MODULES_AUDIO_CODING_NETEQ_DELAY_CONSTRAINTS_H_
     13 
     14 namespace webrtc {
     15 
     16 class DelayConstraints {
     17 public:
     18  DelayConstraints(int max_packets_in_buffer, int base_minimum_delay_ms);
     19 
     20  // Returns the delay (in ms) clamped to the range of valid delays.
     21  int Clamp(int delay_ms) const;
     22 
     23  // Notifies the DelayManager of how much audio data is carried in each packet.
     24  bool SetPacketAudioLength(int length_ms);
     25 
     26  // Accessors and mutators.
     27  // Assuming `delay` is in valid range.
     28  bool SetMinimumDelay(int delay_ms);
     29  bool SetMaximumDelay(int delay_ms);
     30  bool SetBaseMinimumDelay(int delay_ms);
     31  int GetBaseMinimumDelay() const;
     32 
     33  // These accessors are only intended for testing purposes.
     34  int effective_minimum_delay_ms_for_test() const {
     35    return effective_minimum_delay_ms_;
     36  }
     37 
     38 private:
     39  // Provides value which minimum delay can't exceed based on current buffer
     40  // size and given `maximum_delay_ms_`. Lower bound is a constant 0.
     41  int MinimumDelayUpperBound() const;
     42 
     43  // Updates `effective_minimum_delay_ms_` delay based on current
     44  // `minimum_delay_ms_`, `base_minimum_delay_ms_`, `maximum_delay_ms_` and
     45  // buffer size.
     46  void UpdateEffectiveMinimumDelay();
     47 
     48  // Makes sure that `delay_ms` is less than maximum delay, if any maximum
     49  // is set. Also, if possible check `delay_ms` to be less than 75% of
     50  // `max_packets_in_buffer_`.
     51  bool IsValidMinimumDelay(int delay_ms) const;
     52 
     53  // Checks that `delay_ms` is in the range of valid base minimum delays.
     54  bool IsValidBaseMinimumDelay(int delay_ms) const;
     55 
     56  // TODO(jakobi): set maximum buffer delay instead of number of packets.
     57  const int max_packets_in_buffer_;
     58 
     59  int base_minimum_delay_ms_;
     60  int effective_minimum_delay_ms_;  // Used as lower bound for target delay.
     61  int minimum_delay_ms_;            // Externally set minimum delay.
     62  int maximum_delay_ms_;            // Externally set maximum delay. No maximum
     63                                    // delay is enforced if <= 0.
     64 
     65  int packet_len_ms_ = 0;
     66 };
     67 
     68 }  // namespace webrtc
     69 
     70 #endif  // MODULES_AUDIO_CODING_NETEQ_DELAY_CONSTRAINTS_H_