2
2
/*
3
3
* Copyright (C) Roman Arutyunyan
4
4
* Copyright (C) plainheart
5
+ * Copyright (C) Winshining
5
6
*/
6
7
7
8
@@ -277,7 +278,7 @@ ngx_rtmp_stat_bw(ngx_http_request_t *r, ngx_chain_t ***lll,
277
278
{
278
279
u_char buf [NGX_INT64_LEN + 9 ];
279
280
ngx_rtmp_stat_loc_conf_t * slcf ;
280
-
281
+
281
282
slcf = ngx_http_get_module_loc_conf (r , ngx_rtmp_stat_module );
282
283
283
284
ngx_rtmp_update_bandwidth (bw , 0 );
@@ -350,12 +351,12 @@ ngx_rtmp_stat_dump_pool(ngx_http_request_t *r, ngx_chain_t ***lll,
350
351
ngx_uint_t nlarge , size ;
351
352
u_char buf [NGX_INT_T_LEN ];
352
353
ngx_rtmp_stat_loc_conf_t * slcf ;
353
-
354
- slcf = ngx_http_get_module_loc_conf (r , ngx_rtmp_stat_module );
355
354
356
355
size = 0 ;
357
356
nlarge = 0 ;
358
357
ngx_rtmp_stat_get_pool_size (pool , & nlarge , & size );
358
+
359
+ slcf = ngx_http_get_module_loc_conf (r , ngx_rtmp_stat_module );
359
360
if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
360
361
NGX_RTMP_STAT_L ("<pool><nlarge>" );
361
362
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,
576
577
577
578
nclients = 0 ;
578
579
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
+ {
581
584
NGX_RTMP_STAT_L ("\"clients\":[" );
582
585
}
583
-
586
+
584
587
for (ctx = stream -> ctx ; ctx ; ctx = ctx -> next , ++ nclients ) {
585
588
s = ctx -> session ;
586
589
if (slcf -> stat & NGX_RTMP_STAT_CLIENTS ) {
587
-
590
+
588
591
if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
589
592
NGX_RTMP_STAT_L ("<client>" );
590
593
} else {
591
594
NGX_RTMP_STAT_L ("{" );
592
595
}
593
-
596
+
594
597
ngx_rtmp_stat_client (r , lll , s );
595
-
598
+
596
599
if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
597
600
NGX_RTMP_STAT_L ("<dropped>" );
598
601
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,
649
652
NGX_RTMP_STAT_L ("false" );
650
653
}
651
654
}
652
-
653
655
654
656
if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
655
657
NGX_RTMP_STAT_L ("</client>\r\n" );
@@ -665,11 +667,11 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
665
667
}
666
668
}
667
669
total_nclients += nclients ;
668
-
670
+
669
671
if (slcf -> stat & NGX_RTMP_STAT_CLIENTS && slcf -> format & NGX_RTMP_STAT_FORMAT_JSON ) {
670
672
NGX_RTMP_STAT_L ("]," );
671
673
}
672
-
674
+
673
675
if (codec ) {
674
676
if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
675
677
NGX_RTMP_STAT_L ("<meta>" );
@@ -785,7 +787,6 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
785
787
NGX_RTMP_STAT_L ("\"" );
786
788
}
787
789
788
-
789
790
NGX_RTMP_STAT_L ("},\"audio\": {" );
790
791
cname = ngx_rtmp_get_audio_codec_name (codec -> audio_codec_id );
791
792
f = 0 ;
@@ -831,7 +832,7 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
831
832
NGX_RTMP_STAT_L ("}" );
832
833
}
833
834
}
834
-
835
+
835
836
if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
836
837
NGX_RTMP_STAT_L ("<nclients>" );
837
838
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,
873
874
}
874
875
}
875
876
}
876
-
877
+
877
878
if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
878
879
NGX_RTMP_STAT_L ("<nclients>" );
879
880
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,
886
887
"%ui" , total_nclients ) - buf );
887
888
NGX_RTMP_STAT_L ("}" );
888
889
}
889
-
890
890
}
891
891
892
892
@@ -968,7 +968,7 @@ ngx_rtmp_stat_play(ngx_http_request_t *r, ngx_chain_t ***lll,
968
968
NGX_RTMP_STAT_L ("\"timestamp\":" );
969
969
NGX_RTMP_STAT (bbuf , ngx_snprintf (bbuf , sizeof (bbuf ),
970
970
"%D" , s -> current_time ) - bbuf );
971
-
971
+
972
972
NGX_RTMP_STAT_L ("}" );
973
973
}
974
974
}
@@ -1013,9 +1013,9 @@ ngx_rtmp_stat_application(ngx_http_request_t *r, ngx_chain_t ***lll,
1013
1013
ngx_rtmp_core_app_conf_t * cacf )
1014
1014
{
1015
1015
ngx_rtmp_stat_loc_conf_t * slcf ;
1016
-
1016
+
1017
1017
slcf = ngx_http_get_module_loc_conf (r , ngx_rtmp_stat_module );
1018
-
1018
+
1019
1019
if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
1020
1020
NGX_RTMP_STAT_L ("<application>\r\n" );
1021
1021
NGX_RTMP_STAT_L ("<name>" );
@@ -1058,9 +1058,9 @@ ngx_rtmp_stat_server(ngx_http_request_t *r, ngx_chain_t ***lll,
1058
1058
ngx_rtmp_core_app_conf_t * * cacf ;
1059
1059
size_t n ;
1060
1060
ngx_rtmp_stat_loc_conf_t * slcf ;
1061
-
1061
+
1062
1062
slcf = ngx_http_get_module_loc_conf (r , ngx_rtmp_stat_module );
1063
-
1063
+
1064
1064
if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
1065
1065
NGX_RTMP_STAT_L ("<server>\r\n" );
1066
1066
}
@@ -1073,22 +1073,24 @@ ngx_rtmp_stat_server(ngx_http_request_t *r, ngx_chain_t ***lll,
1073
1073
#endif
1074
1074
1075
1075
if (slcf -> format & NGX_RTMP_STAT_FORMAT_JSON ) {
1076
- NGX_RTMP_STAT_L ("\"applications\":[" );
1076
+ NGX_RTMP_STAT_L ("{ \"applications\":[" );
1077
1077
}
1078
-
1078
+
1079
1079
cacf = cscf -> applications .elts ;
1080
1080
for (n = 0 ; n < cscf -> applications .nelts ; ++ n , ++ cacf ) {
1081
1081
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
+ {
1084
1086
NGX_RTMP_STAT_L ("," );
1085
1087
}
1086
1088
}
1087
-
1089
+
1088
1090
if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
1089
1091
NGX_RTMP_STAT_L ("</server>\r\n" );
1090
1092
} else {
1091
- NGX_RTMP_STAT_L ("]" );
1093
+ NGX_RTMP_STAT_L ("]} " );
1092
1094
}
1093
1095
}
1094
1096
@@ -1106,11 +1108,10 @@ ngx_rtmp_stat_handler(ngx_http_request_t *r)
1106
1108
static u_char nbuf [NGX_INT_T_LEN ];
1107
1109
1108
1110
slcf = ngx_http_get_module_loc_conf (r , ngx_rtmp_stat_module );
1109
-
1110
1111
if (slcf -> stat == 0 ) {
1111
1112
return NGX_DECLINED ;
1112
1113
}
1113
-
1114
+
1114
1115
if (slcf -> format == 0 ) {
1115
1116
slcf -> format = NGX_RTMP_STAT_FORMAT_XML ;
1116
1117
}
@@ -1123,7 +1124,7 @@ ngx_rtmp_stat_handler(ngx_http_request_t *r)
1123
1124
cl = NULL ;
1124
1125
ll = & cl ;
1125
1126
lll = & ll ;
1126
-
1127
+
1127
1128
if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
1128
1129
NGX_RTMP_STAT_L ("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n" );
1129
1130
if (slcf -> stylesheet .len ) {
@@ -1201,7 +1202,7 @@ ngx_rtmp_stat_handler(ngx_http_request_t *r)
1201
1202
ngx_rtmp_stat_bw (r , lll , & ngx_rtmp_bw_out , "out" , NGX_RTMP_STAT_BW_BYTES );
1202
1203
1203
1204
if (slcf -> format & NGX_RTMP_STAT_FORMAT_JSON ) {
1204
- NGX_RTMP_STAT_L ("\"server \":{ " );
1205
+ NGX_RTMP_STAT_L ("\"servers \":[ " );
1205
1206
}
1206
1207
1207
1208
cscf = cmcf -> servers .elts ;
@@ -1211,18 +1212,18 @@ ngx_rtmp_stat_handler(ngx_http_request_t *r)
1211
1212
NGX_RTMP_STAT_L ("," );
1212
1213
}
1213
1214
}
1214
-
1215
+
1215
1216
if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
1216
1217
NGX_RTMP_STAT_L ("</http-flv>\r\n" );
1217
1218
} else {
1218
- NGX_RTMP_STAT_L ("} }}" );
1219
+ NGX_RTMP_STAT_L ("] }}" );
1219
1220
}
1220
-
1221
+
1221
1222
len = 0 ;
1222
1223
for (l = cl ; l ; l = l -> next ) {
1223
1224
len += (l -> buf -> last - l -> buf -> pos );
1224
1225
}
1225
-
1226
+
1226
1227
if (slcf -> format & NGX_RTMP_STAT_FORMAT_XML ) {
1227
1228
ngx_str_set (& r -> headers_out .content_type , "text/xml" );
1228
1229
} else {
0 commit comments