From 9cbdf29f7d1a96371e10500d6244096c42a49d35 Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 13 May 2021 16:05:33 +0800 Subject: [PATCH 1/3] SRT: Fix build fail bug, add ssl --- trunk/configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trunk/configure b/trunk/configure index 17371a5cf..9607f9413 100755 --- a/trunk/configure +++ b/trunk/configure @@ -247,7 +247,7 @@ PROTOCOL_OBJS="${MODULE_OBJS[@]}" if [ $SRS_SRT = YES ]; then MODULE_ID="SRT" 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") SRT_INCS=${LibSRTRoot}; MODULE_DIR=${LibSRTRoot} . auto/modules.sh SRT_OBJS="${MODULE_OBJS[@]}" From 393d9766851097d15c2231c515158e7bc0cc4ac4 Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 13 May 2021 22:32:29 +0800 Subject: [PATCH 2/3] SquashSRS4: Fix memory leak --- trunk/src/app/srs_app_statistic.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/trunk/src/app/srs_app_statistic.cpp b/trunk/src/app/srs_app_statistic.cpp index 4e58e9511..d4e856be0 100644 --- a/trunk/src/app/srs_app_statistic.cpp +++ b/trunk/src/app/srs_app_statistic.cpp @@ -214,6 +214,7 @@ SrsStatisticClient::SrsStatisticClient() SrsStatisticClient::~SrsStatisticClient() { + srs_freep(req); } srs_error_t SrsStatisticClient::dumps(SrsJsonObject* obj) From 06f7d7d11b455f0a1ac00ee1dd47942a3a8bdcc9 Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 14 May 2021 08:21:16 +0800 Subject: [PATCH 3/3] Refine id and vid for statistic. 4.0.108 --- README.md | 1 + trunk/src/app/srs_app_http_stream.cpp | 2 +- trunk/src/app/srs_app_rtmp_conn.cpp | 2 +- trunk/src/app/srs_app_server.cpp | 6 ++-- trunk/src/app/srs_app_source.cpp | 2 +- trunk/src/app/srs_app_statistic.cpp | 43 +++++++++------------------ trunk/src/app/srs_app_statistic.hpp | 19 ++++++------ trunk/src/core/srs_core_version4.hpp | 2 +- 8 files changed, 31 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index aeea7a305..b4699a618 100755 --- a/README.md +++ b/README.md @@ -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 diff --git a/trunk/src/app/srs_app_http_stream.cpp b/trunk/src/app/srs_app_http_stream.cpp index 04a3f7a5a..eb4e372e9 100755 --- a/trunk/src/app/srs_app_http_stream.cpp +++ b/trunk/src/app/srs_app_http_stream.cpp @@ -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"); } diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp index d6fe9d630..b2dac498e 100644 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -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"); } diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index 3a0bed647..1c9d9a165 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -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(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); diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index 5f0ce3313..ed737f1cc 100755 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -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; } diff --git a/trunk/src/app/srs_app_statistic.cpp b/trunk/src/app/srs_app_statistic.cpp index d4e856be0..37dbab504 100644 --- a/trunk/src/app/srs_app_statistic.cpp +++ b/trunk/src/app/srs_app_statistic.cpp @@ -34,23 +34,16 @@ using namespace std; #include #include #include +#include -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::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; } diff --git a/trunk/src/app/srs_app_statistic.hpp b/trunk/src/app/srs_app_statistic.hpp index 7ec90a2ac..1441cd57e 100644 --- a/trunk/src/app/srs_app_statistic.hpp +++ b/trunk/src/app/srs_app_statistic.hpp @@ -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(); diff --git a/trunk/src/core/srs_core_version4.hpp b/trunk/src/core/srs_core_version4.hpp index e8f5529dc..35a083367 100644 --- a/trunk/src/core/srs_core_version4.hpp +++ b/trunk/src/core/srs_core_version4.hpp @@ -26,6 +26,6 @@ #define VERSION_MAJOR 4 #define VERSION_MINOR 0 -#define VERSION_REVISION 107 +#define VERSION_REVISION 108 #endif