diff options
-rw-r--r-- | DOCS/man/en/options.rst | 10 | ||||
-rw-r--r-- | core/cfg-mplayer.h | 13 | ||||
-rw-r--r-- | stream/asf_streaming.c | 2 | ||||
-rw-r--r-- | stream/cookies.c | 21 | ||||
-rw-r--r-- | stream/cookies.h | 1 | ||||
-rw-r--r-- | stream/http.c | 2 | ||||
-rw-r--r-- | stream/network.h | 12 | ||||
-rw-r--r-- | stream/stream_lavf.c | 28 | ||||
-rw-r--r-- | stream/stream_udp.c | 2 |
9 files changed, 61 insertions, 30 deletions
diff --git a/DOCS/man/en/options.rst b/DOCS/man/en/options.rst index d4368baf7b..dbf7a5a2e0 100644 --- a/DOCS/man/en/options.rst +++ b/DOCS/man/en/options.rst @@ -495,15 +495,11 @@ (network only) Support cookies when making HTTP requests. Disabled by default. - *WARNING*: works with the deprecated ``mp_http://`` protocol only. - --cookies-file=<filename> (network only) Read HTTP cookies from <filename>. The file is assumed to be in Netscape format. - *WARNING*: works with the deprecated ``mp_http://`` protocol only. - --correct-pts, --no-correct-pts Switches mpv to a mode where timestamps for video frames are calculated differently and video filters which add new frames or modify @@ -824,8 +820,6 @@ --http-header-fields=<field1,field2> Set custom HTTP fields when accessing HTTP stream. - *WARNING*: works with the deprecated ``mp_http://`` protocol only. - *EXAMPLE*: ``mpv --http-header-fields='Field1: value1','Field2: value2' http://localhost:1234`` @@ -1677,8 +1671,6 @@ --referrer=<string> Specify a referrer path or URL for HTTP requests. - *WARNING*: works with the deprecated ``mp_http://`` protocol only. - --reuse-socket (udp:// only) Allows a socket to be reused by other processes as soon as it is closed. @@ -2272,8 +2264,6 @@ --user-agent=<string> Use <string> as user agent for HTTP streaming. - *WARNING*: works with the deprecated ``mp_http://`` protocol only. - -v Increment verbosity level, one level for each ``-v`` found on the command line. diff --git a/core/cfg-mplayer.h b/core/cfg-mplayer.h index 1cb10d3463..eb3b805622 100644 --- a/core/cfg-mplayer.h +++ b/core/cfg-mplayer.h @@ -48,19 +48,6 @@ extern int field_dominance; /* from dec_audio, currently used for ac3surround decoder only */ extern int fakemono; -/* defined in network.c */ -extern char *network_username; -extern char *network_password; -extern int network_bandwidth; -extern char *network_useragent; -extern char *network_referrer; -extern int network_cookies_enabled; -extern char *cookies_file; - -extern int network_prefer_ipv4; -extern int network_ipv4_only_proxy; -extern int reuse_socket; - extern int dvd_speed; /* stream/stream_dvd.c */ /* defined in demux: */ diff --git a/stream/asf_streaming.c b/stream/asf_streaming.c index 3982c19340..862d7c3177 100644 --- a/stream/asf_streaming.c +++ b/stream/asf_streaming.c @@ -45,8 +45,6 @@ #include "demux/asfguid.h" -extern int network_bandwidth; - static int asf_http_streaming_start(stream_t *stream, int *demuxer_type); static int asf_read_wrapper(int fd, void *buffer, int len, streaming_ctrl_t *stream_ctrl) { diff --git a/stream/cookies.c b/stream/cookies.c index d8f8b051f9..5d772b8a6a 100644 --- a/stream/cookies.c +++ b/stream/cookies.c @@ -261,3 +261,24 @@ cookies_set(HTTP_header_t * http_hdr, const char *domain, const char *url) http_set_field(http_hdr, buf); free(buf); } + +// Return a cookies string as expected by lavf (libavformat/http.c). The format +// is like a Set-Cookie header (http://curl.haxx.se/rfc/cookie_spec.html), +// separated by newlines. +char *cookies_lavf(void) +{ + if (!cookie_list) + cookie_list = load_cookies(); + + struct cookie_list_type *list = cookie_list; + char *res = talloc_strdup(NULL, ""); + + while (list) { + res = talloc_asprintf_append_buffer(res, + "%s=%s; path=%s; domain=%s; %s\n", list->name, list->value, + list->path, list->domain, list->secure ? "secure" : ""); + list = list->next; + } + + return res; +} diff --git a/stream/cookies.h b/stream/cookies.h index 88ff96d66a..a24560631b 100644 --- a/stream/cookies.h +++ b/stream/cookies.h @@ -28,5 +28,6 @@ void cookies_set(HTTP_header_t * http_hdr, const char *hostname, const char *url); +char *cookies_lavf(void); #endif /* MPLAYER_COOKIES_H */ diff --git a/stream/http.c b/stream/http.c index 11fe7ed6de..bb96739c45 100644 --- a/stream/http.c +++ b/stream/http.c @@ -45,8 +45,6 @@ #include <libavutil/avutil.h> -extern int network_bandwidth; - typedef struct { unsigned metaint; unsigned metapos; diff --git a/stream/network.h b/stream/network.h index 6e21453b16..a2d1d3d173 100644 --- a/stream/network.h +++ b/stream/network.h @@ -63,6 +63,18 @@ extern const mime_struct_t mime_type_table[]; extern char **network_http_header_fields; +extern char *network_username; +extern char *network_password; +extern int network_bandwidth; +extern char *network_useragent; +extern char *network_referrer; +extern int network_cookies_enabled; +extern char *cookies_file; + +extern int network_prefer_ipv4; +extern int network_ipv4_only_proxy; +extern int reuse_socket; + streaming_ctrl_t *streaming_ctrl_new(void); int streaming_bufferize( streaming_ctrl_t *streaming_ctrl, char *buffer, int size); 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; } diff --git a/stream/stream_udp.c b/stream/stream_udp.c index fc7da19aa0..d447a9238c 100644 --- a/stream/stream_udp.c +++ b/stream/stream_udp.c @@ -60,8 +60,6 @@ udp_streaming_start (stream_t *stream) static int udp_stream_open (stream_t *stream, int mode, void *opts, int *file_format) { - extern int network_bandwidth; - mp_msg (MSGT_OPEN, MSGL_INFO, "STREAM_UDP, URL: %s\n", stream->url); stream->streaming_ctrl = streaming_ctrl_new (); if (!stream->streaming_ctrl) |