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