mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2024-12-29 19:02:21 +00: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:
commit
689a1bd917
@ -68,7 +68,6 @@ typedef struct {
|
||||
uint8_t *post_data;
|
||||
int post_datalen;
|
||||
int is_akamai;
|
||||
int rw_timeout;
|
||||
char *mime_type;
|
||||
char *cookies; ///< holds newline (\n) delimited Set-Cookie header field values (without the "Set-Cookie: " field name)
|
||||
int icy;
|
||||
@ -79,6 +78,7 @@ typedef struct {
|
||||
z_stream inflate_stream;
|
||||
uint8_t *inflate_buffer;
|
||||
#endif
|
||||
AVDictionary *chained_options;
|
||||
} HTTPContext;
|
||||
|
||||
#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 },
|
||||
{"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 },
|
||||
{"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 },
|
||||
{"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 },
|
||||
@ -126,7 +125,7 @@ void ff_http_init_auth_state(URLContext *dest, const URLContext *src)
|
||||
}
|
||||
|
||||
/* 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;
|
||||
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);
|
||||
|
||||
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, &opts);
|
||||
av_dict_free(&opts);
|
||||
&h->interrupt_callback, options);
|
||||
if (err < 0)
|
||||
goto fail;
|
||||
}
|
||||
@ -233,17 +225,24 @@ static int http_open_cnx(URLContext *h)
|
||||
int ff_http_do_new_request(URLContext *h, const char *uri)
|
||||
{
|
||||
HTTPContext *s = h->priv_data;
|
||||
AVDictionary *options = NULL;
|
||||
int ret;
|
||||
|
||||
s->off = 0;
|
||||
s->icy_data_read = 0;
|
||||
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;
|
||||
int ret;
|
||||
|
||||
if( s->seekable == 1 )
|
||||
h->is_streamed = 0;
|
||||
@ -252,6 +251,8 @@ static int http_open(URLContext *h, const char *uri, int flags)
|
||||
|
||||
s->filesize = -1;
|
||||
av_strlcpy(s->location, uri, sizeof(s->location));
|
||||
if (options)
|
||||
av_dict_copy(&s->chained_options, *options, 0);
|
||||
|
||||
if (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");
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@ -879,6 +883,7 @@ static int http_close(URLContext *h)
|
||||
|
||||
if (s->hd)
|
||||
ffurl_closep(&s->hd);
|
||||
av_dict_free(&s->chained_options);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -889,6 +894,7 @@ static int64_t http_seek(URLContext *h, int64_t off, int whence)
|
||||
int64_t old_off = s->off;
|
||||
uint8_t old_buf[BUFFER_SIZE];
|
||||
int old_buf_size;
|
||||
AVDictionary *options = NULL;
|
||||
|
||||
if (whence == AVSEEK_SIZE)
|
||||
return s->filesize;
|
||||
@ -906,7 +912,9 @@ static int64_t http_seek(URLContext *h, int64_t off, int whence)
|
||||
s->off = off;
|
||||
|
||||
/* 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);
|
||||
s->buf_ptr = s->buffer;
|
||||
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;
|
||||
return -1;
|
||||
}
|
||||
av_dict_free(&options);
|
||||
ffurl_close(old_hd);
|
||||
return off;
|
||||
}
|
||||
@ -928,7 +937,7 @@ http_get_file_handle(URLContext *h)
|
||||
#if CONFIG_HTTP_PROTOCOL
|
||||
URLProtocol ff_http_protocol = {
|
||||
.name = "http",
|
||||
.url_open = http_open,
|
||||
.url_open2 = http_open,
|
||||
.url_read = http_read,
|
||||
.url_write = http_write,
|
||||
.url_seek = http_seek,
|
||||
@ -943,7 +952,7 @@ URLProtocol ff_http_protocol = {
|
||||
#if CONFIG_HTTPS_PROTOCOL
|
||||
URLProtocol ff_https_protocol = {
|
||||
.name = "https",
|
||||
.url_open = http_open,
|
||||
.url_open2 = http_open,
|
||||
.url_read = http_read,
|
||||
.url_write = http_write,
|
||||
.url_seek = http_seek,
|
||||
@ -975,8 +984,6 @@ 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;
|
||||
@ -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,
|
||||
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, &opts);
|
||||
av_dict_free(&opts);
|
||||
&h->interrupt_callback, NULL);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user