blob: 5cb779a3b38a194095cca297496eeaaaffd7e775 [file] [log] [blame]
Sebastian Janssondf023aa2018-02-20 19:38:37 +01001/*
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 Gerey3e707812018-11-28 16:47:49 +010014#include "absl/types/optional.h"
Niels Möller0c4f7be2018-05-07 14:01:37 +020015#include "api/transport/bitrate_settings.h"
Christoffer Rodbro6404cdd2020-03-26 20:37:21 +010016#include "api/units/data_rate.h"
Sebastian Janssondf023aa2018-02-20 19:38:37 +010017
18namespace webrtc {
19
20// RtpBitrateConfigurator calculates the bitrate configuration based on received
21// remote configuration combined with local overrides.
22class RtpBitrateConfigurator {
23 public:
24 explicit RtpBitrateConfigurator(const BitrateConstraints& bitrate_config);
25 ~RtpBitrateConfigurator();
Byoungchan Leec065e732022-01-18 09:35:48 +090026
27 RtpBitrateConfigurator(const RtpBitrateConfigurator&) = delete;
28 RtpBitrateConfigurator& operator=(const RtpBitrateConfigurator&) = delete;
29
Sebastian Janssondf023aa2018-02-20 19:38:37 +010030 BitrateConstraints GetConfig() const;
31
Sebastian Jansson8f83b422018-02-21 13:07:13 +010032 // 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
Sebastian Janssondf023aa2018-02-20 19:38:37 +010036 // 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.
Danil Chapovalovb9b146c2018-06-15 12:28:07 +020039 absl::optional<BitrateConstraints> UpdateWithSdpParameters(
Sebastian Janssondf023aa2018-02-20 19:38:37 +010040 const BitrateConstraints& bitrate_config_);
41
Sebastian Jansson8f83b422018-02-21 13:07:13 +010042 // 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.
Sebastian Janssondf023aa2018-02-20 19:38:37 +010045 // 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.
Danil Chapovalovb9b146c2018-06-15 12:28:07 +020048 absl::optional<BitrateConstraints> UpdateWithClientPreferences(
Niels Möller0c4f7be2018-05-07 14:01:37 +020049 const BitrateSettings& bitrate_mask);
Sebastian Janssondf023aa2018-02-20 19:38:37 +010050
Christoffer Rodbro6404cdd2020-03-26 20:37:21 +010051 // Apply a cap for relayed calls.
52 absl::optional<BitrateConstraints> UpdateWithRelayCap(DataRate cap);
53
Sebastian Janssondf023aa2018-02-20 19:38:37 +010054 private:
Artem Titovea240272021-07-26 12:40:21 +020055 // Applies update to the BitrateConstraints cached in `config_`, resetting
56 // with `new_start` if set.
Danil Chapovalovb9b146c2018-06-15 12:28:07 +020057 absl::optional<BitrateConstraints> UpdateConstraints(
58 const absl::optional<int>& new_start);
Sebastian Janssondf023aa2018-02-20 19:38:37 +010059
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
Sebastian Jansson8f83b422018-02-21 13:07:13 +010064 // The config mask set by SetClientBitratePreferences.
Sebastian Janssondf023aa2018-02-20 19:38:37 +010065 // 0 <= min <= start <= max
Niels Möller0c4f7be2018-05-07 14:01:37 +020066 BitrateSettings bitrate_config_mask_;
Sebastian Janssondf023aa2018-02-20 19:38:37 +010067
Sebastian Jansson8f83b422018-02-21 13:07:13 +010068 // The config set by SetSdpBitrateParameters.
Sebastian Janssondf023aa2018-02-20 19:38:37 +010069 // min >= 0, start != 0, max == -1 || max > 0
70 BitrateConstraints base_bitrate_config_;
71
Christoffer Rodbro6404cdd2020-03-26 20:37:21 +010072 // Bandwidth cap applied for relayed calls.
73 DataRate max_bitrate_over_relay_ = DataRate::PlusInfinity();
Sebastian Janssondf023aa2018-02-20 19:38:37 +010074};
75} // namespace webrtc
76
77#endif // CALL_RTP_BITRATE_CONFIGURATOR_H_