Skip to content

Commit 00a8548

Browse files
committed
[fix] fix compatibility bug when Nginx version >= 1.13.1.
1 parent 85bb7bf commit 00a8548

File tree

2 files changed

+54
-9
lines changed

2 files changed

+54
-9
lines changed

ngx_http_flv_live_module.c

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,12 @@ ngx_http_flv_live_send_header(ngx_rtmp_session_t *s)
340340
ngx_http_request_t *r;
341341
ngx_rtmp_live_ctx_t *live_ctx;
342342
ngx_rtmp_codec_ctx_t *codec_ctx;
343-
ngx_table_elt_t *e;
343+
ngx_list_part_t *part;
344+
ngx_table_elt_t *e, *header;
344345
u_char *p;
345346
ngx_chain_t cl_flv_hdr, *pkt;
346347
ngx_buf_t buf_flv_hdr;
348+
ngx_uint_t i;
347349
ngx_str_t chunked_flv_header;
348350
ngx_str_t consec_flv_header;
349351
u_char chunked_flv_header_data[18];
@@ -360,8 +362,37 @@ ngx_http_flv_live_send_header(ngx_rtmp_session_t *s)
360362

361363
ngx_str_set(&r->headers_out.content_type, "video/x-flv");
362364

363-
/* force HTTP header Connection to be close */
364-
r->keepalive = 0;
365+
/* fill HTTP header 'Connection' according to headers_in */
366+
part = &r->headers_in.headers.part;
367+
header = part->elts;
368+
369+
for (i = 0; /* void */; i++) {
370+
if (i >= part->nelts) {
371+
if (part->next == NULL) {
372+
break;
373+
}
374+
375+
part = part->next;
376+
header = part->elts;
377+
i = 0;
378+
}
379+
380+
if (header[i].hash == 0) {
381+
continue;
382+
}
383+
384+
if (ngx_strcasecmp(header[i].key.data, (u_char *) "connection") == 0) {
385+
if (ngx_strcasecmp(header[i].value.data, (u_char *) "keep-alive")
386+
== 0)
387+
{
388+
r->keepalive = 1;
389+
} else {
390+
r->keepalive = 0;
391+
}
392+
393+
break;
394+
}
395+
}
365396

366397
live_ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_live_module);
367398
if (live_ctx && !live_ctx->active) {
@@ -1129,6 +1160,18 @@ ngx_http_flv_live_play(ngx_rtmp_session_t *s, ngx_rtmp_play_t *v)
11291160
r->main->blocked++;
11301161
}
11311162

1163+
#if (nginx_version >= 1013001)
1164+
/**
1165+
* when playing from pull, the downstream requests on the most
1166+
* of time return before the upstream requests, flv.js always
1167+
* sends HTTP header 'Connection: keep-alive', but Nginx has
1168+
* deleted r->blocked in ngx_http_finalize_request, that causes
1169+
* ngx_http_set_keepalive to run the cleanup handlers to close
1170+
* the connection between downstream and server, so play fails
1171+
**/
1172+
r->keepalive = 0;
1173+
#endif
1174+
11321175
if (s->wait_notify_play) {
11331176
goto next;
11341177
}

ngx_rtmp_live_module.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,16 +1492,18 @@ ngx_rtmp_live_play(ngx_rtmp_session_t *s, ngx_rtmp_play_t *v)
14921492
/* request from http */
14931493
r = s->data;
14941494
if (r) {
1495-
if (ngx_http_flv_live_join(s, v->name, 0) == NGX_ERROR) {
1496-
if (r->main->blocked) {
1497-
r->main->blocked--;
1495+
if (s->wait_notify_play) {
1496+
if (ngx_http_flv_live_join(s, v->name, 0) == NGX_ERROR) {
1497+
if (r->main->blocked) {
1498+
r->main->blocked--;
1499+
}
1500+
1501+
return NGX_ERROR;
14981502
}
14991503

1500-
return NGX_ERROR;
1504+
s->wait_notify_play = 0;
15011505
}
15021506

1503-
s->wait_notify_play = 0;
1504-
15051507
goto next;
15061508
}
15071509
}

0 commit comments

Comments
 (0)