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)
|
||||
{
|
||||
clk = c;
|
||||
io.in = NULL;
|
||||
io.out = NULL;
|
||||
io = NULL;
|
||||
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();
|
||||
}
|
||||
// save the old in bytes.
|
||||
if (is.io.in) {
|
||||
is.bytes += is.io.in->get_recv_bytes() - is.io_bytes_base;
|
||||
if (is.io) {
|
||||
is.bytes += is.io->get_recv_bytes() - is.io_bytes_base;
|
||||
}
|
||||
// use new io.
|
||||
is.io.in = in;
|
||||
is.io = in;
|
||||
is.last_bytes = is.io_bytes_base = 0;
|
||||
if (in) {
|
||||
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();
|
||||
}
|
||||
// save the old in bytes.
|
||||
if (os.io.out) {
|
||||
os.bytes += os.io.out->get_send_bytes() - os.io_bytes_base;
|
||||
if (os.io) {
|
||||
os.bytes += os.io->get_send_bytes() - os.io_bytes_base;
|
||||
}
|
||||
// use new io.
|
||||
os.io.out = out;
|
||||
os.io = out;
|
||||
os.last_bytes = os.io_bytes_base = 0;
|
||||
if (out) {
|
||||
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()
|
||||
{
|
||||
// update the total bytes
|
||||
if (os.io.out) {
|
||||
os.last_bytes = os.io.out->get_send_bytes();
|
||||
if (os.io) {
|
||||
os.last_bytes = os.io->get_send_bytes();
|
||||
}
|
||||
|
||||
if (is.io.in) {
|
||||
is.last_bytes = is.io.in->get_recv_bytes();
|
||||
if (is.io) {
|
||||
is.last_bytes = is.io->get_recv_bytes();
|
||||
}
|
||||
|
||||
// resample
|
||||
|
@ -240,8 +239,8 @@ int64_t SrsKbps::get_send_bytes()
|
|||
int64_t bytes = os.bytes;
|
||||
|
||||
// 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;
|
||||
if (os.io) {
|
||||
bytes += os.io->get_send_bytes() - os.io_bytes_base;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
@ -262,8 +261,8 @@ int64_t SrsKbps::get_recv_bytes()
|
|||
int64_t bytes = is.bytes;
|
||||
|
||||
// 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;
|
||||
if (is.io) {
|
||||
bytes += is.io->get_recv_bytes() - is.io_bytes_base;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
|
|
@ -65,15 +65,11 @@ public:
|
|||
class SrsKbpsSlice
|
||||
{
|
||||
private:
|
||||
union slice_io {
|
||||
ISrsProtocolStatistic* in;
|
||||
ISrsProtocolStatistic* out;
|
||||
};
|
||||
SrsWallClock* clk;
|
||||
public:
|
||||
// the slice io used for SrsKbps to invoke,
|
||||
// the SrsKbpsSlice itself never use it.
|
||||
slice_io io;
|
||||
ISrsProtocolStatistic* io;
|
||||
// session startup bytes
|
||||
// @remark, use total_bytes() to get the total bytes of slice.
|
||||
int64_t bytes;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue