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 | |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame^] | 18 | #include <map> |
| 19 | |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 20 | #include "webrtc/modules/interface/module.h" |
pbos@webrtc.org | 2e10b8e | 2013-07-16 12:54:53 +0000 | [diff] [blame] | 21 | #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
| 24 | |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame^] | 25 | class CriticalSectionWrapper; |
| 26 | |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 27 | class BitrateObserver { |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame^] | 28 | // Observer class for bitrate changes announced due to change in bandwidth |
| 29 | // estimate or due to bitrate allocation changes. Fraction loss and rtt is |
| 30 | // also part of this callback to allow the obsevrer to optimize its settings |
| 31 | // for different types of network environments. The bitrate does not include |
| 32 | // packet headers and is measured in bits per second. |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 33 | public: |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame^] | 34 | virtual void OnNetworkChanged(uint32_t bitrate_bps, |
stefan@webrtc.org | edeea91 | 2014-12-08 19:46:23 +0000 | [diff] [blame] | 35 | uint8_t fraction_loss, // 0 - 255. |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame^] | 36 | int64_t rtt_ms) = 0; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 37 | |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 38 | virtual ~BitrateObserver() {} |
| 39 | }; |
| 40 | |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 41 | class BitrateController : public Module { |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame^] | 42 | // This class collects feedback from all streams sent to a peer (via |
| 43 | // RTCPBandwidthObservers). It does one aggregated send side bandwidth |
| 44 | // estimation and divide the available bitrate between all its registered |
| 45 | // BitrateObservers. |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 46 | public: |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame^] | 47 | static const int kDefaultStartBitrateKbps = 300; |
| 48 | |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 49 | static BitrateController* CreateBitrateController(Clock* clock, |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame^] | 50 | BitrateObserver* observer); |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 51 | virtual ~BitrateController() {} |
| 52 | |
| 53 | virtual RtcpBandwidthObserver* CreateRtcpBandwidthObserver() = 0; |
| 54 | |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame^] | 55 | virtual void SetStartBitrate(int start_bitrate_bps) = 0; |
| 56 | virtual void SetMinMaxBitrate(int min_bitrate_bps, int max_bitrate_bps) = 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 | |
solenberg@webrtc.org | 4e65602 | 2014-03-26 14:32:47 +0000 | [diff] [blame] | 62 | virtual void SetReservedBitrate(uint32_t reserved_bitrate_bps) = 0; |
sprang@webrtc.org | 9b79197 | 2014-12-18 11:53:59 +0000 | [diff] [blame] | 63 | |
| 64 | virtual void SetBitrateSent(uint32_t bitrate_sent_bps) = 0; |
| 65 | |
| 66 | virtual void SetCodecMode(webrtc::VideoCodecMode mode) = 0; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 67 | }; |
| 68 | } // namespace webrtc |
| 69 | #endif // WEBRTC_MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_CONTROLLER_H_ |