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" |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 26 | |
| 27 | namespace webrtc { |
| 28 | |
| 29 | class RtcpBandwidthObserverImpl; |
| 30 | |
| 31 | class BitrateControllerImpl : public BitrateController { |
| 32 | public: |
| 33 | friend class RtcpBandwidthObserverImpl; |
| 34 | |
| 35 | explicit BitrateControllerImpl(); |
| 36 | virtual ~BitrateControllerImpl(); |
| 37 | |
pbos@webrtc.org | 4fac8a4 | 2013-07-31 15:16:20 +0000 | [diff] [blame] | 38 | virtual bool AvailableBandwidth(uint32_t* bandwidth) const OVERRIDE; |
pwestin@webrtc.org | a2cd732 | 2012-04-23 08:32:47 +0000 | [diff] [blame] | 39 | |
pbos@webrtc.org | 4fac8a4 | 2013-07-31 15:16:20 +0000 | [diff] [blame] | 40 | virtual RtcpBandwidthObserver* CreateRtcpBandwidthObserver() OVERRIDE; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 41 | |
| 42 | virtual void SetBitrateObserver(BitrateObserver* observer, |
| 43 | const uint32_t start_bitrate, |
| 44 | const uint32_t min_bitrate, |
pbos@webrtc.org | 4fac8a4 | 2013-07-31 15:16:20 +0000 | [diff] [blame] | 45 | const uint32_t max_bitrate) OVERRIDE; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 46 | |
pbos@webrtc.org | 4fac8a4 | 2013-07-31 15:16:20 +0000 | [diff] [blame] | 47 | virtual void RemoveBitrateObserver(BitrateObserver* observer) OVERRIDE; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 48 | |
| 49 | protected: |
| 50 | struct BitrateConfiguration { |
| 51 | BitrateConfiguration(uint32_t start_bitrate, |
| 52 | uint32_t min_bitrate, |
| 53 | uint32_t max_bitrate) |
| 54 | : start_bitrate_(start_bitrate), |
| 55 | min_bitrate_(min_bitrate), |
| 56 | max_bitrate_(max_bitrate) { |
| 57 | } |
| 58 | uint32_t start_bitrate_; |
| 59 | uint32_t min_bitrate_; |
| 60 | uint32_t max_bitrate_; |
| 61 | }; |
| 62 | struct ObserverConfiguration { |
| 63 | ObserverConfiguration(BitrateObserver* observer, |
| 64 | uint32_t bitrate) |
| 65 | : observer_(observer), |
| 66 | min_bitrate_(bitrate) { |
| 67 | } |
| 68 | BitrateObserver* observer_; |
| 69 | uint32_t min_bitrate_; |
| 70 | }; |
henrik.lundin@webrtc.org | 29dd0de | 2013-10-21 14:00:01 +0000 | [diff] [blame] | 71 | typedef std::pair<BitrateObserver*, BitrateConfiguration*> |
| 72 | BitrateObserverConfiguration; |
| 73 | typedef std::list<BitrateObserverConfiguration> BitrateObserverConfList; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 74 | |
| 75 | // Called by BitrateObserver's direct from the RTCP module. |
| 76 | void OnReceivedEstimatedBitrate(const uint32_t bitrate); |
| 77 | |
| 78 | void OnReceivedRtcpReceiverReport(const uint8_t fraction_loss, |
| 79 | const uint32_t rtt, |
| 80 | const int number_of_packets, |
| 81 | const uint32_t now_ms); |
| 82 | |
henrik.lundin@webrtc.org | 29dd0de | 2013-10-21 14:00:01 +0000 | [diff] [blame] | 83 | SendSideBandwidthEstimation bandwidth_estimation_; |
| 84 | BitrateObserverConfList bitrate_observers_; |
| 85 | |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 86 | private: |
| 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); |
henrik.lundin@webrtc.org | 29dd0de | 2013-10-21 14:00:01 +0000 | [diff] [blame] | 94 | // Derived classes must implement this strategy method. |
| 95 | virtual void LowRateAllocation(uint32_t bitrate, |
| 96 | uint8_t fraction_loss, |
| 97 | uint32_t rtt, |
| 98 | uint32_t sum_min_bitrates) = 0; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 99 | |
| 100 | CriticalSectionWrapper* critsect_; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 101 | }; |
| 102 | } // namespace webrtc |
| 103 | #endif // WEBRTC_MODULES_BITRATE_CONTROLLER_BITRATE_CONTROLLER_IMPL_H_ |