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