qiang.li

add client num in statistic with traverse every client

@@ -200,7 +200,8 @@ int SrsRtmpConn::do_cycle() @@ -200,7 +200,8 @@ int SrsRtmpConn::do_cycle()
200 200
201 ret = service_cycle(); 201 ret = service_cycle();
202 http_hooks_on_close(); 202 http_hooks_on_close();
203 - SrsStatistic::instance()->on_close(_srs_context->get_id()); 203 + SrsStatistic* stat = SrsStatistic::instance();
  204 + stat->on_close(_srs_context->get_id());
204 205
205 return ret; 206 return ret;
206 } 207 }
@@ -131,26 +131,19 @@ int SrsStatistic::on_client(int id, SrsRequest* req) @@ -131,26 +131,19 @@ int SrsStatistic::on_client(int id, SrsRequest* req)
131 } else { 131 } else {
132 client = clients[id]; 132 client = clients[id];
133 } 133 }
134 -  
135 - stream->clients[id] = client;  
136 134
137 return ret; 135 return ret;
138 } 136 }
139 137
140 -int SrsStatistic::on_close(int id) 138 +void SrsStatistic::on_close(int id)
141 { 139 {
142 - int ret = ERROR_SUCCESS;  
143 -  
144 std::map<int, SrsStatisticClient*>::iterator it; 140 std::map<int, SrsStatisticClient*>::iterator it;
145 it = clients.find(id); 141 it = clients.find(id);
146 if (it != clients.end()) { 142 if (it != clients.end()) {
147 SrsStatisticClient* client = it->second; 143 SrsStatisticClient* client = it->second;
148 - client->stream->clients.erase(id);  
149 srs_freep(client); 144 srs_freep(client);
150 clients.erase(it); 145 clients.erase(it);
151 } 146 }
152 -  
153 - return ret;  
154 } 147 }
155 148
156 int64_t SrsStatistic::server_id() 149 int64_t SrsStatistic::server_id()
@@ -192,11 +185,20 @@ int SrsStatistic::dumps_streams(stringstream& ss) @@ -192,11 +185,20 @@ int SrsStatistic::dumps_streams(stringstream& ss)
192 ss << __SRS_JFIELD_CONT; 185 ss << __SRS_JFIELD_CONT;
193 } 186 }
194 187
  188 + int client_num = 0;
  189 + std::map<int, SrsStatisticClient*>::iterator it_client;
  190 + for (it_client = clients.begin(); it_client != clients.end(); it_client++) {
  191 + SrsStatisticClient* client = it_client->second;
  192 + if (client->stream == stream) {
  193 + client_num++;
  194 + }
  195 + }
  196 +
195 ss << __SRS_JOBJECT_START 197 ss << __SRS_JOBJECT_START
196 << __SRS_JFIELD_ORG("id", stream->id) << __SRS_JFIELD_CONT 198 << __SRS_JFIELD_ORG("id", stream->id) << __SRS_JFIELD_CONT
197 << __SRS_JFIELD_STR("name", stream->stream) << __SRS_JFIELD_CONT 199 << __SRS_JFIELD_STR("name", stream->stream) << __SRS_JFIELD_CONT
198 << __SRS_JFIELD_ORG("vhost", stream->vhost->id) << __SRS_JFIELD_CONT 200 << __SRS_JFIELD_ORG("vhost", stream->vhost->id) << __SRS_JFIELD_CONT
199 - << __SRS_JFIELD_ORG("clients", stream->clients.size()) 201 + << __SRS_JFIELD_ORG("clients", client_num)
200 << __SRS_JOBJECT_END; 202 << __SRS_JOBJECT_END;
201 } 203 }
202 ss << __SRS_JARRAY_END; 204 ss << __SRS_JARRAY_END;
@@ -34,7 +34,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -34,7 +34,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 #include <string> 34 #include <string>
35 35
36 class SrsRequest; 36 class SrsRequest;
37 -struct SrsStatisticClient;  
38 37
39 struct SrsStatisticVhost 38 struct SrsStatisticVhost
40 { 39 {
@@ -54,7 +53,6 @@ public: @@ -54,7 +53,6 @@ public:
54 std::string app; 53 std::string app;
55 std::string stream; 54 std::string stream;
56 std::string url; 55 std::string url;
57 - std::map<int, SrsStatisticClient*> clients;  
58 public: 56 public:
59 SrsStatisticStream(); 57 SrsStatisticStream();
60 virtual ~SrsStatisticStream(); 58 virtual ~SrsStatisticStream();
@@ -94,7 +92,7 @@ public: @@ -94,7 +92,7 @@ public:
94 /** 92 /**
95 * client close 93 * client close
96 */ 94 */
97 - virtual int on_close(int id); 95 + virtual void on_close(int id);
98 public: 96 public:
99 /** 97 /**
100 * get the server id, used to identify the server. 98 * get the server id, used to identify the server.