Chromium Code Reviews| 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 <queue> | 14 #include <queue> |
| 15 | 15 |
| 16 #include "webrtc/base/basictypes.h" | 16 #include "webrtc/base/basictypes.h" |
| 17 #include "webrtc/typedefs.h" | 17 #include "webrtc/typedefs.h" |
| 18 | 18 |
| 19 namespace webrtc { | 19 namespace webrtc { |
| 20 | 20 |
| 21 // Note that this class isn't thread-safe by itself and therefore relies | 21 // Note that this class isn't thread-safe by itself and therefore relies |
| 22 // on being protected by the caller. | 22 // on being protected by the caller. |
| 23 class BitrateProber { | 23 class BitrateProber { |
| 24 public: | 24 public: |
| 25 BitrateProber(); | 25 BitrateProber(); |
| 26 | 26 |
| 27 enum class State { | |
|
danilchap
2016/08/19 17:19:34
what move this enum type into public part?
No publ
Irfan
2016/08/23 05:46:57
Done. It used to return in an earlier PS.
| |
| 28 // Initial state. No probe clusters have been set up yet for probing. | |
| 29 kInit, | |
| 30 // Probe clusters have been set up and probes are being sent. | |
| 31 kSending, | |
| 32 // Probes have been sent, waiting on probing results. | |
| 33 kWaitForResult, | |
| 34 // Probing is complete. No active probing until an explicit | |
| 35 // request for probing. | |
| 36 kComplete, | |
| 37 // Probing disabled. No probing until explicitly enabled again. | |
| 38 kDisabled, | |
| 39 }; | |
| 40 | |
| 27 void SetEnabled(bool enable); | 41 void SetEnabled(bool enable); |
| 28 | 42 |
| 29 // 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 |
| 30 // 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 |
| 31 // TimeUntilNextProbe(). | 45 // TimeUntilNextProbe(). |
| 32 bool IsProbing() const; | 46 bool IsProbing() const; |
| 33 | 47 |
| 48 bool IsExpectingProbingResults() const; | |
| 49 | |
| 50 void SetEstimatedBitrate(int bitrate_bps); | |
| 51 | |
| 34 // Initializes a new probing session if the prober is allowed to probe. Does | 52 // 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 | 53 // not initialize the prober unless the packet size is large enough to probe |
| 36 // with. | 54 // with. |
| 37 void OnIncomingPacket(size_t packet_size); | 55 void OnIncomingPacket(int64_t now_ms, size_t packet_size); |
| 38 | 56 |
| 39 // Create a cluster used to probe for |bitrate_bps| with |num_packets| number | 57 // Create a cluster used to probe for |bitrate_bps| with |num_packets| number |
| 40 // of packets. | 58 // of packets. |
| 41 void ProbeAtBitrate(uint32_t bitrate_bps, int num_packets); | 59 void ProbeAtBitrate(int bitrate_bps, int num_packets); |
| 42 | 60 |
| 43 // Returns the number of milliseconds until the next packet should be sent to | 61 // Returns the number of milliseconds until the next packet should be sent to |
| 44 // get accurate probing. | 62 // get accurate probing. |
| 45 int TimeUntilNextProbe(int64_t now_ms); | 63 int TimeUntilNextProbe(int64_t now_ms); |
| 46 | 64 |
| 47 // Which cluster that is currently being used for probing. | 65 // Which cluster that is currently being used for probing. |
| 48 int CurrentClusterId() const; | 66 int CurrentClusterId() const; |
| 49 | 67 |
| 50 // Returns the number of bytes that the prober recommends for the next probe | 68 // Returns the number of bytes that the prober recommends for the next probe |
| 51 // packet. | 69 // packet. |
| 52 size_t RecommendedPacketSize() const; | 70 size_t RecommendedPacketSize() const; |
| 53 | 71 |
| 54 // Called to report to the prober that a packet has been sent, which helps the | 72 // Notifies the prober that a probe packet has been sent, which helps the |
| 55 // prober know when to move to the next packet in a probe. | 73 // prober move to the next packet in a probe. |
| 56 void PacketSent(int64_t now_ms, size_t packet_size); | 74 void PacketSent(int64_t now_ms, size_t packet_size); |
| 57 | 75 |
| 58 private: | 76 private: |
| 59 enum class ProbingState { | |
| 60 // Probing will not be triggered in this state at all times. | |
| 61 kDisabled, | |
| 62 // Probing is enabled and ready to trigger on the first packet arrival. | |
| 63 kInactive, | |
| 64 // Probe cluster is filled with the set of data rates to be probed and | |
| 65 // probes are being sent. | |
| 66 kActive, | |
| 67 // Probing is enabled, but currently suspended until an explicit trigger | |
| 68 // to start probing again. | |
| 69 kSuspended, | |
| 70 }; | |
| 71 | |
| 72 struct ProbeCluster { | 77 struct ProbeCluster { |
| 73 int max_probe_packets = 0; | 78 int max_probe_packets = 0; |
| 74 int sent_probe_packets = 0; | 79 int sent_probe_packets = 0; |
| 75 int probe_bitrate_bps = 0; | 80 int probe_bitrate_bps = 0; |
| 76 int id = -1; | 81 int id = -1; |
| 77 }; | 82 }; |
| 78 | 83 |
| 79 // Resets the state of the prober and clears any cluster/timing data tracked. | 84 // Resets the state of the prober and clears any cluster/timing data tracked. |
| 80 void ResetState(); | 85 void ResetState(); |
| 81 | 86 |
| 82 ProbingState probing_state_; | 87 State probing_state_; |
| 83 // Probe bitrate per packet. These are used to compute the delta relative to | 88 // Probe bitrate per packet. These are used to compute the delta relative to |
| 84 // the previous probe packet based on the size and time when that packet was | 89 // the previous probe packet based on the size and time when that packet was |
| 85 // sent. | 90 // sent. |
| 86 std::queue<ProbeCluster> clusters_; | 91 std::queue<ProbeCluster> clusters_; |
| 87 size_t packet_size_last_sent_; | 92 size_t packet_size_last_sent_; |
| 88 // The last time a probe was sent. | 93 // The last time a probe was sent. |
| 89 int64_t time_last_probe_sent_ms_; | 94 int64_t time_last_probe_sent_ms_; |
| 90 int next_cluster_id_; | 95 int next_cluster_id_; |
| 96 int min_bitrate_to_probe_further_; | |
| 97 int estimated_bitrate_bps_; | |
| 91 }; | 98 }; |
| 92 } // namespace webrtc | 99 } // namespace webrtc |
| 93 #endif // WEBRTC_MODULES_PACING_BITRATE_PROBER_H_ | 100 #endif // WEBRTC_MODULES_PACING_BITRATE_PROBER_H_ |
| OLD | NEW |