mirror of
https://github.com/ossrs/srs.git
synced 2025-02-12 11:21:52 +00:00
fix #588, kbps interface error. 2.0.228
This commit is contained in:
parent
c58dbe4d14
commit
6a8c232c5b
2 changed files with 26 additions and 19 deletions
|
@ -120,13 +120,13 @@ void SrsKbps::set_io(ISrsProtocolStatistic* in, ISrsProtocolStatistic* out)
|
|||
}
|
||||
// save the old in bytes.
|
||||
if (is.io.in) {
|
||||
is.bytes += is.last_bytes - is.io_bytes_base;
|
||||
is.bytes += is.io.in->get_recv_bytes() - is.io_bytes_base;
|
||||
}
|
||||
// use new io.
|
||||
is.io.in = in;
|
||||
is.last_bytes = is.io_bytes_base = 0;
|
||||
if (in) {
|
||||
is.bytes += is.io.in->get_recv_bytes() - is.io_bytes_base;
|
||||
is.last_bytes = is.io_bytes_base = in->get_recv_bytes();
|
||||
}
|
||||
// resample
|
||||
is.sample();
|
||||
|
@ -199,11 +199,16 @@ int64_t SrsKbps::get_send_bytes()
|
|||
// session start bytes.
|
||||
int64_t bytes = os.bytes;
|
||||
|
||||
// session delta.
|
||||
// When exists active session, use it to get the last bytes.
|
||||
if (os.io.out) {
|
||||
bytes += os.io.out->get_send_bytes() - os.io_bytes_base;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
// When no active session, the last_bytes record the last valid bytes.
|
||||
// TODO: Maybe the bellow bytes is zero, because the ios.io.out is NULL.
|
||||
bytes += os.last_bytes - os.io_bytes_base;
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
@ -216,11 +221,16 @@ int64_t SrsKbps::get_recv_bytes()
|
|||
// session start bytes.
|
||||
int64_t bytes = is.bytes;
|
||||
|
||||
// session delta.
|
||||
// When exists active session, use it to get the last bytes.
|
||||
if (is.io.in) {
|
||||
bytes += is.io.in->get_recv_bytes() - is.io_bytes_base;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
// When no active session, the last_bytes record the last valid bytes.
|
||||
// TODO: Maybe the bellow bytes is zero, because the ios.io.out is NULL.
|
||||
bytes += is.last_bytes - is.io_bytes_base;
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
@ -274,3 +284,8 @@ void SrsKbps::sample()
|
|||
os.sample();
|
||||
}
|
||||
|
||||
int SrsKbps::size_memory()
|
||||
{
|
||||
return sizeof(SrsKbps);
|
||||
}
|
||||
|
||||
|
|
|
@ -157,14 +157,14 @@ public:
|
|||
* delta->resample();
|
||||
* printf("delta is %d/%d", delta->get_send_bytes_delta(), delta->get_recv_bytes_delta());
|
||||
* delta->cleanup();
|
||||
* the server never know how many bytes already send/recv, for the connection maybe closed.
|
||||
* 4. kbps used as ISrsProtocolStatistic, to provides raw bytes:
|
||||
* SrsKbps* kbps = ...;
|
||||
* kbps->set_io(in, out);
|
||||
* // both kbps->get_recv_bytes() and kbps->get_send_bytes() are available.
|
||||
* // we can use the kbps as the data source of another kbps:
|
||||
* // we can use the kbps as the data source of another kbps:
|
||||
* SrsKbps* user = ...;
|
||||
* user->set_io(kbps, kbps);
|
||||
* the server never know how many bytes already send/recv, for the connection maybe closed.
|
||||
*/
|
||||
class SrsKbps : public virtual ISrsProtocolStatistic, public virtual IKbpsDelta
|
||||
{
|
||||
|
@ -198,26 +198,15 @@ public:
|
|||
// 5m
|
||||
virtual int get_send_kbps_5m();
|
||||
virtual int get_recv_kbps_5m();
|
||||
// interface ISrsProtocolStatistic
|
||||
public:
|
||||
/**
|
||||
* get the total send/recv bytes, from the startup of the oldest io.
|
||||
* @remark, use sample() to update data.
|
||||
*/
|
||||
virtual int64_t get_send_bytes();
|
||||
virtual int64_t get_recv_bytes();
|
||||
// interface IKbpsDelta
|
||||
public:
|
||||
/**
|
||||
* resample to get the delta.
|
||||
*/
|
||||
virtual void resample();
|
||||
/**
|
||||
* get the delta of send/recv bytes.
|
||||
*/
|
||||
virtual int64_t get_send_bytes_delta();
|
||||
virtual int64_t get_recv_bytes_delta();
|
||||
/**
|
||||
* cleanup the delta.
|
||||
*/
|
||||
virtual void cleanup();
|
||||
public:
|
||||
/**
|
||||
|
@ -235,6 +224,9 @@ public:
|
|||
* use the add_delta() is better solutions.
|
||||
*/
|
||||
virtual void sample();
|
||||
// interface ISrsMemorySizer
|
||||
public:
|
||||
virtual int size_memory();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue