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