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: |
| 58 | enum ProbingState { kDisabled, kAllowedToProbe, kProbing, kWait }; |
| 59 | |
philipel | dd32486 | 2016-05-06 17:06:14 +0200 | [diff] [blame^] | 60 | struct ProbeCluster { |
| 61 | int max_probe_packets = 0; |
| 62 | int sent_probe_packets = 0; |
| 63 | int probe_bitrate_bps = 0; |
| 64 | int id = -1; |
| 65 | }; |
| 66 | |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 67 | ProbingState probing_state_; |
| 68 | // Probe bitrate per packet. These are used to compute the delta relative to |
| 69 | // the previous probe packet based on the size and time when that packet was |
| 70 | // sent. |
philipel | dd32486 | 2016-05-06 17:06:14 +0200 | [diff] [blame^] | 71 | std::queue<ProbeCluster> clusters_; |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 72 | size_t packet_size_last_send_; |
| 73 | int64_t time_last_send_ms_; |
philipel | dd32486 | 2016-05-06 17:06:14 +0200 | [diff] [blame^] | 74 | int cluster_id_; |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 75 | }; |
| 76 | } // namespace webrtc |
| 77 | #endif // WEBRTC_MODULES_PACING_BITRATE_PROBER_H_ |