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