2014-10-23 11:57:05 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef WEBRTC_MODULES_PACING_BITRATE_PROBER_H_
|
|
|
|
|
#define WEBRTC_MODULES_PACING_BITRATE_PROBER_H_
|
|
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
|
#include <list>
|
2016-05-06 17:06:14 +02:00
|
|
|
#include <queue>
|
2014-10-23 11:57:05 +00:00
|
|
|
|
|
|
|
|
#include "webrtc/typedefs.h"
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
// Note that this class isn't thread-safe by itself and therefore relies
|
|
|
|
|
// on being protected by the caller.
|
|
|
|
|
class BitrateProber {
|
|
|
|
|
public:
|
|
|
|
|
BitrateProber();
|
|
|
|
|
|
|
|
|
|
void SetEnabled(bool enable);
|
|
|
|
|
|
|
|
|
|
// Returns true if the prober is in a probing session, i.e., it currently
|
|
|
|
|
// wants packets to be sent out according to the time returned by
|
|
|
|
|
// TimeUntilNextProbe().
|
|
|
|
|
bool IsProbing() const;
|
|
|
|
|
|
2016-02-16 16:23:08 +01:00
|
|
|
// Initializes a new probing session if the prober is allowed to probe. Does
|
|
|
|
|
// not initialize the prober unless the packet size is large enough to probe
|
|
|
|
|
// with.
|
2016-05-04 17:12:51 +02:00
|
|
|
void OnIncomingPacket(uint32_t bitrate_bps,
|
|
|
|
|
size_t packet_size,
|
|
|
|
|
int64_t now_ms);
|
2014-10-23 11:57:05 +00:00
|
|
|
|
|
|
|
|
// Returns the number of milliseconds until the next packet should be sent to
|
|
|
|
|
// get accurate probing.
|
|
|
|
|
int TimeUntilNextProbe(int64_t now_ms);
|
|
|
|
|
|
2016-05-06 17:06:14 +02:00
|
|
|
// Which cluster that is currently being used for probing.
|
|
|
|
|
int CurrentClusterId() const;
|
|
|
|
|
|
2015-05-05 10:21:24 +02:00
|
|
|
// Returns the number of bytes that the prober recommends for the next probe
|
|
|
|
|
// packet.
|
|
|
|
|
size_t RecommendedPacketSize() const;
|
|
|
|
|
|
2014-10-23 11:57:05 +00:00
|
|
|
// Called to report to the prober that a packet has been sent, which helps the
|
|
|
|
|
// prober know when to move to the next packet in a probe.
|
|
|
|
|
void PacketSent(int64_t now_ms, size_t packet_size);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
enum ProbingState { kDisabled, kAllowedToProbe, kProbing, kWait };
|
|
|
|
|
|
2016-05-06 17:06:14 +02:00
|
|
|
struct ProbeCluster {
|
|
|
|
|
int max_probe_packets = 0;
|
|
|
|
|
int sent_probe_packets = 0;
|
|
|
|
|
int probe_bitrate_bps = 0;
|
|
|
|
|
int id = -1;
|
|
|
|
|
};
|
|
|
|
|
|
2014-10-23 11:57:05 +00:00
|
|
|
ProbingState probing_state_;
|
|
|
|
|
// Probe bitrate per packet. These are used to compute the delta relative to
|
|
|
|
|
// the previous probe packet based on the size and time when that packet was
|
|
|
|
|
// sent.
|
2016-05-06 17:06:14 +02:00
|
|
|
std::queue<ProbeCluster> clusters_;
|
2014-10-23 11:57:05 +00:00
|
|
|
size_t packet_size_last_send_;
|
|
|
|
|
int64_t time_last_send_ms_;
|
2016-05-06 17:06:14 +02:00
|
|
|
int cluster_id_;
|
2014-10-23 11:57:05 +00:00
|
|
|
};
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
#endif // WEBRTC_MODULES_PACING_BITRATE_PROBER_H_
|