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.
This commit is contained in:
wm4 2013-08-25 22:49:27 +02:00
parent 8be9c49fcd
commit 971e8456fc
17 changed files with 82 additions and 77 deletions

View File

@ -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;
}

View File

@ -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 {

View File

@ -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 },
};

View File

@ -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
},
};

View File

@ -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
},
};

View File

@ -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
},
};

View File

@ -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 },
};

View File

@ -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 },
};

View File

@ -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 },
};

View File

@ -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 },
};

View File

@ -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 },
};

View File

@ -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 },
};

View File

@ -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 },
};

View File

@ -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
},
};

View File

@ -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},
};

View File

@ -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
},
};

View File

@ -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 },
};