Sebastian Jansson | df023aa | 2018-02-20 19:38:37 +0100 | [diff] [blame] | 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 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 14 | #include "absl/types/optional.h" |
Niels Möller | 0c4f7be | 2018-05-07 14:01:37 +0200 | [diff] [blame] | 15 | #include "api/transport/bitrate_settings.h" |
Christoffer Rodbro | 6404cdd | 2020-03-26 20:37:21 +0100 | [diff] [blame] | 16 | #include "api/units/data_rate.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 17 | #include "rtc_base/constructor_magic.h" |
Sebastian Jansson | df023aa | 2018-02-20 19:38:37 +0100 | [diff] [blame] | 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 | BitrateConstraints GetConfig() const; |
| 28 | |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 29 | // The greater min and smaller max set by this and SetClientBitratePreferences |
| 30 | // will be used. The latest non-negative start value from either call will be |
| 31 | // used. Specifying a start bitrate (>0) will reset the current bitrate |
| 32 | // estimate. This is due to how the 'x-google-start-bitrate' flag is currently |
Sebastian Jansson | df023aa | 2018-02-20 19:38:37 +0100 | [diff] [blame] | 33 | // implemented. Passing -1 leaves the start bitrate unchanged. Behavior is not |
| 34 | // guaranteed for other negative values or 0. |
| 35 | // The optional return value is set with new configuration if it was updated. |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 36 | absl::optional<BitrateConstraints> UpdateWithSdpParameters( |
Sebastian Jansson | df023aa | 2018-02-20 19:38:37 +0100 | [diff] [blame] | 37 | const BitrateConstraints& bitrate_config_); |
| 38 | |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 39 | // The greater min and smaller max set by this and SetSdpBitrateParameters |
| 40 | // will be used. The latest non-negative start value form either call will be |
| 41 | // used. Specifying a start bitrate will reset the current bitrate estimate. |
Sebastian Jansson | df023aa | 2018-02-20 19:38:37 +0100 | [diff] [blame] | 42 | // Assumes 0 <= min <= start <= max holds for set parameters. |
| 43 | // Update the bitrate configuration |
| 44 | // The optional return value is set with new configuration if it was updated. |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 45 | absl::optional<BitrateConstraints> UpdateWithClientPreferences( |
Niels Möller | 0c4f7be | 2018-05-07 14:01:37 +0200 | [diff] [blame] | 46 | const BitrateSettings& bitrate_mask); |
Sebastian Jansson | df023aa | 2018-02-20 19:38:37 +0100 | [diff] [blame] | 47 | |
Christoffer Rodbro | 6404cdd | 2020-03-26 20:37:21 +0100 | [diff] [blame] | 48 | // Apply a cap for relayed calls. |
| 49 | absl::optional<BitrateConstraints> UpdateWithRelayCap(DataRate cap); |
| 50 | |
Sebastian Jansson | df023aa | 2018-02-20 19:38:37 +0100 | [diff] [blame] | 51 | private: |
Artem Titov | ea24027 | 2021-07-26 12:40:21 +0200 | [diff] [blame] | 52 | // Applies update to the BitrateConstraints cached in `config_`, resetting |
| 53 | // with `new_start` if set. |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 54 | absl::optional<BitrateConstraints> UpdateConstraints( |
| 55 | const absl::optional<int>& new_start); |
Sebastian Jansson | df023aa | 2018-02-20 19:38:37 +0100 | [diff] [blame] | 56 | |
| 57 | // Bitrate config used until valid bitrate estimates are calculated. Also |
| 58 | // used to cap total bitrate used. This comes from the remote connection. |
| 59 | BitrateConstraints bitrate_config_; |
| 60 | |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 61 | // The config mask set by SetClientBitratePreferences. |
Sebastian Jansson | df023aa | 2018-02-20 19:38:37 +0100 | [diff] [blame] | 62 | // 0 <= min <= start <= max |
Niels Möller | 0c4f7be | 2018-05-07 14:01:37 +0200 | [diff] [blame] | 63 | BitrateSettings bitrate_config_mask_; |
Sebastian Jansson | df023aa | 2018-02-20 19:38:37 +0100 | [diff] [blame] | 64 | |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 65 | // The config set by SetSdpBitrateParameters. |
Sebastian Jansson | df023aa | 2018-02-20 19:38:37 +0100 | [diff] [blame] | 66 | // min >= 0, start != 0, max == -1 || max > 0 |
| 67 | BitrateConstraints base_bitrate_config_; |
| 68 | |
Christoffer Rodbro | 6404cdd | 2020-03-26 20:37:21 +0100 | [diff] [blame] | 69 | // Bandwidth cap applied for relayed calls. |
| 70 | DataRate max_bitrate_over_relay_ = DataRate::PlusInfinity(); |
| 71 | |
Sebastian Jansson | df023aa | 2018-02-20 19:38:37 +0100 | [diff] [blame] | 72 | RTC_DISALLOW_COPY_AND_ASSIGN(RtpBitrateConfigurator); |
| 73 | }; |
| 74 | } // namespace webrtc |
| 75 | |
| 76 | #endif // CALL_RTP_BITRATE_CONFIGURATOR_H_ |