1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

Merge commit '5c53bf7aaf03748464cbf978bffe7ffdb71112b1'

* commit '5c53bf7aaf03748464cbf978bffe7ffdb71112b1':
  http: Pass options through to the nested protocol

Conflicts:
	libavformat/http.c

See: b6f435fbc8
Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2013-09-27 10:13:13 +02:00
commit 689a1bd917

View File

@ -68,7 +68,6 @@ typedef struct {
uint8_t *post_data; uint8_t *post_data;
int post_datalen; int post_datalen;
int is_akamai; int is_akamai;
int rw_timeout;
char *mime_type; char *mime_type;
char *cookies; ///< holds newline (\n) delimited Set-Cookie header field values (without the "Set-Cookie: " field name) char *cookies; ///< holds newline (\n) delimited Set-Cookie header field values (without the "Set-Cookie: " field name)
int icy; int icy;
@ -79,6 +78,7 @@ typedef struct {
z_stream inflate_stream; z_stream inflate_stream;
uint8_t *inflate_buffer; uint8_t *inflate_buffer;
#endif #endif
AVDictionary *chained_options;
} HTTPContext; } HTTPContext;
#define OFFSET(x) offsetof(HTTPContext, x) #define OFFSET(x) offsetof(HTTPContext, x)
@ -93,7 +93,6 @@ static const AVOption options[] = {
{"user-agent", "override User-Agent header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = DEFAULT_USER_AGENT}, 0, 0, D }, {"user-agent", "override User-Agent header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = DEFAULT_USER_AGENT}, 0, 0, D },
{"multiple_requests", "use persistent connections", OFFSET(multiple_requests), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, D|E }, {"multiple_requests", "use persistent connections", OFFSET(multiple_requests), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, D|E },
{"post_data", "set custom HTTP post data", OFFSET(post_data), AV_OPT_TYPE_BINARY, .flags = D|E }, {"post_data", "set custom HTTP post data", OFFSET(post_data), AV_OPT_TYPE_BINARY, .flags = D|E },
{"timeout", "set timeout of socket I/O operations", OFFSET(rw_timeout), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, D|E },
{"mime_type", "set MIME type", OFFSET(mime_type), AV_OPT_TYPE_STRING, {0}, 0, 0, 0 }, {"mime_type", "set MIME type", OFFSET(mime_type), AV_OPT_TYPE_STRING, {0}, 0, 0, 0 },
{"cookies", "set cookies to be sent in applicable future requests, use newline delimited Set-Cookie HTTP field value syntax", OFFSET(cookies), AV_OPT_TYPE_STRING, {0}, 0, 0, 0 }, {"cookies", "set cookies to be sent in applicable future requests, use newline delimited Set-Cookie HTTP field value syntax", OFFSET(cookies), AV_OPT_TYPE_STRING, {0}, 0, 0, 0 },
{"icy", "request ICY metadata", OFFSET(icy), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, D }, {"icy", "request ICY metadata", OFFSET(icy), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, D },
@ -126,7 +125,7 @@ void ff_http_init_auth_state(URLContext *dest, const URLContext *src)
} }
/* return non zero if error */ /* return non zero if error */
static int http_open_cnx(URLContext *h) static int http_open_cnx(URLContext *h, AVDictionary **options)
{ {
const char *path, *proxy_path, *lower_proto = "tcp", *local_path; const char *path, *proxy_path, *lower_proto = "tcp", *local_path;
char hostname[1024], hoststr[1024], proto[10]; char hostname[1024], hoststr[1024], proto[10];
@ -176,15 +175,8 @@ static int http_open_cnx(URLContext *h)
ff_url_join(buf, sizeof(buf), lower_proto, NULL, hostname, port, NULL); ff_url_join(buf, sizeof(buf), lower_proto, NULL, hostname, port, NULL);
if (!s->hd) { 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, err = ffurl_open(&s->hd, buf, AVIO_FLAG_READ_WRITE,
&h->interrupt_callback, &opts); &h->interrupt_callback, options);
av_dict_free(&opts);
if (err < 0) if (err < 0)
goto fail; goto fail;
} }
@ -233,17 +225,24 @@ static int http_open_cnx(URLContext *h)
int ff_http_do_new_request(URLContext *h, const char *uri) int ff_http_do_new_request(URLContext *h, const char *uri)
{ {
HTTPContext *s = h->priv_data; HTTPContext *s = h->priv_data;
AVDictionary *options = NULL;
int ret;
s->off = 0; s->off = 0;
s->icy_data_read = 0; s->icy_data_read = 0;
av_strlcpy(s->location, uri, sizeof(s->location)); av_strlcpy(s->location, uri, sizeof(s->location));
return http_open_cnx(h); av_dict_copy(&options, s->chained_options, 0);
ret = http_open_cnx(h, &options);
av_dict_free(&options);
return ret;
} }
static int http_open(URLContext *h, const char *uri, int flags) static int http_open(URLContext *h, const char *uri, int flags,
AVDictionary **options)
{ {
HTTPContext *s = h->priv_data; HTTPContext *s = h->priv_data;
int ret;
if( s->seekable == 1 ) if( s->seekable == 1 )
h->is_streamed = 0; h->is_streamed = 0;
@ -252,6 +251,8 @@ static int http_open(URLContext *h, const char *uri, int flags)
s->filesize = -1; s->filesize = -1;
av_strlcpy(s->location, uri, sizeof(s->location)); av_strlcpy(s->location, uri, sizeof(s->location));
if (options)
av_dict_copy(&s->chained_options, *options, 0);
if (s->headers) { if (s->headers) {
int len = strlen(s->headers); int len = strlen(s->headers);
@ -259,7 +260,10 @@ static int http_open(URLContext *h, const char *uri, int flags)
av_log(h, AV_LOG_WARNING, "No trailing CRLF found in HTTP header.\n"); av_log(h, AV_LOG_WARNING, "No trailing CRLF found in HTTP header.\n");
} }
return http_open_cnx(h); ret = http_open_cnx(h, options);
if (ret < 0)
av_dict_free(&s->chained_options);
return ret;
} }
static int http_getc(HTTPContext *s) static int http_getc(HTTPContext *s)
{ {
@ -879,6 +883,7 @@ static int http_close(URLContext *h)
if (s->hd) if (s->hd)
ffurl_closep(&s->hd); ffurl_closep(&s->hd);
av_dict_free(&s->chained_options);
return ret; return ret;
} }
@ -889,6 +894,7 @@ static int64_t http_seek(URLContext *h, int64_t off, int whence)
int64_t old_off = s->off; int64_t old_off = s->off;
uint8_t old_buf[BUFFER_SIZE]; uint8_t old_buf[BUFFER_SIZE];
int old_buf_size; int old_buf_size;
AVDictionary *options = NULL;
if (whence == AVSEEK_SIZE) if (whence == AVSEEK_SIZE)
return s->filesize; return s->filesize;
@ -906,7 +912,9 @@ static int64_t http_seek(URLContext *h, int64_t off, int whence)
s->off = off; s->off = off;
/* if it fails, continue on old connection */ /* if it fails, continue on old connection */
if (http_open_cnx(h) < 0) { av_dict_copy(&options, s->chained_options, 0);
if (http_open_cnx(h, &options) < 0) {
av_dict_free(&options);
memcpy(s->buffer, old_buf, old_buf_size); memcpy(s->buffer, old_buf, old_buf_size);
s->buf_ptr = s->buffer; s->buf_ptr = s->buffer;
s->buf_end = s->buffer + old_buf_size; s->buf_end = s->buffer + old_buf_size;
@ -914,6 +922,7 @@ static int64_t http_seek(URLContext *h, int64_t off, int whence)
s->off = old_off; s->off = old_off;
return -1; return -1;
} }
av_dict_free(&options);
ffurl_close(old_hd); ffurl_close(old_hd);
return off; return off;
} }
@ -928,7 +937,7 @@ http_get_file_handle(URLContext *h)
#if CONFIG_HTTP_PROTOCOL #if CONFIG_HTTP_PROTOCOL
URLProtocol ff_http_protocol = { URLProtocol ff_http_protocol = {
.name = "http", .name = "http",
.url_open = http_open, .url_open2 = http_open,
.url_read = http_read, .url_read = http_read,
.url_write = http_write, .url_write = http_write,
.url_seek = http_seek, .url_seek = http_seek,
@ -943,7 +952,7 @@ URLProtocol ff_http_protocol = {
#if CONFIG_HTTPS_PROTOCOL #if CONFIG_HTTPS_PROTOCOL
URLProtocol ff_https_protocol = { URLProtocol ff_https_protocol = {
.name = "https", .name = "https",
.url_open = http_open, .url_open2 = http_open,
.url_read = http_read, .url_read = http_read,
.url_write = http_write, .url_write = http_write,
.url_seek = http_seek, .url_seek = http_seek,
@ -975,8 +984,6 @@ static int http_proxy_open(URLContext *h, const char *uri, int flags)
HTTPAuthType cur_auth_type; HTTPAuthType cur_auth_type;
char *authstr; char *authstr;
int new_loc; int new_loc;
AVDictionary *opts = NULL;
char opts_format[20];
if( s->seekable == 1 ) if( s->seekable == 1 )
h->is_streamed = 0; h->is_streamed = 0;
@ -993,13 +1000,8 @@ static int http_proxy_open(URLContext *h, const char *uri, int flags)
ff_url_join(lower_url, sizeof(lower_url), "tcp", NULL, hostname, port, ff_url_join(lower_url, sizeof(lower_url), "tcp", NULL, hostname, port,
NULL); NULL);
redo: 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, ret = ffurl_open(&s->hd, lower_url, AVIO_FLAG_READ_WRITE,
&h->interrupt_callback, &opts); &h->interrupt_callback, NULL);
av_dict_free(&opts);
if (ret < 0) if (ret < 0)
return ret; return ret;