mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Refine id and vid for statistic. 4.0.108
This commit is contained in:
parent
393d976685
commit
06f7d7d11b
8 changed files with 31 additions and 46 deletions
|
@ -176,6 +176,7 @@ The ports used by SRS:
|
|||
|
||||
## V4 changes
|
||||
|
||||
* v4.0, 2021-05-14, Refine id and vid for statistic. 4.0.108
|
||||
* v4.0, 2021-05-09, Refine tid for sdk and demos. 4.0.106
|
||||
* v4.0, 2021-05-08, Refine shared fast timer. 4.0.105
|
||||
* v4.0, 2021-05-08, Refine global or thread-local variables initialize. 4.0.104
|
||||
|
|
|
@ -606,7 +606,7 @@ srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
|
|||
|
||||
// update the statistic when source disconveried.
|
||||
SrsStatistic* stat = SrsStatistic::instance();
|
||||
if ((err = stat->on_client(_srs_context->get_id(), req, hc, SrsRtmpConnPlay)) != srs_success) {
|
||||
if ((err = stat->on_client(_srs_context->get_id().c_str(), req, hc, SrsRtmpConnPlay)) != srs_success) {
|
||||
return srs_error_wrap(err, "stat on client");
|
||||
}
|
||||
|
||||
|
|
|
@ -534,7 +534,7 @@ srs_error_t SrsRtmpConn::stream_service_cycle()
|
|||
|
||||
// update the statistic when source disconveried.
|
||||
SrsStatistic* stat = SrsStatistic::instance();
|
||||
if ((err = stat->on_client(_srs_context->get_id(), req, this, info->type)) != srs_success) {
|
||||
if ((err = stat->on_client(_srs_context->get_id().c_str(), req, this, info->type)) != srs_success) {
|
||||
return srs_error_wrap(err, "rtmp: stat client");
|
||||
}
|
||||
|
||||
|
|
|
@ -1555,7 +1555,7 @@ void SrsServer::resample_kbps()
|
|||
|
||||
// add delta of connection to server kbps.,
|
||||
// for next sample() of server kbps can get the stat.
|
||||
stat->kbps_add_delta(c->get_id(), conn);
|
||||
stat->kbps_add_delta(c->get_id().c_str(), conn);
|
||||
}
|
||||
|
||||
// TODO: FXME: support all other connections.
|
||||
|
@ -1662,8 +1662,8 @@ void SrsServer::remove(ISrsResource* c)
|
|||
ISrsStartableConneciton* conn = dynamic_cast<ISrsStartableConneciton*>(c);
|
||||
|
||||
SrsStatistic* stat = SrsStatistic::instance();
|
||||
stat->kbps_add_delta(c->get_id(), conn);
|
||||
stat->on_disconnect(c->get_id());
|
||||
stat->kbps_add_delta(c->get_id().c_str(), conn);
|
||||
stat->on_disconnect(c->get_id().c_str());
|
||||
|
||||
// use manager to free it async.
|
||||
conn_manager->remove(c);
|
||||
|
|
|
@ -2518,7 +2518,7 @@ srs_error_t SrsSource::on_publish()
|
|||
}
|
||||
|
||||
SrsStatistic* stat = SrsStatistic::instance();
|
||||
stat->on_stream_publish(req, _source_id);
|
||||
stat->on_stream_publish(req, _source_id.c_str());
|
||||
|
||||
return err;
|
||||
}
|
||||
|
|
|
@ -34,23 +34,16 @@ using namespace std;
|
|||
#include <srs_app_config.hpp>
|
||||
#include <srs_kernel_utility.hpp>
|
||||
#include <srs_protocol_amf0.hpp>
|
||||
#include <srs_protocol_utility.hpp>
|
||||
|
||||
string srs_generate_id()
|
||||
string srs_generate_stat_vid()
|
||||
{
|
||||
static int64_t srs_gvid = 0;
|
||||
|
||||
if (srs_gvid == 0) {
|
||||
srs_gvid = getpid();
|
||||
}
|
||||
|
||||
string prefix = "vid";
|
||||
string rand_id = srs_int2str(srs_get_system_time() % 1000);
|
||||
return prefix + "-" + srs_int2str(srs_gvid++) + "-" + rand_id;
|
||||
return "vid-" + srs_random_str(7);
|
||||
}
|
||||
|
||||
SrsStatisticVhost::SrsStatisticVhost()
|
||||
{
|
||||
id = srs_generate_id();
|
||||
id = srs_generate_stat_vid();
|
||||
|
||||
clk = new SrsWallClock();
|
||||
kbps = new SrsKbps(clk);
|
||||
|
@ -101,7 +94,7 @@ srs_error_t SrsStatisticVhost::dumps(SrsJsonObject* obj)
|
|||
|
||||
SrsStatisticStream::SrsStatisticStream()
|
||||
{
|
||||
id = srs_generate_id();
|
||||
id = srs_generate_stat_vid();
|
||||
vhost = NULL;
|
||||
active = false;
|
||||
|
||||
|
@ -156,7 +149,7 @@ srs_error_t SrsStatisticStream::dumps(SrsJsonObject* obj)
|
|||
obj->set("publish", publish);
|
||||
|
||||
publish->set("active", SrsJsonAny::boolean(active));
|
||||
publish->set("cid", SrsJsonAny::str(connection_cid.c_str()));
|
||||
publish->set("cid", SrsJsonAny::str(publisher_id.c_str()));
|
||||
|
||||
if (!has_video) {
|
||||
obj->set("video", SrsJsonAny::null());
|
||||
|
@ -186,9 +179,9 @@ srs_error_t SrsStatisticStream::dumps(SrsJsonObject* obj)
|
|||
return err;
|
||||
}
|
||||
|
||||
void SrsStatisticStream::publish(SrsContextId cid)
|
||||
void SrsStatisticStream::publish(std::string id)
|
||||
{
|
||||
connection_cid = cid;
|
||||
publisher_id = id;
|
||||
active = true;
|
||||
|
||||
vhost->nb_streams++;
|
||||
|
@ -261,7 +254,7 @@ SrsStatistic* SrsStatistic::_instance = NULL;
|
|||
|
||||
SrsStatistic::SrsStatistic()
|
||||
{
|
||||
_server_id = srs_generate_id();
|
||||
_server_id = srs_generate_stat_vid();
|
||||
|
||||
clk = new SrsWallClock();
|
||||
kbps = new SrsKbps(clk);
|
||||
|
@ -407,12 +400,12 @@ srs_error_t SrsStatistic::on_video_frames(SrsRequest* req, int nb_frames)
|
|||
return err;
|
||||
}
|
||||
|
||||
void SrsStatistic::on_stream_publish(SrsRequest* req, SrsContextId cid)
|
||||
void SrsStatistic::on_stream_publish(SrsRequest* req, std::string publisher_id)
|
||||
{
|
||||
SrsStatisticVhost* vhost = create_vhost(req);
|
||||
SrsStatisticStream* stream = create_stream(vhost, req);
|
||||
|
||||
stream->publish(cid);
|
||||
stream->publish(publisher_id);
|
||||
}
|
||||
|
||||
void SrsStatistic::on_stream_close(SrsRequest* req)
|
||||
|
@ -438,13 +431,10 @@ void SrsStatistic::on_stream_close(SrsRequest* req)
|
|||
}
|
||||
}
|
||||
|
||||
srs_error_t SrsStatistic::on_client(SrsContextId cid, SrsRequest* req, ISrsExpire* conn, SrsRtmpConnType type)
|
||||
srs_error_t SrsStatistic::on_client(std::string id, SrsRequest* req, ISrsExpire* conn, SrsRtmpConnType type)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
// TODO: FIXME: We should use UUID for client ID.
|
||||
std::string id = cid.c_str();
|
||||
|
||||
SrsStatisticVhost* vhost = create_vhost(req);
|
||||
SrsStatisticStream* stream = create_stream(vhost, req);
|
||||
|
||||
|
@ -473,11 +463,8 @@ srs_error_t SrsStatistic::on_client(SrsContextId cid, SrsRequest* req, ISrsExpir
|
|||
return err;
|
||||
}
|
||||
|
||||
void SrsStatistic::on_disconnect(const SrsContextId& cid)
|
||||
void SrsStatistic::on_disconnect(std::string id)
|
||||
{
|
||||
// TODO: FIXME: We should use UUID for client ID.
|
||||
std::string id = cid.c_str();
|
||||
|
||||
std::map<std::string, SrsStatisticClient*>::iterator it;
|
||||
if ((it = clients.find(id)) == clients.end()) {
|
||||
return;
|
||||
|
@ -494,10 +481,8 @@ void SrsStatistic::on_disconnect(const SrsContextId& cid)
|
|||
vhost->nb_clients--;
|
||||
}
|
||||
|
||||
void SrsStatistic::kbps_add_delta(const SrsContextId& cid, ISrsKbpsDelta* delta)
|
||||
void SrsStatistic::kbps_add_delta(std::string id, ISrsKbpsDelta* delta)
|
||||
{
|
||||
// TODO: FIXME: Should not use context id as connection id.
|
||||
std::string id = cid.c_str();
|
||||
if (clients.find(id) == clients.end()) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -68,7 +68,8 @@ public:
|
|||
std::string stream;
|
||||
std::string url;
|
||||
bool active;
|
||||
SrsContextId connection_cid;
|
||||
// The publisher connection id.
|
||||
std::string publisher_id;
|
||||
int nb_clients;
|
||||
uint64_t nb_frames;
|
||||
public:
|
||||
|
@ -101,8 +102,8 @@ public:
|
|||
public:
|
||||
virtual srs_error_t dumps(SrsJsonObject* obj);
|
||||
public:
|
||||
// Publish the stream.
|
||||
virtual void publish(SrsContextId cid);
|
||||
// Publish the stream, id is the publisher.
|
||||
virtual void publish(std::string id);
|
||||
// Close the stream.
|
||||
virtual void close();
|
||||
};
|
||||
|
@ -196,8 +197,8 @@ public:
|
|||
virtual srs_error_t on_video_frames(SrsRequest* req, int nb_frames);
|
||||
// When publish stream.
|
||||
// @param req the request object of publish connection.
|
||||
// @param cid the cid of publish connection.
|
||||
virtual void on_stream_publish(SrsRequest* req, SrsContextId cid);
|
||||
// @param publisher_id The id of publish connection.
|
||||
virtual void on_stream_publish(SrsRequest* req, std::string publisher_id);
|
||||
// When close stream.
|
||||
virtual void on_stream_close(SrsRequest* req);
|
||||
public:
|
||||
|
@ -206,17 +207,15 @@ public:
|
|||
// @param req, the client request object.
|
||||
// @param conn, the physical absract connection object.
|
||||
// @param type, the type of connection.
|
||||
// TODO: FIXME: We should not use context id as client id.
|
||||
virtual srs_error_t on_client(SrsContextId id, SrsRequest* req, ISrsExpire* conn, SrsRtmpConnType type);
|
||||
virtual srs_error_t on_client(std::string id, SrsRequest* req, ISrsExpire* conn, SrsRtmpConnType type);
|
||||
// Client disconnect
|
||||
// @remark the on_disconnect always call, while the on_client is call when
|
||||
// only got the request object, so the client specified by id maybe not
|
||||
// exists in stat.
|
||||
// TODO: FIXME: We should not use context id as client id.
|
||||
virtual void on_disconnect(const SrsContextId& id);
|
||||
virtual void on_disconnect(std::string id);
|
||||
// Sample the kbps, add delta bytes of conn.
|
||||
// Use kbps_sample() to get all result of kbps stat.
|
||||
virtual void kbps_add_delta(const SrsContextId& cid, ISrsKbpsDelta* delta);
|
||||
virtual void kbps_add_delta(std::string id, ISrsKbpsDelta* delta);
|
||||
// Calc the result for all kbps.
|
||||
// @return the server kbps.
|
||||
virtual SrsKbps* kbps_sample();
|
||||
|
|
|
@ -26,6 +26,6 @@
|
|||
|
||||
#define VERSION_MAJOR 4
|
||||
#define VERSION_MINOR 0
|
||||
#define VERSION_REVISION 107
|
||||
#define VERSION_REVISION 108
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue