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 | |
| 11 | #ifndef WEBRTC_MODULES_PACING_BITRATE_PROBER_H_ |
| 12 | #define WEBRTC_MODULES_PACING_BITRATE_PROBER_H_ |
| 13 | |
philipel | dd32486 | 2016-05-06 17:06:14 +0200 | [diff] [blame] | 14 | #include <queue> |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 15 | |
philipel | 4a1ec1e | 2016-08-15 11:51:06 -0700 | [diff] [blame] | 16 | #include "webrtc/base/basictypes.h" |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 17 | #include "webrtc/typedefs.h" |
| 18 | |
| 19 | namespace webrtc { |
| 20 | |
| 21 | // Note that this class isn't thread-safe by itself and therefore relies |
| 22 | // on being protected by the caller. |
| 23 | class BitrateProber { |
| 24 | public: |
| 25 | BitrateProber(); |
| 26 | |
| 27 | void SetEnabled(bool enable); |
| 28 | |
| 29 | // Returns true if the prober is in a probing session, i.e., it currently |
| 30 | // wants packets to be sent out according to the time returned by |
| 31 | // TimeUntilNextProbe(). |
| 32 | bool IsProbing() const; |
| 33 | |
Peter Boström | 0453ef8 | 2016-02-16 16:23:08 +0100 | [diff] [blame] | 34 | // Initializes a new probing session if the prober is allowed to probe. Does |
| 35 | // not initialize the prober unless the packet size is large enough to probe |
| 36 | // with. |
philipel | 4a1ec1e | 2016-08-15 11:51:06 -0700 | [diff] [blame] | 37 | void OnIncomingPacket(size_t packet_size); |
| 38 | |
isheriff | cc5903e | 2016-10-04 08:29:38 -0700 | [diff] [blame] | 39 | // Create a cluster used to probe for |bitrate_bps| with |num_probes| number |
| 40 | // of probes. |
philipel | fd58b61 | 2017-01-04 07:05:25 -0800 | [diff] [blame] | 41 | void CreateProbeCluster(int bitrate_bps); |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 42 | |
isheriff | cc5903e | 2016-10-04 08:29:38 -0700 | [diff] [blame] | 43 | // 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] | 44 | // get accurate probing. |
| 45 | int TimeUntilNextProbe(int64_t now_ms); |
| 46 | |
philipel | dd32486 | 2016-05-06 17:06:14 +0200 | [diff] [blame] | 47 | // Which cluster that is currently being used for probing. |
| 48 | int CurrentClusterId() const; |
| 49 | |
isheriff | cc5903e | 2016-10-04 08:29:38 -0700 | [diff] [blame] | 50 | // Returns the minimum number of bytes that the prober recommends for |
| 51 | // the next probe. |
| 52 | size_t RecommendedMinProbeSize() const; |
Stefan Holmer | 01b4888 | 2015-05-05 10:21:24 +0200 | [diff] [blame] | 53 | |
isheriff | cc5903e | 2016-10-04 08:29:38 -0700 | [diff] [blame] | 54 | // Called to report to the prober that a probe has been sent. In case of |
| 55 | // multiple packets per probe, this call would be made at the end of sending |
| 56 | // the last packet in probe. |probe_size| is the total size of all packets |
| 57 | // in probe. |
| 58 | void ProbeSent(int64_t now_ms, size_t probe_size); |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 59 | |
| 60 | private: |
Irfan Sheriff | 6e11efa | 2016-08-02 12:57:37 -0700 | [diff] [blame] | 61 | enum class ProbingState { |
| 62 | // Probing will not be triggered in this state at all times. |
| 63 | kDisabled, |
| 64 | // Probing is enabled and ready to trigger on the first packet arrival. |
| 65 | kInactive, |
| 66 | // Probe cluster is filled with the set of data rates to be probed and |
| 67 | // probes are being sent. |
| 68 | kActive, |
| 69 | // Probing is enabled, but currently suspended until an explicit trigger |
| 70 | // to start probing again. |
| 71 | kSuspended, |
| 72 | }; |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 73 | |
isheriff | cc5903e | 2016-10-04 08:29:38 -0700 | [diff] [blame] | 74 | // A probe cluster consists of a set of probes. Each probe in turn can be |
sprang | ebfbc8e | 2017-01-10 01:27:28 -0800 | [diff] [blame] | 75 | // divided into a number of packets to accomodate the MTU on the network. |
philipel | dd32486 | 2016-05-06 17:06:14 +0200 | [diff] [blame] | 76 | struct ProbeCluster { |
philipel | fd58b61 | 2017-01-04 07:05:25 -0800 | [diff] [blame] | 77 | int min_probes = 0; |
sprang | ebfbc8e | 2017-01-10 01:27:28 -0800 | [diff] [blame] | 78 | int sent_probes = 0; |
philipel | fd58b61 | 2017-01-04 07:05:25 -0800 | [diff] [blame] | 79 | int min_bytes = 0; |
sprang | ebfbc8e | 2017-01-10 01:27:28 -0800 | [diff] [blame] | 80 | int sent_bytes = 0; |
philipel | fd58b61 | 2017-01-04 07:05:25 -0800 | [diff] [blame] | 81 | int bitrate_bps = 0; |
philipel | dd32486 | 2016-05-06 17:06:14 +0200 | [diff] [blame] | 82 | int id = -1; |
| 83 | }; |
| 84 | |
Irfan Sheriff | 6e11efa | 2016-08-02 12:57:37 -0700 | [diff] [blame] | 85 | // Resets the state of the prober and clears any cluster/timing data tracked. |
| 86 | void ResetState(); |
| 87 | |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 88 | ProbingState probing_state_; |
| 89 | // Probe bitrate per packet. These are used to compute the delta relative to |
| 90 | // the previous probe packet based on the size and time when that packet was |
| 91 | // sent. |
philipel | dd32486 | 2016-05-06 17:06:14 +0200 | [diff] [blame] | 92 | std::queue<ProbeCluster> clusters_; |
sprang | ebfbc8e | 2017-01-10 01:27:28 -0800 | [diff] [blame] | 93 | // A probe can include one or more packets. |
| 94 | size_t probe_size_last_sent_; |
| 95 | // The last time a probe was sent. |
| 96 | int64_t time_last_probe_sent_ms_; |
philipel | 29dca2c | 2016-05-13 11:13:05 +0200 | [diff] [blame] | 97 | int next_cluster_id_; |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 98 | }; |
| 99 | } // namespace webrtc |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 100 | #endif // WEBRTC_MODULES_PACING_BITRATE_PROBER_H_ |