Skip to content
11 changes: 9 additions & 2 deletions ngx_rtmp_stat_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
ngx_int_t n;
ngx_uint_t nclients, total_nclients;
ngx_uint_t f;
ngx_flag_t prev;
u_char buf[NGX_INT_T_LEN];
u_char bbuf[NGX_INT32_LEN];
ngx_rtmp_stat_loc_conf_t *slcf;
Expand All @@ -526,12 +527,13 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
}

total_nclients = 0;
prev = 0;
for (n = 0; n < lacf->nbuckets; ++n) {
for (stream = lacf->streams[n]; stream; stream = stream->next) {
if (slcf->format & NGX_RTMP_STAT_FORMAT_XML) {
NGX_RTMP_STAT_L("<stream>\r\n");
} else {
if (total_nclients || stream->next) {
if (prev) {
NGX_RTMP_STAT_L(",");
}

Expand Down Expand Up @@ -861,6 +863,8 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
}

NGX_RTMP_STAT_L("}");

prev = 1;
}
}
}
Expand All @@ -887,6 +891,7 @@ ngx_rtmp_stat_play(ngx_http_request_t *r, ngx_chain_t ***lll,
ngx_rtmp_play_ctx_t *ctx, *sctx;
ngx_rtmp_session_t *s;
ngx_uint_t n, nclients, total_nclients;
ngx_flag_t prev;
u_char buf[NGX_INT_T_LEN];
u_char bbuf[NGX_INT32_LEN];
ngx_rtmp_stat_loc_conf_t *slcf;
Expand All @@ -905,6 +910,7 @@ ngx_rtmp_stat_play(ngx_http_request_t *r, ngx_chain_t ***lll,
}

total_nclients = 0;
prev = 0;
for (n = 0; n < pacf->nbuckets; ++n) {
for (ctx = pacf->ctx[n]; ctx; ) {
if (slcf->format & NGX_RTMP_STAT_FORMAT_XML) {
Expand All @@ -913,7 +919,7 @@ ngx_rtmp_stat_play(ngx_http_request_t *r, ngx_chain_t ***lll,
NGX_RTMP_STAT_ECS(ctx->name);
NGX_RTMP_STAT_L("</name>\r\n");
} else {
if (total_nclients || ctx->next) {
if (prev) {
NGX_RTMP_STAT_L(",");
}

Expand Down Expand Up @@ -973,6 +979,7 @@ ngx_rtmp_stat_play(ngx_http_request_t *r, ngx_chain_t ***lll,
NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf),
"%ui", nclients) - buf);
NGX_RTMP_STAT_L("}");
prev = 1;
}
}
}
Expand Down