mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Refactor: Extract SrsNetworkKbps from SrsKbps. v5.0.53
This commit is contained in:
parent
937605b18c
commit
2c259bd95b
20 changed files with 949 additions and 662 deletions
|
|
@ -150,7 +150,7 @@ void SrsEdgeRtmpUpstream::set_recv_timeout(srs_utime_t tm)
|
|||
sdk->set_recv_timeout(tm);
|
||||
}
|
||||
|
||||
void SrsEdgeRtmpUpstream::kbps_sample(const char* label, int64_t age)
|
||||
void SrsEdgeRtmpUpstream::kbps_sample(const char* label, srs_utime_t age)
|
||||
{
|
||||
sdk->kbps_sample(label, age);
|
||||
}
|
||||
|
|
@ -377,7 +377,7 @@ void SrsEdgeFlvUpstream::set_recv_timeout(srs_utime_t tm)
|
|||
sdk_->set_recv_timeout(tm);
|
||||
}
|
||||
|
||||
void SrsEdgeFlvUpstream::kbps_sample(const char* label, int64_t age)
|
||||
void SrsEdgeFlvUpstream::kbps_sample(const char* label, srs_utime_t age)
|
||||
{
|
||||
sdk_->kbps_sample(label, age);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public:
|
|||
public:
|
||||
virtual void selected(std::string& server, int& port) = 0;
|
||||
virtual void set_recv_timeout(srs_utime_t tm) = 0;
|
||||
virtual void kbps_sample(const char* label, int64_t age) = 0;
|
||||
virtual void kbps_sample(const char* label, srs_utime_t age) = 0;
|
||||
};
|
||||
|
||||
class SrsEdgeRtmpUpstream : public SrsEdgeUpstream
|
||||
|
|
@ -97,7 +97,7 @@ public:
|
|||
public:
|
||||
virtual void selected(std::string& server, int& port);
|
||||
virtual void set_recv_timeout(srs_utime_t tm);
|
||||
virtual void kbps_sample(const char* label, int64_t age);
|
||||
virtual void kbps_sample(const char* label, srs_utime_t age);
|
||||
};
|
||||
|
||||
class SrsEdgeFlvUpstream : public SrsEdgeUpstream
|
||||
|
|
@ -129,7 +129,7 @@ public:
|
|||
public:
|
||||
virtual void selected(std::string& server, int& port);
|
||||
virtual void set_recv_timeout(srs_utime_t tm);
|
||||
virtual void kbps_sample(const char* label, int64_t age);
|
||||
virtual void kbps_sample(const char* label, srs_utime_t age);
|
||||
};
|
||||
|
||||
// The edge used to ingest stream from origin.
|
||||
|
|
|
|||
|
|
@ -100,9 +100,12 @@ SrsRtmpConn::SrsRtmpConn(SrsServer* svr, srs_netfd_t c, string cip, int cport)
|
|||
ip = cip;
|
||||
port = cport;
|
||||
create_time = srsu2ms(srs_get_system_time());
|
||||
trd = new SrsSTCoroutine("rtmp", this, _srs_context->get_id());
|
||||
|
||||
kbps = new SrsNetworkKbps();
|
||||
kbps->set_io(skt, skt);
|
||||
delta_ = new SrsNetworkDelta();
|
||||
delta_->set_io(skt, skt);
|
||||
trd = new SrsSTCoroutine("rtmp", this, _srs_context->get_id());
|
||||
|
||||
rtmp = new SrsRtmpServer(skt);
|
||||
refer = new SrsRefer();
|
||||
|
|
@ -134,6 +137,7 @@ SrsRtmpConn::~SrsRtmpConn()
|
|||
}
|
||||
srs_freep(trd);
|
||||
|
||||
srs_freep(kbps);
|
||||
srs_freep(delta_);
|
||||
srs_freep(skt);
|
||||
|
||||
|
|
@ -752,7 +756,10 @@ srs_error_t SrsRtmpConn::do_playing(SrsLiveSource* source, SrsLiveConsumer* cons
|
|||
|
||||
// reportable
|
||||
if (pprint->can_print()) {
|
||||
srs_trace("-> " SRS_CONSTS_LOG_PLAY " time=%d, msgs=%d, mw=%d/%d", (int)pprint->age(), count, srsu2msi(mw_sleep), mw_msgs);
|
||||
kbps->sample();
|
||||
srs_trace("-> " SRS_CONSTS_LOG_PLAY " time=%d, msgs=%d, okbps=%d,%d,%d, ikbps=%d,%d,%d, mw=%d/%d",
|
||||
(int)pprint->age(), count, kbps->get_send_kbps(), kbps->get_send_kbps_30s(), kbps->get_send_kbps_5m(),
|
||||
kbps->get_recv_kbps(), kbps->get_recv_kbps_30s(), kbps->get_recv_kbps_5m(), srsu2msi(mw_sleep), mw_msgs);
|
||||
}
|
||||
|
||||
if (count <= 0) {
|
||||
|
|
@ -918,9 +925,13 @@ srs_error_t SrsRtmpConn::do_publishing(SrsLiveSource* source, SrsPublishRecvThre
|
|||
|
||||
// reportable
|
||||
if (pprint->can_print()) {
|
||||
kbps->sample();
|
||||
bool mr = _srs_config->get_mr_enabled(req->vhost);
|
||||
srs_utime_t mr_sleep = _srs_config->get_mr_sleep(req->vhost);
|
||||
srs_trace("<- " SRS_CONSTS_LOG_CLIENT_PUBLISH " time=%d, mr=%d/%d, p1stpt=%d, pnt=%d", (int)pprint->age(), mr, srsu2msi(mr_sleep), srsu2msi(publish_1stpkt_timeout), srsu2msi(publish_normal_timeout));
|
||||
srs_trace("<- " SRS_CONSTS_LOG_CLIENT_PUBLISH " time=%d, okbps=%d,%d,%d, ikbps=%d,%d,%d, mr=%d/%d, p1stpt=%d, pnt=%d",
|
||||
(int)pprint->age(), kbps->get_send_kbps(), kbps->get_send_kbps_30s(), kbps->get_send_kbps_5m(),
|
||||
kbps->get_recv_kbps(), kbps->get_recv_kbps_30s(), kbps->get_recv_kbps_5m(), mr, srsu2msi(mr_sleep),
|
||||
srsu2msi(publish_1stpkt_timeout), srsu2msi(publish_normal_timeout));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -113,6 +113,7 @@ private:
|
|||
int port;
|
||||
// The delta for statistic.
|
||||
SrsNetworkDelta* delta_;
|
||||
SrsNetworkKbps* kbps;
|
||||
// The create time in milliseconds.
|
||||
// for current connection to log self create time and calculate the living time.
|
||||
int64_t create_time;
|
||||
|
|
|
|||
|
|
@ -160,11 +160,14 @@ SrsMpegtsSrtConn::SrsMpegtsSrtConn(SrsSrtServer* srt_server, srs_srt_t srt_fd, s
|
|||
|
||||
srt_fd_ = srt_fd;
|
||||
srt_conn_ = new SrsSrtConnection(srt_fd_);
|
||||
delta_ = new SrsNetworkDelta();
|
||||
delta_->set_io(srt_conn_, srt_conn_);
|
||||
ip_ = ip;
|
||||
port_ = port;
|
||||
|
||||
kbps_ = new SrsNetworkKbps();
|
||||
kbps_->set_io(srt_conn_, srt_conn_);
|
||||
delta_ = new SrsNetworkDelta();
|
||||
delta_->set_io(srt_conn_, srt_conn_);
|
||||
|
||||
trd_ = new SrsSTCoroutine("ts-srt", this, _srs_context->get_id());
|
||||
|
||||
srt_source_ = NULL;
|
||||
|
|
@ -176,6 +179,7 @@ SrsMpegtsSrtConn::~SrsMpegtsSrtConn()
|
|||
{
|
||||
srs_freep(trd_);
|
||||
|
||||
srs_freep(kbps_);
|
||||
srs_freep(delta_);
|
||||
srs_freep(srt_conn_);
|
||||
srs_freep(req_);
|
||||
|
|
@ -408,7 +412,10 @@ srs_error_t SrsMpegtsSrtConn::do_publishing()
|
|||
s.pktRecv(), s.pktRcvLoss(), s.pktRcvRetrans(), s.pktRcvDrop());
|
||||
}
|
||||
|
||||
srs_trace("<- " SRS_CONSTS_LOG_SRT_PUBLISH " time=%d, packets=%d", (int)pprint->age(), nb_packets);
|
||||
kbps_->sample();
|
||||
srs_trace("<- " SRS_CONSTS_LOG_SRT_PUBLISH " time=%" PRId64 ", packets=%d, okbps=%d,%d,%d, ikbps=%d,%d,%d",
|
||||
srsu2ms(pprint->age()), nb_packets, kbps_->get_send_kbps(), kbps_->get_send_kbps_30s(), kbps_->get_send_kbps_5m(),
|
||||
kbps_->get_recv_kbps(), kbps_->get_recv_kbps_30s(), kbps_->get_recv_kbps_5m());
|
||||
nb_packets = 0;
|
||||
}
|
||||
|
||||
|
|
@ -485,7 +492,10 @@ srs_error_t SrsMpegtsSrtConn::do_playing()
|
|||
s.pktSent(), s.pktSndLoss(), s.pktRetrans(), s.pktSndDrop());
|
||||
}
|
||||
|
||||
srs_trace("-> " SRS_CONSTS_LOG_SRT_PLAY " time=%d, packets=%d", (int)pprint->age(), nb_packets);
|
||||
kbps_->sample();
|
||||
srs_trace("-> " SRS_CONSTS_LOG_SRT_PLAY " time=%" PRId64 ", packets=%d, okbps=%d,%d,%d, ikbps=%d,%d,%d",
|
||||
srsu2ms(pprint->age()), nb_packets, kbps_->get_send_kbps(), kbps_->get_send_kbps_30s(), kbps_->get_send_kbps_5m(),
|
||||
kbps_->get_recv_kbps(), kbps_->get_recv_kbps_30s(), kbps_->get_recv_kbps_5m());
|
||||
nb_packets = 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -116,6 +116,7 @@ private:
|
|||
srs_srt_t srt_fd_;
|
||||
SrsSrtConnection* srt_conn_;
|
||||
SrsNetworkDelta* delta_;
|
||||
SrsNetworkKbps* kbps_;
|
||||
std::string ip_;
|
||||
int port_;
|
||||
SrsCoroutine* trd_;
|
||||
|
|
|
|||
|
|
@ -31,10 +31,8 @@ SrsStatisticVhost::SrsStatisticVhost()
|
|||
{
|
||||
id = srs_generate_stat_vid();
|
||||
|
||||
clk = new SrsWallClock();
|
||||
kbps = new SrsKbps(clk);
|
||||
kbps->set_io(NULL, NULL);
|
||||
|
||||
kbps = new SrsKbps();
|
||||
|
||||
nb_clients = 0;
|
||||
nb_streams = 0;
|
||||
}
|
||||
|
|
@ -42,7 +40,6 @@ SrsStatisticVhost::SrsStatisticVhost()
|
|||
SrsStatisticVhost::~SrsStatisticVhost()
|
||||
{
|
||||
srs_freep(kbps);
|
||||
srs_freep(clk);
|
||||
}
|
||||
|
||||
srs_error_t SrsStatisticVhost::dumps(SrsJsonObject* obj)
|
||||
|
|
@ -97,10 +94,8 @@ SrsStatisticStream::SrsStatisticStream()
|
|||
width = 0;
|
||||
height = 0;
|
||||
|
||||
clk = new SrsWallClock();
|
||||
kbps = new SrsKbps(clk);
|
||||
kbps->set_io(NULL, NULL);
|
||||
|
||||
kbps = new SrsKbps();
|
||||
|
||||
nb_clients = 0;
|
||||
frames = new SrsPps();
|
||||
}
|
||||
|
|
@ -108,7 +103,6 @@ SrsStatisticStream::SrsStatisticStream()
|
|||
SrsStatisticStream::~SrsStatisticStream()
|
||||
{
|
||||
srs_freep(kbps);
|
||||
srs_freep(clk);
|
||||
srs_freep(frames);
|
||||
}
|
||||
|
||||
|
|
@ -203,15 +197,12 @@ SrsStatisticClient::SrsStatisticClient()
|
|||
type = SrsRtmpConnUnknown;
|
||||
create = srs_get_system_time();
|
||||
|
||||
clk = new SrsWallClock();
|
||||
kbps = new SrsKbps(clk);
|
||||
kbps->set_io(NULL, NULL);
|
||||
kbps = new SrsKbps();
|
||||
}
|
||||
|
||||
SrsStatisticClient::~SrsStatisticClient()
|
||||
{
|
||||
srs_freep(kbps);
|
||||
srs_freep(clk);
|
||||
srs_freep(req);
|
||||
}
|
||||
|
||||
|
|
@ -246,16 +237,13 @@ SrsStatistic* SrsStatistic::_instance = NULL;
|
|||
|
||||
SrsStatistic::SrsStatistic()
|
||||
{
|
||||
clk = new SrsWallClock();
|
||||
kbps = new SrsKbps(clk);
|
||||
kbps->set_io(NULL, NULL);
|
||||
kbps = new SrsKbps();
|
||||
}
|
||||
|
||||
SrsStatistic::~SrsStatistic()
|
||||
{
|
||||
srs_freep(kbps);
|
||||
srs_freep(clk);
|
||||
|
||||
|
||||
if (true) {
|
||||
std::map<std::string, SrsStatisticVhost*>::iterator it;
|
||||
for (it = vhosts.begin(); it != vhosts.end(); it++) {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ public:
|
|||
public:
|
||||
// The vhost total kbps.
|
||||
SrsKbps* kbps;
|
||||
SrsWallClock* clk;
|
||||
public:
|
||||
SrsStatisticVhost();
|
||||
virtual ~SrsStatisticVhost();
|
||||
|
|
@ -61,7 +60,6 @@ public:
|
|||
public:
|
||||
// The stream total kbps.
|
||||
SrsKbps* kbps;
|
||||
SrsWallClock* clk;
|
||||
// The fps of stream.
|
||||
SrsPps* frames;
|
||||
public:
|
||||
|
|
@ -110,7 +108,6 @@ public:
|
|||
public:
|
||||
// The stream total kbps.
|
||||
SrsKbps* kbps;
|
||||
SrsWallClock* clk;
|
||||
public:
|
||||
SrsStatisticClient();
|
||||
virtual ~SrsStatisticClient();
|
||||
|
|
@ -141,7 +138,6 @@ private:
|
|||
std::map<std::string, SrsStatisticClient*> clients;
|
||||
// The server total kbps.
|
||||
SrsKbps* kbps;
|
||||
SrsWallClock* clk;
|
||||
private:
|
||||
SrsStatistic();
|
||||
virtual ~SrsStatistic();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue