pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 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 | * Usage: this class will register multiple RtcpBitrateObserver's one at each |
| 11 | * RTCP module. It will aggregate the results and run one bandwidth estimation |
| 12 | * and push the result to the encoders via BitrateObserver(s). |
| 13 | */ |
| 14 | |
| 15 | #ifndef WEBRTC_MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_CONTROLLER_H_ |
| 16 | #define WEBRTC_MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_CONTROLLER_H_ |
| 17 | |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 18 | #include "webrtc/modules/interface/module.h" |
pbos@webrtc.org | 2e10b8e | 2013-07-16 12:54:53 +0000 | [diff] [blame] | 19 | #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
| 22 | |
| 23 | class BitrateObserver { |
| 24 | /* |
| 25 | * Observer class for the encoders, each encoder should implement this class |
| 26 | * to get the target bitrate. It also get the fraction loss and rtt to |
stefan@webrtc.org | 42aa10e | 2012-11-13 15:02:13 +0000 | [diff] [blame] | 27 | * optimize its settings for this type of network. |target_bitrate| is the |
| 28 | * target media/payload bitrate excluding packet headers, measured in bits |
| 29 | * per second. |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 30 | */ |
| 31 | public: |
stefan@webrtc.org | edeea91 | 2014-12-08 19:46:23 +0000 | [diff] [blame] | 32 | virtual void OnNetworkChanged(uint32_t target_bitrate, |
| 33 | uint8_t fraction_loss, // 0 - 255. |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 34 | int64_t rtt) = 0; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 35 | |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 36 | virtual ~BitrateObserver() {} |
| 37 | }; |
| 38 | |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 39 | class BitrateController : public Module { |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 40 | /* |
| 41 | * This class collects feedback from all streams sent to a peer (via |
| 42 | * RTCPBandwidthObservers). It does one aggregated send side bandwidth |
| 43 | * estimation and divide the available bitrate between all its registered |
| 44 | * BitrateObservers. |
| 45 | */ |
| 46 | public: |
henrik.lundin@webrtc.org | 29dd0de | 2013-10-21 14:00:01 +0000 | [diff] [blame] | 47 | // The argument |enforce_min_bitrate| controls the behavior when the available |
| 48 | // bitrate is lower than the minimum bitrate, or the sum of minimum bitrates. |
| 49 | // When true, the bitrate will never be set lower than the minimum bitrate(s). |
| 50 | // When false, the bitrate observers will be allocated rates up to their |
| 51 | // respective minimum bitrate, satisfying one observer after the other. |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 52 | static BitrateController* CreateBitrateController(Clock* clock, |
| 53 | bool enforce_min_bitrate); |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 54 | virtual ~BitrateController() {} |
| 55 | |
| 56 | virtual RtcpBandwidthObserver* CreateRtcpBandwidthObserver() = 0; |
| 57 | |
stefan@webrtc.org | 42aa10e | 2012-11-13 15:02:13 +0000 | [diff] [blame] | 58 | // Gets the available payload bandwidth in bits per second. Note that |
| 59 | // this bandwidth excludes packet headers. |
pwestin@webrtc.org | a2cd732 | 2012-04-23 08:32:47 +0000 | [diff] [blame] | 60 | virtual bool AvailableBandwidth(uint32_t* bandwidth) const = 0; |
| 61 | |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 62 | /* |
| 63 | * Set the start and max send bitrate used by the bandwidth management. |
| 64 | * |
| 65 | * observer, updates bitrates if already in use. |
| 66 | * min_bitrate_kbit = 0 equals no min bitrate. |
| 67 | * max_bitrate_kit = 0 equals no max bitrate. |
| 68 | */ |
| 69 | virtual void SetBitrateObserver(BitrateObserver* observer, |
stefan@webrtc.org | edeea91 | 2014-12-08 19:46:23 +0000 | [diff] [blame] | 70 | uint32_t start_bitrate, |
| 71 | uint32_t min_bitrate, |
| 72 | uint32_t max_bitrate) = 0; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 73 | |
| 74 | virtual void RemoveBitrateObserver(BitrateObserver* observer) = 0; |
henrik.lundin@webrtc.org | b56d0e3 | 2013-10-24 09:24:06 +0000 | [diff] [blame] | 75 | |
| 76 | // Changes the mode that was set in the constructor. |
| 77 | virtual void EnforceMinBitrate(bool enforce_min_bitrate) = 0; |
solenberg@webrtc.org | 4e65602 | 2014-03-26 14:32:47 +0000 | [diff] [blame] | 78 | |
| 79 | virtual void SetReservedBitrate(uint32_t reserved_bitrate_bps) = 0; |
sprang@webrtc.org | 9b79197 | 2014-12-18 11:53:59 +0000 | [diff] [blame] | 80 | |
| 81 | virtual void SetBitrateSent(uint32_t bitrate_sent_bps) = 0; |
| 82 | |
| 83 | virtual void SetCodecMode(webrtc::VideoCodecMode mode) = 0; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 84 | }; |
| 85 | } // namespace webrtc |
| 86 | #endif // WEBRTC_MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_CONTROLLER_H_ |