xref: /aosp_15_r20/external/webrtc/modules/congestion_controller/rtp/control_handler.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2018 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_RTP_CONTROL_HANDLER_H_
12 #define MODULES_CONGESTION_CONTROLLER_RTP_CONTROL_HANDLER_H_
13 
14 #include <stdint.h>
15 
16 #include "absl/types/optional.h"
17 #include "api/sequence_checker.h"
18 #include "api/transport/network_types.h"
19 #include "api/units/data_size.h"
20 #include "api/units/time_delta.h"
21 #include "rtc_base/system/no_unique_address.h"
22 
23 namespace webrtc {
24 // This is used to observe the network controller state and route calls to
25 // the proper handler. It also keeps cached values for safe asynchronous use.
26 // This makes sure that things running on the worker queue can't access state
27 // in RtpTransportControllerSend, which would risk causing data race on
28 // destruction unless members are properly ordered.
29 class CongestionControlHandler {
30  public:
31   CongestionControlHandler();
32   ~CongestionControlHandler();
33 
34   CongestionControlHandler(const CongestionControlHandler&) = delete;
35   CongestionControlHandler& operator=(const CongestionControlHandler&) = delete;
36 
37   void SetTargetRate(TargetTransferRate new_target_rate);
38   void SetNetworkAvailability(bool network_available);
39   void SetPacerQueue(TimeDelta expected_queue_time);
40   absl::optional<TargetTransferRate> GetUpdate();
41 
42  private:
43   absl::optional<TargetTransferRate> last_incoming_;
44   absl::optional<TargetTransferRate> last_reported_;
45   bool network_available_ = true;
46   bool encoder_paused_in_last_report_ = false;
47 
48   const bool disable_pacer_emergency_stop_;
49   int64_t pacer_expected_queue_ms_ = 0;
50 
51   RTC_NO_UNIQUE_ADDRESS SequenceChecker sequenced_checker_;
52 };
53 }  // namespace webrtc
54 #endif  // MODULES_CONGESTION_CONTROLLER_RTP_CONTROL_HANDLER_H_
55