blob: a4adefc5eed2444730e350fe82a5e355853ee010 [file] [log] [blame]
sprang233bd872015-09-08 20:25:161/*
2 * Copyright (c) 2015 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
Mirko Bonadei92ea95e2017-09-15 04:47:3111#ifndef MODULES_REMOTE_BITRATE_ESTIMATOR_REMOTE_ESTIMATOR_PROXY_H_
12#define MODULES_REMOTE_BITRATE_ESTIMATOR_REMOTE_ESTIMATOR_PROXY_H_
sprang233bd872015-09-08 20:25:1613
14#include <map>
15#include <vector>
16
Per Kjellander52f7ae72019-09-10 17:28:0617#include "api/transport/network_control.h"
Niels Möllerdecc0762019-04-17 12:14:3218#include "api/transport/webrtc_key_value_config.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3119#include "modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
Niels Möllerdecc0762019-04-17 12:14:3220#include "rtc_base/experiments/field_trial_parser.h"
Johannes Kron3c15f462019-04-02 13:54:2221#include "rtc_base/numerics/sequence_number_util.h"
Markus Handelledcb9072020-07-07 12:12:1522#include "rtc_base/synchronization/mutex.h"
sprang233bd872015-09-08 20:25:1623
24namespace webrtc {
25
26class Clock;
27class PacketRouter;
28namespace rtcp {
29class TransportFeedback;
30}
31
32// Class used when send-side BWE is enabled: This proxy is instantiated on the
33// receive side. It buffers a number of receive timestamps and then sends
34// transport feedback messages back too the send side.
35
36class RemoteEstimatorProxy : public RemoteBitrateEstimator {
37 public:
Sebastian Janssonaa01f272019-01-30 10:28:5938 RemoteEstimatorProxy(Clock* clock,
Niels Möllerdecc0762019-04-17 12:14:3239 TransportFeedbackSenderInterface* feedback_sender,
Per Kjellander52f7ae72019-09-10 17:28:0640 const WebRtcKeyValueConfig* key_value_config,
41 NetworkStateEstimator* network_state_estimator);
Mirko Bonadei64f813e2018-07-18 13:37:0142 ~RemoteEstimatorProxy() override;
sprang233bd872015-09-08 20:25:1643
sprang233bd872015-09-08 20:25:1644 void IncomingPacket(int64_t arrival_time_ms,
45 size_t payload_size,
pbos2169d8b2016-06-20 18:53:0246 const RTPHeader& header) override;
Stefan Holmer62a5ccd2016-02-16 16:07:2147 void RemoveStream(uint32_t ssrc) override {}
sprang233bd872015-09-08 20:25:1648 bool LatestEstimate(std::vector<unsigned int>* ssrcs,
49 unsigned int* bitrate_bps) const override;
stefan4fbd1452015-09-28 10:57:1450 void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override {}
51 void SetMinBitrate(int min_bitrate_bps) override {}
sprang233bd872015-09-08 20:25:1652 int64_t TimeUntilNextProcess() override;
pbosa26ac922016-02-25 12:50:0153 void Process() override;
minyue8927b052016-11-07 15:51:2054 void OnBitrateChanged(int bitrate);
Johannes Kronf59666b2019-04-08 10:57:0655 void SetSendPeriodicFeedback(bool send_periodic_feedback);
sprang233bd872015-09-08 20:25:1656
sprang233bd872015-09-08 20:25:1657 private:
Niels Möllerdecc0762019-04-17 12:14:3258 struct TransportWideFeedbackConfig {
Danil Chapovalov55284022020-02-07 13:53:5259 FieldTrialParameter<TimeDelta> back_window{"wind", TimeDelta::Millis(500)};
60 FieldTrialParameter<TimeDelta> min_interval{"min", TimeDelta::Millis(50)};
61 FieldTrialParameter<TimeDelta> max_interval{"max", TimeDelta::Millis(250)};
62 FieldTrialParameter<TimeDelta> default_interval{"def",
63 TimeDelta::Millis(100)};
Niels Möller8169db62019-06-10 08:09:5464 FieldTrialParameter<double> bandwidth_fraction{"frac", 0.05};
Niels Möllerdecc0762019-04-17 12:14:3265 explicit TransportWideFeedbackConfig(
66 const WebRtcKeyValueConfig* key_value_config) {
Niels Möller8169db62019-06-10 08:09:5467 ParseFieldTrial({&back_window, &min_interval, &max_interval,
68 &default_interval, &bandwidth_fraction},
69 key_value_config->Lookup(
70 "WebRTC-Bwe-TransportWideFeedbackIntervals"));
Niels Möllerdecc0762019-04-17 12:14:3271 }
72 };
73
Johannes Kron599d5922019-02-19 13:27:5774 static const int kMaxNumberOfPackets;
Per Kjellanderf7cb16f2019-09-09 08:31:2175
Johannes Kron599d5922019-02-19 13:27:5776 void SendPeriodicFeedbacks() RTC_EXCLUSIVE_LOCKS_REQUIRED(&lock_);
77 void SendFeedbackOnRequest(int64_t sequence_number,
78 const FeedbackRequest& feedback_request)
79 RTC_EXCLUSIVE_LOCKS_REQUIRED(&lock_);
80 static int64_t BuildFeedbackPacket(
81 uint8_t feedback_packet_count,
82 uint32_t media_ssrc,
83 int64_t base_sequence_number,
84 std::map<int64_t, int64_t>::const_iterator
85 begin_iterator, // |begin_iterator| is inclusive.
86 std::map<int64_t, int64_t>::const_iterator
87 end_iterator, // |end_iterator| is exclusive.
88 rtcp::TransportFeedback* feedback_packet);
sprang233bd872015-09-08 20:25:1689
Sebastian Janssonaa01f272019-01-30 10:28:5990 Clock* const clock_;
Danil Chapovalov599df852017-09-25 13:19:3591 TransportFeedbackSenderInterface* const feedback_sender_;
Niels Möllerdecc0762019-04-17 12:14:3292 const TransportWideFeedbackConfig send_config_;
sprang233bd872015-09-08 20:25:1693 int64_t last_process_time_ms_;
94
Markus Handelledcb9072020-07-07 12:12:1595 Mutex lock_;
Per Kjellander52f7ae72019-09-10 17:28:0696 // |network_state_estimator_| may be null.
97 NetworkStateEstimator* const network_state_estimator_
98 RTC_PT_GUARDED_BY(&lock_);
danilchap56359be2017-09-07 14:53:4599 uint32_t media_ssrc_ RTC_GUARDED_BY(&lock_);
Johannes Kron599d5922019-02-19 13:27:57100 uint8_t feedback_packet_count_ RTC_GUARDED_BY(&lock_);
Johannes Kron3c15f462019-04-02 13:54:22101 SeqNumUnwrapper<uint16_t> unwrapper_ RTC_GUARDED_BY(&lock_);
102 absl::optional<int64_t> periodic_window_start_seq_ RTC_GUARDED_BY(&lock_);
sprang233bd872015-09-08 20:25:16103 // Map unwrapped seq -> time.
danilchap56359be2017-09-07 14:53:45104 std::map<int64_t, int64_t> packet_arrival_times_ RTC_GUARDED_BY(&lock_);
105 int64_t send_interval_ms_ RTC_GUARDED_BY(&lock_);
Johannes Kronf59666b2019-04-08 10:57:06106 bool send_periodic_feedback_ RTC_GUARDED_BY(&lock_);
Per Kjellander52f7ae72019-09-10 17:28:06107
108 // Unwraps absolute send times.
109 uint32_t previous_abs_send_time_ RTC_GUARDED_BY(&lock_);
110 Timestamp abs_send_timestamp_ RTC_GUARDED_BY(&lock_);
sprang233bd872015-09-08 20:25:16111};
112
113} // namespace webrtc
114
Mirko Bonadei92ea95e2017-09-15 04:47:31115#endif // MODULES_REMOTE_BITRATE_ESTIMATOR_REMOTE_ESTIMATOR_PROXY_H_