stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 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 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_PACING_BITRATE_PROBER_H_ |
| 12 | #define MODULES_PACING_BITRATE_PROBER_H_ |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 13 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 14 | #include <stddef.h> |
| 15 | #include <stdint.h> |
philipel | dd32486 | 2016-05-06 17:06:14 +0200 | [diff] [blame] | 16 | #include <queue> |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 17 | |
Jonas Olsson | 24923e8 | 2019-03-27 14:19:04 +0100 | [diff] [blame^] | 18 | #include "api/transport/field_trial_based_config.h" |
Danil Chapovalov | db12856 | 2018-09-17 13:11:50 +0200 | [diff] [blame] | 19 | #include "api/transport/network_types.h" |
Jonas Olsson | 24923e8 | 2019-03-27 14:19:04 +0100 | [diff] [blame^] | 20 | #include "rtc_base/experiments/field_trial_parser.h" |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
philipel | c3b3f7a | 2017-03-29 01:23:13 -0700 | [diff] [blame] | 23 | class RtcEventLog; |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 24 | |
Jonas Olsson | 24923e8 | 2019-03-27 14:19:04 +0100 | [diff] [blame^] | 25 | struct BitrateProberConfig { |
| 26 | explicit BitrateProberConfig(const WebRtcKeyValueConfig* key_value_config); |
| 27 | BitrateProberConfig(const BitrateProberConfig&) = default; |
| 28 | BitrateProberConfig& operator=(const BitrateProberConfig&) = default; |
| 29 | ~BitrateProberConfig() = default; |
| 30 | |
| 31 | // The minimum number probing packets used. |
| 32 | FieldTrialParameter<int> min_probe_packets_sent; |
| 33 | // A minimum interval between probes to allow scheduling to be feasible. |
| 34 | FieldTrialParameter<TimeDelta> min_probe_delta; |
| 35 | // The minimum probing duration. |
| 36 | FieldTrialParameter<TimeDelta> min_probe_duration; |
| 37 | // Maximum amount of time each probe can be delayed. Probe cluster is reset |
| 38 | // and retried from the start when this limit is reached. |
| 39 | FieldTrialParameter<TimeDelta> max_probe_delay; |
| 40 | }; |
| 41 | |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 42 | // Note that this class isn't thread-safe by itself and therefore relies |
| 43 | // on being protected by the caller. |
| 44 | class BitrateProber { |
| 45 | public: |
Jonas Olsson | 24923e8 | 2019-03-27 14:19:04 +0100 | [diff] [blame^] | 46 | explicit BitrateProber(const WebRtcKeyValueConfig& field_trials); |
Mirko Bonadei | b471c90 | 2018-07-18 14:11:27 +0200 | [diff] [blame] | 47 | ~BitrateProber(); |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 48 | |
| 49 | void SetEnabled(bool enable); |
| 50 | |
| 51 | // Returns true if the prober is in a probing session, i.e., it currently |
| 52 | // wants packets to be sent out according to the time returned by |
| 53 | // TimeUntilNextProbe(). |
| 54 | bool IsProbing() const; |
| 55 | |
Peter Boström | 0453ef8 | 2016-02-16 16:23:08 +0100 | [diff] [blame] | 56 | // Initializes a new probing session if the prober is allowed to probe. Does |
| 57 | // not initialize the prober unless the packet size is large enough to probe |
| 58 | // with. |
philipel | 4a1ec1e | 2016-08-15 11:51:06 -0700 | [diff] [blame] | 59 | void OnIncomingPacket(size_t packet_size); |
| 60 | |
isheriff | cc5903e | 2016-10-04 08:29:38 -0700 | [diff] [blame] | 61 | // Create a cluster used to probe for |bitrate_bps| with |num_probes| number |
| 62 | // of probes. |
Piotr (Peter) Slatala | c39f462 | 2019-02-15 07:38:04 -0800 | [diff] [blame] | 63 | void CreateProbeCluster(int bitrate_bps, int64_t now_ms, int cluster_id); |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 64 | |
isheriff | cc5903e | 2016-10-04 08:29:38 -0700 | [diff] [blame] | 65 | // Returns the number of milliseconds until the next probe should be sent to |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 66 | // get accurate probing. |
| 67 | int TimeUntilNextProbe(int64_t now_ms); |
| 68 | |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 69 | // Information about the current probing cluster. |
| 70 | PacedPacketInfo CurrentCluster() const; |
philipel | dd32486 | 2016-05-06 17:06:14 +0200 | [diff] [blame] | 71 | |
isheriff | cc5903e | 2016-10-04 08:29:38 -0700 | [diff] [blame] | 72 | // Returns the minimum number of bytes that the prober recommends for |
| 73 | // the next probe. |
| 74 | size_t RecommendedMinProbeSize() const; |
Stefan Holmer | 01b4888 | 2015-05-05 10:21:24 +0200 | [diff] [blame] | 75 | |
isheriff | cc5903e | 2016-10-04 08:29:38 -0700 | [diff] [blame] | 76 | // Called to report to the prober that a probe has been sent. In case of |
| 77 | // multiple packets per probe, this call would be made at the end of sending |
| 78 | // the last packet in probe. |probe_size| is the total size of all packets |
| 79 | // in probe. |
| 80 | void ProbeSent(int64_t now_ms, size_t probe_size); |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 81 | |
| 82 | private: |
Irfan Sheriff | 6e11efa | 2016-08-02 12:57:37 -0700 | [diff] [blame] | 83 | enum class ProbingState { |
| 84 | // Probing will not be triggered in this state at all times. |
| 85 | kDisabled, |
| 86 | // Probing is enabled and ready to trigger on the first packet arrival. |
| 87 | kInactive, |
| 88 | // Probe cluster is filled with the set of data rates to be probed and |
| 89 | // probes are being sent. |
| 90 | kActive, |
| 91 | // Probing is enabled, but currently suspended until an explicit trigger |
| 92 | // to start probing again. |
| 93 | kSuspended, |
| 94 | }; |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 95 | |
isheriff | cc5903e | 2016-10-04 08:29:38 -0700 | [diff] [blame] | 96 | // A probe cluster consists of a set of probes. Each probe in turn can be |
sergeyu | 6dbbd89 | 2017-01-17 15:07:59 -0800 | [diff] [blame] | 97 | // divided into a number of packets to accommodate the MTU on the network. |
philipel | dd32486 | 2016-05-06 17:06:14 +0200 | [diff] [blame] | 98 | struct ProbeCluster { |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 99 | PacedPacketInfo pace_info; |
sergeyu | 6dbbd89 | 2017-01-17 15:07:59 -0800 | [diff] [blame] | 100 | |
| 101 | int sent_probes = 0; |
| 102 | int sent_bytes = 0; |
Stefan Holmer | 0e3213a | 2017-02-08 15:19:05 +0100 | [diff] [blame] | 103 | int64_t time_created_ms = -1; |
sergeyu | 6dbbd89 | 2017-01-17 15:07:59 -0800 | [diff] [blame] | 104 | int64_t time_started_ms = -1; |
sergeyu | 6dbbd89 | 2017-01-17 15:07:59 -0800 | [diff] [blame] | 105 | int retries = 0; |
philipel | dd32486 | 2016-05-06 17:06:14 +0200 | [diff] [blame] | 106 | }; |
| 107 | |
sergeyu | 6dbbd89 | 2017-01-17 15:07:59 -0800 | [diff] [blame] | 108 | int64_t GetNextProbeTime(const ProbeCluster& cluster); |
| 109 | |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 110 | ProbingState probing_state_; |
sergeyu | 6dbbd89 | 2017-01-17 15:07:59 -0800 | [diff] [blame] | 111 | |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 112 | // Probe bitrate per packet. These are used to compute the delta relative to |
| 113 | // the previous probe packet based on the size and time when that packet was |
| 114 | // sent. |
philipel | dd32486 | 2016-05-06 17:06:14 +0200 | [diff] [blame] | 115 | std::queue<ProbeCluster> clusters_; |
sergeyu | 6dbbd89 | 2017-01-17 15:07:59 -0800 | [diff] [blame] | 116 | |
| 117 | // Time the next probe should be sent when in kActive state. |
| 118 | int64_t next_probe_time_ms_; |
Jonas Olsson | 8f43384 | 2019-03-25 10:10:31 +0100 | [diff] [blame] | 119 | |
| 120 | int total_probe_count_; |
| 121 | int total_failed_probe_count_; |
Jonas Olsson | 24923e8 | 2019-03-27 14:19:04 +0100 | [diff] [blame^] | 122 | |
| 123 | BitrateProberConfig config_; |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 124 | }; |
sergeyu | 6dbbd89 | 2017-01-17 15:07:59 -0800 | [diff] [blame] | 125 | |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 126 | } // namespace webrtc |
sergeyu | 6dbbd89 | 2017-01-17 15:07:59 -0800 | [diff] [blame] | 127 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 128 | #endif // MODULES_PACING_BITRATE_PROBER_H_ |