rtp_bitrate_configurator.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) 2018 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. #ifndef CALL_RTP_BITRATE_CONFIGURATOR_H_
  11. #define CALL_RTP_BITRATE_CONFIGURATOR_H_
  12. #include "absl/types/optional.h"
  13. #include "api/transport/bitrate_settings.h"
  14. #include "api/units/data_rate.h"
  15. #include "rtc_base/constructor_magic.h"
  16. namespace webrtc {
  17. // RtpBitrateConfigurator calculates the bitrate configuration based on received
  18. // remote configuration combined with local overrides.
  19. class RtpBitrateConfigurator {
  20. public:
  21. explicit RtpBitrateConfigurator(const BitrateConstraints& bitrate_config);
  22. ~RtpBitrateConfigurator();
  23. BitrateConstraints GetConfig() const;
  24. // The greater min and smaller max set by this and SetClientBitratePreferences
  25. // will be used. The latest non-negative start value from either call will be
  26. // used. Specifying a start bitrate (>0) will reset the current bitrate
  27. // estimate. This is due to how the 'x-google-start-bitrate' flag is currently
  28. // implemented. Passing -1 leaves the start bitrate unchanged. Behavior is not
  29. // guaranteed for other negative values or 0.
  30. // The optional return value is set with new configuration if it was updated.
  31. absl::optional<BitrateConstraints> UpdateWithSdpParameters(
  32. const BitrateConstraints& bitrate_config_);
  33. // The greater min and smaller max set by this and SetSdpBitrateParameters
  34. // will be used. The latest non-negative start value form either call will be
  35. // used. Specifying a start bitrate will reset the current bitrate estimate.
  36. // Assumes 0 <= min <= start <= max holds for set parameters.
  37. // Update the bitrate configuration
  38. // The optional return value is set with new configuration if it was updated.
  39. absl::optional<BitrateConstraints> UpdateWithClientPreferences(
  40. const BitrateSettings& bitrate_mask);
  41. // Apply a cap for relayed calls.
  42. absl::optional<BitrateConstraints> UpdateWithRelayCap(DataRate cap);
  43. private:
  44. // Applies update to the BitrateConstraints cached in |config_|, resetting
  45. // with |new_start| if set.
  46. absl::optional<BitrateConstraints> UpdateConstraints(
  47. const absl::optional<int>& new_start);
  48. // Bitrate config used until valid bitrate estimates are calculated. Also
  49. // used to cap total bitrate used. This comes from the remote connection.
  50. BitrateConstraints bitrate_config_;
  51. // The config mask set by SetClientBitratePreferences.
  52. // 0 <= min <= start <= max
  53. BitrateSettings bitrate_config_mask_;
  54. // The config set by SetSdpBitrateParameters.
  55. // min >= 0, start != 0, max == -1 || max > 0
  56. BitrateConstraints base_bitrate_config_;
  57. // Bandwidth cap applied for relayed calls.
  58. DataRate max_bitrate_over_relay_ = DataRate::PlusInfinity();
  59. RTC_DISALLOW_COPY_AND_ASSIGN(RtpBitrateConfigurator);
  60. };
  61. } // namespace webrtc
  62. #endif // CALL_RTP_BITRATE_CONFIGURATOR_H_