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

Refine kbps

This commit is contained in:
winlin 2019-01-01 14:04:50 +08:00
parent abfc35c6c7
commit dcebf8a31f
2 changed files with 37 additions and 37 deletions

View file

@ -205,6 +205,33 @@ int SrsKbps::get_recv_kbps_5m()
return is.sample_5m.kbps; return is.sample_5m.kbps;
} }
void SrsKbps::add_delta(IKbpsDelta* delta)
{
srs_assert(delta);
// update the total bytes
is.last_bytes += delta->get_recv_bytes_delta();
os.last_bytes += delta->get_send_bytes_delta();
// we donot sample, please use sample() to do resample.
}
void SrsKbps::sample()
{
// update the total bytes
if (os.io.out) {
os.last_bytes = os.io.out->get_send_bytes();
}
if (is.io.in) {
is.last_bytes = is.io.in->get_recv_bytes();
}
// resample
is.sample();
os.sample();
}
int64_t SrsKbps::get_send_bytes() int64_t SrsKbps::get_send_bytes()
{ {
// we must calc the send bytes dynamically, // we must calc the send bytes dynamically,
@ -272,33 +299,6 @@ void SrsKbps::cleanup()
is.delta_bytes = is.get_total_bytes(); is.delta_bytes = is.get_total_bytes();
} }
void SrsKbps::add_delta(IKbpsDelta* delta)
{
srs_assert(delta);
// update the total bytes
is.last_bytes += delta->get_recv_bytes_delta();
os.last_bytes += delta->get_send_bytes_delta();
// we donot sample, please use sample() to do resample.
}
void SrsKbps::sample()
{
// update the total bytes
if (os.io.out) {
os.last_bytes = os.io.out->get_send_bytes();
}
if (is.io.in) {
is.last_bytes = is.io.in->get_recv_bytes();
}
// resample
is.sample();
os.sample();
}
int SrsKbps::size_memory() int SrsKbps::size_memory()
{ {
return sizeof(SrsKbps); return sizeof(SrsKbps);

View file

@ -218,16 +218,6 @@ public:
// 5m // 5m
virtual int get_send_kbps_5m(); virtual int get_send_kbps_5m();
virtual int get_recv_kbps_5m(); virtual int get_recv_kbps_5m();
// interface ISrsProtocolStatistic
public:
virtual int64_t get_send_bytes();
virtual int64_t get_recv_bytes();
// interface IKbpsDelta
public:
virtual void resample();
virtual int64_t get_send_bytes_delta();
virtual int64_t get_recv_bytes_delta();
virtual void cleanup();
public: public:
/** /**
* add delta to kbps clac mechenism. * add delta to kbps clac mechenism.
@ -244,6 +234,16 @@ public:
* use the add_delta() is better solutions. * use the add_delta() is better solutions.
*/ */
virtual void sample(); virtual void sample();
// interface ISrsProtocolStatistic
public:
virtual int64_t get_send_bytes();
virtual int64_t get_recv_bytes();
// interface IKbpsDelta
public:
virtual void resample();
virtual int64_t get_send_bytes_delta();
virtual int64_t get_recv_bytes_delta();
virtual void cleanup();
// interface ISrsMemorySizer // interface ISrsMemorySizer
public: public:
virtual int size_memory(); virtual int size_memory();