Merge branch '4.0release' into merge/develop

pull/2943/head
winlin 4 years ago
commit 9fbfaf317e

@ -182,6 +182,7 @@ The ports used by SRS:
## V4 changes ## 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-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 shared fast timer. 4.0.105
* v4.0, 2021-05-08, Refine global or thread-local variables initialize. 4.0.104 * v4.0, 2021-05-08, Refine global or thread-local variables initialize. 4.0.104

2
trunk/configure vendored

@ -244,7 +244,7 @@ PROTOCOL_OBJS="${MODULE_OBJS[@]}"
if [ $SRS_SRT = YES ]; then if [ $SRS_SRT = YES ]; then
MODULE_ID="SRT" MODULE_ID="SRT"
MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL" "APP") MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL" "APP")
ModuleLibIncs=(${SRS_OBJS_DIR}) ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSSLRoot})
MODULE_FILES=("srt_server" "srt_handle" "srt_conn" "srt_to_rtmp" "ts_demux" "srt_data") MODULE_FILES=("srt_server" "srt_handle" "srt_conn" "srt_to_rtmp" "ts_demux" "srt_data")
SRT_INCS=${LibSRTRoot}; MODULE_DIR=${LibSRTRoot} . auto/modules.sh SRT_INCS=${LibSRTRoot}; MODULE_DIR=${LibSRTRoot} . auto/modules.sh
SRT_OBJS="${MODULE_OBJS[@]}" SRT_OBJS="${MODULE_OBJS[@]}"

@ -606,7 +606,7 @@ srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
// update the statistic when source disconveried. // update the statistic when source disconveried.
SrsStatistic* stat = SrsStatistic::instance(); 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"); 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. // update the statistic when source disconveried.
SrsStatistic* stat = SrsStatistic::instance(); 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"); return srs_error_wrap(err, "rtmp: stat client");
} }

@ -1555,7 +1555,7 @@ void SrsServer::resample_kbps()
// add delta of connection to server kbps., // add delta of connection to server kbps.,
// for next sample() of server kbps can get the stat. // 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. // TODO: FXME: support all other connections.
@ -1662,8 +1662,8 @@ void SrsServer::remove(ISrsResource* c)
ISrsStartableConneciton* conn = dynamic_cast<ISrsStartableConneciton*>(c); ISrsStartableConneciton* conn = dynamic_cast<ISrsStartableConneciton*>(c);
SrsStatistic* stat = SrsStatistic::instance(); SrsStatistic* stat = SrsStatistic::instance();
stat->kbps_add_delta(c->get_id(), conn); stat->kbps_add_delta(c->get_id().c_str(), conn);
stat->on_disconnect(c->get_id()); stat->on_disconnect(c->get_id().c_str());
// use manager to free it async. // use manager to free it async.
conn_manager->remove(c); conn_manager->remove(c);

@ -2518,7 +2518,7 @@ srs_error_t SrsSource::on_publish()
} }
SrsStatistic* stat = SrsStatistic::instance(); SrsStatistic* stat = SrsStatistic::instance();
stat->on_stream_publish(req, _source_id); stat->on_stream_publish(req, _source_id.c_str());
return err; return err;
} }

@ -34,23 +34,16 @@ using namespace std;
#include <srs_app_config.hpp> #include <srs_app_config.hpp>
#include <srs_kernel_utility.hpp> #include <srs_kernel_utility.hpp>
#include <srs_protocol_amf0.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; return "vid-" + srs_random_str(7);
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;
} }
SrsStatisticVhost::SrsStatisticVhost() SrsStatisticVhost::SrsStatisticVhost()
{ {
id = srs_generate_id(); id = srs_generate_stat_vid();
clk = new SrsWallClock(); clk = new SrsWallClock();
kbps = new SrsKbps(clk); kbps = new SrsKbps(clk);
@ -101,7 +94,7 @@ srs_error_t SrsStatisticVhost::dumps(SrsJsonObject* obj)
SrsStatisticStream::SrsStatisticStream() SrsStatisticStream::SrsStatisticStream()
{ {
id = srs_generate_id(); id = srs_generate_stat_vid();
vhost = NULL; vhost = NULL;
active = false; active = false;
@ -156,7 +149,7 @@ srs_error_t SrsStatisticStream::dumps(SrsJsonObject* obj)
obj->set("publish", publish); obj->set("publish", publish);
publish->set("active", SrsJsonAny::boolean(active)); 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) { if (!has_video) {
obj->set("video", SrsJsonAny::null()); obj->set("video", SrsJsonAny::null());
@ -186,9 +179,9 @@ srs_error_t SrsStatisticStream::dumps(SrsJsonObject* obj)
return err; return err;
} }
void SrsStatisticStream::publish(SrsContextId cid) void SrsStatisticStream::publish(std::string id)
{ {
connection_cid = cid; publisher_id = id;
active = true; active = true;
vhost->nb_streams++; vhost->nb_streams++;
@ -214,6 +207,7 @@ SrsStatisticClient::SrsStatisticClient()
SrsStatisticClient::~SrsStatisticClient() SrsStatisticClient::~SrsStatisticClient()
{ {
srs_freep(req);
} }
srs_error_t SrsStatisticClient::dumps(SrsJsonObject* obj) srs_error_t SrsStatisticClient::dumps(SrsJsonObject* obj)
@ -260,7 +254,7 @@ SrsStatistic* SrsStatistic::_instance = NULL;
SrsStatistic::SrsStatistic() SrsStatistic::SrsStatistic()
{ {
_server_id = srs_generate_id(); _server_id = srs_generate_stat_vid();
clk = new SrsWallClock(); clk = new SrsWallClock();
kbps = new SrsKbps(clk); kbps = new SrsKbps(clk);
@ -406,12 +400,12 @@ srs_error_t SrsStatistic::on_video_frames(SrsRequest* req, int nb_frames)
return err; 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); SrsStatisticVhost* vhost = create_vhost(req);
SrsStatisticStream* stream = create_stream(vhost, req); SrsStatisticStream* stream = create_stream(vhost, req);
stream->publish(cid); stream->publish(publisher_id);
} }
void SrsStatistic::on_stream_close(SrsRequest* req) void SrsStatistic::on_stream_close(SrsRequest* req)
@ -437,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; 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); SrsStatisticVhost* vhost = create_vhost(req);
SrsStatisticStream* stream = create_stream(vhost, req); SrsStatisticStream* stream = create_stream(vhost, req);
@ -472,11 +463,8 @@ srs_error_t SrsStatistic::on_client(SrsContextId cid, SrsRequest* req, ISrsExpir
return err; 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; std::map<std::string, SrsStatisticClient*>::iterator it;
if ((it = clients.find(id)) == clients.end()) { if ((it = clients.find(id)) == clients.end()) {
return; return;
@ -493,10 +481,8 @@ void SrsStatistic::on_disconnect(const SrsContextId& cid)
vhost->nb_clients--; 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()) { if (clients.find(id) == clients.end()) {
return; return;
} }

@ -68,7 +68,8 @@ public:
std::string stream; std::string stream;
std::string url; std::string url;
bool active; bool active;
SrsContextId connection_cid; // The publisher connection id.
std::string publisher_id;
int nb_clients; int nb_clients;
uint64_t nb_frames; uint64_t nb_frames;
public: public:
@ -101,8 +102,8 @@ public:
public: public:
virtual srs_error_t dumps(SrsJsonObject* obj); virtual srs_error_t dumps(SrsJsonObject* obj);
public: public:
// Publish the stream. // Publish the stream, id is the publisher.
virtual void publish(SrsContextId cid); virtual void publish(std::string id);
// Close the stream. // Close the stream.
virtual void close(); virtual void close();
}; };
@ -196,8 +197,8 @@ public:
virtual srs_error_t on_video_frames(SrsRequest* req, int nb_frames); virtual srs_error_t on_video_frames(SrsRequest* req, int nb_frames);
// When publish stream. // When publish stream.
// @param req the request object of publish connection. // @param req the request object of publish connection.
// @param cid the cid of publish connection. // @param publisher_id The id of publish connection.
virtual void on_stream_publish(SrsRequest* req, SrsContextId cid); virtual void on_stream_publish(SrsRequest* req, std::string publisher_id);
// When close stream. // When close stream.
virtual void on_stream_close(SrsRequest* req); virtual void on_stream_close(SrsRequest* req);
public: public:
@ -206,17 +207,15 @@ public:
// @param req, the client request object. // @param req, the client request object.
// @param conn, the physical absract connection object. // @param conn, the physical absract connection object.
// @param type, the type of connection. // @param type, the type of connection.
// TODO: FIXME: We should not use context id as client id. virtual srs_error_t on_client(std::string id, SrsRequest* req, ISrsExpire* conn, SrsRtmpConnType type);
virtual srs_error_t on_client(SrsContextId id, SrsRequest* req, ISrsExpire* conn, SrsRtmpConnType type);
// Client disconnect // Client disconnect
// @remark the on_disconnect always call, while the on_client is call when // @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 // only got the request object, so the client specified by id maybe not
// exists in stat. // exists in stat.
// TODO: FIXME: We should not use context id as client id. virtual void on_disconnect(std::string id);
virtual void on_disconnect(const SrsContextId& id);
// Sample the kbps, add delta bytes of conn. // Sample the kbps, add delta bytes of conn.
// Use kbps_sample() to get all result of kbps stat. // 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. // Calc the result for all kbps.
// @return the server kbps. // @return the server kbps.
virtual SrsKbps* kbps_sample(); virtual SrsKbps* kbps_sample();

@ -26,6 +26,6 @@
#define VERSION_MAJOR 4 #define VERSION_MAJOR 4
#define VERSION_MINOR 0 #define VERSION_MINOR 0
#define VERSION_REVISION 107 #define VERSION_REVISION 108
#endif #endif

Loading…
Cancel
Save