blob: 5e56607cc0bdeff817415aa019ed4e48d898870d [file] [log] [blame]
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +00001/*
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.org2e10b8e2013-07-16 12:54:53 +000018#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000019
stefan@webrtc.org1281dc02012-08-13 16:13:09 +000020#include <list>
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000021#include <map>
henrik.lundin@webrtc.org29dd0de2013-10-21 14:00:01 +000022#include <utility>
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000023
pbos@webrtc.org2e10b8e2013-07-16 12:54:53 +000024#include "webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.h"
25#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000026
27namespace webrtc {
28
29class RtcpBandwidthObserverImpl;
30
31class BitrateControllerImpl : public BitrateController {
32 public:
33 friend class RtcpBandwidthObserverImpl;
34
35 explicit BitrateControllerImpl();
36 virtual ~BitrateControllerImpl();
37
pbos@webrtc.org4fac8a42013-07-31 15:16:20 +000038 virtual bool AvailableBandwidth(uint32_t* bandwidth) const OVERRIDE;
pwestin@webrtc.orga2cd7322012-04-23 08:32:47 +000039
pbos@webrtc.org4fac8a42013-07-31 15:16:20 +000040 virtual RtcpBandwidthObserver* CreateRtcpBandwidthObserver() OVERRIDE;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000041
42 virtual void SetBitrateObserver(BitrateObserver* observer,
43 const uint32_t start_bitrate,
44 const uint32_t min_bitrate,
pbos@webrtc.org4fac8a42013-07-31 15:16:20 +000045 const uint32_t max_bitrate) OVERRIDE;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000046
pbos@webrtc.org4fac8a42013-07-31 15:16:20 +000047 virtual void RemoveBitrateObserver(BitrateObserver* observer) OVERRIDE;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000048
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.org29dd0de2013-10-21 14:00:01 +000071 typedef std::pair<BitrateObserver*, BitrateConfiguration*>
72 BitrateObserverConfiguration;
73 typedef std::list<BitrateObserverConfiguration> BitrateObserverConfList;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000074
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.org29dd0de2013-10-21 14:00:01 +000083 SendSideBandwidthEstimation bandwidth_estimation_;
84 BitrateObserverConfList bitrate_observers_;
85
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000086 private:
87 typedef std::multimap<uint32_t, ObserverConfiguration*> ObserverSortingMap;
88
stefan@webrtc.org1281dc02012-08-13 16:13:09 +000089 BitrateObserverConfList::iterator
90 FindObserverConfigurationPair(const BitrateObserver* observer);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000091 void OnNetworkChanged(const uint32_t bitrate,
92 const uint8_t fraction_loss, // 0 - 255.
93 const uint32_t rtt);
henrik.lundin@webrtc.org29dd0de2013-10-21 14:00:01 +000094 // 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.org1cd11622012-04-19 12:13:52 +000099
100 CriticalSectionWrapper* critsect_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000101};
102} // namespace webrtc
103#endif // WEBRTC_MODULES_BITRATE_CONTROLLER_BITRATE_CONTROLLER_IMPL_H_