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
11#ifndef WEBRTC_CALL_CONGESTION_CONTROLLER_H_
12#define WEBRTC_CALL_CONGESTION_CONTROLLER_H_
13
14#include <vector>
15
16#include "webrtc/base/criticalsection.h"
17#include "webrtc/base/scoped_ptr.h"
18#include "webrtc/base/socket.h"
19#include "webrtc/stream.h"
20
21namespace webrtc {
22
23class BitrateController;
24class BitrateObserver;
25class CallStats;
26class Config;
27class PacedSender;
28class PacketRouter;
29class ProcessThread;
30class RemoteBitrateEstimator;
31class RemoteEstimatorProxy;
32class RtpRtcp;
33class SendStatisticsProxy;
34class TransportFeedbackAdapter;
35class TransportFeedbackObserver;
36class ViEEncoder;
37class VieRemb;
38
39class CongestionController {
40 public:
41  CongestionController(ProcessThread* process_thread, CallStats* call_stats,
42                       BitrateObserver* bitrate_observer);
43  virtual ~CongestionController();
44  virtual void AddEncoder(ViEEncoder* encoder);
45  virtual void RemoveEncoder(ViEEncoder* encoder);
46  virtual void SetBweBitrates(int min_bitrate_bps,
47                              int start_bitrate_bps,
48                              int max_bitrate_bps);
49
50  virtual void SetChannelRembStatus(bool sender,
51                                    bool receiver,
52                                    RtpRtcp* rtp_module);
53
54  virtual void SignalNetworkState(NetworkState state);
55
56  virtual BitrateController* GetBitrateController() const;
57  virtual RemoteBitrateEstimator* GetRemoteBitrateEstimator(
58      bool send_side_bwe) const;
59  virtual int64_t GetPacerQueuingDelayMs() const;
60  virtual PacedSender* pacer() const { return pacer_.get(); }
61  virtual PacketRouter* packet_router() const { return packet_router_.get(); }
62  virtual TransportFeedbackObserver* GetTransportFeedbackObserver();
63
64  virtual void UpdatePacerBitrate(int bitrate_kbps,
65                                  int max_bitrate_kbps,
66                                  int min_bitrate_kbps);
67
68  virtual void OnSentPacket(const rtc::SentPacket& sent_packet);
69
70 private:
71  rtc::scoped_ptr<VieRemb> remb_;
72  rtc::scoped_ptr<PacketRouter> packet_router_;
73  rtc::scoped_ptr<PacedSender> pacer_;
74  rtc::scoped_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_;
75  rtc::scoped_ptr<RemoteEstimatorProxy> remote_estimator_proxy_;
76
77  mutable rtc::CriticalSection encoder_crit_;
78  std::vector<ViEEncoder*> encoders_ GUARDED_BY(encoder_crit_);
79
80  // Registered at construct time and assumed to outlive this class.
81  ProcessThread* const process_thread_;
82  CallStats* const call_stats_;
83
84  rtc::scoped_ptr<ProcessThread> pacer_thread_;
85
86  rtc::scoped_ptr<BitrateController> bitrate_controller_;
87  rtc::scoped_ptr<TransportFeedbackAdapter> transport_feedback_adapter_;
88  int min_bitrate_bps_;
89
90  RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(CongestionController);
91};
92
93}  // namespace webrtc
94
95#endif  // WEBRTC_CALL_CONGESTION_CONTROLLER_H_
96