mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Refactor: Use compositor for ISrsKbpsDelta. v5.0.51
This commit is contained in:
parent
29ae29c693
commit
1630918b0f
24 changed files with 225 additions and 213 deletions
|
@ -90,6 +90,54 @@ void SrsEphemeralDelta::remark(int64_t* in, int64_t* out)
|
|||
in_ = out_ = 0;
|
||||
}
|
||||
|
||||
SrsNetworkDelta::SrsNetworkDelta()
|
||||
{
|
||||
in_ = out_ = NULL;
|
||||
in_base_ = in_delta_ = 0;
|
||||
out_base_ = out_delta_ = 0;
|
||||
}
|
||||
|
||||
SrsNetworkDelta::~SrsNetworkDelta()
|
||||
{
|
||||
}
|
||||
|
||||
void SrsNetworkDelta::set_io(ISrsProtocolStatistic* in, ISrsProtocolStatistic* out)
|
||||
{
|
||||
if (in_) {
|
||||
in_delta_ += in_->get_recv_bytes() - in_base_;
|
||||
}
|
||||
if (in) {
|
||||
in_base_ = in->get_recv_bytes();
|
||||
in_delta_ += in_base_;
|
||||
}
|
||||
in_ = in;
|
||||
|
||||
if (out_) {
|
||||
out_delta_ += out_->get_send_bytes() - out_base_;
|
||||
}
|
||||
if (out) {
|
||||
out_base_ = out->get_send_bytes();
|
||||
out_delta_ += out_base_;
|
||||
}
|
||||
out_ = out;
|
||||
}
|
||||
|
||||
void SrsNetworkDelta::remark(int64_t* in, int64_t* out)
|
||||
{
|
||||
if (in_) {
|
||||
in_delta_ += in_->get_recv_bytes() - in_base_;
|
||||
in_base_ = in_->get_recv_bytes();
|
||||
}
|
||||
if (out_) {
|
||||
out_delta_ += out_->get_send_bytes() - out_base_;
|
||||
out_base_ = out_->get_send_bytes();
|
||||
}
|
||||
|
||||
*in = in_delta_;
|
||||
*out = out_delta_;
|
||||
in_delta_ = out_delta_ = 0;
|
||||
}
|
||||
|
||||
SrsKbps::SrsKbps(SrsWallClock* c) : is(c), os(c)
|
||||
{
|
||||
clk = c;
|
||||
|
@ -249,25 +297,3 @@ int64_t SrsKbps::get_recv_bytes()
|
|||
return bytes;
|
||||
}
|
||||
|
||||
void SrsKbps::remark(int64_t* in, int64_t* out)
|
||||
{
|
||||
sample();
|
||||
|
||||
int64_t inv = is.get_total_bytes() - is.delta_bytes;
|
||||
is.delta_bytes = is.get_total_bytes();
|
||||
if (in) {
|
||||
*in = inv;
|
||||
}
|
||||
|
||||
int64_t outv = os.get_total_bytes() - os.delta_bytes;
|
||||
os.delta_bytes = os.get_total_bytes();
|
||||
if (out) {
|
||||
*out = outv;
|
||||
}
|
||||
}
|
||||
|
||||
int SrsKbps::size_memory()
|
||||
{
|
||||
return sizeof(SrsKbps);
|
||||
}
|
||||
|
||||
|
|
|
@ -101,6 +101,26 @@ public:
|
|||
virtual void remark(int64_t* in, int64_t* out);
|
||||
};
|
||||
|
||||
// A network delta data source for SrsKbps.
|
||||
class SrsNetworkDelta : public ISrsKbpsDelta
|
||||
{
|
||||
private:
|
||||
ISrsProtocolStatistic* in_;
|
||||
ISrsProtocolStatistic* out_;
|
||||
uint64_t in_base_;
|
||||
uint64_t in_delta_;
|
||||
uint64_t out_base_;
|
||||
uint64_t out_delta_;
|
||||
public:
|
||||
SrsNetworkDelta();
|
||||
virtual ~SrsNetworkDelta();
|
||||
public:
|
||||
virtual void set_io(ISrsProtocolStatistic* in, ISrsProtocolStatistic* out);
|
||||
// Interface ISrsKbpsDelta.
|
||||
public:
|
||||
virtual void remark(int64_t* in, int64_t* out);
|
||||
};
|
||||
|
||||
/**
|
||||
* to statistic the kbps of io.
|
||||
* itself can be a statistic source, for example, used for SRS bytes stat.
|
||||
|
@ -121,14 +141,7 @@ public:
|
|||
* kbps->add_delta(in, out)
|
||||
* kbps->sample()
|
||||
* kbps->get_xxx_kbps().
|
||||
* 3. kbps used as ISrsKbpsDelta, to provides delta bytes:
|
||||
* SrsKbps* kbps = ...;
|
||||
* kbps->set_io(in, out);
|
||||
* ISrsKbpsDelta* delta = (ISrsKbpsDelta*)kbps;
|
||||
* int64_t in, out;
|
||||
* delta->remark(&in, out);
|
||||
* printf("delta is %d/%d", in, out);
|
||||
* 4. kbps used as ISrsProtocolStatistic, to provides raw bytes:
|
||||
* 3. 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.
|
||||
|
@ -137,7 +150,7 @@ public:
|
|||
* user->set_io(kbps, kbps);
|
||||
* the server never know how many bytes already send/recv, for the connection maybe closed.
|
||||
*/
|
||||
class SrsKbps : public ISrsProtocolStatistic, public ISrsKbpsDelta
|
||||
class SrsKbps : public ISrsProtocolStatistic
|
||||
{
|
||||
private:
|
||||
SrsKbpsSlice is;
|
||||
|
@ -192,12 +205,6 @@ public:
|
|||
public:
|
||||
virtual int64_t get_send_bytes();
|
||||
virtual int64_t get_recv_bytes();
|
||||
// Interface ISrsKbpsDelta
|
||||
public:
|
||||
virtual void remark(int64_t* in, int64_t* out);
|
||||
// Interface ISrsMemorySizer
|
||||
public:
|
||||
virtual int size_memory();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue