@@ -283,7 +283,7 @@ ngx_rtmp_stat_bw(ngx_http_request_t *r, ngx_chain_t ***lll,
283283 ngx_rtmp_update_bandwidth (bw , 0 );
284284
285285 if (flags & NGX_RTMP_STAT_BW ) {
286- if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
286+ if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
287287 NGX_RTMP_STAT_L ("<bw_" );
288288 NGX_RTMP_STAT_CS (name );
289289 NGX_RTMP_STAT (buf , ngx_snprintf (buf , sizeof (buf ), ">%uL</bw_" ,
@@ -301,7 +301,7 @@ ngx_rtmp_stat_bw(ngx_http_request_t *r, ngx_chain_t ***lll,
301301 }
302302
303303 if (flags & NGX_RTMP_STAT_BYTES ) {
304- if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
304+ if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
305305 NGX_RTMP_STAT_L ("<bytes_" );
306306 NGX_RTMP_STAT_CS (name );
307307 NGX_RTMP_STAT (buf , ngx_snprintf (buf , sizeof (buf ), ">%uL</bytes_" ,
@@ -356,7 +356,7 @@ ngx_rtmp_stat_dump_pool(ngx_http_request_t *r, ngx_chain_t ***lll,
356356 size = 0 ;
357357 nlarge = 0 ;
358358 ngx_rtmp_stat_get_pool_size (pool , & nlarge , & size );
359- if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
359+ if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
360360 NGX_RTMP_STAT_L ("<pool><nlarge>" );
361361 NGX_RTMP_STAT (buf , ngx_snprintf (buf , sizeof (buf ), "%ui" , nlarge ) - buf );
362362 NGX_RTMP_STAT_L ("</nlarge><size>" );
@@ -384,12 +384,12 @@ ngx_rtmp_stat_client(ngx_http_request_t *r, ngx_chain_t ***lll,
384384
385385#ifdef NGX_RTMP_POOL_DEBUG
386386 ngx_rtmp_stat_dump_pool (r , lll , s -> connection -> pool );
387- if (slcf -> format & NGX_RTMP_STAT_FORMAT_JSON ) {
387+ if (slcf -> format & NGX_RTMP_STAT_FORMAT_JSON ) {
388388 NGX_RTMP_STAT_L ("," );
389389 }
390390#endif
391391
392- if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
392+ if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
393393 NGX_RTMP_STAT_L ("<id>" );
394394 NGX_RTMP_STAT (buf , ngx_snprintf (buf , sizeof (buf ), "%ui" ,
395395 (ngx_uint_t ) s -> connection -> number ) - buf );
@@ -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 ];
@@ -517,7 +518,7 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
517518
518519 slcf = ngx_http_get_module_loc_conf (r , ngx_rtmp_stat_module );
519520
520- if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
521+ if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
521522 NGX_RTMP_STAT_L ("<live>\r\n" );
522523 } else {
523524 NGX_RTMP_STAT_L ("\"live\":{" );
@@ -526,19 +527,22 @@ 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 ) {
530+ m = 0 ;
531+ if (n > 0 && lacf -> streams [n - 1 ]) {
532+ m = 1 ;
533+ }
529534 for (stream = lacf -> streams [n ]; stream ; stream = stream -> next ) {
530535
531- if (total_nclients > 0 ) {
532- NGX_RTMP_STAT_L ("," );
533- }
534-
535- if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
536+ 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
541- if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
545+ if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
542546 NGX_RTMP_STAT_L ("<name>" );
543547 NGX_RTMP_STAT_ECS (stream -> name );
544548 NGX_RTMP_STAT_L ("</name>\r\n" );
@@ -650,7 +654,7 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
650654 NGX_RTMP_STAT_L ("</client>\r\n" );
651655 } else {
652656 NGX_RTMP_STAT_L ("}" );
653- if (ctx -> next ) {
657+ if (ctx -> next ) {
654658 NGX_RTMP_STAT_L ("," );
655659 }
656660 }
@@ -666,7 +670,7 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
666670 }
667671
668672 if (codec ) {
669- if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
673+ if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
670674 NGX_RTMP_STAT_L ("<meta>" );
671675
672676 NGX_RTMP_STAT_L ("<video>" );
@@ -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 ) {
@@ -790,7 +794,7 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
790794 NGX_RTMP_STAT_ECS (cname );
791795 }
792796 if (codec -> aac_profile ) {
793- if (f == 1 ) NGX_RTMP_STAT_L ("\"," );
797+ if (f == 1 ) NGX_RTMP_STAT_L ("\"," );
794798 f = 2 ;
795799 NGX_RTMP_STAT_L ("\"profile\":\"" );
796800 NGX_RTMP_STAT_CS (
@@ -799,20 +803,20 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
799803 codec -> aac_ps ));
800804 }
801805 if (codec -> aac_chan_conf ) {
802- if (f >= 1 ) NGX_RTMP_STAT_L ("\"," );
806+ if (f >= 1 ) NGX_RTMP_STAT_L ("\"," );
803807 f = 3 ;
804808 NGX_RTMP_STAT_L ("\"channels\":\"" );
805809 NGX_RTMP_STAT (buf , ngx_snprintf (buf , sizeof (buf ),
806810 "%ui" , codec -> aac_chan_conf ) - buf );
807811 } else if (codec -> audio_channels ) {
808- if (f >= 1 ) NGX_RTMP_STAT_L ("\"," );
812+ if (f >= 1 ) NGX_RTMP_STAT_L ("\"," );
809813 f = 3 ;
810814 NGX_RTMP_STAT_L ("\"channels\":\"" );
811815 NGX_RTMP_STAT (buf , ngx_snprintf (buf , sizeof (buf ),
812816 "%ui" , codec -> audio_channels ) - buf );
813817 }
814818 if (codec -> sample_rate ) {
815- if (f >= 1 ) NGX_RTMP_STAT_L ("\"," );
819+ if (f >= 1 ) NGX_RTMP_STAT_L ("\"," );
816820 f = 4 ;
817821 NGX_RTMP_STAT_L ("\"sample_rate\":" );
818822 NGX_RTMP_STAT (buf , ngx_snprintf (buf , sizeof (buf ),
@@ -827,7 +831,7 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
827831 }
828832 }
829833
830- if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
834+ if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
831835 NGX_RTMP_STAT_L ("<nclients>" );
832836 NGX_RTMP_STAT (buf , ngx_snprintf (buf , sizeof (buf ),
833837 "%ui" , nclients ) - buf );
@@ -843,7 +847,7 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
843847
844848 NGX_RTMP_STAT_L ("</stream>\r\n" );
845849 } else {
846- if (codec ) {
850+ if (codec ) {
847851 NGX_RTMP_STAT_L ("," );
848852 }
849853 NGX_RTMP_STAT_L ("\"nclients\":" );
@@ -869,7 +873,7 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
869873 }
870874 }
871875
872- if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
876+ if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
873877 NGX_RTMP_STAT_L ("<nclients>" );
874878 NGX_RTMP_STAT (buf , ngx_snprintf (buf , sizeof (buf ),
875879 "%ui" , total_nclients ) - buf );
@@ -891,7 +895,7 @@ ngx_rtmp_stat_play(ngx_http_request_t *r, ngx_chain_t ***lll,
891895{
892896 ngx_rtmp_play_ctx_t * ctx , * sctx ;
893897 ngx_rtmp_session_t * s ;
894- ngx_uint_t n , nclients , total_nclients ;
898+ ngx_uint_t m , n , nclients , total_nclients ;
895899 u_char buf [NGX_INT_T_LEN ];
896900 u_char bbuf [NGX_INT32_LEN ];
897901 ngx_rtmp_stat_loc_conf_t * slcf ;
@@ -902,7 +906,7 @@ ngx_rtmp_stat_play(ngx_http_request_t *r, ngx_chain_t ***lll,
902906
903907 slcf = ngx_http_get_module_loc_conf (r , ngx_rtmp_stat_module );
904908
905- if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
909+ if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
906910 NGX_RTMP_STAT_L ("<play>\r\n" );
907911 } else {
908912 NGX_RTMP_STAT_L ("\"play\":{" );
@@ -911,14 +915,21 @@ ngx_rtmp_stat_play(ngx_http_request_t *r, ngx_chain_t ***lll,
911915
912916 total_nclients = 0 ;
913917 for (n = 0 ; n < pacf -> nbuckets ; ++ n ) {
918+ m = 0 ;
919+ if (n > 0 && pacf -> ctx [n - 1 ]) {
920+ m = 1 ;
921+ }
914922 for (ctx = pacf -> ctx [n ]; ctx ; ) {
915923
916- if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
924+ if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
917925 NGX_RTMP_STAT_L ("<stream>\r\n" );
918926 NGX_RTMP_STAT_L ("<name>" );
919927 NGX_RTMP_STAT_ECS (ctx -> name );
920928 NGX_RTMP_STAT_L ("</name>\r\n" );
921929 } else {
930+ if (m == 1 || ctx -> next != NULL ) {
931+ NGX_RTMP_STAT_L ("," );
932+ }
922933 NGX_RTMP_STAT_L ("{\"name\":\"" );
923934 NGX_RTMP_STAT_ECS (ctx -> name );
924935 NGX_RTMP_STAT_L ("\",\"clients\":[" );
@@ -936,7 +947,7 @@ ngx_rtmp_stat_play(ngx_http_request_t *r, ngx_chain_t ***lll,
936947
937948 s = ctx -> session ;
938949 if (slcf -> stat & NGX_RTMP_STAT_CLIENTS ) {
939- if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
950+ if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
940951 NGX_RTMP_STAT_L ("<client>" );
941952
942953 ngx_rtmp_stat_client (r , lll , s );
@@ -957,14 +968,11 @@ ngx_rtmp_stat_play(ngx_http_request_t *r, ngx_chain_t ***lll,
957968 "%D" , s -> current_time ) - bbuf );
958969
959970 NGX_RTMP_STAT_L ("}" );
960- if (ctx -> next ) {
961- NGX_RTMP_STAT_L ("," );
962- }
963971 }
964972 }
965973 }
966974 total_nclients += nclients ;
967- if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
975+ if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
968976 NGX_RTMP_STAT_L ("<active/>" );
969977 NGX_RTMP_STAT_L ("<nclients>" );
970978 NGX_RTMP_STAT (buf , ngx_snprintf (buf , sizeof (buf ),
@@ -983,7 +991,7 @@ ngx_rtmp_stat_play(ngx_http_request_t *r, ngx_chain_t ***lll,
983991 }
984992 }
985993
986- if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
994+ if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
987995 NGX_RTMP_STAT_L ("<nclients>" );
988996 NGX_RTMP_STAT (buf , ngx_snprintf (buf , sizeof (buf ),
989997 "%ui" , total_nclients ) - buf );
@@ -1006,7 +1014,7 @@ ngx_rtmp_stat_application(ngx_http_request_t *r, ngx_chain_t ***lll,
10061014
10071015 slcf = ngx_http_get_module_loc_conf (r , ngx_rtmp_stat_module );
10081016
1009- if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
1017+ if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
10101018 NGX_RTMP_STAT_L ("<application>\r\n" );
10111019 NGX_RTMP_STAT_L ("<name>" );
10121020 NGX_RTMP_STAT_ES (& cacf -> name );
@@ -1033,7 +1041,7 @@ ngx_rtmp_stat_application(ngx_http_request_t *r, ngx_chain_t ***lll,
10331041 cacf -> app_conf [ngx_rtmp_play_module .ctx_index ]);
10341042 }
10351043
1036- if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
1044+ if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
10371045 NGX_RTMP_STAT_L ("</application>\r\n" );
10381046 } else {
10391047 NGX_RTMP_STAT_L ("}" );
@@ -1190,19 +1198,19 @@ ngx_rtmp_stat_handler(ngx_http_request_t *r)
11901198 ngx_rtmp_stat_bw (r , lll , & ngx_rtmp_bw_in , "in" , NGX_RTMP_STAT_BW_BYTES );
11911199 ngx_rtmp_stat_bw (r , lll , & ngx_rtmp_bw_out , "out" , NGX_RTMP_STAT_BW_BYTES );
11921200
1193- if (slcf -> format & NGX_RTMP_STAT_FORMAT_JSON ) {
1201+ if (slcf -> format & NGX_RTMP_STAT_FORMAT_JSON ) {
11941202 NGX_RTMP_STAT_L ("\"server\":{" );
11951203 }
11961204
11971205 cscf = cmcf -> servers .elts ;
11981206 for (n = 0 ; n < cmcf -> servers .nelts ; ++ n , ++ cscf ) {
11991207 ngx_rtmp_stat_server (r , lll , * cscf );
1200- if (slcf -> format & NGX_RTMP_STAT_FORMAT_JSON && n < cmcf -> servers .nelts - 1 ) {
1208+ if (slcf -> format & NGX_RTMP_STAT_FORMAT_JSON && n < cmcf -> servers .nelts - 1 ) {
12011209 NGX_RTMP_STAT_L ("," );
12021210 }
12031211 }
12041212
1205- if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
1213+ if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
12061214 NGX_RTMP_STAT_L ("</http-flv>\r\n" );
12071215 } else {
12081216 NGX_RTMP_STAT_L ("}}}" );
@@ -1213,7 +1221,7 @@ ngx_rtmp_stat_handler(ngx_http_request_t *r)
12131221 len += (l -> buf -> last - l -> buf -> pos );
12141222 }
12151223
1216- if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
1224+ if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
12171225 ngx_str_set (& r -> headers_out .content_type , "text/xml" );
12181226 } else {
12191227 ngx_str_set (& r -> headers_out .content_type , "application/json" );
0 commit comments