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