1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Kernel: Extract SrsPps to kernel

This commit is contained in:
winlin 2021-02-25 13:46:52 +08:00
parent 7b7a225631
commit 20df644a05
7 changed files with 236 additions and 161 deletions

View file

@ -27,50 +27,7 @@
#include <srs_core.hpp>
#include <srs_protocol_io.hpp>
class SrsWallClock;
// A sample for rate-based stat, such as kbps or kps.
class SrsRateSample
{
public:
int64_t total;
srs_utime_t time;
// kbps or kps
int rate;
public:
SrsRateSample();
virtual ~SrsRateSample();
public:
virtual SrsRateSample* update(int64_t nn, srs_utime_t t, int k);
};
// A pps manager every some duration.
class SrsPps
{
private:
SrsWallClock* clk_;
private:
// samples
SrsRateSample sample_10s_;
SrsRateSample sample_30s_;
SrsRateSample sample_1m_;
SrsRateSample sample_5m_;
SrsRateSample sample_60m_;
public:
// Sugar for target to stat.
int64_t sugar;
public:
SrsPps(SrsWallClock* clk);
virtual ~SrsPps();
public:
// Update with the nn which is target.
void update();
// Update with the nn.
void update(int64_t nn);
// Get the 10s average stat.
int r10s();
};
#include <srs_kernel_kbps.hpp>
/**
* a slice of kbps statistic, for input or output.
@ -144,21 +101,6 @@ public:
virtual void remark(int64_t* in, int64_t* out) = 0;
};
/**
* A time source to provide wall clock.
*/
class SrsWallClock
{
public:
SrsWallClock();
virtual ~SrsWallClock();
public:
/**
* Current time in srs_utime_t.
*/
virtual srs_utime_t now();
};
/**
* to statistic the kbps of io.
* itself can be a statistic source, for example, used for SRS bytes stat.
@ -258,7 +200,4 @@ public:
virtual int size_memory();
};
// The global clock.
extern SrsWallClock* _srs_clock;
#endif