• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2017 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 MODULES_CONGESTION_CONTROLLER_INCLUDE_RECEIVE_SIDE_CONGESTION_CONTROLLER_H_
12 #define MODULES_CONGESTION_CONTROLLER_INCLUDE_RECEIVE_SIDE_CONGESTION_CONTROLLER_H_
13 
14 #include <memory>
15 #include <vector>
16 
17 #include "api/transport/field_trial_based_config.h"
18 #include "api/transport/network_control.h"
19 #include "modules/include/module.h"
20 #include "modules/remote_bitrate_estimator/remote_estimator_proxy.h"
21 #include "rtc_base/constructor_magic.h"
22 #include "rtc_base/synchronization/mutex.h"
23 
24 namespace webrtc {
25 class RemoteBitrateEstimator;
26 class RemoteBitrateObserver;
27 
28 // This class represents the congestion control state for receive
29 // streams. For send side bandwidth estimation, this is simply
30 // relaying for each received RTP packet back to the sender. While for
31 // receive side bandwidth estimation, we do the estimation locally and
32 // send our results back to the sender.
33 class ReceiveSideCongestionController : public CallStatsObserver,
34                                         public Module {
35  public:
36   ReceiveSideCongestionController(Clock* clock, PacketRouter* packet_router);
37   ReceiveSideCongestionController(
38       Clock* clock,
39       PacketRouter* packet_router,
40       NetworkStateEstimator* network_state_estimator);
41 
~ReceiveSideCongestionController()42   ~ReceiveSideCongestionController() override {}
43 
44   virtual void OnReceivedPacket(int64_t arrival_time_ms,
45                                 size_t payload_size,
46                                 const RTPHeader& header);
47 
48   void SetSendPeriodicFeedback(bool send_periodic_feedback);
49   // TODO(nisse): Delete these methods, design a more specific interface.
50   virtual RemoteBitrateEstimator* GetRemoteBitrateEstimator(bool send_side_bwe);
51   virtual const RemoteBitrateEstimator* GetRemoteBitrateEstimator(
52       bool send_side_bwe) const;
53 
54   // Implements CallStatsObserver.
55   void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override;
56 
57   // This is send bitrate, used to control the rate of feedback messages.
58   void OnBitrateChanged(int bitrate_bps);
59 
60   // Implements Module.
61   int64_t TimeUntilNextProcess() override;
62   void Process() override;
63 
64  private:
65   class WrappingBitrateEstimator : public RemoteBitrateEstimator {
66    public:
67     WrappingBitrateEstimator(RemoteBitrateObserver* observer, Clock* clock);
68 
69     ~WrappingBitrateEstimator() override;
70 
71     void IncomingPacket(int64_t arrival_time_ms,
72                         size_t payload_size,
73                         const RTPHeader& header) override;
74 
75     void Process() override;
76 
77     int64_t TimeUntilNextProcess() override;
78 
79     void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override;
80 
81     void RemoveStream(unsigned int ssrc) override;
82 
83     bool LatestEstimate(std::vector<unsigned int>* ssrcs,
84                         unsigned int* bitrate_bps) const override;
85 
86     void SetMinBitrate(int min_bitrate_bps) override;
87 
88    private:
89     void PickEstimatorFromHeader(const RTPHeader& header)
90         RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
91     void PickEstimator() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
92     RemoteBitrateObserver* observer_;
93     Clock* const clock_;
94     mutable Mutex mutex_;
95     std::unique_ptr<RemoteBitrateEstimator> rbe_;
96     bool using_absolute_send_time_;
97     uint32_t packets_since_absolute_send_time_;
98     int min_bitrate_bps_;
99 
100     RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WrappingBitrateEstimator);
101   };
102 
103   const FieldTrialBasedConfig field_trial_config_;
104   WrappingBitrateEstimator remote_bitrate_estimator_;
105   RemoteEstimatorProxy remote_estimator_proxy_;
106 };
107 
108 }  // namespace webrtc
109 
110 #endif  // MODULES_CONGESTION_CONTROLLER_INCLUDE_RECEIVE_SIDE_CONGESTION_CONTROLLER_H_
111