Skip to content

Commit 6bb620f

Browse files
committed
added audio and video bw to stat
1 parent da0128a commit 6bb620f

5 files changed

+72
-36
lines changed

ngx_rtmp_bandwidth.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
/* Bandwidth update interval in seconds */
16-
#define NGX_RTMP_BANDWIDTH_INTERVAL 60
16+
#define NGX_RTMP_BANDWIDTH_INTERVAL 10
1717

1818

1919
typedef struct {

ngx_rtmp_live_module.c

+5
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,11 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
10281028
ngx_rtmp_update_bandwidth(&ctx->stream->bw_in, h->mlen);
10291029
ngx_rtmp_update_bandwidth(&ctx->stream->bw_out, h->mlen * peers);
10301030

1031+
ngx_rtmp_update_bandwidth(h->type == NGX_RTMP_MSG_AUDIO ?
1032+
&ctx->stream->bw_in_audio :
1033+
&ctx->stream->bw_in_video,
1034+
h->mlen);
1035+
10311036
return NGX_OK;
10321037
}
10331038

ngx_rtmp_live_module.h

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ struct ngx_rtmp_live_stream_s {
4848
ngx_rtmp_live_stream_t *next;
4949
ngx_rtmp_live_ctx_t *ctx;
5050
ngx_rtmp_bandwidth_t bw_in;
51+
ngx_rtmp_bandwidth_t bw_in_audio;
52+
ngx_rtmp_bandwidth_t bw_in_video;
5153
ngx_rtmp_bandwidth_t bw_out;
5254
ngx_msec_t epoch;
5355
unsigned active:1;

ngx_rtmp_stat_module.c

+36-23
Original file line numberDiff line numberDiff line change
@@ -245,34 +245,39 @@ ngx_rtmp_stat_output(ngx_http_request_t *r, ngx_chain_t ***lll,
245245
#define NGX_RTMP_STAT_ECS(s) NGX_RTMP_STAT_E((s), ngx_strlen(s))
246246

247247

248+
#define NGX_RTMP_STAT_BW 0x01
249+
#define NGX_RTMP_STAT_BYTES 0x02
250+
#define NGX_RTMP_STAT_BW_BYTES 0x03
251+
252+
248253
static void
249254
ngx_rtmp_stat_bw(ngx_http_request_t *r, ngx_chain_t ***lll,
250-
ngx_rtmp_bandwidth_t *bw_in, ngx_rtmp_bandwidth_t *bw_out)
255+
ngx_rtmp_bandwidth_t *bw, char *name,
256+
ngx_uint_t flags)
251257
{
252258
u_char buf[NGX_INT64_LEN + 1];
253259

254-
ngx_rtmp_update_bandwidth(bw_in, 0);
255-
ngx_rtmp_update_bandwidth(bw_out, 0);
256-
257-
NGX_RTMP_STAT_L("<in>");
258-
NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf),
259-
"%uL", bw_in->bytes) - buf);
260-
NGX_RTMP_STAT_L("</in>\r\n");
261-
262-
NGX_RTMP_STAT_L("<out>");
263-
NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf),
264-
"%uL", bw_out->bytes) - buf);
265-
NGX_RTMP_STAT_L("</out>\r\n");
260+
ngx_rtmp_update_bandwidth(bw, 0);
266261

267-
NGX_RTMP_STAT_L("<bwin>");
268-
NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf),
269-
"%uL", bw_in->bandwidth * 8) - buf);
270-
NGX_RTMP_STAT_L("</bwin>\r\n");
262+
if (flags & NGX_RTMP_STAT_BW) {
263+
NGX_RTMP_STAT_L("<bw_");
264+
NGX_RTMP_STAT_CS(name);
265+
NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf), ">%uL</bw_",
266+
bw->bandwidth * 8)
267+
- buf);
268+
NGX_RTMP_STAT_CS(name);
269+
NGX_RTMP_STAT_L(">\r\n");
270+
}
271271

272-
NGX_RTMP_STAT_L("<bwout>");
273-
NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf),
274-
"%uL", bw_out->bandwidth * 8) - buf);
275-
NGX_RTMP_STAT_L("</bwout>\r\n");
272+
if (flags & NGX_RTMP_STAT_BYTES) {
273+
NGX_RTMP_STAT_L("<bytes_");
274+
NGX_RTMP_STAT_CS(name);
275+
NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf), ">%uL</bytes_",
276+
bw->bytes)
277+
- buf);
278+
NGX_RTMP_STAT_CS(name);
279+
NGX_RTMP_STAT_L(">\r\n");
280+
}
276281
}
277282

278283

@@ -440,7 +445,14 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
440445
- buf);
441446
NGX_RTMP_STAT_L("</time>");
442447

443-
ngx_rtmp_stat_bw(r, lll, &stream->bw_in, &stream->bw_out);
448+
ngx_rtmp_stat_bw(r, lll, &stream->bw_in, "in",
449+
NGX_RTMP_STAT_BW_BYTES);
450+
ngx_rtmp_stat_bw(r, lll, &stream->bw_out, "out",
451+
NGX_RTMP_STAT_BW_BYTES);
452+
ngx_rtmp_stat_bw(r, lll, &stream->bw_in_audio, "audio",
453+
NGX_RTMP_STAT_BW);
454+
ngx_rtmp_stat_bw(r, lll, &stream->bw_in_video, "video",
455+
NGX_RTMP_STAT_BW);
444456

445457
nclients = 0;
446458
codec = NULL;
@@ -773,7 +785,8 @@ ngx_rtmp_stat_handler(ngx_http_request_t *r)
773785
"%ui", ngx_rtmp_naccepted) - nbuf);
774786
NGX_RTMP_STAT_L("</naccepted>\r\n");
775787

776-
ngx_rtmp_stat_bw(r, lll, &ngx_rtmp_bw_in, &ngx_rtmp_bw_out);
788+
ngx_rtmp_stat_bw(r, lll, &ngx_rtmp_bw_in, "in", NGX_RTMP_STAT_BW_BYTES);
789+
ngx_rtmp_stat_bw(r, lll, &ngx_rtmp_bw_out, "out", NGX_RTMP_STAT_BW_BYTES);
777790

778791
cscf = cmcf->servers.elts;
779792
for (n = 0; n < cmcf->servers.nelts; ++n, ++cscf) {

stat.xsl

+28-12
Original file line numberDiff line numberDiff line change
@@ -33,43 +33,45 @@
3333
<th>#clients</th>
3434
<th>In bytes</th>
3535
<th>Out bytes</th>
36-
<th>Input bits/s</th>
37-
<th>Output bits/s</th>
38-
<th colspan="3">Video</th>
39-
<th colspan="3">Audio</th>
36+
<th>In bits/s</th>
37+
<th>Out bits/s</th>
38+
<th colspan="4">Video</th>
39+
<th colspan="4">Audio</th>
4040
<th>State</th>
4141
<th>Time</th>
4242
</tr>
4343
<tr>
4444
<td colspan="2">Accepted: <xsl:value-of select="naccepted"/></td>
4545
<td>
4646
<xsl:call-template name="showsize">
47-
<xsl:with-param name="size" select="in"/>
47+
<xsl:with-param name="size" select="bytes_in"/>
4848
</xsl:call-template>
4949
</td>
5050
<td>
5151
<xsl:call-template name="showsize">
52-
<xsl:with-param name="size" select="out"/>
52+
<xsl:with-param name="size" select="bytes_out"/>
5353
</xsl:call-template>
5454
</td>
5555
<td>
5656
<xsl:call-template name="showsize">
57-
<xsl:with-param name="size" select="bwin"/>
57+
<xsl:with-param name="size" select="bw_in"/>
5858
<xsl:with-param name="bits" select="1"/>
5959
<xsl:with-param name="persec" select="1"/>
6060
</xsl:call-template>
6161
</td>
6262
<td>
6363
<xsl:call-template name="showsize">
64-
<xsl:with-param name="size" select="bwout"/>
64+
<xsl:with-param name="size" select="bw_out"/>
6565
<xsl:with-param name="bits" select="1"/>
6666
<xsl:with-param name="persec" select="1"/>
6767
</xsl:call-template>
6868
</td>
6969
<th bgcolor="#999999">codec</th>
70+
<th bgcolor="#999999">bits/s</th>
7071
<th bgcolor="#999999">size</th>
7172
<th bgcolor="#999999">fps</th>
7273
<th bgcolor="#999999">codec</th>
74+
<th bgcolor="#999999">bits/s</th>
7375
<th bgcolor="#999999">freq</th>
7476
<th bgcolor="#999999">chan</th>
7577
<td/>
@@ -145,31 +147,38 @@
145147
<td align="middle"> <xsl:value-of select="nclients"/> </td>
146148
<td>
147149
<xsl:call-template name="showsize">
148-
<xsl:with-param name="size" select="in"/>
150+
<xsl:with-param name="size" select="bytes_in"/>
149151
</xsl:call-template>
150152
</td>
151153
<td>
152154
<xsl:call-template name="showsize">
153-
<xsl:with-param name="size" select="out"/>
155+
<xsl:with-param name="size" select="bytes_out"/>
154156
</xsl:call-template>
155157
</td>
156158
<td>
157159
<xsl:call-template name="showsize">
158-
<xsl:with-param name="size" select="bwin"/>
160+
<xsl:with-param name="size" select="bw_in"/>
159161
<xsl:with-param name="bits" select="1"/>
160162
<xsl:with-param name="persec" select="1"/>
161163
</xsl:call-template>
162164
</td>
163165
<td>
164166
<xsl:call-template name="showsize">
165-
<xsl:with-param name="size" select="bwout"/>
167+
<xsl:with-param name="size" select="bw_out"/>
166168
<xsl:with-param name="bits" select="1"/>
167169
<xsl:with-param name="persec" select="1"/>
168170
</xsl:call-template>
169171
</td>
170172
<td>
171173
<xsl:value-of select="meta/video/codec"/>&#160;<xsl:value-of select="meta/video/profile"/>&#160;<xsl:value-of select="meta/video/level"/>
172174
</td>
175+
<td>
176+
<xsl:call-template name="showsize">
177+
<xsl:with-param name="size" select="bw_video"/>
178+
<xsl:with-param name="bits" select="1"/>
179+
<xsl:with-param name="persec" select="1"/>
180+
</xsl:call-template>
181+
</td>
173182
<td>
174183
<xsl:apply-templates select="meta/video/width"/>
175184
</td>
@@ -179,6 +188,13 @@
179188
<td>
180189
<xsl:value-of select="meta/audio/codec"/>&#160;<xsl:value-of select="meta/audio/profile"/>
181190
</td>
191+
<td>
192+
<xsl:call-template name="showsize">
193+
<xsl:with-param name="size" select="bw_audio"/>
194+
<xsl:with-param name="bits" select="1"/>
195+
<xsl:with-param name="persec" select="1"/>
196+
</xsl:call-template>
197+
</td>
182198
<td>
183199
<xsl:apply-templates select="meta/audio/sample_rate"/>
184200
</td>

0 commit comments

Comments
 (0)