Skip to content

Commit 6cf9f9a

Browse files
committed
[dev] optimize the last PR and force the stream name to be specified in pub and sub.
1 parent 091e935 commit 6cf9f9a

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

ngx_rtmp_cmd_module.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,13 @@ ngx_rtmp_cmd_publish_init(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
539539

540540
ngx_rtmp_cmd_fill_args(v.name, v.args);
541541

542+
if (ngx_strlen(v.name) == 0) {
543+
ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
544+
"publish: no stream name specified");
545+
546+
return NGX_ERROR;
547+
}
548+
542549
if (ngx_rtmp_process_request_line(s, v.name, v.args,
543550
(const u_char *) "publish") != NGX_OK)
544551
{
@@ -603,6 +610,13 @@ ngx_rtmp_cmd_play_init(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
603610

604611
ngx_rtmp_cmd_fill_args(v.name, v.args);
605612

613+
if (ngx_strlen(v.name) == 0) {
614+
ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
615+
"play: no stream name specified");
616+
617+
return NGX_ERROR;
618+
}
619+
606620
if (ngx_rtmp_process_request_line(s, v.name, v.args,
607621
(const u_char *) "play") != NGX_OK)
608622
{
@@ -671,6 +685,13 @@ ngx_rtmp_cmd_play2_init(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
671685

672686
ngx_rtmp_cmd_fill_args(v.name, v.args);
673687

688+
if (ngx_strlen(v.name) == 0) {
689+
ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
690+
"play2: no stream name specified");
691+
692+
return NGX_ERROR;
693+
}
694+
674695
ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
675696
"play2: name='%s' args='%s' start=%i",
676697
v.name, v.args, (ngx_int_t) v.start);

ngx_rtmp_stat_module.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,9 @@ 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;
508507
ngx_uint_t nclients, total_nclients;
509508
ngx_uint_t f;
509+
ngx_flag_t prev;
510510
u_char buf[NGX_INT_T_LEN];
511511
u_char bbuf[NGX_INT32_LEN];
512512
ngx_rtmp_stat_loc_conf_t *slcf;
@@ -527,18 +527,19 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
527527

528528
total_nclients = 0;
529529
for (n = 0; n < lacf->nbuckets; ++n) {
530-
m = 0;
531-
if (n > 0 && lacf->streams[n - 1]) {
532-
m = 1;
530+
prev = 0;
531+
if (n && lacf->streams[n - 1]) {
532+
prev = 1;
533533
}
534+
534535
for (stream = lacf->streams[n]; stream; stream = stream->next) {
535-
536536
if (slcf->format & NGX_RTMP_STAT_FORMAT_XML) {
537537
NGX_RTMP_STAT_L("<stream>\r\n");
538538
} else {
539-
if (m == 1 || stream->next != NULL) {
539+
if (prev || stream->next) {
540540
NGX_RTMP_STAT_L(",");
541541
}
542+
542543
NGX_RTMP_STAT_L("{");
543544
}
544545

@@ -895,7 +896,8 @@ ngx_rtmp_stat_play(ngx_http_request_t *r, ngx_chain_t ***lll,
895896
{
896897
ngx_rtmp_play_ctx_t *ctx, *sctx;
897898
ngx_rtmp_session_t *s;
898-
ngx_uint_t m, n, nclients, total_nclients;
899+
ngx_uint_t n, nclients, total_nclients;
900+
ngx_flag_t prev;
899901
u_char buf[NGX_INT_T_LEN];
900902
u_char bbuf[NGX_INT32_LEN];
901903
ngx_rtmp_stat_loc_conf_t *slcf;
@@ -915,21 +917,22 @@ ngx_rtmp_stat_play(ngx_http_request_t *r, ngx_chain_t ***lll,
915917

916918
total_nclients = 0;
917919
for (n = 0; n < pacf->nbuckets; ++n) {
918-
m = 0;
919-
if (n > 0 && pacf->ctx[n - 1]) {
920-
m = 1;
920+
prev = 0;
921+
if (n && pacf->ctx[n - 1]) {
922+
prev = 1;
921923
}
924+
922925
for (ctx = pacf->ctx[n]; ctx; ) {
923-
924926
if (slcf->format & NGX_RTMP_STAT_FORMAT_XML) {
925927
NGX_RTMP_STAT_L("<stream>\r\n");
926928
NGX_RTMP_STAT_L("<name>");
927929
NGX_RTMP_STAT_ECS(ctx->name);
928930
NGX_RTMP_STAT_L("</name>\r\n");
929931
} else {
930-
if (m == 1 || ctx->next != NULL) {
932+
if (prev || ctx->next) {
931933
NGX_RTMP_STAT_L(",");
932934
}
935+
933936
NGX_RTMP_STAT_L("{\"name\":\"");
934937
NGX_RTMP_STAT_ECS(ctx->name);
935938
NGX_RTMP_STAT_L("\",\"clients\":[");
@@ -938,7 +941,6 @@ ngx_rtmp_stat_play(ngx_http_request_t *r, ngx_chain_t ***lll,
938941
nclients = 0;
939942
sctx = ctx;
940943
for (; ctx; ctx = ctx->next) {
941-
942944
if (ngx_strcmp(ctx->name, sctx->name)) {
943945
break;
944946
}

0 commit comments

Comments
 (0)