Skip to content

Commit 5d3189a

Browse files
committed
fixed crash when seeking incomplete remote file: introduced post seek
1 parent 4eca089 commit 5d3189a

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

ngx_rtmp_play_module.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,13 @@ ngx_rtmp_play_seek(ngx_rtmp_session_t *s, ngx_rtmp_seek_t *v)
490490
goto next;
491491
}
492492

493+
if (!ctx->opened) {
494+
ctx->post_seek = v->offset;
495+
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
496+
"play: post seek=%ui", ctx->post_seek);
497+
goto next;
498+
}
499+
493500
if (ngx_rtmp_send_stream_eof(s, NGX_RTMP_MSID) != NGX_OK) {
494501
return NGX_ERROR;
495502
}
@@ -522,6 +529,12 @@ ngx_rtmp_play_pause(ngx_rtmp_session_t *s, ngx_rtmp_pause_t *v)
522529
goto next;
523530
}
524531

532+
if (!ctx->opened) {
533+
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
534+
"play: pause ignored");
535+
goto next;
536+
}
537+
525538
ngx_log_debug2(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
526539
"play: pause=%i timestamp=%f",
527540
(ngx_int_t) v->pause, v->position);
@@ -676,6 +689,7 @@ ngx_rtmp_play_play(ngx_rtmp_session_t *s, ngx_rtmp_play_t *v)
676689

677690
ctx->file.fd = NGX_INVALID_FILE;
678691
ctx->nentry = NGX_CONF_UNSET_UINT;
692+
ctx->post_seek = NGX_CONF_UNSET_UINT;
679693

680694
sfx = &ctx->fmt->sfx;
681695

@@ -780,6 +794,7 @@ ngx_rtmp_play_open(ngx_rtmp_session_t *s, double start)
780794
{
781795
ngx_rtmp_play_ctx_t *ctx;
782796
ngx_event_t *e;
797+
ngx_uint_t timestamp;
783798

784799
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_play_module);
785800

@@ -809,14 +824,19 @@ ngx_rtmp_play_open(ngx_rtmp_session_t *s, double start)
809824
return NGX_ERROR;
810825
}
811826

812-
if (ngx_rtmp_play_do_seek(s, start < 0 ? 0 : start) != NGX_OK) {
827+
timestamp = ctx->post_seek != NGX_CONF_UNSET_UINT ? ctx->post_seek :
828+
(start < 0 ? 0 : (ngx_uint_t) start);
829+
830+
if (ngx_rtmp_play_do_seek(s, timestamp) != NGX_OK) {
813831
return NGX_ERROR;
814832
}
815833

816834
if (ngx_rtmp_play_do_start(s) != NGX_OK) {
817835
return NGX_ERROR;
818836
}
819837

838+
ctx->opened = 1;
839+
820840
return NGX_OK;
821841
}
822842

ngx_rtmp_play_module.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ typedef struct {
4343
ngx_rtmp_play_fmt_t *fmt;
4444
ngx_event_t send_evt;
4545
unsigned playing:1;
46+
unsigned opened:1;
4647
ngx_uint_t ncrs;
4748
ngx_uint_t nheader;
4849
ngx_uint_t nbody;
@@ -51,6 +52,7 @@ typedef struct {
5152
ngx_uint_t file_id;
5253
ngx_int_t aindex, vindex;
5354
ngx_uint_t nentry;
55+
ngx_uint_t post_seek;
5456
} ngx_rtmp_play_ctx_t;
5557

5658

0 commit comments

Comments
 (0)