mirror of
https://github.com/mpv-player/mpv
synced 2025-01-18 04:51:52 +00:00
options: move network related options to MPOpts
This commit is contained in:
parent
38be9d5fed
commit
3a637d411f
@ -42,19 +42,6 @@
|
||||
#include "player/core.h"
|
||||
#include "osdep/priority.h"
|
||||
|
||||
int network_bandwidth=0;
|
||||
int network_cookies_enabled = 0;
|
||||
char *network_useragent="mpv " VERSION;
|
||||
char *network_referrer=NULL;
|
||||
char **network_http_header_fields=NULL;
|
||||
int network_tls_verify;
|
||||
char *network_tls_ca_file;
|
||||
|
||||
extern char *lirc_configfile;
|
||||
|
||||
extern int mp_msg_color;
|
||||
extern int mp_msg_module;
|
||||
|
||||
/* defined in demux: */
|
||||
extern const m_option_t demux_rawaudio_opts[];
|
||||
extern const m_option_t demux_rawvideo_opts[];
|
||||
@ -279,18 +266,18 @@ const m_option_t mp_opts[] = {
|
||||
{"bluray-angle", &bluray_angle, CONF_TYPE_INT, CONF_RANGE, 0, 999, NULL},
|
||||
#endif /* HAVE_LIBBLURAY */
|
||||
|
||||
{"http-header-fields", &network_http_header_fields, CONF_TYPE_STRING_LIST, 0, 0, 0, NULL},
|
||||
{"user-agent", &network_useragent, CONF_TYPE_STRING, 0, 0, 0, NULL},
|
||||
{"referrer", &network_referrer, CONF_TYPE_STRING, 0, 0, 0, NULL},
|
||||
{"cookies", &network_cookies_enabled, CONF_TYPE_FLAG, 0, 0, 1, NULL},
|
||||
{"cookies-file", &cookies_file, CONF_TYPE_STRING, 0, 0, 0, NULL},
|
||||
OPT_STRINGLIST("http-header-fields", network_http_header_fields, 0),
|
||||
OPT_STRING("user-agent", network_useragent, 0),
|
||||
OPT_STRING("referrer", network_referrer, 0),
|
||||
OPT_FLAG("cookies", network_cookies_enabled, 0),
|
||||
OPT_STRING("cookies-file", network_cookies_file, 0),
|
||||
OPT_CHOICE("rtsp-transport", network_rtsp_transport, 0,
|
||||
({"lavf", 0},
|
||||
{"udp", 1},
|
||||
{"tcp", 2},
|
||||
{"http", 3})),
|
||||
{"tls-verify", &network_tls_verify, CONF_TYPE_FLAG, 0, 0, 0, NULL},
|
||||
{"tls-ca-file", &network_tls_ca_file, CONF_TYPE_STRING, 0, 0, 0, NULL},
|
||||
OPT_FLAG("tls-verify", network_tls_verify, 0),
|
||||
OPT_STRING("tls-ca-file", network_tls_ca_file, 0),
|
||||
|
||||
// ------------------------- demuxer options --------------------
|
||||
|
||||
@ -753,6 +740,8 @@ const struct MPOpts mp_default_opts = {
|
||||
|
||||
.index_mode = -1,
|
||||
|
||||
.network_useragent = "mpv " VERSION,
|
||||
|
||||
.ad_lavc_param = {
|
||||
.ac3drc = 1.,
|
||||
.downmix = 1,
|
||||
|
@ -218,6 +218,14 @@ typedef struct MPOpts {
|
||||
int hwdec_api;
|
||||
char *hwdec_codecs;
|
||||
|
||||
int network_cookies_enabled;
|
||||
char *network_cookies_file;
|
||||
char *network_useragent;
|
||||
char *network_referrer;
|
||||
char **network_http_header_fields;
|
||||
int network_tls_verify;
|
||||
char *network_tls_ca_file;
|
||||
|
||||
struct lavc_param {
|
||||
int fast;
|
||||
char *skip_loop_filter_str;
|
||||
@ -289,15 +297,6 @@ typedef struct MPOpts {
|
||||
} encode_output;
|
||||
} MPOpts;
|
||||
|
||||
// Should be moved into MPOpts
|
||||
extern char **network_http_header_fields;
|
||||
extern char *network_useragent;
|
||||
extern char *network_referrer;
|
||||
extern int network_cookies_enabled;
|
||||
extern int network_tls_verify;
|
||||
extern char *network_tls_ca_file;
|
||||
extern char *cookies_file;
|
||||
|
||||
extern const m_option_t mp_opts[];
|
||||
extern const struct MPOpts mp_default_opts;
|
||||
|
||||
|
@ -39,8 +39,6 @@
|
||||
|
||||
#define MAX_COOKIES 20
|
||||
|
||||
char *cookies_file = NULL;
|
||||
|
||||
typedef struct cookie_list_type {
|
||||
char *name;
|
||||
char *value;
|
||||
@ -173,13 +171,13 @@ static struct cookie_list_type *load_cookies_from(struct mp_log *log,
|
||||
// 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(struct mp_log *log)
|
||||
char *cookies_lavf(void *talloc_ctx, struct mp_log *log, char *file)
|
||||
{
|
||||
if (!cookie_list && cookies_file)
|
||||
cookie_list = load_cookies_from(log, cookies_file, NULL);
|
||||
if (!cookie_list && file && file[0])
|
||||
cookie_list = load_cookies_from(log, file, NULL);
|
||||
|
||||
struct cookie_list_type *list = cookie_list;
|
||||
char *res = talloc_strdup(NULL, "");
|
||||
char *res = talloc_strdup(talloc_ctx, "");
|
||||
|
||||
while (list) {
|
||||
res = talloc_asprintf_append_buffer(res,
|
||||
|
@ -24,6 +24,6 @@
|
||||
#ifndef MPLAYER_COOKIES_H
|
||||
#define MPLAYER_COOKIES_H
|
||||
|
||||
char *cookies_lavf(struct mp_log *log);
|
||||
char *cookies_lavf(void *talloc_ctx, struct mp_log *log, char *file);
|
||||
|
||||
#endif /* MPLAYER_COOKIES_H */
|
||||
|
@ -131,6 +131,7 @@ static const char * const prefix[] = { "lavf://", "ffmpeg://" };
|
||||
|
||||
static int open_f(stream_t *stream, int mode)
|
||||
{
|
||||
struct MPOpts *opts = stream->opts;
|
||||
int flags = 0;
|
||||
AVIOContext *avio = NULL;
|
||||
int res = STREAM_ERROR;
|
||||
@ -179,22 +180,24 @@ static int open_f(stream_t *stream, int mode)
|
||||
}
|
||||
|
||||
// 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(stream->log)), 0);
|
||||
av_dict_set(&dict, "tls_verify", network_tls_verify ? "1" : "0", 0);
|
||||
if (network_tls_ca_file)
|
||||
av_dict_set(&dict, "ca_file", network_tls_ca_file, 0);
|
||||
char *cust_headers = talloc_strdup(temp, "");
|
||||
if (network_referrer) {
|
||||
cust_headers = talloc_asprintf_append(cust_headers, "Referer: %s\r\n",
|
||||
network_referrer);
|
||||
if (opts->network_useragent)
|
||||
av_dict_set(&dict, "user-agent", opts->network_useragent, 0);
|
||||
if (opts->network_cookies_enabled) {
|
||||
char *file = opts->network_cookies_file;
|
||||
av_dict_set(&dict, "cookies", cookies_lavf(temp, stream->log, file), 0);
|
||||
}
|
||||
if (network_http_header_fields) {
|
||||
for (int n = 0; network_http_header_fields[n]; n++) {
|
||||
av_dict_set(&dict, "tls_verify", opts->network_tls_verify ? "1" : "0", 0);
|
||||
if (opts->network_tls_ca_file)
|
||||
av_dict_set(&dict, "ca_file", opts->network_tls_ca_file, 0);
|
||||
char *cust_headers = talloc_strdup(temp, "");
|
||||
if (opts->network_referrer) {
|
||||
cust_headers = talloc_asprintf_append(cust_headers, "Referer: %s\r\n",
|
||||
opts->network_referrer);
|
||||
}
|
||||
if (opts->network_http_header_fields) {
|
||||
for (int n = 0; opts->network_http_header_fields[n]; n++) {
|
||||
cust_headers = talloc_asprintf_append(cust_headers, "%s\r\n",
|
||||
network_http_header_fields[n]);
|
||||
opts->network_http_header_fields[n]);
|
||||
}
|
||||
}
|
||||
if (strlen(cust_headers))
|
||||
|
Loading…
Reference in New Issue
Block a user