blob: b0c0986a199a3c9bcd5477247e7d46b1d448c514 [file] [log] [blame]
stefan@webrtc.org82462aa2014-10-23 11:57:05 +00001/*
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>
philipeldd324862016-05-06 17:06:14 +020016#include <queue>
stefan@webrtc.org82462aa2014-10-23 11:57:05 +000017
18#include "webrtc/typedefs.h"
19
20namespace webrtc {
21
22// Note that this class isn't thread-safe by itself and therefore relies
23// on being protected by the caller.
24class 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öm0453ef82016-02-16 16:23:08 +010035 // 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.
Per28a44562016-05-04 17:12:51 +020038 void OnIncomingPacket(uint32_t bitrate_bps,
39 size_t packet_size,
40 int64_t now_ms);
stefan@webrtc.org82462aa2014-10-23 11:57:05 +000041
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
philipeldd324862016-05-06 17:06:14 +020046 // Which cluster that is currently being used for probing.
47 int CurrentClusterId() const;
48
Stefan Holmer01b48882015-05-05 10:21:24 +020049 // Returns the number of bytes that the prober recommends for the next probe
50 // packet.
51 size_t RecommendedPacketSize() const;
52
stefan@webrtc.org82462aa2014-10-23 11:57:05 +000053 // 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
philipeldd324862016-05-06 17:06:14 +020060 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.org82462aa2014-10-23 11:57:05 +000067 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.
philipeldd324862016-05-06 17:06:14 +020071 std::queue<ProbeCluster> clusters_;
stefan@webrtc.org82462aa2014-10-23 11:57:05 +000072 size_t packet_size_last_send_;
73 int64_t time_last_send_ms_;
philipeldd324862016-05-06 17:06:14 +020074 int cluster_id_;
stefan@webrtc.org82462aa2014-10-23 11:57:05 +000075};
76} // namespace webrtc
77#endif // WEBRTC_MODULES_PACING_BITRATE_PROBER_H_