Commit 7277a4ac authored by Michael Niedermayer's avatar Michael Niedermayer

avformat/http: add reconnect_delay_max option

Signed-off-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
parent a450ec26
...@@ -267,6 +267,9 @@ for live / endless streams. ...@@ -267,6 +267,9 @@ for live / endless streams.
@item reconnect_streamed @item reconnect_streamed
If set then even streamed/non seekable streams will be reconnected on errors. If set then even streamed/non seekable streams will be reconnected on errors.
@item reconnect_delay_max
Sets the maximum delay in seconds after which to give up reconnecting
@item mime_type @item mime_type
Export the MIME type. Export the MIME type.
......
...@@ -109,6 +109,7 @@ typedef struct HTTPContext { ...@@ -109,6 +109,7 @@ typedef struct HTTPContext {
int reconnect_at_eof; int reconnect_at_eof;
int reconnect_streamed; int reconnect_streamed;
int reconnect_delay; int reconnect_delay;
int reconnect_delay_max;
int listen; int listen;
char *resource; char *resource;
int reply_code; int reply_code;
...@@ -148,6 +149,7 @@ static const AVOption options[] = { ...@@ -148,6 +149,7 @@ static const AVOption options[] = {
{ "reconnect", "auto reconnect after disconnect before EOF", OFFSET(reconnect), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, D }, { "reconnect", "auto reconnect after disconnect before EOF", OFFSET(reconnect), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, D },
{ "reconnect_at_eof", "auto reconnect at EOF", OFFSET(reconnect_at_eof), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, D }, { "reconnect_at_eof", "auto reconnect at EOF", OFFSET(reconnect_at_eof), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, D },
{ "reconnect_streamed", "auto reconnect streamed / non seekable streams", OFFSET(reconnect_streamed), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, D }, { "reconnect_streamed", "auto reconnect streamed / non seekable streams", OFFSET(reconnect_streamed), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, D },
{ "reconnect_delay_max", "max reconnect delay in seconds after which to give up", OFFSET(reconnect_delay_max), AV_OPT_TYPE_INT, { .i64 = 120 }, 0, UINT_MAX/1000/1000, D },
{ "listen", "listen on HTTP", OFFSET(listen), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 2, D | E }, { "listen", "listen on HTTP", OFFSET(listen), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 2, D | E },
{ "resource", "The resource requested by a client", OFFSET(resource), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E }, { "resource", "The resource requested by a client", OFFSET(resource), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E },
{ "reply_code", "The http status code to return to a client", OFFSET(reply_code), AV_OPT_TYPE_INT, { .i64 = 200}, INT_MIN, 599, E}, { "reply_code", "The http status code to return to a client", OFFSET(reply_code), AV_OPT_TYPE_INT, { .i64 = 200}, INT_MIN, 599, E},
...@@ -1250,6 +1252,10 @@ static int http_read_stream(URLContext *h, uint8_t *buf, int size) ...@@ -1250,6 +1252,10 @@ static int http_read_stream(URLContext *h, uint8_t *buf, int size)
if ( (read_ret < 0 && s->reconnect && (!h->is_streamed || s->reconnect_streamed) && s->filesize > 0 && s->off < s->filesize) if ( (read_ret < 0 && s->reconnect && (!h->is_streamed || s->reconnect_streamed) && s->filesize > 0 && s->off < s->filesize)
|| (read_ret == 0 && s->reconnect_at_eof && (!h->is_streamed || s->reconnect_streamed))) { || (read_ret == 0 && s->reconnect_at_eof && (!h->is_streamed || s->reconnect_streamed))) {
int64_t target = h->is_streamed ? 0 : s->off; int64_t target = h->is_streamed ? 0 : s->off;
if (s->reconnect_delay > s->reconnect_delay_max)
return AVERROR(EIO);
av_log(h, AV_LOG_INFO, "Will reconnect at %"PRId64" error=%s.\n", s->off, av_err2str(read_ret)); av_log(h, AV_LOG_INFO, "Will reconnect at %"PRId64" error=%s.\n", s->off, av_err2str(read_ret));
av_usleep(1000U*1000*s->reconnect_delay); av_usleep(1000U*1000*s->reconnect_delay);
s->reconnect_delay = 1 + 2*s->reconnect_delay; s->reconnect_delay = 1 + 2*s->reconnect_delay;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment