blob: 58122b6dbb680c2b2b7cf779aa9e65973f7a02d5 [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
18#include "modules/bitrate_controller/include/bitrate_controller.h"
19
stefan@webrtc.org1281dc02012-08-13 16:13:09 +000020#include <list>
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000021#include <map>
22
23#include "system_wrappers/interface/critical_section_wrapper.h"
24#include "modules/bitrate_controller/send_side_bandwidth_estimation.h"
25
26namespace webrtc {
27
28class RtcpBandwidthObserverImpl;
29
30class BitrateControllerImpl : public BitrateController {
31 public:
32 friend class RtcpBandwidthObserverImpl;
33
34 explicit BitrateControllerImpl();
35 virtual ~BitrateControllerImpl();
36
pwestin@webrtc.orga2cd7322012-04-23 08:32:47 +000037 virtual bool AvailableBandwidth(uint32_t* bandwidth) const;
38
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000039 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.org1281dc02012-08-13 16:13:09 +000081 typedef std::pair<BitrateObserver*, BitrateConfiguration*>
82 BitrateObserverConfiguration;
83 typedef std::list<BitrateObserverConfiguration> BitrateObserverConfList;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000084
stefan@webrtc.org1281dc02012-08-13 16:13:09 +000085 BitrateObserverConfList::iterator
86 FindObserverConfigurationPair(const BitrateObserver* observer);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000087 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.org1281dc02012-08-13 16:13:09 +000093 BitrateObserverConfList bitrate_observers_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000094};
95} // namespace webrtc
96#endif // WEBRTC_MODULES_BITRATE_CONTROLLER_BITRATE_CONTROLLER_IMPL_H_