summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-08-25 22:49:27 +0200
committerwm4 <wm4@nowhere>2013-08-26 10:09:45 +0200
commit971e8456fc36eb36213c60ab57828aec8640819b (patch)
tree7384dcb71d7a5d70b13cd351912c21c09f78d909
parent8be9c49fcd8b23463199036eda5fc290ded6d078 (diff)
downloadmpv-971e8456fc36eb36213c60ab57828aec8640819b.tar.bz2
mpv-971e8456fc36eb36213c60ab57828aec8640819b.tar.xz
stream: fix url_options field, make protocols field not fixed length
The way the url_options field was handled was not entirely sane: it's actually a flexible array member, so it points to garbage for streams which do not initialize this member (it just points to the data right after the struct, which is garbage in theory and practice). This was not actually a problem, since the field is only used if priv_size is set (due to how this stuff is used). But it doesn't allow setting priv_size only, which might be useful in some cases. Also, make the protocols array not a fixed size array. Most stream implementations have only 1 protocol prefix, but stream_lavf.c has over 10 (whitelists ffmpeg protocols). The high size of the fixed size protocol array wastes space, and it is _still_ annoying to add new prefixes to stream_lavf (have to bump the maximum length), so make it arbitrary length. The two changes (plus some more cosmetic changes) arte conflated into one, because it was annoying going over all the stream implementations.
-rw-r--r--stream/stream.c9
-rw-r--r--stream/stream.h4
-rw-r--r--stream/stream_avdevice.c2
-rw-r--r--stream/stream_bluray.c14
-rw-r--r--stream/stream_cdda.c16
-rw-r--r--stream/stream_dvb.c14
-rw-r--r--stream/stream_dvd.c20
-rw-r--r--stream/stream_file.c6
-rw-r--r--stream/stream_lavf.c10
-rw-r--r--stream/stream_memory.c6
-rw-r--r--stream/stream_mf.c6
-rw-r--r--stream/stream_null.c6
-rw-r--r--stream/stream_pvr.c6
-rw-r--r--stream/stream_radio.c14
-rw-r--r--stream/stream_smb.c6
-rw-r--r--stream/stream_tv.c14
-rw-r--r--stream/stream_vcd.c6
17 files changed, 82 insertions, 77 deletions
diff --git a/stream/stream.c b/stream/stream.c
index 4650535890..0832cb7f8a 100644
--- a/stream/stream.c
+++ b/stream/stream.c
@@ -150,9 +150,12 @@ void mp_url_unescape_inplace(char *buf)
static const char *find_url_opt(struct stream *s, const char *opt)
{
- for (int n = 0; s->info->url_options && s->info->url_options[n][0]; n++) {
- if (strcmp(s->info->url_options[n][0], opt) == 0)
- return s->info->url_options[n][1];
+ for (int n = 0; s->info->url_options && s->info->url_options[n]; n++) {
+ const char *entry = s->info->url_options[n];
+ const char *t = strchr(entry, '=');
+ assert(t);
+ if (strncmp(opt, entry, t - entry) == 0)
+ return t + 1;
}
return NULL;
}
diff --git a/stream/stream.h b/stream/stream.h
index 27043206c9..1009a2a7b0 100644
--- a/stream/stream.h
+++ b/stream/stream.h
@@ -111,11 +111,11 @@ typedef struct stream_info_st {
const char *name;
// opts is set from ->opts
int (*open)(struct stream *st, int mode);
- const char *protocols[MAX_STREAM_PROTOCOLS];
+ const char **protocols;
int priv_size;
const void *priv_defaults;
const struct m_option *options;
- const char *url_options[][2];
+ const char **url_options;
} stream_info_t;
typedef struct stream {
diff --git a/stream/stream_avdevice.c b/stream/stream_avdevice.c
index e1da3b2958..5e8aefd018 100644
--- a/stream/stream_avdevice.c
+++ b/stream/stream_avdevice.c
@@ -34,5 +34,5 @@ static int open_f(stream_t *stream, int mode)
const stream_info_t stream_info_avdevice = {
.name = "avdevice",
.open = open_f,
- .protocols = { "avdevice", "av", NULL },
+ .protocols = (const char*[]){ "avdevice", "av", NULL },
};
diff --git a/stream/stream_bluray.c b/stream/stream_bluray.c
index 61e63151fb..69e47a0589 100644
--- a/stream/stream_bluray.c
+++ b/stream/stream_bluray.c
@@ -402,15 +402,15 @@ err_no_info:
}
const stream_info_t stream_info_bluray = {
- "bd",
- bluray_stream_open,
- { "bd", "br", "bluray", NULL },
+ .name = "bd",
+ .open = bluray_stream_open,
+ .protocols = (const char*[]){ "bd", "br", "bluray", NULL },
.priv_defaults = &bluray_stream_priv_dflts,
.priv_size = sizeof(struct bluray_priv_s),
.options = bluray_stream_opts_fields,
- .url_options = {
- {"hostname", "title"},
- {"filename", "device"},
- {0}
+ .url_options = (const char*[]){
+ "hostname=title",
+ "filename=device",
+ NULL
},
};
diff --git a/stream/stream_cdda.c b/stream/stream_cdda.c
index 26ad560cae..4c114ca1ac 100644
--- a/stream/stream_cdda.c
+++ b/stream/stream_cdda.c
@@ -460,16 +460,16 @@ static int open_cdda(stream_t *st, int m)
}
const stream_info_t stream_info_cdda = {
- "cdda",
- open_cdda,
- {"cdda", NULL },
+ .name = "cdda",
+ .open = open_cdda,
+ .protocols = (const char*[]){"cdda", NULL },
.priv_size = sizeof(cdda_priv),
.priv_defaults = &cdda_dflts,
.options = cdda_params_fields,
- .url_options = {
- {"hostname", "span"},
- {"port", "speed"},
- {"filename", "device"},
- {0}
+ .url_options = (const char*[]){
+ "hostname=span",
+ "port=speed",
+ "filename=device",
+ NULL
},
};
diff --git a/stream/stream_dvb.c b/stream/stream_dvb.c
index d96aea6905..af79a727eb 100644
--- a/stream/stream_dvb.c
+++ b/stream/stream_dvb.c
@@ -830,15 +830,15 @@ dvb_config_t *dvb_get_config(void)
const stream_info_t stream_info_dvb = {
- "dvbin",
- dvb_open,
- { "dvb", NULL },
+ .name = "dvbin",
+ .open = dvb_open,
+ .protocols = (const char*[]){ "dvb", NULL },
.priv_size = sizeof(dvb_priv_t),
.priv_defaults = &stream_defaults,
.options = stream_params,
- .url_options = {
- {"hostname", "prog"},
- {"username", "card"},
- {0}
+ .url_options = (const char*[]){
+ "hostname=prog",
+ "username=card",
+ NULL
},
};
diff --git a/stream/stream_dvd.c b/stream/stream_dvd.c
index 340002fb46..7f5280c1c3 100644
--- a/stream/stream_dvd.c
+++ b/stream/stream_dvd.c
@@ -1078,21 +1078,21 @@ static int ifo_stream_open (stream_t *stream, int mode)
}
const stream_info_t stream_info_dvd = {
- "dvd",
- open_s,
- { "dvd", NULL },
+ .name = "dvd",
+ .open = open_s,
+ .protocols = (const char*[]){ "dvd", NULL },
.priv_size = sizeof(dvd_priv_t),
.priv_defaults = &stream_priv_dflts,
.options = stream_opts_fields,
- .url_options = {
- {"hostname", "title"},
- {"filename", "device"},
- {0}
+ .url_options = (const char*[]){
+ "hostname=title",
+ "filename=device",
+ NULL
},
};
const stream_info_t stream_info_ifo = {
- "ifo",
- ifo_stream_open,
- { "file", "", NULL },
+ .name = "ifo",
+ .open = ifo_stream_open,
+ .protocols = (const char*[]){ "file", "", NULL },
};
diff --git a/stream/stream_file.c b/stream/stream_file.c
index 87e77d7bf3..b638fdddf0 100644
--- a/stream/stream_file.c
+++ b/stream/stream_file.c
@@ -187,7 +187,7 @@ static int open_f(stream_t *stream, int mode)
}
const stream_info_t stream_info_file = {
- "file",
- open_f,
- { "file", "", NULL },
+ .name = "file",
+ .open = open_f,
+ .protocols = (const char*[]){ "file", "", NULL },
};
diff --git a/stream/stream_lavf.c b/stream/stream_lavf.c
index cedea2fb4b..9a25d7524a 100644
--- a/stream/stream_lavf.c
+++ b/stream/stream_lavf.c
@@ -303,8 +303,10 @@ done:
}
const stream_info_t stream_info_ffmpeg = {
- "ffmpeg",
- open_f,
- { "lavf", "ffmpeg", "rtmp", "rtsp", "http", "https", "mms", "mmst", "mmsh",
- "mmshttp", "udp", "ftp", "rtp", "httpproxy", NULL },
+ .name = "ffmpeg",
+ .open = open_f,
+ .protocols = (const char*[]){
+ "lavf", "ffmpeg", "rtmp", "rtsp", "http", "https", "mms", "mmst", "mmsh",
+ "mmshttp", "udp", "ftp", "rtp", "httpproxy",
+ NULL },
};
diff --git a/stream/stream_memory.c b/stream/stream_memory.c
index eaf74bb07e..ff2b42e020 100644
--- a/stream/stream_memory.c
+++ b/stream/stream_memory.c
@@ -72,7 +72,7 @@ static int open_f(stream_t *stream, int mode)
}
const stream_info_t stream_info_memory = {
- "memory",
- open_f,
- { "memory", NULL },
+ .name = "memory",
+ .open = open_f,
+ .protocols = (const char*[]){ "memory", NULL },
};
diff --git a/stream/stream_mf.c b/stream/stream_mf.c
index 720a73f836..9b80a73d58 100644
--- a/stream/stream_mf.c
+++ b/stream/stream_mf.c
@@ -38,7 +38,7 @@ mf_stream_open (stream_t *stream, int mode)
}
const stream_info_t stream_info_mf = {
- "mf",
- mf_stream_open,
- { "mf", NULL },
+ .name = "mf",
+ .open = mf_stream_open,
+ .protocols = (const char*[]){ "mf", NULL },
};
diff --git a/stream/stream_null.c b/stream/stream_null.c
index 2e2b7886f7..c9a0a430e2 100644
--- a/stream/stream_null.c
+++ b/stream/stream_null.c
@@ -32,7 +32,7 @@ static int open_s(stream_t *stream,int mode)
const stream_info_t stream_info_null = {
- "null",
- open_s,
- { "null", NULL },
+ .name = "null",
+ .open = open_s,
+ .protocols = (const char*[]){ "null", NULL },
};
diff --git a/stream/stream_pvr.c b/stream/stream_pvr.c
index ded2751e11..1b11584803 100644
--- a/stream/stream_pvr.c
+++ b/stream/stream_pvr.c
@@ -1757,7 +1757,7 @@ pvr_force_freq_step (stream_t *stream, int step)
}
const stream_info_t stream_info_pvr = {
- "pvr",
- pvr_stream_open,
- { "pvr", NULL },
+ .name = "pvr",
+ .open = pvr_stream_open,
+ .protocols = (const char*[]){ "pvr", NULL },
};
diff --git a/stream/stream_radio.c b/stream/stream_radio.c
index 643b304936..de2f474bc9 100644
--- a/stream/stream_radio.c
+++ b/stream/stream_radio.c
@@ -959,15 +959,15 @@ static void close_s(struct stream *stream){
}
const stream_info_t stream_info_radio = {
- "radio",
- open_s,
- { "radio", NULL },
+ .name = "radio",
+ .open = open_s,
+ .protocols = (const char*[]){ "radio", NULL },
.priv_size = sizeof(radio_param_t),
.priv_defaults = &stream_radio_defaults,
.options = stream_opts_fields,
- .url_options = {
- {"hostname", "freqchannel"},
- {"filename", "capture"},
- {0}
+ .url_options = (const char*[]){
+ "hostname=freqchannel",
+ "filename=capture",
+ NULL
},
};
diff --git a/stream/stream_smb.c b/stream/stream_smb.c
index d50258be97..3fcfb7e459 100644
--- a/stream/stream_smb.c
+++ b/stream/stream_smb.c
@@ -166,7 +166,7 @@ static int open_f (stream_t *stream, int mode)
}
const stream_info_t stream_info_smb = {
- "smb",
- open_f,
- {"smb", NULL},
+ .name = "smb",
+ .open = open_f,
+ .protocols = (const char*[]){"smb", NULL},
};
diff --git a/stream/stream_tv.c b/stream/stream_tv.c
index ef6f49b4b6..b1c2e63167 100644
--- a/stream/stream_tv.c
+++ b/stream/stream_tv.c
@@ -97,15 +97,15 @@ tv_stream_open (stream_t *stream, int mode)
}
const stream_info_t stream_info_tv = {
- "tv",
- tv_stream_open,
- { "tv", NULL },
+ .name = "tv",
+ .open = tv_stream_open,
+ .protocols = (const char*[]){ "tv", NULL },
.priv_size = sizeof(tv_param_t),
.priv_defaults = &stream_tv_defaults,
.options = stream_opts_fields,
- .url_options = {
- {"hostname", "channel"},
- {"filename", "input"},
- {0}
+ .url_options = (const char*[]){
+ "hostname=channel",
+ "filename=input",
+ NULL
},
};
diff --git a/stream/stream_vcd.c b/stream/stream_vcd.c
index 6ec8453536..dacf2763f8 100644
--- a/stream/stream_vcd.c
+++ b/stream/stream_vcd.c
@@ -177,7 +177,7 @@ static int open_s(stream_t *stream,int mode)
}
const stream_info_t stream_info_vcd = {
- "vcd",
- open_s,
- { "vcd", NULL },
+ .name = "vcd",
+ .open = open_s,
+ .protocols = (const char*[]){ "vcd", NULL },
};