fixed crash when seeking incomplete remote file: introduced post seek

This commit is contained in:
Roman Arutyunyan 2013-03-20 15:20:08 +04:00
parent 4eca0892a3
commit 5d3189ad97
2 changed files with 23 additions and 1 deletions

View file

@ -490,6 +490,13 @@ ngx_rtmp_play_seek(ngx_rtmp_session_t *s, ngx_rtmp_seek_t *v)
goto next;
}
if (!ctx->opened) {
ctx->post_seek = v->offset;
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
"play: post seek=%ui", ctx->post_seek);
goto next;
}
if (ngx_rtmp_send_stream_eof(s, NGX_RTMP_MSID) != NGX_OK) {
return NGX_ERROR;
}
@ -522,6 +529,12 @@ ngx_rtmp_play_pause(ngx_rtmp_session_t *s, ngx_rtmp_pause_t *v)
goto next;
}
if (!ctx->opened) {
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
"play: pause ignored");
goto next;
}
ngx_log_debug2(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
"play: pause=%i timestamp=%f",
(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)
ctx->file.fd = NGX_INVALID_FILE;
ctx->nentry = NGX_CONF_UNSET_UINT;
ctx->post_seek = NGX_CONF_UNSET_UINT;
sfx = &ctx->fmt->sfx;
@ -780,6 +794,7 @@ ngx_rtmp_play_open(ngx_rtmp_session_t *s, double start)
{
ngx_rtmp_play_ctx_t *ctx;
ngx_event_t *e;
ngx_uint_t timestamp;
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_play_module);
@ -809,7 +824,10 @@ ngx_rtmp_play_open(ngx_rtmp_session_t *s, double start)
return NGX_ERROR;
}
if (ngx_rtmp_play_do_seek(s, start < 0 ? 0 : start) != NGX_OK) {
timestamp = ctx->post_seek != NGX_CONF_UNSET_UINT ? ctx->post_seek :
(start < 0 ? 0 : (ngx_uint_t) start);
if (ngx_rtmp_play_do_seek(s, timestamp) != NGX_OK) {
return NGX_ERROR;
}
@ -817,6 +835,8 @@ ngx_rtmp_play_open(ngx_rtmp_session_t *s, double start)
return NGX_ERROR;
}
ctx->opened = 1;
return NGX_OK;
}

View file

@ -43,6 +43,7 @@ typedef struct {
ngx_rtmp_play_fmt_t *fmt;
ngx_event_t send_evt;
unsigned playing:1;
unsigned opened:1;
ngx_uint_t ncrs;
ngx_uint_t nheader;
ngx_uint_t nbody;
@ -51,6 +52,7 @@ typedef struct {
ngx_uint_t file_id;
ngx_int_t aindex, vindex;
ngx_uint_t nentry;
ngx_uint_t post_seek;
} ngx_rtmp_play_ctx_t;