blob: e9016c78a5a9a1171fbd94658437e49c3e1bf2bf [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/pacing/paced_sender.h"
Steve Anton10542f22019-01-11 09:11:00 -080021#include "rtc_base/constructor_magic.h"
Sebastian Jansson74c066c2018-10-15 14:31:24 +020022#include "rtc_base/sequenced_task_checker.h"
23
24namespace 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.
30class CongestionControlHandler {
31 public:
Sebastian Jansson16180952018-12-12 16:49:10 +010032 CongestionControlHandler();
Sebastian Jansson74c066c2018-10-15 14:31:24 +020033 ~CongestionControlHandler();
34
Sebastian Jansson16180952018-12-12 16:49:10 +010035 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 Jansson74c066c2018-10-15 14:31:24 +020039
40 private:
Sebastian Jansson16180952018-12-12 16:49:10 +010041 absl::optional<TargetTransferRate> last_incoming_;
42 absl::optional<TargetTransferRate> last_reported_;
Sebastian Jansson74c066c2018-10-15 14:31:24 +020043 bool network_available_ = true;
Sebastian Jansson16180952018-12-12 16:49:10 +010044 bool encoder_paused_in_last_report_ = false;
45
Christoffer Rodbrob357e542018-11-23 11:19:32 +010046 const bool pacer_pushback_experiment_;
47 const bool disable_pacer_emergency_stop_;
Sebastian Jansson74c066c2018-10-15 14:31:24 +020048 int64_t pacer_expected_queue_ms_ = 0;
49 double encoding_rate_ratio_ = 1.0;
50
51 rtc::SequencedTaskChecker sequenced_checker_;
Sebastian Jansson16180952018-12-12 16:49:10 +010052 RTC_DISALLOW_COPY_AND_ASSIGN(CongestionControlHandler);
Sebastian Jansson74c066c2018-10-15 14:31:24 +020053};
54} // namespace webrtc
55#endif // MODULES_CONGESTION_CONTROLLER_RTP_CONTROL_HANDLER_H_