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