Skip to content

Commit fd4c752

Browse files
committed
[fix] fix a bug that play with flv.js after push will fail.
1 parent b81b82c commit fd4c752

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

ngx_http_flv_live_module.c

+14-17
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ ngx_http_flv_live_send_header(ngx_rtmp_session_t *s)
351351
ngx_str_t chunked_flv_header;
352352
ngx_str_t consec_flv_header;
353353
u_char chunked_flv_header_data[18];
354+
ngx_flag_t connection_header;
354355

355356
/**
356357
* |F|L|V|ver|00000101|header_size|0|0|0|0|, ngx_http_flv_module.c
@@ -365,6 +366,9 @@ ngx_http_flv_live_send_header(ngx_rtmp_session_t *s)
365366
ngx_str_set(&r->headers_out.content_type, "video/x-flv");
366367

367368
/* fill HTTP header 'Connection' according to headers_in */
369+
r->keepalive = 0;
370+
371+
connection_header = 0;
368372
part = &r->headers_in.headers.part;
369373
header = part->elts;
370374

@@ -384,18 +388,21 @@ ngx_http_flv_live_send_header(ngx_rtmp_session_t *s)
384388
}
385389

386390
if (ngx_strcasecmp(header[i].key.data, (u_char *) "connection") == 0) {
391+
connection_header = 1;
387392
if (ngx_strcasecmp(header[i].value.data, (u_char *) "keep-alive")
388393
== 0)
389394
{
390395
r->keepalive = 1;
391-
} else {
392-
r->keepalive = 0;
393396
}
394397

395398
break;
396399
}
397400
}
398401

402+
if (!connection_header && r->http_version == NGX_HTTP_VERSION_11) {
403+
r->keepalive = 1;
404+
}
405+
399406
live_ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_live_module);
400407
if (live_ctx && !live_ctx->active) {
401408
ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
@@ -991,9 +998,7 @@ ngx_http_flv_live_request(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
991998

992999
ngx_http_flv_live_play_handler(&ctx->play);
9931000

994-
if (r->main->blocked == 0) {
995-
r->main->blocked++;
996-
}
1001+
r->main->count++;
9971002

9981003
return ctx->error ? NGX_ERROR : NGX_OK;
9991004
}
@@ -1171,9 +1176,7 @@ ngx_http_flv_live_play(ngx_rtmp_session_t *s, ngx_rtmp_play_t *v)
11711176
goto next;
11721177
}
11731178

1174-
if (r->main->blocked == 0) {
1175-
r->main->blocked++;
1176-
}
1179+
r->main->count++;
11771180

11781181
#if (nginx_version >= 1013001)
11791182
/**
@@ -1194,9 +1197,7 @@ ngx_http_flv_live_play(ngx_rtmp_session_t *s, ngx_rtmp_play_t *v)
11941197
/* join stream as a subscriber */
11951198

11961199
if (ngx_http_flv_live_join(s, v->name, 0) == NGX_ERROR) {
1197-
if (r->main->blocked) {
1198-
r->main->blocked--;
1199-
}
1200+
r->main->count--;
12001201

12011202
return NGX_ERROR;
12021203
}
@@ -1224,9 +1225,7 @@ ngx_http_flv_live_close_http_request(ngx_rtmp_session_t *s)
12241225

12251226
r = s->data;
12261227
if (r && r->connection && !r->connection->destroyed) {
1227-
if (r->main->blocked) {
1228-
r->main->blocked--;
1229-
}
1228+
r->main->count--;
12301229

12311230
if (r->chunked) {
12321231
ngx_http_flv_live_send_tail(s);
@@ -1370,9 +1369,7 @@ ngx_http_flv_live_play_handler(ngx_event_t *ev)
13701369
(ngx_int_t) v.duration, (ngx_int_t) v.reset,
13711370
(ngx_int_t) v.silent);
13721371

1373-
if (r->main->blocked) {
1374-
r->blocked--;
1375-
}
1372+
r->main->count--;
13761373

13771374
if (ngx_rtmp_play(s, &v) != NGX_OK) {
13781375
ctx->error = 1;

ngx_rtmp_live_module.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -1494,9 +1494,7 @@ ngx_rtmp_live_play(ngx_rtmp_session_t *s, ngx_rtmp_play_t *v)
14941494
if (r) {
14951495
if (s->wait_notify_play) {
14961496
if (ngx_http_flv_live_join(s, v->name, 0) == NGX_ERROR) {
1497-
if (r->main->blocked) {
1498-
r->main->blocked--;
1499-
}
1497+
r->main->count--;
15001498

15011499
return NGX_ERROR;
15021500
}

0 commit comments

Comments
 (0)