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