|
|
|
@ -35,7 +35,7 @@ SrsKbpsSample::~SrsKbpsSample()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SrsKbpsSample* SrsKbpsSample::update(int64_t b, int64_t t, int k)
|
|
|
|
|
SrsKbpsSample* SrsKbpsSample::update(int64_t b, srs_utime_t t, int k)
|
|
|
|
|
{
|
|
|
|
|
bytes = b;
|
|
|
|
|
time = t;
|
|
|
|
@ -61,7 +61,7 @@ int64_t SrsKbpsSlice::get_total_bytes()
|
|
|
|
|
|
|
|
|
|
void SrsKbpsSlice::sample()
|
|
|
|
|
{
|
|
|
|
|
int64_t now = clk->time_ms();
|
|
|
|
|
srs_utime_t now = clk->now();
|
|
|
|
|
int64_t total_bytes = get_total_bytes();
|
|
|
|
|
|
|
|
|
|
if (sample_30s.time < 0) {
|
|
|
|
@ -77,20 +77,20 @@ void SrsKbpsSlice::sample()
|
|
|
|
|
sample_60m.update(total_bytes, now, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (now - sample_30s.time >= 30 * 1000) {
|
|
|
|
|
int kbps = (int)((total_bytes - sample_30s.bytes) * 8 / (now - sample_30s.time));
|
|
|
|
|
if (now - sample_30s.time >= 30 * SRS_UTIME_SECONDS) {
|
|
|
|
|
int kbps = (int)((total_bytes - sample_30s.bytes) * 8 / srsu2ms(now - sample_30s.time));
|
|
|
|
|
sample_30s.update(total_bytes, now, kbps);
|
|
|
|
|
}
|
|
|
|
|
if (now - sample_1m.time >= 60 * 1000) {
|
|
|
|
|
int kbps = (int)((total_bytes - sample_1m.bytes) * 8 / (now - sample_1m.time));
|
|
|
|
|
if (now - sample_1m.time >= 60 * SRS_UTIME_SECONDS) {
|
|
|
|
|
int kbps = (int)((total_bytes - sample_1m.bytes) * 8 / srsu2ms(now - sample_1m.time));
|
|
|
|
|
sample_1m.update(total_bytes, now, kbps);
|
|
|
|
|
}
|
|
|
|
|
if (now - sample_5m.time >= 300 * 1000) {
|
|
|
|
|
int kbps = (int)((total_bytes - sample_5m.bytes) * 8 / (now - sample_5m.time));
|
|
|
|
|
if (now - sample_5m.time >= 300 * SRS_UTIME_SECONDS) {
|
|
|
|
|
int kbps = (int)((total_bytes - sample_5m.bytes) * 8 / srsu2ms(now - sample_5m.time));
|
|
|
|
|
sample_5m.update(total_bytes, now, kbps);
|
|
|
|
|
}
|
|
|
|
|
if (now - sample_60m.time >= 3600 * 1000) {
|
|
|
|
|
int kbps = (int)((total_bytes - sample_60m.bytes) * 8 / (now - sample_60m.time));
|
|
|
|
|
if (now - sample_60m.time >= 3600 * SRS_UTIME_SECONDS) {
|
|
|
|
|
int kbps = (int)((total_bytes - sample_60m.bytes) * 8 / srsu2ms(now - sample_60m.time));
|
|
|
|
|
sample_60m.update(total_bytes, now, kbps);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -111,9 +111,9 @@ SrsWallClock::~SrsWallClock()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int64_t SrsWallClock::time_ms()
|
|
|
|
|
srs_utime_t SrsWallClock::now()
|
|
|
|
|
{
|
|
|
|
|
return srsu2ms(srs_get_system_time());
|
|
|
|
|
return srs_get_system_time();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SrsKbps::SrsKbps(SrsWallClock* c) : is(c), os(c)
|
|
|
|
@ -130,7 +130,7 @@ void SrsKbps::set_io(ISrsProtocolStatistic* in, ISrsProtocolStatistic* out)
|
|
|
|
|
// set input stream
|
|
|
|
|
// now, set start time.
|
|
|
|
|
if (is.starttime == 0) {
|
|
|
|
|
is.starttime = clk->time_ms();
|
|
|
|
|
is.starttime = clk->now();
|
|
|
|
|
}
|
|
|
|
|
// save the old in bytes.
|
|
|
|
|
if (is.io) {
|
|
|
|
@ -148,7 +148,7 @@ void SrsKbps::set_io(ISrsProtocolStatistic* in, ISrsProtocolStatistic* out)
|
|
|
|
|
// set output stream
|
|
|
|
|
// now, set start time.
|
|
|
|
|
if (os.starttime == 0) {
|
|
|
|
|
os.starttime = clk->time_ms();
|
|
|
|
|
os.starttime = clk->now();
|
|
|
|
|
}
|
|
|
|
|
// save the old in bytes.
|
|
|
|
|
if (os.io) {
|
|
|
|
@ -166,22 +166,22 @@ void SrsKbps::set_io(ISrsProtocolStatistic* in, ISrsProtocolStatistic* out)
|
|
|
|
|
|
|
|
|
|
int SrsKbps::get_send_kbps()
|
|
|
|
|
{
|
|
|
|
|
int64_t duration = clk->time_ms() - is.starttime;
|
|
|
|
|
srs_utime_t duration = clk->now() - is.starttime;
|
|
|
|
|
if (duration <= 0) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
int64_t bytes = get_send_bytes();
|
|
|
|
|
return (int)(bytes * 8 / duration);
|
|
|
|
|
return (int)(bytes * 8 / srsu2ms(duration));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SrsKbps::get_recv_kbps()
|
|
|
|
|
{
|
|
|
|
|
int64_t duration = clk->time_ms() - os.starttime;
|
|
|
|
|
srs_utime_t duration = clk->now() - os.starttime;
|
|
|
|
|
if (duration <= 0) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
int64_t bytes = get_recv_bytes();
|
|
|
|
|
return (int)(bytes * 8 / duration);
|
|
|
|
|
return (int)(bytes * 8 / srsu2ms(duration));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SrsKbps::get_send_kbps_30s()
|
|
|
|
|