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 encoder via VideoEncoderCallback. |
| 13 | */ |
| 14 | |
| 15 | #ifndef WEBRTC_MODULES_BITRATE_CONTROLLER_BITRATE_CONTROLLER_IMPL_H_ |
| 16 | #define WEBRTC_MODULES_BITRATE_CONTROLLER_BITRATE_CONTROLLER_IMPL_H_ |
| 17 | |
pbos@webrtc.org | 2e10b8e | 2013-07-16 12:54:53 +0000 | [diff] [blame] | 18 | #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 19 | |
stefan@webrtc.org | 1281dc0 | 2012-08-13 16:13:09 +0000 | [diff] [blame] | 20 | #include <list> |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 21 | #include <map> |
henrik.lundin@webrtc.org | 29dd0de | 2013-10-21 14:00:01 +0000 | [diff] [blame] | 22 | #include <utility> |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 23 | |
pbos@webrtc.org | 2e10b8e | 2013-07-16 12:54:53 +0000 | [diff] [blame] | 24 | #include "webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.h" |
| 25 | #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
henrik.lundin@webrtc.org | b56d0e3 | 2013-10-24 09:24:06 +0000 | [diff] [blame] | 26 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 27 | |
| 28 | namespace webrtc { |
| 29 | |
| 30 | class RtcpBandwidthObserverImpl; |
henrik.lundin@webrtc.org | b56d0e3 | 2013-10-24 09:24:06 +0000 | [diff] [blame] | 31 | class LowRateStrategy; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 32 | |
| 33 | class BitrateControllerImpl : public BitrateController { |
| 34 | public: |
| 35 | friend class RtcpBandwidthObserverImpl; |
| 36 | |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 37 | struct BitrateConfiguration { |
| 38 | BitrateConfiguration(uint32_t start_bitrate, |
| 39 | uint32_t min_bitrate, |
| 40 | uint32_t max_bitrate) |
| 41 | : start_bitrate_(start_bitrate), |
| 42 | min_bitrate_(min_bitrate), |
| 43 | max_bitrate_(max_bitrate) { |
| 44 | } |
| 45 | uint32_t start_bitrate_; |
| 46 | uint32_t min_bitrate_; |
| 47 | uint32_t max_bitrate_; |
| 48 | }; |
| 49 | struct ObserverConfiguration { |
| 50 | ObserverConfiguration(BitrateObserver* observer, |
| 51 | uint32_t bitrate) |
| 52 | : observer_(observer), |
| 53 | min_bitrate_(bitrate) { |
| 54 | } |
| 55 | BitrateObserver* observer_; |
| 56 | uint32_t min_bitrate_; |
| 57 | }; |
henrik.lundin@webrtc.org | 29dd0de | 2013-10-21 14:00:01 +0000 | [diff] [blame] | 58 | typedef std::pair<BitrateObserver*, BitrateConfiguration*> |
| 59 | BitrateObserverConfiguration; |
| 60 | typedef std::list<BitrateObserverConfiguration> BitrateObserverConfList; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 61 | |
henrik.lundin@webrtc.org | b56d0e3 | 2013-10-24 09:24:06 +0000 | [diff] [blame] | 62 | explicit BitrateControllerImpl(bool enforce_min_bitrate); |
| 63 | virtual ~BitrateControllerImpl(); |
| 64 | |
| 65 | virtual bool AvailableBandwidth(uint32_t* bandwidth) const OVERRIDE; |
| 66 | |
| 67 | virtual RtcpBandwidthObserver* CreateRtcpBandwidthObserver() OVERRIDE; |
| 68 | |
| 69 | virtual void SetBitrateObserver(BitrateObserver* observer, |
| 70 | const uint32_t start_bitrate, |
| 71 | const uint32_t min_bitrate, |
| 72 | const uint32_t max_bitrate) OVERRIDE; |
| 73 | |
| 74 | virtual void RemoveBitrateObserver(BitrateObserver* observer) OVERRIDE; |
| 75 | |
| 76 | virtual void EnforceMinBitrate(bool enforce_min_bitrate) OVERRIDE; |
| 77 | |
| 78 | private: |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 79 | // Called by BitrateObserver's direct from the RTCP module. |
| 80 | void OnReceivedEstimatedBitrate(const uint32_t bitrate); |
| 81 | |
| 82 | void OnReceivedRtcpReceiverReport(const uint8_t fraction_loss, |
| 83 | const uint32_t rtt, |
| 84 | const int number_of_packets, |
| 85 | const uint32_t now_ms); |
| 86 | |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 87 | typedef std::multimap<uint32_t, ObserverConfiguration*> ObserverSortingMap; |
| 88 | |
stefan@webrtc.org | 1281dc0 | 2012-08-13 16:13:09 +0000 | [diff] [blame] | 89 | BitrateObserverConfList::iterator |
| 90 | FindObserverConfigurationPair(const BitrateObserver* observer); |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 91 | void OnNetworkChanged(const uint32_t bitrate, |
| 92 | const uint8_t fraction_loss, // 0 - 255. |
| 93 | const uint32_t rtt); |
| 94 | |
| 95 | CriticalSectionWrapper* critsect_; |
henrik.lundin@webrtc.org | b56d0e3 | 2013-10-24 09:24:06 +0000 | [diff] [blame] | 96 | SendSideBandwidthEstimation bandwidth_estimation_; |
| 97 | BitrateObserverConfList bitrate_observers_; |
| 98 | scoped_ptr<LowRateStrategy> low_rate_strategy_; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 99 | }; |
| 100 | } // namespace webrtc |
| 101 | #endif // WEBRTC_MODULES_BITRATE_CONTROLLER_BITRATE_CONTROLLER_IMPL_H_ |