Sebastian Jansson | 74c066c | 2018-10-15 14:31:24 +0200 | [diff] [blame] | 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 <algorithm> |
| 15 | #include <memory> |
| 16 | |
| 17 | #include "api/transport/network_control.h" |
| 18 | #include "modules/congestion_controller/include/network_changed_observer.h" |
| 19 | #include "modules/pacing/paced_sender.h" |
| 20 | #include "rtc_base/sequenced_task_checker.h" |
| 21 | |
| 22 | namespace webrtc { |
| 23 | // This is used to observe the network controller state and route calls to |
| 24 | // the proper handler. It also keeps cached values for safe asynchronous use. |
| 25 | // This makes sure that things running on the worker queue can't access state |
| 26 | // in SendSideCongestionController, which would risk causing data race on |
| 27 | // destruction unless members are properly ordered. |
| 28 | class CongestionControlHandler { |
| 29 | public: |
| 30 | CongestionControlHandler(NetworkChangedObserver* observer, |
| 31 | PacedSender* pacer); |
| 32 | ~CongestionControlHandler(); |
| 33 | |
| 34 | void PostUpdates(NetworkControlUpdate update); |
| 35 | |
| 36 | void OnNetworkAvailability(NetworkAvailability msg); |
| 37 | void OnOutstandingData(DataSize in_flight_data); |
| 38 | void OnPacerQueueUpdate(TimeDelta expected_queue_time); |
| 39 | |
| 40 | absl::optional<TargetTransferRate> last_transfer_rate(); |
| 41 | |
| 42 | private: |
| 43 | void SetPacerState(bool paused); |
| 44 | void OnNetworkInvalidation(); |
| 45 | bool IsSendQueueFull() const; |
| 46 | bool HasNetworkParametersToReportChanged(int64_t bitrate_bps, |
| 47 | float loss_rate_ratio, |
| 48 | TimeDelta rtt); |
| 49 | |
| 50 | bool HasNetworkParametersToReportChanged(int64_t bitrate_bps, |
| 51 | uint8_t fraction_loss, |
| 52 | int64_t rtt); |
| 53 | NetworkChangedObserver* observer_ = nullptr; |
| 54 | PacedSender* const pacer_; |
| 55 | |
| 56 | absl::optional<TargetTransferRate> current_target_rate_msg_; |
| 57 | bool network_available_ = true; |
| 58 | bool pacer_paused_ = false; |
| 59 | int64_t last_reported_target_bitrate_bps_ = 0; |
| 60 | uint8_t last_reported_fraction_loss_ = 0; |
| 61 | int64_t last_reported_rtt_ms_ = 0; |
Christoffer Rodbro | b357e54 | 2018-11-23 11:19:32 +0100 | [diff] [blame^] | 62 | const bool pacer_pushback_experiment_; |
| 63 | const bool disable_pacer_emergency_stop_; |
Sebastian Jansson | 74c066c | 2018-10-15 14:31:24 +0200 | [diff] [blame] | 64 | uint32_t min_pushback_target_bitrate_bps_; |
| 65 | int64_t pacer_expected_queue_ms_ = 0; |
| 66 | double encoding_rate_ratio_ = 1.0; |
| 67 | |
| 68 | rtc::SequencedTaskChecker sequenced_checker_; |
| 69 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(CongestionControlHandler); |
| 70 | }; |
| 71 | } // namespace webrtc |
| 72 | #endif // MODULES_CONGESTION_CONTROLLER_RTP_CONTROL_HANDLER_H_ |