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 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 14 | #include <stdint.h> |
Sebastian Jansson | 74c066c | 2018-10-15 14:31:24 +0200 | [diff] [blame] | 15 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 16 | #include "absl/types/optional.h" |
| 17 | #include "api/transport/network_types.h" |
| 18 | #include "api/units/data_size.h" |
| 19 | #include "api/units/time_delta.h" |
Sebastian Jansson | 74c066c | 2018-10-15 14:31:24 +0200 | [diff] [blame] | 20 | #include "modules/pacing/paced_sender.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame^] | 21 | #include "rtc_base/constructor_magic.h" |
Sebastian Jansson | 74c066c | 2018-10-15 14:31:24 +0200 | [diff] [blame] | 22 | #include "rtc_base/sequenced_task_checker.h" |
| 23 | |
| 24 | namespace webrtc { |
| 25 | // This is used to observe the network controller state and route calls to |
| 26 | // the proper handler. It also keeps cached values for safe asynchronous use. |
| 27 | // This makes sure that things running on the worker queue can't access state |
| 28 | // in SendSideCongestionController, which would risk causing data race on |
| 29 | // destruction unless members are properly ordered. |
| 30 | class CongestionControlHandler { |
| 31 | public: |
Sebastian Jansson | 1618095 | 2018-12-12 16:49:10 +0100 | [diff] [blame] | 32 | CongestionControlHandler(); |
Sebastian Jansson | 74c066c | 2018-10-15 14:31:24 +0200 | [diff] [blame] | 33 | ~CongestionControlHandler(); |
| 34 | |
Sebastian Jansson | 1618095 | 2018-12-12 16:49:10 +0100 | [diff] [blame] | 35 | void SetTargetRate(TargetTransferRate new_target_rate); |
| 36 | void SetNetworkAvailability(bool network_available); |
| 37 | void SetPacerQueue(TimeDelta expected_queue_time); |
| 38 | absl::optional<TargetTransferRate> GetUpdate(); |
Sebastian Jansson | 74c066c | 2018-10-15 14:31:24 +0200 | [diff] [blame] | 39 | |
| 40 | private: |
Sebastian Jansson | 1618095 | 2018-12-12 16:49:10 +0100 | [diff] [blame] | 41 | absl::optional<TargetTransferRate> last_incoming_; |
| 42 | absl::optional<TargetTransferRate> last_reported_; |
Sebastian Jansson | 74c066c | 2018-10-15 14:31:24 +0200 | [diff] [blame] | 43 | bool network_available_ = true; |
Sebastian Jansson | 1618095 | 2018-12-12 16:49:10 +0100 | [diff] [blame] | 44 | bool encoder_paused_in_last_report_ = false; |
| 45 | |
Christoffer Rodbro | b357e54 | 2018-11-23 11:19:32 +0100 | [diff] [blame] | 46 | const bool pacer_pushback_experiment_; |
| 47 | const bool disable_pacer_emergency_stop_; |
Sebastian Jansson | 74c066c | 2018-10-15 14:31:24 +0200 | [diff] [blame] | 48 | int64_t pacer_expected_queue_ms_ = 0; |
| 49 | double encoding_rate_ratio_ = 1.0; |
| 50 | |
| 51 | rtc::SequencedTaskChecker sequenced_checker_; |
Sebastian Jansson | 1618095 | 2018-12-12 16:49:10 +0100 | [diff] [blame] | 52 | RTC_DISALLOW_COPY_AND_ASSIGN(CongestionControlHandler); |
Sebastian Jansson | 74c066c | 2018-10-15 14:31:24 +0200 | [diff] [blame] | 53 | }; |
| 54 | } // namespace webrtc |
| 55 | #endif // MODULES_CONGESTION_CONTROLLER_RTP_CONTROL_HANDLER_H_ |