mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Kbps: Remove the union for kbps slice
This commit is contained in:
parent
98706f793e
commit
b4619e3393
2 changed files with 16 additions and 21 deletions
|
@ -46,8 +46,7 @@ SrsKbpsSample* SrsKbpsSample::update(int64_t b, int64_t t, int k)
|
||||||
SrsKbpsSlice::SrsKbpsSlice(SrsWallClock* c)
|
SrsKbpsSlice::SrsKbpsSlice(SrsWallClock* c)
|
||||||
{
|
{
|
||||||
clk = c;
|
clk = c;
|
||||||
io.in = NULL;
|
io = NULL;
|
||||||
io.out = NULL;
|
|
||||||
last_bytes = io_bytes_base = starttime = bytes = delta_bytes = 0;
|
last_bytes = io_bytes_base = starttime = bytes = delta_bytes = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,11 +133,11 @@ void SrsKbps::set_io(ISrsProtocolStatistic* in, ISrsProtocolStatistic* out)
|
||||||
is.starttime = clk->time_ms();
|
is.starttime = clk->time_ms();
|
||||||
}
|
}
|
||||||
// save the old in bytes.
|
// save the old in bytes.
|
||||||
if (is.io.in) {
|
if (is.io) {
|
||||||
is.bytes += is.io.in->get_recv_bytes() - is.io_bytes_base;
|
is.bytes += is.io->get_recv_bytes() - is.io_bytes_base;
|
||||||
}
|
}
|
||||||
// use new io.
|
// use new io.
|
||||||
is.io.in = in;
|
is.io = in;
|
||||||
is.last_bytes = is.io_bytes_base = 0;
|
is.last_bytes = is.io_bytes_base = 0;
|
||||||
if (in) {
|
if (in) {
|
||||||
is.last_bytes = is.io_bytes_base = in->get_recv_bytes();
|
is.last_bytes = is.io_bytes_base = in->get_recv_bytes();
|
||||||
|
@ -152,11 +151,11 @@ void SrsKbps::set_io(ISrsProtocolStatistic* in, ISrsProtocolStatistic* out)
|
||||||
os.starttime = clk->time_ms();
|
os.starttime = clk->time_ms();
|
||||||
}
|
}
|
||||||
// save the old in bytes.
|
// save the old in bytes.
|
||||||
if (os.io.out) {
|
if (os.io) {
|
||||||
os.bytes += os.io.out->get_send_bytes() - os.io_bytes_base;
|
os.bytes += os.io->get_send_bytes() - os.io_bytes_base;
|
||||||
}
|
}
|
||||||
// use new io.
|
// use new io.
|
||||||
os.io.out = out;
|
os.io = out;
|
||||||
os.last_bytes = os.io_bytes_base = 0;
|
os.last_bytes = os.io_bytes_base = 0;
|
||||||
if (out) {
|
if (out) {
|
||||||
os.last_bytes = os.io_bytes_base = out->get_send_bytes();
|
os.last_bytes = os.io_bytes_base = out->get_send_bytes();
|
||||||
|
@ -217,12 +216,12 @@ void SrsKbps::add_delta(int64_t in, int64_t out)
|
||||||
void SrsKbps::sample()
|
void SrsKbps::sample()
|
||||||
{
|
{
|
||||||
// update the total bytes
|
// update the total bytes
|
||||||
if (os.io.out) {
|
if (os.io) {
|
||||||
os.last_bytes = os.io.out->get_send_bytes();
|
os.last_bytes = os.io->get_send_bytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is.io.in) {
|
if (is.io) {
|
||||||
is.last_bytes = is.io.in->get_recv_bytes();
|
is.last_bytes = is.io->get_recv_bytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
// resample
|
// resample
|
||||||
|
@ -240,8 +239,8 @@ int64_t SrsKbps::get_send_bytes()
|
||||||
int64_t bytes = os.bytes;
|
int64_t bytes = os.bytes;
|
||||||
|
|
||||||
// When exists active session, use it to get the last bytes.
|
// When exists active session, use it to get the last bytes.
|
||||||
if (os.io.out) {
|
if (os.io) {
|
||||||
bytes += os.io.out->get_send_bytes() - os.io_bytes_base;
|
bytes += os.io->get_send_bytes() - os.io_bytes_base;
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,8 +261,8 @@ int64_t SrsKbps::get_recv_bytes()
|
||||||
int64_t bytes = is.bytes;
|
int64_t bytes = is.bytes;
|
||||||
|
|
||||||
// When exists active session, use it to get the last bytes.
|
// When exists active session, use it to get the last bytes.
|
||||||
if (is.io.in) {
|
if (is.io) {
|
||||||
bytes += is.io.in->get_recv_bytes() - is.io_bytes_base;
|
bytes += is.io->get_recv_bytes() - is.io_bytes_base;
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,15 +65,11 @@ public:
|
||||||
class SrsKbpsSlice
|
class SrsKbpsSlice
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
union slice_io {
|
|
||||||
ISrsProtocolStatistic* in;
|
|
||||||
ISrsProtocolStatistic* out;
|
|
||||||
};
|
|
||||||
SrsWallClock* clk;
|
SrsWallClock* clk;
|
||||||
public:
|
public:
|
||||||
// the slice io used for SrsKbps to invoke,
|
// the slice io used for SrsKbps to invoke,
|
||||||
// the SrsKbpsSlice itself never use it.
|
// the SrsKbpsSlice itself never use it.
|
||||||
slice_io io;
|
ISrsProtocolStatistic* io;
|
||||||
// session startup bytes
|
// session startup bytes
|
||||||
// @remark, use total_bytes() to get the total bytes of slice.
|
// @remark, use total_bytes() to get the total bytes of slice.
|
||||||
int64_t bytes;
|
int64_t bytes;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue