blob: 07fe8d41a658509aeac423bfe3eef3201117346c [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
Patrik Höglundb6b29e02018-06-21 16:58:01 +020014#include "api/bitrate_constraints.h"
Niels Möller0c4f7be2018-05-07 14:01:37 +020015#include "api/transport/bitrate_settings.h"
Sebastian Janssondf023aa2018-02-20 19:38:37 +010016#include "rtc_base/constructormagic.h"
17
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();
26 BitrateConstraints GetConfig() const;
27
Sebastian Jansson8f83b422018-02-21 13:07:13 +010028 // The greater min and smaller max set by this and SetClientBitratePreferences
29 // will be used. The latest non-negative start value from either call will be
30 // used. Specifying a start bitrate (>0) will reset the current bitrate
31 // estimate. This is due to how the 'x-google-start-bitrate' flag is currently
Sebastian Janssondf023aa2018-02-20 19:38:37 +010032 // implemented. Passing -1 leaves the start bitrate unchanged. Behavior is not
33 // guaranteed for other negative values or 0.
34 // The optional return value is set with new configuration if it was updated.
Danil Chapovalovb9b146c2018-06-15 12:28:07 +020035 absl::optional<BitrateConstraints> UpdateWithSdpParameters(
Sebastian Janssondf023aa2018-02-20 19:38:37 +010036 const BitrateConstraints& bitrate_config_);
37
Sebastian Jansson8f83b422018-02-21 13:07:13 +010038 // The greater min and smaller max set by this and SetSdpBitrateParameters
39 // will be used. The latest non-negative start value form either call will be
40 // used. Specifying a start bitrate will reset the current bitrate estimate.
Sebastian Janssondf023aa2018-02-20 19:38:37 +010041 // Assumes 0 <= min <= start <= max holds for set parameters.
42 // Update the bitrate configuration
43 // The optional return value is set with new configuration if it was updated.
Danil Chapovalovb9b146c2018-06-15 12:28:07 +020044 absl::optional<BitrateConstraints> UpdateWithClientPreferences(
Niels Möller0c4f7be2018-05-07 14:01:37 +020045 const BitrateSettings& bitrate_mask);
Sebastian Janssondf023aa2018-02-20 19:38:37 +010046
47 private:
48 // Applies update to the BitrateConstraints cached in |config_|, resetting
49 // with |new_start| if set.
Danil Chapovalovb9b146c2018-06-15 12:28:07 +020050 absl::optional<BitrateConstraints> UpdateConstraints(
51 const absl::optional<int>& new_start);
Sebastian Janssondf023aa2018-02-20 19:38:37 +010052
53 // Bitrate config used until valid bitrate estimates are calculated. Also
54 // used to cap total bitrate used. This comes from the remote connection.
55 BitrateConstraints bitrate_config_;
56
Sebastian Jansson8f83b422018-02-21 13:07:13 +010057 // The config mask set by SetClientBitratePreferences.
Sebastian Janssondf023aa2018-02-20 19:38:37 +010058 // 0 <= min <= start <= max
Niels Möller0c4f7be2018-05-07 14:01:37 +020059 BitrateSettings bitrate_config_mask_;
Sebastian Janssondf023aa2018-02-20 19:38:37 +010060
Sebastian Jansson8f83b422018-02-21 13:07:13 +010061 // The config set by SetSdpBitrateParameters.
Sebastian Janssondf023aa2018-02-20 19:38:37 +010062 // min >= 0, start != 0, max == -1 || max > 0
63 BitrateConstraints base_bitrate_config_;
64
65 RTC_DISALLOW_COPY_AND_ASSIGN(RtpBitrateConfigurator);
66};
67} // namespace webrtc
68
69#endif // CALL_RTP_BITRATE_CONFIGURATOR_H_