diff options
author | wm4 <wm4@nowhere> | 2013-01-24 16:05:52 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-01-24 17:45:13 +0100 |
commit | dd96c11d5e0166ce6c597d178ee4827193cff16d (patch) | |
tree | d6ff3e8af74aebefe3866e8654683e8356ac5214 /stream/stream_lavf.c | |
parent | 570271c7767e924be3d9d347b04508579dfa4d80 (diff) | |
download | mpv-dd96c11d5e0166ce6c597d178ee4827193cff16d.tar.bz2 mpv-dd96c11d5e0166ce6c597d178ee4827193cff16d.tar.xz |
stream: implement some HTTP specific options for stream_lavf
The "http:" protocol has been switched to use ffmpeg's HTTP
implementation some time ago. One problem with this was that many HTTP
specific options stopped working, because they were obviously
implemented for the internal HTTP implementation only.
Add the missing things. Note that many options will work for ffmpeg
only, as Libav's HTTP implementation is missing these. They will
silently be ignored on Libav.
Some options we can't fix:
--ipv4-only-proxy, --prefer-ipv4, --prefer-ipv6
As far as I can see, not even libavformat internals distinguish
between ipv4 and ipv6.
--user, --passwd
ffmpeg probably supports specifying these in the URL directly.
Diffstat (limited to 'stream/stream_lavf.c')
-rw-r--r-- | stream/stream_lavf.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/stream/stream_lavf.c b/stream/stream_lavf.c index 0b540e26bc..d652bf27a8 100644 --- a/stream/stream_lavf.c +++ b/stream/stream_lavf.c @@ -27,6 +27,9 @@ #include "core/m_struct.h" #include "demux/demux.h" +#include "network.h" +#include "cookies.h" + static int fill_buffer(stream_t *s, char *buffer, int max_len) { AVIOContext *avio = s->priv; @@ -97,6 +100,7 @@ static int open_f(stream_t *stream, int mode, void *opts, int *file_format) int flags = 0; AVIOContext *avio = NULL; int res = STREAM_ERROR; + AVDictionary *dict = NULL; void *temp = talloc_new(NULL); if (mode == STREAM_READ) @@ -137,7 +141,28 @@ static int open_f(stream_t *stream, int mode, void *opts, int *file_format) filename = talloc_asprintf(temp, "mmsh://%.*s", BSTR_P(b_filename)); } - int err = avio_open(&avio, filename, flags); +#ifdef CONFIG_NETWORKING + // HTTP specific options (other protocols ignore them) + if (network_useragent) + av_dict_set(&dict, "user-agent", network_useragent, 0); + if (network_cookies_enabled) + av_dict_set(&dict, "cookies", talloc_steal(temp, cookies_lavf()), 0); + char *cust_headers = talloc_strdup(temp, ""); + if (network_referrer) { + cust_headers = talloc_asprintf_append(cust_headers, "Referer: %s\r\n", + network_referrer); + } + if (network_http_header_fields) { + for (int n = 0; network_http_header_fields[n]; n++) { + cust_headers = talloc_asprintf_append(cust_headers, "%s\r\n", + network_http_header_fields[n]); + } + } + if (strlen(cust_headers)) + av_dict_set(&dict, "headers", cust_headers, 0); +#endif + + int err = avio_open2(&avio, filename, flags, NULL, &dict); if (err < 0) { if (err == AVERROR_PROTOCOL_NOT_FOUND) mp_msg(MSGT_OPEN, MSGL_ERR, "[ffmpeg] Protocol not found. Make sure" @@ -178,6 +203,7 @@ static int open_f(stream_t *stream, int mode, void *opts, int *file_format) res = STREAM_OK; out: + av_dict_free(&dict); talloc_free(temp); return res; } |