Skip to content

Commit 2b962b7

Browse files
committed
[fix] fix on_connect and on_play command bugs and server matching bug.
1 parent 213f15f commit 2b962b7

File tree

3 files changed

+61
-25
lines changed

3 files changed

+61
-25
lines changed

ngx_http_flv_live_module.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -953,10 +953,10 @@ ngx_http_flv_live_request(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
953953
ngx_http_flv_live_play_handler(&ctx->play);
954954

955955
if (r->main->blocked == 0) {
956-
r->blocked++;
956+
r->main->blocked++;
957957
}
958958

959-
return NGX_OK;
959+
return ctx->error ? NGX_ERROR : NGX_OK;
960960
}
961961

962962
return ngx_rtmp_play(s, &v);
@@ -1137,14 +1137,18 @@ ngx_http_flv_live_play(ngx_rtmp_session_t *s, ngx_rtmp_play_t *v)
11371137
}
11381138

11391139
r = s->data;
1140-
if (r == NULL || s->wait_notify_play) {
1140+
if (r == NULL) {
11411141
goto next;
11421142
}
11431143

11441144
if (r->main->blocked == 0) {
11451145
r->main->blocked++;
11461146
}
11471147

1148+
if (s->wait_notify_play) {
1149+
goto next;
1150+
}
1151+
11481152
/* join stream as a subscriber */
11491153

11501154
if (ngx_http_flv_live_join(s, v->name, 0) == NGX_ERROR) {
@@ -1297,20 +1301,19 @@ ngx_http_flv_live_play_handler(ngx_event_t *ev)
12971301
ngx_http_flv_live_ctx_t *ctx;
12981302

12991303
c = ev->data;
1300-
r = c->data;
1304+
if (c->destroyed) {
1305+
return;
1306+
}
13011307

1308+
r = c->data;
13021309
ctx = ngx_http_get_module_ctx(r, ngx_http_flv_live_module);
13031310
s = ctx->s;
13041311

1305-
if (c->destroyed) {
1306-
return;
1312+
if (ev->timer_set) {
1313+
ngx_del_timer(ev);
13071314
}
13081315

13091316
if (!s->wait_notify_connect) {
1310-
if (ev->timer_set) {
1311-
ngx_del_timer(ev);
1312-
}
1313-
13141317
ngx_memzero(&v, sizeof(ngx_rtmp_play_t));
13151318

13161319
ngx_memcpy(v.name, ctx->stream.data, ngx_min(ctx->stream.len,
@@ -1329,7 +1332,9 @@ ngx_http_flv_live_play_handler(ngx_event_t *ev)
13291332
r->blocked--;
13301333
}
13311334

1332-
ngx_rtmp_play(s, &v);
1335+
if (ngx_rtmp_play(s, &v) != NGX_OK) {
1336+
ctx->error = 1;
1337+
}
13331338
} else {
13341339
ngx_add_timer(ev, 20);
13351340
}
@@ -1826,6 +1831,13 @@ ngx_http_flv_live_connect_init(ngx_rtmp_session_t *s, ngx_str_t *app,
18261831

18271832
#undef NGX_RTMP_SET_STRPAR
18281833

1834+
if (ngx_rtmp_process_virtual_host(s) != NGX_OK) {
1835+
ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
1836+
"flv live: failed to process virtual host");
1837+
1838+
return NGX_ERROR;
1839+
}
1840+
18291841
s->stream.len = stream->len;
18301842
s->stream.data = ngx_pstrdup(s->connection->pool, stream);
18311843

ngx_http_flv_live_module.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ typedef struct ngx_http_flv_live_ctx_s {
3232
ngx_rtmp_session_t *s;
3333
ngx_flag_t flv_live;
3434
ngx_flag_t header_sent;
35+
ngx_flag_t error;
3536

3637
ngx_str_t app;
3738
ngx_str_t port;

ngx_rtmp_cmd_module.c

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,32 @@ ngx_rtmp_cmd_connect_init(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
176176
return NGX_ERROR;
177177
}
178178

179+
#define NGX_RTMP_SET_STRPAR(name) \
180+
s->name.len = ngx_strlen(v.name); \
181+
s->name.data = ngx_palloc(s->connection->pool, s->name.len); \
182+
ngx_memcpy(s->name.data, v.name, s->name.len)
183+
184+
NGX_RTMP_SET_STRPAR(app);
185+
NGX_RTMP_SET_STRPAR(args);
186+
NGX_RTMP_SET_STRPAR(flashver);
187+
NGX_RTMP_SET_STRPAR(swf_url);
188+
NGX_RTMP_SET_STRPAR(tc_url);
189+
NGX_RTMP_SET_STRPAR(page_url);
190+
191+
#undef NGX_RTMP_SET_STRPAR
192+
193+
if (s->auto_pushed) {
194+
s->host_start = v.server_name;
195+
s->host_end = v.server_name + ngx_strlen(v.server_name);
196+
}
197+
198+
if (ngx_rtmp_process_virtual_host(s) != NGX_OK) {
199+
ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
200+
"connect: failed to process virtual host");
201+
202+
return NGX_ERROR;
203+
}
204+
179205
len = ngx_strlen(v.app);
180206
if (len > 10 && !ngx_memcmp(v.app + len - 10, "/_definst_", 10)) {
181207
v.app[len - 10] = 0;
@@ -265,6 +291,8 @@ ngx_rtmp_cmd_connect(ngx_rtmp_session_t *s, ngx_rtmp_connect_t *v)
265291
return NGX_ERROR;
266292
}
267293

294+
cscf = ngx_rtmp_get_module_srv_conf(s, ngx_rtmp_core_module);
295+
268296
trans = v->trans;
269297

270298
/* fill session parameters */
@@ -276,9 +304,15 @@ ngx_rtmp_cmd_connect(ngx_rtmp_session_t *s, ngx_rtmp_connect_t *v)
276304

277305

278306
#define NGX_RTMP_SET_STRPAR(name) \
279-
s->name.len = ngx_strlen(v->name); \
280-
s->name.data = ngx_palloc(s->connection->pool, s->name.len); \
281-
ngx_memcpy(s->name.data, v->name, s->name.len)
307+
do { \
308+
if (s->name.len != ngx_strlen(v->name) \
309+
|| ngx_strncasecmp(s->name.data, v->name, s->name.len)) \
310+
{ \
311+
s->name.len = ngx_strlen(v->name); \
312+
s->name.data = ngx_palloc(s->connection->pool, s->name.len); \
313+
ngx_memcpy(s->name.data, v->name, s->name.len); \
314+
} \
315+
} while (0)
282316

283317
NGX_RTMP_SET_STRPAR(app);
284318
NGX_RTMP_SET_STRPAR(args);
@@ -289,17 +323,6 @@ ngx_rtmp_cmd_connect(ngx_rtmp_session_t *s, ngx_rtmp_connect_t *v)
289323

290324
#undef NGX_RTMP_SET_STRPAR
291325

292-
if (s->auto_pushed) {
293-
s->host_start = v->server_name;
294-
s->host_end = v->server_name + ngx_strlen(v->server_name);
295-
}
296-
297-
if (ngx_rtmp_process_virtual_host(s) != NGX_OK) {
298-
return NGX_ERROR;
299-
}
300-
301-
cscf = ngx_rtmp_get_module_srv_conf(s, ngx_rtmp_core_module);
302-
303326
p = ngx_strlchr(s->app.data, s->app.data + s->app.len, '?');
304327
if (p) {
305328
s->app.len = (p - s->app.data);

0 commit comments

Comments
 (0)