sprang | 233bd87 | 2015-09-08 20:25:16 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #ifndef MODULES_REMOTE_BITRATE_ESTIMATOR_REMOTE_ESTIMATOR_PROXY_H_ |
| 12 | #define MODULES_REMOTE_BITRATE_ESTIMATOR_REMOTE_ESTIMATOR_PROXY_H_ |
sprang | 233bd87 | 2015-09-08 20:25:16 | [diff] [blame] | 13 | |
| 14 | #include <map> |
| 15 | #include <vector> |
| 16 | |
Per Kjellander | 52f7ae7 | 2019-09-10 17:28:06 | [diff] [blame] | 17 | #include "api/transport/network_control.h" |
Niels Möller | decc076 | 2019-04-17 12:14:32 | [diff] [blame] | 18 | #include "api/transport/webrtc_key_value_config.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 19 | #include "modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h" |
Niels Möller | decc076 | 2019-04-17 12:14:32 | [diff] [blame] | 20 | #include "rtc_base/experiments/field_trial_parser.h" |
Johannes Kron | 3c15f46 | 2019-04-02 13:54:22 | [diff] [blame] | 21 | #include "rtc_base/numerics/sequence_number_util.h" |
Markus Handell | edcb907 | 2020-07-07 12:12:15 | [diff] [blame] | 22 | #include "rtc_base/synchronization/mutex.h" |
sprang | 233bd87 | 2015-09-08 20:25:16 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
| 25 | |
| 26 | class Clock; |
| 27 | class PacketRouter; |
| 28 | namespace rtcp { |
| 29 | class 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 | |
| 36 | class RemoteEstimatorProxy : public RemoteBitrateEstimator { |
| 37 | public: |
Sebastian Jansson | aa01f27 | 2019-01-30 10:28:59 | [diff] [blame] | 38 | RemoteEstimatorProxy(Clock* clock, |
Niels Möller | decc076 | 2019-04-17 12:14:32 | [diff] [blame] | 39 | TransportFeedbackSenderInterface* feedback_sender, |
Per Kjellander | 52f7ae7 | 2019-09-10 17:28:06 | [diff] [blame] | 40 | const WebRtcKeyValueConfig* key_value_config, |
| 41 | NetworkStateEstimator* network_state_estimator); |
Mirko Bonadei | 64f813e | 2018-07-18 13:37:01 | [diff] [blame] | 42 | ~RemoteEstimatorProxy() override; |
sprang | 233bd87 | 2015-09-08 20:25:16 | [diff] [blame] | 43 | |
sprang | 233bd87 | 2015-09-08 20:25:16 | [diff] [blame] | 44 | void IncomingPacket(int64_t arrival_time_ms, |
| 45 | size_t payload_size, |
pbos | 2169d8b | 2016-06-20 18:53:02 | [diff] [blame] | 46 | const RTPHeader& header) override; |
Stefan Holmer | 62a5ccd | 2016-02-16 16:07:21 | [diff] [blame] | 47 | void RemoveStream(uint32_t ssrc) override {} |
sprang | 233bd87 | 2015-09-08 20:25:16 | [diff] [blame] | 48 | bool LatestEstimate(std::vector<unsigned int>* ssrcs, |
| 49 | unsigned int* bitrate_bps) const override; |
stefan | 4fbd145 | 2015-09-28 10:57:14 | [diff] [blame] | 50 | void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override {} |
| 51 | void SetMinBitrate(int min_bitrate_bps) override {} |
sprang | 233bd87 | 2015-09-08 20:25:16 | [diff] [blame] | 52 | int64_t TimeUntilNextProcess() override; |
pbos | a26ac92 | 2016-02-25 12:50:01 | [diff] [blame] | 53 | void Process() override; |
minyue | 8927b05 | 2016-11-07 15:51:20 | [diff] [blame] | 54 | void OnBitrateChanged(int bitrate); |
Johannes Kron | f59666b | 2019-04-08 10:57:06 | [diff] [blame] | 55 | void SetSendPeriodicFeedback(bool send_periodic_feedback); |
sprang | 233bd87 | 2015-09-08 20:25:16 | [diff] [blame] | 56 | |
sprang | 233bd87 | 2015-09-08 20:25:16 | [diff] [blame] | 57 | private: |
Niels Möller | decc076 | 2019-04-17 12:14:32 | [diff] [blame] | 58 | struct TransportWideFeedbackConfig { |
Danil Chapovalov | 5528402 | 2020-02-07 13:53:52 | [diff] [blame] | 59 | 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öller | 8169db6 | 2019-06-10 08:09:54 | [diff] [blame] | 64 | FieldTrialParameter<double> bandwidth_fraction{"frac", 0.05}; |
Niels Möller | decc076 | 2019-04-17 12:14:32 | [diff] [blame] | 65 | explicit TransportWideFeedbackConfig( |
| 66 | const WebRtcKeyValueConfig* key_value_config) { |
Niels Möller | 8169db6 | 2019-06-10 08:09:54 | [diff] [blame] | 67 | ParseFieldTrial({&back_window, &min_interval, &max_interval, |
| 68 | &default_interval, &bandwidth_fraction}, |
| 69 | key_value_config->Lookup( |
| 70 | "WebRTC-Bwe-TransportWideFeedbackIntervals")); |
Niels Möller | decc076 | 2019-04-17 12:14:32 | [diff] [blame] | 71 | } |
| 72 | }; |
| 73 | |
Johannes Kron | 599d592 | 2019-02-19 13:27:57 | [diff] [blame] | 74 | static const int kMaxNumberOfPackets; |
Per Kjellander | f7cb16f | 2019-09-09 08:31:21 | [diff] [blame] | 75 | |
Johannes Kron | 599d592 | 2019-02-19 13:27:57 | [diff] [blame] | 76 | 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); |
sprang | 233bd87 | 2015-09-08 20:25:16 | [diff] [blame] | 89 | |
Sebastian Jansson | aa01f27 | 2019-01-30 10:28:59 | [diff] [blame] | 90 | Clock* const clock_; |
Danil Chapovalov | 599df85 | 2017-09-25 13:19:35 | [diff] [blame] | 91 | TransportFeedbackSenderInterface* const feedback_sender_; |
Niels Möller | decc076 | 2019-04-17 12:14:32 | [diff] [blame] | 92 | const TransportWideFeedbackConfig send_config_; |
sprang | 233bd87 | 2015-09-08 20:25:16 | [diff] [blame] | 93 | int64_t last_process_time_ms_; |
| 94 | |
Markus Handell | edcb907 | 2020-07-07 12:12:15 | [diff] [blame] | 95 | Mutex lock_; |
Per Kjellander | 52f7ae7 | 2019-09-10 17:28:06 | [diff] [blame] | 96 | // |network_state_estimator_| may be null. |
| 97 | NetworkStateEstimator* const network_state_estimator_ |
| 98 | RTC_PT_GUARDED_BY(&lock_); |
danilchap | 56359be | 2017-09-07 14:53:45 | [diff] [blame] | 99 | uint32_t media_ssrc_ RTC_GUARDED_BY(&lock_); |
Johannes Kron | 599d592 | 2019-02-19 13:27:57 | [diff] [blame] | 100 | uint8_t feedback_packet_count_ RTC_GUARDED_BY(&lock_); |
Johannes Kron | 3c15f46 | 2019-04-02 13:54:22 | [diff] [blame] | 101 | SeqNumUnwrapper<uint16_t> unwrapper_ RTC_GUARDED_BY(&lock_); |
| 102 | absl::optional<int64_t> periodic_window_start_seq_ RTC_GUARDED_BY(&lock_); |
sprang | 233bd87 | 2015-09-08 20:25:16 | [diff] [blame] | 103 | // Map unwrapped seq -> time. |
danilchap | 56359be | 2017-09-07 14:53:45 | [diff] [blame] | 104 | std::map<int64_t, int64_t> packet_arrival_times_ RTC_GUARDED_BY(&lock_); |
| 105 | int64_t send_interval_ms_ RTC_GUARDED_BY(&lock_); |
Johannes Kron | f59666b | 2019-04-08 10:57:06 | [diff] [blame] | 106 | bool send_periodic_feedback_ RTC_GUARDED_BY(&lock_); |
Per Kjellander | 52f7ae7 | 2019-09-10 17:28:06 | [diff] [blame] | 107 | |
| 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_); |
sprang | 233bd87 | 2015-09-08 20:25:16 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | } // namespace webrtc |
| 114 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 115 | #endif // MODULES_REMOTE_BITRATE_ESTIMATOR_REMOTE_ESTIMATOR_PROXY_H_ |