| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_MODULES_PACING_BITRATE_PROBER_H_ | 11 #ifndef WEBRTC_MODULES_PACING_BITRATE_PROBER_H_ |
| 12 #define WEBRTC_MODULES_PACING_BITRATE_PROBER_H_ | 12 #define WEBRTC_MODULES_PACING_BITRATE_PROBER_H_ |
| 13 | 13 |
| 14 #include <cstddef> | 14 #include <cstddef> |
| 15 #include <list> | 15 #include <list> |
| 16 #include <queue> | 16 #include <queue> |
| 17 | 17 |
| 18 #include "webrtc/typedefs.h" | 18 #include "webrtc/typedefs.h" |
| 19 | 19 |
| 20 namespace webrtc { | 20 namespace webrtc { |
| 21 | 21 |
| 22 // Note that this class isn't thread-safe by itself and therefore relies | 22 // Note that this class isn't thread-safe by itself and therefore relies |
| 23 // on being protected by the caller. | 23 // on being protected by the caller. |
| 24 class BitrateProber { | 24 class BitrateProber { |
| 25 public: | 25 public: |
| 26 BitrateProber(); | 26 BitrateProber(); |
| 27 | 27 |
| 28 enum class State { |
| 29 // Probing will not be triggered in this state at all times. |
| 30 kDisabled, |
| 31 // Probing is enabled, but currently inactive. |
| 32 kInactive, |
| 33 // Probe cluster is filled with the set of data rates to be probed and |
| 34 // probing is active. |
| 35 kActive, |
| 36 // Probing is enabled and complete. No active probing until an explicit |
| 37 // request comes in again. |
| 38 kComplete, |
| 39 }; |
| 40 |
| 28 void SetEnabled(bool enable); | 41 void SetEnabled(bool enable); |
| 29 | 42 |
| 30 // Returns true if the prober is in a probing session, i.e., it currently | 43 // 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 | 44 // wants packets to be sent out according to the time returned by |
| 32 // TimeUntilNextProbe(). | 45 // TimeUntilNextProbe(). |
| 33 bool IsProbing() const; | 46 bool IsProbing() const; |
| 34 | 47 |
| 35 // Initializes a new probing session if the prober is allowed to probe. Does | 48 // Initializes a new probing session. |
| 36 // not initialize the prober unless the packet size is large enough to probe | 49 // Returns true on success, false on failure. |
| 37 // with. | 50 bool InitiateProbing(uint32_t bitrate_bps, |
| 38 void OnIncomingPacket(uint32_t bitrate_bps, | 51 const int* multipliers, |
| 39 size_t packet_size, | 52 int multiplier_count); |
| 40 int64_t now_ms); | |
| 41 | 53 |
| 42 // Returns the number of milliseconds until the next packet should be sent to | 54 // Returns the number of milliseconds until the next packet should be sent to |
| 43 // get accurate probing. | 55 // get accurate probing. |
| 44 int TimeUntilNextProbe(int64_t now_ms); | 56 int TimeUntilNextProbe(int64_t now_ms); |
| 45 | 57 |
| 46 // Which cluster that is currently being used for probing. | 58 // Which cluster that is currently being used for probing. |
| 47 int CurrentClusterId() const; | 59 int CurrentClusterId() const; |
| 48 | 60 |
| 49 // Returns the number of bytes that the prober recommends for the next probe | 61 // Returns the number of bytes that the prober recommends for the next probe |
| 50 // packet. | 62 // packet. |
| 51 size_t RecommendedPacketSize() const; | 63 size_t RecommendedPacketSize() const; |
| 52 | 64 |
| 53 // Called to report to the prober that a packet has been sent, which helps the | 65 // Notifies the prober that a probe packet has been sent, which helps the |
| 54 // prober know when to move to the next packet in a probe. | 66 // prober move to the next packet in a probe. |
| 55 void PacketSent(int64_t now_ms, size_t packet_size); | 67 // Returns |probing_state_| after the call. |
| 68 State PacketSent(int64_t now_ms, size_t packet_size); |
| 56 | 69 |
| 57 private: | 70 private: |
| 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 }; | |
| 70 | |
| 71 struct ProbeCluster { | 71 struct ProbeCluster { |
| 72 int max_probe_packets = 0; | 72 int max_probe_packets = 0; |
| 73 int sent_probe_packets = 0; | 73 int sent_probe_packets = 0; |
| 74 int probe_bitrate_bps = 0; | 74 int probe_bitrate_bps = 0; |
| 75 int id = -1; | 75 int id = -1; |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 // Resets the state of the prober and clears any cluster/timing data tracked. | 78 // Resets the state of the prober and clears any cluster/timing data tracked. |
| 79 void ResetState(); | 79 void ResetState(); |
| 80 | 80 |
| 81 ProbingState probing_state_; | 81 State probing_state_; |
| 82 // Probe bitrate per packet. These are used to compute the delta relative to | 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 | 83 // the previous probe packet based on the size and time when that packet was |
| 84 // sent. | 84 // sent. |
| 85 std::queue<ProbeCluster> clusters_; | 85 std::queue<ProbeCluster> clusters_; |
| 86 size_t packet_size_last_sent_; | 86 size_t packet_size_last_sent_; |
| 87 // The last time a probe was sent. | 87 // The last time a probe was sent. |
| 88 int64_t time_last_probe_sent_ms_; | 88 int64_t time_last_probe_sent_ms_; |
| 89 int next_cluster_id_; | 89 int next_cluster_id_; |
| 90 }; | 90 }; |
| 91 } // namespace webrtc | 91 } // namespace webrtc |
| 92 #endif // WEBRTC_MODULES_PACING_BITRATE_PROBER_H_ | 92 #endif // WEBRTC_MODULES_PACING_BITRATE_PROBER_H_ |
| OLD | NEW |