@@ -504,6 +504,7 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
504504 ngx_rtmp_live_ctx_t *ctx;
505505 ngx_rtmp_session_t *s;
506506 ngx_int_t n;
507+ ngx_uint_t m;
507508 ngx_uint_t nclients, total_nclients;
508509 ngx_uint_t f;
509510 u_char buf[NGX_INT_T_LEN];
@@ -526,15 +527,18 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
526527
527528 total_nclients = 0;
528529 for (n = 0; n < lacf->nbuckets; ++n) {
529- for (stream = lacf->streams[n]; ; stream = stream->next) {
530-
531- if (!stream) {
532- break;
533- }
530+ m = 0;
531+ if (n > 0 && lacf->streams[n - 1]) {
532+ m = 1;
533+ }
534+ for (stream = lacf->streams[n]; stream; stream = stream->next) {
534535
535536 if (slcf->format & NGX_RTMP_STAT_FORMAT_XML) {
536537 NGX_RTMP_STAT_L("<stream>\r\n");
537538 } else {
539+ if (m == 1 || stream->next != NULL) {
540+ NGX_RTMP_STAT_L(",");
541+ }
538542 NGX_RTMP_STAT_L("{");
539543 }
540544
@@ -781,7 +785,7 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
781785 }
782786
783787
784- NGX_RTMP_STAT_L("}, \"audio\": {");
788+ NGX_RTMP_STAT_L("},\"audio\": {");
785789 cname = ngx_rtmp_get_audio_codec_name(codec->audio_codec_id);
786790 f = 0;
787791 if (*cname) {
@@ -866,8 +870,6 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
866870
867871 NGX_RTMP_STAT_L("}");
868872 }
869-
870- NGX_RTMP_STAT_L(",");
871873 }
872874 }
873875
@@ -893,7 +895,7 @@ ngx_rtmp_stat_play(ngx_http_request_t *r, ngx_chain_t ***lll,
893895{
894896 ngx_rtmp_play_ctx_t *ctx, *sctx;
895897 ngx_rtmp_session_t *s;
896- ngx_uint_t n, nclients, total_nclients;
898+ ngx_uint_t m, n, nclients, total_nclients;
897899 u_char buf[NGX_INT_T_LEN];
898900 u_char bbuf[NGX_INT32_LEN];
899901 ngx_rtmp_stat_loc_conf_t *slcf;
@@ -913,6 +915,10 @@ ngx_rtmp_stat_play(ngx_http_request_t *r, ngx_chain_t ***lll,
913915
914916 total_nclients = 0;
915917 for (n = 0; n < pacf->nbuckets; ++n) {
918+ m = 0;
919+ if (n > 0 && pacf->ctx[n - 1]) {
920+ m = 1;
921+ }
916922 for (ctx = pacf->ctx[n]; ctx; ) {
917923
918924 if (slcf->format & NGX_RTMP_STAT_FORMAT_XML) {
@@ -921,6 +927,9 @@ ngx_rtmp_stat_play(ngx_http_request_t *r, ngx_chain_t ***lll,
921927 NGX_RTMP_STAT_ECS(ctx->name);
922928 NGX_RTMP_STAT_L("</name>\r\n");
923929 } else {
930+ if (m == 1 || ctx->next != NULL) {
931+ NGX_RTMP_STAT_L(",");
932+ }
924933 NGX_RTMP_STAT_L("{\"name\":\"");
925934 NGX_RTMP_STAT_ECS(ctx->name);
926935 NGX_RTMP_STAT_L("\",\"clients\":[");
@@ -959,9 +968,6 @@ ngx_rtmp_stat_play(ngx_http_request_t *r, ngx_chain_t ***lll,
959968 "%D", s->current_time) - bbuf);
960969
961970 NGX_RTMP_STAT_L("}");
962- if (ctx->next) {
963- NGX_RTMP_STAT_L(",");
964- }
965971 }
966972 }
967973 }
0 commit comments