blob: 0749ce48918fd5deced4dd355439e01b568ad47f [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>
16
17#include "webrtc/typedefs.h"
18
19namespace webrtc {
20
21// Note that this class isn't thread-safe by itself and therefore relies
22// on being protected by the caller.
23class BitrateProber {
24 public:
25 BitrateProber();
26
27 void SetEnabled(bool enable);
28
29 // 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
31 // TimeUntilNextProbe().
32 bool IsProbing() const;
33
Peter Boström0453ef82016-02-16 16:23:08 +010034 // 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
36 // with.
Per28a44562016-05-04 17:12:51 +020037 void OnIncomingPacket(uint32_t bitrate_bps,
38 size_t packet_size,
39 int64_t now_ms);
stefan@webrtc.org82462aa2014-10-23 11:57:05 +000040
41 // Returns the number of milliseconds until the next packet should be sent to
42 // get accurate probing.
43 int TimeUntilNextProbe(int64_t now_ms);
44
Stefan Holmer01b48882015-05-05 10:21:24 +020045 // Returns the number of bytes that the prober recommends for the next probe
46 // packet.
47 size_t RecommendedPacketSize() const;
48
stefan@webrtc.org82462aa2014-10-23 11:57:05 +000049 // Called to report to the prober that a packet has been sent, which helps the
50 // prober know when to move to the next packet in a probe.
51 void PacketSent(int64_t now_ms, size_t packet_size);
52
53 private:
54 enum ProbingState { kDisabled, kAllowedToProbe, kProbing, kWait };
55
56 ProbingState probing_state_;
57 // Probe bitrate per packet. These are used to compute the delta relative to
58 // the previous probe packet based on the size and time when that packet was
59 // sent.
Per28a44562016-05-04 17:12:51 +020060 std::list<uint32_t> probe_bitrates_;
stefan@webrtc.org82462aa2014-10-23 11:57:05 +000061 size_t packet_size_last_send_;
62 int64_t time_last_send_ms_;
63};
64} // namespace webrtc
65#endif // WEBRTC_MODULES_PACING_BITRATE_PROBER_H_