mirror of https://github.com/mpv-player/mpv
stream: add a generic way to setup stream priv defaults
Usually, each stream driver declares the size and option list of its private data. This was pretty natural for when most streams still used global variables to setup their defaults. They did by pointing priv_defaults to the (mutable) struct containing the option values. But falls short when storing the option values in MPOpts. So provide a somewhat inelegant but simple way to let the stream implementation setup the priv struct at initialization time. This is done with the get_defaults callback. It should return a copy of the struct used in MPOpts. (A copy, because if MPOpts is changed, string fields might be deallocated, and if that field is not described by stream_info.options, it won't be copied on init.)
This commit is contained in:
parent
73ac34b220
commit
7689f5f7ce
|
@ -300,6 +300,8 @@ static int open_internal(const stream_info_t *sinfo, struct stream *underlying,
|
|||
.priv_defaults = sinfo->priv_defaults,
|
||||
.options = sinfo->options,
|
||||
};
|
||||
if (sinfo->get_defaults)
|
||||
desc.priv_defaults = sinfo->get_defaults(s);
|
||||
struct m_config *config = m_config_from_obj_desc(s, s->log, &desc);
|
||||
s->priv = config->optstruct;
|
||||
if (s->info->url_options && !parse_url(s, config)) {
|
||||
|
|
|
@ -132,6 +132,7 @@ typedef struct stream_info_st {
|
|||
const char **protocols;
|
||||
int priv_size;
|
||||
const void *priv_defaults;
|
||||
void *(*get_defaults)(struct stream *st);
|
||||
const struct m_option *options;
|
||||
const char **url_options;
|
||||
bool stream_filter;
|
||||
|
|
Loading…
Reference in New Issue