[FFmpeg-devel] [PATCH 1/2] Add 'rw_timeout' into URLContext
Andrey Utkin
andrey.krieger.utkin at gmail.com
Mon Aug 27 15:31:08 CEST 2012
If set non-zero, limits duration of retry_transfer_wrapper() loop, thus
affects ffurl_read*(), ffurl_write()
Measured in microseconds.
---
libavformat/avio.c | 12 ++++++++++--
libavformat/url.h | 1 +
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/libavformat/avio.c b/libavformat/avio.c
index fc902ff..6ed63f4 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)
diff --git a/libavformat/url.h b/libavformat/url.h
index d88ab52..5f75dc9 100644
--- a/libavformat/url.h
+++ b/libavformat/url.h
@@ -48,6 +48,7 @@ typedef struct URLContext {
int is_streamed; /**< true if streamed (no seek possible), default = false */
int is_connected;
AVIOInterruptCB interrupt_callback;
+ int64_t rw_timeout; /**< maximum time to wait for (network) read/write operation completion, in mcs */
} URLContext;
typedef struct URLProtocol {
--
1.7.8.6
More information about the ffmpeg-devel
mailing list