summaryrefslogtreecommitdiff
path: root/libavformat/http.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2015-09-06 20:03:46 +0200
committerMichael Niedermayer <michael@niedermayer.cc>2015-09-07 19:28:46 +0200
commitbdbab4a351591304be07586fe55b8b9f01be28e3 (patch)
tree1c040db09ad69a61ac96955ff08fbeb171ad2565 /libavformat/http.c
parent9bd68dea2b7f4a79aa6c35b6193e3122c8ef2db7 (diff)
avformat/http: exponentially delay reconnection to avoid flooding the server
Reviewed-by: Zhang Rui <bbcallen@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavformat/http.c')
-rw-r--r--libavformat/http.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/libavformat/http.c b/libavformat/http.c
index aa60aefed9..126c7b3063 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -28,6 +28,7 @@
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/opt.h"
+#include "libavutil/time.h"
#include "avformat.h"
#include "http.h"
@@ -107,6 +108,7 @@ typedef struct HTTPContext {
int reconnect;
int reconnect_at_eof;
int reconnect_streamed;
+ int reconnect_delay;
int listen;
char *resource;
int reply_code;
@@ -1249,6 +1251,8 @@ static int http_read_stream(URLContext *h, uint8_t *buf, int size)
|| (read_ret == 0 && s->reconnect_at_eof && (!h->is_streamed || s->reconnect_streamed))) {
int64_t target = h->is_streamed ? 0 : s->off;
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);
+ s->reconnect_delay = 1 + 2*s->reconnect_delay;
seek_ret = http_seek_internal(h, target, SEEK_SET, 1);
if (seek_ret != target) {
av_log(h, AV_LOG_ERROR, "Failed to reconnect at %"PRId64".\n", target);
@@ -1256,7 +1260,8 @@ static int http_read_stream(URLContext *h, uint8_t *buf, int size)
}
read_ret = http_buf_read(h, buf, size);
- }
+ } else
+ s->reconnect_delay = 0;
return read_ret;
}