diff options
author | Andrey Utkin <andrey.krieger.utkin@gmail.com> | 2012-08-27 16:31:08 +0300 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-08-29 00:05:03 +0200 |
commit | 7870722592f58d4d1f5beeabfd11b6afc5285e76 (patch) | |
tree | 7f04e1f7eff95019fa7e45ee31f832dbb7f326dc /libavformat/avio.c | |
parent | a9b1a151d235c7bd41e3458c79ad2160de7e1461 (diff) | |
download | ffmpeg-7870722592f58d4d1f5beeabfd11b6afc5285e76.tar.gz |
Add 'rw_timeout' into URLContext
If set non-zero, limits duration of retry_transfer_wrapper() loop, thus
affects ffurl_read*(), ffurl_write()
Measured in microseconds.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/avio.c')
-rw-r--r-- | libavformat/avio.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/libavformat/avio.c b/libavformat/avio.c index fc902ff8a2..6ed63f4c85 100644 --- a/libavformat/avio.c +++ b/libavformat/avio.c @@ -254,6 +254,7 @@ static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int { int ret, len; int fast_retries = 5; + int64_t wait_since = 0; len = 0; while (len < size_min) { @@ -264,10 +265,17 @@ static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int return ret; if (ret == AVERROR(EAGAIN)) { ret = 0; - if (fast_retries) + if (fast_retries) { fast_retries--; - else + } else { + if (h->rw_timeout) { + if (!wait_since) + wait_since = av_gettime(); + else if (av_gettime() > wait_since + h->rw_timeout) + return AVERROR(ETIMEDOUT); + } av_usleep(1000); + } } else if (ret < 1) return ret < 0 ? ret : len; if (ret) |