22/*
33 * Copyright (C) Roman Arutyunyan
44 * Copyright (C) plainheart
5+ * Copyright (C) Winshining
56 */
67
78
@@ -277,7 +278,7 @@ ngx_rtmp_stat_bw(ngx_http_request_t *r, ngx_chain_t ***lll,
277278{
278279 u_char buf [NGX_INT64_LEN + 9 ];
279280 ngx_rtmp_stat_loc_conf_t * slcf ;
280-
281+
281282 slcf = ngx_http_get_module_loc_conf (r , ngx_rtmp_stat_module );
282283
283284 ngx_rtmp_update_bandwidth (bw , 0 );
@@ -350,12 +351,12 @@ ngx_rtmp_stat_dump_pool(ngx_http_request_t *r, ngx_chain_t ***lll,
350351 ngx_uint_t nlarge , size ;
351352 u_char buf [NGX_INT_T_LEN ];
352353 ngx_rtmp_stat_loc_conf_t * slcf ;
353-
354- slcf = ngx_http_get_module_loc_conf (r , ngx_rtmp_stat_module );
355354
356355 size = 0 ;
357356 nlarge = 0 ;
358357 ngx_rtmp_stat_get_pool_size (pool , & nlarge , & size );
358+
359+ slcf = ngx_http_get_module_loc_conf (r , ngx_rtmp_stat_module );
359360 if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
360361 NGX_RTMP_STAT_L ("<pool><nlarge>" );
361362 NGX_RTMP_STAT (buf , ngx_snprintf (buf , sizeof (buf ), "%ui" , nlarge ) - buf );
@@ -576,23 +577,25 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
576577
577578 nclients = 0 ;
578579 codec = NULL ;
579-
580- if (slcf -> stat & NGX_RTMP_STAT_CLIENTS && slcf -> format & NGX_RTMP_STAT_FORMAT_JSON ) {
580+
581+ if (slcf -> stat & NGX_RTMP_STAT_CLIENTS &&
582+ slcf -> format & NGX_RTMP_STAT_FORMAT_JSON )
583+ {
581584 NGX_RTMP_STAT_L ("\"clients\":[" );
582585 }
583-
586+
584587 for (ctx = stream -> ctx ; ctx ; ctx = ctx -> next , ++ nclients ) {
585588 s = ctx -> session ;
586589 if (slcf -> stat & NGX_RTMP_STAT_CLIENTS ) {
587-
590+
588591 if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
589592 NGX_RTMP_STAT_L ("<client>" );
590593 } else {
591594 NGX_RTMP_STAT_L ("{" );
592595 }
593-
596+
594597 ngx_rtmp_stat_client (r , lll , s );
595-
598+
596599 if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
597600 NGX_RTMP_STAT_L ("<dropped>" );
598601 NGX_RTMP_STAT (buf , ngx_snprintf (buf , sizeof (buf ),
@@ -649,7 +652,6 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
649652 NGX_RTMP_STAT_L ("false" );
650653 }
651654 }
652-
653655
654656 if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
655657 NGX_RTMP_STAT_L ("</client>\r\n" );
@@ -665,11 +667,11 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
665667 }
666668 }
667669 total_nclients += nclients ;
668-
670+
669671 if (slcf -> stat & NGX_RTMP_STAT_CLIENTS && slcf -> format & NGX_RTMP_STAT_FORMAT_JSON ) {
670672 NGX_RTMP_STAT_L ("]," );
671673 }
672-
674+
673675 if (codec ) {
674676 if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
675677 NGX_RTMP_STAT_L ("<meta>" );
@@ -785,7 +787,6 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
785787 NGX_RTMP_STAT_L ("\"" );
786788 }
787789
788-
789790 NGX_RTMP_STAT_L ("},\"audio\": {" );
790791 cname = ngx_rtmp_get_audio_codec_name (codec -> audio_codec_id );
791792 f = 0 ;
@@ -831,7 +832,7 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
831832 NGX_RTMP_STAT_L ("}" );
832833 }
833834 }
834-
835+
835836 if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
836837 NGX_RTMP_STAT_L ("<nclients>" );
837838 NGX_RTMP_STAT (buf , ngx_snprintf (buf , sizeof (buf ),
@@ -873,7 +874,7 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
873874 }
874875 }
875876 }
876-
877+
877878 if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
878879 NGX_RTMP_STAT_L ("<nclients>" );
879880 NGX_RTMP_STAT (buf , ngx_snprintf (buf , sizeof (buf ),
@@ -886,7 +887,6 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
886887 "%ui" , total_nclients ) - buf );
887888 NGX_RTMP_STAT_L ("}" );
888889 }
889-
890890}
891891
892892
@@ -968,7 +968,7 @@ ngx_rtmp_stat_play(ngx_http_request_t *r, ngx_chain_t ***lll,
968968 NGX_RTMP_STAT_L ("\"timestamp\":" );
969969 NGX_RTMP_STAT (bbuf , ngx_snprintf (bbuf , sizeof (bbuf ),
970970 "%D" , s -> current_time ) - bbuf );
971-
971+
972972 NGX_RTMP_STAT_L ("}" );
973973 }
974974 }
@@ -1013,9 +1013,9 @@ ngx_rtmp_stat_application(ngx_http_request_t *r, ngx_chain_t ***lll,
10131013 ngx_rtmp_core_app_conf_t * cacf )
10141014{
10151015 ngx_rtmp_stat_loc_conf_t * slcf ;
1016-
1016+
10171017 slcf = ngx_http_get_module_loc_conf (r , ngx_rtmp_stat_module );
1018-
1018+
10191019 if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
10201020 NGX_RTMP_STAT_L ("<application>\r\n" );
10211021 NGX_RTMP_STAT_L ("<name>" );
@@ -1058,9 +1058,9 @@ ngx_rtmp_stat_server(ngx_http_request_t *r, ngx_chain_t ***lll,
10581058 ngx_rtmp_core_app_conf_t * * cacf ;
10591059 size_t n ;
10601060 ngx_rtmp_stat_loc_conf_t * slcf ;
1061-
1061+
10621062 slcf = ngx_http_get_module_loc_conf (r , ngx_rtmp_stat_module );
1063-
1063+
10641064 if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
10651065 NGX_RTMP_STAT_L ("<server>\r\n" );
10661066 }
@@ -1073,22 +1073,24 @@ ngx_rtmp_stat_server(ngx_http_request_t *r, ngx_chain_t ***lll,
10731073#endif
10741074
10751075 if (slcf -> format & NGX_RTMP_STAT_FORMAT_JSON ) {
1076- NGX_RTMP_STAT_L ("\"applications\":[" );
1076+ NGX_RTMP_STAT_L ("{ \"applications\":[" );
10771077 }
1078-
1078+
10791079 cacf = cscf -> applications .elts ;
10801080 for (n = 0 ; n < cscf -> applications .nelts ; ++ n , ++ cacf ) {
10811081 ngx_rtmp_stat_application (r , lll , * cacf );
1082-
1083- if (slcf -> format & NGX_RTMP_STAT_FORMAT_JSON && n < cscf -> applications .nelts - 1 ) {
1082+
1083+ if (slcf -> format & NGX_RTMP_STAT_FORMAT_JSON &&
1084+ n < cscf -> applications .nelts - 1 )
1085+ {
10841086 NGX_RTMP_STAT_L ("," );
10851087 }
10861088 }
1087-
1089+
10881090 if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
10891091 NGX_RTMP_STAT_L ("</server>\r\n" );
10901092 } else {
1091- NGX_RTMP_STAT_L ("]" );
1093+ NGX_RTMP_STAT_L ("]} " );
10921094 }
10931095}
10941096
@@ -1106,11 +1108,10 @@ ngx_rtmp_stat_handler(ngx_http_request_t *r)
11061108 static u_char nbuf [NGX_INT_T_LEN ];
11071109
11081110 slcf = ngx_http_get_module_loc_conf (r , ngx_rtmp_stat_module );
1109-
11101111 if (slcf -> stat == 0 ) {
11111112 return NGX_DECLINED ;
11121113 }
1113-
1114+
11141115 if (slcf -> format == 0 ) {
11151116 slcf -> format = NGX_RTMP_STAT_FORMAT_XML ;
11161117 }
@@ -1123,7 +1124,7 @@ ngx_rtmp_stat_handler(ngx_http_request_t *r)
11231124 cl = NULL ;
11241125 ll = & cl ;
11251126 lll = & ll ;
1126-
1127+
11271128 if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
11281129 NGX_RTMP_STAT_L ("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n" );
11291130 if (slcf -> stylesheet .len ) {
@@ -1201,7 +1202,7 @@ ngx_rtmp_stat_handler(ngx_http_request_t *r)
12011202 ngx_rtmp_stat_bw (r , lll , & ngx_rtmp_bw_out , "out" , NGX_RTMP_STAT_BW_BYTES );
12021203
12031204 if (slcf -> format & NGX_RTMP_STAT_FORMAT_JSON ) {
1204- NGX_RTMP_STAT_L ("\"server \":{ " );
1205+ NGX_RTMP_STAT_L ("\"servers \":[ " );
12051206 }
12061207
12071208 cscf = cmcf -> servers .elts ;
@@ -1211,18 +1212,18 @@ ngx_rtmp_stat_handler(ngx_http_request_t *r)
12111212 NGX_RTMP_STAT_L ("," );
12121213 }
12131214 }
1214-
1215+
12151216 if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
12161217 NGX_RTMP_STAT_L ("</http-flv>\r\n" );
12171218 } else {
1218- NGX_RTMP_STAT_L ("} }}" );
1219+ NGX_RTMP_STAT_L ("] }}" );
12191220 }
1220-
1221+
12211222 len = 0 ;
12221223 for (l = cl ; l ; l = l -> next ) {
12231224 len += (l -> buf -> last - l -> buf -> pos );
12241225 }
1225-
1226+
12261227 if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
12271228 ngx_str_set (& r -> headers_out .content_type , "text/xml" );
12281229 } else {
0 commit comments