aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Utkin <andrey.krieger.utkin@gmail.com>2012-09-13 03:43:32 +0300
committerMichael Niedermayer <michaelni@gmx.at>2012-10-09 17:47:14 +0200
commitb6f435fbc87c024f8403fca69e6e6b98bccf93fa (patch)
tree34cdab6c76e34a2f1f73d4a85478bf54f67e3201
parent2e009c6042bde419599ebed9165e597bbef23b2f (diff)
downloadffmpeg-b6f435fbc87c024f8403fca69e6e6b98bccf93fa.tar.gz
http: add 'timeout' AVOption
This option is passed though to underlying tcp protocol context Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libavformat/http.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/libavformat/http.c b/libavformat/http.c
index d385011203..a8076b2020 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -61,6 +61,7 @@ typedef struct {
uint8_t *post_data;
int post_datalen;
int is_akamai;
+ int rw_timeout;
} HTTPContext;
#define OFFSET(x) offsetof(HTTPContext, x)
@@ -74,6 +75,7 @@ static const AVOption options[] = {
{"user-agent", "override User-Agent header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC},
{"multiple_requests", "use persistent connections", OFFSET(multiple_requests), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, D|E },
{"post_data", "custom HTTP post data", OFFSET(post_data), AV_OPT_TYPE_BINARY, .flags = D|E },
+{"timeout", "timeout of socket i/o operations", OFFSET(rw_timeout), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, D|E },
{NULL}
};
#define HTTP_CLASS(flavor)\
@@ -151,8 +153,15 @@ static int http_open_cnx(URLContext *h)
ff_url_join(buf, sizeof(buf), lower_proto, NULL, hostname, port, NULL);
if (!s->hd) {
+ AVDictionary *opts = NULL;
+ char opts_format[20];
+ if (s->rw_timeout != -1) {
+ snprintf(opts_format, sizeof(opts_format), "%d", s->rw_timeout);
+ av_dict_set(&opts, "timeout", opts_format, 0);
+ } /* if option is not given, don't pass it and let tcp use its own default */
err = ffurl_open(&s->hd, buf, AVIO_FLAG_READ_WRITE,
- &h->interrupt_callback, NULL);
+ &h->interrupt_callback, &opts);
+ av_dict_free(&opts);
if (err < 0)
goto fail;
}
@@ -709,6 +718,8 @@ static int http_proxy_open(URLContext *h, const char *uri, int flags)
HTTPAuthType cur_auth_type;
char *authstr;
int new_loc;
+ AVDictionary *opts = NULL;
+ char opts_format[20];
if( s->seekable == 1 )
h->is_streamed = 0;
@@ -725,8 +736,13 @@ static int http_proxy_open(URLContext *h, const char *uri, int flags)
ff_url_join(lower_url, sizeof(lower_url), "tcp", NULL, hostname, port,
NULL);
redo:
+ if (s->rw_timeout != -1) {
+ snprintf(opts_format, sizeof(opts_format), "%d", s->rw_timeout);
+ av_dict_set(&opts, "timeout", opts_format, 0);
+ } /* if option is not given, don't pass it and let tcp use its own default */
ret = ffurl_open(&s->hd, lower_url, AVIO_FLAG_READ_WRITE,
- &h->interrupt_callback, NULL);
+ &h->interrupt_callback, &opts);
+ av_dict_free(&opts);
if (ret < 0)
return ret;