blob: 62ed6fda5ab186b91bf54663b2eaa7f031ccf76e [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"
henrik.lundin@webrtc.orgb56d0e32013-10-24 09:24:06 +000026#include "webrtc/system_wrappers/interface/scoped_ptr.h"
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000027
28namespace webrtc {
29
30class RtcpBandwidthObserverImpl;
henrik.lundin@webrtc.orgb56d0e32013-10-24 09:24:06 +000031class LowRateStrategy;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000032
33class BitrateControllerImpl : public BitrateController {
34 public:
35 friend class RtcpBandwidthObserverImpl;
36
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000037 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.org29dd0de2013-10-21 14:00:01 +000058 typedef std::pair<BitrateObserver*, BitrateConfiguration*>
59 BitrateObserverConfiguration;
60 typedef std::list<BitrateObserverConfiguration> BitrateObserverConfList;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000061
henrik.lundin@webrtc.orgb56d0e32013-10-24 09:24:06 +000062 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.org1cd11622012-04-19 12:13:52 +000079 // 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.org1cd11622012-04-19 12:13:52 +000087 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);
94
95 CriticalSectionWrapper* critsect_;
henrik.lundin@webrtc.orgb56d0e32013-10-24 09:24:06 +000096 SendSideBandwidthEstimation bandwidth_estimation_;
97 BitrateObserverConfList bitrate_observers_;
98 scoped_ptr<LowRateStrategy> low_rate_strategy_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000099};
100} // namespace webrtc
101#endif // WEBRTC_MODULES_BITRATE_CONTROLLER_BITRATE_CONTROLLER_IMPL_H_