mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Refine kbps, stub wall clock
This commit is contained in:
parent
4c40370986
commit
c26b475bae
15 changed files with 70 additions and 27 deletions
|
@ -31,8 +31,9 @@ SrsKbpsSample::SrsKbpsSample()
|
|||
kbps = 0;
|
||||
}
|
||||
|
||||
SrsKbpsSlice::SrsKbpsSlice()
|
||||
SrsKbpsSlice::SrsKbpsSlice(SrsWallClock* c)
|
||||
{
|
||||
clk = c;
|
||||
io.in = NULL;
|
||||
io.out = NULL;
|
||||
last_bytes = io_bytes_base = starttime = bytes = delta_bytes = 0;
|
||||
|
@ -49,7 +50,7 @@ int64_t SrsKbpsSlice::get_total_bytes()
|
|||
|
||||
void SrsKbpsSlice::sample()
|
||||
{
|
||||
int64_t now = clock->time_ms();
|
||||
int64_t now = clk->time_ms();
|
||||
int64_t total_bytes = get_total_bytes();
|
||||
|
||||
if (sample_30s.time <= 0) {
|
||||
|
@ -116,14 +117,13 @@ int64_t SrsWallClock::time_ms()
|
|||
return srs_get_system_time_ms();
|
||||
}
|
||||
|
||||
SrsKbps::SrsKbps(SrsWallClock* c)
|
||||
SrsKbps::SrsKbps(SrsWallClock* c) : is(c), os(c)
|
||||
{
|
||||
clock = c;
|
||||
clk = c;
|
||||
}
|
||||
|
||||
SrsKbps::~SrsKbps()
|
||||
{
|
||||
srs_freep(clock);
|
||||
}
|
||||
|
||||
void SrsKbps::set_io(ISrsProtocolStatistic* in, ISrsProtocolStatistic* out)
|
||||
|
@ -131,7 +131,7 @@ void SrsKbps::set_io(ISrsProtocolStatistic* in, ISrsProtocolStatistic* out)
|
|||
// set input stream
|
||||
// now, set start time.
|
||||
if (is.starttime == 0) {
|
||||
is.starttime = clock->time_ms();
|
||||
is.starttime = clk->time_ms();
|
||||
}
|
||||
// save the old in bytes.
|
||||
if (is.io.in) {
|
||||
|
@ -149,7 +149,7 @@ void SrsKbps::set_io(ISrsProtocolStatistic* in, ISrsProtocolStatistic* out)
|
|||
// set output stream
|
||||
// now, set start time.
|
||||
if (os.starttime == 0) {
|
||||
os.starttime = clock->time_ms();
|
||||
os.starttime = clk->time_ms();
|
||||
}
|
||||
// save the old in bytes.
|
||||
if (os.io.out) {
|
||||
|
@ -167,7 +167,7 @@ void SrsKbps::set_io(ISrsProtocolStatistic* in, ISrsProtocolStatistic* out)
|
|||
|
||||
int SrsKbps::get_send_kbps()
|
||||
{
|
||||
int64_t duration = clock->time_ms() - is.starttime;
|
||||
int64_t duration = clk->time_ms() - is.starttime;
|
||||
if (duration <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ int SrsKbps::get_send_kbps()
|
|||
|
||||
int SrsKbps::get_recv_kbps()
|
||||
{
|
||||
int64_t duration = clock->time_ms() - os.starttime;
|
||||
int64_t duration = clk->time_ms() - os.starttime;
|
||||
if (duration <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
|
||||
#include <srs_protocol_io.hpp>
|
||||
|
||||
class SrsWallClock;
|
||||
|
||||
/**
|
||||
* a kbps sample, for example, 1minute kbps,
|
||||
* 10minute kbps sample.
|
||||
|
@ -64,6 +66,7 @@ private:
|
|||
ISrsProtocolStatistic* in;
|
||||
ISrsProtocolStatistic* out;
|
||||
};
|
||||
SrsWallClock* clk;
|
||||
public:
|
||||
// the slice io used for SrsKbps to invoke,
|
||||
// the SrsKbpsSlice itself never use it.
|
||||
|
@ -88,7 +91,7 @@ public:
|
|||
// for the delta bytes.
|
||||
int64_t delta_bytes;
|
||||
public:
|
||||
SrsKbpsSlice();
|
||||
SrsKbpsSlice(SrsWallClock* clk);
|
||||
virtual ~SrsKbpsSlice();
|
||||
public:
|
||||
// Get current total bytes, not depend on sample().
|
||||
|
@ -182,7 +185,7 @@ class SrsKbps : virtual public ISrsProtocolStatistic, virtual public IKbpsDelta
|
|||
private:
|
||||
SrsKbpsSlice is;
|
||||
SrsKbpsSlice os;
|
||||
SrsWallClock* clock;
|
||||
SrsWallClock* clk;
|
||||
public:
|
||||
// We will free the clock c.
|
||||
SrsKbps(SrsWallClock* c);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue