From 310e49e7f34d7f19a3c04e0af5c96e7a75716e5c Mon Sep 17 00:00:00 2001 From: "qiang.li" Date: Thu, 8 Jan 2015 21:58:10 +0800 Subject: [PATCH] add client num in statistic with traverse every client --- trunk/src/app/srs_app_rtmp_conn.cpp | 3 ++- trunk/src/app/srs_app_statistic.cpp | 20 +++++++++++--------- trunk/src/app/srs_app_statistic.hpp | 4 +--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp index e9f9e429a..068796076 100644 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -200,7 +200,8 @@ int SrsRtmpConn::do_cycle() ret = service_cycle(); http_hooks_on_close(); - SrsStatistic::instance()->on_close(_srs_context->get_id()); + SrsStatistic* stat = SrsStatistic::instance(); + stat->on_close(_srs_context->get_id()); return ret; } diff --git a/trunk/src/app/srs_app_statistic.cpp b/trunk/src/app/srs_app_statistic.cpp index 49eef587f..935044d2e 100644 --- a/trunk/src/app/srs_app_statistic.cpp +++ b/trunk/src/app/srs_app_statistic.cpp @@ -131,26 +131,19 @@ int SrsStatistic::on_client(int id, SrsRequest* req) } else { client = clients[id]; } - - stream->clients[id] = client; return ret; } -int SrsStatistic::on_close(int id) +void SrsStatistic::on_close(int id) { - int ret = ERROR_SUCCESS; - std::map::iterator it; it = clients.find(id); if (it != clients.end()) { SrsStatisticClient* client = it->second; - client->stream->clients.erase(id); srs_freep(client); clients.erase(it); } - - return ret; } int64_t SrsStatistic::server_id() @@ -192,11 +185,20 @@ int SrsStatistic::dumps_streams(stringstream& ss) ss << __SRS_JFIELD_CONT; } + int client_num = 0; + std::map::iterator it_client; + for (it_client = clients.begin(); it_client != clients.end(); it_client++) { + SrsStatisticClient* client = it_client->second; + if (client->stream == stream) { + client_num++; + } + } + ss << __SRS_JOBJECT_START << __SRS_JFIELD_ORG("id", stream->id) << __SRS_JFIELD_CONT << __SRS_JFIELD_STR("name", stream->stream) << __SRS_JFIELD_CONT << __SRS_JFIELD_ORG("vhost", stream->vhost->id) << __SRS_JFIELD_CONT - << __SRS_JFIELD_ORG("clients", stream->clients.size()) + << __SRS_JFIELD_ORG("clients", client_num) << __SRS_JOBJECT_END; } ss << __SRS_JARRAY_END; diff --git a/trunk/src/app/srs_app_statistic.hpp b/trunk/src/app/srs_app_statistic.hpp index 0d380549d..0e3c5aa89 100644 --- a/trunk/src/app/srs_app_statistic.hpp +++ b/trunk/src/app/srs_app_statistic.hpp @@ -34,7 +34,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include class SrsRequest; -struct SrsStatisticClient; struct SrsStatisticVhost { @@ -54,7 +53,6 @@ public: std::string app; std::string stream; std::string url; - std::map clients; public: SrsStatisticStream(); virtual ~SrsStatisticStream(); @@ -94,7 +92,7 @@ public: /** * client close */ - virtual int on_close(int id); + virtual void on_close(int id); public: /** * get the server id, used to identify the server.